]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-3.0.4-201109011725.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-3.0.4-201109011725.patch
CommitLineData
7174233d
PK
1diff -urNp linux-3.0.4/arch/alpha/include/asm/elf.h linux-3.0.4/arch/alpha/include/asm/elf.h
2--- linux-3.0.4/arch/alpha/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
3+++ linux-3.0.4/arch/alpha/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
4@@ -90,6 +90,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-3.0.4/arch/alpha/include/asm/pgtable.h linux-3.0.4/arch/alpha/include/asm/pgtable.h
19--- linux-3.0.4/arch/alpha/include/asm/pgtable.h 2011-07-21 22:17:23.000000000 -0400
20+++ linux-3.0.4/arch/alpha/include/asm/pgtable.h 2011-08-23 21:47:55.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-3.0.4/arch/alpha/kernel/module.c linux-3.0.4/arch/alpha/kernel/module.c
40--- linux-3.0.4/arch/alpha/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
41+++ linux-3.0.4/arch/alpha/kernel/module.c 2011-08-23 21:47:55.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-3.0.4/arch/alpha/kernel/osf_sys.c linux-3.0.4/arch/alpha/kernel/osf_sys.c
52--- linux-3.0.4/arch/alpha/kernel/osf_sys.c 2011-07-21 22:17:23.000000000 -0400
53+++ linux-3.0.4/arch/alpha/kernel/osf_sys.c 2011-08-23 21:47:55.000000000 -0400
54@@ -1145,7 +1145,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@@ -1181,6 +1181,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@@ -1188,8 +1192,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-3.0.4/arch/alpha/mm/fault.c linux-3.0.4/arch/alpha/mm/fault.c
86--- linux-3.0.4/arch/alpha/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
87+++ linux-3.0.4/arch/alpha/mm/fault.c 2011-08-23 21:47:55.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-3.0.4/arch/arm/include/asm/elf.h linux-3.0.4/arch/arm/include/asm/elf.h
245--- linux-3.0.4/arch/arm/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
246+++ linux-3.0.4/arch/arm/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
247@@ -116,7 +116,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
263@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t
264 extern void elf_set_personality(const struct elf32_hdr *);
265 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
266
267-struct mm_struct;
268-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
269-#define arch_randomize_brk arch_randomize_brk
270-
271 extern int vectors_user_mapping(void);
272 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
273 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
274diff -urNp linux-3.0.4/arch/arm/include/asm/kmap_types.h linux-3.0.4/arch/arm/include/asm/kmap_types.h
275--- linux-3.0.4/arch/arm/include/asm/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
276+++ linux-3.0.4/arch/arm/include/asm/kmap_types.h 2011-08-23 21:47:55.000000000 -0400
277@@ -21,6 +21,7 @@ enum km_type {
278 KM_L1_CACHE,
279 KM_L2_CACHE,
280 KM_KDB,
281+ KM_CLEARPAGE,
282 KM_TYPE_NR
283 };
284
285diff -urNp linux-3.0.4/arch/arm/include/asm/uaccess.h linux-3.0.4/arch/arm/include/asm/uaccess.h
286--- linux-3.0.4/arch/arm/include/asm/uaccess.h 2011-07-21 22:17:23.000000000 -0400
287+++ linux-3.0.4/arch/arm/include/asm/uaccess.h 2011-08-23 21:47:55.000000000 -0400
288@@ -22,6 +22,8 @@
289 #define VERIFY_READ 0
290 #define VERIFY_WRITE 1
291
292+extern void check_object_size(const void *ptr, unsigned long n, bool to);
293+
294 /*
295 * The exception table consists of pairs of addresses: the first is the
296 * address of an instruction that is allowed to fault, and the second is
297@@ -387,8 +389,23 @@ do { \
298
299
300 #ifdef CONFIG_MMU
301-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
302-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
303+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
304+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
305+
306+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
307+{
308+ if (!__builtin_constant_p(n))
309+ check_object_size(to, n, false);
310+ return ___copy_from_user(to, from, n);
311+}
312+
313+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
314+{
315+ if (!__builtin_constant_p(n))
316+ check_object_size(from, n, true);
317+ return ___copy_to_user(to, from, n);
318+}
319+
320 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
321 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
322 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
323@@ -403,6 +420,9 @@ extern unsigned long __must_check __strn
324
325 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
326 {
327+ if ((long)n < 0)
328+ return n;
329+
330 if (access_ok(VERIFY_READ, from, n))
331 n = __copy_from_user(to, from, n);
332 else /* security hole - plug it */
333@@ -412,6 +432,9 @@ static inline unsigned long __must_check
334
335 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
336 {
337+ if ((long)n < 0)
338+ return n;
339+
340 if (access_ok(VERIFY_WRITE, to, n))
341 n = __copy_to_user(to, from, n);
342 return n;
343diff -urNp linux-3.0.4/arch/arm/kernel/armksyms.c linux-3.0.4/arch/arm/kernel/armksyms.c
344--- linux-3.0.4/arch/arm/kernel/armksyms.c 2011-07-21 22:17:23.000000000 -0400
345+++ linux-3.0.4/arch/arm/kernel/armksyms.c 2011-08-23 21:47:55.000000000 -0400
346@@ -98,8 +98,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
347 #ifdef CONFIG_MMU
348 EXPORT_SYMBOL(copy_page);
349
350-EXPORT_SYMBOL(__copy_from_user);
351-EXPORT_SYMBOL(__copy_to_user);
352+EXPORT_SYMBOL(___copy_from_user);
353+EXPORT_SYMBOL(___copy_to_user);
354 EXPORT_SYMBOL(__clear_user);
355
356 EXPORT_SYMBOL(__get_user_1);
357diff -urNp linux-3.0.4/arch/arm/kernel/process.c linux-3.0.4/arch/arm/kernel/process.c
358--- linux-3.0.4/arch/arm/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
359+++ linux-3.0.4/arch/arm/kernel/process.c 2011-08-23 21:47:55.000000000 -0400
360@@ -28,7 +28,6 @@
361 #include <linux/tick.h>
362 #include <linux/utsname.h>
363 #include <linux/uaccess.h>
364-#include <linux/random.h>
365 #include <linux/hw_breakpoint.h>
366
367 #include <asm/cacheflush.h>
368@@ -479,12 +478,6 @@ unsigned long get_wchan(struct task_stru
369 return 0;
370 }
371
372-unsigned long arch_randomize_brk(struct mm_struct *mm)
373-{
374- unsigned long range_end = mm->brk + 0x02000000;
375- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
376-}
377-
378 #ifdef CONFIG_MMU
379 /*
380 * The vectors page is always readable from user space for the
381diff -urNp linux-3.0.4/arch/arm/kernel/traps.c linux-3.0.4/arch/arm/kernel/traps.c
382--- linux-3.0.4/arch/arm/kernel/traps.c 2011-07-21 22:17:23.000000000 -0400
383+++ linux-3.0.4/arch/arm/kernel/traps.c 2011-08-23 21:48:14.000000000 -0400
384@@ -257,6 +257,8 @@ static int __die(const char *str, int er
385
386 static DEFINE_SPINLOCK(die_lock);
387
388+extern void gr_handle_kernel_exploit(void);
389+
390 /*
391 * This function is protected against re-entrancy.
392 */
393@@ -284,6 +286,9 @@ void die(const char *str, struct pt_regs
394 panic("Fatal exception in interrupt");
395 if (panic_on_oops)
396 panic("Fatal exception");
397+
398+ gr_handle_kernel_exploit();
399+
400 if (ret != NOTIFY_STOP)
401 do_exit(SIGSEGV);
402 }
403diff -urNp linux-3.0.4/arch/arm/lib/copy_from_user.S linux-3.0.4/arch/arm/lib/copy_from_user.S
404--- linux-3.0.4/arch/arm/lib/copy_from_user.S 2011-07-21 22:17:23.000000000 -0400
405+++ linux-3.0.4/arch/arm/lib/copy_from_user.S 2011-08-23 21:47:55.000000000 -0400
406@@ -16,7 +16,7 @@
407 /*
408 * Prototype:
409 *
410- * size_t __copy_from_user(void *to, const void *from, size_t n)
411+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
412 *
413 * Purpose:
414 *
415@@ -84,11 +84,11 @@
416
417 .text
418
419-ENTRY(__copy_from_user)
420+ENTRY(___copy_from_user)
421
422 #include "copy_template.S"
423
424-ENDPROC(__copy_from_user)
425+ENDPROC(___copy_from_user)
426
427 .pushsection .fixup,"ax"
428 .align 0
429diff -urNp linux-3.0.4/arch/arm/lib/copy_to_user.S linux-3.0.4/arch/arm/lib/copy_to_user.S
430--- linux-3.0.4/arch/arm/lib/copy_to_user.S 2011-07-21 22:17:23.000000000 -0400
431+++ linux-3.0.4/arch/arm/lib/copy_to_user.S 2011-08-23 21:47:55.000000000 -0400
432@@ -16,7 +16,7 @@
433 /*
434 * Prototype:
435 *
436- * size_t __copy_to_user(void *to, const void *from, size_t n)
437+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
438 *
439 * Purpose:
440 *
441@@ -88,11 +88,11 @@
442 .text
443
444 ENTRY(__copy_to_user_std)
445-WEAK(__copy_to_user)
446+WEAK(___copy_to_user)
447
448 #include "copy_template.S"
449
450-ENDPROC(__copy_to_user)
451+ENDPROC(___copy_to_user)
452 ENDPROC(__copy_to_user_std)
453
454 .pushsection .fixup,"ax"
455diff -urNp linux-3.0.4/arch/arm/lib/uaccess.S linux-3.0.4/arch/arm/lib/uaccess.S
456--- linux-3.0.4/arch/arm/lib/uaccess.S 2011-07-21 22:17:23.000000000 -0400
457+++ linux-3.0.4/arch/arm/lib/uaccess.S 2011-08-23 21:47:55.000000000 -0400
458@@ -20,7 +20,7 @@
459
460 #define PAGE_SHIFT 12
461
462-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
463+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
464 * Purpose : copy a block to user memory from kernel memory
465 * Params : to - user memory
466 * : from - kernel memory
467@@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May f
468 sub r2, r2, ip
469 b .Lc2u_dest_aligned
470
471-ENTRY(__copy_to_user)
472+ENTRY(___copy_to_user)
473 stmfd sp!, {r2, r4 - r7, lr}
474 cmp r2, #4
475 blt .Lc2u_not_enough
476@@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May f
477 ldrgtb r3, [r1], #0
478 USER( T(strgtb) r3, [r0], #1) @ May fault
479 b .Lc2u_finished
480-ENDPROC(__copy_to_user)
481+ENDPROC(___copy_to_user)
482
483 .pushsection .fixup,"ax"
484 .align 0
485 9001: ldmfd sp!, {r0, r4 - r7, pc}
486 .popsection
487
488-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
489+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
490 * Purpose : copy a block from user memory to kernel memory
491 * Params : to - kernel memory
492 * : from - user memory
493@@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May f
494 sub r2, r2, ip
495 b .Lcfu_dest_aligned
496
497-ENTRY(__copy_from_user)
498+ENTRY(___copy_from_user)
499 stmfd sp!, {r0, r2, r4 - r7, lr}
500 cmp r2, #4
501 blt .Lcfu_not_enough
502@@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May f
503 USER( T(ldrgtb) r3, [r1], #1) @ May fault
504 strgtb r3, [r0], #1
505 b .Lcfu_finished
506-ENDPROC(__copy_from_user)
507+ENDPROC(___copy_from_user)
508
509 .pushsection .fixup,"ax"
510 .align 0
511diff -urNp linux-3.0.4/arch/arm/lib/uaccess_with_memcpy.c linux-3.0.4/arch/arm/lib/uaccess_with_memcpy.c
512--- linux-3.0.4/arch/arm/lib/uaccess_with_memcpy.c 2011-07-21 22:17:23.000000000 -0400
513+++ linux-3.0.4/arch/arm/lib/uaccess_with_memcpy.c 2011-08-23 21:47:55.000000000 -0400
514@@ -103,7 +103,7 @@ out:
515 }
516
517 unsigned long
518-__copy_to_user(void __user *to, const void *from, unsigned long n)
519+___copy_to_user(void __user *to, const void *from, unsigned long n)
520 {
521 /*
522 * This test is stubbed out of the main function above to keep
523diff -urNp linux-3.0.4/arch/arm/mach-ux500/mbox-db5500.c linux-3.0.4/arch/arm/mach-ux500/mbox-db5500.c
524--- linux-3.0.4/arch/arm/mach-ux500/mbox-db5500.c 2011-07-21 22:17:23.000000000 -0400
525+++ linux-3.0.4/arch/arm/mach-ux500/mbox-db5500.c 2011-08-23 21:48:14.000000000 -0400
526@@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct dev
527 return sprintf(buf, "0x%X\n", mbox_value);
528 }
529
530-static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
531+static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
532
533 static int mbox_show(struct seq_file *s, void *data)
534 {
535diff -urNp linux-3.0.4/arch/arm/mm/fault.c linux-3.0.4/arch/arm/mm/fault.c
536--- linux-3.0.4/arch/arm/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
537+++ linux-3.0.4/arch/arm/mm/fault.c 2011-08-23 21:47:55.000000000 -0400
538@@ -182,6 +182,13 @@ __do_user_fault(struct task_struct *tsk,
539 }
540 #endif
541
542+#ifdef CONFIG_PAX_PAGEEXEC
543+ if (fsr & FSR_LNX_PF) {
544+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
545+ do_group_exit(SIGKILL);
546+ }
547+#endif
548+
549 tsk->thread.address = addr;
550 tsk->thread.error_code = fsr;
551 tsk->thread.trap_no = 14;
552@@ -379,6 +386,33 @@ do_page_fault(unsigned long addr, unsign
553 }
554 #endif /* CONFIG_MMU */
555
556+#ifdef CONFIG_PAX_PAGEEXEC
557+void pax_report_insns(void *pc, void *sp)
558+{
559+ long i;
560+
561+ printk(KERN_ERR "PAX: bytes at PC: ");
562+ for (i = 0; i < 20; i++) {
563+ unsigned char c;
564+ if (get_user(c, (__force unsigned char __user *)pc+i))
565+ printk(KERN_CONT "?? ");
566+ else
567+ printk(KERN_CONT "%02x ", c);
568+ }
569+ printk("\n");
570+
571+ printk(KERN_ERR "PAX: bytes at SP-4: ");
572+ for (i = -1; i < 20; i++) {
573+ unsigned long c;
574+ if (get_user(c, (__force unsigned long __user *)sp+i))
575+ printk(KERN_CONT "???????? ");
576+ else
577+ printk(KERN_CONT "%08lx ", c);
578+ }
579+ printk("\n");
580+}
581+#endif
582+
583 /*
584 * First Level Translation Fault Handler
585 *
586diff -urNp linux-3.0.4/arch/arm/mm/mmap.c linux-3.0.4/arch/arm/mm/mmap.c
587--- linux-3.0.4/arch/arm/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
588+++ linux-3.0.4/arch/arm/mm/mmap.c 2011-08-23 21:47:55.000000000 -0400
589@@ -65,6 +65,10 @@ arch_get_unmapped_area(struct file *filp
590 if (len > TASK_SIZE)
591 return -ENOMEM;
592
593+#ifdef CONFIG_PAX_RANDMMAP
594+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
595+#endif
596+
597 if (addr) {
598 if (do_align)
599 addr = COLOUR_ALIGN(addr, pgoff);
600@@ -72,15 +76,14 @@ arch_get_unmapped_area(struct file *filp
601 addr = PAGE_ALIGN(addr);
602
603 vma = find_vma(mm, addr);
604- if (TASK_SIZE - len >= addr &&
605- (!vma || addr + len <= vma->vm_start))
606+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
607 return addr;
608 }
609 if (len > mm->cached_hole_size) {
610- start_addr = addr = mm->free_area_cache;
611+ start_addr = addr = mm->free_area_cache;
612 } else {
613- start_addr = addr = TASK_UNMAPPED_BASE;
614- mm->cached_hole_size = 0;
615+ start_addr = addr = mm->mmap_base;
616+ mm->cached_hole_size = 0;
617 }
618 /* 8 bits of randomness in 20 address space bits */
619 if ((current->flags & PF_RANDOMIZE) &&
620@@ -100,14 +103,14 @@ full_search:
621 * Start a new search - just in case we missed
622 * some holes.
623 */
624- if (start_addr != TASK_UNMAPPED_BASE) {
625- start_addr = addr = TASK_UNMAPPED_BASE;
626+ if (start_addr != mm->mmap_base) {
627+ start_addr = addr = mm->mmap_base;
628 mm->cached_hole_size = 0;
629 goto full_search;
630 }
631 return -ENOMEM;
632 }
633- if (!vma || addr + len <= vma->vm_start) {
634+ if (check_heap_stack_gap(vma, addr, len)) {
635 /*
636 * Remember the place where we stopped the search:
637 */
638diff -urNp linux-3.0.4/arch/avr32/include/asm/elf.h linux-3.0.4/arch/avr32/include/asm/elf.h
639--- linux-3.0.4/arch/avr32/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
640+++ linux-3.0.4/arch/avr32/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
641@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpreg
642 the loader. We need to make sure that it is out of the way of the program
643 that it will "exec", and that there is sufficient room for the brk. */
644
645-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
646+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
647
648+#ifdef CONFIG_PAX_ASLR
649+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
650+
651+#define PAX_DELTA_MMAP_LEN 15
652+#define PAX_DELTA_STACK_LEN 15
653+#endif
654
655 /* This yields a mask that user programs can use to figure out what
656 instruction set this CPU supports. This could be done in user space,
657diff -urNp linux-3.0.4/arch/avr32/include/asm/kmap_types.h linux-3.0.4/arch/avr32/include/asm/kmap_types.h
658--- linux-3.0.4/arch/avr32/include/asm/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
659+++ linux-3.0.4/arch/avr32/include/asm/kmap_types.h 2011-08-23 21:47:55.000000000 -0400
660@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
661 D(11) KM_IRQ1,
662 D(12) KM_SOFTIRQ0,
663 D(13) KM_SOFTIRQ1,
664-D(14) KM_TYPE_NR
665+D(14) KM_CLEARPAGE,
666+D(15) KM_TYPE_NR
667 };
668
669 #undef D
670diff -urNp linux-3.0.4/arch/avr32/mm/fault.c linux-3.0.4/arch/avr32/mm/fault.c
671--- linux-3.0.4/arch/avr32/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
672+++ linux-3.0.4/arch/avr32/mm/fault.c 2011-08-23 21:47:55.000000000 -0400
673@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
674
675 int exception_trace = 1;
676
677+#ifdef CONFIG_PAX_PAGEEXEC
678+void pax_report_insns(void *pc, void *sp)
679+{
680+ unsigned long i;
681+
682+ printk(KERN_ERR "PAX: bytes at PC: ");
683+ for (i = 0; i < 20; i++) {
684+ unsigned char c;
685+ if (get_user(c, (unsigned char *)pc+i))
686+ printk(KERN_CONT "???????? ");
687+ else
688+ printk(KERN_CONT "%02x ", c);
689+ }
690+ printk("\n");
691+}
692+#endif
693+
694 /*
695 * This routine handles page faults. It determines the address and the
696 * problem, and then passes it off to one of the appropriate routines.
697@@ -156,6 +173,16 @@ bad_area:
698 up_read(&mm->mmap_sem);
699
700 if (user_mode(regs)) {
701+
702+#ifdef CONFIG_PAX_PAGEEXEC
703+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
704+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
705+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
706+ do_group_exit(SIGKILL);
707+ }
708+ }
709+#endif
710+
711 if (exception_trace && printk_ratelimit())
712 printk("%s%s[%d]: segfault at %08lx pc %08lx "
713 "sp %08lx ecr %lu\n",
714diff -urNp linux-3.0.4/arch/frv/include/asm/kmap_types.h linux-3.0.4/arch/frv/include/asm/kmap_types.h
715--- linux-3.0.4/arch/frv/include/asm/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
716+++ linux-3.0.4/arch/frv/include/asm/kmap_types.h 2011-08-23 21:47:55.000000000 -0400
717@@ -23,6 +23,7 @@ enum km_type {
718 KM_IRQ1,
719 KM_SOFTIRQ0,
720 KM_SOFTIRQ1,
721+ KM_CLEARPAGE,
722 KM_TYPE_NR
723 };
724
725diff -urNp linux-3.0.4/arch/frv/mm/elf-fdpic.c linux-3.0.4/arch/frv/mm/elf-fdpic.c
726--- linux-3.0.4/arch/frv/mm/elf-fdpic.c 2011-07-21 22:17:23.000000000 -0400
727+++ linux-3.0.4/arch/frv/mm/elf-fdpic.c 2011-08-23 21:47:55.000000000 -0400
728@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
729 if (addr) {
730 addr = PAGE_ALIGN(addr);
731 vma = find_vma(current->mm, addr);
732- if (TASK_SIZE - len >= addr &&
733- (!vma || addr + len <= vma->vm_start))
734+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
735 goto success;
736 }
737
738@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
739 for (; vma; vma = vma->vm_next) {
740 if (addr > limit)
741 break;
742- if (addr + len <= vma->vm_start)
743+ if (check_heap_stack_gap(vma, addr, len))
744 goto success;
745 addr = vma->vm_end;
746 }
747@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
748 for (; vma; vma = vma->vm_next) {
749 if (addr > limit)
750 break;
751- if (addr + len <= vma->vm_start)
752+ if (check_heap_stack_gap(vma, addr, len))
753 goto success;
754 addr = vma->vm_end;
755 }
756diff -urNp linux-3.0.4/arch/ia64/include/asm/elf.h linux-3.0.4/arch/ia64/include/asm/elf.h
757--- linux-3.0.4/arch/ia64/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
758+++ linux-3.0.4/arch/ia64/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
759@@ -42,6 +42,13 @@
760 */
761 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
762
763+#ifdef CONFIG_PAX_ASLR
764+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
765+
766+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
767+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
768+#endif
769+
770 #define PT_IA_64_UNWIND 0x70000001
771
772 /* IA-64 relocations: */
773diff -urNp linux-3.0.4/arch/ia64/include/asm/pgtable.h linux-3.0.4/arch/ia64/include/asm/pgtable.h
774--- linux-3.0.4/arch/ia64/include/asm/pgtable.h 2011-07-21 22:17:23.000000000 -0400
775+++ linux-3.0.4/arch/ia64/include/asm/pgtable.h 2011-08-23 21:47:55.000000000 -0400
776@@ -12,7 +12,7 @@
777 * David Mosberger-Tang <davidm@hpl.hp.com>
778 */
779
780-
781+#include <linux/const.h>
782 #include <asm/mman.h>
783 #include <asm/page.h>
784 #include <asm/processor.h>
785@@ -143,6 +143,17 @@
786 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
787 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
788 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
789+
790+#ifdef CONFIG_PAX_PAGEEXEC
791+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
792+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
793+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
794+#else
795+# define PAGE_SHARED_NOEXEC PAGE_SHARED
796+# define PAGE_READONLY_NOEXEC PAGE_READONLY
797+# define PAGE_COPY_NOEXEC PAGE_COPY
798+#endif
799+
800 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
801 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
802 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
803diff -urNp linux-3.0.4/arch/ia64/include/asm/spinlock.h linux-3.0.4/arch/ia64/include/asm/spinlock.h
804--- linux-3.0.4/arch/ia64/include/asm/spinlock.h 2011-07-21 22:17:23.000000000 -0400
805+++ linux-3.0.4/arch/ia64/include/asm/spinlock.h 2011-08-23 21:47:55.000000000 -0400
806@@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
807 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
808
809 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
810- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
811+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
812 }
813
814 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
815diff -urNp linux-3.0.4/arch/ia64/include/asm/uaccess.h linux-3.0.4/arch/ia64/include/asm/uaccess.h
816--- linux-3.0.4/arch/ia64/include/asm/uaccess.h 2011-07-21 22:17:23.000000000 -0400
817+++ linux-3.0.4/arch/ia64/include/asm/uaccess.h 2011-08-23 21:47:55.000000000 -0400
818@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
819 const void *__cu_from = (from); \
820 long __cu_len = (n); \
821 \
822- if (__access_ok(__cu_to, __cu_len, get_fs())) \
823+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
824 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
825 __cu_len; \
826 })
827@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
828 long __cu_len = (n); \
829 \
830 __chk_user_ptr(__cu_from); \
831- if (__access_ok(__cu_from, __cu_len, get_fs())) \
832+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
833 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
834 __cu_len; \
835 })
836diff -urNp linux-3.0.4/arch/ia64/kernel/module.c linux-3.0.4/arch/ia64/kernel/module.c
837--- linux-3.0.4/arch/ia64/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
838+++ linux-3.0.4/arch/ia64/kernel/module.c 2011-08-23 21:47:55.000000000 -0400
839@@ -315,8 +315,7 @@ module_alloc (unsigned long size)
840 void
841 module_free (struct module *mod, void *module_region)
842 {
843- if (mod && mod->arch.init_unw_table &&
844- module_region == mod->module_init) {
845+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
846 unw_remove_unwind_table(mod->arch.init_unw_table);
847 mod->arch.init_unw_table = NULL;
848 }
849@@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
850 }
851
852 static inline int
853+in_init_rx (const struct module *mod, uint64_t addr)
854+{
855+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
856+}
857+
858+static inline int
859+in_init_rw (const struct module *mod, uint64_t addr)
860+{
861+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
862+}
863+
864+static inline int
865 in_init (const struct module *mod, uint64_t addr)
866 {
867- return addr - (uint64_t) mod->module_init < mod->init_size;
868+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
869+}
870+
871+static inline int
872+in_core_rx (const struct module *mod, uint64_t addr)
873+{
874+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
875+}
876+
877+static inline int
878+in_core_rw (const struct module *mod, uint64_t addr)
879+{
880+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
881 }
882
883 static inline int
884 in_core (const struct module *mod, uint64_t addr)
885 {
886- return addr - (uint64_t) mod->module_core < mod->core_size;
887+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
888 }
889
890 static inline int
891@@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
892 break;
893
894 case RV_BDREL:
895- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
896+ if (in_init_rx(mod, val))
897+ val -= (uint64_t) mod->module_init_rx;
898+ else if (in_init_rw(mod, val))
899+ val -= (uint64_t) mod->module_init_rw;
900+ else if (in_core_rx(mod, val))
901+ val -= (uint64_t) mod->module_core_rx;
902+ else if (in_core_rw(mod, val))
903+ val -= (uint64_t) mod->module_core_rw;
904 break;
905
906 case RV_LTV:
907@@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
908 * addresses have been selected...
909 */
910 uint64_t gp;
911- if (mod->core_size > MAX_LTOFF)
912+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
913 /*
914 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
915 * at the end of the module.
916 */
917- gp = mod->core_size - MAX_LTOFF / 2;
918+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
919 else
920- gp = mod->core_size / 2;
921- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
922+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
923+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
924 mod->arch.gp = gp;
925 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
926 }
927diff -urNp linux-3.0.4/arch/ia64/kernel/sys_ia64.c linux-3.0.4/arch/ia64/kernel/sys_ia64.c
928--- linux-3.0.4/arch/ia64/kernel/sys_ia64.c 2011-07-21 22:17:23.000000000 -0400
929+++ linux-3.0.4/arch/ia64/kernel/sys_ia64.c 2011-08-23 21:47:55.000000000 -0400
930@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
931 if (REGION_NUMBER(addr) == RGN_HPAGE)
932 addr = 0;
933 #endif
934+
935+#ifdef CONFIG_PAX_RANDMMAP
936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
937+ addr = mm->free_area_cache;
938+ else
939+#endif
940+
941 if (!addr)
942 addr = mm->free_area_cache;
943
944@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
945 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
946 /* At this point: (!vma || addr < vma->vm_end). */
947 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
948- if (start_addr != TASK_UNMAPPED_BASE) {
949+ if (start_addr != mm->mmap_base) {
950 /* Start a new search --- just in case we missed some holes. */
951- addr = TASK_UNMAPPED_BASE;
952+ addr = mm->mmap_base;
953 goto full_search;
954 }
955 return -ENOMEM;
956 }
957- if (!vma || addr + len <= vma->vm_start) {
958+ if (check_heap_stack_gap(vma, addr, len)) {
959 /* Remember the address where we stopped this search: */
960 mm->free_area_cache = addr + len;
961 return addr;
962diff -urNp linux-3.0.4/arch/ia64/kernel/vmlinux.lds.S linux-3.0.4/arch/ia64/kernel/vmlinux.lds.S
963--- linux-3.0.4/arch/ia64/kernel/vmlinux.lds.S 2011-07-21 22:17:23.000000000 -0400
964+++ linux-3.0.4/arch/ia64/kernel/vmlinux.lds.S 2011-08-23 21:47:55.000000000 -0400
965@@ -199,7 +199,7 @@ SECTIONS {
966 /* Per-cpu data: */
967 . = ALIGN(PERCPU_PAGE_SIZE);
968 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
969- __phys_per_cpu_start = __per_cpu_load;
970+ __phys_per_cpu_start = per_cpu_load;
971 /*
972 * ensure percpu data fits
973 * into percpu page size
974diff -urNp linux-3.0.4/arch/ia64/mm/fault.c linux-3.0.4/arch/ia64/mm/fault.c
975--- linux-3.0.4/arch/ia64/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
976+++ linux-3.0.4/arch/ia64/mm/fault.c 2011-08-23 21:47:55.000000000 -0400
977@@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned
978 return pte_present(pte);
979 }
980
981+#ifdef CONFIG_PAX_PAGEEXEC
982+void pax_report_insns(void *pc, void *sp)
983+{
984+ unsigned long i;
985+
986+ printk(KERN_ERR "PAX: bytes at PC: ");
987+ for (i = 0; i < 8; i++) {
988+ unsigned int c;
989+ if (get_user(c, (unsigned int *)pc+i))
990+ printk(KERN_CONT "???????? ");
991+ else
992+ printk(KERN_CONT "%08x ", c);
993+ }
994+ printk("\n");
995+}
996+#endif
997+
998 void __kprobes
999 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1000 {
1001@@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long addres
1002 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1003 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1004
1005- if ((vma->vm_flags & mask) != mask)
1006+ if ((vma->vm_flags & mask) != mask) {
1007+
1008+#ifdef CONFIG_PAX_PAGEEXEC
1009+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1010+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1011+ goto bad_area;
1012+
1013+ up_read(&mm->mmap_sem);
1014+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1015+ do_group_exit(SIGKILL);
1016+ }
1017+#endif
1018+
1019 goto bad_area;
1020
1021+ }
1022+
1023 /*
1024 * If for any reason at all we couldn't handle the fault, make
1025 * sure we exit gracefully rather than endlessly redo the
1026diff -urNp linux-3.0.4/arch/ia64/mm/hugetlbpage.c linux-3.0.4/arch/ia64/mm/hugetlbpage.c
1027--- linux-3.0.4/arch/ia64/mm/hugetlbpage.c 2011-07-21 22:17:23.000000000 -0400
1028+++ linux-3.0.4/arch/ia64/mm/hugetlbpage.c 2011-08-23 21:47:55.000000000 -0400
1029@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(
1030 /* At this point: (!vmm || addr < vmm->vm_end). */
1031 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1032 return -ENOMEM;
1033- if (!vmm || (addr + len) <= vmm->vm_start)
1034+ if (check_heap_stack_gap(vmm, addr, len))
1035 return addr;
1036 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1037 }
1038diff -urNp linux-3.0.4/arch/ia64/mm/init.c linux-3.0.4/arch/ia64/mm/init.c
1039--- linux-3.0.4/arch/ia64/mm/init.c 2011-07-21 22:17:23.000000000 -0400
1040+++ linux-3.0.4/arch/ia64/mm/init.c 2011-08-23 21:47:55.000000000 -0400
1041@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
1042 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1043 vma->vm_end = vma->vm_start + PAGE_SIZE;
1044 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1045+
1046+#ifdef CONFIG_PAX_PAGEEXEC
1047+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1048+ vma->vm_flags &= ~VM_EXEC;
1049+
1050+#ifdef CONFIG_PAX_MPROTECT
1051+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
1052+ vma->vm_flags &= ~VM_MAYEXEC;
1053+#endif
1054+
1055+ }
1056+#endif
1057+
1058 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1059 down_write(&current->mm->mmap_sem);
1060 if (insert_vm_struct(current->mm, vma)) {
1061diff -urNp linux-3.0.4/arch/m32r/lib/usercopy.c linux-3.0.4/arch/m32r/lib/usercopy.c
1062--- linux-3.0.4/arch/m32r/lib/usercopy.c 2011-07-21 22:17:23.000000000 -0400
1063+++ linux-3.0.4/arch/m32r/lib/usercopy.c 2011-08-23 21:47:55.000000000 -0400
1064@@ -14,6 +14,9 @@
1065 unsigned long
1066 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1067 {
1068+ if ((long)n < 0)
1069+ return n;
1070+
1071 prefetch(from);
1072 if (access_ok(VERIFY_WRITE, to, n))
1073 __copy_user(to,from,n);
1074@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1075 unsigned long
1076 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1077 {
1078+ if ((long)n < 0)
1079+ return n;
1080+
1081 prefetchw(to);
1082 if (access_ok(VERIFY_READ, from, n))
1083 __copy_user_zeroing(to,from,n);
1084diff -urNp linux-3.0.4/arch/mips/include/asm/elf.h linux-3.0.4/arch/mips/include/asm/elf.h
1085--- linux-3.0.4/arch/mips/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
1086+++ linux-3.0.4/arch/mips/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
1087@@ -372,13 +372,16 @@ extern const char *__elf_platform;
1088 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1089 #endif
1090
1091+#ifdef CONFIG_PAX_ASLR
1092+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1093+
1094+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1095+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1096+#endif
1097+
1098 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1099 struct linux_binprm;
1100 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1101 int uses_interp);
1102
1103-struct mm_struct;
1104-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1105-#define arch_randomize_brk arch_randomize_brk
1106-
1107 #endif /* _ASM_ELF_H */
1108diff -urNp linux-3.0.4/arch/mips/include/asm/page.h linux-3.0.4/arch/mips/include/asm/page.h
1109--- linux-3.0.4/arch/mips/include/asm/page.h 2011-07-21 22:17:23.000000000 -0400
1110+++ linux-3.0.4/arch/mips/include/asm/page.h 2011-08-23 21:47:55.000000000 -0400
1111@@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
1112 #ifdef CONFIG_CPU_MIPS32
1113 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1114 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1115- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1116+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1117 #else
1118 typedef struct { unsigned long long pte; } pte_t;
1119 #define pte_val(x) ((x).pte)
1120diff -urNp linux-3.0.4/arch/mips/include/asm/system.h linux-3.0.4/arch/mips/include/asm/system.h
1121--- linux-3.0.4/arch/mips/include/asm/system.h 2011-07-21 22:17:23.000000000 -0400
1122+++ linux-3.0.4/arch/mips/include/asm/system.h 2011-08-23 21:47:55.000000000 -0400
1123@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1124 */
1125 #define __ARCH_WANT_UNLOCKED_CTXSW
1126
1127-extern unsigned long arch_align_stack(unsigned long sp);
1128+#define arch_align_stack(x) ((x) & ~0xfUL)
1129
1130 #endif /* _ASM_SYSTEM_H */
1131diff -urNp linux-3.0.4/arch/mips/kernel/binfmt_elfn32.c linux-3.0.4/arch/mips/kernel/binfmt_elfn32.c
1132--- linux-3.0.4/arch/mips/kernel/binfmt_elfn32.c 2011-07-21 22:17:23.000000000 -0400
1133+++ linux-3.0.4/arch/mips/kernel/binfmt_elfn32.c 2011-08-23 21:47:55.000000000 -0400
1134@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1135 #undef ELF_ET_DYN_BASE
1136 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1137
1138+#ifdef CONFIG_PAX_ASLR
1139+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1140+
1141+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1142+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1143+#endif
1144+
1145 #include <asm/processor.h>
1146 #include <linux/module.h>
1147 #include <linux/elfcore.h>
1148diff -urNp linux-3.0.4/arch/mips/kernel/binfmt_elfo32.c linux-3.0.4/arch/mips/kernel/binfmt_elfo32.c
1149--- linux-3.0.4/arch/mips/kernel/binfmt_elfo32.c 2011-07-21 22:17:23.000000000 -0400
1150+++ linux-3.0.4/arch/mips/kernel/binfmt_elfo32.c 2011-08-23 21:47:55.000000000 -0400
1151@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1152 #undef ELF_ET_DYN_BASE
1153 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1154
1155+#ifdef CONFIG_PAX_ASLR
1156+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1157+
1158+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1159+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1160+#endif
1161+
1162 #include <asm/processor.h>
1163
1164 /*
1165diff -urNp linux-3.0.4/arch/mips/kernel/process.c linux-3.0.4/arch/mips/kernel/process.c
1166--- linux-3.0.4/arch/mips/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
1167+++ linux-3.0.4/arch/mips/kernel/process.c 2011-08-23 21:47:55.000000000 -0400
1168@@ -473,15 +473,3 @@ unsigned long get_wchan(struct task_stru
1169 out:
1170 return pc;
1171 }
1172-
1173-/*
1174- * Don't forget that the stack pointer must be aligned on a 8 bytes
1175- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1176- */
1177-unsigned long arch_align_stack(unsigned long sp)
1178-{
1179- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1180- sp -= get_random_int() & ~PAGE_MASK;
1181-
1182- return sp & ALMASK;
1183-}
1184diff -urNp linux-3.0.4/arch/mips/mm/fault.c linux-3.0.4/arch/mips/mm/fault.c
1185--- linux-3.0.4/arch/mips/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
1186+++ linux-3.0.4/arch/mips/mm/fault.c 2011-08-23 21:47:55.000000000 -0400
1187@@ -28,6 +28,23 @@
1188 #include <asm/highmem.h> /* For VMALLOC_END */
1189 #include <linux/kdebug.h>
1190
1191+#ifdef CONFIG_PAX_PAGEEXEC
1192+void pax_report_insns(void *pc, void *sp)
1193+{
1194+ unsigned long i;
1195+
1196+ printk(KERN_ERR "PAX: bytes at PC: ");
1197+ for (i = 0; i < 5; i++) {
1198+ unsigned int c;
1199+ if (get_user(c, (unsigned int *)pc+i))
1200+ printk(KERN_CONT "???????? ");
1201+ else
1202+ printk(KERN_CONT "%08x ", c);
1203+ }
1204+ printk("\n");
1205+}
1206+#endif
1207+
1208 /*
1209 * This routine handles page faults. It determines the address,
1210 * and the problem, and then passes it off to one of the appropriate
1211diff -urNp linux-3.0.4/arch/mips/mm/mmap.c linux-3.0.4/arch/mips/mm/mmap.c
1212--- linux-3.0.4/arch/mips/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
1213+++ linux-3.0.4/arch/mips/mm/mmap.c 2011-08-23 21:47:55.000000000 -0400
1214@@ -48,14 +48,18 @@ unsigned long arch_get_unmapped_area(str
1215 do_color_align = 0;
1216 if (filp || (flags & MAP_SHARED))
1217 do_color_align = 1;
1218+
1219+#ifdef CONFIG_PAX_RANDMMAP
1220+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1221+#endif
1222+
1223 if (addr) {
1224 if (do_color_align)
1225 addr = COLOUR_ALIGN(addr, pgoff);
1226 else
1227 addr = PAGE_ALIGN(addr);
1228 vmm = find_vma(current->mm, addr);
1229- if (TASK_SIZE - len >= addr &&
1230- (!vmm || addr + len <= vmm->vm_start))
1231+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
1232 return addr;
1233 }
1234 addr = current->mm->mmap_base;
1235@@ -68,7 +72,7 @@ unsigned long arch_get_unmapped_area(str
1236 /* At this point: (!vmm || addr < vmm->vm_end). */
1237 if (TASK_SIZE - len < addr)
1238 return -ENOMEM;
1239- if (!vmm || addr + len <= vmm->vm_start)
1240+ if (check_heap_stack_gap(vmm, addr, len))
1241 return addr;
1242 addr = vmm->vm_end;
1243 if (do_color_align)
1244@@ -93,30 +97,3 @@ void arch_pick_mmap_layout(struct mm_str
1245 mm->get_unmapped_area = arch_get_unmapped_area;
1246 mm->unmap_area = arch_unmap_area;
1247 }
1248-
1249-static inline unsigned long brk_rnd(void)
1250-{
1251- unsigned long rnd = get_random_int();
1252-
1253- rnd = rnd << PAGE_SHIFT;
1254- /* 8MB for 32bit, 256MB for 64bit */
1255- if (TASK_IS_32BIT_ADDR)
1256- rnd = rnd & 0x7ffffful;
1257- else
1258- rnd = rnd & 0xffffffful;
1259-
1260- return rnd;
1261-}
1262-
1263-unsigned long arch_randomize_brk(struct mm_struct *mm)
1264-{
1265- unsigned long base = mm->brk;
1266- unsigned long ret;
1267-
1268- ret = PAGE_ALIGN(base + brk_rnd());
1269-
1270- if (ret < mm->brk)
1271- return mm->brk;
1272-
1273- return ret;
1274-}
1275diff -urNp linux-3.0.4/arch/parisc/include/asm/elf.h linux-3.0.4/arch/parisc/include/asm/elf.h
1276--- linux-3.0.4/arch/parisc/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
1277+++ linux-3.0.4/arch/parisc/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
1278@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration..
1279
1280 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1281
1282+#ifdef CONFIG_PAX_ASLR
1283+#define PAX_ELF_ET_DYN_BASE 0x10000UL
1284+
1285+#define PAX_DELTA_MMAP_LEN 16
1286+#define PAX_DELTA_STACK_LEN 16
1287+#endif
1288+
1289 /* This yields a mask that user programs can use to figure out what
1290 instruction set this CPU supports. This could be done in user space,
1291 but it's not easy, and we've already done it here. */
1292diff -urNp linux-3.0.4/arch/parisc/include/asm/pgtable.h linux-3.0.4/arch/parisc/include/asm/pgtable.h
1293--- linux-3.0.4/arch/parisc/include/asm/pgtable.h 2011-07-21 22:17:23.000000000 -0400
1294+++ linux-3.0.4/arch/parisc/include/asm/pgtable.h 2011-08-23 21:47:55.000000000 -0400
1295@@ -210,6 +210,17 @@ struct vm_area_struct;
1296 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1297 #define PAGE_COPY PAGE_EXECREAD
1298 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1299+
1300+#ifdef CONFIG_PAX_PAGEEXEC
1301+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1302+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1303+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1304+#else
1305+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1306+# define PAGE_COPY_NOEXEC PAGE_COPY
1307+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1308+#endif
1309+
1310 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1311 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
1312 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
1313diff -urNp linux-3.0.4/arch/parisc/kernel/module.c linux-3.0.4/arch/parisc/kernel/module.c
1314--- linux-3.0.4/arch/parisc/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
1315+++ linux-3.0.4/arch/parisc/kernel/module.c 2011-08-23 21:47:55.000000000 -0400
1316@@ -98,16 +98,38 @@
1317
1318 /* three functions to determine where in the module core
1319 * or init pieces the location is */
1320+static inline int in_init_rx(struct module *me, void *loc)
1321+{
1322+ return (loc >= me->module_init_rx &&
1323+ loc < (me->module_init_rx + me->init_size_rx));
1324+}
1325+
1326+static inline int in_init_rw(struct module *me, void *loc)
1327+{
1328+ return (loc >= me->module_init_rw &&
1329+ loc < (me->module_init_rw + me->init_size_rw));
1330+}
1331+
1332 static inline int in_init(struct module *me, void *loc)
1333 {
1334- return (loc >= me->module_init &&
1335- loc <= (me->module_init + me->init_size));
1336+ return in_init_rx(me, loc) || in_init_rw(me, loc);
1337+}
1338+
1339+static inline int in_core_rx(struct module *me, void *loc)
1340+{
1341+ return (loc >= me->module_core_rx &&
1342+ loc < (me->module_core_rx + me->core_size_rx));
1343+}
1344+
1345+static inline int in_core_rw(struct module *me, void *loc)
1346+{
1347+ return (loc >= me->module_core_rw &&
1348+ loc < (me->module_core_rw + me->core_size_rw));
1349 }
1350
1351 static inline int in_core(struct module *me, void *loc)
1352 {
1353- return (loc >= me->module_core &&
1354- loc <= (me->module_core + me->core_size));
1355+ return in_core_rx(me, loc) || in_core_rw(me, loc);
1356 }
1357
1358 static inline int in_local(struct module *me, void *loc)
1359@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_
1360 }
1361
1362 /* align things a bit */
1363- me->core_size = ALIGN(me->core_size, 16);
1364- me->arch.got_offset = me->core_size;
1365- me->core_size += gots * sizeof(struct got_entry);
1366-
1367- me->core_size = ALIGN(me->core_size, 16);
1368- me->arch.fdesc_offset = me->core_size;
1369- me->core_size += fdescs * sizeof(Elf_Fdesc);
1370+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1371+ me->arch.got_offset = me->core_size_rw;
1372+ me->core_size_rw += gots * sizeof(struct got_entry);
1373+
1374+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1375+ me->arch.fdesc_offset = me->core_size_rw;
1376+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1377
1378 me->arch.got_max = gots;
1379 me->arch.fdesc_max = fdescs;
1380@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module
1381
1382 BUG_ON(value == 0);
1383
1384- got = me->module_core + me->arch.got_offset;
1385+ got = me->module_core_rw + me->arch.got_offset;
1386 for (i = 0; got[i].addr; i++)
1387 if (got[i].addr == value)
1388 goto out;
1389@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module
1390 #ifdef CONFIG_64BIT
1391 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1392 {
1393- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1394+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1395
1396 if (!value) {
1397 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1398@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module
1399
1400 /* Create new one */
1401 fdesc->addr = value;
1402- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1403+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1404 return (Elf_Addr)fdesc;
1405 }
1406 #endif /* CONFIG_64BIT */
1407@@ -857,7 +879,7 @@ register_unwind_table(struct module *me,
1408
1409 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1410 end = table + sechdrs[me->arch.unwind_section].sh_size;
1411- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1412+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1413
1414 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1415 me->arch.unwind_section, table, end, gp);
1416diff -urNp linux-3.0.4/arch/parisc/kernel/sys_parisc.c linux-3.0.4/arch/parisc/kernel/sys_parisc.c
1417--- linux-3.0.4/arch/parisc/kernel/sys_parisc.c 2011-07-21 22:17:23.000000000 -0400
1418+++ linux-3.0.4/arch/parisc/kernel/sys_parisc.c 2011-08-23 21:47:55.000000000 -0400
1419@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
1420 /* At this point: (!vma || addr < vma->vm_end). */
1421 if (TASK_SIZE - len < addr)
1422 return -ENOMEM;
1423- if (!vma || addr + len <= vma->vm_start)
1424+ if (check_heap_stack_gap(vma, addr, len))
1425 return addr;
1426 addr = vma->vm_end;
1427 }
1428@@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
1429 /* At this point: (!vma || addr < vma->vm_end). */
1430 if (TASK_SIZE - len < addr)
1431 return -ENOMEM;
1432- if (!vma || addr + len <= vma->vm_start)
1433+ if (check_heap_stack_gap(vma, addr, len))
1434 return addr;
1435 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1436 if (addr < vma->vm_end) /* handle wraparound */
1437@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1438 if (flags & MAP_FIXED)
1439 return addr;
1440 if (!addr)
1441- addr = TASK_UNMAPPED_BASE;
1442+ addr = current->mm->mmap_base;
1443
1444 if (filp) {
1445 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1446diff -urNp linux-3.0.4/arch/parisc/kernel/traps.c linux-3.0.4/arch/parisc/kernel/traps.c
1447--- linux-3.0.4/arch/parisc/kernel/traps.c 2011-07-21 22:17:23.000000000 -0400
1448+++ linux-3.0.4/arch/parisc/kernel/traps.c 2011-08-23 21:47:55.000000000 -0400
1449@@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
1450
1451 down_read(&current->mm->mmap_sem);
1452 vma = find_vma(current->mm,regs->iaoq[0]);
1453- if (vma && (regs->iaoq[0] >= vma->vm_start)
1454- && (vma->vm_flags & VM_EXEC)) {
1455-
1456+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1457 fault_address = regs->iaoq[0];
1458 fault_space = regs->iasq[0];
1459
1460diff -urNp linux-3.0.4/arch/parisc/mm/fault.c linux-3.0.4/arch/parisc/mm/fault.c
1461--- linux-3.0.4/arch/parisc/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
1462+++ linux-3.0.4/arch/parisc/mm/fault.c 2011-08-23 21:47:55.000000000 -0400
1463@@ -15,6 +15,7 @@
1464 #include <linux/sched.h>
1465 #include <linux/interrupt.h>
1466 #include <linux/module.h>
1467+#include <linux/unistd.h>
1468
1469 #include <asm/uaccess.h>
1470 #include <asm/traps.h>
1471@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1472 static unsigned long
1473 parisc_acctyp(unsigned long code, unsigned int inst)
1474 {
1475- if (code == 6 || code == 16)
1476+ if (code == 6 || code == 7 || code == 16)
1477 return VM_EXEC;
1478
1479 switch (inst & 0xf0000000) {
1480@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
1481 }
1482 #endif
1483
1484+#ifdef CONFIG_PAX_PAGEEXEC
1485+/*
1486+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1487+ *
1488+ * returns 1 when task should be killed
1489+ * 2 when rt_sigreturn trampoline was detected
1490+ * 3 when unpatched PLT trampoline was detected
1491+ */
1492+static int pax_handle_fetch_fault(struct pt_regs *regs)
1493+{
1494+
1495+#ifdef CONFIG_PAX_EMUPLT
1496+ int err;
1497+
1498+ do { /* PaX: unpatched PLT emulation */
1499+ unsigned int bl, depwi;
1500+
1501+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1502+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1503+
1504+ if (err)
1505+ break;
1506+
1507+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1508+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1509+
1510+ err = get_user(ldw, (unsigned int *)addr);
1511+ err |= get_user(bv, (unsigned int *)(addr+4));
1512+ err |= get_user(ldw2, (unsigned int *)(addr+8));
1513+
1514+ if (err)
1515+ break;
1516+
1517+ if (ldw == 0x0E801096U &&
1518+ bv == 0xEAC0C000U &&
1519+ ldw2 == 0x0E881095U)
1520+ {
1521+ unsigned int resolver, map;
1522+
1523+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1524+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1525+ if (err)
1526+ break;
1527+
1528+ regs->gr[20] = instruction_pointer(regs)+8;
1529+ regs->gr[21] = map;
1530+ regs->gr[22] = resolver;
1531+ regs->iaoq[0] = resolver | 3UL;
1532+ regs->iaoq[1] = regs->iaoq[0] + 4;
1533+ return 3;
1534+ }
1535+ }
1536+ } while (0);
1537+#endif
1538+
1539+#ifdef CONFIG_PAX_EMUTRAMP
1540+
1541+#ifndef CONFIG_PAX_EMUSIGRT
1542+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1543+ return 1;
1544+#endif
1545+
1546+ do { /* PaX: rt_sigreturn emulation */
1547+ unsigned int ldi1, ldi2, bel, nop;
1548+
1549+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1550+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1551+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1552+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1553+
1554+ if (err)
1555+ break;
1556+
1557+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1558+ ldi2 == 0x3414015AU &&
1559+ bel == 0xE4008200U &&
1560+ nop == 0x08000240U)
1561+ {
1562+ regs->gr[25] = (ldi1 & 2) >> 1;
1563+ regs->gr[20] = __NR_rt_sigreturn;
1564+ regs->gr[31] = regs->iaoq[1] + 16;
1565+ regs->sr[0] = regs->iasq[1];
1566+ regs->iaoq[0] = 0x100UL;
1567+ regs->iaoq[1] = regs->iaoq[0] + 4;
1568+ regs->iasq[0] = regs->sr[2];
1569+ regs->iasq[1] = regs->sr[2];
1570+ return 2;
1571+ }
1572+ } while (0);
1573+#endif
1574+
1575+ return 1;
1576+}
1577+
1578+void pax_report_insns(void *pc, void *sp)
1579+{
1580+ unsigned long i;
1581+
1582+ printk(KERN_ERR "PAX: bytes at PC: ");
1583+ for (i = 0; i < 5; i++) {
1584+ unsigned int c;
1585+ if (get_user(c, (unsigned int *)pc+i))
1586+ printk(KERN_CONT "???????? ");
1587+ else
1588+ printk(KERN_CONT "%08x ", c);
1589+ }
1590+ printk("\n");
1591+}
1592+#endif
1593+
1594 int fixup_exception(struct pt_regs *regs)
1595 {
1596 const struct exception_table_entry *fix;
1597@@ -192,8 +303,33 @@ good_area:
1598
1599 acc_type = parisc_acctyp(code,regs->iir);
1600
1601- if ((vma->vm_flags & acc_type) != acc_type)
1602+ if ((vma->vm_flags & acc_type) != acc_type) {
1603+
1604+#ifdef CONFIG_PAX_PAGEEXEC
1605+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
1606+ (address & ~3UL) == instruction_pointer(regs))
1607+ {
1608+ up_read(&mm->mmap_sem);
1609+ switch (pax_handle_fetch_fault(regs)) {
1610+
1611+#ifdef CONFIG_PAX_EMUPLT
1612+ case 3:
1613+ return;
1614+#endif
1615+
1616+#ifdef CONFIG_PAX_EMUTRAMP
1617+ case 2:
1618+ return;
1619+#endif
1620+
1621+ }
1622+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
1623+ do_group_exit(SIGKILL);
1624+ }
1625+#endif
1626+
1627 goto bad_area;
1628+ }
1629
1630 /*
1631 * If for any reason at all we couldn't handle the fault, make
1632diff -urNp linux-3.0.4/arch/powerpc/include/asm/elf.h linux-3.0.4/arch/powerpc/include/asm/elf.h
1633--- linux-3.0.4/arch/powerpc/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
1634+++ linux-3.0.4/arch/powerpc/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
1635@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
1636 the loader. We need to make sure that it is out of the way of the program
1637 that it will "exec", and that there is sufficient room for the brk. */
1638
1639-extern unsigned long randomize_et_dyn(unsigned long base);
1640-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
1641+#define ELF_ET_DYN_BASE (0x20000000)
1642+
1643+#ifdef CONFIG_PAX_ASLR
1644+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
1645+
1646+#ifdef __powerpc64__
1647+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
1648+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
1649+#else
1650+#define PAX_DELTA_MMAP_LEN 15
1651+#define PAX_DELTA_STACK_LEN 15
1652+#endif
1653+#endif
1654
1655 /*
1656 * Our registers are always unsigned longs, whether we're a 32 bit
1657@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(s
1658 (0x7ff >> (PAGE_SHIFT - 12)) : \
1659 (0x3ffff >> (PAGE_SHIFT - 12)))
1660
1661-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1662-#define arch_randomize_brk arch_randomize_brk
1663-
1664 #endif /* __KERNEL__ */
1665
1666 /*
1667diff -urNp linux-3.0.4/arch/powerpc/include/asm/kmap_types.h linux-3.0.4/arch/powerpc/include/asm/kmap_types.h
1668--- linux-3.0.4/arch/powerpc/include/asm/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
1669+++ linux-3.0.4/arch/powerpc/include/asm/kmap_types.h 2011-08-23 21:47:55.000000000 -0400
1670@@ -27,6 +27,7 @@ enum km_type {
1671 KM_PPC_SYNC_PAGE,
1672 KM_PPC_SYNC_ICACHE,
1673 KM_KDB,
1674+ KM_CLEARPAGE,
1675 KM_TYPE_NR
1676 };
1677
1678diff -urNp linux-3.0.4/arch/powerpc/include/asm/mman.h linux-3.0.4/arch/powerpc/include/asm/mman.h
1679--- linux-3.0.4/arch/powerpc/include/asm/mman.h 2011-07-21 22:17:23.000000000 -0400
1680+++ linux-3.0.4/arch/powerpc/include/asm/mman.h 2011-08-23 21:47:55.000000000 -0400
1681@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm
1682 }
1683 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
1684
1685-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
1686+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
1687 {
1688 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
1689 }
1690diff -urNp linux-3.0.4/arch/powerpc/include/asm/page_64.h linux-3.0.4/arch/powerpc/include/asm/page_64.h
1691--- linux-3.0.4/arch/powerpc/include/asm/page_64.h 2011-07-21 22:17:23.000000000 -0400
1692+++ linux-3.0.4/arch/powerpc/include/asm/page_64.h 2011-08-23 21:47:55.000000000 -0400
1693@@ -155,15 +155,18 @@ do { \
1694 * stack by default, so in the absence of a PT_GNU_STACK program header
1695 * we turn execute permission off.
1696 */
1697-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1698- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1699+#define VM_STACK_DEFAULT_FLAGS32 \
1700+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1701+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1702
1703 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1704 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1705
1706+#ifndef CONFIG_PAX_PAGEEXEC
1707 #define VM_STACK_DEFAULT_FLAGS \
1708 (is_32bit_task() ? \
1709 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
1710+#endif
1711
1712 #include <asm-generic/getorder.h>
1713
1714diff -urNp linux-3.0.4/arch/powerpc/include/asm/page.h linux-3.0.4/arch/powerpc/include/asm/page.h
1715--- linux-3.0.4/arch/powerpc/include/asm/page.h 2011-07-21 22:17:23.000000000 -0400
1716+++ linux-3.0.4/arch/powerpc/include/asm/page.h 2011-08-23 21:47:55.000000000 -0400
1717@@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
1718 * and needs to be executable. This means the whole heap ends
1719 * up being executable.
1720 */
1721-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1722- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1723+#define VM_DATA_DEFAULT_FLAGS32 \
1724+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1725+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1726
1727 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1728 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1729@@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
1730 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
1731 #endif
1732
1733+#define ktla_ktva(addr) (addr)
1734+#define ktva_ktla(addr) (addr)
1735+
1736 #ifndef __ASSEMBLY__
1737
1738 #undef STRICT_MM_TYPECHECKS
1739diff -urNp linux-3.0.4/arch/powerpc/include/asm/pgtable.h linux-3.0.4/arch/powerpc/include/asm/pgtable.h
1740--- linux-3.0.4/arch/powerpc/include/asm/pgtable.h 2011-07-21 22:17:23.000000000 -0400
1741+++ linux-3.0.4/arch/powerpc/include/asm/pgtable.h 2011-08-23 21:47:55.000000000 -0400
1742@@ -2,6 +2,7 @@
1743 #define _ASM_POWERPC_PGTABLE_H
1744 #ifdef __KERNEL__
1745
1746+#include <linux/const.h>
1747 #ifndef __ASSEMBLY__
1748 #include <asm/processor.h> /* For TASK_SIZE */
1749 #include <asm/mmu.h>
1750diff -urNp linux-3.0.4/arch/powerpc/include/asm/pte-hash32.h linux-3.0.4/arch/powerpc/include/asm/pte-hash32.h
1751--- linux-3.0.4/arch/powerpc/include/asm/pte-hash32.h 2011-07-21 22:17:23.000000000 -0400
1752+++ linux-3.0.4/arch/powerpc/include/asm/pte-hash32.h 2011-08-23 21:47:55.000000000 -0400
1753@@ -21,6 +21,7 @@
1754 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
1755 #define _PAGE_USER 0x004 /* usermode access allowed */
1756 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
1757+#define _PAGE_EXEC _PAGE_GUARDED
1758 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
1759 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
1760 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
1761diff -urNp linux-3.0.4/arch/powerpc/include/asm/reg.h linux-3.0.4/arch/powerpc/include/asm/reg.h
1762--- linux-3.0.4/arch/powerpc/include/asm/reg.h 2011-07-21 22:17:23.000000000 -0400
1763+++ linux-3.0.4/arch/powerpc/include/asm/reg.h 2011-08-23 21:47:55.000000000 -0400
1764@@ -209,6 +209,7 @@
1765 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
1766 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
1767 #define DSISR_NOHPTE 0x40000000 /* no translation found */
1768+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
1769 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
1770 #define DSISR_ISSTORE 0x02000000 /* access was a store */
1771 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
1772diff -urNp linux-3.0.4/arch/powerpc/include/asm/system.h linux-3.0.4/arch/powerpc/include/asm/system.h
1773--- linux-3.0.4/arch/powerpc/include/asm/system.h 2011-07-21 22:17:23.000000000 -0400
1774+++ linux-3.0.4/arch/powerpc/include/asm/system.h 2011-08-23 21:47:55.000000000 -0400
1775@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsi
1776 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
1777 #endif
1778
1779-extern unsigned long arch_align_stack(unsigned long sp);
1780+#define arch_align_stack(x) ((x) & ~0xfUL)
1781
1782 /* Used in very early kernel initialization. */
1783 extern unsigned long reloc_offset(void);
1784diff -urNp linux-3.0.4/arch/powerpc/include/asm/uaccess.h linux-3.0.4/arch/powerpc/include/asm/uaccess.h
1785--- linux-3.0.4/arch/powerpc/include/asm/uaccess.h 2011-07-21 22:17:23.000000000 -0400
1786+++ linux-3.0.4/arch/powerpc/include/asm/uaccess.h 2011-08-23 21:47:55.000000000 -0400
1787@@ -13,6 +13,8 @@
1788 #define VERIFY_READ 0
1789 #define VERIFY_WRITE 1
1790
1791+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1792+
1793 /*
1794 * The fs value determines whether argument validity checking should be
1795 * performed or not. If get_fs() == USER_DS, checking is performed, with
1796@@ -327,52 +329,6 @@ do { \
1797 extern unsigned long __copy_tofrom_user(void __user *to,
1798 const void __user *from, unsigned long size);
1799
1800-#ifndef __powerpc64__
1801-
1802-static inline unsigned long copy_from_user(void *to,
1803- const void __user *from, unsigned long n)
1804-{
1805- unsigned long over;
1806-
1807- if (access_ok(VERIFY_READ, from, n))
1808- return __copy_tofrom_user((__force void __user *)to, from, n);
1809- if ((unsigned long)from < TASK_SIZE) {
1810- over = (unsigned long)from + n - TASK_SIZE;
1811- return __copy_tofrom_user((__force void __user *)to, from,
1812- n - over) + over;
1813- }
1814- return n;
1815-}
1816-
1817-static inline unsigned long copy_to_user(void __user *to,
1818- const void *from, unsigned long n)
1819-{
1820- unsigned long over;
1821-
1822- if (access_ok(VERIFY_WRITE, to, n))
1823- return __copy_tofrom_user(to, (__force void __user *)from, n);
1824- if ((unsigned long)to < TASK_SIZE) {
1825- over = (unsigned long)to + n - TASK_SIZE;
1826- return __copy_tofrom_user(to, (__force void __user *)from,
1827- n - over) + over;
1828- }
1829- return n;
1830-}
1831-
1832-#else /* __powerpc64__ */
1833-
1834-#define __copy_in_user(to, from, size) \
1835- __copy_tofrom_user((to), (from), (size))
1836-
1837-extern unsigned long copy_from_user(void *to, const void __user *from,
1838- unsigned long n);
1839-extern unsigned long copy_to_user(void __user *to, const void *from,
1840- unsigned long n);
1841-extern unsigned long copy_in_user(void __user *to, const void __user *from,
1842- unsigned long n);
1843-
1844-#endif /* __powerpc64__ */
1845-
1846 static inline unsigned long __copy_from_user_inatomic(void *to,
1847 const void __user *from, unsigned long n)
1848 {
1849@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
1850 if (ret == 0)
1851 return 0;
1852 }
1853+
1854+ if (!__builtin_constant_p(n))
1855+ check_object_size(to, n, false);
1856+
1857 return __copy_tofrom_user((__force void __user *)to, from, n);
1858 }
1859
1860@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
1861 if (ret == 0)
1862 return 0;
1863 }
1864+
1865+ if (!__builtin_constant_p(n))
1866+ check_object_size(from, n, true);
1867+
1868 return __copy_tofrom_user(to, (__force const void __user *)from, n);
1869 }
1870
1871@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
1872 return __copy_to_user_inatomic(to, from, size);
1873 }
1874
1875+#ifndef __powerpc64__
1876+
1877+static inline unsigned long __must_check copy_from_user(void *to,
1878+ const void __user *from, unsigned long n)
1879+{
1880+ unsigned long over;
1881+
1882+ if ((long)n < 0)
1883+ return n;
1884+
1885+ if (access_ok(VERIFY_READ, from, n)) {
1886+ if (!__builtin_constant_p(n))
1887+ check_object_size(to, n, false);
1888+ return __copy_tofrom_user((__force void __user *)to, from, n);
1889+ }
1890+ if ((unsigned long)from < TASK_SIZE) {
1891+ over = (unsigned long)from + n - TASK_SIZE;
1892+ if (!__builtin_constant_p(n - over))
1893+ check_object_size(to, n - over, false);
1894+ return __copy_tofrom_user((__force void __user *)to, from,
1895+ n - over) + over;
1896+ }
1897+ return n;
1898+}
1899+
1900+static inline unsigned long __must_check copy_to_user(void __user *to,
1901+ const void *from, unsigned long n)
1902+{
1903+ unsigned long over;
1904+
1905+ if ((long)n < 0)
1906+ return n;
1907+
1908+ if (access_ok(VERIFY_WRITE, to, n)) {
1909+ if (!__builtin_constant_p(n))
1910+ check_object_size(from, n, true);
1911+ return __copy_tofrom_user(to, (__force void __user *)from, n);
1912+ }
1913+ if ((unsigned long)to < TASK_SIZE) {
1914+ over = (unsigned long)to + n - TASK_SIZE;
1915+ if (!__builtin_constant_p(n))
1916+ check_object_size(from, n - over, true);
1917+ return __copy_tofrom_user(to, (__force void __user *)from,
1918+ n - over) + over;
1919+ }
1920+ return n;
1921+}
1922+
1923+#else /* __powerpc64__ */
1924+
1925+#define __copy_in_user(to, from, size) \
1926+ __copy_tofrom_user((to), (from), (size))
1927+
1928+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1929+{
1930+ if ((long)n < 0 || n > INT_MAX)
1931+ return n;
1932+
1933+ if (!__builtin_constant_p(n))
1934+ check_object_size(to, n, false);
1935+
1936+ if (likely(access_ok(VERIFY_READ, from, n)))
1937+ n = __copy_from_user(to, from, n);
1938+ else
1939+ memset(to, 0, n);
1940+ return n;
1941+}
1942+
1943+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1944+{
1945+ if ((long)n < 0 || n > INT_MAX)
1946+ return n;
1947+
1948+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
1949+ if (!__builtin_constant_p(n))
1950+ check_object_size(from, n, true);
1951+ n = __copy_to_user(to, from, n);
1952+ }
1953+ return n;
1954+}
1955+
1956+extern unsigned long copy_in_user(void __user *to, const void __user *from,
1957+ unsigned long n);
1958+
1959+#endif /* __powerpc64__ */
1960+
1961 extern unsigned long __clear_user(void __user *addr, unsigned long size);
1962
1963 static inline unsigned long clear_user(void __user *addr, unsigned long size)
1964diff -urNp linux-3.0.4/arch/powerpc/kernel/exceptions-64e.S linux-3.0.4/arch/powerpc/kernel/exceptions-64e.S
1965--- linux-3.0.4/arch/powerpc/kernel/exceptions-64e.S 2011-07-21 22:17:23.000000000 -0400
1966+++ linux-3.0.4/arch/powerpc/kernel/exceptions-64e.S 2011-08-23 21:47:55.000000000 -0400
1967@@ -567,6 +567,7 @@ storage_fault_common:
1968 std r14,_DAR(r1)
1969 std r15,_DSISR(r1)
1970 addi r3,r1,STACK_FRAME_OVERHEAD
1971+ bl .save_nvgprs
1972 mr r4,r14
1973 mr r5,r15
1974 ld r14,PACA_EXGEN+EX_R14(r13)
1975@@ -576,8 +577,7 @@ storage_fault_common:
1976 cmpdi r3,0
1977 bne- 1f
1978 b .ret_from_except_lite
1979-1: bl .save_nvgprs
1980- mr r5,r3
1981+1: mr r5,r3
1982 addi r3,r1,STACK_FRAME_OVERHEAD
1983 ld r4,_DAR(r1)
1984 bl .bad_page_fault
1985diff -urNp linux-3.0.4/arch/powerpc/kernel/exceptions-64s.S linux-3.0.4/arch/powerpc/kernel/exceptions-64s.S
1986--- linux-3.0.4/arch/powerpc/kernel/exceptions-64s.S 2011-07-21 22:17:23.000000000 -0400
1987+++ linux-3.0.4/arch/powerpc/kernel/exceptions-64s.S 2011-08-23 21:47:55.000000000 -0400
1988@@ -956,10 +956,10 @@ handle_page_fault:
1989 11: ld r4,_DAR(r1)
1990 ld r5,_DSISR(r1)
1991 addi r3,r1,STACK_FRAME_OVERHEAD
1992+ bl .save_nvgprs
1993 bl .do_page_fault
1994 cmpdi r3,0
1995 beq+ 13f
1996- bl .save_nvgprs
1997 mr r5,r3
1998 addi r3,r1,STACK_FRAME_OVERHEAD
1999 lwz r4,_DAR(r1)
2000diff -urNp linux-3.0.4/arch/powerpc/kernel/module_32.c linux-3.0.4/arch/powerpc/kernel/module_32.c
2001--- linux-3.0.4/arch/powerpc/kernel/module_32.c 2011-07-21 22:17:23.000000000 -0400
2002+++ linux-3.0.4/arch/powerpc/kernel/module_32.c 2011-08-23 21:47:55.000000000 -0400
2003@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
2004 me->arch.core_plt_section = i;
2005 }
2006 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2007- printk("Module doesn't contain .plt or .init.plt sections.\n");
2008+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2009 return -ENOEXEC;
2010 }
2011
2012@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
2013
2014 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2015 /* Init, or core PLT? */
2016- if (location >= mod->module_core
2017- && location < mod->module_core + mod->core_size)
2018+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2019+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2020 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2021- else
2022+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2023+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2024 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2025+ else {
2026+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2027+ return ~0UL;
2028+ }
2029
2030 /* Find this entry, or if that fails, the next avail. entry */
2031 while (entry->jump[0]) {
2032diff -urNp linux-3.0.4/arch/powerpc/kernel/module.c linux-3.0.4/arch/powerpc/kernel/module.c
2033--- linux-3.0.4/arch/powerpc/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
2034+++ linux-3.0.4/arch/powerpc/kernel/module.c 2011-08-23 21:47:55.000000000 -0400
2035@@ -31,11 +31,24 @@
2036
2037 LIST_HEAD(module_bug_list);
2038
2039+#ifdef CONFIG_PAX_KERNEXEC
2040 void *module_alloc(unsigned long size)
2041 {
2042 if (size == 0)
2043 return NULL;
2044
2045+ return vmalloc(size);
2046+}
2047+
2048+void *module_alloc_exec(unsigned long size)
2049+#else
2050+void *module_alloc(unsigned long size)
2051+#endif
2052+
2053+{
2054+ if (size == 0)
2055+ return NULL;
2056+
2057 return vmalloc_exec(size);
2058 }
2059
2060@@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
2061 vfree(module_region);
2062 }
2063
2064+#ifdef CONFIG_PAX_KERNEXEC
2065+void module_free_exec(struct module *mod, void *module_region)
2066+{
2067+ module_free(mod, module_region);
2068+}
2069+#endif
2070+
2071 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
2072 const Elf_Shdr *sechdrs,
2073 const char *name)
2074diff -urNp linux-3.0.4/arch/powerpc/kernel/process.c linux-3.0.4/arch/powerpc/kernel/process.c
2075--- linux-3.0.4/arch/powerpc/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
2076+++ linux-3.0.4/arch/powerpc/kernel/process.c 2011-08-23 21:48:14.000000000 -0400
2077@@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
2078 * Lookup NIP late so we have the best change of getting the
2079 * above info out without failing
2080 */
2081- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2082- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2083+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2084+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2085 #endif
2086 show_stack(current, (unsigned long *) regs->gpr[1]);
2087 if (!user_mode(regs))
2088@@ -1183,10 +1183,10 @@ void show_stack(struct task_struct *tsk,
2089 newsp = stack[0];
2090 ip = stack[STACK_FRAME_LR_SAVE];
2091 if (!firstframe || ip != lr) {
2092- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2093+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2094 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2095 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2096- printk(" (%pS)",
2097+ printk(" (%pA)",
2098 (void *)current->ret_stack[curr_frame].ret);
2099 curr_frame--;
2100 }
2101@@ -1206,7 +1206,7 @@ void show_stack(struct task_struct *tsk,
2102 struct pt_regs *regs = (struct pt_regs *)
2103 (sp + STACK_FRAME_OVERHEAD);
2104 lr = regs->link;
2105- printk("--- Exception: %lx at %pS\n LR = %pS\n",
2106+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
2107 regs->trap, (void *)regs->nip, (void *)lr);
2108 firstframe = 1;
2109 }
2110@@ -1281,58 +1281,3 @@ void thread_info_cache_init(void)
2111 }
2112
2113 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2114-
2115-unsigned long arch_align_stack(unsigned long sp)
2116-{
2117- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2118- sp -= get_random_int() & ~PAGE_MASK;
2119- return sp & ~0xf;
2120-}
2121-
2122-static inline unsigned long brk_rnd(void)
2123-{
2124- unsigned long rnd = 0;
2125-
2126- /* 8MB for 32bit, 1GB for 64bit */
2127- if (is_32bit_task())
2128- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2129- else
2130- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2131-
2132- return rnd << PAGE_SHIFT;
2133-}
2134-
2135-unsigned long arch_randomize_brk(struct mm_struct *mm)
2136-{
2137- unsigned long base = mm->brk;
2138- unsigned long ret;
2139-
2140-#ifdef CONFIG_PPC_STD_MMU_64
2141- /*
2142- * If we are using 1TB segments and we are allowed to randomise
2143- * the heap, we can put it above 1TB so it is backed by a 1TB
2144- * segment. Otherwise the heap will be in the bottom 1TB
2145- * which always uses 256MB segments and this may result in a
2146- * performance penalty.
2147- */
2148- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2149- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2150-#endif
2151-
2152- ret = PAGE_ALIGN(base + brk_rnd());
2153-
2154- if (ret < mm->brk)
2155- return mm->brk;
2156-
2157- return ret;
2158-}
2159-
2160-unsigned long randomize_et_dyn(unsigned long base)
2161-{
2162- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2163-
2164- if (ret < base)
2165- return base;
2166-
2167- return ret;
2168-}
2169diff -urNp linux-3.0.4/arch/powerpc/kernel/signal_32.c linux-3.0.4/arch/powerpc/kernel/signal_32.c
2170--- linux-3.0.4/arch/powerpc/kernel/signal_32.c 2011-07-21 22:17:23.000000000 -0400
2171+++ linux-3.0.4/arch/powerpc/kernel/signal_32.c 2011-08-23 21:47:55.000000000 -0400
2172@@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig
2173 /* Save user registers on the stack */
2174 frame = &rt_sf->uc.uc_mcontext;
2175 addr = frame;
2176- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2177+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2178 if (save_user_regs(regs, frame, 0, 1))
2179 goto badframe;
2180 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2181diff -urNp linux-3.0.4/arch/powerpc/kernel/signal_64.c linux-3.0.4/arch/powerpc/kernel/signal_64.c
2182--- linux-3.0.4/arch/powerpc/kernel/signal_64.c 2011-07-21 22:17:23.000000000 -0400
2183+++ linux-3.0.4/arch/powerpc/kernel/signal_64.c 2011-08-23 21:47:55.000000000 -0400
2184@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct
2185 current->thread.fpscr.val = 0;
2186
2187 /* Set up to return from userspace. */
2188- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2189+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2190 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2191 } else {
2192 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2193diff -urNp linux-3.0.4/arch/powerpc/kernel/traps.c linux-3.0.4/arch/powerpc/kernel/traps.c
2194--- linux-3.0.4/arch/powerpc/kernel/traps.c 2011-07-21 22:17:23.000000000 -0400
2195+++ linux-3.0.4/arch/powerpc/kernel/traps.c 2011-08-23 21:48:14.000000000 -0400
2196@@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
2197 static inline void pmac_backlight_unblank(void) { }
2198 #endif
2199
2200+extern void gr_handle_kernel_exploit(void);
2201+
2202 int die(const char *str, struct pt_regs *regs, long err)
2203 {
2204 static struct {
2205@@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs
2206 if (panic_on_oops)
2207 panic("Fatal exception");
2208
2209+ gr_handle_kernel_exploit();
2210+
2211 oops_exit();
2212 do_exit(err);
2213
2214diff -urNp linux-3.0.4/arch/powerpc/kernel/vdso.c linux-3.0.4/arch/powerpc/kernel/vdso.c
2215--- linux-3.0.4/arch/powerpc/kernel/vdso.c 2011-07-21 22:17:23.000000000 -0400
2216+++ linux-3.0.4/arch/powerpc/kernel/vdso.c 2011-08-23 21:47:55.000000000 -0400
2217@@ -36,6 +36,7 @@
2218 #include <asm/firmware.h>
2219 #include <asm/vdso.h>
2220 #include <asm/vdso_datapage.h>
2221+#include <asm/mman.h>
2222
2223 #include "setup.h"
2224
2225@@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
2226 vdso_base = VDSO32_MBASE;
2227 #endif
2228
2229- current->mm->context.vdso_base = 0;
2230+ current->mm->context.vdso_base = ~0UL;
2231
2232 /* vDSO has a problem and was disabled, just don't "enable" it for the
2233 * process
2234@@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
2235 vdso_base = get_unmapped_area(NULL, vdso_base,
2236 (vdso_pages << PAGE_SHIFT) +
2237 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2238- 0, 0);
2239+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
2240 if (IS_ERR_VALUE(vdso_base)) {
2241 rc = vdso_base;
2242 goto fail_mmapsem;
2243diff -urNp linux-3.0.4/arch/powerpc/lib/usercopy_64.c linux-3.0.4/arch/powerpc/lib/usercopy_64.c
2244--- linux-3.0.4/arch/powerpc/lib/usercopy_64.c 2011-07-21 22:17:23.000000000 -0400
2245+++ linux-3.0.4/arch/powerpc/lib/usercopy_64.c 2011-08-23 21:47:55.000000000 -0400
2246@@ -9,22 +9,6 @@
2247 #include <linux/module.h>
2248 #include <asm/uaccess.h>
2249
2250-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2251-{
2252- if (likely(access_ok(VERIFY_READ, from, n)))
2253- n = __copy_from_user(to, from, n);
2254- else
2255- memset(to, 0, n);
2256- return n;
2257-}
2258-
2259-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2260-{
2261- if (likely(access_ok(VERIFY_WRITE, to, n)))
2262- n = __copy_to_user(to, from, n);
2263- return n;
2264-}
2265-
2266 unsigned long copy_in_user(void __user *to, const void __user *from,
2267 unsigned long n)
2268 {
2269@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
2270 return n;
2271 }
2272
2273-EXPORT_SYMBOL(copy_from_user);
2274-EXPORT_SYMBOL(copy_to_user);
2275 EXPORT_SYMBOL(copy_in_user);
2276
2277diff -urNp linux-3.0.4/arch/powerpc/mm/fault.c linux-3.0.4/arch/powerpc/mm/fault.c
2278--- linux-3.0.4/arch/powerpc/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
2279+++ linux-3.0.4/arch/powerpc/mm/fault.c 2011-08-23 21:47:55.000000000 -0400
2280@@ -32,6 +32,10 @@
2281 #include <linux/perf_event.h>
2282 #include <linux/magic.h>
2283 #include <linux/ratelimit.h>
2284+#include <linux/slab.h>
2285+#include <linux/pagemap.h>
2286+#include <linux/compiler.h>
2287+#include <linux/unistd.h>
2288
2289 #include <asm/firmware.h>
2290 #include <asm/page.h>
2291@@ -43,6 +47,7 @@
2292 #include <asm/tlbflush.h>
2293 #include <asm/siginfo.h>
2294 #include <mm/mmu_decl.h>
2295+#include <asm/ptrace.h>
2296
2297 #ifdef CONFIG_KPROBES
2298 static inline int notify_page_fault(struct pt_regs *regs)
2299@@ -66,6 +71,33 @@ static inline int notify_page_fault(stru
2300 }
2301 #endif
2302
2303+#ifdef CONFIG_PAX_PAGEEXEC
2304+/*
2305+ * PaX: decide what to do with offenders (regs->nip = fault address)
2306+ *
2307+ * returns 1 when task should be killed
2308+ */
2309+static int pax_handle_fetch_fault(struct pt_regs *regs)
2310+{
2311+ return 1;
2312+}
2313+
2314+void pax_report_insns(void *pc, void *sp)
2315+{
2316+ unsigned long i;
2317+
2318+ printk(KERN_ERR "PAX: bytes at PC: ");
2319+ for (i = 0; i < 5; i++) {
2320+ unsigned int c;
2321+ if (get_user(c, (unsigned int __user *)pc+i))
2322+ printk(KERN_CONT "???????? ");
2323+ else
2324+ printk(KERN_CONT "%08x ", c);
2325+ }
2326+ printk("\n");
2327+}
2328+#endif
2329+
2330 /*
2331 * Check whether the instruction at regs->nip is a store using
2332 * an update addressing form which will update r1.
2333@@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_re
2334 * indicate errors in DSISR but can validly be set in SRR1.
2335 */
2336 if (trap == 0x400)
2337- error_code &= 0x48200000;
2338+ error_code &= 0x58200000;
2339 else
2340 is_write = error_code & DSISR_ISSTORE;
2341 #else
2342@@ -259,7 +291,7 @@ good_area:
2343 * "undefined". Of those that can be set, this is the only
2344 * one which seems bad.
2345 */
2346- if (error_code & 0x10000000)
2347+ if (error_code & DSISR_GUARDED)
2348 /* Guarded storage error. */
2349 goto bad_area;
2350 #endif /* CONFIG_8xx */
2351@@ -274,7 +306,7 @@ good_area:
2352 * processors use the same I/D cache coherency mechanism
2353 * as embedded.
2354 */
2355- if (error_code & DSISR_PROTFAULT)
2356+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2357 goto bad_area;
2358 #endif /* CONFIG_PPC_STD_MMU */
2359
2360@@ -343,6 +375,23 @@ bad_area:
2361 bad_area_nosemaphore:
2362 /* User mode accesses cause a SIGSEGV */
2363 if (user_mode(regs)) {
2364+
2365+#ifdef CONFIG_PAX_PAGEEXEC
2366+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2367+#ifdef CONFIG_PPC_STD_MMU
2368+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2369+#else
2370+ if (is_exec && regs->nip == address) {
2371+#endif
2372+ switch (pax_handle_fetch_fault(regs)) {
2373+ }
2374+
2375+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2376+ do_group_exit(SIGKILL);
2377+ }
2378+ }
2379+#endif
2380+
2381 _exception(SIGSEGV, regs, code, address);
2382 return 0;
2383 }
2384diff -urNp linux-3.0.4/arch/powerpc/mm/mmap_64.c linux-3.0.4/arch/powerpc/mm/mmap_64.c
2385--- linux-3.0.4/arch/powerpc/mm/mmap_64.c 2011-07-21 22:17:23.000000000 -0400
2386+++ linux-3.0.4/arch/powerpc/mm/mmap_64.c 2011-08-23 21:47:55.000000000 -0400
2387@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
2388 */
2389 if (mmap_is_legacy()) {
2390 mm->mmap_base = TASK_UNMAPPED_BASE;
2391+
2392+#ifdef CONFIG_PAX_RANDMMAP
2393+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2394+ mm->mmap_base += mm->delta_mmap;
2395+#endif
2396+
2397 mm->get_unmapped_area = arch_get_unmapped_area;
2398 mm->unmap_area = arch_unmap_area;
2399 } else {
2400 mm->mmap_base = mmap_base();
2401+
2402+#ifdef CONFIG_PAX_RANDMMAP
2403+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2404+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2405+#endif
2406+
2407 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2408 mm->unmap_area = arch_unmap_area_topdown;
2409 }
2410diff -urNp linux-3.0.4/arch/powerpc/mm/slice.c linux-3.0.4/arch/powerpc/mm/slice.c
2411--- linux-3.0.4/arch/powerpc/mm/slice.c 2011-07-21 22:17:23.000000000 -0400
2412+++ linux-3.0.4/arch/powerpc/mm/slice.c 2011-08-23 21:47:55.000000000 -0400
2413@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
2414 if ((mm->task_size - len) < addr)
2415 return 0;
2416 vma = find_vma(mm, addr);
2417- return (!vma || (addr + len) <= vma->vm_start);
2418+ return check_heap_stack_gap(vma, addr, len);
2419 }
2420
2421 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
2422@@ -256,7 +256,7 @@ full_search:
2423 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
2424 continue;
2425 }
2426- if (!vma || addr + len <= vma->vm_start) {
2427+ if (check_heap_stack_gap(vma, addr, len)) {
2428 /*
2429 * Remember the place where we stopped the search:
2430 */
2431@@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
2432 }
2433 }
2434
2435- addr = mm->mmap_base;
2436- while (addr > len) {
2437+ if (mm->mmap_base < len)
2438+ addr = -ENOMEM;
2439+ else
2440+ addr = mm->mmap_base - len;
2441+
2442+ while (!IS_ERR_VALUE(addr)) {
2443 /* Go down by chunk size */
2444- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
2445+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
2446
2447 /* Check for hit with different page size */
2448 mask = slice_range_to_mask(addr, len);
2449@@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
2450 * return with success:
2451 */
2452 vma = find_vma(mm, addr);
2453- if (!vma || (addr + len) <= vma->vm_start) {
2454+ if (check_heap_stack_gap(vma, addr, len)) {
2455 /* remember the address as a hint for next time */
2456 if (use_cache)
2457 mm->free_area_cache = addr;
2458@@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
2459 mm->cached_hole_size = vma->vm_start - addr;
2460
2461 /* try just below the current vma->vm_start */
2462- addr = vma->vm_start;
2463+ addr = skip_heap_stack_gap(vma, len);
2464 }
2465
2466 /*
2467@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
2468 if (fixed && addr > (mm->task_size - len))
2469 return -EINVAL;
2470
2471+#ifdef CONFIG_PAX_RANDMMAP
2472+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
2473+ addr = 0;
2474+#endif
2475+
2476 /* If hint, make sure it matches our alignment restrictions */
2477 if (!fixed && addr) {
2478 addr = _ALIGN_UP(addr, 1ul << pshift);
2479diff -urNp linux-3.0.4/arch/s390/include/asm/elf.h linux-3.0.4/arch/s390/include/asm/elf.h
2480--- linux-3.0.4/arch/s390/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
2481+++ linux-3.0.4/arch/s390/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
2482@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
2483 the loader. We need to make sure that it is out of the way of the program
2484 that it will "exec", and that there is sufficient room for the brk. */
2485
2486-extern unsigned long randomize_et_dyn(unsigned long base);
2487-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
2488+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
2489+
2490+#ifdef CONFIG_PAX_ASLR
2491+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
2492+
2493+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2494+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2495+#endif
2496
2497 /* This yields a mask that user programs can use to figure out what
2498 instruction set this CPU supports. */
2499@@ -210,7 +216,4 @@ struct linux_binprm;
2500 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2501 int arch_setup_additional_pages(struct linux_binprm *, int);
2502
2503-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2504-#define arch_randomize_brk arch_randomize_brk
2505-
2506 #endif
2507diff -urNp linux-3.0.4/arch/s390/include/asm/system.h linux-3.0.4/arch/s390/include/asm/system.h
2508--- linux-3.0.4/arch/s390/include/asm/system.h 2011-07-21 22:17:23.000000000 -0400
2509+++ linux-3.0.4/arch/s390/include/asm/system.h 2011-08-23 21:47:55.000000000 -0400
2510@@ -255,7 +255,7 @@ extern void (*_machine_restart)(char *co
2511 extern void (*_machine_halt)(void);
2512 extern void (*_machine_power_off)(void);
2513
2514-extern unsigned long arch_align_stack(unsigned long sp);
2515+#define arch_align_stack(x) ((x) & ~0xfUL)
2516
2517 static inline int tprot(unsigned long addr)
2518 {
2519diff -urNp linux-3.0.4/arch/s390/include/asm/uaccess.h linux-3.0.4/arch/s390/include/asm/uaccess.h
2520--- linux-3.0.4/arch/s390/include/asm/uaccess.h 2011-07-21 22:17:23.000000000 -0400
2521+++ linux-3.0.4/arch/s390/include/asm/uaccess.h 2011-08-23 21:47:55.000000000 -0400
2522@@ -235,6 +235,10 @@ static inline unsigned long __must_check
2523 copy_to_user(void __user *to, const void *from, unsigned long n)
2524 {
2525 might_fault();
2526+
2527+ if ((long)n < 0)
2528+ return n;
2529+
2530 if (access_ok(VERIFY_WRITE, to, n))
2531 n = __copy_to_user(to, from, n);
2532 return n;
2533@@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void
2534 static inline unsigned long __must_check
2535 __copy_from_user(void *to, const void __user *from, unsigned long n)
2536 {
2537+ if ((long)n < 0)
2538+ return n;
2539+
2540 if (__builtin_constant_p(n) && (n <= 256))
2541 return uaccess.copy_from_user_small(n, from, to);
2542 else
2543@@ -294,6 +301,10 @@ copy_from_user(void *to, const void __us
2544 unsigned int sz = __compiletime_object_size(to);
2545
2546 might_fault();
2547+
2548+ if ((long)n < 0)
2549+ return n;
2550+
2551 if (unlikely(sz != -1 && sz < n)) {
2552 copy_from_user_overflow();
2553 return n;
2554diff -urNp linux-3.0.4/arch/s390/kernel/module.c linux-3.0.4/arch/s390/kernel/module.c
2555--- linux-3.0.4/arch/s390/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
2556+++ linux-3.0.4/arch/s390/kernel/module.c 2011-08-23 21:47:55.000000000 -0400
2557@@ -168,11 +168,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
2558
2559 /* Increase core size by size of got & plt and set start
2560 offsets for got and plt. */
2561- me->core_size = ALIGN(me->core_size, 4);
2562- me->arch.got_offset = me->core_size;
2563- me->core_size += me->arch.got_size;
2564- me->arch.plt_offset = me->core_size;
2565- me->core_size += me->arch.plt_size;
2566+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
2567+ me->arch.got_offset = me->core_size_rw;
2568+ me->core_size_rw += me->arch.got_size;
2569+ me->arch.plt_offset = me->core_size_rx;
2570+ me->core_size_rx += me->arch.plt_size;
2571 return 0;
2572 }
2573
2574@@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2575 if (info->got_initialized == 0) {
2576 Elf_Addr *gotent;
2577
2578- gotent = me->module_core + me->arch.got_offset +
2579+ gotent = me->module_core_rw + me->arch.got_offset +
2580 info->got_offset;
2581 *gotent = val;
2582 info->got_initialized = 1;
2583@@ -282,7 +282,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2584 else if (r_type == R_390_GOTENT ||
2585 r_type == R_390_GOTPLTENT)
2586 *(unsigned int *) loc =
2587- (val + (Elf_Addr) me->module_core - loc) >> 1;
2588+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
2589 else if (r_type == R_390_GOT64 ||
2590 r_type == R_390_GOTPLT64)
2591 *(unsigned long *) loc = val;
2592@@ -296,7 +296,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2593 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
2594 if (info->plt_initialized == 0) {
2595 unsigned int *ip;
2596- ip = me->module_core + me->arch.plt_offset +
2597+ ip = me->module_core_rx + me->arch.plt_offset +
2598 info->plt_offset;
2599 #ifndef CONFIG_64BIT
2600 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
2601@@ -321,7 +321,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2602 val - loc + 0xffffUL < 0x1ffffeUL) ||
2603 (r_type == R_390_PLT32DBL &&
2604 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
2605- val = (Elf_Addr) me->module_core +
2606+ val = (Elf_Addr) me->module_core_rx +
2607 me->arch.plt_offset +
2608 info->plt_offset;
2609 val += rela->r_addend - loc;
2610@@ -343,7 +343,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2611 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
2612 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
2613 val = val + rela->r_addend -
2614- ((Elf_Addr) me->module_core + me->arch.got_offset);
2615+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
2616 if (r_type == R_390_GOTOFF16)
2617 *(unsigned short *) loc = val;
2618 else if (r_type == R_390_GOTOFF32)
2619@@ -353,7 +353,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
2620 break;
2621 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
2622 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
2623- val = (Elf_Addr) me->module_core + me->arch.got_offset +
2624+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
2625 rela->r_addend - loc;
2626 if (r_type == R_390_GOTPC)
2627 *(unsigned int *) loc = val;
2628diff -urNp linux-3.0.4/arch/s390/kernel/process.c linux-3.0.4/arch/s390/kernel/process.c
2629--- linux-3.0.4/arch/s390/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
2630+++ linux-3.0.4/arch/s390/kernel/process.c 2011-08-23 21:47:55.000000000 -0400
2631@@ -319,39 +319,3 @@ unsigned long get_wchan(struct task_stru
2632 }
2633 return 0;
2634 }
2635-
2636-unsigned long arch_align_stack(unsigned long sp)
2637-{
2638- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2639- sp -= get_random_int() & ~PAGE_MASK;
2640- return sp & ~0xf;
2641-}
2642-
2643-static inline unsigned long brk_rnd(void)
2644-{
2645- /* 8MB for 32bit, 1GB for 64bit */
2646- if (is_32bit_task())
2647- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
2648- else
2649- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
2650-}
2651-
2652-unsigned long arch_randomize_brk(struct mm_struct *mm)
2653-{
2654- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
2655-
2656- if (ret < mm->brk)
2657- return mm->brk;
2658- return ret;
2659-}
2660-
2661-unsigned long randomize_et_dyn(unsigned long base)
2662-{
2663- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2664-
2665- if (!(current->flags & PF_RANDOMIZE))
2666- return base;
2667- if (ret < base)
2668- return base;
2669- return ret;
2670-}
2671diff -urNp linux-3.0.4/arch/s390/kernel/setup.c linux-3.0.4/arch/s390/kernel/setup.c
2672--- linux-3.0.4/arch/s390/kernel/setup.c 2011-07-21 22:17:23.000000000 -0400
2673+++ linux-3.0.4/arch/s390/kernel/setup.c 2011-08-23 21:47:55.000000000 -0400
2674@@ -271,7 +271,7 @@ static int __init early_parse_mem(char *
2675 }
2676 early_param("mem", early_parse_mem);
2677
2678-unsigned int user_mode = HOME_SPACE_MODE;
2679+unsigned int user_mode = SECONDARY_SPACE_MODE;
2680 EXPORT_SYMBOL_GPL(user_mode);
2681
2682 static int set_amode_and_uaccess(unsigned long user_amode,
2683diff -urNp linux-3.0.4/arch/s390/mm/mmap.c linux-3.0.4/arch/s390/mm/mmap.c
2684--- linux-3.0.4/arch/s390/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
2685+++ linux-3.0.4/arch/s390/mm/mmap.c 2011-08-23 21:47:55.000000000 -0400
2686@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_str
2687 */
2688 if (mmap_is_legacy()) {
2689 mm->mmap_base = TASK_UNMAPPED_BASE;
2690+
2691+#ifdef CONFIG_PAX_RANDMMAP
2692+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2693+ mm->mmap_base += mm->delta_mmap;
2694+#endif
2695+
2696 mm->get_unmapped_area = arch_get_unmapped_area;
2697 mm->unmap_area = arch_unmap_area;
2698 } else {
2699 mm->mmap_base = mmap_base();
2700+
2701+#ifdef CONFIG_PAX_RANDMMAP
2702+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2703+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2704+#endif
2705+
2706 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2707 mm->unmap_area = arch_unmap_area_topdown;
2708 }
2709@@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_str
2710 */
2711 if (mmap_is_legacy()) {
2712 mm->mmap_base = TASK_UNMAPPED_BASE;
2713+
2714+#ifdef CONFIG_PAX_RANDMMAP
2715+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2716+ mm->mmap_base += mm->delta_mmap;
2717+#endif
2718+
2719 mm->get_unmapped_area = s390_get_unmapped_area;
2720 mm->unmap_area = arch_unmap_area;
2721 } else {
2722 mm->mmap_base = mmap_base();
2723+
2724+#ifdef CONFIG_PAX_RANDMMAP
2725+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2726+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2727+#endif
2728+
2729 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
2730 mm->unmap_area = arch_unmap_area_topdown;
2731 }
2732diff -urNp linux-3.0.4/arch/score/include/asm/system.h linux-3.0.4/arch/score/include/asm/system.h
2733--- linux-3.0.4/arch/score/include/asm/system.h 2011-07-21 22:17:23.000000000 -0400
2734+++ linux-3.0.4/arch/score/include/asm/system.h 2011-08-23 21:47:55.000000000 -0400
2735@@ -17,7 +17,7 @@ do { \
2736 #define finish_arch_switch(prev) do {} while (0)
2737
2738 typedef void (*vi_handler_t)(void);
2739-extern unsigned long arch_align_stack(unsigned long sp);
2740+#define arch_align_stack(x) (x)
2741
2742 #define mb() barrier()
2743 #define rmb() barrier()
2744diff -urNp linux-3.0.4/arch/score/kernel/process.c linux-3.0.4/arch/score/kernel/process.c
2745--- linux-3.0.4/arch/score/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
2746+++ linux-3.0.4/arch/score/kernel/process.c 2011-08-23 21:47:55.000000000 -0400
2747@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
2748
2749 return task_pt_regs(task)->cp0_epc;
2750 }
2751-
2752-unsigned long arch_align_stack(unsigned long sp)
2753-{
2754- return sp;
2755-}
2756diff -urNp linux-3.0.4/arch/sh/mm/mmap.c linux-3.0.4/arch/sh/mm/mmap.c
2757--- linux-3.0.4/arch/sh/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
2758+++ linux-3.0.4/arch/sh/mm/mmap.c 2011-08-23 21:47:55.000000000 -0400
2759@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
2760 addr = PAGE_ALIGN(addr);
2761
2762 vma = find_vma(mm, addr);
2763- if (TASK_SIZE - len >= addr &&
2764- (!vma || addr + len <= vma->vm_start))
2765+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2766 return addr;
2767 }
2768
2769@@ -106,7 +105,7 @@ full_search:
2770 }
2771 return -ENOMEM;
2772 }
2773- if (likely(!vma || addr + len <= vma->vm_start)) {
2774+ if (likely(check_heap_stack_gap(vma, addr, len))) {
2775 /*
2776 * Remember the place where we stopped the search:
2777 */
2778@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
2779 addr = PAGE_ALIGN(addr);
2780
2781 vma = find_vma(mm, addr);
2782- if (TASK_SIZE - len >= addr &&
2783- (!vma || addr + len <= vma->vm_start))
2784+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2785 return addr;
2786 }
2787
2788@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
2789 /* make sure it can fit in the remaining address space */
2790 if (likely(addr > len)) {
2791 vma = find_vma(mm, addr-len);
2792- if (!vma || addr <= vma->vm_start) {
2793+ if (check_heap_stack_gap(vma, addr - len, len)) {
2794 /* remember the address as a hint for next time */
2795 return (mm->free_area_cache = addr-len);
2796 }
2797@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
2798 if (unlikely(mm->mmap_base < len))
2799 goto bottomup;
2800
2801- addr = mm->mmap_base-len;
2802- if (do_colour_align)
2803- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2804+ addr = mm->mmap_base - len;
2805
2806 do {
2807+ if (do_colour_align)
2808+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2809 /*
2810 * Lookup failure means no vma is above this address,
2811 * else if new region fits below vma->vm_start,
2812 * return with success:
2813 */
2814 vma = find_vma(mm, addr);
2815- if (likely(!vma || addr+len <= vma->vm_start)) {
2816+ if (likely(check_heap_stack_gap(vma, addr, len))) {
2817 /* remember the address as a hint for next time */
2818 return (mm->free_area_cache = addr);
2819 }
2820@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
2821 mm->cached_hole_size = vma->vm_start - addr;
2822
2823 /* try just below the current vma->vm_start */
2824- addr = vma->vm_start-len;
2825- if (do_colour_align)
2826- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2827- } while (likely(len < vma->vm_start));
2828+ addr = skip_heap_stack_gap(vma, len);
2829+ } while (!IS_ERR_VALUE(addr));
2830
2831 bottomup:
2832 /*
2833diff -urNp linux-3.0.4/arch/sparc/include/asm/atomic_64.h linux-3.0.4/arch/sparc/include/asm/atomic_64.h
2834--- linux-3.0.4/arch/sparc/include/asm/atomic_64.h 2011-07-21 22:17:23.000000000 -0400
2835+++ linux-3.0.4/arch/sparc/include/asm/atomic_64.h 2011-08-23 21:48:14.000000000 -0400
2836@@ -14,18 +14,40 @@
2837 #define ATOMIC64_INIT(i) { (i) }
2838
2839 #define atomic_read(v) (*(volatile int *)&(v)->counter)
2840+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
2841+{
2842+ return v->counter;
2843+}
2844 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
2845+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
2846+{
2847+ return v->counter;
2848+}
2849
2850 #define atomic_set(v, i) (((v)->counter) = i)
2851+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
2852+{
2853+ v->counter = i;
2854+}
2855 #define atomic64_set(v, i) (((v)->counter) = i)
2856+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
2857+{
2858+ v->counter = i;
2859+}
2860
2861 extern void atomic_add(int, atomic_t *);
2862+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
2863 extern void atomic64_add(long, atomic64_t *);
2864+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
2865 extern void atomic_sub(int, atomic_t *);
2866+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
2867 extern void atomic64_sub(long, atomic64_t *);
2868+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
2869
2870 extern int atomic_add_ret(int, atomic_t *);
2871+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
2872 extern long atomic64_add_ret(long, atomic64_t *);
2873+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
2874 extern int atomic_sub_ret(int, atomic_t *);
2875 extern long atomic64_sub_ret(long, atomic64_t *);
2876
2877@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomi
2878 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
2879
2880 #define atomic_inc_return(v) atomic_add_ret(1, v)
2881+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
2882+{
2883+ return atomic_add_ret_unchecked(1, v);
2884+}
2885 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
2886+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
2887+{
2888+ return atomic64_add_ret_unchecked(1, v);
2889+}
2890
2891 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
2892 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
2893
2894 #define atomic_add_return(i, v) atomic_add_ret(i, v)
2895+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
2896+{
2897+ return atomic_add_ret_unchecked(i, v);
2898+}
2899 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
2900+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
2901+{
2902+ return atomic64_add_ret_unchecked(i, v);
2903+}
2904
2905 /*
2906 * atomic_inc_and_test - increment and test
2907@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomi
2908 * other cases.
2909 */
2910 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
2911+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
2912+{
2913+ return atomic_inc_return_unchecked(v) == 0;
2914+}
2915 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
2916
2917 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
2918@@ -59,30 +101,65 @@ extern long atomic64_sub_ret(long, atomi
2919 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
2920
2921 #define atomic_inc(v) atomic_add(1, v)
2922+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
2923+{
2924+ atomic_add_unchecked(1, v);
2925+}
2926 #define atomic64_inc(v) atomic64_add(1, v)
2927+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
2928+{
2929+ atomic64_add_unchecked(1, v);
2930+}
2931
2932 #define atomic_dec(v) atomic_sub(1, v)
2933+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
2934+{
2935+ atomic_sub_unchecked(1, v);
2936+}
2937 #define atomic64_dec(v) atomic64_sub(1, v)
2938+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
2939+{
2940+ atomic64_sub_unchecked(1, v);
2941+}
2942
2943 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
2944 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
2945
2946 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
2947+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
2948+{
2949+ return cmpxchg(&v->counter, old, new);
2950+}
2951 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
2952+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
2953+{
2954+ return xchg(&v->counter, new);
2955+}
2956
2957 static inline int atomic_add_unless(atomic_t *v, int a, int u)
2958 {
2959- int c, old;
2960+ int c, old, new;
2961 c = atomic_read(v);
2962 for (;;) {
2963- if (unlikely(c == (u)))
2964+ if (unlikely(c == u))
2965 break;
2966- old = atomic_cmpxchg((v), c, c + (a));
2967+
2968+ asm volatile("addcc %2, %0, %0\n"
2969+
2970+#ifdef CONFIG_PAX_REFCOUNT
2971+ "tvs %%icc, 6\n"
2972+#endif
2973+
2974+ : "=r" (new)
2975+ : "0" (c), "ir" (a)
2976+ : "cc");
2977+
2978+ old = atomic_cmpxchg(v, c, new);
2979 if (likely(old == c))
2980 break;
2981 c = old;
2982 }
2983- return c != (u);
2984+ return c != u;
2985 }
2986
2987 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
2988@@ -90,20 +167,35 @@ static inline int atomic_add_unless(atom
2989 #define atomic64_cmpxchg(v, o, n) \
2990 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
2991 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
2992+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
2993+{
2994+ return xchg(&v->counter, new);
2995+}
2996
2997 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
2998 {
2999- long c, old;
3000+ long c, old, new;
3001 c = atomic64_read(v);
3002 for (;;) {
3003- if (unlikely(c == (u)))
3004+ if (unlikely(c == u))
3005 break;
3006- old = atomic64_cmpxchg((v), c, c + (a));
3007+
3008+ asm volatile("addcc %2, %0, %0\n"
3009+
3010+#ifdef CONFIG_PAX_REFCOUNT
3011+ "tvs %%xcc, 6\n"
3012+#endif
3013+
3014+ : "=r" (new)
3015+ : "0" (c), "ir" (a)
3016+ : "cc");
3017+
3018+ old = atomic64_cmpxchg(v, c, new);
3019 if (likely(old == c))
3020 break;
3021 c = old;
3022 }
3023- return c != (u);
3024+ return c != u;
3025 }
3026
3027 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3028diff -urNp linux-3.0.4/arch/sparc/include/asm/cache.h linux-3.0.4/arch/sparc/include/asm/cache.h
3029--- linux-3.0.4/arch/sparc/include/asm/cache.h 2011-07-21 22:17:23.000000000 -0400
3030+++ linux-3.0.4/arch/sparc/include/asm/cache.h 2011-08-23 21:47:55.000000000 -0400
3031@@ -10,7 +10,7 @@
3032 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
3033
3034 #define L1_CACHE_SHIFT 5
3035-#define L1_CACHE_BYTES 32
3036+#define L1_CACHE_BYTES 32UL
3037
3038 #ifdef CONFIG_SPARC32
3039 #define SMP_CACHE_BYTES_SHIFT 5
3040diff -urNp linux-3.0.4/arch/sparc/include/asm/elf_32.h linux-3.0.4/arch/sparc/include/asm/elf_32.h
3041--- linux-3.0.4/arch/sparc/include/asm/elf_32.h 2011-07-21 22:17:23.000000000 -0400
3042+++ linux-3.0.4/arch/sparc/include/asm/elf_32.h 2011-08-23 21:47:55.000000000 -0400
3043@@ -114,6 +114,13 @@ typedef struct {
3044
3045 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3046
3047+#ifdef CONFIG_PAX_ASLR
3048+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3049+
3050+#define PAX_DELTA_MMAP_LEN 16
3051+#define PAX_DELTA_STACK_LEN 16
3052+#endif
3053+
3054 /* This yields a mask that user programs can use to figure out what
3055 instruction set this cpu supports. This can NOT be done in userspace
3056 on Sparc. */
3057diff -urNp linux-3.0.4/arch/sparc/include/asm/elf_64.h linux-3.0.4/arch/sparc/include/asm/elf_64.h
3058--- linux-3.0.4/arch/sparc/include/asm/elf_64.h 2011-08-23 21:44:40.000000000 -0400
3059+++ linux-3.0.4/arch/sparc/include/asm/elf_64.h 2011-08-23 21:47:55.000000000 -0400
3060@@ -180,6 +180,13 @@ typedef struct {
3061 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3062 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3063
3064+#ifdef CONFIG_PAX_ASLR
3065+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3066+
3067+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3068+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3069+#endif
3070+
3071 extern unsigned long sparc64_elf_hwcap;
3072 #define ELF_HWCAP sparc64_elf_hwcap
3073
3074diff -urNp linux-3.0.4/arch/sparc/include/asm/pgtable_32.h linux-3.0.4/arch/sparc/include/asm/pgtable_32.h
3075--- linux-3.0.4/arch/sparc/include/asm/pgtable_32.h 2011-07-21 22:17:23.000000000 -0400
3076+++ linux-3.0.4/arch/sparc/include/asm/pgtable_32.h 2011-08-23 21:47:55.000000000 -0400
3077@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3078 BTFIXUPDEF_INT(page_none)
3079 BTFIXUPDEF_INT(page_copy)
3080 BTFIXUPDEF_INT(page_readonly)
3081+
3082+#ifdef CONFIG_PAX_PAGEEXEC
3083+BTFIXUPDEF_INT(page_shared_noexec)
3084+BTFIXUPDEF_INT(page_copy_noexec)
3085+BTFIXUPDEF_INT(page_readonly_noexec)
3086+#endif
3087+
3088 BTFIXUPDEF_INT(page_kernel)
3089
3090 #define PMD_SHIFT SUN4C_PMD_SHIFT
3091@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
3092 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3093 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3094
3095+#ifdef CONFIG_PAX_PAGEEXEC
3096+extern pgprot_t PAGE_SHARED_NOEXEC;
3097+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3098+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3099+#else
3100+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3101+# define PAGE_COPY_NOEXEC PAGE_COPY
3102+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3103+#endif
3104+
3105 extern unsigned long page_kernel;
3106
3107 #ifdef MODULE
3108diff -urNp linux-3.0.4/arch/sparc/include/asm/pgtsrmmu.h linux-3.0.4/arch/sparc/include/asm/pgtsrmmu.h
3109--- linux-3.0.4/arch/sparc/include/asm/pgtsrmmu.h 2011-07-21 22:17:23.000000000 -0400
3110+++ linux-3.0.4/arch/sparc/include/asm/pgtsrmmu.h 2011-08-23 21:47:55.000000000 -0400
3111@@ -115,6 +115,13 @@
3112 SRMMU_EXEC | SRMMU_REF)
3113 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3114 SRMMU_EXEC | SRMMU_REF)
3115+
3116+#ifdef CONFIG_PAX_PAGEEXEC
3117+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3118+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3119+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3120+#endif
3121+
3122 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3123 SRMMU_DIRTY | SRMMU_REF)
3124
3125diff -urNp linux-3.0.4/arch/sparc/include/asm/spinlock_64.h linux-3.0.4/arch/sparc/include/asm/spinlock_64.h
3126--- linux-3.0.4/arch/sparc/include/asm/spinlock_64.h 2011-07-21 22:17:23.000000000 -0400
3127+++ linux-3.0.4/arch/sparc/include/asm/spinlock_64.h 2011-08-23 21:47:55.000000000 -0400
3128@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(
3129
3130 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3131
3132-static void inline arch_read_lock(arch_rwlock_t *lock)
3133+static inline void arch_read_lock(arch_rwlock_t *lock)
3134 {
3135 unsigned long tmp1, tmp2;
3136
3137 __asm__ __volatile__ (
3138 "1: ldsw [%2], %0\n"
3139 " brlz,pn %0, 2f\n"
3140-"4: add %0, 1, %1\n"
3141+"4: addcc %0, 1, %1\n"
3142+
3143+#ifdef CONFIG_PAX_REFCOUNT
3144+" tvs %%icc, 6\n"
3145+#endif
3146+
3147 " cas [%2], %0, %1\n"
3148 " cmp %0, %1\n"
3149 " bne,pn %%icc, 1b\n"
3150@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_r
3151 " .previous"
3152 : "=&r" (tmp1), "=&r" (tmp2)
3153 : "r" (lock)
3154- : "memory");
3155+ : "memory", "cc");
3156 }
3157
3158-static int inline arch_read_trylock(arch_rwlock_t *lock)
3159+static inline int arch_read_trylock(arch_rwlock_t *lock)
3160 {
3161 int tmp1, tmp2;
3162
3163@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch
3164 "1: ldsw [%2], %0\n"
3165 " brlz,a,pn %0, 2f\n"
3166 " mov 0, %0\n"
3167-" add %0, 1, %1\n"
3168+" addcc %0, 1, %1\n"
3169+
3170+#ifdef CONFIG_PAX_REFCOUNT
3171+" tvs %%icc, 6\n"
3172+#endif
3173+
3174 " cas [%2], %0, %1\n"
3175 " cmp %0, %1\n"
3176 " bne,pn %%icc, 1b\n"
3177@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch
3178 return tmp1;
3179 }
3180
3181-static void inline arch_read_unlock(arch_rwlock_t *lock)
3182+static inline void arch_read_unlock(arch_rwlock_t *lock)
3183 {
3184 unsigned long tmp1, tmp2;
3185
3186 __asm__ __volatile__(
3187 "1: lduw [%2], %0\n"
3188-" sub %0, 1, %1\n"
3189+" subcc %0, 1, %1\n"
3190+
3191+#ifdef CONFIG_PAX_REFCOUNT
3192+" tvs %%icc, 6\n"
3193+#endif
3194+
3195 " cas [%2], %0, %1\n"
3196 " cmp %0, %1\n"
3197 " bne,pn %%xcc, 1b\n"
3198@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch
3199 : "memory");
3200 }
3201
3202-static void inline arch_write_lock(arch_rwlock_t *lock)
3203+static inline void arch_write_lock(arch_rwlock_t *lock)
3204 {
3205 unsigned long mask, tmp1, tmp2;
3206
3207@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_
3208 : "memory");
3209 }
3210
3211-static void inline arch_write_unlock(arch_rwlock_t *lock)
3212+static inline void arch_write_unlock(arch_rwlock_t *lock)
3213 {
3214 __asm__ __volatile__(
3215 " stw %%g0, [%0]"
3216@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arc
3217 : "memory");
3218 }
3219
3220-static int inline arch_write_trylock(arch_rwlock_t *lock)
3221+static inline int arch_write_trylock(arch_rwlock_t *lock)
3222 {
3223 unsigned long mask, tmp1, tmp2, result;
3224
3225diff -urNp linux-3.0.4/arch/sparc/include/asm/thread_info_32.h linux-3.0.4/arch/sparc/include/asm/thread_info_32.h
3226--- linux-3.0.4/arch/sparc/include/asm/thread_info_32.h 2011-07-21 22:17:23.000000000 -0400
3227+++ linux-3.0.4/arch/sparc/include/asm/thread_info_32.h 2011-08-23 21:47:55.000000000 -0400
3228@@ -50,6 +50,8 @@ struct thread_info {
3229 unsigned long w_saved;
3230
3231 struct restart_block restart_block;
3232+
3233+ unsigned long lowest_stack;
3234 };
3235
3236 /*
3237diff -urNp linux-3.0.4/arch/sparc/include/asm/thread_info_64.h linux-3.0.4/arch/sparc/include/asm/thread_info_64.h
3238--- linux-3.0.4/arch/sparc/include/asm/thread_info_64.h 2011-07-21 22:17:23.000000000 -0400
3239+++ linux-3.0.4/arch/sparc/include/asm/thread_info_64.h 2011-08-23 21:47:55.000000000 -0400
3240@@ -63,6 +63,8 @@ struct thread_info {
3241 struct pt_regs *kern_una_regs;
3242 unsigned int kern_una_insn;
3243
3244+ unsigned long lowest_stack;
3245+
3246 unsigned long fpregs[0] __attribute__ ((aligned(64)));
3247 };
3248
3249diff -urNp linux-3.0.4/arch/sparc/include/asm/uaccess_32.h linux-3.0.4/arch/sparc/include/asm/uaccess_32.h
3250--- linux-3.0.4/arch/sparc/include/asm/uaccess_32.h 2011-07-21 22:17:23.000000000 -0400
3251+++ linux-3.0.4/arch/sparc/include/asm/uaccess_32.h 2011-08-23 21:47:55.000000000 -0400
3252@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
3253
3254 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3255 {
3256- if (n && __access_ok((unsigned long) to, n))
3257+ if ((long)n < 0)
3258+ return n;
3259+
3260+ if (n && __access_ok((unsigned long) to, n)) {
3261+ if (!__builtin_constant_p(n))
3262+ check_object_size(from, n, true);
3263 return __copy_user(to, (__force void __user *) from, n);
3264- else
3265+ } else
3266 return n;
3267 }
3268
3269 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
3270 {
3271+ if ((long)n < 0)
3272+ return n;
3273+
3274+ if (!__builtin_constant_p(n))
3275+ check_object_size(from, n, true);
3276+
3277 return __copy_user(to, (__force void __user *) from, n);
3278 }
3279
3280 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3281 {
3282- if (n && __access_ok((unsigned long) from, n))
3283+ if ((long)n < 0)
3284+ return n;
3285+
3286+ if (n && __access_ok((unsigned long) from, n)) {
3287+ if (!__builtin_constant_p(n))
3288+ check_object_size(to, n, false);
3289 return __copy_user((__force void __user *) to, from, n);
3290- else
3291+ } else
3292 return n;
3293 }
3294
3295 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
3296 {
3297+ if ((long)n < 0)
3298+ return n;
3299+
3300 return __copy_user((__force void __user *) to, from, n);
3301 }
3302
3303diff -urNp linux-3.0.4/arch/sparc/include/asm/uaccess_64.h linux-3.0.4/arch/sparc/include/asm/uaccess_64.h
3304--- linux-3.0.4/arch/sparc/include/asm/uaccess_64.h 2011-07-21 22:17:23.000000000 -0400
3305+++ linux-3.0.4/arch/sparc/include/asm/uaccess_64.h 2011-08-23 21:47:55.000000000 -0400
3306@@ -10,6 +10,7 @@
3307 #include <linux/compiler.h>
3308 #include <linux/string.h>
3309 #include <linux/thread_info.h>
3310+#include <linux/kernel.h>
3311 #include <asm/asi.h>
3312 #include <asm/system.h>
3313 #include <asm/spitfire.h>
3314@@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
3315 static inline unsigned long __must_check
3316 copy_from_user(void *to, const void __user *from, unsigned long size)
3317 {
3318- unsigned long ret = ___copy_from_user(to, from, size);
3319+ unsigned long ret;
3320
3321+ if ((long)size < 0 || size > INT_MAX)
3322+ return size;
3323+
3324+ if (!__builtin_constant_p(size))
3325+ check_object_size(to, size, false);
3326+
3327+ ret = ___copy_from_user(to, from, size);
3328 if (unlikely(ret))
3329 ret = copy_from_user_fixup(to, from, size);
3330
3331@@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
3332 static inline unsigned long __must_check
3333 copy_to_user(void __user *to, const void *from, unsigned long size)
3334 {
3335- unsigned long ret = ___copy_to_user(to, from, size);
3336+ unsigned long ret;
3337+
3338+ if ((long)size < 0 || size > INT_MAX)
3339+ return size;
3340+
3341+ if (!__builtin_constant_p(size))
3342+ check_object_size(from, size, true);
3343
3344+ ret = ___copy_to_user(to, from, size);
3345 if (unlikely(ret))
3346 ret = copy_to_user_fixup(to, from, size);
3347 return ret;
3348diff -urNp linux-3.0.4/arch/sparc/include/asm/uaccess.h linux-3.0.4/arch/sparc/include/asm/uaccess.h
3349--- linux-3.0.4/arch/sparc/include/asm/uaccess.h 2011-07-21 22:17:23.000000000 -0400
3350+++ linux-3.0.4/arch/sparc/include/asm/uaccess.h 2011-08-23 21:47:55.000000000 -0400
3351@@ -1,5 +1,13 @@
3352 #ifndef ___ASM_SPARC_UACCESS_H
3353 #define ___ASM_SPARC_UACCESS_H
3354+
3355+#ifdef __KERNEL__
3356+#ifndef __ASSEMBLY__
3357+#include <linux/types.h>
3358+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3359+#endif
3360+#endif
3361+
3362 #if defined(__sparc__) && defined(__arch64__)
3363 #include <asm/uaccess_64.h>
3364 #else
3365diff -urNp linux-3.0.4/arch/sparc/kernel/Makefile linux-3.0.4/arch/sparc/kernel/Makefile
3366--- linux-3.0.4/arch/sparc/kernel/Makefile 2011-07-21 22:17:23.000000000 -0400
3367+++ linux-3.0.4/arch/sparc/kernel/Makefile 2011-08-23 21:47:55.000000000 -0400
3368@@ -3,7 +3,7 @@
3369 #
3370
3371 asflags-y := -ansi
3372-ccflags-y := -Werror
3373+#ccflags-y := -Werror
3374
3375 extra-y := head_$(BITS).o
3376 extra-y += init_task.o
3377diff -urNp linux-3.0.4/arch/sparc/kernel/process_32.c linux-3.0.4/arch/sparc/kernel/process_32.c
3378--- linux-3.0.4/arch/sparc/kernel/process_32.c 2011-07-21 22:17:23.000000000 -0400
3379+++ linux-3.0.4/arch/sparc/kernel/process_32.c 2011-08-23 21:48:14.000000000 -0400
3380@@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
3381 rw->ins[4], rw->ins[5],
3382 rw->ins[6],
3383 rw->ins[7]);
3384- printk("%pS\n", (void *) rw->ins[7]);
3385+ printk("%pA\n", (void *) rw->ins[7]);
3386 rw = (struct reg_window32 *) rw->ins[6];
3387 }
3388 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
3389@@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
3390
3391 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
3392 r->psr, r->pc, r->npc, r->y, print_tainted());
3393- printk("PC: <%pS>\n", (void *) r->pc);
3394+ printk("PC: <%pA>\n", (void *) r->pc);
3395 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3396 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
3397 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
3398 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3399 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
3400 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
3401- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
3402+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
3403
3404 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
3405 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
3406@@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk,
3407 rw = (struct reg_window32 *) fp;
3408 pc = rw->ins[7];
3409 printk("[%08lx : ", pc);
3410- printk("%pS ] ", (void *) pc);
3411+ printk("%pA ] ", (void *) pc);
3412 fp = rw->ins[6];
3413 } while (++count < 16);
3414 printk("\n");
3415diff -urNp linux-3.0.4/arch/sparc/kernel/process_64.c linux-3.0.4/arch/sparc/kernel/process_64.c
3416--- linux-3.0.4/arch/sparc/kernel/process_64.c 2011-07-21 22:17:23.000000000 -0400
3417+++ linux-3.0.4/arch/sparc/kernel/process_64.c 2011-08-23 21:48:14.000000000 -0400
3418@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
3419 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
3420 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
3421 if (regs->tstate & TSTATE_PRIV)
3422- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
3423+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
3424 }
3425
3426 void show_regs(struct pt_regs *regs)
3427 {
3428 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
3429 regs->tpc, regs->tnpc, regs->y, print_tainted());
3430- printk("TPC: <%pS>\n", (void *) regs->tpc);
3431+ printk("TPC: <%pA>\n", (void *) regs->tpc);
3432 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
3433 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
3434 regs->u_regs[3]);
3435@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
3436 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
3437 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
3438 regs->u_regs[15]);
3439- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
3440+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
3441 show_regwindow(regs);
3442 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
3443 }
3444@@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
3445 ((tp && tp->task) ? tp->task->pid : -1));
3446
3447 if (gp->tstate & TSTATE_PRIV) {
3448- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
3449+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
3450 (void *) gp->tpc,
3451 (void *) gp->o7,
3452 (void *) gp->i7,
3453diff -urNp linux-3.0.4/arch/sparc/kernel/sys_sparc_32.c linux-3.0.4/arch/sparc/kernel/sys_sparc_32.c
3454--- linux-3.0.4/arch/sparc/kernel/sys_sparc_32.c 2011-07-21 22:17:23.000000000 -0400
3455+++ linux-3.0.4/arch/sparc/kernel/sys_sparc_32.c 2011-08-23 21:47:55.000000000 -0400
3456@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
3457 if (ARCH_SUN4C && len > 0x20000000)
3458 return -ENOMEM;
3459 if (!addr)
3460- addr = TASK_UNMAPPED_BASE;
3461+ addr = current->mm->mmap_base;
3462
3463 if (flags & MAP_SHARED)
3464 addr = COLOUR_ALIGN(addr);
3465@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
3466 }
3467 if (TASK_SIZE - PAGE_SIZE - len < addr)
3468 return -ENOMEM;
3469- if (!vmm || addr + len <= vmm->vm_start)
3470+ if (check_heap_stack_gap(vmm, addr, len))
3471 return addr;
3472 addr = vmm->vm_end;
3473 if (flags & MAP_SHARED)
3474diff -urNp linux-3.0.4/arch/sparc/kernel/sys_sparc_64.c linux-3.0.4/arch/sparc/kernel/sys_sparc_64.c
3475--- linux-3.0.4/arch/sparc/kernel/sys_sparc_64.c 2011-07-21 22:17:23.000000000 -0400
3476+++ linux-3.0.4/arch/sparc/kernel/sys_sparc_64.c 2011-08-23 21:47:55.000000000 -0400
3477@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
3478 /* We do not accept a shared mapping if it would violate
3479 * cache aliasing constraints.
3480 */
3481- if ((flags & MAP_SHARED) &&
3482+ if ((filp || (flags & MAP_SHARED)) &&
3483 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
3484 return -EINVAL;
3485 return addr;
3486@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
3487 if (filp || (flags & MAP_SHARED))
3488 do_color_align = 1;
3489
3490+#ifdef CONFIG_PAX_RANDMMAP
3491+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3492+#endif
3493+
3494 if (addr) {
3495 if (do_color_align)
3496 addr = COLOUR_ALIGN(addr, pgoff);
3497@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
3498 addr = PAGE_ALIGN(addr);
3499
3500 vma = find_vma(mm, addr);
3501- if (task_size - len >= addr &&
3502- (!vma || addr + len <= vma->vm_start))
3503+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
3504 return addr;
3505 }
3506
3507 if (len > mm->cached_hole_size) {
3508- start_addr = addr = mm->free_area_cache;
3509+ start_addr = addr = mm->free_area_cache;
3510 } else {
3511- start_addr = addr = TASK_UNMAPPED_BASE;
3512+ start_addr = addr = mm->mmap_base;
3513 mm->cached_hole_size = 0;
3514 }
3515
3516@@ -174,14 +177,14 @@ full_search:
3517 vma = find_vma(mm, VA_EXCLUDE_END);
3518 }
3519 if (unlikely(task_size < addr)) {
3520- if (start_addr != TASK_UNMAPPED_BASE) {
3521- start_addr = addr = TASK_UNMAPPED_BASE;
3522+ if (start_addr != mm->mmap_base) {
3523+ start_addr = addr = mm->mmap_base;
3524 mm->cached_hole_size = 0;
3525 goto full_search;
3526 }
3527 return -ENOMEM;
3528 }
3529- if (likely(!vma || addr + len <= vma->vm_start)) {
3530+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3531 /*
3532 * Remember the place where we stopped the search:
3533 */
3534@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
3535 /* We do not accept a shared mapping if it would violate
3536 * cache aliasing constraints.
3537 */
3538- if ((flags & MAP_SHARED) &&
3539+ if ((filp || (flags & MAP_SHARED)) &&
3540 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
3541 return -EINVAL;
3542 return addr;
3543@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
3544 addr = PAGE_ALIGN(addr);
3545
3546 vma = find_vma(mm, addr);
3547- if (task_size - len >= addr &&
3548- (!vma || addr + len <= vma->vm_start))
3549+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
3550 return addr;
3551 }
3552
3553@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
3554 /* make sure it can fit in the remaining address space */
3555 if (likely(addr > len)) {
3556 vma = find_vma(mm, addr-len);
3557- if (!vma || addr <= vma->vm_start) {
3558+ if (check_heap_stack_gap(vma, addr - len, len)) {
3559 /* remember the address as a hint for next time */
3560 return (mm->free_area_cache = addr-len);
3561 }
3562@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct fi
3563 if (unlikely(mm->mmap_base < len))
3564 goto bottomup;
3565
3566- addr = mm->mmap_base-len;
3567- if (do_color_align)
3568- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3569+ addr = mm->mmap_base - len;
3570
3571 do {
3572+ if (do_color_align)
3573+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3574 /*
3575 * Lookup failure means no vma is above this address,
3576 * else if new region fits below vma->vm_start,
3577 * return with success:
3578 */
3579 vma = find_vma(mm, addr);
3580- if (likely(!vma || addr+len <= vma->vm_start)) {
3581+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3582 /* remember the address as a hint for next time */
3583 return (mm->free_area_cache = addr);
3584 }
3585@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct fi
3586 mm->cached_hole_size = vma->vm_start - addr;
3587
3588 /* try just below the current vma->vm_start */
3589- addr = vma->vm_start-len;
3590- if (do_color_align)
3591- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3592- } while (likely(len < vma->vm_start));
3593+ addr = skip_heap_stack_gap(vma, len);
3594+ } while (!IS_ERR_VALUE(addr));
3595
3596 bottomup:
3597 /*
3598@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_str
3599 gap == RLIM_INFINITY ||
3600 sysctl_legacy_va_layout) {
3601 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3602+
3603+#ifdef CONFIG_PAX_RANDMMAP
3604+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3605+ mm->mmap_base += mm->delta_mmap;
3606+#endif
3607+
3608 mm->get_unmapped_area = arch_get_unmapped_area;
3609 mm->unmap_area = arch_unmap_area;
3610 } else {
3611@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_str
3612 gap = (task_size / 6 * 5);
3613
3614 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
3615+
3616+#ifdef CONFIG_PAX_RANDMMAP
3617+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3618+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3619+#endif
3620+
3621 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3622 mm->unmap_area = arch_unmap_area_topdown;
3623 }
3624diff -urNp linux-3.0.4/arch/sparc/kernel/traps_32.c linux-3.0.4/arch/sparc/kernel/traps_32.c
3625--- linux-3.0.4/arch/sparc/kernel/traps_32.c 2011-07-21 22:17:23.000000000 -0400
3626+++ linux-3.0.4/arch/sparc/kernel/traps_32.c 2011-08-23 21:48:14.000000000 -0400
3627@@ -44,6 +44,8 @@ static void instruction_dump(unsigned lo
3628 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
3629 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
3630
3631+extern void gr_handle_kernel_exploit(void);
3632+
3633 void die_if_kernel(char *str, struct pt_regs *regs)
3634 {
3635 static int die_counter;
3636@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_
3637 count++ < 30 &&
3638 (((unsigned long) rw) >= PAGE_OFFSET) &&
3639 !(((unsigned long) rw) & 0x7)) {
3640- printk("Caller[%08lx]: %pS\n", rw->ins[7],
3641+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
3642 (void *) rw->ins[7]);
3643 rw = (struct reg_window32 *)rw->ins[6];
3644 }
3645 }
3646 printk("Instruction DUMP:");
3647 instruction_dump ((unsigned long *) regs->pc);
3648- if(regs->psr & PSR_PS)
3649+ if(regs->psr & PSR_PS) {
3650+ gr_handle_kernel_exploit();
3651 do_exit(SIGKILL);
3652+ }
3653 do_exit(SIGSEGV);
3654 }
3655
3656diff -urNp linux-3.0.4/arch/sparc/kernel/traps_64.c linux-3.0.4/arch/sparc/kernel/traps_64.c
3657--- linux-3.0.4/arch/sparc/kernel/traps_64.c 2011-07-21 22:17:23.000000000 -0400
3658+++ linux-3.0.4/arch/sparc/kernel/traps_64.c 2011-08-23 21:48:14.000000000 -0400
3659@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
3660 i + 1,
3661 p->trapstack[i].tstate, p->trapstack[i].tpc,
3662 p->trapstack[i].tnpc, p->trapstack[i].tt);
3663- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
3664+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
3665 }
3666 }
3667
3668@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
3669
3670 lvl -= 0x100;
3671 if (regs->tstate & TSTATE_PRIV) {
3672+
3673+#ifdef CONFIG_PAX_REFCOUNT
3674+ if (lvl == 6)
3675+ pax_report_refcount_overflow(regs);
3676+#endif
3677+
3678 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
3679 die_if_kernel(buffer, regs);
3680 }
3681@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
3682 void bad_trap_tl1(struct pt_regs *regs, long lvl)
3683 {
3684 char buffer[32];
3685-
3686+
3687 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
3688 0, lvl, SIGTRAP) == NOTIFY_STOP)
3689 return;
3690
3691+#ifdef CONFIG_PAX_REFCOUNT
3692+ if (lvl == 6)
3693+ pax_report_refcount_overflow(regs);
3694+#endif
3695+
3696 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
3697
3698 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
3699@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
3700 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
3701 printk("%s" "ERROR(%d): ",
3702 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
3703- printk("TPC<%pS>\n", (void *) regs->tpc);
3704+ printk("TPC<%pA>\n", (void *) regs->tpc);
3705 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
3706 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
3707 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
3708@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
3709 smp_processor_id(),
3710 (type & 0x1) ? 'I' : 'D',
3711 regs->tpc);
3712- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
3713+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
3714 panic("Irrecoverable Cheetah+ parity error.");
3715 }
3716
3717@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
3718 smp_processor_id(),
3719 (type & 0x1) ? 'I' : 'D',
3720 regs->tpc);
3721- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
3722+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
3723 }
3724
3725 struct sun4v_error_entry {
3726@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
3727
3728 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
3729 regs->tpc, tl);
3730- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
3731+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
3732 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
3733- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
3734+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
3735 (void *) regs->u_regs[UREG_I7]);
3736 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
3737 "pte[%lx] error[%lx]\n",
3738@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
3739
3740 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
3741 regs->tpc, tl);
3742- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
3743+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
3744 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
3745- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
3746+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
3747 (void *) regs->u_regs[UREG_I7]);
3748 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
3749 "pte[%lx] error[%lx]\n",
3750@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk,
3751 fp = (unsigned long)sf->fp + STACK_BIAS;
3752 }
3753
3754- printk(" [%016lx] %pS\n", pc, (void *) pc);
3755+ printk(" [%016lx] %pA\n", pc, (void *) pc);
3756 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3757 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
3758 int index = tsk->curr_ret_stack;
3759 if (tsk->ret_stack && index >= graph) {
3760 pc = tsk->ret_stack[index - graph].ret;
3761- printk(" [%016lx] %pS\n", pc, (void *) pc);
3762+ printk(" [%016lx] %pA\n", pc, (void *) pc);
3763 graph++;
3764 }
3765 }
3766@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_
3767 return (struct reg_window *) (fp + STACK_BIAS);
3768 }
3769
3770+extern void gr_handle_kernel_exploit(void);
3771+
3772 void die_if_kernel(char *str, struct pt_regs *regs)
3773 {
3774 static int die_counter;
3775@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_
3776 while (rw &&
3777 count++ < 30 &&
3778 kstack_valid(tp, (unsigned long) rw)) {
3779- printk("Caller[%016lx]: %pS\n", rw->ins[7],
3780+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
3781 (void *) rw->ins[7]);
3782
3783 rw = kernel_stack_up(rw);
3784@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_
3785 }
3786 user_instruction_dump ((unsigned int __user *) regs->tpc);
3787 }
3788- if (regs->tstate & TSTATE_PRIV)
3789+ if (regs->tstate & TSTATE_PRIV) {
3790+ gr_handle_kernel_exploit();
3791 do_exit(SIGKILL);
3792+ }
3793 do_exit(SIGSEGV);
3794 }
3795 EXPORT_SYMBOL(die_if_kernel);
3796diff -urNp linux-3.0.4/arch/sparc/kernel/unaligned_64.c linux-3.0.4/arch/sparc/kernel/unaligned_64.c
3797--- linux-3.0.4/arch/sparc/kernel/unaligned_64.c 2011-08-23 21:44:40.000000000 -0400
3798+++ linux-3.0.4/arch/sparc/kernel/unaligned_64.c 2011-08-23 21:48:14.000000000 -0400
3799@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs
3800 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
3801
3802 if (__ratelimit(&ratelimit)) {
3803- printk("Kernel unaligned access at TPC[%lx] %pS\n",
3804+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
3805 regs->tpc, (void *) regs->tpc);
3806 }
3807 }
3808diff -urNp linux-3.0.4/arch/sparc/lib/atomic_64.S linux-3.0.4/arch/sparc/lib/atomic_64.S
3809--- linux-3.0.4/arch/sparc/lib/atomic_64.S 2011-07-21 22:17:23.000000000 -0400
3810+++ linux-3.0.4/arch/sparc/lib/atomic_64.S 2011-08-23 21:47:55.000000000 -0400
3811@@ -18,7 +18,12 @@
3812 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
3813 BACKOFF_SETUP(%o2)
3814 1: lduw [%o1], %g1
3815- add %g1, %o0, %g7
3816+ addcc %g1, %o0, %g7
3817+
3818+#ifdef CONFIG_PAX_REFCOUNT
3819+ tvs %icc, 6
3820+#endif
3821+
3822 cas [%o1], %g1, %g7
3823 cmp %g1, %g7
3824 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
3825@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
3826 2: BACKOFF_SPIN(%o2, %o3, 1b)
3827 .size atomic_add, .-atomic_add
3828
3829+ .globl atomic_add_unchecked
3830+ .type atomic_add_unchecked,#function
3831+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
3832+ BACKOFF_SETUP(%o2)
3833+1: lduw [%o1], %g1
3834+ add %g1, %o0, %g7
3835+ cas [%o1], %g1, %g7
3836+ cmp %g1, %g7
3837+ bne,pn %icc, 2f
3838+ nop
3839+ retl
3840+ nop
3841+2: BACKOFF_SPIN(%o2, %o3, 1b)
3842+ .size atomic_add_unchecked, .-atomic_add_unchecked
3843+
3844 .globl atomic_sub
3845 .type atomic_sub,#function
3846 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
3847 BACKOFF_SETUP(%o2)
3848 1: lduw [%o1], %g1
3849- sub %g1, %o0, %g7
3850+ subcc %g1, %o0, %g7
3851+
3852+#ifdef CONFIG_PAX_REFCOUNT
3853+ tvs %icc, 6
3854+#endif
3855+
3856 cas [%o1], %g1, %g7
3857 cmp %g1, %g7
3858 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
3859@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
3860 2: BACKOFF_SPIN(%o2, %o3, 1b)
3861 .size atomic_sub, .-atomic_sub
3862
3863+ .globl atomic_sub_unchecked
3864+ .type atomic_sub_unchecked,#function
3865+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
3866+ BACKOFF_SETUP(%o2)
3867+1: lduw [%o1], %g1
3868+ sub %g1, %o0, %g7
3869+ cas [%o1], %g1, %g7
3870+ cmp %g1, %g7
3871+ bne,pn %icc, 2f
3872+ nop
3873+ retl
3874+ nop
3875+2: BACKOFF_SPIN(%o2, %o3, 1b)
3876+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
3877+
3878 .globl atomic_add_ret
3879 .type atomic_add_ret,#function
3880 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
3881 BACKOFF_SETUP(%o2)
3882 1: lduw [%o1], %g1
3883- add %g1, %o0, %g7
3884+ addcc %g1, %o0, %g7
3885+
3886+#ifdef CONFIG_PAX_REFCOUNT
3887+ tvs %icc, 6
3888+#endif
3889+
3890 cas [%o1], %g1, %g7
3891 cmp %g1, %g7
3892 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
3893@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
3894 2: BACKOFF_SPIN(%o2, %o3, 1b)
3895 .size atomic_add_ret, .-atomic_add_ret
3896
3897+ .globl atomic_add_ret_unchecked
3898+ .type atomic_add_ret_unchecked,#function
3899+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
3900+ BACKOFF_SETUP(%o2)
3901+1: lduw [%o1], %g1
3902+ addcc %g1, %o0, %g7
3903+ cas [%o1], %g1, %g7
3904+ cmp %g1, %g7
3905+ bne,pn %icc, 2f
3906+ add %g7, %o0, %g7
3907+ sra %g7, 0, %o0
3908+ retl
3909+ nop
3910+2: BACKOFF_SPIN(%o2, %o3, 1b)
3911+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
3912+
3913 .globl atomic_sub_ret
3914 .type atomic_sub_ret,#function
3915 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
3916 BACKOFF_SETUP(%o2)
3917 1: lduw [%o1], %g1
3918- sub %g1, %o0, %g7
3919+ subcc %g1, %o0, %g7
3920+
3921+#ifdef CONFIG_PAX_REFCOUNT
3922+ tvs %icc, 6
3923+#endif
3924+
3925 cas [%o1], %g1, %g7
3926 cmp %g1, %g7
3927 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
3928@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
3929 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
3930 BACKOFF_SETUP(%o2)
3931 1: ldx [%o1], %g1
3932- add %g1, %o0, %g7
3933+ addcc %g1, %o0, %g7
3934+
3935+#ifdef CONFIG_PAX_REFCOUNT
3936+ tvs %xcc, 6
3937+#endif
3938+
3939 casx [%o1], %g1, %g7
3940 cmp %g1, %g7
3941 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
3942@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
3943 2: BACKOFF_SPIN(%o2, %o3, 1b)
3944 .size atomic64_add, .-atomic64_add
3945
3946+ .globl atomic64_add_unchecked
3947+ .type atomic64_add_unchecked,#function
3948+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
3949+ BACKOFF_SETUP(%o2)
3950+1: ldx [%o1], %g1
3951+ addcc %g1, %o0, %g7
3952+ casx [%o1], %g1, %g7
3953+ cmp %g1, %g7
3954+ bne,pn %xcc, 2f
3955+ nop
3956+ retl
3957+ nop
3958+2: BACKOFF_SPIN(%o2, %o3, 1b)
3959+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
3960+
3961 .globl atomic64_sub
3962 .type atomic64_sub,#function
3963 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
3964 BACKOFF_SETUP(%o2)
3965 1: ldx [%o1], %g1
3966- sub %g1, %o0, %g7
3967+ subcc %g1, %o0, %g7
3968+
3969+#ifdef CONFIG_PAX_REFCOUNT
3970+ tvs %xcc, 6
3971+#endif
3972+
3973 casx [%o1], %g1, %g7
3974 cmp %g1, %g7
3975 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
3976@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
3977 2: BACKOFF_SPIN(%o2, %o3, 1b)
3978 .size atomic64_sub, .-atomic64_sub
3979
3980+ .globl atomic64_sub_unchecked
3981+ .type atomic64_sub_unchecked,#function
3982+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
3983+ BACKOFF_SETUP(%o2)
3984+1: ldx [%o1], %g1
3985+ subcc %g1, %o0, %g7
3986+ casx [%o1], %g1, %g7
3987+ cmp %g1, %g7
3988+ bne,pn %xcc, 2f
3989+ nop
3990+ retl
3991+ nop
3992+2: BACKOFF_SPIN(%o2, %o3, 1b)
3993+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
3994+
3995 .globl atomic64_add_ret
3996 .type atomic64_add_ret,#function
3997 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
3998 BACKOFF_SETUP(%o2)
3999 1: ldx [%o1], %g1
4000- add %g1, %o0, %g7
4001+ addcc %g1, %o0, %g7
4002+
4003+#ifdef CONFIG_PAX_REFCOUNT
4004+ tvs %xcc, 6
4005+#endif
4006+
4007 casx [%o1], %g1, %g7
4008 cmp %g1, %g7
4009 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4010@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
4011 2: BACKOFF_SPIN(%o2, %o3, 1b)
4012 .size atomic64_add_ret, .-atomic64_add_ret
4013
4014+ .globl atomic64_add_ret_unchecked
4015+ .type atomic64_add_ret_unchecked,#function
4016+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4017+ BACKOFF_SETUP(%o2)
4018+1: ldx [%o1], %g1
4019+ addcc %g1, %o0, %g7
4020+ casx [%o1], %g1, %g7
4021+ cmp %g1, %g7
4022+ bne,pn %xcc, 2f
4023+ add %g7, %o0, %g7
4024+ mov %g7, %o0
4025+ retl
4026+ nop
4027+2: BACKOFF_SPIN(%o2, %o3, 1b)
4028+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4029+
4030 .globl atomic64_sub_ret
4031 .type atomic64_sub_ret,#function
4032 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4033 BACKOFF_SETUP(%o2)
4034 1: ldx [%o1], %g1
4035- sub %g1, %o0, %g7
4036+ subcc %g1, %o0, %g7
4037+
4038+#ifdef CONFIG_PAX_REFCOUNT
4039+ tvs %xcc, 6
4040+#endif
4041+
4042 casx [%o1], %g1, %g7
4043 cmp %g1, %g7
4044 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4045diff -urNp linux-3.0.4/arch/sparc/lib/ksyms.c linux-3.0.4/arch/sparc/lib/ksyms.c
4046--- linux-3.0.4/arch/sparc/lib/ksyms.c 2011-07-21 22:17:23.000000000 -0400
4047+++ linux-3.0.4/arch/sparc/lib/ksyms.c 2011-08-23 21:48:14.000000000 -0400
4048@@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
4049
4050 /* Atomic counter implementation. */
4051 EXPORT_SYMBOL(atomic_add);
4052+EXPORT_SYMBOL(atomic_add_unchecked);
4053 EXPORT_SYMBOL(atomic_add_ret);
4054+EXPORT_SYMBOL(atomic_add_ret_unchecked);
4055 EXPORT_SYMBOL(atomic_sub);
4056+EXPORT_SYMBOL(atomic_sub_unchecked);
4057 EXPORT_SYMBOL(atomic_sub_ret);
4058 EXPORT_SYMBOL(atomic64_add);
4059+EXPORT_SYMBOL(atomic64_add_unchecked);
4060 EXPORT_SYMBOL(atomic64_add_ret);
4061+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4062 EXPORT_SYMBOL(atomic64_sub);
4063+EXPORT_SYMBOL(atomic64_sub_unchecked);
4064 EXPORT_SYMBOL(atomic64_sub_ret);
4065
4066 /* Atomic bit operations. */
4067diff -urNp linux-3.0.4/arch/sparc/lib/Makefile linux-3.0.4/arch/sparc/lib/Makefile
4068--- linux-3.0.4/arch/sparc/lib/Makefile 2011-08-23 21:44:40.000000000 -0400
4069+++ linux-3.0.4/arch/sparc/lib/Makefile 2011-08-23 21:47:55.000000000 -0400
4070@@ -2,7 +2,7 @@
4071 #
4072
4073 asflags-y := -ansi -DST_DIV0=0x02
4074-ccflags-y := -Werror
4075+#ccflags-y := -Werror
4076
4077 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4078 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4079diff -urNp linux-3.0.4/arch/sparc/Makefile linux-3.0.4/arch/sparc/Makefile
4080--- linux-3.0.4/arch/sparc/Makefile 2011-07-21 22:17:23.000000000 -0400
4081+++ linux-3.0.4/arch/sparc/Makefile 2011-08-23 21:48:14.000000000 -0400
4082@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
4083 # Export what is needed by arch/sparc/boot/Makefile
4084 export VMLINUX_INIT VMLINUX_MAIN
4085 VMLINUX_INIT := $(head-y) $(init-y)
4086-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4087+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4088 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4089 VMLINUX_MAIN += $(drivers-y) $(net-y)
4090
4091diff -urNp linux-3.0.4/arch/sparc/mm/fault_32.c linux-3.0.4/arch/sparc/mm/fault_32.c
4092--- linux-3.0.4/arch/sparc/mm/fault_32.c 2011-07-21 22:17:23.000000000 -0400
4093+++ linux-3.0.4/arch/sparc/mm/fault_32.c 2011-08-23 21:47:55.000000000 -0400
4094@@ -22,6 +22,9 @@
4095 #include <linux/interrupt.h>
4096 #include <linux/module.h>
4097 #include <linux/kdebug.h>
4098+#include <linux/slab.h>
4099+#include <linux/pagemap.h>
4100+#include <linux/compiler.h>
4101
4102 #include <asm/system.h>
4103 #include <asm/page.h>
4104@@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
4105 return safe_compute_effective_address(regs, insn);
4106 }
4107
4108+#ifdef CONFIG_PAX_PAGEEXEC
4109+#ifdef CONFIG_PAX_DLRESOLVE
4110+static void pax_emuplt_close(struct vm_area_struct *vma)
4111+{
4112+ vma->vm_mm->call_dl_resolve = 0UL;
4113+}
4114+
4115+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4116+{
4117+ unsigned int *kaddr;
4118+
4119+ vmf->page = alloc_page(GFP_HIGHUSER);
4120+ if (!vmf->page)
4121+ return VM_FAULT_OOM;
4122+
4123+ kaddr = kmap(vmf->page);
4124+ memset(kaddr, 0, PAGE_SIZE);
4125+ kaddr[0] = 0x9DE3BFA8U; /* save */
4126+ flush_dcache_page(vmf->page);
4127+ kunmap(vmf->page);
4128+ return VM_FAULT_MAJOR;
4129+}
4130+
4131+static const struct vm_operations_struct pax_vm_ops = {
4132+ .close = pax_emuplt_close,
4133+ .fault = pax_emuplt_fault
4134+};
4135+
4136+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4137+{
4138+ int ret;
4139+
4140+ INIT_LIST_HEAD(&vma->anon_vma_chain);
4141+ vma->vm_mm = current->mm;
4142+ vma->vm_start = addr;
4143+ vma->vm_end = addr + PAGE_SIZE;
4144+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4145+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4146+ vma->vm_ops = &pax_vm_ops;
4147+
4148+ ret = insert_vm_struct(current->mm, vma);
4149+ if (ret)
4150+ return ret;
4151+
4152+ ++current->mm->total_vm;
4153+ return 0;
4154+}
4155+#endif
4156+
4157+/*
4158+ * PaX: decide what to do with offenders (regs->pc = fault address)
4159+ *
4160+ * returns 1 when task should be killed
4161+ * 2 when patched PLT trampoline was detected
4162+ * 3 when unpatched PLT trampoline was detected
4163+ */
4164+static int pax_handle_fetch_fault(struct pt_regs *regs)
4165+{
4166+
4167+#ifdef CONFIG_PAX_EMUPLT
4168+ int err;
4169+
4170+ do { /* PaX: patched PLT emulation #1 */
4171+ unsigned int sethi1, sethi2, jmpl;
4172+
4173+ err = get_user(sethi1, (unsigned int *)regs->pc);
4174+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4175+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4176+
4177+ if (err)
4178+ break;
4179+
4180+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4181+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
4182+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
4183+ {
4184+ unsigned int addr;
4185+
4186+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4187+ addr = regs->u_regs[UREG_G1];
4188+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4189+ regs->pc = addr;
4190+ regs->npc = addr+4;
4191+ return 2;
4192+ }
4193+ } while (0);
4194+
4195+ { /* PaX: patched PLT emulation #2 */
4196+ unsigned int ba;
4197+
4198+ err = get_user(ba, (unsigned int *)regs->pc);
4199+
4200+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4201+ unsigned int addr;
4202+
4203+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4204+ regs->pc = addr;
4205+ regs->npc = addr+4;
4206+ return 2;
4207+ }
4208+ }
4209+
4210+ do { /* PaX: patched PLT emulation #3 */
4211+ unsigned int sethi, jmpl, nop;
4212+
4213+ err = get_user(sethi, (unsigned int *)regs->pc);
4214+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4215+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
4216+
4217+ if (err)
4218+ break;
4219+
4220+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4221+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4222+ nop == 0x01000000U)
4223+ {
4224+ unsigned int addr;
4225+
4226+ addr = (sethi & 0x003FFFFFU) << 10;
4227+ regs->u_regs[UREG_G1] = addr;
4228+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4229+ regs->pc = addr;
4230+ regs->npc = addr+4;
4231+ return 2;
4232+ }
4233+ } while (0);
4234+
4235+ do { /* PaX: unpatched PLT emulation step 1 */
4236+ unsigned int sethi, ba, nop;
4237+
4238+ err = get_user(sethi, (unsigned int *)regs->pc);
4239+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
4240+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
4241+
4242+ if (err)
4243+ break;
4244+
4245+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4246+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4247+ nop == 0x01000000U)
4248+ {
4249+ unsigned int addr, save, call;
4250+
4251+ if ((ba & 0xFFC00000U) == 0x30800000U)
4252+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4253+ else
4254+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4255+
4256+ err = get_user(save, (unsigned int *)addr);
4257+ err |= get_user(call, (unsigned int *)(addr+4));
4258+ err |= get_user(nop, (unsigned int *)(addr+8));
4259+ if (err)
4260+ break;
4261+
4262+#ifdef CONFIG_PAX_DLRESOLVE
4263+ if (save == 0x9DE3BFA8U &&
4264+ (call & 0xC0000000U) == 0x40000000U &&
4265+ nop == 0x01000000U)
4266+ {
4267+ struct vm_area_struct *vma;
4268+ unsigned long call_dl_resolve;
4269+
4270+ down_read(&current->mm->mmap_sem);
4271+ call_dl_resolve = current->mm->call_dl_resolve;
4272+ up_read(&current->mm->mmap_sem);
4273+ if (likely(call_dl_resolve))
4274+ goto emulate;
4275+
4276+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4277+
4278+ down_write(&current->mm->mmap_sem);
4279+ if (current->mm->call_dl_resolve) {
4280+ call_dl_resolve = current->mm->call_dl_resolve;
4281+ up_write(&current->mm->mmap_sem);
4282+ if (vma)
4283+ kmem_cache_free(vm_area_cachep, vma);
4284+ goto emulate;
4285+ }
4286+
4287+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4288+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4289+ up_write(&current->mm->mmap_sem);
4290+ if (vma)
4291+ kmem_cache_free(vm_area_cachep, vma);
4292+ return 1;
4293+ }
4294+
4295+ if (pax_insert_vma(vma, call_dl_resolve)) {
4296+ up_write(&current->mm->mmap_sem);
4297+ kmem_cache_free(vm_area_cachep, vma);
4298+ return 1;
4299+ }
4300+
4301+ current->mm->call_dl_resolve = call_dl_resolve;
4302+ up_write(&current->mm->mmap_sem);
4303+
4304+emulate:
4305+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4306+ regs->pc = call_dl_resolve;
4307+ regs->npc = addr+4;
4308+ return 3;
4309+ }
4310+#endif
4311+
4312+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
4313+ if ((save & 0xFFC00000U) == 0x05000000U &&
4314+ (call & 0xFFFFE000U) == 0x85C0A000U &&
4315+ nop == 0x01000000U)
4316+ {
4317+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4318+ regs->u_regs[UREG_G2] = addr + 4;
4319+ addr = (save & 0x003FFFFFU) << 10;
4320+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4321+ regs->pc = addr;
4322+ regs->npc = addr+4;
4323+ return 3;
4324+ }
4325+ }
4326+ } while (0);
4327+
4328+ do { /* PaX: unpatched PLT emulation step 2 */
4329+ unsigned int save, call, nop;
4330+
4331+ err = get_user(save, (unsigned int *)(regs->pc-4));
4332+ err |= get_user(call, (unsigned int *)regs->pc);
4333+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
4334+ if (err)
4335+ break;
4336+
4337+ if (save == 0x9DE3BFA8U &&
4338+ (call & 0xC0000000U) == 0x40000000U &&
4339+ nop == 0x01000000U)
4340+ {
4341+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
4342+
4343+ regs->u_regs[UREG_RETPC] = regs->pc;
4344+ regs->pc = dl_resolve;
4345+ regs->npc = dl_resolve+4;
4346+ return 3;
4347+ }
4348+ } while (0);
4349+#endif
4350+
4351+ return 1;
4352+}
4353+
4354+void pax_report_insns(void *pc, void *sp)
4355+{
4356+ unsigned long i;
4357+
4358+ printk(KERN_ERR "PAX: bytes at PC: ");
4359+ for (i = 0; i < 8; i++) {
4360+ unsigned int c;
4361+ if (get_user(c, (unsigned int *)pc+i))
4362+ printk(KERN_CONT "???????? ");
4363+ else
4364+ printk(KERN_CONT "%08x ", c);
4365+ }
4366+ printk("\n");
4367+}
4368+#endif
4369+
4370 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
4371 int text_fault)
4372 {
4373@@ -281,6 +546,24 @@ good_area:
4374 if(!(vma->vm_flags & VM_WRITE))
4375 goto bad_area;
4376 } else {
4377+
4378+#ifdef CONFIG_PAX_PAGEEXEC
4379+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
4380+ up_read(&mm->mmap_sem);
4381+ switch (pax_handle_fetch_fault(regs)) {
4382+
4383+#ifdef CONFIG_PAX_EMUPLT
4384+ case 2:
4385+ case 3:
4386+ return;
4387+#endif
4388+
4389+ }
4390+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
4391+ do_group_exit(SIGKILL);
4392+ }
4393+#endif
4394+
4395 /* Allow reads even for write-only mappings */
4396 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
4397 goto bad_area;
4398diff -urNp linux-3.0.4/arch/sparc/mm/fault_64.c linux-3.0.4/arch/sparc/mm/fault_64.c
4399--- linux-3.0.4/arch/sparc/mm/fault_64.c 2011-07-21 22:17:23.000000000 -0400
4400+++ linux-3.0.4/arch/sparc/mm/fault_64.c 2011-08-23 21:48:14.000000000 -0400
4401@@ -21,6 +21,9 @@
4402 #include <linux/kprobes.h>
4403 #include <linux/kdebug.h>
4404 #include <linux/percpu.h>
4405+#include <linux/slab.h>
4406+#include <linux/pagemap.h>
4407+#include <linux/compiler.h>
4408
4409 #include <asm/page.h>
4410 #include <asm/pgtable.h>
4411@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
4412 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
4413 regs->tpc);
4414 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
4415- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
4416+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
4417 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
4418 dump_stack();
4419 unhandled_fault(regs->tpc, current, regs);
4420@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
4421 show_regs(regs);
4422 }
4423
4424+#ifdef CONFIG_PAX_PAGEEXEC
4425+#ifdef CONFIG_PAX_DLRESOLVE
4426+static void pax_emuplt_close(struct vm_area_struct *vma)
4427+{
4428+ vma->vm_mm->call_dl_resolve = 0UL;
4429+}
4430+
4431+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4432+{
4433+ unsigned int *kaddr;
4434+
4435+ vmf->page = alloc_page(GFP_HIGHUSER);
4436+ if (!vmf->page)
4437+ return VM_FAULT_OOM;
4438+
4439+ kaddr = kmap(vmf->page);
4440+ memset(kaddr, 0, PAGE_SIZE);
4441+ kaddr[0] = 0x9DE3BFA8U; /* save */
4442+ flush_dcache_page(vmf->page);
4443+ kunmap(vmf->page);
4444+ return VM_FAULT_MAJOR;
4445+}
4446+
4447+static const struct vm_operations_struct pax_vm_ops = {
4448+ .close = pax_emuplt_close,
4449+ .fault = pax_emuplt_fault
4450+};
4451+
4452+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4453+{
4454+ int ret;
4455+
4456+ INIT_LIST_HEAD(&vma->anon_vma_chain);
4457+ vma->vm_mm = current->mm;
4458+ vma->vm_start = addr;
4459+ vma->vm_end = addr + PAGE_SIZE;
4460+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4461+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4462+ vma->vm_ops = &pax_vm_ops;
4463+
4464+ ret = insert_vm_struct(current->mm, vma);
4465+ if (ret)
4466+ return ret;
4467+
4468+ ++current->mm->total_vm;
4469+ return 0;
4470+}
4471+#endif
4472+
4473+/*
4474+ * PaX: decide what to do with offenders (regs->tpc = fault address)
4475+ *
4476+ * returns 1 when task should be killed
4477+ * 2 when patched PLT trampoline was detected
4478+ * 3 when unpatched PLT trampoline was detected
4479+ */
4480+static int pax_handle_fetch_fault(struct pt_regs *regs)
4481+{
4482+
4483+#ifdef CONFIG_PAX_EMUPLT
4484+ int err;
4485+
4486+ do { /* PaX: patched PLT emulation #1 */
4487+ unsigned int sethi1, sethi2, jmpl;
4488+
4489+ err = get_user(sethi1, (unsigned int *)regs->tpc);
4490+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4491+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
4492+
4493+ if (err)
4494+ break;
4495+
4496+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4497+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
4498+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
4499+ {
4500+ unsigned long addr;
4501+
4502+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4503+ addr = regs->u_regs[UREG_G1];
4504+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4505+
4506+ if (test_thread_flag(TIF_32BIT))
4507+ addr &= 0xFFFFFFFFUL;
4508+
4509+ regs->tpc = addr;
4510+ regs->tnpc = addr+4;
4511+ return 2;
4512+ }
4513+ } while (0);
4514+
4515+ { /* PaX: patched PLT emulation #2 */
4516+ unsigned int ba;
4517+
4518+ err = get_user(ba, (unsigned int *)regs->tpc);
4519+
4520+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4521+ unsigned long addr;
4522+
4523+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4524+
4525+ if (test_thread_flag(TIF_32BIT))
4526+ addr &= 0xFFFFFFFFUL;
4527+
4528+ regs->tpc = addr;
4529+ regs->tnpc = addr+4;
4530+ return 2;
4531+ }
4532+ }
4533+
4534+ do { /* PaX: patched PLT emulation #3 */
4535+ unsigned int sethi, jmpl, nop;
4536+
4537+ err = get_user(sethi, (unsigned int *)regs->tpc);
4538+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
4539+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4540+
4541+ if (err)
4542+ break;
4543+
4544+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4545+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4546+ nop == 0x01000000U)
4547+ {
4548+ unsigned long addr;
4549+
4550+ addr = (sethi & 0x003FFFFFU) << 10;
4551+ regs->u_regs[UREG_G1] = addr;
4552+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4553+
4554+ if (test_thread_flag(TIF_32BIT))
4555+ addr &= 0xFFFFFFFFUL;
4556+
4557+ regs->tpc = addr;
4558+ regs->tnpc = addr+4;
4559+ return 2;
4560+ }
4561+ } while (0);
4562+
4563+ do { /* PaX: patched PLT emulation #4 */
4564+ unsigned int sethi, mov1, call, mov2;
4565+
4566+ err = get_user(sethi, (unsigned int *)regs->tpc);
4567+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
4568+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
4569+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
4570+
4571+ if (err)
4572+ break;
4573+
4574+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4575+ mov1 == 0x8210000FU &&
4576+ (call & 0xC0000000U) == 0x40000000U &&
4577+ mov2 == 0x9E100001U)
4578+ {
4579+ unsigned long addr;
4580+
4581+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
4582+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
4583+
4584+ if (test_thread_flag(TIF_32BIT))
4585+ addr &= 0xFFFFFFFFUL;
4586+
4587+ regs->tpc = addr;
4588+ regs->tnpc = addr+4;
4589+ return 2;
4590+ }
4591+ } while (0);
4592+
4593+ do { /* PaX: patched PLT emulation #5 */
4594+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
4595+
4596+ err = get_user(sethi, (unsigned int *)regs->tpc);
4597+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
4598+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
4599+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
4600+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
4601+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
4602+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
4603+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
4604+
4605+ if (err)
4606+ break;
4607+
4608+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4609+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
4610+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4611+ (or1 & 0xFFFFE000U) == 0x82106000U &&
4612+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
4613+ sllx == 0x83287020U &&
4614+ jmpl == 0x81C04005U &&
4615+ nop == 0x01000000U)
4616+ {
4617+ unsigned long addr;
4618+
4619+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
4620+ regs->u_regs[UREG_G1] <<= 32;
4621+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
4622+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
4623+ regs->tpc = addr;
4624+ regs->tnpc = addr+4;
4625+ return 2;
4626+ }
4627+ } while (0);
4628+
4629+ do { /* PaX: patched PLT emulation #6 */
4630+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
4631+
4632+ err = get_user(sethi, (unsigned int *)regs->tpc);
4633+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
4634+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
4635+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
4636+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
4637+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
4638+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
4639+
4640+ if (err)
4641+ break;
4642+
4643+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4644+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
4645+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4646+ sllx == 0x83287020U &&
4647+ (or & 0xFFFFE000U) == 0x8A116000U &&
4648+ jmpl == 0x81C04005U &&
4649+ nop == 0x01000000U)
4650+ {
4651+ unsigned long addr;
4652+
4653+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
4654+ regs->u_regs[UREG_G1] <<= 32;
4655+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
4656+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
4657+ regs->tpc = addr;
4658+ regs->tnpc = addr+4;
4659+ return 2;
4660+ }
4661+ } while (0);
4662+
4663+ do { /* PaX: unpatched PLT emulation step 1 */
4664+ unsigned int sethi, ba, nop;
4665+
4666+ err = get_user(sethi, (unsigned int *)regs->tpc);
4667+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
4668+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4669+
4670+ if (err)
4671+ break;
4672+
4673+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4674+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4675+ nop == 0x01000000U)
4676+ {
4677+ unsigned long addr;
4678+ unsigned int save, call;
4679+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
4680+
4681+ if ((ba & 0xFFC00000U) == 0x30800000U)
4682+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4683+ else
4684+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
4685+
4686+ if (test_thread_flag(TIF_32BIT))
4687+ addr &= 0xFFFFFFFFUL;
4688+
4689+ err = get_user(save, (unsigned int *)addr);
4690+ err |= get_user(call, (unsigned int *)(addr+4));
4691+ err |= get_user(nop, (unsigned int *)(addr+8));
4692+ if (err)
4693+ break;
4694+
4695+#ifdef CONFIG_PAX_DLRESOLVE
4696+ if (save == 0x9DE3BFA8U &&
4697+ (call & 0xC0000000U) == 0x40000000U &&
4698+ nop == 0x01000000U)
4699+ {
4700+ struct vm_area_struct *vma;
4701+ unsigned long call_dl_resolve;
4702+
4703+ down_read(&current->mm->mmap_sem);
4704+ call_dl_resolve = current->mm->call_dl_resolve;
4705+ up_read(&current->mm->mmap_sem);
4706+ if (likely(call_dl_resolve))
4707+ goto emulate;
4708+
4709+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4710+
4711+ down_write(&current->mm->mmap_sem);
4712+ if (current->mm->call_dl_resolve) {
4713+ call_dl_resolve = current->mm->call_dl_resolve;
4714+ up_write(&current->mm->mmap_sem);
4715+ if (vma)
4716+ kmem_cache_free(vm_area_cachep, vma);
4717+ goto emulate;
4718+ }
4719+
4720+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4721+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4722+ up_write(&current->mm->mmap_sem);
4723+ if (vma)
4724+ kmem_cache_free(vm_area_cachep, vma);
4725+ return 1;
4726+ }
4727+
4728+ if (pax_insert_vma(vma, call_dl_resolve)) {
4729+ up_write(&current->mm->mmap_sem);
4730+ kmem_cache_free(vm_area_cachep, vma);
4731+ return 1;
4732+ }
4733+
4734+ current->mm->call_dl_resolve = call_dl_resolve;
4735+ up_write(&current->mm->mmap_sem);
4736+
4737+emulate:
4738+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4739+ regs->tpc = call_dl_resolve;
4740+ regs->tnpc = addr+4;
4741+ return 3;
4742+ }
4743+#endif
4744+
4745+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
4746+ if ((save & 0xFFC00000U) == 0x05000000U &&
4747+ (call & 0xFFFFE000U) == 0x85C0A000U &&
4748+ nop == 0x01000000U)
4749+ {
4750+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4751+ regs->u_regs[UREG_G2] = addr + 4;
4752+ addr = (save & 0x003FFFFFU) << 10;
4753+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4754+
4755+ if (test_thread_flag(TIF_32BIT))
4756+ addr &= 0xFFFFFFFFUL;
4757+
4758+ regs->tpc = addr;
4759+ regs->tnpc = addr+4;
4760+ return 3;
4761+ }
4762+
4763+ /* PaX: 64-bit PLT stub */
4764+ err = get_user(sethi1, (unsigned int *)addr);
4765+ err |= get_user(sethi2, (unsigned int *)(addr+4));
4766+ err |= get_user(or1, (unsigned int *)(addr+8));
4767+ err |= get_user(or2, (unsigned int *)(addr+12));
4768+ err |= get_user(sllx, (unsigned int *)(addr+16));
4769+ err |= get_user(add, (unsigned int *)(addr+20));
4770+ err |= get_user(jmpl, (unsigned int *)(addr+24));
4771+ err |= get_user(nop, (unsigned int *)(addr+28));
4772+ if (err)
4773+ break;
4774+
4775+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
4776+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4777+ (or1 & 0xFFFFE000U) == 0x88112000U &&
4778+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
4779+ sllx == 0x89293020U &&
4780+ add == 0x8A010005U &&
4781+ jmpl == 0x89C14000U &&
4782+ nop == 0x01000000U)
4783+ {
4784+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4785+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
4786+ regs->u_regs[UREG_G4] <<= 32;
4787+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
4788+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
4789+ regs->u_regs[UREG_G4] = addr + 24;
4790+ addr = regs->u_regs[UREG_G5];
4791+ regs->tpc = addr;
4792+ regs->tnpc = addr+4;
4793+ return 3;
4794+ }
4795+ }
4796+ } while (0);
4797+
4798+#ifdef CONFIG_PAX_DLRESOLVE
4799+ do { /* PaX: unpatched PLT emulation step 2 */
4800+ unsigned int save, call, nop;
4801+
4802+ err = get_user(save, (unsigned int *)(regs->tpc-4));
4803+ err |= get_user(call, (unsigned int *)regs->tpc);
4804+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
4805+ if (err)
4806+ break;
4807+
4808+ if (save == 0x9DE3BFA8U &&
4809+ (call & 0xC0000000U) == 0x40000000U &&
4810+ nop == 0x01000000U)
4811+ {
4812+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
4813+
4814+ if (test_thread_flag(TIF_32BIT))
4815+ dl_resolve &= 0xFFFFFFFFUL;
4816+
4817+ regs->u_regs[UREG_RETPC] = regs->tpc;
4818+ regs->tpc = dl_resolve;
4819+ regs->tnpc = dl_resolve+4;
4820+ return 3;
4821+ }
4822+ } while (0);
4823+#endif
4824+
4825+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
4826+ unsigned int sethi, ba, nop;
4827+
4828+ err = get_user(sethi, (unsigned int *)regs->tpc);
4829+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
4830+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4831+
4832+ if (err)
4833+ break;
4834+
4835+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4836+ (ba & 0xFFF00000U) == 0x30600000U &&
4837+ nop == 0x01000000U)
4838+ {
4839+ unsigned long addr;
4840+
4841+ addr = (sethi & 0x003FFFFFU) << 10;
4842+ regs->u_regs[UREG_G1] = addr;
4843+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
4844+
4845+ if (test_thread_flag(TIF_32BIT))
4846+ addr &= 0xFFFFFFFFUL;
4847+
4848+ regs->tpc = addr;
4849+ regs->tnpc = addr+4;
4850+ return 2;
4851+ }
4852+ } while (0);
4853+
4854+#endif
4855+
4856+ return 1;
4857+}
4858+
4859+void pax_report_insns(void *pc, void *sp)
4860+{
4861+ unsigned long i;
4862+
4863+ printk(KERN_ERR "PAX: bytes at PC: ");
4864+ for (i = 0; i < 8; i++) {
4865+ unsigned int c;
4866+ if (get_user(c, (unsigned int *)pc+i))
4867+ printk(KERN_CONT "???????? ");
4868+ else
4869+ printk(KERN_CONT "%08x ", c);
4870+ }
4871+ printk("\n");
4872+}
4873+#endif
4874+
4875 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
4876 {
4877 struct mm_struct *mm = current->mm;
4878@@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
4879 if (!vma)
4880 goto bad_area;
4881
4882+#ifdef CONFIG_PAX_PAGEEXEC
4883+ /* PaX: detect ITLB misses on non-exec pages */
4884+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
4885+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
4886+ {
4887+ if (address != regs->tpc)
4888+ goto good_area;
4889+
4890+ up_read(&mm->mmap_sem);
4891+ switch (pax_handle_fetch_fault(regs)) {
4892+
4893+#ifdef CONFIG_PAX_EMUPLT
4894+ case 2:
4895+ case 3:
4896+ return;
4897+#endif
4898+
4899+ }
4900+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
4901+ do_group_exit(SIGKILL);
4902+ }
4903+#endif
4904+
4905 /* Pure DTLB misses do not tell us whether the fault causing
4906 * load/store/atomic was a write or not, it only says that there
4907 * was no match. So in such a case we (carefully) read the
4908diff -urNp linux-3.0.4/arch/sparc/mm/hugetlbpage.c linux-3.0.4/arch/sparc/mm/hugetlbpage.c
4909--- linux-3.0.4/arch/sparc/mm/hugetlbpage.c 2011-07-21 22:17:23.000000000 -0400
4910+++ linux-3.0.4/arch/sparc/mm/hugetlbpage.c 2011-08-23 21:47:55.000000000 -0400
4911@@ -68,7 +68,7 @@ full_search:
4912 }
4913 return -ENOMEM;
4914 }
4915- if (likely(!vma || addr + len <= vma->vm_start)) {
4916+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4917 /*
4918 * Remember the place where we stopped the search:
4919 */
4920@@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
4921 /* make sure it can fit in the remaining address space */
4922 if (likely(addr > len)) {
4923 vma = find_vma(mm, addr-len);
4924- if (!vma || addr <= vma->vm_start) {
4925+ if (check_heap_stack_gap(vma, addr - len, len)) {
4926 /* remember the address as a hint for next time */
4927 return (mm->free_area_cache = addr-len);
4928 }
4929@@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct
4930 if (unlikely(mm->mmap_base < len))
4931 goto bottomup;
4932
4933- addr = (mm->mmap_base-len) & HPAGE_MASK;
4934+ addr = mm->mmap_base - len;
4935
4936 do {
4937+ addr &= HPAGE_MASK;
4938 /*
4939 * Lookup failure means no vma is above this address,
4940 * else if new region fits below vma->vm_start,
4941 * return with success:
4942 */
4943 vma = find_vma(mm, addr);
4944- if (likely(!vma || addr+len <= vma->vm_start)) {
4945+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4946 /* remember the address as a hint for next time */
4947 return (mm->free_area_cache = addr);
4948 }
4949@@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct
4950 mm->cached_hole_size = vma->vm_start - addr;
4951
4952 /* try just below the current vma->vm_start */
4953- addr = (vma->vm_start-len) & HPAGE_MASK;
4954- } while (likely(len < vma->vm_start));
4955+ addr = skip_heap_stack_gap(vma, len);
4956+ } while (!IS_ERR_VALUE(addr));
4957
4958 bottomup:
4959 /*
4960@@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *f
4961 if (addr) {
4962 addr = ALIGN(addr, HPAGE_SIZE);
4963 vma = find_vma(mm, addr);
4964- if (task_size - len >= addr &&
4965- (!vma || addr + len <= vma->vm_start))
4966+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4967 return addr;
4968 }
4969 if (mm->get_unmapped_area == arch_get_unmapped_area)
4970diff -urNp linux-3.0.4/arch/sparc/mm/init_32.c linux-3.0.4/arch/sparc/mm/init_32.c
4971--- linux-3.0.4/arch/sparc/mm/init_32.c 2011-07-21 22:17:23.000000000 -0400
4972+++ linux-3.0.4/arch/sparc/mm/init_32.c 2011-08-23 21:47:55.000000000 -0400
4973@@ -316,6 +316,9 @@ extern void device_scan(void);
4974 pgprot_t PAGE_SHARED __read_mostly;
4975 EXPORT_SYMBOL(PAGE_SHARED);
4976
4977+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
4978+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
4979+
4980 void __init paging_init(void)
4981 {
4982 switch(sparc_cpu_model) {
4983@@ -344,17 +347,17 @@ void __init paging_init(void)
4984
4985 /* Initialize the protection map with non-constant, MMU dependent values. */
4986 protection_map[0] = PAGE_NONE;
4987- protection_map[1] = PAGE_READONLY;
4988- protection_map[2] = PAGE_COPY;
4989- protection_map[3] = PAGE_COPY;
4990+ protection_map[1] = PAGE_READONLY_NOEXEC;
4991+ protection_map[2] = PAGE_COPY_NOEXEC;
4992+ protection_map[3] = PAGE_COPY_NOEXEC;
4993 protection_map[4] = PAGE_READONLY;
4994 protection_map[5] = PAGE_READONLY;
4995 protection_map[6] = PAGE_COPY;
4996 protection_map[7] = PAGE_COPY;
4997 protection_map[8] = PAGE_NONE;
4998- protection_map[9] = PAGE_READONLY;
4999- protection_map[10] = PAGE_SHARED;
5000- protection_map[11] = PAGE_SHARED;
5001+ protection_map[9] = PAGE_READONLY_NOEXEC;
5002+ protection_map[10] = PAGE_SHARED_NOEXEC;
5003+ protection_map[11] = PAGE_SHARED_NOEXEC;
5004 protection_map[12] = PAGE_READONLY;
5005 protection_map[13] = PAGE_READONLY;
5006 protection_map[14] = PAGE_SHARED;
5007diff -urNp linux-3.0.4/arch/sparc/mm/Makefile linux-3.0.4/arch/sparc/mm/Makefile
5008--- linux-3.0.4/arch/sparc/mm/Makefile 2011-07-21 22:17:23.000000000 -0400
5009+++ linux-3.0.4/arch/sparc/mm/Makefile 2011-08-23 21:47:55.000000000 -0400
5010@@ -2,7 +2,7 @@
5011 #
5012
5013 asflags-y := -ansi
5014-ccflags-y := -Werror
5015+#ccflags-y := -Werror
5016
5017 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5018 obj-y += fault_$(BITS).o
5019diff -urNp linux-3.0.4/arch/sparc/mm/srmmu.c linux-3.0.4/arch/sparc/mm/srmmu.c
5020--- linux-3.0.4/arch/sparc/mm/srmmu.c 2011-07-21 22:17:23.000000000 -0400
5021+++ linux-3.0.4/arch/sparc/mm/srmmu.c 2011-08-23 21:47:55.000000000 -0400
5022@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5023 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5024 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5025 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5026+
5027+#ifdef CONFIG_PAX_PAGEEXEC
5028+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5029+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5030+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5031+#endif
5032+
5033 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5034 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5035
5036diff -urNp linux-3.0.4/arch/um/include/asm/kmap_types.h linux-3.0.4/arch/um/include/asm/kmap_types.h
5037--- linux-3.0.4/arch/um/include/asm/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
5038+++ linux-3.0.4/arch/um/include/asm/kmap_types.h 2011-08-23 21:47:55.000000000 -0400
5039@@ -23,6 +23,7 @@ enum km_type {
5040 KM_IRQ1,
5041 KM_SOFTIRQ0,
5042 KM_SOFTIRQ1,
5043+ KM_CLEARPAGE,
5044 KM_TYPE_NR
5045 };
5046
5047diff -urNp linux-3.0.4/arch/um/include/asm/page.h linux-3.0.4/arch/um/include/asm/page.h
5048--- linux-3.0.4/arch/um/include/asm/page.h 2011-07-21 22:17:23.000000000 -0400
5049+++ linux-3.0.4/arch/um/include/asm/page.h 2011-08-23 21:47:55.000000000 -0400
5050@@ -14,6 +14,9 @@
5051 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5052 #define PAGE_MASK (~(PAGE_SIZE-1))
5053
5054+#define ktla_ktva(addr) (addr)
5055+#define ktva_ktla(addr) (addr)
5056+
5057 #ifndef __ASSEMBLY__
5058
5059 struct page;
5060diff -urNp linux-3.0.4/arch/um/kernel/process.c linux-3.0.4/arch/um/kernel/process.c
5061--- linux-3.0.4/arch/um/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
5062+++ linux-3.0.4/arch/um/kernel/process.c 2011-08-23 21:47:55.000000000 -0400
5063@@ -404,22 +404,6 @@ int singlestepping(void * t)
5064 return 2;
5065 }
5066
5067-/*
5068- * Only x86 and x86_64 have an arch_align_stack().
5069- * All other arches have "#define arch_align_stack(x) (x)"
5070- * in their asm/system.h
5071- * As this is included in UML from asm-um/system-generic.h,
5072- * we can use it to behave as the subarch does.
5073- */
5074-#ifndef arch_align_stack
5075-unsigned long arch_align_stack(unsigned long sp)
5076-{
5077- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5078- sp -= get_random_int() % 8192;
5079- return sp & ~0xf;
5080-}
5081-#endif
5082-
5083 unsigned long get_wchan(struct task_struct *p)
5084 {
5085 unsigned long stack_page, sp, ip;
5086diff -urNp linux-3.0.4/arch/um/sys-i386/syscalls.c linux-3.0.4/arch/um/sys-i386/syscalls.c
5087--- linux-3.0.4/arch/um/sys-i386/syscalls.c 2011-07-21 22:17:23.000000000 -0400
5088+++ linux-3.0.4/arch/um/sys-i386/syscalls.c 2011-08-23 21:47:55.000000000 -0400
5089@@ -11,6 +11,21 @@
5090 #include "asm/uaccess.h"
5091 #include "asm/unistd.h"
5092
5093+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
5094+{
5095+ unsigned long pax_task_size = TASK_SIZE;
5096+
5097+#ifdef CONFIG_PAX_SEGMEXEC
5098+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
5099+ pax_task_size = SEGMEXEC_TASK_SIZE;
5100+#endif
5101+
5102+ if (len > pax_task_size || addr > pax_task_size - len)
5103+ return -EINVAL;
5104+
5105+ return 0;
5106+}
5107+
5108 /*
5109 * The prototype on i386 is:
5110 *
5111diff -urNp linux-3.0.4/arch/x86/boot/bitops.h linux-3.0.4/arch/x86/boot/bitops.h
5112--- linux-3.0.4/arch/x86/boot/bitops.h 2011-07-21 22:17:23.000000000 -0400
5113+++ linux-3.0.4/arch/x86/boot/bitops.h 2011-08-23 21:47:55.000000000 -0400
5114@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
5115 u8 v;
5116 const u32 *p = (const u32 *)addr;
5117
5118- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5119+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5120 return v;
5121 }
5122
5123@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
5124
5125 static inline void set_bit(int nr, void *addr)
5126 {
5127- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5128+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5129 }
5130
5131 #endif /* BOOT_BITOPS_H */
5132diff -urNp linux-3.0.4/arch/x86/boot/boot.h linux-3.0.4/arch/x86/boot/boot.h
5133--- linux-3.0.4/arch/x86/boot/boot.h 2011-07-21 22:17:23.000000000 -0400
5134+++ linux-3.0.4/arch/x86/boot/boot.h 2011-08-23 21:47:55.000000000 -0400
5135@@ -85,7 +85,7 @@ static inline void io_delay(void)
5136 static inline u16 ds(void)
5137 {
5138 u16 seg;
5139- asm("movw %%ds,%0" : "=rm" (seg));
5140+ asm volatile("movw %%ds,%0" : "=rm" (seg));
5141 return seg;
5142 }
5143
5144@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
5145 static inline int memcmp(const void *s1, const void *s2, size_t len)
5146 {
5147 u8 diff;
5148- asm("repe; cmpsb; setnz %0"
5149+ asm volatile("repe; cmpsb; setnz %0"
5150 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5151 return diff;
5152 }
5153diff -urNp linux-3.0.4/arch/x86/boot/compressed/head_32.S linux-3.0.4/arch/x86/boot/compressed/head_32.S
5154--- linux-3.0.4/arch/x86/boot/compressed/head_32.S 2011-07-21 22:17:23.000000000 -0400
5155+++ linux-3.0.4/arch/x86/boot/compressed/head_32.S 2011-08-23 21:47:55.000000000 -0400
5156@@ -76,7 +76,7 @@ ENTRY(startup_32)
5157 notl %eax
5158 andl %eax, %ebx
5159 #else
5160- movl $LOAD_PHYSICAL_ADDR, %ebx
5161+ movl $____LOAD_PHYSICAL_ADDR, %ebx
5162 #endif
5163
5164 /* Target address to relocate to for decompression */
5165@@ -162,7 +162,7 @@ relocated:
5166 * and where it was actually loaded.
5167 */
5168 movl %ebp, %ebx
5169- subl $LOAD_PHYSICAL_ADDR, %ebx
5170+ subl $____LOAD_PHYSICAL_ADDR, %ebx
5171 jz 2f /* Nothing to be done if loaded at compiled addr. */
5172 /*
5173 * Process relocations.
5174@@ -170,8 +170,7 @@ relocated:
5175
5176 1: subl $4, %edi
5177 movl (%edi), %ecx
5178- testl %ecx, %ecx
5179- jz 2f
5180+ jecxz 2f
5181 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5182 jmp 1b
5183 2:
5184diff -urNp linux-3.0.4/arch/x86/boot/compressed/head_64.S linux-3.0.4/arch/x86/boot/compressed/head_64.S
5185--- linux-3.0.4/arch/x86/boot/compressed/head_64.S 2011-07-21 22:17:23.000000000 -0400
5186+++ linux-3.0.4/arch/x86/boot/compressed/head_64.S 2011-08-23 21:47:55.000000000 -0400
5187@@ -91,7 +91,7 @@ ENTRY(startup_32)
5188 notl %eax
5189 andl %eax, %ebx
5190 #else
5191- movl $LOAD_PHYSICAL_ADDR, %ebx
5192+ movl $____LOAD_PHYSICAL_ADDR, %ebx
5193 #endif
5194
5195 /* Target address to relocate to for decompression */
5196@@ -233,7 +233,7 @@ ENTRY(startup_64)
5197 notq %rax
5198 andq %rax, %rbp
5199 #else
5200- movq $LOAD_PHYSICAL_ADDR, %rbp
5201+ movq $____LOAD_PHYSICAL_ADDR, %rbp
5202 #endif
5203
5204 /* Target address to relocate to for decompression */
5205diff -urNp linux-3.0.4/arch/x86/boot/compressed/Makefile linux-3.0.4/arch/x86/boot/compressed/Makefile
5206--- linux-3.0.4/arch/x86/boot/compressed/Makefile 2011-07-21 22:17:23.000000000 -0400
5207+++ linux-3.0.4/arch/x86/boot/compressed/Makefile 2011-08-23 21:47:55.000000000 -0400
5208@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=smal
5209 KBUILD_CFLAGS += $(cflags-y)
5210 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
5211 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
5212+ifdef CONSTIFY_PLUGIN
5213+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5214+endif
5215
5216 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5217 GCOV_PROFILE := n
5218diff -urNp linux-3.0.4/arch/x86/boot/compressed/misc.c linux-3.0.4/arch/x86/boot/compressed/misc.c
5219--- linux-3.0.4/arch/x86/boot/compressed/misc.c 2011-07-21 22:17:23.000000000 -0400
5220+++ linux-3.0.4/arch/x86/boot/compressed/misc.c 2011-08-23 21:47:55.000000000 -0400
5221@@ -310,7 +310,7 @@ static void parse_elf(void *output)
5222 case PT_LOAD:
5223 #ifdef CONFIG_RELOCATABLE
5224 dest = output;
5225- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
5226+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
5227 #else
5228 dest = (void *)(phdr->p_paddr);
5229 #endif
5230@@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *
5231 error("Destination address too large");
5232 #endif
5233 #ifndef CONFIG_RELOCATABLE
5234- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
5235+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
5236 error("Wrong destination address");
5237 #endif
5238
5239diff -urNp linux-3.0.4/arch/x86/boot/compressed/relocs.c linux-3.0.4/arch/x86/boot/compressed/relocs.c
5240--- linux-3.0.4/arch/x86/boot/compressed/relocs.c 2011-07-21 22:17:23.000000000 -0400
5241+++ linux-3.0.4/arch/x86/boot/compressed/relocs.c 2011-08-23 21:47:55.000000000 -0400
5242@@ -13,8 +13,11 @@
5243
5244 static void die(char *fmt, ...);
5245
5246+#include "../../../../include/generated/autoconf.h"
5247+
5248 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
5249 static Elf32_Ehdr ehdr;
5250+static Elf32_Phdr *phdr;
5251 static unsigned long reloc_count, reloc_idx;
5252 static unsigned long *relocs;
5253
5254@@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
5255 }
5256 }
5257
5258+static void read_phdrs(FILE *fp)
5259+{
5260+ unsigned int i;
5261+
5262+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
5263+ if (!phdr) {
5264+ die("Unable to allocate %d program headers\n",
5265+ ehdr.e_phnum);
5266+ }
5267+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
5268+ die("Seek to %d failed: %s\n",
5269+ ehdr.e_phoff, strerror(errno));
5270+ }
5271+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
5272+ die("Cannot read ELF program headers: %s\n",
5273+ strerror(errno));
5274+ }
5275+ for(i = 0; i < ehdr.e_phnum; i++) {
5276+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
5277+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
5278+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
5279+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
5280+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
5281+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
5282+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
5283+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
5284+ }
5285+
5286+}
5287+
5288 static void read_shdrs(FILE *fp)
5289 {
5290- int i;
5291+ unsigned int i;
5292 Elf32_Shdr shdr;
5293
5294 secs = calloc(ehdr.e_shnum, sizeof(struct section));
5295@@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
5296
5297 static void read_strtabs(FILE *fp)
5298 {
5299- int i;
5300+ unsigned int i;
5301 for (i = 0; i < ehdr.e_shnum; i++) {
5302 struct section *sec = &secs[i];
5303 if (sec->shdr.sh_type != SHT_STRTAB) {
5304@@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
5305
5306 static void read_symtabs(FILE *fp)
5307 {
5308- int i,j;
5309+ unsigned int i,j;
5310 for (i = 0; i < ehdr.e_shnum; i++) {
5311 struct section *sec = &secs[i];
5312 if (sec->shdr.sh_type != SHT_SYMTAB) {
5313@@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
5314
5315 static void read_relocs(FILE *fp)
5316 {
5317- int i,j;
5318+ unsigned int i,j;
5319+ uint32_t base;
5320+
5321 for (i = 0; i < ehdr.e_shnum; i++) {
5322 struct section *sec = &secs[i];
5323 if (sec->shdr.sh_type != SHT_REL) {
5324@@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
5325 die("Cannot read symbol table: %s\n",
5326 strerror(errno));
5327 }
5328+ base = 0;
5329+ for (j = 0; j < ehdr.e_phnum; j++) {
5330+ if (phdr[j].p_type != PT_LOAD )
5331+ continue;
5332+ 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)
5333+ continue;
5334+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
5335+ break;
5336+ }
5337 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
5338 Elf32_Rel *rel = &sec->reltab[j];
5339- rel->r_offset = elf32_to_cpu(rel->r_offset);
5340+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
5341 rel->r_info = elf32_to_cpu(rel->r_info);
5342 }
5343 }
5344@@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
5345
5346 static void print_absolute_symbols(void)
5347 {
5348- int i;
5349+ unsigned int i;
5350 printf("Absolute symbols\n");
5351 printf(" Num: Value Size Type Bind Visibility Name\n");
5352 for (i = 0; i < ehdr.e_shnum; i++) {
5353 struct section *sec = &secs[i];
5354 char *sym_strtab;
5355 Elf32_Sym *sh_symtab;
5356- int j;
5357+ unsigned int j;
5358
5359 if (sec->shdr.sh_type != SHT_SYMTAB) {
5360 continue;
5361@@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
5362
5363 static void print_absolute_relocs(void)
5364 {
5365- int i, printed = 0;
5366+ unsigned int i, printed = 0;
5367
5368 for (i = 0; i < ehdr.e_shnum; i++) {
5369 struct section *sec = &secs[i];
5370 struct section *sec_applies, *sec_symtab;
5371 char *sym_strtab;
5372 Elf32_Sym *sh_symtab;
5373- int j;
5374+ unsigned int j;
5375 if (sec->shdr.sh_type != SHT_REL) {
5376 continue;
5377 }
5378@@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
5379
5380 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
5381 {
5382- int i;
5383+ unsigned int i;
5384 /* Walk through the relocations */
5385 for (i = 0; i < ehdr.e_shnum; i++) {
5386 char *sym_strtab;
5387 Elf32_Sym *sh_symtab;
5388 struct section *sec_applies, *sec_symtab;
5389- int j;
5390+ unsigned int j;
5391 struct section *sec = &secs[i];
5392
5393 if (sec->shdr.sh_type != SHT_REL) {
5394@@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
5395 !is_rel_reloc(sym_name(sym_strtab, sym))) {
5396 continue;
5397 }
5398+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
5399+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
5400+ continue;
5401+
5402+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
5403+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
5404+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
5405+ continue;
5406+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
5407+ continue;
5408+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
5409+ continue;
5410+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
5411+ continue;
5412+#endif
5413+
5414 switch (r_type) {
5415 case R_386_NONE:
5416 case R_386_PC32:
5417@@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
5418
5419 static void emit_relocs(int as_text)
5420 {
5421- int i;
5422+ unsigned int i;
5423 /* Count how many relocations I have and allocate space for them. */
5424 reloc_count = 0;
5425 walk_relocs(count_reloc);
5426@@ -665,6 +725,7 @@ int main(int argc, char **argv)
5427 fname, strerror(errno));
5428 }
5429 read_ehdr(fp);
5430+ read_phdrs(fp);
5431 read_shdrs(fp);
5432 read_strtabs(fp);
5433 read_symtabs(fp);
5434diff -urNp linux-3.0.4/arch/x86/boot/cpucheck.c linux-3.0.4/arch/x86/boot/cpucheck.c
5435--- linux-3.0.4/arch/x86/boot/cpucheck.c 2011-07-21 22:17:23.000000000 -0400
5436+++ linux-3.0.4/arch/x86/boot/cpucheck.c 2011-08-23 21:47:55.000000000 -0400
5437@@ -74,7 +74,7 @@ static int has_fpu(void)
5438 u16 fcw = -1, fsw = -1;
5439 u32 cr0;
5440
5441- asm("movl %%cr0,%0" : "=r" (cr0));
5442+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
5443 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
5444 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
5445 asm volatile("movl %0,%%cr0" : : "r" (cr0));
5446@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
5447 {
5448 u32 f0, f1;
5449
5450- asm("pushfl ; "
5451+ asm volatile("pushfl ; "
5452 "pushfl ; "
5453 "popl %0 ; "
5454 "movl %0,%1 ; "
5455@@ -115,7 +115,7 @@ static void get_flags(void)
5456 set_bit(X86_FEATURE_FPU, cpu.flags);
5457
5458 if (has_eflag(X86_EFLAGS_ID)) {
5459- asm("cpuid"
5460+ asm volatile("cpuid"
5461 : "=a" (max_intel_level),
5462 "=b" (cpu_vendor[0]),
5463 "=d" (cpu_vendor[1]),
5464@@ -124,7 +124,7 @@ static void get_flags(void)
5465
5466 if (max_intel_level >= 0x00000001 &&
5467 max_intel_level <= 0x0000ffff) {
5468- asm("cpuid"
5469+ asm volatile("cpuid"
5470 : "=a" (tfms),
5471 "=c" (cpu.flags[4]),
5472 "=d" (cpu.flags[0])
5473@@ -136,7 +136,7 @@ static void get_flags(void)
5474 cpu.model += ((tfms >> 16) & 0xf) << 4;
5475 }
5476
5477- asm("cpuid"
5478+ asm volatile("cpuid"
5479 : "=a" (max_amd_level)
5480 : "a" (0x80000000)
5481 : "ebx", "ecx", "edx");
5482@@ -144,7 +144,7 @@ static void get_flags(void)
5483 if (max_amd_level >= 0x80000001 &&
5484 max_amd_level <= 0x8000ffff) {
5485 u32 eax = 0x80000001;
5486- asm("cpuid"
5487+ asm volatile("cpuid"
5488 : "+a" (eax),
5489 "=c" (cpu.flags[6]),
5490 "=d" (cpu.flags[1])
5491@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
5492 u32 ecx = MSR_K7_HWCR;
5493 u32 eax, edx;
5494
5495- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5496+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5497 eax &= ~(1 << 15);
5498- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5499+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5500
5501 get_flags(); /* Make sure it really did something */
5502 err = check_flags();
5503@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
5504 u32 ecx = MSR_VIA_FCR;
5505 u32 eax, edx;
5506
5507- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5508+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5509 eax |= (1<<1)|(1<<7);
5510- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5511+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5512
5513 set_bit(X86_FEATURE_CX8, cpu.flags);
5514 err = check_flags();
5515@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
5516 u32 eax, edx;
5517 u32 level = 1;
5518
5519- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5520- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
5521- asm("cpuid"
5522+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5523+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
5524+ asm volatile("cpuid"
5525 : "+a" (level), "=d" (cpu.flags[0])
5526 : : "ecx", "ebx");
5527- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5528+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5529
5530 err = check_flags();
5531 }
5532diff -urNp linux-3.0.4/arch/x86/boot/header.S linux-3.0.4/arch/x86/boot/header.S
5533--- linux-3.0.4/arch/x86/boot/header.S 2011-07-21 22:17:23.000000000 -0400
5534+++ linux-3.0.4/arch/x86/boot/header.S 2011-08-23 21:47:55.000000000 -0400
5535@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
5536 # single linked list of
5537 # struct setup_data
5538
5539-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
5540+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
5541
5542 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
5543 #define VO_INIT_SIZE (VO__end - VO__text)
5544diff -urNp linux-3.0.4/arch/x86/boot/Makefile linux-3.0.4/arch/x86/boot/Makefile
5545--- linux-3.0.4/arch/x86/boot/Makefile 2011-07-21 22:17:23.000000000 -0400
5546+++ linux-3.0.4/arch/x86/boot/Makefile 2011-08-23 21:47:55.000000000 -0400
5547@@ -69,6 +69,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
5548 $(call cc-option, -fno-stack-protector) \
5549 $(call cc-option, -mpreferred-stack-boundary=2)
5550 KBUILD_CFLAGS += $(call cc-option, -m32)
5551+ifdef CONSTIFY_PLUGIN
5552+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5553+endif
5554 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5555 GCOV_PROFILE := n
5556
5557diff -urNp linux-3.0.4/arch/x86/boot/memory.c linux-3.0.4/arch/x86/boot/memory.c
5558--- linux-3.0.4/arch/x86/boot/memory.c 2011-07-21 22:17:23.000000000 -0400
5559+++ linux-3.0.4/arch/x86/boot/memory.c 2011-08-23 21:47:55.000000000 -0400
5560@@ -19,7 +19,7 @@
5561
5562 static int detect_memory_e820(void)
5563 {
5564- int count = 0;
5565+ unsigned int count = 0;
5566 struct biosregs ireg, oreg;
5567 struct e820entry *desc = boot_params.e820_map;
5568 static struct e820entry buf; /* static so it is zeroed */
5569diff -urNp linux-3.0.4/arch/x86/boot/video.c linux-3.0.4/arch/x86/boot/video.c
5570--- linux-3.0.4/arch/x86/boot/video.c 2011-07-21 22:17:23.000000000 -0400
5571+++ linux-3.0.4/arch/x86/boot/video.c 2011-08-23 21:47:55.000000000 -0400
5572@@ -96,7 +96,7 @@ static void store_mode_params(void)
5573 static unsigned int get_entry(void)
5574 {
5575 char entry_buf[4];
5576- int i, len = 0;
5577+ unsigned int i, len = 0;
5578 int key;
5579 unsigned int v;
5580
5581diff -urNp linux-3.0.4/arch/x86/boot/video-vesa.c linux-3.0.4/arch/x86/boot/video-vesa.c
5582--- linux-3.0.4/arch/x86/boot/video-vesa.c 2011-07-21 22:17:23.000000000 -0400
5583+++ linux-3.0.4/arch/x86/boot/video-vesa.c 2011-08-23 21:47:55.000000000 -0400
5584@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
5585
5586 boot_params.screen_info.vesapm_seg = oreg.es;
5587 boot_params.screen_info.vesapm_off = oreg.di;
5588+ boot_params.screen_info.vesapm_size = oreg.cx;
5589 }
5590
5591 /*
5592diff -urNp linux-3.0.4/arch/x86/ia32/ia32_aout.c linux-3.0.4/arch/x86/ia32/ia32_aout.c
5593--- linux-3.0.4/arch/x86/ia32/ia32_aout.c 2011-07-21 22:17:23.000000000 -0400
5594+++ linux-3.0.4/arch/x86/ia32/ia32_aout.c 2011-08-23 21:48:14.000000000 -0400
5595@@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
5596 unsigned long dump_start, dump_size;
5597 struct user32 dump;
5598
5599+ memset(&dump, 0, sizeof(dump));
5600+
5601 fs = get_fs();
5602 set_fs(KERNEL_DS);
5603 has_dumped = 1;
5604diff -urNp linux-3.0.4/arch/x86/ia32/ia32entry.S linux-3.0.4/arch/x86/ia32/ia32entry.S
5605--- linux-3.0.4/arch/x86/ia32/ia32entry.S 2011-07-21 22:17:23.000000000 -0400
5606+++ linux-3.0.4/arch/x86/ia32/ia32entry.S 2011-08-25 17:36:37.000000000 -0400
5607@@ -13,6 +13,7 @@
5608 #include <asm/thread_info.h>
5609 #include <asm/segment.h>
5610 #include <asm/irqflags.h>
5611+#include <asm/pgtable.h>
5612 #include <linux/linkage.h>
5613
5614 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
5615@@ -95,6 +96,29 @@ ENTRY(native_irq_enable_sysexit)
5616 ENDPROC(native_irq_enable_sysexit)
5617 #endif
5618
5619+ .macro pax_enter_kernel_user
5620+#ifdef CONFIG_PAX_MEMORY_UDEREF
5621+ call pax_enter_kernel_user
5622+#endif
5623+ .endm
5624+
5625+ .macro pax_exit_kernel_user
5626+#ifdef CONFIG_PAX_MEMORY_UDEREF
5627+ call pax_exit_kernel_user
5628+#endif
5629+#ifdef CONFIG_PAX_RANDKSTACK
5630+ pushq %rax
5631+ call pax_randomize_kstack
5632+ popq %rax
5633+#endif
5634+ .endm
5635+
5636+ .macro pax_erase_kstack
5637+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
5638+ call pax_erase_kstack
5639+#endif
5640+ .endm
5641+
5642 /*
5643 * 32bit SYSENTER instruction entry.
5644 *
5645@@ -121,7 +145,7 @@ ENTRY(ia32_sysenter_target)
5646 CFI_REGISTER rsp,rbp
5647 SWAPGS_UNSAFE_STACK
5648 movq PER_CPU_VAR(kernel_stack), %rsp
5649- addq $(KERNEL_STACK_OFFSET),%rsp
5650+ pax_enter_kernel_user
5651 /*
5652 * No need to follow this irqs on/off section: the syscall
5653 * disabled irqs, here we enable it straight after entry:
5654@@ -134,7 +158,8 @@ ENTRY(ia32_sysenter_target)
5655 CFI_REL_OFFSET rsp,0
5656 pushfq_cfi
5657 /*CFI_REL_OFFSET rflags,0*/
5658- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
5659+ GET_THREAD_INFO(%r10)
5660+ movl TI_sysenter_return(%r10), %r10d
5661 CFI_REGISTER rip,r10
5662 pushq_cfi $__USER32_CS
5663 /*CFI_REL_OFFSET cs,0*/
5664@@ -146,6 +171,12 @@ ENTRY(ia32_sysenter_target)
5665 SAVE_ARGS 0,0,1
5666 /* no need to do an access_ok check here because rbp has been
5667 32bit zero extended */
5668+
5669+#ifdef CONFIG_PAX_MEMORY_UDEREF
5670+ mov $PAX_USER_SHADOW_BASE,%r10
5671+ add %r10,%rbp
5672+#endif
5673+
5674 1: movl (%rbp),%ebp
5675 .section __ex_table,"a"
5676 .quad 1b,ia32_badarg
5677@@ -168,6 +199,8 @@ sysenter_dispatch:
5678 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
5679 jnz sysexit_audit
5680 sysexit_from_sys_call:
5681+ pax_exit_kernel_user
5682+ pax_erase_kstack
5683 andl $~TS_COMPAT,TI_status(%r10)
5684 /* clear IF, that popfq doesn't enable interrupts early */
5685 andl $~0x200,EFLAGS-R11(%rsp)
5686@@ -194,6 +227,9 @@ sysexit_from_sys_call:
5687 movl %eax,%esi /* 2nd arg: syscall number */
5688 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
5689 call audit_syscall_entry
5690+
5691+ pax_erase_kstack
5692+
5693 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
5694 cmpq $(IA32_NR_syscalls-1),%rax
5695 ja ia32_badsys
5696@@ -246,6 +282,9 @@ sysenter_tracesys:
5697 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
5698 movq %rsp,%rdi /* &pt_regs -> arg1 */
5699 call syscall_trace_enter
5700+
5701+ pax_erase_kstack
5702+
5703 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
5704 RESTORE_REST
5705 cmpq $(IA32_NR_syscalls-1),%rax
5706@@ -277,19 +316,24 @@ ENDPROC(ia32_sysenter_target)
5707 ENTRY(ia32_cstar_target)
5708 CFI_STARTPROC32 simple
5709 CFI_SIGNAL_FRAME
5710- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
5711+ CFI_DEF_CFA rsp,0
5712 CFI_REGISTER rip,rcx
5713 /*CFI_REGISTER rflags,r11*/
5714 SWAPGS_UNSAFE_STACK
5715 movl %esp,%r8d
5716 CFI_REGISTER rsp,r8
5717 movq PER_CPU_VAR(kernel_stack),%rsp
5718+
5719+#ifdef CONFIG_PAX_MEMORY_UDEREF
5720+ pax_enter_kernel_user
5721+#endif
5722+
5723 /*
5724 * No need to follow this irqs on/off section: the syscall
5725 * disabled irqs and here we enable it straight after entry:
5726 */
5727 ENABLE_INTERRUPTS(CLBR_NONE)
5728- SAVE_ARGS 8,1,1
5729+ SAVE_ARGS 8*6,1,1
5730 movl %eax,%eax /* zero extension */
5731 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
5732 movq %rcx,RIP-ARGOFFSET(%rsp)
5733@@ -305,6 +349,12 @@ ENTRY(ia32_cstar_target)
5734 /* no need to do an access_ok check here because r8 has been
5735 32bit zero extended */
5736 /* hardware stack frame is complete now */
5737+
5738+#ifdef CONFIG_PAX_MEMORY_UDEREF
5739+ mov $PAX_USER_SHADOW_BASE,%r10
5740+ add %r10,%r8
5741+#endif
5742+
5743 1: movl (%r8),%r9d
5744 .section __ex_table,"a"
5745 .quad 1b,ia32_badarg
5746@@ -327,6 +377,8 @@ cstar_dispatch:
5747 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
5748 jnz sysretl_audit
5749 sysretl_from_sys_call:
5750+ pax_exit_kernel_user
5751+ pax_erase_kstack
5752 andl $~TS_COMPAT,TI_status(%r10)
5753 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
5754 movl RIP-ARGOFFSET(%rsp),%ecx
5755@@ -364,6 +416,9 @@ cstar_tracesys:
5756 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
5757 movq %rsp,%rdi /* &pt_regs -> arg1 */
5758 call syscall_trace_enter
5759+
5760+ pax_erase_kstack
5761+
5762 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
5763 RESTORE_REST
5764 xchgl %ebp,%r9d
5765@@ -409,6 +464,7 @@ ENTRY(ia32_syscall)
5766 CFI_REL_OFFSET rip,RIP-RIP
5767 PARAVIRT_ADJUST_EXCEPTION_FRAME
5768 SWAPGS
5769+ pax_enter_kernel_user
5770 /*
5771 * No need to follow this irqs on/off section: the syscall
5772 * disabled irqs and here we enable it straight after entry:
5773@@ -441,6 +497,9 @@ ia32_tracesys:
5774 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
5775 movq %rsp,%rdi /* &pt_regs -> arg1 */
5776 call syscall_trace_enter
5777+
5778+ pax_erase_kstack
5779+
5780 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
5781 RESTORE_REST
5782 cmpq $(IA32_NR_syscalls-1),%rax
5783diff -urNp linux-3.0.4/arch/x86/ia32/ia32_signal.c linux-3.0.4/arch/x86/ia32/ia32_signal.c
5784--- linux-3.0.4/arch/x86/ia32/ia32_signal.c 2011-07-21 22:17:23.000000000 -0400
5785+++ linux-3.0.4/arch/x86/ia32/ia32_signal.c 2011-08-23 21:47:55.000000000 -0400
5786@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
5787 sp -= frame_size;
5788 /* Align the stack pointer according to the i386 ABI,
5789 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
5790- sp = ((sp + 4) & -16ul) - 4;
5791+ sp = ((sp - 12) & -16ul) - 4;
5792 return (void __user *) sp;
5793 }
5794
5795@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
5796 * These are actually not used anymore, but left because some
5797 * gdb versions depend on them as a marker.
5798 */
5799- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
5800+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
5801 } put_user_catch(err);
5802
5803 if (err)
5804@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
5805 0xb8,
5806 __NR_ia32_rt_sigreturn,
5807 0x80cd,
5808- 0,
5809+ 0
5810 };
5811
5812 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
5813@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
5814
5815 if (ka->sa.sa_flags & SA_RESTORER)
5816 restorer = ka->sa.sa_restorer;
5817+ else if (current->mm->context.vdso)
5818+ /* Return stub is in 32bit vsyscall page */
5819+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
5820 else
5821- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
5822- rt_sigreturn);
5823+ restorer = &frame->retcode;
5824 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
5825
5826 /*
5827 * Not actually used anymore, but left because some gdb
5828 * versions need it.
5829 */
5830- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
5831+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
5832 } put_user_catch(err);
5833
5834 if (err)
5835diff -urNp linux-3.0.4/arch/x86/include/asm/alternative.h linux-3.0.4/arch/x86/include/asm/alternative.h
5836--- linux-3.0.4/arch/x86/include/asm/alternative.h 2011-07-21 22:17:23.000000000 -0400
5837+++ linux-3.0.4/arch/x86/include/asm/alternative.h 2011-08-23 21:47:55.000000000 -0400
5838@@ -93,7 +93,7 @@ static inline int alternatives_text_rese
5839 ".section .discard,\"aw\",@progbits\n" \
5840 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
5841 ".previous\n" \
5842- ".section .altinstr_replacement, \"ax\"\n" \
5843+ ".section .altinstr_replacement, \"a\"\n" \
5844 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
5845 ".previous"
5846
5847diff -urNp linux-3.0.4/arch/x86/include/asm/apic.h linux-3.0.4/arch/x86/include/asm/apic.h
5848--- linux-3.0.4/arch/x86/include/asm/apic.h 2011-07-21 22:17:23.000000000 -0400
5849+++ linux-3.0.4/arch/x86/include/asm/apic.h 2011-08-23 21:48:14.000000000 -0400
5850@@ -45,7 +45,7 @@ static inline void generic_apic_probe(vo
5851
5852 #ifdef CONFIG_X86_LOCAL_APIC
5853
5854-extern unsigned int apic_verbosity;
5855+extern int apic_verbosity;
5856 extern int local_apic_timer_c2_ok;
5857
5858 extern int disable_apic;
5859diff -urNp linux-3.0.4/arch/x86/include/asm/apm.h linux-3.0.4/arch/x86/include/asm/apm.h
5860--- linux-3.0.4/arch/x86/include/asm/apm.h 2011-07-21 22:17:23.000000000 -0400
5861+++ linux-3.0.4/arch/x86/include/asm/apm.h 2011-08-23 21:47:55.000000000 -0400
5862@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
5863 __asm__ __volatile__(APM_DO_ZERO_SEGS
5864 "pushl %%edi\n\t"
5865 "pushl %%ebp\n\t"
5866- "lcall *%%cs:apm_bios_entry\n\t"
5867+ "lcall *%%ss:apm_bios_entry\n\t"
5868 "setc %%al\n\t"
5869 "popl %%ebp\n\t"
5870 "popl %%edi\n\t"
5871@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
5872 __asm__ __volatile__(APM_DO_ZERO_SEGS
5873 "pushl %%edi\n\t"
5874 "pushl %%ebp\n\t"
5875- "lcall *%%cs:apm_bios_entry\n\t"
5876+ "lcall *%%ss:apm_bios_entry\n\t"
5877 "setc %%bl\n\t"
5878 "popl %%ebp\n\t"
5879 "popl %%edi\n\t"
5880diff -urNp linux-3.0.4/arch/x86/include/asm/atomic64_32.h linux-3.0.4/arch/x86/include/asm/atomic64_32.h
5881--- linux-3.0.4/arch/x86/include/asm/atomic64_32.h 2011-07-21 22:17:23.000000000 -0400
5882+++ linux-3.0.4/arch/x86/include/asm/atomic64_32.h 2011-08-23 21:47:55.000000000 -0400
5883@@ -12,6 +12,14 @@ typedef struct {
5884 u64 __aligned(8) counter;
5885 } atomic64_t;
5886
5887+#ifdef CONFIG_PAX_REFCOUNT
5888+typedef struct {
5889+ u64 __aligned(8) counter;
5890+} atomic64_unchecked_t;
5891+#else
5892+typedef atomic64_t atomic64_unchecked_t;
5893+#endif
5894+
5895 #define ATOMIC64_INIT(val) { (val) }
5896
5897 #ifdef CONFIG_X86_CMPXCHG64
5898@@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg
5899 }
5900
5901 /**
5902+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
5903+ * @p: pointer to type atomic64_unchecked_t
5904+ * @o: expected value
5905+ * @n: new value
5906+ *
5907+ * Atomically sets @v to @n if it was equal to @o and returns
5908+ * the old value.
5909+ */
5910+
5911+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
5912+{
5913+ return cmpxchg64(&v->counter, o, n);
5914+}
5915+
5916+/**
5917 * atomic64_xchg - xchg atomic64 variable
5918 * @v: pointer to type atomic64_t
5919 * @n: value to assign
5920@@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64
5921 }
5922
5923 /**
5924+ * atomic64_set_unchecked - set atomic64 variable
5925+ * @v: pointer to type atomic64_unchecked_t
5926+ * @n: value to assign
5927+ *
5928+ * Atomically sets the value of @v to @n.
5929+ */
5930+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
5931+{
5932+ unsigned high = (unsigned)(i >> 32);
5933+ unsigned low = (unsigned)i;
5934+ asm volatile(ATOMIC64_ALTERNATIVE(set)
5935+ : "+b" (low), "+c" (high)
5936+ : "S" (v)
5937+ : "eax", "edx", "memory"
5938+ );
5939+}
5940+
5941+/**
5942 * atomic64_read - read atomic64 variable
5943 * @v: pointer to type atomic64_t
5944 *
5945@@ -93,6 +134,22 @@ static inline long long atomic64_read(at
5946 }
5947
5948 /**
5949+ * atomic64_read_unchecked - read atomic64 variable
5950+ * @v: pointer to type atomic64_unchecked_t
5951+ *
5952+ * Atomically reads the value of @v and returns it.
5953+ */
5954+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
5955+{
5956+ long long r;
5957+ asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
5958+ : "=A" (r), "+c" (v)
5959+ : : "memory"
5960+ );
5961+ return r;
5962+ }
5963+
5964+/**
5965 * atomic64_add_return - add and return
5966 * @i: integer value to add
5967 * @v: pointer to type atomic64_t
5968@@ -108,6 +165,22 @@ static inline long long atomic64_add_ret
5969 return i;
5970 }
5971
5972+/**
5973+ * atomic64_add_return_unchecked - add and return
5974+ * @i: integer value to add
5975+ * @v: pointer to type atomic64_unchecked_t
5976+ *
5977+ * Atomically adds @i to @v and returns @i + *@v
5978+ */
5979+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
5980+{
5981+ asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
5982+ : "+A" (i), "+c" (v)
5983+ : : "memory"
5984+ );
5985+ return i;
5986+}
5987+
5988 /*
5989 * Other variants with different arithmetic operators:
5990 */
5991@@ -131,6 +204,17 @@ static inline long long atomic64_inc_ret
5992 return a;
5993 }
5994
5995+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5996+{
5997+ long long a;
5998+ asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
5999+ : "=A" (a)
6000+ : "S" (v)
6001+ : "memory", "ecx"
6002+ );
6003+ return a;
6004+}
6005+
6006 static inline long long atomic64_dec_return(atomic64_t *v)
6007 {
6008 long long a;
6009@@ -159,6 +243,22 @@ static inline long long atomic64_add(lon
6010 }
6011
6012 /**
6013+ * atomic64_add_unchecked - add integer to atomic64 variable
6014+ * @i: integer value to add
6015+ * @v: pointer to type atomic64_unchecked_t
6016+ *
6017+ * Atomically adds @i to @v.
6018+ */
6019+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
6020+{
6021+ asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
6022+ : "+A" (i), "+c" (v)
6023+ : : "memory"
6024+ );
6025+ return i;
6026+}
6027+
6028+/**
6029 * atomic64_sub - subtract the atomic64 variable
6030 * @i: integer value to subtract
6031 * @v: pointer to type atomic64_t
6032diff -urNp linux-3.0.4/arch/x86/include/asm/atomic64_64.h linux-3.0.4/arch/x86/include/asm/atomic64_64.h
6033--- linux-3.0.4/arch/x86/include/asm/atomic64_64.h 2011-07-21 22:17:23.000000000 -0400
6034+++ linux-3.0.4/arch/x86/include/asm/atomic64_64.h 2011-08-23 21:47:55.000000000 -0400
6035@@ -18,7 +18,19 @@
6036 */
6037 static inline long atomic64_read(const atomic64_t *v)
6038 {
6039- return (*(volatile long *)&(v)->counter);
6040+ return (*(volatile const long *)&(v)->counter);
6041+}
6042+
6043+/**
6044+ * atomic64_read_unchecked - read atomic64 variable
6045+ * @v: pointer of type atomic64_unchecked_t
6046+ *
6047+ * Atomically reads the value of @v.
6048+ * Doesn't imply a read memory barrier.
6049+ */
6050+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6051+{
6052+ return (*(volatile const long *)&(v)->counter);
6053 }
6054
6055 /**
6056@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
6057 }
6058
6059 /**
6060+ * atomic64_set_unchecked - set atomic64 variable
6061+ * @v: pointer to type atomic64_unchecked_t
6062+ * @i: required value
6063+ *
6064+ * Atomically sets the value of @v to @i.
6065+ */
6066+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6067+{
6068+ v->counter = i;
6069+}
6070+
6071+/**
6072 * atomic64_add - add integer to atomic64 variable
6073 * @i: integer value to add
6074 * @v: pointer to type atomic64_t
6075@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
6076 */
6077 static inline void atomic64_add(long i, atomic64_t *v)
6078 {
6079+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
6080+
6081+#ifdef CONFIG_PAX_REFCOUNT
6082+ "jno 0f\n"
6083+ LOCK_PREFIX "subq %1,%0\n"
6084+ "int $4\n0:\n"
6085+ _ASM_EXTABLE(0b, 0b)
6086+#endif
6087+
6088+ : "=m" (v->counter)
6089+ : "er" (i), "m" (v->counter));
6090+}
6091+
6092+/**
6093+ * atomic64_add_unchecked - add integer to atomic64 variable
6094+ * @i: integer value to add
6095+ * @v: pointer to type atomic64_unchecked_t
6096+ *
6097+ * Atomically adds @i to @v.
6098+ */
6099+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6100+{
6101 asm volatile(LOCK_PREFIX "addq %1,%0"
6102 : "=m" (v->counter)
6103 : "er" (i), "m" (v->counter));
6104@@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
6105 */
6106 static inline void atomic64_sub(long i, atomic64_t *v)
6107 {
6108- asm volatile(LOCK_PREFIX "subq %1,%0"
6109+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
6110+
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ "jno 0f\n"
6113+ LOCK_PREFIX "addq %1,%0\n"
6114+ "int $4\n0:\n"
6115+ _ASM_EXTABLE(0b, 0b)
6116+#endif
6117+
6118+ : "=m" (v->counter)
6119+ : "er" (i), "m" (v->counter));
6120+}
6121+
6122+/**
6123+ * atomic64_sub_unchecked - subtract the atomic64 variable
6124+ * @i: integer value to subtract
6125+ * @v: pointer to type atomic64_unchecked_t
6126+ *
6127+ * Atomically subtracts @i from @v.
6128+ */
6129+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6130+{
6131+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
6132 : "=m" (v->counter)
6133 : "er" (i), "m" (v->counter));
6134 }
6135@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
6136 {
6137 unsigned char c;
6138
6139- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
6140+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
6141+
6142+#ifdef CONFIG_PAX_REFCOUNT
6143+ "jno 0f\n"
6144+ LOCK_PREFIX "addq %2,%0\n"
6145+ "int $4\n0:\n"
6146+ _ASM_EXTABLE(0b, 0b)
6147+#endif
6148+
6149+ "sete %1\n"
6150 : "=m" (v->counter), "=qm" (c)
6151 : "er" (i), "m" (v->counter) : "memory");
6152 return c;
6153@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
6154 */
6155 static inline void atomic64_inc(atomic64_t *v)
6156 {
6157+ asm volatile(LOCK_PREFIX "incq %0\n"
6158+
6159+#ifdef CONFIG_PAX_REFCOUNT
6160+ "jno 0f\n"
6161+ LOCK_PREFIX "decq %0\n"
6162+ "int $4\n0:\n"
6163+ _ASM_EXTABLE(0b, 0b)
6164+#endif
6165+
6166+ : "=m" (v->counter)
6167+ : "m" (v->counter));
6168+}
6169+
6170+/**
6171+ * atomic64_inc_unchecked - increment atomic64 variable
6172+ * @v: pointer to type atomic64_unchecked_t
6173+ *
6174+ * Atomically increments @v by 1.
6175+ */
6176+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6177+{
6178 asm volatile(LOCK_PREFIX "incq %0"
6179 : "=m" (v->counter)
6180 : "m" (v->counter));
6181@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
6182 */
6183 static inline void atomic64_dec(atomic64_t *v)
6184 {
6185- asm volatile(LOCK_PREFIX "decq %0"
6186+ asm volatile(LOCK_PREFIX "decq %0\n"
6187+
6188+#ifdef CONFIG_PAX_REFCOUNT
6189+ "jno 0f\n"
6190+ LOCK_PREFIX "incq %0\n"
6191+ "int $4\n0:\n"
6192+ _ASM_EXTABLE(0b, 0b)
6193+#endif
6194+
6195+ : "=m" (v->counter)
6196+ : "m" (v->counter));
6197+}
6198+
6199+/**
6200+ * atomic64_dec_unchecked - decrement atomic64 variable
6201+ * @v: pointer to type atomic64_t
6202+ *
6203+ * Atomically decrements @v by 1.
6204+ */
6205+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6206+{
6207+ asm volatile(LOCK_PREFIX "decq %0\n"
6208 : "=m" (v->counter)
6209 : "m" (v->counter));
6210 }
6211@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
6212 {
6213 unsigned char c;
6214
6215- asm volatile(LOCK_PREFIX "decq %0; sete %1"
6216+ asm volatile(LOCK_PREFIX "decq %0\n"
6217+
6218+#ifdef CONFIG_PAX_REFCOUNT
6219+ "jno 0f\n"
6220+ LOCK_PREFIX "incq %0\n"
6221+ "int $4\n0:\n"
6222+ _ASM_EXTABLE(0b, 0b)
6223+#endif
6224+
6225+ "sete %1\n"
6226 : "=m" (v->counter), "=qm" (c)
6227 : "m" (v->counter) : "memory");
6228 return c != 0;
6229@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
6230 {
6231 unsigned char c;
6232
6233- asm volatile(LOCK_PREFIX "incq %0; sete %1"
6234+ asm volatile(LOCK_PREFIX "incq %0\n"
6235+
6236+#ifdef CONFIG_PAX_REFCOUNT
6237+ "jno 0f\n"
6238+ LOCK_PREFIX "decq %0\n"
6239+ "int $4\n0:\n"
6240+ _ASM_EXTABLE(0b, 0b)
6241+#endif
6242+
6243+ "sete %1\n"
6244 : "=m" (v->counter), "=qm" (c)
6245 : "m" (v->counter) : "memory");
6246 return c != 0;
6247@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
6248 {
6249 unsigned char c;
6250
6251- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
6252+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
6253+
6254+#ifdef CONFIG_PAX_REFCOUNT
6255+ "jno 0f\n"
6256+ LOCK_PREFIX "subq %2,%0\n"
6257+ "int $4\n0:\n"
6258+ _ASM_EXTABLE(0b, 0b)
6259+#endif
6260+
6261+ "sets %1\n"
6262 : "=m" (v->counter), "=qm" (c)
6263 : "er" (i), "m" (v->counter) : "memory");
6264 return c;
6265@@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
6266 static inline long atomic64_add_return(long i, atomic64_t *v)
6267 {
6268 long __i = i;
6269- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
6270+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
6271+
6272+#ifdef CONFIG_PAX_REFCOUNT
6273+ "jno 0f\n"
6274+ "movq %0, %1\n"
6275+ "int $4\n0:\n"
6276+ _ASM_EXTABLE(0b, 0b)
6277+#endif
6278+
6279+ : "+r" (i), "+m" (v->counter)
6280+ : : "memory");
6281+ return i + __i;
6282+}
6283+
6284+/**
6285+ * atomic64_add_return_unchecked - add and return
6286+ * @i: integer value to add
6287+ * @v: pointer to type atomic64_unchecked_t
6288+ *
6289+ * Atomically adds @i to @v and returns @i + @v
6290+ */
6291+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6292+{
6293+ long __i = i;
6294+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
6295 : "+r" (i), "+m" (v->counter)
6296 : : "memory");
6297 return i + __i;
6298@@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
6299 }
6300
6301 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
6302+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6303+{
6304+ return atomic64_add_return_unchecked(1, v);
6305+}
6306 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
6307
6308 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6309@@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atom
6310 return cmpxchg(&v->counter, old, new);
6311 }
6312
6313+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
6314+{
6315+ return cmpxchg(&v->counter, old, new);
6316+}
6317+
6318 static inline long atomic64_xchg(atomic64_t *v, long new)
6319 {
6320 return xchg(&v->counter, new);
6321@@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic6
6322 */
6323 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
6324 {
6325- long c, old;
6326+ long c, old, new;
6327 c = atomic64_read(v);
6328 for (;;) {
6329- if (unlikely(c == (u)))
6330+ if (unlikely(c == u))
6331 break;
6332- old = atomic64_cmpxchg((v), c, c + (a));
6333+
6334+ asm volatile("add %2,%0\n"
6335+
6336+#ifdef CONFIG_PAX_REFCOUNT
6337+ "jno 0f\n"
6338+ "sub %2,%0\n"
6339+ "int $4\n0:\n"
6340+ _ASM_EXTABLE(0b, 0b)
6341+#endif
6342+
6343+ : "=r" (new)
6344+ : "0" (c), "ir" (a));
6345+
6346+ old = atomic64_cmpxchg(v, c, new);
6347 if (likely(old == c))
6348 break;
6349 c = old;
6350 }
6351- return c != (u);
6352+ return c != u;
6353 }
6354
6355 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6356diff -urNp linux-3.0.4/arch/x86/include/asm/atomic.h linux-3.0.4/arch/x86/include/asm/atomic.h
6357--- linux-3.0.4/arch/x86/include/asm/atomic.h 2011-07-21 22:17:23.000000000 -0400
6358+++ linux-3.0.4/arch/x86/include/asm/atomic.h 2011-08-23 21:47:55.000000000 -0400
6359@@ -22,7 +22,18 @@
6360 */
6361 static inline int atomic_read(const atomic_t *v)
6362 {
6363- return (*(volatile int *)&(v)->counter);
6364+ return (*(volatile const int *)&(v)->counter);
6365+}
6366+
6367+/**
6368+ * atomic_read_unchecked - read atomic variable
6369+ * @v: pointer of type atomic_unchecked_t
6370+ *
6371+ * Atomically reads the value of @v.
6372+ */
6373+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6374+{
6375+ return (*(volatile const int *)&(v)->counter);
6376 }
6377
6378 /**
6379@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
6380 }
6381
6382 /**
6383+ * atomic_set_unchecked - set atomic variable
6384+ * @v: pointer of type atomic_unchecked_t
6385+ * @i: required value
6386+ *
6387+ * Atomically sets the value of @v to @i.
6388+ */
6389+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6390+{
6391+ v->counter = i;
6392+}
6393+
6394+/**
6395 * atomic_add - add integer to atomic variable
6396 * @i: integer value to add
6397 * @v: pointer of type atomic_t
6398@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
6399 */
6400 static inline void atomic_add(int i, atomic_t *v)
6401 {
6402- asm volatile(LOCK_PREFIX "addl %1,%0"
6403+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6404+
6405+#ifdef CONFIG_PAX_REFCOUNT
6406+ "jno 0f\n"
6407+ LOCK_PREFIX "subl %1,%0\n"
6408+ "int $4\n0:\n"
6409+ _ASM_EXTABLE(0b, 0b)
6410+#endif
6411+
6412+ : "+m" (v->counter)
6413+ : "ir" (i));
6414+}
6415+
6416+/**
6417+ * atomic_add_unchecked - add integer to atomic variable
6418+ * @i: integer value to add
6419+ * @v: pointer of type atomic_unchecked_t
6420+ *
6421+ * Atomically adds @i to @v.
6422+ */
6423+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6424+{
6425+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6426 : "+m" (v->counter)
6427 : "ir" (i));
6428 }
6429@@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
6430 */
6431 static inline void atomic_sub(int i, atomic_t *v)
6432 {
6433- asm volatile(LOCK_PREFIX "subl %1,%0"
6434+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
6435+
6436+#ifdef CONFIG_PAX_REFCOUNT
6437+ "jno 0f\n"
6438+ LOCK_PREFIX "addl %1,%0\n"
6439+ "int $4\n0:\n"
6440+ _ASM_EXTABLE(0b, 0b)
6441+#endif
6442+
6443+ : "+m" (v->counter)
6444+ : "ir" (i));
6445+}
6446+
6447+/**
6448+ * atomic_sub_unchecked - subtract integer from atomic variable
6449+ * @i: integer value to subtract
6450+ * @v: pointer of type atomic_unchecked_t
6451+ *
6452+ * Atomically subtracts @i from @v.
6453+ */
6454+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
6455+{
6456+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
6457 : "+m" (v->counter)
6458 : "ir" (i));
6459 }
6460@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
6461 {
6462 unsigned char c;
6463
6464- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
6465+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
6466+
6467+#ifdef CONFIG_PAX_REFCOUNT
6468+ "jno 0f\n"
6469+ LOCK_PREFIX "addl %2,%0\n"
6470+ "int $4\n0:\n"
6471+ _ASM_EXTABLE(0b, 0b)
6472+#endif
6473+
6474+ "sete %1\n"
6475 : "+m" (v->counter), "=qm" (c)
6476 : "ir" (i) : "memory");
6477 return c;
6478@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
6479 */
6480 static inline void atomic_inc(atomic_t *v)
6481 {
6482- asm volatile(LOCK_PREFIX "incl %0"
6483+ asm volatile(LOCK_PREFIX "incl %0\n"
6484+
6485+#ifdef CONFIG_PAX_REFCOUNT
6486+ "jno 0f\n"
6487+ LOCK_PREFIX "decl %0\n"
6488+ "int $4\n0:\n"
6489+ _ASM_EXTABLE(0b, 0b)
6490+#endif
6491+
6492+ : "+m" (v->counter));
6493+}
6494+
6495+/**
6496+ * atomic_inc_unchecked - increment atomic variable
6497+ * @v: pointer of type atomic_unchecked_t
6498+ *
6499+ * Atomically increments @v by 1.
6500+ */
6501+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6502+{
6503+ asm volatile(LOCK_PREFIX "incl %0\n"
6504 : "+m" (v->counter));
6505 }
6506
6507@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
6508 */
6509 static inline void atomic_dec(atomic_t *v)
6510 {
6511- asm volatile(LOCK_PREFIX "decl %0"
6512+ asm volatile(LOCK_PREFIX "decl %0\n"
6513+
6514+#ifdef CONFIG_PAX_REFCOUNT
6515+ "jno 0f\n"
6516+ LOCK_PREFIX "incl %0\n"
6517+ "int $4\n0:\n"
6518+ _ASM_EXTABLE(0b, 0b)
6519+#endif
6520+
6521+ : "+m" (v->counter));
6522+}
6523+
6524+/**
6525+ * atomic_dec_unchecked - decrement atomic variable
6526+ * @v: pointer of type atomic_unchecked_t
6527+ *
6528+ * Atomically decrements @v by 1.
6529+ */
6530+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6531+{
6532+ asm volatile(LOCK_PREFIX "decl %0\n"
6533 : "+m" (v->counter));
6534 }
6535
6536@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
6537 {
6538 unsigned char c;
6539
6540- asm volatile(LOCK_PREFIX "decl %0; sete %1"
6541+ asm volatile(LOCK_PREFIX "decl %0\n"
6542+
6543+#ifdef CONFIG_PAX_REFCOUNT
6544+ "jno 0f\n"
6545+ LOCK_PREFIX "incl %0\n"
6546+ "int $4\n0:\n"
6547+ _ASM_EXTABLE(0b, 0b)
6548+#endif
6549+
6550+ "sete %1\n"
6551 : "+m" (v->counter), "=qm" (c)
6552 : : "memory");
6553 return c != 0;
6554@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(at
6555 {
6556 unsigned char c;
6557
6558- asm volatile(LOCK_PREFIX "incl %0; sete %1"
6559+ asm volatile(LOCK_PREFIX "incl %0\n"
6560+
6561+#ifdef CONFIG_PAX_REFCOUNT
6562+ "jno 0f\n"
6563+ LOCK_PREFIX "decl %0\n"
6564+ "int $4\n0:\n"
6565+ _ASM_EXTABLE(0b, 0b)
6566+#endif
6567+
6568+ "sete %1\n"
6569+ : "+m" (v->counter), "=qm" (c)
6570+ : : "memory");
6571+ return c != 0;
6572+}
6573+
6574+/**
6575+ * atomic_inc_and_test_unchecked - increment and test
6576+ * @v: pointer of type atomic_unchecked_t
6577+ *
6578+ * Atomically increments @v by 1
6579+ * and returns true if the result is zero, or false for all
6580+ * other cases.
6581+ */
6582+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6583+{
6584+ unsigned char c;
6585+
6586+ asm volatile(LOCK_PREFIX "incl %0\n"
6587+ "sete %1\n"
6588 : "+m" (v->counter), "=qm" (c)
6589 : : "memory");
6590 return c != 0;
6591@@ -157,7 +310,16 @@ static inline int atomic_add_negative(in
6592 {
6593 unsigned char c;
6594
6595- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
6596+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
6597+
6598+#ifdef CONFIG_PAX_REFCOUNT
6599+ "jno 0f\n"
6600+ LOCK_PREFIX "subl %2,%0\n"
6601+ "int $4\n0:\n"
6602+ _ASM_EXTABLE(0b, 0b)
6603+#endif
6604+
6605+ "sets %1\n"
6606 : "+m" (v->counter), "=qm" (c)
6607 : "ir" (i) : "memory");
6608 return c;
6609@@ -180,6 +342,46 @@ static inline int atomic_add_return(int
6610 #endif
6611 /* Modern 486+ processor */
6612 __i = i;
6613+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
6614+
6615+#ifdef CONFIG_PAX_REFCOUNT
6616+ "jno 0f\n"
6617+ "movl %0, %1\n"
6618+ "int $4\n0:\n"
6619+ _ASM_EXTABLE(0b, 0b)
6620+#endif
6621+
6622+ : "+r" (i), "+m" (v->counter)
6623+ : : "memory");
6624+ return i + __i;
6625+
6626+#ifdef CONFIG_M386
6627+no_xadd: /* Legacy 386 processor */
6628+ local_irq_save(flags);
6629+ __i = atomic_read(v);
6630+ atomic_set(v, i + __i);
6631+ local_irq_restore(flags);
6632+ return i + __i;
6633+#endif
6634+}
6635+
6636+/**
6637+ * atomic_add_return_unchecked - add integer and return
6638+ * @v: pointer of type atomic_unchecked_t
6639+ * @i: integer value to add
6640+ *
6641+ * Atomically adds @i to @v and returns @i + @v
6642+ */
6643+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6644+{
6645+ int __i;
6646+#ifdef CONFIG_M386
6647+ unsigned long flags;
6648+ if (unlikely(boot_cpu_data.x86 <= 3))
6649+ goto no_xadd;
6650+#endif
6651+ /* Modern 486+ processor */
6652+ __i = i;
6653 asm volatile(LOCK_PREFIX "xaddl %0, %1"
6654 : "+r" (i), "+m" (v->counter)
6655 : : "memory");
6656@@ -208,6 +410,10 @@ static inline int atomic_sub_return(int
6657 }
6658
6659 #define atomic_inc_return(v) (atomic_add_return(1, v))
6660+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6661+{
6662+ return atomic_add_return_unchecked(1, v);
6663+}
6664 #define atomic_dec_return(v) (atomic_sub_return(1, v))
6665
6666 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6667@@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_
6668 return cmpxchg(&v->counter, old, new);
6669 }
6670
6671+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6672+{
6673+ return cmpxchg(&v->counter, old, new);
6674+}
6675+
6676 static inline int atomic_xchg(atomic_t *v, int new)
6677 {
6678 return xchg(&v->counter, new);
6679 }
6680
6681+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6682+{
6683+ return xchg(&v->counter, new);
6684+}
6685+
6686 /**
6687 * atomic_add_unless - add unless the number is already a given value
6688 * @v: pointer of type atomic_t
6689@@ -231,21 +447,77 @@ static inline int atomic_xchg(atomic_t *
6690 */
6691 static inline int atomic_add_unless(atomic_t *v, int a, int u)
6692 {
6693- int c, old;
6694+ int c, old, new;
6695 c = atomic_read(v);
6696 for (;;) {
6697- if (unlikely(c == (u)))
6698+ if (unlikely(c == u))
6699 break;
6700- old = atomic_cmpxchg((v), c, c + (a));
6701+
6702+ asm volatile("addl %2,%0\n"
6703+
6704+#ifdef CONFIG_PAX_REFCOUNT
6705+ "jno 0f\n"
6706+ "subl %2,%0\n"
6707+ "int $4\n0:\n"
6708+ _ASM_EXTABLE(0b, 0b)
6709+#endif
6710+
6711+ : "=r" (new)
6712+ : "0" (c), "ir" (a));
6713+
6714+ old = atomic_cmpxchg(v, c, new);
6715 if (likely(old == c))
6716 break;
6717 c = old;
6718 }
6719- return c != (u);
6720+ return c != u;
6721 }
6722
6723 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
6724
6725+/**
6726+ * atomic_inc_not_zero_hint - increment if not null
6727+ * @v: pointer of type atomic_t
6728+ * @hint: probable value of the atomic before the increment
6729+ *
6730+ * This version of atomic_inc_not_zero() gives a hint of probable
6731+ * value of the atomic. This helps processor to not read the memory
6732+ * before doing the atomic read/modify/write cycle, lowering
6733+ * number of bus transactions on some arches.
6734+ *
6735+ * Returns: 0 if increment was not done, 1 otherwise.
6736+ */
6737+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
6738+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
6739+{
6740+ int val, c = hint, new;
6741+
6742+ /* sanity test, should be removed by compiler if hint is a constant */
6743+ if (!hint)
6744+ return atomic_inc_not_zero(v);
6745+
6746+ do {
6747+ asm volatile("incl %0\n"
6748+
6749+#ifdef CONFIG_PAX_REFCOUNT
6750+ "jno 0f\n"
6751+ "decl %0\n"
6752+ "int $4\n0:\n"
6753+ _ASM_EXTABLE(0b, 0b)
6754+#endif
6755+
6756+ : "=r" (new)
6757+ : "0" (c));
6758+
6759+ val = atomic_cmpxchg(v, c, new);
6760+ if (val == c)
6761+ return 1;
6762+ c = val;
6763+ } while (c);
6764+
6765+ return 0;
6766+}
6767+
6768 /*
6769 * atomic_dec_if_positive - decrement by 1 if old value positive
6770 * @v: pointer of type atomic_t
6771diff -urNp linux-3.0.4/arch/x86/include/asm/bitops.h linux-3.0.4/arch/x86/include/asm/bitops.h
6772--- linux-3.0.4/arch/x86/include/asm/bitops.h 2011-07-21 22:17:23.000000000 -0400
6773+++ linux-3.0.4/arch/x86/include/asm/bitops.h 2011-08-23 21:47:55.000000000 -0400
6774@@ -38,7 +38,7 @@
6775 * a mask operation on a byte.
6776 */
6777 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
6778-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
6779+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
6780 #define CONST_MASK(nr) (1 << ((nr) & 7))
6781
6782 /**
6783diff -urNp linux-3.0.4/arch/x86/include/asm/boot.h linux-3.0.4/arch/x86/include/asm/boot.h
6784--- linux-3.0.4/arch/x86/include/asm/boot.h 2011-07-21 22:17:23.000000000 -0400
6785+++ linux-3.0.4/arch/x86/include/asm/boot.h 2011-08-23 21:47:55.000000000 -0400
6786@@ -11,10 +11,15 @@
6787 #include <asm/pgtable_types.h>
6788
6789 /* Physical address where kernel should be loaded. */
6790-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
6791+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
6792 + (CONFIG_PHYSICAL_ALIGN - 1)) \
6793 & ~(CONFIG_PHYSICAL_ALIGN - 1))
6794
6795+#ifndef __ASSEMBLY__
6796+extern unsigned char __LOAD_PHYSICAL_ADDR[];
6797+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
6798+#endif
6799+
6800 /* Minimum kernel alignment, as a power of two */
6801 #ifdef CONFIG_X86_64
6802 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
6803diff -urNp linux-3.0.4/arch/x86/include/asm/cacheflush.h linux-3.0.4/arch/x86/include/asm/cacheflush.h
6804--- linux-3.0.4/arch/x86/include/asm/cacheflush.h 2011-07-21 22:17:23.000000000 -0400
6805+++ linux-3.0.4/arch/x86/include/asm/cacheflush.h 2011-08-23 21:47:55.000000000 -0400
6806@@ -26,7 +26,7 @@ static inline unsigned long get_page_mem
6807 unsigned long pg_flags = pg->flags & _PGMT_MASK;
6808
6809 if (pg_flags == _PGMT_DEFAULT)
6810- return -1;
6811+ return ~0UL;
6812 else if (pg_flags == _PGMT_WC)
6813 return _PAGE_CACHE_WC;
6814 else if (pg_flags == _PGMT_UC_MINUS)
6815diff -urNp linux-3.0.4/arch/x86/include/asm/cache.h linux-3.0.4/arch/x86/include/asm/cache.h
6816--- linux-3.0.4/arch/x86/include/asm/cache.h 2011-07-21 22:17:23.000000000 -0400
6817+++ linux-3.0.4/arch/x86/include/asm/cache.h 2011-08-23 21:47:55.000000000 -0400
6818@@ -5,12 +5,13 @@
6819
6820 /* L1 cache line size */
6821 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6822-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6823+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6824
6825 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6826+#define __read_only __attribute__((__section__(".data..read_only")))
6827
6828 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
6829-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
6830+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
6831
6832 #ifdef CONFIG_X86_VSMP
6833 #ifdef CONFIG_SMP
6834diff -urNp linux-3.0.4/arch/x86/include/asm/checksum_32.h linux-3.0.4/arch/x86/include/asm/checksum_32.h
6835--- linux-3.0.4/arch/x86/include/asm/checksum_32.h 2011-07-21 22:17:23.000000000 -0400
6836+++ linux-3.0.4/arch/x86/include/asm/checksum_32.h 2011-08-23 21:47:55.000000000 -0400
6837@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
6838 int len, __wsum sum,
6839 int *src_err_ptr, int *dst_err_ptr);
6840
6841+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
6842+ int len, __wsum sum,
6843+ int *src_err_ptr, int *dst_err_ptr);
6844+
6845+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
6846+ int len, __wsum sum,
6847+ int *src_err_ptr, int *dst_err_ptr);
6848+
6849 /*
6850 * Note: when you get a NULL pointer exception here this means someone
6851 * passed in an incorrect kernel address to one of these functions.
6852@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
6853 int *err_ptr)
6854 {
6855 might_sleep();
6856- return csum_partial_copy_generic((__force void *)src, dst,
6857+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
6858 len, sum, err_ptr, NULL);
6859 }
6860
6861@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
6862 {
6863 might_sleep();
6864 if (access_ok(VERIFY_WRITE, dst, len))
6865- return csum_partial_copy_generic(src, (__force void *)dst,
6866+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
6867 len, sum, NULL, err_ptr);
6868
6869 if (len)
6870diff -urNp linux-3.0.4/arch/x86/include/asm/cpufeature.h linux-3.0.4/arch/x86/include/asm/cpufeature.h
6871--- linux-3.0.4/arch/x86/include/asm/cpufeature.h 2011-07-21 22:17:23.000000000 -0400
6872+++ linux-3.0.4/arch/x86/include/asm/cpufeature.h 2011-08-23 21:47:55.000000000 -0400
6873@@ -358,7 +358,7 @@ static __always_inline __pure bool __sta
6874 ".section .discard,\"aw\",@progbits\n"
6875 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
6876 ".previous\n"
6877- ".section .altinstr_replacement,\"ax\"\n"
6878+ ".section .altinstr_replacement,\"a\"\n"
6879 "3: movb $1,%0\n"
6880 "4:\n"
6881 ".previous\n"
6882diff -urNp linux-3.0.4/arch/x86/include/asm/desc_defs.h linux-3.0.4/arch/x86/include/asm/desc_defs.h
6883--- linux-3.0.4/arch/x86/include/asm/desc_defs.h 2011-07-21 22:17:23.000000000 -0400
6884+++ linux-3.0.4/arch/x86/include/asm/desc_defs.h 2011-08-23 21:47:55.000000000 -0400
6885@@ -31,6 +31,12 @@ struct desc_struct {
6886 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
6887 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
6888 };
6889+ struct {
6890+ u16 offset_low;
6891+ u16 seg;
6892+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
6893+ unsigned offset_high: 16;
6894+ } gate;
6895 };
6896 } __attribute__((packed));
6897
6898diff -urNp linux-3.0.4/arch/x86/include/asm/desc.h linux-3.0.4/arch/x86/include/asm/desc.h
6899--- linux-3.0.4/arch/x86/include/asm/desc.h 2011-07-21 22:17:23.000000000 -0400
6900+++ linux-3.0.4/arch/x86/include/asm/desc.h 2011-08-23 21:47:55.000000000 -0400
6901@@ -4,6 +4,7 @@
6902 #include <asm/desc_defs.h>
6903 #include <asm/ldt.h>
6904 #include <asm/mmu.h>
6905+#include <asm/pgtable.h>
6906
6907 #include <linux/smp.h>
6908
6909@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_
6910
6911 desc->type = (info->read_exec_only ^ 1) << 1;
6912 desc->type |= info->contents << 2;
6913+ desc->type |= info->seg_not_present ^ 1;
6914
6915 desc->s = 1;
6916 desc->dpl = 0x3;
6917@@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_
6918 }
6919
6920 extern struct desc_ptr idt_descr;
6921-extern gate_desc idt_table[];
6922-
6923-struct gdt_page {
6924- struct desc_struct gdt[GDT_ENTRIES];
6925-} __attribute__((aligned(PAGE_SIZE)));
6926-
6927-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
6928+extern gate_desc idt_table[256];
6929
6930+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
6931 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
6932 {
6933- return per_cpu(gdt_page, cpu).gdt;
6934+ return cpu_gdt_table[cpu];
6935 }
6936
6937 #ifdef CONFIG_X86_64
6938@@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *
6939 unsigned long base, unsigned dpl, unsigned flags,
6940 unsigned short seg)
6941 {
6942- gate->a = (seg << 16) | (base & 0xffff);
6943- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
6944+ gate->gate.offset_low = base;
6945+ gate->gate.seg = seg;
6946+ gate->gate.reserved = 0;
6947+ gate->gate.type = type;
6948+ gate->gate.s = 0;
6949+ gate->gate.dpl = dpl;
6950+ gate->gate.p = 1;
6951+ gate->gate.offset_high = base >> 16;
6952 }
6953
6954 #endif
6955@@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(str
6956
6957 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
6958 {
6959+ pax_open_kernel();
6960 memcpy(&idt[entry], gate, sizeof(*gate));
6961+ pax_close_kernel();
6962 }
6963
6964 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
6965 {
6966+ pax_open_kernel();
6967 memcpy(&ldt[entry], desc, 8);
6968+ pax_close_kernel();
6969 }
6970
6971 static inline void
6972@@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struc
6973 default: size = sizeof(*gdt); break;
6974 }
6975
6976+ pax_open_kernel();
6977 memcpy(&gdt[entry], desc, size);
6978+ pax_close_kernel();
6979 }
6980
6981 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
6982@@ -207,7 +216,9 @@ static inline void native_set_ldt(const
6983
6984 static inline void native_load_tr_desc(void)
6985 {
6986+ pax_open_kernel();
6987 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
6988+ pax_close_kernel();
6989 }
6990
6991 static inline void native_load_gdt(const struct desc_ptr *dtr)
6992@@ -244,8 +255,10 @@ static inline void native_load_tls(struc
6993 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
6994 unsigned int i;
6995
6996+ pax_open_kernel();
6997 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
6998 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
6999+ pax_close_kernel();
7000 }
7001
7002 #define _LDT_empty(info) \
7003@@ -307,7 +320,7 @@ static inline void set_desc_limit(struct
7004 desc->limit = (limit >> 16) & 0xf;
7005 }
7006
7007-static inline void _set_gate(int gate, unsigned type, void *addr,
7008+static inline void _set_gate(int gate, unsigned type, const void *addr,
7009 unsigned dpl, unsigned ist, unsigned seg)
7010 {
7011 gate_desc s;
7012@@ -326,7 +339,7 @@ static inline void _set_gate(int gate, u
7013 * Pentium F0 0F bugfix can have resulted in the mapped
7014 * IDT being write-protected.
7015 */
7016-static inline void set_intr_gate(unsigned int n, void *addr)
7017+static inline void set_intr_gate(unsigned int n, const void *addr)
7018 {
7019 BUG_ON((unsigned)n > 0xFF);
7020 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
7021@@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsig
7022 /*
7023 * This routine sets up an interrupt gate at directory privilege level 3.
7024 */
7025-static inline void set_system_intr_gate(unsigned int n, void *addr)
7026+static inline void set_system_intr_gate(unsigned int n, const void *addr)
7027 {
7028 BUG_ON((unsigned)n > 0xFF);
7029 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
7030 }
7031
7032-static inline void set_system_trap_gate(unsigned int n, void *addr)
7033+static inline void set_system_trap_gate(unsigned int n, const void *addr)
7034 {
7035 BUG_ON((unsigned)n > 0xFF);
7036 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
7037 }
7038
7039-static inline void set_trap_gate(unsigned int n, void *addr)
7040+static inline void set_trap_gate(unsigned int n, const void *addr)
7041 {
7042 BUG_ON((unsigned)n > 0xFF);
7043 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
7044@@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigne
7045 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
7046 {
7047 BUG_ON((unsigned)n > 0xFF);
7048- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
7049+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
7050 }
7051
7052-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
7053+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
7054 {
7055 BUG_ON((unsigned)n > 0xFF);
7056 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
7057 }
7058
7059-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
7060+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
7061 {
7062 BUG_ON((unsigned)n > 0xFF);
7063 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
7064 }
7065
7066+#ifdef CONFIG_X86_32
7067+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
7068+{
7069+ struct desc_struct d;
7070+
7071+ if (likely(limit))
7072+ limit = (limit - 1UL) >> PAGE_SHIFT;
7073+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
7074+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
7075+}
7076+#endif
7077+
7078 #endif /* _ASM_X86_DESC_H */
7079diff -urNp linux-3.0.4/arch/x86/include/asm/e820.h linux-3.0.4/arch/x86/include/asm/e820.h
7080--- linux-3.0.4/arch/x86/include/asm/e820.h 2011-07-21 22:17:23.000000000 -0400
7081+++ linux-3.0.4/arch/x86/include/asm/e820.h 2011-08-23 21:47:55.000000000 -0400
7082@@ -69,7 +69,7 @@ struct e820map {
7083 #define ISA_START_ADDRESS 0xa0000
7084 #define ISA_END_ADDRESS 0x100000
7085
7086-#define BIOS_BEGIN 0x000a0000
7087+#define BIOS_BEGIN 0x000c0000
7088 #define BIOS_END 0x00100000
7089
7090 #define BIOS_ROM_BASE 0xffe00000
7091diff -urNp linux-3.0.4/arch/x86/include/asm/elf.h linux-3.0.4/arch/x86/include/asm/elf.h
7092--- linux-3.0.4/arch/x86/include/asm/elf.h 2011-07-21 22:17:23.000000000 -0400
7093+++ linux-3.0.4/arch/x86/include/asm/elf.h 2011-08-23 21:47:55.000000000 -0400
7094@@ -237,7 +237,25 @@ extern int force_personality32;
7095 the loader. We need to make sure that it is out of the way of the program
7096 that it will "exec", and that there is sufficient room for the brk. */
7097
7098+#ifdef CONFIG_PAX_SEGMEXEC
7099+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
7100+#else
7101 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7102+#endif
7103+
7104+#ifdef CONFIG_PAX_ASLR
7105+#ifdef CONFIG_X86_32
7106+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
7107+
7108+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
7109+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
7110+#else
7111+#define PAX_ELF_ET_DYN_BASE 0x400000UL
7112+
7113+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
7114+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
7115+#endif
7116+#endif
7117
7118 /* This yields a mask that user programs can use to figure out what
7119 instruction set this CPU supports. This could be done in user space,
7120@@ -290,9 +308,7 @@ do { \
7121
7122 #define ARCH_DLINFO \
7123 do { \
7124- if (vdso_enabled) \
7125- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
7126- (unsigned long)current->mm->context.vdso); \
7127+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
7128 } while (0)
7129
7130 #define AT_SYSINFO 32
7131@@ -303,7 +319,7 @@ do { \
7132
7133 #endif /* !CONFIG_X86_32 */
7134
7135-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
7136+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
7137
7138 #define VDSO_ENTRY \
7139 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
7140@@ -317,7 +333,4 @@ extern int arch_setup_additional_pages(s
7141 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
7142 #define compat_arch_setup_additional_pages syscall32_setup_pages
7143
7144-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7145-#define arch_randomize_brk arch_randomize_brk
7146-
7147 #endif /* _ASM_X86_ELF_H */
7148diff -urNp linux-3.0.4/arch/x86/include/asm/emergency-restart.h linux-3.0.4/arch/x86/include/asm/emergency-restart.h
7149--- linux-3.0.4/arch/x86/include/asm/emergency-restart.h 2011-07-21 22:17:23.000000000 -0400
7150+++ linux-3.0.4/arch/x86/include/asm/emergency-restart.h 2011-08-23 21:47:55.000000000 -0400
7151@@ -15,6 +15,6 @@ enum reboot_type {
7152
7153 extern enum reboot_type reboot_type;
7154
7155-extern void machine_emergency_restart(void);
7156+extern void machine_emergency_restart(void) __noreturn;
7157
7158 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
7159diff -urNp linux-3.0.4/arch/x86/include/asm/futex.h linux-3.0.4/arch/x86/include/asm/futex.h
7160--- linux-3.0.4/arch/x86/include/asm/futex.h 2011-07-21 22:17:23.000000000 -0400
7161+++ linux-3.0.4/arch/x86/include/asm/futex.h 2011-08-23 21:47:55.000000000 -0400
7162@@ -12,16 +12,18 @@
7163 #include <asm/system.h>
7164
7165 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
7166+ typecheck(u32 *, uaddr); \
7167 asm volatile("1:\t" insn "\n" \
7168 "2:\t.section .fixup,\"ax\"\n" \
7169 "3:\tmov\t%3, %1\n" \
7170 "\tjmp\t2b\n" \
7171 "\t.previous\n" \
7172 _ASM_EXTABLE(1b, 3b) \
7173- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
7174+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
7175 : "i" (-EFAULT), "0" (oparg), "1" (0))
7176
7177 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
7178+ typecheck(u32 *, uaddr); \
7179 asm volatile("1:\tmovl %2, %0\n" \
7180 "\tmovl\t%0, %3\n" \
7181 "\t" insn "\n" \
7182@@ -34,7 +36,7 @@
7183 _ASM_EXTABLE(1b, 4b) \
7184 _ASM_EXTABLE(2b, 4b) \
7185 : "=&a" (oldval), "=&r" (ret), \
7186- "+m" (*uaddr), "=&r" (tem) \
7187+ "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
7188 : "r" (oparg), "i" (-EFAULT), "1" (0))
7189
7190 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
7191@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
7192
7193 switch (op) {
7194 case FUTEX_OP_SET:
7195- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
7196+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
7197 break;
7198 case FUTEX_OP_ADD:
7199- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
7200+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
7201 uaddr, oparg);
7202 break;
7203 case FUTEX_OP_OR:
7204@@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_i
7205 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
7206 return -EFAULT;
7207
7208- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
7209+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
7210 "2:\t.section .fixup, \"ax\"\n"
7211 "3:\tmov %3, %0\n"
7212 "\tjmp 2b\n"
7213 "\t.previous\n"
7214 _ASM_EXTABLE(1b, 3b)
7215- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
7216+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
7217 : "i" (-EFAULT), "r" (newval), "1" (oldval)
7218 : "memory"
7219 );
7220diff -urNp linux-3.0.4/arch/x86/include/asm/hw_irq.h linux-3.0.4/arch/x86/include/asm/hw_irq.h
7221--- linux-3.0.4/arch/x86/include/asm/hw_irq.h 2011-07-21 22:17:23.000000000 -0400
7222+++ linux-3.0.4/arch/x86/include/asm/hw_irq.h 2011-08-23 21:47:55.000000000 -0400
7223@@ -137,8 +137,8 @@ extern void setup_ioapic_dest(void);
7224 extern void enable_IO_APIC(void);
7225
7226 /* Statistics */
7227-extern atomic_t irq_err_count;
7228-extern atomic_t irq_mis_count;
7229+extern atomic_unchecked_t irq_err_count;
7230+extern atomic_unchecked_t irq_mis_count;
7231
7232 /* EISA */
7233 extern void eisa_set_level_irq(unsigned int irq);
7234diff -urNp linux-3.0.4/arch/x86/include/asm/i387.h linux-3.0.4/arch/x86/include/asm/i387.h
7235--- linux-3.0.4/arch/x86/include/asm/i387.h 2011-07-21 22:17:23.000000000 -0400
7236+++ linux-3.0.4/arch/x86/include/asm/i387.h 2011-08-23 21:47:55.000000000 -0400
7237@@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
7238 {
7239 int err;
7240
7241+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
7242+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
7243+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
7244+#endif
7245+
7246 /* See comment in fxsave() below. */
7247 #ifdef CONFIG_AS_FXSAVEQ
7248 asm volatile("1: fxrstorq %[fx]\n\t"
7249@@ -121,6 +126,11 @@ static inline int fxsave_user(struct i38
7250 {
7251 int err;
7252
7253+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
7254+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
7255+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
7256+#endif
7257+
7258 /*
7259 * Clear the bytes not touched by the fxsave and reserved
7260 * for the SW usage.
7261@@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu
7262 #endif /* CONFIG_X86_64 */
7263
7264 /* We need a safe address that is cheap to find and that is already
7265- in L1 during context switch. The best choices are unfortunately
7266- different for UP and SMP */
7267-#ifdef CONFIG_SMP
7268-#define safe_address (__per_cpu_offset[0])
7269-#else
7270-#define safe_address (kstat_cpu(0).cpustat.user)
7271-#endif
7272+ in L1 during context switch. */
7273+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
7274
7275 /*
7276 * These must be called with preempt disabled
7277@@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void
7278 struct thread_info *me = current_thread_info();
7279 preempt_disable();
7280 if (me->status & TS_USEDFPU)
7281- __save_init_fpu(me->task);
7282+ __save_init_fpu(current);
7283 else
7284 clts();
7285 }
7286diff -urNp linux-3.0.4/arch/x86/include/asm/io.h linux-3.0.4/arch/x86/include/asm/io.h
7287--- linux-3.0.4/arch/x86/include/asm/io.h 2011-07-21 22:17:23.000000000 -0400
7288+++ linux-3.0.4/arch/x86/include/asm/io.h 2011-08-23 21:47:55.000000000 -0400
7289@@ -196,6 +196,17 @@ extern void set_iounmap_nonlazy(void);
7290
7291 #include <linux/vmalloc.h>
7292
7293+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
7294+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
7295+{
7296+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
7297+}
7298+
7299+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
7300+{
7301+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
7302+}
7303+
7304 /*
7305 * Convert a virtual cached pointer to an uncached pointer
7306 */
7307diff -urNp linux-3.0.4/arch/x86/include/asm/irqflags.h linux-3.0.4/arch/x86/include/asm/irqflags.h
7308--- linux-3.0.4/arch/x86/include/asm/irqflags.h 2011-07-21 22:17:23.000000000 -0400
7309+++ linux-3.0.4/arch/x86/include/asm/irqflags.h 2011-08-23 21:47:55.000000000 -0400
7310@@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
7311 sti; \
7312 sysexit
7313
7314+#define GET_CR0_INTO_RDI mov %cr0, %rdi
7315+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
7316+#define GET_CR3_INTO_RDI mov %cr3, %rdi
7317+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
7318+
7319 #else
7320 #define INTERRUPT_RETURN iret
7321 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
7322diff -urNp linux-3.0.4/arch/x86/include/asm/kprobes.h linux-3.0.4/arch/x86/include/asm/kprobes.h
7323--- linux-3.0.4/arch/x86/include/asm/kprobes.h 2011-07-21 22:17:23.000000000 -0400
7324+++ linux-3.0.4/arch/x86/include/asm/kprobes.h 2011-08-23 21:47:55.000000000 -0400
7325@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
7326 #define RELATIVEJUMP_SIZE 5
7327 #define RELATIVECALL_OPCODE 0xe8
7328 #define RELATIVE_ADDR_SIZE 4
7329-#define MAX_STACK_SIZE 64
7330-#define MIN_STACK_SIZE(ADDR) \
7331- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
7332- THREAD_SIZE - (unsigned long)(ADDR))) \
7333- ? (MAX_STACK_SIZE) \
7334- : (((unsigned long)current_thread_info()) + \
7335- THREAD_SIZE - (unsigned long)(ADDR)))
7336+#define MAX_STACK_SIZE 64UL
7337+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
7338
7339 #define flush_insn_slot(p) do { } while (0)
7340
7341diff -urNp linux-3.0.4/arch/x86/include/asm/kvm_host.h linux-3.0.4/arch/x86/include/asm/kvm_host.h
7342--- linux-3.0.4/arch/x86/include/asm/kvm_host.h 2011-07-21 22:17:23.000000000 -0400
7343+++ linux-3.0.4/arch/x86/include/asm/kvm_host.h 2011-08-26 19:49:56.000000000 -0400
7344@@ -441,7 +441,7 @@ struct kvm_arch {
7345 unsigned int n_used_mmu_pages;
7346 unsigned int n_requested_mmu_pages;
7347 unsigned int n_max_mmu_pages;
7348- atomic_t invlpg_counter;
7349+ atomic_unchecked_t invlpg_counter;
7350 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
7351 /*
7352 * Hash table of struct kvm_mmu_page.
7353@@ -619,7 +619,7 @@ struct kvm_x86_ops {
7354 enum x86_intercept_stage stage);
7355
7356 const struct trace_print_flags *exit_reasons_str;
7357-};
7358+} __do_const;
7359
7360 struct kvm_arch_async_pf {
7361 u32 token;
7362diff -urNp linux-3.0.4/arch/x86/include/asm/local.h linux-3.0.4/arch/x86/include/asm/local.h
7363--- linux-3.0.4/arch/x86/include/asm/local.h 2011-07-21 22:17:23.000000000 -0400
7364+++ linux-3.0.4/arch/x86/include/asm/local.h 2011-08-23 21:47:55.000000000 -0400
7365@@ -18,26 +18,58 @@ typedef struct {
7366
7367 static inline void local_inc(local_t *l)
7368 {
7369- asm volatile(_ASM_INC "%0"
7370+ asm volatile(_ASM_INC "%0\n"
7371+
7372+#ifdef CONFIG_PAX_REFCOUNT
7373+ "jno 0f\n"
7374+ _ASM_DEC "%0\n"
7375+ "int $4\n0:\n"
7376+ _ASM_EXTABLE(0b, 0b)
7377+#endif
7378+
7379 : "+m" (l->a.counter));
7380 }
7381
7382 static inline void local_dec(local_t *l)
7383 {
7384- asm volatile(_ASM_DEC "%0"
7385+ asm volatile(_ASM_DEC "%0\n"
7386+
7387+#ifdef CONFIG_PAX_REFCOUNT
7388+ "jno 0f\n"
7389+ _ASM_INC "%0\n"
7390+ "int $4\n0:\n"
7391+ _ASM_EXTABLE(0b, 0b)
7392+#endif
7393+
7394 : "+m" (l->a.counter));
7395 }
7396
7397 static inline void local_add(long i, local_t *l)
7398 {
7399- asm volatile(_ASM_ADD "%1,%0"
7400+ asm volatile(_ASM_ADD "%1,%0\n"
7401+
7402+#ifdef CONFIG_PAX_REFCOUNT
7403+ "jno 0f\n"
7404+ _ASM_SUB "%1,%0\n"
7405+ "int $4\n0:\n"
7406+ _ASM_EXTABLE(0b, 0b)
7407+#endif
7408+
7409 : "+m" (l->a.counter)
7410 : "ir" (i));
7411 }
7412
7413 static inline void local_sub(long i, local_t *l)
7414 {
7415- asm volatile(_ASM_SUB "%1,%0"
7416+ asm volatile(_ASM_SUB "%1,%0\n"
7417+
7418+#ifdef CONFIG_PAX_REFCOUNT
7419+ "jno 0f\n"
7420+ _ASM_ADD "%1,%0\n"
7421+ "int $4\n0:\n"
7422+ _ASM_EXTABLE(0b, 0b)
7423+#endif
7424+
7425 : "+m" (l->a.counter)
7426 : "ir" (i));
7427 }
7428@@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
7429 {
7430 unsigned char c;
7431
7432- asm volatile(_ASM_SUB "%2,%0; sete %1"
7433+ asm volatile(_ASM_SUB "%2,%0\n"
7434+
7435+#ifdef CONFIG_PAX_REFCOUNT
7436+ "jno 0f\n"
7437+ _ASM_ADD "%2,%0\n"
7438+ "int $4\n0:\n"
7439+ _ASM_EXTABLE(0b, 0b)
7440+#endif
7441+
7442+ "sete %1\n"
7443 : "+m" (l->a.counter), "=qm" (c)
7444 : "ir" (i) : "memory");
7445 return c;
7446@@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
7447 {
7448 unsigned char c;
7449
7450- asm volatile(_ASM_DEC "%0; sete %1"
7451+ asm volatile(_ASM_DEC "%0\n"
7452+
7453+#ifdef CONFIG_PAX_REFCOUNT
7454+ "jno 0f\n"
7455+ _ASM_INC "%0\n"
7456+ "int $4\n0:\n"
7457+ _ASM_EXTABLE(0b, 0b)
7458+#endif
7459+
7460+ "sete %1\n"
7461 : "+m" (l->a.counter), "=qm" (c)
7462 : : "memory");
7463 return c != 0;
7464@@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
7465 {
7466 unsigned char c;
7467
7468- asm volatile(_ASM_INC "%0; sete %1"
7469+ asm volatile(_ASM_INC "%0\n"
7470+
7471+#ifdef CONFIG_PAX_REFCOUNT
7472+ "jno 0f\n"
7473+ _ASM_DEC "%0\n"
7474+ "int $4\n0:\n"
7475+ _ASM_EXTABLE(0b, 0b)
7476+#endif
7477+
7478+ "sete %1\n"
7479 : "+m" (l->a.counter), "=qm" (c)
7480 : : "memory");
7481 return c != 0;
7482@@ -110,7 +169,16 @@ static inline int local_add_negative(lon
7483 {
7484 unsigned char c;
7485
7486- asm volatile(_ASM_ADD "%2,%0; sets %1"
7487+ asm volatile(_ASM_ADD "%2,%0\n"
7488+
7489+#ifdef CONFIG_PAX_REFCOUNT
7490+ "jno 0f\n"
7491+ _ASM_SUB "%2,%0\n"
7492+ "int $4\n0:\n"
7493+ _ASM_EXTABLE(0b, 0b)
7494+#endif
7495+
7496+ "sets %1\n"
7497 : "+m" (l->a.counter), "=qm" (c)
7498 : "ir" (i) : "memory");
7499 return c;
7500@@ -133,7 +201,15 @@ static inline long local_add_return(long
7501 #endif
7502 /* Modern 486+ processor */
7503 __i = i;
7504- asm volatile(_ASM_XADD "%0, %1;"
7505+ asm volatile(_ASM_XADD "%0, %1\n"
7506+
7507+#ifdef CONFIG_PAX_REFCOUNT
7508+ "jno 0f\n"
7509+ _ASM_MOV "%0,%1\n"
7510+ "int $4\n0:\n"
7511+ _ASM_EXTABLE(0b, 0b)
7512+#endif
7513+
7514 : "+r" (i), "+m" (l->a.counter)
7515 : : "memory");
7516 return i + __i;
7517diff -urNp linux-3.0.4/arch/x86/include/asm/mman.h linux-3.0.4/arch/x86/include/asm/mman.h
7518--- linux-3.0.4/arch/x86/include/asm/mman.h 2011-07-21 22:17:23.000000000 -0400
7519+++ linux-3.0.4/arch/x86/include/asm/mman.h 2011-08-23 21:47:55.000000000 -0400
7520@@ -5,4 +5,14 @@
7521
7522 #include <asm-generic/mman.h>
7523
7524+#ifdef __KERNEL__
7525+#ifndef __ASSEMBLY__
7526+#ifdef CONFIG_X86_32
7527+#define arch_mmap_check i386_mmap_check
7528+int i386_mmap_check(unsigned long addr, unsigned long len,
7529+ unsigned long flags);
7530+#endif
7531+#endif
7532+#endif
7533+
7534 #endif /* _ASM_X86_MMAN_H */
7535diff -urNp linux-3.0.4/arch/x86/include/asm/mmu_context.h linux-3.0.4/arch/x86/include/asm/mmu_context.h
7536--- linux-3.0.4/arch/x86/include/asm/mmu_context.h 2011-07-21 22:17:23.000000000 -0400
7537+++ linux-3.0.4/arch/x86/include/asm/mmu_context.h 2011-08-23 21:48:14.000000000 -0400
7538@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *m
7539
7540 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
7541 {
7542+
7543+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
7544+ unsigned int i;
7545+ pgd_t *pgd;
7546+
7547+ pax_open_kernel();
7548+ pgd = get_cpu_pgd(smp_processor_id());
7549+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
7550+ set_pgd_batched(pgd+i, native_make_pgd(0));
7551+ pax_close_kernel();
7552+#endif
7553+
7554 #ifdef CONFIG_SMP
7555 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
7556 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
7557@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_s
7558 struct task_struct *tsk)
7559 {
7560 unsigned cpu = smp_processor_id();
7561+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
7562+ int tlbstate = TLBSTATE_OK;
7563+#endif
7564
7565 if (likely(prev != next)) {
7566 #ifdef CONFIG_SMP
7567+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
7568+ tlbstate = percpu_read(cpu_tlbstate.state);
7569+#endif
7570 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
7571 percpu_write(cpu_tlbstate.active_mm, next);
7572 #endif
7573 cpumask_set_cpu(cpu, mm_cpumask(next));
7574
7575 /* Re-load page tables */
7576+#ifdef CONFIG_PAX_PER_CPU_PGD
7577+ pax_open_kernel();
7578+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
7579+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
7580+ pax_close_kernel();
7581+ load_cr3(get_cpu_pgd(cpu));
7582+#else
7583 load_cr3(next->pgd);
7584+#endif
7585
7586 /* stop flush ipis for the previous mm */
7587 cpumask_clear_cpu(cpu, mm_cpumask(prev));
7588@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_s
7589 */
7590 if (unlikely(prev->context.ldt != next->context.ldt))
7591 load_LDT_nolock(&next->context);
7592- }
7593+
7594+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
7595+ if (!(__supported_pte_mask & _PAGE_NX)) {
7596+ smp_mb__before_clear_bit();
7597+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
7598+ smp_mb__after_clear_bit();
7599+ cpu_set(cpu, next->context.cpu_user_cs_mask);
7600+ }
7601+#endif
7602+
7603+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
7604+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
7605+ prev->context.user_cs_limit != next->context.user_cs_limit))
7606+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
7607 #ifdef CONFIG_SMP
7608+ else if (unlikely(tlbstate != TLBSTATE_OK))
7609+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
7610+#endif
7611+#endif
7612+
7613+ }
7614 else {
7615+
7616+#ifdef CONFIG_PAX_PER_CPU_PGD
7617+ pax_open_kernel();
7618+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
7619+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
7620+ pax_close_kernel();
7621+ load_cr3(get_cpu_pgd(cpu));
7622+#endif
7623+
7624+#ifdef CONFIG_SMP
7625 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
7626 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
7627
7628@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_s
7629 * tlb flush IPI delivery. We must reload CR3
7630 * to make sure to use no freed page tables.
7631 */
7632+
7633+#ifndef CONFIG_PAX_PER_CPU_PGD
7634 load_cr3(next->pgd);
7635+#endif
7636+
7637 load_LDT_nolock(&next->context);
7638+
7639+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
7640+ if (!(__supported_pte_mask & _PAGE_NX))
7641+ cpu_set(cpu, next->context.cpu_user_cs_mask);
7642+#endif
7643+
7644+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
7645+#ifdef CONFIG_PAX_PAGEEXEC
7646+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
7647+#endif
7648+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
7649+#endif
7650+
7651 }
7652- }
7653 #endif
7654+ }
7655 }
7656
7657 #define activate_mm(prev, next) \
7658diff -urNp linux-3.0.4/arch/x86/include/asm/mmu.h linux-3.0.4/arch/x86/include/asm/mmu.h
7659--- linux-3.0.4/arch/x86/include/asm/mmu.h 2011-07-21 22:17:23.000000000 -0400
7660+++ linux-3.0.4/arch/x86/include/asm/mmu.h 2011-08-23 21:47:55.000000000 -0400
7661@@ -9,7 +9,7 @@
7662 * we put the segment information here.
7663 */
7664 typedef struct {
7665- void *ldt;
7666+ struct desc_struct *ldt;
7667 int size;
7668
7669 #ifdef CONFIG_X86_64
7670@@ -18,7 +18,19 @@ typedef struct {
7671 #endif
7672
7673 struct mutex lock;
7674- void *vdso;
7675+ unsigned long vdso;
7676+
7677+#ifdef CONFIG_X86_32
7678+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
7679+ unsigned long user_cs_base;
7680+ unsigned long user_cs_limit;
7681+
7682+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
7683+ cpumask_t cpu_user_cs_mask;
7684+#endif
7685+
7686+#endif
7687+#endif
7688 } mm_context_t;
7689
7690 #ifdef CONFIG_SMP
7691diff -urNp linux-3.0.4/arch/x86/include/asm/module.h linux-3.0.4/arch/x86/include/asm/module.h
7692--- linux-3.0.4/arch/x86/include/asm/module.h 2011-07-21 22:17:23.000000000 -0400
7693+++ linux-3.0.4/arch/x86/include/asm/module.h 2011-08-23 21:48:14.000000000 -0400
7694@@ -5,6 +5,7 @@
7695
7696 #ifdef CONFIG_X86_64
7697 /* X86_64 does not define MODULE_PROC_FAMILY */
7698+#define MODULE_PROC_FAMILY ""
7699 #elif defined CONFIG_M386
7700 #define MODULE_PROC_FAMILY "386 "
7701 #elif defined CONFIG_M486
7702@@ -59,8 +60,30 @@
7703 #error unknown processor family
7704 #endif
7705
7706-#ifdef CONFIG_X86_32
7707-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
7708+#ifdef CONFIG_PAX_MEMORY_UDEREF
7709+#define MODULE_PAX_UDEREF "UDEREF "
7710+#else
7711+#define MODULE_PAX_UDEREF ""
7712+#endif
7713+
7714+#ifdef CONFIG_PAX_KERNEXEC
7715+#define MODULE_PAX_KERNEXEC "KERNEXEC "
7716+#else
7717+#define MODULE_PAX_KERNEXEC ""
7718 #endif
7719
7720+#ifdef CONFIG_PAX_REFCOUNT
7721+#define MODULE_PAX_REFCOUNT "REFCOUNT "
7722+#else
7723+#define MODULE_PAX_REFCOUNT ""
7724+#endif
7725+
7726+#ifdef CONFIG_GRKERNSEC
7727+#define MODULE_GRSEC "GRSECURITY "
7728+#else
7729+#define MODULE_GRSEC ""
7730+#endif
7731+
7732+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
7733+
7734 #endif /* _ASM_X86_MODULE_H */
7735diff -urNp linux-3.0.4/arch/x86/include/asm/page_64_types.h linux-3.0.4/arch/x86/include/asm/page_64_types.h
7736--- linux-3.0.4/arch/x86/include/asm/page_64_types.h 2011-07-21 22:17:23.000000000 -0400
7737+++ linux-3.0.4/arch/x86/include/asm/page_64_types.h 2011-08-23 21:47:55.000000000 -0400
7738@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
7739
7740 /* duplicated to the one in bootmem.h */
7741 extern unsigned long max_pfn;
7742-extern unsigned long phys_base;
7743+extern const unsigned long phys_base;
7744
7745 extern unsigned long __phys_addr(unsigned long);
7746 #define __phys_reloc_hide(x) (x)
7747diff -urNp linux-3.0.4/arch/x86/include/asm/paravirt.h linux-3.0.4/arch/x86/include/asm/paravirt.h
7748--- linux-3.0.4/arch/x86/include/asm/paravirt.h 2011-07-21 22:17:23.000000000 -0400
7749+++ linux-3.0.4/arch/x86/include/asm/paravirt.h 2011-08-23 21:47:55.000000000 -0400
7750@@ -658,6 +658,18 @@ static inline void set_pgd(pgd_t *pgdp,
7751 val);
7752 }
7753
7754+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
7755+{
7756+ pgdval_t val = native_pgd_val(pgd);
7757+
7758+ if (sizeof(pgdval_t) > sizeof(long))
7759+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
7760+ val, (u64)val >> 32);
7761+ else
7762+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
7763+ val);
7764+}
7765+
7766 static inline void pgd_clear(pgd_t *pgdp)
7767 {
7768 set_pgd(pgdp, __pgd(0));
7769@@ -739,6 +751,21 @@ static inline void __set_fixmap(unsigned
7770 pv_mmu_ops.set_fixmap(idx, phys, flags);
7771 }
7772
7773+#ifdef CONFIG_PAX_KERNEXEC
7774+static inline unsigned long pax_open_kernel(void)
7775+{
7776+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
7777+}
7778+
7779+static inline unsigned long pax_close_kernel(void)
7780+{
7781+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
7782+}
7783+#else
7784+static inline unsigned long pax_open_kernel(void) { return 0; }
7785+static inline unsigned long pax_close_kernel(void) { return 0; }
7786+#endif
7787+
7788 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
7789
7790 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
7791@@ -955,7 +982,7 @@ extern void default_banner(void);
7792
7793 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
7794 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
7795-#define PARA_INDIRECT(addr) *%cs:addr
7796+#define PARA_INDIRECT(addr) *%ss:addr
7797 #endif
7798
7799 #define INTERRUPT_RETURN \
7800@@ -1032,6 +1059,21 @@ extern void default_banner(void);
7801 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
7802 CLBR_NONE, \
7803 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
7804+
7805+#define GET_CR0_INTO_RDI \
7806+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
7807+ mov %rax,%rdi
7808+
7809+#define SET_RDI_INTO_CR0 \
7810+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
7811+
7812+#define GET_CR3_INTO_RDI \
7813+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
7814+ mov %rax,%rdi
7815+
7816+#define SET_RDI_INTO_CR3 \
7817+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
7818+
7819 #endif /* CONFIG_X86_32 */
7820
7821 #endif /* __ASSEMBLY__ */
7822diff -urNp linux-3.0.4/arch/x86/include/asm/paravirt_types.h linux-3.0.4/arch/x86/include/asm/paravirt_types.h
7823--- linux-3.0.4/arch/x86/include/asm/paravirt_types.h 2011-07-21 22:17:23.000000000 -0400
7824+++ linux-3.0.4/arch/x86/include/asm/paravirt_types.h 2011-08-23 21:47:55.000000000 -0400
7825@@ -78,19 +78,19 @@ struct pv_init_ops {
7826 */
7827 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
7828 unsigned long addr, unsigned len);
7829-};
7830+} __no_const;
7831
7832
7833 struct pv_lazy_ops {
7834 /* Set deferred update mode, used for batching operations. */
7835 void (*enter)(void);
7836 void (*leave)(void);
7837-};
7838+} __no_const;
7839
7840 struct pv_time_ops {
7841 unsigned long long (*sched_clock)(void);
7842 unsigned long (*get_tsc_khz)(void);
7843-};
7844+} __no_const;
7845
7846 struct pv_cpu_ops {
7847 /* hooks for various privileged instructions */
7848@@ -186,7 +186,7 @@ struct pv_cpu_ops {
7849
7850 void (*start_context_switch)(struct task_struct *prev);
7851 void (*end_context_switch)(struct task_struct *next);
7852-};
7853+} __no_const;
7854
7855 struct pv_irq_ops {
7856 /*
7857@@ -217,7 +217,7 @@ struct pv_apic_ops {
7858 unsigned long start_eip,
7859 unsigned long start_esp);
7860 #endif
7861-};
7862+} __no_const;
7863
7864 struct pv_mmu_ops {
7865 unsigned long (*read_cr2)(void);
7866@@ -306,6 +306,7 @@ struct pv_mmu_ops {
7867 struct paravirt_callee_save make_pud;
7868
7869 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
7870+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
7871 #endif /* PAGETABLE_LEVELS == 4 */
7872 #endif /* PAGETABLE_LEVELS >= 3 */
7873
7874@@ -317,6 +318,12 @@ struct pv_mmu_ops {
7875 an mfn. We can tell which is which from the index. */
7876 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
7877 phys_addr_t phys, pgprot_t flags);
7878+
7879+#ifdef CONFIG_PAX_KERNEXEC
7880+ unsigned long (*pax_open_kernel)(void);
7881+ unsigned long (*pax_close_kernel)(void);
7882+#endif
7883+
7884 };
7885
7886 struct arch_spinlock;
7887@@ -327,7 +334,7 @@ struct pv_lock_ops {
7888 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
7889 int (*spin_trylock)(struct arch_spinlock *lock);
7890 void (*spin_unlock)(struct arch_spinlock *lock);
7891-};
7892+} __no_const;
7893
7894 /* This contains all the paravirt structures: we get a convenient
7895 * number for each function using the offset which we use to indicate
7896diff -urNp linux-3.0.4/arch/x86/include/asm/pgalloc.h linux-3.0.4/arch/x86/include/asm/pgalloc.h
7897--- linux-3.0.4/arch/x86/include/asm/pgalloc.h 2011-07-21 22:17:23.000000000 -0400
7898+++ linux-3.0.4/arch/x86/include/asm/pgalloc.h 2011-08-23 21:47:55.000000000 -0400
7899@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
7900 pmd_t *pmd, pte_t *pte)
7901 {
7902 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
7903+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
7904+}
7905+
7906+static inline void pmd_populate_user(struct mm_struct *mm,
7907+ pmd_t *pmd, pte_t *pte)
7908+{
7909+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
7910 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
7911 }
7912
7913diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable-2level.h linux-3.0.4/arch/x86/include/asm/pgtable-2level.h
7914--- linux-3.0.4/arch/x86/include/asm/pgtable-2level.h 2011-07-21 22:17:23.000000000 -0400
7915+++ linux-3.0.4/arch/x86/include/asm/pgtable-2level.h 2011-08-23 21:47:55.000000000 -0400
7916@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
7917
7918 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
7919 {
7920+ pax_open_kernel();
7921 *pmdp = pmd;
7922+ pax_close_kernel();
7923 }
7924
7925 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
7926diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable_32.h linux-3.0.4/arch/x86/include/asm/pgtable_32.h
7927--- linux-3.0.4/arch/x86/include/asm/pgtable_32.h 2011-07-21 22:17:23.000000000 -0400
7928+++ linux-3.0.4/arch/x86/include/asm/pgtable_32.h 2011-08-23 21:47:55.000000000 -0400
7929@@ -25,9 +25,6 @@
7930 struct mm_struct;
7931 struct vm_area_struct;
7932
7933-extern pgd_t swapper_pg_dir[1024];
7934-extern pgd_t initial_page_table[1024];
7935-
7936 static inline void pgtable_cache_init(void) { }
7937 static inline void check_pgt_cache(void) { }
7938 void paging_init(void);
7939@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
7940 # include <asm/pgtable-2level.h>
7941 #endif
7942
7943+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
7944+extern pgd_t initial_page_table[PTRS_PER_PGD];
7945+#ifdef CONFIG_X86_PAE
7946+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
7947+#endif
7948+
7949 #if defined(CONFIG_HIGHPTE)
7950 #define pte_offset_map(dir, address) \
7951 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
7952@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
7953 /* Clear a kernel PTE and flush it from the TLB */
7954 #define kpte_clear_flush(ptep, vaddr) \
7955 do { \
7956+ pax_open_kernel(); \
7957 pte_clear(&init_mm, (vaddr), (ptep)); \
7958+ pax_close_kernel(); \
7959 __flush_tlb_one((vaddr)); \
7960 } while (0)
7961
7962@@ -74,6 +79,9 @@ do { \
7963
7964 #endif /* !__ASSEMBLY__ */
7965
7966+#define HAVE_ARCH_UNMAPPED_AREA
7967+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
7968+
7969 /*
7970 * kern_addr_valid() is (1) for FLATMEM and (0) for
7971 * SPARSEMEM and DISCONTIGMEM
7972diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable_32_types.h linux-3.0.4/arch/x86/include/asm/pgtable_32_types.h
7973--- linux-3.0.4/arch/x86/include/asm/pgtable_32_types.h 2011-07-21 22:17:23.000000000 -0400
7974+++ linux-3.0.4/arch/x86/include/asm/pgtable_32_types.h 2011-08-23 21:47:55.000000000 -0400
7975@@ -8,7 +8,7 @@
7976 */
7977 #ifdef CONFIG_X86_PAE
7978 # include <asm/pgtable-3level_types.h>
7979-# define PMD_SIZE (1UL << PMD_SHIFT)
7980+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
7981 # define PMD_MASK (~(PMD_SIZE - 1))
7982 #else
7983 # include <asm/pgtable-2level_types.h>
7984@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
7985 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
7986 #endif
7987
7988+#ifdef CONFIG_PAX_KERNEXEC
7989+#ifndef __ASSEMBLY__
7990+extern unsigned char MODULES_EXEC_VADDR[];
7991+extern unsigned char MODULES_EXEC_END[];
7992+#endif
7993+#include <asm/boot.h>
7994+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
7995+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
7996+#else
7997+#define ktla_ktva(addr) (addr)
7998+#define ktva_ktla(addr) (addr)
7999+#endif
8000+
8001 #define MODULES_VADDR VMALLOC_START
8002 #define MODULES_END VMALLOC_END
8003 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
8004diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable-3level.h linux-3.0.4/arch/x86/include/asm/pgtable-3level.h
8005--- linux-3.0.4/arch/x86/include/asm/pgtable-3level.h 2011-07-21 22:17:23.000000000 -0400
8006+++ linux-3.0.4/arch/x86/include/asm/pgtable-3level.h 2011-08-23 21:47:55.000000000 -0400
8007@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
8008
8009 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8010 {
8011+ pax_open_kernel();
8012 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
8013+ pax_close_kernel();
8014 }
8015
8016 static inline void native_set_pud(pud_t *pudp, pud_t pud)
8017 {
8018+ pax_open_kernel();
8019 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
8020+ pax_close_kernel();
8021 }
8022
8023 /*
8024diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable_64.h linux-3.0.4/arch/x86/include/asm/pgtable_64.h
8025--- linux-3.0.4/arch/x86/include/asm/pgtable_64.h 2011-07-21 22:17:23.000000000 -0400
8026+++ linux-3.0.4/arch/x86/include/asm/pgtable_64.h 2011-08-23 21:47:55.000000000 -0400
8027@@ -16,10 +16,13 @@
8028
8029 extern pud_t level3_kernel_pgt[512];
8030 extern pud_t level3_ident_pgt[512];
8031+extern pud_t level3_vmalloc_pgt[512];
8032+extern pud_t level3_vmemmap_pgt[512];
8033+extern pud_t level2_vmemmap_pgt[512];
8034 extern pmd_t level2_kernel_pgt[512];
8035 extern pmd_t level2_fixmap_pgt[512];
8036-extern pmd_t level2_ident_pgt[512];
8037-extern pgd_t init_level4_pgt[];
8038+extern pmd_t level2_ident_pgt[512*2];
8039+extern pgd_t init_level4_pgt[512];
8040
8041 #define swapper_pg_dir init_level4_pgt
8042
8043@@ -61,7 +64,9 @@ static inline void native_set_pte_atomic
8044
8045 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8046 {
8047+ pax_open_kernel();
8048 *pmdp = pmd;
8049+ pax_close_kernel();
8050 }
8051
8052 static inline void native_pmd_clear(pmd_t *pmd)
8053@@ -107,6 +112,13 @@ static inline void native_pud_clear(pud_
8054
8055 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
8056 {
8057+ pax_open_kernel();
8058+ *pgdp = pgd;
8059+ pax_close_kernel();
8060+}
8061+
8062+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
8063+{
8064 *pgdp = pgd;
8065 }
8066
8067diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable_64_types.h linux-3.0.4/arch/x86/include/asm/pgtable_64_types.h
8068--- linux-3.0.4/arch/x86/include/asm/pgtable_64_types.h 2011-07-21 22:17:23.000000000 -0400
8069+++ linux-3.0.4/arch/x86/include/asm/pgtable_64_types.h 2011-08-23 21:47:55.000000000 -0400
8070@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
8071 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
8072 #define MODULES_END _AC(0xffffffffff000000, UL)
8073 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
8074+#define MODULES_EXEC_VADDR MODULES_VADDR
8075+#define MODULES_EXEC_END MODULES_END
8076+
8077+#define ktla_ktva(addr) (addr)
8078+#define ktva_ktla(addr) (addr)
8079
8080 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
8081diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable.h linux-3.0.4/arch/x86/include/asm/pgtable.h
8082--- linux-3.0.4/arch/x86/include/asm/pgtable.h 2011-07-21 22:17:23.000000000 -0400
8083+++ linux-3.0.4/arch/x86/include/asm/pgtable.h 2011-08-23 21:47:55.000000000 -0400
8084@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm
8085
8086 #ifndef __PAGETABLE_PUD_FOLDED
8087 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
8088+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
8089 #define pgd_clear(pgd) native_pgd_clear(pgd)
8090 #endif
8091
8092@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm
8093
8094 #define arch_end_context_switch(prev) do {} while(0)
8095
8096+#define pax_open_kernel() native_pax_open_kernel()
8097+#define pax_close_kernel() native_pax_close_kernel()
8098 #endif /* CONFIG_PARAVIRT */
8099
8100+#define __HAVE_ARCH_PAX_OPEN_KERNEL
8101+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
8102+
8103+#ifdef CONFIG_PAX_KERNEXEC
8104+static inline unsigned long native_pax_open_kernel(void)
8105+{
8106+ unsigned long cr0;
8107+
8108+ preempt_disable();
8109+ barrier();
8110+ cr0 = read_cr0() ^ X86_CR0_WP;
8111+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
8112+ write_cr0(cr0);
8113+ return cr0 ^ X86_CR0_WP;
8114+}
8115+
8116+static inline unsigned long native_pax_close_kernel(void)
8117+{
8118+ unsigned long cr0;
8119+
8120+ cr0 = read_cr0() ^ X86_CR0_WP;
8121+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
8122+ write_cr0(cr0);
8123+ barrier();
8124+ preempt_enable_no_resched();
8125+ return cr0 ^ X86_CR0_WP;
8126+}
8127+#else
8128+static inline unsigned long native_pax_open_kernel(void) { return 0; }
8129+static inline unsigned long native_pax_close_kernel(void) { return 0; }
8130+#endif
8131+
8132 /*
8133 * The following only work if pte_present() is true.
8134 * Undefined behaviour if not..
8135 */
8136+static inline int pte_user(pte_t pte)
8137+{
8138+ return pte_val(pte) & _PAGE_USER;
8139+}
8140+
8141 static inline int pte_dirty(pte_t pte)
8142 {
8143 return pte_flags(pte) & _PAGE_DIRTY;
8144@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t
8145 return pte_clear_flags(pte, _PAGE_RW);
8146 }
8147
8148+static inline pte_t pte_mkread(pte_t pte)
8149+{
8150+ return __pte(pte_val(pte) | _PAGE_USER);
8151+}
8152+
8153 static inline pte_t pte_mkexec(pte_t pte)
8154 {
8155- return pte_clear_flags(pte, _PAGE_NX);
8156+#ifdef CONFIG_X86_PAE
8157+ if (__supported_pte_mask & _PAGE_NX)
8158+ return pte_clear_flags(pte, _PAGE_NX);
8159+ else
8160+#endif
8161+ return pte_set_flags(pte, _PAGE_USER);
8162+}
8163+
8164+static inline pte_t pte_exprotect(pte_t pte)
8165+{
8166+#ifdef CONFIG_X86_PAE
8167+ if (__supported_pte_mask & _PAGE_NX)
8168+ return pte_set_flags(pte, _PAGE_NX);
8169+ else
8170+#endif
8171+ return pte_clear_flags(pte, _PAGE_USER);
8172 }
8173
8174 static inline pte_t pte_mkdirty(pte_t pte)
8175@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long
8176 #endif
8177
8178 #ifndef __ASSEMBLY__
8179+
8180+#ifdef CONFIG_PAX_PER_CPU_PGD
8181+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
8182+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
8183+{
8184+ return cpu_pgd[cpu];
8185+}
8186+#endif
8187+
8188 #include <linux/mm_types.h>
8189
8190 static inline int pte_none(pte_t pte)
8191@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *p
8192
8193 static inline int pgd_bad(pgd_t pgd)
8194 {
8195- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
8196+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
8197 }
8198
8199 static inline int pgd_none(pgd_t pgd)
8200@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
8201 * pgd_offset() returns a (pgd_t *)
8202 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
8203 */
8204-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
8205+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
8206+
8207+#ifdef CONFIG_PAX_PER_CPU_PGD
8208+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
8209+#endif
8210+
8211 /*
8212 * a shortcut which implies the use of the kernel's pgd, instead
8213 * of a process's
8214@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
8215 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
8216 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
8217
8218+#ifdef CONFIG_X86_32
8219+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
8220+#else
8221+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
8222+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
8223+
8224+#ifdef CONFIG_PAX_MEMORY_UDEREF
8225+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
8226+#else
8227+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
8228+#endif
8229+
8230+#endif
8231+
8232 #ifndef __ASSEMBLY__
8233
8234 extern int direct_gbpages;
8235@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(st
8236 * dst and src can be on the same page, but the range must not overlap,
8237 * and must not cross a page boundary.
8238 */
8239-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
8240+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
8241 {
8242- memcpy(dst, src, count * sizeof(pgd_t));
8243+ pax_open_kernel();
8244+ while (count--)
8245+ *dst++ = *src++;
8246+ pax_close_kernel();
8247 }
8248
8249+#ifdef CONFIG_PAX_PER_CPU_PGD
8250+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
8251+#endif
8252+
8253+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8254+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
8255+#else
8256+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
8257+#endif
8258
8259 #include <asm-generic/pgtable.h>
8260 #endif /* __ASSEMBLY__ */
8261diff -urNp linux-3.0.4/arch/x86/include/asm/pgtable_types.h linux-3.0.4/arch/x86/include/asm/pgtable_types.h
8262--- linux-3.0.4/arch/x86/include/asm/pgtable_types.h 2011-07-21 22:17:23.000000000 -0400
8263+++ linux-3.0.4/arch/x86/include/asm/pgtable_types.h 2011-08-23 21:47:55.000000000 -0400
8264@@ -16,13 +16,12 @@
8265 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
8266 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
8267 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
8268-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
8269+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
8270 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
8271 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
8272 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
8273-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
8274-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
8275-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
8276+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
8277+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
8278 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
8279
8280 /* If _PAGE_BIT_PRESENT is clear, we use these: */
8281@@ -40,7 +39,6 @@
8282 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
8283 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
8284 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
8285-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
8286 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
8287 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
8288 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
8289@@ -57,8 +55,10 @@
8290
8291 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
8292 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
8293-#else
8294+#elif defined(CONFIG_KMEMCHECK)
8295 #define _PAGE_NX (_AT(pteval_t, 0))
8296+#else
8297+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
8298 #endif
8299
8300 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
8301@@ -96,6 +96,9 @@
8302 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
8303 _PAGE_ACCESSED)
8304
8305+#define PAGE_READONLY_NOEXEC PAGE_READONLY
8306+#define PAGE_SHARED_NOEXEC PAGE_SHARED
8307+
8308 #define __PAGE_KERNEL_EXEC \
8309 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
8310 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
8311@@ -106,8 +109,8 @@
8312 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
8313 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
8314 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
8315-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
8316-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
8317+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
8318+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
8319 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
8320 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
8321 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
8322@@ -166,8 +169,8 @@
8323 * bits are combined, this will alow user to access the high address mapped
8324 * VDSO in the presence of CONFIG_COMPAT_VDSO
8325 */
8326-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
8327-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
8328+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
8329+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
8330 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
8331 #endif
8332
8333@@ -205,7 +208,17 @@ static inline pgdval_t pgd_flags(pgd_t p
8334 {
8335 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
8336 }
8337+#endif
8338
8339+#if PAGETABLE_LEVELS == 3
8340+#include <asm-generic/pgtable-nopud.h>
8341+#endif
8342+
8343+#if PAGETABLE_LEVELS == 2
8344+#include <asm-generic/pgtable-nopmd.h>
8345+#endif
8346+
8347+#ifndef __ASSEMBLY__
8348 #if PAGETABLE_LEVELS > 3
8349 typedef struct { pudval_t pud; } pud_t;
8350
8351@@ -219,8 +232,6 @@ static inline pudval_t native_pud_val(pu
8352 return pud.pud;
8353 }
8354 #else
8355-#include <asm-generic/pgtable-nopud.h>
8356-
8357 static inline pudval_t native_pud_val(pud_t pud)
8358 {
8359 return native_pgd_val(pud.pgd);
8360@@ -240,8 +251,6 @@ static inline pmdval_t native_pmd_val(pm
8361 return pmd.pmd;
8362 }
8363 #else
8364-#include <asm-generic/pgtable-nopmd.h>
8365-
8366 static inline pmdval_t native_pmd_val(pmd_t pmd)
8367 {
8368 return native_pgd_val(pmd.pud.pgd);
8369@@ -281,7 +290,6 @@ typedef struct page *pgtable_t;
8370
8371 extern pteval_t __supported_pte_mask;
8372 extern void set_nx(void);
8373-extern int nx_enabled;
8374
8375 #define pgprot_writecombine pgprot_writecombine
8376 extern pgprot_t pgprot_writecombine(pgprot_t prot);
8377diff -urNp linux-3.0.4/arch/x86/include/asm/processor.h linux-3.0.4/arch/x86/include/asm/processor.h
8378--- linux-3.0.4/arch/x86/include/asm/processor.h 2011-07-21 22:17:23.000000000 -0400
8379+++ linux-3.0.4/arch/x86/include/asm/processor.h 2011-08-23 21:47:55.000000000 -0400
8380@@ -266,7 +266,7 @@ struct tss_struct {
8381
8382 } ____cacheline_aligned;
8383
8384-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
8385+extern struct tss_struct init_tss[NR_CPUS];
8386
8387 /*
8388 * Save the original ist values for checking stack pointers during debugging
8389@@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(co
8390 */
8391 #define TASK_SIZE PAGE_OFFSET
8392 #define TASK_SIZE_MAX TASK_SIZE
8393+
8394+#ifdef CONFIG_PAX_SEGMEXEC
8395+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
8396+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
8397+#else
8398 #define STACK_TOP TASK_SIZE
8399-#define STACK_TOP_MAX STACK_TOP
8400+#endif
8401+
8402+#define STACK_TOP_MAX TASK_SIZE
8403
8404 #define INIT_THREAD { \
8405- .sp0 = sizeof(init_stack) + (long)&init_stack, \
8406+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
8407 .vm86_info = NULL, \
8408 .sysenter_cs = __KERNEL_CS, \
8409 .io_bitmap_ptr = NULL, \
8410@@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(co
8411 */
8412 #define INIT_TSS { \
8413 .x86_tss = { \
8414- .sp0 = sizeof(init_stack) + (long)&init_stack, \
8415+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
8416 .ss0 = __KERNEL_DS, \
8417 .ss1 = __KERNEL_CS, \
8418 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
8419@@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(co
8420 extern unsigned long thread_saved_pc(struct task_struct *tsk);
8421
8422 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
8423-#define KSTK_TOP(info) \
8424-({ \
8425- unsigned long *__ptr = (unsigned long *)(info); \
8426- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
8427-})
8428+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
8429
8430 /*
8431 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
8432@@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(str
8433 #define task_pt_regs(task) \
8434 ({ \
8435 struct pt_regs *__regs__; \
8436- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
8437+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
8438 __regs__ - 1; \
8439 })
8440
8441@@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(str
8442 /*
8443 * User space process size. 47bits minus one guard page.
8444 */
8445-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
8446+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
8447
8448 /* This decides where the kernel will search for a free chunk of vm
8449 * space during mmap's.
8450 */
8451 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
8452- 0xc0000000 : 0xFFFFe000)
8453+ 0xc0000000 : 0xFFFFf000)
8454
8455 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
8456 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
8457@@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(str
8458 #define STACK_TOP_MAX TASK_SIZE_MAX
8459
8460 #define INIT_THREAD { \
8461- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
8462+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
8463 }
8464
8465 #define INIT_TSS { \
8466- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
8467+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
8468 }
8469
8470 /*
8471@@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs
8472 */
8473 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
8474
8475+#ifdef CONFIG_PAX_SEGMEXEC
8476+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
8477+#endif
8478+
8479 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
8480
8481 /* Get/set a process' ability to use the timestamp counter instruction */
8482diff -urNp linux-3.0.4/arch/x86/include/asm/ptrace.h linux-3.0.4/arch/x86/include/asm/ptrace.h
8483--- linux-3.0.4/arch/x86/include/asm/ptrace.h 2011-07-21 22:17:23.000000000 -0400
8484+++ linux-3.0.4/arch/x86/include/asm/ptrace.h 2011-08-23 21:47:55.000000000 -0400
8485@@ -153,28 +153,29 @@ static inline unsigned long regs_return_
8486 }
8487
8488 /*
8489- * user_mode_vm(regs) determines whether a register set came from user mode.
8490+ * user_mode(regs) determines whether a register set came from user mode.
8491 * This is true if V8086 mode was enabled OR if the register set was from
8492 * protected mode with RPL-3 CS value. This tricky test checks that with
8493 * one comparison. Many places in the kernel can bypass this full check
8494- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
8495+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
8496+ * be used.
8497 */
8498-static inline int user_mode(struct pt_regs *regs)
8499+static inline int user_mode_novm(struct pt_regs *regs)
8500 {
8501 #ifdef CONFIG_X86_32
8502 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
8503 #else
8504- return !!(regs->cs & 3);
8505+ return !!(regs->cs & SEGMENT_RPL_MASK);
8506 #endif
8507 }
8508
8509-static inline int user_mode_vm(struct pt_regs *regs)
8510+static inline int user_mode(struct pt_regs *regs)
8511 {
8512 #ifdef CONFIG_X86_32
8513 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
8514 USER_RPL;
8515 #else
8516- return user_mode(regs);
8517+ return user_mode_novm(regs);
8518 #endif
8519 }
8520
8521diff -urNp linux-3.0.4/arch/x86/include/asm/reboot.h linux-3.0.4/arch/x86/include/asm/reboot.h
8522--- linux-3.0.4/arch/x86/include/asm/reboot.h 2011-07-21 22:17:23.000000000 -0400
8523+++ linux-3.0.4/arch/x86/include/asm/reboot.h 2011-08-23 21:47:55.000000000 -0400
8524@@ -6,19 +6,19 @@
8525 struct pt_regs;
8526
8527 struct machine_ops {
8528- void (*restart)(char *cmd);
8529- void (*halt)(void);
8530- void (*power_off)(void);
8531+ void (* __noreturn restart)(char *cmd);
8532+ void (* __noreturn halt)(void);
8533+ void (* __noreturn power_off)(void);
8534 void (*shutdown)(void);
8535 void (*crash_shutdown)(struct pt_regs *);
8536- void (*emergency_restart)(void);
8537-};
8538+ void (* __noreturn emergency_restart)(void);
8539+} __no_const;
8540
8541 extern struct machine_ops machine_ops;
8542
8543 void native_machine_crash_shutdown(struct pt_regs *regs);
8544 void native_machine_shutdown(void);
8545-void machine_real_restart(unsigned int type);
8546+void machine_real_restart(unsigned int type) __noreturn;
8547 /* These must match dispatch_table in reboot_32.S */
8548 #define MRR_BIOS 0
8549 #define MRR_APM 1
8550diff -urNp linux-3.0.4/arch/x86/include/asm/rwsem.h linux-3.0.4/arch/x86/include/asm/rwsem.h
8551--- linux-3.0.4/arch/x86/include/asm/rwsem.h 2011-07-21 22:17:23.000000000 -0400
8552+++ linux-3.0.4/arch/x86/include/asm/rwsem.h 2011-08-23 21:47:55.000000000 -0400
8553@@ -64,6 +64,14 @@ static inline void __down_read(struct rw
8554 {
8555 asm volatile("# beginning down_read\n\t"
8556 LOCK_PREFIX _ASM_INC "(%1)\n\t"
8557+
8558+#ifdef CONFIG_PAX_REFCOUNT
8559+ "jno 0f\n"
8560+ LOCK_PREFIX _ASM_DEC "(%1)\n"
8561+ "int $4\n0:\n"
8562+ _ASM_EXTABLE(0b, 0b)
8563+#endif
8564+
8565 /* adds 0x00000001 */
8566 " jns 1f\n"
8567 " call call_rwsem_down_read_failed\n"
8568@@ -85,6 +93,14 @@ static inline int __down_read_trylock(st
8569 "1:\n\t"
8570 " mov %1,%2\n\t"
8571 " add %3,%2\n\t"
8572+
8573+#ifdef CONFIG_PAX_REFCOUNT
8574+ "jno 0f\n"
8575+ "sub %3,%2\n"
8576+ "int $4\n0:\n"
8577+ _ASM_EXTABLE(0b, 0b)
8578+#endif
8579+
8580 " jle 2f\n\t"
8581 LOCK_PREFIX " cmpxchg %2,%0\n\t"
8582 " jnz 1b\n\t"
8583@@ -104,6 +120,14 @@ static inline void __down_write_nested(s
8584 long tmp;
8585 asm volatile("# beginning down_write\n\t"
8586 LOCK_PREFIX " xadd %1,(%2)\n\t"
8587+
8588+#ifdef CONFIG_PAX_REFCOUNT
8589+ "jno 0f\n"
8590+ "mov %1,(%2)\n"
8591+ "int $4\n0:\n"
8592+ _ASM_EXTABLE(0b, 0b)
8593+#endif
8594+
8595 /* adds 0xffff0001, returns the old value */
8596 " test %1,%1\n\t"
8597 /* was the count 0 before? */
8598@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_s
8599 long tmp;
8600 asm volatile("# beginning __up_read\n\t"
8601 LOCK_PREFIX " xadd %1,(%2)\n\t"
8602+
8603+#ifdef CONFIG_PAX_REFCOUNT
8604+ "jno 0f\n"
8605+ "mov %1,(%2)\n"
8606+ "int $4\n0:\n"
8607+ _ASM_EXTABLE(0b, 0b)
8608+#endif
8609+
8610 /* subtracts 1, returns the old value */
8611 " jns 1f\n\t"
8612 " call call_rwsem_wake\n" /* expects old value in %edx */
8613@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_
8614 long tmp;
8615 asm volatile("# beginning __up_write\n\t"
8616 LOCK_PREFIX " xadd %1,(%2)\n\t"
8617+
8618+#ifdef CONFIG_PAX_REFCOUNT
8619+ "jno 0f\n"
8620+ "mov %1,(%2)\n"
8621+ "int $4\n0:\n"
8622+ _ASM_EXTABLE(0b, 0b)
8623+#endif
8624+
8625 /* subtracts 0xffff0001, returns the old value */
8626 " jns 1f\n\t"
8627 " call call_rwsem_wake\n" /* expects old value in %edx */
8628@@ -176,6 +216,14 @@ static inline void __downgrade_write(str
8629 {
8630 asm volatile("# beginning __downgrade_write\n\t"
8631 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
8632+
8633+#ifdef CONFIG_PAX_REFCOUNT
8634+ "jno 0f\n"
8635+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
8636+ "int $4\n0:\n"
8637+ _ASM_EXTABLE(0b, 0b)
8638+#endif
8639+
8640 /*
8641 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
8642 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
8643@@ -194,7 +242,15 @@ static inline void __downgrade_write(str
8644 */
8645 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
8646 {
8647- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
8648+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
8649+
8650+#ifdef CONFIG_PAX_REFCOUNT
8651+ "jno 0f\n"
8652+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
8653+ "int $4\n0:\n"
8654+ _ASM_EXTABLE(0b, 0b)
8655+#endif
8656+
8657 : "+m" (sem->count)
8658 : "er" (delta));
8659 }
8660@@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(l
8661 {
8662 long tmp = delta;
8663
8664- asm volatile(LOCK_PREFIX "xadd %0,%1"
8665+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
8666+
8667+#ifdef CONFIG_PAX_REFCOUNT
8668+ "jno 0f\n"
8669+ "mov %0,%1\n"
8670+ "int $4\n0:\n"
8671+ _ASM_EXTABLE(0b, 0b)
8672+#endif
8673+
8674 : "+r" (tmp), "+m" (sem->count)
8675 : : "memory");
8676
8677diff -urNp linux-3.0.4/arch/x86/include/asm/segment.h linux-3.0.4/arch/x86/include/asm/segment.h
8678--- linux-3.0.4/arch/x86/include/asm/segment.h 2011-07-21 22:17:23.000000000 -0400
8679+++ linux-3.0.4/arch/x86/include/asm/segment.h 2011-08-23 21:47:55.000000000 -0400
8680@@ -64,8 +64,8 @@
8681 * 26 - ESPFIX small SS
8682 * 27 - per-cpu [ offset to per-cpu data area ]
8683 * 28 - stack_canary-20 [ for stack protector ]
8684- * 29 - unused
8685- * 30 - unused
8686+ * 29 - PCI BIOS CS
8687+ * 30 - PCI BIOS DS
8688 * 31 - TSS for double fault handler
8689 */
8690 #define GDT_ENTRY_TLS_MIN 6
8691@@ -79,6 +79,8 @@
8692
8693 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
8694
8695+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
8696+
8697 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
8698
8699 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
8700@@ -104,6 +106,12 @@
8701 #define __KERNEL_STACK_CANARY 0
8702 #endif
8703
8704+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
8705+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
8706+
8707+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
8708+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
8709+
8710 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
8711
8712 /*
8713@@ -141,7 +149,7 @@
8714 */
8715
8716 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
8717-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
8718+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
8719
8720
8721 #else
8722@@ -165,6 +173,8 @@
8723 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
8724 #define __USER32_DS __USER_DS
8725
8726+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
8727+
8728 #define GDT_ENTRY_TSS 8 /* needs two entries */
8729 #define GDT_ENTRY_LDT 10 /* needs two entries */
8730 #define GDT_ENTRY_TLS_MIN 12
8731@@ -185,6 +195,7 @@
8732 #endif
8733
8734 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
8735+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
8736 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
8737 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
8738 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
8739diff -urNp linux-3.0.4/arch/x86/include/asm/smp.h linux-3.0.4/arch/x86/include/asm/smp.h
8740--- linux-3.0.4/arch/x86/include/asm/smp.h 2011-07-21 22:17:23.000000000 -0400
8741+++ linux-3.0.4/arch/x86/include/asm/smp.h 2011-08-23 21:47:55.000000000 -0400
8742@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_
8743 /* cpus sharing the last level cache: */
8744 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
8745 DECLARE_PER_CPU(u16, cpu_llc_id);
8746-DECLARE_PER_CPU(int, cpu_number);
8747+DECLARE_PER_CPU(unsigned int, cpu_number);
8748
8749 static inline struct cpumask *cpu_sibling_mask(int cpu)
8750 {
8751@@ -77,7 +77,7 @@ struct smp_ops {
8752
8753 void (*send_call_func_ipi)(const struct cpumask *mask);
8754 void (*send_call_func_single_ipi)(int cpu);
8755-};
8756+} __no_const;
8757
8758 /* Globals due to paravirt */
8759 extern void set_cpu_sibling_map(int cpu);
8760@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitd
8761 extern int safe_smp_processor_id(void);
8762
8763 #elif defined(CONFIG_X86_64_SMP)
8764-#define raw_smp_processor_id() (percpu_read(cpu_number))
8765-
8766-#define stack_smp_processor_id() \
8767-({ \
8768- struct thread_info *ti; \
8769- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
8770- ti->cpu; \
8771-})
8772+#define raw_smp_processor_id() (percpu_read(cpu_number))
8773+#define stack_smp_processor_id() raw_smp_processor_id()
8774 #define safe_smp_processor_id() smp_processor_id()
8775
8776 #endif
8777diff -urNp linux-3.0.4/arch/x86/include/asm/spinlock.h linux-3.0.4/arch/x86/include/asm/spinlock.h
8778--- linux-3.0.4/arch/x86/include/asm/spinlock.h 2011-07-21 22:17:23.000000000 -0400
8779+++ linux-3.0.4/arch/x86/include/asm/spinlock.h 2011-08-23 21:47:55.000000000 -0400
8780@@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
8781 static inline void arch_read_lock(arch_rwlock_t *rw)
8782 {
8783 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
8784+
8785+#ifdef CONFIG_PAX_REFCOUNT
8786+ "jno 0f\n"
8787+ LOCK_PREFIX " addl $1,(%0)\n"
8788+ "int $4\n0:\n"
8789+ _ASM_EXTABLE(0b, 0b)
8790+#endif
8791+
8792 "jns 1f\n"
8793 "call __read_lock_failed\n\t"
8794 "1:\n"
8795@@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
8796 static inline void arch_write_lock(arch_rwlock_t *rw)
8797 {
8798 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
8799+
8800+#ifdef CONFIG_PAX_REFCOUNT
8801+ "jno 0f\n"
8802+ LOCK_PREFIX " addl %1,(%0)\n"
8803+ "int $4\n0:\n"
8804+ _ASM_EXTABLE(0b, 0b)
8805+#endif
8806+
8807 "jz 1f\n"
8808 "call __write_lock_failed\n\t"
8809 "1:\n"
8810@@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
8811
8812 static inline void arch_read_unlock(arch_rwlock_t *rw)
8813 {
8814- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
8815+ asm volatile(LOCK_PREFIX "incl %0\n"
8816+
8817+#ifdef CONFIG_PAX_REFCOUNT
8818+ "jno 0f\n"
8819+ LOCK_PREFIX "decl %0\n"
8820+ "int $4\n0:\n"
8821+ _ASM_EXTABLE(0b, 0b)
8822+#endif
8823+
8824+ :"+m" (rw->lock) : : "memory");
8825 }
8826
8827 static inline void arch_write_unlock(arch_rwlock_t *rw)
8828 {
8829- asm volatile(LOCK_PREFIX "addl %1, %0"
8830+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
8831+
8832+#ifdef CONFIG_PAX_REFCOUNT
8833+ "jno 0f\n"
8834+ LOCK_PREFIX "subl %1, %0\n"
8835+ "int $4\n0:\n"
8836+ _ASM_EXTABLE(0b, 0b)
8837+#endif
8838+
8839 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
8840 }
8841
8842diff -urNp linux-3.0.4/arch/x86/include/asm/stackprotector.h linux-3.0.4/arch/x86/include/asm/stackprotector.h
8843--- linux-3.0.4/arch/x86/include/asm/stackprotector.h 2011-07-21 22:17:23.000000000 -0400
8844+++ linux-3.0.4/arch/x86/include/asm/stackprotector.h 2011-08-23 21:47:55.000000000 -0400
8845@@ -48,7 +48,7 @@
8846 * head_32 for boot CPU and setup_per_cpu_areas() for others.
8847 */
8848 #define GDT_STACK_CANARY_INIT \
8849- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
8850+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
8851
8852 /*
8853 * Initialize the stackprotector canary value.
8854@@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
8855
8856 static inline void load_stack_canary_segment(void)
8857 {
8858-#ifdef CONFIG_X86_32
8859+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
8860 asm volatile ("mov %0, %%gs" : : "r" (0));
8861 #endif
8862 }
8863diff -urNp linux-3.0.4/arch/x86/include/asm/stacktrace.h linux-3.0.4/arch/x86/include/asm/stacktrace.h
8864--- linux-3.0.4/arch/x86/include/asm/stacktrace.h 2011-07-21 22:17:23.000000000 -0400
8865+++ linux-3.0.4/arch/x86/include/asm/stacktrace.h 2011-08-23 21:47:55.000000000 -0400
8866@@ -11,28 +11,20 @@
8867
8868 extern int kstack_depth_to_print;
8869
8870-struct thread_info;
8871+struct task_struct;
8872 struct stacktrace_ops;
8873
8874-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
8875- unsigned long *stack,
8876- unsigned long bp,
8877- const struct stacktrace_ops *ops,
8878- void *data,
8879- unsigned long *end,
8880- int *graph);
8881-
8882-extern unsigned long
8883-print_context_stack(struct thread_info *tinfo,
8884- unsigned long *stack, unsigned long bp,
8885- const struct stacktrace_ops *ops, void *data,
8886- unsigned long *end, int *graph);
8887-
8888-extern unsigned long
8889-print_context_stack_bp(struct thread_info *tinfo,
8890- unsigned long *stack, unsigned long bp,
8891- const struct stacktrace_ops *ops, void *data,
8892- unsigned long *end, int *graph);
8893+typedef unsigned long walk_stack_t(struct task_struct *task,
8894+ void *stack_start,
8895+ unsigned long *stack,
8896+ unsigned long bp,
8897+ const struct stacktrace_ops *ops,
8898+ void *data,
8899+ unsigned long *end,
8900+ int *graph);
8901+
8902+extern walk_stack_t print_context_stack;
8903+extern walk_stack_t print_context_stack_bp;
8904
8905 /* Generic stack tracer with callbacks */
8906
8907@@ -40,7 +32,7 @@ struct stacktrace_ops {
8908 void (*address)(void *data, unsigned long address, int reliable);
8909 /* On negative return stop dumping */
8910 int (*stack)(void *data, char *name);
8911- walk_stack_t walk_stack;
8912+ walk_stack_t *walk_stack;
8913 };
8914
8915 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
8916diff -urNp linux-3.0.4/arch/x86/include/asm/system.h linux-3.0.4/arch/x86/include/asm/system.h
8917--- linux-3.0.4/arch/x86/include/asm/system.h 2011-07-21 22:17:23.000000000 -0400
8918+++ linux-3.0.4/arch/x86/include/asm/system.h 2011-08-23 21:47:55.000000000 -0400
8919@@ -129,7 +129,7 @@ do { \
8920 "call __switch_to\n\t" \
8921 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
8922 __switch_canary \
8923- "movq %P[thread_info](%%rsi),%%r8\n\t" \
8924+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
8925 "movq %%rax,%%rdi\n\t" \
8926 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
8927 "jnz ret_from_fork\n\t" \
8928@@ -140,7 +140,7 @@ do { \
8929 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
8930 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
8931 [_tif_fork] "i" (_TIF_FORK), \
8932- [thread_info] "i" (offsetof(struct task_struct, stack)), \
8933+ [thread_info] "m" (current_tinfo), \
8934 [current_task] "m" (current_task) \
8935 __switch_canary_iparam \
8936 : "memory", "cc" __EXTRA_CLOBBER)
8937@@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
8938 {
8939 unsigned long __limit;
8940 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
8941- return __limit + 1;
8942+ return __limit;
8943 }
8944
8945 static inline void native_clts(void)
8946@@ -397,12 +397,12 @@ void enable_hlt(void);
8947
8948 void cpu_idle_wait(void);
8949
8950-extern unsigned long arch_align_stack(unsigned long sp);
8951+#define arch_align_stack(x) ((x) & ~0xfUL)
8952 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
8953
8954 void default_idle(void);
8955
8956-void stop_this_cpu(void *dummy);
8957+void stop_this_cpu(void *dummy) __noreturn;
8958
8959 /*
8960 * Force strict CPU ordering.
8961diff -urNp linux-3.0.4/arch/x86/include/asm/thread_info.h linux-3.0.4/arch/x86/include/asm/thread_info.h
8962--- linux-3.0.4/arch/x86/include/asm/thread_info.h 2011-07-21 22:17:23.000000000 -0400
8963+++ linux-3.0.4/arch/x86/include/asm/thread_info.h 2011-08-23 21:47:55.000000000 -0400
8964@@ -10,6 +10,7 @@
8965 #include <linux/compiler.h>
8966 #include <asm/page.h>
8967 #include <asm/types.h>
8968+#include <asm/percpu.h>
8969
8970 /*
8971 * low level task data that entry.S needs immediate access to
8972@@ -24,7 +25,6 @@ struct exec_domain;
8973 #include <asm/atomic.h>
8974
8975 struct thread_info {
8976- struct task_struct *task; /* main task structure */
8977 struct exec_domain *exec_domain; /* execution domain */
8978 __u32 flags; /* low level flags */
8979 __u32 status; /* thread synchronous flags */
8980@@ -34,18 +34,12 @@ struct thread_info {
8981 mm_segment_t addr_limit;
8982 struct restart_block restart_block;
8983 void __user *sysenter_return;
8984-#ifdef CONFIG_X86_32
8985- unsigned long previous_esp; /* ESP of the previous stack in
8986- case of nested (IRQ) stacks
8987- */
8988- __u8 supervisor_stack[0];
8989-#endif
8990+ unsigned long lowest_stack;
8991 int uaccess_err;
8992 };
8993
8994-#define INIT_THREAD_INFO(tsk) \
8995+#define INIT_THREAD_INFO \
8996 { \
8997- .task = &tsk, \
8998 .exec_domain = &default_exec_domain, \
8999 .flags = 0, \
9000 .cpu = 0, \
9001@@ -56,7 +50,7 @@ struct thread_info {
9002 }, \
9003 }
9004
9005-#define init_thread_info (init_thread_union.thread_info)
9006+#define init_thread_info (init_thread_union.stack)
9007 #define init_stack (init_thread_union.stack)
9008
9009 #else /* !__ASSEMBLY__ */
9010@@ -170,6 +164,23 @@ struct thread_info {
9011 ret; \
9012 })
9013
9014+#ifdef __ASSEMBLY__
9015+/* how to get the thread information struct from ASM */
9016+#define GET_THREAD_INFO(reg) \
9017+ mov PER_CPU_VAR(current_tinfo), reg
9018+
9019+/* use this one if reg already contains %esp */
9020+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
9021+#else
9022+/* how to get the thread information struct from C */
9023+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
9024+
9025+static __always_inline struct thread_info *current_thread_info(void)
9026+{
9027+ return percpu_read_stable(current_tinfo);
9028+}
9029+#endif
9030+
9031 #ifdef CONFIG_X86_32
9032
9033 #define STACK_WARN (THREAD_SIZE/8)
9034@@ -180,35 +191,13 @@ struct thread_info {
9035 */
9036 #ifndef __ASSEMBLY__
9037
9038-
9039 /* how to get the current stack pointer from C */
9040 register unsigned long current_stack_pointer asm("esp") __used;
9041
9042-/* how to get the thread information struct from C */
9043-static inline struct thread_info *current_thread_info(void)
9044-{
9045- return (struct thread_info *)
9046- (current_stack_pointer & ~(THREAD_SIZE - 1));
9047-}
9048-
9049-#else /* !__ASSEMBLY__ */
9050-
9051-/* how to get the thread information struct from ASM */
9052-#define GET_THREAD_INFO(reg) \
9053- movl $-THREAD_SIZE, reg; \
9054- andl %esp, reg
9055-
9056-/* use this one if reg already contains %esp */
9057-#define GET_THREAD_INFO_WITH_ESP(reg) \
9058- andl $-THREAD_SIZE, reg
9059-
9060 #endif
9061
9062 #else /* X86_32 */
9063
9064-#include <asm/percpu.h>
9065-#define KERNEL_STACK_OFFSET (5*8)
9066-
9067 /*
9068 * macros/functions for gaining access to the thread information structure
9069 * preempt_count needs to be 1 initially, until the scheduler is functional.
9070@@ -216,21 +205,8 @@ static inline struct thread_info *curren
9071 #ifndef __ASSEMBLY__
9072 DECLARE_PER_CPU(unsigned long, kernel_stack);
9073
9074-static inline struct thread_info *current_thread_info(void)
9075-{
9076- struct thread_info *ti;
9077- ti = (void *)(percpu_read_stable(kernel_stack) +
9078- KERNEL_STACK_OFFSET - THREAD_SIZE);
9079- return ti;
9080-}
9081-
9082-#else /* !__ASSEMBLY__ */
9083-
9084-/* how to get the thread information struct from ASM */
9085-#define GET_THREAD_INFO(reg) \
9086- movq PER_CPU_VAR(kernel_stack),reg ; \
9087- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
9088-
9089+/* how to get the current stack pointer from C */
9090+register unsigned long current_stack_pointer asm("rsp") __used;
9091 #endif
9092
9093 #endif /* !X86_32 */
9094@@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
9095 extern void free_thread_info(struct thread_info *ti);
9096 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
9097 #define arch_task_cache_init arch_task_cache_init
9098+
9099+#define __HAVE_THREAD_FUNCTIONS
9100+#define task_thread_info(task) (&(task)->tinfo)
9101+#define task_stack_page(task) ((task)->stack)
9102+#define setup_thread_stack(p, org) do {} while (0)
9103+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
9104+
9105+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
9106+extern struct task_struct *alloc_task_struct_node(int node);
9107+extern void free_task_struct(struct task_struct *);
9108+
9109 #endif
9110 #endif /* _ASM_X86_THREAD_INFO_H */
9111diff -urNp linux-3.0.4/arch/x86/include/asm/uaccess_32.h linux-3.0.4/arch/x86/include/asm/uaccess_32.h
9112--- linux-3.0.4/arch/x86/include/asm/uaccess_32.h 2011-07-21 22:17:23.000000000 -0400
9113+++ linux-3.0.4/arch/x86/include/asm/uaccess_32.h 2011-08-23 21:48:14.000000000 -0400
9114@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_u
9115 static __always_inline unsigned long __must_check
9116 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
9117 {
9118+ pax_track_stack();
9119+
9120+ if ((long)n < 0)
9121+ return n;
9122+
9123 if (__builtin_constant_p(n)) {
9124 unsigned long ret;
9125
9126@@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to,
9127 return ret;
9128 }
9129 }
9130+ if (!__builtin_constant_p(n))
9131+ check_object_size(from, n, true);
9132 return __copy_to_user_ll(to, from, n);
9133 }
9134
9135@@ -82,12 +89,16 @@ static __always_inline unsigned long __m
9136 __copy_to_user(void __user *to, const void *from, unsigned long n)
9137 {
9138 might_fault();
9139+
9140 return __copy_to_user_inatomic(to, from, n);
9141 }
9142
9143 static __always_inline unsigned long
9144 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
9145 {
9146+ if ((long)n < 0)
9147+ return n;
9148+
9149 /* Avoid zeroing the tail if the copy fails..
9150 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
9151 * but as the zeroing behaviour is only significant when n is not
9152@@ -137,6 +148,12 @@ static __always_inline unsigned long
9153 __copy_from_user(void *to, const void __user *from, unsigned long n)
9154 {
9155 might_fault();
9156+
9157+ pax_track_stack();
9158+
9159+ if ((long)n < 0)
9160+ return n;
9161+
9162 if (__builtin_constant_p(n)) {
9163 unsigned long ret;
9164
9165@@ -152,6 +169,8 @@ __copy_from_user(void *to, const void __
9166 return ret;
9167 }
9168 }
9169+ if (!__builtin_constant_p(n))
9170+ check_object_size(to, n, false);
9171 return __copy_from_user_ll(to, from, n);
9172 }
9173
9174@@ -159,6 +178,10 @@ static __always_inline unsigned long __c
9175 const void __user *from, unsigned long n)
9176 {
9177 might_fault();
9178+
9179+ if ((long)n < 0)
9180+ return n;
9181+
9182 if (__builtin_constant_p(n)) {
9183 unsigned long ret;
9184
9185@@ -181,15 +204,19 @@ static __always_inline unsigned long
9186 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
9187 unsigned long n)
9188 {
9189- return __copy_from_user_ll_nocache_nozero(to, from, n);
9190-}
9191+ if ((long)n < 0)
9192+ return n;
9193
9194-unsigned long __must_check copy_to_user(void __user *to,
9195- const void *from, unsigned long n);
9196-unsigned long __must_check _copy_from_user(void *to,
9197- const void __user *from,
9198- unsigned long n);
9199+ return __copy_from_user_ll_nocache_nozero(to, from, n);
9200+}
9201
9202+extern void copy_to_user_overflow(void)
9203+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
9204+ __compiletime_error("copy_to_user() buffer size is not provably correct")
9205+#else
9206+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
9207+#endif
9208+;
9209
9210 extern void copy_from_user_overflow(void)
9211 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
9212@@ -199,17 +226,61 @@ extern void copy_from_user_overflow(void
9213 #endif
9214 ;
9215
9216-static inline unsigned long __must_check copy_from_user(void *to,
9217- const void __user *from,
9218- unsigned long n)
9219+/**
9220+ * copy_to_user: - Copy a block of data into user space.
9221+ * @to: Destination address, in user space.
9222+ * @from: Source address, in kernel space.
9223+ * @n: Number of bytes to copy.
9224+ *
9225+ * Context: User context only. This function may sleep.
9226+ *
9227+ * Copy data from kernel space to user space.
9228+ *
9229+ * Returns number of bytes that could not be copied.
9230+ * On success, this will be zero.
9231+ */
9232+static inline unsigned long __must_check
9233+copy_to_user(void __user *to, const void *from, unsigned long n)
9234+{
9235+ int sz = __compiletime_object_size(from);
9236+
9237+ if (unlikely(sz != -1 && sz < n))
9238+ copy_to_user_overflow();
9239+ else if (access_ok(VERIFY_WRITE, to, n))
9240+ n = __copy_to_user(to, from, n);
9241+ return n;
9242+}
9243+
9244+/**
9245+ * copy_from_user: - Copy a block of data from user space.
9246+ * @to: Destination address, in kernel space.
9247+ * @from: Source address, in user space.
9248+ * @n: Number of bytes to copy.
9249+ *
9250+ * Context: User context only. This function may sleep.
9251+ *
9252+ * Copy data from user space to kernel space.
9253+ *
9254+ * Returns number of bytes that could not be copied.
9255+ * On success, this will be zero.
9256+ *
9257+ * If some data could not be copied, this function will pad the copied
9258+ * data to the requested size using zero bytes.
9259+ */
9260+static inline unsigned long __must_check
9261+copy_from_user(void *to, const void __user *from, unsigned long n)
9262 {
9263 int sz = __compiletime_object_size(to);
9264
9265- if (likely(sz == -1 || sz >= n))
9266- n = _copy_from_user(to, from, n);
9267- else
9268+ if (unlikely(sz != -1 && sz < n))
9269 copy_from_user_overflow();
9270-
9271+ else if (access_ok(VERIFY_READ, from, n))
9272+ n = __copy_from_user(to, from, n);
9273+ else if ((long)n > 0) {
9274+ if (!__builtin_constant_p(n))
9275+ check_object_size(to, n, false);
9276+ memset(to, 0, n);
9277+ }
9278 return n;
9279 }
9280
9281diff -urNp linux-3.0.4/arch/x86/include/asm/uaccess_64.h linux-3.0.4/arch/x86/include/asm/uaccess_64.h
9282--- linux-3.0.4/arch/x86/include/asm/uaccess_64.h 2011-07-21 22:17:23.000000000 -0400
9283+++ linux-3.0.4/arch/x86/include/asm/uaccess_64.h 2011-08-23 21:48:14.000000000 -0400
9284@@ -10,6 +10,9 @@
9285 #include <asm/alternative.h>
9286 #include <asm/cpufeature.h>
9287 #include <asm/page.h>
9288+#include <asm/pgtable.h>
9289+
9290+#define set_fs(x) (current_thread_info()->addr_limit = (x))
9291
9292 /*
9293 * Copy To/From Userspace
9294@@ -36,26 +39,26 @@ copy_user_generic(void *to, const void *
9295 return ret;
9296 }
9297
9298-__must_check unsigned long
9299-_copy_to_user(void __user *to, const void *from, unsigned len);
9300-__must_check unsigned long
9301-_copy_from_user(void *to, const void __user *from, unsigned len);
9302+static __always_inline __must_check unsigned long
9303+__copy_to_user(void __user *to, const void *from, unsigned len);
9304+static __always_inline __must_check unsigned long
9305+__copy_from_user(void *to, const void __user *from, unsigned len);
9306 __must_check unsigned long
9307 copy_in_user(void __user *to, const void __user *from, unsigned len);
9308
9309 static inline unsigned long __must_check copy_from_user(void *to,
9310 const void __user *from,
9311- unsigned long n)
9312+ unsigned n)
9313 {
9314- int sz = __compiletime_object_size(to);
9315-
9316 might_fault();
9317- if (likely(sz == -1 || sz >= n))
9318- n = _copy_from_user(to, from, n);
9319-#ifdef CONFIG_DEBUG_VM
9320- else
9321- WARN(1, "Buffer overflow detected!\n");
9322-#endif
9323+
9324+ if (access_ok(VERIFY_READ, from, n))
9325+ n = __copy_from_user(to, from, n);
9326+ else if ((int)n > 0) {
9327+ if (!__builtin_constant_p(n))
9328+ check_object_size(to, n, false);
9329+ memset(to, 0, n);
9330+ }
9331 return n;
9332 }
9333
9334@@ -64,110 +67,198 @@ int copy_to_user(void __user *dst, const
9335 {
9336 might_fault();
9337
9338- return _copy_to_user(dst, src, size);
9339+ if (access_ok(VERIFY_WRITE, dst, size))
9340+ size = __copy_to_user(dst, src, size);
9341+ return size;
9342 }
9343
9344 static __always_inline __must_check
9345-int __copy_from_user(void *dst, const void __user *src, unsigned size)
9346+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
9347 {
9348- int ret = 0;
9349+ int sz = __compiletime_object_size(dst);
9350+ unsigned ret = 0;
9351
9352 might_fault();
9353- if (!__builtin_constant_p(size))
9354- return copy_user_generic(dst, (__force void *)src, size);
9355+
9356+ pax_track_stack();
9357+
9358+ if ((int)size < 0)
9359+ return size;
9360+
9361+#ifdef CONFIG_PAX_MEMORY_UDEREF
9362+ if (!__access_ok(VERIFY_READ, src, size))
9363+ return size;
9364+#endif
9365+
9366+ if (unlikely(sz != -1 && sz < size)) {
9367+#ifdef CONFIG_DEBUG_VM
9368+ WARN(1, "Buffer overflow detected!\n");
9369+#endif
9370+ return size;
9371+ }
9372+
9373+ if (!__builtin_constant_p(size)) {
9374+ check_object_size(dst, size, false);
9375+
9376+#ifdef CONFIG_PAX_MEMORY_UDEREF
9377+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9378+ src += PAX_USER_SHADOW_BASE;
9379+#endif
9380+
9381+ return copy_user_generic(dst, (__force const void *)src, size);
9382+ }
9383 switch (size) {
9384- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
9385+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
9386 ret, "b", "b", "=q", 1);
9387 return ret;
9388- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
9389+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
9390 ret, "w", "w", "=r", 2);
9391 return ret;
9392- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
9393+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
9394 ret, "l", "k", "=r", 4);
9395 return ret;
9396- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
9397+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9398 ret, "q", "", "=r", 8);
9399 return ret;
9400 case 10:
9401- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
9402+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9403 ret, "q", "", "=r", 10);
9404 if (unlikely(ret))
9405 return ret;
9406 __get_user_asm(*(u16 *)(8 + (char *)dst),
9407- (u16 __user *)(8 + (char __user *)src),
9408+ (const u16 __user *)(8 + (const char __user *)src),
9409 ret, "w", "w", "=r", 2);
9410 return ret;
9411 case 16:
9412- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
9413+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9414 ret, "q", "", "=r", 16);
9415 if (unlikely(ret))
9416 return ret;
9417 __get_user_asm(*(u64 *)(8 + (char *)dst),
9418- (u64 __user *)(8 + (char __user *)src),
9419+ (const u64 __user *)(8 + (const char __user *)src),
9420 ret, "q", "", "=r", 8);
9421 return ret;
9422 default:
9423- return copy_user_generic(dst, (__force void *)src, size);
9424+
9425+#ifdef CONFIG_PAX_MEMORY_UDEREF
9426+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9427+ src += PAX_USER_SHADOW_BASE;
9428+#endif
9429+
9430+ return copy_user_generic(dst, (__force const void *)src, size);
9431 }
9432 }
9433
9434 static __always_inline __must_check
9435-int __copy_to_user(void __user *dst, const void *src, unsigned size)
9436+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
9437 {
9438- int ret = 0;
9439+ int sz = __compiletime_object_size(src);
9440+ unsigned ret = 0;
9441
9442 might_fault();
9443- if (!__builtin_constant_p(size))
9444+
9445+ pax_track_stack();
9446+
9447+ if ((int)size < 0)
9448+ return size;
9449+
9450+#ifdef CONFIG_PAX_MEMORY_UDEREF
9451+ if (!__access_ok(VERIFY_WRITE, dst, size))
9452+ return size;
9453+#endif
9454+
9455+ if (unlikely(sz != -1 && sz < size)) {
9456+#ifdef CONFIG_DEBUG_VM
9457+ WARN(1, "Buffer overflow detected!\n");
9458+#endif
9459+ return size;
9460+ }
9461+
9462+ if (!__builtin_constant_p(size)) {
9463+ check_object_size(src, size, true);
9464+
9465+#ifdef CONFIG_PAX_MEMORY_UDEREF
9466+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9467+ dst += PAX_USER_SHADOW_BASE;
9468+#endif
9469+
9470 return copy_user_generic((__force void *)dst, src, size);
9471+ }
9472 switch (size) {
9473- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
9474+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
9475 ret, "b", "b", "iq", 1);
9476 return ret;
9477- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
9478+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
9479 ret, "w", "w", "ir", 2);
9480 return ret;
9481- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
9482+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
9483 ret, "l", "k", "ir", 4);
9484 return ret;
9485- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
9486+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9487 ret, "q", "", "er", 8);
9488 return ret;
9489 case 10:
9490- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
9491+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9492 ret, "q", "", "er", 10);
9493 if (unlikely(ret))
9494 return ret;
9495 asm("":::"memory");
9496- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
9497+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
9498 ret, "w", "w", "ir", 2);
9499 return ret;
9500 case 16:
9501- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
9502+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9503 ret, "q", "", "er", 16);
9504 if (unlikely(ret))
9505 return ret;
9506 asm("":::"memory");
9507- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
9508+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
9509 ret, "q", "", "er", 8);
9510 return ret;
9511 default:
9512+
9513+#ifdef CONFIG_PAX_MEMORY_UDEREF
9514+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9515+ dst += PAX_USER_SHADOW_BASE;
9516+#endif
9517+
9518 return copy_user_generic((__force void *)dst, src, size);
9519 }
9520 }
9521
9522 static __always_inline __must_check
9523-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
9524+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
9525 {
9526- int ret = 0;
9527+ unsigned ret = 0;
9528
9529 might_fault();
9530- if (!__builtin_constant_p(size))
9531+
9532+ if ((int)size < 0)
9533+ return size;
9534+
9535+#ifdef CONFIG_PAX_MEMORY_UDEREF
9536+ if (!__access_ok(VERIFY_READ, src, size))
9537+ return size;
9538+ if (!__access_ok(VERIFY_WRITE, dst, size))
9539+ return size;
9540+#endif
9541+
9542+ if (!__builtin_constant_p(size)) {
9543+
9544+#ifdef CONFIG_PAX_MEMORY_UDEREF
9545+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9546+ src += PAX_USER_SHADOW_BASE;
9547+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9548+ dst += PAX_USER_SHADOW_BASE;
9549+#endif
9550+
9551 return copy_user_generic((__force void *)dst,
9552- (__force void *)src, size);
9553+ (__force const void *)src, size);
9554+ }
9555 switch (size) {
9556 case 1: {
9557 u8 tmp;
9558- __get_user_asm(tmp, (u8 __user *)src,
9559+ __get_user_asm(tmp, (const u8 __user *)src,
9560 ret, "b", "b", "=q", 1);
9561 if (likely(!ret))
9562 __put_user_asm(tmp, (u8 __user *)dst,
9563@@ -176,7 +267,7 @@ int __copy_in_user(void __user *dst, con
9564 }
9565 case 2: {
9566 u16 tmp;
9567- __get_user_asm(tmp, (u16 __user *)src,
9568+ __get_user_asm(tmp, (const u16 __user *)src,
9569 ret, "w", "w", "=r", 2);
9570 if (likely(!ret))
9571 __put_user_asm(tmp, (u16 __user *)dst,
9572@@ -186,7 +277,7 @@ int __copy_in_user(void __user *dst, con
9573
9574 case 4: {
9575 u32 tmp;
9576- __get_user_asm(tmp, (u32 __user *)src,
9577+ __get_user_asm(tmp, (const u32 __user *)src,
9578 ret, "l", "k", "=r", 4);
9579 if (likely(!ret))
9580 __put_user_asm(tmp, (u32 __user *)dst,
9581@@ -195,7 +286,7 @@ int __copy_in_user(void __user *dst, con
9582 }
9583 case 8: {
9584 u64 tmp;
9585- __get_user_asm(tmp, (u64 __user *)src,
9586+ __get_user_asm(tmp, (const u64 __user *)src,
9587 ret, "q", "", "=r", 8);
9588 if (likely(!ret))
9589 __put_user_asm(tmp, (u64 __user *)dst,
9590@@ -203,8 +294,16 @@ int __copy_in_user(void __user *dst, con
9591 return ret;
9592 }
9593 default:
9594+
9595+#ifdef CONFIG_PAX_MEMORY_UDEREF
9596+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9597+ src += PAX_USER_SHADOW_BASE;
9598+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9599+ dst += PAX_USER_SHADOW_BASE;
9600+#endif
9601+
9602 return copy_user_generic((__force void *)dst,
9603- (__force void *)src, size);
9604+ (__force const void *)src, size);
9605 }
9606 }
9607
9608@@ -221,33 +320,72 @@ __must_check unsigned long __clear_user(
9609 static __must_check __always_inline int
9610 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
9611 {
9612+ pax_track_stack();
9613+
9614+ if ((int)size < 0)
9615+ return size;
9616+
9617+#ifdef CONFIG_PAX_MEMORY_UDEREF
9618+ if (!__access_ok(VERIFY_READ, src, size))
9619+ return size;
9620+
9621+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9622+ src += PAX_USER_SHADOW_BASE;
9623+#endif
9624+
9625 return copy_user_generic(dst, (__force const void *)src, size);
9626 }
9627
9628-static __must_check __always_inline int
9629+static __must_check __always_inline unsigned long
9630 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
9631 {
9632+ if ((int)size < 0)
9633+ return size;
9634+
9635+#ifdef CONFIG_PAX_MEMORY_UDEREF
9636+ if (!__access_ok(VERIFY_WRITE, dst, size))
9637+ return size;
9638+
9639+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9640+ dst += PAX_USER_SHADOW_BASE;
9641+#endif
9642+
9643 return copy_user_generic((__force void *)dst, src, size);
9644 }
9645
9646-extern long __copy_user_nocache(void *dst, const void __user *src,
9647+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
9648 unsigned size, int zerorest);
9649
9650-static inline int
9651-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
9652+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
9653 {
9654 might_sleep();
9655+
9656+ if ((int)size < 0)
9657+ return size;
9658+
9659+#ifdef CONFIG_PAX_MEMORY_UDEREF
9660+ if (!__access_ok(VERIFY_READ, src, size))
9661+ return size;
9662+#endif
9663+
9664 return __copy_user_nocache(dst, src, size, 1);
9665 }
9666
9667-static inline int
9668-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
9669+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
9670 unsigned size)
9671 {
9672+ if ((int)size < 0)
9673+ return size;
9674+
9675+#ifdef CONFIG_PAX_MEMORY_UDEREF
9676+ if (!__access_ok(VERIFY_READ, src, size))
9677+ return size;
9678+#endif
9679+
9680 return __copy_user_nocache(dst, src, size, 0);
9681 }
9682
9683-unsigned long
9684+extern unsigned long
9685 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
9686
9687 #endif /* _ASM_X86_UACCESS_64_H */
9688diff -urNp linux-3.0.4/arch/x86/include/asm/uaccess.h linux-3.0.4/arch/x86/include/asm/uaccess.h
9689--- linux-3.0.4/arch/x86/include/asm/uaccess.h 2011-07-21 22:17:23.000000000 -0400
9690+++ linux-3.0.4/arch/x86/include/asm/uaccess.h 2011-08-23 21:47:55.000000000 -0400
9691@@ -7,12 +7,15 @@
9692 #include <linux/compiler.h>
9693 #include <linux/thread_info.h>
9694 #include <linux/string.h>
9695+#include <linux/sched.h>
9696 #include <asm/asm.h>
9697 #include <asm/page.h>
9698
9699 #define VERIFY_READ 0
9700 #define VERIFY_WRITE 1
9701
9702+extern void check_object_size(const void *ptr, unsigned long n, bool to);
9703+
9704 /*
9705 * The fs value determines whether argument validity checking should be
9706 * performed or not. If get_fs() == USER_DS, checking is performed, with
9707@@ -28,7 +31,12 @@
9708
9709 #define get_ds() (KERNEL_DS)
9710 #define get_fs() (current_thread_info()->addr_limit)
9711+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
9712+void __set_fs(mm_segment_t x);
9713+void set_fs(mm_segment_t x);
9714+#else
9715 #define set_fs(x) (current_thread_info()->addr_limit = (x))
9716+#endif
9717
9718 #define segment_eq(a, b) ((a).seg == (b).seg)
9719
9720@@ -76,7 +84,33 @@
9721 * checks that the pointer is in the user space range - after calling
9722 * this function, memory access functions may still return -EFAULT.
9723 */
9724-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
9725+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
9726+#define access_ok(type, addr, size) \
9727+({ \
9728+ long __size = size; \
9729+ unsigned long __addr = (unsigned long)addr; \
9730+ unsigned long __addr_ao = __addr & PAGE_MASK; \
9731+ unsigned long __end_ao = __addr + __size - 1; \
9732+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
9733+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
9734+ while(__addr_ao <= __end_ao) { \
9735+ char __c_ao; \
9736+ __addr_ao += PAGE_SIZE; \
9737+ if (__size > PAGE_SIZE) \
9738+ cond_resched(); \
9739+ if (__get_user(__c_ao, (char __user *)__addr)) \
9740+ break; \
9741+ if (type != VERIFY_WRITE) { \
9742+ __addr = __addr_ao; \
9743+ continue; \
9744+ } \
9745+ if (__put_user(__c_ao, (char __user *)__addr)) \
9746+ break; \
9747+ __addr = __addr_ao; \
9748+ } \
9749+ } \
9750+ __ret_ao; \
9751+})
9752
9753 /*
9754 * The exception table consists of pairs of addresses: the first is the
9755@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
9756 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
9757 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
9758
9759-
9760+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
9761+#define __copyuser_seg "gs;"
9762+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
9763+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
9764+#else
9765+#define __copyuser_seg
9766+#define __COPYUSER_SET_ES
9767+#define __COPYUSER_RESTORE_ES
9768+#endif
9769
9770 #ifdef CONFIG_X86_32
9771 #define __put_user_asm_u64(x, addr, err, errret) \
9772- asm volatile("1: movl %%eax,0(%2)\n" \
9773- "2: movl %%edx,4(%2)\n" \
9774+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
9775+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
9776 "3:\n" \
9777 ".section .fixup,\"ax\"\n" \
9778 "4: movl %3,%0\n" \
9779@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
9780 : "A" (x), "r" (addr), "i" (errret), "0" (err))
9781
9782 #define __put_user_asm_ex_u64(x, addr) \
9783- asm volatile("1: movl %%eax,0(%1)\n" \
9784- "2: movl %%edx,4(%1)\n" \
9785+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
9786+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
9787 "3:\n" \
9788 _ASM_EXTABLE(1b, 2b - 1b) \
9789 _ASM_EXTABLE(2b, 3b - 2b) \
9790@@ -373,7 +415,7 @@ do { \
9791 } while (0)
9792
9793 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
9794- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
9795+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
9796 "2:\n" \
9797 ".section .fixup,\"ax\"\n" \
9798 "3: mov %3,%0\n" \
9799@@ -381,7 +423,7 @@ do { \
9800 " jmp 2b\n" \
9801 ".previous\n" \
9802 _ASM_EXTABLE(1b, 3b) \
9803- : "=r" (err), ltype(x) \
9804+ : "=r" (err), ltype (x) \
9805 : "m" (__m(addr)), "i" (errret), "0" (err))
9806
9807 #define __get_user_size_ex(x, ptr, size) \
9808@@ -406,7 +448,7 @@ do { \
9809 } while (0)
9810
9811 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
9812- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
9813+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
9814 "2:\n" \
9815 _ASM_EXTABLE(1b, 2b - 1b) \
9816 : ltype(x) : "m" (__m(addr)))
9817@@ -423,13 +465,24 @@ do { \
9818 int __gu_err; \
9819 unsigned long __gu_val; \
9820 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
9821- (x) = (__force __typeof__(*(ptr)))__gu_val; \
9822+ (x) = (__typeof__(*(ptr)))__gu_val; \
9823 __gu_err; \
9824 })
9825
9826 /* FIXME: this hack is definitely wrong -AK */
9827 struct __large_struct { unsigned long buf[100]; };
9828-#define __m(x) (*(struct __large_struct __user *)(x))
9829+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9830+#define ____m(x) \
9831+({ \
9832+ unsigned long ____x = (unsigned long)(x); \
9833+ if (____x < PAX_USER_SHADOW_BASE) \
9834+ ____x += PAX_USER_SHADOW_BASE; \
9835+ (void __user *)____x; \
9836+})
9837+#else
9838+#define ____m(x) (x)
9839+#endif
9840+#define __m(x) (*(struct __large_struct __user *)____m(x))
9841
9842 /*
9843 * Tell gcc we read from memory instead of writing: this is because
9844@@ -437,7 +490,7 @@ struct __large_struct { unsigned long bu
9845 * aliasing issues.
9846 */
9847 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
9848- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
9849+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
9850 "2:\n" \
9851 ".section .fixup,\"ax\"\n" \
9852 "3: mov %3,%0\n" \
9853@@ -445,10 +498,10 @@ struct __large_struct { unsigned long bu
9854 ".previous\n" \
9855 _ASM_EXTABLE(1b, 3b) \
9856 : "=r"(err) \
9857- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
9858+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
9859
9860 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
9861- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
9862+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
9863 "2:\n" \
9864 _ASM_EXTABLE(1b, 2b - 1b) \
9865 : : ltype(x), "m" (__m(addr)))
9866@@ -487,8 +540,12 @@ struct __large_struct { unsigned long bu
9867 * On error, the variable @x is set to zero.
9868 */
9869
9870+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9871+#define __get_user(x, ptr) get_user((x), (ptr))
9872+#else
9873 #define __get_user(x, ptr) \
9874 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
9875+#endif
9876
9877 /**
9878 * __put_user: - Write a simple value into user space, with less checking.
9879@@ -510,8 +567,12 @@ struct __large_struct { unsigned long bu
9880 * Returns zero on success, or -EFAULT on error.
9881 */
9882
9883+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9884+#define __put_user(x, ptr) put_user((x), (ptr))
9885+#else
9886 #define __put_user(x, ptr) \
9887 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
9888+#endif
9889
9890 #define __get_user_unaligned __get_user
9891 #define __put_user_unaligned __put_user
9892@@ -529,7 +590,7 @@ struct __large_struct { unsigned long bu
9893 #define get_user_ex(x, ptr) do { \
9894 unsigned long __gue_val; \
9895 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
9896- (x) = (__force __typeof__(*(ptr)))__gue_val; \
9897+ (x) = (__typeof__(*(ptr)))__gue_val; \
9898 } while (0)
9899
9900 #ifdef CONFIG_X86_WP_WORKS_OK
9901diff -urNp linux-3.0.4/arch/x86/include/asm/x86_init.h linux-3.0.4/arch/x86/include/asm/x86_init.h
9902--- linux-3.0.4/arch/x86/include/asm/x86_init.h 2011-07-21 22:17:23.000000000 -0400
9903+++ linux-3.0.4/arch/x86/include/asm/x86_init.h 2011-08-23 21:47:55.000000000 -0400
9904@@ -28,7 +28,7 @@ struct x86_init_mpparse {
9905 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
9906 void (*find_smp_config)(void);
9907 void (*get_smp_config)(unsigned int early);
9908-};
9909+} __no_const;
9910
9911 /**
9912 * struct x86_init_resources - platform specific resource related ops
9913@@ -42,7 +42,7 @@ struct x86_init_resources {
9914 void (*probe_roms)(void);
9915 void (*reserve_resources)(void);
9916 char *(*memory_setup)(void);
9917-};
9918+} __no_const;
9919
9920 /**
9921 * struct x86_init_irqs - platform specific interrupt setup
9922@@ -55,7 +55,7 @@ struct x86_init_irqs {
9923 void (*pre_vector_init)(void);
9924 void (*intr_init)(void);
9925 void (*trap_init)(void);
9926-};
9927+} __no_const;
9928
9929 /**
9930 * struct x86_init_oem - oem platform specific customizing functions
9931@@ -65,7 +65,7 @@ struct x86_init_irqs {
9932 struct x86_init_oem {
9933 void (*arch_setup)(void);
9934 void (*banner)(void);
9935-};
9936+} __no_const;
9937
9938 /**
9939 * struct x86_init_mapping - platform specific initial kernel pagetable setup
9940@@ -76,7 +76,7 @@ struct x86_init_oem {
9941 */
9942 struct x86_init_mapping {
9943 void (*pagetable_reserve)(u64 start, u64 end);
9944-};
9945+} __no_const;
9946
9947 /**
9948 * struct x86_init_paging - platform specific paging functions
9949@@ -86,7 +86,7 @@ struct x86_init_mapping {
9950 struct x86_init_paging {
9951 void (*pagetable_setup_start)(pgd_t *base);
9952 void (*pagetable_setup_done)(pgd_t *base);
9953-};
9954+} __no_const;
9955
9956 /**
9957 * struct x86_init_timers - platform specific timer setup
9958@@ -101,7 +101,7 @@ struct x86_init_timers {
9959 void (*tsc_pre_init)(void);
9960 void (*timer_init)(void);
9961 void (*wallclock_init)(void);
9962-};
9963+} __no_const;
9964
9965 /**
9966 * struct x86_init_iommu - platform specific iommu setup
9967@@ -109,7 +109,7 @@ struct x86_init_timers {
9968 */
9969 struct x86_init_iommu {
9970 int (*iommu_init)(void);
9971-};
9972+} __no_const;
9973
9974 /**
9975 * struct x86_init_pci - platform specific pci init functions
9976@@ -123,7 +123,7 @@ struct x86_init_pci {
9977 int (*init)(void);
9978 void (*init_irq)(void);
9979 void (*fixup_irqs)(void);
9980-};
9981+} __no_const;
9982
9983 /**
9984 * struct x86_init_ops - functions for platform specific setup
9985@@ -139,7 +139,7 @@ struct x86_init_ops {
9986 struct x86_init_timers timers;
9987 struct x86_init_iommu iommu;
9988 struct x86_init_pci pci;
9989-};
9990+} __no_const;
9991
9992 /**
9993 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
9994@@ -147,7 +147,7 @@ struct x86_init_ops {
9995 */
9996 struct x86_cpuinit_ops {
9997 void (*setup_percpu_clockev)(void);
9998-};
9999+} __no_const;
10000
10001 /**
10002 * struct x86_platform_ops - platform specific runtime functions
10003@@ -166,7 +166,7 @@ struct x86_platform_ops {
10004 bool (*is_untracked_pat_range)(u64 start, u64 end);
10005 void (*nmi_init)(void);
10006 int (*i8042_detect)(void);
10007-};
10008+} __no_const;
10009
10010 struct pci_dev;
10011
10012@@ -174,7 +174,7 @@ struct x86_msi_ops {
10013 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
10014 void (*teardown_msi_irq)(unsigned int irq);
10015 void (*teardown_msi_irqs)(struct pci_dev *dev);
10016-};
10017+} __no_const;
10018
10019 extern struct x86_init_ops x86_init;
10020 extern struct x86_cpuinit_ops x86_cpuinit;
10021diff -urNp linux-3.0.4/arch/x86/include/asm/xsave.h linux-3.0.4/arch/x86/include/asm/xsave.h
10022--- linux-3.0.4/arch/x86/include/asm/xsave.h 2011-07-21 22:17:23.000000000 -0400
10023+++ linux-3.0.4/arch/x86/include/asm/xsave.h 2011-08-23 21:47:55.000000000 -0400
10024@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
10025 {
10026 int err;
10027
10028+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10029+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
10030+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
10031+#endif
10032+
10033 /*
10034 * Clear the xsave header first, so that reserved fields are
10035 * initialized to zero.
10036@@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
10037 u32 lmask = mask;
10038 u32 hmask = mask >> 32;
10039
10040+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10041+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
10042+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
10043+#endif
10044+
10045 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
10046 "2:\n"
10047 ".section .fixup,\"ax\"\n"
10048diff -urNp linux-3.0.4/arch/x86/Kconfig linux-3.0.4/arch/x86/Kconfig
10049--- linux-3.0.4/arch/x86/Kconfig 2011-07-21 22:17:23.000000000 -0400
10050+++ linux-3.0.4/arch/x86/Kconfig 2011-08-23 21:48:14.000000000 -0400
10051@@ -229,7 +229,7 @@ config X86_HT
10052
10053 config X86_32_LAZY_GS
10054 def_bool y
10055- depends on X86_32 && !CC_STACKPROTECTOR
10056+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10057
10058 config ARCH_HWEIGHT_CFLAGS
10059 string
10060@@ -1018,7 +1018,7 @@ choice
10061
10062 config NOHIGHMEM
10063 bool "off"
10064- depends on !X86_NUMAQ
10065+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10066 ---help---
10067 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10068 However, the address space of 32-bit x86 processors is only 4
10069@@ -1055,7 +1055,7 @@ config NOHIGHMEM
10070
10071 config HIGHMEM4G
10072 bool "4GB"
10073- depends on !X86_NUMAQ
10074+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10075 ---help---
10076 Select this if you have a 32-bit processor and between 1 and 4
10077 gigabytes of physical RAM.
10078@@ -1109,7 +1109,7 @@ config PAGE_OFFSET
10079 hex
10080 default 0xB0000000 if VMSPLIT_3G_OPT
10081 default 0x80000000 if VMSPLIT_2G
10082- default 0x78000000 if VMSPLIT_2G_OPT
10083+ default 0x70000000 if VMSPLIT_2G_OPT
10084 default 0x40000000 if VMSPLIT_1G
10085 default 0xC0000000
10086 depends on X86_32
10087@@ -1453,7 +1453,7 @@ config ARCH_USES_PG_UNCACHED
10088
10089 config EFI
10090 bool "EFI runtime service support"
10091- depends on ACPI
10092+ depends on ACPI && !PAX_KERNEXEC
10093 ---help---
10094 This enables the kernel to use EFI runtime services that are
10095 available (such as the EFI variable services).
10096@@ -1483,6 +1483,7 @@ config SECCOMP
10097
10098 config CC_STACKPROTECTOR
10099 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
10100+ depends on X86_64 || !PAX_MEMORY_UDEREF
10101 ---help---
10102 This option turns on the -fstack-protector GCC feature. This
10103 feature puts, at the beginning of functions, a canary value on
10104@@ -1540,6 +1541,7 @@ config KEXEC_JUMP
10105 config PHYSICAL_START
10106 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
10107 default "0x1000000"
10108+ range 0x400000 0x40000000
10109 ---help---
10110 This gives the physical address where the kernel is loaded.
10111
10112@@ -1603,6 +1605,7 @@ config X86_NEED_RELOCS
10113 config PHYSICAL_ALIGN
10114 hex "Alignment value to which kernel should be aligned" if X86_32
10115 default "0x1000000"
10116+ range 0x400000 0x1000000 if PAX_KERNEXEC
10117 range 0x2000 0x1000000
10118 ---help---
10119 This value puts the alignment restrictions on physical address
10120@@ -1634,9 +1637,10 @@ config HOTPLUG_CPU
10121 Say N if you want to disable CPU hotplug.
10122
10123 config COMPAT_VDSO
10124- def_bool y
10125+ def_bool n
10126 prompt "Compat VDSO support"
10127 depends on X86_32 || IA32_EMULATION
10128+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
10129 ---help---
10130 Map the 32-bit VDSO to the predictable old-style address too.
10131
10132diff -urNp linux-3.0.4/arch/x86/Kconfig.cpu linux-3.0.4/arch/x86/Kconfig.cpu
10133--- linux-3.0.4/arch/x86/Kconfig.cpu 2011-07-21 22:17:23.000000000 -0400
10134+++ linux-3.0.4/arch/x86/Kconfig.cpu 2011-08-23 21:47:55.000000000 -0400
10135@@ -338,7 +338,7 @@ config X86_PPRO_FENCE
10136
10137 config X86_F00F_BUG
10138 def_bool y
10139- depends on M586MMX || M586TSC || M586 || M486 || M386
10140+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
10141
10142 config X86_INVD_BUG
10143 def_bool y
10144@@ -362,7 +362,7 @@ config X86_POPAD_OK
10145
10146 config X86_ALIGNMENT_16
10147 def_bool y
10148- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10149+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10150
10151 config X86_INTEL_USERCOPY
10152 def_bool y
10153@@ -408,7 +408,7 @@ config X86_CMPXCHG64
10154 # generates cmov.
10155 config X86_CMOV
10156 def_bool y
10157- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10158+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10159
10160 config X86_MINIMUM_CPU_FAMILY
10161 int
10162diff -urNp linux-3.0.4/arch/x86/Kconfig.debug linux-3.0.4/arch/x86/Kconfig.debug
10163--- linux-3.0.4/arch/x86/Kconfig.debug 2011-07-21 22:17:23.000000000 -0400
10164+++ linux-3.0.4/arch/x86/Kconfig.debug 2011-08-23 21:47:55.000000000 -0400
10165@@ -81,7 +81,7 @@ config X86_PTDUMP
10166 config DEBUG_RODATA
10167 bool "Write protect kernel read-only data structures"
10168 default y
10169- depends on DEBUG_KERNEL
10170+ depends on DEBUG_KERNEL && BROKEN
10171 ---help---
10172 Mark the kernel read-only data as write-protected in the pagetables,
10173 in order to catch accidental (and incorrect) writes to such const
10174@@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
10175
10176 config DEBUG_SET_MODULE_RONX
10177 bool "Set loadable kernel module data as NX and text as RO"
10178- depends on MODULES
10179+ depends on MODULES && BROKEN
10180 ---help---
10181 This option helps catch unintended modifications to loadable
10182 kernel module's text and read-only data. It also prevents execution
10183diff -urNp linux-3.0.4/arch/x86/kernel/acpi/realmode/Makefile linux-3.0.4/arch/x86/kernel/acpi/realmode/Makefile
10184--- linux-3.0.4/arch/x86/kernel/acpi/realmode/Makefile 2011-07-21 22:17:23.000000000 -0400
10185+++ linux-3.0.4/arch/x86/kernel/acpi/realmode/Makefile 2011-08-23 21:47:55.000000000 -0400
10186@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
10187 $(call cc-option, -fno-stack-protector) \
10188 $(call cc-option, -mpreferred-stack-boundary=2)
10189 KBUILD_CFLAGS += $(call cc-option, -m32)
10190+ifdef CONSTIFY_PLUGIN
10191+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
10192+endif
10193 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10194 GCOV_PROFILE := n
10195
10196diff -urNp linux-3.0.4/arch/x86/kernel/acpi/realmode/wakeup.S linux-3.0.4/arch/x86/kernel/acpi/realmode/wakeup.S
10197--- linux-3.0.4/arch/x86/kernel/acpi/realmode/wakeup.S 2011-07-21 22:17:23.000000000 -0400
10198+++ linux-3.0.4/arch/x86/kernel/acpi/realmode/wakeup.S 2011-08-23 21:48:14.000000000 -0400
10199@@ -108,6 +108,9 @@ wakeup_code:
10200 /* Do any other stuff... */
10201
10202 #ifndef CONFIG_64BIT
10203+ /* Recheck NX bit overrides (64bit path does this in trampoline */
10204+ call verify_cpu
10205+
10206 /* This could also be done in C code... */
10207 movl pmode_cr3, %eax
10208 movl %eax, %cr3
10209@@ -131,6 +134,7 @@ wakeup_code:
10210 movl pmode_cr0, %eax
10211 movl %eax, %cr0
10212 jmp pmode_return
10213+# include "../../verify_cpu.S"
10214 #else
10215 pushw $0
10216 pushw trampoline_segment
10217diff -urNp linux-3.0.4/arch/x86/kernel/acpi/sleep.c linux-3.0.4/arch/x86/kernel/acpi/sleep.c
10218--- linux-3.0.4/arch/x86/kernel/acpi/sleep.c 2011-07-21 22:17:23.000000000 -0400
10219+++ linux-3.0.4/arch/x86/kernel/acpi/sleep.c 2011-08-23 21:47:55.000000000 -0400
10220@@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
10221 header->trampoline_segment = trampoline_address() >> 4;
10222 #ifdef CONFIG_SMP
10223 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
10224+
10225+ pax_open_kernel();
10226 early_gdt_descr.address =
10227 (unsigned long)get_cpu_gdt_table(smp_processor_id());
10228+ pax_close_kernel();
10229+
10230 initial_gs = per_cpu_offset(smp_processor_id());
10231 #endif
10232 initial_code = (unsigned long)wakeup_long64;
10233diff -urNp linux-3.0.4/arch/x86/kernel/acpi/wakeup_32.S linux-3.0.4/arch/x86/kernel/acpi/wakeup_32.S
10234--- linux-3.0.4/arch/x86/kernel/acpi/wakeup_32.S 2011-07-21 22:17:23.000000000 -0400
10235+++ linux-3.0.4/arch/x86/kernel/acpi/wakeup_32.S 2011-08-23 21:47:55.000000000 -0400
10236@@ -30,13 +30,11 @@ wakeup_pmode_return:
10237 # and restore the stack ... but you need gdt for this to work
10238 movl saved_context_esp, %esp
10239
10240- movl %cs:saved_magic, %eax
10241- cmpl $0x12345678, %eax
10242+ cmpl $0x12345678, saved_magic
10243 jne bogus_magic
10244
10245 # jump to place where we left off
10246- movl saved_eip, %eax
10247- jmp *%eax
10248+ jmp *(saved_eip)
10249
10250 bogus_magic:
10251 jmp bogus_magic
10252diff -urNp linux-3.0.4/arch/x86/kernel/alternative.c linux-3.0.4/arch/x86/kernel/alternative.c
10253--- linux-3.0.4/arch/x86/kernel/alternative.c 2011-07-21 22:17:23.000000000 -0400
10254+++ linux-3.0.4/arch/x86/kernel/alternative.c 2011-08-23 21:47:55.000000000 -0400
10255@@ -313,7 +313,7 @@ static void alternatives_smp_lock(const
10256 if (!*poff || ptr < text || ptr >= text_end)
10257 continue;
10258 /* turn DS segment override prefix into lock prefix */
10259- if (*ptr == 0x3e)
10260+ if (*ktla_ktva(ptr) == 0x3e)
10261 text_poke(ptr, ((unsigned char []){0xf0}), 1);
10262 };
10263 mutex_unlock(&text_mutex);
10264@@ -334,7 +334,7 @@ static void alternatives_smp_unlock(cons
10265 if (!*poff || ptr < text || ptr >= text_end)
10266 continue;
10267 /* turn lock prefix into DS segment override prefix */
10268- if (*ptr == 0xf0)
10269+ if (*ktla_ktva(ptr) == 0xf0)
10270 text_poke(ptr, ((unsigned char []){0x3E}), 1);
10271 };
10272 mutex_unlock(&text_mutex);
10273@@ -503,7 +503,7 @@ void __init_or_module apply_paravirt(str
10274
10275 BUG_ON(p->len > MAX_PATCH_LEN);
10276 /* prep the buffer with the original instructions */
10277- memcpy(insnbuf, p->instr, p->len);
10278+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
10279 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
10280 (unsigned long)p->instr, p->len);
10281
10282@@ -571,7 +571,7 @@ void __init alternative_instructions(voi
10283 if (smp_alt_once)
10284 free_init_pages("SMP alternatives",
10285 (unsigned long)__smp_locks,
10286- (unsigned long)__smp_locks_end);
10287+ PAGE_ALIGN((unsigned long)__smp_locks_end));
10288
10289 restart_nmi();
10290 }
10291@@ -588,13 +588,17 @@ void __init alternative_instructions(voi
10292 * instructions. And on the local CPU you need to be protected again NMI or MCE
10293 * handlers seeing an inconsistent instruction while you patch.
10294 */
10295-void *__init_or_module text_poke_early(void *addr, const void *opcode,
10296+void *__kprobes text_poke_early(void *addr, const void *opcode,
10297 size_t len)
10298 {
10299 unsigned long flags;
10300 local_irq_save(flags);
10301- memcpy(addr, opcode, len);
10302+
10303+ pax_open_kernel();
10304+ memcpy(ktla_ktva(addr), opcode, len);
10305 sync_core();
10306+ pax_close_kernel();
10307+
10308 local_irq_restore(flags);
10309 /* Could also do a CLFLUSH here to speed up CPU recovery; but
10310 that causes hangs on some VIA CPUs. */
10311@@ -616,36 +620,22 @@ void *__init_or_module text_poke_early(v
10312 */
10313 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
10314 {
10315- unsigned long flags;
10316- char *vaddr;
10317+ unsigned char *vaddr = ktla_ktva(addr);
10318 struct page *pages[2];
10319- int i;
10320+ size_t i;
10321
10322 if (!core_kernel_text((unsigned long)addr)) {
10323- pages[0] = vmalloc_to_page(addr);
10324- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
10325+ pages[0] = vmalloc_to_page(vaddr);
10326+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
10327 } else {
10328- pages[0] = virt_to_page(addr);
10329+ pages[0] = virt_to_page(vaddr);
10330 WARN_ON(!PageReserved(pages[0]));
10331- pages[1] = virt_to_page(addr + PAGE_SIZE);
10332+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
10333 }
10334 BUG_ON(!pages[0]);
10335- local_irq_save(flags);
10336- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
10337- if (pages[1])
10338- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
10339- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
10340- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
10341- clear_fixmap(FIX_TEXT_POKE0);
10342- if (pages[1])
10343- clear_fixmap(FIX_TEXT_POKE1);
10344- local_flush_tlb();
10345- sync_core();
10346- /* Could also do a CLFLUSH here to speed up CPU recovery; but
10347- that causes hangs on some VIA CPUs. */
10348+ text_poke_early(addr, opcode, len);
10349 for (i = 0; i < len; i++)
10350- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
10351- local_irq_restore(flags);
10352+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
10353 return addr;
10354 }
10355
10356diff -urNp linux-3.0.4/arch/x86/kernel/apic/apic.c linux-3.0.4/arch/x86/kernel/apic/apic.c
10357--- linux-3.0.4/arch/x86/kernel/apic/apic.c 2011-07-21 22:17:23.000000000 -0400
10358+++ linux-3.0.4/arch/x86/kernel/apic/apic.c 2011-08-23 21:48:14.000000000 -0400
10359@@ -173,7 +173,7 @@ int first_system_vector = 0xfe;
10360 /*
10361 * Debug level, exported for io_apic.c
10362 */
10363-unsigned int apic_verbosity;
10364+int apic_verbosity;
10365
10366 int pic_mode;
10367
10368@@ -1834,7 +1834,7 @@ void smp_error_interrupt(struct pt_regs
10369 apic_write(APIC_ESR, 0);
10370 v1 = apic_read(APIC_ESR);
10371 ack_APIC_irq();
10372- atomic_inc(&irq_err_count);
10373+ atomic_inc_unchecked(&irq_err_count);
10374
10375 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
10376 smp_processor_id(), v0 , v1);
10377@@ -2190,6 +2190,8 @@ static int __cpuinit apic_cluster_num(vo
10378 u16 *bios_cpu_apicid;
10379 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
10380
10381+ pax_track_stack();
10382+
10383 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
10384 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
10385
10386diff -urNp linux-3.0.4/arch/x86/kernel/apic/io_apic.c linux-3.0.4/arch/x86/kernel/apic/io_apic.c
10387--- linux-3.0.4/arch/x86/kernel/apic/io_apic.c 2011-07-21 22:17:23.000000000 -0400
10388+++ linux-3.0.4/arch/x86/kernel/apic/io_apic.c 2011-08-23 21:47:55.000000000 -0400
10389@@ -1028,7 +1028,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
10390 }
10391 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
10392
10393-void lock_vector_lock(void)
10394+void lock_vector_lock(void) __acquires(vector_lock)
10395 {
10396 /* Used to the online set of cpus does not change
10397 * during assign_irq_vector.
10398@@ -1036,7 +1036,7 @@ void lock_vector_lock(void)
10399 raw_spin_lock(&vector_lock);
10400 }
10401
10402-void unlock_vector_lock(void)
10403+void unlock_vector_lock(void) __releases(vector_lock)
10404 {
10405 raw_spin_unlock(&vector_lock);
10406 }
10407@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_dat
10408 ack_APIC_irq();
10409 }
10410
10411-atomic_t irq_mis_count;
10412+atomic_unchecked_t irq_mis_count;
10413
10414 /*
10415 * IO-APIC versions below 0x20 don't support EOI register.
10416@@ -2472,7 +2472,7 @@ static void ack_apic_level(struct irq_da
10417 * at the cpu.
10418 */
10419 if (!(v & (1 << (i & 0x1f)))) {
10420- atomic_inc(&irq_mis_count);
10421+ atomic_inc_unchecked(&irq_mis_count);
10422
10423 eoi_ioapic_irq(irq, cfg);
10424 }
10425diff -urNp linux-3.0.4/arch/x86/kernel/apm_32.c linux-3.0.4/arch/x86/kernel/apm_32.c
10426--- linux-3.0.4/arch/x86/kernel/apm_32.c 2011-07-21 22:17:23.000000000 -0400
10427+++ linux-3.0.4/arch/x86/kernel/apm_32.c 2011-08-23 21:47:55.000000000 -0400
10428@@ -413,7 +413,7 @@ static DEFINE_MUTEX(apm_mutex);
10429 * This is for buggy BIOS's that refer to (real mode) segment 0x40
10430 * even though they are called in protected mode.
10431 */
10432-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
10433+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
10434 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
10435
10436 static const char driver_version[] = "1.16ac"; /* no spaces */
10437@@ -591,7 +591,10 @@ static long __apm_bios_call(void *_call)
10438 BUG_ON(cpu != 0);
10439 gdt = get_cpu_gdt_table(cpu);
10440 save_desc_40 = gdt[0x40 / 8];
10441+
10442+ pax_open_kernel();
10443 gdt[0x40 / 8] = bad_bios_desc;
10444+ pax_close_kernel();
10445
10446 apm_irq_save(flags);
10447 APM_DO_SAVE_SEGS;
10448@@ -600,7 +603,11 @@ static long __apm_bios_call(void *_call)
10449 &call->esi);
10450 APM_DO_RESTORE_SEGS;
10451 apm_irq_restore(flags);
10452+
10453+ pax_open_kernel();
10454 gdt[0x40 / 8] = save_desc_40;
10455+ pax_close_kernel();
10456+
10457 put_cpu();
10458
10459 return call->eax & 0xff;
10460@@ -667,7 +674,10 @@ static long __apm_bios_call_simple(void
10461 BUG_ON(cpu != 0);
10462 gdt = get_cpu_gdt_table(cpu);
10463 save_desc_40 = gdt[0x40 / 8];
10464+
10465+ pax_open_kernel();
10466 gdt[0x40 / 8] = bad_bios_desc;
10467+ pax_close_kernel();
10468
10469 apm_irq_save(flags);
10470 APM_DO_SAVE_SEGS;
10471@@ -675,7 +685,11 @@ static long __apm_bios_call_simple(void
10472 &call->eax);
10473 APM_DO_RESTORE_SEGS;
10474 apm_irq_restore(flags);
10475+
10476+ pax_open_kernel();
10477 gdt[0x40 / 8] = save_desc_40;
10478+ pax_close_kernel();
10479+
10480 put_cpu();
10481 return error;
10482 }
10483@@ -2349,12 +2363,15 @@ static int __init apm_init(void)
10484 * code to that CPU.
10485 */
10486 gdt = get_cpu_gdt_table(0);
10487+
10488+ pax_open_kernel();
10489 set_desc_base(&gdt[APM_CS >> 3],
10490 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
10491 set_desc_base(&gdt[APM_CS_16 >> 3],
10492 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
10493 set_desc_base(&gdt[APM_DS >> 3],
10494 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
10495+ pax_close_kernel();
10496
10497 proc_create("apm", 0, NULL, &apm_file_ops);
10498
10499diff -urNp linux-3.0.4/arch/x86/kernel/asm-offsets_64.c linux-3.0.4/arch/x86/kernel/asm-offsets_64.c
10500--- linux-3.0.4/arch/x86/kernel/asm-offsets_64.c 2011-07-21 22:17:23.000000000 -0400
10501+++ linux-3.0.4/arch/x86/kernel/asm-offsets_64.c 2011-08-23 21:47:55.000000000 -0400
10502@@ -69,6 +69,7 @@ int main(void)
10503 BLANK();
10504 #undef ENTRY
10505
10506+ DEFINE(TSS_size, sizeof(struct tss_struct));
10507 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
10508 BLANK();
10509
10510diff -urNp linux-3.0.4/arch/x86/kernel/asm-offsets.c linux-3.0.4/arch/x86/kernel/asm-offsets.c
10511--- linux-3.0.4/arch/x86/kernel/asm-offsets.c 2011-07-21 22:17:23.000000000 -0400
10512+++ linux-3.0.4/arch/x86/kernel/asm-offsets.c 2011-08-23 21:47:55.000000000 -0400
10513@@ -33,6 +33,8 @@ void common(void) {
10514 OFFSET(TI_status, thread_info, status);
10515 OFFSET(TI_addr_limit, thread_info, addr_limit);
10516 OFFSET(TI_preempt_count, thread_info, preempt_count);
10517+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
10518+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
10519
10520 BLANK();
10521 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
10522@@ -53,8 +55,26 @@ void common(void) {
10523 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
10524 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
10525 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
10526+
10527+#ifdef CONFIG_PAX_KERNEXEC
10528+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
10529+#endif
10530+
10531+#ifdef CONFIG_PAX_MEMORY_UDEREF
10532+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
10533+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
10534+#ifdef CONFIG_X86_64
10535+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
10536+#endif
10537 #endif
10538
10539+#endif
10540+
10541+ BLANK();
10542+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
10543+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
10544+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
10545+
10546 #ifdef CONFIG_XEN
10547 BLANK();
10548 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
10549diff -urNp linux-3.0.4/arch/x86/kernel/cpu/amd.c linux-3.0.4/arch/x86/kernel/cpu/amd.c
10550--- linux-3.0.4/arch/x86/kernel/cpu/amd.c 2011-07-21 22:17:23.000000000 -0400
10551+++ linux-3.0.4/arch/x86/kernel/cpu/amd.c 2011-08-23 21:47:55.000000000 -0400
10552@@ -647,7 +647,7 @@ static unsigned int __cpuinit amd_size_c
10553 unsigned int size)
10554 {
10555 /* AMD errata T13 (order #21922) */
10556- if ((c->x86 == 6)) {
10557+ if (c->x86 == 6) {
10558 /* Duron Rev A0 */
10559 if (c->x86_model == 3 && c->x86_mask == 0)
10560 size = 64;
10561diff -urNp linux-3.0.4/arch/x86/kernel/cpu/common.c linux-3.0.4/arch/x86/kernel/cpu/common.c
10562--- linux-3.0.4/arch/x86/kernel/cpu/common.c 2011-07-21 22:17:23.000000000 -0400
10563+++ linux-3.0.4/arch/x86/kernel/cpu/common.c 2011-08-23 21:47:55.000000000 -0400
10564@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
10565
10566 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
10567
10568-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
10569-#ifdef CONFIG_X86_64
10570- /*
10571- * We need valid kernel segments for data and code in long mode too
10572- * IRET will check the segment types kkeil 2000/10/28
10573- * Also sysret mandates a special GDT layout
10574- *
10575- * TLS descriptors are currently at a different place compared to i386.
10576- * Hopefully nobody expects them at a fixed place (Wine?)
10577- */
10578- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
10579- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
10580- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
10581- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
10582- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
10583- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
10584-#else
10585- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
10586- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
10587- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
10588- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
10589- /*
10590- * Segments used for calling PnP BIOS have byte granularity.
10591- * They code segments and data segments have fixed 64k limits,
10592- * the transfer segment sizes are set at run time.
10593- */
10594- /* 32-bit code */
10595- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
10596- /* 16-bit code */
10597- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
10598- /* 16-bit data */
10599- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
10600- /* 16-bit data */
10601- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
10602- /* 16-bit data */
10603- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
10604- /*
10605- * The APM segments have byte granularity and their bases
10606- * are set at run time. All have 64k limits.
10607- */
10608- /* 32-bit code */
10609- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
10610- /* 16-bit code */
10611- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
10612- /* data */
10613- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
10614-
10615- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
10616- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
10617- GDT_STACK_CANARY_INIT
10618-#endif
10619-} };
10620-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
10621-
10622 static int __init x86_xsave_setup(char *s)
10623 {
10624 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
10625@@ -371,7 +317,7 @@ void switch_to_new_gdt(int cpu)
10626 {
10627 struct desc_ptr gdt_descr;
10628
10629- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
10630+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
10631 gdt_descr.size = GDT_SIZE - 1;
10632 load_gdt(&gdt_descr);
10633 /* Reload the per-cpu base */
10634@@ -840,6 +786,10 @@ static void __cpuinit identify_cpu(struc
10635 /* Filter out anything that depends on CPUID levels we don't have */
10636 filter_cpuid_features(c, true);
10637
10638+#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
10639+ setup_clear_cpu_cap(X86_FEATURE_SEP);
10640+#endif
10641+
10642 /* If the model name is still unset, do table lookup. */
10643 if (!c->x86_model_id[0]) {
10644 const char *p;
10645@@ -1019,6 +969,9 @@ static __init int setup_disablecpuid(cha
10646 }
10647 __setup("clearcpuid=", setup_disablecpuid);
10648
10649+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
10650+EXPORT_PER_CPU_SYMBOL(current_tinfo);
10651+
10652 #ifdef CONFIG_X86_64
10653 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
10654
10655@@ -1034,7 +987,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
10656 EXPORT_PER_CPU_SYMBOL(current_task);
10657
10658 DEFINE_PER_CPU(unsigned long, kernel_stack) =
10659- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
10660+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
10661 EXPORT_PER_CPU_SYMBOL(kernel_stack);
10662
10663 DEFINE_PER_CPU(char *, irq_stack_ptr) =
10664@@ -1099,7 +1052,7 @@ struct pt_regs * __cpuinit idle_regs(str
10665 {
10666 memset(regs, 0, sizeof(struct pt_regs));
10667 regs->fs = __KERNEL_PERCPU;
10668- regs->gs = __KERNEL_STACK_CANARY;
10669+ savesegment(gs, regs->gs);
10670
10671 return regs;
10672 }
10673@@ -1154,7 +1107,7 @@ void __cpuinit cpu_init(void)
10674 int i;
10675
10676 cpu = stack_smp_processor_id();
10677- t = &per_cpu(init_tss, cpu);
10678+ t = init_tss + cpu;
10679 oist = &per_cpu(orig_ist, cpu);
10680
10681 #ifdef CONFIG_NUMA
10682@@ -1180,7 +1133,7 @@ void __cpuinit cpu_init(void)
10683 switch_to_new_gdt(cpu);
10684 loadsegment(fs, 0);
10685
10686- load_idt((const struct desc_ptr *)&idt_descr);
10687+ load_idt(&idt_descr);
10688
10689 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
10690 syscall_init();
10691@@ -1189,7 +1142,6 @@ void __cpuinit cpu_init(void)
10692 wrmsrl(MSR_KERNEL_GS_BASE, 0);
10693 barrier();
10694
10695- x86_configure_nx();
10696 if (cpu != 0)
10697 enable_x2apic();
10698
10699@@ -1243,7 +1195,7 @@ void __cpuinit cpu_init(void)
10700 {
10701 int cpu = smp_processor_id();
10702 struct task_struct *curr = current;
10703- struct tss_struct *t = &per_cpu(init_tss, cpu);
10704+ struct tss_struct *t = init_tss + cpu;
10705 struct thread_struct *thread = &curr->thread;
10706
10707 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
10708diff -urNp linux-3.0.4/arch/x86/kernel/cpu/intel.c linux-3.0.4/arch/x86/kernel/cpu/intel.c
10709--- linux-3.0.4/arch/x86/kernel/cpu/intel.c 2011-08-29 23:26:13.000000000 -0400
10710+++ linux-3.0.4/arch/x86/kernel/cpu/intel.c 2011-08-29 23:30:14.000000000 -0400
10711@@ -172,7 +172,7 @@ static void __cpuinit trap_init_f00f_bug
10712 * Update the IDT descriptor and reload the IDT so that
10713 * it uses the read-only mapped virtual address.
10714 */
10715- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
10716+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
10717 load_idt(&idt_descr);
10718 }
10719 #endif
10720diff -urNp linux-3.0.4/arch/x86/kernel/cpu/Makefile linux-3.0.4/arch/x86/kernel/cpu/Makefile
10721--- linux-3.0.4/arch/x86/kernel/cpu/Makefile 2011-07-21 22:17:23.000000000 -0400
10722+++ linux-3.0.4/arch/x86/kernel/cpu/Makefile 2011-08-23 21:47:55.000000000 -0400
10723@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
10724 CFLAGS_REMOVE_perf_event.o = -pg
10725 endif
10726
10727-# Make sure load_percpu_segment has no stackprotector
10728-nostackp := $(call cc-option, -fno-stack-protector)
10729-CFLAGS_common.o := $(nostackp)
10730-
10731 obj-y := intel_cacheinfo.o scattered.o topology.o
10732 obj-y += proc.o capflags.o powerflags.o common.o
10733 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
10734diff -urNp linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce.c linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce.c
10735--- linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce.c 2011-07-21 22:17:23.000000000 -0400
10736+++ linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce.c 2011-08-23 21:47:55.000000000 -0400
10737@@ -46,6 +46,7 @@
10738 #include <asm/ipi.h>
10739 #include <asm/mce.h>
10740 #include <asm/msr.h>
10741+#include <asm/local.h>
10742
10743 #include "mce-internal.h"
10744
10745@@ -208,7 +209,7 @@ static void print_mce(struct mce *m)
10746 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
10747 m->cs, m->ip);
10748
10749- if (m->cs == __KERNEL_CS)
10750+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
10751 print_symbol("{%s}", m->ip);
10752 pr_cont("\n");
10753 }
10754@@ -236,10 +237,10 @@ static void print_mce(struct mce *m)
10755
10756 #define PANIC_TIMEOUT 5 /* 5 seconds */
10757
10758-static atomic_t mce_paniced;
10759+static atomic_unchecked_t mce_paniced;
10760
10761 static int fake_panic;
10762-static atomic_t mce_fake_paniced;
10763+static atomic_unchecked_t mce_fake_paniced;
10764
10765 /* Panic in progress. Enable interrupts and wait for final IPI */
10766 static void wait_for_panic(void)
10767@@ -263,7 +264,7 @@ static void mce_panic(char *msg, struct
10768 /*
10769 * Make sure only one CPU runs in machine check panic
10770 */
10771- if (atomic_inc_return(&mce_paniced) > 1)
10772+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
10773 wait_for_panic();
10774 barrier();
10775
10776@@ -271,7 +272,7 @@ static void mce_panic(char *msg, struct
10777 console_verbose();
10778 } else {
10779 /* Don't log too much for fake panic */
10780- if (atomic_inc_return(&mce_fake_paniced) > 1)
10781+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
10782 return;
10783 }
10784 /* First print corrected ones that are still unlogged */
10785@@ -638,7 +639,7 @@ static int mce_timed_out(u64 *t)
10786 * might have been modified by someone else.
10787 */
10788 rmb();
10789- if (atomic_read(&mce_paniced))
10790+ if (atomic_read_unchecked(&mce_paniced))
10791 wait_for_panic();
10792 if (!monarch_timeout)
10793 goto out;
10794@@ -1452,14 +1453,14 @@ void __cpuinit mcheck_cpu_init(struct cp
10795 */
10796
10797 static DEFINE_SPINLOCK(mce_state_lock);
10798-static int open_count; /* #times opened */
10799+static local_t open_count; /* #times opened */
10800 static int open_exclu; /* already open exclusive? */
10801
10802 static int mce_open(struct inode *inode, struct file *file)
10803 {
10804 spin_lock(&mce_state_lock);
10805
10806- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
10807+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
10808 spin_unlock(&mce_state_lock);
10809
10810 return -EBUSY;
10811@@ -1467,7 +1468,7 @@ static int mce_open(struct inode *inode,
10812
10813 if (file->f_flags & O_EXCL)
10814 open_exclu = 1;
10815- open_count++;
10816+ local_inc(&open_count);
10817
10818 spin_unlock(&mce_state_lock);
10819
10820@@ -1478,7 +1479,7 @@ static int mce_release(struct inode *ino
10821 {
10822 spin_lock(&mce_state_lock);
10823
10824- open_count--;
10825+ local_dec(&open_count);
10826 open_exclu = 0;
10827
10828 spin_unlock(&mce_state_lock);
10829@@ -2163,7 +2164,7 @@ struct dentry *mce_get_debugfs_dir(void)
10830 static void mce_reset(void)
10831 {
10832 cpu_missing = 0;
10833- atomic_set(&mce_fake_paniced, 0);
10834+ atomic_set_unchecked(&mce_fake_paniced, 0);
10835 atomic_set(&mce_executing, 0);
10836 atomic_set(&mce_callin, 0);
10837 atomic_set(&global_nwo, 0);
10838diff -urNp linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce-inject.c linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce-inject.c
10839--- linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-07-21 22:17:23.000000000 -0400
10840+++ linux-3.0.4/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-08-23 21:47:55.000000000 -0400
10841@@ -215,7 +215,9 @@ static int inject_init(void)
10842 if (!alloc_cpumask_var(&mce_inject_cpumask, GFP_KERNEL))
10843 return -ENOMEM;
10844 printk(KERN_INFO "Machine check injector initialized\n");
10845- mce_chrdev_ops.write = mce_write;
10846+ pax_open_kernel();
10847+ *(void **)&mce_chrdev_ops.write = mce_write;
10848+ pax_close_kernel();
10849 register_die_notifier(&mce_raise_nb);
10850 return 0;
10851 }
10852diff -urNp linux-3.0.4/arch/x86/kernel/cpu/mtrr/main.c linux-3.0.4/arch/x86/kernel/cpu/mtrr/main.c
10853--- linux-3.0.4/arch/x86/kernel/cpu/mtrr/main.c 2011-08-29 23:26:13.000000000 -0400
10854+++ linux-3.0.4/arch/x86/kernel/cpu/mtrr/main.c 2011-08-29 23:26:21.000000000 -0400
10855@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
10856 u64 size_or_mask, size_and_mask;
10857 static bool mtrr_aps_delayed_init;
10858
10859-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
10860+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
10861
10862 const struct mtrr_ops *mtrr_if;
10863
10864diff -urNp linux-3.0.4/arch/x86/kernel/cpu/mtrr/mtrr.h linux-3.0.4/arch/x86/kernel/cpu/mtrr/mtrr.h
10865--- linux-3.0.4/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-07-21 22:17:23.000000000 -0400
10866+++ linux-3.0.4/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-08-26 19:49:56.000000000 -0400
10867@@ -25,7 +25,7 @@ struct mtrr_ops {
10868 int (*validate_add_page)(unsigned long base, unsigned long size,
10869 unsigned int type);
10870 int (*have_wrcomb)(void);
10871-};
10872+} __do_const;
10873
10874 extern int generic_get_free_region(unsigned long base, unsigned long size,
10875 int replace_reg);
10876diff -urNp linux-3.0.4/arch/x86/kernel/cpu/perf_event.c linux-3.0.4/arch/x86/kernel/cpu/perf_event.c
10877--- linux-3.0.4/arch/x86/kernel/cpu/perf_event.c 2011-07-21 22:17:23.000000000 -0400
10878+++ linux-3.0.4/arch/x86/kernel/cpu/perf_event.c 2011-08-23 21:48:14.000000000 -0400
10879@@ -781,6 +781,8 @@ static int x86_schedule_events(struct cp
10880 int i, j, w, wmax, num = 0;
10881 struct hw_perf_event *hwc;
10882
10883+ pax_track_stack();
10884+
10885 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
10886
10887 for (i = 0; i < n; i++) {
10888@@ -1872,7 +1874,7 @@ perf_callchain_user(struct perf_callchai
10889 break;
10890
10891 perf_callchain_store(entry, frame.return_address);
10892- fp = frame.next_frame;
10893+ fp = (__force const void __user *)frame.next_frame;
10894 }
10895 }
10896
10897diff -urNp linux-3.0.4/arch/x86/kernel/crash.c linux-3.0.4/arch/x86/kernel/crash.c
10898--- linux-3.0.4/arch/x86/kernel/crash.c 2011-07-21 22:17:23.000000000 -0400
10899+++ linux-3.0.4/arch/x86/kernel/crash.c 2011-08-23 21:47:55.000000000 -0400
10900@@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
10901 regs = args->regs;
10902
10903 #ifdef CONFIG_X86_32
10904- if (!user_mode_vm(regs)) {
10905+ if (!user_mode(regs)) {
10906 crash_fixup_ss_esp(&fixed_regs, regs);
10907 regs = &fixed_regs;
10908 }
10909diff -urNp linux-3.0.4/arch/x86/kernel/doublefault_32.c linux-3.0.4/arch/x86/kernel/doublefault_32.c
10910--- linux-3.0.4/arch/x86/kernel/doublefault_32.c 2011-07-21 22:17:23.000000000 -0400
10911+++ linux-3.0.4/arch/x86/kernel/doublefault_32.c 2011-08-23 21:47:55.000000000 -0400
10912@@ -11,7 +11,7 @@
10913
10914 #define DOUBLEFAULT_STACKSIZE (1024)
10915 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
10916-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
10917+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
10918
10919 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
10920
10921@@ -21,7 +21,7 @@ static void doublefault_fn(void)
10922 unsigned long gdt, tss;
10923
10924 store_gdt(&gdt_desc);
10925- gdt = gdt_desc.address;
10926+ gdt = (unsigned long)gdt_desc.address;
10927
10928 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
10929
10930@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
10931 /* 0x2 bit is always set */
10932 .flags = X86_EFLAGS_SF | 0x2,
10933 .sp = STACK_START,
10934- .es = __USER_DS,
10935+ .es = __KERNEL_DS,
10936 .cs = __KERNEL_CS,
10937 .ss = __KERNEL_DS,
10938- .ds = __USER_DS,
10939+ .ds = __KERNEL_DS,
10940 .fs = __KERNEL_PERCPU,
10941
10942 .__cr3 = __pa_nodebug(swapper_pg_dir),
10943diff -urNp linux-3.0.4/arch/x86/kernel/dumpstack_32.c linux-3.0.4/arch/x86/kernel/dumpstack_32.c
10944--- linux-3.0.4/arch/x86/kernel/dumpstack_32.c 2011-07-21 22:17:23.000000000 -0400
10945+++ linux-3.0.4/arch/x86/kernel/dumpstack_32.c 2011-08-23 21:47:55.000000000 -0400
10946@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task
10947 bp = stack_frame(task, regs);
10948
10949 for (;;) {
10950- struct thread_info *context;
10951+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
10952
10953- context = (struct thread_info *)
10954- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
10955- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
10956+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
10957
10958- stack = (unsigned long *)context->previous_esp;
10959- if (!stack)
10960+ if (stack_start == task_stack_page(task))
10961 break;
10962+ stack = *(unsigned long **)stack_start;
10963 if (ops->stack(data, "IRQ") < 0)
10964 break;
10965 touch_nmi_watchdog();
10966@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs
10967 * When in-kernel, we also print out the stack and code at the
10968 * time of the fault..
10969 */
10970- if (!user_mode_vm(regs)) {
10971+ if (!user_mode(regs)) {
10972 unsigned int code_prologue = code_bytes * 43 / 64;
10973 unsigned int code_len = code_bytes;
10974 unsigned char c;
10975 u8 *ip;
10976+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
10977
10978 printk(KERN_EMERG "Stack:\n");
10979 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
10980
10981 printk(KERN_EMERG "Code: ");
10982
10983- ip = (u8 *)regs->ip - code_prologue;
10984+ ip = (u8 *)regs->ip - code_prologue + cs_base;
10985 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
10986 /* try starting at IP */
10987- ip = (u8 *)regs->ip;
10988+ ip = (u8 *)regs->ip + cs_base;
10989 code_len = code_len - code_prologue + 1;
10990 }
10991 for (i = 0; i < code_len; i++, ip++) {
10992@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs
10993 printk(" Bad EIP value.");
10994 break;
10995 }
10996- if (ip == (u8 *)regs->ip)
10997+ if (ip == (u8 *)regs->ip + cs_base)
10998 printk("<%02x> ", c);
10999 else
11000 printk("%02x ", c);
11001@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
11002 {
11003 unsigned short ud2;
11004
11005+ ip = ktla_ktva(ip);
11006 if (ip < PAGE_OFFSET)
11007 return 0;
11008 if (probe_kernel_address((unsigned short *)ip, ud2))
11009diff -urNp linux-3.0.4/arch/x86/kernel/dumpstack_64.c linux-3.0.4/arch/x86/kernel/dumpstack_64.c
11010--- linux-3.0.4/arch/x86/kernel/dumpstack_64.c 2011-07-21 22:17:23.000000000 -0400
11011+++ linux-3.0.4/arch/x86/kernel/dumpstack_64.c 2011-08-23 21:47:55.000000000 -0400
11012@@ -147,9 +147,9 @@ void dump_trace(struct task_struct *task
11013 unsigned long *irq_stack_end =
11014 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
11015 unsigned used = 0;
11016- struct thread_info *tinfo;
11017 int graph = 0;
11018 unsigned long dummy;
11019+ void *stack_start;
11020
11021 if (!task)
11022 task = current;
11023@@ -167,10 +167,10 @@ void dump_trace(struct task_struct *task
11024 * current stack address. If the stacks consist of nested
11025 * exceptions
11026 */
11027- tinfo = task_thread_info(task);
11028 for (;;) {
11029 char *id;
11030 unsigned long *estack_end;
11031+
11032 estack_end = in_exception_stack(cpu, (unsigned long)stack,
11033 &used, &id);
11034
11035@@ -178,7 +178,7 @@ void dump_trace(struct task_struct *task
11036 if (ops->stack(data, id) < 0)
11037 break;
11038
11039- bp = ops->walk_stack(tinfo, stack, bp, ops,
11040+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
11041 data, estack_end, &graph);
11042 ops->stack(data, "<EOE>");
11043 /*
11044@@ -197,7 +197,7 @@ void dump_trace(struct task_struct *task
11045 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
11046 if (ops->stack(data, "IRQ") < 0)
11047 break;
11048- bp = ops->walk_stack(tinfo, stack, bp,
11049+ bp = ops->walk_stack(task, irq_stack, stack, bp,
11050 ops, data, irq_stack_end, &graph);
11051 /*
11052 * We link to the next stack (which would be
11053@@ -218,7 +218,8 @@ void dump_trace(struct task_struct *task
11054 /*
11055 * This handles the process stack:
11056 */
11057- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
11058+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
11059+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
11060 put_cpu();
11061 }
11062 EXPORT_SYMBOL(dump_trace);
11063diff -urNp linux-3.0.4/arch/x86/kernel/dumpstack.c linux-3.0.4/arch/x86/kernel/dumpstack.c
11064--- linux-3.0.4/arch/x86/kernel/dumpstack.c 2011-07-21 22:17:23.000000000 -0400
11065+++ linux-3.0.4/arch/x86/kernel/dumpstack.c 2011-08-23 21:48:14.000000000 -0400
11066@@ -2,6 +2,9 @@
11067 * Copyright (C) 1991, 1992 Linus Torvalds
11068 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
11069 */
11070+#ifdef CONFIG_GRKERNSEC_HIDESYM
11071+#define __INCLUDED_BY_HIDESYM 1
11072+#endif
11073 #include <linux/kallsyms.h>
11074 #include <linux/kprobes.h>
11075 #include <linux/uaccess.h>
11076@@ -35,9 +38,8 @@ void printk_address(unsigned long addres
11077 static void
11078 print_ftrace_graph_addr(unsigned long addr, void *data,
11079 const struct stacktrace_ops *ops,
11080- struct thread_info *tinfo, int *graph)
11081+ struct task_struct *task, int *graph)
11082 {
11083- struct task_struct *task = tinfo->task;
11084 unsigned long ret_addr;
11085 int index = task->curr_ret_stack;
11086
11087@@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long ad
11088 static inline void
11089 print_ftrace_graph_addr(unsigned long addr, void *data,
11090 const struct stacktrace_ops *ops,
11091- struct thread_info *tinfo, int *graph)
11092+ struct task_struct *task, int *graph)
11093 { }
11094 #endif
11095
11096@@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long ad
11097 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
11098 */
11099
11100-static inline int valid_stack_ptr(struct thread_info *tinfo,
11101- void *p, unsigned int size, void *end)
11102+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
11103 {
11104- void *t = tinfo;
11105 if (end) {
11106 if (p < end && p >= (end-THREAD_SIZE))
11107 return 1;
11108@@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct
11109 }
11110
11111 unsigned long
11112-print_context_stack(struct thread_info *tinfo,
11113+print_context_stack(struct task_struct *task, void *stack_start,
11114 unsigned long *stack, unsigned long bp,
11115 const struct stacktrace_ops *ops, void *data,
11116 unsigned long *end, int *graph)
11117 {
11118 struct stack_frame *frame = (struct stack_frame *)bp;
11119
11120- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
11121+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
11122 unsigned long addr;
11123
11124 addr = *stack;
11125@@ -102,7 +102,7 @@ print_context_stack(struct thread_info *
11126 } else {
11127 ops->address(data, addr, 0);
11128 }
11129- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
11130+ print_ftrace_graph_addr(addr, data, ops, task, graph);
11131 }
11132 stack++;
11133 }
11134@@ -111,7 +111,7 @@ print_context_stack(struct thread_info *
11135 EXPORT_SYMBOL_GPL(print_context_stack);
11136
11137 unsigned long
11138-print_context_stack_bp(struct thread_info *tinfo,
11139+print_context_stack_bp(struct task_struct *task, void *stack_start,
11140 unsigned long *stack, unsigned long bp,
11141 const struct stacktrace_ops *ops, void *data,
11142 unsigned long *end, int *graph)
11143@@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_inf
11144 struct stack_frame *frame = (struct stack_frame *)bp;
11145 unsigned long *ret_addr = &frame->return_address;
11146
11147- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
11148+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
11149 unsigned long addr = *ret_addr;
11150
11151 if (!__kernel_text_address(addr))
11152@@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_inf
11153 ops->address(data, addr, 1);
11154 frame = frame->next_frame;
11155 ret_addr = &frame->return_address;
11156- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
11157+ print_ftrace_graph_addr(addr, data, ops, task, graph);
11158 }
11159
11160 return (unsigned long)frame;
11161@@ -186,7 +186,7 @@ void dump_stack(void)
11162
11163 bp = stack_frame(current, NULL);
11164 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
11165- current->pid, current->comm, print_tainted(),
11166+ task_pid_nr(current), current->comm, print_tainted(),
11167 init_utsname()->release,
11168 (int)strcspn(init_utsname()->version, " "),
11169 init_utsname()->version);
11170@@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
11171 }
11172 EXPORT_SYMBOL_GPL(oops_begin);
11173
11174+extern void gr_handle_kernel_exploit(void);
11175+
11176 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
11177 {
11178 if (regs && kexec_should_crash(current))
11179@@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long fl
11180 panic("Fatal exception in interrupt");
11181 if (panic_on_oops)
11182 panic("Fatal exception");
11183- do_exit(signr);
11184+
11185+ gr_handle_kernel_exploit();
11186+
11187+ do_group_exit(signr);
11188 }
11189
11190 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
11191@@ -269,7 +274,7 @@ int __kprobes __die(const char *str, str
11192
11193 show_registers(regs);
11194 #ifdef CONFIG_X86_32
11195- if (user_mode_vm(regs)) {
11196+ if (user_mode(regs)) {
11197 sp = regs->sp;
11198 ss = regs->ss & 0xffff;
11199 } else {
11200@@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs
11201 unsigned long flags = oops_begin();
11202 int sig = SIGSEGV;
11203
11204- if (!user_mode_vm(regs))
11205+ if (!user_mode(regs))
11206 report_bug(regs->ip, regs);
11207
11208 if (__die(str, regs, err))
11209diff -urNp linux-3.0.4/arch/x86/kernel/early_printk.c linux-3.0.4/arch/x86/kernel/early_printk.c
11210--- linux-3.0.4/arch/x86/kernel/early_printk.c 2011-07-21 22:17:23.000000000 -0400
11211+++ linux-3.0.4/arch/x86/kernel/early_printk.c 2011-08-23 21:48:14.000000000 -0400
11212@@ -7,6 +7,7 @@
11213 #include <linux/pci_regs.h>
11214 #include <linux/pci_ids.h>
11215 #include <linux/errno.h>
11216+#include <linux/sched.h>
11217 #include <asm/io.h>
11218 #include <asm/processor.h>
11219 #include <asm/fcntl.h>
11220@@ -179,6 +180,8 @@ asmlinkage void early_printk(const char
11221 int n;
11222 va_list ap;
11223
11224+ pax_track_stack();
11225+
11226 va_start(ap, fmt);
11227 n = vscnprintf(buf, sizeof(buf), fmt, ap);
11228 early_console->write(early_console, buf, n);
11229diff -urNp linux-3.0.4/arch/x86/kernel/entry_32.S linux-3.0.4/arch/x86/kernel/entry_32.S
11230--- linux-3.0.4/arch/x86/kernel/entry_32.S 2011-07-21 22:17:23.000000000 -0400
11231+++ linux-3.0.4/arch/x86/kernel/entry_32.S 2011-08-30 18:23:52.000000000 -0400
11232@@ -185,13 +185,146 @@
11233 /*CFI_REL_OFFSET gs, PT_GS*/
11234 .endm
11235 .macro SET_KERNEL_GS reg
11236+
11237+#ifdef CONFIG_CC_STACKPROTECTOR
11238 movl $(__KERNEL_STACK_CANARY), \reg
11239+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
11240+ movl $(__USER_DS), \reg
11241+#else
11242+ xorl \reg, \reg
11243+#endif
11244+
11245 movl \reg, %gs
11246 .endm
11247
11248 #endif /* CONFIG_X86_32_LAZY_GS */
11249
11250-.macro SAVE_ALL
11251+.macro pax_enter_kernel
11252+#ifdef CONFIG_PAX_KERNEXEC
11253+ call pax_enter_kernel
11254+#endif
11255+.endm
11256+
11257+.macro pax_exit_kernel
11258+#ifdef CONFIG_PAX_KERNEXEC
11259+ call pax_exit_kernel
11260+#endif
11261+.endm
11262+
11263+#ifdef CONFIG_PAX_KERNEXEC
11264+ENTRY(pax_enter_kernel)
11265+#ifdef CONFIG_PARAVIRT
11266+ pushl %eax
11267+ pushl %ecx
11268+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
11269+ mov %eax, %esi
11270+#else
11271+ mov %cr0, %esi
11272+#endif
11273+ bts $16, %esi
11274+ jnc 1f
11275+ mov %cs, %esi
11276+ cmp $__KERNEL_CS, %esi
11277+ jz 3f
11278+ ljmp $__KERNEL_CS, $3f
11279+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
11280+2:
11281+#ifdef CONFIG_PARAVIRT
11282+ mov %esi, %eax
11283+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11284+#else
11285+ mov %esi, %cr0
11286+#endif
11287+3:
11288+#ifdef CONFIG_PARAVIRT
11289+ popl %ecx
11290+ popl %eax
11291+#endif
11292+ ret
11293+ENDPROC(pax_enter_kernel)
11294+
11295+ENTRY(pax_exit_kernel)
11296+#ifdef CONFIG_PARAVIRT
11297+ pushl %eax
11298+ pushl %ecx
11299+#endif
11300+ mov %cs, %esi
11301+ cmp $__KERNEXEC_KERNEL_CS, %esi
11302+ jnz 2f
11303+#ifdef CONFIG_PARAVIRT
11304+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
11305+ mov %eax, %esi
11306+#else
11307+ mov %cr0, %esi
11308+#endif
11309+ btr $16, %esi
11310+ ljmp $__KERNEL_CS, $1f
11311+1:
11312+#ifdef CONFIG_PARAVIRT
11313+ mov %esi, %eax
11314+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
11315+#else
11316+ mov %esi, %cr0
11317+#endif
11318+2:
11319+#ifdef CONFIG_PARAVIRT
11320+ popl %ecx
11321+ popl %eax
11322+#endif
11323+ ret
11324+ENDPROC(pax_exit_kernel)
11325+#endif
11326+
11327+.macro pax_erase_kstack
11328+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11329+ call pax_erase_kstack
11330+#endif
11331+.endm
11332+
11333+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11334+/*
11335+ * ebp: thread_info
11336+ * ecx, edx: can be clobbered
11337+ */
11338+ENTRY(pax_erase_kstack)
11339+ pushl %edi
11340+ pushl %eax
11341+
11342+ mov TI_lowest_stack(%ebp), %edi
11343+ mov $-0xBEEF, %eax
11344+ std
11345+
11346+1: mov %edi, %ecx
11347+ and $THREAD_SIZE_asm - 1, %ecx
11348+ shr $2, %ecx
11349+ repne scasl
11350+ jecxz 2f
11351+
11352+ cmp $2*16, %ecx
11353+ jc 2f
11354+
11355+ mov $2*16, %ecx
11356+ repe scasl
11357+ jecxz 2f
11358+ jne 1b
11359+
11360+2: cld
11361+ mov %esp, %ecx
11362+ sub %edi, %ecx
11363+ shr $2, %ecx
11364+ rep stosl
11365+
11366+ mov TI_task_thread_sp0(%ebp), %edi
11367+ sub $128, %edi
11368+ mov %edi, TI_lowest_stack(%ebp)
11369+
11370+ popl %eax
11371+ popl %edi
11372+ ret
11373+ENDPROC(pax_erase_kstack)
11374+#endif
11375+
11376+.macro __SAVE_ALL _DS
11377 cld
11378 PUSH_GS
11379 pushl_cfi %fs
11380@@ -214,7 +347,7 @@
11381 CFI_REL_OFFSET ecx, 0
11382 pushl_cfi %ebx
11383 CFI_REL_OFFSET ebx, 0
11384- movl $(__USER_DS), %edx
11385+ movl $\_DS, %edx
11386 movl %edx, %ds
11387 movl %edx, %es
11388 movl $(__KERNEL_PERCPU), %edx
11389@@ -222,6 +355,15 @@
11390 SET_KERNEL_GS %edx
11391 .endm
11392
11393+.macro SAVE_ALL
11394+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
11395+ __SAVE_ALL __KERNEL_DS
11396+ pax_enter_kernel
11397+#else
11398+ __SAVE_ALL __USER_DS
11399+#endif
11400+.endm
11401+
11402 .macro RESTORE_INT_REGS
11403 popl_cfi %ebx
11404 CFI_RESTORE ebx
11405@@ -332,7 +474,15 @@ check_userspace:
11406 movb PT_CS(%esp), %al
11407 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
11408 cmpl $USER_RPL, %eax
11409+
11410+#ifdef CONFIG_PAX_KERNEXEC
11411+ jae resume_userspace
11412+
11413+ PAX_EXIT_KERNEL
11414+ jmp resume_kernel
11415+#else
11416 jb resume_kernel # not returning to v8086 or userspace
11417+#endif
11418
11419 ENTRY(resume_userspace)
11420 LOCKDEP_SYS_EXIT
11421@@ -344,7 +494,7 @@ ENTRY(resume_userspace)
11422 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
11423 # int/exception return?
11424 jne work_pending
11425- jmp restore_all
11426+ jmp restore_all_pax
11427 END(ret_from_exception)
11428
11429 #ifdef CONFIG_PREEMPT
11430@@ -394,23 +544,34 @@ sysenter_past_esp:
11431 /*CFI_REL_OFFSET cs, 0*/
11432 /*
11433 * Push current_thread_info()->sysenter_return to the stack.
11434- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
11435- * pushed above; +8 corresponds to copy_thread's esp0 setting.
11436 */
11437- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
11438+ pushl_cfi $0
11439 CFI_REL_OFFSET eip, 0
11440
11441 pushl_cfi %eax
11442 SAVE_ALL
11443+ GET_THREAD_INFO(%ebp)
11444+ movl TI_sysenter_return(%ebp),%ebp
11445+ movl %ebp,PT_EIP(%esp)
11446 ENABLE_INTERRUPTS(CLBR_NONE)
11447
11448 /*
11449 * Load the potential sixth argument from user stack.
11450 * Careful about security.
11451 */
11452+ movl PT_OLDESP(%esp),%ebp
11453+
11454+#ifdef CONFIG_PAX_MEMORY_UDEREF
11455+ mov PT_OLDSS(%esp),%ds
11456+1: movl %ds:(%ebp),%ebp
11457+ push %ss
11458+ pop %ds
11459+#else
11460 cmpl $__PAGE_OFFSET-3,%ebp
11461 jae syscall_fault
11462 1: movl (%ebp),%ebp
11463+#endif
11464+
11465 movl %ebp,PT_EBP(%esp)
11466 .section __ex_table,"a"
11467 .align 4
11468@@ -433,12 +594,24 @@ sysenter_do_call:
11469 testl $_TIF_ALLWORK_MASK, %ecx
11470 jne sysexit_audit
11471 sysenter_exit:
11472+
11473+#ifdef CONFIG_PAX_RANDKSTACK
11474+ pushl_cfi %eax
11475+ movl %esp, %eax
11476+ call pax_randomize_kstack
11477+ popl_cfi %eax
11478+#endif
11479+
11480+ pax_erase_kstack
11481+
11482 /* if something modifies registers it must also disable sysexit */
11483 movl PT_EIP(%esp), %edx
11484 movl PT_OLDESP(%esp), %ecx
11485 xorl %ebp,%ebp
11486 TRACE_IRQS_ON
11487 1: mov PT_FS(%esp), %fs
11488+2: mov PT_DS(%esp), %ds
11489+3: mov PT_ES(%esp), %es
11490 PTGS_TO_GS
11491 ENABLE_INTERRUPTS_SYSEXIT
11492
11493@@ -455,6 +628,9 @@ sysenter_audit:
11494 movl %eax,%edx /* 2nd arg: syscall number */
11495 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
11496 call audit_syscall_entry
11497+
11498+ pax_erase_kstack
11499+
11500 pushl_cfi %ebx
11501 movl PT_EAX(%esp),%eax /* reload syscall number */
11502 jmp sysenter_do_call
11503@@ -481,11 +657,17 @@ sysexit_audit:
11504
11505 CFI_ENDPROC
11506 .pushsection .fixup,"ax"
11507-2: movl $0,PT_FS(%esp)
11508+4: movl $0,PT_FS(%esp)
11509+ jmp 1b
11510+5: movl $0,PT_DS(%esp)
11511+ jmp 1b
11512+6: movl $0,PT_ES(%esp)
11513 jmp 1b
11514 .section __ex_table,"a"
11515 .align 4
11516- .long 1b,2b
11517+ .long 1b,4b
11518+ .long 2b,5b
11519+ .long 3b,6b
11520 .popsection
11521 PTGS_TO_GS_EX
11522 ENDPROC(ia32_sysenter_target)
11523@@ -518,6 +700,15 @@ syscall_exit:
11524 testl $_TIF_ALLWORK_MASK, %ecx # current->work
11525 jne syscall_exit_work
11526
11527+restore_all_pax:
11528+
11529+#ifdef CONFIG_PAX_RANDKSTACK
11530+ movl %esp, %eax
11531+ call pax_randomize_kstack
11532+#endif
11533+
11534+ pax_erase_kstack
11535+
11536 restore_all:
11537 TRACE_IRQS_IRET
11538 restore_all_notrace:
11539@@ -577,14 +768,34 @@ ldt_ss:
11540 * compensating for the offset by changing to the ESPFIX segment with
11541 * a base address that matches for the difference.
11542 */
11543-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
11544+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
11545 mov %esp, %edx /* load kernel esp */
11546 mov PT_OLDESP(%esp), %eax /* load userspace esp */
11547 mov %dx, %ax /* eax: new kernel esp */
11548 sub %eax, %edx /* offset (low word is 0) */
11549+#ifdef CONFIG_SMP
11550+ movl PER_CPU_VAR(cpu_number), %ebx
11551+ shll $PAGE_SHIFT_asm, %ebx
11552+ addl $cpu_gdt_table, %ebx
11553+#else
11554+ movl $cpu_gdt_table, %ebx
11555+#endif
11556 shr $16, %edx
11557- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
11558- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
11559+
11560+#ifdef CONFIG_PAX_KERNEXEC
11561+ mov %cr0, %esi
11562+ btr $16, %esi
11563+ mov %esi, %cr0
11564+#endif
11565+
11566+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
11567+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
11568+
11569+#ifdef CONFIG_PAX_KERNEXEC
11570+ bts $16, %esi
11571+ mov %esi, %cr0
11572+#endif
11573+
11574 pushl_cfi $__ESPFIX_SS
11575 pushl_cfi %eax /* new kernel esp */
11576 /* Disable interrupts, but do not irqtrace this section: we
11577@@ -613,29 +824,23 @@ work_resched:
11578 movl TI_flags(%ebp), %ecx
11579 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
11580 # than syscall tracing?
11581- jz restore_all
11582+ jz restore_all_pax
11583 testb $_TIF_NEED_RESCHED, %cl
11584 jnz work_resched
11585
11586 work_notifysig: # deal with pending signals and
11587 # notify-resume requests
11588+ movl %esp, %eax
11589 #ifdef CONFIG_VM86
11590 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
11591- movl %esp, %eax
11592- jne work_notifysig_v86 # returning to kernel-space or
11593+ jz 1f # returning to kernel-space or
11594 # vm86-space
11595- xorl %edx, %edx
11596- call do_notify_resume
11597- jmp resume_userspace_sig
11598
11599- ALIGN
11600-work_notifysig_v86:
11601 pushl_cfi %ecx # save ti_flags for do_notify_resume
11602 call save_v86_state # %eax contains pt_regs pointer
11603 popl_cfi %ecx
11604 movl %eax, %esp
11605-#else
11606- movl %esp, %eax
11607+1:
11608 #endif
11609 xorl %edx, %edx
11610 call do_notify_resume
11611@@ -648,6 +853,9 @@ syscall_trace_entry:
11612 movl $-ENOSYS,PT_EAX(%esp)
11613 movl %esp, %eax
11614 call syscall_trace_enter
11615+
11616+ pax_erase_kstack
11617+
11618 /* What it returned is what we'll actually use. */
11619 cmpl $(nr_syscalls), %eax
11620 jnae syscall_call
11621@@ -670,6 +878,10 @@ END(syscall_exit_work)
11622
11623 RING0_INT_FRAME # can't unwind into user space anyway
11624 syscall_fault:
11625+#ifdef CONFIG_PAX_MEMORY_UDEREF
11626+ push %ss
11627+ pop %ds
11628+#endif
11629 GET_THREAD_INFO(%ebp)
11630 movl $-EFAULT,PT_EAX(%esp)
11631 jmp resume_userspace
11632@@ -752,6 +964,36 @@ ptregs_clone:
11633 CFI_ENDPROC
11634 ENDPROC(ptregs_clone)
11635
11636+ ALIGN;
11637+ENTRY(kernel_execve)
11638+ CFI_STARTPROC
11639+ pushl_cfi %ebp
11640+ sub $PT_OLDSS+4,%esp
11641+ pushl_cfi %edi
11642+ pushl_cfi %ecx
11643+ pushl_cfi %eax
11644+ lea 3*4(%esp),%edi
11645+ mov $PT_OLDSS/4+1,%ecx
11646+ xorl %eax,%eax
11647+ rep stosl
11648+ popl_cfi %eax
11649+ popl_cfi %ecx
11650+ popl_cfi %edi
11651+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
11652+ pushl_cfi %esp
11653+ call sys_execve
11654+ add $4,%esp
11655+ CFI_ADJUST_CFA_OFFSET -4
11656+ GET_THREAD_INFO(%ebp)
11657+ test %eax,%eax
11658+ jz syscall_exit
11659+ add $PT_OLDSS+4,%esp
11660+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
11661+ popl_cfi %ebp
11662+ ret
11663+ CFI_ENDPROC
11664+ENDPROC(kernel_execve)
11665+
11666 .macro FIXUP_ESPFIX_STACK
11667 /*
11668 * Switch back for ESPFIX stack to the normal zerobased stack
11669@@ -761,8 +1003,15 @@ ENDPROC(ptregs_clone)
11670 * normal stack and adjusts ESP with the matching offset.
11671 */
11672 /* fixup the stack */
11673- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
11674- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
11675+#ifdef CONFIG_SMP
11676+ movl PER_CPU_VAR(cpu_number), %ebx
11677+ shll $PAGE_SHIFT_asm, %ebx
11678+ addl $cpu_gdt_table, %ebx
11679+#else
11680+ movl $cpu_gdt_table, %ebx
11681+#endif
11682+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
11683+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
11684 shl $16, %eax
11685 addl %esp, %eax /* the adjusted stack pointer */
11686 pushl_cfi $__KERNEL_DS
11687@@ -1213,7 +1462,6 @@ return_to_handler:
11688 jmp *%ecx
11689 #endif
11690
11691-.section .rodata,"a"
11692 #include "syscall_table_32.S"
11693
11694 syscall_table_size=(.-sys_call_table)
11695@@ -1259,9 +1507,12 @@ error_code:
11696 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
11697 REG_TO_PTGS %ecx
11698 SET_KERNEL_GS %ecx
11699- movl $(__USER_DS), %ecx
11700+ movl $(__KERNEL_DS), %ecx
11701 movl %ecx, %ds
11702 movl %ecx, %es
11703+
11704+ pax_enter_kernel
11705+
11706 TRACE_IRQS_OFF
11707 movl %esp,%eax # pt_regs pointer
11708 call *%edi
11709@@ -1346,6 +1597,9 @@ nmi_stack_correct:
11710 xorl %edx,%edx # zero error code
11711 movl %esp,%eax # pt_regs pointer
11712 call do_nmi
11713+
11714+ pax_exit_kernel
11715+
11716 jmp restore_all_notrace
11717 CFI_ENDPROC
11718
11719@@ -1382,6 +1636,9 @@ nmi_espfix_stack:
11720 FIXUP_ESPFIX_STACK # %eax == %esp
11721 xorl %edx,%edx # zero error code
11722 call do_nmi
11723+
11724+ pax_exit_kernel
11725+
11726 RESTORE_REGS
11727 lss 12+4(%esp), %esp # back to espfix stack
11728 CFI_ADJUST_CFA_OFFSET -24
11729diff -urNp linux-3.0.4/arch/x86/kernel/entry_64.S linux-3.0.4/arch/x86/kernel/entry_64.S
11730--- linux-3.0.4/arch/x86/kernel/entry_64.S 2011-07-21 22:17:23.000000000 -0400
11731+++ linux-3.0.4/arch/x86/kernel/entry_64.S 2011-08-26 19:49:56.000000000 -0400
11732@@ -53,6 +53,7 @@
11733 #include <asm/paravirt.h>
11734 #include <asm/ftrace.h>
11735 #include <asm/percpu.h>
11736+#include <asm/pgtable.h>
11737
11738 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11739 #include <linux/elf-em.h>
11740@@ -176,6 +177,264 @@ ENTRY(native_usergs_sysret64)
11741 ENDPROC(native_usergs_sysret64)
11742 #endif /* CONFIG_PARAVIRT */
11743
11744+ .macro ljmpq sel, off
11745+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
11746+ .byte 0x48; ljmp *1234f(%rip)
11747+ .pushsection .rodata
11748+ .align 16
11749+ 1234: .quad \off; .word \sel
11750+ .popsection
11751+#else
11752+ pushq $\sel
11753+ pushq $\off
11754+ lretq
11755+#endif
11756+ .endm
11757+
11758+ .macro pax_enter_kernel
11759+#ifdef CONFIG_PAX_KERNEXEC
11760+ call pax_enter_kernel
11761+#endif
11762+ .endm
11763+
11764+ .macro pax_exit_kernel
11765+#ifdef CONFIG_PAX_KERNEXEC
11766+ call pax_exit_kernel
11767+#endif
11768+ .endm
11769+
11770+#ifdef CONFIG_PAX_KERNEXEC
11771+ENTRY(pax_enter_kernel)
11772+ pushq %rdi
11773+
11774+#ifdef CONFIG_PARAVIRT
11775+ PV_SAVE_REGS(CLBR_RDI)
11776+#endif
11777+
11778+ GET_CR0_INTO_RDI
11779+ bts $16,%rdi
11780+ jnc 1f
11781+ mov %cs,%edi
11782+ cmp $__KERNEL_CS,%edi
11783+ jz 3f
11784+ ljmpq __KERNEL_CS,3f
11785+1: ljmpq __KERNEXEC_KERNEL_CS,2f
11786+2: SET_RDI_INTO_CR0
11787+3:
11788+
11789+#ifdef CONFIG_PARAVIRT
11790+ PV_RESTORE_REGS(CLBR_RDI)
11791+#endif
11792+
11793+ popq %rdi
11794+ retq
11795+ENDPROC(pax_enter_kernel)
11796+
11797+ENTRY(pax_exit_kernel)
11798+ pushq %rdi
11799+
11800+#ifdef CONFIG_PARAVIRT
11801+ PV_SAVE_REGS(CLBR_RDI)
11802+#endif
11803+
11804+ mov %cs,%rdi
11805+ cmp $__KERNEXEC_KERNEL_CS,%edi
11806+ jnz 2f
11807+ GET_CR0_INTO_RDI
11808+ btr $16,%rdi
11809+ ljmpq __KERNEL_CS,1f
11810+1: SET_RDI_INTO_CR0
11811+2:
11812+
11813+#ifdef CONFIG_PARAVIRT
11814+ PV_RESTORE_REGS(CLBR_RDI);
11815+#endif
11816+
11817+ popq %rdi
11818+ retq
11819+ENDPROC(pax_exit_kernel)
11820+#endif
11821+
11822+ .macro pax_enter_kernel_user
11823+#ifdef CONFIG_PAX_MEMORY_UDEREF
11824+ call pax_enter_kernel_user
11825+#endif
11826+ .endm
11827+
11828+ .macro pax_exit_kernel_user
11829+#ifdef CONFIG_PAX_MEMORY_UDEREF
11830+ call pax_exit_kernel_user
11831+#endif
11832+#ifdef CONFIG_PAX_RANDKSTACK
11833+ push %rax
11834+ call pax_randomize_kstack
11835+ pop %rax
11836+#endif
11837+ .endm
11838+
11839+#ifdef CONFIG_PAX_MEMORY_UDEREF
11840+ENTRY(pax_enter_kernel_user)
11841+ pushq %rdi
11842+ pushq %rbx
11843+
11844+#ifdef CONFIG_PARAVIRT
11845+ PV_SAVE_REGS(CLBR_RDI)
11846+#endif
11847+
11848+ GET_CR3_INTO_RDI
11849+ mov %rdi,%rbx
11850+ add $__START_KERNEL_map,%rbx
11851+ sub phys_base(%rip),%rbx
11852+
11853+#ifdef CONFIG_PARAVIRT
11854+ pushq %rdi
11855+ cmpl $0, pv_info+PARAVIRT_enabled
11856+ jz 1f
11857+ i = 0
11858+ .rept USER_PGD_PTRS
11859+ mov i*8(%rbx),%rsi
11860+ mov $0,%sil
11861+ lea i*8(%rbx),%rdi
11862+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
11863+ i = i + 1
11864+ .endr
11865+ jmp 2f
11866+1:
11867+#endif
11868+
11869+ i = 0
11870+ .rept USER_PGD_PTRS
11871+ movb $0,i*8(%rbx)
11872+ i = i + 1
11873+ .endr
11874+
11875+#ifdef CONFIG_PARAVIRT
11876+2: popq %rdi
11877+#endif
11878+ SET_RDI_INTO_CR3
11879+
11880+#ifdef CONFIG_PAX_KERNEXEC
11881+ GET_CR0_INTO_RDI
11882+ bts $16,%rdi
11883+ SET_RDI_INTO_CR0
11884+#endif
11885+
11886+#ifdef CONFIG_PARAVIRT
11887+ PV_RESTORE_REGS(CLBR_RDI)
11888+#endif
11889+
11890+ popq %rbx
11891+ popq %rdi
11892+ retq
11893+ENDPROC(pax_enter_kernel_user)
11894+
11895+ENTRY(pax_exit_kernel_user)
11896+ push %rdi
11897+
11898+#ifdef CONFIG_PARAVIRT
11899+ pushq %rbx
11900+ PV_SAVE_REGS(CLBR_RDI)
11901+#endif
11902+
11903+#ifdef CONFIG_PAX_KERNEXEC
11904+ GET_CR0_INTO_RDI
11905+ btr $16,%rdi
11906+ SET_RDI_INTO_CR0
11907+#endif
11908+
11909+ GET_CR3_INTO_RDI
11910+ add $__START_KERNEL_map,%rdi
11911+ sub phys_base(%rip),%rdi
11912+
11913+#ifdef CONFIG_PARAVIRT
11914+ cmpl $0, pv_info+PARAVIRT_enabled
11915+ jz 1f
11916+ mov %rdi,%rbx
11917+ i = 0
11918+ .rept USER_PGD_PTRS
11919+ mov i*8(%rbx),%rsi
11920+ mov $0x67,%sil
11921+ lea i*8(%rbx),%rdi
11922+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
11923+ i = i + 1
11924+ .endr
11925+ jmp 2f
11926+1:
11927+#endif
11928+
11929+ i = 0
11930+ .rept USER_PGD_PTRS
11931+ movb $0x67,i*8(%rdi)
11932+ i = i + 1
11933+ .endr
11934+
11935+#ifdef CONFIG_PARAVIRT
11936+2: PV_RESTORE_REGS(CLBR_RDI)
11937+ popq %rbx
11938+#endif
11939+
11940+ popq %rdi
11941+ retq
11942+ENDPROC(pax_exit_kernel_user)
11943+#endif
11944+
11945+ .macro pax_erase_kstack
11946+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11947+ call pax_erase_kstack
11948+#endif
11949+ .endm
11950+
11951+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11952+/*
11953+ * r10: thread_info
11954+ * rcx, rdx: can be clobbered
11955+ */
11956+ENTRY(pax_erase_kstack)
11957+ pushq %rdi
11958+ pushq %rax
11959+ pushq %r10
11960+
11961+ GET_THREAD_INFO(%r10)
11962+ mov TI_lowest_stack(%r10), %rdi
11963+ mov $-0xBEEF, %rax
11964+ std
11965+
11966+1: mov %edi, %ecx
11967+ and $THREAD_SIZE_asm - 1, %ecx
11968+ shr $3, %ecx
11969+ repne scasq
11970+ jecxz 2f
11971+
11972+ cmp $2*8, %ecx
11973+ jc 2f
11974+
11975+ mov $2*8, %ecx
11976+ repe scasq
11977+ jecxz 2f
11978+ jne 1b
11979+
11980+2: cld
11981+ mov %esp, %ecx
11982+ sub %edi, %ecx
11983+
11984+ cmp $THREAD_SIZE_asm, %rcx
11985+ jb 3f
11986+ ud2
11987+3:
11988+
11989+ shr $3, %ecx
11990+ rep stosq
11991+
11992+ mov TI_task_thread_sp0(%r10), %rdi
11993+ sub $256, %rdi
11994+ mov %rdi, TI_lowest_stack(%r10)
11995+
11996+ popq %r10
11997+ popq %rax
11998+ popq %rdi
11999+ ret
12000+ENDPROC(pax_erase_kstack)
12001+#endif
12002
12003 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
12004 #ifdef CONFIG_TRACE_IRQFLAGS
12005@@ -318,7 +577,7 @@ ENTRY(save_args)
12006 leaq -RBP+8(%rsp),%rdi /* arg1 for handler */
12007 movq_cfi rbp, 8 /* push %rbp */
12008 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
12009- testl $3, CS(%rdi)
12010+ testb $3, CS(%rdi)
12011 je 1f
12012 SWAPGS
12013 /*
12014@@ -409,7 +668,7 @@ ENTRY(ret_from_fork)
12015
12016 RESTORE_REST
12017
12018- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
12019+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
12020 je int_ret_from_sys_call
12021
12022 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
12023@@ -455,7 +714,7 @@ END(ret_from_fork)
12024 ENTRY(system_call)
12025 CFI_STARTPROC simple
12026 CFI_SIGNAL_FRAME
12027- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
12028+ CFI_DEF_CFA rsp,0
12029 CFI_REGISTER rip,rcx
12030 /*CFI_REGISTER rflags,r11*/
12031 SWAPGS_UNSAFE_STACK
12032@@ -468,12 +727,13 @@ ENTRY(system_call_after_swapgs)
12033
12034 movq %rsp,PER_CPU_VAR(old_rsp)
12035 movq PER_CPU_VAR(kernel_stack),%rsp
12036+ pax_enter_kernel_user
12037 /*
12038 * No need to follow this irqs off/on section - it's straight
12039 * and short:
12040 */
12041 ENABLE_INTERRUPTS(CLBR_NONE)
12042- SAVE_ARGS 8,1
12043+ SAVE_ARGS 8*6,1
12044 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
12045 movq %rcx,RIP-ARGOFFSET(%rsp)
12046 CFI_REL_OFFSET rip,RIP-ARGOFFSET
12047@@ -502,6 +762,8 @@ sysret_check:
12048 andl %edi,%edx
12049 jnz sysret_careful
12050 CFI_REMEMBER_STATE
12051+ pax_exit_kernel_user
12052+ pax_erase_kstack
12053 /*
12054 * sysretq will re-enable interrupts:
12055 */
12056@@ -560,6 +822,9 @@ auditsys:
12057 movq %rax,%rsi /* 2nd arg: syscall number */
12058 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
12059 call audit_syscall_entry
12060+
12061+ pax_erase_kstack
12062+
12063 LOAD_ARGS 0 /* reload call-clobbered registers */
12064 jmp system_call_fastpath
12065
12066@@ -590,6 +855,9 @@ tracesys:
12067 FIXUP_TOP_OF_STACK %rdi
12068 movq %rsp,%rdi
12069 call syscall_trace_enter
12070+
12071+ pax_erase_kstack
12072+
12073 /*
12074 * Reload arg registers from stack in case ptrace changed them.
12075 * We don't reload %rax because syscall_trace_enter() returned
12076@@ -611,7 +879,7 @@ tracesys:
12077 GLOBAL(int_ret_from_sys_call)
12078 DISABLE_INTERRUPTS(CLBR_NONE)
12079 TRACE_IRQS_OFF
12080- testl $3,CS-ARGOFFSET(%rsp)
12081+ testb $3,CS-ARGOFFSET(%rsp)
12082 je retint_restore_args
12083 movl $_TIF_ALLWORK_MASK,%edi
12084 /* edi: mask to check */
12085@@ -793,6 +1061,16 @@ END(interrupt)
12086 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
12087 call save_args
12088 PARTIAL_FRAME 0
12089+#ifdef CONFIG_PAX_MEMORY_UDEREF
12090+ testb $3, CS(%rdi)
12091+ jnz 1f
12092+ pax_enter_kernel
12093+ jmp 2f
12094+1: pax_enter_kernel_user
12095+2:
12096+#else
12097+ pax_enter_kernel
12098+#endif
12099 call \func
12100 .endm
12101
12102@@ -825,7 +1103,7 @@ ret_from_intr:
12103 CFI_ADJUST_CFA_OFFSET -8
12104 exit_intr:
12105 GET_THREAD_INFO(%rcx)
12106- testl $3,CS-ARGOFFSET(%rsp)
12107+ testb $3,CS-ARGOFFSET(%rsp)
12108 je retint_kernel
12109
12110 /* Interrupt came from user space */
12111@@ -847,12 +1125,15 @@ retint_swapgs: /* return to user-space
12112 * The iretq could re-enable interrupts:
12113 */
12114 DISABLE_INTERRUPTS(CLBR_ANY)
12115+ pax_exit_kernel_user
12116+ pax_erase_kstack
12117 TRACE_IRQS_IRETQ
12118 SWAPGS
12119 jmp restore_args
12120
12121 retint_restore_args: /* return to kernel space */
12122 DISABLE_INTERRUPTS(CLBR_ANY)
12123+ pax_exit_kernel
12124 /*
12125 * The iretq could re-enable interrupts:
12126 */
12127@@ -1027,6 +1308,16 @@ ENTRY(\sym)
12128 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
12129 call error_entry
12130 DEFAULT_FRAME 0
12131+#ifdef CONFIG_PAX_MEMORY_UDEREF
12132+ testb $3, CS(%rsp)
12133+ jnz 1f
12134+ pax_enter_kernel
12135+ jmp 2f
12136+1: pax_enter_kernel_user
12137+2:
12138+#else
12139+ pax_enter_kernel
12140+#endif
12141 movq %rsp,%rdi /* pt_regs pointer */
12142 xorl %esi,%esi /* no error code */
12143 call \do_sym
12144@@ -1044,6 +1335,16 @@ ENTRY(\sym)
12145 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
12146 call save_paranoid
12147 TRACE_IRQS_OFF
12148+#ifdef CONFIG_PAX_MEMORY_UDEREF
12149+ testb $3, CS(%rsp)
12150+ jnz 1f
12151+ pax_enter_kernel
12152+ jmp 2f
12153+1: pax_enter_kernel_user
12154+2:
12155+#else
12156+ pax_enter_kernel
12157+#endif
12158 movq %rsp,%rdi /* pt_regs pointer */
12159 xorl %esi,%esi /* no error code */
12160 call \do_sym
12161@@ -1052,7 +1353,7 @@ ENTRY(\sym)
12162 END(\sym)
12163 .endm
12164
12165-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
12166+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
12167 .macro paranoidzeroentry_ist sym do_sym ist
12168 ENTRY(\sym)
12169 INTR_FRAME
12170@@ -1062,8 +1363,24 @@ ENTRY(\sym)
12171 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
12172 call save_paranoid
12173 TRACE_IRQS_OFF
12174+#ifdef CONFIG_PAX_MEMORY_UDEREF
12175+ testb $3, CS(%rsp)
12176+ jnz 1f
12177+ pax_enter_kernel
12178+ jmp 2f
12179+1: pax_enter_kernel_user
12180+2:
12181+#else
12182+ pax_enter_kernel
12183+#endif
12184 movq %rsp,%rdi /* pt_regs pointer */
12185 xorl %esi,%esi /* no error code */
12186+#ifdef CONFIG_SMP
12187+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
12188+ lea init_tss(%r12), %r12
12189+#else
12190+ lea init_tss(%rip), %r12
12191+#endif
12192 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
12193 call \do_sym
12194 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
12195@@ -1080,6 +1397,16 @@ ENTRY(\sym)
12196 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
12197 call error_entry
12198 DEFAULT_FRAME 0
12199+#ifdef CONFIG_PAX_MEMORY_UDEREF
12200+ testb $3, CS(%rsp)
12201+ jnz 1f
12202+ pax_enter_kernel
12203+ jmp 2f
12204+1: pax_enter_kernel_user
12205+2:
12206+#else
12207+ pax_enter_kernel
12208+#endif
12209 movq %rsp,%rdi /* pt_regs pointer */
12210 movq ORIG_RAX(%rsp),%rsi /* get error code */
12211 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
12212@@ -1099,6 +1426,16 @@ ENTRY(\sym)
12213 call save_paranoid
12214 DEFAULT_FRAME 0
12215 TRACE_IRQS_OFF
12216+#ifdef CONFIG_PAX_MEMORY_UDEREF
12217+ testb $3, CS(%rsp)
12218+ jnz 1f
12219+ pax_enter_kernel
12220+ jmp 2f
12221+1: pax_enter_kernel_user
12222+2:
12223+#else
12224+ pax_enter_kernel
12225+#endif
12226 movq %rsp,%rdi /* pt_regs pointer */
12227 movq ORIG_RAX(%rsp),%rsi /* get error code */
12228 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
12229@@ -1361,14 +1698,27 @@ ENTRY(paranoid_exit)
12230 TRACE_IRQS_OFF
12231 testl %ebx,%ebx /* swapgs needed? */
12232 jnz paranoid_restore
12233- testl $3,CS(%rsp)
12234+ testb $3,CS(%rsp)
12235 jnz paranoid_userspace
12236+#ifdef CONFIG_PAX_MEMORY_UDEREF
12237+ pax_exit_kernel
12238+ TRACE_IRQS_IRETQ 0
12239+ SWAPGS_UNSAFE_STACK
12240+ RESTORE_ALL 8
12241+ jmp irq_return
12242+#endif
12243 paranoid_swapgs:
12244+#ifdef CONFIG_PAX_MEMORY_UDEREF
12245+ pax_exit_kernel_user
12246+#else
12247+ pax_exit_kernel
12248+#endif
12249 TRACE_IRQS_IRETQ 0
12250 SWAPGS_UNSAFE_STACK
12251 RESTORE_ALL 8
12252 jmp irq_return
12253 paranoid_restore:
12254+ pax_exit_kernel
12255 TRACE_IRQS_IRETQ 0
12256 RESTORE_ALL 8
12257 jmp irq_return
12258@@ -1426,7 +1776,7 @@ ENTRY(error_entry)
12259 movq_cfi r14, R14+8
12260 movq_cfi r15, R15+8
12261 xorl %ebx,%ebx
12262- testl $3,CS+8(%rsp)
12263+ testb $3,CS+8(%rsp)
12264 je error_kernelspace
12265 error_swapgs:
12266 SWAPGS
12267@@ -1490,6 +1840,16 @@ ENTRY(nmi)
12268 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
12269 call save_paranoid
12270 DEFAULT_FRAME 0
12271+#ifdef CONFIG_PAX_MEMORY_UDEREF
12272+ testb $3, CS(%rsp)
12273+ jnz 1f
12274+ pax_enter_kernel
12275+ jmp 2f
12276+1: pax_enter_kernel_user
12277+2:
12278+#else
12279+ pax_enter_kernel
12280+#endif
12281 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
12282 movq %rsp,%rdi
12283 movq $-1,%rsi
12284@@ -1500,11 +1860,25 @@ ENTRY(nmi)
12285 DISABLE_INTERRUPTS(CLBR_NONE)
12286 testl %ebx,%ebx /* swapgs needed? */
12287 jnz nmi_restore
12288- testl $3,CS(%rsp)
12289+ testb $3,CS(%rsp)
12290 jnz nmi_userspace
12291+#ifdef CONFIG_PAX_MEMORY_UDEREF
12292+ pax_exit_kernel
12293+ SWAPGS_UNSAFE_STACK
12294+ RESTORE_ALL 8
12295+ jmp irq_return
12296+#endif
12297 nmi_swapgs:
12298+#ifdef CONFIG_PAX_MEMORY_UDEREF
12299+ pax_exit_kernel_user
12300+#else
12301+ pax_exit_kernel
12302+#endif
12303 SWAPGS_UNSAFE_STACK
12304+ RESTORE_ALL 8
12305+ jmp irq_return
12306 nmi_restore:
12307+ pax_exit_kernel
12308 RESTORE_ALL 8
12309 jmp irq_return
12310 nmi_userspace:
12311diff -urNp linux-3.0.4/arch/x86/kernel/ftrace.c linux-3.0.4/arch/x86/kernel/ftrace.c
12312--- linux-3.0.4/arch/x86/kernel/ftrace.c 2011-07-21 22:17:23.000000000 -0400
12313+++ linux-3.0.4/arch/x86/kernel/ftrace.c 2011-08-23 21:47:55.000000000 -0400
12314@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the
12315 static const void *mod_code_newcode; /* holds the text to write to the IP */
12316
12317 static unsigned nmi_wait_count;
12318-static atomic_t nmi_update_count = ATOMIC_INIT(0);
12319+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
12320
12321 int ftrace_arch_read_dyn_info(char *buf, int size)
12322 {
12323@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf,
12324
12325 r = snprintf(buf, size, "%u %u",
12326 nmi_wait_count,
12327- atomic_read(&nmi_update_count));
12328+ atomic_read_unchecked(&nmi_update_count));
12329 return r;
12330 }
12331
12332@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
12333
12334 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
12335 smp_rmb();
12336+ pax_open_kernel();
12337 ftrace_mod_code();
12338- atomic_inc(&nmi_update_count);
12339+ pax_close_kernel();
12340+ atomic_inc_unchecked(&nmi_update_count);
12341 }
12342 /* Must have previous changes seen before executions */
12343 smp_mb();
12344@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, uns
12345 {
12346 unsigned char replaced[MCOUNT_INSN_SIZE];
12347
12348+ ip = ktla_ktva(ip);
12349+
12350 /*
12351 * Note: Due to modules and __init, code can
12352 * disappear and change, we need to protect against faulting
12353@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_fun
12354 unsigned char old[MCOUNT_INSN_SIZE], *new;
12355 int ret;
12356
12357- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
12358+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
12359 new = ftrace_call_replace(ip, (unsigned long)func);
12360 ret = ftrace_modify_code(ip, old, new);
12361
12362@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long
12363 {
12364 unsigned char code[MCOUNT_INSN_SIZE];
12365
12366+ ip = ktla_ktva(ip);
12367+
12368 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
12369 return -EFAULT;
12370
12371diff -urNp linux-3.0.4/arch/x86/kernel/head32.c linux-3.0.4/arch/x86/kernel/head32.c
12372--- linux-3.0.4/arch/x86/kernel/head32.c 2011-07-21 22:17:23.000000000 -0400
12373+++ linux-3.0.4/arch/x86/kernel/head32.c 2011-08-23 21:47:55.000000000 -0400
12374@@ -19,6 +19,7 @@
12375 #include <asm/io_apic.h>
12376 #include <asm/bios_ebda.h>
12377 #include <asm/tlbflush.h>
12378+#include <asm/boot.h>
12379
12380 static void __init i386_default_early_setup(void)
12381 {
12382@@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
12383 {
12384 memblock_init();
12385
12386- memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
12387+ memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
12388
12389 #ifdef CONFIG_BLK_DEV_INITRD
12390 /* Reserve INITRD */
12391diff -urNp linux-3.0.4/arch/x86/kernel/head_32.S linux-3.0.4/arch/x86/kernel/head_32.S
12392--- linux-3.0.4/arch/x86/kernel/head_32.S 2011-07-21 22:17:23.000000000 -0400
12393+++ linux-3.0.4/arch/x86/kernel/head_32.S 2011-08-23 21:47:55.000000000 -0400
12394@@ -25,6 +25,12 @@
12395 /* Physical address */
12396 #define pa(X) ((X) - __PAGE_OFFSET)
12397
12398+#ifdef CONFIG_PAX_KERNEXEC
12399+#define ta(X) (X)
12400+#else
12401+#define ta(X) ((X) - __PAGE_OFFSET)
12402+#endif
12403+
12404 /*
12405 * References to members of the new_cpu_data structure.
12406 */
12407@@ -54,11 +60,7 @@
12408 * and small than max_low_pfn, otherwise will waste some page table entries
12409 */
12410
12411-#if PTRS_PER_PMD > 1
12412-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
12413-#else
12414-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
12415-#endif
12416+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
12417
12418 /* Number of possible pages in the lowmem region */
12419 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
12420@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
12421 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
12422
12423 /*
12424+ * Real beginning of normal "text" segment
12425+ */
12426+ENTRY(stext)
12427+ENTRY(_stext)
12428+
12429+/*
12430 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
12431 * %esi points to the real-mode code as a 32-bit pointer.
12432 * CS and DS must be 4 GB flat segments, but we don't depend on
12433@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
12434 * can.
12435 */
12436 __HEAD
12437+
12438+#ifdef CONFIG_PAX_KERNEXEC
12439+ jmp startup_32
12440+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
12441+.fill PAGE_SIZE-5,1,0xcc
12442+#endif
12443+
12444 ENTRY(startup_32)
12445 movl pa(stack_start),%ecx
12446
12447@@ -105,6 +120,57 @@ ENTRY(startup_32)
12448 2:
12449 leal -__PAGE_OFFSET(%ecx),%esp
12450
12451+#ifdef CONFIG_SMP
12452+ movl $pa(cpu_gdt_table),%edi
12453+ movl $__per_cpu_load,%eax
12454+ movw %ax,__KERNEL_PERCPU + 2(%edi)
12455+ rorl $16,%eax
12456+ movb %al,__KERNEL_PERCPU + 4(%edi)
12457+ movb %ah,__KERNEL_PERCPU + 7(%edi)
12458+ movl $__per_cpu_end - 1,%eax
12459+ subl $__per_cpu_start,%eax
12460+ movw %ax,__KERNEL_PERCPU + 0(%edi)
12461+#endif
12462+
12463+#ifdef CONFIG_PAX_MEMORY_UDEREF
12464+ movl $NR_CPUS,%ecx
12465+ movl $pa(cpu_gdt_table),%edi
12466+1:
12467+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
12468+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
12469+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
12470+ addl $PAGE_SIZE_asm,%edi
12471+ loop 1b
12472+#endif
12473+
12474+#ifdef CONFIG_PAX_KERNEXEC
12475+ movl $pa(boot_gdt),%edi
12476+ movl $__LOAD_PHYSICAL_ADDR,%eax
12477+ movw %ax,__BOOT_CS + 2(%edi)
12478+ rorl $16,%eax
12479+ movb %al,__BOOT_CS + 4(%edi)
12480+ movb %ah,__BOOT_CS + 7(%edi)
12481+ rorl $16,%eax
12482+
12483+ ljmp $(__BOOT_CS),$1f
12484+1:
12485+
12486+ movl $NR_CPUS,%ecx
12487+ movl $pa(cpu_gdt_table),%edi
12488+ addl $__PAGE_OFFSET,%eax
12489+1:
12490+ movw %ax,__KERNEL_CS + 2(%edi)
12491+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
12492+ rorl $16,%eax
12493+ movb %al,__KERNEL_CS + 4(%edi)
12494+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
12495+ movb %ah,__KERNEL_CS + 7(%edi)
12496+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
12497+ rorl $16,%eax
12498+ addl $PAGE_SIZE_asm,%edi
12499+ loop 1b
12500+#endif
12501+
12502 /*
12503 * Clear BSS first so that there are no surprises...
12504 */
12505@@ -195,8 +261,11 @@ ENTRY(startup_32)
12506 movl %eax, pa(max_pfn_mapped)
12507
12508 /* Do early initialization of the fixmap area */
12509- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
12510- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
12511+#ifdef CONFIG_COMPAT_VDSO
12512+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
12513+#else
12514+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
12515+#endif
12516 #else /* Not PAE */
12517
12518 page_pde_offset = (__PAGE_OFFSET >> 20);
12519@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
12520 movl %eax, pa(max_pfn_mapped)
12521
12522 /* Do early initialization of the fixmap area */
12523- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
12524- movl %eax,pa(initial_page_table+0xffc)
12525+#ifdef CONFIG_COMPAT_VDSO
12526+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
12527+#else
12528+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
12529+#endif
12530 #endif
12531
12532 #ifdef CONFIG_PARAVIRT
12533@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
12534 cmpl $num_subarch_entries, %eax
12535 jae bad_subarch
12536
12537- movl pa(subarch_entries)(,%eax,4), %eax
12538- subl $__PAGE_OFFSET, %eax
12539- jmp *%eax
12540+ jmp *pa(subarch_entries)(,%eax,4)
12541
12542 bad_subarch:
12543 WEAK(lguest_entry)
12544@@ -255,10 +325,10 @@ WEAK(xen_entry)
12545 __INITDATA
12546
12547 subarch_entries:
12548- .long default_entry /* normal x86/PC */
12549- .long lguest_entry /* lguest hypervisor */
12550- .long xen_entry /* Xen hypervisor */
12551- .long default_entry /* Moorestown MID */
12552+ .long ta(default_entry) /* normal x86/PC */
12553+ .long ta(lguest_entry) /* lguest hypervisor */
12554+ .long ta(xen_entry) /* Xen hypervisor */
12555+ .long ta(default_entry) /* Moorestown MID */
12556 num_subarch_entries = (. - subarch_entries) / 4
12557 .previous
12558 #else
12559@@ -312,6 +382,7 @@ default_entry:
12560 orl %edx,%eax
12561 movl %eax,%cr4
12562
12563+#ifdef CONFIG_X86_PAE
12564 testb $X86_CR4_PAE, %al # check if PAE is enabled
12565 jz 6f
12566
12567@@ -340,6 +411,9 @@ default_entry:
12568 /* Make changes effective */
12569 wrmsr
12570
12571+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
12572+#endif
12573+
12574 6:
12575
12576 /*
12577@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
12578 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
12579 movl %eax,%ss # after changing gdt.
12580
12581- movl $(__USER_DS),%eax # DS/ES contains default USER segment
12582+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
12583 movl %eax,%ds
12584 movl %eax,%es
12585
12586@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
12587 */
12588 cmpb $0,ready
12589 jne 1f
12590- movl $gdt_page,%eax
12591+ movl $cpu_gdt_table,%eax
12592 movl $stack_canary,%ecx
12593+#ifdef CONFIG_SMP
12594+ addl $__per_cpu_load,%ecx
12595+#endif
12596 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
12597 shrl $16, %ecx
12598 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
12599 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
12600 1:
12601-#endif
12602 movl $(__KERNEL_STACK_CANARY),%eax
12603+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12604+ movl $(__USER_DS),%eax
12605+#else
12606+ xorl %eax,%eax
12607+#endif
12608 movl %eax,%gs
12609
12610 xorl %eax,%eax # Clear LDT
12611@@ -558,22 +639,22 @@ early_page_fault:
12612 jmp early_fault
12613
12614 early_fault:
12615- cld
12616 #ifdef CONFIG_PRINTK
12617+ cmpl $1,%ss:early_recursion_flag
12618+ je hlt_loop
12619+ incl %ss:early_recursion_flag
12620+ cld
12621 pusha
12622 movl $(__KERNEL_DS),%eax
12623 movl %eax,%ds
12624 movl %eax,%es
12625- cmpl $2,early_recursion_flag
12626- je hlt_loop
12627- incl early_recursion_flag
12628 movl %cr2,%eax
12629 pushl %eax
12630 pushl %edx /* trapno */
12631 pushl $fault_msg
12632 call printk
12633+; call dump_stack
12634 #endif
12635- call dump_stack
12636 hlt_loop:
12637 hlt
12638 jmp hlt_loop
12639@@ -581,8 +662,11 @@ hlt_loop:
12640 /* This is the default interrupt "handler" :-) */
12641 ALIGN
12642 ignore_int:
12643- cld
12644 #ifdef CONFIG_PRINTK
12645+ cmpl $2,%ss:early_recursion_flag
12646+ je hlt_loop
12647+ incl %ss:early_recursion_flag
12648+ cld
12649 pushl %eax
12650 pushl %ecx
12651 pushl %edx
12652@@ -591,9 +675,6 @@ ignore_int:
12653 movl $(__KERNEL_DS),%eax
12654 movl %eax,%ds
12655 movl %eax,%es
12656- cmpl $2,early_recursion_flag
12657- je hlt_loop
12658- incl early_recursion_flag
12659 pushl 16(%esp)
12660 pushl 24(%esp)
12661 pushl 32(%esp)
12662@@ -622,29 +703,43 @@ ENTRY(initial_code)
12663 /*
12664 * BSS section
12665 */
12666-__PAGE_ALIGNED_BSS
12667- .align PAGE_SIZE
12668 #ifdef CONFIG_X86_PAE
12669+.section .initial_pg_pmd,"a",@progbits
12670 initial_pg_pmd:
12671 .fill 1024*KPMDS,4,0
12672 #else
12673+.section .initial_page_table,"a",@progbits
12674 ENTRY(initial_page_table)
12675 .fill 1024,4,0
12676 #endif
12677+.section .initial_pg_fixmap,"a",@progbits
12678 initial_pg_fixmap:
12679 .fill 1024,4,0
12680+.section .empty_zero_page,"a",@progbits
12681 ENTRY(empty_zero_page)
12682 .fill 4096,1,0
12683+.section .swapper_pg_dir,"a",@progbits
12684 ENTRY(swapper_pg_dir)
12685+#ifdef CONFIG_X86_PAE
12686+ .fill 4,8,0
12687+#else
12688 .fill 1024,4,0
12689+#endif
12690+
12691+/*
12692+ * The IDT has to be page-aligned to simplify the Pentium
12693+ * F0 0F bug workaround.. We have a special link segment
12694+ * for this.
12695+ */
12696+.section .idt,"a",@progbits
12697+ENTRY(idt_table)
12698+ .fill 256,8,0
12699
12700 /*
12701 * This starts the data section.
12702 */
12703 #ifdef CONFIG_X86_PAE
12704-__PAGE_ALIGNED_DATA
12705- /* Page-aligned for the benefit of paravirt? */
12706- .align PAGE_SIZE
12707+.section .initial_page_table,"a",@progbits
12708 ENTRY(initial_page_table)
12709 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
12710 # if KPMDS == 3
12711@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
12712 # error "Kernel PMDs should be 1, 2 or 3"
12713 # endif
12714 .align PAGE_SIZE /* needs to be page-sized too */
12715+
12716+#ifdef CONFIG_PAX_PER_CPU_PGD
12717+ENTRY(cpu_pgd)
12718+ .rept NR_CPUS
12719+ .fill 4,8,0
12720+ .endr
12721+#endif
12722+
12723 #endif
12724
12725 .data
12726 .balign 4
12727 ENTRY(stack_start)
12728- .long init_thread_union+THREAD_SIZE
12729+ .long init_thread_union+THREAD_SIZE-8
12730+
12731+ready: .byte 0
12732
12733+.section .rodata,"a",@progbits
12734 early_recursion_flag:
12735 .long 0
12736
12737-ready: .byte 0
12738-
12739 int_msg:
12740 .asciz "Unknown interrupt or fault at: %p %p %p\n"
12741
12742@@ -707,7 +811,7 @@ fault_msg:
12743 .word 0 # 32 bit align gdt_desc.address
12744 boot_gdt_descr:
12745 .word __BOOT_DS+7
12746- .long boot_gdt - __PAGE_OFFSET
12747+ .long pa(boot_gdt)
12748
12749 .word 0 # 32-bit align idt_desc.address
12750 idt_descr:
12751@@ -718,7 +822,7 @@ idt_descr:
12752 .word 0 # 32 bit align gdt_desc.address
12753 ENTRY(early_gdt_descr)
12754 .word GDT_ENTRIES*8-1
12755- .long gdt_page /* Overwritten for secondary CPUs */
12756+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
12757
12758 /*
12759 * The boot_gdt must mirror the equivalent in setup.S and is
12760@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
12761 .align L1_CACHE_BYTES
12762 ENTRY(boot_gdt)
12763 .fill GDT_ENTRY_BOOT_CS,8,0
12764- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
12765- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
12766+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
12767+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
12768+
12769+ .align PAGE_SIZE_asm
12770+ENTRY(cpu_gdt_table)
12771+ .rept NR_CPUS
12772+ .quad 0x0000000000000000 /* NULL descriptor */
12773+ .quad 0x0000000000000000 /* 0x0b reserved */
12774+ .quad 0x0000000000000000 /* 0x13 reserved */
12775+ .quad 0x0000000000000000 /* 0x1b reserved */
12776+
12777+#ifdef CONFIG_PAX_KERNEXEC
12778+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
12779+#else
12780+ .quad 0x0000000000000000 /* 0x20 unused */
12781+#endif
12782+
12783+ .quad 0x0000000000000000 /* 0x28 unused */
12784+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
12785+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
12786+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
12787+ .quad 0x0000000000000000 /* 0x4b reserved */
12788+ .quad 0x0000000000000000 /* 0x53 reserved */
12789+ .quad 0x0000000000000000 /* 0x5b reserved */
12790+
12791+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
12792+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
12793+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
12794+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
12795+
12796+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
12797+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
12798+
12799+ /*
12800+ * Segments used for calling PnP BIOS have byte granularity.
12801+ * The code segments and data segments have fixed 64k limits,
12802+ * the transfer segment sizes are set at run time.
12803+ */
12804+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
12805+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
12806+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
12807+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
12808+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
12809+
12810+ /*
12811+ * The APM segments have byte granularity and their bases
12812+ * are set at run time. All have 64k limits.
12813+ */
12814+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
12815+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
12816+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
12817+
12818+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
12819+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
12820+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
12821+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
12822+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
12823+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
12824+
12825+ /* Be sure this is zeroed to avoid false validations in Xen */
12826+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
12827+ .endr
12828diff -urNp linux-3.0.4/arch/x86/kernel/head_64.S linux-3.0.4/arch/x86/kernel/head_64.S
12829--- linux-3.0.4/arch/x86/kernel/head_64.S 2011-07-21 22:17:23.000000000 -0400
12830+++ linux-3.0.4/arch/x86/kernel/head_64.S 2011-08-23 21:47:55.000000000 -0400
12831@@ -19,6 +19,7 @@
12832 #include <asm/cache.h>
12833 #include <asm/processor-flags.h>
12834 #include <asm/percpu.h>
12835+#include <asm/cpufeature.h>
12836
12837 #ifdef CONFIG_PARAVIRT
12838 #include <asm/asm-offsets.h>
12839@@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
12840 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
12841 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
12842 L3_START_KERNEL = pud_index(__START_KERNEL_map)
12843+L4_VMALLOC_START = pgd_index(VMALLOC_START)
12844+L3_VMALLOC_START = pud_index(VMALLOC_START)
12845+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
12846+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
12847
12848 .text
12849 __HEAD
12850@@ -85,35 +90,22 @@ startup_64:
12851 */
12852 addq %rbp, init_level4_pgt + 0(%rip)
12853 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
12854+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
12855+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
12856 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
12857
12858 addq %rbp, level3_ident_pgt + 0(%rip)
12859+#ifndef CONFIG_XEN
12860+ addq %rbp, level3_ident_pgt + 8(%rip)
12861+#endif
12862
12863- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
12864- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
12865+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
12866
12867- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
12868+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
12869+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
12870
12871- /* Add an Identity mapping if I am above 1G */
12872- leaq _text(%rip), %rdi
12873- andq $PMD_PAGE_MASK, %rdi
12874-
12875- movq %rdi, %rax
12876- shrq $PUD_SHIFT, %rax
12877- andq $(PTRS_PER_PUD - 1), %rax
12878- jz ident_complete
12879-
12880- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
12881- leaq level3_ident_pgt(%rip), %rbx
12882- movq %rdx, 0(%rbx, %rax, 8)
12883-
12884- movq %rdi, %rax
12885- shrq $PMD_SHIFT, %rax
12886- andq $(PTRS_PER_PMD - 1), %rax
12887- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
12888- leaq level2_spare_pgt(%rip), %rbx
12889- movq %rdx, 0(%rbx, %rax, 8)
12890-ident_complete:
12891+ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
12892+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
12893
12894 /*
12895 * Fixup the kernel text+data virtual addresses. Note that
12896@@ -160,8 +152,8 @@ ENTRY(secondary_startup_64)
12897 * after the boot processor executes this code.
12898 */
12899
12900- /* Enable PAE mode and PGE */
12901- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
12902+ /* Enable PAE mode and PSE/PGE */
12903+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
12904 movq %rax, %cr4
12905
12906 /* Setup early boot stage 4 level pagetables. */
12907@@ -183,9 +175,14 @@ ENTRY(secondary_startup_64)
12908 movl $MSR_EFER, %ecx
12909 rdmsr
12910 btsl $_EFER_SCE, %eax /* Enable System Call */
12911- btl $20,%edi /* No Execute supported? */
12912+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
12913 jnc 1f
12914 btsl $_EFER_NX, %eax
12915+ leaq init_level4_pgt(%rip), %rdi
12916+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
12917+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
12918+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
12919+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
12920 1: wrmsr /* Make changes effective */
12921
12922 /* Setup cr0 */
12923@@ -269,7 +266,7 @@ ENTRY(secondary_startup_64)
12924 bad_address:
12925 jmp bad_address
12926
12927- .section ".init.text","ax"
12928+ __INIT
12929 #ifdef CONFIG_EARLY_PRINTK
12930 .globl early_idt_handlers
12931 early_idt_handlers:
12932@@ -314,18 +311,23 @@ ENTRY(early_idt_handler)
12933 #endif /* EARLY_PRINTK */
12934 1: hlt
12935 jmp 1b
12936+ .previous
12937
12938 #ifdef CONFIG_EARLY_PRINTK
12939+ __INITDATA
12940 early_recursion_flag:
12941 .long 0
12942+ .previous
12943
12944+ .section .rodata,"a",@progbits
12945 early_idt_msg:
12946 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
12947 early_idt_ripmsg:
12948 .asciz "RIP %s\n"
12949-#endif /* CONFIG_EARLY_PRINTK */
12950 .previous
12951+#endif /* CONFIG_EARLY_PRINTK */
12952
12953+ .section .rodata,"a",@progbits
12954 #define NEXT_PAGE(name) \
12955 .balign PAGE_SIZE; \
12956 ENTRY(name)
12957@@ -338,7 +340,6 @@ ENTRY(name)
12958 i = i + 1 ; \
12959 .endr
12960
12961- .data
12962 /*
12963 * This default setting generates an ident mapping at address 0x100000
12964 * and a mapping for the kernel that precisely maps virtual address
12965@@ -349,13 +350,36 @@ NEXT_PAGE(init_level4_pgt)
12966 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12967 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
12968 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12969+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
12970+ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
12971+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
12972+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
12973 .org init_level4_pgt + L4_START_KERNEL*8, 0
12974 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
12975 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
12976
12977+#ifdef CONFIG_PAX_PER_CPU_PGD
12978+NEXT_PAGE(cpu_pgd)
12979+ .rept NR_CPUS
12980+ .fill 512,8,0
12981+ .endr
12982+#endif
12983+
12984 NEXT_PAGE(level3_ident_pgt)
12985 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12986+#ifdef CONFIG_XEN
12987 .fill 511,8,0
12988+#else
12989+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
12990+ .fill 510,8,0
12991+#endif
12992+
12993+NEXT_PAGE(level3_vmalloc_pgt)
12994+ .fill 512,8,0
12995+
12996+NEXT_PAGE(level3_vmemmap_pgt)
12997+ .fill L3_VMEMMAP_START,8,0
12998+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
12999
13000 NEXT_PAGE(level3_kernel_pgt)
13001 .fill L3_START_KERNEL,8,0
13002@@ -363,20 +387,23 @@ NEXT_PAGE(level3_kernel_pgt)
13003 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
13004 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
13005
13006+NEXT_PAGE(level2_vmemmap_pgt)
13007+ .fill 512,8,0
13008+
13009 NEXT_PAGE(level2_fixmap_pgt)
13010- .fill 506,8,0
13011- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
13012- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
13013- .fill 5,8,0
13014+ .fill 507,8,0
13015+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
13016+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
13017+ .fill 4,8,0
13018
13019-NEXT_PAGE(level1_fixmap_pgt)
13020+NEXT_PAGE(level1_vsyscall_pgt)
13021 .fill 512,8,0
13022
13023-NEXT_PAGE(level2_ident_pgt)
13024- /* Since I easily can, map the first 1G.
13025+ /* Since I easily can, map the first 2G.
13026 * Don't set NX because code runs from these pages.
13027 */
13028- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
13029+NEXT_PAGE(level2_ident_pgt)
13030+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
13031
13032 NEXT_PAGE(level2_kernel_pgt)
13033 /*
13034@@ -389,33 +416,55 @@ NEXT_PAGE(level2_kernel_pgt)
13035 * If you want to increase this then increase MODULES_VADDR
13036 * too.)
13037 */
13038- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
13039- KERNEL_IMAGE_SIZE/PMD_SIZE)
13040-
13041-NEXT_PAGE(level2_spare_pgt)
13042- .fill 512, 8, 0
13043+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
13044
13045 #undef PMDS
13046 #undef NEXT_PAGE
13047
13048- .data
13049+ .align PAGE_SIZE
13050+ENTRY(cpu_gdt_table)
13051+ .rept NR_CPUS
13052+ .quad 0x0000000000000000 /* NULL descriptor */
13053+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
13054+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
13055+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
13056+ .quad 0x00cffb000000ffff /* __USER32_CS */
13057+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
13058+ .quad 0x00affb000000ffff /* __USER_CS */
13059+
13060+#ifdef CONFIG_PAX_KERNEXEC
13061+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
13062+#else
13063+ .quad 0x0 /* unused */
13064+#endif
13065+
13066+ .quad 0,0 /* TSS */
13067+ .quad 0,0 /* LDT */
13068+ .quad 0,0,0 /* three TLS descriptors */
13069+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
13070+ /* asm/segment.h:GDT_ENTRIES must match this */
13071+
13072+ /* zero the remaining page */
13073+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
13074+ .endr
13075+
13076 .align 16
13077 .globl early_gdt_descr
13078 early_gdt_descr:
13079 .word GDT_ENTRIES*8-1
13080 early_gdt_descr_base:
13081- .quad INIT_PER_CPU_VAR(gdt_page)
13082+ .quad cpu_gdt_table
13083
13084 ENTRY(phys_base)
13085 /* This must match the first entry in level2_kernel_pgt */
13086 .quad 0x0000000000000000
13087
13088 #include "../../x86/xen/xen-head.S"
13089-
13090- .section .bss, "aw", @nobits
13091+
13092+ .section .rodata,"a",@progbits
13093 .align L1_CACHE_BYTES
13094 ENTRY(idt_table)
13095- .skip IDT_ENTRIES * 16
13096+ .fill 512,8,0
13097
13098 __PAGE_ALIGNED_BSS
13099 .align PAGE_SIZE
13100diff -urNp linux-3.0.4/arch/x86/kernel/i386_ksyms_32.c linux-3.0.4/arch/x86/kernel/i386_ksyms_32.c
13101--- linux-3.0.4/arch/x86/kernel/i386_ksyms_32.c 2011-07-21 22:17:23.000000000 -0400
13102+++ linux-3.0.4/arch/x86/kernel/i386_ksyms_32.c 2011-08-23 21:47:55.000000000 -0400
13103@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
13104 EXPORT_SYMBOL(cmpxchg8b_emu);
13105 #endif
13106
13107+EXPORT_SYMBOL_GPL(cpu_gdt_table);
13108+
13109 /* Networking helper routines. */
13110 EXPORT_SYMBOL(csum_partial_copy_generic);
13111+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
13112+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
13113
13114 EXPORT_SYMBOL(__get_user_1);
13115 EXPORT_SYMBOL(__get_user_2);
13116@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
13117
13118 EXPORT_SYMBOL(csum_partial);
13119 EXPORT_SYMBOL(empty_zero_page);
13120+
13121+#ifdef CONFIG_PAX_KERNEXEC
13122+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
13123+#endif
13124diff -urNp linux-3.0.4/arch/x86/kernel/i8259.c linux-3.0.4/arch/x86/kernel/i8259.c
13125--- linux-3.0.4/arch/x86/kernel/i8259.c 2011-07-21 22:17:23.000000000 -0400
13126+++ linux-3.0.4/arch/x86/kernel/i8259.c 2011-08-23 21:47:55.000000000 -0400
13127@@ -210,7 +210,7 @@ spurious_8259A_irq:
13128 "spurious 8259A interrupt: IRQ%d.\n", irq);
13129 spurious_irq_mask |= irqmask;
13130 }
13131- atomic_inc(&irq_err_count);
13132+ atomic_inc_unchecked(&irq_err_count);
13133 /*
13134 * Theoretically we do not have to handle this IRQ,
13135 * but in Linux this does not cause problems and is
13136diff -urNp linux-3.0.4/arch/x86/kernel/init_task.c linux-3.0.4/arch/x86/kernel/init_task.c
13137--- linux-3.0.4/arch/x86/kernel/init_task.c 2011-07-21 22:17:23.000000000 -0400
13138+++ linux-3.0.4/arch/x86/kernel/init_task.c 2011-08-23 21:47:55.000000000 -0400
13139@@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
13140 * way process stacks are handled. This is done by having a special
13141 * "init_task" linker map entry..
13142 */
13143-union thread_union init_thread_union __init_task_data =
13144- { INIT_THREAD_INFO(init_task) };
13145+union thread_union init_thread_union __init_task_data;
13146
13147 /*
13148 * Initial task structure.
13149@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
13150 * section. Since TSS's are completely CPU-local, we want them
13151 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
13152 */
13153-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
13154-
13155+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
13156+EXPORT_SYMBOL(init_tss);
13157diff -urNp linux-3.0.4/arch/x86/kernel/ioport.c linux-3.0.4/arch/x86/kernel/ioport.c
13158--- linux-3.0.4/arch/x86/kernel/ioport.c 2011-07-21 22:17:23.000000000 -0400
13159+++ linux-3.0.4/arch/x86/kernel/ioport.c 2011-08-23 21:48:14.000000000 -0400
13160@@ -6,6 +6,7 @@
13161 #include <linux/sched.h>
13162 #include <linux/kernel.h>
13163 #include <linux/capability.h>
13164+#include <linux/security.h>
13165 #include <linux/errno.h>
13166 #include <linux/types.h>
13167 #include <linux/ioport.h>
13168@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long
13169
13170 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
13171 return -EINVAL;
13172+#ifdef CONFIG_GRKERNSEC_IO
13173+ if (turn_on && grsec_disable_privio) {
13174+ gr_handle_ioperm();
13175+ return -EPERM;
13176+ }
13177+#endif
13178 if (turn_on && !capable(CAP_SYS_RAWIO))
13179 return -EPERM;
13180
13181@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long
13182 * because the ->io_bitmap_max value must match the bitmap
13183 * contents:
13184 */
13185- tss = &per_cpu(init_tss, get_cpu());
13186+ tss = init_tss + get_cpu();
13187
13188 if (turn_on)
13189 bitmap_clear(t->io_bitmap_ptr, from, num);
13190@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct
13191 return -EINVAL;
13192 /* Trying to gain more privileges? */
13193 if (level > old) {
13194+#ifdef CONFIG_GRKERNSEC_IO
13195+ if (grsec_disable_privio) {
13196+ gr_handle_iopl();
13197+ return -EPERM;
13198+ }
13199+#endif
13200 if (!capable(CAP_SYS_RAWIO))
13201 return -EPERM;
13202 }
13203diff -urNp linux-3.0.4/arch/x86/kernel/irq_32.c linux-3.0.4/arch/x86/kernel/irq_32.c
13204--- linux-3.0.4/arch/x86/kernel/irq_32.c 2011-07-21 22:17:23.000000000 -0400
13205+++ linux-3.0.4/arch/x86/kernel/irq_32.c 2011-08-23 21:47:55.000000000 -0400
13206@@ -36,7 +36,7 @@ static int check_stack_overflow(void)
13207 __asm__ __volatile__("andl %%esp,%0" :
13208 "=r" (sp) : "0" (THREAD_SIZE - 1));
13209
13210- return sp < (sizeof(struct thread_info) + STACK_WARN);
13211+ return sp < STACK_WARN;
13212 }
13213
13214 static void print_stack_overflow(void)
13215@@ -54,8 +54,8 @@ static inline void print_stack_overflow(
13216 * per-CPU IRQ handling contexts (thread information and stack)
13217 */
13218 union irq_ctx {
13219- struct thread_info tinfo;
13220- u32 stack[THREAD_SIZE/sizeof(u32)];
13221+ unsigned long previous_esp;
13222+ u32 stack[THREAD_SIZE/sizeof(u32)];
13223 } __attribute__((aligned(THREAD_SIZE)));
13224
13225 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
13226@@ -75,10 +75,9 @@ static void call_on_stack(void *func, vo
13227 static inline int
13228 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
13229 {
13230- union irq_ctx *curctx, *irqctx;
13231+ union irq_ctx *irqctx;
13232 u32 *isp, arg1, arg2;
13233
13234- curctx = (union irq_ctx *) current_thread_info();
13235 irqctx = __this_cpu_read(hardirq_ctx);
13236
13237 /*
13238@@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struc
13239 * handler) we can't do that and just have to keep using the
13240 * current stack (which is the irq stack already after all)
13241 */
13242- if (unlikely(curctx == irqctx))
13243+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
13244 return 0;
13245
13246 /* build the stack frame on the IRQ stack */
13247- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
13248- irqctx->tinfo.task = curctx->tinfo.task;
13249- irqctx->tinfo.previous_esp = current_stack_pointer;
13250+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
13251+ irqctx->previous_esp = current_stack_pointer;
13252
13253- /*
13254- * Copy the softirq bits in preempt_count so that the
13255- * softirq checks work in the hardirq context.
13256- */
13257- irqctx->tinfo.preempt_count =
13258- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
13259- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
13260+#ifdef CONFIG_PAX_MEMORY_UDEREF
13261+ __set_fs(MAKE_MM_SEG(0));
13262+#endif
13263
13264 if (unlikely(overflow))
13265 call_on_stack(print_stack_overflow, isp);
13266@@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struc
13267 : "0" (irq), "1" (desc), "2" (isp),
13268 "D" (desc->handle_irq)
13269 : "memory", "cc", "ecx");
13270+
13271+#ifdef CONFIG_PAX_MEMORY_UDEREF
13272+ __set_fs(current_thread_info()->addr_limit);
13273+#endif
13274+
13275 return 1;
13276 }
13277
13278@@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struc
13279 */
13280 void __cpuinit irq_ctx_init(int cpu)
13281 {
13282- union irq_ctx *irqctx;
13283-
13284 if (per_cpu(hardirq_ctx, cpu))
13285 return;
13286
13287- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
13288- THREAD_FLAGS,
13289- THREAD_ORDER));
13290- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
13291- irqctx->tinfo.cpu = cpu;
13292- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
13293- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
13294-
13295- per_cpu(hardirq_ctx, cpu) = irqctx;
13296-
13297- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
13298- THREAD_FLAGS,
13299- THREAD_ORDER));
13300- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
13301- irqctx->tinfo.cpu = cpu;
13302- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
13303-
13304- per_cpu(softirq_ctx, cpu) = irqctx;
13305+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
13306+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
13307
13308 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
13309 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
13310@@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
13311 asmlinkage void do_softirq(void)
13312 {
13313 unsigned long flags;
13314- struct thread_info *curctx;
13315 union irq_ctx *irqctx;
13316 u32 *isp;
13317
13318@@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
13319 local_irq_save(flags);
13320
13321 if (local_softirq_pending()) {
13322- curctx = current_thread_info();
13323 irqctx = __this_cpu_read(softirq_ctx);
13324- irqctx->tinfo.task = curctx->task;
13325- irqctx->tinfo.previous_esp = current_stack_pointer;
13326+ irqctx->previous_esp = current_stack_pointer;
13327
13328 /* build the stack frame on the softirq stack */
13329- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
13330+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
13331+
13332+#ifdef CONFIG_PAX_MEMORY_UDEREF
13333+ __set_fs(MAKE_MM_SEG(0));
13334+#endif
13335
13336 call_on_stack(__do_softirq, isp);
13337+
13338+#ifdef CONFIG_PAX_MEMORY_UDEREF
13339+ __set_fs(current_thread_info()->addr_limit);
13340+#endif
13341+
13342 /*
13343 * Shouldn't happen, we returned above if in_interrupt():
13344 */
13345diff -urNp linux-3.0.4/arch/x86/kernel/irq.c linux-3.0.4/arch/x86/kernel/irq.c
13346--- linux-3.0.4/arch/x86/kernel/irq.c 2011-07-21 22:17:23.000000000 -0400
13347+++ linux-3.0.4/arch/x86/kernel/irq.c 2011-08-23 21:47:55.000000000 -0400
13348@@ -17,7 +17,7 @@
13349 #include <asm/mce.h>
13350 #include <asm/hw_irq.h>
13351
13352-atomic_t irq_err_count;
13353+atomic_unchecked_t irq_err_count;
13354
13355 /* Function pointer for generic interrupt vector handling */
13356 void (*x86_platform_ipi_callback)(void) = NULL;
13357@@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file
13358 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
13359 seq_printf(p, " Machine check polls\n");
13360 #endif
13361- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
13362+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
13363 #if defined(CONFIG_X86_IO_APIC)
13364- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
13365+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
13366 #endif
13367 return 0;
13368 }
13369@@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
13370
13371 u64 arch_irq_stat(void)
13372 {
13373- u64 sum = atomic_read(&irq_err_count);
13374+ u64 sum = atomic_read_unchecked(&irq_err_count);
13375
13376 #ifdef CONFIG_X86_IO_APIC
13377- sum += atomic_read(&irq_mis_count);
13378+ sum += atomic_read_unchecked(&irq_mis_count);
13379 #endif
13380 return sum;
13381 }
13382diff -urNp linux-3.0.4/arch/x86/kernel/kgdb.c linux-3.0.4/arch/x86/kernel/kgdb.c
13383--- linux-3.0.4/arch/x86/kernel/kgdb.c 2011-07-21 22:17:23.000000000 -0400
13384+++ linux-3.0.4/arch/x86/kernel/kgdb.c 2011-08-23 21:47:55.000000000 -0400
13385@@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem,
13386 #ifdef CONFIG_X86_32
13387 switch (regno) {
13388 case GDB_SS:
13389- if (!user_mode_vm(regs))
13390+ if (!user_mode(regs))
13391 *(unsigned long *)mem = __KERNEL_DS;
13392 break;
13393 case GDB_SP:
13394- if (!user_mode_vm(regs))
13395+ if (!user_mode(regs))
13396 *(unsigned long *)mem = kernel_stack_pointer(regs);
13397 break;
13398 case GDB_GS:
13399@@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vec
13400 case 'k':
13401 /* clear the trace bit */
13402 linux_regs->flags &= ~X86_EFLAGS_TF;
13403- atomic_set(&kgdb_cpu_doing_single_step, -1);
13404+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
13405
13406 /* set the trace bit if we're stepping */
13407 if (remcomInBuffer[0] == 's') {
13408 linux_regs->flags |= X86_EFLAGS_TF;
13409- atomic_set(&kgdb_cpu_doing_single_step,
13410+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
13411 raw_smp_processor_id());
13412 }
13413
13414@@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args
13415 return NOTIFY_DONE;
13416
13417 case DIE_DEBUG:
13418- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
13419+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
13420 if (user_mode(regs))
13421 return single_step_cont(regs, args);
13422 break;
13423diff -urNp linux-3.0.4/arch/x86/kernel/kprobes.c linux-3.0.4/arch/x86/kernel/kprobes.c
13424--- linux-3.0.4/arch/x86/kernel/kprobes.c 2011-07-21 22:17:23.000000000 -0400
13425+++ linux-3.0.4/arch/x86/kernel/kprobes.c 2011-08-23 21:47:55.000000000 -0400
13426@@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
13427 } __attribute__((packed)) *insn;
13428
13429 insn = (struct __arch_relative_insn *)from;
13430+
13431+ pax_open_kernel();
13432 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
13433 insn->op = op;
13434+ pax_close_kernel();
13435 }
13436
13437 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
13438@@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
13439 kprobe_opcode_t opcode;
13440 kprobe_opcode_t *orig_opcodes = opcodes;
13441
13442- if (search_exception_tables((unsigned long)opcodes))
13443+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
13444 return 0; /* Page fault may occur on this address. */
13445
13446 retry:
13447@@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
13448 }
13449 }
13450 insn_get_length(&insn);
13451+ pax_open_kernel();
13452 memcpy(dest, insn.kaddr, insn.length);
13453+ pax_close_kernel();
13454
13455 #ifdef CONFIG_X86_64
13456 if (insn_rip_relative(&insn)) {
13457@@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
13458 (u8 *) dest;
13459 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
13460 disp = (u8 *) dest + insn_offset_displacement(&insn);
13461+ pax_open_kernel();
13462 *(s32 *) disp = (s32) newdisp;
13463+ pax_close_kernel();
13464 }
13465 #endif
13466 return insn.length;
13467@@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
13468 */
13469 __copy_instruction(p->ainsn.insn, p->addr, 0);
13470
13471- if (can_boost(p->addr))
13472+ if (can_boost(ktla_ktva(p->addr)))
13473 p->ainsn.boostable = 0;
13474 else
13475 p->ainsn.boostable = -1;
13476
13477- p->opcode = *p->addr;
13478+ p->opcode = *(ktla_ktva(p->addr));
13479 }
13480
13481 int __kprobes arch_prepare_kprobe(struct kprobe *p)
13482@@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
13483 * nor set current_kprobe, because it doesn't use single
13484 * stepping.
13485 */
13486- regs->ip = (unsigned long)p->ainsn.insn;
13487+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
13488 preempt_enable_no_resched();
13489 return;
13490 }
13491@@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
13492 if (p->opcode == BREAKPOINT_INSTRUCTION)
13493 regs->ip = (unsigned long)p->addr;
13494 else
13495- regs->ip = (unsigned long)p->ainsn.insn;
13496+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
13497 }
13498
13499 /*
13500@@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
13501 setup_singlestep(p, regs, kcb, 0);
13502 return 1;
13503 }
13504- } else if (*addr != BREAKPOINT_INSTRUCTION) {
13505+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
13506 /*
13507 * The breakpoint instruction was removed right
13508 * after we hit it. Another cpu has removed
13509@@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
13510 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
13511 {
13512 unsigned long *tos = stack_addr(regs);
13513- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
13514+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
13515 unsigned long orig_ip = (unsigned long)p->addr;
13516 kprobe_opcode_t *insn = p->ainsn.insn;
13517
13518@@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
13519 struct die_args *args = data;
13520 int ret = NOTIFY_DONE;
13521
13522- if (args->regs && user_mode_vm(args->regs))
13523+ if (args->regs && user_mode(args->regs))
13524 return ret;
13525
13526 switch (val) {
13527@@ -1381,7 +1388,7 @@ int __kprobes arch_prepare_optimized_kpr
13528 * Verify if the address gap is in 2GB range, because this uses
13529 * a relative jump.
13530 */
13531- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
13532+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
13533 if (abs(rel) > 0x7fffffff)
13534 return -ERANGE;
13535
13536@@ -1402,11 +1409,11 @@ int __kprobes arch_prepare_optimized_kpr
13537 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
13538
13539 /* Set probe function call */
13540- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
13541+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
13542
13543 /* Set returning jmp instruction at the tail of out-of-line buffer */
13544 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
13545- (u8 *)op->kp.addr + op->optinsn.size);
13546+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
13547
13548 flush_icache_range((unsigned long) buf,
13549 (unsigned long) buf + TMPL_END_IDX +
13550@@ -1428,7 +1435,7 @@ static void __kprobes setup_optimize_kpr
13551 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
13552
13553 /* Backup instructions which will be replaced by jump address */
13554- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
13555+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
13556 RELATIVE_ADDR_SIZE);
13557
13558 insn_buf[0] = RELATIVEJUMP_OPCODE;
13559diff -urNp linux-3.0.4/arch/x86/kernel/kvm.c linux-3.0.4/arch/x86/kernel/kvm.c
13560--- linux-3.0.4/arch/x86/kernel/kvm.c 2011-07-21 22:17:23.000000000 -0400
13561+++ linux-3.0.4/arch/x86/kernel/kvm.c 2011-08-24 18:10:12.000000000 -0400
13562@@ -426,6 +426,7 @@ static void __init paravirt_ops_setup(vo
13563 pv_mmu_ops.set_pud = kvm_set_pud;
13564 #if PAGETABLE_LEVELS == 4
13565 pv_mmu_ops.set_pgd = kvm_set_pgd;
13566+ pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
13567 #endif
13568 #endif
13569 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
13570diff -urNp linux-3.0.4/arch/x86/kernel/ldt.c linux-3.0.4/arch/x86/kernel/ldt.c
13571--- linux-3.0.4/arch/x86/kernel/ldt.c 2011-07-21 22:17:23.000000000 -0400
13572+++ linux-3.0.4/arch/x86/kernel/ldt.c 2011-08-23 21:47:55.000000000 -0400
13573@@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
13574 if (reload) {
13575 #ifdef CONFIG_SMP
13576 preempt_disable();
13577- load_LDT(pc);
13578+ load_LDT_nolock(pc);
13579 if (!cpumask_equal(mm_cpumask(current->mm),
13580 cpumask_of(smp_processor_id())))
13581 smp_call_function(flush_ldt, current->mm, 1);
13582 preempt_enable();
13583 #else
13584- load_LDT(pc);
13585+ load_LDT_nolock(pc);
13586 #endif
13587 }
13588 if (oldsize) {
13589@@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
13590 return err;
13591
13592 for (i = 0; i < old->size; i++)
13593- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
13594+ write_ldt_entry(new->ldt, i, old->ldt + i);
13595 return 0;
13596 }
13597
13598@@ -116,6 +116,24 @@ int init_new_context(struct task_struct
13599 retval = copy_ldt(&mm->context, &old_mm->context);
13600 mutex_unlock(&old_mm->context.lock);
13601 }
13602+
13603+ if (tsk == current) {
13604+ mm->context.vdso = 0;
13605+
13606+#ifdef CONFIG_X86_32
13607+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13608+ mm->context.user_cs_base = 0UL;
13609+ mm->context.user_cs_limit = ~0UL;
13610+
13611+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13612+ cpus_clear(mm->context.cpu_user_cs_mask);
13613+#endif
13614+
13615+#endif
13616+#endif
13617+
13618+ }
13619+
13620 return retval;
13621 }
13622
13623@@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
13624 }
13625 }
13626
13627+#ifdef CONFIG_PAX_SEGMEXEC
13628+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
13629+ error = -EINVAL;
13630+ goto out_unlock;
13631+ }
13632+#endif
13633+
13634 fill_ldt(&ldt, &ldt_info);
13635 if (oldmode)
13636 ldt.avl = 0;
13637diff -urNp linux-3.0.4/arch/x86/kernel/machine_kexec_32.c linux-3.0.4/arch/x86/kernel/machine_kexec_32.c
13638--- linux-3.0.4/arch/x86/kernel/machine_kexec_32.c 2011-07-21 22:17:23.000000000 -0400
13639+++ linux-3.0.4/arch/x86/kernel/machine_kexec_32.c 2011-08-23 21:47:55.000000000 -0400
13640@@ -27,7 +27,7 @@
13641 #include <asm/cacheflush.h>
13642 #include <asm/debugreg.h>
13643
13644-static void set_idt(void *newidt, __u16 limit)
13645+static void set_idt(struct desc_struct *newidt, __u16 limit)
13646 {
13647 struct desc_ptr curidt;
13648
13649@@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
13650 }
13651
13652
13653-static void set_gdt(void *newgdt, __u16 limit)
13654+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
13655 {
13656 struct desc_ptr curgdt;
13657
13658@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
13659 }
13660
13661 control_page = page_address(image->control_code_page);
13662- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
13663+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
13664
13665 relocate_kernel_ptr = control_page;
13666 page_list[PA_CONTROL_PAGE] = __pa(control_page);
13667diff -urNp linux-3.0.4/arch/x86/kernel/microcode_intel.c linux-3.0.4/arch/x86/kernel/microcode_intel.c
13668--- linux-3.0.4/arch/x86/kernel/microcode_intel.c 2011-07-21 22:17:23.000000000 -0400
13669+++ linux-3.0.4/arch/x86/kernel/microcode_intel.c 2011-08-23 21:47:55.000000000 -0400
13670@@ -440,13 +440,13 @@ static enum ucode_state request_microcod
13671
13672 static int get_ucode_user(void *to, const void *from, size_t n)
13673 {
13674- return copy_from_user(to, from, n);
13675+ return copy_from_user(to, (__force const void __user *)from, n);
13676 }
13677
13678 static enum ucode_state
13679 request_microcode_user(int cpu, const void __user *buf, size_t size)
13680 {
13681- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
13682+ return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
13683 }
13684
13685 static void microcode_fini_cpu(int cpu)
13686diff -urNp linux-3.0.4/arch/x86/kernel/module.c linux-3.0.4/arch/x86/kernel/module.c
13687--- linux-3.0.4/arch/x86/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
13688+++ linux-3.0.4/arch/x86/kernel/module.c 2011-08-23 21:47:55.000000000 -0400
13689@@ -36,21 +36,66 @@
13690 #define DEBUGP(fmt...)
13691 #endif
13692
13693-void *module_alloc(unsigned long size)
13694+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
13695 {
13696 if (PAGE_ALIGN(size) > MODULES_LEN)
13697 return NULL;
13698 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
13699- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
13700+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
13701 -1, __builtin_return_address(0));
13702 }
13703
13704+void *module_alloc(unsigned long size)
13705+{
13706+
13707+#ifdef CONFIG_PAX_KERNEXEC
13708+ return __module_alloc(size, PAGE_KERNEL);
13709+#else
13710+ return __module_alloc(size, PAGE_KERNEL_EXEC);
13711+#endif
13712+
13713+}
13714+
13715 /* Free memory returned from module_alloc */
13716 void module_free(struct module *mod, void *module_region)
13717 {
13718 vfree(module_region);
13719 }
13720
13721+#ifdef CONFIG_PAX_KERNEXEC
13722+#ifdef CONFIG_X86_32
13723+void *module_alloc_exec(unsigned long size)
13724+{
13725+ struct vm_struct *area;
13726+
13727+ if (size == 0)
13728+ return NULL;
13729+
13730+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
13731+ return area ? area->addr : NULL;
13732+}
13733+EXPORT_SYMBOL(module_alloc_exec);
13734+
13735+void module_free_exec(struct module *mod, void *module_region)
13736+{
13737+ vunmap(module_region);
13738+}
13739+EXPORT_SYMBOL(module_free_exec);
13740+#else
13741+void module_free_exec(struct module *mod, void *module_region)
13742+{
13743+ module_free(mod, module_region);
13744+}
13745+EXPORT_SYMBOL(module_free_exec);
13746+
13747+void *module_alloc_exec(unsigned long size)
13748+{
13749+ return __module_alloc(size, PAGE_KERNEL_RX);
13750+}
13751+EXPORT_SYMBOL(module_alloc_exec);
13752+#endif
13753+#endif
13754+
13755 /* We don't need anything special. */
13756 int module_frob_arch_sections(Elf_Ehdr *hdr,
13757 Elf_Shdr *sechdrs,
13758@@ -70,14 +115,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
13759 unsigned int i;
13760 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
13761 Elf32_Sym *sym;
13762- uint32_t *location;
13763+ uint32_t *plocation, location;
13764
13765 DEBUGP("Applying relocate section %u to %u\n", relsec,
13766 sechdrs[relsec].sh_info);
13767 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
13768 /* This is where to make the change */
13769- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
13770- + rel[i].r_offset;
13771+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
13772+ location = (uint32_t)plocation;
13773+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
13774+ plocation = ktla_ktva((void *)plocation);
13775 /* This is the symbol it is referring to. Note that all
13776 undefined symbols have been resolved. */
13777 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
13778@@ -86,11 +133,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
13779 switch (ELF32_R_TYPE(rel[i].r_info)) {
13780 case R_386_32:
13781 /* We add the value into the location given */
13782- *location += sym->st_value;
13783+ pax_open_kernel();
13784+ *plocation += sym->st_value;
13785+ pax_close_kernel();
13786 break;
13787 case R_386_PC32:
13788 /* Add the value, subtract its postition */
13789- *location += sym->st_value - (uint32_t)location;
13790+ pax_open_kernel();
13791+ *plocation += sym->st_value - location;
13792+ pax_close_kernel();
13793 break;
13794 default:
13795 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
13796@@ -146,21 +197,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
13797 case R_X86_64_NONE:
13798 break;
13799 case R_X86_64_64:
13800+ pax_open_kernel();
13801 *(u64 *)loc = val;
13802+ pax_close_kernel();
13803 break;
13804 case R_X86_64_32:
13805+ pax_open_kernel();
13806 *(u32 *)loc = val;
13807+ pax_close_kernel();
13808 if (val != *(u32 *)loc)
13809 goto overflow;
13810 break;
13811 case R_X86_64_32S:
13812+ pax_open_kernel();
13813 *(s32 *)loc = val;
13814+ pax_close_kernel();
13815 if ((s64)val != *(s32 *)loc)
13816 goto overflow;
13817 break;
13818 case R_X86_64_PC32:
13819 val -= (u64)loc;
13820+ pax_open_kernel();
13821 *(u32 *)loc = val;
13822+ pax_close_kernel();
13823+
13824 #if 0
13825 if ((s64)val != *(s32 *)loc)
13826 goto overflow;
13827diff -urNp linux-3.0.4/arch/x86/kernel/paravirt.c linux-3.0.4/arch/x86/kernel/paravirt.c
13828--- linux-3.0.4/arch/x86/kernel/paravirt.c 2011-07-21 22:17:23.000000000 -0400
13829+++ linux-3.0.4/arch/x86/kernel/paravirt.c 2011-08-23 21:48:14.000000000 -0400
13830@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
13831 {
13832 return x;
13833 }
13834+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
13835+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
13836+#endif
13837
13838 void __init default_banner(void)
13839 {
13840@@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbu
13841 * corresponding structure. */
13842 static void *get_call_destination(u8 type)
13843 {
13844- struct paravirt_patch_template tmpl = {
13845+ const struct paravirt_patch_template tmpl = {
13846 .pv_init_ops = pv_init_ops,
13847 .pv_time_ops = pv_time_ops,
13848 .pv_cpu_ops = pv_cpu_ops,
13849@@ -133,6 +136,9 @@ static void *get_call_destination(u8 typ
13850 .pv_lock_ops = pv_lock_ops,
13851 #endif
13852 };
13853+
13854+ pax_track_stack();
13855+
13856 return *((void **)&tmpl + type);
13857 }
13858
13859@@ -145,15 +151,19 @@ unsigned paravirt_patch_default(u8 type,
13860 if (opfunc == NULL)
13861 /* If there's no function, patch it with a ud2a (BUG) */
13862 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
13863- else if (opfunc == _paravirt_nop)
13864+ else if (opfunc == (void *)_paravirt_nop)
13865 /* If the operation is a nop, then nop the callsite */
13866 ret = paravirt_patch_nop();
13867
13868 /* identity functions just return their single argument */
13869- else if (opfunc == _paravirt_ident_32)
13870+ else if (opfunc == (void *)_paravirt_ident_32)
13871 ret = paravirt_patch_ident_32(insnbuf, len);
13872- else if (opfunc == _paravirt_ident_64)
13873+ else if (opfunc == (void *)_paravirt_ident_64)
13874 ret = paravirt_patch_ident_64(insnbuf, len);
13875+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
13876+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
13877+ ret = paravirt_patch_ident_64(insnbuf, len);
13878+#endif
13879
13880 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
13881 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
13882@@ -178,7 +188,7 @@ unsigned paravirt_patch_insns(void *insn
13883 if (insn_len > len || start == NULL)
13884 insn_len = len;
13885 else
13886- memcpy(insnbuf, start, insn_len);
13887+ memcpy(insnbuf, ktla_ktva(start), insn_len);
13888
13889 return insn_len;
13890 }
13891@@ -294,22 +304,22 @@ void arch_flush_lazy_mmu_mode(void)
13892 preempt_enable();
13893 }
13894
13895-struct pv_info pv_info = {
13896+struct pv_info pv_info __read_only = {
13897 .name = "bare hardware",
13898 .paravirt_enabled = 0,
13899 .kernel_rpl = 0,
13900 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
13901 };
13902
13903-struct pv_init_ops pv_init_ops = {
13904+struct pv_init_ops pv_init_ops __read_only = {
13905 .patch = native_patch,
13906 };
13907
13908-struct pv_time_ops pv_time_ops = {
13909+struct pv_time_ops pv_time_ops __read_only = {
13910 .sched_clock = native_sched_clock,
13911 };
13912
13913-struct pv_irq_ops pv_irq_ops = {
13914+struct pv_irq_ops pv_irq_ops __read_only = {
13915 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
13916 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
13917 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
13918@@ -321,7 +331,7 @@ struct pv_irq_ops pv_irq_ops = {
13919 #endif
13920 };
13921
13922-struct pv_cpu_ops pv_cpu_ops = {
13923+struct pv_cpu_ops pv_cpu_ops __read_only = {
13924 .cpuid = native_cpuid,
13925 .get_debugreg = native_get_debugreg,
13926 .set_debugreg = native_set_debugreg,
13927@@ -382,21 +392,26 @@ struct pv_cpu_ops pv_cpu_ops = {
13928 .end_context_switch = paravirt_nop,
13929 };
13930
13931-struct pv_apic_ops pv_apic_ops = {
13932+struct pv_apic_ops pv_apic_ops __read_only = {
13933 #ifdef CONFIG_X86_LOCAL_APIC
13934 .startup_ipi_hook = paravirt_nop,
13935 #endif
13936 };
13937
13938-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
13939+#ifdef CONFIG_X86_32
13940+#ifdef CONFIG_X86_PAE
13941+/* 64-bit pagetable entries */
13942+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
13943+#else
13944 /* 32-bit pagetable entries */
13945 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
13946+#endif
13947 #else
13948 /* 64-bit pagetable entries */
13949 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
13950 #endif
13951
13952-struct pv_mmu_ops pv_mmu_ops = {
13953+struct pv_mmu_ops pv_mmu_ops __read_only = {
13954
13955 .read_cr2 = native_read_cr2,
13956 .write_cr2 = native_write_cr2,
13957@@ -446,6 +461,7 @@ struct pv_mmu_ops pv_mmu_ops = {
13958 .make_pud = PTE_IDENT,
13959
13960 .set_pgd = native_set_pgd,
13961+ .set_pgd_batched = native_set_pgd_batched,
13962 #endif
13963 #endif /* PAGETABLE_LEVELS >= 3 */
13964
13965@@ -465,6 +481,12 @@ struct pv_mmu_ops pv_mmu_ops = {
13966 },
13967
13968 .set_fixmap = native_set_fixmap,
13969+
13970+#ifdef CONFIG_PAX_KERNEXEC
13971+ .pax_open_kernel = native_pax_open_kernel,
13972+ .pax_close_kernel = native_pax_close_kernel,
13973+#endif
13974+
13975 };
13976
13977 EXPORT_SYMBOL_GPL(pv_time_ops);
13978diff -urNp linux-3.0.4/arch/x86/kernel/paravirt-spinlocks.c linux-3.0.4/arch/x86/kernel/paravirt-spinlocks.c
13979--- linux-3.0.4/arch/x86/kernel/paravirt-spinlocks.c 2011-07-21 22:17:23.000000000 -0400
13980+++ linux-3.0.4/arch/x86/kernel/paravirt-spinlocks.c 2011-08-23 21:47:55.000000000 -0400
13981@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
13982 arch_spin_lock(lock);
13983 }
13984
13985-struct pv_lock_ops pv_lock_ops = {
13986+struct pv_lock_ops pv_lock_ops __read_only = {
13987 #ifdef CONFIG_SMP
13988 .spin_is_locked = __ticket_spin_is_locked,
13989 .spin_is_contended = __ticket_spin_is_contended,
13990diff -urNp linux-3.0.4/arch/x86/kernel/pci-iommu_table.c linux-3.0.4/arch/x86/kernel/pci-iommu_table.c
13991--- linux-3.0.4/arch/x86/kernel/pci-iommu_table.c 2011-07-21 22:17:23.000000000 -0400
13992+++ linux-3.0.4/arch/x86/kernel/pci-iommu_table.c 2011-08-23 21:48:14.000000000 -0400
13993@@ -2,7 +2,7 @@
13994 #include <asm/iommu_table.h>
13995 #include <linux/string.h>
13996 #include <linux/kallsyms.h>
13997-
13998+#include <linux/sched.h>
13999
14000 #define DEBUG 1
14001
14002@@ -51,6 +51,8 @@ void __init check_iommu_entries(struct i
14003 {
14004 struct iommu_table_entry *p, *q, *x;
14005
14006+ pax_track_stack();
14007+
14008 /* Simple cyclic dependency checker. */
14009 for (p = start; p < finish; p++) {
14010 q = find_dependents_of(start, finish, p);
14011diff -urNp linux-3.0.4/arch/x86/kernel/process_32.c linux-3.0.4/arch/x86/kernel/process_32.c
14012--- linux-3.0.4/arch/x86/kernel/process_32.c 2011-07-21 22:17:23.000000000 -0400
14013+++ linux-3.0.4/arch/x86/kernel/process_32.c 2011-08-23 21:47:55.000000000 -0400
14014@@ -65,6 +65,7 @@ asmlinkage void ret_from_fork(void) __as
14015 unsigned long thread_saved_pc(struct task_struct *tsk)
14016 {
14017 return ((unsigned long *)tsk->thread.sp)[3];
14018+//XXX return tsk->thread.eip;
14019 }
14020
14021 #ifndef CONFIG_SMP
14022@@ -126,15 +127,14 @@ void __show_regs(struct pt_regs *regs, i
14023 unsigned long sp;
14024 unsigned short ss, gs;
14025
14026- if (user_mode_vm(regs)) {
14027+ if (user_mode(regs)) {
14028 sp = regs->sp;
14029 ss = regs->ss & 0xffff;
14030- gs = get_user_gs(regs);
14031 } else {
14032 sp = kernel_stack_pointer(regs);
14033 savesegment(ss, ss);
14034- savesegment(gs, gs);
14035 }
14036+ gs = get_user_gs(regs);
14037
14038 show_regs_common();
14039
14040@@ -196,13 +196,14 @@ int copy_thread(unsigned long clone_flag
14041 struct task_struct *tsk;
14042 int err;
14043
14044- childregs = task_pt_regs(p);
14045+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
14046 *childregs = *regs;
14047 childregs->ax = 0;
14048 childregs->sp = sp;
14049
14050 p->thread.sp = (unsigned long) childregs;
14051 p->thread.sp0 = (unsigned long) (childregs+1);
14052+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
14053
14054 p->thread.ip = (unsigned long) ret_from_fork;
14055
14056@@ -292,7 +293,7 @@ __switch_to(struct task_struct *prev_p,
14057 struct thread_struct *prev = &prev_p->thread,
14058 *next = &next_p->thread;
14059 int cpu = smp_processor_id();
14060- struct tss_struct *tss = &per_cpu(init_tss, cpu);
14061+ struct tss_struct *tss = init_tss + cpu;
14062 bool preload_fpu;
14063
14064 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
14065@@ -327,6 +328,10 @@ __switch_to(struct task_struct *prev_p,
14066 */
14067 lazy_save_gs(prev->gs);
14068
14069+#ifdef CONFIG_PAX_MEMORY_UDEREF
14070+ __set_fs(task_thread_info(next_p)->addr_limit);
14071+#endif
14072+
14073 /*
14074 * Load the per-thread Thread-Local Storage descriptor.
14075 */
14076@@ -362,6 +367,9 @@ __switch_to(struct task_struct *prev_p,
14077 */
14078 arch_end_context_switch(next_p);
14079
14080+ percpu_write(current_task, next_p);
14081+ percpu_write(current_tinfo, &next_p->tinfo);
14082+
14083 if (preload_fpu)
14084 __math_state_restore();
14085
14086@@ -371,8 +379,6 @@ __switch_to(struct task_struct *prev_p,
14087 if (prev->gs | next->gs)
14088 lazy_load_gs(next->gs);
14089
14090- percpu_write(current_task, next_p);
14091-
14092 return prev_p;
14093 }
14094
14095@@ -402,4 +408,3 @@ unsigned long get_wchan(struct task_stru
14096 } while (count++ < 16);
14097 return 0;
14098 }
14099-
14100diff -urNp linux-3.0.4/arch/x86/kernel/process_64.c linux-3.0.4/arch/x86/kernel/process_64.c
14101--- linux-3.0.4/arch/x86/kernel/process_64.c 2011-07-21 22:17:23.000000000 -0400
14102+++ linux-3.0.4/arch/x86/kernel/process_64.c 2011-08-23 21:47:55.000000000 -0400
14103@@ -87,7 +87,7 @@ static void __exit_idle(void)
14104 void exit_idle(void)
14105 {
14106 /* idle loop has pid 0 */
14107- if (current->pid)
14108+ if (task_pid_nr(current))
14109 return;
14110 __exit_idle();
14111 }
14112@@ -260,8 +260,7 @@ int copy_thread(unsigned long clone_flag
14113 struct pt_regs *childregs;
14114 struct task_struct *me = current;
14115
14116- childregs = ((struct pt_regs *)
14117- (THREAD_SIZE + task_stack_page(p))) - 1;
14118+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
14119 *childregs = *regs;
14120
14121 childregs->ax = 0;
14122@@ -273,6 +272,7 @@ int copy_thread(unsigned long clone_flag
14123 p->thread.sp = (unsigned long) childregs;
14124 p->thread.sp0 = (unsigned long) (childregs+1);
14125 p->thread.usersp = me->thread.usersp;
14126+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
14127
14128 set_tsk_thread_flag(p, TIF_FORK);
14129
14130@@ -375,7 +375,7 @@ __switch_to(struct task_struct *prev_p,
14131 struct thread_struct *prev = &prev_p->thread;
14132 struct thread_struct *next = &next_p->thread;
14133 int cpu = smp_processor_id();
14134- struct tss_struct *tss = &per_cpu(init_tss, cpu);
14135+ struct tss_struct *tss = init_tss + cpu;
14136 unsigned fsindex, gsindex;
14137 bool preload_fpu;
14138
14139@@ -471,10 +471,9 @@ __switch_to(struct task_struct *prev_p,
14140 prev->usersp = percpu_read(old_rsp);
14141 percpu_write(old_rsp, next->usersp);
14142 percpu_write(current_task, next_p);
14143+ percpu_write(current_tinfo, &next_p->tinfo);
14144
14145- percpu_write(kernel_stack,
14146- (unsigned long)task_stack_page(next_p) +
14147- THREAD_SIZE - KERNEL_STACK_OFFSET);
14148+ percpu_write(kernel_stack, next->sp0);
14149
14150 /*
14151 * Now maybe reload the debug registers and handle I/O bitmaps
14152@@ -536,12 +535,11 @@ unsigned long get_wchan(struct task_stru
14153 if (!p || p == current || p->state == TASK_RUNNING)
14154 return 0;
14155 stack = (unsigned long)task_stack_page(p);
14156- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
14157+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
14158 return 0;
14159 fp = *(u64 *)(p->thread.sp);
14160 do {
14161- if (fp < (unsigned long)stack ||
14162- fp >= (unsigned long)stack+THREAD_SIZE)
14163+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
14164 return 0;
14165 ip = *(u64 *)(fp+8);
14166 if (!in_sched_functions(ip))
14167diff -urNp linux-3.0.4/arch/x86/kernel/process.c linux-3.0.4/arch/x86/kernel/process.c
14168--- linux-3.0.4/arch/x86/kernel/process.c 2011-07-21 22:17:23.000000000 -0400
14169+++ linux-3.0.4/arch/x86/kernel/process.c 2011-08-30 18:23:52.000000000 -0400
14170@@ -48,16 +48,33 @@ void free_thread_xstate(struct task_stru
14171
14172 void free_thread_info(struct thread_info *ti)
14173 {
14174- free_thread_xstate(ti->task);
14175 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
14176 }
14177
14178+static struct kmem_cache *task_struct_cachep;
14179+
14180 void arch_task_cache_init(void)
14181 {
14182- task_xstate_cachep =
14183- kmem_cache_create("task_xstate", xstate_size,
14184+ /* create a slab on which task_structs can be allocated */
14185+ task_struct_cachep =
14186+ kmem_cache_create("task_struct", sizeof(struct task_struct),
14187+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
14188+
14189+ task_xstate_cachep =
14190+ kmem_cache_create("task_xstate", xstate_size,
14191 __alignof__(union thread_xstate),
14192- SLAB_PANIC | SLAB_NOTRACK, NULL);
14193+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
14194+}
14195+
14196+struct task_struct *alloc_task_struct_node(int node)
14197+{
14198+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
14199+}
14200+
14201+void free_task_struct(struct task_struct *task)
14202+{
14203+ free_thread_xstate(task);
14204+ kmem_cache_free(task_struct_cachep, task);
14205 }
14206
14207 /*
14208@@ -70,7 +87,7 @@ void exit_thread(void)
14209 unsigned long *bp = t->io_bitmap_ptr;
14210
14211 if (bp) {
14212- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
14213+ struct tss_struct *tss = init_tss + get_cpu();
14214
14215 t->io_bitmap_ptr = NULL;
14216 clear_thread_flag(TIF_IO_BITMAP);
14217@@ -106,7 +123,7 @@ void show_regs_common(void)
14218
14219 printk(KERN_CONT "\n");
14220 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
14221- current->pid, current->comm, print_tainted(),
14222+ task_pid_nr(current), current->comm, print_tainted(),
14223 init_utsname()->release,
14224 (int)strcspn(init_utsname()->version, " "),
14225 init_utsname()->version);
14226@@ -120,6 +137,9 @@ void flush_thread(void)
14227 {
14228 struct task_struct *tsk = current;
14229
14230+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14231+ loadsegment(gs, 0);
14232+#endif
14233 flush_ptrace_hw_breakpoint(tsk);
14234 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
14235 /*
14236@@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), voi
14237 regs.di = (unsigned long) arg;
14238
14239 #ifdef CONFIG_X86_32
14240- regs.ds = __USER_DS;
14241- regs.es = __USER_DS;
14242+ regs.ds = __KERNEL_DS;
14243+ regs.es = __KERNEL_DS;
14244 regs.fs = __KERNEL_PERCPU;
14245- regs.gs = __KERNEL_STACK_CANARY;
14246+ savesegment(gs, regs.gs);
14247 #else
14248 regs.ss = __KERNEL_DS;
14249 #endif
14250@@ -403,7 +423,7 @@ void default_idle(void)
14251 EXPORT_SYMBOL(default_idle);
14252 #endif
14253
14254-void stop_this_cpu(void *dummy)
14255+__noreturn void stop_this_cpu(void *dummy)
14256 {
14257 local_irq_disable();
14258 /*
14259@@ -668,16 +688,37 @@ static int __init idle_setup(char *str)
14260 }
14261 early_param("idle", idle_setup);
14262
14263-unsigned long arch_align_stack(unsigned long sp)
14264+#ifdef CONFIG_PAX_RANDKSTACK
14265+void pax_randomize_kstack(struct pt_regs *regs)
14266 {
14267- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
14268- sp -= get_random_int() % 8192;
14269- return sp & ~0xf;
14270-}
14271+ struct thread_struct *thread = &current->thread;
14272+ unsigned long time;
14273
14274-unsigned long arch_randomize_brk(struct mm_struct *mm)
14275-{
14276- unsigned long range_end = mm->brk + 0x02000000;
14277- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
14278-}
14279+ if (!randomize_va_space)
14280+ return;
14281+
14282+ if (v8086_mode(regs))
14283+ return;
14284
14285+ rdtscl(time);
14286+
14287+ /* P4 seems to return a 0 LSB, ignore it */
14288+#ifdef CONFIG_MPENTIUM4
14289+ time &= 0x3EUL;
14290+ time <<= 2;
14291+#elif defined(CONFIG_X86_64)
14292+ time &= 0xFUL;
14293+ time <<= 4;
14294+#else
14295+ time &= 0x1FUL;
14296+ time <<= 3;
14297+#endif
14298+
14299+ thread->sp0 ^= time;
14300+ load_sp0(init_tss + smp_processor_id(), thread);
14301+
14302+#ifdef CONFIG_X86_64
14303+ percpu_write(kernel_stack, thread->sp0);
14304+#endif
14305+}
14306+#endif
14307diff -urNp linux-3.0.4/arch/x86/kernel/ptrace.c linux-3.0.4/arch/x86/kernel/ptrace.c
14308--- linux-3.0.4/arch/x86/kernel/ptrace.c 2011-07-21 22:17:23.000000000 -0400
14309+++ linux-3.0.4/arch/x86/kernel/ptrace.c 2011-08-23 21:47:55.000000000 -0400
14310@@ -821,7 +821,7 @@ long arch_ptrace(struct task_struct *chi
14311 unsigned long addr, unsigned long data)
14312 {
14313 int ret;
14314- unsigned long __user *datap = (unsigned long __user *)data;
14315+ unsigned long __user *datap = (__force unsigned long __user *)data;
14316
14317 switch (request) {
14318 /* read the word at location addr in the USER area. */
14319@@ -906,14 +906,14 @@ long arch_ptrace(struct task_struct *chi
14320 if ((int) addr < 0)
14321 return -EIO;
14322 ret = do_get_thread_area(child, addr,
14323- (struct user_desc __user *)data);
14324+ (__force struct user_desc __user *) data);
14325 break;
14326
14327 case PTRACE_SET_THREAD_AREA:
14328 if ((int) addr < 0)
14329 return -EIO;
14330 ret = do_set_thread_area(child, addr,
14331- (struct user_desc __user *)data, 0);
14332+ (__force struct user_desc __user *) data, 0);
14333 break;
14334 #endif
14335
14336@@ -1330,7 +1330,7 @@ static void fill_sigtrap_info(struct tas
14337 memset(info, 0, sizeof(*info));
14338 info->si_signo = SIGTRAP;
14339 info->si_code = si_code;
14340- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
14341+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
14342 }
14343
14344 void user_single_step_siginfo(struct task_struct *tsk,
14345diff -urNp linux-3.0.4/arch/x86/kernel/pvclock.c linux-3.0.4/arch/x86/kernel/pvclock.c
14346--- linux-3.0.4/arch/x86/kernel/pvclock.c 2011-07-21 22:17:23.000000000 -0400
14347+++ linux-3.0.4/arch/x86/kernel/pvclock.c 2011-08-23 21:47:55.000000000 -0400
14348@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvc
14349 return pv_tsc_khz;
14350 }
14351
14352-static atomic64_t last_value = ATOMIC64_INIT(0);
14353+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
14354
14355 void pvclock_resume(void)
14356 {
14357- atomic64_set(&last_value, 0);
14358+ atomic64_set_unchecked(&last_value, 0);
14359 }
14360
14361 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
14362@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct
14363 * updating at the same time, and one of them could be slightly behind,
14364 * making the assumption that last_value always go forward fail to hold.
14365 */
14366- last = atomic64_read(&last_value);
14367+ last = atomic64_read_unchecked(&last_value);
14368 do {
14369 if (ret < last)
14370 return last;
14371- last = atomic64_cmpxchg(&last_value, last, ret);
14372+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
14373 } while (unlikely(last != ret));
14374
14375 return ret;
14376diff -urNp linux-3.0.4/arch/x86/kernel/reboot.c linux-3.0.4/arch/x86/kernel/reboot.c
14377--- linux-3.0.4/arch/x86/kernel/reboot.c 2011-07-21 22:17:23.000000000 -0400
14378+++ linux-3.0.4/arch/x86/kernel/reboot.c 2011-08-23 21:47:55.000000000 -0400
14379@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
14380 EXPORT_SYMBOL(pm_power_off);
14381
14382 static const struct desc_ptr no_idt = {};
14383-static int reboot_mode;
14384+static unsigned short reboot_mode;
14385 enum reboot_type reboot_type = BOOT_ACPI;
14386 int reboot_force;
14387
14388@@ -315,13 +315,17 @@ core_initcall(reboot_init);
14389 extern const unsigned char machine_real_restart_asm[];
14390 extern const u64 machine_real_restart_gdt[3];
14391
14392-void machine_real_restart(unsigned int type)
14393+__noreturn void machine_real_restart(unsigned int type)
14394 {
14395 void *restart_va;
14396 unsigned long restart_pa;
14397- void (*restart_lowmem)(unsigned int);
14398+ void (* __noreturn restart_lowmem)(unsigned int);
14399 u64 *lowmem_gdt;
14400
14401+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14402+ struct desc_struct *gdt;
14403+#endif
14404+
14405 local_irq_disable();
14406
14407 /* Write zero to CMOS register number 0x0f, which the BIOS POST
14408@@ -347,14 +351,14 @@ void machine_real_restart(unsigned int t
14409 boot)". This seems like a fairly standard thing that gets set by
14410 REBOOT.COM programs, and the previous reset routine did this
14411 too. */
14412- *((unsigned short *)0x472) = reboot_mode;
14413+ *(unsigned short *)(__va(0x472)) = reboot_mode;
14414
14415 /* Patch the GDT in the low memory trampoline */
14416 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
14417
14418 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
14419 restart_pa = virt_to_phys(restart_va);
14420- restart_lowmem = (void (*)(unsigned int))restart_pa;
14421+ restart_lowmem = (void *)restart_pa;
14422
14423 /* GDT[0]: GDT self-pointer */
14424 lowmem_gdt[0] =
14425@@ -365,7 +369,33 @@ void machine_real_restart(unsigned int t
14426 GDT_ENTRY(0x009b, restart_pa, 0xffff);
14427
14428 /* Jump to the identity-mapped low memory code */
14429+
14430+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14431+ gdt = get_cpu_gdt_table(smp_processor_id());
14432+ pax_open_kernel();
14433+#ifdef CONFIG_PAX_MEMORY_UDEREF
14434+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
14435+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
14436+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
14437+#endif
14438+#ifdef CONFIG_PAX_KERNEXEC
14439+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
14440+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
14441+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
14442+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
14443+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
14444+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
14445+#endif
14446+ pax_close_kernel();
14447+#endif
14448+
14449+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14450+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
14451+ unreachable();
14452+#else
14453 restart_lowmem(type);
14454+#endif
14455+
14456 }
14457 #ifdef CONFIG_APM_MODULE
14458 EXPORT_SYMBOL(machine_real_restart);
14459@@ -523,7 +553,7 @@ void __attribute__((weak)) mach_reboot_f
14460 * try to force a triple fault and then cycle between hitting the keyboard
14461 * controller and doing that
14462 */
14463-static void native_machine_emergency_restart(void)
14464+__noreturn static void native_machine_emergency_restart(void)
14465 {
14466 int i;
14467 int attempt = 0;
14468@@ -647,13 +677,13 @@ void native_machine_shutdown(void)
14469 #endif
14470 }
14471
14472-static void __machine_emergency_restart(int emergency)
14473+static __noreturn void __machine_emergency_restart(int emergency)
14474 {
14475 reboot_emergency = emergency;
14476 machine_ops.emergency_restart();
14477 }
14478
14479-static void native_machine_restart(char *__unused)
14480+static __noreturn void native_machine_restart(char *__unused)
14481 {
14482 printk("machine restart\n");
14483
14484@@ -662,7 +692,7 @@ static void native_machine_restart(char
14485 __machine_emergency_restart(0);
14486 }
14487
14488-static void native_machine_halt(void)
14489+static __noreturn void native_machine_halt(void)
14490 {
14491 /* stop other cpus and apics */
14492 machine_shutdown();
14493@@ -673,7 +703,7 @@ static void native_machine_halt(void)
14494 stop_this_cpu(NULL);
14495 }
14496
14497-static void native_machine_power_off(void)
14498+__noreturn static void native_machine_power_off(void)
14499 {
14500 if (pm_power_off) {
14501 if (!reboot_force)
14502@@ -682,6 +712,7 @@ static void native_machine_power_off(voi
14503 }
14504 /* a fallback in case there is no PM info available */
14505 tboot_shutdown(TB_SHUTDOWN_HALT);
14506+ unreachable();
14507 }
14508
14509 struct machine_ops machine_ops = {
14510diff -urNp linux-3.0.4/arch/x86/kernel/setup.c linux-3.0.4/arch/x86/kernel/setup.c
14511--- linux-3.0.4/arch/x86/kernel/setup.c 2011-07-21 22:17:23.000000000 -0400
14512+++ linux-3.0.4/arch/x86/kernel/setup.c 2011-08-23 21:47:55.000000000 -0400
14513@@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
14514 * area (640->1Mb) as ram even though it is not.
14515 * take them out.
14516 */
14517- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
14518+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
14519 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
14520 }
14521
14522@@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
14523
14524 if (!boot_params.hdr.root_flags)
14525 root_mountflags &= ~MS_RDONLY;
14526- init_mm.start_code = (unsigned long) _text;
14527- init_mm.end_code = (unsigned long) _etext;
14528+ init_mm.start_code = ktla_ktva((unsigned long) _text);
14529+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
14530 init_mm.end_data = (unsigned long) _edata;
14531 init_mm.brk = _brk_end;
14532
14533- code_resource.start = virt_to_phys(_text);
14534- code_resource.end = virt_to_phys(_etext)-1;
14535- data_resource.start = virt_to_phys(_etext);
14536+ code_resource.start = virt_to_phys(ktla_ktva(_text));
14537+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
14538+ data_resource.start = virt_to_phys(_sdata);
14539 data_resource.end = virt_to_phys(_edata)-1;
14540 bss_resource.start = virt_to_phys(&__bss_start);
14541 bss_resource.end = virt_to_phys(&__bss_stop)-1;
14542diff -urNp linux-3.0.4/arch/x86/kernel/setup_percpu.c linux-3.0.4/arch/x86/kernel/setup_percpu.c
14543--- linux-3.0.4/arch/x86/kernel/setup_percpu.c 2011-07-21 22:17:23.000000000 -0400
14544+++ linux-3.0.4/arch/x86/kernel/setup_percpu.c 2011-08-23 21:47:55.000000000 -0400
14545@@ -21,19 +21,17 @@
14546 #include <asm/cpu.h>
14547 #include <asm/stackprotector.h>
14548
14549-DEFINE_PER_CPU(int, cpu_number);
14550+#ifdef CONFIG_SMP
14551+DEFINE_PER_CPU(unsigned int, cpu_number);
14552 EXPORT_PER_CPU_SYMBOL(cpu_number);
14553+#endif
14554
14555-#ifdef CONFIG_X86_64
14556 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
14557-#else
14558-#define BOOT_PERCPU_OFFSET 0
14559-#endif
14560
14561 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
14562 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
14563
14564-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
14565+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
14566 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
14567 };
14568 EXPORT_SYMBOL(__per_cpu_offset);
14569@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
14570 {
14571 #ifdef CONFIG_X86_32
14572 struct desc_struct gdt;
14573+ unsigned long base = per_cpu_offset(cpu);
14574
14575- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
14576- 0x2 | DESCTYPE_S, 0x8);
14577- gdt.s = 1;
14578+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
14579+ 0x83 | DESCTYPE_S, 0xC);
14580 write_gdt_entry(get_cpu_gdt_table(cpu),
14581 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
14582 #endif
14583@@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
14584 /* alrighty, percpu areas up and running */
14585 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
14586 for_each_possible_cpu(cpu) {
14587+#ifdef CONFIG_CC_STACKPROTECTOR
14588+#ifdef CONFIG_X86_32
14589+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
14590+#endif
14591+#endif
14592 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
14593 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
14594 per_cpu(cpu_number, cpu) = cpu;
14595@@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
14596 */
14597 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
14598 #endif
14599+#ifdef CONFIG_CC_STACKPROTECTOR
14600+#ifdef CONFIG_X86_32
14601+ if (!cpu)
14602+ per_cpu(stack_canary.canary, cpu) = canary;
14603+#endif
14604+#endif
14605 /*
14606 * Up to this point, the boot CPU has been using .init.data
14607 * area. Reload any changed state for the boot CPU.
14608diff -urNp linux-3.0.4/arch/x86/kernel/signal.c linux-3.0.4/arch/x86/kernel/signal.c
14609--- linux-3.0.4/arch/x86/kernel/signal.c 2011-07-21 22:17:23.000000000 -0400
14610+++ linux-3.0.4/arch/x86/kernel/signal.c 2011-08-23 21:48:14.000000000 -0400
14611@@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
14612 * Align the stack pointer according to the i386 ABI,
14613 * i.e. so that on function entry ((sp + 4) & 15) == 0.
14614 */
14615- sp = ((sp + 4) & -16ul) - 4;
14616+ sp = ((sp - 12) & -16ul) - 4;
14617 #else /* !CONFIG_X86_32 */
14618 sp = round_down(sp, 16) - 8;
14619 #endif
14620@@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
14621 * Return an always-bogus address instead so we will die with SIGSEGV.
14622 */
14623 if (onsigstack && !likely(on_sig_stack(sp)))
14624- return (void __user *)-1L;
14625+ return (__force void __user *)-1L;
14626
14627 /* save i387 state */
14628 if (used_math() && save_i387_xstate(*fpstate) < 0)
14629- return (void __user *)-1L;
14630+ return (__force void __user *)-1L;
14631
14632 return (void __user *)sp;
14633 }
14634@@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
14635 }
14636
14637 if (current->mm->context.vdso)
14638- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
14639+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
14640 else
14641- restorer = &frame->retcode;
14642+ restorer = (void __user *)&frame->retcode;
14643 if (ka->sa.sa_flags & SA_RESTORER)
14644 restorer = ka->sa.sa_restorer;
14645
14646@@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
14647 * reasons and because gdb uses it as a signature to notice
14648 * signal handler stack frames.
14649 */
14650- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
14651+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
14652
14653 if (err)
14654 return -EFAULT;
14655@@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
14656 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
14657
14658 /* Set up to return from userspace. */
14659- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14660+ if (current->mm->context.vdso)
14661+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14662+ else
14663+ restorer = (void __user *)&frame->retcode;
14664 if (ka->sa.sa_flags & SA_RESTORER)
14665 restorer = ka->sa.sa_restorer;
14666 put_user_ex(restorer, &frame->pretcode);
14667@@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
14668 * reasons and because gdb uses it as a signature to notice
14669 * signal handler stack frames.
14670 */
14671- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
14672+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
14673 } put_user_catch(err);
14674
14675 if (err)
14676@@ -769,6 +772,8 @@ static void do_signal(struct pt_regs *re
14677 int signr;
14678 sigset_t *oldset;
14679
14680+ pax_track_stack();
14681+
14682 /*
14683 * We want the common case to go fast, which is why we may in certain
14684 * cases get here from kernel mode. Just return without doing anything
14685@@ -776,7 +781,7 @@ static void do_signal(struct pt_regs *re
14686 * X86_32: vm86 regs switched out by assembly code before reaching
14687 * here, so testing against kernel CS suffices.
14688 */
14689- if (!user_mode(regs))
14690+ if (!user_mode_novm(regs))
14691 return;
14692
14693 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
14694diff -urNp linux-3.0.4/arch/x86/kernel/smpboot.c linux-3.0.4/arch/x86/kernel/smpboot.c
14695--- linux-3.0.4/arch/x86/kernel/smpboot.c 2011-07-21 22:17:23.000000000 -0400
14696+++ linux-3.0.4/arch/x86/kernel/smpboot.c 2011-08-23 21:47:55.000000000 -0400
14697@@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int api
14698 set_idle_for_cpu(cpu, c_idle.idle);
14699 do_rest:
14700 per_cpu(current_task, cpu) = c_idle.idle;
14701+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
14702 #ifdef CONFIG_X86_32
14703 /* Stack for startup_32 can be just as for start_secondary onwards */
14704 irq_ctx_init(cpu);
14705 #else
14706 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
14707 initial_gs = per_cpu_offset(cpu);
14708- per_cpu(kernel_stack, cpu) =
14709- (unsigned long)task_stack_page(c_idle.idle) -
14710- KERNEL_STACK_OFFSET + THREAD_SIZE;
14711+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
14712 #endif
14713+
14714+ pax_open_kernel();
14715 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14716+ pax_close_kernel();
14717+
14718 initial_code = (unsigned long)start_secondary;
14719 stack_start = c_idle.idle->thread.sp;
14720
14721@@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int
14722
14723 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
14724
14725+#ifdef CONFIG_PAX_PER_CPU_PGD
14726+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
14727+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
14728+ KERNEL_PGD_PTRS);
14729+#endif
14730+
14731 err = do_boot_cpu(apicid, cpu);
14732 if (err) {
14733 pr_debug("do_boot_cpu failed %d\n", err);
14734diff -urNp linux-3.0.4/arch/x86/kernel/step.c linux-3.0.4/arch/x86/kernel/step.c
14735--- linux-3.0.4/arch/x86/kernel/step.c 2011-07-21 22:17:23.000000000 -0400
14736+++ linux-3.0.4/arch/x86/kernel/step.c 2011-08-23 21:47:55.000000000 -0400
14737@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
14738 struct desc_struct *desc;
14739 unsigned long base;
14740
14741- seg &= ~7UL;
14742+ seg >>= 3;
14743
14744 mutex_lock(&child->mm->context.lock);
14745- if (unlikely((seg >> 3) >= child->mm->context.size))
14746+ if (unlikely(seg >= child->mm->context.size))
14747 addr = -1L; /* bogus selector, access would fault */
14748 else {
14749 desc = child->mm->context.ldt + seg;
14750@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
14751 addr += base;
14752 }
14753 mutex_unlock(&child->mm->context.lock);
14754- }
14755+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
14756+ addr = ktla_ktva(addr);
14757
14758 return addr;
14759 }
14760@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
14761 unsigned char opcode[15];
14762 unsigned long addr = convert_ip_to_linear(child, regs);
14763
14764+ if (addr == -EINVAL)
14765+ return 0;
14766+
14767 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
14768 for (i = 0; i < copied; i++) {
14769 switch (opcode[i]) {
14770@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
14771
14772 #ifdef CONFIG_X86_64
14773 case 0x40 ... 0x4f:
14774- if (regs->cs != __USER_CS)
14775+ if ((regs->cs & 0xffff) != __USER_CS)
14776 /* 32-bit mode: register increment */
14777 return 0;
14778 /* 64-bit mode: REX prefix */
14779diff -urNp linux-3.0.4/arch/x86/kernel/syscall_table_32.S linux-3.0.4/arch/x86/kernel/syscall_table_32.S
14780--- linux-3.0.4/arch/x86/kernel/syscall_table_32.S 2011-07-21 22:17:23.000000000 -0400
14781+++ linux-3.0.4/arch/x86/kernel/syscall_table_32.S 2011-08-23 21:47:55.000000000 -0400
14782@@ -1,3 +1,4 @@
14783+.section .rodata,"a",@progbits
14784 ENTRY(sys_call_table)
14785 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
14786 .long sys_exit
14787diff -urNp linux-3.0.4/arch/x86/kernel/sys_i386_32.c linux-3.0.4/arch/x86/kernel/sys_i386_32.c
14788--- linux-3.0.4/arch/x86/kernel/sys_i386_32.c 2011-07-21 22:17:23.000000000 -0400
14789+++ linux-3.0.4/arch/x86/kernel/sys_i386_32.c 2011-08-23 21:47:55.000000000 -0400
14790@@ -24,17 +24,224 @@
14791
14792 #include <asm/syscalls.h>
14793
14794-/*
14795- * Do a system call from kernel instead of calling sys_execve so we
14796- * end up with proper pt_regs.
14797- */
14798-int kernel_execve(const char *filename,
14799- const char *const argv[],
14800- const char *const envp[])
14801+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
14802 {
14803- long __res;
14804- asm volatile ("int $0x80"
14805- : "=a" (__res)
14806- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
14807- return __res;
14808+ unsigned long pax_task_size = TASK_SIZE;
14809+
14810+#ifdef CONFIG_PAX_SEGMEXEC
14811+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
14812+ pax_task_size = SEGMEXEC_TASK_SIZE;
14813+#endif
14814+
14815+ if (len > pax_task_size || addr > pax_task_size - len)
14816+ return -EINVAL;
14817+
14818+ return 0;
14819+}
14820+
14821+unsigned long
14822+arch_get_unmapped_area(struct file *filp, unsigned long addr,
14823+ unsigned long len, unsigned long pgoff, unsigned long flags)
14824+{
14825+ struct mm_struct *mm = current->mm;
14826+ struct vm_area_struct *vma;
14827+ unsigned long start_addr, pax_task_size = TASK_SIZE;
14828+
14829+#ifdef CONFIG_PAX_SEGMEXEC
14830+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
14831+ pax_task_size = SEGMEXEC_TASK_SIZE;
14832+#endif
14833+
14834+ pax_task_size -= PAGE_SIZE;
14835+
14836+ if (len > pax_task_size)
14837+ return -ENOMEM;
14838+
14839+ if (flags & MAP_FIXED)
14840+ return addr;
14841+
14842+#ifdef CONFIG_PAX_RANDMMAP
14843+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14844+#endif
14845+
14846+ if (addr) {
14847+ addr = PAGE_ALIGN(addr);
14848+ if (pax_task_size - len >= addr) {
14849+ vma = find_vma(mm, addr);
14850+ if (check_heap_stack_gap(vma, addr, len))
14851+ return addr;
14852+ }
14853+ }
14854+ if (len > mm->cached_hole_size) {
14855+ start_addr = addr = mm->free_area_cache;
14856+ } else {
14857+ start_addr = addr = mm->mmap_base;
14858+ mm->cached_hole_size = 0;
14859+ }
14860+
14861+#ifdef CONFIG_PAX_PAGEEXEC
14862+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
14863+ start_addr = 0x00110000UL;
14864+
14865+#ifdef CONFIG_PAX_RANDMMAP
14866+ if (mm->pax_flags & MF_PAX_RANDMMAP)
14867+ start_addr += mm->delta_mmap & 0x03FFF000UL;
14868+#endif
14869+
14870+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
14871+ start_addr = addr = mm->mmap_base;
14872+ else
14873+ addr = start_addr;
14874+ }
14875+#endif
14876+
14877+full_search:
14878+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
14879+ /* At this point: (!vma || addr < vma->vm_end). */
14880+ if (pax_task_size - len < addr) {
14881+ /*
14882+ * Start a new search - just in case we missed
14883+ * some holes.
14884+ */
14885+ if (start_addr != mm->mmap_base) {
14886+ start_addr = addr = mm->mmap_base;
14887+ mm->cached_hole_size = 0;
14888+ goto full_search;
14889+ }
14890+ return -ENOMEM;
14891+ }
14892+ if (check_heap_stack_gap(vma, addr, len))
14893+ break;
14894+ if (addr + mm->cached_hole_size < vma->vm_start)
14895+ mm->cached_hole_size = vma->vm_start - addr;
14896+ addr = vma->vm_end;
14897+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
14898+ start_addr = addr = mm->mmap_base;
14899+ mm->cached_hole_size = 0;
14900+ goto full_search;
14901+ }
14902+ }
14903+
14904+ /*
14905+ * Remember the place where we stopped the search:
14906+ */
14907+ mm->free_area_cache = addr + len;
14908+ return addr;
14909+}
14910+
14911+unsigned long
14912+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
14913+ const unsigned long len, const unsigned long pgoff,
14914+ const unsigned long flags)
14915+{
14916+ struct vm_area_struct *vma;
14917+ struct mm_struct *mm = current->mm;
14918+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
14919+
14920+#ifdef CONFIG_PAX_SEGMEXEC
14921+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
14922+ pax_task_size = SEGMEXEC_TASK_SIZE;
14923+#endif
14924+
14925+ pax_task_size -= PAGE_SIZE;
14926+
14927+ /* requested length too big for entire address space */
14928+ if (len > pax_task_size)
14929+ return -ENOMEM;
14930+
14931+ if (flags & MAP_FIXED)
14932+ return addr;
14933+
14934+#ifdef CONFIG_PAX_PAGEEXEC
14935+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
14936+ goto bottomup;
14937+#endif
14938+
14939+#ifdef CONFIG_PAX_RANDMMAP
14940+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14941+#endif
14942+
14943+ /* requesting a specific address */
14944+ if (addr) {
14945+ addr = PAGE_ALIGN(addr);
14946+ if (pax_task_size - len >= addr) {
14947+ vma = find_vma(mm, addr);
14948+ if (check_heap_stack_gap(vma, addr, len))
14949+ return addr;
14950+ }
14951+ }
14952+
14953+ /* check if free_area_cache is useful for us */
14954+ if (len <= mm->cached_hole_size) {
14955+ mm->cached_hole_size = 0;
14956+ mm->free_area_cache = mm->mmap_base;
14957+ }
14958+
14959+ /* either no address requested or can't fit in requested address hole */
14960+ addr = mm->free_area_cache;
14961+
14962+ /* make sure it can fit in the remaining address space */
14963+ if (addr > len) {
14964+ vma = find_vma(mm, addr-len);
14965+ if (check_heap_stack_gap(vma, addr - len, len))
14966+ /* remember the address as a hint for next time */
14967+ return (mm->free_area_cache = addr-len);
14968+ }
14969+
14970+ if (mm->mmap_base < len)
14971+ goto bottomup;
14972+
14973+ addr = mm->mmap_base-len;
14974+
14975+ do {
14976+ /*
14977+ * Lookup failure means no vma is above this address,
14978+ * else if new region fits below vma->vm_start,
14979+ * return with success:
14980+ */
14981+ vma = find_vma(mm, addr);
14982+ if (check_heap_stack_gap(vma, addr, len))
14983+ /* remember the address as a hint for next time */
14984+ return (mm->free_area_cache = addr);
14985+
14986+ /* remember the largest hole we saw so far */
14987+ if (addr + mm->cached_hole_size < vma->vm_start)
14988+ mm->cached_hole_size = vma->vm_start - addr;
14989+
14990+ /* try just below the current vma->vm_start */
14991+ addr = skip_heap_stack_gap(vma, len);
14992+ } while (!IS_ERR_VALUE(addr));
14993+
14994+bottomup:
14995+ /*
14996+ * A failed mmap() very likely causes application failure,
14997+ * so fall back to the bottom-up function here. This scenario
14998+ * can happen with large stack limits and large mmap()
14999+ * allocations.
15000+ */
15001+
15002+#ifdef CONFIG_PAX_SEGMEXEC
15003+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
15004+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
15005+ else
15006+#endif
15007+
15008+ mm->mmap_base = TASK_UNMAPPED_BASE;
15009+
15010+#ifdef CONFIG_PAX_RANDMMAP
15011+ if (mm->pax_flags & MF_PAX_RANDMMAP)
15012+ mm->mmap_base += mm->delta_mmap;
15013+#endif
15014+
15015+ mm->free_area_cache = mm->mmap_base;
15016+ mm->cached_hole_size = ~0UL;
15017+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
15018+ /*
15019+ * Restore the topdown base:
15020+ */
15021+ mm->mmap_base = base;
15022+ mm->free_area_cache = base;
15023+ mm->cached_hole_size = ~0UL;
15024+
15025+ return addr;
15026 }
15027diff -urNp linux-3.0.4/arch/x86/kernel/sys_x86_64.c linux-3.0.4/arch/x86/kernel/sys_x86_64.c
15028--- linux-3.0.4/arch/x86/kernel/sys_x86_64.c 2011-07-21 22:17:23.000000000 -0400
15029+++ linux-3.0.4/arch/x86/kernel/sys_x86_64.c 2011-08-23 21:47:55.000000000 -0400
15030@@ -32,8 +32,8 @@ out:
15031 return error;
15032 }
15033
15034-static void find_start_end(unsigned long flags, unsigned long *begin,
15035- unsigned long *end)
15036+static void find_start_end(struct mm_struct *mm, unsigned long flags,
15037+ unsigned long *begin, unsigned long *end)
15038 {
15039 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
15040 unsigned long new_begin;
15041@@ -52,7 +52,7 @@ static void find_start_end(unsigned long
15042 *begin = new_begin;
15043 }
15044 } else {
15045- *begin = TASK_UNMAPPED_BASE;
15046+ *begin = mm->mmap_base;
15047 *end = TASK_SIZE;
15048 }
15049 }
15050@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
15051 if (flags & MAP_FIXED)
15052 return addr;
15053
15054- find_start_end(flags, &begin, &end);
15055+ find_start_end(mm, flags, &begin, &end);
15056
15057 if (len > end)
15058 return -ENOMEM;
15059
15060+#ifdef CONFIG_PAX_RANDMMAP
15061+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
15062+#endif
15063+
15064 if (addr) {
15065 addr = PAGE_ALIGN(addr);
15066 vma = find_vma(mm, addr);
15067- if (end - len >= addr &&
15068- (!vma || addr + len <= vma->vm_start))
15069+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
15070 return addr;
15071 }
15072 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
15073@@ -106,7 +109,7 @@ full_search:
15074 }
15075 return -ENOMEM;
15076 }
15077- if (!vma || addr + len <= vma->vm_start) {
15078+ if (check_heap_stack_gap(vma, addr, len)) {
15079 /*
15080 * Remember the place where we stopped the search:
15081 */
15082@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
15083 {
15084 struct vm_area_struct *vma;
15085 struct mm_struct *mm = current->mm;
15086- unsigned long addr = addr0;
15087+ unsigned long base = mm->mmap_base, addr = addr0;
15088
15089 /* requested length too big for entire address space */
15090 if (len > TASK_SIZE)
15091@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
15092 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
15093 goto bottomup;
15094
15095+#ifdef CONFIG_PAX_RANDMMAP
15096+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
15097+#endif
15098+
15099 /* requesting a specific address */
15100 if (addr) {
15101 addr = PAGE_ALIGN(addr);
15102- vma = find_vma(mm, addr);
15103- if (TASK_SIZE - len >= addr &&
15104- (!vma || addr + len <= vma->vm_start))
15105- return addr;
15106+ if (TASK_SIZE - len >= addr) {
15107+ vma = find_vma(mm, addr);
15108+ if (check_heap_stack_gap(vma, addr, len))
15109+ return addr;
15110+ }
15111 }
15112
15113 /* check if free_area_cache is useful for us */
15114@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
15115 /* make sure it can fit in the remaining address space */
15116 if (addr > len) {
15117 vma = find_vma(mm, addr-len);
15118- if (!vma || addr <= vma->vm_start)
15119+ if (check_heap_stack_gap(vma, addr - len, len))
15120 /* remember the address as a hint for next time */
15121 return mm->free_area_cache = addr-len;
15122 }
15123@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
15124 * return with success:
15125 */
15126 vma = find_vma(mm, addr);
15127- if (!vma || addr+len <= vma->vm_start)
15128+ if (check_heap_stack_gap(vma, addr, len))
15129 /* remember the address as a hint for next time */
15130 return mm->free_area_cache = addr;
15131
15132@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
15133 mm->cached_hole_size = vma->vm_start - addr;
15134
15135 /* try just below the current vma->vm_start */
15136- addr = vma->vm_start-len;
15137- } while (len < vma->vm_start);
15138+ addr = skip_heap_stack_gap(vma, len);
15139+ } while (!IS_ERR_VALUE(addr));
15140
15141 bottomup:
15142 /*
15143@@ -198,13 +206,21 @@ bottomup:
15144 * can happen with large stack limits and large mmap()
15145 * allocations.
15146 */
15147+ mm->mmap_base = TASK_UNMAPPED_BASE;
15148+
15149+#ifdef CONFIG_PAX_RANDMMAP
15150+ if (mm->pax_flags & MF_PAX_RANDMMAP)
15151+ mm->mmap_base += mm->delta_mmap;
15152+#endif
15153+
15154+ mm->free_area_cache = mm->mmap_base;
15155 mm->cached_hole_size = ~0UL;
15156- mm->free_area_cache = TASK_UNMAPPED_BASE;
15157 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
15158 /*
15159 * Restore the topdown base:
15160 */
15161- mm->free_area_cache = mm->mmap_base;
15162+ mm->mmap_base = base;
15163+ mm->free_area_cache = base;
15164 mm->cached_hole_size = ~0UL;
15165
15166 return addr;
15167diff -urNp linux-3.0.4/arch/x86/kernel/tboot.c linux-3.0.4/arch/x86/kernel/tboot.c
15168--- linux-3.0.4/arch/x86/kernel/tboot.c 2011-07-21 22:17:23.000000000 -0400
15169+++ linux-3.0.4/arch/x86/kernel/tboot.c 2011-08-23 21:47:55.000000000 -0400
15170@@ -217,7 +217,7 @@ static int tboot_setup_sleep(void)
15171
15172 void tboot_shutdown(u32 shutdown_type)
15173 {
15174- void (*shutdown)(void);
15175+ void (* __noreturn shutdown)(void);
15176
15177 if (!tboot_enabled())
15178 return;
15179@@ -239,7 +239,7 @@ void tboot_shutdown(u32 shutdown_type)
15180
15181 switch_to_tboot_pt();
15182
15183- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
15184+ shutdown = (void *)tboot->shutdown_entry;
15185 shutdown();
15186
15187 /* should not reach here */
15188@@ -296,7 +296,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
15189 tboot_shutdown(acpi_shutdown_map[sleep_state]);
15190 }
15191
15192-static atomic_t ap_wfs_count;
15193+static atomic_unchecked_t ap_wfs_count;
15194
15195 static int tboot_wait_for_aps(int num_aps)
15196 {
15197@@ -320,9 +320,9 @@ static int __cpuinit tboot_cpu_callback(
15198 {
15199 switch (action) {
15200 case CPU_DYING:
15201- atomic_inc(&ap_wfs_count);
15202+ atomic_inc_unchecked(&ap_wfs_count);
15203 if (num_online_cpus() == 1)
15204- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
15205+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
15206 return NOTIFY_BAD;
15207 break;
15208 }
15209@@ -341,7 +341,7 @@ static __init int tboot_late_init(void)
15210
15211 tboot_create_trampoline();
15212
15213- atomic_set(&ap_wfs_count, 0);
15214+ atomic_set_unchecked(&ap_wfs_count, 0);
15215 register_hotcpu_notifier(&tboot_cpu_notifier);
15216 return 0;
15217 }
15218diff -urNp linux-3.0.4/arch/x86/kernel/time.c linux-3.0.4/arch/x86/kernel/time.c
15219--- linux-3.0.4/arch/x86/kernel/time.c 2011-07-21 22:17:23.000000000 -0400
15220+++ linux-3.0.4/arch/x86/kernel/time.c 2011-08-23 21:47:55.000000000 -0400
15221@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs
15222 {
15223 unsigned long pc = instruction_pointer(regs);
15224
15225- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
15226+ if (!user_mode(regs) && in_lock_functions(pc)) {
15227 #ifdef CONFIG_FRAME_POINTER
15228- return *(unsigned long *)(regs->bp + sizeof(long));
15229+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
15230 #else
15231 unsigned long *sp =
15232 (unsigned long *)kernel_stack_pointer(regs);
15233@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
15234 * or above a saved flags. Eflags has bits 22-31 zero,
15235 * kernel addresses don't.
15236 */
15237+
15238+#ifdef CONFIG_PAX_KERNEXEC
15239+ return ktla_ktva(sp[0]);
15240+#else
15241 if (sp[0] >> 22)
15242 return sp[0];
15243 if (sp[1] >> 22)
15244 return sp[1];
15245 #endif
15246+
15247+#endif
15248 }
15249 return pc;
15250 }
15251diff -urNp linux-3.0.4/arch/x86/kernel/tls.c linux-3.0.4/arch/x86/kernel/tls.c
15252--- linux-3.0.4/arch/x86/kernel/tls.c 2011-07-21 22:17:23.000000000 -0400
15253+++ linux-3.0.4/arch/x86/kernel/tls.c 2011-08-23 21:47:55.000000000 -0400
15254@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
15255 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
15256 return -EINVAL;
15257
15258+#ifdef CONFIG_PAX_SEGMEXEC
15259+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
15260+ return -EINVAL;
15261+#endif
15262+
15263 set_tls_desc(p, idx, &info, 1);
15264
15265 return 0;
15266diff -urNp linux-3.0.4/arch/x86/kernel/trampoline_32.S linux-3.0.4/arch/x86/kernel/trampoline_32.S
15267--- linux-3.0.4/arch/x86/kernel/trampoline_32.S 2011-07-21 22:17:23.000000000 -0400
15268+++ linux-3.0.4/arch/x86/kernel/trampoline_32.S 2011-08-23 21:47:55.000000000 -0400
15269@@ -32,6 +32,12 @@
15270 #include <asm/segment.h>
15271 #include <asm/page_types.h>
15272
15273+#ifdef CONFIG_PAX_KERNEXEC
15274+#define ta(X) (X)
15275+#else
15276+#define ta(X) ((X) - __PAGE_OFFSET)
15277+#endif
15278+
15279 #ifdef CONFIG_SMP
15280
15281 .section ".x86_trampoline","a"
15282@@ -62,7 +68,7 @@ r_base = .
15283 inc %ax # protected mode (PE) bit
15284 lmsw %ax # into protected mode
15285 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
15286- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
15287+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
15288
15289 # These need to be in the same 64K segment as the above;
15290 # hence we don't use the boot_gdt_descr defined in head.S
15291diff -urNp linux-3.0.4/arch/x86/kernel/trampoline_64.S linux-3.0.4/arch/x86/kernel/trampoline_64.S
15292--- linux-3.0.4/arch/x86/kernel/trampoline_64.S 2011-07-21 22:17:23.000000000 -0400
15293+++ linux-3.0.4/arch/x86/kernel/trampoline_64.S 2011-08-23 21:47:55.000000000 -0400
15294@@ -90,7 +90,7 @@ startup_32:
15295 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
15296 movl %eax, %ds
15297
15298- movl $X86_CR4_PAE, %eax
15299+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15300 movl %eax, %cr4 # Enable PAE mode
15301
15302 # Setup trampoline 4 level pagetables
15303@@ -138,7 +138,7 @@ tidt:
15304 # so the kernel can live anywhere
15305 .balign 4
15306 tgdt:
15307- .short tgdt_end - tgdt # gdt limit
15308+ .short tgdt_end - tgdt - 1 # gdt limit
15309 .long tgdt - r_base
15310 .short 0
15311 .quad 0x00cf9b000000ffff # __KERNEL32_CS
15312diff -urNp linux-3.0.4/arch/x86/kernel/traps.c linux-3.0.4/arch/x86/kernel/traps.c
15313--- linux-3.0.4/arch/x86/kernel/traps.c 2011-07-21 22:17:23.000000000 -0400
15314+++ linux-3.0.4/arch/x86/kernel/traps.c 2011-08-23 21:47:55.000000000 -0400
15315@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
15316
15317 /* Do we ignore FPU interrupts ? */
15318 char ignore_fpu_irq;
15319-
15320-/*
15321- * The IDT has to be page-aligned to simplify the Pentium
15322- * F0 0F bug workaround.
15323- */
15324-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
15325 #endif
15326
15327 DECLARE_BITMAP(used_vectors, NR_VECTORS);
15328@@ -117,13 +111,13 @@ static inline void preempt_conditional_c
15329 }
15330
15331 static void __kprobes
15332-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
15333+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
15334 long error_code, siginfo_t *info)
15335 {
15336 struct task_struct *tsk = current;
15337
15338 #ifdef CONFIG_X86_32
15339- if (regs->flags & X86_VM_MASK) {
15340+ if (v8086_mode(regs)) {
15341 /*
15342 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
15343 * On nmi (interrupt 2), do_trap should not be called.
15344@@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str
15345 }
15346 #endif
15347
15348- if (!user_mode(regs))
15349+ if (!user_mode_novm(regs))
15350 goto kernel_trap;
15351
15352 #ifdef CONFIG_X86_32
15353@@ -157,7 +151,7 @@ trap_signal:
15354 printk_ratelimit()) {
15355 printk(KERN_INFO
15356 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
15357- tsk->comm, tsk->pid, str,
15358+ tsk->comm, task_pid_nr(tsk), str,
15359 regs->ip, regs->sp, error_code);
15360 print_vma_addr(" in ", regs->ip);
15361 printk("\n");
15362@@ -174,8 +168,20 @@ kernel_trap:
15363 if (!fixup_exception(regs)) {
15364 tsk->thread.error_code = error_code;
15365 tsk->thread.trap_no = trapnr;
15366+
15367+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15368+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
15369+ str = "PAX: suspicious stack segment fault";
15370+#endif
15371+
15372 die(str, regs, error_code);
15373 }
15374+
15375+#ifdef CONFIG_PAX_REFCOUNT
15376+ if (trapnr == 4)
15377+ pax_report_refcount_overflow(regs);
15378+#endif
15379+
15380 return;
15381
15382 #ifdef CONFIG_X86_32
15383@@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *re
15384 conditional_sti(regs);
15385
15386 #ifdef CONFIG_X86_32
15387- if (regs->flags & X86_VM_MASK)
15388+ if (v8086_mode(regs))
15389 goto gp_in_vm86;
15390 #endif
15391
15392 tsk = current;
15393- if (!user_mode(regs))
15394+ if (!user_mode_novm(regs))
15395 goto gp_in_kernel;
15396
15397+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15398+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
15399+ struct mm_struct *mm = tsk->mm;
15400+ unsigned long limit;
15401+
15402+ down_write(&mm->mmap_sem);
15403+ limit = mm->context.user_cs_limit;
15404+ if (limit < TASK_SIZE) {
15405+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
15406+ up_write(&mm->mmap_sem);
15407+ return;
15408+ }
15409+ up_write(&mm->mmap_sem);
15410+ }
15411+#endif
15412+
15413 tsk->thread.error_code = error_code;
15414 tsk->thread.trap_no = 13;
15415
15416@@ -304,6 +326,13 @@ gp_in_kernel:
15417 if (notify_die(DIE_GPF, "general protection fault", regs,
15418 error_code, 13, SIGSEGV) == NOTIFY_STOP)
15419 return;
15420+
15421+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15422+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
15423+ die("PAX: suspicious general protection fault", regs, error_code);
15424+ else
15425+#endif
15426+
15427 die("general protection fault", regs, error_code);
15428 }
15429
15430@@ -433,6 +462,17 @@ static notrace __kprobes void default_do
15431 dotraplinkage notrace __kprobes void
15432 do_nmi(struct pt_regs *regs, long error_code)
15433 {
15434+
15435+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15436+ if (!user_mode(regs)) {
15437+ unsigned long cs = regs->cs & 0xFFFF;
15438+ unsigned long ip = ktva_ktla(regs->ip);
15439+
15440+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
15441+ regs->ip = ip;
15442+ }
15443+#endif
15444+
15445 nmi_enter();
15446
15447 inc_irq_stat(__nmi_count);
15448@@ -569,7 +609,7 @@ dotraplinkage void __kprobes do_debug(st
15449 /* It's safe to allow irq's after DR6 has been saved */
15450 preempt_conditional_sti(regs);
15451
15452- if (regs->flags & X86_VM_MASK) {
15453+ if (v8086_mode(regs)) {
15454 handle_vm86_trap((struct kernel_vm86_regs *) regs,
15455 error_code, 1);
15456 preempt_conditional_cli(regs);
15457@@ -583,7 +623,7 @@ dotraplinkage void __kprobes do_debug(st
15458 * We already checked v86 mode above, so we can check for kernel mode
15459 * by just checking the CPL of CS.
15460 */
15461- if ((dr6 & DR_STEP) && !user_mode(regs)) {
15462+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
15463 tsk->thread.debugreg6 &= ~DR_STEP;
15464 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
15465 regs->flags &= ~X86_EFLAGS_TF;
15466@@ -612,7 +652,7 @@ void math_error(struct pt_regs *regs, in
15467 return;
15468 conditional_sti(regs);
15469
15470- if (!user_mode_vm(regs))
15471+ if (!user_mode(regs))
15472 {
15473 if (!fixup_exception(regs)) {
15474 task->thread.error_code = error_code;
15475@@ -723,7 +763,7 @@ asmlinkage void __attribute__((weak)) sm
15476 void __math_state_restore(void)
15477 {
15478 struct thread_info *thread = current_thread_info();
15479- struct task_struct *tsk = thread->task;
15480+ struct task_struct *tsk = current;
15481
15482 /*
15483 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
15484@@ -750,8 +790,7 @@ void __math_state_restore(void)
15485 */
15486 asmlinkage void math_state_restore(void)
15487 {
15488- struct thread_info *thread = current_thread_info();
15489- struct task_struct *tsk = thread->task;
15490+ struct task_struct *tsk = current;
15491
15492 if (!tsk_used_math(tsk)) {
15493 local_irq_enable();
15494diff -urNp linux-3.0.4/arch/x86/kernel/verify_cpu.S linux-3.0.4/arch/x86/kernel/verify_cpu.S
15495--- linux-3.0.4/arch/x86/kernel/verify_cpu.S 2011-07-21 22:17:23.000000000 -0400
15496+++ linux-3.0.4/arch/x86/kernel/verify_cpu.S 2011-08-23 21:48:14.000000000 -0400
15497@@ -20,6 +20,7 @@
15498 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
15499 * arch/x86/kernel/trampoline_64.S: secondary processor verification
15500 * arch/x86/kernel/head_32.S: processor startup
15501+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
15502 *
15503 * verify_cpu, returns the status of longmode and SSE in register %eax.
15504 * 0: Success 1: Failure
15505diff -urNp linux-3.0.4/arch/x86/kernel/vm86_32.c linux-3.0.4/arch/x86/kernel/vm86_32.c
15506--- linux-3.0.4/arch/x86/kernel/vm86_32.c 2011-07-21 22:17:23.000000000 -0400
15507+++ linux-3.0.4/arch/x86/kernel/vm86_32.c 2011-08-23 21:48:14.000000000 -0400
15508@@ -41,6 +41,7 @@
15509 #include <linux/ptrace.h>
15510 #include <linux/audit.h>
15511 #include <linux/stddef.h>
15512+#include <linux/grsecurity.h>
15513
15514 #include <asm/uaccess.h>
15515 #include <asm/io.h>
15516@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
15517 do_exit(SIGSEGV);
15518 }
15519
15520- tss = &per_cpu(init_tss, get_cpu());
15521+ tss = init_tss + get_cpu();
15522 current->thread.sp0 = current->thread.saved_sp0;
15523 current->thread.sysenter_cs = __KERNEL_CS;
15524 load_sp0(tss, &current->thread);
15525@@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __use
15526 struct task_struct *tsk;
15527 int tmp, ret = -EPERM;
15528
15529+#ifdef CONFIG_GRKERNSEC_VM86
15530+ if (!capable(CAP_SYS_RAWIO)) {
15531+ gr_handle_vm86();
15532+ goto out;
15533+ }
15534+#endif
15535+
15536 tsk = current;
15537 if (tsk->thread.saved_sp0)
15538 goto out;
15539@@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned
15540 int tmp, ret;
15541 struct vm86plus_struct __user *v86;
15542
15543+#ifdef CONFIG_GRKERNSEC_VM86
15544+ if (!capable(CAP_SYS_RAWIO)) {
15545+ gr_handle_vm86();
15546+ ret = -EPERM;
15547+ goto out;
15548+ }
15549+#endif
15550+
15551 tsk = current;
15552 switch (cmd) {
15553 case VM86_REQUEST_IRQ:
15554@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
15555 tsk->thread.saved_fs = info->regs32->fs;
15556 tsk->thread.saved_gs = get_user_gs(info->regs32);
15557
15558- tss = &per_cpu(init_tss, get_cpu());
15559+ tss = init_tss + get_cpu();
15560 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
15561 if (cpu_has_sep)
15562 tsk->thread.sysenter_cs = 0;
15563@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
15564 goto cannot_handle;
15565 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
15566 goto cannot_handle;
15567- intr_ptr = (unsigned long __user *) (i << 2);
15568+ intr_ptr = (__force unsigned long __user *) (i << 2);
15569 if (get_user(segoffs, intr_ptr))
15570 goto cannot_handle;
15571 if ((segoffs >> 16) == BIOSSEG)
15572diff -urNp linux-3.0.4/arch/x86/kernel/vmlinux.lds.S linux-3.0.4/arch/x86/kernel/vmlinux.lds.S
15573--- linux-3.0.4/arch/x86/kernel/vmlinux.lds.S 2011-07-21 22:17:23.000000000 -0400
15574+++ linux-3.0.4/arch/x86/kernel/vmlinux.lds.S 2011-08-23 21:47:55.000000000 -0400
15575@@ -26,6 +26,13 @@
15576 #include <asm/page_types.h>
15577 #include <asm/cache.h>
15578 #include <asm/boot.h>
15579+#include <asm/segment.h>
15580+
15581+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15582+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
15583+#else
15584+#define __KERNEL_TEXT_OFFSET 0
15585+#endif
15586
15587 #undef i386 /* in case the preprocessor is a 32bit one */
15588
15589@@ -69,31 +76,46 @@ jiffies_64 = jiffies;
15590
15591 PHDRS {
15592 text PT_LOAD FLAGS(5); /* R_E */
15593+#ifdef CONFIG_X86_32
15594+ module PT_LOAD FLAGS(5); /* R_E */
15595+#endif
15596+#ifdef CONFIG_XEN
15597+ rodata PT_LOAD FLAGS(5); /* R_E */
15598+#else
15599+ rodata PT_LOAD FLAGS(4); /* R__ */
15600+#endif
15601 data PT_LOAD FLAGS(6); /* RW_ */
15602 #ifdef CONFIG_X86_64
15603 user PT_LOAD FLAGS(5); /* R_E */
15604+#endif
15605+ init.begin PT_LOAD FLAGS(6); /* RW_ */
15606 #ifdef CONFIG_SMP
15607 percpu PT_LOAD FLAGS(6); /* RW_ */
15608 #endif
15609+ text.init PT_LOAD FLAGS(5); /* R_E */
15610+ text.exit PT_LOAD FLAGS(5); /* R_E */
15611 init PT_LOAD FLAGS(7); /* RWE */
15612-#endif
15613 note PT_NOTE FLAGS(0); /* ___ */
15614 }
15615
15616 SECTIONS
15617 {
15618 #ifdef CONFIG_X86_32
15619- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
15620- phys_startup_32 = startup_32 - LOAD_OFFSET;
15621+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
15622 #else
15623- . = __START_KERNEL;
15624- phys_startup_64 = startup_64 - LOAD_OFFSET;
15625+ . = __START_KERNEL;
15626 #endif
15627
15628 /* Text and read-only data */
15629- .text : AT(ADDR(.text) - LOAD_OFFSET) {
15630- _text = .;
15631+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
15632 /* bootstrapping code */
15633+#ifdef CONFIG_X86_32
15634+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
15635+#else
15636+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
15637+#endif
15638+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
15639+ _text = .;
15640 HEAD_TEXT
15641 #ifdef CONFIG_X86_32
15642 . = ALIGN(PAGE_SIZE);
15643@@ -109,13 +131,47 @@ SECTIONS
15644 IRQENTRY_TEXT
15645 *(.fixup)
15646 *(.gnu.warning)
15647- /* End of text section */
15648- _etext = .;
15649 } :text = 0x9090
15650
15651- NOTES :text :note
15652+ . += __KERNEL_TEXT_OFFSET;
15653+
15654+#ifdef CONFIG_X86_32
15655+ . = ALIGN(PAGE_SIZE);
15656+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
15657+
15658+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
15659+ MODULES_EXEC_VADDR = .;
15660+ BYTE(0)
15661+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
15662+ . = ALIGN(HPAGE_SIZE);
15663+ MODULES_EXEC_END = . - 1;
15664+#endif
15665+
15666+ } :module
15667+#endif
15668+
15669+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
15670+ /* End of text section */
15671+ _etext = . - __KERNEL_TEXT_OFFSET;
15672+ }
15673+
15674+#ifdef CONFIG_X86_32
15675+ . = ALIGN(PAGE_SIZE);
15676+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
15677+ *(.idt)
15678+ . = ALIGN(PAGE_SIZE);
15679+ *(.empty_zero_page)
15680+ *(.initial_pg_fixmap)
15681+ *(.initial_pg_pmd)
15682+ *(.initial_page_table)
15683+ *(.swapper_pg_dir)
15684+ } :rodata
15685+#endif
15686+
15687+ . = ALIGN(PAGE_SIZE);
15688+ NOTES :rodata :note
15689
15690- EXCEPTION_TABLE(16) :text = 0x9090
15691+ EXCEPTION_TABLE(16) :rodata
15692
15693 #if defined(CONFIG_DEBUG_RODATA)
15694 /* .text should occupy whole number of pages */
15695@@ -127,16 +183,20 @@ SECTIONS
15696
15697 /* Data */
15698 .data : AT(ADDR(.data) - LOAD_OFFSET) {
15699+
15700+#ifdef CONFIG_PAX_KERNEXEC
15701+ . = ALIGN(HPAGE_SIZE);
15702+#else
15703+ . = ALIGN(PAGE_SIZE);
15704+#endif
15705+
15706 /* Start of data section */
15707 _sdata = .;
15708
15709 /* init_task */
15710 INIT_TASK_DATA(THREAD_SIZE)
15711
15712-#ifdef CONFIG_X86_32
15713- /* 32 bit has nosave before _edata */
15714 NOSAVE_DATA
15715-#endif
15716
15717 PAGE_ALIGNED_DATA(PAGE_SIZE)
15718
15719@@ -208,12 +268,19 @@ SECTIONS
15720 #endif /* CONFIG_X86_64 */
15721
15722 /* Init code and data - will be freed after init */
15723- . = ALIGN(PAGE_SIZE);
15724 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
15725+ BYTE(0)
15726+
15727+#ifdef CONFIG_PAX_KERNEXEC
15728+ . = ALIGN(HPAGE_SIZE);
15729+#else
15730+ . = ALIGN(PAGE_SIZE);
15731+#endif
15732+
15733 __init_begin = .; /* paired with __init_end */
15734- }
15735+ } :init.begin
15736
15737-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
15738+#ifdef CONFIG_SMP
15739 /*
15740 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
15741 * output PHDR, so the next output section - .init.text - should
15742@@ -222,12 +289,27 @@ SECTIONS
15743 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
15744 #endif
15745
15746- INIT_TEXT_SECTION(PAGE_SIZE)
15747-#ifdef CONFIG_X86_64
15748- :init
15749-#endif
15750+ . = ALIGN(PAGE_SIZE);
15751+ init_begin = .;
15752+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
15753+ VMLINUX_SYMBOL(_sinittext) = .;
15754+ INIT_TEXT
15755+ VMLINUX_SYMBOL(_einittext) = .;
15756+ . = ALIGN(PAGE_SIZE);
15757+ } :text.init
15758
15759- INIT_DATA_SECTION(16)
15760+ /*
15761+ * .exit.text is discard at runtime, not link time, to deal with
15762+ * references from .altinstructions and .eh_frame
15763+ */
15764+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
15765+ EXIT_TEXT
15766+ . = ALIGN(16);
15767+ } :text.exit
15768+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
15769+
15770+ . = ALIGN(PAGE_SIZE);
15771+ INIT_DATA_SECTION(16) :init
15772
15773 /*
15774 * Code and data for a variety of lowlevel trampolines, to be
15775@@ -301,19 +383,12 @@ SECTIONS
15776 }
15777
15778 . = ALIGN(8);
15779- /*
15780- * .exit.text is discard at runtime, not link time, to deal with
15781- * references from .altinstructions and .eh_frame
15782- */
15783- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
15784- EXIT_TEXT
15785- }
15786
15787 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
15788 EXIT_DATA
15789 }
15790
15791-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
15792+#ifndef CONFIG_SMP
15793 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
15794 #endif
15795
15796@@ -332,16 +407,10 @@ SECTIONS
15797 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
15798 __smp_locks = .;
15799 *(.smp_locks)
15800- . = ALIGN(PAGE_SIZE);
15801 __smp_locks_end = .;
15802+ . = ALIGN(PAGE_SIZE);
15803 }
15804
15805-#ifdef CONFIG_X86_64
15806- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
15807- NOSAVE_DATA
15808- }
15809-#endif
15810-
15811 /* BSS */
15812 . = ALIGN(PAGE_SIZE);
15813 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
15814@@ -357,6 +426,7 @@ SECTIONS
15815 __brk_base = .;
15816 . += 64 * 1024; /* 64k alignment slop space */
15817 *(.brk_reservation) /* areas brk users have reserved */
15818+ . = ALIGN(HPAGE_SIZE);
15819 __brk_limit = .;
15820 }
15821
15822@@ -383,13 +453,12 @@ SECTIONS
15823 * for the boot processor.
15824 */
15825 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
15826-INIT_PER_CPU(gdt_page);
15827 INIT_PER_CPU(irq_stack_union);
15828
15829 /*
15830 * Build-time check on the image size:
15831 */
15832-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
15833+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
15834 "kernel image bigger than KERNEL_IMAGE_SIZE");
15835
15836 #ifdef CONFIG_SMP
15837diff -urNp linux-3.0.4/arch/x86/kernel/vsyscall_64.c linux-3.0.4/arch/x86/kernel/vsyscall_64.c
15838--- linux-3.0.4/arch/x86/kernel/vsyscall_64.c 2011-07-21 22:17:23.000000000 -0400
15839+++ linux-3.0.4/arch/x86/kernel/vsyscall_64.c 2011-08-23 21:47:55.000000000 -0400
15840@@ -53,7 +53,7 @@ DEFINE_VVAR(int, vgetcpu_mode);
15841 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
15842 {
15843 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
15844- .sysctl_enabled = 1,
15845+ .sysctl_enabled = 0,
15846 };
15847
15848 void update_vsyscall_tz(void)
15849@@ -231,7 +231,7 @@ static long __vsyscall(3) venosys_1(void
15850 static ctl_table kernel_table2[] = {
15851 { .procname = "vsyscall64",
15852 .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int),
15853- .mode = 0644,
15854+ .mode = 0444,
15855 .proc_handler = proc_dointvec },
15856 {}
15857 };
15858diff -urNp linux-3.0.4/arch/x86/kernel/x8664_ksyms_64.c linux-3.0.4/arch/x86/kernel/x8664_ksyms_64.c
15859--- linux-3.0.4/arch/x86/kernel/x8664_ksyms_64.c 2011-07-21 22:17:23.000000000 -0400
15860+++ linux-3.0.4/arch/x86/kernel/x8664_ksyms_64.c 2011-08-23 21:47:55.000000000 -0400
15861@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
15862 EXPORT_SYMBOL(copy_user_generic_string);
15863 EXPORT_SYMBOL(copy_user_generic_unrolled);
15864 EXPORT_SYMBOL(__copy_user_nocache);
15865-EXPORT_SYMBOL(_copy_from_user);
15866-EXPORT_SYMBOL(_copy_to_user);
15867
15868 EXPORT_SYMBOL(copy_page);
15869 EXPORT_SYMBOL(clear_page);
15870diff -urNp linux-3.0.4/arch/x86/kernel/xsave.c linux-3.0.4/arch/x86/kernel/xsave.c
15871--- linux-3.0.4/arch/x86/kernel/xsave.c 2011-07-21 22:17:23.000000000 -0400
15872+++ linux-3.0.4/arch/x86/kernel/xsave.c 2011-08-23 21:47:55.000000000 -0400
15873@@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
15874 fx_sw_user->xstate_size > fx_sw_user->extended_size)
15875 return -EINVAL;
15876
15877- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
15878+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
15879 fx_sw_user->extended_size -
15880 FP_XSTATE_MAGIC2_SIZE));
15881 if (err)
15882@@ -267,7 +267,7 @@ fx_only:
15883 * the other extended state.
15884 */
15885 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
15886- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
15887+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
15888 }
15889
15890 /*
15891@@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
15892 if (use_xsave())
15893 err = restore_user_xstate(buf);
15894 else
15895- err = fxrstor_checking((__force struct i387_fxsave_struct *)
15896+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
15897 buf);
15898 if (unlikely(err)) {
15899 /*
15900diff -urNp linux-3.0.4/arch/x86/kvm/emulate.c linux-3.0.4/arch/x86/kvm/emulate.c
15901--- linux-3.0.4/arch/x86/kvm/emulate.c 2011-07-21 22:17:23.000000000 -0400
15902+++ linux-3.0.4/arch/x86/kvm/emulate.c 2011-08-23 21:47:55.000000000 -0400
15903@@ -96,7 +96,7 @@
15904 #define Src2ImmByte (2<<29)
15905 #define Src2One (3<<29)
15906 #define Src2Imm (4<<29)
15907-#define Src2Mask (7<<29)
15908+#define Src2Mask (7U<<29)
15909
15910 #define X2(x...) x, x
15911 #define X3(x...) X2(x), x
15912@@ -207,6 +207,7 @@ struct gprefix {
15913
15914 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
15915 do { \
15916+ unsigned long _tmp; \
15917 __asm__ __volatile__ ( \
15918 _PRE_EFLAGS("0", "4", "2") \
15919 _op _suffix " %"_x"3,%1; " \
15920@@ -220,8 +221,6 @@ struct gprefix {
15921 /* Raw emulation: instruction has two explicit operands. */
15922 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
15923 do { \
15924- unsigned long _tmp; \
15925- \
15926 switch ((_dst).bytes) { \
15927 case 2: \
15928 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
15929@@ -237,7 +236,6 @@ struct gprefix {
15930
15931 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
15932 do { \
15933- unsigned long _tmp; \
15934 switch ((_dst).bytes) { \
15935 case 1: \
15936 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
15937diff -urNp linux-3.0.4/arch/x86/kvm/lapic.c linux-3.0.4/arch/x86/kvm/lapic.c
15938--- linux-3.0.4/arch/x86/kvm/lapic.c 2011-07-21 22:17:23.000000000 -0400
15939+++ linux-3.0.4/arch/x86/kvm/lapic.c 2011-08-23 21:47:55.000000000 -0400
15940@@ -53,7 +53,7 @@
15941 #define APIC_BUS_CYCLE_NS 1
15942
15943 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
15944-#define apic_debug(fmt, arg...)
15945+#define apic_debug(fmt, arg...) do {} while (0)
15946
15947 #define APIC_LVT_NUM 6
15948 /* 14 is the version for Xeon and Pentium 8.4.8*/
15949diff -urNp linux-3.0.4/arch/x86/kvm/mmu.c linux-3.0.4/arch/x86/kvm/mmu.c
15950--- linux-3.0.4/arch/x86/kvm/mmu.c 2011-07-21 22:17:23.000000000 -0400
15951+++ linux-3.0.4/arch/x86/kvm/mmu.c 2011-08-23 21:47:55.000000000 -0400
15952@@ -3238,7 +3238,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
15953
15954 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
15955
15956- invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
15957+ invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
15958
15959 /*
15960 * Assume that the pte write on a page table of the same type
15961@@ -3270,7 +3270,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
15962 }
15963
15964 spin_lock(&vcpu->kvm->mmu_lock);
15965- if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
15966+ if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
15967 gentry = 0;
15968 kvm_mmu_free_some_pages(vcpu);
15969 ++vcpu->kvm->stat.mmu_pte_write;
15970diff -urNp linux-3.0.4/arch/x86/kvm/paging_tmpl.h linux-3.0.4/arch/x86/kvm/paging_tmpl.h
15971--- linux-3.0.4/arch/x86/kvm/paging_tmpl.h 2011-07-21 22:17:23.000000000 -0400
15972+++ linux-3.0.4/arch/x86/kvm/paging_tmpl.h 2011-08-23 21:48:14.000000000 -0400
15973@@ -583,6 +583,8 @@ static int FNAME(page_fault)(struct kvm_
15974 unsigned long mmu_seq;
15975 bool map_writable;
15976
15977+ pax_track_stack();
15978+
15979 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
15980
15981 r = mmu_topup_memory_caches(vcpu);
15982@@ -703,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcp
15983 if (need_flush)
15984 kvm_flush_remote_tlbs(vcpu->kvm);
15985
15986- atomic_inc(&vcpu->kvm->arch.invlpg_counter);
15987+ atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
15988
15989 spin_unlock(&vcpu->kvm->mmu_lock);
15990
15991diff -urNp linux-3.0.4/arch/x86/kvm/svm.c linux-3.0.4/arch/x86/kvm/svm.c
15992--- linux-3.0.4/arch/x86/kvm/svm.c 2011-07-21 22:17:23.000000000 -0400
15993+++ linux-3.0.4/arch/x86/kvm/svm.c 2011-08-23 21:47:55.000000000 -0400
15994@@ -3377,7 +3377,11 @@ static void reload_tss(struct kvm_vcpu *
15995 int cpu = raw_smp_processor_id();
15996
15997 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
15998+
15999+ pax_open_kernel();
16000 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
16001+ pax_close_kernel();
16002+
16003 load_TR_desc();
16004 }
16005
16006@@ -3755,6 +3759,10 @@ static void svm_vcpu_run(struct kvm_vcpu
16007 #endif
16008 #endif
16009
16010+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16011+ __set_fs(current_thread_info()->addr_limit);
16012+#endif
16013+
16014 reload_tss(vcpu);
16015
16016 local_irq_disable();
16017diff -urNp linux-3.0.4/arch/x86/kvm/vmx.c linux-3.0.4/arch/x86/kvm/vmx.c
16018--- linux-3.0.4/arch/x86/kvm/vmx.c 2011-07-21 22:17:23.000000000 -0400
16019+++ linux-3.0.4/arch/x86/kvm/vmx.c 2011-08-23 21:47:55.000000000 -0400
16020@@ -797,7 +797,11 @@ static void reload_tss(void)
16021 struct desc_struct *descs;
16022
16023 descs = (void *)gdt->address;
16024+
16025+ pax_open_kernel();
16026 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
16027+ pax_close_kernel();
16028+
16029 load_TR_desc();
16030 }
16031
16032@@ -1747,8 +1751,11 @@ static __init int hardware_setup(void)
16033 if (!cpu_has_vmx_flexpriority())
16034 flexpriority_enabled = 0;
16035
16036- if (!cpu_has_vmx_tpr_shadow())
16037- kvm_x86_ops->update_cr8_intercept = NULL;
16038+ if (!cpu_has_vmx_tpr_shadow()) {
16039+ pax_open_kernel();
16040+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
16041+ pax_close_kernel();
16042+ }
16043
16044 if (enable_ept && !cpu_has_vmx_ept_2m_page())
16045 kvm_disable_largepages();
16046@@ -2814,7 +2821,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
16047 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
16048
16049 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
16050- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
16051+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
16052 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
16053 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
16054 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
16055@@ -4211,6 +4218,12 @@ static void __noclone vmx_vcpu_run(struc
16056 "jmp .Lkvm_vmx_return \n\t"
16057 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
16058 ".Lkvm_vmx_return: "
16059+
16060+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16061+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
16062+ ".Lkvm_vmx_return2: "
16063+#endif
16064+
16065 /* Save guest registers, load host registers, keep flags */
16066 "mov %0, %c[wordsize](%%"R"sp) \n\t"
16067 "pop %0 \n\t"
16068@@ -4259,6 +4272,11 @@ static void __noclone vmx_vcpu_run(struc
16069 #endif
16070 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
16071 [wordsize]"i"(sizeof(ulong))
16072+
16073+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16074+ ,[cs]"i"(__KERNEL_CS)
16075+#endif
16076+
16077 : "cc", "memory"
16078 , R"ax", R"bx", R"di", R"si"
16079 #ifdef CONFIG_X86_64
16080@@ -4276,7 +4294,16 @@ static void __noclone vmx_vcpu_run(struc
16081
16082 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
16083
16084- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
16085+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
16086+
16087+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16088+ loadsegment(fs, __KERNEL_PERCPU);
16089+#endif
16090+
16091+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16092+ __set_fs(current_thread_info()->addr_limit);
16093+#endif
16094+
16095 vmx->launched = 1;
16096
16097 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
16098diff -urNp linux-3.0.4/arch/x86/kvm/x86.c linux-3.0.4/arch/x86/kvm/x86.c
16099--- linux-3.0.4/arch/x86/kvm/x86.c 2011-07-21 22:17:23.000000000 -0400
16100+++ linux-3.0.4/arch/x86/kvm/x86.c 2011-08-23 21:47:55.000000000 -0400
16101@@ -2057,6 +2057,8 @@ long kvm_arch_dev_ioctl(struct file *fil
16102 if (n < msr_list.nmsrs)
16103 goto out;
16104 r = -EFAULT;
16105+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
16106+ goto out;
16107 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
16108 num_msrs_to_save * sizeof(u32)))
16109 goto out;
16110@@ -2229,15 +2231,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
16111 struct kvm_cpuid2 *cpuid,
16112 struct kvm_cpuid_entry2 __user *entries)
16113 {
16114- int r;
16115+ int r, i;
16116
16117 r = -E2BIG;
16118 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
16119 goto out;
16120 r = -EFAULT;
16121- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
16122- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
16123+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
16124 goto out;
16125+ for (i = 0; i < cpuid->nent; ++i) {
16126+ struct kvm_cpuid_entry2 cpuid_entry;
16127+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
16128+ goto out;
16129+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
16130+ }
16131 vcpu->arch.cpuid_nent = cpuid->nent;
16132 kvm_apic_set_version(vcpu);
16133 kvm_x86_ops->cpuid_update(vcpu);
16134@@ -2252,15 +2259,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
16135 struct kvm_cpuid2 *cpuid,
16136 struct kvm_cpuid_entry2 __user *entries)
16137 {
16138- int r;
16139+ int r, i;
16140
16141 r = -E2BIG;
16142 if (cpuid->nent < vcpu->arch.cpuid_nent)
16143 goto out;
16144 r = -EFAULT;
16145- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
16146- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
16147+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
16148 goto out;
16149+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
16150+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
16151+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
16152+ goto out;
16153+ }
16154 return 0;
16155
16156 out:
16157@@ -2579,7 +2590,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
16158 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
16159 struct kvm_interrupt *irq)
16160 {
16161- if (irq->irq < 0 || irq->irq >= 256)
16162+ if (irq->irq >= 256)
16163 return -EINVAL;
16164 if (irqchip_in_kernel(vcpu->kvm))
16165 return -ENXIO;
16166@@ -4878,7 +4889,7 @@ void kvm_after_handle_nmi(struct kvm_vcp
16167 }
16168 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
16169
16170-int kvm_arch_init(void *opaque)
16171+int kvm_arch_init(const void *opaque)
16172 {
16173 int r;
16174 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
16175diff -urNp linux-3.0.4/arch/x86/lguest/boot.c linux-3.0.4/arch/x86/lguest/boot.c
16176--- linux-3.0.4/arch/x86/lguest/boot.c 2011-07-21 22:17:23.000000000 -0400
16177+++ linux-3.0.4/arch/x86/lguest/boot.c 2011-08-23 21:47:55.000000000 -0400
16178@@ -1176,9 +1176,10 @@ static __init int early_put_chars(u32 vt
16179 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
16180 * Launcher to reboot us.
16181 */
16182-static void lguest_restart(char *reason)
16183+static __noreturn void lguest_restart(char *reason)
16184 {
16185 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
16186+ BUG();
16187 }
16188
16189 /*G:050
16190diff -urNp linux-3.0.4/arch/x86/lib/atomic64_32.c linux-3.0.4/arch/x86/lib/atomic64_32.c
16191--- linux-3.0.4/arch/x86/lib/atomic64_32.c 2011-07-21 22:17:23.000000000 -0400
16192+++ linux-3.0.4/arch/x86/lib/atomic64_32.c 2011-08-23 21:47:55.000000000 -0400
16193@@ -8,18 +8,30 @@
16194
16195 long long atomic64_read_cx8(long long, const atomic64_t *v);
16196 EXPORT_SYMBOL(atomic64_read_cx8);
16197+long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
16198+EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
16199 long long atomic64_set_cx8(long long, const atomic64_t *v);
16200 EXPORT_SYMBOL(atomic64_set_cx8);
16201+long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
16202+EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
16203 long long atomic64_xchg_cx8(long long, unsigned high);
16204 EXPORT_SYMBOL(atomic64_xchg_cx8);
16205 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
16206 EXPORT_SYMBOL(atomic64_add_return_cx8);
16207+long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
16208+EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
16209 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
16210 EXPORT_SYMBOL(atomic64_sub_return_cx8);
16211+long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
16212+EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
16213 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
16214 EXPORT_SYMBOL(atomic64_inc_return_cx8);
16215+long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
16216+EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
16217 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
16218 EXPORT_SYMBOL(atomic64_dec_return_cx8);
16219+long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
16220+EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
16221 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
16222 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
16223 int atomic64_inc_not_zero_cx8(atomic64_t *v);
16224@@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
16225 #ifndef CONFIG_X86_CMPXCHG64
16226 long long atomic64_read_386(long long, const atomic64_t *v);
16227 EXPORT_SYMBOL(atomic64_read_386);
16228+long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
16229+EXPORT_SYMBOL(atomic64_read_unchecked_386);
16230 long long atomic64_set_386(long long, const atomic64_t *v);
16231 EXPORT_SYMBOL(atomic64_set_386);
16232+long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
16233+EXPORT_SYMBOL(atomic64_set_unchecked_386);
16234 long long atomic64_xchg_386(long long, unsigned high);
16235 EXPORT_SYMBOL(atomic64_xchg_386);
16236 long long atomic64_add_return_386(long long a, atomic64_t *v);
16237 EXPORT_SYMBOL(atomic64_add_return_386);
16238+long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
16239+EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
16240 long long atomic64_sub_return_386(long long a, atomic64_t *v);
16241 EXPORT_SYMBOL(atomic64_sub_return_386);
16242+long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
16243+EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
16244 long long atomic64_inc_return_386(long long a, atomic64_t *v);
16245 EXPORT_SYMBOL(atomic64_inc_return_386);
16246+long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
16247+EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
16248 long long atomic64_dec_return_386(long long a, atomic64_t *v);
16249 EXPORT_SYMBOL(atomic64_dec_return_386);
16250+long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
16251+EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
16252 long long atomic64_add_386(long long a, atomic64_t *v);
16253 EXPORT_SYMBOL(atomic64_add_386);
16254+long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
16255+EXPORT_SYMBOL(atomic64_add_unchecked_386);
16256 long long atomic64_sub_386(long long a, atomic64_t *v);
16257 EXPORT_SYMBOL(atomic64_sub_386);
16258+long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
16259+EXPORT_SYMBOL(atomic64_sub_unchecked_386);
16260 long long atomic64_inc_386(long long a, atomic64_t *v);
16261 EXPORT_SYMBOL(atomic64_inc_386);
16262+long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
16263+EXPORT_SYMBOL(atomic64_inc_unchecked_386);
16264 long long atomic64_dec_386(long long a, atomic64_t *v);
16265 EXPORT_SYMBOL(atomic64_dec_386);
16266+long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
16267+EXPORT_SYMBOL(atomic64_dec_unchecked_386);
16268 long long atomic64_dec_if_positive_386(atomic64_t *v);
16269 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
16270 int atomic64_inc_not_zero_386(atomic64_t *v);
16271diff -urNp linux-3.0.4/arch/x86/lib/atomic64_386_32.S linux-3.0.4/arch/x86/lib/atomic64_386_32.S
16272--- linux-3.0.4/arch/x86/lib/atomic64_386_32.S 2011-07-21 22:17:23.000000000 -0400
16273+++ linux-3.0.4/arch/x86/lib/atomic64_386_32.S 2011-08-23 21:47:55.000000000 -0400
16274@@ -48,6 +48,10 @@ BEGIN(read)
16275 movl (v), %eax
16276 movl 4(v), %edx
16277 RET_ENDP
16278+BEGIN(read_unchecked)
16279+ movl (v), %eax
16280+ movl 4(v), %edx
16281+RET_ENDP
16282 #undef v
16283
16284 #define v %esi
16285@@ -55,6 +59,10 @@ BEGIN(set)
16286 movl %ebx, (v)
16287 movl %ecx, 4(v)
16288 RET_ENDP
16289+BEGIN(set_unchecked)
16290+ movl %ebx, (v)
16291+ movl %ecx, 4(v)
16292+RET_ENDP
16293 #undef v
16294
16295 #define v %esi
16296@@ -70,6 +78,20 @@ RET_ENDP
16297 BEGIN(add)
16298 addl %eax, (v)
16299 adcl %edx, 4(v)
16300+
16301+#ifdef CONFIG_PAX_REFCOUNT
16302+ jno 0f
16303+ subl %eax, (v)
16304+ sbbl %edx, 4(v)
16305+ int $4
16306+0:
16307+ _ASM_EXTABLE(0b, 0b)
16308+#endif
16309+
16310+RET_ENDP
16311+BEGIN(add_unchecked)
16312+ addl %eax, (v)
16313+ adcl %edx, 4(v)
16314 RET_ENDP
16315 #undef v
16316
16317@@ -77,6 +99,24 @@ RET_ENDP
16318 BEGIN(add_return)
16319 addl (v), %eax
16320 adcl 4(v), %edx
16321+
16322+#ifdef CONFIG_PAX_REFCOUNT
16323+ into
16324+1234:
16325+ _ASM_EXTABLE(1234b, 2f)
16326+#endif
16327+
16328+ movl %eax, (v)
16329+ movl %edx, 4(v)
16330+
16331+#ifdef CONFIG_PAX_REFCOUNT
16332+2:
16333+#endif
16334+
16335+RET_ENDP
16336+BEGIN(add_return_unchecked)
16337+ addl (v), %eax
16338+ adcl 4(v), %edx
16339 movl %eax, (v)
16340 movl %edx, 4(v)
16341 RET_ENDP
16342@@ -86,6 +126,20 @@ RET_ENDP
16343 BEGIN(sub)
16344 subl %eax, (v)
16345 sbbl %edx, 4(v)
16346+
16347+#ifdef CONFIG_PAX_REFCOUNT
16348+ jno 0f
16349+ addl %eax, (v)
16350+ adcl %edx, 4(v)
16351+ int $4
16352+0:
16353+ _ASM_EXTABLE(0b, 0b)
16354+#endif
16355+
16356+RET_ENDP
16357+BEGIN(sub_unchecked)
16358+ subl %eax, (v)
16359+ sbbl %edx, 4(v)
16360 RET_ENDP
16361 #undef v
16362
16363@@ -96,6 +150,27 @@ BEGIN(sub_return)
16364 sbbl $0, %edx
16365 addl (v), %eax
16366 adcl 4(v), %edx
16367+
16368+#ifdef CONFIG_PAX_REFCOUNT
16369+ into
16370+1234:
16371+ _ASM_EXTABLE(1234b, 2f)
16372+#endif
16373+
16374+ movl %eax, (v)
16375+ movl %edx, 4(v)
16376+
16377+#ifdef CONFIG_PAX_REFCOUNT
16378+2:
16379+#endif
16380+
16381+RET_ENDP
16382+BEGIN(sub_return_unchecked)
16383+ negl %edx
16384+ negl %eax
16385+ sbbl $0, %edx
16386+ addl (v), %eax
16387+ adcl 4(v), %edx
16388 movl %eax, (v)
16389 movl %edx, 4(v)
16390 RET_ENDP
16391@@ -105,6 +180,20 @@ RET_ENDP
16392 BEGIN(inc)
16393 addl $1, (v)
16394 adcl $0, 4(v)
16395+
16396+#ifdef CONFIG_PAX_REFCOUNT
16397+ jno 0f
16398+ subl $1, (v)
16399+ sbbl $0, 4(v)
16400+ int $4
16401+0:
16402+ _ASM_EXTABLE(0b, 0b)
16403+#endif
16404+
16405+RET_ENDP
16406+BEGIN(inc_unchecked)
16407+ addl $1, (v)
16408+ adcl $0, 4(v)
16409 RET_ENDP
16410 #undef v
16411
16412@@ -114,6 +203,26 @@ BEGIN(inc_return)
16413 movl 4(v), %edx
16414 addl $1, %eax
16415 adcl $0, %edx
16416+
16417+#ifdef CONFIG_PAX_REFCOUNT
16418+ into
16419+1234:
16420+ _ASM_EXTABLE(1234b, 2f)
16421+#endif
16422+
16423+ movl %eax, (v)
16424+ movl %edx, 4(v)
16425+
16426+#ifdef CONFIG_PAX_REFCOUNT
16427+2:
16428+#endif
16429+
16430+RET_ENDP
16431+BEGIN(inc_return_unchecked)
16432+ movl (v), %eax
16433+ movl 4(v), %edx
16434+ addl $1, %eax
16435+ adcl $0, %edx
16436 movl %eax, (v)
16437 movl %edx, 4(v)
16438 RET_ENDP
16439@@ -123,6 +232,20 @@ RET_ENDP
16440 BEGIN(dec)
16441 subl $1, (v)
16442 sbbl $0, 4(v)
16443+
16444+#ifdef CONFIG_PAX_REFCOUNT
16445+ jno 0f
16446+ addl $1, (v)
16447+ adcl $0, 4(v)
16448+ int $4
16449+0:
16450+ _ASM_EXTABLE(0b, 0b)
16451+#endif
16452+
16453+RET_ENDP
16454+BEGIN(dec_unchecked)
16455+ subl $1, (v)
16456+ sbbl $0, 4(v)
16457 RET_ENDP
16458 #undef v
16459
16460@@ -132,6 +255,26 @@ BEGIN(dec_return)
16461 movl 4(v), %edx
16462 subl $1, %eax
16463 sbbl $0, %edx
16464+
16465+#ifdef CONFIG_PAX_REFCOUNT
16466+ into
16467+1234:
16468+ _ASM_EXTABLE(1234b, 2f)
16469+#endif
16470+
16471+ movl %eax, (v)
16472+ movl %edx, 4(v)
16473+
16474+#ifdef CONFIG_PAX_REFCOUNT
16475+2:
16476+#endif
16477+
16478+RET_ENDP
16479+BEGIN(dec_return_unchecked)
16480+ movl (v), %eax
16481+ movl 4(v), %edx
16482+ subl $1, %eax
16483+ sbbl $0, %edx
16484 movl %eax, (v)
16485 movl %edx, 4(v)
16486 RET_ENDP
16487@@ -143,6 +286,13 @@ BEGIN(add_unless)
16488 adcl %edx, %edi
16489 addl (v), %eax
16490 adcl 4(v), %edx
16491+
16492+#ifdef CONFIG_PAX_REFCOUNT
16493+ into
16494+1234:
16495+ _ASM_EXTABLE(1234b, 2f)
16496+#endif
16497+
16498 cmpl %eax, %esi
16499 je 3f
16500 1:
16501@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
16502 1:
16503 addl $1, %eax
16504 adcl $0, %edx
16505+
16506+#ifdef CONFIG_PAX_REFCOUNT
16507+ into
16508+1234:
16509+ _ASM_EXTABLE(1234b, 2f)
16510+#endif
16511+
16512 movl %eax, (v)
16513 movl %edx, 4(v)
16514 movl $1, %eax
16515@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
16516 movl 4(v), %edx
16517 subl $1, %eax
16518 sbbl $0, %edx
16519+
16520+#ifdef CONFIG_PAX_REFCOUNT
16521+ into
16522+1234:
16523+ _ASM_EXTABLE(1234b, 1f)
16524+#endif
16525+
16526 js 1f
16527 movl %eax, (v)
16528 movl %edx, 4(v)
16529diff -urNp linux-3.0.4/arch/x86/lib/atomic64_cx8_32.S linux-3.0.4/arch/x86/lib/atomic64_cx8_32.S
16530--- linux-3.0.4/arch/x86/lib/atomic64_cx8_32.S 2011-07-21 22:17:23.000000000 -0400
16531+++ linux-3.0.4/arch/x86/lib/atomic64_cx8_32.S 2011-08-23 21:47:55.000000000 -0400
16532@@ -39,6 +39,14 @@ ENTRY(atomic64_read_cx8)
16533 CFI_ENDPROC
16534 ENDPROC(atomic64_read_cx8)
16535
16536+ENTRY(atomic64_read_unchecked_cx8)
16537+ CFI_STARTPROC
16538+
16539+ read64 %ecx
16540+ ret
16541+ CFI_ENDPROC
16542+ENDPROC(atomic64_read_unchecked_cx8)
16543+
16544 ENTRY(atomic64_set_cx8)
16545 CFI_STARTPROC
16546
16547@@ -52,6 +60,19 @@ ENTRY(atomic64_set_cx8)
16548 CFI_ENDPROC
16549 ENDPROC(atomic64_set_cx8)
16550
16551+ENTRY(atomic64_set_unchecked_cx8)
16552+ CFI_STARTPROC
16553+
16554+1:
16555+/* we don't need LOCK_PREFIX since aligned 64-bit writes
16556+ * are atomic on 586 and newer */
16557+ cmpxchg8b (%esi)
16558+ jne 1b
16559+
16560+ ret
16561+ CFI_ENDPROC
16562+ENDPROC(atomic64_set_unchecked_cx8)
16563+
16564 ENTRY(atomic64_xchg_cx8)
16565 CFI_STARTPROC
16566
16567@@ -66,8 +87,8 @@ ENTRY(atomic64_xchg_cx8)
16568 CFI_ENDPROC
16569 ENDPROC(atomic64_xchg_cx8)
16570
16571-.macro addsub_return func ins insc
16572-ENTRY(atomic64_\func\()_return_cx8)
16573+.macro addsub_return func ins insc unchecked=""
16574+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
16575 CFI_STARTPROC
16576 SAVE ebp
16577 SAVE ebx
16578@@ -84,27 +105,43 @@ ENTRY(atomic64_\func\()_return_cx8)
16579 movl %edx, %ecx
16580 \ins\()l %esi, %ebx
16581 \insc\()l %edi, %ecx
16582+
16583+.ifb \unchecked
16584+#ifdef CONFIG_PAX_REFCOUNT
16585+ into
16586+2:
16587+ _ASM_EXTABLE(2b, 3f)
16588+#endif
16589+.endif
16590+
16591 LOCK_PREFIX
16592 cmpxchg8b (%ebp)
16593 jne 1b
16594-
16595-10:
16596 movl %ebx, %eax
16597 movl %ecx, %edx
16598+
16599+.ifb \unchecked
16600+#ifdef CONFIG_PAX_REFCOUNT
16601+3:
16602+#endif
16603+.endif
16604+
16605 RESTORE edi
16606 RESTORE esi
16607 RESTORE ebx
16608 RESTORE ebp
16609 ret
16610 CFI_ENDPROC
16611-ENDPROC(atomic64_\func\()_return_cx8)
16612+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
16613 .endm
16614
16615 addsub_return add add adc
16616 addsub_return sub sub sbb
16617+addsub_return add add adc _unchecked
16618+addsub_return sub sub sbb _unchecked
16619
16620-.macro incdec_return func ins insc
16621-ENTRY(atomic64_\func\()_return_cx8)
16622+.macro incdec_return func ins insc unchecked
16623+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
16624 CFI_STARTPROC
16625 SAVE ebx
16626
16627@@ -114,21 +151,38 @@ ENTRY(atomic64_\func\()_return_cx8)
16628 movl %edx, %ecx
16629 \ins\()l $1, %ebx
16630 \insc\()l $0, %ecx
16631+
16632+.ifb \unchecked
16633+#ifdef CONFIG_PAX_REFCOUNT
16634+ into
16635+2:
16636+ _ASM_EXTABLE(2b, 3f)
16637+#endif
16638+.endif
16639+
16640 LOCK_PREFIX
16641 cmpxchg8b (%esi)
16642 jne 1b
16643
16644-10:
16645 movl %ebx, %eax
16646 movl %ecx, %edx
16647+
16648+.ifb \unchecked
16649+#ifdef CONFIG_PAX_REFCOUNT
16650+3:
16651+#endif
16652+.endif
16653+
16654 RESTORE ebx
16655 ret
16656 CFI_ENDPROC
16657-ENDPROC(atomic64_\func\()_return_cx8)
16658+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
16659 .endm
16660
16661 incdec_return inc add adc
16662 incdec_return dec sub sbb
16663+incdec_return inc add adc _unchecked
16664+incdec_return dec sub sbb _unchecked
16665
16666 ENTRY(atomic64_dec_if_positive_cx8)
16667 CFI_STARTPROC
16668@@ -140,6 +194,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
16669 movl %edx, %ecx
16670 subl $1, %ebx
16671 sbb $0, %ecx
16672+
16673+#ifdef CONFIG_PAX_REFCOUNT
16674+ into
16675+1234:
16676+ _ASM_EXTABLE(1234b, 2f)
16677+#endif
16678+
16679 js 2f
16680 LOCK_PREFIX
16681 cmpxchg8b (%esi)
16682@@ -174,6 +235,13 @@ ENTRY(atomic64_add_unless_cx8)
16683 movl %edx, %ecx
16684 addl %esi, %ebx
16685 adcl %edi, %ecx
16686+
16687+#ifdef CONFIG_PAX_REFCOUNT
16688+ into
16689+1234:
16690+ _ASM_EXTABLE(1234b, 3f)
16691+#endif
16692+
16693 LOCK_PREFIX
16694 cmpxchg8b (%ebp)
16695 jne 1b
16696@@ -206,6 +274,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
16697 movl %edx, %ecx
16698 addl $1, %ebx
16699 adcl $0, %ecx
16700+
16701+#ifdef CONFIG_PAX_REFCOUNT
16702+ into
16703+1234:
16704+ _ASM_EXTABLE(1234b, 3f)
16705+#endif
16706+
16707 LOCK_PREFIX
16708 cmpxchg8b (%esi)
16709 jne 1b
16710diff -urNp linux-3.0.4/arch/x86/lib/checksum_32.S linux-3.0.4/arch/x86/lib/checksum_32.S
16711--- linux-3.0.4/arch/x86/lib/checksum_32.S 2011-07-21 22:17:23.000000000 -0400
16712+++ linux-3.0.4/arch/x86/lib/checksum_32.S 2011-08-23 21:47:55.000000000 -0400
16713@@ -28,7 +28,8 @@
16714 #include <linux/linkage.h>
16715 #include <asm/dwarf2.h>
16716 #include <asm/errno.h>
16717-
16718+#include <asm/segment.h>
16719+
16720 /*
16721 * computes a partial checksum, e.g. for TCP/UDP fragments
16722 */
16723@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (
16724
16725 #define ARGBASE 16
16726 #define FP 12
16727-
16728-ENTRY(csum_partial_copy_generic)
16729+
16730+ENTRY(csum_partial_copy_generic_to_user)
16731 CFI_STARTPROC
16732+
16733+#ifdef CONFIG_PAX_MEMORY_UDEREF
16734+ pushl_cfi %gs
16735+ popl_cfi %es
16736+ jmp csum_partial_copy_generic
16737+#endif
16738+
16739+ENTRY(csum_partial_copy_generic_from_user)
16740+
16741+#ifdef CONFIG_PAX_MEMORY_UDEREF
16742+ pushl_cfi %gs
16743+ popl_cfi %ds
16744+#endif
16745+
16746+ENTRY(csum_partial_copy_generic)
16747 subl $4,%esp
16748 CFI_ADJUST_CFA_OFFSET 4
16749 pushl_cfi %edi
16750@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
16751 jmp 4f
16752 SRC(1: movw (%esi), %bx )
16753 addl $2, %esi
16754-DST( movw %bx, (%edi) )
16755+DST( movw %bx, %es:(%edi) )
16756 addl $2, %edi
16757 addw %bx, %ax
16758 adcl $0, %eax
16759@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
16760 SRC(1: movl (%esi), %ebx )
16761 SRC( movl 4(%esi), %edx )
16762 adcl %ebx, %eax
16763-DST( movl %ebx, (%edi) )
16764+DST( movl %ebx, %es:(%edi) )
16765 adcl %edx, %eax
16766-DST( movl %edx, 4(%edi) )
16767+DST( movl %edx, %es:4(%edi) )
16768
16769 SRC( movl 8(%esi), %ebx )
16770 SRC( movl 12(%esi), %edx )
16771 adcl %ebx, %eax
16772-DST( movl %ebx, 8(%edi) )
16773+DST( movl %ebx, %es:8(%edi) )
16774 adcl %edx, %eax
16775-DST( movl %edx, 12(%edi) )
16776+DST( movl %edx, %es:12(%edi) )
16777
16778 SRC( movl 16(%esi), %ebx )
16779 SRC( movl 20(%esi), %edx )
16780 adcl %ebx, %eax
16781-DST( movl %ebx, 16(%edi) )
16782+DST( movl %ebx, %es:16(%edi) )
16783 adcl %edx, %eax
16784-DST( movl %edx, 20(%edi) )
16785+DST( movl %edx, %es:20(%edi) )
16786
16787 SRC( movl 24(%esi), %ebx )
16788 SRC( movl 28(%esi), %edx )
16789 adcl %ebx, %eax
16790-DST( movl %ebx, 24(%edi) )
16791+DST( movl %ebx, %es:24(%edi) )
16792 adcl %edx, %eax
16793-DST( movl %edx, 28(%edi) )
16794+DST( movl %edx, %es:28(%edi) )
16795
16796 lea 32(%esi), %esi
16797 lea 32(%edi), %edi
16798@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
16799 shrl $2, %edx # This clears CF
16800 SRC(3: movl (%esi), %ebx )
16801 adcl %ebx, %eax
16802-DST( movl %ebx, (%edi) )
16803+DST( movl %ebx, %es:(%edi) )
16804 lea 4(%esi), %esi
16805 lea 4(%edi), %edi
16806 dec %edx
16807@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
16808 jb 5f
16809 SRC( movw (%esi), %cx )
16810 leal 2(%esi), %esi
16811-DST( movw %cx, (%edi) )
16812+DST( movw %cx, %es:(%edi) )
16813 leal 2(%edi), %edi
16814 je 6f
16815 shll $16,%ecx
16816 SRC(5: movb (%esi), %cl )
16817-DST( movb %cl, (%edi) )
16818+DST( movb %cl, %es:(%edi) )
16819 6: addl %ecx, %eax
16820 adcl $0, %eax
16821 7:
16822@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
16823
16824 6001:
16825 movl ARGBASE+20(%esp), %ebx # src_err_ptr
16826- movl $-EFAULT, (%ebx)
16827+ movl $-EFAULT, %ss:(%ebx)
16828
16829 # zero the complete destination - computing the rest
16830 # is too much work
16831@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
16832
16833 6002:
16834 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
16835- movl $-EFAULT,(%ebx)
16836+ movl $-EFAULT,%ss:(%ebx)
16837 jmp 5000b
16838
16839 .previous
16840
16841+ pushl_cfi %ss
16842+ popl_cfi %ds
16843+ pushl_cfi %ss
16844+ popl_cfi %es
16845 popl_cfi %ebx
16846 CFI_RESTORE ebx
16847 popl_cfi %esi
16848@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
16849 popl_cfi %ecx # equivalent to addl $4,%esp
16850 ret
16851 CFI_ENDPROC
16852-ENDPROC(csum_partial_copy_generic)
16853+ENDPROC(csum_partial_copy_generic_to_user)
16854
16855 #else
16856
16857 /* Version for PentiumII/PPro */
16858
16859 #define ROUND1(x) \
16860+ nop; nop; nop; \
16861 SRC(movl x(%esi), %ebx ) ; \
16862 addl %ebx, %eax ; \
16863- DST(movl %ebx, x(%edi) ) ;
16864+ DST(movl %ebx, %es:x(%edi)) ;
16865
16866 #define ROUND(x) \
16867+ nop; nop; nop; \
16868 SRC(movl x(%esi), %ebx ) ; \
16869 adcl %ebx, %eax ; \
16870- DST(movl %ebx, x(%edi) ) ;
16871+ DST(movl %ebx, %es:x(%edi)) ;
16872
16873 #define ARGBASE 12
16874-
16875-ENTRY(csum_partial_copy_generic)
16876+
16877+ENTRY(csum_partial_copy_generic_to_user)
16878 CFI_STARTPROC
16879+
16880+#ifdef CONFIG_PAX_MEMORY_UDEREF
16881+ pushl_cfi %gs
16882+ popl_cfi %es
16883+ jmp csum_partial_copy_generic
16884+#endif
16885+
16886+ENTRY(csum_partial_copy_generic_from_user)
16887+
16888+#ifdef CONFIG_PAX_MEMORY_UDEREF
16889+ pushl_cfi %gs
16890+ popl_cfi %ds
16891+#endif
16892+
16893+ENTRY(csum_partial_copy_generic)
16894 pushl_cfi %ebx
16895 CFI_REL_OFFSET ebx, 0
16896 pushl_cfi %edi
16897@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
16898 subl %ebx, %edi
16899 lea -1(%esi),%edx
16900 andl $-32,%edx
16901- lea 3f(%ebx,%ebx), %ebx
16902+ lea 3f(%ebx,%ebx,2), %ebx
16903 testl %esi, %esi
16904 jmp *%ebx
16905 1: addl $64,%esi
16906@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
16907 jb 5f
16908 SRC( movw (%esi), %dx )
16909 leal 2(%esi), %esi
16910-DST( movw %dx, (%edi) )
16911+DST( movw %dx, %es:(%edi) )
16912 leal 2(%edi), %edi
16913 je 6f
16914 shll $16,%edx
16915 5:
16916 SRC( movb (%esi), %dl )
16917-DST( movb %dl, (%edi) )
16918+DST( movb %dl, %es:(%edi) )
16919 6: addl %edx, %eax
16920 adcl $0, %eax
16921 7:
16922 .section .fixup, "ax"
16923 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
16924- movl $-EFAULT, (%ebx)
16925+ movl $-EFAULT, %ss:(%ebx)
16926 # zero the complete destination (computing the rest is too much work)
16927 movl ARGBASE+8(%esp),%edi # dst
16928 movl ARGBASE+12(%esp),%ecx # len
16929@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
16930 rep; stosb
16931 jmp 7b
16932 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
16933- movl $-EFAULT, (%ebx)
16934+ movl $-EFAULT, %ss:(%ebx)
16935 jmp 7b
16936 .previous
16937
16938+#ifdef CONFIG_PAX_MEMORY_UDEREF
16939+ pushl_cfi %ss
16940+ popl_cfi %ds
16941+ pushl_cfi %ss
16942+ popl_cfi %es
16943+#endif
16944+
16945 popl_cfi %esi
16946 CFI_RESTORE esi
16947 popl_cfi %edi
16948@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
16949 CFI_RESTORE ebx
16950 ret
16951 CFI_ENDPROC
16952-ENDPROC(csum_partial_copy_generic)
16953+ENDPROC(csum_partial_copy_generic_to_user)
16954
16955 #undef ROUND
16956 #undef ROUND1
16957diff -urNp linux-3.0.4/arch/x86/lib/clear_page_64.S linux-3.0.4/arch/x86/lib/clear_page_64.S
16958--- linux-3.0.4/arch/x86/lib/clear_page_64.S 2011-07-21 22:17:23.000000000 -0400
16959+++ linux-3.0.4/arch/x86/lib/clear_page_64.S 2011-08-23 21:47:55.000000000 -0400
16960@@ -58,7 +58,7 @@ ENDPROC(clear_page)
16961
16962 #include <asm/cpufeature.h>
16963
16964- .section .altinstr_replacement,"ax"
16965+ .section .altinstr_replacement,"a"
16966 1: .byte 0xeb /* jmp <disp8> */
16967 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
16968 2: .byte 0xeb /* jmp <disp8> */
16969diff -urNp linux-3.0.4/arch/x86/lib/copy_page_64.S linux-3.0.4/arch/x86/lib/copy_page_64.S
16970--- linux-3.0.4/arch/x86/lib/copy_page_64.S 2011-07-21 22:17:23.000000000 -0400
16971+++ linux-3.0.4/arch/x86/lib/copy_page_64.S 2011-08-23 21:47:55.000000000 -0400
16972@@ -104,7 +104,7 @@ ENDPROC(copy_page)
16973
16974 #include <asm/cpufeature.h>
16975
16976- .section .altinstr_replacement,"ax"
16977+ .section .altinstr_replacement,"a"
16978 1: .byte 0xeb /* jmp <disp8> */
16979 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
16980 2:
16981diff -urNp linux-3.0.4/arch/x86/lib/copy_user_64.S linux-3.0.4/arch/x86/lib/copy_user_64.S
16982--- linux-3.0.4/arch/x86/lib/copy_user_64.S 2011-07-21 22:17:23.000000000 -0400
16983+++ linux-3.0.4/arch/x86/lib/copy_user_64.S 2011-08-23 21:47:55.000000000 -0400
16984@@ -16,6 +16,7 @@
16985 #include <asm/thread_info.h>
16986 #include <asm/cpufeature.h>
16987 #include <asm/alternative-asm.h>
16988+#include <asm/pgtable.h>
16989
16990 /*
16991 * By placing feature2 after feature1 in altinstructions section, we logically
16992@@ -29,7 +30,7 @@
16993 .byte 0xe9 /* 32bit jump */
16994 .long \orig-1f /* by default jump to orig */
16995 1:
16996- .section .altinstr_replacement,"ax"
16997+ .section .altinstr_replacement,"a"
16998 2: .byte 0xe9 /* near jump with 32bit immediate */
16999 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
17000 3: .byte 0xe9 /* near jump with 32bit immediate */
17001@@ -71,41 +72,13 @@
17002 #endif
17003 .endm
17004
17005-/* Standard copy_to_user with segment limit checking */
17006-ENTRY(_copy_to_user)
17007- CFI_STARTPROC
17008- GET_THREAD_INFO(%rax)
17009- movq %rdi,%rcx
17010- addq %rdx,%rcx
17011- jc bad_to_user
17012- cmpq TI_addr_limit(%rax),%rcx
17013- ja bad_to_user
17014- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
17015- copy_user_generic_unrolled,copy_user_generic_string, \
17016- copy_user_enhanced_fast_string
17017- CFI_ENDPROC
17018-ENDPROC(_copy_to_user)
17019-
17020-/* Standard copy_from_user with segment limit checking */
17021-ENTRY(_copy_from_user)
17022- CFI_STARTPROC
17023- GET_THREAD_INFO(%rax)
17024- movq %rsi,%rcx
17025- addq %rdx,%rcx
17026- jc bad_from_user
17027- cmpq TI_addr_limit(%rax),%rcx
17028- ja bad_from_user
17029- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
17030- copy_user_generic_unrolled,copy_user_generic_string, \
17031- copy_user_enhanced_fast_string
17032- CFI_ENDPROC
17033-ENDPROC(_copy_from_user)
17034-
17035 .section .fixup,"ax"
17036 /* must zero dest */
17037 ENTRY(bad_from_user)
17038 bad_from_user:
17039 CFI_STARTPROC
17040+ testl %edx,%edx
17041+ js bad_to_user
17042 movl %edx,%ecx
17043 xorl %eax,%eax
17044 rep
17045diff -urNp linux-3.0.4/arch/x86/lib/copy_user_nocache_64.S linux-3.0.4/arch/x86/lib/copy_user_nocache_64.S
17046--- linux-3.0.4/arch/x86/lib/copy_user_nocache_64.S 2011-07-21 22:17:23.000000000 -0400
17047+++ linux-3.0.4/arch/x86/lib/copy_user_nocache_64.S 2011-08-23 21:47:55.000000000 -0400
17048@@ -14,6 +14,7 @@
17049 #include <asm/current.h>
17050 #include <asm/asm-offsets.h>
17051 #include <asm/thread_info.h>
17052+#include <asm/pgtable.h>
17053
17054 .macro ALIGN_DESTINATION
17055 #ifdef FIX_ALIGNMENT
17056@@ -50,6 +51,15 @@
17057 */
17058 ENTRY(__copy_user_nocache)
17059 CFI_STARTPROC
17060+
17061+#ifdef CONFIG_PAX_MEMORY_UDEREF
17062+ mov $PAX_USER_SHADOW_BASE,%rcx
17063+ cmp %rcx,%rsi
17064+ jae 1f
17065+ add %rcx,%rsi
17066+1:
17067+#endif
17068+
17069 cmpl $8,%edx
17070 jb 20f /* less then 8 bytes, go to byte copy loop */
17071 ALIGN_DESTINATION
17072diff -urNp linux-3.0.4/arch/x86/lib/csum-wrappers_64.c linux-3.0.4/arch/x86/lib/csum-wrappers_64.c
17073--- linux-3.0.4/arch/x86/lib/csum-wrappers_64.c 2011-07-21 22:17:23.000000000 -0400
17074+++ linux-3.0.4/arch/x86/lib/csum-wrappers_64.c 2011-08-23 21:47:55.000000000 -0400
17075@@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
17076 len -= 2;
17077 }
17078 }
17079+
17080+#ifdef CONFIG_PAX_MEMORY_UDEREF
17081+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
17082+ src += PAX_USER_SHADOW_BASE;
17083+#endif
17084+
17085 isum = csum_partial_copy_generic((__force const void *)src,
17086 dst, len, isum, errp, NULL);
17087 if (unlikely(*errp))
17088@@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
17089 }
17090
17091 *errp = 0;
17092+
17093+#ifdef CONFIG_PAX_MEMORY_UDEREF
17094+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
17095+ dst += PAX_USER_SHADOW_BASE;
17096+#endif
17097+
17098 return csum_partial_copy_generic(src, (void __force *)dst,
17099 len, isum, NULL, errp);
17100 }
17101diff -urNp linux-3.0.4/arch/x86/lib/getuser.S linux-3.0.4/arch/x86/lib/getuser.S
17102--- linux-3.0.4/arch/x86/lib/getuser.S 2011-07-21 22:17:23.000000000 -0400
17103+++ linux-3.0.4/arch/x86/lib/getuser.S 2011-08-23 21:47:55.000000000 -0400
17104@@ -33,14 +33,35 @@
17105 #include <asm/asm-offsets.h>
17106 #include <asm/thread_info.h>
17107 #include <asm/asm.h>
17108+#include <asm/segment.h>
17109+#include <asm/pgtable.h>
17110+
17111+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17112+#define __copyuser_seg gs;
17113+#else
17114+#define __copyuser_seg
17115+#endif
17116
17117 .text
17118 ENTRY(__get_user_1)
17119 CFI_STARTPROC
17120+
17121+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17122 GET_THREAD_INFO(%_ASM_DX)
17123 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
17124 jae bad_get_user
17125-1: movzb (%_ASM_AX),%edx
17126+
17127+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17128+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
17129+ cmp %_ASM_DX,%_ASM_AX
17130+ jae 1234f
17131+ add %_ASM_DX,%_ASM_AX
17132+1234:
17133+#endif
17134+
17135+#endif
17136+
17137+1: __copyuser_seg movzb (%_ASM_AX),%edx
17138 xor %eax,%eax
17139 ret
17140 CFI_ENDPROC
17141@@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
17142 ENTRY(__get_user_2)
17143 CFI_STARTPROC
17144 add $1,%_ASM_AX
17145+
17146+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17147 jc bad_get_user
17148 GET_THREAD_INFO(%_ASM_DX)
17149 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
17150 jae bad_get_user
17151-2: movzwl -1(%_ASM_AX),%edx
17152+
17153+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17154+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
17155+ cmp %_ASM_DX,%_ASM_AX
17156+ jae 1234f
17157+ add %_ASM_DX,%_ASM_AX
17158+1234:
17159+#endif
17160+
17161+#endif
17162+
17163+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
17164 xor %eax,%eax
17165 ret
17166 CFI_ENDPROC
17167@@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
17168 ENTRY(__get_user_4)
17169 CFI_STARTPROC
17170 add $3,%_ASM_AX
17171+
17172+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17173 jc bad_get_user
17174 GET_THREAD_INFO(%_ASM_DX)
17175 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
17176 jae bad_get_user
17177-3: mov -3(%_ASM_AX),%edx
17178+
17179+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17180+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
17181+ cmp %_ASM_DX,%_ASM_AX
17182+ jae 1234f
17183+ add %_ASM_DX,%_ASM_AX
17184+1234:
17185+#endif
17186+
17187+#endif
17188+
17189+3: __copyuser_seg mov -3(%_ASM_AX),%edx
17190 xor %eax,%eax
17191 ret
17192 CFI_ENDPROC
17193@@ -80,6 +127,15 @@ ENTRY(__get_user_8)
17194 GET_THREAD_INFO(%_ASM_DX)
17195 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
17196 jae bad_get_user
17197+
17198+#ifdef CONFIG_PAX_MEMORY_UDEREF
17199+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
17200+ cmp %_ASM_DX,%_ASM_AX
17201+ jae 1234f
17202+ add %_ASM_DX,%_ASM_AX
17203+1234:
17204+#endif
17205+
17206 4: movq -7(%_ASM_AX),%_ASM_DX
17207 xor %eax,%eax
17208 ret
17209diff -urNp linux-3.0.4/arch/x86/lib/insn.c linux-3.0.4/arch/x86/lib/insn.c
17210--- linux-3.0.4/arch/x86/lib/insn.c 2011-07-21 22:17:23.000000000 -0400
17211+++ linux-3.0.4/arch/x86/lib/insn.c 2011-08-23 21:47:55.000000000 -0400
17212@@ -21,6 +21,11 @@
17213 #include <linux/string.h>
17214 #include <asm/inat.h>
17215 #include <asm/insn.h>
17216+#ifdef __KERNEL__
17217+#include <asm/pgtable_types.h>
17218+#else
17219+#define ktla_ktva(addr) addr
17220+#endif
17221
17222 #define get_next(t, insn) \
17223 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
17224@@ -40,8 +45,8 @@
17225 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
17226 {
17227 memset(insn, 0, sizeof(*insn));
17228- insn->kaddr = kaddr;
17229- insn->next_byte = kaddr;
17230+ insn->kaddr = ktla_ktva(kaddr);
17231+ insn->next_byte = ktla_ktva(kaddr);
17232 insn->x86_64 = x86_64 ? 1 : 0;
17233 insn->opnd_bytes = 4;
17234 if (x86_64)
17235diff -urNp linux-3.0.4/arch/x86/lib/mmx_32.c linux-3.0.4/arch/x86/lib/mmx_32.c
17236--- linux-3.0.4/arch/x86/lib/mmx_32.c 2011-07-21 22:17:23.000000000 -0400
17237+++ linux-3.0.4/arch/x86/lib/mmx_32.c 2011-08-23 21:47:55.000000000 -0400
17238@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
17239 {
17240 void *p;
17241 int i;
17242+ unsigned long cr0;
17243
17244 if (unlikely(in_interrupt()))
17245 return __memcpy(to, from, len);
17246@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
17247 kernel_fpu_begin();
17248
17249 __asm__ __volatile__ (
17250- "1: prefetch (%0)\n" /* This set is 28 bytes */
17251- " prefetch 64(%0)\n"
17252- " prefetch 128(%0)\n"
17253- " prefetch 192(%0)\n"
17254- " prefetch 256(%0)\n"
17255+ "1: prefetch (%1)\n" /* This set is 28 bytes */
17256+ " prefetch 64(%1)\n"
17257+ " prefetch 128(%1)\n"
17258+ " prefetch 192(%1)\n"
17259+ " prefetch 256(%1)\n"
17260 "2: \n"
17261 ".section .fixup, \"ax\"\n"
17262- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
17263+ "3: \n"
17264+
17265+#ifdef CONFIG_PAX_KERNEXEC
17266+ " movl %%cr0, %0\n"
17267+ " movl %0, %%eax\n"
17268+ " andl $0xFFFEFFFF, %%eax\n"
17269+ " movl %%eax, %%cr0\n"
17270+#endif
17271+
17272+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
17273+
17274+#ifdef CONFIG_PAX_KERNEXEC
17275+ " movl %0, %%cr0\n"
17276+#endif
17277+
17278 " jmp 2b\n"
17279 ".previous\n"
17280 _ASM_EXTABLE(1b, 3b)
17281- : : "r" (from));
17282+ : "=&r" (cr0) : "r" (from) : "ax");
17283
17284 for ( ; i > 5; i--) {
17285 __asm__ __volatile__ (
17286- "1: prefetch 320(%0)\n"
17287- "2: movq (%0), %%mm0\n"
17288- " movq 8(%0), %%mm1\n"
17289- " movq 16(%0), %%mm2\n"
17290- " movq 24(%0), %%mm3\n"
17291- " movq %%mm0, (%1)\n"
17292- " movq %%mm1, 8(%1)\n"
17293- " movq %%mm2, 16(%1)\n"
17294- " movq %%mm3, 24(%1)\n"
17295- " movq 32(%0), %%mm0\n"
17296- " movq 40(%0), %%mm1\n"
17297- " movq 48(%0), %%mm2\n"
17298- " movq 56(%0), %%mm3\n"
17299- " movq %%mm0, 32(%1)\n"
17300- " movq %%mm1, 40(%1)\n"
17301- " movq %%mm2, 48(%1)\n"
17302- " movq %%mm3, 56(%1)\n"
17303+ "1: prefetch 320(%1)\n"
17304+ "2: movq (%1), %%mm0\n"
17305+ " movq 8(%1), %%mm1\n"
17306+ " movq 16(%1), %%mm2\n"
17307+ " movq 24(%1), %%mm3\n"
17308+ " movq %%mm0, (%2)\n"
17309+ " movq %%mm1, 8(%2)\n"
17310+ " movq %%mm2, 16(%2)\n"
17311+ " movq %%mm3, 24(%2)\n"
17312+ " movq 32(%1), %%mm0\n"
17313+ " movq 40(%1), %%mm1\n"
17314+ " movq 48(%1), %%mm2\n"
17315+ " movq 56(%1), %%mm3\n"
17316+ " movq %%mm0, 32(%2)\n"
17317+ " movq %%mm1, 40(%2)\n"
17318+ " movq %%mm2, 48(%2)\n"
17319+ " movq %%mm3, 56(%2)\n"
17320 ".section .fixup, \"ax\"\n"
17321- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
17322+ "3:\n"
17323+
17324+#ifdef CONFIG_PAX_KERNEXEC
17325+ " movl %%cr0, %0\n"
17326+ " movl %0, %%eax\n"
17327+ " andl $0xFFFEFFFF, %%eax\n"
17328+ " movl %%eax, %%cr0\n"
17329+#endif
17330+
17331+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
17332+
17333+#ifdef CONFIG_PAX_KERNEXEC
17334+ " movl %0, %%cr0\n"
17335+#endif
17336+
17337 " jmp 2b\n"
17338 ".previous\n"
17339 _ASM_EXTABLE(1b, 3b)
17340- : : "r" (from), "r" (to) : "memory");
17341+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
17342
17343 from += 64;
17344 to += 64;
17345@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
17346 static void fast_copy_page(void *to, void *from)
17347 {
17348 int i;
17349+ unsigned long cr0;
17350
17351 kernel_fpu_begin();
17352
17353@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
17354 * but that is for later. -AV
17355 */
17356 __asm__ __volatile__(
17357- "1: prefetch (%0)\n"
17358- " prefetch 64(%0)\n"
17359- " prefetch 128(%0)\n"
17360- " prefetch 192(%0)\n"
17361- " prefetch 256(%0)\n"
17362+ "1: prefetch (%1)\n"
17363+ " prefetch 64(%1)\n"
17364+ " prefetch 128(%1)\n"
17365+ " prefetch 192(%1)\n"
17366+ " prefetch 256(%1)\n"
17367 "2: \n"
17368 ".section .fixup, \"ax\"\n"
17369- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
17370+ "3: \n"
17371+
17372+#ifdef CONFIG_PAX_KERNEXEC
17373+ " movl %%cr0, %0\n"
17374+ " movl %0, %%eax\n"
17375+ " andl $0xFFFEFFFF, %%eax\n"
17376+ " movl %%eax, %%cr0\n"
17377+#endif
17378+
17379+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
17380+
17381+#ifdef CONFIG_PAX_KERNEXEC
17382+ " movl %0, %%cr0\n"
17383+#endif
17384+
17385 " jmp 2b\n"
17386 ".previous\n"
17387- _ASM_EXTABLE(1b, 3b) : : "r" (from));
17388+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
17389
17390 for (i = 0; i < (4096-320)/64; i++) {
17391 __asm__ __volatile__ (
17392- "1: prefetch 320(%0)\n"
17393- "2: movq (%0), %%mm0\n"
17394- " movntq %%mm0, (%1)\n"
17395- " movq 8(%0), %%mm1\n"
17396- " movntq %%mm1, 8(%1)\n"
17397- " movq 16(%0), %%mm2\n"
17398- " movntq %%mm2, 16(%1)\n"
17399- " movq 24(%0), %%mm3\n"
17400- " movntq %%mm3, 24(%1)\n"
17401- " movq 32(%0), %%mm4\n"
17402- " movntq %%mm4, 32(%1)\n"
17403- " movq 40(%0), %%mm5\n"
17404- " movntq %%mm5, 40(%1)\n"
17405- " movq 48(%0), %%mm6\n"
17406- " movntq %%mm6, 48(%1)\n"
17407- " movq 56(%0), %%mm7\n"
17408- " movntq %%mm7, 56(%1)\n"
17409+ "1: prefetch 320(%1)\n"
17410+ "2: movq (%1), %%mm0\n"
17411+ " movntq %%mm0, (%2)\n"
17412+ " movq 8(%1), %%mm1\n"
17413+ " movntq %%mm1, 8(%2)\n"
17414+ " movq 16(%1), %%mm2\n"
17415+ " movntq %%mm2, 16(%2)\n"
17416+ " movq 24(%1), %%mm3\n"
17417+ " movntq %%mm3, 24(%2)\n"
17418+ " movq 32(%1), %%mm4\n"
17419+ " movntq %%mm4, 32(%2)\n"
17420+ " movq 40(%1), %%mm5\n"
17421+ " movntq %%mm5, 40(%2)\n"
17422+ " movq 48(%1), %%mm6\n"
17423+ " movntq %%mm6, 48(%2)\n"
17424+ " movq 56(%1), %%mm7\n"
17425+ " movntq %%mm7, 56(%2)\n"
17426 ".section .fixup, \"ax\"\n"
17427- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
17428+ "3:\n"
17429+
17430+#ifdef CONFIG_PAX_KERNEXEC
17431+ " movl %%cr0, %0\n"
17432+ " movl %0, %%eax\n"
17433+ " andl $0xFFFEFFFF, %%eax\n"
17434+ " movl %%eax, %%cr0\n"
17435+#endif
17436+
17437+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
17438+
17439+#ifdef CONFIG_PAX_KERNEXEC
17440+ " movl %0, %%cr0\n"
17441+#endif
17442+
17443 " jmp 2b\n"
17444 ".previous\n"
17445- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
17446+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
17447
17448 from += 64;
17449 to += 64;
17450@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
17451 static void fast_copy_page(void *to, void *from)
17452 {
17453 int i;
17454+ unsigned long cr0;
17455
17456 kernel_fpu_begin();
17457
17458 __asm__ __volatile__ (
17459- "1: prefetch (%0)\n"
17460- " prefetch 64(%0)\n"
17461- " prefetch 128(%0)\n"
17462- " prefetch 192(%0)\n"
17463- " prefetch 256(%0)\n"
17464+ "1: prefetch (%1)\n"
17465+ " prefetch 64(%1)\n"
17466+ " prefetch 128(%1)\n"
17467+ " prefetch 192(%1)\n"
17468+ " prefetch 256(%1)\n"
17469 "2: \n"
17470 ".section .fixup, \"ax\"\n"
17471- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
17472+ "3: \n"
17473+
17474+#ifdef CONFIG_PAX_KERNEXEC
17475+ " movl %%cr0, %0\n"
17476+ " movl %0, %%eax\n"
17477+ " andl $0xFFFEFFFF, %%eax\n"
17478+ " movl %%eax, %%cr0\n"
17479+#endif
17480+
17481+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
17482+
17483+#ifdef CONFIG_PAX_KERNEXEC
17484+ " movl %0, %%cr0\n"
17485+#endif
17486+
17487 " jmp 2b\n"
17488 ".previous\n"
17489- _ASM_EXTABLE(1b, 3b) : : "r" (from));
17490+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
17491
17492 for (i = 0; i < 4096/64; i++) {
17493 __asm__ __volatile__ (
17494- "1: prefetch 320(%0)\n"
17495- "2: movq (%0), %%mm0\n"
17496- " movq 8(%0), %%mm1\n"
17497- " movq 16(%0), %%mm2\n"
17498- " movq 24(%0), %%mm3\n"
17499- " movq %%mm0, (%1)\n"
17500- " movq %%mm1, 8(%1)\n"
17501- " movq %%mm2, 16(%1)\n"
17502- " movq %%mm3, 24(%1)\n"
17503- " movq 32(%0), %%mm0\n"
17504- " movq 40(%0), %%mm1\n"
17505- " movq 48(%0), %%mm2\n"
17506- " movq 56(%0), %%mm3\n"
17507- " movq %%mm0, 32(%1)\n"
17508- " movq %%mm1, 40(%1)\n"
17509- " movq %%mm2, 48(%1)\n"
17510- " movq %%mm3, 56(%1)\n"
17511+ "1: prefetch 320(%1)\n"
17512+ "2: movq (%1), %%mm0\n"
17513+ " movq 8(%1), %%mm1\n"
17514+ " movq 16(%1), %%mm2\n"
17515+ " movq 24(%1), %%mm3\n"
17516+ " movq %%mm0, (%2)\n"
17517+ " movq %%mm1, 8(%2)\n"
17518+ " movq %%mm2, 16(%2)\n"
17519+ " movq %%mm3, 24(%2)\n"
17520+ " movq 32(%1), %%mm0\n"
17521+ " movq 40(%1), %%mm1\n"
17522+ " movq 48(%1), %%mm2\n"
17523+ " movq 56(%1), %%mm3\n"
17524+ " movq %%mm0, 32(%2)\n"
17525+ " movq %%mm1, 40(%2)\n"
17526+ " movq %%mm2, 48(%2)\n"
17527+ " movq %%mm3, 56(%2)\n"
17528 ".section .fixup, \"ax\"\n"
17529- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
17530+ "3:\n"
17531+
17532+#ifdef CONFIG_PAX_KERNEXEC
17533+ " movl %%cr0, %0\n"
17534+ " movl %0, %%eax\n"
17535+ " andl $0xFFFEFFFF, %%eax\n"
17536+ " movl %%eax, %%cr0\n"
17537+#endif
17538+
17539+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
17540+
17541+#ifdef CONFIG_PAX_KERNEXEC
17542+ " movl %0, %%cr0\n"
17543+#endif
17544+
17545 " jmp 2b\n"
17546 ".previous\n"
17547 _ASM_EXTABLE(1b, 3b)
17548- : : "r" (from), "r" (to) : "memory");
17549+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
17550
17551 from += 64;
17552 to += 64;
17553diff -urNp linux-3.0.4/arch/x86/lib/putuser.S linux-3.0.4/arch/x86/lib/putuser.S
17554--- linux-3.0.4/arch/x86/lib/putuser.S 2011-07-21 22:17:23.000000000 -0400
17555+++ linux-3.0.4/arch/x86/lib/putuser.S 2011-08-23 21:47:55.000000000 -0400
17556@@ -15,7 +15,8 @@
17557 #include <asm/thread_info.h>
17558 #include <asm/errno.h>
17559 #include <asm/asm.h>
17560-
17561+#include <asm/segment.h>
17562+#include <asm/pgtable.h>
17563
17564 /*
17565 * __put_user_X
17566@@ -29,52 +30,119 @@
17567 * as they get called from within inline assembly.
17568 */
17569
17570-#define ENTER CFI_STARTPROC ; \
17571- GET_THREAD_INFO(%_ASM_BX)
17572+#define ENTER CFI_STARTPROC
17573 #define EXIT ret ; \
17574 CFI_ENDPROC
17575
17576+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17577+#define _DEST %_ASM_CX,%_ASM_BX
17578+#else
17579+#define _DEST %_ASM_CX
17580+#endif
17581+
17582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17583+#define __copyuser_seg gs;
17584+#else
17585+#define __copyuser_seg
17586+#endif
17587+
17588 .text
17589 ENTRY(__put_user_1)
17590 ENTER
17591+
17592+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17593+ GET_THREAD_INFO(%_ASM_BX)
17594 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
17595 jae bad_put_user
17596-1: movb %al,(%_ASM_CX)
17597+
17598+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17599+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
17600+ cmp %_ASM_BX,%_ASM_CX
17601+ jb 1234f
17602+ xor %ebx,%ebx
17603+1234:
17604+#endif
17605+
17606+#endif
17607+
17608+1: __copyuser_seg movb %al,(_DEST)
17609 xor %eax,%eax
17610 EXIT
17611 ENDPROC(__put_user_1)
17612
17613 ENTRY(__put_user_2)
17614 ENTER
17615+
17616+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17617+ GET_THREAD_INFO(%_ASM_BX)
17618 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
17619 sub $1,%_ASM_BX
17620 cmp %_ASM_BX,%_ASM_CX
17621 jae bad_put_user
17622-2: movw %ax,(%_ASM_CX)
17623+
17624+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17625+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
17626+ cmp %_ASM_BX,%_ASM_CX
17627+ jb 1234f
17628+ xor %ebx,%ebx
17629+1234:
17630+#endif
17631+
17632+#endif
17633+
17634+2: __copyuser_seg movw %ax,(_DEST)
17635 xor %eax,%eax
17636 EXIT
17637 ENDPROC(__put_user_2)
17638
17639 ENTRY(__put_user_4)
17640 ENTER
17641+
17642+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17643+ GET_THREAD_INFO(%_ASM_BX)
17644 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
17645 sub $3,%_ASM_BX
17646 cmp %_ASM_BX,%_ASM_CX
17647 jae bad_put_user
17648-3: movl %eax,(%_ASM_CX)
17649+
17650+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17651+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
17652+ cmp %_ASM_BX,%_ASM_CX
17653+ jb 1234f
17654+ xor %ebx,%ebx
17655+1234:
17656+#endif
17657+
17658+#endif
17659+
17660+3: __copyuser_seg movl %eax,(_DEST)
17661 xor %eax,%eax
17662 EXIT
17663 ENDPROC(__put_user_4)
17664
17665 ENTRY(__put_user_8)
17666 ENTER
17667+
17668+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
17669+ GET_THREAD_INFO(%_ASM_BX)
17670 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
17671 sub $7,%_ASM_BX
17672 cmp %_ASM_BX,%_ASM_CX
17673 jae bad_put_user
17674-4: mov %_ASM_AX,(%_ASM_CX)
17675+
17676+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17677+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
17678+ cmp %_ASM_BX,%_ASM_CX
17679+ jb 1234f
17680+ xor %ebx,%ebx
17681+1234:
17682+#endif
17683+
17684+#endif
17685+
17686+4: __copyuser_seg mov %_ASM_AX,(_DEST)
17687 #ifdef CONFIG_X86_32
17688-5: movl %edx,4(%_ASM_CX)
17689+5: __copyuser_seg movl %edx,4(_DEST)
17690 #endif
17691 xor %eax,%eax
17692 EXIT
17693diff -urNp linux-3.0.4/arch/x86/lib/usercopy_32.c linux-3.0.4/arch/x86/lib/usercopy_32.c
17694--- linux-3.0.4/arch/x86/lib/usercopy_32.c 2011-07-21 22:17:23.000000000 -0400
17695+++ linux-3.0.4/arch/x86/lib/usercopy_32.c 2011-08-23 21:47:55.000000000 -0400
17696@@ -43,7 +43,7 @@ do { \
17697 __asm__ __volatile__( \
17698 " testl %1,%1\n" \
17699 " jz 2f\n" \
17700- "0: lodsb\n" \
17701+ "0: "__copyuser_seg"lodsb\n" \
17702 " stosb\n" \
17703 " testb %%al,%%al\n" \
17704 " jz 1f\n" \
17705@@ -128,10 +128,12 @@ do { \
17706 int __d0; \
17707 might_fault(); \
17708 __asm__ __volatile__( \
17709+ __COPYUSER_SET_ES \
17710 "0: rep; stosl\n" \
17711 " movl %2,%0\n" \
17712 "1: rep; stosb\n" \
17713 "2:\n" \
17714+ __COPYUSER_RESTORE_ES \
17715 ".section .fixup,\"ax\"\n" \
17716 "3: lea 0(%2,%0,4),%0\n" \
17717 " jmp 2b\n" \
17718@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
17719 might_fault();
17720
17721 __asm__ __volatile__(
17722+ __COPYUSER_SET_ES
17723 " testl %0, %0\n"
17724 " jz 3f\n"
17725 " andl %0,%%ecx\n"
17726@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
17727 " subl %%ecx,%0\n"
17728 " addl %0,%%eax\n"
17729 "1:\n"
17730+ __COPYUSER_RESTORE_ES
17731 ".section .fixup,\"ax\"\n"
17732 "2: xorl %%eax,%%eax\n"
17733 " jmp 1b\n"
17734@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
17735
17736 #ifdef CONFIG_X86_INTEL_USERCOPY
17737 static unsigned long
17738-__copy_user_intel(void __user *to, const void *from, unsigned long size)
17739+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
17740 {
17741 int d0, d1;
17742 __asm__ __volatile__(
17743@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
17744 " .align 2,0x90\n"
17745 "3: movl 0(%4), %%eax\n"
17746 "4: movl 4(%4), %%edx\n"
17747- "5: movl %%eax, 0(%3)\n"
17748- "6: movl %%edx, 4(%3)\n"
17749+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
17750+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
17751 "7: movl 8(%4), %%eax\n"
17752 "8: movl 12(%4),%%edx\n"
17753- "9: movl %%eax, 8(%3)\n"
17754- "10: movl %%edx, 12(%3)\n"
17755+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
17756+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
17757 "11: movl 16(%4), %%eax\n"
17758 "12: movl 20(%4), %%edx\n"
17759- "13: movl %%eax, 16(%3)\n"
17760- "14: movl %%edx, 20(%3)\n"
17761+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
17762+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
17763 "15: movl 24(%4), %%eax\n"
17764 "16: movl 28(%4), %%edx\n"
17765- "17: movl %%eax, 24(%3)\n"
17766- "18: movl %%edx, 28(%3)\n"
17767+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
17768+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
17769 "19: movl 32(%4), %%eax\n"
17770 "20: movl 36(%4), %%edx\n"
17771- "21: movl %%eax, 32(%3)\n"
17772- "22: movl %%edx, 36(%3)\n"
17773+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
17774+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
17775 "23: movl 40(%4), %%eax\n"
17776 "24: movl 44(%4), %%edx\n"
17777- "25: movl %%eax, 40(%3)\n"
17778- "26: movl %%edx, 44(%3)\n"
17779+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
17780+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
17781 "27: movl 48(%4), %%eax\n"
17782 "28: movl 52(%4), %%edx\n"
17783- "29: movl %%eax, 48(%3)\n"
17784- "30: movl %%edx, 52(%3)\n"
17785+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
17786+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
17787 "31: movl 56(%4), %%eax\n"
17788 "32: movl 60(%4), %%edx\n"
17789- "33: movl %%eax, 56(%3)\n"
17790- "34: movl %%edx, 60(%3)\n"
17791+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
17792+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
17793 " addl $-64, %0\n"
17794 " addl $64, %4\n"
17795 " addl $64, %3\n"
17796@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
17797 " shrl $2, %0\n"
17798 " andl $3, %%eax\n"
17799 " cld\n"
17800+ __COPYUSER_SET_ES
17801 "99: rep; movsl\n"
17802 "36: movl %%eax, %0\n"
17803 "37: rep; movsb\n"
17804 "100:\n"
17805+ __COPYUSER_RESTORE_ES
17806+ ".section .fixup,\"ax\"\n"
17807+ "101: lea 0(%%eax,%0,4),%0\n"
17808+ " jmp 100b\n"
17809+ ".previous\n"
17810+ ".section __ex_table,\"a\"\n"
17811+ " .align 4\n"
17812+ " .long 1b,100b\n"
17813+ " .long 2b,100b\n"
17814+ " .long 3b,100b\n"
17815+ " .long 4b,100b\n"
17816+ " .long 5b,100b\n"
17817+ " .long 6b,100b\n"
17818+ " .long 7b,100b\n"
17819+ " .long 8b,100b\n"
17820+ " .long 9b,100b\n"
17821+ " .long 10b,100b\n"
17822+ " .long 11b,100b\n"
17823+ " .long 12b,100b\n"
17824+ " .long 13b,100b\n"
17825+ " .long 14b,100b\n"
17826+ " .long 15b,100b\n"
17827+ " .long 16b,100b\n"
17828+ " .long 17b,100b\n"
17829+ " .long 18b,100b\n"
17830+ " .long 19b,100b\n"
17831+ " .long 20b,100b\n"
17832+ " .long 21b,100b\n"
17833+ " .long 22b,100b\n"
17834+ " .long 23b,100b\n"
17835+ " .long 24b,100b\n"
17836+ " .long 25b,100b\n"
17837+ " .long 26b,100b\n"
17838+ " .long 27b,100b\n"
17839+ " .long 28b,100b\n"
17840+ " .long 29b,100b\n"
17841+ " .long 30b,100b\n"
17842+ " .long 31b,100b\n"
17843+ " .long 32b,100b\n"
17844+ " .long 33b,100b\n"
17845+ " .long 34b,100b\n"
17846+ " .long 35b,100b\n"
17847+ " .long 36b,100b\n"
17848+ " .long 37b,100b\n"
17849+ " .long 99b,101b\n"
17850+ ".previous"
17851+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
17852+ : "1"(to), "2"(from), "0"(size)
17853+ : "eax", "edx", "memory");
17854+ return size;
17855+}
17856+
17857+static unsigned long
17858+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
17859+{
17860+ int d0, d1;
17861+ __asm__ __volatile__(
17862+ " .align 2,0x90\n"
17863+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
17864+ " cmpl $67, %0\n"
17865+ " jbe 3f\n"
17866+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
17867+ " .align 2,0x90\n"
17868+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
17869+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
17870+ "5: movl %%eax, 0(%3)\n"
17871+ "6: movl %%edx, 4(%3)\n"
17872+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
17873+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
17874+ "9: movl %%eax, 8(%3)\n"
17875+ "10: movl %%edx, 12(%3)\n"
17876+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
17877+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
17878+ "13: movl %%eax, 16(%3)\n"
17879+ "14: movl %%edx, 20(%3)\n"
17880+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
17881+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
17882+ "17: movl %%eax, 24(%3)\n"
17883+ "18: movl %%edx, 28(%3)\n"
17884+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
17885+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
17886+ "21: movl %%eax, 32(%3)\n"
17887+ "22: movl %%edx, 36(%3)\n"
17888+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
17889+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
17890+ "25: movl %%eax, 40(%3)\n"
17891+ "26: movl %%edx, 44(%3)\n"
17892+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
17893+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
17894+ "29: movl %%eax, 48(%3)\n"
17895+ "30: movl %%edx, 52(%3)\n"
17896+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
17897+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
17898+ "33: movl %%eax, 56(%3)\n"
17899+ "34: movl %%edx, 60(%3)\n"
17900+ " addl $-64, %0\n"
17901+ " addl $64, %4\n"
17902+ " addl $64, %3\n"
17903+ " cmpl $63, %0\n"
17904+ " ja 1b\n"
17905+ "35: movl %0, %%eax\n"
17906+ " shrl $2, %0\n"
17907+ " andl $3, %%eax\n"
17908+ " cld\n"
17909+ "99: rep; "__copyuser_seg" movsl\n"
17910+ "36: movl %%eax, %0\n"
17911+ "37: rep; "__copyuser_seg" movsb\n"
17912+ "100:\n"
17913 ".section .fixup,\"ax\"\n"
17914 "101: lea 0(%%eax,%0,4),%0\n"
17915 " jmp 100b\n"
17916@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
17917 int d0, d1;
17918 __asm__ __volatile__(
17919 " .align 2,0x90\n"
17920- "0: movl 32(%4), %%eax\n"
17921+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
17922 " cmpl $67, %0\n"
17923 " jbe 2f\n"
17924- "1: movl 64(%4), %%eax\n"
17925+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
17926 " .align 2,0x90\n"
17927- "2: movl 0(%4), %%eax\n"
17928- "21: movl 4(%4), %%edx\n"
17929+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
17930+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
17931 " movl %%eax, 0(%3)\n"
17932 " movl %%edx, 4(%3)\n"
17933- "3: movl 8(%4), %%eax\n"
17934- "31: movl 12(%4),%%edx\n"
17935+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
17936+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
17937 " movl %%eax, 8(%3)\n"
17938 " movl %%edx, 12(%3)\n"
17939- "4: movl 16(%4), %%eax\n"
17940- "41: movl 20(%4), %%edx\n"
17941+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
17942+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
17943 " movl %%eax, 16(%3)\n"
17944 " movl %%edx, 20(%3)\n"
17945- "10: movl 24(%4), %%eax\n"
17946- "51: movl 28(%4), %%edx\n"
17947+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
17948+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
17949 " movl %%eax, 24(%3)\n"
17950 " movl %%edx, 28(%3)\n"
17951- "11: movl 32(%4), %%eax\n"
17952- "61: movl 36(%4), %%edx\n"
17953+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
17954+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
17955 " movl %%eax, 32(%3)\n"
17956 " movl %%edx, 36(%3)\n"
17957- "12: movl 40(%4), %%eax\n"
17958- "71: movl 44(%4), %%edx\n"
17959+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
17960+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
17961 " movl %%eax, 40(%3)\n"
17962 " movl %%edx, 44(%3)\n"
17963- "13: movl 48(%4), %%eax\n"
17964- "81: movl 52(%4), %%edx\n"
17965+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
17966+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
17967 " movl %%eax, 48(%3)\n"
17968 " movl %%edx, 52(%3)\n"
17969- "14: movl 56(%4), %%eax\n"
17970- "91: movl 60(%4), %%edx\n"
17971+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
17972+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
17973 " movl %%eax, 56(%3)\n"
17974 " movl %%edx, 60(%3)\n"
17975 " addl $-64, %0\n"
17976@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
17977 " shrl $2, %0\n"
17978 " andl $3, %%eax\n"
17979 " cld\n"
17980- "6: rep; movsl\n"
17981+ "6: rep; "__copyuser_seg" movsl\n"
17982 " movl %%eax,%0\n"
17983- "7: rep; movsb\n"
17984+ "7: rep; "__copyuser_seg" movsb\n"
17985 "8:\n"
17986 ".section .fixup,\"ax\"\n"
17987 "9: lea 0(%%eax,%0,4),%0\n"
17988@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
17989
17990 __asm__ __volatile__(
17991 " .align 2,0x90\n"
17992- "0: movl 32(%4), %%eax\n"
17993+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
17994 " cmpl $67, %0\n"
17995 " jbe 2f\n"
17996- "1: movl 64(%4), %%eax\n"
17997+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
17998 " .align 2,0x90\n"
17999- "2: movl 0(%4), %%eax\n"
18000- "21: movl 4(%4), %%edx\n"
18001+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
18002+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
18003 " movnti %%eax, 0(%3)\n"
18004 " movnti %%edx, 4(%3)\n"
18005- "3: movl 8(%4), %%eax\n"
18006- "31: movl 12(%4),%%edx\n"
18007+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
18008+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
18009 " movnti %%eax, 8(%3)\n"
18010 " movnti %%edx, 12(%3)\n"
18011- "4: movl 16(%4), %%eax\n"
18012- "41: movl 20(%4), %%edx\n"
18013+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
18014+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
18015 " movnti %%eax, 16(%3)\n"
18016 " movnti %%edx, 20(%3)\n"
18017- "10: movl 24(%4), %%eax\n"
18018- "51: movl 28(%4), %%edx\n"
18019+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
18020+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
18021 " movnti %%eax, 24(%3)\n"
18022 " movnti %%edx, 28(%3)\n"
18023- "11: movl 32(%4), %%eax\n"
18024- "61: movl 36(%4), %%edx\n"
18025+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
18026+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
18027 " movnti %%eax, 32(%3)\n"
18028 " movnti %%edx, 36(%3)\n"
18029- "12: movl 40(%4), %%eax\n"
18030- "71: movl 44(%4), %%edx\n"
18031+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
18032+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
18033 " movnti %%eax, 40(%3)\n"
18034 " movnti %%edx, 44(%3)\n"
18035- "13: movl 48(%4), %%eax\n"
18036- "81: movl 52(%4), %%edx\n"
18037+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
18038+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
18039 " movnti %%eax, 48(%3)\n"
18040 " movnti %%edx, 52(%3)\n"
18041- "14: movl 56(%4), %%eax\n"
18042- "91: movl 60(%4), %%edx\n"
18043+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
18044+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
18045 " movnti %%eax, 56(%3)\n"
18046 " movnti %%edx, 60(%3)\n"
18047 " addl $-64, %0\n"
18048@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
18049 " shrl $2, %0\n"
18050 " andl $3, %%eax\n"
18051 " cld\n"
18052- "6: rep; movsl\n"
18053+ "6: rep; "__copyuser_seg" movsl\n"
18054 " movl %%eax,%0\n"
18055- "7: rep; movsb\n"
18056+ "7: rep; "__copyuser_seg" movsb\n"
18057 "8:\n"
18058 ".section .fixup,\"ax\"\n"
18059 "9: lea 0(%%eax,%0,4),%0\n"
18060@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
18061
18062 __asm__ __volatile__(
18063 " .align 2,0x90\n"
18064- "0: movl 32(%4), %%eax\n"
18065+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
18066 " cmpl $67, %0\n"
18067 " jbe 2f\n"
18068- "1: movl 64(%4), %%eax\n"
18069+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
18070 " .align 2,0x90\n"
18071- "2: movl 0(%4), %%eax\n"
18072- "21: movl 4(%4), %%edx\n"
18073+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
18074+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
18075 " movnti %%eax, 0(%3)\n"
18076 " movnti %%edx, 4(%3)\n"
18077- "3: movl 8(%4), %%eax\n"
18078- "31: movl 12(%4),%%edx\n"
18079+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
18080+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
18081 " movnti %%eax, 8(%3)\n"
18082 " movnti %%edx, 12(%3)\n"
18083- "4: movl 16(%4), %%eax\n"
18084- "41: movl 20(%4), %%edx\n"
18085+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
18086+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
18087 " movnti %%eax, 16(%3)\n"
18088 " movnti %%edx, 20(%3)\n"
18089- "10: movl 24(%4), %%eax\n"
18090- "51: movl 28(%4), %%edx\n"
18091+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
18092+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
18093 " movnti %%eax, 24(%3)\n"
18094 " movnti %%edx, 28(%3)\n"
18095- "11: movl 32(%4), %%eax\n"
18096- "61: movl 36(%4), %%edx\n"
18097+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
18098+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
18099 " movnti %%eax, 32(%3)\n"
18100 " movnti %%edx, 36(%3)\n"
18101- "12: movl 40(%4), %%eax\n"
18102- "71: movl 44(%4), %%edx\n"
18103+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
18104+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
18105 " movnti %%eax, 40(%3)\n"
18106 " movnti %%edx, 44(%3)\n"
18107- "13: movl 48(%4), %%eax\n"
18108- "81: movl 52(%4), %%edx\n"
18109+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
18110+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
18111 " movnti %%eax, 48(%3)\n"
18112 " movnti %%edx, 52(%3)\n"
18113- "14: movl 56(%4), %%eax\n"
18114- "91: movl 60(%4), %%edx\n"
18115+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
18116+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
18117 " movnti %%eax, 56(%3)\n"
18118 " movnti %%edx, 60(%3)\n"
18119 " addl $-64, %0\n"
18120@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
18121 " shrl $2, %0\n"
18122 " andl $3, %%eax\n"
18123 " cld\n"
18124- "6: rep; movsl\n"
18125+ "6: rep; "__copyuser_seg" movsl\n"
18126 " movl %%eax,%0\n"
18127- "7: rep; movsb\n"
18128+ "7: rep; "__copyuser_seg" movsb\n"
18129 "8:\n"
18130 ".section .fixup,\"ax\"\n"
18131 "9: lea 0(%%eax,%0,4),%0\n"
18132@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
18133 */
18134 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
18135 unsigned long size);
18136-unsigned long __copy_user_intel(void __user *to, const void *from,
18137+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
18138+ unsigned long size);
18139+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
18140 unsigned long size);
18141 unsigned long __copy_user_zeroing_intel_nocache(void *to,
18142 const void __user *from, unsigned long size);
18143 #endif /* CONFIG_X86_INTEL_USERCOPY */
18144
18145 /* Generic arbitrary sized copy. */
18146-#define __copy_user(to, from, size) \
18147+#define __copy_user(to, from, size, prefix, set, restore) \
18148 do { \
18149 int __d0, __d1, __d2; \
18150 __asm__ __volatile__( \
18151+ set \
18152 " cmp $7,%0\n" \
18153 " jbe 1f\n" \
18154 " movl %1,%0\n" \
18155 " negl %0\n" \
18156 " andl $7,%0\n" \
18157 " subl %0,%3\n" \
18158- "4: rep; movsb\n" \
18159+ "4: rep; "prefix"movsb\n" \
18160 " movl %3,%0\n" \
18161 " shrl $2,%0\n" \
18162 " andl $3,%3\n" \
18163 " .align 2,0x90\n" \
18164- "0: rep; movsl\n" \
18165+ "0: rep; "prefix"movsl\n" \
18166 " movl %3,%0\n" \
18167- "1: rep; movsb\n" \
18168+ "1: rep; "prefix"movsb\n" \
18169 "2:\n" \
18170+ restore \
18171 ".section .fixup,\"ax\"\n" \
18172 "5: addl %3,%0\n" \
18173 " jmp 2b\n" \
18174@@ -682,14 +799,14 @@ do { \
18175 " negl %0\n" \
18176 " andl $7,%0\n" \
18177 " subl %0,%3\n" \
18178- "4: rep; movsb\n" \
18179+ "4: rep; "__copyuser_seg"movsb\n" \
18180 " movl %3,%0\n" \
18181 " shrl $2,%0\n" \
18182 " andl $3,%3\n" \
18183 " .align 2,0x90\n" \
18184- "0: rep; movsl\n" \
18185+ "0: rep; "__copyuser_seg"movsl\n" \
18186 " movl %3,%0\n" \
18187- "1: rep; movsb\n" \
18188+ "1: rep; "__copyuser_seg"movsb\n" \
18189 "2:\n" \
18190 ".section .fixup,\"ax\"\n" \
18191 "5: addl %3,%0\n" \
18192@@ -775,9 +892,9 @@ survive:
18193 }
18194 #endif
18195 if (movsl_is_ok(to, from, n))
18196- __copy_user(to, from, n);
18197+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
18198 else
18199- n = __copy_user_intel(to, from, n);
18200+ n = __generic_copy_to_user_intel(to, from, n);
18201 return n;
18202 }
18203 EXPORT_SYMBOL(__copy_to_user_ll);
18204@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
18205 unsigned long n)
18206 {
18207 if (movsl_is_ok(to, from, n))
18208- __copy_user(to, from, n);
18209+ __copy_user(to, from, n, __copyuser_seg, "", "");
18210 else
18211- n = __copy_user_intel((void __user *)to,
18212- (const void *)from, n);
18213+ n = __generic_copy_from_user_intel(to, from, n);
18214 return n;
18215 }
18216 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
18217@@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocach
18218 if (n > 64 && cpu_has_xmm2)
18219 n = __copy_user_intel_nocache(to, from, n);
18220 else
18221- __copy_user(to, from, n);
18222+ __copy_user(to, from, n, __copyuser_seg, "", "");
18223 #else
18224- __copy_user(to, from, n);
18225+ __copy_user(to, from, n, __copyuser_seg, "", "");
18226 #endif
18227 return n;
18228 }
18229 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
18230
18231-/**
18232- * copy_to_user: - Copy a block of data into user space.
18233- * @to: Destination address, in user space.
18234- * @from: Source address, in kernel space.
18235- * @n: Number of bytes to copy.
18236- *
18237- * Context: User context only. This function may sleep.
18238- *
18239- * Copy data from kernel space to user space.
18240- *
18241- * Returns number of bytes that could not be copied.
18242- * On success, this will be zero.
18243- */
18244-unsigned long
18245-copy_to_user(void __user *to, const void *from, unsigned long n)
18246+void copy_from_user_overflow(void)
18247 {
18248- if (access_ok(VERIFY_WRITE, to, n))
18249- n = __copy_to_user(to, from, n);
18250- return n;
18251+ WARN(1, "Buffer overflow detected!\n");
18252 }
18253-EXPORT_SYMBOL(copy_to_user);
18254+EXPORT_SYMBOL(copy_from_user_overflow);
18255
18256-/**
18257- * copy_from_user: - Copy a block of data from user space.
18258- * @to: Destination address, in kernel space.
18259- * @from: Source address, in user space.
18260- * @n: Number of bytes to copy.
18261- *
18262- * Context: User context only. This function may sleep.
18263- *
18264- * Copy data from user space to kernel space.
18265- *
18266- * Returns number of bytes that could not be copied.
18267- * On success, this will be zero.
18268- *
18269- * If some data could not be copied, this function will pad the copied
18270- * data to the requested size using zero bytes.
18271- */
18272-unsigned long
18273-_copy_from_user(void *to, const void __user *from, unsigned long n)
18274+void copy_to_user_overflow(void)
18275 {
18276- if (access_ok(VERIFY_READ, from, n))
18277- n = __copy_from_user(to, from, n);
18278- else
18279- memset(to, 0, n);
18280- return n;
18281+ WARN(1, "Buffer overflow detected!\n");
18282 }
18283-EXPORT_SYMBOL(_copy_from_user);
18284+EXPORT_SYMBOL(copy_to_user_overflow);
18285
18286-void copy_from_user_overflow(void)
18287+#ifdef CONFIG_PAX_MEMORY_UDEREF
18288+void __set_fs(mm_segment_t x)
18289 {
18290- WARN(1, "Buffer overflow detected!\n");
18291+ switch (x.seg) {
18292+ case 0:
18293+ loadsegment(gs, 0);
18294+ break;
18295+ case TASK_SIZE_MAX:
18296+ loadsegment(gs, __USER_DS);
18297+ break;
18298+ case -1UL:
18299+ loadsegment(gs, __KERNEL_DS);
18300+ break;
18301+ default:
18302+ BUG();
18303+ }
18304+ return;
18305 }
18306-EXPORT_SYMBOL(copy_from_user_overflow);
18307+EXPORT_SYMBOL(__set_fs);
18308+
18309+void set_fs(mm_segment_t x)
18310+{
18311+ current_thread_info()->addr_limit = x;
18312+ __set_fs(x);
18313+}
18314+EXPORT_SYMBOL(set_fs);
18315+#endif
18316diff -urNp linux-3.0.4/arch/x86/lib/usercopy_64.c linux-3.0.4/arch/x86/lib/usercopy_64.c
18317--- linux-3.0.4/arch/x86/lib/usercopy_64.c 2011-07-21 22:17:23.000000000 -0400
18318+++ linux-3.0.4/arch/x86/lib/usercopy_64.c 2011-08-23 21:47:55.000000000 -0400
18319@@ -42,6 +42,12 @@ long
18320 __strncpy_from_user(char *dst, const char __user *src, long count)
18321 {
18322 long res;
18323+
18324+#ifdef CONFIG_PAX_MEMORY_UDEREF
18325+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
18326+ src += PAX_USER_SHADOW_BASE;
18327+#endif
18328+
18329 __do_strncpy_from_user(dst, src, count, res);
18330 return res;
18331 }
18332@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
18333 {
18334 long __d0;
18335 might_fault();
18336+
18337+#ifdef CONFIG_PAX_MEMORY_UDEREF
18338+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
18339+ addr += PAX_USER_SHADOW_BASE;
18340+#endif
18341+
18342 /* no memory constraint because it doesn't change any memory gcc knows
18343 about */
18344 asm volatile(
18345@@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
18346
18347 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
18348 {
18349- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
18350+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
18351+
18352+#ifdef CONFIG_PAX_MEMORY_UDEREF
18353+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
18354+ to += PAX_USER_SHADOW_BASE;
18355+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
18356+ from += PAX_USER_SHADOW_BASE;
18357+#endif
18358+
18359 return copy_user_generic((__force void *)to, (__force void *)from, len);
18360- }
18361- return len;
18362+ }
18363+ return len;
18364 }
18365 EXPORT_SYMBOL(copy_in_user);
18366
18367diff -urNp linux-3.0.4/arch/x86/Makefile linux-3.0.4/arch/x86/Makefile
18368--- linux-3.0.4/arch/x86/Makefile 2011-07-21 22:17:23.000000000 -0400
18369+++ linux-3.0.4/arch/x86/Makefile 2011-08-23 21:48:14.000000000 -0400
18370@@ -44,6 +44,7 @@ ifeq ($(CONFIG_X86_32),y)
18371 else
18372 BITS := 64
18373 UTS_MACHINE := x86_64
18374+ biarch := $(call cc-option,-m64)
18375 CHECKFLAGS += -D__x86_64__ -m64
18376
18377 KBUILD_AFLAGS += -m64
18378@@ -195,3 +196,12 @@ define archhelp
18379 echo ' FDARGS="..." arguments for the booted kernel'
18380 echo ' FDINITRD=file initrd for the booted kernel'
18381 endef
18382+
18383+define OLD_LD
18384+
18385+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
18386+*** Please upgrade your binutils to 2.18 or newer
18387+endef
18388+
18389+archprepare:
18390+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
18391diff -urNp linux-3.0.4/arch/x86/mm/extable.c linux-3.0.4/arch/x86/mm/extable.c
18392--- linux-3.0.4/arch/x86/mm/extable.c 2011-07-21 22:17:23.000000000 -0400
18393+++ linux-3.0.4/arch/x86/mm/extable.c 2011-08-23 21:47:55.000000000 -0400
18394@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs
18395 const struct exception_table_entry *fixup;
18396
18397 #ifdef CONFIG_PNPBIOS
18398- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
18399+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
18400 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
18401 extern u32 pnp_bios_is_utter_crap;
18402 pnp_bios_is_utter_crap = 1;
18403diff -urNp linux-3.0.4/arch/x86/mm/fault.c linux-3.0.4/arch/x86/mm/fault.c
18404--- linux-3.0.4/arch/x86/mm/fault.c 2011-07-21 22:17:23.000000000 -0400
18405+++ linux-3.0.4/arch/x86/mm/fault.c 2011-08-23 21:48:14.000000000 -0400
18406@@ -13,10 +13,18 @@
18407 #include <linux/perf_event.h> /* perf_sw_event */
18408 #include <linux/hugetlb.h> /* hstate_index_to_shift */
18409 #include <linux/prefetch.h> /* prefetchw */
18410+#include <linux/unistd.h>
18411+#include <linux/compiler.h>
18412
18413 #include <asm/traps.h> /* dotraplinkage, ... */
18414 #include <asm/pgalloc.h> /* pgd_*(), ... */
18415 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
18416+#include <asm/vsyscall.h>
18417+#include <asm/tlbflush.h>
18418+
18419+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18420+#include <asm/stacktrace.h>
18421+#endif
18422
18423 /*
18424 * Page fault error code bits:
18425@@ -54,7 +62,7 @@ static inline int __kprobes notify_page_
18426 int ret = 0;
18427
18428 /* kprobe_running() needs smp_processor_id() */
18429- if (kprobes_built_in() && !user_mode_vm(regs)) {
18430+ if (kprobes_built_in() && !user_mode(regs)) {
18431 preempt_disable();
18432 if (kprobe_running() && kprobe_fault_handler(regs, 14))
18433 ret = 1;
18434@@ -115,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *re
18435 return !instr_lo || (instr_lo>>1) == 1;
18436 case 0x00:
18437 /* Prefetch instruction is 0x0F0D or 0x0F18 */
18438- if (probe_kernel_address(instr, opcode))
18439+ if (user_mode(regs)) {
18440+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
18441+ return 0;
18442+ } else if (probe_kernel_address(instr, opcode))
18443 return 0;
18444
18445 *prefetch = (instr_lo == 0xF) &&
18446@@ -149,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsign
18447 while (instr < max_instr) {
18448 unsigned char opcode;
18449
18450- if (probe_kernel_address(instr, opcode))
18451+ if (user_mode(regs)) {
18452+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
18453+ break;
18454+ } else if (probe_kernel_address(instr, opcode))
18455 break;
18456
18457 instr++;
18458@@ -180,6 +194,30 @@ force_sig_info_fault(int si_signo, int s
18459 force_sig_info(si_signo, &info, tsk);
18460 }
18461
18462+#ifdef CONFIG_PAX_EMUTRAMP
18463+static int pax_handle_fetch_fault(struct pt_regs *regs);
18464+#endif
18465+
18466+#ifdef CONFIG_PAX_PAGEEXEC
18467+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
18468+{
18469+ pgd_t *pgd;
18470+ pud_t *pud;
18471+ pmd_t *pmd;
18472+
18473+ pgd = pgd_offset(mm, address);
18474+ if (!pgd_present(*pgd))
18475+ return NULL;
18476+ pud = pud_offset(pgd, address);
18477+ if (!pud_present(*pud))
18478+ return NULL;
18479+ pmd = pmd_offset(pud, address);
18480+ if (!pmd_present(*pmd))
18481+ return NULL;
18482+ return pmd;
18483+}
18484+#endif
18485+
18486 DEFINE_SPINLOCK(pgd_lock);
18487 LIST_HEAD(pgd_list);
18488
18489@@ -230,10 +268,22 @@ void vmalloc_sync_all(void)
18490 for (address = VMALLOC_START & PMD_MASK;
18491 address >= TASK_SIZE && address < FIXADDR_TOP;
18492 address += PMD_SIZE) {
18493+
18494+#ifdef CONFIG_PAX_PER_CPU_PGD
18495+ unsigned long cpu;
18496+#else
18497 struct page *page;
18498+#endif
18499
18500 spin_lock(&pgd_lock);
18501+
18502+#ifdef CONFIG_PAX_PER_CPU_PGD
18503+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
18504+ pgd_t *pgd = get_cpu_pgd(cpu);
18505+ pmd_t *ret;
18506+#else
18507 list_for_each_entry(page, &pgd_list, lru) {
18508+ pgd_t *pgd = page_address(page);
18509 spinlock_t *pgt_lock;
18510 pmd_t *ret;
18511
18512@@ -241,8 +291,13 @@ void vmalloc_sync_all(void)
18513 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
18514
18515 spin_lock(pgt_lock);
18516- ret = vmalloc_sync_one(page_address(page), address);
18517+#endif
18518+
18519+ ret = vmalloc_sync_one(pgd, address);
18520+
18521+#ifndef CONFIG_PAX_PER_CPU_PGD
18522 spin_unlock(pgt_lock);
18523+#endif
18524
18525 if (!ret)
18526 break;
18527@@ -276,6 +331,11 @@ static noinline __kprobes int vmalloc_fa
18528 * an interrupt in the middle of a task switch..
18529 */
18530 pgd_paddr = read_cr3();
18531+
18532+#ifdef CONFIG_PAX_PER_CPU_PGD
18533+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
18534+#endif
18535+
18536 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
18537 if (!pmd_k)
18538 return -1;
18539@@ -371,7 +431,14 @@ static noinline __kprobes int vmalloc_fa
18540 * happen within a race in page table update. In the later
18541 * case just flush:
18542 */
18543+
18544+#ifdef CONFIG_PAX_PER_CPU_PGD
18545+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
18546+ pgd = pgd_offset_cpu(smp_processor_id(), address);
18547+#else
18548 pgd = pgd_offset(current->active_mm, address);
18549+#endif
18550+
18551 pgd_ref = pgd_offset_k(address);
18552 if (pgd_none(*pgd_ref))
18553 return -1;
18554@@ -533,7 +600,7 @@ static int is_errata93(struct pt_regs *r
18555 static int is_errata100(struct pt_regs *regs, unsigned long address)
18556 {
18557 #ifdef CONFIG_X86_64
18558- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
18559+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
18560 return 1;
18561 #endif
18562 return 0;
18563@@ -560,7 +627,7 @@ static int is_f00f_bug(struct pt_regs *r
18564 }
18565
18566 static const char nx_warning[] = KERN_CRIT
18567-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
18568+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
18569
18570 static void
18571 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
18572@@ -569,14 +636,25 @@ show_fault_oops(struct pt_regs *regs, un
18573 if (!oops_may_print())
18574 return;
18575
18576- if (error_code & PF_INSTR) {
18577+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
18578 unsigned int level;
18579
18580 pte_t *pte = lookup_address(address, &level);
18581
18582 if (pte && pte_present(*pte) && !pte_exec(*pte))
18583- printk(nx_warning, current_uid());
18584+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
18585+ }
18586+
18587+#ifdef CONFIG_PAX_KERNEXEC
18588+ if (init_mm.start_code <= address && address < init_mm.end_code) {
18589+ if (current->signal->curr_ip)
18590+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
18591+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
18592+ else
18593+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
18594+ current->comm, task_pid_nr(current), current_uid(), current_euid());
18595 }
18596+#endif
18597
18598 printk(KERN_ALERT "BUG: unable to handle kernel ");
18599 if (address < PAGE_SIZE)
18600@@ -702,6 +780,66 @@ __bad_area_nosemaphore(struct pt_regs *r
18601 unsigned long address, int si_code)
18602 {
18603 struct task_struct *tsk = current;
18604+#if defined(CONFIG_X86_64) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18605+ struct mm_struct *mm = tsk->mm;
18606+#endif
18607+
18608+#ifdef CONFIG_X86_64
18609+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
18610+ if (regs->ip == VSYSCALL_ADDR(__NR_vgettimeofday) ||
18611+ regs->ip == VSYSCALL_ADDR(__NR_vtime) ||
18612+ regs->ip == VSYSCALL_ADDR(__NR_vgetcpu)) {
18613+ regs->ip += mm->context.vdso - PAGE_SIZE - VSYSCALL_START;
18614+ return;
18615+ }
18616+ }
18617+#endif
18618+
18619+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18620+ if (mm && (error_code & PF_USER)) {
18621+ unsigned long ip = regs->ip;
18622+
18623+ if (v8086_mode(regs))
18624+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
18625+
18626+ /*
18627+ * It's possible to have interrupts off here:
18628+ */
18629+ local_irq_enable();
18630+
18631+#ifdef CONFIG_PAX_PAGEEXEC
18632+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
18633+ (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
18634+
18635+#ifdef CONFIG_PAX_EMUTRAMP
18636+ switch (pax_handle_fetch_fault(regs)) {
18637+ case 2:
18638+ return;
18639+ }
18640+#endif
18641+
18642+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
18643+ do_group_exit(SIGKILL);
18644+ }
18645+#endif
18646+
18647+#ifdef CONFIG_PAX_SEGMEXEC
18648+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
18649+
18650+#ifdef CONFIG_PAX_EMUTRAMP
18651+ switch (pax_handle_fetch_fault(regs)) {
18652+ case 2:
18653+ return;
18654+ }
18655+#endif
18656+
18657+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
18658+ do_group_exit(SIGKILL);
18659+ }
18660+#endif
18661+
18662+ }
18663+#endif
18664
18665 /* User mode accesses just cause a SIGSEGV */
18666 if (error_code & PF_USER) {
18667@@ -871,6 +1009,99 @@ static int spurious_fault_check(unsigned
18668 return 1;
18669 }
18670
18671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18672+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
18673+{
18674+ pte_t *pte;
18675+ pmd_t *pmd;
18676+ spinlock_t *ptl;
18677+ unsigned char pte_mask;
18678+
18679+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
18680+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
18681+ return 0;
18682+
18683+ /* PaX: it's our fault, let's handle it if we can */
18684+
18685+ /* PaX: take a look at read faults before acquiring any locks */
18686+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
18687+ /* instruction fetch attempt from a protected page in user mode */
18688+ up_read(&mm->mmap_sem);
18689+
18690+#ifdef CONFIG_PAX_EMUTRAMP
18691+ switch (pax_handle_fetch_fault(regs)) {
18692+ case 2:
18693+ return 1;
18694+ }
18695+#endif
18696+
18697+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
18698+ do_group_exit(SIGKILL);
18699+ }
18700+
18701+ pmd = pax_get_pmd(mm, address);
18702+ if (unlikely(!pmd))
18703+ return 0;
18704+
18705+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
18706+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
18707+ pte_unmap_unlock(pte, ptl);
18708+ return 0;
18709+ }
18710+
18711+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
18712+ /* write attempt to a protected page in user mode */
18713+ pte_unmap_unlock(pte, ptl);
18714+ return 0;
18715+ }
18716+
18717+#ifdef CONFIG_SMP
18718+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
18719+#else
18720+ if (likely(address > get_limit(regs->cs)))
18721+#endif
18722+ {
18723+ set_pte(pte, pte_mkread(*pte));
18724+ __flush_tlb_one(address);
18725+ pte_unmap_unlock(pte, ptl);
18726+ up_read(&mm->mmap_sem);
18727+ return 1;
18728+ }
18729+
18730+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
18731+
18732+ /*
18733+ * PaX: fill DTLB with user rights and retry
18734+ */
18735+ __asm__ __volatile__ (
18736+ "orb %2,(%1)\n"
18737+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
18738+/*
18739+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
18740+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
18741+ * page fault when examined during a TLB load attempt. this is true not only
18742+ * for PTEs holding a non-present entry but also present entries that will
18743+ * raise a page fault (such as those set up by PaX, or the copy-on-write
18744+ * mechanism). in effect it means that we do *not* need to flush the TLBs
18745+ * for our target pages since their PTEs are simply not in the TLBs at all.
18746+
18747+ * the best thing in omitting it is that we gain around 15-20% speed in the
18748+ * fast path of the page fault handler and can get rid of tracing since we
18749+ * can no longer flush unintended entries.
18750+ */
18751+ "invlpg (%0)\n"
18752+#endif
18753+ __copyuser_seg"testb $0,(%0)\n"
18754+ "xorb %3,(%1)\n"
18755+ :
18756+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
18757+ : "memory", "cc");
18758+ pte_unmap_unlock(pte, ptl);
18759+ up_read(&mm->mmap_sem);
18760+ return 1;
18761+}
18762+#endif
18763+
18764 /*
18765 * Handle a spurious fault caused by a stale TLB entry.
18766 *
18767@@ -943,6 +1174,9 @@ int show_unhandled_signals = 1;
18768 static inline int
18769 access_error(unsigned long error_code, struct vm_area_struct *vma)
18770 {
18771+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
18772+ return 1;
18773+
18774 if (error_code & PF_WRITE) {
18775 /* write, present and write, not present: */
18776 if (unlikely(!(vma->vm_flags & VM_WRITE)))
18777@@ -976,19 +1210,33 @@ do_page_fault(struct pt_regs *regs, unsi
18778 {
18779 struct vm_area_struct *vma;
18780 struct task_struct *tsk;
18781- unsigned long address;
18782 struct mm_struct *mm;
18783 int fault;
18784 int write = error_code & PF_WRITE;
18785 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
18786 (write ? FAULT_FLAG_WRITE : 0);
18787
18788+ /* Get the faulting address: */
18789+ unsigned long address = read_cr2();
18790+
18791+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18792+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
18793+ if (!search_exception_tables(regs->ip)) {
18794+ bad_area_nosemaphore(regs, error_code, address);
18795+ return;
18796+ }
18797+ if (address < PAX_USER_SHADOW_BASE) {
18798+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
18799+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
18800+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
18801+ } else
18802+ address -= PAX_USER_SHADOW_BASE;
18803+ }
18804+#endif
18805+
18806 tsk = current;
18807 mm = tsk->mm;
18808
18809- /* Get the faulting address: */
18810- address = read_cr2();
18811-
18812 /*
18813 * Detect and handle instructions that would cause a page fault for
18814 * both a tracked kernel page and a userspace page.
18815@@ -1048,7 +1296,7 @@ do_page_fault(struct pt_regs *regs, unsi
18816 * User-mode registers count as a user access even for any
18817 * potential system fault or CPU buglet:
18818 */
18819- if (user_mode_vm(regs)) {
18820+ if (user_mode(regs)) {
18821 local_irq_enable();
18822 error_code |= PF_USER;
18823 } else {
18824@@ -1103,6 +1351,11 @@ retry:
18825 might_sleep();
18826 }
18827
18828+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18829+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
18830+ return;
18831+#endif
18832+
18833 vma = find_vma(mm, address);
18834 if (unlikely(!vma)) {
18835 bad_area(regs, error_code, address);
18836@@ -1114,18 +1367,24 @@ retry:
18837 bad_area(regs, error_code, address);
18838 return;
18839 }
18840- if (error_code & PF_USER) {
18841- /*
18842- * Accessing the stack below %sp is always a bug.
18843- * The large cushion allows instructions like enter
18844- * and pusha to work. ("enter $65535, $31" pushes
18845- * 32 pointers and then decrements %sp by 65535.)
18846- */
18847- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
18848- bad_area(regs, error_code, address);
18849- return;
18850- }
18851+ /*
18852+ * Accessing the stack below %sp is always a bug.
18853+ * The large cushion allows instructions like enter
18854+ * and pusha to work. ("enter $65535, $31" pushes
18855+ * 32 pointers and then decrements %sp by 65535.)
18856+ */
18857+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
18858+ bad_area(regs, error_code, address);
18859+ return;
18860 }
18861+
18862+#ifdef CONFIG_PAX_SEGMEXEC
18863+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
18864+ bad_area(regs, error_code, address);
18865+ return;
18866+ }
18867+#endif
18868+
18869 if (unlikely(expand_stack(vma, address))) {
18870 bad_area(regs, error_code, address);
18871 return;
18872@@ -1180,3 +1439,199 @@ good_area:
18873
18874 up_read(&mm->mmap_sem);
18875 }
18876+
18877+#ifdef CONFIG_PAX_EMUTRAMP
18878+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
18879+{
18880+ int err;
18881+
18882+ do { /* PaX: gcc trampoline emulation #1 */
18883+ unsigned char mov1, mov2;
18884+ unsigned short jmp;
18885+ unsigned int addr1, addr2;
18886+
18887+#ifdef CONFIG_X86_64
18888+ if ((regs->ip + 11) >> 32)
18889+ break;
18890+#endif
18891+
18892+ err = get_user(mov1, (unsigned char __user *)regs->ip);
18893+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
18894+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
18895+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
18896+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
18897+
18898+ if (err)
18899+ break;
18900+
18901+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
18902+ regs->cx = addr1;
18903+ regs->ax = addr2;
18904+ regs->ip = addr2;
18905+ return 2;
18906+ }
18907+ } while (0);
18908+
18909+ do { /* PaX: gcc trampoline emulation #2 */
18910+ unsigned char mov, jmp;
18911+ unsigned int addr1, addr2;
18912+
18913+#ifdef CONFIG_X86_64
18914+ if ((regs->ip + 9) >> 32)
18915+ break;
18916+#endif
18917+
18918+ err = get_user(mov, (unsigned char __user *)regs->ip);
18919+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
18920+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
18921+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
18922+
18923+ if (err)
18924+ break;
18925+
18926+ if (mov == 0xB9 && jmp == 0xE9) {
18927+ regs->cx = addr1;
18928+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
18929+ return 2;
18930+ }
18931+ } while (0);
18932+
18933+ return 1; /* PaX in action */
18934+}
18935+
18936+#ifdef CONFIG_X86_64
18937+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
18938+{
18939+ int err;
18940+
18941+ do { /* PaX: gcc trampoline emulation #1 */
18942+ unsigned short mov1, mov2, jmp1;
18943+ unsigned char jmp2;
18944+ unsigned int addr1;
18945+ unsigned long addr2;
18946+
18947+ err = get_user(mov1, (unsigned short __user *)regs->ip);
18948+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
18949+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
18950+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
18951+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
18952+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
18953+
18954+ if (err)
18955+ break;
18956+
18957+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
18958+ regs->r11 = addr1;
18959+ regs->r10 = addr2;
18960+ regs->ip = addr1;
18961+ return 2;
18962+ }
18963+ } while (0);
18964+
18965+ do { /* PaX: gcc trampoline emulation #2 */
18966+ unsigned short mov1, mov2, jmp1;
18967+ unsigned char jmp2;
18968+ unsigned long addr1, addr2;
18969+
18970+ err = get_user(mov1, (unsigned short __user *)regs->ip);
18971+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
18972+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
18973+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
18974+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
18975+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
18976+
18977+ if (err)
18978+ break;
18979+
18980+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
18981+ regs->r11 = addr1;
18982+ regs->r10 = addr2;
18983+ regs->ip = addr1;
18984+ return 2;
18985+ }
18986+ } while (0);
18987+
18988+ return 1; /* PaX in action */
18989+}
18990+#endif
18991+
18992+/*
18993+ * PaX: decide what to do with offenders (regs->ip = fault address)
18994+ *
18995+ * returns 1 when task should be killed
18996+ * 2 when gcc trampoline was detected
18997+ */
18998+static int pax_handle_fetch_fault(struct pt_regs *regs)
18999+{
19000+ if (v8086_mode(regs))
19001+ return 1;
19002+
19003+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
19004+ return 1;
19005+
19006+#ifdef CONFIG_X86_32
19007+ return pax_handle_fetch_fault_32(regs);
19008+#else
19009+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
19010+ return pax_handle_fetch_fault_32(regs);
19011+ else
19012+ return pax_handle_fetch_fault_64(regs);
19013+#endif
19014+}
19015+#endif
19016+
19017+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19018+void pax_report_insns(void *pc, void *sp)
19019+{
19020+ long i;
19021+
19022+ printk(KERN_ERR "PAX: bytes at PC: ");
19023+ for (i = 0; i < 20; i++) {
19024+ unsigned char c;
19025+ if (get_user(c, (__force unsigned char __user *)pc+i))
19026+ printk(KERN_CONT "?? ");
19027+ else
19028+ printk(KERN_CONT "%02x ", c);
19029+ }
19030+ printk("\n");
19031+
19032+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
19033+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
19034+ unsigned long c;
19035+ if (get_user(c, (__force unsigned long __user *)sp+i))
19036+#ifdef CONFIG_X86_32
19037+ printk(KERN_CONT "???????? ");
19038+#else
19039+ printk(KERN_CONT "???????????????? ");
19040+#endif
19041+ else
19042+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
19043+ }
19044+ printk("\n");
19045+}
19046+#endif
19047+
19048+/**
19049+ * probe_kernel_write(): safely attempt to write to a location
19050+ * @dst: address to write to
19051+ * @src: pointer to the data that shall be written
19052+ * @size: size of the data chunk
19053+ *
19054+ * Safely write to address @dst from the buffer at @src. If a kernel fault
19055+ * happens, handle that and return -EFAULT.
19056+ */
19057+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
19058+{
19059+ long ret;
19060+ mm_segment_t old_fs = get_fs();
19061+
19062+ set_fs(KERNEL_DS);
19063+ pagefault_disable();
19064+ pax_open_kernel();
19065+ ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
19066+ pax_close_kernel();
19067+ pagefault_enable();
19068+ set_fs(old_fs);
19069+
19070+ return ret ? -EFAULT : 0;
19071+}
19072diff -urNp linux-3.0.4/arch/x86/mm/gup.c linux-3.0.4/arch/x86/mm/gup.c
19073--- linux-3.0.4/arch/x86/mm/gup.c 2011-07-21 22:17:23.000000000 -0400
19074+++ linux-3.0.4/arch/x86/mm/gup.c 2011-08-23 21:47:55.000000000 -0400
19075@@ -263,7 +263,7 @@ int __get_user_pages_fast(unsigned long
19076 addr = start;
19077 len = (unsigned long) nr_pages << PAGE_SHIFT;
19078 end = start + len;
19079- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
19080+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
19081 (void __user *)start, len)))
19082 return 0;
19083
19084diff -urNp linux-3.0.4/arch/x86/mm/highmem_32.c linux-3.0.4/arch/x86/mm/highmem_32.c
19085--- linux-3.0.4/arch/x86/mm/highmem_32.c 2011-07-21 22:17:23.000000000 -0400
19086+++ linux-3.0.4/arch/x86/mm/highmem_32.c 2011-08-23 21:47:55.000000000 -0400
19087@@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
19088 idx = type + KM_TYPE_NR*smp_processor_id();
19089 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
19090 BUG_ON(!pte_none(*(kmap_pte-idx)));
19091+
19092+ pax_open_kernel();
19093 set_pte(kmap_pte-idx, mk_pte(page, prot));
19094+ pax_close_kernel();
19095
19096 return (void *)vaddr;
19097 }
19098diff -urNp linux-3.0.4/arch/x86/mm/hugetlbpage.c linux-3.0.4/arch/x86/mm/hugetlbpage.c
19099--- linux-3.0.4/arch/x86/mm/hugetlbpage.c 2011-07-21 22:17:23.000000000 -0400
19100+++ linux-3.0.4/arch/x86/mm/hugetlbpage.c 2011-08-23 21:47:55.000000000 -0400
19101@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
19102 struct hstate *h = hstate_file(file);
19103 struct mm_struct *mm = current->mm;
19104 struct vm_area_struct *vma;
19105- unsigned long start_addr;
19106+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19107+
19108+#ifdef CONFIG_PAX_SEGMEXEC
19109+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19110+ pax_task_size = SEGMEXEC_TASK_SIZE;
19111+#endif
19112+
19113+ pax_task_size -= PAGE_SIZE;
19114
19115 if (len > mm->cached_hole_size) {
19116- start_addr = mm->free_area_cache;
19117+ start_addr = mm->free_area_cache;
19118 } else {
19119- start_addr = TASK_UNMAPPED_BASE;
19120- mm->cached_hole_size = 0;
19121+ start_addr = mm->mmap_base;
19122+ mm->cached_hole_size = 0;
19123 }
19124
19125 full_search:
19126@@ -280,26 +287,27 @@ full_search:
19127
19128 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19129 /* At this point: (!vma || addr < vma->vm_end). */
19130- if (TASK_SIZE - len < addr) {
19131+ if (pax_task_size - len < addr) {
19132 /*
19133 * Start a new search - just in case we missed
19134 * some holes.
19135 */
19136- if (start_addr != TASK_UNMAPPED_BASE) {
19137- start_addr = TASK_UNMAPPED_BASE;
19138+ if (start_addr != mm->mmap_base) {
19139+ start_addr = mm->mmap_base;
19140 mm->cached_hole_size = 0;
19141 goto full_search;
19142 }
19143 return -ENOMEM;
19144 }
19145- if (!vma || addr + len <= vma->vm_start) {
19146- mm->free_area_cache = addr + len;
19147- return addr;
19148- }
19149+ if (check_heap_stack_gap(vma, addr, len))
19150+ break;
19151 if (addr + mm->cached_hole_size < vma->vm_start)
19152 mm->cached_hole_size = vma->vm_start - addr;
19153 addr = ALIGN(vma->vm_end, huge_page_size(h));
19154 }
19155+
19156+ mm->free_area_cache = addr + len;
19157+ return addr;
19158 }
19159
19160 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
19161@@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
19162 {
19163 struct hstate *h = hstate_file(file);
19164 struct mm_struct *mm = current->mm;
19165- struct vm_area_struct *vma, *prev_vma;
19166- unsigned long base = mm->mmap_base, addr = addr0;
19167+ struct vm_area_struct *vma;
19168+ unsigned long base = mm->mmap_base, addr;
19169 unsigned long largest_hole = mm->cached_hole_size;
19170- int first_time = 1;
19171
19172 /* don't allow allocations above current base */
19173 if (mm->free_area_cache > base)
19174@@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmappe
19175 largest_hole = 0;
19176 mm->free_area_cache = base;
19177 }
19178-try_again:
19179+
19180 /* make sure it can fit in the remaining address space */
19181 if (mm->free_area_cache < len)
19182 goto fail;
19183
19184 /* either no address requested or can't fit in requested address hole */
19185- addr = (mm->free_area_cache - len) & huge_page_mask(h);
19186+ addr = (mm->free_area_cache - len);
19187 do {
19188+ addr &= huge_page_mask(h);
19189+ vma = find_vma(mm, addr);
19190 /*
19191 * Lookup failure means no vma is above this address,
19192 * i.e. return with success:
19193- */
19194- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
19195- return addr;
19196-
19197- /*
19198 * new region fits between prev_vma->vm_end and
19199 * vma->vm_start, use it:
19200 */
19201- if (addr + len <= vma->vm_start &&
19202- (!prev_vma || (addr >= prev_vma->vm_end))) {
19203+ if (check_heap_stack_gap(vma, addr, len)) {
19204 /* remember the address as a hint for next time */
19205- mm->cached_hole_size = largest_hole;
19206- return (mm->free_area_cache = addr);
19207- } else {
19208- /* pull free_area_cache down to the first hole */
19209- if (mm->free_area_cache == vma->vm_end) {
19210- mm->free_area_cache = vma->vm_start;
19211- mm->cached_hole_size = largest_hole;
19212- }
19213+ mm->cached_hole_size = largest_hole;
19214+ return (mm->free_area_cache = addr);
19215+ }
19216+ /* pull free_area_cache down to the first hole */
19217+ if (mm->free_area_cache == vma->vm_end) {
19218+ mm->free_area_cache = vma->vm_start;
19219+ mm->cached_hole_size = largest_hole;
19220 }
19221
19222 /* remember the largest hole we saw so far */
19223 if (addr + largest_hole < vma->vm_start)
19224- largest_hole = vma->vm_start - addr;
19225+ largest_hole = vma->vm_start - addr;
19226
19227 /* try just below the current vma->vm_start */
19228- addr = (vma->vm_start - len) & huge_page_mask(h);
19229- } while (len <= vma->vm_start);
19230+ addr = skip_heap_stack_gap(vma, len);
19231+ } while (!IS_ERR_VALUE(addr));
19232
19233 fail:
19234 /*
19235- * if hint left us with no space for the requested
19236- * mapping then try again:
19237- */
19238- if (first_time) {
19239- mm->free_area_cache = base;
19240- largest_hole = 0;
19241- first_time = 0;
19242- goto try_again;
19243- }
19244- /*
19245 * A failed mmap() very likely causes application failure,
19246 * so fall back to the bottom-up function here. This scenario
19247 * can happen with large stack limits and large mmap()
19248 * allocations.
19249 */
19250- mm->free_area_cache = TASK_UNMAPPED_BASE;
19251+
19252+#ifdef CONFIG_PAX_SEGMEXEC
19253+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19254+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19255+ else
19256+#endif
19257+
19258+ mm->mmap_base = TASK_UNMAPPED_BASE;
19259+
19260+#ifdef CONFIG_PAX_RANDMMAP
19261+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19262+ mm->mmap_base += mm->delta_mmap;
19263+#endif
19264+
19265+ mm->free_area_cache = mm->mmap_base;
19266 mm->cached_hole_size = ~0UL;
19267 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
19268 len, pgoff, flags);
19269@@ -386,6 +392,7 @@ fail:
19270 /*
19271 * Restore the topdown base:
19272 */
19273+ mm->mmap_base = base;
19274 mm->free_area_cache = base;
19275 mm->cached_hole_size = ~0UL;
19276
19277@@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *f
19278 struct hstate *h = hstate_file(file);
19279 struct mm_struct *mm = current->mm;
19280 struct vm_area_struct *vma;
19281+ unsigned long pax_task_size = TASK_SIZE;
19282
19283 if (len & ~huge_page_mask(h))
19284 return -EINVAL;
19285- if (len > TASK_SIZE)
19286+
19287+#ifdef CONFIG_PAX_SEGMEXEC
19288+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19289+ pax_task_size = SEGMEXEC_TASK_SIZE;
19290+#endif
19291+
19292+ pax_task_size -= PAGE_SIZE;
19293+
19294+ if (len > pax_task_size)
19295 return -ENOMEM;
19296
19297 if (flags & MAP_FIXED) {
19298@@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *f
19299 if (addr) {
19300 addr = ALIGN(addr, huge_page_size(h));
19301 vma = find_vma(mm, addr);
19302- if (TASK_SIZE - len >= addr &&
19303- (!vma || addr + len <= vma->vm_start))
19304+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
19305 return addr;
19306 }
19307 if (mm->get_unmapped_area == arch_get_unmapped_area)
19308diff -urNp linux-3.0.4/arch/x86/mm/init_32.c linux-3.0.4/arch/x86/mm/init_32.c
19309--- linux-3.0.4/arch/x86/mm/init_32.c 2011-07-21 22:17:23.000000000 -0400
19310+++ linux-3.0.4/arch/x86/mm/init_32.c 2011-08-23 21:47:55.000000000 -0400
19311@@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
19312 }
19313
19314 /*
19315- * Creates a middle page table and puts a pointer to it in the
19316- * given global directory entry. This only returns the gd entry
19317- * in non-PAE compilation mode, since the middle layer is folded.
19318- */
19319-static pmd_t * __init one_md_table_init(pgd_t *pgd)
19320-{
19321- pud_t *pud;
19322- pmd_t *pmd_table;
19323-
19324-#ifdef CONFIG_X86_PAE
19325- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
19326- if (after_bootmem)
19327- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
19328- else
19329- pmd_table = (pmd_t *)alloc_low_page();
19330- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
19331- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
19332- pud = pud_offset(pgd, 0);
19333- BUG_ON(pmd_table != pmd_offset(pud, 0));
19334-
19335- return pmd_table;
19336- }
19337-#endif
19338- pud = pud_offset(pgd, 0);
19339- pmd_table = pmd_offset(pud, 0);
19340-
19341- return pmd_table;
19342-}
19343-
19344-/*
19345 * Create a page table and place a pointer to it in a middle page
19346 * directory entry:
19347 */
19348@@ -123,13 +93,28 @@ static pte_t * __init one_page_table_ini
19349 page_table = (pte_t *)alloc_low_page();
19350
19351 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
19352+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19353+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
19354+#else
19355 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
19356+#endif
19357 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
19358 }
19359
19360 return pte_offset_kernel(pmd, 0);
19361 }
19362
19363+static pmd_t * __init one_md_table_init(pgd_t *pgd)
19364+{
19365+ pud_t *pud;
19366+ pmd_t *pmd_table;
19367+
19368+ pud = pud_offset(pgd, 0);
19369+ pmd_table = pmd_offset(pud, 0);
19370+
19371+ return pmd_table;
19372+}
19373+
19374 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
19375 {
19376 int pgd_idx = pgd_index(vaddr);
19377@@ -203,6 +188,7 @@ page_table_range_init(unsigned long star
19378 int pgd_idx, pmd_idx;
19379 unsigned long vaddr;
19380 pgd_t *pgd;
19381+ pud_t *pud;
19382 pmd_t *pmd;
19383 pte_t *pte = NULL;
19384
19385@@ -212,8 +198,13 @@ page_table_range_init(unsigned long star
19386 pgd = pgd_base + pgd_idx;
19387
19388 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
19389- pmd = one_md_table_init(pgd);
19390- pmd = pmd + pmd_index(vaddr);
19391+ pud = pud_offset(pgd, vaddr);
19392+ pmd = pmd_offset(pud, vaddr);
19393+
19394+#ifdef CONFIG_X86_PAE
19395+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
19396+#endif
19397+
19398 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
19399 pmd++, pmd_idx++) {
19400 pte = page_table_kmap_check(one_page_table_init(pmd),
19401@@ -225,11 +216,20 @@ page_table_range_init(unsigned long star
19402 }
19403 }
19404
19405-static inline int is_kernel_text(unsigned long addr)
19406+static inline int is_kernel_text(unsigned long start, unsigned long end)
19407 {
19408- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
19409- return 1;
19410- return 0;
19411+ if ((start > ktla_ktva((unsigned long)_etext) ||
19412+ end <= ktla_ktva((unsigned long)_stext)) &&
19413+ (start > ktla_ktva((unsigned long)_einittext) ||
19414+ end <= ktla_ktva((unsigned long)_sinittext)) &&
19415+
19416+#ifdef CONFIG_ACPI_SLEEP
19417+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
19418+#endif
19419+
19420+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
19421+ return 0;
19422+ return 1;
19423 }
19424
19425 /*
19426@@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned lo
19427 unsigned long last_map_addr = end;
19428 unsigned long start_pfn, end_pfn;
19429 pgd_t *pgd_base = swapper_pg_dir;
19430- int pgd_idx, pmd_idx, pte_ofs;
19431+ unsigned int pgd_idx, pmd_idx, pte_ofs;
19432 unsigned long pfn;
19433 pgd_t *pgd;
19434+ pud_t *pud;
19435 pmd_t *pmd;
19436 pte_t *pte;
19437 unsigned pages_2m, pages_4k;
19438@@ -281,8 +282,13 @@ repeat:
19439 pfn = start_pfn;
19440 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
19441 pgd = pgd_base + pgd_idx;
19442- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
19443- pmd = one_md_table_init(pgd);
19444+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
19445+ pud = pud_offset(pgd, 0);
19446+ pmd = pmd_offset(pud, 0);
19447+
19448+#ifdef CONFIG_X86_PAE
19449+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
19450+#endif
19451
19452 if (pfn >= end_pfn)
19453 continue;
19454@@ -294,14 +300,13 @@ repeat:
19455 #endif
19456 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
19457 pmd++, pmd_idx++) {
19458- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
19459+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
19460
19461 /*
19462 * Map with big pages if possible, otherwise
19463 * create normal page tables:
19464 */
19465 if (use_pse) {
19466- unsigned int addr2;
19467 pgprot_t prot = PAGE_KERNEL_LARGE;
19468 /*
19469 * first pass will use the same initial
19470@@ -311,11 +316,7 @@ repeat:
19471 __pgprot(PTE_IDENT_ATTR |
19472 _PAGE_PSE);
19473
19474- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
19475- PAGE_OFFSET + PAGE_SIZE-1;
19476-
19477- if (is_kernel_text(addr) ||
19478- is_kernel_text(addr2))
19479+ if (is_kernel_text(address, address + PMD_SIZE))
19480 prot = PAGE_KERNEL_LARGE_EXEC;
19481
19482 pages_2m++;
19483@@ -332,7 +333,7 @@ repeat:
19484 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
19485 pte += pte_ofs;
19486 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
19487- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
19488+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
19489 pgprot_t prot = PAGE_KERNEL;
19490 /*
19491 * first pass will use the same initial
19492@@ -340,7 +341,7 @@ repeat:
19493 */
19494 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
19495
19496- if (is_kernel_text(addr))
19497+ if (is_kernel_text(address, address + PAGE_SIZE))
19498 prot = PAGE_KERNEL_EXEC;
19499
19500 pages_4k++;
19501@@ -472,7 +473,7 @@ void __init native_pagetable_setup_start
19502
19503 pud = pud_offset(pgd, va);
19504 pmd = pmd_offset(pud, va);
19505- if (!pmd_present(*pmd))
19506+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
19507 break;
19508
19509 pte = pte_offset_kernel(pmd, va);
19510@@ -524,12 +525,10 @@ void __init early_ioremap_page_table_ran
19511
19512 static void __init pagetable_init(void)
19513 {
19514- pgd_t *pgd_base = swapper_pg_dir;
19515-
19516- permanent_kmaps_init(pgd_base);
19517+ permanent_kmaps_init(swapper_pg_dir);
19518 }
19519
19520-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
19521+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
19522 EXPORT_SYMBOL_GPL(__supported_pte_mask);
19523
19524 /* user-defined highmem size */
19525@@ -757,6 +756,12 @@ void __init mem_init(void)
19526
19527 pci_iommu_alloc();
19528
19529+#ifdef CONFIG_PAX_PER_CPU_PGD
19530+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
19531+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19532+ KERNEL_PGD_PTRS);
19533+#endif
19534+
19535 #ifdef CONFIG_FLATMEM
19536 BUG_ON(!mem_map);
19537 #endif
19538@@ -774,7 +779,7 @@ void __init mem_init(void)
19539 set_highmem_pages_init();
19540
19541 codesize = (unsigned long) &_etext - (unsigned long) &_text;
19542- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
19543+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
19544 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
19545
19546 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
19547@@ -815,10 +820,10 @@ void __init mem_init(void)
19548 ((unsigned long)&__init_end -
19549 (unsigned long)&__init_begin) >> 10,
19550
19551- (unsigned long)&_etext, (unsigned long)&_edata,
19552- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
19553+ (unsigned long)&_sdata, (unsigned long)&_edata,
19554+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
19555
19556- (unsigned long)&_text, (unsigned long)&_etext,
19557+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
19558 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
19559
19560 /*
19561@@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
19562 if (!kernel_set_to_readonly)
19563 return;
19564
19565+ start = ktla_ktva(start);
19566 pr_debug("Set kernel text: %lx - %lx for read write\n",
19567 start, start+size);
19568
19569@@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
19570 if (!kernel_set_to_readonly)
19571 return;
19572
19573+ start = ktla_ktva(start);
19574 pr_debug("Set kernel text: %lx - %lx for read only\n",
19575 start, start+size);
19576
19577@@ -938,6 +945,7 @@ void mark_rodata_ro(void)
19578 unsigned long start = PFN_ALIGN(_text);
19579 unsigned long size = PFN_ALIGN(_etext) - start;
19580
19581+ start = ktla_ktva(start);
19582 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
19583 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
19584 size >> 10);
19585diff -urNp linux-3.0.4/arch/x86/mm/init_64.c linux-3.0.4/arch/x86/mm/init_64.c
19586--- linux-3.0.4/arch/x86/mm/init_64.c 2011-07-21 22:17:23.000000000 -0400
19587+++ linux-3.0.4/arch/x86/mm/init_64.c 2011-08-23 21:47:55.000000000 -0400
19588@@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpa
19589 * around without checking the pgd every time.
19590 */
19591
19592-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
19593+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
19594 EXPORT_SYMBOL_GPL(__supported_pte_mask);
19595
19596 int force_personality32;
19597@@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long star
19598
19599 for (address = start; address <= end; address += PGDIR_SIZE) {
19600 const pgd_t *pgd_ref = pgd_offset_k(address);
19601+
19602+#ifdef CONFIG_PAX_PER_CPU_PGD
19603+ unsigned long cpu;
19604+#else
19605 struct page *page;
19606+#endif
19607
19608 if (pgd_none(*pgd_ref))
19609 continue;
19610
19611 spin_lock(&pgd_lock);
19612+
19613+#ifdef CONFIG_PAX_PER_CPU_PGD
19614+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
19615+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
19616+#else
19617 list_for_each_entry(page, &pgd_list, lru) {
19618 pgd_t *pgd;
19619 spinlock_t *pgt_lock;
19620@@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long star
19621 /* the pgt_lock only for Xen */
19622 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
19623 spin_lock(pgt_lock);
19624+#endif
19625
19626 if (pgd_none(*pgd))
19627 set_pgd(pgd, *pgd_ref);
19628@@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long star
19629 BUG_ON(pgd_page_vaddr(*pgd)
19630 != pgd_page_vaddr(*pgd_ref));
19631
19632+#ifndef CONFIG_PAX_PER_CPU_PGD
19633 spin_unlock(pgt_lock);
19634+#endif
19635+
19636 }
19637 spin_unlock(&pgd_lock);
19638 }
19639@@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
19640 pmd = fill_pmd(pud, vaddr);
19641 pte = fill_pte(pmd, vaddr);
19642
19643+ pax_open_kernel();
19644 set_pte(pte, new_pte);
19645+ pax_close_kernel();
19646
19647 /*
19648 * It's enough to flush this one mapping.
19649@@ -262,14 +278,12 @@ static void __init __init_extra_mapping(
19650 pgd = pgd_offset_k((unsigned long)__va(phys));
19651 if (pgd_none(*pgd)) {
19652 pud = (pud_t *) spp_getpage();
19653- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
19654- _PAGE_USER));
19655+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
19656 }
19657 pud = pud_offset(pgd, (unsigned long)__va(phys));
19658 if (pud_none(*pud)) {
19659 pmd = (pmd_t *) spp_getpage();
19660- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
19661- _PAGE_USER));
19662+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
19663 }
19664 pmd = pmd_offset(pud, phys);
19665 BUG_ON(!pmd_none(*pmd));
19666@@ -693,6 +707,12 @@ void __init mem_init(void)
19667
19668 pci_iommu_alloc();
19669
19670+#ifdef CONFIG_PAX_PER_CPU_PGD
19671+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
19672+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19673+ KERNEL_PGD_PTRS);
19674+#endif
19675+
19676 /* clear_bss() already clear the empty_zero_page */
19677
19678 reservedpages = 0;
19679@@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
19680 static struct vm_area_struct gate_vma = {
19681 .vm_start = VSYSCALL_START,
19682 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
19683- .vm_page_prot = PAGE_READONLY_EXEC,
19684- .vm_flags = VM_READ | VM_EXEC
19685+ .vm_page_prot = PAGE_READONLY,
19686+ .vm_flags = VM_READ
19687 };
19688
19689 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
19690@@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long add
19691
19692 const char *arch_vma_name(struct vm_area_struct *vma)
19693 {
19694- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
19695+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
19696 return "[vdso]";
19697 if (vma == &gate_vma)
19698 return "[vsyscall]";
19699diff -urNp linux-3.0.4/arch/x86/mm/init.c linux-3.0.4/arch/x86/mm/init.c
19700--- linux-3.0.4/arch/x86/mm/init.c 2011-07-21 22:17:23.000000000 -0400
19701+++ linux-3.0.4/arch/x86/mm/init.c 2011-08-23 21:48:14.000000000 -0400
19702@@ -31,7 +31,7 @@ int direct_gbpages
19703 static void __init find_early_table_space(unsigned long end, int use_pse,
19704 int use_gbpages)
19705 {
19706- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
19707+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
19708 phys_addr_t base;
19709
19710 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
19711@@ -313,12 +313,34 @@ unsigned long __init_refok init_memory_m
19712 */
19713 int devmem_is_allowed(unsigned long pagenr)
19714 {
19715- if (pagenr <= 256)
19716+#ifdef CONFIG_GRKERNSEC_KMEM
19717+ /* allow BDA */
19718+ if (!pagenr)
19719+ return 1;
19720+ /* allow EBDA */
19721+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
19722+ return 1;
19723+#else
19724+ if (!pagenr)
19725+ return 1;
19726+#ifdef CONFIG_VM86
19727+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
19728+ return 1;
19729+#endif
19730+#endif
19731+
19732+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
19733 return 1;
19734+#ifdef CONFIG_GRKERNSEC_KMEM
19735+ /* throw out everything else below 1MB */
19736+ if (pagenr <= 256)
19737+ return 0;
19738+#endif
19739 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
19740 return 0;
19741 if (!page_is_ram(pagenr))
19742 return 1;
19743+
19744 return 0;
19745 }
19746
19747@@ -373,6 +395,86 @@ void free_init_pages(char *what, unsigne
19748
19749 void free_initmem(void)
19750 {
19751+
19752+#ifdef CONFIG_PAX_KERNEXEC
19753+#ifdef CONFIG_X86_32
19754+ /* PaX: limit KERNEL_CS to actual size */
19755+ unsigned long addr, limit;
19756+ struct desc_struct d;
19757+ int cpu;
19758+
19759+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
19760+ limit = (limit - 1UL) >> PAGE_SHIFT;
19761+
19762+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
19763+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
19764+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
19765+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
19766+ }
19767+
19768+ /* PaX: make KERNEL_CS read-only */
19769+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
19770+ if (!paravirt_enabled())
19771+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
19772+/*
19773+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
19774+ pgd = pgd_offset_k(addr);
19775+ pud = pud_offset(pgd, addr);
19776+ pmd = pmd_offset(pud, addr);
19777+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
19778+ }
19779+*/
19780+#ifdef CONFIG_X86_PAE
19781+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
19782+/*
19783+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
19784+ pgd = pgd_offset_k(addr);
19785+ pud = pud_offset(pgd, addr);
19786+ pmd = pmd_offset(pud, addr);
19787+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
19788+ }
19789+*/
19790+#endif
19791+
19792+#ifdef CONFIG_MODULES
19793+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
19794+#endif
19795+
19796+#else
19797+ pgd_t *pgd;
19798+ pud_t *pud;
19799+ pmd_t *pmd;
19800+ unsigned long addr, end;
19801+
19802+ /* PaX: make kernel code/rodata read-only, rest non-executable */
19803+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
19804+ pgd = pgd_offset_k(addr);
19805+ pud = pud_offset(pgd, addr);
19806+ pmd = pmd_offset(pud, addr);
19807+ if (!pmd_present(*pmd))
19808+ continue;
19809+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
19810+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
19811+ else
19812+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
19813+ }
19814+
19815+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
19816+ end = addr + KERNEL_IMAGE_SIZE;
19817+ for (; addr < end; addr += PMD_SIZE) {
19818+ pgd = pgd_offset_k(addr);
19819+ pud = pud_offset(pgd, addr);
19820+ pmd = pmd_offset(pud, addr);
19821+ if (!pmd_present(*pmd))
19822+ continue;
19823+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
19824+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
19825+ }
19826+#endif
19827+
19828+ flush_tlb_all();
19829+#endif
19830+
19831 free_init_pages("unused kernel memory",
19832 (unsigned long)(&__init_begin),
19833 (unsigned long)(&__init_end));
19834diff -urNp linux-3.0.4/arch/x86/mm/iomap_32.c linux-3.0.4/arch/x86/mm/iomap_32.c
19835--- linux-3.0.4/arch/x86/mm/iomap_32.c 2011-07-21 22:17:23.000000000 -0400
19836+++ linux-3.0.4/arch/x86/mm/iomap_32.c 2011-08-23 21:47:55.000000000 -0400
19837@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
19838 type = kmap_atomic_idx_push();
19839 idx = type + KM_TYPE_NR * smp_processor_id();
19840 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
19841+
19842+ pax_open_kernel();
19843 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
19844+ pax_close_kernel();
19845+
19846 arch_flush_lazy_mmu_mode();
19847
19848 return (void *)vaddr;
19849diff -urNp linux-3.0.4/arch/x86/mm/ioremap.c linux-3.0.4/arch/x86/mm/ioremap.c
19850--- linux-3.0.4/arch/x86/mm/ioremap.c 2011-07-21 22:17:23.000000000 -0400
19851+++ linux-3.0.4/arch/x86/mm/ioremap.c 2011-08-23 21:47:55.000000000 -0400
19852@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(re
19853 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
19854 int is_ram = page_is_ram(pfn);
19855
19856- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
19857+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
19858 return NULL;
19859 WARN_ON_ONCE(is_ram);
19860 }
19861@@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
19862 early_param("early_ioremap_debug", early_ioremap_debug_setup);
19863
19864 static __initdata int after_paging_init;
19865-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
19866+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
19867
19868 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
19869 {
19870@@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
19871 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
19872
19873 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
19874- memset(bm_pte, 0, sizeof(bm_pte));
19875- pmd_populate_kernel(&init_mm, pmd, bm_pte);
19876+ pmd_populate_user(&init_mm, pmd, bm_pte);
19877
19878 /*
19879 * The boot-ioremap range spans multiple pmds, for which
19880diff -urNp linux-3.0.4/arch/x86/mm/kmemcheck/kmemcheck.c linux-3.0.4/arch/x86/mm/kmemcheck/kmemcheck.c
19881--- linux-3.0.4/arch/x86/mm/kmemcheck/kmemcheck.c 2011-07-21 22:17:23.000000000 -0400
19882+++ linux-3.0.4/arch/x86/mm/kmemcheck/kmemcheck.c 2011-08-23 21:47:55.000000000 -0400
19883@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
19884 * memory (e.g. tracked pages)? For now, we need this to avoid
19885 * invoking kmemcheck for PnP BIOS calls.
19886 */
19887- if (regs->flags & X86_VM_MASK)
19888+ if (v8086_mode(regs))
19889 return false;
19890- if (regs->cs != __KERNEL_CS)
19891+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
19892 return false;
19893
19894 pte = kmemcheck_pte_lookup(address);
19895diff -urNp linux-3.0.4/arch/x86/mm/mmap.c linux-3.0.4/arch/x86/mm/mmap.c
19896--- linux-3.0.4/arch/x86/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
19897+++ linux-3.0.4/arch/x86/mm/mmap.c 2011-08-23 21:47:55.000000000 -0400
19898@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
19899 * Leave an at least ~128 MB hole with possible stack randomization.
19900 */
19901 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
19902-#define MAX_GAP (TASK_SIZE/6*5)
19903+#define MAX_GAP (pax_task_size/6*5)
19904
19905 /*
19906 * True on X86_32 or when emulating IA32 on X86_64
19907@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
19908 return rnd << PAGE_SHIFT;
19909 }
19910
19911-static unsigned long mmap_base(void)
19912+static unsigned long mmap_base(struct mm_struct *mm)
19913 {
19914 unsigned long gap = rlimit(RLIMIT_STACK);
19915+ unsigned long pax_task_size = TASK_SIZE;
19916+
19917+#ifdef CONFIG_PAX_SEGMEXEC
19918+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19919+ pax_task_size = SEGMEXEC_TASK_SIZE;
19920+#endif
19921
19922 if (gap < MIN_GAP)
19923 gap = MIN_GAP;
19924 else if (gap > MAX_GAP)
19925 gap = MAX_GAP;
19926
19927- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
19928+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
19929 }
19930
19931 /*
19932 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
19933 * does, but not when emulating X86_32
19934 */
19935-static unsigned long mmap_legacy_base(void)
19936+static unsigned long mmap_legacy_base(struct mm_struct *mm)
19937 {
19938- if (mmap_is_ia32())
19939+ if (mmap_is_ia32()) {
19940+
19941+#ifdef CONFIG_PAX_SEGMEXEC
19942+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19943+ return SEGMEXEC_TASK_UNMAPPED_BASE;
19944+ else
19945+#endif
19946+
19947 return TASK_UNMAPPED_BASE;
19948- else
19949+ } else
19950 return TASK_UNMAPPED_BASE + mmap_rnd();
19951 }
19952
19953@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
19954 void arch_pick_mmap_layout(struct mm_struct *mm)
19955 {
19956 if (mmap_is_legacy()) {
19957- mm->mmap_base = mmap_legacy_base();
19958+ mm->mmap_base = mmap_legacy_base(mm);
19959+
19960+#ifdef CONFIG_PAX_RANDMMAP
19961+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19962+ mm->mmap_base += mm->delta_mmap;
19963+#endif
19964+
19965 mm->get_unmapped_area = arch_get_unmapped_area;
19966 mm->unmap_area = arch_unmap_area;
19967 } else {
19968- mm->mmap_base = mmap_base();
19969+ mm->mmap_base = mmap_base(mm);
19970+
19971+#ifdef CONFIG_PAX_RANDMMAP
19972+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19973+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
19974+#endif
19975+
19976 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
19977 mm->unmap_area = arch_unmap_area_topdown;
19978 }
19979diff -urNp linux-3.0.4/arch/x86/mm/mmio-mod.c linux-3.0.4/arch/x86/mm/mmio-mod.c
19980--- linux-3.0.4/arch/x86/mm/mmio-mod.c 2011-07-21 22:17:23.000000000 -0400
19981+++ linux-3.0.4/arch/x86/mm/mmio-mod.c 2011-08-23 21:47:55.000000000 -0400
19982@@ -195,7 +195,7 @@ static void pre(struct kmmio_probe *p, s
19983 break;
19984 default:
19985 {
19986- unsigned char *ip = (unsigned char *)instptr;
19987+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
19988 my_trace->opcode = MMIO_UNKNOWN_OP;
19989 my_trace->width = 0;
19990 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
19991@@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p,
19992 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
19993 void __iomem *addr)
19994 {
19995- static atomic_t next_id;
19996+ static atomic_unchecked_t next_id;
19997 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
19998 /* These are page-unaligned. */
19999 struct mmiotrace_map map = {
20000@@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_
20001 .private = trace
20002 },
20003 .phys = offset,
20004- .id = atomic_inc_return(&next_id)
20005+ .id = atomic_inc_return_unchecked(&next_id)
20006 };
20007 map.map_id = trace->id;
20008
20009diff -urNp linux-3.0.4/arch/x86/mm/pageattr.c linux-3.0.4/arch/x86/mm/pageattr.c
20010--- linux-3.0.4/arch/x86/mm/pageattr.c 2011-07-21 22:17:23.000000000 -0400
20011+++ linux-3.0.4/arch/x86/mm/pageattr.c 2011-08-23 21:47:55.000000000 -0400
20012@@ -261,7 +261,7 @@ static inline pgprot_t static_protection
20013 */
20014 #ifdef CONFIG_PCI_BIOS
20015 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
20016- pgprot_val(forbidden) |= _PAGE_NX;
20017+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
20018 #endif
20019
20020 /*
20021@@ -269,9 +269,10 @@ static inline pgprot_t static_protection
20022 * Does not cover __inittext since that is gone later on. On
20023 * 64bit we do not enforce !NX on the low mapping
20024 */
20025- if (within(address, (unsigned long)_text, (unsigned long)_etext))
20026- pgprot_val(forbidden) |= _PAGE_NX;
20027+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
20028+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
20029
20030+#ifdef CONFIG_DEBUG_RODATA
20031 /*
20032 * The .rodata section needs to be read-only. Using the pfn
20033 * catches all aliases.
20034@@ -279,6 +280,7 @@ static inline pgprot_t static_protection
20035 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
20036 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
20037 pgprot_val(forbidden) |= _PAGE_RW;
20038+#endif
20039
20040 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
20041 /*
20042@@ -317,6 +319,13 @@ static inline pgprot_t static_protection
20043 }
20044 #endif
20045
20046+#ifdef CONFIG_PAX_KERNEXEC
20047+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
20048+ pgprot_val(forbidden) |= _PAGE_RW;
20049+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
20050+ }
20051+#endif
20052+
20053 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
20054
20055 return prot;
20056@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
20057 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
20058 {
20059 /* change init_mm */
20060+ pax_open_kernel();
20061 set_pte_atomic(kpte, pte);
20062+
20063 #ifdef CONFIG_X86_32
20064 if (!SHARED_KERNEL_PMD) {
20065+
20066+#ifdef CONFIG_PAX_PER_CPU_PGD
20067+ unsigned long cpu;
20068+#else
20069 struct page *page;
20070+#endif
20071
20072+#ifdef CONFIG_PAX_PER_CPU_PGD
20073+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
20074+ pgd_t *pgd = get_cpu_pgd(cpu);
20075+#else
20076 list_for_each_entry(page, &pgd_list, lru) {
20077- pgd_t *pgd;
20078+ pgd_t *pgd = (pgd_t *)page_address(page);
20079+#endif
20080+
20081 pud_t *pud;
20082 pmd_t *pmd;
20083
20084- pgd = (pgd_t *)page_address(page) + pgd_index(address);
20085+ pgd += pgd_index(address);
20086 pud = pud_offset(pgd, address);
20087 pmd = pmd_offset(pud, address);
20088 set_pte_atomic((pte_t *)pmd, pte);
20089 }
20090 }
20091 #endif
20092+ pax_close_kernel();
20093 }
20094
20095 static int
20096diff -urNp linux-3.0.4/arch/x86/mm/pageattr-test.c linux-3.0.4/arch/x86/mm/pageattr-test.c
20097--- linux-3.0.4/arch/x86/mm/pageattr-test.c 2011-07-21 22:17:23.000000000 -0400
20098+++ linux-3.0.4/arch/x86/mm/pageattr-test.c 2011-08-23 21:47:55.000000000 -0400
20099@@ -36,7 +36,7 @@ enum {
20100
20101 static int pte_testbit(pte_t pte)
20102 {
20103- return pte_flags(pte) & _PAGE_UNUSED1;
20104+ return pte_flags(pte) & _PAGE_CPA_TEST;
20105 }
20106
20107 struct split_state {
20108diff -urNp linux-3.0.4/arch/x86/mm/pat.c linux-3.0.4/arch/x86/mm/pat.c
20109--- linux-3.0.4/arch/x86/mm/pat.c 2011-07-21 22:17:23.000000000 -0400
20110+++ linux-3.0.4/arch/x86/mm/pat.c 2011-08-23 21:47:55.000000000 -0400
20111@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
20112
20113 if (!entry) {
20114 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
20115- current->comm, current->pid, start, end);
20116+ current->comm, task_pid_nr(current), start, end);
20117 return -EINVAL;
20118 }
20119
20120@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
20121 while (cursor < to) {
20122 if (!devmem_is_allowed(pfn)) {
20123 printk(KERN_INFO
20124- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
20125- current->comm, from, to);
20126+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
20127+ current->comm, from, to, cursor);
20128 return 0;
20129 }
20130 cursor += PAGE_SIZE;
20131@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
20132 printk(KERN_INFO
20133 "%s:%d ioremap_change_attr failed %s "
20134 "for %Lx-%Lx\n",
20135- current->comm, current->pid,
20136+ current->comm, task_pid_nr(current),
20137 cattr_name(flags),
20138 base, (unsigned long long)(base + size));
20139 return -EINVAL;
20140@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
20141 if (want_flags != flags) {
20142 printk(KERN_WARNING
20143 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
20144- current->comm, current->pid,
20145+ current->comm, task_pid_nr(current),
20146 cattr_name(want_flags),
20147 (unsigned long long)paddr,
20148 (unsigned long long)(paddr + size),
20149@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
20150 free_memtype(paddr, paddr + size);
20151 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
20152 " for %Lx-%Lx, got %s\n",
20153- current->comm, current->pid,
20154+ current->comm, task_pid_nr(current),
20155 cattr_name(want_flags),
20156 (unsigned long long)paddr,
20157 (unsigned long long)(paddr + size),
20158diff -urNp linux-3.0.4/arch/x86/mm/pf_in.c linux-3.0.4/arch/x86/mm/pf_in.c
20159--- linux-3.0.4/arch/x86/mm/pf_in.c 2011-07-21 22:17:23.000000000 -0400
20160+++ linux-3.0.4/arch/x86/mm/pf_in.c 2011-08-23 21:47:55.000000000 -0400
20161@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned l
20162 int i;
20163 enum reason_type rv = OTHERS;
20164
20165- p = (unsigned char *)ins_addr;
20166+ p = (unsigned char *)ktla_ktva(ins_addr);
20167 p += skip_prefix(p, &prf);
20168 p += get_opcode(p, &opcode);
20169
20170@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(un
20171 struct prefix_bits prf;
20172 int i;
20173
20174- p = (unsigned char *)ins_addr;
20175+ p = (unsigned char *)ktla_ktva(ins_addr);
20176 p += skip_prefix(p, &prf);
20177 p += get_opcode(p, &opcode);
20178
20179@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned
20180 struct prefix_bits prf;
20181 int i;
20182
20183- p = (unsigned char *)ins_addr;
20184+ p = (unsigned char *)ktla_ktva(ins_addr);
20185 p += skip_prefix(p, &prf);
20186 p += get_opcode(p, &opcode);
20187
20188@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned l
20189 struct prefix_bits prf;
20190 int i;
20191
20192- p = (unsigned char *)ins_addr;
20193+ p = (unsigned char *)ktla_ktva(ins_addr);
20194 p += skip_prefix(p, &prf);
20195 p += get_opcode(p, &opcode);
20196 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
20197@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned l
20198 struct prefix_bits prf;
20199 int i;
20200
20201- p = (unsigned char *)ins_addr;
20202+ p = (unsigned char *)ktla_ktva(ins_addr);
20203 p += skip_prefix(p, &prf);
20204 p += get_opcode(p, &opcode);
20205 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
20206diff -urNp linux-3.0.4/arch/x86/mm/pgtable_32.c linux-3.0.4/arch/x86/mm/pgtable_32.c
20207--- linux-3.0.4/arch/x86/mm/pgtable_32.c 2011-07-21 22:17:23.000000000 -0400
20208+++ linux-3.0.4/arch/x86/mm/pgtable_32.c 2011-08-23 21:47:55.000000000 -0400
20209@@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
20210 return;
20211 }
20212 pte = pte_offset_kernel(pmd, vaddr);
20213+
20214+ pax_open_kernel();
20215 if (pte_val(pteval))
20216 set_pte_at(&init_mm, vaddr, pte, pteval);
20217 else
20218 pte_clear(&init_mm, vaddr, pte);
20219+ pax_close_kernel();
20220
20221 /*
20222 * It's enough to flush this one mapping.
20223diff -urNp linux-3.0.4/arch/x86/mm/pgtable.c linux-3.0.4/arch/x86/mm/pgtable.c
20224--- linux-3.0.4/arch/x86/mm/pgtable.c 2011-07-21 22:17:23.000000000 -0400
20225+++ linux-3.0.4/arch/x86/mm/pgtable.c 2011-08-23 21:47:55.000000000 -0400
20226@@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *p
20227 list_del(&page->lru);
20228 }
20229
20230-#define UNSHARED_PTRS_PER_PGD \
20231- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
20232+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20233+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
20234
20235+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
20236+{
20237+ while (count--)
20238+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
20239+}
20240+#endif
20241+
20242+#ifdef CONFIG_PAX_PER_CPU_PGD
20243+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
20244+{
20245+ while (count--)
20246+
20247+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20248+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
20249+#else
20250+ *dst++ = *src++;
20251+#endif
20252
20253+}
20254+#endif
20255+
20256+#ifdef CONFIG_X86_64
20257+#define pxd_t pud_t
20258+#define pyd_t pgd_t
20259+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
20260+#define pxd_free(mm, pud) pud_free((mm), (pud))
20261+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
20262+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
20263+#define PYD_SIZE PGDIR_SIZE
20264+#else
20265+#define pxd_t pmd_t
20266+#define pyd_t pud_t
20267+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
20268+#define pxd_free(mm, pud) pmd_free((mm), (pud))
20269+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
20270+#define pyd_offset(mm ,address) pud_offset((mm), (address))
20271+#define PYD_SIZE PUD_SIZE
20272+#endif
20273+
20274+#ifdef CONFIG_PAX_PER_CPU_PGD
20275+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
20276+static inline void pgd_dtor(pgd_t *pgd) {}
20277+#else
20278 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
20279 {
20280 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
20281@@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
20282 pgd_list_del(pgd);
20283 spin_unlock(&pgd_lock);
20284 }
20285+#endif
20286
20287 /*
20288 * List of all pgd's needed for non-PAE so it can invalidate entries
20289@@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
20290 * -- wli
20291 */
20292
20293-#ifdef CONFIG_X86_PAE
20294+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
20295 /*
20296 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
20297 * updating the top-level pagetable entries to guarantee the
20298@@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
20299 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
20300 * and initialize the kernel pmds here.
20301 */
20302-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
20303+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
20304
20305 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
20306 {
20307@@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm,
20308 */
20309 flush_tlb_mm(mm);
20310 }
20311+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
20312+#define PREALLOCATED_PXDS USER_PGD_PTRS
20313 #else /* !CONFIG_X86_PAE */
20314
20315 /* No need to prepopulate any pagetable entries in non-PAE modes. */
20316-#define PREALLOCATED_PMDS 0
20317+#define PREALLOCATED_PXDS 0
20318
20319 #endif /* CONFIG_X86_PAE */
20320
20321-static void free_pmds(pmd_t *pmds[])
20322+static void free_pxds(pxd_t *pxds[])
20323 {
20324 int i;
20325
20326- for(i = 0; i < PREALLOCATED_PMDS; i++)
20327- if (pmds[i])
20328- free_page((unsigned long)pmds[i]);
20329+ for(i = 0; i < PREALLOCATED_PXDS; i++)
20330+ if (pxds[i])
20331+ free_page((unsigned long)pxds[i]);
20332 }
20333
20334-static int preallocate_pmds(pmd_t *pmds[])
20335+static int preallocate_pxds(pxd_t *pxds[])
20336 {
20337 int i;
20338 bool failed = false;
20339
20340- for(i = 0; i < PREALLOCATED_PMDS; i++) {
20341- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
20342- if (pmd == NULL)
20343+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
20344+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
20345+ if (pxd == NULL)
20346 failed = true;
20347- pmds[i] = pmd;
20348+ pxds[i] = pxd;
20349 }
20350
20351 if (failed) {
20352- free_pmds(pmds);
20353+ free_pxds(pxds);
20354 return -ENOMEM;
20355 }
20356
20357@@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[
20358 * preallocate which never got a corresponding vma will need to be
20359 * freed manually.
20360 */
20361-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
20362+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
20363 {
20364 int i;
20365
20366- for(i = 0; i < PREALLOCATED_PMDS; i++) {
20367+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
20368 pgd_t pgd = pgdp[i];
20369
20370 if (pgd_val(pgd) != 0) {
20371- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
20372+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
20373
20374- pgdp[i] = native_make_pgd(0);
20375+ set_pgd(pgdp + i, native_make_pgd(0));
20376
20377- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
20378- pmd_free(mm, pmd);
20379+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
20380+ pxd_free(mm, pxd);
20381 }
20382 }
20383 }
20384
20385-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
20386+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
20387 {
20388- pud_t *pud;
20389+ pyd_t *pyd;
20390 unsigned long addr;
20391 int i;
20392
20393- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
20394+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
20395 return;
20396
20397- pud = pud_offset(pgd, 0);
20398+#ifdef CONFIG_X86_64
20399+ pyd = pyd_offset(mm, 0L);
20400+#else
20401+ pyd = pyd_offset(pgd, 0L);
20402+#endif
20403
20404- for (addr = i = 0; i < PREALLOCATED_PMDS;
20405- i++, pud++, addr += PUD_SIZE) {
20406- pmd_t *pmd = pmds[i];
20407+ for (addr = i = 0; i < PREALLOCATED_PXDS;
20408+ i++, pyd++, addr += PYD_SIZE) {
20409+ pxd_t *pxd = pxds[i];
20410
20411 if (i >= KERNEL_PGD_BOUNDARY)
20412- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
20413- sizeof(pmd_t) * PTRS_PER_PMD);
20414+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
20415+ sizeof(pxd_t) * PTRS_PER_PMD);
20416
20417- pud_populate(mm, pud, pmd);
20418+ pyd_populate(mm, pyd, pxd);
20419 }
20420 }
20421
20422 pgd_t *pgd_alloc(struct mm_struct *mm)
20423 {
20424 pgd_t *pgd;
20425- pmd_t *pmds[PREALLOCATED_PMDS];
20426+ pxd_t *pxds[PREALLOCATED_PXDS];
20427
20428 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
20429
20430@@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
20431
20432 mm->pgd = pgd;
20433
20434- if (preallocate_pmds(pmds) != 0)
20435+ if (preallocate_pxds(pxds) != 0)
20436 goto out_free_pgd;
20437
20438 if (paravirt_pgd_alloc(mm) != 0)
20439- goto out_free_pmds;
20440+ goto out_free_pxds;
20441
20442 /*
20443 * Make sure that pre-populating the pmds is atomic with
20444@@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
20445 spin_lock(&pgd_lock);
20446
20447 pgd_ctor(mm, pgd);
20448- pgd_prepopulate_pmd(mm, pgd, pmds);
20449+ pgd_prepopulate_pxd(mm, pgd, pxds);
20450
20451 spin_unlock(&pgd_lock);
20452
20453 return pgd;
20454
20455-out_free_pmds:
20456- free_pmds(pmds);
20457+out_free_pxds:
20458+ free_pxds(pxds);
20459 out_free_pgd:
20460 free_page((unsigned long)pgd);
20461 out:
20462@@ -295,7 +344,7 @@ out:
20463
20464 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
20465 {
20466- pgd_mop_up_pmds(mm, pgd);
20467+ pgd_mop_up_pxds(mm, pgd);
20468 pgd_dtor(pgd);
20469 paravirt_pgd_free(mm, pgd);
20470 free_page((unsigned long)pgd);
20471diff -urNp linux-3.0.4/arch/x86/mm/setup_nx.c linux-3.0.4/arch/x86/mm/setup_nx.c
20472--- linux-3.0.4/arch/x86/mm/setup_nx.c 2011-07-21 22:17:23.000000000 -0400
20473+++ linux-3.0.4/arch/x86/mm/setup_nx.c 2011-08-23 21:47:55.000000000 -0400
20474@@ -5,8 +5,10 @@
20475 #include <asm/pgtable.h>
20476 #include <asm/proto.h>
20477
20478+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
20479 static int disable_nx __cpuinitdata;
20480
20481+#ifndef CONFIG_PAX_PAGEEXEC
20482 /*
20483 * noexec = on|off
20484 *
20485@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
20486 return 0;
20487 }
20488 early_param("noexec", noexec_setup);
20489+#endif
20490+
20491+#endif
20492
20493 void __cpuinit x86_configure_nx(void)
20494 {
20495+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
20496 if (cpu_has_nx && !disable_nx)
20497 __supported_pte_mask |= _PAGE_NX;
20498 else
20499+#endif
20500 __supported_pte_mask &= ~_PAGE_NX;
20501 }
20502
20503diff -urNp linux-3.0.4/arch/x86/mm/tlb.c linux-3.0.4/arch/x86/mm/tlb.c
20504--- linux-3.0.4/arch/x86/mm/tlb.c 2011-07-21 22:17:23.000000000 -0400
20505+++ linux-3.0.4/arch/x86/mm/tlb.c 2011-08-23 21:47:55.000000000 -0400
20506@@ -65,7 +65,11 @@ void leave_mm(int cpu)
20507 BUG();
20508 cpumask_clear_cpu(cpu,
20509 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
20510+
20511+#ifndef CONFIG_PAX_PER_CPU_PGD
20512 load_cr3(swapper_pg_dir);
20513+#endif
20514+
20515 }
20516 EXPORT_SYMBOL_GPL(leave_mm);
20517
20518diff -urNp linux-3.0.4/arch/x86/net/bpf_jit_comp.c linux-3.0.4/arch/x86/net/bpf_jit_comp.c
20519--- linux-3.0.4/arch/x86/net/bpf_jit_comp.c 2011-07-21 22:17:23.000000000 -0400
20520+++ linux-3.0.4/arch/x86/net/bpf_jit_comp.c 2011-08-23 21:47:55.000000000 -0400
20521@@ -589,7 +589,9 @@ cond_branch: f_offset = addrs[i + filt
20522 module_free(NULL, image);
20523 return;
20524 }
20525+ pax_open_kernel();
20526 memcpy(image + proglen, temp, ilen);
20527+ pax_close_kernel();
20528 }
20529 proglen += ilen;
20530 addrs[i] = proglen;
20531@@ -609,7 +611,7 @@ cond_branch: f_offset = addrs[i + filt
20532 break;
20533 }
20534 if (proglen == oldproglen) {
20535- image = module_alloc(max_t(unsigned int,
20536+ image = module_alloc_exec(max_t(unsigned int,
20537 proglen,
20538 sizeof(struct work_struct)));
20539 if (!image)
20540diff -urNp linux-3.0.4/arch/x86/oprofile/backtrace.c linux-3.0.4/arch/x86/oprofile/backtrace.c
20541--- linux-3.0.4/arch/x86/oprofile/backtrace.c 2011-08-23 21:44:40.000000000 -0400
20542+++ linux-3.0.4/arch/x86/oprofile/backtrace.c 2011-08-23 21:47:55.000000000 -0400
20543@@ -148,7 +148,7 @@ x86_backtrace(struct pt_regs * const reg
20544 {
20545 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
20546
20547- if (!user_mode_vm(regs)) {
20548+ if (!user_mode(regs)) {
20549 unsigned long stack = kernel_stack_pointer(regs);
20550 if (depth)
20551 dump_trace(NULL, regs, (unsigned long *)stack, 0,
20552diff -urNp linux-3.0.4/arch/x86/pci/mrst.c linux-3.0.4/arch/x86/pci/mrst.c
20553--- linux-3.0.4/arch/x86/pci/mrst.c 2011-07-21 22:17:23.000000000 -0400
20554+++ linux-3.0.4/arch/x86/pci/mrst.c 2011-08-23 21:47:55.000000000 -0400
20555@@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
20556 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
20557 pci_mmcfg_late_init();
20558 pcibios_enable_irq = mrst_pci_irq_enable;
20559- pci_root_ops = pci_mrst_ops;
20560+ pax_open_kernel();
20561+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
20562+ pax_close_kernel();
20563 /* Continue with standard init */
20564 return 1;
20565 }
20566diff -urNp linux-3.0.4/arch/x86/pci/pcbios.c linux-3.0.4/arch/x86/pci/pcbios.c
20567--- linux-3.0.4/arch/x86/pci/pcbios.c 2011-07-21 22:17:23.000000000 -0400
20568+++ linux-3.0.4/arch/x86/pci/pcbios.c 2011-08-23 21:47:55.000000000 -0400
20569@@ -79,50 +79,93 @@ union bios32 {
20570 static struct {
20571 unsigned long address;
20572 unsigned short segment;
20573-} bios32_indirect = { 0, __KERNEL_CS };
20574+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
20575
20576 /*
20577 * Returns the entry point for the given service, NULL on error
20578 */
20579
20580-static unsigned long bios32_service(unsigned long service)
20581+static unsigned long __devinit bios32_service(unsigned long service)
20582 {
20583 unsigned char return_code; /* %al */
20584 unsigned long address; /* %ebx */
20585 unsigned long length; /* %ecx */
20586 unsigned long entry; /* %edx */
20587 unsigned long flags;
20588+ struct desc_struct d, *gdt;
20589
20590 local_irq_save(flags);
20591- __asm__("lcall *(%%edi); cld"
20592+
20593+ gdt = get_cpu_gdt_table(smp_processor_id());
20594+
20595+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
20596+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
20597+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
20598+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
20599+
20600+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
20601 : "=a" (return_code),
20602 "=b" (address),
20603 "=c" (length),
20604 "=d" (entry)
20605 : "0" (service),
20606 "1" (0),
20607- "D" (&bios32_indirect));
20608+ "D" (&bios32_indirect),
20609+ "r"(__PCIBIOS_DS)
20610+ : "memory");
20611+
20612+ pax_open_kernel();
20613+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
20614+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
20615+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
20616+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
20617+ pax_close_kernel();
20618+
20619 local_irq_restore(flags);
20620
20621 switch (return_code) {
20622- case 0:
20623- return address + entry;
20624- case 0x80: /* Not present */
20625- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
20626- return 0;
20627- default: /* Shouldn't happen */
20628- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
20629- service, return_code);
20630+ case 0: {
20631+ int cpu;
20632+ unsigned char flags;
20633+
20634+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
20635+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
20636+ printk(KERN_WARNING "bios32_service: not valid\n");
20637 return 0;
20638+ }
20639+ address = address + PAGE_OFFSET;
20640+ length += 16UL; /* some BIOSs underreport this... */
20641+ flags = 4;
20642+ if (length >= 64*1024*1024) {
20643+ length >>= PAGE_SHIFT;
20644+ flags |= 8;
20645+ }
20646+
20647+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
20648+ gdt = get_cpu_gdt_table(cpu);
20649+ pack_descriptor(&d, address, length, 0x9b, flags);
20650+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
20651+ pack_descriptor(&d, address, length, 0x93, flags);
20652+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
20653+ }
20654+ return entry;
20655+ }
20656+ case 0x80: /* Not present */
20657+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
20658+ return 0;
20659+ default: /* Shouldn't happen */
20660+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
20661+ service, return_code);
20662+ return 0;
20663 }
20664 }
20665
20666 static struct {
20667 unsigned long address;
20668 unsigned short segment;
20669-} pci_indirect = { 0, __KERNEL_CS };
20670+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
20671
20672-static int pci_bios_present;
20673+static int pci_bios_present __read_only;
20674
20675 static int __devinit check_pcibios(void)
20676 {
20677@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
20678 unsigned long flags, pcibios_entry;
20679
20680 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
20681- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
20682+ pci_indirect.address = pcibios_entry;
20683
20684 local_irq_save(flags);
20685- __asm__(
20686- "lcall *(%%edi); cld\n\t"
20687+ __asm__("movw %w6, %%ds\n\t"
20688+ "lcall *%%ss:(%%edi); cld\n\t"
20689+ "push %%ss\n\t"
20690+ "pop %%ds\n\t"
20691 "jc 1f\n\t"
20692 "xor %%ah, %%ah\n"
20693 "1:"
20694@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
20695 "=b" (ebx),
20696 "=c" (ecx)
20697 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
20698- "D" (&pci_indirect)
20699+ "D" (&pci_indirect),
20700+ "r" (__PCIBIOS_DS)
20701 : "memory");
20702 local_irq_restore(flags);
20703
20704@@ -188,7 +234,10 @@ static int pci_bios_read(unsigned int se
20705
20706 switch (len) {
20707 case 1:
20708- __asm__("lcall *(%%esi); cld\n\t"
20709+ __asm__("movw %w6, %%ds\n\t"
20710+ "lcall *%%ss:(%%esi); cld\n\t"
20711+ "push %%ss\n\t"
20712+ "pop %%ds\n\t"
20713 "jc 1f\n\t"
20714 "xor %%ah, %%ah\n"
20715 "1:"
20716@@ -197,7 +246,8 @@ static int pci_bios_read(unsigned int se
20717 : "1" (PCIBIOS_READ_CONFIG_BYTE),
20718 "b" (bx),
20719 "D" ((long)reg),
20720- "S" (&pci_indirect));
20721+ "S" (&pci_indirect),
20722+ "r" (__PCIBIOS_DS));
20723 /*
20724 * Zero-extend the result beyond 8 bits, do not trust the
20725 * BIOS having done it:
20726@@ -205,7 +255,10 @@ static int pci_bios_read(unsigned int se
20727 *value &= 0xff;
20728 break;
20729 case 2:
20730- __asm__("lcall *(%%esi); cld\n\t"
20731+ __asm__("movw %w6, %%ds\n\t"
20732+ "lcall *%%ss:(%%esi); cld\n\t"
20733+ "push %%ss\n\t"
20734+ "pop %%ds\n\t"
20735 "jc 1f\n\t"
20736 "xor %%ah, %%ah\n"
20737 "1:"
20738@@ -214,7 +267,8 @@ static int pci_bios_read(unsigned int se
20739 : "1" (PCIBIOS_READ_CONFIG_WORD),
20740 "b" (bx),
20741 "D" ((long)reg),
20742- "S" (&pci_indirect));
20743+ "S" (&pci_indirect),
20744+ "r" (__PCIBIOS_DS));
20745 /*
20746 * Zero-extend the result beyond 16 bits, do not trust the
20747 * BIOS having done it:
20748@@ -222,7 +276,10 @@ static int pci_bios_read(unsigned int se
20749 *value &= 0xffff;
20750 break;
20751 case 4:
20752- __asm__("lcall *(%%esi); cld\n\t"
20753+ __asm__("movw %w6, %%ds\n\t"
20754+ "lcall *%%ss:(%%esi); cld\n\t"
20755+ "push %%ss\n\t"
20756+ "pop %%ds\n\t"
20757 "jc 1f\n\t"
20758 "xor %%ah, %%ah\n"
20759 "1:"
20760@@ -231,7 +288,8 @@ static int pci_bios_read(unsigned int se
20761 : "1" (PCIBIOS_READ_CONFIG_DWORD),
20762 "b" (bx),
20763 "D" ((long)reg),
20764- "S" (&pci_indirect));
20765+ "S" (&pci_indirect),
20766+ "r" (__PCIBIOS_DS));
20767 break;
20768 }
20769
20770@@ -254,7 +312,10 @@ static int pci_bios_write(unsigned int s
20771
20772 switch (len) {
20773 case 1:
20774- __asm__("lcall *(%%esi); cld\n\t"
20775+ __asm__("movw %w6, %%ds\n\t"
20776+ "lcall *%%ss:(%%esi); cld\n\t"
20777+ "push %%ss\n\t"
20778+ "pop %%ds\n\t"
20779 "jc 1f\n\t"
20780 "xor %%ah, %%ah\n"
20781 "1:"
20782@@ -263,10 +324,14 @@ static int pci_bios_write(unsigned int s
20783 "c" (value),
20784 "b" (bx),
20785 "D" ((long)reg),
20786- "S" (&pci_indirect));
20787+ "S" (&pci_indirect),
20788+ "r" (__PCIBIOS_DS));
20789 break;
20790 case 2:
20791- __asm__("lcall *(%%esi); cld\n\t"
20792+ __asm__("movw %w6, %%ds\n\t"
20793+ "lcall *%%ss:(%%esi); cld\n\t"
20794+ "push %%ss\n\t"
20795+ "pop %%ds\n\t"
20796 "jc 1f\n\t"
20797 "xor %%ah, %%ah\n"
20798 "1:"
20799@@ -275,10 +340,14 @@ static int pci_bios_write(unsigned int s
20800 "c" (value),
20801 "b" (bx),
20802 "D" ((long)reg),
20803- "S" (&pci_indirect));
20804+ "S" (&pci_indirect),
20805+ "r" (__PCIBIOS_DS));
20806 break;
20807 case 4:
20808- __asm__("lcall *(%%esi); cld\n\t"
20809+ __asm__("movw %w6, %%ds\n\t"
20810+ "lcall *%%ss:(%%esi); cld\n\t"
20811+ "push %%ss\n\t"
20812+ "pop %%ds\n\t"
20813 "jc 1f\n\t"
20814 "xor %%ah, %%ah\n"
20815 "1:"
20816@@ -287,7 +356,8 @@ static int pci_bios_write(unsigned int s
20817 "c" (value),
20818 "b" (bx),
20819 "D" ((long)reg),
20820- "S" (&pci_indirect));
20821+ "S" (&pci_indirect),
20822+ "r" (__PCIBIOS_DS));
20823 break;
20824 }
20825
20826@@ -392,10 +462,13 @@ struct irq_routing_table * pcibios_get_i
20827
20828 DBG("PCI: Fetching IRQ routing table... ");
20829 __asm__("push %%es\n\t"
20830+ "movw %w8, %%ds\n\t"
20831 "push %%ds\n\t"
20832 "pop %%es\n\t"
20833- "lcall *(%%esi); cld\n\t"
20834+ "lcall *%%ss:(%%esi); cld\n\t"
20835 "pop %%es\n\t"
20836+ "push %%ss\n\t"
20837+ "pop %%ds\n"
20838 "jc 1f\n\t"
20839 "xor %%ah, %%ah\n"
20840 "1:"
20841@@ -406,7 +479,8 @@ struct irq_routing_table * pcibios_get_i
20842 "1" (0),
20843 "D" ((long) &opt),
20844 "S" (&pci_indirect),
20845- "m" (opt)
20846+ "m" (opt),
20847+ "r" (__PCIBIOS_DS)
20848 : "memory");
20849 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
20850 if (ret & 0xff00)
20851@@ -430,7 +504,10 @@ int pcibios_set_irq_routing(struct pci_d
20852 {
20853 int ret;
20854
20855- __asm__("lcall *(%%esi); cld\n\t"
20856+ __asm__("movw %w5, %%ds\n\t"
20857+ "lcall *%%ss:(%%esi); cld\n\t"
20858+ "push %%ss\n\t"
20859+ "pop %%ds\n"
20860 "jc 1f\n\t"
20861 "xor %%ah, %%ah\n"
20862 "1:"
20863@@ -438,7 +515,8 @@ int pcibios_set_irq_routing(struct pci_d
20864 : "0" (PCIBIOS_SET_PCI_HW_INT),
20865 "b" ((dev->bus->number << 8) | dev->devfn),
20866 "c" ((irq << 8) | (pin + 10)),
20867- "S" (&pci_indirect));
20868+ "S" (&pci_indirect),
20869+ "r" (__PCIBIOS_DS));
20870 return !(ret & 0xff00);
20871 }
20872 EXPORT_SYMBOL(pcibios_set_irq_routing);
20873diff -urNp linux-3.0.4/arch/x86/platform/efi/efi_32.c linux-3.0.4/arch/x86/platform/efi/efi_32.c
20874--- linux-3.0.4/arch/x86/platform/efi/efi_32.c 2011-07-21 22:17:23.000000000 -0400
20875+++ linux-3.0.4/arch/x86/platform/efi/efi_32.c 2011-08-23 21:47:55.000000000 -0400
20876@@ -38,70 +38,37 @@
20877 */
20878
20879 static unsigned long efi_rt_eflags;
20880-static pgd_t efi_bak_pg_dir_pointer[2];
20881+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
20882
20883-void efi_call_phys_prelog(void)
20884+void __init efi_call_phys_prelog(void)
20885 {
20886- unsigned long cr4;
20887- unsigned long temp;
20888 struct desc_ptr gdt_descr;
20889
20890 local_irq_save(efi_rt_eflags);
20891
20892- /*
20893- * If I don't have PAE, I should just duplicate two entries in page
20894- * directory. If I have PAE, I just need to duplicate one entry in
20895- * page directory.
20896- */
20897- cr4 = read_cr4_safe();
20898-
20899- if (cr4 & X86_CR4_PAE) {
20900- efi_bak_pg_dir_pointer[0].pgd =
20901- swapper_pg_dir[pgd_index(0)].pgd;
20902- swapper_pg_dir[0].pgd =
20903- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
20904- } else {
20905- efi_bak_pg_dir_pointer[0].pgd =
20906- swapper_pg_dir[pgd_index(0)].pgd;
20907- efi_bak_pg_dir_pointer[1].pgd =
20908- swapper_pg_dir[pgd_index(0x400000)].pgd;
20909- swapper_pg_dir[pgd_index(0)].pgd =
20910- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
20911- temp = PAGE_OFFSET + 0x400000;
20912- swapper_pg_dir[pgd_index(0x400000)].pgd =
20913- swapper_pg_dir[pgd_index(temp)].pgd;
20914- }
20915+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
20916+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20917+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
20918
20919 /*
20920 * After the lock is released, the original page table is restored.
20921 */
20922 __flush_tlb_all();
20923
20924- gdt_descr.address = __pa(get_cpu_gdt_table(0));
20925+ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
20926 gdt_descr.size = GDT_SIZE - 1;
20927 load_gdt(&gdt_descr);
20928 }
20929
20930-void efi_call_phys_epilog(void)
20931+void __init efi_call_phys_epilog(void)
20932 {
20933- unsigned long cr4;
20934 struct desc_ptr gdt_descr;
20935
20936- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
20937+ gdt_descr.address = get_cpu_gdt_table(0);
20938 gdt_descr.size = GDT_SIZE - 1;
20939 load_gdt(&gdt_descr);
20940
20941- cr4 = read_cr4_safe();
20942-
20943- if (cr4 & X86_CR4_PAE) {
20944- swapper_pg_dir[pgd_index(0)].pgd =
20945- efi_bak_pg_dir_pointer[0].pgd;
20946- } else {
20947- swapper_pg_dir[pgd_index(0)].pgd =
20948- efi_bak_pg_dir_pointer[0].pgd;
20949- swapper_pg_dir[pgd_index(0x400000)].pgd =
20950- efi_bak_pg_dir_pointer[1].pgd;
20951- }
20952+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
20953
20954 /*
20955 * After the lock is released, the original page table is restored.
20956diff -urNp linux-3.0.4/arch/x86/platform/efi/efi_stub_32.S linux-3.0.4/arch/x86/platform/efi/efi_stub_32.S
20957--- linux-3.0.4/arch/x86/platform/efi/efi_stub_32.S 2011-07-21 22:17:23.000000000 -0400
20958+++ linux-3.0.4/arch/x86/platform/efi/efi_stub_32.S 2011-08-23 21:47:55.000000000 -0400
20959@@ -6,6 +6,7 @@
20960 */
20961
20962 #include <linux/linkage.h>
20963+#include <linux/init.h>
20964 #include <asm/page_types.h>
20965
20966 /*
20967@@ -20,7 +21,7 @@
20968 * service functions will comply with gcc calling convention, too.
20969 */
20970
20971-.text
20972+__INIT
20973 ENTRY(efi_call_phys)
20974 /*
20975 * 0. The function can only be called in Linux kernel. So CS has been
20976@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
20977 * The mapping of lower virtual memory has been created in prelog and
20978 * epilog.
20979 */
20980- movl $1f, %edx
20981- subl $__PAGE_OFFSET, %edx
20982- jmp *%edx
20983+ jmp 1f-__PAGE_OFFSET
20984 1:
20985
20986 /*
20987@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
20988 * parameter 2, ..., param n. To make things easy, we save the return
20989 * address of efi_call_phys in a global variable.
20990 */
20991- popl %edx
20992- movl %edx, saved_return_addr
20993- /* get the function pointer into ECX*/
20994- popl %ecx
20995- movl %ecx, efi_rt_function_ptr
20996- movl $2f, %edx
20997- subl $__PAGE_OFFSET, %edx
20998- pushl %edx
20999+ popl (saved_return_addr)
21000+ popl (efi_rt_function_ptr)
21001
21002 /*
21003 * 3. Clear PG bit in %CR0.
21004@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
21005 /*
21006 * 5. Call the physical function.
21007 */
21008- jmp *%ecx
21009+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
21010
21011-2:
21012 /*
21013 * 6. After EFI runtime service returns, control will return to
21014 * following instruction. We'd better readjust stack pointer first.
21015@@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
21016 movl %cr0, %edx
21017 orl $0x80000000, %edx
21018 movl %edx, %cr0
21019- jmp 1f
21020-1:
21021+
21022 /*
21023 * 8. Now restore the virtual mode from flat mode by
21024 * adding EIP with PAGE_OFFSET.
21025 */
21026- movl $1f, %edx
21027- jmp *%edx
21028+ jmp 1f+__PAGE_OFFSET
21029 1:
21030
21031 /*
21032 * 9. Balance the stack. And because EAX contain the return value,
21033 * we'd better not clobber it.
21034 */
21035- leal efi_rt_function_ptr, %edx
21036- movl (%edx), %ecx
21037- pushl %ecx
21038+ pushl (efi_rt_function_ptr)
21039
21040 /*
21041- * 10. Push the saved return address onto the stack and return.
21042+ * 10. Return to the saved return address.
21043 */
21044- leal saved_return_addr, %edx
21045- movl (%edx), %ecx
21046- pushl %ecx
21047- ret
21048+ jmpl *(saved_return_addr)
21049 ENDPROC(efi_call_phys)
21050 .previous
21051
21052-.data
21053+__INITDATA
21054 saved_return_addr:
21055 .long 0
21056 efi_rt_function_ptr:
21057diff -urNp linux-3.0.4/arch/x86/platform/mrst/mrst.c linux-3.0.4/arch/x86/platform/mrst/mrst.c
21058--- linux-3.0.4/arch/x86/platform/mrst/mrst.c 2011-07-21 22:17:23.000000000 -0400
21059+++ linux-3.0.4/arch/x86/platform/mrst/mrst.c 2011-08-23 21:47:55.000000000 -0400
21060@@ -239,14 +239,16 @@ static int mrst_i8042_detect(void)
21061 }
21062
21063 /* Reboot and power off are handled by the SCU on a MID device */
21064-static void mrst_power_off(void)
21065+static __noreturn void mrst_power_off(void)
21066 {
21067 intel_scu_ipc_simple_command(0xf1, 1);
21068+ BUG();
21069 }
21070
21071-static void mrst_reboot(void)
21072+static __noreturn void mrst_reboot(void)
21073 {
21074 intel_scu_ipc_simple_command(0xf1, 0);
21075+ BUG();
21076 }
21077
21078 /*
21079diff -urNp linux-3.0.4/arch/x86/platform/uv/tlb_uv.c linux-3.0.4/arch/x86/platform/uv/tlb_uv.c
21080--- linux-3.0.4/arch/x86/platform/uv/tlb_uv.c 2011-07-21 22:17:23.000000000 -0400
21081+++ linux-3.0.4/arch/x86/platform/uv/tlb_uv.c 2011-08-23 21:48:14.000000000 -0400
21082@@ -373,6 +373,8 @@ static void reset_with_ipi(struct bau_ta
21083 cpumask_t mask;
21084 struct reset_args reset_args;
21085
21086+ pax_track_stack();
21087+
21088 reset_args.sender = sender;
21089 cpus_clear(mask);
21090 /* find a single cpu for each uvhub in this distribution mask */
21091diff -urNp linux-3.0.4/arch/x86/power/cpu.c linux-3.0.4/arch/x86/power/cpu.c
21092--- linux-3.0.4/arch/x86/power/cpu.c 2011-07-21 22:17:23.000000000 -0400
21093+++ linux-3.0.4/arch/x86/power/cpu.c 2011-08-23 21:47:55.000000000 -0400
21094@@ -130,7 +130,7 @@ static void do_fpu_end(void)
21095 static void fix_processor_context(void)
21096 {
21097 int cpu = smp_processor_id();
21098- struct tss_struct *t = &per_cpu(init_tss, cpu);
21099+ struct tss_struct *t = init_tss + cpu;
21100
21101 set_tss_desc(cpu, t); /*
21102 * This just modifies memory; should not be
21103@@ -140,7 +140,9 @@ static void fix_processor_context(void)
21104 */
21105
21106 #ifdef CONFIG_X86_64
21107+ pax_open_kernel();
21108 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
21109+ pax_close_kernel();
21110
21111 syscall_init(); /* This sets MSR_*STAR and related */
21112 #endif
21113diff -urNp linux-3.0.4/arch/x86/vdso/Makefile linux-3.0.4/arch/x86/vdso/Makefile
21114--- linux-3.0.4/arch/x86/vdso/Makefile 2011-07-21 22:17:23.000000000 -0400
21115+++ linux-3.0.4/arch/x86/vdso/Makefile 2011-08-23 21:47:55.000000000 -0400
21116@@ -136,7 +136,7 @@ quiet_cmd_vdso = VDSO $@
21117 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
21118 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
21119
21120-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
21121+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
21122 GCOV_PROFILE := n
21123
21124 #
21125diff -urNp linux-3.0.4/arch/x86/vdso/vdso32-setup.c linux-3.0.4/arch/x86/vdso/vdso32-setup.c
21126--- linux-3.0.4/arch/x86/vdso/vdso32-setup.c 2011-07-21 22:17:23.000000000 -0400
21127+++ linux-3.0.4/arch/x86/vdso/vdso32-setup.c 2011-08-23 21:47:55.000000000 -0400
21128@@ -25,6 +25,7 @@
21129 #include <asm/tlbflush.h>
21130 #include <asm/vdso.h>
21131 #include <asm/proto.h>
21132+#include <asm/mman.h>
21133
21134 enum {
21135 VDSO_DISABLED = 0,
21136@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
21137 void enable_sep_cpu(void)
21138 {
21139 int cpu = get_cpu();
21140- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21141+ struct tss_struct *tss = init_tss + cpu;
21142
21143 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21144 put_cpu();
21145@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
21146 gate_vma.vm_start = FIXADDR_USER_START;
21147 gate_vma.vm_end = FIXADDR_USER_END;
21148 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
21149- gate_vma.vm_page_prot = __P101;
21150+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
21151 /*
21152 * Make sure the vDSO gets into every core dump.
21153 * Dumping its contents makes post-mortem fully interpretable later
21154@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
21155 if (compat)
21156 addr = VDSO_HIGH_BASE;
21157 else {
21158- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
21159+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
21160 if (IS_ERR_VALUE(addr)) {
21161 ret = addr;
21162 goto up_fail;
21163 }
21164 }
21165
21166- current->mm->context.vdso = (void *)addr;
21167+ current->mm->context.vdso = addr;
21168
21169 if (compat_uses_vma || !compat) {
21170 /*
21171@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
21172 }
21173
21174 current_thread_info()->sysenter_return =
21175- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
21176+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
21177
21178 up_fail:
21179 if (ret)
21180- current->mm->context.vdso = NULL;
21181+ current->mm->context.vdso = 0;
21182
21183 up_write(&mm->mmap_sem);
21184
21185@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
21186
21187 const char *arch_vma_name(struct vm_area_struct *vma)
21188 {
21189- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
21190+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
21191 return "[vdso]";
21192+
21193+#ifdef CONFIG_PAX_SEGMEXEC
21194+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
21195+ return "[vdso]";
21196+#endif
21197+
21198 return NULL;
21199 }
21200
21201@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
21202 * Check to see if the corresponding task was created in compat vdso
21203 * mode.
21204 */
21205- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
21206+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
21207 return &gate_vma;
21208 return NULL;
21209 }
21210diff -urNp linux-3.0.4/arch/x86/vdso/vma.c linux-3.0.4/arch/x86/vdso/vma.c
21211--- linux-3.0.4/arch/x86/vdso/vma.c 2011-07-21 22:17:23.000000000 -0400
21212+++ linux-3.0.4/arch/x86/vdso/vma.c 2011-08-23 21:47:55.000000000 -0400
21213@@ -15,18 +15,19 @@
21214 #include <asm/proto.h>
21215 #include <asm/vdso.h>
21216
21217-unsigned int __read_mostly vdso_enabled = 1;
21218-
21219 extern char vdso_start[], vdso_end[];
21220 extern unsigned short vdso_sync_cpuid;
21221+extern char __vsyscall_0;
21222
21223 static struct page **vdso_pages;
21224+static struct page *vsyscall_page;
21225 static unsigned vdso_size;
21226
21227 static int __init init_vdso_vars(void)
21228 {
21229- int npages = (vdso_end - vdso_start + PAGE_SIZE - 1) / PAGE_SIZE;
21230- int i;
21231+ size_t nbytes = vdso_end - vdso_start;
21232+ size_t npages = (nbytes + PAGE_SIZE - 1) / PAGE_SIZE;
21233+ size_t i;
21234
21235 vdso_size = npages << PAGE_SHIFT;
21236 vdso_pages = kmalloc(sizeof(struct page *) * npages, GFP_KERNEL);
21237@@ -34,19 +35,19 @@ static int __init init_vdso_vars(void)
21238 goto oom;
21239 for (i = 0; i < npages; i++) {
21240 struct page *p;
21241- p = alloc_page(GFP_KERNEL);
21242+ p = alloc_page(GFP_KERNEL | __GFP_ZERO);
21243 if (!p)
21244 goto oom;
21245 vdso_pages[i] = p;
21246- copy_page(page_address(p), vdso_start + i*PAGE_SIZE);
21247+ memcpy(page_address(p), vdso_start + i*PAGE_SIZE, nbytes > PAGE_SIZE ? PAGE_SIZE : nbytes);
21248+ nbytes -= PAGE_SIZE;
21249 }
21250+ vsyscall_page = pfn_to_page((__pa_symbol(&__vsyscall_0)) >> PAGE_SHIFT);
21251
21252 return 0;
21253
21254 oom:
21255- printk("Cannot allocate vdso\n");
21256- vdso_enabled = 0;
21257- return -ENOMEM;
21258+ panic("Cannot allocate vdso\n");
21259 }
21260 subsys_initcall(init_vdso_vars);
21261
21262@@ -80,37 +81,35 @@ int arch_setup_additional_pages(struct l
21263 unsigned long addr;
21264 int ret;
21265
21266- if (!vdso_enabled)
21267- return 0;
21268-
21269 down_write(&mm->mmap_sem);
21270- addr = vdso_addr(mm->start_stack, vdso_size);
21271- addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
21272+ addr = vdso_addr(mm->start_stack, vdso_size + PAGE_SIZE);
21273+ addr = get_unmapped_area(NULL, addr, vdso_size + PAGE_SIZE, 0, 0);
21274 if (IS_ERR_VALUE(addr)) {
21275 ret = addr;
21276 goto up_fail;
21277 }
21278
21279- current->mm->context.vdso = (void *)addr;
21280+ mm->context.vdso = addr + PAGE_SIZE;
21281
21282- ret = install_special_mapping(mm, addr, vdso_size,
21283+ ret = install_special_mapping(mm, addr, PAGE_SIZE,
21284 VM_READ|VM_EXEC|
21285- VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
21286+ VM_MAYREAD|VM_MAYEXEC|
21287 VM_ALWAYSDUMP,
21288- vdso_pages);
21289+ &vsyscall_page);
21290 if (ret) {
21291- current->mm->context.vdso = NULL;
21292+ mm->context.vdso = 0;
21293 goto up_fail;
21294 }
21295
21296+ ret = install_special_mapping(mm, addr + PAGE_SIZE, vdso_size,
21297+ VM_READ|VM_EXEC|
21298+ VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
21299+ VM_ALWAYSDUMP,
21300+ vdso_pages);
21301+ if (ret)
21302+ mm->context.vdso = 0;
21303+
21304 up_fail:
21305 up_write(&mm->mmap_sem);
21306 return ret;
21307 }
21308-
21309-static __init int vdso_setup(char *s)
21310-{
21311- vdso_enabled = simple_strtoul(s, NULL, 0);
21312- return 0;
21313-}
21314-__setup("vdso=", vdso_setup);
21315diff -urNp linux-3.0.4/arch/x86/xen/enlighten.c linux-3.0.4/arch/x86/xen/enlighten.c
21316--- linux-3.0.4/arch/x86/xen/enlighten.c 2011-08-29 23:26:13.000000000 -0400
21317+++ linux-3.0.4/arch/x86/xen/enlighten.c 2011-08-29 23:26:21.000000000 -0400
21318@@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
21319
21320 struct shared_info xen_dummy_shared_info;
21321
21322-void *xen_initial_gdt;
21323-
21324 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
21325 __read_mostly int xen_have_vector_callback;
21326 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
21327@@ -1010,7 +1008,7 @@ static const struct pv_apic_ops xen_apic
21328 #endif
21329 };
21330
21331-static void xen_reboot(int reason)
21332+static __noreturn void xen_reboot(int reason)
21333 {
21334 struct sched_shutdown r = { .reason = reason };
21335
21336@@ -1018,17 +1016,17 @@ static void xen_reboot(int reason)
21337 BUG();
21338 }
21339
21340-static void xen_restart(char *msg)
21341+static __noreturn void xen_restart(char *msg)
21342 {
21343 xen_reboot(SHUTDOWN_reboot);
21344 }
21345
21346-static void xen_emergency_restart(void)
21347+static __noreturn void xen_emergency_restart(void)
21348 {
21349 xen_reboot(SHUTDOWN_reboot);
21350 }
21351
21352-static void xen_machine_halt(void)
21353+static __noreturn void xen_machine_halt(void)
21354 {
21355 xen_reboot(SHUTDOWN_poweroff);
21356 }
21357@@ -1134,7 +1132,17 @@ asmlinkage void __init xen_start_kernel(
21358 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
21359
21360 /* Work out if we support NX */
21361- x86_configure_nx();
21362+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
21363+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
21364+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
21365+ unsigned l, h;
21366+
21367+ __supported_pte_mask |= _PAGE_NX;
21368+ rdmsr(MSR_EFER, l, h);
21369+ l |= EFER_NX;
21370+ wrmsr(MSR_EFER, l, h);
21371+ }
21372+#endif
21373
21374 xen_setup_features();
21375
21376@@ -1165,13 +1173,6 @@ asmlinkage void __init xen_start_kernel(
21377
21378 machine_ops = xen_machine_ops;
21379
21380- /*
21381- * The only reliable way to retain the initial address of the
21382- * percpu gdt_page is to remember it here, so we can go and
21383- * mark it RW later, when the initial percpu area is freed.
21384- */
21385- xen_initial_gdt = &per_cpu(gdt_page, 0);
21386-
21387 xen_smp_init();
21388
21389 #ifdef CONFIG_ACPI_NUMA
21390diff -urNp linux-3.0.4/arch/x86/xen/mmu.c linux-3.0.4/arch/x86/xen/mmu.c
21391--- linux-3.0.4/arch/x86/xen/mmu.c 2011-08-29 23:26:13.000000000 -0400
21392+++ linux-3.0.4/arch/x86/xen/mmu.c 2011-08-29 23:26:21.000000000 -0400
21393@@ -1683,6 +1683,8 @@ pgd_t * __init xen_setup_kernel_pagetabl
21394 convert_pfn_mfn(init_level4_pgt);
21395 convert_pfn_mfn(level3_ident_pgt);
21396 convert_pfn_mfn(level3_kernel_pgt);
21397+ convert_pfn_mfn(level3_vmalloc_pgt);
21398+ convert_pfn_mfn(level3_vmemmap_pgt);
21399
21400 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
21401 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
21402@@ -1701,7 +1703,10 @@ pgd_t * __init xen_setup_kernel_pagetabl
21403 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
21404 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
21405 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
21406+ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
21407+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
21408 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
21409+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
21410 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
21411 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
21412
21413@@ -1913,6 +1918,7 @@ static void __init xen_post_allocator_in
21414 pv_mmu_ops.set_pud = xen_set_pud;
21415 #if PAGETABLE_LEVELS == 4
21416 pv_mmu_ops.set_pgd = xen_set_pgd;
21417+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
21418 #endif
21419
21420 /* This will work as long as patching hasn't happened yet
21421@@ -1994,6 +2000,7 @@ static const struct pv_mmu_ops xen_mmu_o
21422 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
21423 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
21424 .set_pgd = xen_set_pgd_hyper,
21425+ .set_pgd_batched = xen_set_pgd_hyper,
21426
21427 .alloc_pud = xen_alloc_pmd_init,
21428 .release_pud = xen_release_pmd_init,
21429diff -urNp linux-3.0.4/arch/x86/xen/smp.c linux-3.0.4/arch/x86/xen/smp.c
21430--- linux-3.0.4/arch/x86/xen/smp.c 2011-08-29 23:26:13.000000000 -0400
21431+++ linux-3.0.4/arch/x86/xen/smp.c 2011-08-29 23:26:21.000000000 -0400
21432@@ -193,11 +193,6 @@ static void __init xen_smp_prepare_boot_
21433 {
21434 BUG_ON(smp_processor_id() != 0);
21435 native_smp_prepare_boot_cpu();
21436-
21437- /* We've switched to the "real" per-cpu gdt, so make sure the
21438- old memory can be recycled */
21439- make_lowmem_page_readwrite(xen_initial_gdt);
21440-
21441 xen_filter_cpu_maps();
21442 xen_setup_vcpu_info_placement();
21443 }
21444@@ -265,12 +260,12 @@ cpu_initialize_context(unsigned int cpu,
21445 gdt = get_cpu_gdt_table(cpu);
21446
21447 ctxt->flags = VGCF_IN_KERNEL;
21448- ctxt->user_regs.ds = __USER_DS;
21449- ctxt->user_regs.es = __USER_DS;
21450+ ctxt->user_regs.ds = __KERNEL_DS;
21451+ ctxt->user_regs.es = __KERNEL_DS;
21452 ctxt->user_regs.ss = __KERNEL_DS;
21453 #ifdef CONFIG_X86_32
21454 ctxt->user_regs.fs = __KERNEL_PERCPU;
21455- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
21456+ savesegment(gs, ctxt->user_regs.gs);
21457 #else
21458 ctxt->gs_base_kernel = per_cpu_offset(cpu);
21459 #endif
21460@@ -321,13 +316,12 @@ static int __cpuinit xen_cpu_up(unsigned
21461 int rc;
21462
21463 per_cpu(current_task, cpu) = idle;
21464+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
21465 #ifdef CONFIG_X86_32
21466 irq_ctx_init(cpu);
21467 #else
21468 clear_tsk_thread_flag(idle, TIF_FORK);
21469- per_cpu(kernel_stack, cpu) =
21470- (unsigned long)task_stack_page(idle) -
21471- KERNEL_STACK_OFFSET + THREAD_SIZE;
21472+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
21473 #endif
21474 xen_setup_runstate_info(cpu);
21475 xen_setup_timer(cpu);
21476diff -urNp linux-3.0.4/arch/x86/xen/xen-asm_32.S linux-3.0.4/arch/x86/xen/xen-asm_32.S
21477--- linux-3.0.4/arch/x86/xen/xen-asm_32.S 2011-07-21 22:17:23.000000000 -0400
21478+++ linux-3.0.4/arch/x86/xen/xen-asm_32.S 2011-08-23 21:47:55.000000000 -0400
21479@@ -83,14 +83,14 @@ ENTRY(xen_iret)
21480 ESP_OFFSET=4 # bytes pushed onto stack
21481
21482 /*
21483- * Store vcpu_info pointer for easy access. Do it this way to
21484- * avoid having to reload %fs
21485+ * Store vcpu_info pointer for easy access.
21486 */
21487 #ifdef CONFIG_SMP
21488- GET_THREAD_INFO(%eax)
21489- movl TI_cpu(%eax), %eax
21490- movl __per_cpu_offset(,%eax,4), %eax
21491- mov xen_vcpu(%eax), %eax
21492+ push %fs
21493+ mov $(__KERNEL_PERCPU), %eax
21494+ mov %eax, %fs
21495+ mov PER_CPU_VAR(xen_vcpu), %eax
21496+ pop %fs
21497 #else
21498 movl xen_vcpu, %eax
21499 #endif
21500diff -urNp linux-3.0.4/arch/x86/xen/xen-head.S linux-3.0.4/arch/x86/xen/xen-head.S
21501--- linux-3.0.4/arch/x86/xen/xen-head.S 2011-07-21 22:17:23.000000000 -0400
21502+++ linux-3.0.4/arch/x86/xen/xen-head.S 2011-08-23 21:47:55.000000000 -0400
21503@@ -19,6 +19,17 @@ ENTRY(startup_xen)
21504 #ifdef CONFIG_X86_32
21505 mov %esi,xen_start_info
21506 mov $init_thread_union+THREAD_SIZE,%esp
21507+#ifdef CONFIG_SMP
21508+ movl $cpu_gdt_table,%edi
21509+ movl $__per_cpu_load,%eax
21510+ movw %ax,__KERNEL_PERCPU + 2(%edi)
21511+ rorl $16,%eax
21512+ movb %al,__KERNEL_PERCPU + 4(%edi)
21513+ movb %ah,__KERNEL_PERCPU + 7(%edi)
21514+ movl $__per_cpu_end - 1,%eax
21515+ subl $__per_cpu_start,%eax
21516+ movw %ax,__KERNEL_PERCPU + 0(%edi)
21517+#endif
21518 #else
21519 mov %rsi,xen_start_info
21520 mov $init_thread_union+THREAD_SIZE,%rsp
21521diff -urNp linux-3.0.4/arch/x86/xen/xen-ops.h linux-3.0.4/arch/x86/xen/xen-ops.h
21522--- linux-3.0.4/arch/x86/xen/xen-ops.h 2011-08-23 21:44:40.000000000 -0400
21523+++ linux-3.0.4/arch/x86/xen/xen-ops.h 2011-08-23 21:47:55.000000000 -0400
21524@@ -10,8 +10,6 @@
21525 extern const char xen_hypervisor_callback[];
21526 extern const char xen_failsafe_callback[];
21527
21528-extern void *xen_initial_gdt;
21529-
21530 struct trap_info;
21531 void xen_copy_trap_info(struct trap_info *traps);
21532
21533diff -urNp linux-3.0.4/block/blk-iopoll.c linux-3.0.4/block/blk-iopoll.c
21534--- linux-3.0.4/block/blk-iopoll.c 2011-07-21 22:17:23.000000000 -0400
21535+++ linux-3.0.4/block/blk-iopoll.c 2011-08-23 21:47:55.000000000 -0400
21536@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
21537 }
21538 EXPORT_SYMBOL(blk_iopoll_complete);
21539
21540-static void blk_iopoll_softirq(struct softirq_action *h)
21541+static void blk_iopoll_softirq(void)
21542 {
21543 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
21544 int rearm = 0, budget = blk_iopoll_budget;
21545diff -urNp linux-3.0.4/block/blk-map.c linux-3.0.4/block/blk-map.c
21546--- linux-3.0.4/block/blk-map.c 2011-07-21 22:17:23.000000000 -0400
21547+++ linux-3.0.4/block/blk-map.c 2011-08-23 21:47:55.000000000 -0400
21548@@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
21549 if (!len || !kbuf)
21550 return -EINVAL;
21551
21552- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
21553+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
21554 if (do_copy)
21555 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
21556 else
21557diff -urNp linux-3.0.4/block/blk-softirq.c linux-3.0.4/block/blk-softirq.c
21558--- linux-3.0.4/block/blk-softirq.c 2011-07-21 22:17:23.000000000 -0400
21559+++ linux-3.0.4/block/blk-softirq.c 2011-08-23 21:47:55.000000000 -0400
21560@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
21561 * Softirq action handler - move entries to local list and loop over them
21562 * while passing them to the queue registered handler.
21563 */
21564-static void blk_done_softirq(struct softirq_action *h)
21565+static void blk_done_softirq(void)
21566 {
21567 struct list_head *cpu_list, local_list;
21568
21569diff -urNp linux-3.0.4/block/bsg.c linux-3.0.4/block/bsg.c
21570--- linux-3.0.4/block/bsg.c 2011-07-21 22:17:23.000000000 -0400
21571+++ linux-3.0.4/block/bsg.c 2011-08-23 21:47:55.000000000 -0400
21572@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
21573 struct sg_io_v4 *hdr, struct bsg_device *bd,
21574 fmode_t has_write_perm)
21575 {
21576+ unsigned char tmpcmd[sizeof(rq->__cmd)];
21577+ unsigned char *cmdptr;
21578+
21579 if (hdr->request_len > BLK_MAX_CDB) {
21580 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
21581 if (!rq->cmd)
21582 return -ENOMEM;
21583- }
21584+ cmdptr = rq->cmd;
21585+ } else
21586+ cmdptr = tmpcmd;
21587
21588- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
21589+ if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
21590 hdr->request_len))
21591 return -EFAULT;
21592
21593+ if (cmdptr != rq->cmd)
21594+ memcpy(rq->cmd, cmdptr, hdr->request_len);
21595+
21596 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
21597 if (blk_verify_command(rq->cmd, has_write_perm))
21598 return -EPERM;
21599diff -urNp linux-3.0.4/block/scsi_ioctl.c linux-3.0.4/block/scsi_ioctl.c
21600--- linux-3.0.4/block/scsi_ioctl.c 2011-07-21 22:17:23.000000000 -0400
21601+++ linux-3.0.4/block/scsi_ioctl.c 2011-08-23 21:47:55.000000000 -0400
21602@@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
21603 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
21604 struct sg_io_hdr *hdr, fmode_t mode)
21605 {
21606- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
21607+ unsigned char tmpcmd[sizeof(rq->__cmd)];
21608+ unsigned char *cmdptr;
21609+
21610+ if (rq->cmd != rq->__cmd)
21611+ cmdptr = rq->cmd;
21612+ else
21613+ cmdptr = tmpcmd;
21614+
21615+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
21616 return -EFAULT;
21617+
21618+ if (cmdptr != rq->cmd)
21619+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
21620+
21621 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
21622 return -EPERM;
21623
21624@@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *
21625 int err;
21626 unsigned int in_len, out_len, bytes, opcode, cmdlen;
21627 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
21628+ unsigned char tmpcmd[sizeof(rq->__cmd)];
21629+ unsigned char *cmdptr;
21630
21631 if (!sic)
21632 return -EINVAL;
21633@@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *
21634 */
21635 err = -EFAULT;
21636 rq->cmd_len = cmdlen;
21637- if (copy_from_user(rq->cmd, sic->data, cmdlen))
21638+
21639+ if (rq->cmd != rq->__cmd)
21640+ cmdptr = rq->cmd;
21641+ else
21642+ cmdptr = tmpcmd;
21643+
21644+ if (copy_from_user(cmdptr, sic->data, cmdlen))
21645 goto error;
21646
21647+ if (rq->cmd != cmdptr)
21648+ memcpy(rq->cmd, cmdptr, cmdlen);
21649+
21650 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
21651 goto error;
21652
21653diff -urNp linux-3.0.4/crypto/cryptd.c linux-3.0.4/crypto/cryptd.c
21654--- linux-3.0.4/crypto/cryptd.c 2011-07-21 22:17:23.000000000 -0400
21655+++ linux-3.0.4/crypto/cryptd.c 2011-08-23 21:47:55.000000000 -0400
21656@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
21657
21658 struct cryptd_blkcipher_request_ctx {
21659 crypto_completion_t complete;
21660-};
21661+} __no_const;
21662
21663 struct cryptd_hash_ctx {
21664 struct crypto_shash *child;
21665@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
21666
21667 struct cryptd_aead_request_ctx {
21668 crypto_completion_t complete;
21669-};
21670+} __no_const;
21671
21672 static void cryptd_queue_worker(struct work_struct *work);
21673
21674diff -urNp linux-3.0.4/crypto/gf128mul.c linux-3.0.4/crypto/gf128mul.c
21675--- linux-3.0.4/crypto/gf128mul.c 2011-07-21 22:17:23.000000000 -0400
21676+++ linux-3.0.4/crypto/gf128mul.c 2011-08-23 21:47:55.000000000 -0400
21677@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128
21678 for (i = 0; i < 7; ++i)
21679 gf128mul_x_lle(&p[i + 1], &p[i]);
21680
21681- memset(r, 0, sizeof(r));
21682+ memset(r, 0, sizeof(*r));
21683 for (i = 0;;) {
21684 u8 ch = ((u8 *)b)[15 - i];
21685
21686@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128
21687 for (i = 0; i < 7; ++i)
21688 gf128mul_x_bbe(&p[i + 1], &p[i]);
21689
21690- memset(r, 0, sizeof(r));
21691+ memset(r, 0, sizeof(*r));
21692 for (i = 0;;) {
21693 u8 ch = ((u8 *)b)[i];
21694
21695diff -urNp linux-3.0.4/crypto/serpent.c linux-3.0.4/crypto/serpent.c
21696--- linux-3.0.4/crypto/serpent.c 2011-07-21 22:17:23.000000000 -0400
21697+++ linux-3.0.4/crypto/serpent.c 2011-08-23 21:48:14.000000000 -0400
21698@@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
21699 u32 r0,r1,r2,r3,r4;
21700 int i;
21701
21702+ pax_track_stack();
21703+
21704 /* Copy key, add padding */
21705
21706 for (i = 0; i < keylen; ++i)
21707diff -urNp linux-3.0.4/Documentation/dontdiff linux-3.0.4/Documentation/dontdiff
21708--- linux-3.0.4/Documentation/dontdiff 2011-07-21 22:17:23.000000000 -0400
21709+++ linux-3.0.4/Documentation/dontdiff 2011-08-23 21:47:55.000000000 -0400
21710@@ -5,6 +5,7 @@
21711 *.cis
21712 *.cpio
21713 *.csp
21714+*.dbg
21715 *.dsp
21716 *.dvi
21717 *.elf
21718@@ -48,9 +49,11 @@
21719 *.tab.h
21720 *.tex
21721 *.ver
21722+*.vim
21723 *.xml
21724 *.xz
21725 *_MODULES
21726+*_reg_safe.h
21727 *_vga16.c
21728 *~
21729 \#*#
21730@@ -70,6 +73,7 @@ Kerntypes
21731 Module.markers
21732 Module.symvers
21733 PENDING
21734+PERF*
21735 SCCS
21736 System.map*
21737 TAGS
21738@@ -98,6 +102,8 @@ bzImage*
21739 capability_names.h
21740 capflags.c
21741 classlist.h*
21742+clut_vga16.c
21743+common-cmds.h
21744 comp*.log
21745 compile.h*
21746 conf
21747@@ -126,12 +132,14 @@ fore200e_pca_fw.c*
21748 gconf
21749 gconf.glade.h
21750 gen-devlist
21751+gen-kdb_cmds.c
21752 gen_crc32table
21753 gen_init_cpio
21754 generated
21755 genheaders
21756 genksyms
21757 *_gray256.c
21758+hash
21759 hpet_example
21760 hugepage-mmap
21761 hugepage-shm
21762@@ -146,7 +154,6 @@ int32.c
21763 int4.c
21764 int8.c
21765 kallsyms
21766-kconfig
21767 keywords.c
21768 ksym.c*
21769 ksym.h*
21770@@ -154,7 +161,6 @@ kxgettext
21771 lkc_defs.h
21772 lex.c
21773 lex.*.c
21774-linux
21775 logo_*.c
21776 logo_*_clut224.c
21777 logo_*_mono.c
21778@@ -174,6 +180,7 @@ mkboot
21779 mkbugboot
21780 mkcpustr
21781 mkdep
21782+mkpiggy
21783 mkprep
21784 mkregtable
21785 mktables
21786@@ -209,6 +216,7 @@ r300_reg_safe.h
21787 r420_reg_safe.h
21788 r600_reg_safe.h
21789 recordmcount
21790+regdb.c
21791 relocs
21792 rlim_names.h
21793 rn50_reg_safe.h
21794@@ -219,6 +227,7 @@ setup
21795 setup.bin
21796 setup.elf
21797 sImage
21798+slabinfo
21799 sm_tbl*
21800 split-include
21801 syscalltab.h
21802@@ -246,7 +255,9 @@ vmlinux
21803 vmlinux-*
21804 vmlinux.aout
21805 vmlinux.bin.all
21806+vmlinux.bin.bz2
21807 vmlinux.lds
21808+vmlinux.relocs
21809 vmlinuz
21810 voffset.h
21811 vsyscall.lds
21812@@ -254,6 +265,7 @@ vsyscall_32.lds
21813 wanxlfw.inc
21814 uImage
21815 unifdef
21816+utsrelease.h
21817 wakeup.bin
21818 wakeup.elf
21819 wakeup.lds
21820diff -urNp linux-3.0.4/Documentation/kernel-parameters.txt linux-3.0.4/Documentation/kernel-parameters.txt
21821--- linux-3.0.4/Documentation/kernel-parameters.txt 2011-07-21 22:17:23.000000000 -0400
21822+++ linux-3.0.4/Documentation/kernel-parameters.txt 2011-08-23 21:47:55.000000000 -0400
21823@@ -1883,6 +1883,13 @@ bytes respectively. Such letter suffixes
21824 the specified number of seconds. This is to be used if
21825 your oopses keep scrolling off the screen.
21826
21827+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
21828+ virtualization environments that don't cope well with the
21829+ expand down segment used by UDEREF on X86-32 or the frequent
21830+ page table updates on X86-64.
21831+
21832+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
21833+
21834 pcbit= [HW,ISDN]
21835
21836 pcd. [PARIDE]
21837diff -urNp linux-3.0.4/drivers/acpi/apei/cper.c linux-3.0.4/drivers/acpi/apei/cper.c
21838--- linux-3.0.4/drivers/acpi/apei/cper.c 2011-07-21 22:17:23.000000000 -0400
21839+++ linux-3.0.4/drivers/acpi/apei/cper.c 2011-08-23 21:47:55.000000000 -0400
21840@@ -38,12 +38,12 @@
21841 */
21842 u64 cper_next_record_id(void)
21843 {
21844- static atomic64_t seq;
21845+ static atomic64_unchecked_t seq;
21846
21847- if (!atomic64_read(&seq))
21848- atomic64_set(&seq, ((u64)get_seconds()) << 32);
21849+ if (!atomic64_read_unchecked(&seq))
21850+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
21851
21852- return atomic64_inc_return(&seq);
21853+ return atomic64_inc_return_unchecked(&seq);
21854 }
21855 EXPORT_SYMBOL_GPL(cper_next_record_id);
21856
21857diff -urNp linux-3.0.4/drivers/acpi/ec_sys.c linux-3.0.4/drivers/acpi/ec_sys.c
21858--- linux-3.0.4/drivers/acpi/ec_sys.c 2011-07-21 22:17:23.000000000 -0400
21859+++ linux-3.0.4/drivers/acpi/ec_sys.c 2011-08-24 19:06:55.000000000 -0400
21860@@ -11,6 +11,7 @@
21861 #include <linux/kernel.h>
21862 #include <linux/acpi.h>
21863 #include <linux/debugfs.h>
21864+#include <asm/uaccess.h>
21865 #include "internal.h"
21866
21867 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
21868@@ -39,7 +40,7 @@ static ssize_t acpi_ec_read_io(struct fi
21869 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
21870 */
21871 unsigned int size = EC_SPACE_SIZE;
21872- u8 *data = (u8 *) buf;
21873+ u8 data;
21874 loff_t init_off = *off;
21875 int err = 0;
21876
21877@@ -52,9 +53,11 @@ static ssize_t acpi_ec_read_io(struct fi
21878 size = count;
21879
21880 while (size) {
21881- err = ec_read(*off, &data[*off - init_off]);
21882+ err = ec_read(*off, &data);
21883 if (err)
21884 return err;
21885+ if (put_user(data, &buf[*off - init_off]))
21886+ return -EFAULT;
21887 *off += 1;
21888 size--;
21889 }
21890@@ -70,7 +73,6 @@ static ssize_t acpi_ec_write_io(struct f
21891
21892 unsigned int size = count;
21893 loff_t init_off = *off;
21894- u8 *data = (u8 *) buf;
21895 int err = 0;
21896
21897 if (*off >= EC_SPACE_SIZE)
21898@@ -81,7 +83,9 @@ static ssize_t acpi_ec_write_io(struct f
21899 }
21900
21901 while (size) {
21902- u8 byte_write = data[*off - init_off];
21903+ u8 byte_write;
21904+ if (get_user(byte_write, &buf[*off - init_off]))
21905+ return -EFAULT;
21906 err = ec_write(*off, byte_write);
21907 if (err)
21908 return err;
21909diff -urNp linux-3.0.4/drivers/acpi/proc.c linux-3.0.4/drivers/acpi/proc.c
21910--- linux-3.0.4/drivers/acpi/proc.c 2011-07-21 22:17:23.000000000 -0400
21911+++ linux-3.0.4/drivers/acpi/proc.c 2011-08-23 21:47:55.000000000 -0400
21912@@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct f
21913 size_t count, loff_t * ppos)
21914 {
21915 struct list_head *node, *next;
21916- char strbuf[5];
21917- char str[5] = "";
21918- unsigned int len = count;
21919-
21920- if (len > 4)
21921- len = 4;
21922- if (len < 0)
21923- return -EFAULT;
21924+ char strbuf[5] = {0};
21925
21926- if (copy_from_user(strbuf, buffer, len))
21927+ if (count > 4)
21928+ count = 4;
21929+ if (copy_from_user(strbuf, buffer, count))
21930 return -EFAULT;
21931- strbuf[len] = '\0';
21932- sscanf(strbuf, "%s", str);
21933+ strbuf[count] = '\0';
21934
21935 mutex_lock(&acpi_device_lock);
21936 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
21937@@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct f
21938 if (!dev->wakeup.flags.valid)
21939 continue;
21940
21941- if (!strncmp(dev->pnp.bus_id, str, 4)) {
21942+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
21943 if (device_can_wakeup(&dev->dev)) {
21944 bool enable = !device_may_wakeup(&dev->dev);
21945 device_set_wakeup_enable(&dev->dev, enable);
21946diff -urNp linux-3.0.4/drivers/acpi/processor_driver.c linux-3.0.4/drivers/acpi/processor_driver.c
21947--- linux-3.0.4/drivers/acpi/processor_driver.c 2011-07-21 22:17:23.000000000 -0400
21948+++ linux-3.0.4/drivers/acpi/processor_driver.c 2011-08-23 21:47:55.000000000 -0400
21949@@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(
21950 return 0;
21951 #endif
21952
21953- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
21954+ BUG_ON(pr->id >= nr_cpu_ids);
21955
21956 /*
21957 * Buggy BIOS check
21958diff -urNp linux-3.0.4/drivers/ata/libata-core.c linux-3.0.4/drivers/ata/libata-core.c
21959--- linux-3.0.4/drivers/ata/libata-core.c 2011-07-21 22:17:23.000000000 -0400
21960+++ linux-3.0.4/drivers/ata/libata-core.c 2011-08-23 21:47:55.000000000 -0400
21961@@ -4753,7 +4753,7 @@ void ata_qc_free(struct ata_queued_cmd *
21962 struct ata_port *ap;
21963 unsigned int tag;
21964
21965- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
21966+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
21967 ap = qc->ap;
21968
21969 qc->flags = 0;
21970@@ -4769,7 +4769,7 @@ void __ata_qc_complete(struct ata_queued
21971 struct ata_port *ap;
21972 struct ata_link *link;
21973
21974- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
21975+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
21976 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
21977 ap = qc->ap;
21978 link = qc->dev->link;
21979@@ -5774,6 +5774,7 @@ static void ata_finalize_port_ops(struct
21980 return;
21981
21982 spin_lock(&lock);
21983+ pax_open_kernel();
21984
21985 for (cur = ops->inherits; cur; cur = cur->inherits) {
21986 void **inherit = (void **)cur;
21987@@ -5787,8 +5788,9 @@ static void ata_finalize_port_ops(struct
21988 if (IS_ERR(*pp))
21989 *pp = NULL;
21990
21991- ops->inherits = NULL;
21992+ *(struct ata_port_operations **)&ops->inherits = NULL;
21993
21994+ pax_close_kernel();
21995 spin_unlock(&lock);
21996 }
21997
21998diff -urNp linux-3.0.4/drivers/ata/libata-eh.c linux-3.0.4/drivers/ata/libata-eh.c
21999--- linux-3.0.4/drivers/ata/libata-eh.c 2011-07-21 22:17:23.000000000 -0400
22000+++ linux-3.0.4/drivers/ata/libata-eh.c 2011-08-23 21:48:14.000000000 -0400
22001@@ -2518,6 +2518,8 @@ void ata_eh_report(struct ata_port *ap)
22002 {
22003 struct ata_link *link;
22004
22005+ pax_track_stack();
22006+
22007 ata_for_each_link(link, ap, HOST_FIRST)
22008 ata_eh_link_report(link);
22009 }
22010diff -urNp linux-3.0.4/drivers/ata/pata_arasan_cf.c linux-3.0.4/drivers/ata/pata_arasan_cf.c
22011--- linux-3.0.4/drivers/ata/pata_arasan_cf.c 2011-07-21 22:17:23.000000000 -0400
22012+++ linux-3.0.4/drivers/ata/pata_arasan_cf.c 2011-08-23 21:47:55.000000000 -0400
22013@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(str
22014 /* Handle platform specific quirks */
22015 if (pdata->quirk) {
22016 if (pdata->quirk & CF_BROKEN_PIO) {
22017- ap->ops->set_piomode = NULL;
22018+ pax_open_kernel();
22019+ *(void **)&ap->ops->set_piomode = NULL;
22020+ pax_close_kernel();
22021 ap->pio_mask = 0;
22022 }
22023 if (pdata->quirk & CF_BROKEN_MWDMA)
22024diff -urNp linux-3.0.4/drivers/atm/adummy.c linux-3.0.4/drivers/atm/adummy.c
22025--- linux-3.0.4/drivers/atm/adummy.c 2011-07-21 22:17:23.000000000 -0400
22026+++ linux-3.0.4/drivers/atm/adummy.c 2011-08-23 21:47:55.000000000 -0400
22027@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
22028 vcc->pop(vcc, skb);
22029 else
22030 dev_kfree_skb_any(skb);
22031- atomic_inc(&vcc->stats->tx);
22032+ atomic_inc_unchecked(&vcc->stats->tx);
22033
22034 return 0;
22035 }
22036diff -urNp linux-3.0.4/drivers/atm/ambassador.c linux-3.0.4/drivers/atm/ambassador.c
22037--- linux-3.0.4/drivers/atm/ambassador.c 2011-07-21 22:17:23.000000000 -0400
22038+++ linux-3.0.4/drivers/atm/ambassador.c 2011-08-23 21:47:55.000000000 -0400
22039@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
22040 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
22041
22042 // VC layer stats
22043- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22044+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22045
22046 // free the descriptor
22047 kfree (tx_descr);
22048@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
22049 dump_skb ("<<<", vc, skb);
22050
22051 // VC layer stats
22052- atomic_inc(&atm_vcc->stats->rx);
22053+ atomic_inc_unchecked(&atm_vcc->stats->rx);
22054 __net_timestamp(skb);
22055 // end of our responsibility
22056 atm_vcc->push (atm_vcc, skb);
22057@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
22058 } else {
22059 PRINTK (KERN_INFO, "dropped over-size frame");
22060 // should we count this?
22061- atomic_inc(&atm_vcc->stats->rx_drop);
22062+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22063 }
22064
22065 } else {
22066@@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
22067 }
22068
22069 if (check_area (skb->data, skb->len)) {
22070- atomic_inc(&atm_vcc->stats->tx_err);
22071+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
22072 return -ENOMEM; // ?
22073 }
22074
22075diff -urNp linux-3.0.4/drivers/atm/atmtcp.c linux-3.0.4/drivers/atm/atmtcp.c
22076--- linux-3.0.4/drivers/atm/atmtcp.c 2011-07-21 22:17:23.000000000 -0400
22077+++ linux-3.0.4/drivers/atm/atmtcp.c 2011-08-23 21:47:55.000000000 -0400
22078@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
22079 if (vcc->pop) vcc->pop(vcc,skb);
22080 else dev_kfree_skb(skb);
22081 if (dev_data) return 0;
22082- atomic_inc(&vcc->stats->tx_err);
22083+ atomic_inc_unchecked(&vcc->stats->tx_err);
22084 return -ENOLINK;
22085 }
22086 size = skb->len+sizeof(struct atmtcp_hdr);
22087@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
22088 if (!new_skb) {
22089 if (vcc->pop) vcc->pop(vcc,skb);
22090 else dev_kfree_skb(skb);
22091- atomic_inc(&vcc->stats->tx_err);
22092+ atomic_inc_unchecked(&vcc->stats->tx_err);
22093 return -ENOBUFS;
22094 }
22095 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
22096@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
22097 if (vcc->pop) vcc->pop(vcc,skb);
22098 else dev_kfree_skb(skb);
22099 out_vcc->push(out_vcc,new_skb);
22100- atomic_inc(&vcc->stats->tx);
22101- atomic_inc(&out_vcc->stats->rx);
22102+ atomic_inc_unchecked(&vcc->stats->tx);
22103+ atomic_inc_unchecked(&out_vcc->stats->rx);
22104 return 0;
22105 }
22106
22107@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
22108 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
22109 read_unlock(&vcc_sklist_lock);
22110 if (!out_vcc) {
22111- atomic_inc(&vcc->stats->tx_err);
22112+ atomic_inc_unchecked(&vcc->stats->tx_err);
22113 goto done;
22114 }
22115 skb_pull(skb,sizeof(struct atmtcp_hdr));
22116@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
22117 __net_timestamp(new_skb);
22118 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
22119 out_vcc->push(out_vcc,new_skb);
22120- atomic_inc(&vcc->stats->tx);
22121- atomic_inc(&out_vcc->stats->rx);
22122+ atomic_inc_unchecked(&vcc->stats->tx);
22123+ atomic_inc_unchecked(&out_vcc->stats->rx);
22124 done:
22125 if (vcc->pop) vcc->pop(vcc,skb);
22126 else dev_kfree_skb(skb);
22127diff -urNp linux-3.0.4/drivers/atm/eni.c linux-3.0.4/drivers/atm/eni.c
22128--- linux-3.0.4/drivers/atm/eni.c 2011-07-21 22:17:23.000000000 -0400
22129+++ linux-3.0.4/drivers/atm/eni.c 2011-08-23 21:47:55.000000000 -0400
22130@@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
22131 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
22132 vcc->dev->number);
22133 length = 0;
22134- atomic_inc(&vcc->stats->rx_err);
22135+ atomic_inc_unchecked(&vcc->stats->rx_err);
22136 }
22137 else {
22138 length = ATM_CELL_SIZE-1; /* no HEC */
22139@@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
22140 size);
22141 }
22142 eff = length = 0;
22143- atomic_inc(&vcc->stats->rx_err);
22144+ atomic_inc_unchecked(&vcc->stats->rx_err);
22145 }
22146 else {
22147 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
22148@@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
22149 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
22150 vcc->dev->number,vcc->vci,length,size << 2,descr);
22151 length = eff = 0;
22152- atomic_inc(&vcc->stats->rx_err);
22153+ atomic_inc_unchecked(&vcc->stats->rx_err);
22154 }
22155 }
22156 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
22157@@ -771,7 +771,7 @@ rx_dequeued++;
22158 vcc->push(vcc,skb);
22159 pushed++;
22160 }
22161- atomic_inc(&vcc->stats->rx);
22162+ atomic_inc_unchecked(&vcc->stats->rx);
22163 }
22164 wake_up(&eni_dev->rx_wait);
22165 }
22166@@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
22167 PCI_DMA_TODEVICE);
22168 if (vcc->pop) vcc->pop(vcc,skb);
22169 else dev_kfree_skb_irq(skb);
22170- atomic_inc(&vcc->stats->tx);
22171+ atomic_inc_unchecked(&vcc->stats->tx);
22172 wake_up(&eni_dev->tx_wait);
22173 dma_complete++;
22174 }
22175diff -urNp linux-3.0.4/drivers/atm/firestream.c linux-3.0.4/drivers/atm/firestream.c
22176--- linux-3.0.4/drivers/atm/firestream.c 2011-07-21 22:17:23.000000000 -0400
22177+++ linux-3.0.4/drivers/atm/firestream.c 2011-08-23 21:47:55.000000000 -0400
22178@@ -749,7 +749,7 @@ static void process_txdone_queue (struct
22179 }
22180 }
22181
22182- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22183+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22184
22185 fs_dprintk (FS_DEBUG_TXMEM, "i");
22186 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
22187@@ -816,7 +816,7 @@ static void process_incoming (struct fs_
22188 #endif
22189 skb_put (skb, qe->p1 & 0xffff);
22190 ATM_SKB(skb)->vcc = atm_vcc;
22191- atomic_inc(&atm_vcc->stats->rx);
22192+ atomic_inc_unchecked(&atm_vcc->stats->rx);
22193 __net_timestamp(skb);
22194 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
22195 atm_vcc->push (atm_vcc, skb);
22196@@ -837,12 +837,12 @@ static void process_incoming (struct fs_
22197 kfree (pe);
22198 }
22199 if (atm_vcc)
22200- atomic_inc(&atm_vcc->stats->rx_drop);
22201+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22202 break;
22203 case 0x1f: /* Reassembly abort: no buffers. */
22204 /* Silently increment error counter. */
22205 if (atm_vcc)
22206- atomic_inc(&atm_vcc->stats->rx_drop);
22207+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22208 break;
22209 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
22210 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
22211diff -urNp linux-3.0.4/drivers/atm/fore200e.c linux-3.0.4/drivers/atm/fore200e.c
22212--- linux-3.0.4/drivers/atm/fore200e.c 2011-07-21 22:17:23.000000000 -0400
22213+++ linux-3.0.4/drivers/atm/fore200e.c 2011-08-23 21:47:55.000000000 -0400
22214@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
22215 #endif
22216 /* check error condition */
22217 if (*entry->status & STATUS_ERROR)
22218- atomic_inc(&vcc->stats->tx_err);
22219+ atomic_inc_unchecked(&vcc->stats->tx_err);
22220 else
22221- atomic_inc(&vcc->stats->tx);
22222+ atomic_inc_unchecked(&vcc->stats->tx);
22223 }
22224 }
22225
22226@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
22227 if (skb == NULL) {
22228 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
22229
22230- atomic_inc(&vcc->stats->rx_drop);
22231+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22232 return -ENOMEM;
22233 }
22234
22235@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
22236
22237 dev_kfree_skb_any(skb);
22238
22239- atomic_inc(&vcc->stats->rx_drop);
22240+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22241 return -ENOMEM;
22242 }
22243
22244 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
22245
22246 vcc->push(vcc, skb);
22247- atomic_inc(&vcc->stats->rx);
22248+ atomic_inc_unchecked(&vcc->stats->rx);
22249
22250 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
22251
22252@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
22253 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
22254 fore200e->atm_dev->number,
22255 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
22256- atomic_inc(&vcc->stats->rx_err);
22257+ atomic_inc_unchecked(&vcc->stats->rx_err);
22258 }
22259 }
22260
22261@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
22262 goto retry_here;
22263 }
22264
22265- atomic_inc(&vcc->stats->tx_err);
22266+ atomic_inc_unchecked(&vcc->stats->tx_err);
22267
22268 fore200e->tx_sat++;
22269 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
22270diff -urNp linux-3.0.4/drivers/atm/he.c linux-3.0.4/drivers/atm/he.c
22271--- linux-3.0.4/drivers/atm/he.c 2011-07-21 22:17:23.000000000 -0400
22272+++ linux-3.0.4/drivers/atm/he.c 2011-08-23 21:47:55.000000000 -0400
22273@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22274
22275 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
22276 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
22277- atomic_inc(&vcc->stats->rx_drop);
22278+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22279 goto return_host_buffers;
22280 }
22281
22282@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22283 RBRQ_LEN_ERR(he_dev->rbrq_head)
22284 ? "LEN_ERR" : "",
22285 vcc->vpi, vcc->vci);
22286- atomic_inc(&vcc->stats->rx_err);
22287+ atomic_inc_unchecked(&vcc->stats->rx_err);
22288 goto return_host_buffers;
22289 }
22290
22291@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22292 vcc->push(vcc, skb);
22293 spin_lock(&he_dev->global_lock);
22294
22295- atomic_inc(&vcc->stats->rx);
22296+ atomic_inc_unchecked(&vcc->stats->rx);
22297
22298 return_host_buffers:
22299 ++pdus_assembled;
22300@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
22301 tpd->vcc->pop(tpd->vcc, tpd->skb);
22302 else
22303 dev_kfree_skb_any(tpd->skb);
22304- atomic_inc(&tpd->vcc->stats->tx_err);
22305+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
22306 }
22307 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
22308 return;
22309@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22310 vcc->pop(vcc, skb);
22311 else
22312 dev_kfree_skb_any(skb);
22313- atomic_inc(&vcc->stats->tx_err);
22314+ atomic_inc_unchecked(&vcc->stats->tx_err);
22315 return -EINVAL;
22316 }
22317
22318@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22319 vcc->pop(vcc, skb);
22320 else
22321 dev_kfree_skb_any(skb);
22322- atomic_inc(&vcc->stats->tx_err);
22323+ atomic_inc_unchecked(&vcc->stats->tx_err);
22324 return -EINVAL;
22325 }
22326 #endif
22327@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22328 vcc->pop(vcc, skb);
22329 else
22330 dev_kfree_skb_any(skb);
22331- atomic_inc(&vcc->stats->tx_err);
22332+ atomic_inc_unchecked(&vcc->stats->tx_err);
22333 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22334 return -ENOMEM;
22335 }
22336@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22337 vcc->pop(vcc, skb);
22338 else
22339 dev_kfree_skb_any(skb);
22340- atomic_inc(&vcc->stats->tx_err);
22341+ atomic_inc_unchecked(&vcc->stats->tx_err);
22342 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22343 return -ENOMEM;
22344 }
22345@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22346 __enqueue_tpd(he_dev, tpd, cid);
22347 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22348
22349- atomic_inc(&vcc->stats->tx);
22350+ atomic_inc_unchecked(&vcc->stats->tx);
22351
22352 return 0;
22353 }
22354diff -urNp linux-3.0.4/drivers/atm/horizon.c linux-3.0.4/drivers/atm/horizon.c
22355--- linux-3.0.4/drivers/atm/horizon.c 2011-07-21 22:17:23.000000000 -0400
22356+++ linux-3.0.4/drivers/atm/horizon.c 2011-08-23 21:47:55.000000000 -0400
22357@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
22358 {
22359 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
22360 // VC layer stats
22361- atomic_inc(&vcc->stats->rx);
22362+ atomic_inc_unchecked(&vcc->stats->rx);
22363 __net_timestamp(skb);
22364 // end of our responsibility
22365 vcc->push (vcc, skb);
22366@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
22367 dev->tx_iovec = NULL;
22368
22369 // VC layer stats
22370- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22371+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22372
22373 // free the skb
22374 hrz_kfree_skb (skb);
22375diff -urNp linux-3.0.4/drivers/atm/idt77252.c linux-3.0.4/drivers/atm/idt77252.c
22376--- linux-3.0.4/drivers/atm/idt77252.c 2011-07-21 22:17:23.000000000 -0400
22377+++ linux-3.0.4/drivers/atm/idt77252.c 2011-08-23 21:47:55.000000000 -0400
22378@@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
22379 else
22380 dev_kfree_skb(skb);
22381
22382- atomic_inc(&vcc->stats->tx);
22383+ atomic_inc_unchecked(&vcc->stats->tx);
22384 }
22385
22386 atomic_dec(&scq->used);
22387@@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
22388 if ((sb = dev_alloc_skb(64)) == NULL) {
22389 printk("%s: Can't allocate buffers for aal0.\n",
22390 card->name);
22391- atomic_add(i, &vcc->stats->rx_drop);
22392+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
22393 break;
22394 }
22395 if (!atm_charge(vcc, sb->truesize)) {
22396 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
22397 card->name);
22398- atomic_add(i - 1, &vcc->stats->rx_drop);
22399+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
22400 dev_kfree_skb(sb);
22401 break;
22402 }
22403@@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
22404 ATM_SKB(sb)->vcc = vcc;
22405 __net_timestamp(sb);
22406 vcc->push(vcc, sb);
22407- atomic_inc(&vcc->stats->rx);
22408+ atomic_inc_unchecked(&vcc->stats->rx);
22409
22410 cell += ATM_CELL_PAYLOAD;
22411 }
22412@@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
22413 "(CDC: %08x)\n",
22414 card->name, len, rpp->len, readl(SAR_REG_CDC));
22415 recycle_rx_pool_skb(card, rpp);
22416- atomic_inc(&vcc->stats->rx_err);
22417+ atomic_inc_unchecked(&vcc->stats->rx_err);
22418 return;
22419 }
22420 if (stat & SAR_RSQE_CRC) {
22421 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
22422 recycle_rx_pool_skb(card, rpp);
22423- atomic_inc(&vcc->stats->rx_err);
22424+ atomic_inc_unchecked(&vcc->stats->rx_err);
22425 return;
22426 }
22427 if (skb_queue_len(&rpp->queue) > 1) {
22428@@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
22429 RXPRINTK("%s: Can't alloc RX skb.\n",
22430 card->name);
22431 recycle_rx_pool_skb(card, rpp);
22432- atomic_inc(&vcc->stats->rx_err);
22433+ atomic_inc_unchecked(&vcc->stats->rx_err);
22434 return;
22435 }
22436 if (!atm_charge(vcc, skb->truesize)) {
22437@@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
22438 __net_timestamp(skb);
22439
22440 vcc->push(vcc, skb);
22441- atomic_inc(&vcc->stats->rx);
22442+ atomic_inc_unchecked(&vcc->stats->rx);
22443
22444 return;
22445 }
22446@@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
22447 __net_timestamp(skb);
22448
22449 vcc->push(vcc, skb);
22450- atomic_inc(&vcc->stats->rx);
22451+ atomic_inc_unchecked(&vcc->stats->rx);
22452
22453 if (skb->truesize > SAR_FB_SIZE_3)
22454 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
22455@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *car
22456 if (vcc->qos.aal != ATM_AAL0) {
22457 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
22458 card->name, vpi, vci);
22459- atomic_inc(&vcc->stats->rx_drop);
22460+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22461 goto drop;
22462 }
22463
22464 if ((sb = dev_alloc_skb(64)) == NULL) {
22465 printk("%s: Can't allocate buffers for AAL0.\n",
22466 card->name);
22467- atomic_inc(&vcc->stats->rx_err);
22468+ atomic_inc_unchecked(&vcc->stats->rx_err);
22469 goto drop;
22470 }
22471
22472@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *car
22473 ATM_SKB(sb)->vcc = vcc;
22474 __net_timestamp(sb);
22475 vcc->push(vcc, sb);
22476- atomic_inc(&vcc->stats->rx);
22477+ atomic_inc_unchecked(&vcc->stats->rx);
22478
22479 drop:
22480 skb_pull(queue, 64);
22481@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22482
22483 if (vc == NULL) {
22484 printk("%s: NULL connection in send().\n", card->name);
22485- atomic_inc(&vcc->stats->tx_err);
22486+ atomic_inc_unchecked(&vcc->stats->tx_err);
22487 dev_kfree_skb(skb);
22488 return -EINVAL;
22489 }
22490 if (!test_bit(VCF_TX, &vc->flags)) {
22491 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
22492- atomic_inc(&vcc->stats->tx_err);
22493+ atomic_inc_unchecked(&vcc->stats->tx_err);
22494 dev_kfree_skb(skb);
22495 return -EINVAL;
22496 }
22497@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22498 break;
22499 default:
22500 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
22501- atomic_inc(&vcc->stats->tx_err);
22502+ atomic_inc_unchecked(&vcc->stats->tx_err);
22503 dev_kfree_skb(skb);
22504 return -EINVAL;
22505 }
22506
22507 if (skb_shinfo(skb)->nr_frags != 0) {
22508 printk("%s: No scatter-gather yet.\n", card->name);
22509- atomic_inc(&vcc->stats->tx_err);
22510+ atomic_inc_unchecked(&vcc->stats->tx_err);
22511 dev_kfree_skb(skb);
22512 return -EINVAL;
22513 }
22514@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22515
22516 err = queue_skb(card, vc, skb, oam);
22517 if (err) {
22518- atomic_inc(&vcc->stats->tx_err);
22519+ atomic_inc_unchecked(&vcc->stats->tx_err);
22520 dev_kfree_skb(skb);
22521 return err;
22522 }
22523@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
22524 skb = dev_alloc_skb(64);
22525 if (!skb) {
22526 printk("%s: Out of memory in send_oam().\n", card->name);
22527- atomic_inc(&vcc->stats->tx_err);
22528+ atomic_inc_unchecked(&vcc->stats->tx_err);
22529 return -ENOMEM;
22530 }
22531 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
22532diff -urNp linux-3.0.4/drivers/atm/iphase.c linux-3.0.4/drivers/atm/iphase.c
22533--- linux-3.0.4/drivers/atm/iphase.c 2011-07-21 22:17:23.000000000 -0400
22534+++ linux-3.0.4/drivers/atm/iphase.c 2011-08-23 21:47:55.000000000 -0400
22535@@ -1120,7 +1120,7 @@ static int rx_pkt(struct atm_dev *dev)
22536 status = (u_short) (buf_desc_ptr->desc_mode);
22537 if (status & (RX_CER | RX_PTE | RX_OFL))
22538 {
22539- atomic_inc(&vcc->stats->rx_err);
22540+ atomic_inc_unchecked(&vcc->stats->rx_err);
22541 IF_ERR(printk("IA: bad packet, dropping it");)
22542 if (status & RX_CER) {
22543 IF_ERR(printk(" cause: packet CRC error\n");)
22544@@ -1143,7 +1143,7 @@ static int rx_pkt(struct atm_dev *dev)
22545 len = dma_addr - buf_addr;
22546 if (len > iadev->rx_buf_sz) {
22547 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
22548- atomic_inc(&vcc->stats->rx_err);
22549+ atomic_inc_unchecked(&vcc->stats->rx_err);
22550 goto out_free_desc;
22551 }
22552
22553@@ -1293,7 +1293,7 @@ static void rx_dle_intr(struct atm_dev *
22554 ia_vcc = INPH_IA_VCC(vcc);
22555 if (ia_vcc == NULL)
22556 {
22557- atomic_inc(&vcc->stats->rx_err);
22558+ atomic_inc_unchecked(&vcc->stats->rx_err);
22559 dev_kfree_skb_any(skb);
22560 atm_return(vcc, atm_guess_pdu2truesize(len));
22561 goto INCR_DLE;
22562@@ -1305,7 +1305,7 @@ static void rx_dle_intr(struct atm_dev *
22563 if ((length > iadev->rx_buf_sz) || (length >
22564 (skb->len - sizeof(struct cpcs_trailer))))
22565 {
22566- atomic_inc(&vcc->stats->rx_err);
22567+ atomic_inc_unchecked(&vcc->stats->rx_err);
22568 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
22569 length, skb->len);)
22570 dev_kfree_skb_any(skb);
22571@@ -1321,7 +1321,7 @@ static void rx_dle_intr(struct atm_dev *
22572
22573 IF_RX(printk("rx_dle_intr: skb push");)
22574 vcc->push(vcc,skb);
22575- atomic_inc(&vcc->stats->rx);
22576+ atomic_inc_unchecked(&vcc->stats->rx);
22577 iadev->rx_pkt_cnt++;
22578 }
22579 INCR_DLE:
22580@@ -2801,15 +2801,15 @@ static int ia_ioctl(struct atm_dev *dev,
22581 {
22582 struct k_sonet_stats *stats;
22583 stats = &PRIV(_ia_dev[board])->sonet_stats;
22584- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
22585- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
22586- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
22587- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
22588- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
22589- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
22590- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
22591- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
22592- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
22593+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
22594+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
22595+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
22596+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
22597+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
22598+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
22599+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
22600+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
22601+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
22602 }
22603 ia_cmds.status = 0;
22604 break;
22605@@ -2914,7 +2914,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
22606 if ((desc == 0) || (desc > iadev->num_tx_desc))
22607 {
22608 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
22609- atomic_inc(&vcc->stats->tx);
22610+ atomic_inc_unchecked(&vcc->stats->tx);
22611 if (vcc->pop)
22612 vcc->pop(vcc, skb);
22613 else
22614@@ -3019,14 +3019,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
22615 ATM_DESC(skb) = vcc->vci;
22616 skb_queue_tail(&iadev->tx_dma_q, skb);
22617
22618- atomic_inc(&vcc->stats->tx);
22619+ atomic_inc_unchecked(&vcc->stats->tx);
22620 iadev->tx_pkt_cnt++;
22621 /* Increment transaction counter */
22622 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
22623
22624 #if 0
22625 /* add flow control logic */
22626- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
22627+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
22628 if (iavcc->vc_desc_cnt > 10) {
22629 vcc->tx_quota = vcc->tx_quota * 3 / 4;
22630 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
22631diff -urNp linux-3.0.4/drivers/atm/lanai.c linux-3.0.4/drivers/atm/lanai.c
22632--- linux-3.0.4/drivers/atm/lanai.c 2011-07-21 22:17:23.000000000 -0400
22633+++ linux-3.0.4/drivers/atm/lanai.c 2011-08-23 21:47:55.000000000 -0400
22634@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
22635 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
22636 lanai_endtx(lanai, lvcc);
22637 lanai_free_skb(lvcc->tx.atmvcc, skb);
22638- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
22639+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
22640 }
22641
22642 /* Try to fill the buffer - don't call unless there is backlog */
22643@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
22644 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
22645 __net_timestamp(skb);
22646 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
22647- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
22648+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
22649 out:
22650 lvcc->rx.buf.ptr = end;
22651 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
22652@@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
22653 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
22654 "vcc %d\n", lanai->number, (unsigned int) s, vci);
22655 lanai->stats.service_rxnotaal5++;
22656- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
22657+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
22658 return 0;
22659 }
22660 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
22661@@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
22662 int bytes;
22663 read_unlock(&vcc_sklist_lock);
22664 DPRINTK("got trashed rx pdu on vci %d\n", vci);
22665- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
22666+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
22667 lvcc->stats.x.aal5.service_trash++;
22668 bytes = (SERVICE_GET_END(s) * 16) -
22669 (((unsigned long) lvcc->rx.buf.ptr) -
22670@@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
22671 }
22672 if (s & SERVICE_STREAM) {
22673 read_unlock(&vcc_sklist_lock);
22674- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
22675+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
22676 lvcc->stats.x.aal5.service_stream++;
22677 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
22678 "PDU on VCI %d!\n", lanai->number, vci);
22679@@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
22680 return 0;
22681 }
22682 DPRINTK("got rx crc error on vci %d\n", vci);
22683- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
22684+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
22685 lvcc->stats.x.aal5.service_rxcrc++;
22686 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
22687 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
22688diff -urNp linux-3.0.4/drivers/atm/nicstar.c linux-3.0.4/drivers/atm/nicstar.c
22689--- linux-3.0.4/drivers/atm/nicstar.c 2011-07-21 22:17:23.000000000 -0400
22690+++ linux-3.0.4/drivers/atm/nicstar.c 2011-08-23 21:47:55.000000000 -0400
22691@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
22692 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
22693 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
22694 card->index);
22695- atomic_inc(&vcc->stats->tx_err);
22696+ atomic_inc_unchecked(&vcc->stats->tx_err);
22697 dev_kfree_skb_any(skb);
22698 return -EINVAL;
22699 }
22700@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
22701 if (!vc->tx) {
22702 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
22703 card->index);
22704- atomic_inc(&vcc->stats->tx_err);
22705+ atomic_inc_unchecked(&vcc->stats->tx_err);
22706 dev_kfree_skb_any(skb);
22707 return -EINVAL;
22708 }
22709@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
22710 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
22711 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
22712 card->index);
22713- atomic_inc(&vcc->stats->tx_err);
22714+ atomic_inc_unchecked(&vcc->stats->tx_err);
22715 dev_kfree_skb_any(skb);
22716 return -EINVAL;
22717 }
22718
22719 if (skb_shinfo(skb)->nr_frags != 0) {
22720 printk("nicstar%d: No scatter-gather yet.\n", card->index);
22721- atomic_inc(&vcc->stats->tx_err);
22722+ atomic_inc_unchecked(&vcc->stats->tx_err);
22723 dev_kfree_skb_any(skb);
22724 return -EINVAL;
22725 }
22726@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
22727 }
22728
22729 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
22730- atomic_inc(&vcc->stats->tx_err);
22731+ atomic_inc_unchecked(&vcc->stats->tx_err);
22732 dev_kfree_skb_any(skb);
22733 return -EIO;
22734 }
22735- atomic_inc(&vcc->stats->tx);
22736+ atomic_inc_unchecked(&vcc->stats->tx);
22737
22738 return 0;
22739 }
22740@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
22741 printk
22742 ("nicstar%d: Can't allocate buffers for aal0.\n",
22743 card->index);
22744- atomic_add(i, &vcc->stats->rx_drop);
22745+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
22746 break;
22747 }
22748 if (!atm_charge(vcc, sb->truesize)) {
22749 RXPRINTK
22750 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
22751 card->index);
22752- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
22753+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
22754 dev_kfree_skb_any(sb);
22755 break;
22756 }
22757@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
22758 ATM_SKB(sb)->vcc = vcc;
22759 __net_timestamp(sb);
22760 vcc->push(vcc, sb);
22761- atomic_inc(&vcc->stats->rx);
22762+ atomic_inc_unchecked(&vcc->stats->rx);
22763 cell += ATM_CELL_PAYLOAD;
22764 }
22765
22766@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
22767 if (iovb == NULL) {
22768 printk("nicstar%d: Out of iovec buffers.\n",
22769 card->index);
22770- atomic_inc(&vcc->stats->rx_drop);
22771+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22772 recycle_rx_buf(card, skb);
22773 return;
22774 }
22775@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
22776 small or large buffer itself. */
22777 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
22778 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
22779- atomic_inc(&vcc->stats->rx_err);
22780+ atomic_inc_unchecked(&vcc->stats->rx_err);
22781 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
22782 NS_MAX_IOVECS);
22783 NS_PRV_IOVCNT(iovb) = 0;
22784@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
22785 ("nicstar%d: Expected a small buffer, and this is not one.\n",
22786 card->index);
22787 which_list(card, skb);
22788- atomic_inc(&vcc->stats->rx_err);
22789+ atomic_inc_unchecked(&vcc->stats->rx_err);
22790 recycle_rx_buf(card, skb);
22791 vc->rx_iov = NULL;
22792 recycle_iov_buf(card, iovb);
22793@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
22794 ("nicstar%d: Expected a large buffer, and this is not one.\n",
22795 card->index);
22796 which_list(card, skb);
22797- atomic_inc(&vcc->stats->rx_err);
22798+ atomic_inc_unchecked(&vcc->stats->rx_err);
22799 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
22800 NS_PRV_IOVCNT(iovb));
22801 vc->rx_iov = NULL;
22802@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
22803 printk(" - PDU size mismatch.\n");
22804 else
22805 printk(".\n");
22806- atomic_inc(&vcc->stats->rx_err);
22807+ atomic_inc_unchecked(&vcc->stats->rx_err);
22808 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
22809 NS_PRV_IOVCNT(iovb));
22810 vc->rx_iov = NULL;
22811@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
22812 /* skb points to a small buffer */
22813 if (!atm_charge(vcc, skb->truesize)) {
22814 push_rxbufs(card, skb);
22815- atomic_inc(&vcc->stats->rx_drop);
22816+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22817 } else {
22818 skb_put(skb, len);
22819 dequeue_sm_buf(card, skb);
22820@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
22821 ATM_SKB(skb)->vcc = vcc;
22822 __net_timestamp(skb);
22823 vcc->push(vcc, skb);
22824- atomic_inc(&vcc->stats->rx);
22825+ atomic_inc_unchecked(&vcc->stats->rx);
22826 }
22827 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
22828 struct sk_buff *sb;
22829@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
22830 if (len <= NS_SMBUFSIZE) {
22831 if (!atm_charge(vcc, sb->truesize)) {
22832 push_rxbufs(card, sb);
22833- atomic_inc(&vcc->stats->rx_drop);
22834+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22835 } else {
22836 skb_put(sb, len);
22837 dequeue_sm_buf(card, sb);
22838@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
22839 ATM_SKB(sb)->vcc = vcc;
22840 __net_timestamp(sb);
22841 vcc->push(vcc, sb);
22842- atomic_inc(&vcc->stats->rx);
22843+ atomic_inc_unchecked(&vcc->stats->rx);
22844 }
22845
22846 push_rxbufs(card, skb);
22847@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
22848
22849 if (!atm_charge(vcc, skb->truesize)) {
22850 push_rxbufs(card, skb);
22851- atomic_inc(&vcc->stats->rx_drop);
22852+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22853 } else {
22854 dequeue_lg_buf(card, skb);
22855 #ifdef NS_USE_DESTRUCTORS
22856@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
22857 ATM_SKB(skb)->vcc = vcc;
22858 __net_timestamp(skb);
22859 vcc->push(vcc, skb);
22860- atomic_inc(&vcc->stats->rx);
22861+ atomic_inc_unchecked(&vcc->stats->rx);
22862 }
22863
22864 push_rxbufs(card, sb);
22865@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
22866 printk
22867 ("nicstar%d: Out of huge buffers.\n",
22868 card->index);
22869- atomic_inc(&vcc->stats->rx_drop);
22870+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22871 recycle_iovec_rx_bufs(card,
22872 (struct iovec *)
22873 iovb->data,
22874@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
22875 card->hbpool.count++;
22876 } else
22877 dev_kfree_skb_any(hb);
22878- atomic_inc(&vcc->stats->rx_drop);
22879+ atomic_inc_unchecked(&vcc->stats->rx_drop);
22880 } else {
22881 /* Copy the small buffer to the huge buffer */
22882 sb = (struct sk_buff *)iov->iov_base;
22883@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
22884 #endif /* NS_USE_DESTRUCTORS */
22885 __net_timestamp(hb);
22886 vcc->push(vcc, hb);
22887- atomic_inc(&vcc->stats->rx);
22888+ atomic_inc_unchecked(&vcc->stats->rx);
22889 }
22890 }
22891
22892diff -urNp linux-3.0.4/drivers/atm/solos-pci.c linux-3.0.4/drivers/atm/solos-pci.c
22893--- linux-3.0.4/drivers/atm/solos-pci.c 2011-07-21 22:17:23.000000000 -0400
22894+++ linux-3.0.4/drivers/atm/solos-pci.c 2011-08-23 21:48:14.000000000 -0400
22895@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
22896 }
22897 atm_charge(vcc, skb->truesize);
22898 vcc->push(vcc, skb);
22899- atomic_inc(&vcc->stats->rx);
22900+ atomic_inc_unchecked(&vcc->stats->rx);
22901 break;
22902
22903 case PKT_STATUS:
22904@@ -899,6 +899,8 @@ static int print_buffer(struct sk_buff *
22905 char msg[500];
22906 char item[10];
22907
22908+ pax_track_stack();
22909+
22910 len = buf->len;
22911 for (i = 0; i < len; i++){
22912 if(i % 8 == 0)
22913@@ -1008,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_car
22914 vcc = SKB_CB(oldskb)->vcc;
22915
22916 if (vcc) {
22917- atomic_inc(&vcc->stats->tx);
22918+ atomic_inc_unchecked(&vcc->stats->tx);
22919 solos_pop(vcc, oldskb);
22920 } else
22921 dev_kfree_skb_irq(oldskb);
22922diff -urNp linux-3.0.4/drivers/atm/suni.c linux-3.0.4/drivers/atm/suni.c
22923--- linux-3.0.4/drivers/atm/suni.c 2011-07-21 22:17:23.000000000 -0400
22924+++ linux-3.0.4/drivers/atm/suni.c 2011-08-23 21:47:55.000000000 -0400
22925@@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
22926
22927
22928 #define ADD_LIMITED(s,v) \
22929- atomic_add((v),&stats->s); \
22930- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
22931+ atomic_add_unchecked((v),&stats->s); \
22932+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
22933
22934
22935 static void suni_hz(unsigned long from_timer)
22936diff -urNp linux-3.0.4/drivers/atm/uPD98402.c linux-3.0.4/drivers/atm/uPD98402.c
22937--- linux-3.0.4/drivers/atm/uPD98402.c 2011-07-21 22:17:23.000000000 -0400
22938+++ linux-3.0.4/drivers/atm/uPD98402.c 2011-08-23 21:47:55.000000000 -0400
22939@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
22940 struct sonet_stats tmp;
22941 int error = 0;
22942
22943- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
22944+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
22945 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
22946 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
22947 if (zero && !error) {
22948@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
22949
22950
22951 #define ADD_LIMITED(s,v) \
22952- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
22953- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
22954- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
22955+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
22956+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
22957+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
22958
22959
22960 static void stat_event(struct atm_dev *dev)
22961@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
22962 if (reason & uPD98402_INT_PFM) stat_event(dev);
22963 if (reason & uPD98402_INT_PCO) {
22964 (void) GET(PCOCR); /* clear interrupt cause */
22965- atomic_add(GET(HECCT),
22966+ atomic_add_unchecked(GET(HECCT),
22967 &PRIV(dev)->sonet_stats.uncorr_hcs);
22968 }
22969 if ((reason & uPD98402_INT_RFO) &&
22970@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
22971 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
22972 uPD98402_INT_LOS),PIMR); /* enable them */
22973 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
22974- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
22975- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
22976- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
22977+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
22978+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
22979+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
22980 return 0;
22981 }
22982
22983diff -urNp linux-3.0.4/drivers/atm/zatm.c linux-3.0.4/drivers/atm/zatm.c
22984--- linux-3.0.4/drivers/atm/zatm.c 2011-07-21 22:17:23.000000000 -0400
22985+++ linux-3.0.4/drivers/atm/zatm.c 2011-08-23 21:47:55.000000000 -0400
22986@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
22987 }
22988 if (!size) {
22989 dev_kfree_skb_irq(skb);
22990- if (vcc) atomic_inc(&vcc->stats->rx_err);
22991+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
22992 continue;
22993 }
22994 if (!atm_charge(vcc,skb->truesize)) {
22995@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
22996 skb->len = size;
22997 ATM_SKB(skb)->vcc = vcc;
22998 vcc->push(vcc,skb);
22999- atomic_inc(&vcc->stats->rx);
23000+ atomic_inc_unchecked(&vcc->stats->rx);
23001 }
23002 zout(pos & 0xffff,MTA(mbx));
23003 #if 0 /* probably a stupid idea */
23004@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
23005 skb_queue_head(&zatm_vcc->backlog,skb);
23006 break;
23007 }
23008- atomic_inc(&vcc->stats->tx);
23009+ atomic_inc_unchecked(&vcc->stats->tx);
23010 wake_up(&zatm_vcc->tx_wait);
23011 }
23012
23013diff -urNp linux-3.0.4/drivers/base/power/wakeup.c linux-3.0.4/drivers/base/power/wakeup.c
23014--- linux-3.0.4/drivers/base/power/wakeup.c 2011-07-21 22:17:23.000000000 -0400
23015+++ linux-3.0.4/drivers/base/power/wakeup.c 2011-08-23 21:47:55.000000000 -0400
23016@@ -29,14 +29,14 @@ bool events_check_enabled;
23017 * They need to be modified together atomically, so it's better to use one
23018 * atomic variable to hold them both.
23019 */
23020-static atomic_t combined_event_count = ATOMIC_INIT(0);
23021+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
23022
23023 #define IN_PROGRESS_BITS (sizeof(int) * 4)
23024 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
23025
23026 static void split_counters(unsigned int *cnt, unsigned int *inpr)
23027 {
23028- unsigned int comb = atomic_read(&combined_event_count);
23029+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
23030
23031 *cnt = (comb >> IN_PROGRESS_BITS);
23032 *inpr = comb & MAX_IN_PROGRESS;
23033@@ -350,7 +350,7 @@ static void wakeup_source_activate(struc
23034 ws->last_time = ktime_get();
23035
23036 /* Increment the counter of events in progress. */
23037- atomic_inc(&combined_event_count);
23038+ atomic_inc_unchecked(&combined_event_count);
23039 }
23040
23041 /**
23042@@ -440,7 +440,7 @@ static void wakeup_source_deactivate(str
23043 * Increment the counter of registered wakeup events and decrement the
23044 * couter of wakeup events in progress simultaneously.
23045 */
23046- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
23047+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
23048 }
23049
23050 /**
23051diff -urNp linux-3.0.4/drivers/block/cciss.c linux-3.0.4/drivers/block/cciss.c
23052--- linux-3.0.4/drivers/block/cciss.c 2011-07-21 22:17:23.000000000 -0400
23053+++ linux-3.0.4/drivers/block/cciss.c 2011-08-23 21:48:14.000000000 -0400
23054@@ -1179,6 +1179,8 @@ static int cciss_ioctl32_passthru(struct
23055 int err;
23056 u32 cp;
23057
23058+ memset(&arg64, 0, sizeof(arg64));
23059+
23060 err = 0;
23061 err |=
23062 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
23063@@ -2986,7 +2988,7 @@ static void start_io(ctlr_info_t *h)
23064 while (!list_empty(&h->reqQ)) {
23065 c = list_entry(h->reqQ.next, CommandList_struct, list);
23066 /* can't do anything if fifo is full */
23067- if ((h->access.fifo_full(h))) {
23068+ if ((h->access->fifo_full(h))) {
23069 dev_warn(&h->pdev->dev, "fifo full\n");
23070 break;
23071 }
23072@@ -2996,7 +2998,7 @@ static void start_io(ctlr_info_t *h)
23073 h->Qdepth--;
23074
23075 /* Tell the controller execute command */
23076- h->access.submit_command(h, c);
23077+ h->access->submit_command(h, c);
23078
23079 /* Put job onto the completed Q */
23080 addQ(&h->cmpQ, c);
23081@@ -3422,17 +3424,17 @@ startio:
23082
23083 static inline unsigned long get_next_completion(ctlr_info_t *h)
23084 {
23085- return h->access.command_completed(h);
23086+ return h->access->command_completed(h);
23087 }
23088
23089 static inline int interrupt_pending(ctlr_info_t *h)
23090 {
23091- return h->access.intr_pending(h);
23092+ return h->access->intr_pending(h);
23093 }
23094
23095 static inline long interrupt_not_for_us(ctlr_info_t *h)
23096 {
23097- return ((h->access.intr_pending(h) == 0) ||
23098+ return ((h->access->intr_pending(h) == 0) ||
23099 (h->interrupts_enabled == 0));
23100 }
23101
23102@@ -3465,7 +3467,7 @@ static inline u32 next_command(ctlr_info
23103 u32 a;
23104
23105 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
23106- return h->access.command_completed(h);
23107+ return h->access->command_completed(h);
23108
23109 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
23110 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
23111@@ -4020,7 +4022,7 @@ static void __devinit cciss_put_controll
23112 trans_support & CFGTBL_Trans_use_short_tags);
23113
23114 /* Change the access methods to the performant access methods */
23115- h->access = SA5_performant_access;
23116+ h->access = &SA5_performant_access;
23117 h->transMethod = CFGTBL_Trans_Performant;
23118
23119 return;
23120@@ -4292,7 +4294,7 @@ static int __devinit cciss_pci_init(ctlr
23121 if (prod_index < 0)
23122 return -ENODEV;
23123 h->product_name = products[prod_index].product_name;
23124- h->access = *(products[prod_index].access);
23125+ h->access = products[prod_index].access;
23126
23127 if (cciss_board_disabled(h)) {
23128 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
23129@@ -5002,7 +5004,7 @@ reinit_after_soft_reset:
23130 }
23131
23132 /* make sure the board interrupts are off */
23133- h->access.set_intr_mask(h, CCISS_INTR_OFF);
23134+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
23135 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
23136 if (rc)
23137 goto clean2;
23138@@ -5054,7 +5056,7 @@ reinit_after_soft_reset:
23139 * fake ones to scoop up any residual completions.
23140 */
23141 spin_lock_irqsave(&h->lock, flags);
23142- h->access.set_intr_mask(h, CCISS_INTR_OFF);
23143+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
23144 spin_unlock_irqrestore(&h->lock, flags);
23145 free_irq(h->intr[PERF_MODE_INT], h);
23146 rc = cciss_request_irq(h, cciss_msix_discard_completions,
23147@@ -5074,9 +5076,9 @@ reinit_after_soft_reset:
23148 dev_info(&h->pdev->dev, "Board READY.\n");
23149 dev_info(&h->pdev->dev,
23150 "Waiting for stale completions to drain.\n");
23151- h->access.set_intr_mask(h, CCISS_INTR_ON);
23152+ h->access->set_intr_mask(h, CCISS_INTR_ON);
23153 msleep(10000);
23154- h->access.set_intr_mask(h, CCISS_INTR_OFF);
23155+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
23156
23157 rc = controller_reset_failed(h->cfgtable);
23158 if (rc)
23159@@ -5099,7 +5101,7 @@ reinit_after_soft_reset:
23160 cciss_scsi_setup(h);
23161
23162 /* Turn the interrupts on so we can service requests */
23163- h->access.set_intr_mask(h, CCISS_INTR_ON);
23164+ h->access->set_intr_mask(h, CCISS_INTR_ON);
23165
23166 /* Get the firmware version */
23167 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
23168@@ -5171,7 +5173,7 @@ static void cciss_shutdown(struct pci_de
23169 kfree(flush_buf);
23170 if (return_code != IO_OK)
23171 dev_warn(&h->pdev->dev, "Error flushing cache\n");
23172- h->access.set_intr_mask(h, CCISS_INTR_OFF);
23173+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
23174 free_irq(h->intr[PERF_MODE_INT], h);
23175 }
23176
23177diff -urNp linux-3.0.4/drivers/block/cciss.h linux-3.0.4/drivers/block/cciss.h
23178--- linux-3.0.4/drivers/block/cciss.h 2011-08-23 21:44:40.000000000 -0400
23179+++ linux-3.0.4/drivers/block/cciss.h 2011-08-23 21:47:55.000000000 -0400
23180@@ -100,7 +100,7 @@ struct ctlr_info
23181 /* information about each logical volume */
23182 drive_info_struct *drv[CISS_MAX_LUN];
23183
23184- struct access_method access;
23185+ struct access_method *access;
23186
23187 /* queue and queue Info */
23188 struct list_head reqQ;
23189diff -urNp linux-3.0.4/drivers/block/cpqarray.c linux-3.0.4/drivers/block/cpqarray.c
23190--- linux-3.0.4/drivers/block/cpqarray.c 2011-07-21 22:17:23.000000000 -0400
23191+++ linux-3.0.4/drivers/block/cpqarray.c 2011-08-23 21:48:14.000000000 -0400
23192@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_c
23193 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
23194 goto Enomem4;
23195 }
23196- hba[i]->access.set_intr_mask(hba[i], 0);
23197+ hba[i]->access->set_intr_mask(hba[i], 0);
23198 if (request_irq(hba[i]->intr, do_ida_intr,
23199 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
23200 {
23201@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_c
23202 add_timer(&hba[i]->timer);
23203
23204 /* Enable IRQ now that spinlock and rate limit timer are set up */
23205- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
23206+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
23207
23208 for(j=0; j<NWD; j++) {
23209 struct gendisk *disk = ida_gendisk[i][j];
23210@@ -694,7 +694,7 @@ DBGINFO(
23211 for(i=0; i<NR_PRODUCTS; i++) {
23212 if (board_id == products[i].board_id) {
23213 c->product_name = products[i].product_name;
23214- c->access = *(products[i].access);
23215+ c->access = products[i].access;
23216 break;
23217 }
23218 }
23219@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detec
23220 hba[ctlr]->intr = intr;
23221 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
23222 hba[ctlr]->product_name = products[j].product_name;
23223- hba[ctlr]->access = *(products[j].access);
23224+ hba[ctlr]->access = products[j].access;
23225 hba[ctlr]->ctlr = ctlr;
23226 hba[ctlr]->board_id = board_id;
23227 hba[ctlr]->pci_dev = NULL; /* not PCI */
23228@@ -911,6 +911,8 @@ static void do_ida_request(struct reques
23229 struct scatterlist tmp_sg[SG_MAX];
23230 int i, dir, seg;
23231
23232+ pax_track_stack();
23233+
23234 queue_next:
23235 creq = blk_peek_request(q);
23236 if (!creq)
23237@@ -980,7 +982,7 @@ static void start_io(ctlr_info_t *h)
23238
23239 while((c = h->reqQ) != NULL) {
23240 /* Can't do anything if we're busy */
23241- if (h->access.fifo_full(h) == 0)
23242+ if (h->access->fifo_full(h) == 0)
23243 return;
23244
23245 /* Get the first entry from the request Q */
23246@@ -988,7 +990,7 @@ static void start_io(ctlr_info_t *h)
23247 h->Qdepth--;
23248
23249 /* Tell the controller to do our bidding */
23250- h->access.submit_command(h, c);
23251+ h->access->submit_command(h, c);
23252
23253 /* Get onto the completion Q */
23254 addQ(&h->cmpQ, c);
23255@@ -1050,7 +1052,7 @@ static irqreturn_t do_ida_intr(int irq,
23256 unsigned long flags;
23257 __u32 a,a1;
23258
23259- istat = h->access.intr_pending(h);
23260+ istat = h->access->intr_pending(h);
23261 /* Is this interrupt for us? */
23262 if (istat == 0)
23263 return IRQ_NONE;
23264@@ -1061,7 +1063,7 @@ static irqreturn_t do_ida_intr(int irq,
23265 */
23266 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
23267 if (istat & FIFO_NOT_EMPTY) {
23268- while((a = h->access.command_completed(h))) {
23269+ while((a = h->access->command_completed(h))) {
23270 a1 = a; a &= ~3;
23271 if ((c = h->cmpQ) == NULL)
23272 {
23273@@ -1449,11 +1451,11 @@ static int sendcmd(
23274 /*
23275 * Disable interrupt
23276 */
23277- info_p->access.set_intr_mask(info_p, 0);
23278+ info_p->access->set_intr_mask(info_p, 0);
23279 /* Make sure there is room in the command FIFO */
23280 /* Actually it should be completely empty at this time. */
23281 for (i = 200000; i > 0; i--) {
23282- temp = info_p->access.fifo_full(info_p);
23283+ temp = info_p->access->fifo_full(info_p);
23284 if (temp != 0) {
23285 break;
23286 }
23287@@ -1466,7 +1468,7 @@ DBG(
23288 /*
23289 * Send the cmd
23290 */
23291- info_p->access.submit_command(info_p, c);
23292+ info_p->access->submit_command(info_p, c);
23293 complete = pollcomplete(ctlr);
23294
23295 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
23296@@ -1549,9 +1551,9 @@ static int revalidate_allvol(ctlr_info_t
23297 * we check the new geometry. Then turn interrupts back on when
23298 * we're done.
23299 */
23300- host->access.set_intr_mask(host, 0);
23301+ host->access->set_intr_mask(host, 0);
23302 getgeometry(ctlr);
23303- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
23304+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
23305
23306 for(i=0; i<NWD; i++) {
23307 struct gendisk *disk = ida_gendisk[ctlr][i];
23308@@ -1591,7 +1593,7 @@ static int pollcomplete(int ctlr)
23309 /* Wait (up to 2 seconds) for a command to complete */
23310
23311 for (i = 200000; i > 0; i--) {
23312- done = hba[ctlr]->access.command_completed(hba[ctlr]);
23313+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
23314 if (done == 0) {
23315 udelay(10); /* a short fixed delay */
23316 } else
23317diff -urNp linux-3.0.4/drivers/block/cpqarray.h linux-3.0.4/drivers/block/cpqarray.h
23318--- linux-3.0.4/drivers/block/cpqarray.h 2011-07-21 22:17:23.000000000 -0400
23319+++ linux-3.0.4/drivers/block/cpqarray.h 2011-08-23 21:47:55.000000000 -0400
23320@@ -99,7 +99,7 @@ struct ctlr_info {
23321 drv_info_t drv[NWD];
23322 struct proc_dir_entry *proc;
23323
23324- struct access_method access;
23325+ struct access_method *access;
23326
23327 cmdlist_t *reqQ;
23328 cmdlist_t *cmpQ;
23329diff -urNp linux-3.0.4/drivers/block/DAC960.c linux-3.0.4/drivers/block/DAC960.c
23330--- linux-3.0.4/drivers/block/DAC960.c 2011-07-21 22:17:23.000000000 -0400
23331+++ linux-3.0.4/drivers/block/DAC960.c 2011-08-23 21:48:14.000000000 -0400
23332@@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfigur
23333 unsigned long flags;
23334 int Channel, TargetID;
23335
23336+ pax_track_stack();
23337+
23338 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
23339 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
23340 sizeof(DAC960_SCSI_Inquiry_T) +
23341diff -urNp linux-3.0.4/drivers/block/drbd/drbd_int.h linux-3.0.4/drivers/block/drbd/drbd_int.h
23342--- linux-3.0.4/drivers/block/drbd/drbd_int.h 2011-07-21 22:17:23.000000000 -0400
23343+++ linux-3.0.4/drivers/block/drbd/drbd_int.h 2011-08-23 21:47:55.000000000 -0400
23344@@ -737,7 +737,7 @@ struct drbd_request;
23345 struct drbd_epoch {
23346 struct list_head list;
23347 unsigned int barrier_nr;
23348- atomic_t epoch_size; /* increased on every request added. */
23349+ atomic_unchecked_t epoch_size; /* increased on every request added. */
23350 atomic_t active; /* increased on every req. added, and dec on every finished. */
23351 unsigned long flags;
23352 };
23353@@ -1109,7 +1109,7 @@ struct drbd_conf {
23354 void *int_dig_in;
23355 void *int_dig_vv;
23356 wait_queue_head_t seq_wait;
23357- atomic_t packet_seq;
23358+ atomic_unchecked_t packet_seq;
23359 unsigned int peer_seq;
23360 spinlock_t peer_seq_lock;
23361 unsigned int minor;
23362diff -urNp linux-3.0.4/drivers/block/drbd/drbd_main.c linux-3.0.4/drivers/block/drbd/drbd_main.c
23363--- linux-3.0.4/drivers/block/drbd/drbd_main.c 2011-07-21 22:17:23.000000000 -0400
23364+++ linux-3.0.4/drivers/block/drbd/drbd_main.c 2011-08-23 21:47:55.000000000 -0400
23365@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_co
23366 p.sector = sector;
23367 p.block_id = block_id;
23368 p.blksize = blksize;
23369- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
23370+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
23371
23372 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
23373 return false;
23374@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *m
23375 p.sector = cpu_to_be64(req->sector);
23376 p.block_id = (unsigned long)req;
23377 p.seq_num = cpu_to_be32(req->seq_num =
23378- atomic_add_return(1, &mdev->packet_seq));
23379+ atomic_add_return_unchecked(1, &mdev->packet_seq));
23380
23381 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
23382
23383@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_
23384 atomic_set(&mdev->unacked_cnt, 0);
23385 atomic_set(&mdev->local_cnt, 0);
23386 atomic_set(&mdev->net_cnt, 0);
23387- atomic_set(&mdev->packet_seq, 0);
23388+ atomic_set_unchecked(&mdev->packet_seq, 0);
23389 atomic_set(&mdev->pp_in_use, 0);
23390 atomic_set(&mdev->pp_in_use_by_net, 0);
23391 atomic_set(&mdev->rs_sect_in, 0);
23392@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf
23393 mdev->receiver.t_state);
23394
23395 /* no need to lock it, I'm the only thread alive */
23396- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
23397- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
23398+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
23399+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
23400 mdev->al_writ_cnt =
23401 mdev->bm_writ_cnt =
23402 mdev->read_cnt =
23403diff -urNp linux-3.0.4/drivers/block/drbd/drbd_nl.c linux-3.0.4/drivers/block/drbd/drbd_nl.c
23404--- linux-3.0.4/drivers/block/drbd/drbd_nl.c 2011-07-21 22:17:23.000000000 -0400
23405+++ linux-3.0.4/drivers/block/drbd/drbd_nl.c 2011-08-23 21:47:55.000000000 -0400
23406@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(stru
23407 module_put(THIS_MODULE);
23408 }
23409
23410-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
23411+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
23412
23413 static unsigned short *
23414 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
23415@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *
23416 cn_reply->id.idx = CN_IDX_DRBD;
23417 cn_reply->id.val = CN_VAL_DRBD;
23418
23419- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
23420+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
23421 cn_reply->ack = 0; /* not used here. */
23422 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
23423 (int)((char *)tl - (char *)reply->tag_list);
23424@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_co
23425 cn_reply->id.idx = CN_IDX_DRBD;
23426 cn_reply->id.val = CN_VAL_DRBD;
23427
23428- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
23429+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
23430 cn_reply->ack = 0; /* not used here. */
23431 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
23432 (int)((char *)tl - (char *)reply->tag_list);
23433@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mde
23434 cn_reply->id.idx = CN_IDX_DRBD;
23435 cn_reply->id.val = CN_VAL_DRBD;
23436
23437- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
23438+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
23439 cn_reply->ack = 0; // not used here.
23440 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
23441 (int)((char*)tl - (char*)reply->tag_list);
23442@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drb
23443 cn_reply->id.idx = CN_IDX_DRBD;
23444 cn_reply->id.val = CN_VAL_DRBD;
23445
23446- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
23447+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
23448 cn_reply->ack = 0; /* not used here. */
23449 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
23450 (int)((char *)tl - (char *)reply->tag_list);
23451diff -urNp linux-3.0.4/drivers/block/drbd/drbd_receiver.c linux-3.0.4/drivers/block/drbd/drbd_receiver.c
23452--- linux-3.0.4/drivers/block/drbd/drbd_receiver.c 2011-07-21 22:17:23.000000000 -0400
23453+++ linux-3.0.4/drivers/block/drbd/drbd_receiver.c 2011-08-23 21:47:55.000000000 -0400
23454@@ -894,7 +894,7 @@ retry:
23455 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
23456 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
23457
23458- atomic_set(&mdev->packet_seq, 0);
23459+ atomic_set_unchecked(&mdev->packet_seq, 0);
23460 mdev->peer_seq = 0;
23461
23462 drbd_thread_start(&mdev->asender);
23463@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish
23464 do {
23465 next_epoch = NULL;
23466
23467- epoch_size = atomic_read(&epoch->epoch_size);
23468+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
23469
23470 switch (ev & ~EV_CLEANUP) {
23471 case EV_PUT:
23472@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish
23473 rv = FE_DESTROYED;
23474 } else {
23475 epoch->flags = 0;
23476- atomic_set(&epoch->epoch_size, 0);
23477+ atomic_set_unchecked(&epoch->epoch_size, 0);
23478 /* atomic_set(&epoch->active, 0); is already zero */
23479 if (rv == FE_STILL_LIVE)
23480 rv = FE_RECYCLED;
23481@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_c
23482 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
23483 drbd_flush(mdev);
23484
23485- if (atomic_read(&mdev->current_epoch->epoch_size)) {
23486+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
23487 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
23488 if (epoch)
23489 break;
23490 }
23491
23492 epoch = mdev->current_epoch;
23493- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
23494+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
23495
23496 D_ASSERT(atomic_read(&epoch->active) == 0);
23497 D_ASSERT(epoch->flags == 0);
23498@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_c
23499 }
23500
23501 epoch->flags = 0;
23502- atomic_set(&epoch->epoch_size, 0);
23503+ atomic_set_unchecked(&epoch->epoch_size, 0);
23504 atomic_set(&epoch->active, 0);
23505
23506 spin_lock(&mdev->epoch_lock);
23507- if (atomic_read(&mdev->current_epoch->epoch_size)) {
23508+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
23509 list_add(&epoch->list, &mdev->current_epoch->list);
23510 mdev->current_epoch = epoch;
23511 mdev->epochs++;
23512@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf
23513 spin_unlock(&mdev->peer_seq_lock);
23514
23515 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
23516- atomic_inc(&mdev->current_epoch->epoch_size);
23517+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
23518 return drbd_drain_block(mdev, data_size);
23519 }
23520
23521@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf
23522
23523 spin_lock(&mdev->epoch_lock);
23524 e->epoch = mdev->current_epoch;
23525- atomic_inc(&e->epoch->epoch_size);
23526+ atomic_inc_unchecked(&e->epoch->epoch_size);
23527 atomic_inc(&e->epoch->active);
23528 spin_unlock(&mdev->epoch_lock);
23529
23530@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_
23531 D_ASSERT(list_empty(&mdev->done_ee));
23532
23533 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
23534- atomic_set(&mdev->current_epoch->epoch_size, 0);
23535+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
23536 D_ASSERT(list_empty(&mdev->current_epoch->list));
23537 }
23538
23539diff -urNp linux-3.0.4/drivers/block/nbd.c linux-3.0.4/drivers/block/nbd.c
23540--- linux-3.0.4/drivers/block/nbd.c 2011-07-21 22:17:23.000000000 -0400
23541+++ linux-3.0.4/drivers/block/nbd.c 2011-08-23 21:48:14.000000000 -0400
23542@@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *
23543 struct kvec iov;
23544 sigset_t blocked, oldset;
23545
23546+ pax_track_stack();
23547+
23548 if (unlikely(!sock)) {
23549 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
23550 lo->disk->disk_name, (send ? "send" : "recv"));
23551@@ -572,6 +574,8 @@ static void do_nbd_request(struct reques
23552 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
23553 unsigned int cmd, unsigned long arg)
23554 {
23555+ pax_track_stack();
23556+
23557 switch (cmd) {
23558 case NBD_DISCONNECT: {
23559 struct request sreq;
23560diff -urNp linux-3.0.4/drivers/char/agp/frontend.c linux-3.0.4/drivers/char/agp/frontend.c
23561--- linux-3.0.4/drivers/char/agp/frontend.c 2011-07-21 22:17:23.000000000 -0400
23562+++ linux-3.0.4/drivers/char/agp/frontend.c 2011-08-23 21:47:55.000000000 -0400
23563@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
23564 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
23565 return -EFAULT;
23566
23567- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
23568+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
23569 return -EFAULT;
23570
23571 client = agp_find_client_by_pid(reserve.pid);
23572diff -urNp linux-3.0.4/drivers/char/briq_panel.c linux-3.0.4/drivers/char/briq_panel.c
23573--- linux-3.0.4/drivers/char/briq_panel.c 2011-07-21 22:17:23.000000000 -0400
23574+++ linux-3.0.4/drivers/char/briq_panel.c 2011-08-23 21:48:14.000000000 -0400
23575@@ -9,6 +9,7 @@
23576 #include <linux/types.h>
23577 #include <linux/errno.h>
23578 #include <linux/tty.h>
23579+#include <linux/mutex.h>
23580 #include <linux/timer.h>
23581 #include <linux/kernel.h>
23582 #include <linux/wait.h>
23583@@ -34,6 +35,7 @@ static int vfd_is_open;
23584 static unsigned char vfd[40];
23585 static int vfd_cursor;
23586 static unsigned char ledpb, led;
23587+static DEFINE_MUTEX(vfd_mutex);
23588
23589 static void update_vfd(void)
23590 {
23591@@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct f
23592 if (!vfd_is_open)
23593 return -EBUSY;
23594
23595+ mutex_lock(&vfd_mutex);
23596 for (;;) {
23597 char c;
23598 if (!indx)
23599 break;
23600- if (get_user(c, buf))
23601+ if (get_user(c, buf)) {
23602+ mutex_unlock(&vfd_mutex);
23603 return -EFAULT;
23604+ }
23605 if (esc) {
23606 set_led(c);
23607 esc = 0;
23608@@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct f
23609 buf++;
23610 }
23611 update_vfd();
23612+ mutex_unlock(&vfd_mutex);
23613
23614 return len;
23615 }
23616diff -urNp linux-3.0.4/drivers/char/genrtc.c linux-3.0.4/drivers/char/genrtc.c
23617--- linux-3.0.4/drivers/char/genrtc.c 2011-07-21 22:17:23.000000000 -0400
23618+++ linux-3.0.4/drivers/char/genrtc.c 2011-08-23 21:48:14.000000000 -0400
23619@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *fi
23620 switch (cmd) {
23621
23622 case RTC_PLL_GET:
23623+ memset(&pll, 0, sizeof(pll));
23624 if (get_rtc_pll(&pll))
23625 return -EINVAL;
23626 else
23627diff -urNp linux-3.0.4/drivers/char/hpet.c linux-3.0.4/drivers/char/hpet.c
23628--- linux-3.0.4/drivers/char/hpet.c 2011-07-21 22:17:23.000000000 -0400
23629+++ linux-3.0.4/drivers/char/hpet.c 2011-08-23 21:47:55.000000000 -0400
23630@@ -572,7 +572,7 @@ static inline unsigned long hpet_time_di
23631 }
23632
23633 static int
23634-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
23635+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
23636 struct hpet_info *info)
23637 {
23638 struct hpet_timer __iomem *timer;
23639diff -urNp linux-3.0.4/drivers/char/ipmi/ipmi_msghandler.c linux-3.0.4/drivers/char/ipmi/ipmi_msghandler.c
23640--- linux-3.0.4/drivers/char/ipmi/ipmi_msghandler.c 2011-07-21 22:17:23.000000000 -0400
23641+++ linux-3.0.4/drivers/char/ipmi/ipmi_msghandler.c 2011-08-23 21:48:14.000000000 -0400
23642@@ -415,7 +415,7 @@ struct ipmi_smi {
23643 struct proc_dir_entry *proc_dir;
23644 char proc_dir_name[10];
23645
23646- atomic_t stats[IPMI_NUM_STATS];
23647+ atomic_unchecked_t stats[IPMI_NUM_STATS];
23648
23649 /*
23650 * run_to_completion duplicate of smb_info, smi_info
23651@@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
23652
23653
23654 #define ipmi_inc_stat(intf, stat) \
23655- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
23656+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
23657 #define ipmi_get_stat(intf, stat) \
23658- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
23659+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
23660
23661 static int is_lan_addr(struct ipmi_addr *addr)
23662 {
23663@@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
23664 INIT_LIST_HEAD(&intf->cmd_rcvrs);
23665 init_waitqueue_head(&intf->waitq);
23666 for (i = 0; i < IPMI_NUM_STATS; i++)
23667- atomic_set(&intf->stats[i], 0);
23668+ atomic_set_unchecked(&intf->stats[i], 0);
23669
23670 intf->proc_dir = NULL;
23671
23672@@ -4220,6 +4220,8 @@ static void send_panic_events(char *str)
23673 struct ipmi_smi_msg smi_msg;
23674 struct ipmi_recv_msg recv_msg;
23675
23676+ pax_track_stack();
23677+
23678 si = (struct ipmi_system_interface_addr *) &addr;
23679 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
23680 si->channel = IPMI_BMC_CHANNEL;
23681diff -urNp linux-3.0.4/drivers/char/ipmi/ipmi_si_intf.c linux-3.0.4/drivers/char/ipmi/ipmi_si_intf.c
23682--- linux-3.0.4/drivers/char/ipmi/ipmi_si_intf.c 2011-07-21 22:17:23.000000000 -0400
23683+++ linux-3.0.4/drivers/char/ipmi/ipmi_si_intf.c 2011-08-23 21:47:55.000000000 -0400
23684@@ -277,7 +277,7 @@ struct smi_info {
23685 unsigned char slave_addr;
23686
23687 /* Counters and things for the proc filesystem. */
23688- atomic_t stats[SI_NUM_STATS];
23689+ atomic_unchecked_t stats[SI_NUM_STATS];
23690
23691 struct task_struct *thread;
23692
23693@@ -286,9 +286,9 @@ struct smi_info {
23694 };
23695
23696 #define smi_inc_stat(smi, stat) \
23697- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
23698+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
23699 #define smi_get_stat(smi, stat) \
23700- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
23701+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
23702
23703 #define SI_MAX_PARMS 4
23704
23705@@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info
23706 atomic_set(&new_smi->req_events, 0);
23707 new_smi->run_to_completion = 0;
23708 for (i = 0; i < SI_NUM_STATS; i++)
23709- atomic_set(&new_smi->stats[i], 0);
23710+ atomic_set_unchecked(&new_smi->stats[i], 0);
23711
23712 new_smi->interrupt_disabled = 1;
23713 atomic_set(&new_smi->stop_operation, 0);
23714diff -urNp linux-3.0.4/drivers/char/Kconfig linux-3.0.4/drivers/char/Kconfig
23715--- linux-3.0.4/drivers/char/Kconfig 2011-07-21 22:17:23.000000000 -0400
23716+++ linux-3.0.4/drivers/char/Kconfig 2011-08-23 21:48:14.000000000 -0400
23717@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
23718
23719 config DEVKMEM
23720 bool "/dev/kmem virtual device support"
23721- default y
23722+ default n
23723+ depends on !GRKERNSEC_KMEM
23724 help
23725 Say Y here if you want to support the /dev/kmem device. The
23726 /dev/kmem device is rarely used, but can be used for certain
23727@@ -596,6 +597,7 @@ config DEVPORT
23728 bool
23729 depends on !M68K
23730 depends on ISA || PCI
23731+ depends on !GRKERNSEC_KMEM
23732 default y
23733
23734 source "drivers/s390/char/Kconfig"
23735diff -urNp linux-3.0.4/drivers/char/mem.c linux-3.0.4/drivers/char/mem.c
23736--- linux-3.0.4/drivers/char/mem.c 2011-07-21 22:17:23.000000000 -0400
23737+++ linux-3.0.4/drivers/char/mem.c 2011-08-23 21:48:14.000000000 -0400
23738@@ -18,6 +18,7 @@
23739 #include <linux/raw.h>
23740 #include <linux/tty.h>
23741 #include <linux/capability.h>
23742+#include <linux/security.h>
23743 #include <linux/ptrace.h>
23744 #include <linux/device.h>
23745 #include <linux/highmem.h>
23746@@ -34,6 +35,10 @@
23747 # include <linux/efi.h>
23748 #endif
23749
23750+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
23751+extern struct file_operations grsec_fops;
23752+#endif
23753+
23754 static inline unsigned long size_inside_page(unsigned long start,
23755 unsigned long size)
23756 {
23757@@ -65,9 +70,13 @@ static inline int range_is_allowed(unsig
23758
23759 while (cursor < to) {
23760 if (!devmem_is_allowed(pfn)) {
23761+#ifdef CONFIG_GRKERNSEC_KMEM
23762+ gr_handle_mem_readwrite(from, to);
23763+#else
23764 printk(KERN_INFO
23765 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23766 current->comm, from, to);
23767+#endif
23768 return 0;
23769 }
23770 cursor += PAGE_SIZE;
23771@@ -75,6 +84,11 @@ static inline int range_is_allowed(unsig
23772 }
23773 return 1;
23774 }
23775+#elif defined(CONFIG_GRKERNSEC_KMEM)
23776+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23777+{
23778+ return 0;
23779+}
23780 #else
23781 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23782 {
23783@@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *fil
23784
23785 while (count > 0) {
23786 unsigned long remaining;
23787+ char *temp;
23788
23789 sz = size_inside_page(p, count);
23790
23791@@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *fil
23792 if (!ptr)
23793 return -EFAULT;
23794
23795- remaining = copy_to_user(buf, ptr, sz);
23796+#ifdef CONFIG_PAX_USERCOPY
23797+ temp = kmalloc(sz, GFP_KERNEL);
23798+ if (!temp) {
23799+ unxlate_dev_mem_ptr(p, ptr);
23800+ return -ENOMEM;
23801+ }
23802+ memcpy(temp, ptr, sz);
23803+#else
23804+ temp = ptr;
23805+#endif
23806+
23807+ remaining = copy_to_user(buf, temp, sz);
23808+
23809+#ifdef CONFIG_PAX_USERCOPY
23810+ kfree(temp);
23811+#endif
23812+
23813 unxlate_dev_mem_ptr(p, ptr);
23814 if (remaining)
23815 return -EFAULT;
23816@@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *fi
23817 size_t count, loff_t *ppos)
23818 {
23819 unsigned long p = *ppos;
23820- ssize_t low_count, read, sz;
23821+ ssize_t low_count, read, sz, err = 0;
23822 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
23823- int err = 0;
23824
23825 read = 0;
23826 if (p < (unsigned long) high_memory) {
23827@@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *fi
23828 }
23829 #endif
23830 while (low_count > 0) {
23831+ char *temp;
23832+
23833 sz = size_inside_page(p, low_count);
23834
23835 /*
23836@@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *fi
23837 */
23838 kbuf = xlate_dev_kmem_ptr((char *)p);
23839
23840- if (copy_to_user(buf, kbuf, sz))
23841+#ifdef CONFIG_PAX_USERCOPY
23842+ temp = kmalloc(sz, GFP_KERNEL);
23843+ if (!temp)
23844+ return -ENOMEM;
23845+ memcpy(temp, kbuf, sz);
23846+#else
23847+ temp = kbuf;
23848+#endif
23849+
23850+ err = copy_to_user(buf, temp, sz);
23851+
23852+#ifdef CONFIG_PAX_USERCOPY
23853+ kfree(temp);
23854+#endif
23855+
23856+ if (err)
23857 return -EFAULT;
23858 buf += sz;
23859 p += sz;
23860@@ -866,6 +913,9 @@ static const struct memdev {
23861 #ifdef CONFIG_CRASH_DUMP
23862 [12] = { "oldmem", 0, &oldmem_fops, NULL },
23863 #endif
23864+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
23865+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
23866+#endif
23867 };
23868
23869 static int memory_open(struct inode *inode, struct file *filp)
23870diff -urNp linux-3.0.4/drivers/char/nvram.c linux-3.0.4/drivers/char/nvram.c
23871--- linux-3.0.4/drivers/char/nvram.c 2011-07-21 22:17:23.000000000 -0400
23872+++ linux-3.0.4/drivers/char/nvram.c 2011-08-23 21:47:55.000000000 -0400
23873@@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
23874
23875 spin_unlock_irq(&rtc_lock);
23876
23877- if (copy_to_user(buf, contents, tmp - contents))
23878+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
23879 return -EFAULT;
23880
23881 *ppos = i;
23882diff -urNp linux-3.0.4/drivers/char/random.c linux-3.0.4/drivers/char/random.c
23883--- linux-3.0.4/drivers/char/random.c 2011-08-23 21:44:40.000000000 -0400
23884+++ linux-3.0.4/drivers/char/random.c 2011-08-23 21:48:14.000000000 -0400
23885@@ -261,8 +261,13 @@
23886 /*
23887 * Configuration information
23888 */
23889+#ifdef CONFIG_GRKERNSEC_RANDNET
23890+#define INPUT_POOL_WORDS 512
23891+#define OUTPUT_POOL_WORDS 128
23892+#else
23893 #define INPUT_POOL_WORDS 128
23894 #define OUTPUT_POOL_WORDS 32
23895+#endif
23896 #define SEC_XFER_SIZE 512
23897 #define EXTRACT_SIZE 10
23898
23899@@ -300,10 +305,17 @@ static struct poolinfo {
23900 int poolwords;
23901 int tap1, tap2, tap3, tap4, tap5;
23902 } poolinfo_table[] = {
23903+#ifdef CONFIG_GRKERNSEC_RANDNET
23904+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
23905+ { 512, 411, 308, 208, 104, 1 },
23906+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
23907+ { 128, 103, 76, 51, 25, 1 },
23908+#else
23909 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
23910 { 128, 103, 76, 51, 25, 1 },
23911 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
23912 { 32, 26, 20, 14, 7, 1 },
23913+#endif
23914 #if 0
23915 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
23916 { 2048, 1638, 1231, 819, 411, 1 },
23917@@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(stru
23918
23919 extract_buf(r, tmp);
23920 i = min_t(int, nbytes, EXTRACT_SIZE);
23921- if (copy_to_user(buf, tmp, i)) {
23922+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
23923 ret = -EFAULT;
23924 break;
23925 }
23926@@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
23927 #include <linux/sysctl.h>
23928
23929 static int min_read_thresh = 8, min_write_thresh;
23930-static int max_read_thresh = INPUT_POOL_WORDS * 32;
23931+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
23932 static int max_write_thresh = INPUT_POOL_WORDS * 32;
23933 static char sysctl_bootid[16];
23934
23935diff -urNp linux-3.0.4/drivers/char/sonypi.c linux-3.0.4/drivers/char/sonypi.c
23936--- linux-3.0.4/drivers/char/sonypi.c 2011-07-21 22:17:23.000000000 -0400
23937+++ linux-3.0.4/drivers/char/sonypi.c 2011-08-23 21:47:55.000000000 -0400
23938@@ -55,6 +55,7 @@
23939 #include <asm/uaccess.h>
23940 #include <asm/io.h>
23941 #include <asm/system.h>
23942+#include <asm/local.h>
23943
23944 #include <linux/sonypi.h>
23945
23946@@ -491,7 +492,7 @@ static struct sonypi_device {
23947 spinlock_t fifo_lock;
23948 wait_queue_head_t fifo_proc_list;
23949 struct fasync_struct *fifo_async;
23950- int open_count;
23951+ local_t open_count;
23952 int model;
23953 struct input_dev *input_jog_dev;
23954 struct input_dev *input_key_dev;
23955@@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, st
23956 static int sonypi_misc_release(struct inode *inode, struct file *file)
23957 {
23958 mutex_lock(&sonypi_device.lock);
23959- sonypi_device.open_count--;
23960+ local_dec(&sonypi_device.open_count);
23961 mutex_unlock(&sonypi_device.lock);
23962 return 0;
23963 }
23964@@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode
23965 {
23966 mutex_lock(&sonypi_device.lock);
23967 /* Flush input queue on first open */
23968- if (!sonypi_device.open_count)
23969+ if (!local_read(&sonypi_device.open_count))
23970 kfifo_reset(&sonypi_device.fifo);
23971- sonypi_device.open_count++;
23972+ local_inc(&sonypi_device.open_count);
23973 mutex_unlock(&sonypi_device.lock);
23974
23975 return 0;
23976diff -urNp linux-3.0.4/drivers/char/tpm/tpm_bios.c linux-3.0.4/drivers/char/tpm/tpm_bios.c
23977--- linux-3.0.4/drivers/char/tpm/tpm_bios.c 2011-07-21 22:17:23.000000000 -0400
23978+++ linux-3.0.4/drivers/char/tpm/tpm_bios.c 2011-08-23 21:47:55.000000000 -0400
23979@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
23980 event = addr;
23981
23982 if ((event->event_type == 0 && event->event_size == 0) ||
23983- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
23984+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
23985 return NULL;
23986
23987 return addr;
23988@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
23989 return NULL;
23990
23991 if ((event->event_type == 0 && event->event_size == 0) ||
23992- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
23993+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
23994 return NULL;
23995
23996 (*pos)++;
23997@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
23998 int i;
23999
24000 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
24001- seq_putc(m, data[i]);
24002+ if (!seq_putc(m, data[i]))
24003+ return -EFAULT;
24004
24005 return 0;
24006 }
24007@@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
24008 log->bios_event_log_end = log->bios_event_log + len;
24009
24010 virt = acpi_os_map_memory(start, len);
24011+ if (!virt) {
24012+ kfree(log->bios_event_log);
24013+ log->bios_event_log = NULL;
24014+ return -EFAULT;
24015+ }
24016
24017 memcpy(log->bios_event_log, virt, len);
24018
24019diff -urNp linux-3.0.4/drivers/char/tpm/tpm.c linux-3.0.4/drivers/char/tpm/tpm.c
24020--- linux-3.0.4/drivers/char/tpm/tpm.c 2011-07-21 22:17:23.000000000 -0400
24021+++ linux-3.0.4/drivers/char/tpm/tpm.c 2011-08-23 21:48:14.000000000 -0400
24022@@ -411,7 +411,7 @@ static ssize_t tpm_transmit(struct tpm_c
24023 chip->vendor.req_complete_val)
24024 goto out_recv;
24025
24026- if ((status == chip->vendor.req_canceled)) {
24027+ if (status == chip->vendor.req_canceled) {
24028 dev_err(chip->dev, "Operation Canceled\n");
24029 rc = -ECANCELED;
24030 goto out;
24031@@ -844,6 +844,8 @@ ssize_t tpm_show_pubek(struct device *de
24032
24033 struct tpm_chip *chip = dev_get_drvdata(dev);
24034
24035+ pax_track_stack();
24036+
24037 tpm_cmd.header.in = tpm_readpubek_header;
24038 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
24039 "attempting to read the PUBEK");
24040diff -urNp linux-3.0.4/drivers/crypto/hifn_795x.c linux-3.0.4/drivers/crypto/hifn_795x.c
24041--- linux-3.0.4/drivers/crypto/hifn_795x.c 2011-07-21 22:17:23.000000000 -0400
24042+++ linux-3.0.4/drivers/crypto/hifn_795x.c 2011-08-23 21:48:14.000000000 -0400
24043@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
24044 0xCA, 0x34, 0x2B, 0x2E};
24045 struct scatterlist sg;
24046
24047+ pax_track_stack();
24048+
24049 memset(src, 0, sizeof(src));
24050 memset(ctx.key, 0, sizeof(ctx.key));
24051
24052diff -urNp linux-3.0.4/drivers/crypto/padlock-aes.c linux-3.0.4/drivers/crypto/padlock-aes.c
24053--- linux-3.0.4/drivers/crypto/padlock-aes.c 2011-07-21 22:17:23.000000000 -0400
24054+++ linux-3.0.4/drivers/crypto/padlock-aes.c 2011-08-23 21:48:14.000000000 -0400
24055@@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm
24056 struct crypto_aes_ctx gen_aes;
24057 int cpu;
24058
24059+ pax_track_stack();
24060+
24061 if (key_len % 8) {
24062 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
24063 return -EINVAL;
24064diff -urNp linux-3.0.4/drivers/edac/edac_pci_sysfs.c linux-3.0.4/drivers/edac/edac_pci_sysfs.c
24065--- linux-3.0.4/drivers/edac/edac_pci_sysfs.c 2011-07-21 22:17:23.000000000 -0400
24066+++ linux-3.0.4/drivers/edac/edac_pci_sysfs.c 2011-08-23 21:47:55.000000000 -0400
24067@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log
24068 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
24069 static int edac_pci_poll_msec = 1000; /* one second workq period */
24070
24071-static atomic_t pci_parity_count = ATOMIC_INIT(0);
24072-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
24073+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
24074+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
24075
24076 static struct kobject *edac_pci_top_main_kobj;
24077 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
24078@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(str
24079 edac_printk(KERN_CRIT, EDAC_PCI,
24080 "Signaled System Error on %s\n",
24081 pci_name(dev));
24082- atomic_inc(&pci_nonparity_count);
24083+ atomic_inc_unchecked(&pci_nonparity_count);
24084 }
24085
24086 if (status & (PCI_STATUS_PARITY)) {
24087@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(str
24088 "Master Data Parity Error on %s\n",
24089 pci_name(dev));
24090
24091- atomic_inc(&pci_parity_count);
24092+ atomic_inc_unchecked(&pci_parity_count);
24093 }
24094
24095 if (status & (PCI_STATUS_DETECTED_PARITY)) {
24096@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(str
24097 "Detected Parity Error on %s\n",
24098 pci_name(dev));
24099
24100- atomic_inc(&pci_parity_count);
24101+ atomic_inc_unchecked(&pci_parity_count);
24102 }
24103 }
24104
24105@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(str
24106 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
24107 "Signaled System Error on %s\n",
24108 pci_name(dev));
24109- atomic_inc(&pci_nonparity_count);
24110+ atomic_inc_unchecked(&pci_nonparity_count);
24111 }
24112
24113 if (status & (PCI_STATUS_PARITY)) {
24114@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(str
24115 "Master Data Parity Error on "
24116 "%s\n", pci_name(dev));
24117
24118- atomic_inc(&pci_parity_count);
24119+ atomic_inc_unchecked(&pci_parity_count);
24120 }
24121
24122 if (status & (PCI_STATUS_DETECTED_PARITY)) {
24123@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(str
24124 "Detected Parity Error on %s\n",
24125 pci_name(dev));
24126
24127- atomic_inc(&pci_parity_count);
24128+ atomic_inc_unchecked(&pci_parity_count);
24129 }
24130 }
24131 }
24132@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
24133 if (!check_pci_errors)
24134 return;
24135
24136- before_count = atomic_read(&pci_parity_count);
24137+ before_count = atomic_read_unchecked(&pci_parity_count);
24138
24139 /* scan all PCI devices looking for a Parity Error on devices and
24140 * bridges.
24141@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
24142 /* Only if operator has selected panic on PCI Error */
24143 if (edac_pci_get_panic_on_pe()) {
24144 /* If the count is different 'after' from 'before' */
24145- if (before_count != atomic_read(&pci_parity_count))
24146+ if (before_count != atomic_read_unchecked(&pci_parity_count))
24147 panic("EDAC: PCI Parity Error");
24148 }
24149 }
24150diff -urNp linux-3.0.4/drivers/edac/mce_amd.h linux-3.0.4/drivers/edac/mce_amd.h
24151--- linux-3.0.4/drivers/edac/mce_amd.h 2011-07-21 22:17:23.000000000 -0400
24152+++ linux-3.0.4/drivers/edac/mce_amd.h 2011-08-23 21:47:55.000000000 -0400
24153@@ -83,7 +83,7 @@ struct amd_decoder_ops {
24154 bool (*dc_mce)(u16, u8);
24155 bool (*ic_mce)(u16, u8);
24156 bool (*nb_mce)(u16, u8);
24157-};
24158+} __no_const;
24159
24160 void amd_report_gart_errors(bool);
24161 void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32));
24162diff -urNp linux-3.0.4/drivers/firewire/core-card.c linux-3.0.4/drivers/firewire/core-card.c
24163--- linux-3.0.4/drivers/firewire/core-card.c 2011-07-21 22:17:23.000000000 -0400
24164+++ linux-3.0.4/drivers/firewire/core-card.c 2011-08-23 21:47:55.000000000 -0400
24165@@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
24166
24167 void fw_core_remove_card(struct fw_card *card)
24168 {
24169- struct fw_card_driver dummy_driver = dummy_driver_template;
24170+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
24171
24172 card->driver->update_phy_reg(card, 4,
24173 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
24174diff -urNp linux-3.0.4/drivers/firewire/core-cdev.c linux-3.0.4/drivers/firewire/core-cdev.c
24175--- linux-3.0.4/drivers/firewire/core-cdev.c 2011-08-23 21:44:40.000000000 -0400
24176+++ linux-3.0.4/drivers/firewire/core-cdev.c 2011-08-23 21:47:55.000000000 -0400
24177@@ -1313,8 +1313,7 @@ static int init_iso_resource(struct clie
24178 int ret;
24179
24180 if ((request->channels == 0 && request->bandwidth == 0) ||
24181- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
24182- request->bandwidth < 0)
24183+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
24184 return -EINVAL;
24185
24186 r = kmalloc(sizeof(*r), GFP_KERNEL);
24187diff -urNp linux-3.0.4/drivers/firewire/core.h linux-3.0.4/drivers/firewire/core.h
24188--- linux-3.0.4/drivers/firewire/core.h 2011-07-21 22:17:23.000000000 -0400
24189+++ linux-3.0.4/drivers/firewire/core.h 2011-08-23 21:47:55.000000000 -0400
24190@@ -101,6 +101,7 @@ struct fw_card_driver {
24191
24192 int (*stop_iso)(struct fw_iso_context *ctx);
24193 };
24194+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
24195
24196 void fw_card_initialize(struct fw_card *card,
24197 const struct fw_card_driver *driver, struct device *device);
24198diff -urNp linux-3.0.4/drivers/firewire/core-transaction.c linux-3.0.4/drivers/firewire/core-transaction.c
24199--- linux-3.0.4/drivers/firewire/core-transaction.c 2011-07-21 22:17:23.000000000 -0400
24200+++ linux-3.0.4/drivers/firewire/core-transaction.c 2011-08-23 21:48:14.000000000 -0400
24201@@ -37,6 +37,7 @@
24202 #include <linux/timer.h>
24203 #include <linux/types.h>
24204 #include <linux/workqueue.h>
24205+#include <linux/sched.h>
24206
24207 #include <asm/byteorder.h>
24208
24209@@ -422,6 +423,8 @@ int fw_run_transaction(struct fw_card *c
24210 struct transaction_callback_data d;
24211 struct fw_transaction t;
24212
24213+ pax_track_stack();
24214+
24215 init_timer_on_stack(&t.split_timeout_timer);
24216 init_completion(&d.done);
24217 d.payload = payload;
24218diff -urNp linux-3.0.4/drivers/firmware/dmi_scan.c linux-3.0.4/drivers/firmware/dmi_scan.c
24219--- linux-3.0.4/drivers/firmware/dmi_scan.c 2011-07-21 22:17:23.000000000 -0400
24220+++ linux-3.0.4/drivers/firmware/dmi_scan.c 2011-08-23 21:47:55.000000000 -0400
24221@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
24222 }
24223 }
24224 else {
24225- /*
24226- * no iounmap() for that ioremap(); it would be a no-op, but
24227- * it's so early in setup that sucker gets confused into doing
24228- * what it shouldn't if we actually call it.
24229- */
24230 p = dmi_ioremap(0xF0000, 0x10000);
24231 if (p == NULL)
24232 goto error;
24233diff -urNp linux-3.0.4/drivers/gpio/vr41xx_giu.c linux-3.0.4/drivers/gpio/vr41xx_giu.c
24234--- linux-3.0.4/drivers/gpio/vr41xx_giu.c 2011-07-21 22:17:23.000000000 -0400
24235+++ linux-3.0.4/drivers/gpio/vr41xx_giu.c 2011-08-23 21:47:55.000000000 -0400
24236@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
24237 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
24238 maskl, pendl, maskh, pendh);
24239
24240- atomic_inc(&irq_err_count);
24241+ atomic_inc_unchecked(&irq_err_count);
24242
24243 return -EINVAL;
24244 }
24245diff -urNp linux-3.0.4/drivers/gpu/drm/drm_crtc_helper.c linux-3.0.4/drivers/gpu/drm/drm_crtc_helper.c
24246--- linux-3.0.4/drivers/gpu/drm/drm_crtc_helper.c 2011-07-21 22:17:23.000000000 -0400
24247+++ linux-3.0.4/drivers/gpu/drm/drm_crtc_helper.c 2011-08-23 21:48:14.000000000 -0400
24248@@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
24249 struct drm_crtc *tmp;
24250 int crtc_mask = 1;
24251
24252- WARN(!crtc, "checking null crtc?\n");
24253+ BUG_ON(!crtc);
24254
24255 dev = crtc->dev;
24256
24257@@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm
24258 struct drm_encoder *encoder;
24259 bool ret = true;
24260
24261+ pax_track_stack();
24262+
24263 crtc->enabled = drm_helper_crtc_in_use(crtc);
24264 if (!crtc->enabled)
24265 return true;
24266diff -urNp linux-3.0.4/drivers/gpu/drm/drm_drv.c linux-3.0.4/drivers/gpu/drm/drm_drv.c
24267--- linux-3.0.4/drivers/gpu/drm/drm_drv.c 2011-07-21 22:17:23.000000000 -0400
24268+++ linux-3.0.4/drivers/gpu/drm/drm_drv.c 2011-08-23 21:47:55.000000000 -0400
24269@@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
24270
24271 dev = file_priv->minor->dev;
24272 atomic_inc(&dev->ioctl_count);
24273- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
24274+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
24275 ++file_priv->ioctl_count;
24276
24277 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
24278diff -urNp linux-3.0.4/drivers/gpu/drm/drm_fops.c linux-3.0.4/drivers/gpu/drm/drm_fops.c
24279--- linux-3.0.4/drivers/gpu/drm/drm_fops.c 2011-07-21 22:17:23.000000000 -0400
24280+++ linux-3.0.4/drivers/gpu/drm/drm_fops.c 2011-08-23 21:47:55.000000000 -0400
24281@@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
24282 }
24283
24284 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
24285- atomic_set(&dev->counts[i], 0);
24286+ atomic_set_unchecked(&dev->counts[i], 0);
24287
24288 dev->sigdata.lock = NULL;
24289
24290@@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
24291
24292 retcode = drm_open_helper(inode, filp, dev);
24293 if (!retcode) {
24294- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
24295- if (!dev->open_count++)
24296+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
24297+ if (local_inc_return(&dev->open_count) == 1)
24298 retcode = drm_setup(dev);
24299 }
24300 if (!retcode) {
24301@@ -472,7 +472,7 @@ int drm_release(struct inode *inode, str
24302
24303 mutex_lock(&drm_global_mutex);
24304
24305- DRM_DEBUG("open_count = %d\n", dev->open_count);
24306+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
24307
24308 if (dev->driver->preclose)
24309 dev->driver->preclose(dev, file_priv);
24310@@ -484,7 +484,7 @@ int drm_release(struct inode *inode, str
24311 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
24312 task_pid_nr(current),
24313 (long)old_encode_dev(file_priv->minor->device),
24314- dev->open_count);
24315+ local_read(&dev->open_count));
24316
24317 /* if the master has gone away we can't do anything with the lock */
24318 if (file_priv->minor->master)
24319@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, str
24320 * End inline drm_release
24321 */
24322
24323- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
24324- if (!--dev->open_count) {
24325+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
24326+ if (local_dec_and_test(&dev->open_count)) {
24327 if (atomic_read(&dev->ioctl_count)) {
24328 DRM_ERROR("Device busy: %d\n",
24329 atomic_read(&dev->ioctl_count));
24330diff -urNp linux-3.0.4/drivers/gpu/drm/drm_global.c linux-3.0.4/drivers/gpu/drm/drm_global.c
24331--- linux-3.0.4/drivers/gpu/drm/drm_global.c 2011-07-21 22:17:23.000000000 -0400
24332+++ linux-3.0.4/drivers/gpu/drm/drm_global.c 2011-08-23 21:47:55.000000000 -0400
24333@@ -36,7 +36,7 @@
24334 struct drm_global_item {
24335 struct mutex mutex;
24336 void *object;
24337- int refcount;
24338+ atomic_t refcount;
24339 };
24340
24341 static struct drm_global_item glob[DRM_GLOBAL_NUM];
24342@@ -49,7 +49,7 @@ void drm_global_init(void)
24343 struct drm_global_item *item = &glob[i];
24344 mutex_init(&item->mutex);
24345 item->object = NULL;
24346- item->refcount = 0;
24347+ atomic_set(&item->refcount, 0);
24348 }
24349 }
24350
24351@@ -59,7 +59,7 @@ void drm_global_release(void)
24352 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
24353 struct drm_global_item *item = &glob[i];
24354 BUG_ON(item->object != NULL);
24355- BUG_ON(item->refcount != 0);
24356+ BUG_ON(atomic_read(&item->refcount) != 0);
24357 }
24358 }
24359
24360@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
24361 void *object;
24362
24363 mutex_lock(&item->mutex);
24364- if (item->refcount == 0) {
24365+ if (atomic_read(&item->refcount) == 0) {
24366 item->object = kzalloc(ref->size, GFP_KERNEL);
24367 if (unlikely(item->object == NULL)) {
24368 ret = -ENOMEM;
24369@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
24370 goto out_err;
24371
24372 }
24373- ++item->refcount;
24374+ atomic_inc(&item->refcount);
24375 ref->object = item->object;
24376 object = item->object;
24377 mutex_unlock(&item->mutex);
24378@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
24379 struct drm_global_item *item = &glob[ref->global_type];
24380
24381 mutex_lock(&item->mutex);
24382- BUG_ON(item->refcount == 0);
24383+ BUG_ON(atomic_read(&item->refcount) == 0);
24384 BUG_ON(ref->object != item->object);
24385- if (--item->refcount == 0) {
24386+ if (atomic_dec_and_test(&item->refcount)) {
24387 ref->release(ref);
24388 item->object = NULL;
24389 }
24390diff -urNp linux-3.0.4/drivers/gpu/drm/drm_info.c linux-3.0.4/drivers/gpu/drm/drm_info.c
24391--- linux-3.0.4/drivers/gpu/drm/drm_info.c 2011-07-21 22:17:23.000000000 -0400
24392+++ linux-3.0.4/drivers/gpu/drm/drm_info.c 2011-08-23 21:48:14.000000000 -0400
24393@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
24394 struct drm_local_map *map;
24395 struct drm_map_list *r_list;
24396
24397- /* Hardcoded from _DRM_FRAME_BUFFER,
24398- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
24399- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
24400- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
24401+ static const char * const types[] = {
24402+ [_DRM_FRAME_BUFFER] = "FB",
24403+ [_DRM_REGISTERS] = "REG",
24404+ [_DRM_SHM] = "SHM",
24405+ [_DRM_AGP] = "AGP",
24406+ [_DRM_SCATTER_GATHER] = "SG",
24407+ [_DRM_CONSISTENT] = "PCI",
24408+ [_DRM_GEM] = "GEM" };
24409 const char *type;
24410 int i;
24411
24412@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
24413 map = r_list->map;
24414 if (!map)
24415 continue;
24416- if (map->type < 0 || map->type > 5)
24417+ if (map->type >= ARRAY_SIZE(types))
24418 type = "??";
24419 else
24420 type = types[map->type];
24421@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, voi
24422 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
24423 vma->vm_flags & VM_LOCKED ? 'l' : '-',
24424 vma->vm_flags & VM_IO ? 'i' : '-',
24425+#ifdef CONFIG_GRKERNSEC_HIDESYM
24426+ 0);
24427+#else
24428 vma->vm_pgoff);
24429+#endif
24430
24431 #if defined(__i386__)
24432 pgprot = pgprot_val(vma->vm_page_prot);
24433diff -urNp linux-3.0.4/drivers/gpu/drm/drm_ioctl.c linux-3.0.4/drivers/gpu/drm/drm_ioctl.c
24434--- linux-3.0.4/drivers/gpu/drm/drm_ioctl.c 2011-07-21 22:17:23.000000000 -0400
24435+++ linux-3.0.4/drivers/gpu/drm/drm_ioctl.c 2011-08-23 21:47:55.000000000 -0400
24436@@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev,
24437 stats->data[i].value =
24438 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
24439 else
24440- stats->data[i].value = atomic_read(&dev->counts[i]);
24441+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
24442 stats->data[i].type = dev->types[i];
24443 }
24444
24445diff -urNp linux-3.0.4/drivers/gpu/drm/drm_lock.c linux-3.0.4/drivers/gpu/drm/drm_lock.c
24446--- linux-3.0.4/drivers/gpu/drm/drm_lock.c 2011-07-21 22:17:23.000000000 -0400
24447+++ linux-3.0.4/drivers/gpu/drm/drm_lock.c 2011-08-23 21:47:55.000000000 -0400
24448@@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
24449 if (drm_lock_take(&master->lock, lock->context)) {
24450 master->lock.file_priv = file_priv;
24451 master->lock.lock_time = jiffies;
24452- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
24453+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
24454 break; /* Got lock */
24455 }
24456
24457@@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
24458 return -EINVAL;
24459 }
24460
24461- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
24462+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
24463
24464 if (drm_lock_free(&master->lock, lock->context)) {
24465 /* FIXME: Should really bail out here. */
24466diff -urNp linux-3.0.4/drivers/gpu/drm/i810/i810_dma.c linux-3.0.4/drivers/gpu/drm/i810/i810_dma.c
24467--- linux-3.0.4/drivers/gpu/drm/i810/i810_dma.c 2011-07-21 22:17:23.000000000 -0400
24468+++ linux-3.0.4/drivers/gpu/drm/i810/i810_dma.c 2011-08-23 21:47:55.000000000 -0400
24469@@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_de
24470 dma->buflist[vertex->idx],
24471 vertex->discard, vertex->used);
24472
24473- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
24474- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
24475+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
24476+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
24477 sarea_priv->last_enqueue = dev_priv->counter - 1;
24478 sarea_priv->last_dispatch = (int)hw_status[5];
24479
24480@@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device
24481 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
24482 mc->last_render);
24483
24484- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
24485- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
24486+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
24487+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
24488 sarea_priv->last_enqueue = dev_priv->counter - 1;
24489 sarea_priv->last_dispatch = (int)hw_status[5];
24490
24491diff -urNp linux-3.0.4/drivers/gpu/drm/i810/i810_drv.h linux-3.0.4/drivers/gpu/drm/i810/i810_drv.h
24492--- linux-3.0.4/drivers/gpu/drm/i810/i810_drv.h 2011-07-21 22:17:23.000000000 -0400
24493+++ linux-3.0.4/drivers/gpu/drm/i810/i810_drv.h 2011-08-23 21:47:55.000000000 -0400
24494@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
24495 int page_flipping;
24496
24497 wait_queue_head_t irq_queue;
24498- atomic_t irq_received;
24499- atomic_t irq_emitted;
24500+ atomic_unchecked_t irq_received;
24501+ atomic_unchecked_t irq_emitted;
24502
24503 int front_offset;
24504 } drm_i810_private_t;
24505diff -urNp linux-3.0.4/drivers/gpu/drm/i915/i915_debugfs.c linux-3.0.4/drivers/gpu/drm/i915/i915_debugfs.c
24506--- linux-3.0.4/drivers/gpu/drm/i915/i915_debugfs.c 2011-07-21 22:17:23.000000000 -0400
24507+++ linux-3.0.4/drivers/gpu/drm/i915/i915_debugfs.c 2011-08-23 21:47:55.000000000 -0400
24508@@ -497,7 +497,7 @@ static int i915_interrupt_info(struct se
24509 I915_READ(GTIMR));
24510 }
24511 seq_printf(m, "Interrupts received: %d\n",
24512- atomic_read(&dev_priv->irq_received));
24513+ atomic_read_unchecked(&dev_priv->irq_received));
24514 for (i = 0; i < I915_NUM_RINGS; i++) {
24515 if (IS_GEN6(dev)) {
24516 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
24517diff -urNp linux-3.0.4/drivers/gpu/drm/i915/i915_dma.c linux-3.0.4/drivers/gpu/drm/i915/i915_dma.c
24518--- linux-3.0.4/drivers/gpu/drm/i915/i915_dma.c 2011-08-23 21:44:40.000000000 -0400
24519+++ linux-3.0.4/drivers/gpu/drm/i915/i915_dma.c 2011-08-23 21:47:55.000000000 -0400
24520@@ -1169,7 +1169,7 @@ static bool i915_switcheroo_can_switch(s
24521 bool can_switch;
24522
24523 spin_lock(&dev->count_lock);
24524- can_switch = (dev->open_count == 0);
24525+ can_switch = (local_read(&dev->open_count) == 0);
24526 spin_unlock(&dev->count_lock);
24527 return can_switch;
24528 }
24529diff -urNp linux-3.0.4/drivers/gpu/drm/i915/i915_drv.h linux-3.0.4/drivers/gpu/drm/i915/i915_drv.h
24530--- linux-3.0.4/drivers/gpu/drm/i915/i915_drv.h 2011-07-21 22:17:23.000000000 -0400
24531+++ linux-3.0.4/drivers/gpu/drm/i915/i915_drv.h 2011-08-23 21:47:55.000000000 -0400
24532@@ -219,7 +219,7 @@ struct drm_i915_display_funcs {
24533 /* render clock increase/decrease */
24534 /* display clock increase/decrease */
24535 /* pll clock increase/decrease */
24536-};
24537+} __no_const;
24538
24539 struct intel_device_info {
24540 u8 gen;
24541@@ -300,7 +300,7 @@ typedef struct drm_i915_private {
24542 int current_page;
24543 int page_flipping;
24544
24545- atomic_t irq_received;
24546+ atomic_unchecked_t irq_received;
24547
24548 /* protects the irq masks */
24549 spinlock_t irq_lock;
24550@@ -874,7 +874,7 @@ struct drm_i915_gem_object {
24551 * will be page flipped away on the next vblank. When it
24552 * reaches 0, dev_priv->pending_flip_queue will be woken up.
24553 */
24554- atomic_t pending_flip;
24555+ atomic_unchecked_t pending_flip;
24556 };
24557
24558 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
24559@@ -1247,7 +1247,7 @@ extern int intel_setup_gmbus(struct drm_
24560 extern void intel_teardown_gmbus(struct drm_device *dev);
24561 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
24562 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
24563-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
24564+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
24565 {
24566 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
24567 }
24568diff -urNp linux-3.0.4/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-3.0.4/drivers/gpu/drm/i915/i915_gem_execbuffer.c
24569--- linux-3.0.4/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-07-21 22:17:23.000000000 -0400
24570+++ linux-3.0.4/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-08-23 21:47:55.000000000 -0400
24571@@ -188,7 +188,7 @@ i915_gem_object_set_to_gpu_domain(struct
24572 i915_gem_clflush_object(obj);
24573
24574 if (obj->base.pending_write_domain)
24575- cd->flips |= atomic_read(&obj->pending_flip);
24576+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
24577
24578 /* The actual obj->write_domain will be updated with
24579 * pending_write_domain after we emit the accumulated flush for all
24580diff -urNp linux-3.0.4/drivers/gpu/drm/i915/i915_irq.c linux-3.0.4/drivers/gpu/drm/i915/i915_irq.c
24581--- linux-3.0.4/drivers/gpu/drm/i915/i915_irq.c 2011-08-23 21:44:40.000000000 -0400
24582+++ linux-3.0.4/drivers/gpu/drm/i915/i915_irq.c 2011-08-23 21:47:55.000000000 -0400
24583@@ -473,7 +473,7 @@ static irqreturn_t ivybridge_irq_handler
24584 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
24585 struct drm_i915_master_private *master_priv;
24586
24587- atomic_inc(&dev_priv->irq_received);
24588+ atomic_inc_unchecked(&dev_priv->irq_received);
24589
24590 /* disable master interrupt before clearing iir */
24591 de_ier = I915_READ(DEIER);
24592@@ -563,7 +563,7 @@ static irqreturn_t ironlake_irq_handler(
24593 struct drm_i915_master_private *master_priv;
24594 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
24595
24596- atomic_inc(&dev_priv->irq_received);
24597+ atomic_inc_unchecked(&dev_priv->irq_received);
24598
24599 if (IS_GEN6(dev))
24600 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
24601@@ -1226,7 +1226,7 @@ static irqreturn_t i915_driver_irq_handl
24602 int ret = IRQ_NONE, pipe;
24603 bool blc_event = false;
24604
24605- atomic_inc(&dev_priv->irq_received);
24606+ atomic_inc_unchecked(&dev_priv->irq_received);
24607
24608 iir = I915_READ(IIR);
24609
24610@@ -1735,7 +1735,7 @@ static void ironlake_irq_preinstall(stru
24611 {
24612 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
24613
24614- atomic_set(&dev_priv->irq_received, 0);
24615+ atomic_set_unchecked(&dev_priv->irq_received, 0);
24616
24617 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
24618 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
24619@@ -1899,7 +1899,7 @@ static void i915_driver_irq_preinstall(s
24620 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
24621 int pipe;
24622
24623- atomic_set(&dev_priv->irq_received, 0);
24624+ atomic_set_unchecked(&dev_priv->irq_received, 0);
24625
24626 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
24627 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
24628diff -urNp linux-3.0.4/drivers/gpu/drm/i915/intel_display.c linux-3.0.4/drivers/gpu/drm/i915/intel_display.c
24629--- linux-3.0.4/drivers/gpu/drm/i915/intel_display.c 2011-08-23 21:44:40.000000000 -0400
24630+++ linux-3.0.4/drivers/gpu/drm/i915/intel_display.c 2011-08-23 21:47:55.000000000 -0400
24631@@ -1961,7 +1961,7 @@ intel_pipe_set_base(struct drm_crtc *crt
24632
24633 wait_event(dev_priv->pending_flip_queue,
24634 atomic_read(&dev_priv->mm.wedged) ||
24635- atomic_read(&obj->pending_flip) == 0);
24636+ atomic_read_unchecked(&obj->pending_flip) == 0);
24637
24638 /* Big Hammer, we also need to ensure that any pending
24639 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
24640@@ -2548,7 +2548,7 @@ static void intel_crtc_wait_for_pending_
24641 obj = to_intel_framebuffer(crtc->fb)->obj;
24642 dev_priv = crtc->dev->dev_private;
24643 wait_event(dev_priv->pending_flip_queue,
24644- atomic_read(&obj->pending_flip) == 0);
24645+ atomic_read_unchecked(&obj->pending_flip) == 0);
24646 }
24647
24648 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
24649@@ -6225,7 +6225,7 @@ static void do_intel_finish_page_flip(st
24650
24651 atomic_clear_mask(1 << intel_crtc->plane,
24652 &obj->pending_flip.counter);
24653- if (atomic_read(&obj->pending_flip) == 0)
24654+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
24655 wake_up(&dev_priv->pending_flip_queue);
24656
24657 schedule_work(&work->work);
24658@@ -6514,7 +6514,7 @@ static int intel_crtc_page_flip(struct d
24659 /* Block clients from rendering to the new back buffer until
24660 * the flip occurs and the object is no longer visible.
24661 */
24662- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
24663+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
24664
24665 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
24666 if (ret)
24667@@ -6527,7 +6527,7 @@ static int intel_crtc_page_flip(struct d
24668 return 0;
24669
24670 cleanup_pending:
24671- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
24672+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
24673 cleanup_objs:
24674 drm_gem_object_unreference(&work->old_fb_obj->base);
24675 drm_gem_object_unreference(&obj->base);
24676diff -urNp linux-3.0.4/drivers/gpu/drm/mga/mga_drv.h linux-3.0.4/drivers/gpu/drm/mga/mga_drv.h
24677--- linux-3.0.4/drivers/gpu/drm/mga/mga_drv.h 2011-07-21 22:17:23.000000000 -0400
24678+++ linux-3.0.4/drivers/gpu/drm/mga/mga_drv.h 2011-08-23 21:47:55.000000000 -0400
24679@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
24680 u32 clear_cmd;
24681 u32 maccess;
24682
24683- atomic_t vbl_received; /**< Number of vblanks received. */
24684+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
24685 wait_queue_head_t fence_queue;
24686- atomic_t last_fence_retired;
24687+ atomic_unchecked_t last_fence_retired;
24688 u32 next_fence_to_post;
24689
24690 unsigned int fb_cpp;
24691diff -urNp linux-3.0.4/drivers/gpu/drm/mga/mga_irq.c linux-3.0.4/drivers/gpu/drm/mga/mga_irq.c
24692--- linux-3.0.4/drivers/gpu/drm/mga/mga_irq.c 2011-07-21 22:17:23.000000000 -0400
24693+++ linux-3.0.4/drivers/gpu/drm/mga/mga_irq.c 2011-08-23 21:47:55.000000000 -0400
24694@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
24695 if (crtc != 0)
24696 return 0;
24697
24698- return atomic_read(&dev_priv->vbl_received);
24699+ return atomic_read_unchecked(&dev_priv->vbl_received);
24700 }
24701
24702
24703@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
24704 /* VBLANK interrupt */
24705 if (status & MGA_VLINEPEN) {
24706 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
24707- atomic_inc(&dev_priv->vbl_received);
24708+ atomic_inc_unchecked(&dev_priv->vbl_received);
24709 drm_handle_vblank(dev, 0);
24710 handled = 1;
24711 }
24712@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
24713 if ((prim_start & ~0x03) != (prim_end & ~0x03))
24714 MGA_WRITE(MGA_PRIMEND, prim_end);
24715
24716- atomic_inc(&dev_priv->last_fence_retired);
24717+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
24718 DRM_WAKEUP(&dev_priv->fence_queue);
24719 handled = 1;
24720 }
24721@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_dev
24722 * using fences.
24723 */
24724 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
24725- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
24726+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
24727 - *sequence) <= (1 << 23)));
24728
24729 *sequence = cur_fence;
24730diff -urNp linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_bios.c linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_bios.c
24731--- linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_bios.c 2011-07-21 22:17:23.000000000 -0400
24732+++ linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_bios.c 2011-08-26 19:49:56.000000000 -0400
24733@@ -200,7 +200,7 @@ struct methods {
24734 const char desc[8];
24735 void (*loadbios)(struct drm_device *, uint8_t *);
24736 const bool rw;
24737-};
24738+} __do_const;
24739
24740 static struct methods shadow_methods[] = {
24741 { "PRAMIN", load_vbios_pramin, true },
24742@@ -5488,7 +5488,7 @@ parse_bit_displayport_tbl_entry(struct d
24743 struct bit_table {
24744 const char id;
24745 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
24746-};
24747+} __no_const;
24748
24749 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
24750
24751diff -urNp linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_drv.h linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_drv.h
24752--- linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-07-21 22:17:23.000000000 -0400
24753+++ linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-08-23 21:47:55.000000000 -0400
24754@@ -227,7 +227,7 @@ struct nouveau_channel {
24755 struct list_head pending;
24756 uint32_t sequence;
24757 uint32_t sequence_ack;
24758- atomic_t last_sequence_irq;
24759+ atomic_unchecked_t last_sequence_irq;
24760 } fence;
24761
24762 /* DMA push buffer */
24763@@ -304,7 +304,7 @@ struct nouveau_exec_engine {
24764 u32 handle, u16 class);
24765 void (*set_tile_region)(struct drm_device *dev, int i);
24766 void (*tlb_flush)(struct drm_device *, int engine);
24767-};
24768+} __no_const;
24769
24770 struct nouveau_instmem_engine {
24771 void *priv;
24772@@ -325,13 +325,13 @@ struct nouveau_instmem_engine {
24773 struct nouveau_mc_engine {
24774 int (*init)(struct drm_device *dev);
24775 void (*takedown)(struct drm_device *dev);
24776-};
24777+} __no_const;
24778
24779 struct nouveau_timer_engine {
24780 int (*init)(struct drm_device *dev);
24781 void (*takedown)(struct drm_device *dev);
24782 uint64_t (*read)(struct drm_device *dev);
24783-};
24784+} __no_const;
24785
24786 struct nouveau_fb_engine {
24787 int num_tiles;
24788@@ -494,7 +494,7 @@ struct nouveau_vram_engine {
24789 void (*put)(struct drm_device *, struct nouveau_mem **);
24790
24791 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
24792-};
24793+} __no_const;
24794
24795 struct nouveau_engine {
24796 struct nouveau_instmem_engine instmem;
24797@@ -640,7 +640,7 @@ struct drm_nouveau_private {
24798 struct drm_global_reference mem_global_ref;
24799 struct ttm_bo_global_ref bo_global_ref;
24800 struct ttm_bo_device bdev;
24801- atomic_t validate_sequence;
24802+ atomic_unchecked_t validate_sequence;
24803 } ttm;
24804
24805 struct {
24806diff -urNp linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_fence.c linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_fence.c
24807--- linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-07-21 22:17:23.000000000 -0400
24808+++ linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-08-23 21:47:55.000000000 -0400
24809@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_chan
24810 if (USE_REFCNT(dev))
24811 sequence = nvchan_rd32(chan, 0x48);
24812 else
24813- sequence = atomic_read(&chan->fence.last_sequence_irq);
24814+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
24815
24816 if (chan->fence.sequence_ack == sequence)
24817 goto out;
24818@@ -544,7 +544,7 @@ nouveau_fence_channel_init(struct nouvea
24819
24820 INIT_LIST_HEAD(&chan->fence.pending);
24821 spin_lock_init(&chan->fence.lock);
24822- atomic_set(&chan->fence.last_sequence_irq, 0);
24823+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
24824 return 0;
24825 }
24826
24827diff -urNp linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_gem.c linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_gem.c
24828--- linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-07-21 22:17:23.000000000 -0400
24829+++ linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-08-23 21:47:55.000000000 -0400
24830@@ -249,7 +249,7 @@ validate_init(struct nouveau_channel *ch
24831 int trycnt = 0;
24832 int ret, i;
24833
24834- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
24835+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
24836 retry:
24837 if (++trycnt > 100000) {
24838 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
24839diff -urNp linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_state.c linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_state.c
24840--- linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_state.c 2011-07-21 22:17:23.000000000 -0400
24841+++ linux-3.0.4/drivers/gpu/drm/nouveau/nouveau_state.c 2011-08-23 21:47:55.000000000 -0400
24842@@ -488,7 +488,7 @@ static bool nouveau_switcheroo_can_switc
24843 bool can_switch;
24844
24845 spin_lock(&dev->count_lock);
24846- can_switch = (dev->open_count == 0);
24847+ can_switch = (local_read(&dev->open_count) == 0);
24848 spin_unlock(&dev->count_lock);
24849 return can_switch;
24850 }
24851diff -urNp linux-3.0.4/drivers/gpu/drm/nouveau/nv04_graph.c linux-3.0.4/drivers/gpu/drm/nouveau/nv04_graph.c
24852--- linux-3.0.4/drivers/gpu/drm/nouveau/nv04_graph.c 2011-07-21 22:17:23.000000000 -0400
24853+++ linux-3.0.4/drivers/gpu/drm/nouveau/nv04_graph.c 2011-08-23 21:47:55.000000000 -0400
24854@@ -560,7 +560,7 @@ static int
24855 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
24856 u32 class, u32 mthd, u32 data)
24857 {
24858- atomic_set(&chan->fence.last_sequence_irq, data);
24859+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
24860 return 0;
24861 }
24862
24863diff -urNp linux-3.0.4/drivers/gpu/drm/r128/r128_cce.c linux-3.0.4/drivers/gpu/drm/r128/r128_cce.c
24864--- linux-3.0.4/drivers/gpu/drm/r128/r128_cce.c 2011-07-21 22:17:23.000000000 -0400
24865+++ linux-3.0.4/drivers/gpu/drm/r128/r128_cce.c 2011-08-23 21:47:55.000000000 -0400
24866@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
24867
24868 /* GH: Simple idle check.
24869 */
24870- atomic_set(&dev_priv->idle_count, 0);
24871+ atomic_set_unchecked(&dev_priv->idle_count, 0);
24872
24873 /* We don't support anything other than bus-mastering ring mode,
24874 * but the ring can be in either AGP or PCI space for the ring
24875diff -urNp linux-3.0.4/drivers/gpu/drm/r128/r128_drv.h linux-3.0.4/drivers/gpu/drm/r128/r128_drv.h
24876--- linux-3.0.4/drivers/gpu/drm/r128/r128_drv.h 2011-07-21 22:17:23.000000000 -0400
24877+++ linux-3.0.4/drivers/gpu/drm/r128/r128_drv.h 2011-08-23 21:47:55.000000000 -0400
24878@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
24879 int is_pci;
24880 unsigned long cce_buffers_offset;
24881
24882- atomic_t idle_count;
24883+ atomic_unchecked_t idle_count;
24884
24885 int page_flipping;
24886 int current_page;
24887 u32 crtc_offset;
24888 u32 crtc_offset_cntl;
24889
24890- atomic_t vbl_received;
24891+ atomic_unchecked_t vbl_received;
24892
24893 u32 color_fmt;
24894 unsigned int front_offset;
24895diff -urNp linux-3.0.4/drivers/gpu/drm/r128/r128_irq.c linux-3.0.4/drivers/gpu/drm/r128/r128_irq.c
24896--- linux-3.0.4/drivers/gpu/drm/r128/r128_irq.c 2011-07-21 22:17:23.000000000 -0400
24897+++ linux-3.0.4/drivers/gpu/drm/r128/r128_irq.c 2011-08-23 21:47:55.000000000 -0400
24898@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
24899 if (crtc != 0)
24900 return 0;
24901
24902- return atomic_read(&dev_priv->vbl_received);
24903+ return atomic_read_unchecked(&dev_priv->vbl_received);
24904 }
24905
24906 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
24907@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
24908 /* VBLANK interrupt */
24909 if (status & R128_CRTC_VBLANK_INT) {
24910 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
24911- atomic_inc(&dev_priv->vbl_received);
24912+ atomic_inc_unchecked(&dev_priv->vbl_received);
24913 drm_handle_vblank(dev, 0);
24914 return IRQ_HANDLED;
24915 }
24916diff -urNp linux-3.0.4/drivers/gpu/drm/r128/r128_state.c linux-3.0.4/drivers/gpu/drm/r128/r128_state.c
24917--- linux-3.0.4/drivers/gpu/drm/r128/r128_state.c 2011-07-21 22:17:23.000000000 -0400
24918+++ linux-3.0.4/drivers/gpu/drm/r128/r128_state.c 2011-08-23 21:47:55.000000000 -0400
24919@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_priv
24920
24921 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
24922 {
24923- if (atomic_read(&dev_priv->idle_count) == 0)
24924+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
24925 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
24926 else
24927- atomic_set(&dev_priv->idle_count, 0);
24928+ atomic_set_unchecked(&dev_priv->idle_count, 0);
24929 }
24930
24931 #endif
24932diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/atom.c linux-3.0.4/drivers/gpu/drm/radeon/atom.c
24933--- linux-3.0.4/drivers/gpu/drm/radeon/atom.c 2011-07-21 22:17:23.000000000 -0400
24934+++ linux-3.0.4/drivers/gpu/drm/radeon/atom.c 2011-08-23 21:48:14.000000000 -0400
24935@@ -1245,6 +1245,8 @@ struct atom_context *atom_parse(struct c
24936 char name[512];
24937 int i;
24938
24939+ pax_track_stack();
24940+
24941 ctx->card = card;
24942 ctx->bios = bios;
24943
24944diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/mkregtable.c linux-3.0.4/drivers/gpu/drm/radeon/mkregtable.c
24945--- linux-3.0.4/drivers/gpu/drm/radeon/mkregtable.c 2011-07-21 22:17:23.000000000 -0400
24946+++ linux-3.0.4/drivers/gpu/drm/radeon/mkregtable.c 2011-08-23 21:47:55.000000000 -0400
24947@@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
24948 regex_t mask_rex;
24949 regmatch_t match[4];
24950 char buf[1024];
24951- size_t end;
24952+ long end;
24953 int len;
24954 int done = 0;
24955 int r;
24956 unsigned o;
24957 struct offset *offset;
24958 char last_reg_s[10];
24959- int last_reg;
24960+ unsigned long last_reg;
24961
24962 if (regcomp
24963 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
24964diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_atombios.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_atombios.c
24965--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_atombios.c 2011-07-21 22:17:23.000000000 -0400
24966+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_atombios.c 2011-08-23 21:48:14.000000000 -0400
24967@@ -545,6 +545,8 @@ bool radeon_get_atom_connector_info_from
24968 struct radeon_gpio_rec gpio;
24969 struct radeon_hpd hpd;
24970
24971+ pax_track_stack();
24972+
24973 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
24974 return false;
24975
24976diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_device.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_device.c
24977--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_device.c 2011-08-23 21:44:40.000000000 -0400
24978+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_device.c 2011-08-23 21:47:55.000000000 -0400
24979@@ -678,7 +678,7 @@ static bool radeon_switcheroo_can_switch
24980 bool can_switch;
24981
24982 spin_lock(&dev->count_lock);
24983- can_switch = (dev->open_count == 0);
24984+ can_switch = (local_read(&dev->open_count) == 0);
24985 spin_unlock(&dev->count_lock);
24986 return can_switch;
24987 }
24988diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_display.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_display.c
24989--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_display.c 2011-08-23 21:44:40.000000000 -0400
24990+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_display.c 2011-08-23 21:48:14.000000000 -0400
24991@@ -946,6 +946,8 @@ void radeon_compute_pll_legacy(struct ra
24992 uint32_t post_div;
24993 u32 pll_out_min, pll_out_max;
24994
24995+ pax_track_stack();
24996+
24997 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
24998 freq = freq * 1000;
24999
25000diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_drv.h linux-3.0.4/drivers/gpu/drm/radeon/radeon_drv.h
25001--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_drv.h 2011-07-21 22:17:23.000000000 -0400
25002+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_drv.h 2011-08-23 21:47:55.000000000 -0400
25003@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
25004
25005 /* SW interrupt */
25006 wait_queue_head_t swi_queue;
25007- atomic_t swi_emitted;
25008+ atomic_unchecked_t swi_emitted;
25009 int vblank_crtc;
25010 uint32_t irq_enable_reg;
25011 uint32_t r500_disp_irq_reg;
25012diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_fence.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_fence.c
25013--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_fence.c 2011-07-21 22:17:23.000000000 -0400
25014+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_fence.c 2011-08-23 21:47:55.000000000 -0400
25015@@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_devi
25016 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
25017 return 0;
25018 }
25019- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
25020+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
25021 if (!rdev->cp.ready)
25022 /* FIXME: cp is not running assume everythings is done right
25023 * away
25024@@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct rade
25025 return r;
25026 }
25027 radeon_fence_write(rdev, 0);
25028- atomic_set(&rdev->fence_drv.seq, 0);
25029+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
25030 INIT_LIST_HEAD(&rdev->fence_drv.created);
25031 INIT_LIST_HEAD(&rdev->fence_drv.emited);
25032 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
25033diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon.h linux-3.0.4/drivers/gpu/drm/radeon/radeon.h
25034--- linux-3.0.4/drivers/gpu/drm/radeon/radeon.h 2011-07-21 22:17:23.000000000 -0400
25035+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon.h 2011-08-23 21:47:55.000000000 -0400
25036@@ -191,7 +191,7 @@ extern int sumo_get_temp(struct radeon_d
25037 */
25038 struct radeon_fence_driver {
25039 uint32_t scratch_reg;
25040- atomic_t seq;
25041+ atomic_unchecked_t seq;
25042 uint32_t last_seq;
25043 unsigned long last_jiffies;
25044 unsigned long last_timeout;
25045@@ -960,7 +960,7 @@ struct radeon_asic {
25046 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
25047 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
25048 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
25049-};
25050+} __no_const;
25051
25052 /*
25053 * Asic structures
25054diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_ioc32.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_ioc32.c
25055--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-07-21 22:17:23.000000000 -0400
25056+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-08-23 21:47:55.000000000 -0400
25057@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(str
25058 request = compat_alloc_user_space(sizeof(*request));
25059 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
25060 || __put_user(req32.param, &request->param)
25061- || __put_user((void __user *)(unsigned long)req32.value,
25062+ || __put_user((unsigned long)req32.value,
25063 &request->value))
25064 return -EFAULT;
25065
25066diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_irq.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_irq.c
25067--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_irq.c 2011-07-21 22:17:23.000000000 -0400
25068+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_irq.c 2011-08-23 21:47:55.000000000 -0400
25069@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
25070 unsigned int ret;
25071 RING_LOCALS;
25072
25073- atomic_inc(&dev_priv->swi_emitted);
25074- ret = atomic_read(&dev_priv->swi_emitted);
25075+ atomic_inc_unchecked(&dev_priv->swi_emitted);
25076+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
25077
25078 BEGIN_RING(4);
25079 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
25080@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
25081 drm_radeon_private_t *dev_priv =
25082 (drm_radeon_private_t *) dev->dev_private;
25083
25084- atomic_set(&dev_priv->swi_emitted, 0);
25085+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
25086 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
25087
25088 dev->max_vblank_count = 0x001fffff;
25089diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_state.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_state.c
25090--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_state.c 2011-07-21 22:17:23.000000000 -0400
25091+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_state.c 2011-08-23 21:47:55.000000000 -0400
25092@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
25093 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
25094 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
25095
25096- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
25097+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
25098 sarea_priv->nbox * sizeof(depth_boxes[0])))
25099 return -EFAULT;
25100
25101@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
25102 {
25103 drm_radeon_private_t *dev_priv = dev->dev_private;
25104 drm_radeon_getparam_t *param = data;
25105- int value;
25106+ int value = 0;
25107
25108 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
25109
25110diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/radeon_ttm.c linux-3.0.4/drivers/gpu/drm/radeon/radeon_ttm.c
25111--- linux-3.0.4/drivers/gpu/drm/radeon/radeon_ttm.c 2011-07-21 22:17:23.000000000 -0400
25112+++ linux-3.0.4/drivers/gpu/drm/radeon/radeon_ttm.c 2011-08-23 21:47:55.000000000 -0400
25113@@ -644,8 +644,10 @@ int radeon_mmap(struct file *filp, struc
25114 }
25115 if (unlikely(ttm_vm_ops == NULL)) {
25116 ttm_vm_ops = vma->vm_ops;
25117- radeon_ttm_vm_ops = *ttm_vm_ops;
25118- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
25119+ pax_open_kernel();
25120+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
25121+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
25122+ pax_close_kernel();
25123 }
25124 vma->vm_ops = &radeon_ttm_vm_ops;
25125 return 0;
25126diff -urNp linux-3.0.4/drivers/gpu/drm/radeon/rs690.c linux-3.0.4/drivers/gpu/drm/radeon/rs690.c
25127--- linux-3.0.4/drivers/gpu/drm/radeon/rs690.c 2011-07-21 22:17:23.000000000 -0400
25128+++ linux-3.0.4/drivers/gpu/drm/radeon/rs690.c 2011-08-23 21:47:55.000000000 -0400
25129@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct
25130 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
25131 rdev->pm.sideport_bandwidth.full)
25132 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
25133- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
25134+ read_delay_latency.full = dfixed_const(800 * 1000);
25135 read_delay_latency.full = dfixed_div(read_delay_latency,
25136 rdev->pm.igp_sideport_mclk);
25137+ a.full = dfixed_const(370);
25138+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
25139 } else {
25140 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
25141 rdev->pm.k8_bandwidth.full)
25142diff -urNp linux-3.0.4/drivers/gpu/drm/ttm/ttm_page_alloc.c linux-3.0.4/drivers/gpu/drm/ttm/ttm_page_alloc.c
25143--- linux-3.0.4/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-07-21 22:17:23.000000000 -0400
25144+++ linux-3.0.4/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-08-23 21:47:55.000000000 -0400
25145@@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages
25146 static int ttm_pool_mm_shrink(struct shrinker *shrink,
25147 struct shrink_control *sc)
25148 {
25149- static atomic_t start_pool = ATOMIC_INIT(0);
25150+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
25151 unsigned i;
25152- unsigned pool_offset = atomic_add_return(1, &start_pool);
25153+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
25154 struct ttm_page_pool *pool;
25155 int shrink_pages = sc->nr_to_scan;
25156
25157diff -urNp linux-3.0.4/drivers/gpu/drm/via/via_drv.h linux-3.0.4/drivers/gpu/drm/via/via_drv.h
25158--- linux-3.0.4/drivers/gpu/drm/via/via_drv.h 2011-07-21 22:17:23.000000000 -0400
25159+++ linux-3.0.4/drivers/gpu/drm/via/via_drv.h 2011-08-23 21:47:55.000000000 -0400
25160@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
25161 typedef uint32_t maskarray_t[5];
25162
25163 typedef struct drm_via_irq {
25164- atomic_t irq_received;
25165+ atomic_unchecked_t irq_received;
25166 uint32_t pending_mask;
25167 uint32_t enable_mask;
25168 wait_queue_head_t irq_queue;
25169@@ -75,7 +75,7 @@ typedef struct drm_via_private {
25170 struct timeval last_vblank;
25171 int last_vblank_valid;
25172 unsigned usec_per_vblank;
25173- atomic_t vbl_received;
25174+ atomic_unchecked_t vbl_received;
25175 drm_via_state_t hc_state;
25176 char pci_buf[VIA_PCI_BUF_SIZE];
25177 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
25178diff -urNp linux-3.0.4/drivers/gpu/drm/via/via_irq.c linux-3.0.4/drivers/gpu/drm/via/via_irq.c
25179--- linux-3.0.4/drivers/gpu/drm/via/via_irq.c 2011-07-21 22:17:23.000000000 -0400
25180+++ linux-3.0.4/drivers/gpu/drm/via/via_irq.c 2011-08-23 21:47:55.000000000 -0400
25181@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
25182 if (crtc != 0)
25183 return 0;
25184
25185- return atomic_read(&dev_priv->vbl_received);
25186+ return atomic_read_unchecked(&dev_priv->vbl_received);
25187 }
25188
25189 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
25190@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
25191
25192 status = VIA_READ(VIA_REG_INTERRUPT);
25193 if (status & VIA_IRQ_VBLANK_PENDING) {
25194- atomic_inc(&dev_priv->vbl_received);
25195- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
25196+ atomic_inc_unchecked(&dev_priv->vbl_received);
25197+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
25198 do_gettimeofday(&cur_vblank);
25199 if (dev_priv->last_vblank_valid) {
25200 dev_priv->usec_per_vblank =
25201@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
25202 dev_priv->last_vblank = cur_vblank;
25203 dev_priv->last_vblank_valid = 1;
25204 }
25205- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
25206+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
25207 DRM_DEBUG("US per vblank is: %u\n",
25208 dev_priv->usec_per_vblank);
25209 }
25210@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
25211
25212 for (i = 0; i < dev_priv->num_irqs; ++i) {
25213 if (status & cur_irq->pending_mask) {
25214- atomic_inc(&cur_irq->irq_received);
25215+ atomic_inc_unchecked(&cur_irq->irq_received);
25216 DRM_WAKEUP(&cur_irq->irq_queue);
25217 handled = 1;
25218 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
25219@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *d
25220 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
25221 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
25222 masks[irq][4]));
25223- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
25224+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
25225 } else {
25226 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
25227 (((cur_irq_sequence =
25228- atomic_read(&cur_irq->irq_received)) -
25229+ atomic_read_unchecked(&cur_irq->irq_received)) -
25230 *sequence) <= (1 << 23)));
25231 }
25232 *sequence = cur_irq_sequence;
25233@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct dr
25234 }
25235
25236 for (i = 0; i < dev_priv->num_irqs; ++i) {
25237- atomic_set(&cur_irq->irq_received, 0);
25238+ atomic_set_unchecked(&cur_irq->irq_received, 0);
25239 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
25240 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
25241 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
25242@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev,
25243 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
25244 case VIA_IRQ_RELATIVE:
25245 irqwait->request.sequence +=
25246- atomic_read(&cur_irq->irq_received);
25247+ atomic_read_unchecked(&cur_irq->irq_received);
25248 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
25249 case VIA_IRQ_ABSOLUTE:
25250 break;
25251diff -urNp linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
25252--- linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-07-21 22:17:23.000000000 -0400
25253+++ linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-08-23 21:47:55.000000000 -0400
25254@@ -240,7 +240,7 @@ struct vmw_private {
25255 * Fencing and IRQs.
25256 */
25257
25258- atomic_t fence_seq;
25259+ atomic_unchecked_t fence_seq;
25260 wait_queue_head_t fence_queue;
25261 wait_queue_head_t fifo_queue;
25262 atomic_t fence_queue_waiters;
25263diff -urNp linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
25264--- linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-07-21 22:17:23.000000000 -0400
25265+++ linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-08-23 21:47:55.000000000 -0400
25266@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev
25267 while (!vmw_lag_lt(queue, us)) {
25268 spin_lock(&queue->lock);
25269 if (list_empty(&queue->head))
25270- sequence = atomic_read(&dev_priv->fence_seq);
25271+ sequence = atomic_read_unchecked(&dev_priv->fence_seq);
25272 else {
25273 fence = list_first_entry(&queue->head,
25274 struct vmw_fence, head);
25275diff -urNp linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
25276--- linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-07-21 22:17:23.000000000 -0400
25277+++ linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-08-23 21:47:55.000000000 -0400
25278@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *de
25279 (unsigned int) min,
25280 (unsigned int) fifo->capabilities);
25281
25282- atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
25283+ atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
25284 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
25285 vmw_fence_queue_init(&fifo->fence_queue);
25286 return vmw_fifo_send_fence(dev_priv, &dummy);
25287@@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_priva
25288
25289 fm = vmw_fifo_reserve(dev_priv, bytes);
25290 if (unlikely(fm == NULL)) {
25291- *sequence = atomic_read(&dev_priv->fence_seq);
25292+ *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
25293 ret = -ENOMEM;
25294 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
25295 false, 3*HZ);
25296@@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_priva
25297 }
25298
25299 do {
25300- *sequence = atomic_add_return(1, &dev_priv->fence_seq);
25301+ *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
25302 } while (*sequence == 0);
25303
25304 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
25305diff -urNp linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
25306--- linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-07-21 22:17:23.000000000 -0400
25307+++ linux-3.0.4/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-08-23 21:47:55.000000000 -0400
25308@@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_priva
25309 * emitted. Then the fence is stale and signaled.
25310 */
25311
25312- ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
25313+ ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
25314 > VMW_FENCE_WRAP);
25315
25316 return ret;
25317@@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private
25318
25319 if (fifo_idle)
25320 down_read(&fifo_state->rwsem);
25321- signal_seq = atomic_read(&dev_priv->fence_seq);
25322+ signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
25323 ret = 0;
25324
25325 for (;;) {
25326diff -urNp linux-3.0.4/drivers/hid/hid-core.c linux-3.0.4/drivers/hid/hid-core.c
25327--- linux-3.0.4/drivers/hid/hid-core.c 2011-07-21 22:17:23.000000000 -0400
25328+++ linux-3.0.4/drivers/hid/hid-core.c 2011-08-23 21:47:55.000000000 -0400
25329@@ -1923,7 +1923,7 @@ static bool hid_ignore(struct hid_device
25330
25331 int hid_add_device(struct hid_device *hdev)
25332 {
25333- static atomic_t id = ATOMIC_INIT(0);
25334+ static atomic_unchecked_t id = ATOMIC_INIT(0);
25335 int ret;
25336
25337 if (WARN_ON(hdev->status & HID_STAT_ADDED))
25338@@ -1938,7 +1938,7 @@ int hid_add_device(struct hid_device *hd
25339 /* XXX hack, any other cleaner solution after the driver core
25340 * is converted to allow more than 20 bytes as the device name? */
25341 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
25342- hdev->vendor, hdev->product, atomic_inc_return(&id));
25343+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
25344
25345 hid_debug_register(hdev, dev_name(&hdev->dev));
25346 ret = device_add(&hdev->dev);
25347diff -urNp linux-3.0.4/drivers/hid/usbhid/hiddev.c linux-3.0.4/drivers/hid/usbhid/hiddev.c
25348--- linux-3.0.4/drivers/hid/usbhid/hiddev.c 2011-07-21 22:17:23.000000000 -0400
25349+++ linux-3.0.4/drivers/hid/usbhid/hiddev.c 2011-08-23 21:47:55.000000000 -0400
25350@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *fi
25351 break;
25352
25353 case HIDIOCAPPLICATION:
25354- if (arg < 0 || arg >= hid->maxapplication)
25355+ if (arg >= hid->maxapplication)
25356 break;
25357
25358 for (i = 0; i < hid->maxcollection; i++)
25359diff -urNp linux-3.0.4/drivers/hwmon/acpi_power_meter.c linux-3.0.4/drivers/hwmon/acpi_power_meter.c
25360--- linux-3.0.4/drivers/hwmon/acpi_power_meter.c 2011-07-21 22:17:23.000000000 -0400
25361+++ linux-3.0.4/drivers/hwmon/acpi_power_meter.c 2011-08-23 21:47:55.000000000 -0400
25362@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
25363 return res;
25364
25365 temp /= 1000;
25366- if (temp < 0)
25367- return -EINVAL;
25368
25369 mutex_lock(&resource->lock);
25370 resource->trip[attr->index - 7] = temp;
25371diff -urNp linux-3.0.4/drivers/hwmon/sht15.c linux-3.0.4/drivers/hwmon/sht15.c
25372--- linux-3.0.4/drivers/hwmon/sht15.c 2011-07-21 22:17:23.000000000 -0400
25373+++ linux-3.0.4/drivers/hwmon/sht15.c 2011-08-23 21:47:55.000000000 -0400
25374@@ -166,7 +166,7 @@ struct sht15_data {
25375 int supply_uV;
25376 bool supply_uV_valid;
25377 struct work_struct update_supply_work;
25378- atomic_t interrupt_handled;
25379+ atomic_unchecked_t interrupt_handled;
25380 };
25381
25382 /**
25383@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht1
25384 return ret;
25385
25386 gpio_direction_input(data->pdata->gpio_data);
25387- atomic_set(&data->interrupt_handled, 0);
25388+ atomic_set_unchecked(&data->interrupt_handled, 0);
25389
25390 enable_irq(gpio_to_irq(data->pdata->gpio_data));
25391 if (gpio_get_value(data->pdata->gpio_data) == 0) {
25392 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
25393 /* Only relevant if the interrupt hasn't occurred. */
25394- if (!atomic_read(&data->interrupt_handled))
25395+ if (!atomic_read_unchecked(&data->interrupt_handled))
25396 schedule_work(&data->read_work);
25397 }
25398 ret = wait_event_timeout(data->wait_queue,
25399@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired
25400
25401 /* First disable the interrupt */
25402 disable_irq_nosync(irq);
25403- atomic_inc(&data->interrupt_handled);
25404+ atomic_inc_unchecked(&data->interrupt_handled);
25405 /* Then schedule a reading work struct */
25406 if (data->state != SHT15_READING_NOTHING)
25407 schedule_work(&data->read_work);
25408@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct wo
25409 * If not, then start the interrupt again - care here as could
25410 * have gone low in meantime so verify it hasn't!
25411 */
25412- atomic_set(&data->interrupt_handled, 0);
25413+ atomic_set_unchecked(&data->interrupt_handled, 0);
25414 enable_irq(gpio_to_irq(data->pdata->gpio_data));
25415 /* If still not occurred or another handler has been scheduled */
25416 if (gpio_get_value(data->pdata->gpio_data)
25417- || atomic_read(&data->interrupt_handled))
25418+ || atomic_read_unchecked(&data->interrupt_handled))
25419 return;
25420 }
25421
25422diff -urNp linux-3.0.4/drivers/hwmon/w83791d.c linux-3.0.4/drivers/hwmon/w83791d.c
25423--- linux-3.0.4/drivers/hwmon/w83791d.c 2011-07-21 22:17:23.000000000 -0400
25424+++ linux-3.0.4/drivers/hwmon/w83791d.c 2011-08-23 21:47:55.000000000 -0400
25425@@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
25426 struct i2c_board_info *info);
25427 static int w83791d_remove(struct i2c_client *client);
25428
25429-static int w83791d_read(struct i2c_client *client, u8 register);
25430-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
25431+static int w83791d_read(struct i2c_client *client, u8 reg);
25432+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
25433 static struct w83791d_data *w83791d_update_device(struct device *dev);
25434
25435 #ifdef DEBUG
25436diff -urNp linux-3.0.4/drivers/i2c/busses/i2c-amd756-s4882.c linux-3.0.4/drivers/i2c/busses/i2c-amd756-s4882.c
25437--- linux-3.0.4/drivers/i2c/busses/i2c-amd756-s4882.c 2011-07-21 22:17:23.000000000 -0400
25438+++ linux-3.0.4/drivers/i2c/busses/i2c-amd756-s4882.c 2011-08-23 21:47:55.000000000 -0400
25439@@ -43,7 +43,7 @@
25440 extern struct i2c_adapter amd756_smbus;
25441
25442 static struct i2c_adapter *s4882_adapter;
25443-static struct i2c_algorithm *s4882_algo;
25444+static i2c_algorithm_no_const *s4882_algo;
25445
25446 /* Wrapper access functions for multiplexed SMBus */
25447 static DEFINE_MUTEX(amd756_lock);
25448diff -urNp linux-3.0.4/drivers/i2c/busses/i2c-nforce2-s4985.c linux-3.0.4/drivers/i2c/busses/i2c-nforce2-s4985.c
25449--- linux-3.0.4/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-07-21 22:17:23.000000000 -0400
25450+++ linux-3.0.4/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-08-23 21:47:55.000000000 -0400
25451@@ -41,7 +41,7 @@
25452 extern struct i2c_adapter *nforce2_smbus;
25453
25454 static struct i2c_adapter *s4985_adapter;
25455-static struct i2c_algorithm *s4985_algo;
25456+static i2c_algorithm_no_const *s4985_algo;
25457
25458 /* Wrapper access functions for multiplexed SMBus */
25459 static DEFINE_MUTEX(nforce2_lock);
25460diff -urNp linux-3.0.4/drivers/i2c/i2c-mux.c linux-3.0.4/drivers/i2c/i2c-mux.c
25461--- linux-3.0.4/drivers/i2c/i2c-mux.c 2011-07-21 22:17:23.000000000 -0400
25462+++ linux-3.0.4/drivers/i2c/i2c-mux.c 2011-08-23 21:47:55.000000000 -0400
25463@@ -28,7 +28,7 @@
25464 /* multiplexer per channel data */
25465 struct i2c_mux_priv {
25466 struct i2c_adapter adap;
25467- struct i2c_algorithm algo;
25468+ i2c_algorithm_no_const algo;
25469
25470 struct i2c_adapter *parent;
25471 void *mux_dev; /* the mux chip/device */
25472diff -urNp linux-3.0.4/drivers/ide/ide-cd.c linux-3.0.4/drivers/ide/ide-cd.c
25473--- linux-3.0.4/drivers/ide/ide-cd.c 2011-07-21 22:17:23.000000000 -0400
25474+++ linux-3.0.4/drivers/ide/ide-cd.c 2011-08-23 21:47:55.000000000 -0400
25475@@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_
25476 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
25477 if ((unsigned long)buf & alignment
25478 || blk_rq_bytes(rq) & q->dma_pad_mask
25479- || object_is_on_stack(buf))
25480+ || object_starts_on_stack(buf))
25481 drive->dma = 0;
25482 }
25483 }
25484diff -urNp linux-3.0.4/drivers/ide/ide-floppy.c linux-3.0.4/drivers/ide/ide-floppy.c
25485--- linux-3.0.4/drivers/ide/ide-floppy.c 2011-07-21 22:17:23.000000000 -0400
25486+++ linux-3.0.4/drivers/ide/ide-floppy.c 2011-08-23 21:48:14.000000000 -0400
25487@@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_d
25488 u8 pc_buf[256], header_len, desc_cnt;
25489 int i, rc = 1, blocks, length;
25490
25491+ pax_track_stack();
25492+
25493 ide_debug_log(IDE_DBG_FUNC, "enter");
25494
25495 drive->bios_cyl = 0;
25496diff -urNp linux-3.0.4/drivers/ide/setup-pci.c linux-3.0.4/drivers/ide/setup-pci.c
25497--- linux-3.0.4/drivers/ide/setup-pci.c 2011-07-21 22:17:23.000000000 -0400
25498+++ linux-3.0.4/drivers/ide/setup-pci.c 2011-08-23 21:48:14.000000000 -0400
25499@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
25500 int ret, i, n_ports = dev2 ? 4 : 2;
25501 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
25502
25503+ pax_track_stack();
25504+
25505 for (i = 0; i < n_ports / 2; i++) {
25506 ret = ide_setup_pci_controller(pdev[i], d, !i);
25507 if (ret < 0)
25508diff -urNp linux-3.0.4/drivers/infiniband/core/cm.c linux-3.0.4/drivers/infiniband/core/cm.c
25509--- linux-3.0.4/drivers/infiniband/core/cm.c 2011-07-21 22:17:23.000000000 -0400
25510+++ linux-3.0.4/drivers/infiniband/core/cm.c 2011-08-23 21:47:55.000000000 -0400
25511@@ -113,7 +113,7 @@ static char const counter_group_names[CM
25512
25513 struct cm_counter_group {
25514 struct kobject obj;
25515- atomic_long_t counter[CM_ATTR_COUNT];
25516+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
25517 };
25518
25519 struct cm_counter_attribute {
25520@@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
25521 struct ib_mad_send_buf *msg = NULL;
25522 int ret;
25523
25524- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25525+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25526 counter[CM_REQ_COUNTER]);
25527
25528 /* Quick state check to discard duplicate REQs. */
25529@@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
25530 if (!cm_id_priv)
25531 return;
25532
25533- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25534+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25535 counter[CM_REP_COUNTER]);
25536 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
25537 if (ret)
25538@@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
25539 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
25540 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
25541 spin_unlock_irq(&cm_id_priv->lock);
25542- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25543+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25544 counter[CM_RTU_COUNTER]);
25545 goto out;
25546 }
25547@@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_wor
25548 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
25549 dreq_msg->local_comm_id);
25550 if (!cm_id_priv) {
25551- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25552+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25553 counter[CM_DREQ_COUNTER]);
25554 cm_issue_drep(work->port, work->mad_recv_wc);
25555 return -EINVAL;
25556@@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_wor
25557 case IB_CM_MRA_REP_RCVD:
25558 break;
25559 case IB_CM_TIMEWAIT:
25560- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25561+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25562 counter[CM_DREQ_COUNTER]);
25563 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
25564 goto unlock;
25565@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_wor
25566 cm_free_msg(msg);
25567 goto deref;
25568 case IB_CM_DREQ_RCVD:
25569- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25570+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25571 counter[CM_DREQ_COUNTER]);
25572 goto unlock;
25573 default:
25574@@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work
25575 ib_modify_mad(cm_id_priv->av.port->mad_agent,
25576 cm_id_priv->msg, timeout)) {
25577 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
25578- atomic_long_inc(&work->port->
25579+ atomic_long_inc_unchecked(&work->port->
25580 counter_group[CM_RECV_DUPLICATES].
25581 counter[CM_MRA_COUNTER]);
25582 goto out;
25583@@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work
25584 break;
25585 case IB_CM_MRA_REQ_RCVD:
25586 case IB_CM_MRA_REP_RCVD:
25587- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25588+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25589 counter[CM_MRA_COUNTER]);
25590 /* fall through */
25591 default:
25592@@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work
25593 case IB_CM_LAP_IDLE:
25594 break;
25595 case IB_CM_MRA_LAP_SENT:
25596- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25597+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25598 counter[CM_LAP_COUNTER]);
25599 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
25600 goto unlock;
25601@@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work
25602 cm_free_msg(msg);
25603 goto deref;
25604 case IB_CM_LAP_RCVD:
25605- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25606+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25607 counter[CM_LAP_COUNTER]);
25608 goto unlock;
25609 default:
25610@@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm
25611 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
25612 if (cur_cm_id_priv) {
25613 spin_unlock_irq(&cm.lock);
25614- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25615+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25616 counter[CM_SIDR_REQ_COUNTER]);
25617 goto out; /* Duplicate message. */
25618 }
25619@@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_ma
25620 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
25621 msg->retries = 1;
25622
25623- atomic_long_add(1 + msg->retries,
25624+ atomic_long_add_unchecked(1 + msg->retries,
25625 &port->counter_group[CM_XMIT].counter[attr_index]);
25626 if (msg->retries)
25627- atomic_long_add(msg->retries,
25628+ atomic_long_add_unchecked(msg->retries,
25629 &port->counter_group[CM_XMIT_RETRIES].
25630 counter[attr_index]);
25631
25632@@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_ma
25633 }
25634
25635 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
25636- atomic_long_inc(&port->counter_group[CM_RECV].
25637+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
25638 counter[attr_id - CM_ATTR_ID_OFFSET]);
25639
25640 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
25641@@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct ko
25642 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
25643
25644 return sprintf(buf, "%ld\n",
25645- atomic_long_read(&group->counter[cm_attr->index]));
25646+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
25647 }
25648
25649 static const struct sysfs_ops cm_counter_ops = {
25650diff -urNp linux-3.0.4/drivers/infiniband/core/fmr_pool.c linux-3.0.4/drivers/infiniband/core/fmr_pool.c
25651--- linux-3.0.4/drivers/infiniband/core/fmr_pool.c 2011-07-21 22:17:23.000000000 -0400
25652+++ linux-3.0.4/drivers/infiniband/core/fmr_pool.c 2011-08-23 21:47:55.000000000 -0400
25653@@ -97,8 +97,8 @@ struct ib_fmr_pool {
25654
25655 struct task_struct *thread;
25656
25657- atomic_t req_ser;
25658- atomic_t flush_ser;
25659+ atomic_unchecked_t req_ser;
25660+ atomic_unchecked_t flush_ser;
25661
25662 wait_queue_head_t force_wait;
25663 };
25664@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
25665 struct ib_fmr_pool *pool = pool_ptr;
25666
25667 do {
25668- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
25669+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
25670 ib_fmr_batch_release(pool);
25671
25672- atomic_inc(&pool->flush_ser);
25673+ atomic_inc_unchecked(&pool->flush_ser);
25674 wake_up_interruptible(&pool->force_wait);
25675
25676 if (pool->flush_function)
25677@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
25678 }
25679
25680 set_current_state(TASK_INTERRUPTIBLE);
25681- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
25682+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
25683 !kthread_should_stop())
25684 schedule();
25685 __set_current_state(TASK_RUNNING);
25686@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
25687 pool->dirty_watermark = params->dirty_watermark;
25688 pool->dirty_len = 0;
25689 spin_lock_init(&pool->pool_lock);
25690- atomic_set(&pool->req_ser, 0);
25691- atomic_set(&pool->flush_ser, 0);
25692+ atomic_set_unchecked(&pool->req_ser, 0);
25693+ atomic_set_unchecked(&pool->flush_ser, 0);
25694 init_waitqueue_head(&pool->force_wait);
25695
25696 pool->thread = kthread_run(ib_fmr_cleanup_thread,
25697@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
25698 }
25699 spin_unlock_irq(&pool->pool_lock);
25700
25701- serial = atomic_inc_return(&pool->req_ser);
25702+ serial = atomic_inc_return_unchecked(&pool->req_ser);
25703 wake_up_process(pool->thread);
25704
25705 if (wait_event_interruptible(pool->force_wait,
25706- atomic_read(&pool->flush_ser) - serial >= 0))
25707+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
25708 return -EINTR;
25709
25710 return 0;
25711@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
25712 } else {
25713 list_add_tail(&fmr->list, &pool->dirty_list);
25714 if (++pool->dirty_len >= pool->dirty_watermark) {
25715- atomic_inc(&pool->req_ser);
25716+ atomic_inc_unchecked(&pool->req_ser);
25717 wake_up_process(pool->thread);
25718 }
25719 }
25720diff -urNp linux-3.0.4/drivers/infiniband/hw/cxgb4/mem.c linux-3.0.4/drivers/infiniband/hw/cxgb4/mem.c
25721--- linux-3.0.4/drivers/infiniband/hw/cxgb4/mem.c 2011-07-21 22:17:23.000000000 -0400
25722+++ linux-3.0.4/drivers/infiniband/hw/cxgb4/mem.c 2011-08-23 21:47:55.000000000 -0400
25723@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_r
25724 int err;
25725 struct fw_ri_tpte tpt;
25726 u32 stag_idx;
25727- static atomic_t key;
25728+ static atomic_unchecked_t key;
25729
25730 if (c4iw_fatal_error(rdev))
25731 return -EIO;
25732@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_r
25733 &rdev->resource.tpt_fifo_lock);
25734 if (!stag_idx)
25735 return -ENOMEM;
25736- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
25737+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
25738 }
25739 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
25740 __func__, stag_state, type, pdid, stag_idx);
25741diff -urNp linux-3.0.4/drivers/infiniband/hw/ipath/ipath_fs.c linux-3.0.4/drivers/infiniband/hw/ipath/ipath_fs.c
25742--- linux-3.0.4/drivers/infiniband/hw/ipath/ipath_fs.c 2011-07-21 22:17:23.000000000 -0400
25743+++ linux-3.0.4/drivers/infiniband/hw/ipath/ipath_fs.c 2011-08-23 21:48:14.000000000 -0400
25744@@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(stru
25745 struct infinipath_counters counters;
25746 struct ipath_devdata *dd;
25747
25748+ pax_track_stack();
25749+
25750 dd = file->f_path.dentry->d_inode->i_private;
25751 dd->ipath_f_read_counters(dd, &counters);
25752
25753diff -urNp linux-3.0.4/drivers/infiniband/hw/ipath/ipath_rc.c linux-3.0.4/drivers/infiniband/hw/ipath/ipath_rc.c
25754--- linux-3.0.4/drivers/infiniband/hw/ipath/ipath_rc.c 2011-07-21 22:17:23.000000000 -0400
25755+++ linux-3.0.4/drivers/infiniband/hw/ipath/ipath_rc.c 2011-08-23 21:47:55.000000000 -0400
25756@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *de
25757 struct ib_atomic_eth *ateth;
25758 struct ipath_ack_entry *e;
25759 u64 vaddr;
25760- atomic64_t *maddr;
25761+ atomic64_unchecked_t *maddr;
25762 u64 sdata;
25763 u32 rkey;
25764 u8 next;
25765@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *de
25766 IB_ACCESS_REMOTE_ATOMIC)))
25767 goto nack_acc_unlck;
25768 /* Perform atomic OP and save result. */
25769- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
25770+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
25771 sdata = be64_to_cpu(ateth->swap_data);
25772 e = &qp->s_ack_queue[qp->r_head_ack_queue];
25773 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
25774- (u64) atomic64_add_return(sdata, maddr) - sdata :
25775+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
25776 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
25777 be64_to_cpu(ateth->compare_data),
25778 sdata);
25779diff -urNp linux-3.0.4/drivers/infiniband/hw/ipath/ipath_ruc.c linux-3.0.4/drivers/infiniband/hw/ipath/ipath_ruc.c
25780--- linux-3.0.4/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-07-21 22:17:23.000000000 -0400
25781+++ linux-3.0.4/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-08-23 21:47:55.000000000 -0400
25782@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ip
25783 unsigned long flags;
25784 struct ib_wc wc;
25785 u64 sdata;
25786- atomic64_t *maddr;
25787+ atomic64_unchecked_t *maddr;
25788 enum ib_wc_status send_status;
25789
25790 /*
25791@@ -382,11 +382,11 @@ again:
25792 IB_ACCESS_REMOTE_ATOMIC)))
25793 goto acc_err;
25794 /* Perform atomic OP and save result. */
25795- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
25796+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
25797 sdata = wqe->wr.wr.atomic.compare_add;
25798 *(u64 *) sqp->s_sge.sge.vaddr =
25799 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
25800- (u64) atomic64_add_return(sdata, maddr) - sdata :
25801+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
25802 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
25803 sdata, wqe->wr.wr.atomic.swap);
25804 goto send_comp;
25805diff -urNp linux-3.0.4/drivers/infiniband/hw/nes/nes.c linux-3.0.4/drivers/infiniband/hw/nes/nes.c
25806--- linux-3.0.4/drivers/infiniband/hw/nes/nes.c 2011-07-21 22:17:23.000000000 -0400
25807+++ linux-3.0.4/drivers/infiniband/hw/nes/nes.c 2011-08-23 21:47:55.000000000 -0400
25808@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
25809 LIST_HEAD(nes_adapter_list);
25810 static LIST_HEAD(nes_dev_list);
25811
25812-atomic_t qps_destroyed;
25813+atomic_unchecked_t qps_destroyed;
25814
25815 static unsigned int ee_flsh_adapter;
25816 static unsigned int sysfs_nonidx_addr;
25817@@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(str
25818 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
25819 struct nes_adapter *nesadapter = nesdev->nesadapter;
25820
25821- atomic_inc(&qps_destroyed);
25822+ atomic_inc_unchecked(&qps_destroyed);
25823
25824 /* Free the control structures */
25825
25826diff -urNp linux-3.0.4/drivers/infiniband/hw/nes/nes_cm.c linux-3.0.4/drivers/infiniband/hw/nes/nes_cm.c
25827--- linux-3.0.4/drivers/infiniband/hw/nes/nes_cm.c 2011-07-21 22:17:23.000000000 -0400
25828+++ linux-3.0.4/drivers/infiniband/hw/nes/nes_cm.c 2011-08-23 21:47:55.000000000 -0400
25829@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
25830 u32 cm_packets_retrans;
25831 u32 cm_packets_created;
25832 u32 cm_packets_received;
25833-atomic_t cm_listens_created;
25834-atomic_t cm_listens_destroyed;
25835+atomic_unchecked_t cm_listens_created;
25836+atomic_unchecked_t cm_listens_destroyed;
25837 u32 cm_backlog_drops;
25838-atomic_t cm_loopbacks;
25839-atomic_t cm_nodes_created;
25840-atomic_t cm_nodes_destroyed;
25841-atomic_t cm_accel_dropped_pkts;
25842-atomic_t cm_resets_recvd;
25843+atomic_unchecked_t cm_loopbacks;
25844+atomic_unchecked_t cm_nodes_created;
25845+atomic_unchecked_t cm_nodes_destroyed;
25846+atomic_unchecked_t cm_accel_dropped_pkts;
25847+atomic_unchecked_t cm_resets_recvd;
25848
25849 static inline int mini_cm_accelerated(struct nes_cm_core *,
25850 struct nes_cm_node *);
25851@@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
25852
25853 static struct nes_cm_core *g_cm_core;
25854
25855-atomic_t cm_connects;
25856-atomic_t cm_accepts;
25857-atomic_t cm_disconnects;
25858-atomic_t cm_closes;
25859-atomic_t cm_connecteds;
25860-atomic_t cm_connect_reqs;
25861-atomic_t cm_rejects;
25862+atomic_unchecked_t cm_connects;
25863+atomic_unchecked_t cm_accepts;
25864+atomic_unchecked_t cm_disconnects;
25865+atomic_unchecked_t cm_closes;
25866+atomic_unchecked_t cm_connecteds;
25867+atomic_unchecked_t cm_connect_reqs;
25868+atomic_unchecked_t cm_rejects;
25869
25870
25871 /**
25872@@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(str
25873 kfree(listener);
25874 listener = NULL;
25875 ret = 0;
25876- atomic_inc(&cm_listens_destroyed);
25877+ atomic_inc_unchecked(&cm_listens_destroyed);
25878 } else {
25879 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
25880 }
25881@@ -1240,7 +1240,7 @@ static struct nes_cm_node *make_cm_node(
25882 cm_node->rem_mac);
25883
25884 add_hte_node(cm_core, cm_node);
25885- atomic_inc(&cm_nodes_created);
25886+ atomic_inc_unchecked(&cm_nodes_created);
25887
25888 return cm_node;
25889 }
25890@@ -1298,7 +1298,7 @@ static int rem_ref_cm_node(struct nes_cm
25891 }
25892
25893 atomic_dec(&cm_core->node_cnt);
25894- atomic_inc(&cm_nodes_destroyed);
25895+ atomic_inc_unchecked(&cm_nodes_destroyed);
25896 nesqp = cm_node->nesqp;
25897 if (nesqp) {
25898 nesqp->cm_node = NULL;
25899@@ -1365,7 +1365,7 @@ static int process_options(struct nes_cm
25900
25901 static void drop_packet(struct sk_buff *skb)
25902 {
25903- atomic_inc(&cm_accel_dropped_pkts);
25904+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
25905 dev_kfree_skb_any(skb);
25906 }
25907
25908@@ -1428,7 +1428,7 @@ static void handle_rst_pkt(struct nes_cm
25909 {
25910
25911 int reset = 0; /* whether to send reset in case of err.. */
25912- atomic_inc(&cm_resets_recvd);
25913+ atomic_inc_unchecked(&cm_resets_recvd);
25914 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
25915 " refcnt=%d\n", cm_node, cm_node->state,
25916 atomic_read(&cm_node->ref_count));
25917@@ -2057,7 +2057,7 @@ static struct nes_cm_node *mini_cm_conne
25918 rem_ref_cm_node(cm_node->cm_core, cm_node);
25919 return NULL;
25920 }
25921- atomic_inc(&cm_loopbacks);
25922+ atomic_inc_unchecked(&cm_loopbacks);
25923 loopbackremotenode->loopbackpartner = cm_node;
25924 loopbackremotenode->tcp_cntxt.rcv_wscale =
25925 NES_CM_DEFAULT_RCV_WND_SCALE;
25926@@ -2332,7 +2332,7 @@ static int mini_cm_recv_pkt(struct nes_c
25927 add_ref_cm_node(cm_node);
25928 } else if (cm_node->state == NES_CM_STATE_TSA) {
25929 rem_ref_cm_node(cm_core, cm_node);
25930- atomic_inc(&cm_accel_dropped_pkts);
25931+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
25932 dev_kfree_skb_any(skb);
25933 break;
25934 }
25935@@ -2638,7 +2638,7 @@ static int nes_cm_disconn_true(struct ne
25936
25937 if ((cm_id) && (cm_id->event_handler)) {
25938 if (issue_disconn) {
25939- atomic_inc(&cm_disconnects);
25940+ atomic_inc_unchecked(&cm_disconnects);
25941 cm_event.event = IW_CM_EVENT_DISCONNECT;
25942 cm_event.status = disconn_status;
25943 cm_event.local_addr = cm_id->local_addr;
25944@@ -2660,7 +2660,7 @@ static int nes_cm_disconn_true(struct ne
25945 }
25946
25947 if (issue_close) {
25948- atomic_inc(&cm_closes);
25949+ atomic_inc_unchecked(&cm_closes);
25950 nes_disconnect(nesqp, 1);
25951
25952 cm_id->provider_data = nesqp;
25953@@ -2791,7 +2791,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
25954
25955 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
25956 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
25957- atomic_inc(&cm_accepts);
25958+ atomic_inc_unchecked(&cm_accepts);
25959
25960 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
25961 netdev_refcnt_read(nesvnic->netdev));
25962@@ -3001,7 +3001,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
25963
25964 struct nes_cm_core *cm_core;
25965
25966- atomic_inc(&cm_rejects);
25967+ atomic_inc_unchecked(&cm_rejects);
25968 cm_node = (struct nes_cm_node *) cm_id->provider_data;
25969 loopback = cm_node->loopbackpartner;
25970 cm_core = cm_node->cm_core;
25971@@ -3067,7 +3067,7 @@ int nes_connect(struct iw_cm_id *cm_id,
25972 ntohl(cm_id->local_addr.sin_addr.s_addr),
25973 ntohs(cm_id->local_addr.sin_port));
25974
25975- atomic_inc(&cm_connects);
25976+ atomic_inc_unchecked(&cm_connects);
25977 nesqp->active_conn = 1;
25978
25979 /* cache the cm_id in the qp */
25980@@ -3173,7 +3173,7 @@ int nes_create_listen(struct iw_cm_id *c
25981 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
25982 return err;
25983 }
25984- atomic_inc(&cm_listens_created);
25985+ atomic_inc_unchecked(&cm_listens_created);
25986 }
25987
25988 cm_id->add_ref(cm_id);
25989@@ -3278,7 +3278,7 @@ static void cm_event_connected(struct ne
25990 if (nesqp->destroyed) {
25991 return;
25992 }
25993- atomic_inc(&cm_connecteds);
25994+ atomic_inc_unchecked(&cm_connecteds);
25995 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
25996 " local port 0x%04X. jiffies = %lu.\n",
25997 nesqp->hwqp.qp_id,
25998@@ -3493,7 +3493,7 @@ static void cm_event_reset(struct nes_cm
25999
26000 cm_id->add_ref(cm_id);
26001 ret = cm_id->event_handler(cm_id, &cm_event);
26002- atomic_inc(&cm_closes);
26003+ atomic_inc_unchecked(&cm_closes);
26004 cm_event.event = IW_CM_EVENT_CLOSE;
26005 cm_event.status = 0;
26006 cm_event.provider_data = cm_id->provider_data;
26007@@ -3529,7 +3529,7 @@ static void cm_event_mpa_req(struct nes_
26008 return;
26009 cm_id = cm_node->cm_id;
26010
26011- atomic_inc(&cm_connect_reqs);
26012+ atomic_inc_unchecked(&cm_connect_reqs);
26013 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
26014 cm_node, cm_id, jiffies);
26015
26016@@ -3567,7 +3567,7 @@ static void cm_event_mpa_reject(struct n
26017 return;
26018 cm_id = cm_node->cm_id;
26019
26020- atomic_inc(&cm_connect_reqs);
26021+ atomic_inc_unchecked(&cm_connect_reqs);
26022 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
26023 cm_node, cm_id, jiffies);
26024
26025diff -urNp linux-3.0.4/drivers/infiniband/hw/nes/nes.h linux-3.0.4/drivers/infiniband/hw/nes/nes.h
26026--- linux-3.0.4/drivers/infiniband/hw/nes/nes.h 2011-07-21 22:17:23.000000000 -0400
26027+++ linux-3.0.4/drivers/infiniband/hw/nes/nes.h 2011-08-23 21:47:55.000000000 -0400
26028@@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
26029 extern unsigned int wqm_quanta;
26030 extern struct list_head nes_adapter_list;
26031
26032-extern atomic_t cm_connects;
26033-extern atomic_t cm_accepts;
26034-extern atomic_t cm_disconnects;
26035-extern atomic_t cm_closes;
26036-extern atomic_t cm_connecteds;
26037-extern atomic_t cm_connect_reqs;
26038-extern atomic_t cm_rejects;
26039-extern atomic_t mod_qp_timouts;
26040-extern atomic_t qps_created;
26041-extern atomic_t qps_destroyed;
26042-extern atomic_t sw_qps_destroyed;
26043+extern atomic_unchecked_t cm_connects;
26044+extern atomic_unchecked_t cm_accepts;
26045+extern atomic_unchecked_t cm_disconnects;
26046+extern atomic_unchecked_t cm_closes;
26047+extern atomic_unchecked_t cm_connecteds;
26048+extern atomic_unchecked_t cm_connect_reqs;
26049+extern atomic_unchecked_t cm_rejects;
26050+extern atomic_unchecked_t mod_qp_timouts;
26051+extern atomic_unchecked_t qps_created;
26052+extern atomic_unchecked_t qps_destroyed;
26053+extern atomic_unchecked_t sw_qps_destroyed;
26054 extern u32 mh_detected;
26055 extern u32 mh_pauses_sent;
26056 extern u32 cm_packets_sent;
26057@@ -194,14 +194,14 @@ extern u32 cm_packets_created;
26058 extern u32 cm_packets_received;
26059 extern u32 cm_packets_dropped;
26060 extern u32 cm_packets_retrans;
26061-extern atomic_t cm_listens_created;
26062-extern atomic_t cm_listens_destroyed;
26063+extern atomic_unchecked_t cm_listens_created;
26064+extern atomic_unchecked_t cm_listens_destroyed;
26065 extern u32 cm_backlog_drops;
26066-extern atomic_t cm_loopbacks;
26067-extern atomic_t cm_nodes_created;
26068-extern atomic_t cm_nodes_destroyed;
26069-extern atomic_t cm_accel_dropped_pkts;
26070-extern atomic_t cm_resets_recvd;
26071+extern atomic_unchecked_t cm_loopbacks;
26072+extern atomic_unchecked_t cm_nodes_created;
26073+extern atomic_unchecked_t cm_nodes_destroyed;
26074+extern atomic_unchecked_t cm_accel_dropped_pkts;
26075+extern atomic_unchecked_t cm_resets_recvd;
26076
26077 extern u32 int_mod_timer_init;
26078 extern u32 int_mod_cq_depth_256;
26079diff -urNp linux-3.0.4/drivers/infiniband/hw/nes/nes_nic.c linux-3.0.4/drivers/infiniband/hw/nes/nes_nic.c
26080--- linux-3.0.4/drivers/infiniband/hw/nes/nes_nic.c 2011-07-21 22:17:23.000000000 -0400
26081+++ linux-3.0.4/drivers/infiniband/hw/nes/nes_nic.c 2011-08-23 21:47:55.000000000 -0400
26082@@ -1274,31 +1274,31 @@ static void nes_netdev_get_ethtool_stats
26083 target_stat_values[++index] = mh_detected;
26084 target_stat_values[++index] = mh_pauses_sent;
26085 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
26086- target_stat_values[++index] = atomic_read(&cm_connects);
26087- target_stat_values[++index] = atomic_read(&cm_accepts);
26088- target_stat_values[++index] = atomic_read(&cm_disconnects);
26089- target_stat_values[++index] = atomic_read(&cm_connecteds);
26090- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
26091- target_stat_values[++index] = atomic_read(&cm_rejects);
26092- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
26093- target_stat_values[++index] = atomic_read(&qps_created);
26094- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
26095- target_stat_values[++index] = atomic_read(&qps_destroyed);
26096- target_stat_values[++index] = atomic_read(&cm_closes);
26097+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
26098+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
26099+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
26100+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
26101+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
26102+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
26103+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
26104+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
26105+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
26106+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
26107+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
26108 target_stat_values[++index] = cm_packets_sent;
26109 target_stat_values[++index] = cm_packets_bounced;
26110 target_stat_values[++index] = cm_packets_created;
26111 target_stat_values[++index] = cm_packets_received;
26112 target_stat_values[++index] = cm_packets_dropped;
26113 target_stat_values[++index] = cm_packets_retrans;
26114- target_stat_values[++index] = atomic_read(&cm_listens_created);
26115- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
26116+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
26117+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
26118 target_stat_values[++index] = cm_backlog_drops;
26119- target_stat_values[++index] = atomic_read(&cm_loopbacks);
26120- target_stat_values[++index] = atomic_read(&cm_nodes_created);
26121- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
26122- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
26123- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
26124+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
26125+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
26126+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
26127+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
26128+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
26129 target_stat_values[++index] = nesadapter->free_4kpbl;
26130 target_stat_values[++index] = nesadapter->free_256pbl;
26131 target_stat_values[++index] = int_mod_timer_init;
26132diff -urNp linux-3.0.4/drivers/infiniband/hw/nes/nes_verbs.c linux-3.0.4/drivers/infiniband/hw/nes/nes_verbs.c
26133--- linux-3.0.4/drivers/infiniband/hw/nes/nes_verbs.c 2011-07-21 22:17:23.000000000 -0400
26134+++ linux-3.0.4/drivers/infiniband/hw/nes/nes_verbs.c 2011-08-23 21:47:55.000000000 -0400
26135@@ -46,9 +46,9 @@
26136
26137 #include <rdma/ib_umem.h>
26138
26139-atomic_t mod_qp_timouts;
26140-atomic_t qps_created;
26141-atomic_t sw_qps_destroyed;
26142+atomic_unchecked_t mod_qp_timouts;
26143+atomic_unchecked_t qps_created;
26144+atomic_unchecked_t sw_qps_destroyed;
26145
26146 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
26147
26148@@ -1141,7 +1141,7 @@ static struct ib_qp *nes_create_qp(struc
26149 if (init_attr->create_flags)
26150 return ERR_PTR(-EINVAL);
26151
26152- atomic_inc(&qps_created);
26153+ atomic_inc_unchecked(&qps_created);
26154 switch (init_attr->qp_type) {
26155 case IB_QPT_RC:
26156 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
26157@@ -1470,7 +1470,7 @@ static int nes_destroy_qp(struct ib_qp *
26158 struct iw_cm_event cm_event;
26159 int ret;
26160
26161- atomic_inc(&sw_qps_destroyed);
26162+ atomic_inc_unchecked(&sw_qps_destroyed);
26163 nesqp->destroyed = 1;
26164
26165 /* Blow away the connection if it exists. */
26166diff -urNp linux-3.0.4/drivers/infiniband/hw/qib/qib.h linux-3.0.4/drivers/infiniband/hw/qib/qib.h
26167--- linux-3.0.4/drivers/infiniband/hw/qib/qib.h 2011-07-21 22:17:23.000000000 -0400
26168+++ linux-3.0.4/drivers/infiniband/hw/qib/qib.h 2011-08-23 21:47:55.000000000 -0400
26169@@ -51,6 +51,7 @@
26170 #include <linux/completion.h>
26171 #include <linux/kref.h>
26172 #include <linux/sched.h>
26173+#include <linux/slab.h>
26174
26175 #include "qib_common.h"
26176 #include "qib_verbs.h"
26177diff -urNp linux-3.0.4/drivers/input/gameport/gameport.c linux-3.0.4/drivers/input/gameport/gameport.c
26178--- linux-3.0.4/drivers/input/gameport/gameport.c 2011-07-21 22:17:23.000000000 -0400
26179+++ linux-3.0.4/drivers/input/gameport/gameport.c 2011-08-23 21:47:55.000000000 -0400
26180@@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
26181 */
26182 static void gameport_init_port(struct gameport *gameport)
26183 {
26184- static atomic_t gameport_no = ATOMIC_INIT(0);
26185+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
26186
26187 __module_get(THIS_MODULE);
26188
26189 mutex_init(&gameport->drv_mutex);
26190 device_initialize(&gameport->dev);
26191 dev_set_name(&gameport->dev, "gameport%lu",
26192- (unsigned long)atomic_inc_return(&gameport_no) - 1);
26193+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
26194 gameport->dev.bus = &gameport_bus;
26195 gameport->dev.release = gameport_release_port;
26196 if (gameport->parent)
26197diff -urNp linux-3.0.4/drivers/input/input.c linux-3.0.4/drivers/input/input.c
26198--- linux-3.0.4/drivers/input/input.c 2011-07-21 22:17:23.000000000 -0400
26199+++ linux-3.0.4/drivers/input/input.c 2011-08-23 21:47:55.000000000 -0400
26200@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struc
26201 */
26202 int input_register_device(struct input_dev *dev)
26203 {
26204- static atomic_t input_no = ATOMIC_INIT(0);
26205+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
26206 struct input_handler *handler;
26207 const char *path;
26208 int error;
26209@@ -1851,7 +1851,7 @@ int input_register_device(struct input_d
26210 dev->setkeycode = input_default_setkeycode;
26211
26212 dev_set_name(&dev->dev, "input%ld",
26213- (unsigned long) atomic_inc_return(&input_no) - 1);
26214+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
26215
26216 error = device_add(&dev->dev);
26217 if (error)
26218diff -urNp linux-3.0.4/drivers/input/joystick/sidewinder.c linux-3.0.4/drivers/input/joystick/sidewinder.c
26219--- linux-3.0.4/drivers/input/joystick/sidewinder.c 2011-07-21 22:17:23.000000000 -0400
26220+++ linux-3.0.4/drivers/input/joystick/sidewinder.c 2011-08-23 21:48:14.000000000 -0400
26221@@ -30,6 +30,7 @@
26222 #include <linux/kernel.h>
26223 #include <linux/module.h>
26224 #include <linux/slab.h>
26225+#include <linux/sched.h>
26226 #include <linux/init.h>
26227 #include <linux/input.h>
26228 #include <linux/gameport.h>
26229@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
26230 unsigned char buf[SW_LENGTH];
26231 int i;
26232
26233+ pax_track_stack();
26234+
26235 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
26236
26237 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
26238diff -urNp linux-3.0.4/drivers/input/joystick/xpad.c linux-3.0.4/drivers/input/joystick/xpad.c
26239--- linux-3.0.4/drivers/input/joystick/xpad.c 2011-07-21 22:17:23.000000000 -0400
26240+++ linux-3.0.4/drivers/input/joystick/xpad.c 2011-08-23 21:47:55.000000000 -0400
26241@@ -689,7 +689,7 @@ static void xpad_led_set(struct led_clas
26242
26243 static int xpad_led_probe(struct usb_xpad *xpad)
26244 {
26245- static atomic_t led_seq = ATOMIC_INIT(0);
26246+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
26247 long led_no;
26248 struct xpad_led *led;
26249 struct led_classdev *led_cdev;
26250@@ -702,7 +702,7 @@ static int xpad_led_probe(struct usb_xpa
26251 if (!led)
26252 return -ENOMEM;
26253
26254- led_no = (long)atomic_inc_return(&led_seq) - 1;
26255+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
26256
26257 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
26258 led->xpad = xpad;
26259diff -urNp linux-3.0.4/drivers/input/mousedev.c linux-3.0.4/drivers/input/mousedev.c
26260--- linux-3.0.4/drivers/input/mousedev.c 2011-07-21 22:17:23.000000000 -0400
26261+++ linux-3.0.4/drivers/input/mousedev.c 2011-08-23 21:47:55.000000000 -0400
26262@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file
26263
26264 spin_unlock_irq(&client->packet_lock);
26265
26266- if (copy_to_user(buffer, data, count))
26267+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
26268 return -EFAULT;
26269
26270 return count;
26271diff -urNp linux-3.0.4/drivers/input/serio/serio.c linux-3.0.4/drivers/input/serio/serio.c
26272--- linux-3.0.4/drivers/input/serio/serio.c 2011-07-21 22:17:23.000000000 -0400
26273+++ linux-3.0.4/drivers/input/serio/serio.c 2011-08-23 21:47:55.000000000 -0400
26274@@ -497,7 +497,7 @@ static void serio_release_port(struct de
26275 */
26276 static void serio_init_port(struct serio *serio)
26277 {
26278- static atomic_t serio_no = ATOMIC_INIT(0);
26279+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
26280
26281 __module_get(THIS_MODULE);
26282
26283@@ -508,7 +508,7 @@ static void serio_init_port(struct serio
26284 mutex_init(&serio->drv_mutex);
26285 device_initialize(&serio->dev);
26286 dev_set_name(&serio->dev, "serio%ld",
26287- (long)atomic_inc_return(&serio_no) - 1);
26288+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
26289 serio->dev.bus = &serio_bus;
26290 serio->dev.release = serio_release_port;
26291 serio->dev.groups = serio_device_attr_groups;
26292diff -urNp linux-3.0.4/drivers/isdn/capi/capi.c linux-3.0.4/drivers/isdn/capi/capi.c
26293--- linux-3.0.4/drivers/isdn/capi/capi.c 2011-07-21 22:17:23.000000000 -0400
26294+++ linux-3.0.4/drivers/isdn/capi/capi.c 2011-08-23 21:47:55.000000000 -0400
26295@@ -83,8 +83,8 @@ struct capiminor {
26296
26297 struct capi20_appl *ap;
26298 u32 ncci;
26299- atomic_t datahandle;
26300- atomic_t msgid;
26301+ atomic_unchecked_t datahandle;
26302+ atomic_unchecked_t msgid;
26303
26304 struct tty_port port;
26305 int ttyinstop;
26306@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *m
26307 capimsg_setu16(s, 2, mp->ap->applid);
26308 capimsg_setu8 (s, 4, CAPI_DATA_B3);
26309 capimsg_setu8 (s, 5, CAPI_RESP);
26310- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
26311+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
26312 capimsg_setu32(s, 8, mp->ncci);
26313 capimsg_setu16(s, 12, datahandle);
26314 }
26315@@ -518,14 +518,14 @@ static void handle_minor_send(struct cap
26316 mp->outbytes -= len;
26317 spin_unlock_bh(&mp->outlock);
26318
26319- datahandle = atomic_inc_return(&mp->datahandle);
26320+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
26321 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
26322 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
26323 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
26324 capimsg_setu16(skb->data, 2, mp->ap->applid);
26325 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
26326 capimsg_setu8 (skb->data, 5, CAPI_REQ);
26327- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
26328+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
26329 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
26330 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
26331 capimsg_setu16(skb->data, 16, len); /* Data length */
26332diff -urNp linux-3.0.4/drivers/isdn/gigaset/common.c linux-3.0.4/drivers/isdn/gigaset/common.c
26333--- linux-3.0.4/drivers/isdn/gigaset/common.c 2011-07-21 22:17:23.000000000 -0400
26334+++ linux-3.0.4/drivers/isdn/gigaset/common.c 2011-08-23 21:47:55.000000000 -0400
26335@@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
26336 cs->commands_pending = 0;
26337 cs->cur_at_seq = 0;
26338 cs->gotfwver = -1;
26339- cs->open_count = 0;
26340+ local_set(&cs->open_count, 0);
26341 cs->dev = NULL;
26342 cs->tty = NULL;
26343 cs->tty_dev = NULL;
26344diff -urNp linux-3.0.4/drivers/isdn/gigaset/gigaset.h linux-3.0.4/drivers/isdn/gigaset/gigaset.h
26345--- linux-3.0.4/drivers/isdn/gigaset/gigaset.h 2011-07-21 22:17:23.000000000 -0400
26346+++ linux-3.0.4/drivers/isdn/gigaset/gigaset.h 2011-08-23 21:47:55.000000000 -0400
26347@@ -35,6 +35,7 @@
26348 #include <linux/tty_driver.h>
26349 #include <linux/list.h>
26350 #include <asm/atomic.h>
26351+#include <asm/local.h>
26352
26353 #define GIG_VERSION {0, 5, 0, 0}
26354 #define GIG_COMPAT {0, 4, 0, 0}
26355@@ -433,7 +434,7 @@ struct cardstate {
26356 spinlock_t cmdlock;
26357 unsigned curlen, cmdbytes;
26358
26359- unsigned open_count;
26360+ local_t open_count;
26361 struct tty_struct *tty;
26362 struct tasklet_struct if_wake_tasklet;
26363 unsigned control_state;
26364diff -urNp linux-3.0.4/drivers/isdn/gigaset/interface.c linux-3.0.4/drivers/isdn/gigaset/interface.c
26365--- linux-3.0.4/drivers/isdn/gigaset/interface.c 2011-07-21 22:17:23.000000000 -0400
26366+++ linux-3.0.4/drivers/isdn/gigaset/interface.c 2011-08-23 21:47:55.000000000 -0400
26367@@ -162,9 +162,7 @@ static int if_open(struct tty_struct *tt
26368 }
26369 tty->driver_data = cs;
26370
26371- ++cs->open_count;
26372-
26373- if (cs->open_count == 1) {
26374+ if (local_inc_return(&cs->open_count) == 1) {
26375 spin_lock_irqsave(&cs->lock, flags);
26376 cs->tty = tty;
26377 spin_unlock_irqrestore(&cs->lock, flags);
26378@@ -192,10 +190,10 @@ static void if_close(struct tty_struct *
26379
26380 if (!cs->connected)
26381 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
26382- else if (!cs->open_count)
26383+ else if (!local_read(&cs->open_count))
26384 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26385 else {
26386- if (!--cs->open_count) {
26387+ if (!local_dec_return(&cs->open_count)) {
26388 spin_lock_irqsave(&cs->lock, flags);
26389 cs->tty = NULL;
26390 spin_unlock_irqrestore(&cs->lock, flags);
26391@@ -230,7 +228,7 @@ static int if_ioctl(struct tty_struct *t
26392 if (!cs->connected) {
26393 gig_dbg(DEBUG_IF, "not connected");
26394 retval = -ENODEV;
26395- } else if (!cs->open_count)
26396+ } else if (!local_read(&cs->open_count))
26397 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26398 else {
26399 retval = 0;
26400@@ -360,7 +358,7 @@ static int if_write(struct tty_struct *t
26401 retval = -ENODEV;
26402 goto done;
26403 }
26404- if (!cs->open_count) {
26405+ if (!local_read(&cs->open_count)) {
26406 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26407 retval = -ENODEV;
26408 goto done;
26409@@ -413,7 +411,7 @@ static int if_write_room(struct tty_stru
26410 if (!cs->connected) {
26411 gig_dbg(DEBUG_IF, "not connected");
26412 retval = -ENODEV;
26413- } else if (!cs->open_count)
26414+ } else if (!local_read(&cs->open_count))
26415 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26416 else if (cs->mstate != MS_LOCKED) {
26417 dev_warn(cs->dev, "can't write to unlocked device\n");
26418@@ -443,7 +441,7 @@ static int if_chars_in_buffer(struct tty
26419
26420 if (!cs->connected)
26421 gig_dbg(DEBUG_IF, "not connected");
26422- else if (!cs->open_count)
26423+ else if (!local_read(&cs->open_count))
26424 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26425 else if (cs->mstate != MS_LOCKED)
26426 dev_warn(cs->dev, "can't write to unlocked device\n");
26427@@ -471,7 +469,7 @@ static void if_throttle(struct tty_struc
26428
26429 if (!cs->connected)
26430 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
26431- else if (!cs->open_count)
26432+ else if (!local_read(&cs->open_count))
26433 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26434 else
26435 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
26436@@ -495,7 +493,7 @@ static void if_unthrottle(struct tty_str
26437
26438 if (!cs->connected)
26439 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
26440- else if (!cs->open_count)
26441+ else if (!local_read(&cs->open_count))
26442 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26443 else
26444 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
26445@@ -526,7 +524,7 @@ static void if_set_termios(struct tty_st
26446 goto out;
26447 }
26448
26449- if (!cs->open_count) {
26450+ if (!local_read(&cs->open_count)) {
26451 dev_warn(cs->dev, "%s: device not opened\n", __func__);
26452 goto out;
26453 }
26454diff -urNp linux-3.0.4/drivers/isdn/hardware/avm/b1.c linux-3.0.4/drivers/isdn/hardware/avm/b1.c
26455--- linux-3.0.4/drivers/isdn/hardware/avm/b1.c 2011-07-21 22:17:23.000000000 -0400
26456+++ linux-3.0.4/drivers/isdn/hardware/avm/b1.c 2011-08-23 21:47:55.000000000 -0400
26457@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
26458 }
26459 if (left) {
26460 if (t4file->user) {
26461- if (copy_from_user(buf, dp, left))
26462+ if (left > sizeof buf || copy_from_user(buf, dp, left))
26463 return -EFAULT;
26464 } else {
26465 memcpy(buf, dp, left);
26466@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
26467 }
26468 if (left) {
26469 if (config->user) {
26470- if (copy_from_user(buf, dp, left))
26471+ if (left > sizeof buf || copy_from_user(buf, dp, left))
26472 return -EFAULT;
26473 } else {
26474 memcpy(buf, dp, left);
26475diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/capidtmf.c linux-3.0.4/drivers/isdn/hardware/eicon/capidtmf.c
26476--- linux-3.0.4/drivers/isdn/hardware/eicon/capidtmf.c 2011-07-21 22:17:23.000000000 -0400
26477+++ linux-3.0.4/drivers/isdn/hardware/eicon/capidtmf.c 2011-08-23 21:48:14.000000000 -0400
26478@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
26479 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
26480 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
26481
26482+ pax_track_stack();
26483
26484 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
26485 {
26486diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/capifunc.c linux-3.0.4/drivers/isdn/hardware/eicon/capifunc.c
26487--- linux-3.0.4/drivers/isdn/hardware/eicon/capifunc.c 2011-07-21 22:17:23.000000000 -0400
26488+++ linux-3.0.4/drivers/isdn/hardware/eicon/capifunc.c 2011-08-23 21:48:14.000000000 -0400
26489@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
26490 IDI_SYNC_REQ req;
26491 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
26492
26493+ pax_track_stack();
26494+
26495 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
26496
26497 for (x = 0; x < MAX_DESCRIPTORS; x++) {
26498diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/diddfunc.c linux-3.0.4/drivers/isdn/hardware/eicon/diddfunc.c
26499--- linux-3.0.4/drivers/isdn/hardware/eicon/diddfunc.c 2011-07-21 22:17:23.000000000 -0400
26500+++ linux-3.0.4/drivers/isdn/hardware/eicon/diddfunc.c 2011-08-23 21:48:14.000000000 -0400
26501@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
26502 IDI_SYNC_REQ req;
26503 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
26504
26505+ pax_track_stack();
26506+
26507 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
26508
26509 for (x = 0; x < MAX_DESCRIPTORS; x++) {
26510diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/divasfunc.c linux-3.0.4/drivers/isdn/hardware/eicon/divasfunc.c
26511--- linux-3.0.4/drivers/isdn/hardware/eicon/divasfunc.c 2011-07-21 22:17:23.000000000 -0400
26512+++ linux-3.0.4/drivers/isdn/hardware/eicon/divasfunc.c 2011-08-23 21:48:14.000000000 -0400
26513@@ -160,6 +160,8 @@ static int DIVA_INIT_FUNCTION connect_di
26514 IDI_SYNC_REQ req;
26515 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
26516
26517+ pax_track_stack();
26518+
26519 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
26520
26521 for (x = 0; x < MAX_DESCRIPTORS; x++) {
26522diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/divasync.h linux-3.0.4/drivers/isdn/hardware/eicon/divasync.h
26523--- linux-3.0.4/drivers/isdn/hardware/eicon/divasync.h 2011-07-21 22:17:23.000000000 -0400
26524+++ linux-3.0.4/drivers/isdn/hardware/eicon/divasync.h 2011-08-23 21:47:55.000000000 -0400
26525@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
26526 } diva_didd_add_adapter_t;
26527 typedef struct _diva_didd_remove_adapter {
26528 IDI_CALL p_request;
26529-} diva_didd_remove_adapter_t;
26530+} __no_const diva_didd_remove_adapter_t;
26531 typedef struct _diva_didd_read_adapter_array {
26532 void * buffer;
26533 dword length;
26534diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/idifunc.c linux-3.0.4/drivers/isdn/hardware/eicon/idifunc.c
26535--- linux-3.0.4/drivers/isdn/hardware/eicon/idifunc.c 2011-07-21 22:17:23.000000000 -0400
26536+++ linux-3.0.4/drivers/isdn/hardware/eicon/idifunc.c 2011-08-23 21:48:14.000000000 -0400
26537@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
26538 IDI_SYNC_REQ req;
26539 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
26540
26541+ pax_track_stack();
26542+
26543 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
26544
26545 for (x = 0; x < MAX_DESCRIPTORS; x++) {
26546diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/message.c linux-3.0.4/drivers/isdn/hardware/eicon/message.c
26547--- linux-3.0.4/drivers/isdn/hardware/eicon/message.c 2011-07-21 22:17:23.000000000 -0400
26548+++ linux-3.0.4/drivers/isdn/hardware/eicon/message.c 2011-08-23 21:48:14.000000000 -0400
26549@@ -4886,6 +4886,8 @@ static void sig_ind(PLCI *plci)
26550 dword d;
26551 word w;
26552
26553+ pax_track_stack();
26554+
26555 a = plci->adapter;
26556 Id = ((word)plci->Id<<8)|a->Id;
26557 PUT_WORD(&SS_Ind[4],0x0000);
26558@@ -7480,6 +7482,8 @@ static word add_b1(PLCI *plci, API_PARSE
26559 word j, n, w;
26560 dword d;
26561
26562+ pax_track_stack();
26563+
26564
26565 for(i=0;i<8;i++) bp_parms[i].length = 0;
26566 for(i=0;i<2;i++) global_config[i].length = 0;
26567@@ -7954,6 +7958,8 @@ static word add_b23(PLCI *plci, API_PARS
26568 const byte llc3[] = {4,3,2,2,6,6,0};
26569 const byte header[] = {0,2,3,3,0,0,0};
26570
26571+ pax_track_stack();
26572+
26573 for(i=0;i<8;i++) bp_parms[i].length = 0;
26574 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
26575 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
26576@@ -14741,6 +14747,8 @@ static void group_optimization(DIVA_CAPI
26577 word appl_number_group_type[MAX_APPL];
26578 PLCI *auxplci;
26579
26580+ pax_track_stack();
26581+
26582 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
26583
26584 if(!a->group_optimization_enabled)
26585diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/mntfunc.c linux-3.0.4/drivers/isdn/hardware/eicon/mntfunc.c
26586--- linux-3.0.4/drivers/isdn/hardware/eicon/mntfunc.c 2011-07-21 22:17:23.000000000 -0400
26587+++ linux-3.0.4/drivers/isdn/hardware/eicon/mntfunc.c 2011-08-23 21:48:14.000000000 -0400
26588@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
26589 IDI_SYNC_REQ req;
26590 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
26591
26592+ pax_track_stack();
26593+
26594 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
26595
26596 for (x = 0; x < MAX_DESCRIPTORS; x++) {
26597diff -urNp linux-3.0.4/drivers/isdn/hardware/eicon/xdi_adapter.h linux-3.0.4/drivers/isdn/hardware/eicon/xdi_adapter.h
26598--- linux-3.0.4/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-07-21 22:17:23.000000000 -0400
26599+++ linux-3.0.4/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-08-23 21:47:55.000000000 -0400
26600@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
26601 typedef struct _diva_os_idi_adapter_interface {
26602 diva_init_card_proc_t cleanup_adapter_proc;
26603 diva_cmd_card_proc_t cmd_proc;
26604-} diva_os_idi_adapter_interface_t;
26605+} __no_const diva_os_idi_adapter_interface_t;
26606
26607 typedef struct _diva_os_xdi_adapter {
26608 struct list_head link;
26609diff -urNp linux-3.0.4/drivers/isdn/i4l/isdn_common.c linux-3.0.4/drivers/isdn/i4l/isdn_common.c
26610--- linux-3.0.4/drivers/isdn/i4l/isdn_common.c 2011-07-21 22:17:23.000000000 -0400
26611+++ linux-3.0.4/drivers/isdn/i4l/isdn_common.c 2011-08-23 21:48:14.000000000 -0400
26612@@ -1286,6 +1286,8 @@ isdn_ioctl(struct file *file, uint cmd,
26613 } iocpar;
26614 void __user *argp = (void __user *)arg;
26615
26616+ pax_track_stack();
26617+
26618 #define name iocpar.name
26619 #define bname iocpar.bname
26620 #define iocts iocpar.iocts
26621diff -urNp linux-3.0.4/drivers/isdn/icn/icn.c linux-3.0.4/drivers/isdn/icn/icn.c
26622--- linux-3.0.4/drivers/isdn/icn/icn.c 2011-07-21 22:17:23.000000000 -0400
26623+++ linux-3.0.4/drivers/isdn/icn/icn.c 2011-08-23 21:47:55.000000000 -0400
26624@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
26625 if (count > len)
26626 count = len;
26627 if (user) {
26628- if (copy_from_user(msg, buf, count))
26629+ if (count > sizeof msg || copy_from_user(msg, buf, count))
26630 return -EFAULT;
26631 } else
26632 memcpy(msg, buf, count);
26633diff -urNp linux-3.0.4/drivers/lguest/core.c linux-3.0.4/drivers/lguest/core.c
26634--- linux-3.0.4/drivers/lguest/core.c 2011-07-21 22:17:23.000000000 -0400
26635+++ linux-3.0.4/drivers/lguest/core.c 2011-08-23 21:47:55.000000000 -0400
26636@@ -92,9 +92,17 @@ static __init int map_switcher(void)
26637 * it's worked so far. The end address needs +1 because __get_vm_area
26638 * allocates an extra guard page, so we need space for that.
26639 */
26640+
26641+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26642+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
26643+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
26644+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
26645+#else
26646 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
26647 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
26648 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
26649+#endif
26650+
26651 if (!switcher_vma) {
26652 err = -ENOMEM;
26653 printk("lguest: could not map switcher pages high\n");
26654@@ -119,7 +127,7 @@ static __init int map_switcher(void)
26655 * Now the Switcher is mapped at the right address, we can't fail!
26656 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
26657 */
26658- memcpy(switcher_vma->addr, start_switcher_text,
26659+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
26660 end_switcher_text - start_switcher_text);
26661
26662 printk(KERN_INFO "lguest: mapped switcher at %p\n",
26663diff -urNp linux-3.0.4/drivers/lguest/x86/core.c linux-3.0.4/drivers/lguest/x86/core.c
26664--- linux-3.0.4/drivers/lguest/x86/core.c 2011-07-21 22:17:23.000000000 -0400
26665+++ linux-3.0.4/drivers/lguest/x86/core.c 2011-08-23 21:47:55.000000000 -0400
26666@@ -59,7 +59,7 @@ static struct {
26667 /* Offset from where switcher.S was compiled to where we've copied it */
26668 static unsigned long switcher_offset(void)
26669 {
26670- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
26671+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
26672 }
26673
26674 /* This cpu's struct lguest_pages. */
26675@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
26676 * These copies are pretty cheap, so we do them unconditionally: */
26677 /* Save the current Host top-level page directory.
26678 */
26679+
26680+#ifdef CONFIG_PAX_PER_CPU_PGD
26681+ pages->state.host_cr3 = read_cr3();
26682+#else
26683 pages->state.host_cr3 = __pa(current->mm->pgd);
26684+#endif
26685+
26686 /*
26687 * Set up the Guest's page tables to see this CPU's pages (and no
26688 * other CPU's pages).
26689@@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
26690 * compiled-in switcher code and the high-mapped copy we just made.
26691 */
26692 for (i = 0; i < IDT_ENTRIES; i++)
26693- default_idt_entries[i] += switcher_offset();
26694+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
26695
26696 /*
26697 * Set up the Switcher's per-cpu areas.
26698@@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
26699 * it will be undisturbed when we switch. To change %cs and jump we
26700 * need this structure to feed to Intel's "lcall" instruction.
26701 */
26702- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
26703+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
26704 lguest_entry.segment = LGUEST_CS;
26705
26706 /*
26707diff -urNp linux-3.0.4/drivers/lguest/x86/switcher_32.S linux-3.0.4/drivers/lguest/x86/switcher_32.S
26708--- linux-3.0.4/drivers/lguest/x86/switcher_32.S 2011-07-21 22:17:23.000000000 -0400
26709+++ linux-3.0.4/drivers/lguest/x86/switcher_32.S 2011-08-23 21:47:55.000000000 -0400
26710@@ -87,6 +87,7 @@
26711 #include <asm/page.h>
26712 #include <asm/segment.h>
26713 #include <asm/lguest.h>
26714+#include <asm/processor-flags.h>
26715
26716 // We mark the start of the code to copy
26717 // It's placed in .text tho it's never run here
26718@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
26719 // Changes type when we load it: damn Intel!
26720 // For after we switch over our page tables
26721 // That entry will be read-only: we'd crash.
26722+
26723+#ifdef CONFIG_PAX_KERNEXEC
26724+ mov %cr0, %edx
26725+ xor $X86_CR0_WP, %edx
26726+ mov %edx, %cr0
26727+#endif
26728+
26729 movl $(GDT_ENTRY_TSS*8), %edx
26730 ltr %dx
26731
26732@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
26733 // Let's clear it again for our return.
26734 // The GDT descriptor of the Host
26735 // Points to the table after two "size" bytes
26736- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
26737+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
26738 // Clear "used" from type field (byte 5, bit 2)
26739- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
26740+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
26741+
26742+#ifdef CONFIG_PAX_KERNEXEC
26743+ mov %cr0, %eax
26744+ xor $X86_CR0_WP, %eax
26745+ mov %eax, %cr0
26746+#endif
26747
26748 // Once our page table's switched, the Guest is live!
26749 // The Host fades as we run this final step.
26750@@ -295,13 +309,12 @@ deliver_to_host:
26751 // I consulted gcc, and it gave
26752 // These instructions, which I gladly credit:
26753 leal (%edx,%ebx,8), %eax
26754- movzwl (%eax),%edx
26755- movl 4(%eax), %eax
26756- xorw %ax, %ax
26757- orl %eax, %edx
26758+ movl 4(%eax), %edx
26759+ movw (%eax), %dx
26760 // Now the address of the handler's in %edx
26761 // We call it now: its "iret" drops us home.
26762- jmp *%edx
26763+ ljmp $__KERNEL_CS, $1f
26764+1: jmp *%edx
26765
26766 // Every interrupt can come to us here
26767 // But we must truly tell each apart.
26768diff -urNp linux-3.0.4/drivers/md/dm.c linux-3.0.4/drivers/md/dm.c
26769--- linux-3.0.4/drivers/md/dm.c 2011-08-23 21:44:40.000000000 -0400
26770+++ linux-3.0.4/drivers/md/dm.c 2011-08-23 21:47:55.000000000 -0400
26771@@ -164,9 +164,9 @@ struct mapped_device {
26772 /*
26773 * Event handling.
26774 */
26775- atomic_t event_nr;
26776+ atomic_unchecked_t event_nr;
26777 wait_queue_head_t eventq;
26778- atomic_t uevent_seq;
26779+ atomic_unchecked_t uevent_seq;
26780 struct list_head uevent_list;
26781 spinlock_t uevent_lock; /* Protect access to uevent_list */
26782
26783@@ -1842,8 +1842,8 @@ static struct mapped_device *alloc_dev(i
26784 rwlock_init(&md->map_lock);
26785 atomic_set(&md->holders, 1);
26786 atomic_set(&md->open_count, 0);
26787- atomic_set(&md->event_nr, 0);
26788- atomic_set(&md->uevent_seq, 0);
26789+ atomic_set_unchecked(&md->event_nr, 0);
26790+ atomic_set_unchecked(&md->uevent_seq, 0);
26791 INIT_LIST_HEAD(&md->uevent_list);
26792 spin_lock_init(&md->uevent_lock);
26793
26794@@ -1977,7 +1977,7 @@ static void event_callback(void *context
26795
26796 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
26797
26798- atomic_inc(&md->event_nr);
26799+ atomic_inc_unchecked(&md->event_nr);
26800 wake_up(&md->eventq);
26801 }
26802
26803@@ -2553,18 +2553,18 @@ int dm_kobject_uevent(struct mapped_devi
26804
26805 uint32_t dm_next_uevent_seq(struct mapped_device *md)
26806 {
26807- return atomic_add_return(1, &md->uevent_seq);
26808+ return atomic_add_return_unchecked(1, &md->uevent_seq);
26809 }
26810
26811 uint32_t dm_get_event_nr(struct mapped_device *md)
26812 {
26813- return atomic_read(&md->event_nr);
26814+ return atomic_read_unchecked(&md->event_nr);
26815 }
26816
26817 int dm_wait_event(struct mapped_device *md, int event_nr)
26818 {
26819 return wait_event_interruptible(md->eventq,
26820- (event_nr != atomic_read(&md->event_nr)));
26821+ (event_nr != atomic_read_unchecked(&md->event_nr)));
26822 }
26823
26824 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
26825diff -urNp linux-3.0.4/drivers/md/dm-ioctl.c linux-3.0.4/drivers/md/dm-ioctl.c
26826--- linux-3.0.4/drivers/md/dm-ioctl.c 2011-07-21 22:17:23.000000000 -0400
26827+++ linux-3.0.4/drivers/md/dm-ioctl.c 2011-08-23 21:47:55.000000000 -0400
26828@@ -1551,7 +1551,7 @@ static int validate_params(uint cmd, str
26829 cmd == DM_LIST_VERSIONS_CMD)
26830 return 0;
26831
26832- if ((cmd == DM_DEV_CREATE_CMD)) {
26833+ if (cmd == DM_DEV_CREATE_CMD) {
26834 if (!*param->name) {
26835 DMWARN("name not supplied when creating device");
26836 return -EINVAL;
26837diff -urNp linux-3.0.4/drivers/md/dm-raid1.c linux-3.0.4/drivers/md/dm-raid1.c
26838--- linux-3.0.4/drivers/md/dm-raid1.c 2011-07-21 22:17:23.000000000 -0400
26839+++ linux-3.0.4/drivers/md/dm-raid1.c 2011-08-23 21:47:55.000000000 -0400
26840@@ -40,7 +40,7 @@ enum dm_raid1_error {
26841
26842 struct mirror {
26843 struct mirror_set *ms;
26844- atomic_t error_count;
26845+ atomic_unchecked_t error_count;
26846 unsigned long error_type;
26847 struct dm_dev *dev;
26848 sector_t offset;
26849@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(s
26850 struct mirror *m;
26851
26852 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
26853- if (!atomic_read(&m->error_count))
26854+ if (!atomic_read_unchecked(&m->error_count))
26855 return m;
26856
26857 return NULL;
26858@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m
26859 * simple way to tell if a device has encountered
26860 * errors.
26861 */
26862- atomic_inc(&m->error_count);
26863+ atomic_inc_unchecked(&m->error_count);
26864
26865 if (test_and_set_bit(error_type, &m->error_type))
26866 return;
26867@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(stru
26868 struct mirror *m = get_default_mirror(ms);
26869
26870 do {
26871- if (likely(!atomic_read(&m->error_count)))
26872+ if (likely(!atomic_read_unchecked(&m->error_count)))
26873 return m;
26874
26875 if (m-- == ms->mirror)
26876@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
26877 {
26878 struct mirror *default_mirror = get_default_mirror(m->ms);
26879
26880- return !atomic_read(&default_mirror->error_count);
26881+ return !atomic_read_unchecked(&default_mirror->error_count);
26882 }
26883
26884 static int mirror_available(struct mirror_set *ms, struct bio *bio)
26885@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *
26886 */
26887 if (likely(region_in_sync(ms, region, 1)))
26888 m = choose_mirror(ms, bio->bi_sector);
26889- else if (m && atomic_read(&m->error_count))
26890+ else if (m && atomic_read_unchecked(&m->error_count))
26891 m = NULL;
26892
26893 if (likely(m))
26894@@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set
26895 }
26896
26897 ms->mirror[mirror].ms = ms;
26898- atomic_set(&(ms->mirror[mirror].error_count), 0);
26899+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
26900 ms->mirror[mirror].error_type = 0;
26901 ms->mirror[mirror].offset = offset;
26902
26903@@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_targ
26904 */
26905 static char device_status_char(struct mirror *m)
26906 {
26907- if (!atomic_read(&(m->error_count)))
26908+ if (!atomic_read_unchecked(&(m->error_count)))
26909 return 'A';
26910
26911 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
26912diff -urNp linux-3.0.4/drivers/md/dm-stripe.c linux-3.0.4/drivers/md/dm-stripe.c
26913--- linux-3.0.4/drivers/md/dm-stripe.c 2011-07-21 22:17:23.000000000 -0400
26914+++ linux-3.0.4/drivers/md/dm-stripe.c 2011-08-23 21:47:55.000000000 -0400
26915@@ -20,7 +20,7 @@ struct stripe {
26916 struct dm_dev *dev;
26917 sector_t physical_start;
26918
26919- atomic_t error_count;
26920+ atomic_unchecked_t error_count;
26921 };
26922
26923 struct stripe_c {
26924@@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *
26925 kfree(sc);
26926 return r;
26927 }
26928- atomic_set(&(sc->stripe[i].error_count), 0);
26929+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
26930 }
26931
26932 ti->private = sc;
26933@@ -314,7 +314,7 @@ static int stripe_status(struct dm_targe
26934 DMEMIT("%d ", sc->stripes);
26935 for (i = 0; i < sc->stripes; i++) {
26936 DMEMIT("%s ", sc->stripe[i].dev->name);
26937- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
26938+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
26939 'D' : 'A';
26940 }
26941 buffer[i] = '\0';
26942@@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_targe
26943 */
26944 for (i = 0; i < sc->stripes; i++)
26945 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
26946- atomic_inc(&(sc->stripe[i].error_count));
26947- if (atomic_read(&(sc->stripe[i].error_count)) <
26948+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
26949+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
26950 DM_IO_ERROR_THRESHOLD)
26951 schedule_work(&sc->trigger_event);
26952 }
26953diff -urNp linux-3.0.4/drivers/md/dm-table.c linux-3.0.4/drivers/md/dm-table.c
26954--- linux-3.0.4/drivers/md/dm-table.c 2011-07-21 22:17:23.000000000 -0400
26955+++ linux-3.0.4/drivers/md/dm-table.c 2011-08-23 21:47:55.000000000 -0400
26956@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct
26957 if (!dev_size)
26958 return 0;
26959
26960- if ((start >= dev_size) || (start + len > dev_size)) {
26961+ if ((start >= dev_size) || (len > dev_size - start)) {
26962 DMWARN("%s: %s too small for target: "
26963 "start=%llu, len=%llu, dev_size=%llu",
26964 dm_device_name(ti->table->md), bdevname(bdev, b),
26965diff -urNp linux-3.0.4/drivers/md/md.c linux-3.0.4/drivers/md/md.c
26966--- linux-3.0.4/drivers/md/md.c 2011-07-21 22:17:23.000000000 -0400
26967+++ linux-3.0.4/drivers/md/md.c 2011-08-23 21:47:55.000000000 -0400
26968@@ -226,10 +226,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
26969 * start build, activate spare
26970 */
26971 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
26972-static atomic_t md_event_count;
26973+static atomic_unchecked_t md_event_count;
26974 void md_new_event(mddev_t *mddev)
26975 {
26976- atomic_inc(&md_event_count);
26977+ atomic_inc_unchecked(&md_event_count);
26978 wake_up(&md_event_waiters);
26979 }
26980 EXPORT_SYMBOL_GPL(md_new_event);
26981@@ -239,7 +239,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
26982 */
26983 static void md_new_event_inintr(mddev_t *mddev)
26984 {
26985- atomic_inc(&md_event_count);
26986+ atomic_inc_unchecked(&md_event_count);
26987 wake_up(&md_event_waiters);
26988 }
26989
26990@@ -1457,7 +1457,7 @@ static int super_1_load(mdk_rdev_t *rdev
26991
26992 rdev->preferred_minor = 0xffff;
26993 rdev->data_offset = le64_to_cpu(sb->data_offset);
26994- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
26995+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
26996
26997 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
26998 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
26999@@ -1635,7 +1635,7 @@ static void super_1_sync(mddev_t *mddev,
27000 else
27001 sb->resync_offset = cpu_to_le64(0);
27002
27003- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
27004+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
27005
27006 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
27007 sb->size = cpu_to_le64(mddev->dev_sectors);
27008@@ -2428,7 +2428,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
27009 static ssize_t
27010 errors_show(mdk_rdev_t *rdev, char *page)
27011 {
27012- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
27013+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
27014 }
27015
27016 static ssize_t
27017@@ -2437,7 +2437,7 @@ errors_store(mdk_rdev_t *rdev, const cha
27018 char *e;
27019 unsigned long n = simple_strtoul(buf, &e, 10);
27020 if (*buf && (*e == 0 || *e == '\n')) {
27021- atomic_set(&rdev->corrected_errors, n);
27022+ atomic_set_unchecked(&rdev->corrected_errors, n);
27023 return len;
27024 }
27025 return -EINVAL;
27026@@ -2793,8 +2793,8 @@ void md_rdev_init(mdk_rdev_t *rdev)
27027 rdev->last_read_error.tv_sec = 0;
27028 rdev->last_read_error.tv_nsec = 0;
27029 atomic_set(&rdev->nr_pending, 0);
27030- atomic_set(&rdev->read_errors, 0);
27031- atomic_set(&rdev->corrected_errors, 0);
27032+ atomic_set_unchecked(&rdev->read_errors, 0);
27033+ atomic_set_unchecked(&rdev->corrected_errors, 0);
27034
27035 INIT_LIST_HEAD(&rdev->same_set);
27036 init_waitqueue_head(&rdev->blocked_wait);
27037@@ -6415,7 +6415,7 @@ static int md_seq_show(struct seq_file *
27038
27039 spin_unlock(&pers_lock);
27040 seq_printf(seq, "\n");
27041- mi->event = atomic_read(&md_event_count);
27042+ mi->event = atomic_read_unchecked(&md_event_count);
27043 return 0;
27044 }
27045 if (v == (void*)2) {
27046@@ -6504,7 +6504,7 @@ static int md_seq_show(struct seq_file *
27047 chunk_kb ? "KB" : "B");
27048 if (bitmap->file) {
27049 seq_printf(seq, ", file: ");
27050- seq_path(seq, &bitmap->file->f_path, " \t\n");
27051+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
27052 }
27053
27054 seq_printf(seq, "\n");
27055@@ -6538,7 +6538,7 @@ static int md_seq_open(struct inode *ino
27056 else {
27057 struct seq_file *p = file->private_data;
27058 p->private = mi;
27059- mi->event = atomic_read(&md_event_count);
27060+ mi->event = atomic_read_unchecked(&md_event_count);
27061 }
27062 return error;
27063 }
27064@@ -6554,7 +6554,7 @@ static unsigned int mdstat_poll(struct f
27065 /* always allow read */
27066 mask = POLLIN | POLLRDNORM;
27067
27068- if (mi->event != atomic_read(&md_event_count))
27069+ if (mi->event != atomic_read_unchecked(&md_event_count))
27070 mask |= POLLERR | POLLPRI;
27071 return mask;
27072 }
27073@@ -6598,7 +6598,7 @@ static int is_mddev_idle(mddev_t *mddev,
27074 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
27075 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
27076 (int)part_stat_read(&disk->part0, sectors[1]) -
27077- atomic_read(&disk->sync_io);
27078+ atomic_read_unchecked(&disk->sync_io);
27079 /* sync IO will cause sync_io to increase before the disk_stats
27080 * as sync_io is counted when a request starts, and
27081 * disk_stats is counted when it completes.
27082diff -urNp linux-3.0.4/drivers/md/md.h linux-3.0.4/drivers/md/md.h
27083--- linux-3.0.4/drivers/md/md.h 2011-07-21 22:17:23.000000000 -0400
27084+++ linux-3.0.4/drivers/md/md.h 2011-08-23 21:47:55.000000000 -0400
27085@@ -97,13 +97,13 @@ struct mdk_rdev_s
27086 * only maintained for arrays that
27087 * support hot removal
27088 */
27089- atomic_t read_errors; /* number of consecutive read errors that
27090+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
27091 * we have tried to ignore.
27092 */
27093 struct timespec last_read_error; /* monotonic time since our
27094 * last read error
27095 */
27096- atomic_t corrected_errors; /* number of corrected read errors,
27097+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
27098 * for reporting to userspace and storing
27099 * in superblock.
27100 */
27101@@ -344,7 +344,7 @@ static inline void rdev_dec_pending(mdk_
27102
27103 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
27104 {
27105- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
27106+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
27107 }
27108
27109 struct mdk_personality
27110diff -urNp linux-3.0.4/drivers/md/raid10.c linux-3.0.4/drivers/md/raid10.c
27111--- linux-3.0.4/drivers/md/raid10.c 2011-07-21 22:17:23.000000000 -0400
27112+++ linux-3.0.4/drivers/md/raid10.c 2011-08-23 21:47:55.000000000 -0400
27113@@ -1186,7 +1186,7 @@ static void end_sync_read(struct bio *bi
27114 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
27115 set_bit(R10BIO_Uptodate, &r10_bio->state);
27116 else {
27117- atomic_add(r10_bio->sectors,
27118+ atomic_add_unchecked(r10_bio->sectors,
27119 &conf->mirrors[d].rdev->corrected_errors);
27120 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
27121 md_error(r10_bio->mddev,
27122@@ -1394,7 +1394,7 @@ static void check_decay_read_errors(mdde
27123 {
27124 struct timespec cur_time_mon;
27125 unsigned long hours_since_last;
27126- unsigned int read_errors = atomic_read(&rdev->read_errors);
27127+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
27128
27129 ktime_get_ts(&cur_time_mon);
27130
27131@@ -1416,9 +1416,9 @@ static void check_decay_read_errors(mdde
27132 * overflowing the shift of read_errors by hours_since_last.
27133 */
27134 if (hours_since_last >= 8 * sizeof(read_errors))
27135- atomic_set(&rdev->read_errors, 0);
27136+ atomic_set_unchecked(&rdev->read_errors, 0);
27137 else
27138- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
27139+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
27140 }
27141
27142 /*
27143@@ -1448,8 +1448,8 @@ static void fix_read_error(conf_t *conf,
27144 return;
27145
27146 check_decay_read_errors(mddev, rdev);
27147- atomic_inc(&rdev->read_errors);
27148- if (atomic_read(&rdev->read_errors) > max_read_errors) {
27149+ atomic_inc_unchecked(&rdev->read_errors);
27150+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
27151 char b[BDEVNAME_SIZE];
27152 bdevname(rdev->bdev, b);
27153
27154@@ -1457,7 +1457,7 @@ static void fix_read_error(conf_t *conf,
27155 "md/raid10:%s: %s: Raid device exceeded "
27156 "read_error threshold [cur %d:max %d]\n",
27157 mdname(mddev), b,
27158- atomic_read(&rdev->read_errors), max_read_errors);
27159+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
27160 printk(KERN_NOTICE
27161 "md/raid10:%s: %s: Failing raid device\n",
27162 mdname(mddev), b);
27163@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf,
27164 test_bit(In_sync, &rdev->flags)) {
27165 atomic_inc(&rdev->nr_pending);
27166 rcu_read_unlock();
27167- atomic_add(s, &rdev->corrected_errors);
27168+ atomic_add_unchecked(s, &rdev->corrected_errors);
27169 if (sync_page_io(rdev,
27170 r10_bio->devs[sl].addr +
27171 sect,
27172diff -urNp linux-3.0.4/drivers/md/raid1.c linux-3.0.4/drivers/md/raid1.c
27173--- linux-3.0.4/drivers/md/raid1.c 2011-07-21 22:17:23.000000000 -0400
27174+++ linux-3.0.4/drivers/md/raid1.c 2011-08-23 21:47:55.000000000 -0400
27175@@ -1263,7 +1263,7 @@ static int fix_sync_read_error(r1bio_t *
27176 rdev_dec_pending(rdev, mddev);
27177 md_error(mddev, rdev);
27178 } else
27179- atomic_add(s, &rdev->corrected_errors);
27180+ atomic_add_unchecked(s, &rdev->corrected_errors);
27181 }
27182 d = start;
27183 while (d != r1_bio->read_disk) {
27184@@ -1492,7 +1492,7 @@ static void fix_read_error(conf_t *conf,
27185 /* Well, this device is dead */
27186 md_error(mddev, rdev);
27187 else {
27188- atomic_add(s, &rdev->corrected_errors);
27189+ atomic_add_unchecked(s, &rdev->corrected_errors);
27190 printk(KERN_INFO
27191 "md/raid1:%s: read error corrected "
27192 "(%d sectors at %llu on %s)\n",
27193diff -urNp linux-3.0.4/drivers/md/raid5.c linux-3.0.4/drivers/md/raid5.c
27194--- linux-3.0.4/drivers/md/raid5.c 2011-07-21 22:17:23.000000000 -0400
27195+++ linux-3.0.4/drivers/md/raid5.c 2011-08-23 21:48:14.000000000 -0400
27196@@ -550,7 +550,7 @@ static void ops_run_io(struct stripe_hea
27197 bi->bi_next = NULL;
27198 if ((rw & WRITE) &&
27199 test_bit(R5_ReWrite, &sh->dev[i].flags))
27200- atomic_add(STRIPE_SECTORS,
27201+ atomic_add_unchecked(STRIPE_SECTORS,
27202 &rdev->corrected_errors);
27203 generic_make_request(bi);
27204 } else {
27205@@ -1596,15 +1596,15 @@ static void raid5_end_read_request(struc
27206 clear_bit(R5_ReadError, &sh->dev[i].flags);
27207 clear_bit(R5_ReWrite, &sh->dev[i].flags);
27208 }
27209- if (atomic_read(&conf->disks[i].rdev->read_errors))
27210- atomic_set(&conf->disks[i].rdev->read_errors, 0);
27211+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
27212+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
27213 } else {
27214 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
27215 int retry = 0;
27216 rdev = conf->disks[i].rdev;
27217
27218 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
27219- atomic_inc(&rdev->read_errors);
27220+ atomic_inc_unchecked(&rdev->read_errors);
27221 if (conf->mddev->degraded >= conf->max_degraded)
27222 printk_rl(KERN_WARNING
27223 "md/raid:%s: read error not correctable "
27224@@ -1622,7 +1622,7 @@ static void raid5_end_read_request(struc
27225 (unsigned long long)(sh->sector
27226 + rdev->data_offset),
27227 bdn);
27228- else if (atomic_read(&rdev->read_errors)
27229+ else if (atomic_read_unchecked(&rdev->read_errors)
27230 > conf->max_nr_stripes)
27231 printk(KERN_WARNING
27232 "md/raid:%s: Too many read errors, failing device %s.\n",
27233@@ -1945,6 +1945,7 @@ static sector_t compute_blocknr(struct s
27234 sector_t r_sector;
27235 struct stripe_head sh2;
27236
27237+ pax_track_stack();
27238
27239 chunk_offset = sector_div(new_sector, sectors_per_chunk);
27240 stripe = new_sector;
27241diff -urNp linux-3.0.4/drivers/media/common/saa7146_hlp.c linux-3.0.4/drivers/media/common/saa7146_hlp.c
27242--- linux-3.0.4/drivers/media/common/saa7146_hlp.c 2011-07-21 22:17:23.000000000 -0400
27243+++ linux-3.0.4/drivers/media/common/saa7146_hlp.c 2011-08-23 21:48:14.000000000 -0400
27244@@ -353,6 +353,8 @@ static void calculate_clipping_registers
27245
27246 int x[32], y[32], w[32], h[32];
27247
27248+ pax_track_stack();
27249+
27250 /* clear out memory */
27251 memset(&line_list[0], 0x00, sizeof(u32)*32);
27252 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
27253diff -urNp linux-3.0.4/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-3.0.4/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
27254--- linux-3.0.4/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-07-21 22:17:23.000000000 -0400
27255+++ linux-3.0.4/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-08-23 21:48:14.000000000 -0400
27256@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
27257 u8 buf[HOST_LINK_BUF_SIZE];
27258 int i;
27259
27260+ pax_track_stack();
27261+
27262 dprintk("%s\n", __func__);
27263
27264 /* check if we have space for a link buf in the rx_buffer */
27265@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
27266 unsigned long timeout;
27267 int written;
27268
27269+ pax_track_stack();
27270+
27271 dprintk("%s\n", __func__);
27272
27273 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
27274diff -urNp linux-3.0.4/drivers/media/dvb/dvb-core/dvb_demux.h linux-3.0.4/drivers/media/dvb/dvb-core/dvb_demux.h
27275--- linux-3.0.4/drivers/media/dvb/dvb-core/dvb_demux.h 2011-07-21 22:17:23.000000000 -0400
27276+++ linux-3.0.4/drivers/media/dvb/dvb-core/dvb_demux.h 2011-08-24 18:24:40.000000000 -0400
27277@@ -68,12 +68,12 @@ struct dvb_demux_feed {
27278 union {
27279 struct dmx_ts_feed ts;
27280 struct dmx_section_feed sec;
27281- } feed;
27282+ } __no_const feed;
27283
27284 union {
27285 dmx_ts_cb ts;
27286 dmx_section_cb sec;
27287- } cb;
27288+ } __no_const cb;
27289
27290 struct dvb_demux *demux;
27291 void *priv;
27292diff -urNp linux-3.0.4/drivers/media/dvb/dvb-core/dvbdev.c linux-3.0.4/drivers/media/dvb/dvb-core/dvbdev.c
27293--- linux-3.0.4/drivers/media/dvb/dvb-core/dvbdev.c 2011-07-21 22:17:23.000000000 -0400
27294+++ linux-3.0.4/drivers/media/dvb/dvb-core/dvbdev.c 2011-08-24 18:24:19.000000000 -0400
27295@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapt
27296 const struct dvb_device *template, void *priv, int type)
27297 {
27298 struct dvb_device *dvbdev;
27299- struct file_operations *dvbdevfops;
27300+ file_operations_no_const *dvbdevfops;
27301 struct device *clsdev;
27302 int minor;
27303 int id;
27304diff -urNp linux-3.0.4/drivers/media/dvb/dvb-usb/cxusb.c linux-3.0.4/drivers/media/dvb/dvb-usb/cxusb.c
27305--- linux-3.0.4/drivers/media/dvb/dvb-usb/cxusb.c 2011-07-21 22:17:23.000000000 -0400
27306+++ linux-3.0.4/drivers/media/dvb/dvb-usb/cxusb.c 2011-08-24 18:26:33.000000000 -0400
27307@@ -1059,7 +1059,7 @@ static struct dib0070_config dib7070p_di
27308 struct dib0700_adapter_state {
27309 int (*set_param_save) (struct dvb_frontend *,
27310 struct dvb_frontend_parameters *);
27311-};
27312+} __no_const;
27313
27314 static int dib7070_set_param_override(struct dvb_frontend *fe,
27315 struct dvb_frontend_parameters *fep)
27316diff -urNp linux-3.0.4/drivers/media/dvb/dvb-usb/dib0700_core.c linux-3.0.4/drivers/media/dvb/dvb-usb/dib0700_core.c
27317--- linux-3.0.4/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-07-21 22:17:23.000000000 -0400
27318+++ linux-3.0.4/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-08-23 21:48:14.000000000 -0400
27319@@ -434,6 +434,8 @@ int dib0700_download_firmware(struct usb
27320 if (!buf)
27321 return -ENOMEM;
27322
27323+ pax_track_stack();
27324+
27325 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
27326 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
27327 hx.addr, hx.len, hx.chk);
27328diff -urNp linux-3.0.4/drivers/media/dvb/dvb-usb/dibusb.h linux-3.0.4/drivers/media/dvb/dvb-usb/dibusb.h
27329--- linux-3.0.4/drivers/media/dvb/dvb-usb/dibusb.h 2011-07-21 22:17:23.000000000 -0400
27330+++ linux-3.0.4/drivers/media/dvb/dvb-usb/dibusb.h 2011-08-24 18:27:27.000000000 -0400
27331@@ -97,7 +97,7 @@
27332 #define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02
27333
27334 struct dibusb_state {
27335- struct dib_fe_xfer_ops ops;
27336+ dib_fe_xfer_ops_no_const ops;
27337 int mt2060_present;
27338 u8 tuner_addr;
27339 };
27340diff -urNp linux-3.0.4/drivers/media/dvb/dvb-usb/dw2102.c linux-3.0.4/drivers/media/dvb/dvb-usb/dw2102.c
27341--- linux-3.0.4/drivers/media/dvb/dvb-usb/dw2102.c 2011-07-21 22:17:23.000000000 -0400
27342+++ linux-3.0.4/drivers/media/dvb/dvb-usb/dw2102.c 2011-08-24 18:27:45.000000000 -0400
27343@@ -95,7 +95,7 @@ struct su3000_state {
27344
27345 struct s6x0_state {
27346 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
27347-};
27348+} __no_const;
27349
27350 /* debug */
27351 static int dvb_usb_dw2102_debug;
27352diff -urNp linux-3.0.4/drivers/media/dvb/dvb-usb/lmedm04.c linux-3.0.4/drivers/media/dvb/dvb-usb/lmedm04.c
27353--- linux-3.0.4/drivers/media/dvb/dvb-usb/lmedm04.c 2011-07-21 22:17:23.000000000 -0400
27354+++ linux-3.0.4/drivers/media/dvb/dvb-usb/lmedm04.c 2011-08-23 21:48:14.000000000 -0400
27355@@ -742,6 +742,7 @@ static int lme2510_download_firmware(str
27356 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
27357 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
27358
27359+ pax_track_stack();
27360
27361 data[0] = 0x8a;
27362 len_in = 1;
27363@@ -764,6 +765,8 @@ static void lme_coldreset(struct usb_dev
27364 int ret = 0, len_in;
27365 u8 data[512] = {0};
27366
27367+ pax_track_stack();
27368+
27369 data[0] = 0x0a;
27370 len_in = 1;
27371 info("FRM Firmware Cold Reset");
27372diff -urNp linux-3.0.4/drivers/media/dvb/frontends/dib3000.h linux-3.0.4/drivers/media/dvb/frontends/dib3000.h
27373--- linux-3.0.4/drivers/media/dvb/frontends/dib3000.h 2011-07-21 22:17:23.000000000 -0400
27374+++ linux-3.0.4/drivers/media/dvb/frontends/dib3000.h 2011-08-24 18:28:18.000000000 -0400
27375@@ -40,10 +40,11 @@ struct dib_fe_xfer_ops
27376 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
27377 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
27378 };
27379+typedef struct dib_fe_xfer_ops __no_const dib_fe_xfer_ops_no_const;
27380
27381 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
27382 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
27383- struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops);
27384+ struct i2c_adapter* i2c, dib_fe_xfer_ops_no_const *xfer_ops);
27385 #else
27386 static inline struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
27387 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
27388diff -urNp linux-3.0.4/drivers/media/dvb/frontends/dib3000mb.c linux-3.0.4/drivers/media/dvb/frontends/dib3000mb.c
27389--- linux-3.0.4/drivers/media/dvb/frontends/dib3000mb.c 2011-07-21 22:17:23.000000000 -0400
27390+++ linux-3.0.4/drivers/media/dvb/frontends/dib3000mb.c 2011-08-24 18:28:42.000000000 -0400
27391@@ -756,7 +756,7 @@ static int dib3000mb_tuner_pass_ctrl(str
27392 static struct dvb_frontend_ops dib3000mb_ops;
27393
27394 struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
27395- struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
27396+ struct i2c_adapter* i2c, dib_fe_xfer_ops_no_const *xfer_ops)
27397 {
27398 struct dib3000_state* state = NULL;
27399
27400diff -urNp linux-3.0.4/drivers/media/dvb/frontends/mb86a16.c linux-3.0.4/drivers/media/dvb/frontends/mb86a16.c
27401--- linux-3.0.4/drivers/media/dvb/frontends/mb86a16.c 2011-07-21 22:17:23.000000000 -0400
27402+++ linux-3.0.4/drivers/media/dvb/frontends/mb86a16.c 2011-08-23 21:48:14.000000000 -0400
27403@@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16
27404 int ret = -1;
27405 int sync;
27406
27407+ pax_track_stack();
27408+
27409 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
27410
27411 fcp = 3000;
27412diff -urNp linux-3.0.4/drivers/media/dvb/frontends/or51211.c linux-3.0.4/drivers/media/dvb/frontends/or51211.c
27413--- linux-3.0.4/drivers/media/dvb/frontends/or51211.c 2011-07-21 22:17:23.000000000 -0400
27414+++ linux-3.0.4/drivers/media/dvb/frontends/or51211.c 2011-08-23 21:48:14.000000000 -0400
27415@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
27416 u8 tudata[585];
27417 int i;
27418
27419+ pax_track_stack();
27420+
27421 dprintk("Firmware is %zd bytes\n",fw->size);
27422
27423 /* Get eprom data */
27424diff -urNp linux-3.0.4/drivers/media/video/cx18/cx18-driver.c linux-3.0.4/drivers/media/video/cx18/cx18-driver.c
27425--- linux-3.0.4/drivers/media/video/cx18/cx18-driver.c 2011-07-21 22:17:23.000000000 -0400
27426+++ linux-3.0.4/drivers/media/video/cx18/cx18-driver.c 2011-08-23 21:48:14.000000000 -0400
27427@@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
27428 struct i2c_client c;
27429 u8 eedata[256];
27430
27431+ pax_track_stack();
27432+
27433 memset(&c, 0, sizeof(c));
27434 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
27435 c.adapter = &cx->i2c_adap[0];
27436diff -urNp linux-3.0.4/drivers/media/video/cx23885/cx23885-input.c linux-3.0.4/drivers/media/video/cx23885/cx23885-input.c
27437--- linux-3.0.4/drivers/media/video/cx23885/cx23885-input.c 2011-07-21 22:17:23.000000000 -0400
27438+++ linux-3.0.4/drivers/media/video/cx23885/cx23885-input.c 2011-08-23 21:48:14.000000000 -0400
27439@@ -53,6 +53,8 @@ static void cx23885_input_process_measur
27440 bool handle = false;
27441 struct ir_raw_event ir_core_event[64];
27442
27443+ pax_track_stack();
27444+
27445 do {
27446 num = 0;
27447 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
27448diff -urNp linux-3.0.4/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-3.0.4/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
27449--- linux-3.0.4/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-07-21 22:17:23.000000000 -0400
27450+++ linux-3.0.4/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-08-23 21:48:14.000000000 -0400
27451@@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
27452 u8 *eeprom;
27453 struct tveeprom tvdata;
27454
27455+ pax_track_stack();
27456+
27457 memset(&tvdata,0,sizeof(tvdata));
27458
27459 eeprom = pvr2_eeprom_fetch(hdw);
27460diff -urNp linux-3.0.4/drivers/media/video/saa7134/saa6752hs.c linux-3.0.4/drivers/media/video/saa7134/saa6752hs.c
27461--- linux-3.0.4/drivers/media/video/saa7134/saa6752hs.c 2011-07-21 22:17:23.000000000 -0400
27462+++ linux-3.0.4/drivers/media/video/saa7134/saa6752hs.c 2011-08-23 21:48:14.000000000 -0400
27463@@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_su
27464 unsigned char localPAT[256];
27465 unsigned char localPMT[256];
27466
27467+ pax_track_stack();
27468+
27469 /* Set video format - must be done first as it resets other settings */
27470 set_reg8(client, 0x41, h->video_format);
27471
27472diff -urNp linux-3.0.4/drivers/media/video/saa7164/saa7164-cmd.c linux-3.0.4/drivers/media/video/saa7164/saa7164-cmd.c
27473--- linux-3.0.4/drivers/media/video/saa7164/saa7164-cmd.c 2011-07-21 22:17:23.000000000 -0400
27474+++ linux-3.0.4/drivers/media/video/saa7164/saa7164-cmd.c 2011-08-23 21:48:14.000000000 -0400
27475@@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_d
27476 u8 tmp[512];
27477 dprintk(DBGLVL_CMD, "%s()\n", __func__);
27478
27479+ pax_track_stack();
27480+
27481 /* While any outstand message on the bus exists... */
27482 do {
27483
27484@@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
27485 u8 tmp[512];
27486 dprintk(DBGLVL_CMD, "%s()\n", __func__);
27487
27488+ pax_track_stack();
27489+
27490 while (loop) {
27491
27492 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
27493diff -urNp linux-3.0.4/drivers/media/video/timblogiw.c linux-3.0.4/drivers/media/video/timblogiw.c
27494--- linux-3.0.4/drivers/media/video/timblogiw.c 2011-07-21 22:17:23.000000000 -0400
27495+++ linux-3.0.4/drivers/media/video/timblogiw.c 2011-08-24 18:29:20.000000000 -0400
27496@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *f
27497
27498 /* Platform device functions */
27499
27500-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
27501+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
27502 .vidioc_querycap = timblogiw_querycap,
27503 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
27504 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
27505diff -urNp linux-3.0.4/drivers/media/video/usbvision/usbvision-core.c linux-3.0.4/drivers/media/video/usbvision/usbvision-core.c
27506--- linux-3.0.4/drivers/media/video/usbvision/usbvision-core.c 2011-07-21 22:17:23.000000000 -0400
27507+++ linux-3.0.4/drivers/media/video/usbvision/usbvision-core.c 2011-08-23 21:48:14.000000000 -0400
27508@@ -707,6 +707,8 @@ static enum parse_state usbvision_parse_
27509 unsigned char rv, gv, bv;
27510 static unsigned char *Y, *U, *V;
27511
27512+ pax_track_stack();
27513+
27514 frame = usbvision->cur_frame;
27515 image_size = frame->frmwidth * frame->frmheight;
27516 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
27517diff -urNp linux-3.0.4/drivers/media/video/videobuf-dma-sg.c linux-3.0.4/drivers/media/video/videobuf-dma-sg.c
27518--- linux-3.0.4/drivers/media/video/videobuf-dma-sg.c 2011-07-21 22:17:23.000000000 -0400
27519+++ linux-3.0.4/drivers/media/video/videobuf-dma-sg.c 2011-08-23 21:48:14.000000000 -0400
27520@@ -606,6 +606,8 @@ void *videobuf_sg_alloc(size_t size)
27521 {
27522 struct videobuf_queue q;
27523
27524+ pax_track_stack();
27525+
27526 /* Required to make generic handler to call __videobuf_alloc */
27527 q.int_ops = &sg_ops;
27528
27529diff -urNp linux-3.0.4/drivers/message/fusion/mptbase.c linux-3.0.4/drivers/message/fusion/mptbase.c
27530--- linux-3.0.4/drivers/message/fusion/mptbase.c 2011-07-21 22:17:23.000000000 -0400
27531+++ linux-3.0.4/drivers/message/fusion/mptbase.c 2011-08-23 21:48:14.000000000 -0400
27532@@ -6681,8 +6681,13 @@ static int mpt_iocinfo_proc_show(struct
27533 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
27534 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
27535
27536+#ifdef CONFIG_GRKERNSEC_HIDESYM
27537+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
27538+#else
27539 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
27540 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
27541+#endif
27542+
27543 /*
27544 * Rounding UP to nearest 4-kB boundary here...
27545 */
27546diff -urNp linux-3.0.4/drivers/message/fusion/mptsas.c linux-3.0.4/drivers/message/fusion/mptsas.c
27547--- linux-3.0.4/drivers/message/fusion/mptsas.c 2011-07-21 22:17:23.000000000 -0400
27548+++ linux-3.0.4/drivers/message/fusion/mptsas.c 2011-08-23 21:47:55.000000000 -0400
27549@@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
27550 return 0;
27551 }
27552
27553+static inline void
27554+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
27555+{
27556+ if (phy_info->port_details) {
27557+ phy_info->port_details->rphy = rphy;
27558+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
27559+ ioc->name, rphy));
27560+ }
27561+
27562+ if (rphy) {
27563+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
27564+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
27565+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
27566+ ioc->name, rphy, rphy->dev.release));
27567+ }
27568+}
27569+
27570 /* no mutex */
27571 static void
27572 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
27573@@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
27574 return NULL;
27575 }
27576
27577-static inline void
27578-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
27579-{
27580- if (phy_info->port_details) {
27581- phy_info->port_details->rphy = rphy;
27582- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
27583- ioc->name, rphy));
27584- }
27585-
27586- if (rphy) {
27587- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
27588- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
27589- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
27590- ioc->name, rphy, rphy->dev.release));
27591- }
27592-}
27593-
27594 static inline struct sas_port *
27595 mptsas_get_port(struct mptsas_phyinfo *phy_info)
27596 {
27597diff -urNp linux-3.0.4/drivers/message/fusion/mptscsih.c linux-3.0.4/drivers/message/fusion/mptscsih.c
27598--- linux-3.0.4/drivers/message/fusion/mptscsih.c 2011-07-21 22:17:23.000000000 -0400
27599+++ linux-3.0.4/drivers/message/fusion/mptscsih.c 2011-08-23 21:47:55.000000000 -0400
27600@@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
27601
27602 h = shost_priv(SChost);
27603
27604- if (h) {
27605- if (h->info_kbuf == NULL)
27606- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
27607- return h->info_kbuf;
27608- h->info_kbuf[0] = '\0';
27609+ if (!h)
27610+ return NULL;
27611
27612- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
27613- h->info_kbuf[size-1] = '\0';
27614- }
27615+ if (h->info_kbuf == NULL)
27616+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
27617+ return h->info_kbuf;
27618+ h->info_kbuf[0] = '\0';
27619+
27620+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
27621+ h->info_kbuf[size-1] = '\0';
27622
27623 return h->info_kbuf;
27624 }
27625diff -urNp linux-3.0.4/drivers/message/i2o/i2o_config.c linux-3.0.4/drivers/message/i2o/i2o_config.c
27626--- linux-3.0.4/drivers/message/i2o/i2o_config.c 2011-07-21 22:17:23.000000000 -0400
27627+++ linux-3.0.4/drivers/message/i2o/i2o_config.c 2011-08-23 21:48:14.000000000 -0400
27628@@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned lon
27629 struct i2o_message *msg;
27630 unsigned int iop;
27631
27632+ pax_track_stack();
27633+
27634 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
27635 return -EFAULT;
27636
27637diff -urNp linux-3.0.4/drivers/message/i2o/i2o_proc.c linux-3.0.4/drivers/message/i2o/i2o_proc.c
27638--- linux-3.0.4/drivers/message/i2o/i2o_proc.c 2011-07-21 22:17:23.000000000 -0400
27639+++ linux-3.0.4/drivers/message/i2o/i2o_proc.c 2011-08-23 21:47:55.000000000 -0400
27640@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
27641 "Array Controller Device"
27642 };
27643
27644-static char *chtostr(u8 * chars, int n)
27645-{
27646- char tmp[256];
27647- tmp[0] = 0;
27648- return strncat(tmp, (char *)chars, n);
27649-}
27650-
27651 static int i2o_report_query_status(struct seq_file *seq, int block_status,
27652 char *group)
27653 {
27654@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
27655
27656 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
27657 seq_printf(seq, "%-#8x", ddm_table.module_id);
27658- seq_printf(seq, "%-29s",
27659- chtostr(ddm_table.module_name_version, 28));
27660+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
27661 seq_printf(seq, "%9d ", ddm_table.data_size);
27662 seq_printf(seq, "%8d", ddm_table.code_size);
27663
27664@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
27665
27666 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
27667 seq_printf(seq, "%-#8x", dst->module_id);
27668- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
27669- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
27670+ seq_printf(seq, "%-.28s", dst->module_name_version);
27671+ seq_printf(seq, "%-.8s", dst->date);
27672 seq_printf(seq, "%8d ", dst->module_size);
27673 seq_printf(seq, "%8d ", dst->mpb_size);
27674 seq_printf(seq, "0x%04x", dst->module_flags);
27675@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
27676 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
27677 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
27678 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
27679- seq_printf(seq, "Vendor info : %s\n",
27680- chtostr((u8 *) (work32 + 2), 16));
27681- seq_printf(seq, "Product info : %s\n",
27682- chtostr((u8 *) (work32 + 6), 16));
27683- seq_printf(seq, "Description : %s\n",
27684- chtostr((u8 *) (work32 + 10), 16));
27685- seq_printf(seq, "Product rev. : %s\n",
27686- chtostr((u8 *) (work32 + 14), 8));
27687+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
27688+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
27689+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
27690+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
27691
27692 seq_printf(seq, "Serial number : ");
27693 print_serial_number(seq, (u8 *) (work32 + 16),
27694@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
27695 }
27696
27697 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
27698- seq_printf(seq, "Module name : %s\n",
27699- chtostr(result.module_name, 24));
27700- seq_printf(seq, "Module revision : %s\n",
27701- chtostr(result.module_rev, 8));
27702+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
27703+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
27704
27705 seq_printf(seq, "Serial number : ");
27706 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
27707@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
27708 return 0;
27709 }
27710
27711- seq_printf(seq, "Device name : %s\n",
27712- chtostr(result.device_name, 64));
27713- seq_printf(seq, "Service name : %s\n",
27714- chtostr(result.service_name, 64));
27715- seq_printf(seq, "Physical name : %s\n",
27716- chtostr(result.physical_location, 64));
27717- seq_printf(seq, "Instance number : %s\n",
27718- chtostr(result.instance_number, 4));
27719+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
27720+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
27721+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
27722+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
27723
27724 return 0;
27725 }
27726diff -urNp linux-3.0.4/drivers/message/i2o/iop.c linux-3.0.4/drivers/message/i2o/iop.c
27727--- linux-3.0.4/drivers/message/i2o/iop.c 2011-07-21 22:17:23.000000000 -0400
27728+++ linux-3.0.4/drivers/message/i2o/iop.c 2011-08-23 21:47:55.000000000 -0400
27729@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
27730
27731 spin_lock_irqsave(&c->context_list_lock, flags);
27732
27733- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
27734- atomic_inc(&c->context_list_counter);
27735+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
27736+ atomic_inc_unchecked(&c->context_list_counter);
27737
27738- entry->context = atomic_read(&c->context_list_counter);
27739+ entry->context = atomic_read_unchecked(&c->context_list_counter);
27740
27741 list_add(&entry->list, &c->context_list);
27742
27743@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(voi
27744
27745 #if BITS_PER_LONG == 64
27746 spin_lock_init(&c->context_list_lock);
27747- atomic_set(&c->context_list_counter, 0);
27748+ atomic_set_unchecked(&c->context_list_counter, 0);
27749 INIT_LIST_HEAD(&c->context_list);
27750 #endif
27751
27752diff -urNp linux-3.0.4/drivers/mfd/abx500-core.c linux-3.0.4/drivers/mfd/abx500-core.c
27753--- linux-3.0.4/drivers/mfd/abx500-core.c 2011-07-21 22:17:23.000000000 -0400
27754+++ linux-3.0.4/drivers/mfd/abx500-core.c 2011-08-23 21:47:55.000000000 -0400
27755@@ -14,7 +14,7 @@ static LIST_HEAD(abx500_list);
27756
27757 struct abx500_device_entry {
27758 struct list_head list;
27759- struct abx500_ops ops;
27760+ abx500_ops_no_const ops;
27761 struct device *dev;
27762 };
27763
27764diff -urNp linux-3.0.4/drivers/mfd/janz-cmodio.c linux-3.0.4/drivers/mfd/janz-cmodio.c
27765--- linux-3.0.4/drivers/mfd/janz-cmodio.c 2011-07-21 22:17:23.000000000 -0400
27766+++ linux-3.0.4/drivers/mfd/janz-cmodio.c 2011-08-23 21:47:55.000000000 -0400
27767@@ -13,6 +13,7 @@
27768
27769 #include <linux/kernel.h>
27770 #include <linux/module.h>
27771+#include <linux/slab.h>
27772 #include <linux/init.h>
27773 #include <linux/pci.h>
27774 #include <linux/interrupt.h>
27775diff -urNp linux-3.0.4/drivers/mfd/wm8350-i2c.c linux-3.0.4/drivers/mfd/wm8350-i2c.c
27776--- linux-3.0.4/drivers/mfd/wm8350-i2c.c 2011-07-21 22:17:23.000000000 -0400
27777+++ linux-3.0.4/drivers/mfd/wm8350-i2c.c 2011-08-23 21:48:14.000000000 -0400
27778@@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struc
27779 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
27780 int ret;
27781
27782+ pax_track_stack();
27783+
27784 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
27785 return -EINVAL;
27786
27787diff -urNp linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.c linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.c
27788--- linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.c 2011-07-21 22:17:23.000000000 -0400
27789+++ linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.c 2011-08-23 21:47:55.000000000 -0400
27790@@ -435,7 +435,7 @@ static irqreturn_t lis302dl_interrupt(in
27791 * the lid is closed. This leads to interrupts as soon as a little move
27792 * is done.
27793 */
27794- atomic_inc(&lis3_dev.count);
27795+ atomic_inc_unchecked(&lis3_dev.count);
27796
27797 wake_up_interruptible(&lis3_dev.misc_wait);
27798 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
27799@@ -518,7 +518,7 @@ static int lis3lv02d_misc_open(struct in
27800 if (lis3_dev.pm_dev)
27801 pm_runtime_get_sync(lis3_dev.pm_dev);
27802
27803- atomic_set(&lis3_dev.count, 0);
27804+ atomic_set_unchecked(&lis3_dev.count, 0);
27805 return 0;
27806 }
27807
27808@@ -545,7 +545,7 @@ static ssize_t lis3lv02d_misc_read(struc
27809 add_wait_queue(&lis3_dev.misc_wait, &wait);
27810 while (true) {
27811 set_current_state(TASK_INTERRUPTIBLE);
27812- data = atomic_xchg(&lis3_dev.count, 0);
27813+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
27814 if (data)
27815 break;
27816
27817@@ -583,7 +583,7 @@ out:
27818 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
27819 {
27820 poll_wait(file, &lis3_dev.misc_wait, wait);
27821- if (atomic_read(&lis3_dev.count))
27822+ if (atomic_read_unchecked(&lis3_dev.count))
27823 return POLLIN | POLLRDNORM;
27824 return 0;
27825 }
27826diff -urNp linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.h linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.h
27827--- linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.h 2011-07-21 22:17:23.000000000 -0400
27828+++ linux-3.0.4/drivers/misc/lis3lv02d/lis3lv02d.h 2011-08-23 21:47:55.000000000 -0400
27829@@ -265,7 +265,7 @@ struct lis3lv02d {
27830 struct input_polled_dev *idev; /* input device */
27831 struct platform_device *pdev; /* platform device */
27832 struct regulator_bulk_data regulators[2];
27833- atomic_t count; /* interrupt count after last read */
27834+ atomic_unchecked_t count; /* interrupt count after last read */
27835 union axis_conversion ac; /* hw -> logical axis */
27836 int mapped_btns[3];
27837
27838diff -urNp linux-3.0.4/drivers/misc/sgi-gru/gruhandles.c linux-3.0.4/drivers/misc/sgi-gru/gruhandles.c
27839--- linux-3.0.4/drivers/misc/sgi-gru/gruhandles.c 2011-07-21 22:17:23.000000000 -0400
27840+++ linux-3.0.4/drivers/misc/sgi-gru/gruhandles.c 2011-08-23 21:47:55.000000000 -0400
27841@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
27842 unsigned long nsec;
27843
27844 nsec = CLKS2NSEC(clks);
27845- atomic_long_inc(&mcs_op_statistics[op].count);
27846- atomic_long_add(nsec, &mcs_op_statistics[op].total);
27847+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
27848+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
27849 if (mcs_op_statistics[op].max < nsec)
27850 mcs_op_statistics[op].max = nsec;
27851 }
27852diff -urNp linux-3.0.4/drivers/misc/sgi-gru/gruprocfs.c linux-3.0.4/drivers/misc/sgi-gru/gruprocfs.c
27853--- linux-3.0.4/drivers/misc/sgi-gru/gruprocfs.c 2011-07-21 22:17:23.000000000 -0400
27854+++ linux-3.0.4/drivers/misc/sgi-gru/gruprocfs.c 2011-08-23 21:47:55.000000000 -0400
27855@@ -32,9 +32,9 @@
27856
27857 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
27858
27859-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
27860+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
27861 {
27862- unsigned long val = atomic_long_read(v);
27863+ unsigned long val = atomic_long_read_unchecked(v);
27864
27865 seq_printf(s, "%16lu %s\n", val, id);
27866 }
27867@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
27868
27869 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
27870 for (op = 0; op < mcsop_last; op++) {
27871- count = atomic_long_read(&mcs_op_statistics[op].count);
27872- total = atomic_long_read(&mcs_op_statistics[op].total);
27873+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
27874+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
27875 max = mcs_op_statistics[op].max;
27876 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
27877 count ? total / count : 0, max);
27878diff -urNp linux-3.0.4/drivers/misc/sgi-gru/grutables.h linux-3.0.4/drivers/misc/sgi-gru/grutables.h
27879--- linux-3.0.4/drivers/misc/sgi-gru/grutables.h 2011-07-21 22:17:23.000000000 -0400
27880+++ linux-3.0.4/drivers/misc/sgi-gru/grutables.h 2011-08-23 21:47:55.000000000 -0400
27881@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
27882 * GRU statistics.
27883 */
27884 struct gru_stats_s {
27885- atomic_long_t vdata_alloc;
27886- atomic_long_t vdata_free;
27887- atomic_long_t gts_alloc;
27888- atomic_long_t gts_free;
27889- atomic_long_t gms_alloc;
27890- atomic_long_t gms_free;
27891- atomic_long_t gts_double_allocate;
27892- atomic_long_t assign_context;
27893- atomic_long_t assign_context_failed;
27894- atomic_long_t free_context;
27895- atomic_long_t load_user_context;
27896- atomic_long_t load_kernel_context;
27897- atomic_long_t lock_kernel_context;
27898- atomic_long_t unlock_kernel_context;
27899- atomic_long_t steal_user_context;
27900- atomic_long_t steal_kernel_context;
27901- atomic_long_t steal_context_failed;
27902- atomic_long_t nopfn;
27903- atomic_long_t asid_new;
27904- atomic_long_t asid_next;
27905- atomic_long_t asid_wrap;
27906- atomic_long_t asid_reuse;
27907- atomic_long_t intr;
27908- atomic_long_t intr_cbr;
27909- atomic_long_t intr_tfh;
27910- atomic_long_t intr_spurious;
27911- atomic_long_t intr_mm_lock_failed;
27912- atomic_long_t call_os;
27913- atomic_long_t call_os_wait_queue;
27914- atomic_long_t user_flush_tlb;
27915- atomic_long_t user_unload_context;
27916- atomic_long_t user_exception;
27917- atomic_long_t set_context_option;
27918- atomic_long_t check_context_retarget_intr;
27919- atomic_long_t check_context_unload;
27920- atomic_long_t tlb_dropin;
27921- atomic_long_t tlb_preload_page;
27922- atomic_long_t tlb_dropin_fail_no_asid;
27923- atomic_long_t tlb_dropin_fail_upm;
27924- atomic_long_t tlb_dropin_fail_invalid;
27925- atomic_long_t tlb_dropin_fail_range_active;
27926- atomic_long_t tlb_dropin_fail_idle;
27927- atomic_long_t tlb_dropin_fail_fmm;
27928- atomic_long_t tlb_dropin_fail_no_exception;
27929- atomic_long_t tfh_stale_on_fault;
27930- atomic_long_t mmu_invalidate_range;
27931- atomic_long_t mmu_invalidate_page;
27932- atomic_long_t flush_tlb;
27933- atomic_long_t flush_tlb_gru;
27934- atomic_long_t flush_tlb_gru_tgh;
27935- atomic_long_t flush_tlb_gru_zero_asid;
27936-
27937- atomic_long_t copy_gpa;
27938- atomic_long_t read_gpa;
27939-
27940- atomic_long_t mesq_receive;
27941- atomic_long_t mesq_receive_none;
27942- atomic_long_t mesq_send;
27943- atomic_long_t mesq_send_failed;
27944- atomic_long_t mesq_noop;
27945- atomic_long_t mesq_send_unexpected_error;
27946- atomic_long_t mesq_send_lb_overflow;
27947- atomic_long_t mesq_send_qlimit_reached;
27948- atomic_long_t mesq_send_amo_nacked;
27949- atomic_long_t mesq_send_put_nacked;
27950- atomic_long_t mesq_page_overflow;
27951- atomic_long_t mesq_qf_locked;
27952- atomic_long_t mesq_qf_noop_not_full;
27953- atomic_long_t mesq_qf_switch_head_failed;
27954- atomic_long_t mesq_qf_unexpected_error;
27955- atomic_long_t mesq_noop_unexpected_error;
27956- atomic_long_t mesq_noop_lb_overflow;
27957- atomic_long_t mesq_noop_qlimit_reached;
27958- atomic_long_t mesq_noop_amo_nacked;
27959- atomic_long_t mesq_noop_put_nacked;
27960- atomic_long_t mesq_noop_page_overflow;
27961+ atomic_long_unchecked_t vdata_alloc;
27962+ atomic_long_unchecked_t vdata_free;
27963+ atomic_long_unchecked_t gts_alloc;
27964+ atomic_long_unchecked_t gts_free;
27965+ atomic_long_unchecked_t gms_alloc;
27966+ atomic_long_unchecked_t gms_free;
27967+ atomic_long_unchecked_t gts_double_allocate;
27968+ atomic_long_unchecked_t assign_context;
27969+ atomic_long_unchecked_t assign_context_failed;
27970+ atomic_long_unchecked_t free_context;
27971+ atomic_long_unchecked_t load_user_context;
27972+ atomic_long_unchecked_t load_kernel_context;
27973+ atomic_long_unchecked_t lock_kernel_context;
27974+ atomic_long_unchecked_t unlock_kernel_context;
27975+ atomic_long_unchecked_t steal_user_context;
27976+ atomic_long_unchecked_t steal_kernel_context;
27977+ atomic_long_unchecked_t steal_context_failed;
27978+ atomic_long_unchecked_t nopfn;
27979+ atomic_long_unchecked_t asid_new;
27980+ atomic_long_unchecked_t asid_next;
27981+ atomic_long_unchecked_t asid_wrap;
27982+ atomic_long_unchecked_t asid_reuse;
27983+ atomic_long_unchecked_t intr;
27984+ atomic_long_unchecked_t intr_cbr;
27985+ atomic_long_unchecked_t intr_tfh;
27986+ atomic_long_unchecked_t intr_spurious;
27987+ atomic_long_unchecked_t intr_mm_lock_failed;
27988+ atomic_long_unchecked_t call_os;
27989+ atomic_long_unchecked_t call_os_wait_queue;
27990+ atomic_long_unchecked_t user_flush_tlb;
27991+ atomic_long_unchecked_t user_unload_context;
27992+ atomic_long_unchecked_t user_exception;
27993+ atomic_long_unchecked_t set_context_option;
27994+ atomic_long_unchecked_t check_context_retarget_intr;
27995+ atomic_long_unchecked_t check_context_unload;
27996+ atomic_long_unchecked_t tlb_dropin;
27997+ atomic_long_unchecked_t tlb_preload_page;
27998+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
27999+ atomic_long_unchecked_t tlb_dropin_fail_upm;
28000+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
28001+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
28002+ atomic_long_unchecked_t tlb_dropin_fail_idle;
28003+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
28004+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
28005+ atomic_long_unchecked_t tfh_stale_on_fault;
28006+ atomic_long_unchecked_t mmu_invalidate_range;
28007+ atomic_long_unchecked_t mmu_invalidate_page;
28008+ atomic_long_unchecked_t flush_tlb;
28009+ atomic_long_unchecked_t flush_tlb_gru;
28010+ atomic_long_unchecked_t flush_tlb_gru_tgh;
28011+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
28012+
28013+ atomic_long_unchecked_t copy_gpa;
28014+ atomic_long_unchecked_t read_gpa;
28015+
28016+ atomic_long_unchecked_t mesq_receive;
28017+ atomic_long_unchecked_t mesq_receive_none;
28018+ atomic_long_unchecked_t mesq_send;
28019+ atomic_long_unchecked_t mesq_send_failed;
28020+ atomic_long_unchecked_t mesq_noop;
28021+ atomic_long_unchecked_t mesq_send_unexpected_error;
28022+ atomic_long_unchecked_t mesq_send_lb_overflow;
28023+ atomic_long_unchecked_t mesq_send_qlimit_reached;
28024+ atomic_long_unchecked_t mesq_send_amo_nacked;
28025+ atomic_long_unchecked_t mesq_send_put_nacked;
28026+ atomic_long_unchecked_t mesq_page_overflow;
28027+ atomic_long_unchecked_t mesq_qf_locked;
28028+ atomic_long_unchecked_t mesq_qf_noop_not_full;
28029+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
28030+ atomic_long_unchecked_t mesq_qf_unexpected_error;
28031+ atomic_long_unchecked_t mesq_noop_unexpected_error;
28032+ atomic_long_unchecked_t mesq_noop_lb_overflow;
28033+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
28034+ atomic_long_unchecked_t mesq_noop_amo_nacked;
28035+ atomic_long_unchecked_t mesq_noop_put_nacked;
28036+ atomic_long_unchecked_t mesq_noop_page_overflow;
28037
28038 };
28039
28040@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
28041 tghop_invalidate, mcsop_last};
28042
28043 struct mcs_op_statistic {
28044- atomic_long_t count;
28045- atomic_long_t total;
28046+ atomic_long_unchecked_t count;
28047+ atomic_long_unchecked_t total;
28048 unsigned long max;
28049 };
28050
28051@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
28052
28053 #define STAT(id) do { \
28054 if (gru_options & OPT_STATS) \
28055- atomic_long_inc(&gru_stats.id); \
28056+ atomic_long_inc_unchecked(&gru_stats.id); \
28057 } while (0)
28058
28059 #ifdef CONFIG_SGI_GRU_DEBUG
28060diff -urNp linux-3.0.4/drivers/misc/sgi-xp/xp.h linux-3.0.4/drivers/misc/sgi-xp/xp.h
28061--- linux-3.0.4/drivers/misc/sgi-xp/xp.h 2011-07-21 22:17:23.000000000 -0400
28062+++ linux-3.0.4/drivers/misc/sgi-xp/xp.h 2011-08-23 21:47:55.000000000 -0400
28063@@ -289,7 +289,7 @@ struct xpc_interface {
28064 xpc_notify_func, void *);
28065 void (*received) (short, int, void *);
28066 enum xp_retval (*partid_to_nasids) (short, void *);
28067-};
28068+} __no_const;
28069
28070 extern struct xpc_interface xpc_interface;
28071
28072diff -urNp linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0001.c linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0001.c
28073--- linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0001.c 2011-07-21 22:17:23.000000000 -0400
28074+++ linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0001.c 2011-08-23 21:48:14.000000000 -0400
28075@@ -757,6 +757,8 @@ static int chip_ready (struct map_info *
28076 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
28077 unsigned long timeo = jiffies + HZ;
28078
28079+ pax_track_stack();
28080+
28081 /* Prevent setting state FL_SYNCING for chip in suspended state. */
28082 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
28083 goto sleep;
28084@@ -1653,6 +1655,8 @@ static int __xipram do_write_buffer(stru
28085 unsigned long initial_adr;
28086 int initial_len = len;
28087
28088+ pax_track_stack();
28089+
28090 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
28091 adr += chip->start;
28092 initial_adr = adr;
28093@@ -1871,6 +1875,8 @@ static int __xipram do_erase_oneblock(st
28094 int retries = 3;
28095 int ret;
28096
28097+ pax_track_stack();
28098+
28099 adr += chip->start;
28100
28101 retry:
28102diff -urNp linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0020.c linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0020.c
28103--- linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0020.c 2011-07-21 22:17:23.000000000 -0400
28104+++ linux-3.0.4/drivers/mtd/chips/cfi_cmdset_0020.c 2011-08-23 21:48:14.000000000 -0400
28105@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
28106 unsigned long cmd_addr;
28107 struct cfi_private *cfi = map->fldrv_priv;
28108
28109+ pax_track_stack();
28110+
28111 adr += chip->start;
28112
28113 /* Ensure cmd read/writes are aligned. */
28114@@ -429,6 +431,8 @@ static inline int do_write_buffer(struct
28115 DECLARE_WAITQUEUE(wait, current);
28116 int wbufsize, z;
28117
28118+ pax_track_stack();
28119+
28120 /* M58LW064A requires bus alignment for buffer wriets -- saw */
28121 if (adr & (map_bankwidth(map)-1))
28122 return -EINVAL;
28123@@ -743,6 +747,8 @@ static inline int do_erase_oneblock(stru
28124 DECLARE_WAITQUEUE(wait, current);
28125 int ret = 0;
28126
28127+ pax_track_stack();
28128+
28129 adr += chip->start;
28130
28131 /* Let's determine this according to the interleave only once */
28132@@ -1048,6 +1054,8 @@ static inline int do_lock_oneblock(struc
28133 unsigned long timeo = jiffies + HZ;
28134 DECLARE_WAITQUEUE(wait, current);
28135
28136+ pax_track_stack();
28137+
28138 adr += chip->start;
28139
28140 /* Let's determine this according to the interleave only once */
28141@@ -1197,6 +1205,8 @@ static inline int do_unlock_oneblock(str
28142 unsigned long timeo = jiffies + HZ;
28143 DECLARE_WAITQUEUE(wait, current);
28144
28145+ pax_track_stack();
28146+
28147 adr += chip->start;
28148
28149 /* Let's determine this according to the interleave only once */
28150diff -urNp linux-3.0.4/drivers/mtd/devices/doc2000.c linux-3.0.4/drivers/mtd/devices/doc2000.c
28151--- linux-3.0.4/drivers/mtd/devices/doc2000.c 2011-07-21 22:17:23.000000000 -0400
28152+++ linux-3.0.4/drivers/mtd/devices/doc2000.c 2011-08-23 21:47:55.000000000 -0400
28153@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
28154
28155 /* The ECC will not be calculated correctly if less than 512 is written */
28156 /* DBB-
28157- if (len != 0x200 && eccbuf)
28158+ if (len != 0x200)
28159 printk(KERN_WARNING
28160 "ECC needs a full sector write (adr: %lx size %lx)\n",
28161 (long) to, (long) len);
28162diff -urNp linux-3.0.4/drivers/mtd/devices/doc2001.c linux-3.0.4/drivers/mtd/devices/doc2001.c
28163--- linux-3.0.4/drivers/mtd/devices/doc2001.c 2011-07-21 22:17:23.000000000 -0400
28164+++ linux-3.0.4/drivers/mtd/devices/doc2001.c 2011-08-23 21:47:55.000000000 -0400
28165@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
28166 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
28167
28168 /* Don't allow read past end of device */
28169- if (from >= this->totlen)
28170+ if (from >= this->totlen || !len)
28171 return -EINVAL;
28172
28173 /* Don't allow a single read to cross a 512-byte block boundary */
28174diff -urNp linux-3.0.4/drivers/mtd/ftl.c linux-3.0.4/drivers/mtd/ftl.c
28175--- linux-3.0.4/drivers/mtd/ftl.c 2011-07-21 22:17:23.000000000 -0400
28176+++ linux-3.0.4/drivers/mtd/ftl.c 2011-08-23 21:48:14.000000000 -0400
28177@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
28178 loff_t offset;
28179 uint16_t srcunitswap = cpu_to_le16(srcunit);
28180
28181+ pax_track_stack();
28182+
28183 eun = &part->EUNInfo[srcunit];
28184 xfer = &part->XferInfo[xferunit];
28185 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
28186diff -urNp linux-3.0.4/drivers/mtd/inftlcore.c linux-3.0.4/drivers/mtd/inftlcore.c
28187--- linux-3.0.4/drivers/mtd/inftlcore.c 2011-07-21 22:17:23.000000000 -0400
28188+++ linux-3.0.4/drivers/mtd/inftlcore.c 2011-08-23 21:48:14.000000000 -0400
28189@@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLr
28190 struct inftl_oob oob;
28191 size_t retlen;
28192
28193+ pax_track_stack();
28194+
28195 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
28196 "pending=%d)\n", inftl, thisVUC, pendingblock);
28197
28198diff -urNp linux-3.0.4/drivers/mtd/inftlmount.c linux-3.0.4/drivers/mtd/inftlmount.c
28199--- linux-3.0.4/drivers/mtd/inftlmount.c 2011-07-21 22:17:23.000000000 -0400
28200+++ linux-3.0.4/drivers/mtd/inftlmount.c 2011-08-23 21:48:14.000000000 -0400
28201@@ -53,6 +53,8 @@ static int find_boot_record(struct INFTL
28202 struct INFTLPartition *ip;
28203 size_t retlen;
28204
28205+ pax_track_stack();
28206+
28207 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
28208
28209 /*
28210diff -urNp linux-3.0.4/drivers/mtd/lpddr/qinfo_probe.c linux-3.0.4/drivers/mtd/lpddr/qinfo_probe.c
28211--- linux-3.0.4/drivers/mtd/lpddr/qinfo_probe.c 2011-07-21 22:17:23.000000000 -0400
28212+++ linux-3.0.4/drivers/mtd/lpddr/qinfo_probe.c 2011-08-23 21:48:14.000000000 -0400
28213@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
28214 {
28215 map_word pfow_val[4];
28216
28217+ pax_track_stack();
28218+
28219 /* Check identification string */
28220 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
28221 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
28222diff -urNp linux-3.0.4/drivers/mtd/mtdchar.c linux-3.0.4/drivers/mtd/mtdchar.c
28223--- linux-3.0.4/drivers/mtd/mtdchar.c 2011-07-21 22:17:23.000000000 -0400
28224+++ linux-3.0.4/drivers/mtd/mtdchar.c 2011-08-23 21:48:14.000000000 -0400
28225@@ -553,6 +553,8 @@ static int mtd_ioctl(struct file *file,
28226 u_long size;
28227 struct mtd_info_user info;
28228
28229+ pax_track_stack();
28230+
28231 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
28232
28233 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
28234diff -urNp linux-3.0.4/drivers/mtd/nand/denali.c linux-3.0.4/drivers/mtd/nand/denali.c
28235--- linux-3.0.4/drivers/mtd/nand/denali.c 2011-07-21 22:17:23.000000000 -0400
28236+++ linux-3.0.4/drivers/mtd/nand/denali.c 2011-08-23 21:47:55.000000000 -0400
28237@@ -26,6 +26,7 @@
28238 #include <linux/pci.h>
28239 #include <linux/mtd/mtd.h>
28240 #include <linux/module.h>
28241+#include <linux/slab.h>
28242
28243 #include "denali.h"
28244
28245diff -urNp linux-3.0.4/drivers/mtd/nftlcore.c linux-3.0.4/drivers/mtd/nftlcore.c
28246--- linux-3.0.4/drivers/mtd/nftlcore.c 2011-07-21 22:17:23.000000000 -0400
28247+++ linux-3.0.4/drivers/mtd/nftlcore.c 2011-08-23 21:48:14.000000000 -0400
28248@@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLre
28249 int inplace = 1;
28250 size_t retlen;
28251
28252+ pax_track_stack();
28253+
28254 memset(BlockMap, 0xff, sizeof(BlockMap));
28255 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
28256
28257diff -urNp linux-3.0.4/drivers/mtd/nftlmount.c linux-3.0.4/drivers/mtd/nftlmount.c
28258--- linux-3.0.4/drivers/mtd/nftlmount.c 2011-07-21 22:17:23.000000000 -0400
28259+++ linux-3.0.4/drivers/mtd/nftlmount.c 2011-08-23 21:48:14.000000000 -0400
28260@@ -24,6 +24,7 @@
28261 #include <asm/errno.h>
28262 #include <linux/delay.h>
28263 #include <linux/slab.h>
28264+#include <linux/sched.h>
28265 #include <linux/mtd/mtd.h>
28266 #include <linux/mtd/nand.h>
28267 #include <linux/mtd/nftl.h>
28268@@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLr
28269 struct mtd_info *mtd = nftl->mbd.mtd;
28270 unsigned int i;
28271
28272+ pax_track_stack();
28273+
28274 /* Assume logical EraseSize == physical erasesize for starting the scan.
28275 We'll sort it out later if we find a MediaHeader which says otherwise */
28276 /* Actually, we won't. The new DiskOnChip driver has already scanned
28277diff -urNp linux-3.0.4/drivers/mtd/ubi/build.c linux-3.0.4/drivers/mtd/ubi/build.c
28278--- linux-3.0.4/drivers/mtd/ubi/build.c 2011-07-21 22:17:23.000000000 -0400
28279+++ linux-3.0.4/drivers/mtd/ubi/build.c 2011-08-23 21:47:55.000000000 -0400
28280@@ -1287,7 +1287,7 @@ module_exit(ubi_exit);
28281 static int __init bytes_str_to_int(const char *str)
28282 {
28283 char *endp;
28284- unsigned long result;
28285+ unsigned long result, scale = 1;
28286
28287 result = simple_strtoul(str, &endp, 0);
28288 if (str == endp || result >= INT_MAX) {
28289@@ -1298,11 +1298,11 @@ static int __init bytes_str_to_int(const
28290
28291 switch (*endp) {
28292 case 'G':
28293- result *= 1024;
28294+ scale *= 1024;
28295 case 'M':
28296- result *= 1024;
28297+ scale *= 1024;
28298 case 'K':
28299- result *= 1024;
28300+ scale *= 1024;
28301 if (endp[1] == 'i' && endp[2] == 'B')
28302 endp += 2;
28303 case '\0':
28304@@ -1313,7 +1313,13 @@ static int __init bytes_str_to_int(const
28305 return -EINVAL;
28306 }
28307
28308- return result;
28309+ if ((intoverflow_t)result*scale >= INT_MAX) {
28310+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
28311+ str);
28312+ return -EINVAL;
28313+ }
28314+
28315+ return result*scale;
28316 }
28317
28318 /**
28319diff -urNp linux-3.0.4/drivers/net/bna/bfa_ioc_ct.c linux-3.0.4/drivers/net/bna/bfa_ioc_ct.c
28320--- linux-3.0.4/drivers/net/bna/bfa_ioc_ct.c 2011-07-21 22:17:23.000000000 -0400
28321+++ linux-3.0.4/drivers/net/bna/bfa_ioc_ct.c 2011-08-23 21:47:55.000000000 -0400
28322@@ -48,7 +48,21 @@ static void bfa_ioc_ct_sync_ack(struct b
28323 static bool bfa_ioc_ct_sync_complete(struct bfa_ioc *ioc);
28324 static enum bfa_status bfa_ioc_ct_pll_init(void __iomem *rb, bool fcmode);
28325
28326-static struct bfa_ioc_hwif nw_hwif_ct;
28327+static struct bfa_ioc_hwif nw_hwif_ct = {
28328+ .ioc_pll_init = bfa_ioc_ct_pll_init,
28329+ .ioc_firmware_lock = bfa_ioc_ct_firmware_lock,
28330+ .ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock,
28331+ .ioc_reg_init = bfa_ioc_ct_reg_init,
28332+ .ioc_map_port = bfa_ioc_ct_map_port,
28333+ .ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set,
28334+ .ioc_notify_fail = bfa_ioc_ct_notify_fail,
28335+ .ioc_ownership_reset = bfa_ioc_ct_ownership_reset,
28336+ .ioc_sync_start = bfa_ioc_ct_sync_start,
28337+ .ioc_sync_join = bfa_ioc_ct_sync_join,
28338+ .ioc_sync_leave = bfa_ioc_ct_sync_leave,
28339+ .ioc_sync_ack = bfa_ioc_ct_sync_ack,
28340+ .ioc_sync_complete = bfa_ioc_ct_sync_complete
28341+};
28342
28343 /**
28344 * Called from bfa_ioc_attach() to map asic specific calls.
28345@@ -56,20 +70,6 @@ static struct bfa_ioc_hwif nw_hwif_ct;
28346 void
28347 bfa_nw_ioc_set_ct_hwif(struct bfa_ioc *ioc)
28348 {
28349- nw_hwif_ct.ioc_pll_init = bfa_ioc_ct_pll_init;
28350- nw_hwif_ct.ioc_firmware_lock = bfa_ioc_ct_firmware_lock;
28351- nw_hwif_ct.ioc_firmware_unlock = bfa_ioc_ct_firmware_unlock;
28352- nw_hwif_ct.ioc_reg_init = bfa_ioc_ct_reg_init;
28353- nw_hwif_ct.ioc_map_port = bfa_ioc_ct_map_port;
28354- nw_hwif_ct.ioc_isr_mode_set = bfa_ioc_ct_isr_mode_set;
28355- nw_hwif_ct.ioc_notify_fail = bfa_ioc_ct_notify_fail;
28356- nw_hwif_ct.ioc_ownership_reset = bfa_ioc_ct_ownership_reset;
28357- nw_hwif_ct.ioc_sync_start = bfa_ioc_ct_sync_start;
28358- nw_hwif_ct.ioc_sync_join = bfa_ioc_ct_sync_join;
28359- nw_hwif_ct.ioc_sync_leave = bfa_ioc_ct_sync_leave;
28360- nw_hwif_ct.ioc_sync_ack = bfa_ioc_ct_sync_ack;
28361- nw_hwif_ct.ioc_sync_complete = bfa_ioc_ct_sync_complete;
28362-
28363 ioc->ioc_hwif = &nw_hwif_ct;
28364 }
28365
28366diff -urNp linux-3.0.4/drivers/net/bna/bnad.c linux-3.0.4/drivers/net/bna/bnad.c
28367--- linux-3.0.4/drivers/net/bna/bnad.c 2011-07-21 22:17:23.000000000 -0400
28368+++ linux-3.0.4/drivers/net/bna/bnad.c 2011-08-23 21:47:55.000000000 -0400
28369@@ -1681,7 +1681,14 @@ bnad_setup_tx(struct bnad *bnad, uint tx
28370 struct bna_intr_info *intr_info =
28371 &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
28372 struct bna_tx_config *tx_config = &bnad->tx_config[tx_id];
28373- struct bna_tx_event_cbfn tx_cbfn;
28374+ static struct bna_tx_event_cbfn tx_cbfn = {
28375+ /* Initialize the tx event handlers */
28376+ .tcb_setup_cbfn = bnad_cb_tcb_setup,
28377+ .tcb_destroy_cbfn = bnad_cb_tcb_destroy,
28378+ .tx_stall_cbfn = bnad_cb_tx_stall,
28379+ .tx_resume_cbfn = bnad_cb_tx_resume,
28380+ .tx_cleanup_cbfn = bnad_cb_tx_cleanup
28381+ };
28382 struct bna_tx *tx;
28383 unsigned long flags;
28384
28385@@ -1690,13 +1697,6 @@ bnad_setup_tx(struct bnad *bnad, uint tx
28386 tx_config->txq_depth = bnad->txq_depth;
28387 tx_config->tx_type = BNA_TX_T_REGULAR;
28388
28389- /* Initialize the tx event handlers */
28390- tx_cbfn.tcb_setup_cbfn = bnad_cb_tcb_setup;
28391- tx_cbfn.tcb_destroy_cbfn = bnad_cb_tcb_destroy;
28392- tx_cbfn.tx_stall_cbfn = bnad_cb_tx_stall;
28393- tx_cbfn.tx_resume_cbfn = bnad_cb_tx_resume;
28394- tx_cbfn.tx_cleanup_cbfn = bnad_cb_tx_cleanup;
28395-
28396 /* Get BNA's resource requirement for one tx object */
28397 spin_lock_irqsave(&bnad->bna_lock, flags);
28398 bna_tx_res_req(bnad->num_txq_per_tx,
28399@@ -1827,21 +1827,21 @@ bnad_setup_rx(struct bnad *bnad, uint rx
28400 struct bna_intr_info *intr_info =
28401 &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
28402 struct bna_rx_config *rx_config = &bnad->rx_config[rx_id];
28403- struct bna_rx_event_cbfn rx_cbfn;
28404+ static struct bna_rx_event_cbfn rx_cbfn = {
28405+ /* Initialize the Rx event handlers */
28406+ .rcb_setup_cbfn = bnad_cb_rcb_setup,
28407+ .rcb_destroy_cbfn = bnad_cb_rcb_destroy,
28408+ .ccb_setup_cbfn = bnad_cb_ccb_setup,
28409+ .ccb_destroy_cbfn = bnad_cb_ccb_destroy,
28410+ .rx_cleanup_cbfn = bnad_cb_rx_cleanup,
28411+ .rx_post_cbfn = bnad_cb_rx_post
28412+ };
28413 struct bna_rx *rx;
28414 unsigned long flags;
28415
28416 /* Initialize the Rx object configuration */
28417 bnad_init_rx_config(bnad, rx_config);
28418
28419- /* Initialize the Rx event handlers */
28420- rx_cbfn.rcb_setup_cbfn = bnad_cb_rcb_setup;
28421- rx_cbfn.rcb_destroy_cbfn = bnad_cb_rcb_destroy;
28422- rx_cbfn.ccb_setup_cbfn = bnad_cb_ccb_setup;
28423- rx_cbfn.ccb_destroy_cbfn = bnad_cb_ccb_destroy;
28424- rx_cbfn.rx_cleanup_cbfn = bnad_cb_rx_cleanup;
28425- rx_cbfn.rx_post_cbfn = bnad_cb_rx_post;
28426-
28427 /* Get BNA's resource requirement for one Rx object */
28428 spin_lock_irqsave(&bnad->bna_lock, flags);
28429 bna_rx_res_req(rx_config, res_info);
28430diff -urNp linux-3.0.4/drivers/net/bnx2.c linux-3.0.4/drivers/net/bnx2.c
28431--- linux-3.0.4/drivers/net/bnx2.c 2011-07-21 22:17:23.000000000 -0400
28432+++ linux-3.0.4/drivers/net/bnx2.c 2011-08-23 21:48:14.000000000 -0400
28433@@ -5828,6 +5828,8 @@ bnx2_test_nvram(struct bnx2 *bp)
28434 int rc = 0;
28435 u32 magic, csum;
28436
28437+ pax_track_stack();
28438+
28439 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
28440 goto test_nvram_done;
28441
28442diff -urNp linux-3.0.4/drivers/net/bnx2x/bnx2x_ethtool.c linux-3.0.4/drivers/net/bnx2x/bnx2x_ethtool.c
28443--- linux-3.0.4/drivers/net/bnx2x/bnx2x_ethtool.c 2011-07-21 22:17:23.000000000 -0400
28444+++ linux-3.0.4/drivers/net/bnx2x/bnx2x_ethtool.c 2011-08-23 21:48:14.000000000 -0400
28445@@ -1705,6 +1705,8 @@ static int bnx2x_test_nvram(struct bnx2x
28446 int i, rc;
28447 u32 magic, crc;
28448
28449+ pax_track_stack();
28450+
28451 if (BP_NOMCP(bp))
28452 return 0;
28453
28454diff -urNp linux-3.0.4/drivers/net/cxgb3/l2t.h linux-3.0.4/drivers/net/cxgb3/l2t.h
28455--- linux-3.0.4/drivers/net/cxgb3/l2t.h 2011-07-21 22:17:23.000000000 -0400
28456+++ linux-3.0.4/drivers/net/cxgb3/l2t.h 2011-08-23 21:47:55.000000000 -0400
28457@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)
28458 */
28459 struct l2t_skb_cb {
28460 arp_failure_handler_func arp_failure_handler;
28461-};
28462+} __no_const;
28463
28464 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
28465
28466diff -urNp linux-3.0.4/drivers/net/cxgb4/cxgb4_main.c linux-3.0.4/drivers/net/cxgb4/cxgb4_main.c
28467--- linux-3.0.4/drivers/net/cxgb4/cxgb4_main.c 2011-07-21 22:17:23.000000000 -0400
28468+++ linux-3.0.4/drivers/net/cxgb4/cxgb4_main.c 2011-08-23 21:48:14.000000000 -0400
28469@@ -3396,6 +3396,8 @@ static int __devinit enable_msix(struct
28470 unsigned int nchan = adap->params.nports;
28471 struct msix_entry entries[MAX_INGQ + 1];
28472
28473+ pax_track_stack();
28474+
28475 for (i = 0; i < ARRAY_SIZE(entries); ++i)
28476 entries[i].entry = i;
28477
28478diff -urNp linux-3.0.4/drivers/net/cxgb4/t4_hw.c linux-3.0.4/drivers/net/cxgb4/t4_hw.c
28479--- linux-3.0.4/drivers/net/cxgb4/t4_hw.c 2011-07-21 22:17:23.000000000 -0400
28480+++ linux-3.0.4/drivers/net/cxgb4/t4_hw.c 2011-08-23 21:48:14.000000000 -0400
28481@@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter
28482 u8 vpd[VPD_LEN], csum;
28483 unsigned int vpdr_len, kw_offset, id_len;
28484
28485+ pax_track_stack();
28486+
28487 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
28488 if (ret < 0)
28489 return ret;
28490diff -urNp linux-3.0.4/drivers/net/e1000e/82571.c linux-3.0.4/drivers/net/e1000e/82571.c
28491--- linux-3.0.4/drivers/net/e1000e/82571.c 2011-07-21 22:17:23.000000000 -0400
28492+++ linux-3.0.4/drivers/net/e1000e/82571.c 2011-08-23 21:47:55.000000000 -0400
28493@@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(s
28494 {
28495 struct e1000_hw *hw = &adapter->hw;
28496 struct e1000_mac_info *mac = &hw->mac;
28497- struct e1000_mac_operations *func = &mac->ops;
28498+ e1000_mac_operations_no_const *func = &mac->ops;
28499 u32 swsm = 0;
28500 u32 swsm2 = 0;
28501 bool force_clear_smbi = false;
28502diff -urNp linux-3.0.4/drivers/net/e1000e/es2lan.c linux-3.0.4/drivers/net/e1000e/es2lan.c
28503--- linux-3.0.4/drivers/net/e1000e/es2lan.c 2011-07-21 22:17:23.000000000 -0400
28504+++ linux-3.0.4/drivers/net/e1000e/es2lan.c 2011-08-23 21:47:55.000000000 -0400
28505@@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es
28506 {
28507 struct e1000_hw *hw = &adapter->hw;
28508 struct e1000_mac_info *mac = &hw->mac;
28509- struct e1000_mac_operations *func = &mac->ops;
28510+ e1000_mac_operations_no_const *func = &mac->ops;
28511
28512 /* Set media type */
28513 switch (adapter->pdev->device) {
28514diff -urNp linux-3.0.4/drivers/net/e1000e/hw.h linux-3.0.4/drivers/net/e1000e/hw.h
28515--- linux-3.0.4/drivers/net/e1000e/hw.h 2011-07-21 22:17:23.000000000 -0400
28516+++ linux-3.0.4/drivers/net/e1000e/hw.h 2011-08-23 21:47:55.000000000 -0400
28517@@ -776,6 +776,7 @@ struct e1000_mac_operations {
28518 void (*write_vfta)(struct e1000_hw *, u32, u32);
28519 s32 (*read_mac_addr)(struct e1000_hw *);
28520 };
28521+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
28522
28523 /* Function pointers for the PHY. */
28524 struct e1000_phy_operations {
28525@@ -799,6 +800,7 @@ struct e1000_phy_operations {
28526 void (*power_up)(struct e1000_hw *);
28527 void (*power_down)(struct e1000_hw *);
28528 };
28529+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
28530
28531 /* Function pointers for the NVM. */
28532 struct e1000_nvm_operations {
28533@@ -810,9 +812,10 @@ struct e1000_nvm_operations {
28534 s32 (*validate)(struct e1000_hw *);
28535 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
28536 };
28537+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
28538
28539 struct e1000_mac_info {
28540- struct e1000_mac_operations ops;
28541+ e1000_mac_operations_no_const ops;
28542 u8 addr[ETH_ALEN];
28543 u8 perm_addr[ETH_ALEN];
28544
28545@@ -853,7 +856,7 @@ struct e1000_mac_info {
28546 };
28547
28548 struct e1000_phy_info {
28549- struct e1000_phy_operations ops;
28550+ e1000_phy_operations_no_const ops;
28551
28552 enum e1000_phy_type type;
28553
28554@@ -887,7 +890,7 @@ struct e1000_phy_info {
28555 };
28556
28557 struct e1000_nvm_info {
28558- struct e1000_nvm_operations ops;
28559+ e1000_nvm_operations_no_const ops;
28560
28561 enum e1000_nvm_type type;
28562 enum e1000_nvm_override override;
28563diff -urNp linux-3.0.4/drivers/net/hamradio/6pack.c linux-3.0.4/drivers/net/hamradio/6pack.c
28564--- linux-3.0.4/drivers/net/hamradio/6pack.c 2011-07-21 22:17:23.000000000 -0400
28565+++ linux-3.0.4/drivers/net/hamradio/6pack.c 2011-08-23 21:48:14.000000000 -0400
28566@@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct t
28567 unsigned char buf[512];
28568 int count1;
28569
28570+ pax_track_stack();
28571+
28572 if (!count)
28573 return;
28574
28575diff -urNp linux-3.0.4/drivers/net/igb/e1000_hw.h linux-3.0.4/drivers/net/igb/e1000_hw.h
28576--- linux-3.0.4/drivers/net/igb/e1000_hw.h 2011-07-21 22:17:23.000000000 -0400
28577+++ linux-3.0.4/drivers/net/igb/e1000_hw.h 2011-08-23 21:47:55.000000000 -0400
28578@@ -314,6 +314,7 @@ struct e1000_mac_operations {
28579 s32 (*read_mac_addr)(struct e1000_hw *);
28580 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
28581 };
28582+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
28583
28584 struct e1000_phy_operations {
28585 s32 (*acquire)(struct e1000_hw *);
28586@@ -330,6 +331,7 @@ struct e1000_phy_operations {
28587 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
28588 s32 (*write_reg)(struct e1000_hw *, u32, u16);
28589 };
28590+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
28591
28592 struct e1000_nvm_operations {
28593 s32 (*acquire)(struct e1000_hw *);
28594@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
28595 s32 (*update)(struct e1000_hw *);
28596 s32 (*validate)(struct e1000_hw *);
28597 };
28598+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
28599
28600 struct e1000_info {
28601 s32 (*get_invariants)(struct e1000_hw *);
28602@@ -350,7 +353,7 @@ struct e1000_info {
28603 extern const struct e1000_info e1000_82575_info;
28604
28605 struct e1000_mac_info {
28606- struct e1000_mac_operations ops;
28607+ e1000_mac_operations_no_const ops;
28608
28609 u8 addr[6];
28610 u8 perm_addr[6];
28611@@ -388,7 +391,7 @@ struct e1000_mac_info {
28612 };
28613
28614 struct e1000_phy_info {
28615- struct e1000_phy_operations ops;
28616+ e1000_phy_operations_no_const ops;
28617
28618 enum e1000_phy_type type;
28619
28620@@ -423,7 +426,7 @@ struct e1000_phy_info {
28621 };
28622
28623 struct e1000_nvm_info {
28624- struct e1000_nvm_operations ops;
28625+ e1000_nvm_operations_no_const ops;
28626 enum e1000_nvm_type type;
28627 enum e1000_nvm_override override;
28628
28629@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
28630 s32 (*check_for_ack)(struct e1000_hw *, u16);
28631 s32 (*check_for_rst)(struct e1000_hw *, u16);
28632 };
28633+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
28634
28635 struct e1000_mbx_stats {
28636 u32 msgs_tx;
28637@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
28638 };
28639
28640 struct e1000_mbx_info {
28641- struct e1000_mbx_operations ops;
28642+ e1000_mbx_operations_no_const ops;
28643 struct e1000_mbx_stats stats;
28644 u32 timeout;
28645 u32 usec_delay;
28646diff -urNp linux-3.0.4/drivers/net/igbvf/vf.h linux-3.0.4/drivers/net/igbvf/vf.h
28647--- linux-3.0.4/drivers/net/igbvf/vf.h 2011-07-21 22:17:23.000000000 -0400
28648+++ linux-3.0.4/drivers/net/igbvf/vf.h 2011-08-23 21:47:55.000000000 -0400
28649@@ -189,9 +189,10 @@ struct e1000_mac_operations {
28650 s32 (*read_mac_addr)(struct e1000_hw *);
28651 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
28652 };
28653+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
28654
28655 struct e1000_mac_info {
28656- struct e1000_mac_operations ops;
28657+ e1000_mac_operations_no_const ops;
28658 u8 addr[6];
28659 u8 perm_addr[6];
28660
28661@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
28662 s32 (*check_for_ack)(struct e1000_hw *);
28663 s32 (*check_for_rst)(struct e1000_hw *);
28664 };
28665+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
28666
28667 struct e1000_mbx_stats {
28668 u32 msgs_tx;
28669@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
28670 };
28671
28672 struct e1000_mbx_info {
28673- struct e1000_mbx_operations ops;
28674+ e1000_mbx_operations_no_const ops;
28675 struct e1000_mbx_stats stats;
28676 u32 timeout;
28677 u32 usec_delay;
28678diff -urNp linux-3.0.4/drivers/net/ixgb/ixgb_main.c linux-3.0.4/drivers/net/ixgb/ixgb_main.c
28679--- linux-3.0.4/drivers/net/ixgb/ixgb_main.c 2011-07-21 22:17:23.000000000 -0400
28680+++ linux-3.0.4/drivers/net/ixgb/ixgb_main.c 2011-08-23 21:48:14.000000000 -0400
28681@@ -1070,6 +1070,8 @@ ixgb_set_multi(struct net_device *netdev
28682 u32 rctl;
28683 int i;
28684
28685+ pax_track_stack();
28686+
28687 /* Check for Promiscuous and All Multicast modes */
28688
28689 rctl = IXGB_READ_REG(hw, RCTL);
28690diff -urNp linux-3.0.4/drivers/net/ixgb/ixgb_param.c linux-3.0.4/drivers/net/ixgb/ixgb_param.c
28691--- linux-3.0.4/drivers/net/ixgb/ixgb_param.c 2011-07-21 22:17:23.000000000 -0400
28692+++ linux-3.0.4/drivers/net/ixgb/ixgb_param.c 2011-08-23 21:48:14.000000000 -0400
28693@@ -261,6 +261,9 @@ void __devinit
28694 ixgb_check_options(struct ixgb_adapter *adapter)
28695 {
28696 int bd = adapter->bd_number;
28697+
28698+ pax_track_stack();
28699+
28700 if (bd >= IXGB_MAX_NIC) {
28701 pr_notice("Warning: no configuration for board #%i\n", bd);
28702 pr_notice("Using defaults for all values\n");
28703diff -urNp linux-3.0.4/drivers/net/ixgbe/ixgbe_type.h linux-3.0.4/drivers/net/ixgbe/ixgbe_type.h
28704--- linux-3.0.4/drivers/net/ixgbe/ixgbe_type.h 2011-07-21 22:17:23.000000000 -0400
28705+++ linux-3.0.4/drivers/net/ixgbe/ixgbe_type.h 2011-08-23 21:47:55.000000000 -0400
28706@@ -2584,6 +2584,7 @@ struct ixgbe_eeprom_operations {
28707 s32 (*update_checksum)(struct ixgbe_hw *);
28708 u16 (*calc_checksum)(struct ixgbe_hw *);
28709 };
28710+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
28711
28712 struct ixgbe_mac_operations {
28713 s32 (*init_hw)(struct ixgbe_hw *);
28714@@ -2639,6 +2640,7 @@ struct ixgbe_mac_operations {
28715 /* Flow Control */
28716 s32 (*fc_enable)(struct ixgbe_hw *, s32);
28717 };
28718+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
28719
28720 struct ixgbe_phy_operations {
28721 s32 (*identify)(struct ixgbe_hw *);
28722@@ -2658,9 +2660,10 @@ struct ixgbe_phy_operations {
28723 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
28724 s32 (*check_overtemp)(struct ixgbe_hw *);
28725 };
28726+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
28727
28728 struct ixgbe_eeprom_info {
28729- struct ixgbe_eeprom_operations ops;
28730+ ixgbe_eeprom_operations_no_const ops;
28731 enum ixgbe_eeprom_type type;
28732 u32 semaphore_delay;
28733 u16 word_size;
28734@@ -2670,7 +2673,7 @@ struct ixgbe_eeprom_info {
28735
28736 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
28737 struct ixgbe_mac_info {
28738- struct ixgbe_mac_operations ops;
28739+ ixgbe_mac_operations_no_const ops;
28740 enum ixgbe_mac_type type;
28741 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
28742 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
28743@@ -2698,7 +2701,7 @@ struct ixgbe_mac_info {
28744 };
28745
28746 struct ixgbe_phy_info {
28747- struct ixgbe_phy_operations ops;
28748+ ixgbe_phy_operations_no_const ops;
28749 struct mdio_if_info mdio;
28750 enum ixgbe_phy_type type;
28751 u32 id;
28752@@ -2726,6 +2729,7 @@ struct ixgbe_mbx_operations {
28753 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
28754 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
28755 };
28756+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
28757
28758 struct ixgbe_mbx_stats {
28759 u32 msgs_tx;
28760@@ -2737,7 +2741,7 @@ struct ixgbe_mbx_stats {
28761 };
28762
28763 struct ixgbe_mbx_info {
28764- struct ixgbe_mbx_operations ops;
28765+ ixgbe_mbx_operations_no_const ops;
28766 struct ixgbe_mbx_stats stats;
28767 u32 timeout;
28768 u32 usec_delay;
28769diff -urNp linux-3.0.4/drivers/net/ixgbevf/vf.h linux-3.0.4/drivers/net/ixgbevf/vf.h
28770--- linux-3.0.4/drivers/net/ixgbevf/vf.h 2011-07-21 22:17:23.000000000 -0400
28771+++ linux-3.0.4/drivers/net/ixgbevf/vf.h 2011-08-23 21:47:55.000000000 -0400
28772@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
28773 s32 (*clear_vfta)(struct ixgbe_hw *);
28774 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
28775 };
28776+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
28777
28778 enum ixgbe_mac_type {
28779 ixgbe_mac_unknown = 0,
28780@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
28781 };
28782
28783 struct ixgbe_mac_info {
28784- struct ixgbe_mac_operations ops;
28785+ ixgbe_mac_operations_no_const ops;
28786 u8 addr[6];
28787 u8 perm_addr[6];
28788
28789@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
28790 s32 (*check_for_ack)(struct ixgbe_hw *);
28791 s32 (*check_for_rst)(struct ixgbe_hw *);
28792 };
28793+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
28794
28795 struct ixgbe_mbx_stats {
28796 u32 msgs_tx;
28797@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
28798 };
28799
28800 struct ixgbe_mbx_info {
28801- struct ixgbe_mbx_operations ops;
28802+ ixgbe_mbx_operations_no_const ops;
28803 struct ixgbe_mbx_stats stats;
28804 u32 timeout;
28805 u32 udelay;
28806diff -urNp linux-3.0.4/drivers/net/ksz884x.c linux-3.0.4/drivers/net/ksz884x.c
28807--- linux-3.0.4/drivers/net/ksz884x.c 2011-07-21 22:17:23.000000000 -0400
28808+++ linux-3.0.4/drivers/net/ksz884x.c 2011-08-23 21:48:14.000000000 -0400
28809@@ -6534,6 +6534,8 @@ static void netdev_get_ethtool_stats(str
28810 int rc;
28811 u64 counter[TOTAL_PORT_COUNTER_NUM];
28812
28813+ pax_track_stack();
28814+
28815 mutex_lock(&hw_priv->lock);
28816 n = SWITCH_PORT_NUM;
28817 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
28818diff -urNp linux-3.0.4/drivers/net/mlx4/main.c linux-3.0.4/drivers/net/mlx4/main.c
28819--- linux-3.0.4/drivers/net/mlx4/main.c 2011-07-21 22:17:23.000000000 -0400
28820+++ linux-3.0.4/drivers/net/mlx4/main.c 2011-08-23 21:48:14.000000000 -0400
28821@@ -40,6 +40,7 @@
28822 #include <linux/dma-mapping.h>
28823 #include <linux/slab.h>
28824 #include <linux/io-mapping.h>
28825+#include <linux/sched.h>
28826
28827 #include <linux/mlx4/device.h>
28828 #include <linux/mlx4/doorbell.h>
28829@@ -764,6 +765,8 @@ static int mlx4_init_hca(struct mlx4_dev
28830 u64 icm_size;
28831 int err;
28832
28833+ pax_track_stack();
28834+
28835 err = mlx4_QUERY_FW(dev);
28836 if (err) {
28837 if (err == -EACCES)
28838diff -urNp linux-3.0.4/drivers/net/niu.c linux-3.0.4/drivers/net/niu.c
28839--- linux-3.0.4/drivers/net/niu.c 2011-08-23 21:44:40.000000000 -0400
28840+++ linux-3.0.4/drivers/net/niu.c 2011-08-23 21:48:14.000000000 -0400
28841@@ -9056,6 +9056,8 @@ static void __devinit niu_try_msix(struc
28842 int i, num_irqs, err;
28843 u8 first_ldg;
28844
28845+ pax_track_stack();
28846+
28847 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
28848 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
28849 ldg_num_map[i] = first_ldg + i;
28850diff -urNp linux-3.0.4/drivers/net/pcnet32.c linux-3.0.4/drivers/net/pcnet32.c
28851--- linux-3.0.4/drivers/net/pcnet32.c 2011-07-21 22:17:23.000000000 -0400
28852+++ linux-3.0.4/drivers/net/pcnet32.c 2011-08-23 21:47:55.000000000 -0400
28853@@ -82,7 +82,7 @@ static int cards_found;
28854 /*
28855 * VLB I/O addresses
28856 */
28857-static unsigned int pcnet32_portlist[] __initdata =
28858+static unsigned int pcnet32_portlist[] __devinitdata =
28859 { 0x300, 0x320, 0x340, 0x360, 0 };
28860
28861 static int pcnet32_debug;
28862@@ -270,7 +270,7 @@ struct pcnet32_private {
28863 struct sk_buff **rx_skbuff;
28864 dma_addr_t *tx_dma_addr;
28865 dma_addr_t *rx_dma_addr;
28866- struct pcnet32_access a;
28867+ struct pcnet32_access *a;
28868 spinlock_t lock; /* Guard lock */
28869 unsigned int cur_rx, cur_tx; /* The next free ring entry */
28870 unsigned int rx_ring_size; /* current rx ring size */
28871@@ -460,9 +460,9 @@ static void pcnet32_netif_start(struct n
28872 u16 val;
28873
28874 netif_wake_queue(dev);
28875- val = lp->a.read_csr(ioaddr, CSR3);
28876+ val = lp->a->read_csr(ioaddr, CSR3);
28877 val &= 0x00ff;
28878- lp->a.write_csr(ioaddr, CSR3, val);
28879+ lp->a->write_csr(ioaddr, CSR3, val);
28880 napi_enable(&lp->napi);
28881 }
28882
28883@@ -730,7 +730,7 @@ static u32 pcnet32_get_link(struct net_d
28884 r = mii_link_ok(&lp->mii_if);
28885 } else if (lp->chip_version >= PCNET32_79C970A) {
28886 ulong ioaddr = dev->base_addr; /* card base I/O address */
28887- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
28888+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
28889 } else { /* can not detect link on really old chips */
28890 r = 1;
28891 }
28892@@ -792,7 +792,7 @@ static int pcnet32_set_ringparam(struct
28893 pcnet32_netif_stop(dev);
28894
28895 spin_lock_irqsave(&lp->lock, flags);
28896- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
28897+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
28898
28899 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
28900
28901@@ -868,7 +868,7 @@ static void pcnet32_ethtool_test(struct
28902 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
28903 {
28904 struct pcnet32_private *lp = netdev_priv(dev);
28905- struct pcnet32_access *a = &lp->a; /* access to registers */
28906+ struct pcnet32_access *a = lp->a; /* access to registers */
28907 ulong ioaddr = dev->base_addr; /* card base I/O address */
28908 struct sk_buff *skb; /* sk buff */
28909 int x, i; /* counters */
28910@@ -888,21 +888,21 @@ static int pcnet32_loopback_test(struct
28911 pcnet32_netif_stop(dev);
28912
28913 spin_lock_irqsave(&lp->lock, flags);
28914- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
28915+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
28916
28917 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
28918
28919 /* Reset the PCNET32 */
28920- lp->a.reset(ioaddr);
28921- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
28922+ lp->a->reset(ioaddr);
28923+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
28924
28925 /* switch pcnet32 to 32bit mode */
28926- lp->a.write_bcr(ioaddr, 20, 2);
28927+ lp->a->write_bcr(ioaddr, 20, 2);
28928
28929 /* purge & init rings but don't actually restart */
28930 pcnet32_restart(dev, 0x0000);
28931
28932- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
28933+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
28934
28935 /* Initialize Transmit buffers. */
28936 size = data_len + 15;
28937@@ -947,10 +947,10 @@ static int pcnet32_loopback_test(struct
28938
28939 /* set int loopback in CSR15 */
28940 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
28941- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
28942+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
28943
28944 teststatus = cpu_to_le16(0x8000);
28945- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
28946+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
28947
28948 /* Check status of descriptors */
28949 for (x = 0; x < numbuffs; x++) {
28950@@ -969,7 +969,7 @@ static int pcnet32_loopback_test(struct
28951 }
28952 }
28953
28954- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
28955+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
28956 wmb();
28957 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
28958 netdev_printk(KERN_DEBUG, dev, "RX loopback packets:\n");
28959@@ -1015,7 +1015,7 @@ clean_up:
28960 pcnet32_restart(dev, CSR0_NORMAL);
28961 } else {
28962 pcnet32_purge_rx_ring(dev);
28963- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
28964+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
28965 }
28966 spin_unlock_irqrestore(&lp->lock, flags);
28967
28968@@ -1026,7 +1026,7 @@ static int pcnet32_set_phys_id(struct ne
28969 enum ethtool_phys_id_state state)
28970 {
28971 struct pcnet32_private *lp = netdev_priv(dev);
28972- struct pcnet32_access *a = &lp->a;
28973+ struct pcnet32_access *a = lp->a;
28974 ulong ioaddr = dev->base_addr;
28975 unsigned long flags;
28976 int i;
28977@@ -1067,7 +1067,7 @@ static int pcnet32_suspend(struct net_de
28978 {
28979 int csr5;
28980 struct pcnet32_private *lp = netdev_priv(dev);
28981- struct pcnet32_access *a = &lp->a;
28982+ struct pcnet32_access *a = lp->a;
28983 ulong ioaddr = dev->base_addr;
28984 int ticks;
28985
28986@@ -1324,8 +1324,8 @@ static int pcnet32_poll(struct napi_stru
28987 spin_lock_irqsave(&lp->lock, flags);
28988 if (pcnet32_tx(dev)) {
28989 /* reset the chip to clear the error condition, then restart */
28990- lp->a.reset(ioaddr);
28991- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
28992+ lp->a->reset(ioaddr);
28993+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
28994 pcnet32_restart(dev, CSR0_START);
28995 netif_wake_queue(dev);
28996 }
28997@@ -1337,12 +1337,12 @@ static int pcnet32_poll(struct napi_stru
28998 __napi_complete(napi);
28999
29000 /* clear interrupt masks */
29001- val = lp->a.read_csr(ioaddr, CSR3);
29002+ val = lp->a->read_csr(ioaddr, CSR3);
29003 val &= 0x00ff;
29004- lp->a.write_csr(ioaddr, CSR3, val);
29005+ lp->a->write_csr(ioaddr, CSR3, val);
29006
29007 /* Set interrupt enable. */
29008- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
29009+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
29010
29011 spin_unlock_irqrestore(&lp->lock, flags);
29012 }
29013@@ -1365,7 +1365,7 @@ static void pcnet32_get_regs(struct net_
29014 int i, csr0;
29015 u16 *buff = ptr;
29016 struct pcnet32_private *lp = netdev_priv(dev);
29017- struct pcnet32_access *a = &lp->a;
29018+ struct pcnet32_access *a = lp->a;
29019 ulong ioaddr = dev->base_addr;
29020 unsigned long flags;
29021
29022@@ -1401,9 +1401,9 @@ static void pcnet32_get_regs(struct net_
29023 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
29024 if (lp->phymask & (1 << j)) {
29025 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
29026- lp->a.write_bcr(ioaddr, 33,
29027+ lp->a->write_bcr(ioaddr, 33,
29028 (j << 5) | i);
29029- *buff++ = lp->a.read_bcr(ioaddr, 34);
29030+ *buff++ = lp->a->read_bcr(ioaddr, 34);
29031 }
29032 }
29033 }
29034@@ -1785,7 +1785,7 @@ pcnet32_probe1(unsigned long ioaddr, int
29035 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
29036 lp->options |= PCNET32_PORT_FD;
29037
29038- lp->a = *a;
29039+ lp->a = a;
29040
29041 /* prior to register_netdev, dev->name is not yet correct */
29042 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
29043@@ -1844,7 +1844,7 @@ pcnet32_probe1(unsigned long ioaddr, int
29044 if (lp->mii) {
29045 /* lp->phycount and lp->phymask are set to 0 by memset above */
29046
29047- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
29048+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
29049 /* scan for PHYs */
29050 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
29051 unsigned short id1, id2;
29052@@ -1864,7 +1864,7 @@ pcnet32_probe1(unsigned long ioaddr, int
29053 pr_info("Found PHY %04x:%04x at address %d\n",
29054 id1, id2, i);
29055 }
29056- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
29057+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
29058 if (lp->phycount > 1)
29059 lp->options |= PCNET32_PORT_MII;
29060 }
29061@@ -2020,10 +2020,10 @@ static int pcnet32_open(struct net_devic
29062 }
29063
29064 /* Reset the PCNET32 */
29065- lp->a.reset(ioaddr);
29066+ lp->a->reset(ioaddr);
29067
29068 /* switch pcnet32 to 32bit mode */
29069- lp->a.write_bcr(ioaddr, 20, 2);
29070+ lp->a->write_bcr(ioaddr, 20, 2);
29071
29072 netif_printk(lp, ifup, KERN_DEBUG, dev,
29073 "%s() irq %d tx/rx rings %#x/%#x init %#x\n",
29074@@ -2032,14 +2032,14 @@ static int pcnet32_open(struct net_devic
29075 (u32) (lp->init_dma_addr));
29076
29077 /* set/reset autoselect bit */
29078- val = lp->a.read_bcr(ioaddr, 2) & ~2;
29079+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
29080 if (lp->options & PCNET32_PORT_ASEL)
29081 val |= 2;
29082- lp->a.write_bcr(ioaddr, 2, val);
29083+ lp->a->write_bcr(ioaddr, 2, val);
29084
29085 /* handle full duplex setting */
29086 if (lp->mii_if.full_duplex) {
29087- val = lp->a.read_bcr(ioaddr, 9) & ~3;
29088+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
29089 if (lp->options & PCNET32_PORT_FD) {
29090 val |= 1;
29091 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
29092@@ -2049,14 +2049,14 @@ static int pcnet32_open(struct net_devic
29093 if (lp->chip_version == 0x2627)
29094 val |= 3;
29095 }
29096- lp->a.write_bcr(ioaddr, 9, val);
29097+ lp->a->write_bcr(ioaddr, 9, val);
29098 }
29099
29100 /* set/reset GPSI bit in test register */
29101- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
29102+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
29103 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
29104 val |= 0x10;
29105- lp->a.write_csr(ioaddr, 124, val);
29106+ lp->a->write_csr(ioaddr, 124, val);
29107
29108 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
29109 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
29110@@ -2075,24 +2075,24 @@ static int pcnet32_open(struct net_devic
29111 * duplex, and/or enable auto negotiation, and clear DANAS
29112 */
29113 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
29114- lp->a.write_bcr(ioaddr, 32,
29115- lp->a.read_bcr(ioaddr, 32) | 0x0080);
29116+ lp->a->write_bcr(ioaddr, 32,
29117+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
29118 /* disable Auto Negotiation, set 10Mpbs, HD */
29119- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
29120+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
29121 if (lp->options & PCNET32_PORT_FD)
29122 val |= 0x10;
29123 if (lp->options & PCNET32_PORT_100)
29124 val |= 0x08;
29125- lp->a.write_bcr(ioaddr, 32, val);
29126+ lp->a->write_bcr(ioaddr, 32, val);
29127 } else {
29128 if (lp->options & PCNET32_PORT_ASEL) {
29129- lp->a.write_bcr(ioaddr, 32,
29130- lp->a.read_bcr(ioaddr,
29131+ lp->a->write_bcr(ioaddr, 32,
29132+ lp->a->read_bcr(ioaddr,
29133 32) | 0x0080);
29134 /* enable auto negotiate, setup, disable fd */
29135- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
29136+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
29137 val |= 0x20;
29138- lp->a.write_bcr(ioaddr, 32, val);
29139+ lp->a->write_bcr(ioaddr, 32, val);
29140 }
29141 }
29142 } else {
29143@@ -2105,10 +2105,10 @@ static int pcnet32_open(struct net_devic
29144 * There is really no good other way to handle multiple PHYs
29145 * other than turning off all automatics
29146 */
29147- val = lp->a.read_bcr(ioaddr, 2);
29148- lp->a.write_bcr(ioaddr, 2, val & ~2);
29149- val = lp->a.read_bcr(ioaddr, 32);
29150- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
29151+ val = lp->a->read_bcr(ioaddr, 2);
29152+ lp->a->write_bcr(ioaddr, 2, val & ~2);
29153+ val = lp->a->read_bcr(ioaddr, 32);
29154+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
29155
29156 if (!(lp->options & PCNET32_PORT_ASEL)) {
29157 /* setup ecmd */
29158@@ -2118,7 +2118,7 @@ static int pcnet32_open(struct net_devic
29159 ethtool_cmd_speed_set(&ecmd,
29160 (lp->options & PCNET32_PORT_100) ?
29161 SPEED_100 : SPEED_10);
29162- bcr9 = lp->a.read_bcr(ioaddr, 9);
29163+ bcr9 = lp->a->read_bcr(ioaddr, 9);
29164
29165 if (lp->options & PCNET32_PORT_FD) {
29166 ecmd.duplex = DUPLEX_FULL;
29167@@ -2127,7 +2127,7 @@ static int pcnet32_open(struct net_devic
29168 ecmd.duplex = DUPLEX_HALF;
29169 bcr9 |= ~(1 << 0);
29170 }
29171- lp->a.write_bcr(ioaddr, 9, bcr9);
29172+ lp->a->write_bcr(ioaddr, 9, bcr9);
29173 }
29174
29175 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
29176@@ -2158,9 +2158,9 @@ static int pcnet32_open(struct net_devic
29177
29178 #ifdef DO_DXSUFLO
29179 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
29180- val = lp->a.read_csr(ioaddr, CSR3);
29181+ val = lp->a->read_csr(ioaddr, CSR3);
29182 val |= 0x40;
29183- lp->a.write_csr(ioaddr, CSR3, val);
29184+ lp->a->write_csr(ioaddr, CSR3, val);
29185 }
29186 #endif
29187
29188@@ -2176,11 +2176,11 @@ static int pcnet32_open(struct net_devic
29189 napi_enable(&lp->napi);
29190
29191 /* Re-initialize the PCNET32, and start it when done. */
29192- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
29193- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
29194+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
29195+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
29196
29197- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
29198- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
29199+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
29200+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
29201
29202 netif_start_queue(dev);
29203
29204@@ -2192,19 +2192,19 @@ static int pcnet32_open(struct net_devic
29205
29206 i = 0;
29207 while (i++ < 100)
29208- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
29209+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
29210 break;
29211 /*
29212 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
29213 * reports that doing so triggers a bug in the '974.
29214 */
29215- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
29216+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
29217
29218 netif_printk(lp, ifup, KERN_DEBUG, dev,
29219 "pcnet32 open after %d ticks, init block %#x csr0 %4.4x\n",
29220 i,
29221 (u32) (lp->init_dma_addr),
29222- lp->a.read_csr(ioaddr, CSR0));
29223+ lp->a->read_csr(ioaddr, CSR0));
29224
29225 spin_unlock_irqrestore(&lp->lock, flags);
29226
29227@@ -2218,7 +2218,7 @@ err_free_ring:
29228 * Switch back to 16bit mode to avoid problems with dumb
29229 * DOS packet driver after a warm reboot
29230 */
29231- lp->a.write_bcr(ioaddr, 20, 4);
29232+ lp->a->write_bcr(ioaddr, 20, 4);
29233
29234 err_free_irq:
29235 spin_unlock_irqrestore(&lp->lock, flags);
29236@@ -2323,7 +2323,7 @@ static void pcnet32_restart(struct net_d
29237
29238 /* wait for stop */
29239 for (i = 0; i < 100; i++)
29240- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
29241+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
29242 break;
29243
29244 if (i >= 100)
29245@@ -2335,13 +2335,13 @@ static void pcnet32_restart(struct net_d
29246 return;
29247
29248 /* ReInit Ring */
29249- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
29250+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
29251 i = 0;
29252 while (i++ < 1000)
29253- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
29254+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
29255 break;
29256
29257- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
29258+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
29259 }
29260
29261 static void pcnet32_tx_timeout(struct net_device *dev)
29262@@ -2353,8 +2353,8 @@ static void pcnet32_tx_timeout(struct ne
29263 /* Transmitter timeout, serious problems. */
29264 if (pcnet32_debug & NETIF_MSG_DRV)
29265 pr_err("%s: transmit timed out, status %4.4x, resetting\n",
29266- dev->name, lp->a.read_csr(ioaddr, CSR0));
29267- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
29268+ dev->name, lp->a->read_csr(ioaddr, CSR0));
29269+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
29270 dev->stats.tx_errors++;
29271 if (netif_msg_tx_err(lp)) {
29272 int i;
29273@@ -2397,7 +2397,7 @@ static netdev_tx_t pcnet32_start_xmit(st
29274
29275 netif_printk(lp, tx_queued, KERN_DEBUG, dev,
29276 "%s() called, csr0 %4.4x\n",
29277- __func__, lp->a.read_csr(ioaddr, CSR0));
29278+ __func__, lp->a->read_csr(ioaddr, CSR0));
29279
29280 /* Default status -- will not enable Successful-TxDone
29281 * interrupt when that option is available to us.
29282@@ -2427,7 +2427,7 @@ static netdev_tx_t pcnet32_start_xmit(st
29283 dev->stats.tx_bytes += skb->len;
29284
29285 /* Trigger an immediate send poll. */
29286- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
29287+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
29288
29289 if (lp->tx_ring[(entry + 1) & lp->tx_mod_mask].base != 0) {
29290 lp->tx_full = 1;
29291@@ -2452,16 +2452,16 @@ pcnet32_interrupt(int irq, void *dev_id)
29292
29293 spin_lock(&lp->lock);
29294
29295- csr0 = lp->a.read_csr(ioaddr, CSR0);
29296+ csr0 = lp->a->read_csr(ioaddr, CSR0);
29297 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
29298 if (csr0 == 0xffff)
29299 break; /* PCMCIA remove happened */
29300 /* Acknowledge all of the current interrupt sources ASAP. */
29301- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
29302+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
29303
29304 netif_printk(lp, intr, KERN_DEBUG, dev,
29305 "interrupt csr0=%#2.2x new csr=%#2.2x\n",
29306- csr0, lp->a.read_csr(ioaddr, CSR0));
29307+ csr0, lp->a->read_csr(ioaddr, CSR0));
29308
29309 /* Log misc errors. */
29310 if (csr0 & 0x4000)
29311@@ -2488,19 +2488,19 @@ pcnet32_interrupt(int irq, void *dev_id)
29312 if (napi_schedule_prep(&lp->napi)) {
29313 u16 val;
29314 /* set interrupt masks */
29315- val = lp->a.read_csr(ioaddr, CSR3);
29316+ val = lp->a->read_csr(ioaddr, CSR3);
29317 val |= 0x5f00;
29318- lp->a.write_csr(ioaddr, CSR3, val);
29319+ lp->a->write_csr(ioaddr, CSR3, val);
29320
29321 __napi_schedule(&lp->napi);
29322 break;
29323 }
29324- csr0 = lp->a.read_csr(ioaddr, CSR0);
29325+ csr0 = lp->a->read_csr(ioaddr, CSR0);
29326 }
29327
29328 netif_printk(lp, intr, KERN_DEBUG, dev,
29329 "exiting interrupt, csr0=%#4.4x\n",
29330- lp->a.read_csr(ioaddr, CSR0));
29331+ lp->a->read_csr(ioaddr, CSR0));
29332
29333 spin_unlock(&lp->lock);
29334
29335@@ -2520,20 +2520,20 @@ static int pcnet32_close(struct net_devi
29336
29337 spin_lock_irqsave(&lp->lock, flags);
29338
29339- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
29340+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
29341
29342 netif_printk(lp, ifdown, KERN_DEBUG, dev,
29343 "Shutting down ethercard, status was %2.2x\n",
29344- lp->a.read_csr(ioaddr, CSR0));
29345+ lp->a->read_csr(ioaddr, CSR0));
29346
29347 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
29348- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
29349+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
29350
29351 /*
29352 * Switch back to 16bit mode to avoid problems with dumb
29353 * DOS packet driver after a warm reboot
29354 */
29355- lp->a.write_bcr(ioaddr, 20, 4);
29356+ lp->a->write_bcr(ioaddr, 20, 4);
29357
29358 spin_unlock_irqrestore(&lp->lock, flags);
29359
29360@@ -2556,7 +2556,7 @@ static struct net_device_stats *pcnet32_
29361 unsigned long flags;
29362
29363 spin_lock_irqsave(&lp->lock, flags);
29364- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
29365+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
29366 spin_unlock_irqrestore(&lp->lock, flags);
29367
29368 return &dev->stats;
29369@@ -2578,10 +2578,10 @@ static void pcnet32_load_multicast(struc
29370 if (dev->flags & IFF_ALLMULTI) {
29371 ib->filter[0] = cpu_to_le32(~0U);
29372 ib->filter[1] = cpu_to_le32(~0U);
29373- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
29374- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
29375- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
29376- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
29377+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
29378+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
29379+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
29380+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
29381 return;
29382 }
29383 /* clear the multicast filter */
29384@@ -2601,7 +2601,7 @@ static void pcnet32_load_multicast(struc
29385 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
29386 }
29387 for (i = 0; i < 4; i++)
29388- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
29389+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
29390 le16_to_cpu(mcast_table[i]));
29391 }
29392
29393@@ -2616,28 +2616,28 @@ static void pcnet32_set_multicast_list(s
29394
29395 spin_lock_irqsave(&lp->lock, flags);
29396 suspended = pcnet32_suspend(dev, &flags, 0);
29397- csr15 = lp->a.read_csr(ioaddr, CSR15);
29398+ csr15 = lp->a->read_csr(ioaddr, CSR15);
29399 if (dev->flags & IFF_PROMISC) {
29400 /* Log any net taps. */
29401 netif_info(lp, hw, dev, "Promiscuous mode enabled\n");
29402 lp->init_block->mode =
29403 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
29404 7);
29405- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
29406+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
29407 } else {
29408 lp->init_block->mode =
29409 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
29410- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
29411+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
29412 pcnet32_load_multicast(dev);
29413 }
29414
29415 if (suspended) {
29416 int csr5;
29417 /* clear SUSPEND (SPND) - CSR5 bit 0 */
29418- csr5 = lp->a.read_csr(ioaddr, CSR5);
29419- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
29420+ csr5 = lp->a->read_csr(ioaddr, CSR5);
29421+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
29422 } else {
29423- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
29424+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
29425 pcnet32_restart(dev, CSR0_NORMAL);
29426 netif_wake_queue(dev);
29427 }
29428@@ -2655,8 +2655,8 @@ static int mdio_read(struct net_device *
29429 if (!lp->mii)
29430 return 0;
29431
29432- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
29433- val_out = lp->a.read_bcr(ioaddr, 34);
29434+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
29435+ val_out = lp->a->read_bcr(ioaddr, 34);
29436
29437 return val_out;
29438 }
29439@@ -2670,8 +2670,8 @@ static void mdio_write(struct net_device
29440 if (!lp->mii)
29441 return;
29442
29443- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
29444- lp->a.write_bcr(ioaddr, 34, val);
29445+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
29446+ lp->a->write_bcr(ioaddr, 34, val);
29447 }
29448
29449 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
29450@@ -2748,7 +2748,7 @@ static void pcnet32_check_media(struct n
29451 curr_link = mii_link_ok(&lp->mii_if);
29452 } else {
29453 ulong ioaddr = dev->base_addr; /* card base I/O address */
29454- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
29455+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
29456 }
29457 if (!curr_link) {
29458 if (prev_link || verbose) {
29459@@ -2771,13 +2771,13 @@ static void pcnet32_check_media(struct n
29460 (ecmd.duplex == DUPLEX_FULL)
29461 ? "full" : "half");
29462 }
29463- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
29464+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
29465 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
29466 if (lp->mii_if.full_duplex)
29467 bcr9 |= (1 << 0);
29468 else
29469 bcr9 &= ~(1 << 0);
29470- lp->a.write_bcr(dev->base_addr, 9, bcr9);
29471+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
29472 }
29473 } else {
29474 netif_info(lp, link, dev, "link up\n");
29475diff -urNp linux-3.0.4/drivers/net/ppp_generic.c linux-3.0.4/drivers/net/ppp_generic.c
29476--- linux-3.0.4/drivers/net/ppp_generic.c 2011-07-21 22:17:23.000000000 -0400
29477+++ linux-3.0.4/drivers/net/ppp_generic.c 2011-08-23 21:47:55.000000000 -0400
29478@@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, st
29479 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
29480 struct ppp_stats stats;
29481 struct ppp_comp_stats cstats;
29482- char *vers;
29483
29484 switch (cmd) {
29485 case SIOCGPPPSTATS:
29486@@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, st
29487 break;
29488
29489 case SIOCGPPPVER:
29490- vers = PPP_VERSION;
29491- if (copy_to_user(addr, vers, strlen(vers) + 1))
29492+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
29493 break;
29494 err = 0;
29495 break;
29496diff -urNp linux-3.0.4/drivers/net/r8169.c linux-3.0.4/drivers/net/r8169.c
29497--- linux-3.0.4/drivers/net/r8169.c 2011-08-23 21:44:40.000000000 -0400
29498+++ linux-3.0.4/drivers/net/r8169.c 2011-08-23 21:47:55.000000000 -0400
29499@@ -645,12 +645,12 @@ struct rtl8169_private {
29500 struct mdio_ops {
29501 void (*write)(void __iomem *, int, int);
29502 int (*read)(void __iomem *, int);
29503- } mdio_ops;
29504+ } __no_const mdio_ops;
29505
29506 struct pll_power_ops {
29507 void (*down)(struct rtl8169_private *);
29508 void (*up)(struct rtl8169_private *);
29509- } pll_power_ops;
29510+ } __no_const pll_power_ops;
29511
29512 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
29513 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
29514diff -urNp linux-3.0.4/drivers/net/tg3.h linux-3.0.4/drivers/net/tg3.h
29515--- linux-3.0.4/drivers/net/tg3.h 2011-07-21 22:17:23.000000000 -0400
29516+++ linux-3.0.4/drivers/net/tg3.h 2011-08-23 21:47:55.000000000 -0400
29517@@ -134,6 +134,7 @@
29518 #define CHIPREV_ID_5750_A0 0x4000
29519 #define CHIPREV_ID_5750_A1 0x4001
29520 #define CHIPREV_ID_5750_A3 0x4003
29521+#define CHIPREV_ID_5750_C1 0x4201
29522 #define CHIPREV_ID_5750_C2 0x4202
29523 #define CHIPREV_ID_5752_A0_HW 0x5000
29524 #define CHIPREV_ID_5752_A0 0x6000
29525diff -urNp linux-3.0.4/drivers/net/tokenring/abyss.c linux-3.0.4/drivers/net/tokenring/abyss.c
29526--- linux-3.0.4/drivers/net/tokenring/abyss.c 2011-07-21 22:17:23.000000000 -0400
29527+++ linux-3.0.4/drivers/net/tokenring/abyss.c 2011-08-23 21:47:55.000000000 -0400
29528@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver =
29529
29530 static int __init abyss_init (void)
29531 {
29532- abyss_netdev_ops = tms380tr_netdev_ops;
29533+ pax_open_kernel();
29534+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
29535
29536- abyss_netdev_ops.ndo_open = abyss_open;
29537- abyss_netdev_ops.ndo_stop = abyss_close;
29538+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
29539+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
29540+ pax_close_kernel();
29541
29542 return pci_register_driver(&abyss_driver);
29543 }
29544diff -urNp linux-3.0.4/drivers/net/tokenring/madgemc.c linux-3.0.4/drivers/net/tokenring/madgemc.c
29545--- linux-3.0.4/drivers/net/tokenring/madgemc.c 2011-07-21 22:17:23.000000000 -0400
29546+++ linux-3.0.4/drivers/net/tokenring/madgemc.c 2011-08-23 21:47:55.000000000 -0400
29547@@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver
29548
29549 static int __init madgemc_init (void)
29550 {
29551- madgemc_netdev_ops = tms380tr_netdev_ops;
29552- madgemc_netdev_ops.ndo_open = madgemc_open;
29553- madgemc_netdev_ops.ndo_stop = madgemc_close;
29554+ pax_open_kernel();
29555+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
29556+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
29557+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
29558+ pax_close_kernel();
29559
29560 return mca_register_driver (&madgemc_driver);
29561 }
29562diff -urNp linux-3.0.4/drivers/net/tokenring/proteon.c linux-3.0.4/drivers/net/tokenring/proteon.c
29563--- linux-3.0.4/drivers/net/tokenring/proteon.c 2011-07-21 22:17:23.000000000 -0400
29564+++ linux-3.0.4/drivers/net/tokenring/proteon.c 2011-08-23 21:47:55.000000000 -0400
29565@@ -353,9 +353,11 @@ static int __init proteon_init(void)
29566 struct platform_device *pdev;
29567 int i, num = 0, err = 0;
29568
29569- proteon_netdev_ops = tms380tr_netdev_ops;
29570- proteon_netdev_ops.ndo_open = proteon_open;
29571- proteon_netdev_ops.ndo_stop = tms380tr_close;
29572+ pax_open_kernel();
29573+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
29574+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
29575+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
29576+ pax_close_kernel();
29577
29578 err = platform_driver_register(&proteon_driver);
29579 if (err)
29580diff -urNp linux-3.0.4/drivers/net/tokenring/skisa.c linux-3.0.4/drivers/net/tokenring/skisa.c
29581--- linux-3.0.4/drivers/net/tokenring/skisa.c 2011-07-21 22:17:23.000000000 -0400
29582+++ linux-3.0.4/drivers/net/tokenring/skisa.c 2011-08-23 21:47:55.000000000 -0400
29583@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
29584 struct platform_device *pdev;
29585 int i, num = 0, err = 0;
29586
29587- sk_isa_netdev_ops = tms380tr_netdev_ops;
29588- sk_isa_netdev_ops.ndo_open = sk_isa_open;
29589- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
29590+ pax_open_kernel();
29591+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
29592+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
29593+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
29594+ pax_close_kernel();
29595
29596 err = platform_driver_register(&sk_isa_driver);
29597 if (err)
29598diff -urNp linux-3.0.4/drivers/net/tulip/de2104x.c linux-3.0.4/drivers/net/tulip/de2104x.c
29599--- linux-3.0.4/drivers/net/tulip/de2104x.c 2011-07-21 22:17:23.000000000 -0400
29600+++ linux-3.0.4/drivers/net/tulip/de2104x.c 2011-08-23 21:48:14.000000000 -0400
29601@@ -1794,6 +1794,8 @@ static void __devinit de21041_get_srom_i
29602 struct de_srom_info_leaf *il;
29603 void *bufp;
29604
29605+ pax_track_stack();
29606+
29607 /* download entire eeprom */
29608 for (i = 0; i < DE_EEPROM_WORDS; i++)
29609 ((__le16 *)ee_data)[i] =
29610diff -urNp linux-3.0.4/drivers/net/tulip/de4x5.c linux-3.0.4/drivers/net/tulip/de4x5.c
29611--- linux-3.0.4/drivers/net/tulip/de4x5.c 2011-07-21 22:17:23.000000000 -0400
29612+++ linux-3.0.4/drivers/net/tulip/de4x5.c 2011-08-23 21:47:55.000000000 -0400
29613@@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
29614 for (i=0; i<ETH_ALEN; i++) {
29615 tmp.addr[i] = dev->dev_addr[i];
29616 }
29617- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
29618+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
29619 break;
29620
29621 case DE4X5_SET_HWADDR: /* Set the hardware address */
29622@@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
29623 spin_lock_irqsave(&lp->lock, flags);
29624 memcpy(&statbuf, &lp->pktStats, ioc->len);
29625 spin_unlock_irqrestore(&lp->lock, flags);
29626- if (copy_to_user(ioc->data, &statbuf, ioc->len))
29627+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
29628 return -EFAULT;
29629 break;
29630 }
29631diff -urNp linux-3.0.4/drivers/net/usb/hso.c linux-3.0.4/drivers/net/usb/hso.c
29632--- linux-3.0.4/drivers/net/usb/hso.c 2011-07-21 22:17:23.000000000 -0400
29633+++ linux-3.0.4/drivers/net/usb/hso.c 2011-08-23 21:47:55.000000000 -0400
29634@@ -71,7 +71,7 @@
29635 #include <asm/byteorder.h>
29636 #include <linux/serial_core.h>
29637 #include <linux/serial.h>
29638-
29639+#include <asm/local.h>
29640
29641 #define MOD_AUTHOR "Option Wireless"
29642 #define MOD_DESCRIPTION "USB High Speed Option driver"
29643@@ -257,7 +257,7 @@ struct hso_serial {
29644
29645 /* from usb_serial_port */
29646 struct tty_struct *tty;
29647- int open_count;
29648+ local_t open_count;
29649 spinlock_t serial_lock;
29650
29651 int (*write_data) (struct hso_serial *serial);
29652@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_
29653 struct urb *urb;
29654
29655 urb = serial->rx_urb[0];
29656- if (serial->open_count > 0) {
29657+ if (local_read(&serial->open_count) > 0) {
29658 count = put_rxbuf_data(urb, serial);
29659 if (count == -1)
29660 return;
29661@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_cal
29662 DUMP1(urb->transfer_buffer, urb->actual_length);
29663
29664 /* Anyone listening? */
29665- if (serial->open_count == 0)
29666+ if (local_read(&serial->open_count) == 0)
29667 return;
29668
29669 if (status == 0) {
29670@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
29671 spin_unlock_irq(&serial->serial_lock);
29672
29673 /* check for port already opened, if not set the termios */
29674- serial->open_count++;
29675- if (serial->open_count == 1) {
29676+ if (local_inc_return(&serial->open_count) == 1) {
29677 serial->rx_state = RX_IDLE;
29678 /* Force default termio settings */
29679 _hso_serial_set_termios(tty, NULL);
29680@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_st
29681 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
29682 if (result) {
29683 hso_stop_serial_device(serial->parent);
29684- serial->open_count--;
29685+ local_dec(&serial->open_count);
29686 kref_put(&serial->parent->ref, hso_serial_ref_free);
29687 }
29688 } else {
29689@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_
29690
29691 /* reset the rts and dtr */
29692 /* do the actual close */
29693- serial->open_count--;
29694+ local_dec(&serial->open_count);
29695
29696- if (serial->open_count <= 0) {
29697- serial->open_count = 0;
29698+ if (local_read(&serial->open_count) <= 0) {
29699+ local_set(&serial->open_count, 0);
29700 spin_lock_irq(&serial->serial_lock);
29701 if (serial->tty == tty) {
29702 serial->tty->driver_data = NULL;
29703@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struc
29704
29705 /* the actual setup */
29706 spin_lock_irqsave(&serial->serial_lock, flags);
29707- if (serial->open_count)
29708+ if (local_read(&serial->open_count))
29709 _hso_serial_set_termios(tty, old);
29710 else
29711 tty->termios = old;
29712@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *ur
29713 D1("Pending read interrupt on port %d\n", i);
29714 spin_lock(&serial->serial_lock);
29715 if (serial->rx_state == RX_IDLE &&
29716- serial->open_count > 0) {
29717+ local_read(&serial->open_count) > 0) {
29718 /* Setup and send a ctrl req read on
29719 * port i */
29720 if (!serial->rx_urb_filled[0]) {
29721@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interfa
29722 /* Start all serial ports */
29723 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
29724 if (serial_table[i] && (serial_table[i]->interface == iface)) {
29725- if (dev2ser(serial_table[i])->open_count) {
29726+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
29727 result =
29728 hso_start_serial_device(serial_table[i], GFP_NOIO);
29729 hso_kick_transmit(dev2ser(serial_table[i]));
29730diff -urNp linux-3.0.4/drivers/net/vmxnet3/vmxnet3_ethtool.c linux-3.0.4/drivers/net/vmxnet3/vmxnet3_ethtool.c
29731--- linux-3.0.4/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-07-21 22:17:23.000000000 -0400
29732+++ linux-3.0.4/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-08-23 21:47:55.000000000 -0400
29733@@ -594,8 +594,7 @@ vmxnet3_set_rss_indir(struct net_device
29734 * Return with error code if any of the queue indices
29735 * is out of range
29736 */
29737- if (p->ring_index[i] < 0 ||
29738- p->ring_index[i] >= adapter->num_rx_queues)
29739+ if (p->ring_index[i] >= adapter->num_rx_queues)
29740 return -EINVAL;
29741 }
29742
29743diff -urNp linux-3.0.4/drivers/net/vxge/vxge-config.h linux-3.0.4/drivers/net/vxge/vxge-config.h
29744--- linux-3.0.4/drivers/net/vxge/vxge-config.h 2011-07-21 22:17:23.000000000 -0400
29745+++ linux-3.0.4/drivers/net/vxge/vxge-config.h 2011-08-23 21:47:55.000000000 -0400
29746@@ -512,7 +512,7 @@ struct vxge_hw_uld_cbs {
29747 void (*link_down)(struct __vxge_hw_device *devh);
29748 void (*crit_err)(struct __vxge_hw_device *devh,
29749 enum vxge_hw_event type, u64 ext_data);
29750-};
29751+} __no_const;
29752
29753 /*
29754 * struct __vxge_hw_blockpool_entry - Block private data structure
29755diff -urNp linux-3.0.4/drivers/net/vxge/vxge-main.c linux-3.0.4/drivers/net/vxge/vxge-main.c
29756--- linux-3.0.4/drivers/net/vxge/vxge-main.c 2011-07-21 22:17:23.000000000 -0400
29757+++ linux-3.0.4/drivers/net/vxge/vxge-main.c 2011-08-23 21:48:14.000000000 -0400
29758@@ -98,6 +98,8 @@ static inline void VXGE_COMPLETE_VPATH_T
29759 struct sk_buff *completed[NR_SKB_COMPLETED];
29760 int more;
29761
29762+ pax_track_stack();
29763+
29764 do {
29765 more = 0;
29766 skb_ptr = completed;
29767@@ -1920,6 +1922,8 @@ static enum vxge_hw_status vxge_rth_conf
29768 u8 mtable[256] = {0}; /* CPU to vpath mapping */
29769 int index;
29770
29771+ pax_track_stack();
29772+
29773 /*
29774 * Filling
29775 * - itable with bucket numbers
29776diff -urNp linux-3.0.4/drivers/net/vxge/vxge-traffic.h linux-3.0.4/drivers/net/vxge/vxge-traffic.h
29777--- linux-3.0.4/drivers/net/vxge/vxge-traffic.h 2011-07-21 22:17:23.000000000 -0400
29778+++ linux-3.0.4/drivers/net/vxge/vxge-traffic.h 2011-08-23 21:47:55.000000000 -0400
29779@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
29780 struct vxge_hw_mempool_dma *dma_object,
29781 u32 index,
29782 u32 is_last);
29783-};
29784+} __no_const;
29785
29786 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
29787 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
29788diff -urNp linux-3.0.4/drivers/net/wan/cycx_x25.c linux-3.0.4/drivers/net/wan/cycx_x25.c
29789--- linux-3.0.4/drivers/net/wan/cycx_x25.c 2011-07-21 22:17:23.000000000 -0400
29790+++ linux-3.0.4/drivers/net/wan/cycx_x25.c 2011-08-23 21:48:14.000000000 -0400
29791@@ -1018,6 +1018,8 @@ static void hex_dump(char *msg, unsigned
29792 unsigned char hex[1024],
29793 * phex = hex;
29794
29795+ pax_track_stack();
29796+
29797 if (len >= (sizeof(hex) / 2))
29798 len = (sizeof(hex) / 2) - 1;
29799
29800diff -urNp linux-3.0.4/drivers/net/wan/hdlc_x25.c linux-3.0.4/drivers/net/wan/hdlc_x25.c
29801--- linux-3.0.4/drivers/net/wan/hdlc_x25.c 2011-07-21 22:17:23.000000000 -0400
29802+++ linux-3.0.4/drivers/net/wan/hdlc_x25.c 2011-08-23 21:47:55.000000000 -0400
29803@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_bu
29804
29805 static int x25_open(struct net_device *dev)
29806 {
29807- struct lapb_register_struct cb;
29808+ static struct lapb_register_struct cb = {
29809+ .connect_confirmation = x25_connected,
29810+ .connect_indication = x25_connected,
29811+ .disconnect_confirmation = x25_disconnected,
29812+ .disconnect_indication = x25_disconnected,
29813+ .data_indication = x25_data_indication,
29814+ .data_transmit = x25_data_transmit
29815+ };
29816 int result;
29817
29818- cb.connect_confirmation = x25_connected;
29819- cb.connect_indication = x25_connected;
29820- cb.disconnect_confirmation = x25_disconnected;
29821- cb.disconnect_indication = x25_disconnected;
29822- cb.data_indication = x25_data_indication;
29823- cb.data_transmit = x25_data_transmit;
29824-
29825 result = lapb_register(dev, &cb);
29826 if (result != LAPB_OK)
29827 return result;
29828diff -urNp linux-3.0.4/drivers/net/wimax/i2400m/usb-fw.c linux-3.0.4/drivers/net/wimax/i2400m/usb-fw.c
29829--- linux-3.0.4/drivers/net/wimax/i2400m/usb-fw.c 2011-07-21 22:17:23.000000000 -0400
29830+++ linux-3.0.4/drivers/net/wimax/i2400m/usb-fw.c 2011-08-23 21:48:14.000000000 -0400
29831@@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
29832 int do_autopm = 1;
29833 DECLARE_COMPLETION_ONSTACK(notif_completion);
29834
29835+ pax_track_stack();
29836+
29837 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
29838 i2400m, ack, ack_size);
29839 BUG_ON(_ack == i2400m->bm_ack_buf);
29840diff -urNp linux-3.0.4/drivers/net/wireless/airo.c linux-3.0.4/drivers/net/wireless/airo.c
29841--- linux-3.0.4/drivers/net/wireless/airo.c 2011-08-23 21:44:40.000000000 -0400
29842+++ linux-3.0.4/drivers/net/wireless/airo.c 2011-08-23 21:48:14.000000000 -0400
29843@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (s
29844 BSSListElement * loop_net;
29845 BSSListElement * tmp_net;
29846
29847+ pax_track_stack();
29848+
29849 /* Blow away current list of scan results */
29850 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
29851 list_move_tail (&loop_net->list, &ai->network_free_list);
29852@@ -3794,6 +3796,8 @@ static u16 setup_card(struct airo_info *
29853 WepKeyRid wkr;
29854 int rc;
29855
29856+ pax_track_stack();
29857+
29858 memset( &mySsid, 0, sizeof( mySsid ) );
29859 kfree (ai->flash);
29860 ai->flash = NULL;
29861@@ -4753,6 +4757,8 @@ static int proc_stats_rid_open( struct i
29862 __le32 *vals = stats.vals;
29863 int len;
29864
29865+ pax_track_stack();
29866+
29867 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
29868 return -ENOMEM;
29869 data = file->private_data;
29870@@ -5476,6 +5482,8 @@ static int proc_BSSList_open( struct ino
29871 /* If doLoseSync is not 1, we won't do a Lose Sync */
29872 int doLoseSync = -1;
29873
29874+ pax_track_stack();
29875+
29876 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
29877 return -ENOMEM;
29878 data = file->private_data;
29879@@ -7181,6 +7189,8 @@ static int airo_get_aplist(struct net_de
29880 int i;
29881 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
29882
29883+ pax_track_stack();
29884+
29885 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
29886 if (!qual)
29887 return -ENOMEM;
29888@@ -7741,6 +7751,8 @@ static void airo_read_wireless_stats(str
29889 CapabilityRid cap_rid;
29890 __le32 *vals = stats_rid.vals;
29891
29892+ pax_track_stack();
29893+
29894 /* Get stats out of the card */
29895 clear_bit(JOB_WSTATS, &local->jobs);
29896 if (local->power.event) {
29897diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath5k/debug.c linux-3.0.4/drivers/net/wireless/ath/ath5k/debug.c
29898--- linux-3.0.4/drivers/net/wireless/ath/ath5k/debug.c 2011-07-21 22:17:23.000000000 -0400
29899+++ linux-3.0.4/drivers/net/wireless/ath/ath5k/debug.c 2011-08-23 21:48:14.000000000 -0400
29900@@ -204,6 +204,8 @@ static ssize_t read_file_beacon(struct f
29901 unsigned int v;
29902 u64 tsf;
29903
29904+ pax_track_stack();
29905+
29906 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
29907 len += snprintf(buf+len, sizeof(buf)-len,
29908 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
29909@@ -323,6 +325,8 @@ static ssize_t read_file_debug(struct fi
29910 unsigned int len = 0;
29911 unsigned int i;
29912
29913+ pax_track_stack();
29914+
29915 len += snprintf(buf+len, sizeof(buf)-len,
29916 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
29917
29918@@ -384,6 +388,8 @@ static ssize_t read_file_antenna(struct
29919 unsigned int i;
29920 unsigned int v;
29921
29922+ pax_track_stack();
29923+
29924 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
29925 sc->ah->ah_ant_mode);
29926 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
29927@@ -494,6 +500,8 @@ static ssize_t read_file_misc(struct fil
29928 unsigned int len = 0;
29929 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
29930
29931+ pax_track_stack();
29932+
29933 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
29934 sc->bssidmask);
29935 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
29936@@ -550,6 +558,8 @@ static ssize_t read_file_frameerrors(str
29937 unsigned int len = 0;
29938 int i;
29939
29940+ pax_track_stack();
29941+
29942 len += snprintf(buf+len, sizeof(buf)-len,
29943 "RX\n---------------------\n");
29944 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
29945@@ -667,6 +677,8 @@ static ssize_t read_file_ani(struct file
29946 char buf[700];
29947 unsigned int len = 0;
29948
29949+ pax_track_stack();
29950+
29951 len += snprintf(buf+len, sizeof(buf)-len,
29952 "HW has PHY error counters:\t%s\n",
29953 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
29954@@ -827,6 +839,8 @@ static ssize_t read_file_queue(struct fi
29955 struct ath5k_buf *bf, *bf0;
29956 int i, n;
29957
29958+ pax_track_stack();
29959+
29960 len += snprintf(buf+len, sizeof(buf)-len,
29961 "available txbuffers: %d\n", sc->txbuf_len);
29962
29963diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_calib.c linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_calib.c
29964--- linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-07-21 22:17:23.000000000 -0400
29965+++ linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-08-23 21:48:14.000000000 -0400
29966@@ -757,6 +757,8 @@ static void ar9003_hw_tx_iq_cal_post_pro
29967 int i, im, j;
29968 int nmeasurement;
29969
29970+ pax_track_stack();
29971+
29972 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
29973 if (ah->txchainmask & (1 << i))
29974 num_chains++;
29975diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_paprd.c linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
29976--- linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-07-21 22:17:23.000000000 -0400
29977+++ linux-3.0.4/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-08-23 21:48:14.000000000 -0400
29978@@ -356,6 +356,8 @@ static bool create_pa_curve(u32 *data_L,
29979 int theta_low_bin = 0;
29980 int i;
29981
29982+ pax_track_stack();
29983+
29984 /* disregard any bin that contains <= 16 samples */
29985 thresh_accum_cnt = 16;
29986 scale_factor = 5;
29987diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath9k/debug.c linux-3.0.4/drivers/net/wireless/ath/ath9k/debug.c
29988--- linux-3.0.4/drivers/net/wireless/ath/ath9k/debug.c 2011-07-21 22:17:23.000000000 -0400
29989+++ linux-3.0.4/drivers/net/wireless/ath/ath9k/debug.c 2011-08-23 21:48:14.000000000 -0400
29990@@ -337,6 +337,8 @@ static ssize_t read_file_interrupt(struc
29991 char buf[512];
29992 unsigned int len = 0;
29993
29994+ pax_track_stack();
29995+
29996 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
29997 len += snprintf(buf + len, sizeof(buf) - len,
29998 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
29999@@ -427,6 +429,8 @@ static ssize_t read_file_wiphy(struct fi
30000 u8 addr[ETH_ALEN];
30001 u32 tmp;
30002
30003+ pax_track_stack();
30004+
30005 len += snprintf(buf + len, sizeof(buf) - len,
30006 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
30007 wiphy_name(sc->hw->wiphy),
30008diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath9k/htc_drv_debug.c linux-3.0.4/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
30009--- linux-3.0.4/drivers/net/wireless/ath/ath9k/htc_drv_debug.c 2011-07-21 22:17:23.000000000 -0400
30010+++ linux-3.0.4/drivers/net/wireless/ath/ath9k/htc_drv_debug.c 2011-08-23 21:48:14.000000000 -0400
30011@@ -31,6 +31,8 @@ static ssize_t read_file_tgt_int_stats(s
30012 unsigned int len = 0;
30013 int ret = 0;
30014
30015+ pax_track_stack();
30016+
30017 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
30018
30019 ath9k_htc_ps_wakeup(priv);
30020@@ -89,6 +91,8 @@ static ssize_t read_file_tgt_tx_stats(st
30021 unsigned int len = 0;
30022 int ret = 0;
30023
30024+ pax_track_stack();
30025+
30026 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
30027
30028 ath9k_htc_ps_wakeup(priv);
30029@@ -159,6 +163,8 @@ static ssize_t read_file_tgt_rx_stats(st
30030 unsigned int len = 0;
30031 int ret = 0;
30032
30033+ pax_track_stack();
30034+
30035 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
30036
30037 ath9k_htc_ps_wakeup(priv);
30038@@ -203,6 +209,8 @@ static ssize_t read_file_xmit(struct fil
30039 char buf[512];
30040 unsigned int len = 0;
30041
30042+ pax_track_stack();
30043+
30044 len += snprintf(buf + len, sizeof(buf) - len,
30045 "%20s : %10u\n", "Buffers queued",
30046 priv->debug.tx_stats.buf_queued);
30047@@ -376,6 +384,8 @@ static ssize_t read_file_slot(struct fil
30048 char buf[512];
30049 unsigned int len = 0;
30050
30051+ pax_track_stack();
30052+
30053 spin_lock_bh(&priv->tx.tx_lock);
30054
30055 len += snprintf(buf + len, sizeof(buf) - len, "TX slot bitmap : ");
30056@@ -411,6 +421,8 @@ static ssize_t read_file_queue(struct fi
30057 char buf[512];
30058 unsigned int len = 0;
30059
30060+ pax_track_stack();
30061+
30062 len += snprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n",
30063 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue));
30064
30065diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath9k/hw.h linux-3.0.4/drivers/net/wireless/ath/ath9k/hw.h
30066--- linux-3.0.4/drivers/net/wireless/ath/ath9k/hw.h 2011-08-23 21:44:40.000000000 -0400
30067+++ linux-3.0.4/drivers/net/wireless/ath/ath9k/hw.h 2011-08-23 21:47:55.000000000 -0400
30068@@ -585,7 +585,7 @@ struct ath_hw_private_ops {
30069
30070 /* ANI */
30071 void (*ani_cache_ini_regs)(struct ath_hw *ah);
30072-};
30073+} __no_const;
30074
30075 /**
30076 * struct ath_hw_ops - callbacks used by hardware code and driver code
30077@@ -637,7 +637,7 @@ struct ath_hw_ops {
30078 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
30079 struct ath_hw_antcomb_conf *antconf);
30080
30081-};
30082+} __no_const;
30083
30084 struct ath_nf_limits {
30085 s16 max;
30086@@ -650,7 +650,7 @@ struct ath_nf_limits {
30087 #define AH_UNPLUGGED 0x2 /* The card has been physically removed. */
30088
30089 struct ath_hw {
30090- struct ath_ops reg_ops;
30091+ ath_ops_no_const reg_ops;
30092
30093 struct ieee80211_hw *hw;
30094 struct ath_common common;
30095diff -urNp linux-3.0.4/drivers/net/wireless/ath/ath.h linux-3.0.4/drivers/net/wireless/ath/ath.h
30096--- linux-3.0.4/drivers/net/wireless/ath/ath.h 2011-07-21 22:17:23.000000000 -0400
30097+++ linux-3.0.4/drivers/net/wireless/ath/ath.h 2011-08-23 21:47:55.000000000 -0400
30098@@ -121,6 +121,7 @@ struct ath_ops {
30099 void (*write_flush) (void *);
30100 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
30101 };
30102+typedef struct ath_ops __no_const ath_ops_no_const;
30103
30104 struct ath_common;
30105 struct ath_bus_ops;
30106diff -urNp linux-3.0.4/drivers/net/wireless/ipw2x00/ipw2100.c linux-3.0.4/drivers/net/wireless/ipw2x00/ipw2100.c
30107--- linux-3.0.4/drivers/net/wireless/ipw2x00/ipw2100.c 2011-07-21 22:17:23.000000000 -0400
30108+++ linux-3.0.4/drivers/net/wireless/ipw2x00/ipw2100.c 2011-08-23 21:48:14.000000000 -0400
30109@@ -2100,6 +2100,8 @@ static int ipw2100_set_essid(struct ipw2
30110 int err;
30111 DECLARE_SSID_BUF(ssid);
30112
30113+ pax_track_stack();
30114+
30115 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
30116
30117 if (ssid_len)
30118@@ -5449,6 +5451,8 @@ static int ipw2100_set_key(struct ipw210
30119 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
30120 int err;
30121
30122+ pax_track_stack();
30123+
30124 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
30125 idx, keylen, len);
30126
30127diff -urNp linux-3.0.4/drivers/net/wireless/ipw2x00/libipw_rx.c linux-3.0.4/drivers/net/wireless/ipw2x00/libipw_rx.c
30128--- linux-3.0.4/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-07-21 22:17:23.000000000 -0400
30129+++ linux-3.0.4/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-08-23 21:48:14.000000000 -0400
30130@@ -1565,6 +1565,8 @@ static void libipw_process_probe_respons
30131 unsigned long flags;
30132 DECLARE_SSID_BUF(ssid);
30133
30134+ pax_track_stack();
30135+
30136 LIBIPW_DEBUG_SCAN("'%s' (%pM"
30137 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
30138 print_ssid(ssid, info_element->data, info_element->len),
30139diff -urNp linux-3.0.4/drivers/net/wireless/iwlegacy/iwl3945-base.c linux-3.0.4/drivers/net/wireless/iwlegacy/iwl3945-base.c
30140--- linux-3.0.4/drivers/net/wireless/iwlegacy/iwl3945-base.c 2011-07-21 22:17:23.000000000 -0400
30141+++ linux-3.0.4/drivers/net/wireless/iwlegacy/iwl3945-base.c 2011-08-23 21:47:55.000000000 -0400
30142@@ -3962,7 +3962,9 @@ static int iwl3945_pci_probe(struct pci_
30143 */
30144 if (iwl3945_mod_params.disable_hw_scan) {
30145 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
30146- iwl3945_hw_ops.hw_scan = NULL;
30147+ pax_open_kernel();
30148+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
30149+ pax_close_kernel();
30150 }
30151
30152 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
30153diff -urNp linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
30154--- linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-07-21 22:17:23.000000000 -0400
30155+++ linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-08-23 21:48:14.000000000 -0400
30156@@ -910,6 +910,8 @@ static void rs_tx_status(void *priv_r, s
30157 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
30158 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
30159
30160+ pax_track_stack();
30161+
30162 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
30163
30164 /* Treat uninitialized rate scaling data same as non-existing. */
30165@@ -2918,6 +2920,8 @@ static void rs_fill_link_cmd(struct iwl_
30166 container_of(lq_sta, struct iwl_station_priv, lq_sta);
30167 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
30168
30169+ pax_track_stack();
30170+
30171 /* Override starting rate (index 0) if needed for debug purposes */
30172 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
30173
30174diff -urNp linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debugfs.c
30175--- linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-07-21 22:17:23.000000000 -0400
30176+++ linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-08-23 21:48:14.000000000 -0400
30177@@ -548,6 +548,8 @@ static ssize_t iwl_dbgfs_status_read(str
30178 int pos = 0;
30179 const size_t bufsz = sizeof(buf);
30180
30181+ pax_track_stack();
30182+
30183 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
30184 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
30185 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
30186@@ -680,6 +682,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
30187 char buf[256 * NUM_IWL_RXON_CTX];
30188 const size_t bufsz = sizeof(buf);
30189
30190+ pax_track_stack();
30191+
30192 for_each_context(priv, ctx) {
30193 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
30194 ctx->ctxid);
30195diff -urNp linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debug.h linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debug.h
30196--- linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-07-21 22:17:23.000000000 -0400
30197+++ linux-3.0.4/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-08-23 21:47:55.000000000 -0400
30198@@ -68,8 +68,8 @@ do {
30199 } while (0)
30200
30201 #else
30202-#define IWL_DEBUG(__priv, level, fmt, args...)
30203-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
30204+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
30205+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
30206 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
30207 const void *p, u32 len)
30208 {}
30209diff -urNp linux-3.0.4/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-3.0.4/drivers/net/wireless/iwmc3200wifi/debugfs.c
30210--- linux-3.0.4/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-07-21 22:17:23.000000000 -0400
30211+++ linux-3.0.4/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-08-23 21:48:14.000000000 -0400
30212@@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
30213 int buf_len = 512;
30214 size_t len = 0;
30215
30216+ pax_track_stack();
30217+
30218 if (*ppos != 0)
30219 return 0;
30220 if (count < sizeof(buf))
30221diff -urNp linux-3.0.4/drivers/net/wireless/mac80211_hwsim.c linux-3.0.4/drivers/net/wireless/mac80211_hwsim.c
30222--- linux-3.0.4/drivers/net/wireless/mac80211_hwsim.c 2011-07-21 22:17:23.000000000 -0400
30223+++ linux-3.0.4/drivers/net/wireless/mac80211_hwsim.c 2011-08-23 21:47:55.000000000 -0400
30224@@ -1260,9 +1260,11 @@ static int __init init_mac80211_hwsim(vo
30225 return -EINVAL;
30226
30227 if (fake_hw_scan) {
30228- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
30229- mac80211_hwsim_ops.sw_scan_start = NULL;
30230- mac80211_hwsim_ops.sw_scan_complete = NULL;
30231+ pax_open_kernel();
30232+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
30233+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
30234+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
30235+ pax_close_kernel();
30236 }
30237
30238 spin_lock_init(&hwsim_radio_lock);
30239diff -urNp linux-3.0.4/drivers/net/wireless/rndis_wlan.c linux-3.0.4/drivers/net/wireless/rndis_wlan.c
30240--- linux-3.0.4/drivers/net/wireless/rndis_wlan.c 2011-07-21 22:17:23.000000000 -0400
30241+++ linux-3.0.4/drivers/net/wireless/rndis_wlan.c 2011-08-23 21:47:55.000000000 -0400
30242@@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbn
30243
30244 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
30245
30246- if (rts_threshold < 0 || rts_threshold > 2347)
30247+ if (rts_threshold > 2347)
30248 rts_threshold = 2347;
30249
30250 tmp = cpu_to_le32(rts_threshold);
30251diff -urNp linux-3.0.4/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c linux-3.0.4/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
30252--- linux-3.0.4/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-07-21 22:17:23.000000000 -0400
30253+++ linux-3.0.4/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-08-23 21:48:14.000000000 -0400
30254@@ -837,6 +837,8 @@ bool _rtl92c_phy_sw_chnl_step_by_step(st
30255 u8 rfpath;
30256 u8 num_total_rfpath = rtlphy->num_total_rfpath;
30257
30258+ pax_track_stack();
30259+
30260 precommoncmdcnt = 0;
30261 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
30262 MAX_PRECMD_CNT,
30263diff -urNp linux-3.0.4/drivers/net/wireless/wl1251/wl1251.h linux-3.0.4/drivers/net/wireless/wl1251/wl1251.h
30264--- linux-3.0.4/drivers/net/wireless/wl1251/wl1251.h 2011-07-21 22:17:23.000000000 -0400
30265+++ linux-3.0.4/drivers/net/wireless/wl1251/wl1251.h 2011-08-23 21:47:55.000000000 -0400
30266@@ -266,7 +266,7 @@ struct wl1251_if_operations {
30267 void (*reset)(struct wl1251 *wl);
30268 void (*enable_irq)(struct wl1251 *wl);
30269 void (*disable_irq)(struct wl1251 *wl);
30270-};
30271+} __no_const;
30272
30273 struct wl1251 {
30274 struct ieee80211_hw *hw;
30275diff -urNp linux-3.0.4/drivers/net/wireless/wl12xx/spi.c linux-3.0.4/drivers/net/wireless/wl12xx/spi.c
30276--- linux-3.0.4/drivers/net/wireless/wl12xx/spi.c 2011-07-21 22:17:23.000000000 -0400
30277+++ linux-3.0.4/drivers/net/wireless/wl12xx/spi.c 2011-08-23 21:48:14.000000000 -0400
30278@@ -280,6 +280,8 @@ static void wl1271_spi_raw_write(struct
30279 u32 chunk_len;
30280 int i;
30281
30282+ pax_track_stack();
30283+
30284 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
30285
30286 spi_message_init(&m);
30287diff -urNp linux-3.0.4/drivers/oprofile/buffer_sync.c linux-3.0.4/drivers/oprofile/buffer_sync.c
30288--- linux-3.0.4/drivers/oprofile/buffer_sync.c 2011-07-21 22:17:23.000000000 -0400
30289+++ linux-3.0.4/drivers/oprofile/buffer_sync.c 2011-08-23 21:47:55.000000000 -0400
30290@@ -343,7 +343,7 @@ static void add_data(struct op_entry *en
30291 if (cookie == NO_COOKIE)
30292 offset = pc;
30293 if (cookie == INVALID_COOKIE) {
30294- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
30295+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
30296 offset = pc;
30297 }
30298 if (cookie != last_cookie) {
30299@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct
30300 /* add userspace sample */
30301
30302 if (!mm) {
30303- atomic_inc(&oprofile_stats.sample_lost_no_mm);
30304+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
30305 return 0;
30306 }
30307
30308 cookie = lookup_dcookie(mm, s->eip, &offset);
30309
30310 if (cookie == INVALID_COOKIE) {
30311- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
30312+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
30313 return 0;
30314 }
30315
30316@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
30317 /* ignore backtraces if failed to add a sample */
30318 if (state == sb_bt_start) {
30319 state = sb_bt_ignore;
30320- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
30321+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
30322 }
30323 }
30324 release_mm(mm);
30325diff -urNp linux-3.0.4/drivers/oprofile/event_buffer.c linux-3.0.4/drivers/oprofile/event_buffer.c
30326--- linux-3.0.4/drivers/oprofile/event_buffer.c 2011-07-21 22:17:23.000000000 -0400
30327+++ linux-3.0.4/drivers/oprofile/event_buffer.c 2011-08-23 21:47:55.000000000 -0400
30328@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
30329 }
30330
30331 if (buffer_pos == buffer_size) {
30332- atomic_inc(&oprofile_stats.event_lost_overflow);
30333+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
30334 return;
30335 }
30336
30337diff -urNp linux-3.0.4/drivers/oprofile/oprof.c linux-3.0.4/drivers/oprofile/oprof.c
30338--- linux-3.0.4/drivers/oprofile/oprof.c 2011-07-21 22:17:23.000000000 -0400
30339+++ linux-3.0.4/drivers/oprofile/oprof.c 2011-08-23 21:47:55.000000000 -0400
30340@@ -110,7 +110,7 @@ static void switch_worker(struct work_st
30341 if (oprofile_ops.switch_events())
30342 return;
30343
30344- atomic_inc(&oprofile_stats.multiplex_counter);
30345+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
30346 start_switch_worker();
30347 }
30348
30349diff -urNp linux-3.0.4/drivers/oprofile/oprofilefs.c linux-3.0.4/drivers/oprofile/oprofilefs.c
30350--- linux-3.0.4/drivers/oprofile/oprofilefs.c 2011-07-21 22:17:23.000000000 -0400
30351+++ linux-3.0.4/drivers/oprofile/oprofilefs.c 2011-08-23 21:47:55.000000000 -0400
30352@@ -186,7 +186,7 @@ static const struct file_operations atom
30353
30354
30355 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
30356- char const *name, atomic_t *val)
30357+ char const *name, atomic_unchecked_t *val)
30358 {
30359 return __oprofilefs_create_file(sb, root, name,
30360 &atomic_ro_fops, 0444, val);
30361diff -urNp linux-3.0.4/drivers/oprofile/oprofile_stats.c linux-3.0.4/drivers/oprofile/oprofile_stats.c
30362--- linux-3.0.4/drivers/oprofile/oprofile_stats.c 2011-07-21 22:17:23.000000000 -0400
30363+++ linux-3.0.4/drivers/oprofile/oprofile_stats.c 2011-08-23 21:47:55.000000000 -0400
30364@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
30365 cpu_buf->sample_invalid_eip = 0;
30366 }
30367
30368- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
30369- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
30370- atomic_set(&oprofile_stats.event_lost_overflow, 0);
30371- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
30372- atomic_set(&oprofile_stats.multiplex_counter, 0);
30373+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
30374+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
30375+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
30376+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
30377+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
30378 }
30379
30380
30381diff -urNp linux-3.0.4/drivers/oprofile/oprofile_stats.h linux-3.0.4/drivers/oprofile/oprofile_stats.h
30382--- linux-3.0.4/drivers/oprofile/oprofile_stats.h 2011-07-21 22:17:23.000000000 -0400
30383+++ linux-3.0.4/drivers/oprofile/oprofile_stats.h 2011-08-23 21:47:55.000000000 -0400
30384@@ -13,11 +13,11 @@
30385 #include <asm/atomic.h>
30386
30387 struct oprofile_stat_struct {
30388- atomic_t sample_lost_no_mm;
30389- atomic_t sample_lost_no_mapping;
30390- atomic_t bt_lost_no_mapping;
30391- atomic_t event_lost_overflow;
30392- atomic_t multiplex_counter;
30393+ atomic_unchecked_t sample_lost_no_mm;
30394+ atomic_unchecked_t sample_lost_no_mapping;
30395+ atomic_unchecked_t bt_lost_no_mapping;
30396+ atomic_unchecked_t event_lost_overflow;
30397+ atomic_unchecked_t multiplex_counter;
30398 };
30399
30400 extern struct oprofile_stat_struct oprofile_stats;
30401diff -urNp linux-3.0.4/drivers/parport/procfs.c linux-3.0.4/drivers/parport/procfs.c
30402--- linux-3.0.4/drivers/parport/procfs.c 2011-07-21 22:17:23.000000000 -0400
30403+++ linux-3.0.4/drivers/parport/procfs.c 2011-08-23 21:47:55.000000000 -0400
30404@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
30405
30406 *ppos += len;
30407
30408- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
30409+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
30410 }
30411
30412 #ifdef CONFIG_PARPORT_1284
30413@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
30414
30415 *ppos += len;
30416
30417- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
30418+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
30419 }
30420 #endif /* IEEE1284.3 support. */
30421
30422diff -urNp linux-3.0.4/drivers/pci/hotplug/cpci_hotplug.h linux-3.0.4/drivers/pci/hotplug/cpci_hotplug.h
30423--- linux-3.0.4/drivers/pci/hotplug/cpci_hotplug.h 2011-07-21 22:17:23.000000000 -0400
30424+++ linux-3.0.4/drivers/pci/hotplug/cpci_hotplug.h 2011-08-23 21:47:55.000000000 -0400
30425@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
30426 int (*hardware_test) (struct slot* slot, u32 value);
30427 u8 (*get_power) (struct slot* slot);
30428 int (*set_power) (struct slot* slot, int value);
30429-};
30430+} __no_const;
30431
30432 struct cpci_hp_controller {
30433 unsigned int irq;
30434diff -urNp linux-3.0.4/drivers/pci/hotplug/cpqphp_nvram.c linux-3.0.4/drivers/pci/hotplug/cpqphp_nvram.c
30435--- linux-3.0.4/drivers/pci/hotplug/cpqphp_nvram.c 2011-07-21 22:17:23.000000000 -0400
30436+++ linux-3.0.4/drivers/pci/hotplug/cpqphp_nvram.c 2011-08-23 21:47:55.000000000 -0400
30437@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
30438
30439 void compaq_nvram_init (void __iomem *rom_start)
30440 {
30441+
30442+#ifndef CONFIG_PAX_KERNEXEC
30443 if (rom_start) {
30444 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
30445 }
30446+#endif
30447+
30448 dbg("int15 entry = %p\n", compaq_int15_entry_point);
30449
30450 /* initialize our int15 lock */
30451diff -urNp linux-3.0.4/drivers/pci/pcie/aspm.c linux-3.0.4/drivers/pci/pcie/aspm.c
30452--- linux-3.0.4/drivers/pci/pcie/aspm.c 2011-07-21 22:17:23.000000000 -0400
30453+++ linux-3.0.4/drivers/pci/pcie/aspm.c 2011-08-23 21:47:55.000000000 -0400
30454@@ -27,9 +27,9 @@
30455 #define MODULE_PARAM_PREFIX "pcie_aspm."
30456
30457 /* Note: those are not register definitions */
30458-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
30459-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
30460-#define ASPM_STATE_L1 (4) /* L1 state */
30461+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
30462+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
30463+#define ASPM_STATE_L1 (4U) /* L1 state */
30464 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
30465 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
30466
30467diff -urNp linux-3.0.4/drivers/pci/probe.c linux-3.0.4/drivers/pci/probe.c
30468--- linux-3.0.4/drivers/pci/probe.c 2011-07-21 22:17:23.000000000 -0400
30469+++ linux-3.0.4/drivers/pci/probe.c 2011-08-23 21:47:55.000000000 -0400
30470@@ -129,7 +129,7 @@ int __pci_read_base(struct pci_dev *dev,
30471 u32 l, sz, mask;
30472 u16 orig_cmd;
30473
30474- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
30475+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
30476
30477 if (!dev->mmio_always_on) {
30478 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
30479diff -urNp linux-3.0.4/drivers/pci/proc.c linux-3.0.4/drivers/pci/proc.c
30480--- linux-3.0.4/drivers/pci/proc.c 2011-07-21 22:17:23.000000000 -0400
30481+++ linux-3.0.4/drivers/pci/proc.c 2011-08-23 21:48:14.000000000 -0400
30482@@ -476,7 +476,16 @@ static const struct file_operations proc
30483 static int __init pci_proc_init(void)
30484 {
30485 struct pci_dev *dev = NULL;
30486+
30487+#ifdef CONFIG_GRKERNSEC_PROC_ADD
30488+#ifdef CONFIG_GRKERNSEC_PROC_USER
30489+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
30490+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
30491+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
30492+#endif
30493+#else
30494 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
30495+#endif
30496 proc_create("devices", 0, proc_bus_pci_dir,
30497 &proc_bus_pci_dev_operations);
30498 proc_initialized = 1;
30499diff -urNp linux-3.0.4/drivers/pci/xen-pcifront.c linux-3.0.4/drivers/pci/xen-pcifront.c
30500--- linux-3.0.4/drivers/pci/xen-pcifront.c 2011-07-21 22:17:23.000000000 -0400
30501+++ linux-3.0.4/drivers/pci/xen-pcifront.c 2011-08-23 21:48:14.000000000 -0400
30502@@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_
30503 struct pcifront_sd *sd = bus->sysdata;
30504 struct pcifront_device *pdev = pcifront_get_pdev(sd);
30505
30506+ pax_track_stack();
30507+
30508 if (verbose_request)
30509 dev_info(&pdev->xdev->dev,
30510 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
30511@@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci
30512 struct pcifront_sd *sd = bus->sysdata;
30513 struct pcifront_device *pdev = pcifront_get_pdev(sd);
30514
30515+ pax_track_stack();
30516+
30517 if (verbose_request)
30518 dev_info(&pdev->xdev->dev,
30519 "write dev=%04x:%02x:%02x.%01x - "
30520@@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(stru
30521 struct pcifront_device *pdev = pcifront_get_pdev(sd);
30522 struct msi_desc *entry;
30523
30524+ pax_track_stack();
30525+
30526 if (nvec > SH_INFO_MAX_VEC) {
30527 dev_err(&dev->dev, "too much vector for pci frontend: %x."
30528 " Increase SH_INFO_MAX_VEC.\n", nvec);
30529@@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(st
30530 struct pcifront_sd *sd = dev->bus->sysdata;
30531 struct pcifront_device *pdev = pcifront_get_pdev(sd);
30532
30533+ pax_track_stack();
30534+
30535 err = do_pci_op(pdev, &op);
30536
30537 /* What should do for error ? */
30538@@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struc
30539 struct pcifront_sd *sd = dev->bus->sysdata;
30540 struct pcifront_device *pdev = pcifront_get_pdev(sd);
30541
30542+ pax_track_stack();
30543+
30544 err = do_pci_op(pdev, &op);
30545 if (likely(!err)) {
30546 vector[0] = op.value;
30547diff -urNp linux-3.0.4/drivers/platform/x86/thinkpad_acpi.c linux-3.0.4/drivers/platform/x86/thinkpad_acpi.c
30548--- linux-3.0.4/drivers/platform/x86/thinkpad_acpi.c 2011-07-21 22:17:23.000000000 -0400
30549+++ linux-3.0.4/drivers/platform/x86/thinkpad_acpi.c 2011-08-23 21:47:55.000000000 -0400
30550@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
30551 return 0;
30552 }
30553
30554-void static hotkey_mask_warn_incomplete_mask(void)
30555+static void hotkey_mask_warn_incomplete_mask(void)
30556 {
30557 /* log only what the user can fix... */
30558 const u32 wantedmask = hotkey_driver_mask &
30559diff -urNp linux-3.0.4/drivers/pnp/pnpbios/bioscalls.c linux-3.0.4/drivers/pnp/pnpbios/bioscalls.c
30560--- linux-3.0.4/drivers/pnp/pnpbios/bioscalls.c 2011-07-21 22:17:23.000000000 -0400
30561+++ linux-3.0.4/drivers/pnp/pnpbios/bioscalls.c 2011-08-23 21:47:55.000000000 -0400
30562@@ -59,7 +59,7 @@ do { \
30563 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
30564 } while(0)
30565
30566-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
30567+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
30568 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
30569
30570 /*
30571@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
30572
30573 cpu = get_cpu();
30574 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
30575+
30576+ pax_open_kernel();
30577 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
30578+ pax_close_kernel();
30579
30580 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
30581 spin_lock_irqsave(&pnp_bios_lock, flags);
30582@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
30583 :"memory");
30584 spin_unlock_irqrestore(&pnp_bios_lock, flags);
30585
30586+ pax_open_kernel();
30587 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
30588+ pax_close_kernel();
30589+
30590 put_cpu();
30591
30592 /* If we get here and this is set then the PnP BIOS faulted on us. */
30593@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
30594 return status;
30595 }
30596
30597-void pnpbios_calls_init(union pnp_bios_install_struct *header)
30598+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
30599 {
30600 int i;
30601
30602@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
30603 pnp_bios_callpoint.offset = header->fields.pm16offset;
30604 pnp_bios_callpoint.segment = PNP_CS16;
30605
30606+ pax_open_kernel();
30607+
30608 for_each_possible_cpu(i) {
30609 struct desc_struct *gdt = get_cpu_gdt_table(i);
30610 if (!gdt)
30611@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
30612 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
30613 (unsigned long)__va(header->fields.pm16dseg));
30614 }
30615+
30616+ pax_close_kernel();
30617 }
30618diff -urNp linux-3.0.4/drivers/pnp/resource.c linux-3.0.4/drivers/pnp/resource.c
30619--- linux-3.0.4/drivers/pnp/resource.c 2011-07-21 22:17:23.000000000 -0400
30620+++ linux-3.0.4/drivers/pnp/resource.c 2011-08-23 21:47:55.000000000 -0400
30621@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
30622 return 1;
30623
30624 /* check if the resource is valid */
30625- if (*irq < 0 || *irq > 15)
30626+ if (*irq > 15)
30627 return 0;
30628
30629 /* check if the resource is reserved */
30630@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
30631 return 1;
30632
30633 /* check if the resource is valid */
30634- if (*dma < 0 || *dma == 4 || *dma > 7)
30635+ if (*dma == 4 || *dma > 7)
30636 return 0;
30637
30638 /* check if the resource is reserved */
30639diff -urNp linux-3.0.4/drivers/power/bq27x00_battery.c linux-3.0.4/drivers/power/bq27x00_battery.c
30640--- linux-3.0.4/drivers/power/bq27x00_battery.c 2011-07-21 22:17:23.000000000 -0400
30641+++ linux-3.0.4/drivers/power/bq27x00_battery.c 2011-08-23 21:47:55.000000000 -0400
30642@@ -67,7 +67,7 @@
30643 struct bq27x00_device_info;
30644 struct bq27x00_access_methods {
30645 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
30646-};
30647+} __no_const;
30648
30649 enum bq27x00_chip { BQ27000, BQ27500 };
30650
30651diff -urNp linux-3.0.4/drivers/regulator/max8660.c linux-3.0.4/drivers/regulator/max8660.c
30652--- linux-3.0.4/drivers/regulator/max8660.c 2011-07-21 22:17:23.000000000 -0400
30653+++ linux-3.0.4/drivers/regulator/max8660.c 2011-08-23 21:47:55.000000000 -0400
30654@@ -383,8 +383,10 @@ static int __devinit max8660_probe(struc
30655 max8660->shadow_regs[MAX8660_OVER1] = 5;
30656 } else {
30657 /* Otherwise devices can be toggled via software */
30658- max8660_dcdc_ops.enable = max8660_dcdc_enable;
30659- max8660_dcdc_ops.disable = max8660_dcdc_disable;
30660+ pax_open_kernel();
30661+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
30662+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
30663+ pax_close_kernel();
30664 }
30665
30666 /*
30667diff -urNp linux-3.0.4/drivers/regulator/mc13892-regulator.c linux-3.0.4/drivers/regulator/mc13892-regulator.c
30668--- linux-3.0.4/drivers/regulator/mc13892-regulator.c 2011-07-21 22:17:23.000000000 -0400
30669+++ linux-3.0.4/drivers/regulator/mc13892-regulator.c 2011-08-23 21:47:55.000000000 -0400
30670@@ -564,10 +564,12 @@ static int __devinit mc13892_regulator_p
30671 }
30672 mc13xxx_unlock(mc13892);
30673
30674- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
30675+ pax_open_kernel();
30676+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
30677 = mc13892_vcam_set_mode;
30678- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
30679+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
30680 = mc13892_vcam_get_mode;
30681+ pax_close_kernel();
30682 for (i = 0; i < pdata->num_regulators; i++) {
30683 init_data = &pdata->regulators[i];
30684 priv->regulators[i] = regulator_register(
30685diff -urNp linux-3.0.4/drivers/rtc/rtc-dev.c linux-3.0.4/drivers/rtc/rtc-dev.c
30686--- linux-3.0.4/drivers/rtc/rtc-dev.c 2011-07-21 22:17:23.000000000 -0400
30687+++ linux-3.0.4/drivers/rtc/rtc-dev.c 2011-08-23 21:48:14.000000000 -0400
30688@@ -14,6 +14,7 @@
30689 #include <linux/module.h>
30690 #include <linux/rtc.h>
30691 #include <linux/sched.h>
30692+#include <linux/grsecurity.h>
30693 #include "rtc-core.h"
30694
30695 static dev_t rtc_devt;
30696@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *f
30697 if (copy_from_user(&tm, uarg, sizeof(tm)))
30698 return -EFAULT;
30699
30700+ gr_log_timechange();
30701+
30702 return rtc_set_time(rtc, &tm);
30703
30704 case RTC_PIE_ON:
30705diff -urNp linux-3.0.4/drivers/scsi/aacraid/aacraid.h linux-3.0.4/drivers/scsi/aacraid/aacraid.h
30706--- linux-3.0.4/drivers/scsi/aacraid/aacraid.h 2011-07-21 22:17:23.000000000 -0400
30707+++ linux-3.0.4/drivers/scsi/aacraid/aacraid.h 2011-08-23 21:47:55.000000000 -0400
30708@@ -492,7 +492,7 @@ struct adapter_ops
30709 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
30710 /* Administrative operations */
30711 int (*adapter_comm)(struct aac_dev * dev, int comm);
30712-};
30713+} __no_const;
30714
30715 /*
30716 * Define which interrupt handler needs to be installed
30717diff -urNp linux-3.0.4/drivers/scsi/aacraid/commctrl.c linux-3.0.4/drivers/scsi/aacraid/commctrl.c
30718--- linux-3.0.4/drivers/scsi/aacraid/commctrl.c 2011-07-21 22:17:23.000000000 -0400
30719+++ linux-3.0.4/drivers/scsi/aacraid/commctrl.c 2011-08-23 21:48:14.000000000 -0400
30720@@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_d
30721 u32 actual_fibsize64, actual_fibsize = 0;
30722 int i;
30723
30724+ pax_track_stack();
30725
30726 if (dev->in_reset) {
30727 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
30728diff -urNp linux-3.0.4/drivers/scsi/bfa/bfad.c linux-3.0.4/drivers/scsi/bfa/bfad.c
30729--- linux-3.0.4/drivers/scsi/bfa/bfad.c 2011-07-21 22:17:23.000000000 -0400
30730+++ linux-3.0.4/drivers/scsi/bfa/bfad.c 2011-08-23 21:48:14.000000000 -0400
30731@@ -1032,6 +1032,8 @@ bfad_start_ops(struct bfad_s *bfad) {
30732 struct bfad_vport_s *vport, *vport_new;
30733 struct bfa_fcs_driver_info_s driver_info;
30734
30735+ pax_track_stack();
30736+
30737 /* Fill the driver_info info to fcs*/
30738 memset(&driver_info, 0, sizeof(driver_info));
30739 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
30740diff -urNp linux-3.0.4/drivers/scsi/bfa/bfa_fcs_lport.c linux-3.0.4/drivers/scsi/bfa/bfa_fcs_lport.c
30741--- linux-3.0.4/drivers/scsi/bfa/bfa_fcs_lport.c 2011-07-21 22:17:23.000000000 -0400
30742+++ linux-3.0.4/drivers/scsi/bfa/bfa_fcs_lport.c 2011-08-23 21:48:14.000000000 -0400
30743@@ -1559,6 +1559,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struc
30744 u16 len, count;
30745 u16 templen;
30746
30747+ pax_track_stack();
30748+
30749 /*
30750 * get hba attributes
30751 */
30752@@ -1836,6 +1838,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(
30753 u8 count = 0;
30754 u16 templen;
30755
30756+ pax_track_stack();
30757+
30758 /*
30759 * get port attributes
30760 */
30761diff -urNp linux-3.0.4/drivers/scsi/bfa/bfa_fcs_rport.c linux-3.0.4/drivers/scsi/bfa/bfa_fcs_rport.c
30762--- linux-3.0.4/drivers/scsi/bfa/bfa_fcs_rport.c 2011-07-21 22:17:23.000000000 -0400
30763+++ linux-3.0.4/drivers/scsi/bfa/bfa_fcs_rport.c 2011-08-23 21:48:14.000000000 -0400
30764@@ -1844,6 +1844,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fc
30765 struct fc_rpsc_speed_info_s speeds;
30766 struct bfa_port_attr_s pport_attr;
30767
30768+ pax_track_stack();
30769+
30770 bfa_trc(port->fcs, rx_fchs->s_id);
30771 bfa_trc(port->fcs, rx_fchs->d_id);
30772
30773diff -urNp linux-3.0.4/drivers/scsi/bfa/bfa.h linux-3.0.4/drivers/scsi/bfa/bfa.h
30774--- linux-3.0.4/drivers/scsi/bfa/bfa.h 2011-07-21 22:17:23.000000000 -0400
30775+++ linux-3.0.4/drivers/scsi/bfa/bfa.h 2011-08-23 21:47:55.000000000 -0400
30776@@ -238,7 +238,7 @@ struct bfa_hwif_s {
30777 u32 *nvecs, u32 *maxvec);
30778 void (*hw_msix_get_rme_range) (struct bfa_s *bfa, u32 *start,
30779 u32 *end);
30780-};
30781+} __no_const;
30782 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
30783
30784 struct bfa_iocfc_s {
30785diff -urNp linux-3.0.4/drivers/scsi/bfa/bfa_ioc.h linux-3.0.4/drivers/scsi/bfa/bfa_ioc.h
30786--- linux-3.0.4/drivers/scsi/bfa/bfa_ioc.h 2011-07-21 22:17:23.000000000 -0400
30787+++ linux-3.0.4/drivers/scsi/bfa/bfa_ioc.h 2011-08-23 21:47:55.000000000 -0400
30788@@ -196,7 +196,7 @@ struct bfa_ioc_cbfn_s {
30789 bfa_ioc_disable_cbfn_t disable_cbfn;
30790 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
30791 bfa_ioc_reset_cbfn_t reset_cbfn;
30792-};
30793+} __no_const;
30794
30795 /*
30796 * Heartbeat failure notification queue element.
30797@@ -268,7 +268,7 @@ struct bfa_ioc_hwif_s {
30798 void (*ioc_sync_leave) (struct bfa_ioc_s *ioc);
30799 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
30800 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
30801-};
30802+} __no_const;
30803
30804 #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
30805 #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
30806diff -urNp linux-3.0.4/drivers/scsi/BusLogic.c linux-3.0.4/drivers/scsi/BusLogic.c
30807--- linux-3.0.4/drivers/scsi/BusLogic.c 2011-07-21 22:17:23.000000000 -0400
30808+++ linux-3.0.4/drivers/scsi/BusLogic.c 2011-08-23 21:48:14.000000000 -0400
30809@@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFla
30810 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
30811 *PrototypeHostAdapter)
30812 {
30813+ pax_track_stack();
30814+
30815 /*
30816 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
30817 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
30818diff -urNp linux-3.0.4/drivers/scsi/dpt_i2o.c linux-3.0.4/drivers/scsi/dpt_i2o.c
30819--- linux-3.0.4/drivers/scsi/dpt_i2o.c 2011-07-21 22:17:23.000000000 -0400
30820+++ linux-3.0.4/drivers/scsi/dpt_i2o.c 2011-08-23 21:48:14.000000000 -0400
30821@@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* p
30822 dma_addr_t addr;
30823 ulong flags = 0;
30824
30825+ pax_track_stack();
30826+
30827 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
30828 // get user msg size in u32s
30829 if(get_user(size, &user_msg[0])){
30830@@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
30831 s32 rcode;
30832 dma_addr_t addr;
30833
30834+ pax_track_stack();
30835+
30836 memset(msg, 0 , sizeof(msg));
30837 len = scsi_bufflen(cmd);
30838 direction = 0x00000000;
30839diff -urNp linux-3.0.4/drivers/scsi/eata.c linux-3.0.4/drivers/scsi/eata.c
30840--- linux-3.0.4/drivers/scsi/eata.c 2011-07-21 22:17:23.000000000 -0400
30841+++ linux-3.0.4/drivers/scsi/eata.c 2011-08-23 21:48:14.000000000 -0400
30842@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
30843 struct hostdata *ha;
30844 char name[16];
30845
30846+ pax_track_stack();
30847+
30848 sprintf(name, "%s%d", driver_name, j);
30849
30850 if (!request_region(port_base, REGION_SIZE, driver_name)) {
30851diff -urNp linux-3.0.4/drivers/scsi/fcoe/fcoe_ctlr.c linux-3.0.4/drivers/scsi/fcoe/fcoe_ctlr.c
30852--- linux-3.0.4/drivers/scsi/fcoe/fcoe_ctlr.c 2011-07-21 22:17:23.000000000 -0400
30853+++ linux-3.0.4/drivers/scsi/fcoe/fcoe_ctlr.c 2011-08-23 21:48:14.000000000 -0400
30854@@ -2503,6 +2503,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe
30855 } buf;
30856 int rc;
30857
30858+ pax_track_stack();
30859+
30860 fiph = (struct fip_header *)skb->data;
30861 sub = fiph->fip_subcode;
30862
30863diff -urNp linux-3.0.4/drivers/scsi/gdth.c linux-3.0.4/drivers/scsi/gdth.c
30864--- linux-3.0.4/drivers/scsi/gdth.c 2011-07-21 22:17:23.000000000 -0400
30865+++ linux-3.0.4/drivers/scsi/gdth.c 2011-08-23 21:48:14.000000000 -0400
30866@@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
30867 unsigned long flags;
30868 gdth_ha_str *ha;
30869
30870+ pax_track_stack();
30871+
30872 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
30873 return -EFAULT;
30874 ha = gdth_find_ha(ldrv.ionode);
30875@@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg
30876 gdth_ha_str *ha;
30877 int rval;
30878
30879+ pax_track_stack();
30880+
30881 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
30882 res.number >= MAX_HDRIVES)
30883 return -EFAULT;
30884@@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg,
30885 gdth_ha_str *ha;
30886 int rval;
30887
30888+ pax_track_stack();
30889+
30890 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
30891 return -EFAULT;
30892 ha = gdth_find_ha(gen.ionode);
30893@@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
30894 int i;
30895 gdth_cmd_str gdtcmd;
30896 char cmnd[MAX_COMMAND_SIZE];
30897+
30898+ pax_track_stack();
30899+
30900 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
30901
30902 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
30903diff -urNp linux-3.0.4/drivers/scsi/gdth_proc.c linux-3.0.4/drivers/scsi/gdth_proc.c
30904--- linux-3.0.4/drivers/scsi/gdth_proc.c 2011-07-21 22:17:23.000000000 -0400
30905+++ linux-3.0.4/drivers/scsi/gdth_proc.c 2011-08-23 21:48:14.000000000 -0400
30906@@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi
30907 u64 paddr;
30908
30909 char cmnd[MAX_COMMAND_SIZE];
30910+
30911+ pax_track_stack();
30912+
30913 memset(cmnd, 0xff, 12);
30914 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
30915
30916@@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,ch
30917 gdth_hget_str *phg;
30918 char cmnd[MAX_COMMAND_SIZE];
30919
30920+ pax_track_stack();
30921+
30922 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
30923 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
30924 if (!gdtcmd || !estr)
30925diff -urNp linux-3.0.4/drivers/scsi/hosts.c linux-3.0.4/drivers/scsi/hosts.c
30926--- linux-3.0.4/drivers/scsi/hosts.c 2011-07-21 22:17:23.000000000 -0400
30927+++ linux-3.0.4/drivers/scsi/hosts.c 2011-08-23 21:47:55.000000000 -0400
30928@@ -42,7 +42,7 @@
30929 #include "scsi_logging.h"
30930
30931
30932-static atomic_t scsi_host_next_hn; /* host_no for next new host */
30933+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
30934
30935
30936 static void scsi_host_cls_release(struct device *dev)
30937@@ -354,7 +354,7 @@ struct Scsi_Host *scsi_host_alloc(struct
30938 * subtract one because we increment first then return, but we need to
30939 * know what the next host number was before increment
30940 */
30941- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
30942+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
30943 shost->dma_channel = 0xff;
30944
30945 /* These three are default values which can be overridden */
30946diff -urNp linux-3.0.4/drivers/scsi/hpsa.c linux-3.0.4/drivers/scsi/hpsa.c
30947--- linux-3.0.4/drivers/scsi/hpsa.c 2011-07-21 22:17:23.000000000 -0400
30948+++ linux-3.0.4/drivers/scsi/hpsa.c 2011-08-23 21:47:55.000000000 -0400
30949@@ -498,7 +498,7 @@ static inline u32 next_command(struct ct
30950 u32 a;
30951
30952 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
30953- return h->access.command_completed(h);
30954+ return h->access->command_completed(h);
30955
30956 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
30957 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
30958@@ -2938,7 +2938,7 @@ static void start_io(struct ctlr_info *h
30959 while (!list_empty(&h->reqQ)) {
30960 c = list_entry(h->reqQ.next, struct CommandList, list);
30961 /* can't do anything if fifo is full */
30962- if ((h->access.fifo_full(h))) {
30963+ if ((h->access->fifo_full(h))) {
30964 dev_warn(&h->pdev->dev, "fifo full\n");
30965 break;
30966 }
30967@@ -2948,7 +2948,7 @@ static void start_io(struct ctlr_info *h
30968 h->Qdepth--;
30969
30970 /* Tell the controller execute command */
30971- h->access.submit_command(h, c);
30972+ h->access->submit_command(h, c);
30973
30974 /* Put job onto the completed Q */
30975 addQ(&h->cmpQ, c);
30976@@ -2957,17 +2957,17 @@ static void start_io(struct ctlr_info *h
30977
30978 static inline unsigned long get_next_completion(struct ctlr_info *h)
30979 {
30980- return h->access.command_completed(h);
30981+ return h->access->command_completed(h);
30982 }
30983
30984 static inline bool interrupt_pending(struct ctlr_info *h)
30985 {
30986- return h->access.intr_pending(h);
30987+ return h->access->intr_pending(h);
30988 }
30989
30990 static inline long interrupt_not_for_us(struct ctlr_info *h)
30991 {
30992- return (h->access.intr_pending(h) == 0) ||
30993+ return (h->access->intr_pending(h) == 0) ||
30994 (h->interrupts_enabled == 0);
30995 }
30996
30997@@ -3857,7 +3857,7 @@ static int __devinit hpsa_pci_init(struc
30998 if (prod_index < 0)
30999 return -ENODEV;
31000 h->product_name = products[prod_index].product_name;
31001- h->access = *(products[prod_index].access);
31002+ h->access = products[prod_index].access;
31003
31004 if (hpsa_board_disabled(h->pdev)) {
31005 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31006@@ -4134,7 +4134,7 @@ reinit_after_soft_reset:
31007 }
31008
31009 /* make sure the board interrupts are off */
31010- h->access.set_intr_mask(h, HPSA_INTR_OFF);
31011+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
31012
31013 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
31014 goto clean2;
31015@@ -4168,7 +4168,7 @@ reinit_after_soft_reset:
31016 * fake ones to scoop up any residual completions.
31017 */
31018 spin_lock_irqsave(&h->lock, flags);
31019- h->access.set_intr_mask(h, HPSA_INTR_OFF);
31020+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
31021 spin_unlock_irqrestore(&h->lock, flags);
31022 free_irq(h->intr[h->intr_mode], h);
31023 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
31024@@ -4187,9 +4187,9 @@ reinit_after_soft_reset:
31025 dev_info(&h->pdev->dev, "Board READY.\n");
31026 dev_info(&h->pdev->dev,
31027 "Waiting for stale completions to drain.\n");
31028- h->access.set_intr_mask(h, HPSA_INTR_ON);
31029+ h->access->set_intr_mask(h, HPSA_INTR_ON);
31030 msleep(10000);
31031- h->access.set_intr_mask(h, HPSA_INTR_OFF);
31032+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
31033
31034 rc = controller_reset_failed(h->cfgtable);
31035 if (rc)
31036@@ -4210,7 +4210,7 @@ reinit_after_soft_reset:
31037 }
31038
31039 /* Turn the interrupts on so we can service requests */
31040- h->access.set_intr_mask(h, HPSA_INTR_ON);
31041+ h->access->set_intr_mask(h, HPSA_INTR_ON);
31042
31043 hpsa_hba_inquiry(h);
31044 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
31045@@ -4263,7 +4263,7 @@ static void hpsa_shutdown(struct pci_dev
31046 * To write all data in the battery backed cache to disks
31047 */
31048 hpsa_flush_cache(h);
31049- h->access.set_intr_mask(h, HPSA_INTR_OFF);
31050+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
31051 free_irq(h->intr[h->intr_mode], h);
31052 #ifdef CONFIG_PCI_MSI
31053 if (h->msix_vector)
31054@@ -4426,7 +4426,7 @@ static __devinit void hpsa_enter_perform
31055 return;
31056 }
31057 /* Change the access methods to the performant access methods */
31058- h->access = SA5_performant_access;
31059+ h->access = &SA5_performant_access;
31060 h->transMethod = CFGTBL_Trans_Performant;
31061 }
31062
31063diff -urNp linux-3.0.4/drivers/scsi/hpsa.h linux-3.0.4/drivers/scsi/hpsa.h
31064--- linux-3.0.4/drivers/scsi/hpsa.h 2011-08-23 21:44:40.000000000 -0400
31065+++ linux-3.0.4/drivers/scsi/hpsa.h 2011-08-23 21:47:55.000000000 -0400
31066@@ -73,7 +73,7 @@ struct ctlr_info {
31067 unsigned int msix_vector;
31068 unsigned int msi_vector;
31069 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
31070- struct access_method access;
31071+ struct access_method *access;
31072
31073 /* queue and queue Info */
31074 struct list_head reqQ;
31075diff -urNp linux-3.0.4/drivers/scsi/ips.h linux-3.0.4/drivers/scsi/ips.h
31076--- linux-3.0.4/drivers/scsi/ips.h 2011-07-21 22:17:23.000000000 -0400
31077+++ linux-3.0.4/drivers/scsi/ips.h 2011-08-23 21:47:55.000000000 -0400
31078@@ -1027,7 +1027,7 @@ typedef struct {
31079 int (*intr)(struct ips_ha *);
31080 void (*enableint)(struct ips_ha *);
31081 uint32_t (*statupd)(struct ips_ha *);
31082-} ips_hw_func_t;
31083+} __no_const ips_hw_func_t;
31084
31085 typedef struct ips_ha {
31086 uint8_t ha_id[IPS_MAX_CHANNELS+1];
31087diff -urNp linux-3.0.4/drivers/scsi/libfc/fc_exch.c linux-3.0.4/drivers/scsi/libfc/fc_exch.c
31088--- linux-3.0.4/drivers/scsi/libfc/fc_exch.c 2011-07-21 22:17:23.000000000 -0400
31089+++ linux-3.0.4/drivers/scsi/libfc/fc_exch.c 2011-08-23 21:47:55.000000000 -0400
31090@@ -105,12 +105,12 @@ struct fc_exch_mgr {
31091 * all together if not used XXX
31092 */
31093 struct {
31094- atomic_t no_free_exch;
31095- atomic_t no_free_exch_xid;
31096- atomic_t xid_not_found;
31097- atomic_t xid_busy;
31098- atomic_t seq_not_found;
31099- atomic_t non_bls_resp;
31100+ atomic_unchecked_t no_free_exch;
31101+ atomic_unchecked_t no_free_exch_xid;
31102+ atomic_unchecked_t xid_not_found;
31103+ atomic_unchecked_t xid_busy;
31104+ atomic_unchecked_t seq_not_found;
31105+ atomic_unchecked_t non_bls_resp;
31106 } stats;
31107 };
31108
31109@@ -700,7 +700,7 @@ static struct fc_exch *fc_exch_em_alloc(
31110 /* allocate memory for exchange */
31111 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
31112 if (!ep) {
31113- atomic_inc(&mp->stats.no_free_exch);
31114+ atomic_inc_unchecked(&mp->stats.no_free_exch);
31115 goto out;
31116 }
31117 memset(ep, 0, sizeof(*ep));
31118@@ -761,7 +761,7 @@ out:
31119 return ep;
31120 err:
31121 spin_unlock_bh(&pool->lock);
31122- atomic_inc(&mp->stats.no_free_exch_xid);
31123+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
31124 mempool_free(ep, mp->ep_pool);
31125 return NULL;
31126 }
31127@@ -906,7 +906,7 @@ static enum fc_pf_rjt_reason fc_seq_look
31128 xid = ntohs(fh->fh_ox_id); /* we originated exch */
31129 ep = fc_exch_find(mp, xid);
31130 if (!ep) {
31131- atomic_inc(&mp->stats.xid_not_found);
31132+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31133 reject = FC_RJT_OX_ID;
31134 goto out;
31135 }
31136@@ -936,7 +936,7 @@ static enum fc_pf_rjt_reason fc_seq_look
31137 ep = fc_exch_find(mp, xid);
31138 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
31139 if (ep) {
31140- atomic_inc(&mp->stats.xid_busy);
31141+ atomic_inc_unchecked(&mp->stats.xid_busy);
31142 reject = FC_RJT_RX_ID;
31143 goto rel;
31144 }
31145@@ -947,7 +947,7 @@ static enum fc_pf_rjt_reason fc_seq_look
31146 }
31147 xid = ep->xid; /* get our XID */
31148 } else if (!ep) {
31149- atomic_inc(&mp->stats.xid_not_found);
31150+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31151 reject = FC_RJT_RX_ID; /* XID not found */
31152 goto out;
31153 }
31154@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_look
31155 } else {
31156 sp = &ep->seq;
31157 if (sp->id != fh->fh_seq_id) {
31158- atomic_inc(&mp->stats.seq_not_found);
31159+ atomic_inc_unchecked(&mp->stats.seq_not_found);
31160 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
31161 goto rel;
31162 }
31163@@ -1392,22 +1392,22 @@ static void fc_exch_recv_seq_resp(struct
31164
31165 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
31166 if (!ep) {
31167- atomic_inc(&mp->stats.xid_not_found);
31168+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31169 goto out;
31170 }
31171 if (ep->esb_stat & ESB_ST_COMPLETE) {
31172- atomic_inc(&mp->stats.xid_not_found);
31173+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31174 goto rel;
31175 }
31176 if (ep->rxid == FC_XID_UNKNOWN)
31177 ep->rxid = ntohs(fh->fh_rx_id);
31178 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
31179- atomic_inc(&mp->stats.xid_not_found);
31180+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31181 goto rel;
31182 }
31183 if (ep->did != ntoh24(fh->fh_s_id) &&
31184 ep->did != FC_FID_FLOGI) {
31185- atomic_inc(&mp->stats.xid_not_found);
31186+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31187 goto rel;
31188 }
31189 sof = fr_sof(fp);
31190@@ -1416,7 +1416,7 @@ static void fc_exch_recv_seq_resp(struct
31191 sp->ssb_stat |= SSB_ST_RESP;
31192 sp->id = fh->fh_seq_id;
31193 } else if (sp->id != fh->fh_seq_id) {
31194- atomic_inc(&mp->stats.seq_not_found);
31195+ atomic_inc_unchecked(&mp->stats.seq_not_found);
31196 goto rel;
31197 }
31198
31199@@ -1480,9 +1480,9 @@ static void fc_exch_recv_resp(struct fc_
31200 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
31201
31202 if (!sp)
31203- atomic_inc(&mp->stats.xid_not_found);
31204+ atomic_inc_unchecked(&mp->stats.xid_not_found);
31205 else
31206- atomic_inc(&mp->stats.non_bls_resp);
31207+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
31208
31209 fc_frame_free(fp);
31210 }
31211diff -urNp linux-3.0.4/drivers/scsi/libsas/sas_ata.c linux-3.0.4/drivers/scsi/libsas/sas_ata.c
31212--- linux-3.0.4/drivers/scsi/libsas/sas_ata.c 2011-07-21 22:17:23.000000000 -0400
31213+++ linux-3.0.4/drivers/scsi/libsas/sas_ata.c 2011-08-23 21:47:55.000000000 -0400
31214@@ -368,7 +368,7 @@ static struct ata_port_operations sas_sa
31215 .postreset = ata_std_postreset,
31216 .error_handler = ata_std_error_handler,
31217 .post_internal_cmd = sas_ata_post_internal,
31218- .qc_defer = ata_std_qc_defer,
31219+ .qc_defer = ata_std_qc_defer,
31220 .qc_prep = ata_noop_qc_prep,
31221 .qc_issue = sas_ata_qc_issue,
31222 .qc_fill_rtf = sas_ata_qc_fill_rtf,
31223diff -urNp linux-3.0.4/drivers/scsi/lpfc/lpfc_debugfs.c linux-3.0.4/drivers/scsi/lpfc/lpfc_debugfs.c
31224--- linux-3.0.4/drivers/scsi/lpfc/lpfc_debugfs.c 2011-07-21 22:17:23.000000000 -0400
31225+++ linux-3.0.4/drivers/scsi/lpfc/lpfc_debugfs.c 2011-08-23 21:48:14.000000000 -0400
31226@@ -104,7 +104,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_
31227
31228 #include <linux/debugfs.h>
31229
31230-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
31231+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
31232 static unsigned long lpfc_debugfs_start_time = 0L;
31233
31234 /* iDiag */
31235@@ -141,7 +141,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
31236 lpfc_debugfs_enable = 0;
31237
31238 len = 0;
31239- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
31240+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
31241 (lpfc_debugfs_max_disc_trc - 1);
31242 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
31243 dtp = vport->disc_trc + i;
31244@@ -202,7 +202,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
31245 lpfc_debugfs_enable = 0;
31246
31247 len = 0;
31248- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
31249+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
31250 (lpfc_debugfs_max_slow_ring_trc - 1);
31251 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
31252 dtp = phba->slow_ring_trc + i;
31253@@ -380,6 +380,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
31254 uint32_t *ptr;
31255 char buffer[1024];
31256
31257+ pax_track_stack();
31258+
31259 off = 0;
31260 spin_lock_irq(&phba->hbalock);
31261
31262@@ -617,14 +619,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
31263 !vport || !vport->disc_trc)
31264 return;
31265
31266- index = atomic_inc_return(&vport->disc_trc_cnt) &
31267+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
31268 (lpfc_debugfs_max_disc_trc - 1);
31269 dtp = vport->disc_trc + index;
31270 dtp->fmt = fmt;
31271 dtp->data1 = data1;
31272 dtp->data2 = data2;
31273 dtp->data3 = data3;
31274- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
31275+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
31276 dtp->jif = jiffies;
31277 #endif
31278 return;
31279@@ -655,14 +657,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
31280 !phba || !phba->slow_ring_trc)
31281 return;
31282
31283- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
31284+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
31285 (lpfc_debugfs_max_slow_ring_trc - 1);
31286 dtp = phba->slow_ring_trc + index;
31287 dtp->fmt = fmt;
31288 dtp->data1 = data1;
31289 dtp->data2 = data2;
31290 dtp->data3 = data3;
31291- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
31292+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
31293 dtp->jif = jiffies;
31294 #endif
31295 return;
31296@@ -2606,7 +2608,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
31297 "slow_ring buffer\n");
31298 goto debug_failed;
31299 }
31300- atomic_set(&phba->slow_ring_trc_cnt, 0);
31301+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
31302 memset(phba->slow_ring_trc, 0,
31303 (sizeof(struct lpfc_debugfs_trc) *
31304 lpfc_debugfs_max_slow_ring_trc));
31305@@ -2652,7 +2654,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
31306 "buffer\n");
31307 goto debug_failed;
31308 }
31309- atomic_set(&vport->disc_trc_cnt, 0);
31310+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
31311
31312 snprintf(name, sizeof(name), "discovery_trace");
31313 vport->debug_disc_trc =
31314diff -urNp linux-3.0.4/drivers/scsi/lpfc/lpfc.h linux-3.0.4/drivers/scsi/lpfc/lpfc.h
31315--- linux-3.0.4/drivers/scsi/lpfc/lpfc.h 2011-07-21 22:17:23.000000000 -0400
31316+++ linux-3.0.4/drivers/scsi/lpfc/lpfc.h 2011-08-23 21:47:55.000000000 -0400
31317@@ -420,7 +420,7 @@ struct lpfc_vport {
31318 struct dentry *debug_nodelist;
31319 struct dentry *vport_debugfs_root;
31320 struct lpfc_debugfs_trc *disc_trc;
31321- atomic_t disc_trc_cnt;
31322+ atomic_unchecked_t disc_trc_cnt;
31323 #endif
31324 uint8_t stat_data_enabled;
31325 uint8_t stat_data_blocked;
31326@@ -826,8 +826,8 @@ struct lpfc_hba {
31327 struct timer_list fabric_block_timer;
31328 unsigned long bit_flags;
31329 #define FABRIC_COMANDS_BLOCKED 0
31330- atomic_t num_rsrc_err;
31331- atomic_t num_cmd_success;
31332+ atomic_unchecked_t num_rsrc_err;
31333+ atomic_unchecked_t num_cmd_success;
31334 unsigned long last_rsrc_error_time;
31335 unsigned long last_ramp_down_time;
31336 unsigned long last_ramp_up_time;
31337@@ -841,7 +841,7 @@ struct lpfc_hba {
31338 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
31339 struct dentry *debug_slow_ring_trc;
31340 struct lpfc_debugfs_trc *slow_ring_trc;
31341- atomic_t slow_ring_trc_cnt;
31342+ atomic_unchecked_t slow_ring_trc_cnt;
31343 /* iDiag debugfs sub-directory */
31344 struct dentry *idiag_root;
31345 struct dentry *idiag_pci_cfg;
31346diff -urNp linux-3.0.4/drivers/scsi/lpfc/lpfc_init.c linux-3.0.4/drivers/scsi/lpfc/lpfc_init.c
31347--- linux-3.0.4/drivers/scsi/lpfc/lpfc_init.c 2011-07-21 22:17:23.000000000 -0400
31348+++ linux-3.0.4/drivers/scsi/lpfc/lpfc_init.c 2011-08-23 21:47:56.000000000 -0400
31349@@ -9923,8 +9923,10 @@ lpfc_init(void)
31350 printk(LPFC_COPYRIGHT "\n");
31351
31352 if (lpfc_enable_npiv) {
31353- lpfc_transport_functions.vport_create = lpfc_vport_create;
31354- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
31355+ pax_open_kernel();
31356+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
31357+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
31358+ pax_close_kernel();
31359 }
31360 lpfc_transport_template =
31361 fc_attach_transport(&lpfc_transport_functions);
31362diff -urNp linux-3.0.4/drivers/scsi/lpfc/lpfc_scsi.c linux-3.0.4/drivers/scsi/lpfc/lpfc_scsi.c
31363--- linux-3.0.4/drivers/scsi/lpfc/lpfc_scsi.c 2011-07-21 22:17:23.000000000 -0400
31364+++ linux-3.0.4/drivers/scsi/lpfc/lpfc_scsi.c 2011-08-23 21:47:56.000000000 -0400
31365@@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
31366 uint32_t evt_posted;
31367
31368 spin_lock_irqsave(&phba->hbalock, flags);
31369- atomic_inc(&phba->num_rsrc_err);
31370+ atomic_inc_unchecked(&phba->num_rsrc_err);
31371 phba->last_rsrc_error_time = jiffies;
31372
31373 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
31374@@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
31375 unsigned long flags;
31376 struct lpfc_hba *phba = vport->phba;
31377 uint32_t evt_posted;
31378- atomic_inc(&phba->num_cmd_success);
31379+ atomic_inc_unchecked(&phba->num_cmd_success);
31380
31381 if (vport->cfg_lun_queue_depth <= queue_depth)
31382 return;
31383@@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
31384 unsigned long num_rsrc_err, num_cmd_success;
31385 int i;
31386
31387- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
31388- num_cmd_success = atomic_read(&phba->num_cmd_success);
31389+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
31390+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
31391
31392 vports = lpfc_create_vport_work_array(phba);
31393 if (vports != NULL)
31394@@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
31395 }
31396 }
31397 lpfc_destroy_vport_work_array(phba, vports);
31398- atomic_set(&phba->num_rsrc_err, 0);
31399- atomic_set(&phba->num_cmd_success, 0);
31400+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
31401+ atomic_set_unchecked(&phba->num_cmd_success, 0);
31402 }
31403
31404 /**
31405@@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
31406 }
31407 }
31408 lpfc_destroy_vport_work_array(phba, vports);
31409- atomic_set(&phba->num_rsrc_err, 0);
31410- atomic_set(&phba->num_cmd_success, 0);
31411+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
31412+ atomic_set_unchecked(&phba->num_cmd_success, 0);
31413 }
31414
31415 /**
31416diff -urNp linux-3.0.4/drivers/scsi/megaraid/megaraid_mbox.c linux-3.0.4/drivers/scsi/megaraid/megaraid_mbox.c
31417--- linux-3.0.4/drivers/scsi/megaraid/megaraid_mbox.c 2011-07-21 22:17:23.000000000 -0400
31418+++ linux-3.0.4/drivers/scsi/megaraid/megaraid_mbox.c 2011-08-23 21:48:14.000000000 -0400
31419@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter
31420 int rval;
31421 int i;
31422
31423+ pax_track_stack();
31424+
31425 // Allocate memory for the base list of scb for management module.
31426 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
31427
31428diff -urNp linux-3.0.4/drivers/scsi/osd/osd_initiator.c linux-3.0.4/drivers/scsi/osd/osd_initiator.c
31429--- linux-3.0.4/drivers/scsi/osd/osd_initiator.c 2011-07-21 22:17:23.000000000 -0400
31430+++ linux-3.0.4/drivers/scsi/osd/osd_initiator.c 2011-08-23 21:48:14.000000000 -0400
31431@@ -97,6 +97,8 @@ static int _osd_get_print_system_info(st
31432 int nelem = ARRAY_SIZE(get_attrs), a = 0;
31433 int ret;
31434
31435+ pax_track_stack();
31436+
31437 or = osd_start_request(od, GFP_KERNEL);
31438 if (!or)
31439 return -ENOMEM;
31440diff -urNp linux-3.0.4/drivers/scsi/pmcraid.c linux-3.0.4/drivers/scsi/pmcraid.c
31441--- linux-3.0.4/drivers/scsi/pmcraid.c 2011-08-23 21:44:40.000000000 -0400
31442+++ linux-3.0.4/drivers/scsi/pmcraid.c 2011-08-23 21:47:56.000000000 -0400
31443@@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct sc
31444 res->scsi_dev = scsi_dev;
31445 scsi_dev->hostdata = res;
31446 res->change_detected = 0;
31447- atomic_set(&res->read_failures, 0);
31448- atomic_set(&res->write_failures, 0);
31449+ atomic_set_unchecked(&res->read_failures, 0);
31450+ atomic_set_unchecked(&res->write_failures, 0);
31451 rc = 0;
31452 }
31453 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
31454@@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct
31455
31456 /* If this was a SCSI read/write command keep count of errors */
31457 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
31458- atomic_inc(&res->read_failures);
31459+ atomic_inc_unchecked(&res->read_failures);
31460 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
31461- atomic_inc(&res->write_failures);
31462+ atomic_inc_unchecked(&res->write_failures);
31463
31464 if (!RES_IS_GSCSI(res->cfg_entry) &&
31465 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
31466@@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
31467 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
31468 * hrrq_id assigned here in queuecommand
31469 */
31470- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
31471+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
31472 pinstance->num_hrrq;
31473 cmd->cmd_done = pmcraid_io_done;
31474
31475@@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
31476 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
31477 * hrrq_id assigned here in queuecommand
31478 */
31479- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
31480+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
31481 pinstance->num_hrrq;
31482
31483 if (request_size) {
31484@@ -4498,7 +4498,7 @@ static void pmcraid_worker_function(stru
31485
31486 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
31487 /* add resources only after host is added into system */
31488- if (!atomic_read(&pinstance->expose_resources))
31489+ if (!atomic_read_unchecked(&pinstance->expose_resources))
31490 return;
31491
31492 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
31493@@ -5332,8 +5332,8 @@ static int __devinit pmcraid_init_instan
31494 init_waitqueue_head(&pinstance->reset_wait_q);
31495
31496 atomic_set(&pinstance->outstanding_cmds, 0);
31497- atomic_set(&pinstance->last_message_id, 0);
31498- atomic_set(&pinstance->expose_resources, 0);
31499+ atomic_set_unchecked(&pinstance->last_message_id, 0);
31500+ atomic_set_unchecked(&pinstance->expose_resources, 0);
31501
31502 INIT_LIST_HEAD(&pinstance->free_res_q);
31503 INIT_LIST_HEAD(&pinstance->used_res_q);
31504@@ -6048,7 +6048,7 @@ static int __devinit pmcraid_probe(
31505 /* Schedule worker thread to handle CCN and take care of adding and
31506 * removing devices to OS
31507 */
31508- atomic_set(&pinstance->expose_resources, 1);
31509+ atomic_set_unchecked(&pinstance->expose_resources, 1);
31510 schedule_work(&pinstance->worker_q);
31511 return rc;
31512
31513diff -urNp linux-3.0.4/drivers/scsi/pmcraid.h linux-3.0.4/drivers/scsi/pmcraid.h
31514--- linux-3.0.4/drivers/scsi/pmcraid.h 2011-07-21 22:17:23.000000000 -0400
31515+++ linux-3.0.4/drivers/scsi/pmcraid.h 2011-08-23 21:47:56.000000000 -0400
31516@@ -749,7 +749,7 @@ struct pmcraid_instance {
31517 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
31518
31519 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
31520- atomic_t last_message_id;
31521+ atomic_unchecked_t last_message_id;
31522
31523 /* configuration table */
31524 struct pmcraid_config_table *cfg_table;
31525@@ -778,7 +778,7 @@ struct pmcraid_instance {
31526 atomic_t outstanding_cmds;
31527
31528 /* should add/delete resources to mid-layer now ?*/
31529- atomic_t expose_resources;
31530+ atomic_unchecked_t expose_resources;
31531
31532
31533
31534@@ -814,8 +814,8 @@ struct pmcraid_resource_entry {
31535 struct pmcraid_config_table_entry_ext cfg_entry_ext;
31536 };
31537 struct scsi_device *scsi_dev; /* Link scsi_device structure */
31538- atomic_t read_failures; /* count of failed READ commands */
31539- atomic_t write_failures; /* count of failed WRITE commands */
31540+ atomic_unchecked_t read_failures; /* count of failed READ commands */
31541+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
31542
31543 /* To indicate add/delete/modify during CCN */
31544 u8 change_detected;
31545diff -urNp linux-3.0.4/drivers/scsi/qla2xxx/qla_def.h linux-3.0.4/drivers/scsi/qla2xxx/qla_def.h
31546--- linux-3.0.4/drivers/scsi/qla2xxx/qla_def.h 2011-07-21 22:17:23.000000000 -0400
31547+++ linux-3.0.4/drivers/scsi/qla2xxx/qla_def.h 2011-08-23 21:47:56.000000000 -0400
31548@@ -2244,7 +2244,7 @@ struct isp_operations {
31549 int (*get_flash_version) (struct scsi_qla_host *, void *);
31550 int (*start_scsi) (srb_t *);
31551 int (*abort_isp) (struct scsi_qla_host *);
31552-};
31553+} __no_const;
31554
31555 /* MSI-X Support *************************************************************/
31556
31557diff -urNp linux-3.0.4/drivers/scsi/qla4xxx/ql4_def.h linux-3.0.4/drivers/scsi/qla4xxx/ql4_def.h
31558--- linux-3.0.4/drivers/scsi/qla4xxx/ql4_def.h 2011-07-21 22:17:23.000000000 -0400
31559+++ linux-3.0.4/drivers/scsi/qla4xxx/ql4_def.h 2011-08-23 21:47:56.000000000 -0400
31560@@ -256,7 +256,7 @@ struct ddb_entry {
31561 atomic_t retry_relogin_timer; /* Min Time between relogins
31562 * (4000 only) */
31563 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
31564- atomic_t relogin_retry_count; /* Num of times relogin has been
31565+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
31566 * retried */
31567
31568 uint16_t port;
31569diff -urNp linux-3.0.4/drivers/scsi/qla4xxx/ql4_init.c linux-3.0.4/drivers/scsi/qla4xxx/ql4_init.c
31570--- linux-3.0.4/drivers/scsi/qla4xxx/ql4_init.c 2011-07-21 22:17:23.000000000 -0400
31571+++ linux-3.0.4/drivers/scsi/qla4xxx/ql4_init.c 2011-08-23 21:47:56.000000000 -0400
31572@@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_
31573 ddb_entry->fw_ddb_index = fw_ddb_index;
31574 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
31575 atomic_set(&ddb_entry->relogin_timer, 0);
31576- atomic_set(&ddb_entry->relogin_retry_count, 0);
31577+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
31578 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
31579 list_add_tail(&ddb_entry->list, &ha->ddb_list);
31580 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
31581@@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct s
31582 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
31583 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
31584 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
31585- atomic_set(&ddb_entry->relogin_retry_count, 0);
31586+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
31587 atomic_set(&ddb_entry->relogin_timer, 0);
31588 clear_bit(DF_RELOGIN, &ddb_entry->flags);
31589 iscsi_unblock_session(ddb_entry->sess);
31590diff -urNp linux-3.0.4/drivers/scsi/qla4xxx/ql4_os.c linux-3.0.4/drivers/scsi/qla4xxx/ql4_os.c
31591--- linux-3.0.4/drivers/scsi/qla4xxx/ql4_os.c 2011-07-21 22:17:23.000000000 -0400
31592+++ linux-3.0.4/drivers/scsi/qla4xxx/ql4_os.c 2011-08-23 21:47:56.000000000 -0400
31593@@ -811,13 +811,13 @@ static void qla4xxx_timer(struct scsi_ql
31594 ddb_entry->fw_ddb_device_state ==
31595 DDB_DS_SESSION_FAILED) {
31596 /* Reset retry relogin timer */
31597- atomic_inc(&ddb_entry->relogin_retry_count);
31598+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
31599 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
31600 " timed out-retrying"
31601 " relogin (%d)\n",
31602 ha->host_no,
31603 ddb_entry->fw_ddb_index,
31604- atomic_read(&ddb_entry->
31605+ atomic_read_unchecked(&ddb_entry->
31606 relogin_retry_count))
31607 );
31608 start_dpc++;
31609diff -urNp linux-3.0.4/drivers/scsi/scsi.c linux-3.0.4/drivers/scsi/scsi.c
31610--- linux-3.0.4/drivers/scsi/scsi.c 2011-07-21 22:17:23.000000000 -0400
31611+++ linux-3.0.4/drivers/scsi/scsi.c 2011-08-23 21:47:56.000000000 -0400
31612@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
31613 unsigned long timeout;
31614 int rtn = 0;
31615
31616- atomic_inc(&cmd->device->iorequest_cnt);
31617+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
31618
31619 /* check if the device is still usable */
31620 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
31621diff -urNp linux-3.0.4/drivers/scsi/scsi_debug.c linux-3.0.4/drivers/scsi/scsi_debug.c
31622--- linux-3.0.4/drivers/scsi/scsi_debug.c 2011-07-21 22:17:23.000000000 -0400
31623+++ linux-3.0.4/drivers/scsi/scsi_debug.c 2011-08-23 21:48:14.000000000 -0400
31624@@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_
31625 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
31626 unsigned char *cmd = (unsigned char *)scp->cmnd;
31627
31628+ pax_track_stack();
31629+
31630 if ((errsts = check_readiness(scp, 1, devip)))
31631 return errsts;
31632 memset(arr, 0, sizeof(arr));
31633@@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cm
31634 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
31635 unsigned char *cmd = (unsigned char *)scp->cmnd;
31636
31637+ pax_track_stack();
31638+
31639 if ((errsts = check_readiness(scp, 1, devip)))
31640 return errsts;
31641 memset(arr, 0, sizeof(arr));
31642diff -urNp linux-3.0.4/drivers/scsi/scsi_lib.c linux-3.0.4/drivers/scsi/scsi_lib.c
31643--- linux-3.0.4/drivers/scsi/scsi_lib.c 2011-08-23 21:44:40.000000000 -0400
31644+++ linux-3.0.4/drivers/scsi/scsi_lib.c 2011-08-23 21:47:56.000000000 -0400
31645@@ -1412,7 +1412,7 @@ static void scsi_kill_request(struct req
31646 shost = sdev->host;
31647 scsi_init_cmd_errh(cmd);
31648 cmd->result = DID_NO_CONNECT << 16;
31649- atomic_inc(&cmd->device->iorequest_cnt);
31650+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
31651
31652 /*
31653 * SCSI request completion path will do scsi_device_unbusy(),
31654@@ -1438,9 +1438,9 @@ static void scsi_softirq_done(struct req
31655
31656 INIT_LIST_HEAD(&cmd->eh_entry);
31657
31658- atomic_inc(&cmd->device->iodone_cnt);
31659+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
31660 if (cmd->result)
31661- atomic_inc(&cmd->device->ioerr_cnt);
31662+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
31663
31664 disposition = scsi_decide_disposition(cmd);
31665 if (disposition != SUCCESS &&
31666diff -urNp linux-3.0.4/drivers/scsi/scsi_sysfs.c linux-3.0.4/drivers/scsi/scsi_sysfs.c
31667--- linux-3.0.4/drivers/scsi/scsi_sysfs.c 2011-07-21 22:17:23.000000000 -0400
31668+++ linux-3.0.4/drivers/scsi/scsi_sysfs.c 2011-08-23 21:47:56.000000000 -0400
31669@@ -622,7 +622,7 @@ show_iostat_##field(struct device *dev,
31670 char *buf) \
31671 { \
31672 struct scsi_device *sdev = to_scsi_device(dev); \
31673- unsigned long long count = atomic_read(&sdev->field); \
31674+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
31675 return snprintf(buf, 20, "0x%llx\n", count); \
31676 } \
31677 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
31678diff -urNp linux-3.0.4/drivers/scsi/scsi_transport_fc.c linux-3.0.4/drivers/scsi/scsi_transport_fc.c
31679--- linux-3.0.4/drivers/scsi/scsi_transport_fc.c 2011-07-21 22:17:23.000000000 -0400
31680+++ linux-3.0.4/drivers/scsi/scsi_transport_fc.c 2011-08-23 21:47:56.000000000 -0400
31681@@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_
31682 * Netlink Infrastructure
31683 */
31684
31685-static atomic_t fc_event_seq;
31686+static atomic_unchecked_t fc_event_seq;
31687
31688 /**
31689 * fc_get_event_number - Obtain the next sequential FC event number
31690@@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
31691 u32
31692 fc_get_event_number(void)
31693 {
31694- return atomic_add_return(1, &fc_event_seq);
31695+ return atomic_add_return_unchecked(1, &fc_event_seq);
31696 }
31697 EXPORT_SYMBOL(fc_get_event_number);
31698
31699@@ -645,7 +645,7 @@ static __init int fc_transport_init(void
31700 {
31701 int error;
31702
31703- atomic_set(&fc_event_seq, 0);
31704+ atomic_set_unchecked(&fc_event_seq, 0);
31705
31706 error = transport_class_register(&fc_host_class);
31707 if (error)
31708@@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char
31709 char *cp;
31710
31711 *val = simple_strtoul(buf, &cp, 0);
31712- if ((*cp && (*cp != '\n')) || (*val < 0))
31713+ if (*cp && (*cp != '\n'))
31714 return -EINVAL;
31715 /*
31716 * Check for overflow; dev_loss_tmo is u32
31717diff -urNp linux-3.0.4/drivers/scsi/scsi_transport_iscsi.c linux-3.0.4/drivers/scsi/scsi_transport_iscsi.c
31718--- linux-3.0.4/drivers/scsi/scsi_transport_iscsi.c 2011-07-21 22:17:23.000000000 -0400
31719+++ linux-3.0.4/drivers/scsi/scsi_transport_iscsi.c 2011-08-23 21:47:56.000000000 -0400
31720@@ -83,7 +83,7 @@ struct iscsi_internal {
31721 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
31722 };
31723
31724-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
31725+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
31726 static struct workqueue_struct *iscsi_eh_timer_workq;
31727
31728 /*
31729@@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_s
31730 int err;
31731
31732 ihost = shost->shost_data;
31733- session->sid = atomic_add_return(1, &iscsi_session_nr);
31734+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
31735
31736 if (id == ISCSI_MAX_TARGET) {
31737 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
31738@@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(v
31739 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
31740 ISCSI_TRANSPORT_VERSION);
31741
31742- atomic_set(&iscsi_session_nr, 0);
31743+ atomic_set_unchecked(&iscsi_session_nr, 0);
31744
31745 err = class_register(&iscsi_transport_class);
31746 if (err)
31747diff -urNp linux-3.0.4/drivers/scsi/scsi_transport_srp.c linux-3.0.4/drivers/scsi/scsi_transport_srp.c
31748--- linux-3.0.4/drivers/scsi/scsi_transport_srp.c 2011-07-21 22:17:23.000000000 -0400
31749+++ linux-3.0.4/drivers/scsi/scsi_transport_srp.c 2011-08-23 21:47:56.000000000 -0400
31750@@ -33,7 +33,7 @@
31751 #include "scsi_transport_srp_internal.h"
31752
31753 struct srp_host_attrs {
31754- atomic_t next_port_id;
31755+ atomic_unchecked_t next_port_id;
31756 };
31757 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
31758
31759@@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
31760 struct Scsi_Host *shost = dev_to_shost(dev);
31761 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
31762
31763- atomic_set(&srp_host->next_port_id, 0);
31764+ atomic_set_unchecked(&srp_host->next_port_id, 0);
31765 return 0;
31766 }
31767
31768@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
31769 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
31770 rport->roles = ids->roles;
31771
31772- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
31773+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
31774 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
31775
31776 transport_setup_device(&rport->dev);
31777diff -urNp linux-3.0.4/drivers/scsi/sg.c linux-3.0.4/drivers/scsi/sg.c
31778--- linux-3.0.4/drivers/scsi/sg.c 2011-07-21 22:17:23.000000000 -0400
31779+++ linux-3.0.4/drivers/scsi/sg.c 2011-08-23 21:47:56.000000000 -0400
31780@@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
31781 const struct file_operations * fops;
31782 };
31783
31784-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
31785+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
31786 {"allow_dio", &adio_fops},
31787 {"debug", &debug_fops},
31788 {"def_reserved_size", &dressz_fops},
31789@@ -2325,7 +2325,7 @@ sg_proc_init(void)
31790 {
31791 int k, mask;
31792 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
31793- struct sg_proc_leaf * leaf;
31794+ const struct sg_proc_leaf * leaf;
31795
31796 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
31797 if (!sg_proc_sgp)
31798diff -urNp linux-3.0.4/drivers/scsi/sym53c8xx_2/sym_glue.c linux-3.0.4/drivers/scsi/sym53c8xx_2/sym_glue.c
31799--- linux-3.0.4/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-07-21 22:17:23.000000000 -0400
31800+++ linux-3.0.4/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-08-23 21:48:14.000000000 -0400
31801@@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct p
31802 int do_iounmap = 0;
31803 int do_disable_device = 1;
31804
31805+ pax_track_stack();
31806+
31807 memset(&sym_dev, 0, sizeof(sym_dev));
31808 memset(&nvram, 0, sizeof(nvram));
31809 sym_dev.pdev = pdev;
31810diff -urNp linux-3.0.4/drivers/scsi/vmw_pvscsi.c linux-3.0.4/drivers/scsi/vmw_pvscsi.c
31811--- linux-3.0.4/drivers/scsi/vmw_pvscsi.c 2011-07-21 22:17:23.000000000 -0400
31812+++ linux-3.0.4/drivers/scsi/vmw_pvscsi.c 2011-08-23 21:48:14.000000000 -0400
31813@@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const
31814 dma_addr_t base;
31815 unsigned i;
31816
31817+ pax_track_stack();
31818+
31819 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
31820 cmd.reqRingNumPages = adapter->req_pages;
31821 cmd.cmpRingNumPages = adapter->cmp_pages;
31822diff -urNp linux-3.0.4/drivers/spi/spi.c linux-3.0.4/drivers/spi/spi.c
31823--- linux-3.0.4/drivers/spi/spi.c 2011-07-21 22:17:23.000000000 -0400
31824+++ linux-3.0.4/drivers/spi/spi.c 2011-08-23 21:47:56.000000000 -0400
31825@@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *ma
31826 EXPORT_SYMBOL_GPL(spi_bus_unlock);
31827
31828 /* portable code must never pass more than 32 bytes */
31829-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
31830+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
31831
31832 static u8 *buf;
31833
31834diff -urNp linux-3.0.4/drivers/staging/ath6kl/os/linux/ar6000_drv.c linux-3.0.4/drivers/staging/ath6kl/os/linux/ar6000_drv.c
31835--- linux-3.0.4/drivers/staging/ath6kl/os/linux/ar6000_drv.c 2011-08-23 21:44:40.000000000 -0400
31836+++ linux-3.0.4/drivers/staging/ath6kl/os/linux/ar6000_drv.c 2011-08-23 21:48:14.000000000 -0400
31837@@ -362,7 +362,7 @@ static struct ar_cookie s_ar_cookie_mem[
31838 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
31839
31840
31841-static struct net_device_ops ar6000_netdev_ops = {
31842+static net_device_ops_no_const ar6000_netdev_ops = {
31843 .ndo_init = NULL,
31844 .ndo_open = ar6000_open,
31845 .ndo_stop = ar6000_close,
31846diff -urNp linux-3.0.4/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h linux-3.0.4/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h
31847--- linux-3.0.4/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h 2011-07-21 22:17:23.000000000 -0400
31848+++ linux-3.0.4/drivers/staging/ath6kl/os/linux/include/ar6k_pal.h 2011-08-23 21:47:56.000000000 -0400
31849@@ -30,7 +30,7 @@ typedef bool (*ar6k_pal_recv_pkt_t)(void
31850 typedef struct ar6k_pal_config_s
31851 {
31852 ar6k_pal_recv_pkt_t fpar6k_pal_recv_pkt;
31853-}ar6k_pal_config_t;
31854+} __no_const ar6k_pal_config_t;
31855
31856 void register_pal_cb(ar6k_pal_config_t *palConfig_p);
31857 #endif /* _AR6K_PAL_H_ */
31858diff -urNp linux-3.0.4/drivers/staging/brcm80211/brcmfmac/dhd_linux.c linux-3.0.4/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
31859--- linux-3.0.4/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-07-21 22:17:23.000000000 -0400
31860+++ linux-3.0.4/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-08-23 21:47:56.000000000 -0400
31861@@ -853,14 +853,14 @@ static void dhd_op_if(dhd_if_t *ifp)
31862 free_netdev(ifp->net);
31863 }
31864 /* Allocate etherdev, including space for private structure */
31865- ifp->net = alloc_etherdev(sizeof(dhd));
31866+ ifp->net = alloc_etherdev(sizeof(*dhd));
31867 if (!ifp->net) {
31868 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
31869 ret = -ENOMEM;
31870 }
31871 if (ret == 0) {
31872 strcpy(ifp->net->name, ifp->name);
31873- memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
31874+ memcpy(netdev_priv(ifp->net), dhd, sizeof(*dhd));
31875 err = dhd_net_attach(&dhd->pub, ifp->idx);
31876 if (err != 0) {
31877 DHD_ERROR(("%s: dhd_net_attach failed, "
31878@@ -1872,7 +1872,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
31879 strcpy(nv_path, nvram_path);
31880
31881 /* Allocate etherdev, including space for private structure */
31882- net = alloc_etherdev(sizeof(dhd));
31883+ net = alloc_etherdev(sizeof(*dhd));
31884 if (!net) {
31885 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
31886 goto fail;
31887@@ -1888,7 +1888,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
31888 /*
31889 * Save the dhd_info into the priv
31890 */
31891- memcpy(netdev_priv(net), &dhd, sizeof(dhd));
31892+ memcpy(netdev_priv(net), dhd, sizeof(*dhd));
31893
31894 /* Set network interface name if it was provided as module parameter */
31895 if (iface_name[0]) {
31896@@ -2004,7 +2004,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
31897 /*
31898 * Save the dhd_info into the priv
31899 */
31900- memcpy(netdev_priv(net), &dhd, sizeof(dhd));
31901+ memcpy(netdev_priv(net), dhd, sizeof(*dhd));
31902
31903 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
31904 g_bus = bus;
31905diff -urNp linux-3.0.4/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_int.h linux-3.0.4/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_int.h
31906--- linux-3.0.4/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_int.h 2011-07-21 22:17:23.000000000 -0400
31907+++ linux-3.0.4/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_int.h 2011-08-23 21:47:56.000000000 -0400
31908@@ -593,7 +593,7 @@ struct phy_func_ptr {
31909 initfn_t carrsuppr;
31910 rxsigpwrfn_t rxsigpwr;
31911 detachfn_t detach;
31912-};
31913+} __no_const;
31914 typedef struct phy_func_ptr phy_func_ptr_t;
31915
31916 struct phy_info {
31917diff -urNp linux-3.0.4/drivers/staging/brcm80211/include/bcmsdh.h linux-3.0.4/drivers/staging/brcm80211/include/bcmsdh.h
31918--- linux-3.0.4/drivers/staging/brcm80211/include/bcmsdh.h 2011-07-21 22:17:23.000000000 -0400
31919+++ linux-3.0.4/drivers/staging/brcm80211/include/bcmsdh.h 2011-08-23 21:47:56.000000000 -0400
31920@@ -185,7 +185,7 @@ typedef struct {
31921 u16 func, uint bustype, void *regsva, void *param);
31922 /* detach from device */
31923 void (*detach) (void *ch);
31924-} bcmsdh_driver_t;
31925+} __no_const bcmsdh_driver_t;
31926
31927 /* platform specific/high level functions */
31928 extern int bcmsdh_register(bcmsdh_driver_t *driver);
31929diff -urNp linux-3.0.4/drivers/staging/et131x/et1310_tx.c linux-3.0.4/drivers/staging/et131x/et1310_tx.c
31930--- linux-3.0.4/drivers/staging/et131x/et1310_tx.c 2011-07-21 22:17:23.000000000 -0400
31931+++ linux-3.0.4/drivers/staging/et131x/et1310_tx.c 2011-08-23 21:47:56.000000000 -0400
31932@@ -635,11 +635,11 @@ inline void et131x_free_send_packet(stru
31933 struct net_device_stats *stats = &etdev->net_stats;
31934
31935 if (tcb->flags & fMP_DEST_BROAD)
31936- atomic_inc(&etdev->Stats.brdcstxmt);
31937+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
31938 else if (tcb->flags & fMP_DEST_MULTI)
31939- atomic_inc(&etdev->Stats.multixmt);
31940+ atomic_inc_unchecked(&etdev->Stats.multixmt);
31941 else
31942- atomic_inc(&etdev->Stats.unixmt);
31943+ atomic_inc_unchecked(&etdev->Stats.unixmt);
31944
31945 if (tcb->skb) {
31946 stats->tx_bytes += tcb->skb->len;
31947diff -urNp linux-3.0.4/drivers/staging/et131x/et131x_adapter.h linux-3.0.4/drivers/staging/et131x/et131x_adapter.h
31948--- linux-3.0.4/drivers/staging/et131x/et131x_adapter.h 2011-07-21 22:17:23.000000000 -0400
31949+++ linux-3.0.4/drivers/staging/et131x/et131x_adapter.h 2011-08-23 21:47:56.000000000 -0400
31950@@ -110,11 +110,11 @@ typedef struct _ce_stats_t {
31951 * operations
31952 */
31953 u32 unircv; /* # multicast packets received */
31954- atomic_t unixmt; /* # multicast packets for Tx */
31955+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
31956 u32 multircv; /* # multicast packets received */
31957- atomic_t multixmt; /* # multicast packets for Tx */
31958+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
31959 u32 brdcstrcv; /* # broadcast packets received */
31960- atomic_t brdcstxmt; /* # broadcast packets for Tx */
31961+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
31962 u32 norcvbuf; /* # Rx packets discarded */
31963 u32 noxmtbuf; /* # Tx packets discarded */
31964
31965diff -urNp linux-3.0.4/drivers/staging/hv/channel.c linux-3.0.4/drivers/staging/hv/channel.c
31966--- linux-3.0.4/drivers/staging/hv/channel.c 2011-08-23 21:44:40.000000000 -0400
31967+++ linux-3.0.4/drivers/staging/hv/channel.c 2011-08-23 21:47:56.000000000 -0400
31968@@ -433,8 +433,8 @@ int vmbus_establish_gpadl(struct vmbus_c
31969 int ret = 0;
31970 int t;
31971
31972- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31973- atomic_inc(&vmbus_connection.next_gpadl_handle);
31974+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31975+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31976
31977 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31978 if (ret)
31979diff -urNp linux-3.0.4/drivers/staging/hv/hv.c linux-3.0.4/drivers/staging/hv/hv.c
31980--- linux-3.0.4/drivers/staging/hv/hv.c 2011-07-21 22:17:23.000000000 -0400
31981+++ linux-3.0.4/drivers/staging/hv/hv.c 2011-08-23 21:47:56.000000000 -0400
31982@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, voi
31983 u64 output_address = (output) ? virt_to_phys(output) : 0;
31984 u32 output_address_hi = output_address >> 32;
31985 u32 output_address_lo = output_address & 0xFFFFFFFF;
31986- volatile void *hypercall_page = hv_context.hypercall_page;
31987+ volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31988
31989 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31990 "=a"(hv_status_lo) : "d" (control_hi),
31991diff -urNp linux-3.0.4/drivers/staging/hv/hv_mouse.c linux-3.0.4/drivers/staging/hv/hv_mouse.c
31992--- linux-3.0.4/drivers/staging/hv/hv_mouse.c 2011-07-21 22:17:23.000000000 -0400
31993+++ linux-3.0.4/drivers/staging/hv/hv_mouse.c 2011-08-23 21:47:56.000000000 -0400
31994@@ -879,8 +879,10 @@ static void reportdesc_callback(struct h
31995 if (hid_dev) {
31996 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
31997
31998- hid_dev->ll_driver->open = mousevsc_hid_open;
31999- hid_dev->ll_driver->close = mousevsc_hid_close;
32000+ pax_open_kernel();
32001+ *(void **)&hid_dev->ll_driver->open = mousevsc_hid_open;
32002+ *(void **)&hid_dev->ll_driver->close = mousevsc_hid_close;
32003+ pax_close_kernel();
32004
32005 hid_dev->bus = BUS_VIRTUAL;
32006 hid_dev->vendor = input_device_ctx->device_info.vendor;
32007diff -urNp linux-3.0.4/drivers/staging/hv/hyperv_vmbus.h linux-3.0.4/drivers/staging/hv/hyperv_vmbus.h
32008--- linux-3.0.4/drivers/staging/hv/hyperv_vmbus.h 2011-07-21 22:17:23.000000000 -0400
32009+++ linux-3.0.4/drivers/staging/hv/hyperv_vmbus.h 2011-08-23 21:47:56.000000000 -0400
32010@@ -559,7 +559,7 @@ enum vmbus_connect_state {
32011 struct vmbus_connection {
32012 enum vmbus_connect_state conn_state;
32013
32014- atomic_t next_gpadl_handle;
32015+ atomic_unchecked_t next_gpadl_handle;
32016
32017 /*
32018 * Represents channel interrupts. Each bit position represents a
32019diff -urNp linux-3.0.4/drivers/staging/hv/rndis_filter.c linux-3.0.4/drivers/staging/hv/rndis_filter.c
32020--- linux-3.0.4/drivers/staging/hv/rndis_filter.c 2011-08-23 21:44:40.000000000 -0400
32021+++ linux-3.0.4/drivers/staging/hv/rndis_filter.c 2011-08-23 21:47:56.000000000 -0400
32022@@ -43,7 +43,7 @@ struct rndis_device {
32023
32024 enum rndis_device_state state;
32025 u32 link_stat;
32026- atomic_t new_req_id;
32027+ atomic_unchecked_t new_req_id;
32028
32029 spinlock_t request_lock;
32030 struct list_head req_list;
32031@@ -117,7 +117,7 @@ static struct rndis_request *get_rndis_r
32032 * template
32033 */
32034 set = &rndis_msg->msg.set_req;
32035- set->req_id = atomic_inc_return(&dev->new_req_id);
32036+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
32037
32038 /* Add to the request list */
32039 spin_lock_irqsave(&dev->request_lock, flags);
32040@@ -637,7 +637,7 @@ static void rndis_filter_halt_device(str
32041
32042 /* Setup the rndis set */
32043 halt = &request->request_msg.msg.halt_req;
32044- halt->req_id = atomic_inc_return(&dev->new_req_id);
32045+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
32046
32047 /* Ignore return since this msg is optional. */
32048 rndis_filter_send_request(dev, request);
32049diff -urNp linux-3.0.4/drivers/staging/hv/vmbus_drv.c linux-3.0.4/drivers/staging/hv/vmbus_drv.c
32050--- linux-3.0.4/drivers/staging/hv/vmbus_drv.c 2011-07-21 22:17:23.000000000 -0400
32051+++ linux-3.0.4/drivers/staging/hv/vmbus_drv.c 2011-08-23 21:47:56.000000000 -0400
32052@@ -668,11 +668,11 @@ int vmbus_child_device_register(struct h
32053 {
32054 int ret = 0;
32055
32056- static atomic_t device_num = ATOMIC_INIT(0);
32057+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
32058
32059 /* Set the device name. Otherwise, device_register() will fail. */
32060 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
32061- atomic_inc_return(&device_num));
32062+ atomic_inc_return_unchecked(&device_num));
32063
32064 /* The new device belongs to this bus */
32065 child_device_obj->device.bus = &hv_bus; /* device->dev.bus; */
32066diff -urNp linux-3.0.4/drivers/staging/iio/ring_generic.h linux-3.0.4/drivers/staging/iio/ring_generic.h
32067--- linux-3.0.4/drivers/staging/iio/ring_generic.h 2011-07-21 22:17:23.000000000 -0400
32068+++ linux-3.0.4/drivers/staging/iio/ring_generic.h 2011-08-23 21:47:56.000000000 -0400
32069@@ -62,7 +62,7 @@ struct iio_ring_access_funcs {
32070
32071 int (*is_enabled)(struct iio_ring_buffer *ring);
32072 int (*enable)(struct iio_ring_buffer *ring);
32073-};
32074+} __no_const;
32075
32076 struct iio_ring_setup_ops {
32077 int (*preenable)(struct iio_dev *);
32078diff -urNp linux-3.0.4/drivers/staging/octeon/ethernet.c linux-3.0.4/drivers/staging/octeon/ethernet.c
32079--- linux-3.0.4/drivers/staging/octeon/ethernet.c 2011-07-21 22:17:23.000000000 -0400
32080+++ linux-3.0.4/drivers/staging/octeon/ethernet.c 2011-08-23 21:47:56.000000000 -0400
32081@@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_
32082 * since the RX tasklet also increments it.
32083 */
32084 #ifdef CONFIG_64BIT
32085- atomic64_add(rx_status.dropped_packets,
32086- (atomic64_t *)&priv->stats.rx_dropped);
32087+ atomic64_add_unchecked(rx_status.dropped_packets,
32088+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
32089 #else
32090- atomic_add(rx_status.dropped_packets,
32091- (atomic_t *)&priv->stats.rx_dropped);
32092+ atomic_add_unchecked(rx_status.dropped_packets,
32093+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
32094 #endif
32095 }
32096
32097diff -urNp linux-3.0.4/drivers/staging/octeon/ethernet-rx.c linux-3.0.4/drivers/staging/octeon/ethernet-rx.c
32098--- linux-3.0.4/drivers/staging/octeon/ethernet-rx.c 2011-07-21 22:17:23.000000000 -0400
32099+++ linux-3.0.4/drivers/staging/octeon/ethernet-rx.c 2011-08-23 21:47:56.000000000 -0400
32100@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi
32101 /* Increment RX stats for virtual ports */
32102 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
32103 #ifdef CONFIG_64BIT
32104- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
32105- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
32106+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
32107+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
32108 #else
32109- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
32110- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
32111+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
32112+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
32113 #endif
32114 }
32115 netif_receive_skb(skb);
32116@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi
32117 dev->name);
32118 */
32119 #ifdef CONFIG_64BIT
32120- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
32121+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
32122 #else
32123- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
32124+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
32125 #endif
32126 dev_kfree_skb_irq(skb);
32127 }
32128diff -urNp linux-3.0.4/drivers/staging/pohmelfs/inode.c linux-3.0.4/drivers/staging/pohmelfs/inode.c
32129--- linux-3.0.4/drivers/staging/pohmelfs/inode.c 2011-07-21 22:17:23.000000000 -0400
32130+++ linux-3.0.4/drivers/staging/pohmelfs/inode.c 2011-08-23 21:47:56.000000000 -0400
32131@@ -1856,7 +1856,7 @@ static int pohmelfs_fill_super(struct su
32132 mutex_init(&psb->mcache_lock);
32133 psb->mcache_root = RB_ROOT;
32134 psb->mcache_timeout = msecs_to_jiffies(5000);
32135- atomic_long_set(&psb->mcache_gen, 0);
32136+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
32137
32138 psb->trans_max_pages = 100;
32139
32140@@ -1871,7 +1871,7 @@ static int pohmelfs_fill_super(struct su
32141 INIT_LIST_HEAD(&psb->crypto_ready_list);
32142 INIT_LIST_HEAD(&psb->crypto_active_list);
32143
32144- atomic_set(&psb->trans_gen, 1);
32145+ atomic_set_unchecked(&psb->trans_gen, 1);
32146 atomic_long_set(&psb->total_inodes, 0);
32147
32148 mutex_init(&psb->state_lock);
32149diff -urNp linux-3.0.4/drivers/staging/pohmelfs/mcache.c linux-3.0.4/drivers/staging/pohmelfs/mcache.c
32150--- linux-3.0.4/drivers/staging/pohmelfs/mcache.c 2011-07-21 22:17:23.000000000 -0400
32151+++ linux-3.0.4/drivers/staging/pohmelfs/mcache.c 2011-08-23 21:47:56.000000000 -0400
32152@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
32153 m->data = data;
32154 m->start = start;
32155 m->size = size;
32156- m->gen = atomic_long_inc_return(&psb->mcache_gen);
32157+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
32158
32159 mutex_lock(&psb->mcache_lock);
32160 err = pohmelfs_mcache_insert(psb, m);
32161diff -urNp linux-3.0.4/drivers/staging/pohmelfs/netfs.h linux-3.0.4/drivers/staging/pohmelfs/netfs.h
32162--- linux-3.0.4/drivers/staging/pohmelfs/netfs.h 2011-07-21 22:17:23.000000000 -0400
32163+++ linux-3.0.4/drivers/staging/pohmelfs/netfs.h 2011-08-23 21:47:56.000000000 -0400
32164@@ -571,14 +571,14 @@ struct pohmelfs_config;
32165 struct pohmelfs_sb {
32166 struct rb_root mcache_root;
32167 struct mutex mcache_lock;
32168- atomic_long_t mcache_gen;
32169+ atomic_long_unchecked_t mcache_gen;
32170 unsigned long mcache_timeout;
32171
32172 unsigned int idx;
32173
32174 unsigned int trans_retries;
32175
32176- atomic_t trans_gen;
32177+ atomic_unchecked_t trans_gen;
32178
32179 unsigned int crypto_attached_size;
32180 unsigned int crypto_align_size;
32181diff -urNp linux-3.0.4/drivers/staging/pohmelfs/trans.c linux-3.0.4/drivers/staging/pohmelfs/trans.c
32182--- linux-3.0.4/drivers/staging/pohmelfs/trans.c 2011-07-21 22:17:23.000000000 -0400
32183+++ linux-3.0.4/drivers/staging/pohmelfs/trans.c 2011-08-23 21:47:56.000000000 -0400
32184@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
32185 int err;
32186 struct netfs_cmd *cmd = t->iovec.iov_base;
32187
32188- t->gen = atomic_inc_return(&psb->trans_gen);
32189+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
32190
32191 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
32192 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
32193diff -urNp linux-3.0.4/drivers/staging/rtl8712/rtl871x_io.h linux-3.0.4/drivers/staging/rtl8712/rtl871x_io.h
32194--- linux-3.0.4/drivers/staging/rtl8712/rtl871x_io.h 2011-07-21 22:17:23.000000000 -0400
32195+++ linux-3.0.4/drivers/staging/rtl8712/rtl871x_io.h 2011-08-23 21:47:56.000000000 -0400
32196@@ -83,7 +83,7 @@ struct _io_ops {
32197 u8 *pmem);
32198 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
32199 u8 *pmem);
32200-};
32201+} __no_const;
32202
32203 struct io_req {
32204 struct list_head list;
32205diff -urNp linux-3.0.4/drivers/staging/sbe-2t3e3/netdev.c linux-3.0.4/drivers/staging/sbe-2t3e3/netdev.c
32206--- linux-3.0.4/drivers/staging/sbe-2t3e3/netdev.c 2011-07-21 22:17:23.000000000 -0400
32207+++ linux-3.0.4/drivers/staging/sbe-2t3e3/netdev.c 2011-08-24 18:21:41.000000000 -0400
32208@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, s
32209 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
32210
32211 if (rlen)
32212- if (copy_to_user(data, &resp, rlen))
32213+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
32214 return -EFAULT;
32215
32216 return 0;
32217diff -urNp linux-3.0.4/drivers/staging/tty/stallion.c linux-3.0.4/drivers/staging/tty/stallion.c
32218--- linux-3.0.4/drivers/staging/tty/stallion.c 2011-07-21 22:17:23.000000000 -0400
32219+++ linux-3.0.4/drivers/staging/tty/stallion.c 2011-08-23 21:48:14.000000000 -0400
32220@@ -2406,6 +2406,8 @@ static int stl_getportstruct(struct stlp
32221 struct stlport stl_dummyport;
32222 struct stlport *portp;
32223
32224+ pax_track_stack();
32225+
32226 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
32227 return -EFAULT;
32228 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
32229diff -urNp linux-3.0.4/drivers/staging/usbip/usbip_common.h linux-3.0.4/drivers/staging/usbip/usbip_common.h
32230--- linux-3.0.4/drivers/staging/usbip/usbip_common.h 2011-07-21 22:17:23.000000000 -0400
32231+++ linux-3.0.4/drivers/staging/usbip/usbip_common.h 2011-08-23 21:47:56.000000000 -0400
32232@@ -315,7 +315,7 @@ struct usbip_device {
32233 void (*shutdown)(struct usbip_device *);
32234 void (*reset)(struct usbip_device *);
32235 void (*unusable)(struct usbip_device *);
32236- } eh_ops;
32237+ } __no_const eh_ops;
32238 };
32239
32240 void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
32241diff -urNp linux-3.0.4/drivers/staging/usbip/vhci.h linux-3.0.4/drivers/staging/usbip/vhci.h
32242--- linux-3.0.4/drivers/staging/usbip/vhci.h 2011-07-21 22:17:23.000000000 -0400
32243+++ linux-3.0.4/drivers/staging/usbip/vhci.h 2011-08-23 21:47:56.000000000 -0400
32244@@ -94,7 +94,7 @@ struct vhci_hcd {
32245 unsigned resuming:1;
32246 unsigned long re_timeout;
32247
32248- atomic_t seqnum;
32249+ atomic_unchecked_t seqnum;
32250
32251 /*
32252 * NOTE:
32253diff -urNp linux-3.0.4/drivers/staging/usbip/vhci_hcd.c linux-3.0.4/drivers/staging/usbip/vhci_hcd.c
32254--- linux-3.0.4/drivers/staging/usbip/vhci_hcd.c 2011-08-23 21:44:40.000000000 -0400
32255+++ linux-3.0.4/drivers/staging/usbip/vhci_hcd.c 2011-08-23 21:47:56.000000000 -0400
32256@@ -511,7 +511,7 @@ static void vhci_tx_urb(struct urb *urb)
32257 return;
32258 }
32259
32260- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
32261+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
32262 if (priv->seqnum == 0xffff)
32263 dev_info(&urb->dev->dev, "seqnum max\n");
32264
32265@@ -765,7 +765,7 @@ static int vhci_urb_dequeue(struct usb_h
32266 return -ENOMEM;
32267 }
32268
32269- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
32270+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
32271 if (unlink->seqnum == 0xffff)
32272 pr_info("seqnum max\n");
32273
32274@@ -955,7 +955,7 @@ static int vhci_start(struct usb_hcd *hc
32275 vdev->rhport = rhport;
32276 }
32277
32278- atomic_set(&vhci->seqnum, 0);
32279+ atomic_set_unchecked(&vhci->seqnum, 0);
32280 spin_lock_init(&vhci->lock);
32281
32282 hcd->power_budget = 0; /* no limit */
32283diff -urNp linux-3.0.4/drivers/staging/usbip/vhci_rx.c linux-3.0.4/drivers/staging/usbip/vhci_rx.c
32284--- linux-3.0.4/drivers/staging/usbip/vhci_rx.c 2011-07-21 22:17:23.000000000 -0400
32285+++ linux-3.0.4/drivers/staging/usbip/vhci_rx.c 2011-08-23 21:47:56.000000000 -0400
32286@@ -76,7 +76,7 @@ static void vhci_recv_ret_submit(struct
32287 if (!urb) {
32288 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
32289 pr_info("max seqnum %d\n",
32290- atomic_read(&the_controller->seqnum));
32291+ atomic_read_unchecked(&the_controller->seqnum));
32292 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
32293 return;
32294 }
32295diff -urNp linux-3.0.4/drivers/staging/vt6655/hostap.c linux-3.0.4/drivers/staging/vt6655/hostap.c
32296--- linux-3.0.4/drivers/staging/vt6655/hostap.c 2011-07-21 22:17:23.000000000 -0400
32297+++ linux-3.0.4/drivers/staging/vt6655/hostap.c 2011-08-23 21:47:56.000000000 -0400
32298@@ -79,14 +79,13 @@ static int msglevel
32299 *
32300 */
32301
32302+static net_device_ops_no_const apdev_netdev_ops;
32303+
32304 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
32305 {
32306 PSDevice apdev_priv;
32307 struct net_device *dev = pDevice->dev;
32308 int ret;
32309- const struct net_device_ops apdev_netdev_ops = {
32310- .ndo_start_xmit = pDevice->tx_80211,
32311- };
32312
32313 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
32314
32315@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevic
32316 *apdev_priv = *pDevice;
32317 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
32318
32319+ /* only half broken now */
32320+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
32321 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
32322
32323 pDevice->apdev->type = ARPHRD_IEEE80211;
32324diff -urNp linux-3.0.4/drivers/staging/vt6656/hostap.c linux-3.0.4/drivers/staging/vt6656/hostap.c
32325--- linux-3.0.4/drivers/staging/vt6656/hostap.c 2011-07-21 22:17:23.000000000 -0400
32326+++ linux-3.0.4/drivers/staging/vt6656/hostap.c 2011-08-23 21:47:56.000000000 -0400
32327@@ -80,14 +80,13 @@ static int msglevel
32328 *
32329 */
32330
32331+static net_device_ops_no_const apdev_netdev_ops;
32332+
32333 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
32334 {
32335 PSDevice apdev_priv;
32336 struct net_device *dev = pDevice->dev;
32337 int ret;
32338- const struct net_device_ops apdev_netdev_ops = {
32339- .ndo_start_xmit = pDevice->tx_80211,
32340- };
32341
32342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
32343
32344@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevic
32345 *apdev_priv = *pDevice;
32346 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
32347
32348+ /* only half broken now */
32349+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
32350 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
32351
32352 pDevice->apdev->type = ARPHRD_IEEE80211;
32353diff -urNp linux-3.0.4/drivers/staging/wlan-ng/hfa384x_usb.c linux-3.0.4/drivers/staging/wlan-ng/hfa384x_usb.c
32354--- linux-3.0.4/drivers/staging/wlan-ng/hfa384x_usb.c 2011-07-21 22:17:23.000000000 -0400
32355+++ linux-3.0.4/drivers/staging/wlan-ng/hfa384x_usb.c 2011-08-23 21:47:56.000000000 -0400
32356@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hf
32357
32358 struct usbctlx_completor {
32359 int (*complete) (struct usbctlx_completor *);
32360-};
32361+} __no_const;
32362
32363 static int
32364 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
32365diff -urNp linux-3.0.4/drivers/staging/zcache/tmem.c linux-3.0.4/drivers/staging/zcache/tmem.c
32366--- linux-3.0.4/drivers/staging/zcache/tmem.c 2011-07-21 22:17:23.000000000 -0400
32367+++ linux-3.0.4/drivers/staging/zcache/tmem.c 2011-08-23 21:47:56.000000000 -0400
32368@@ -39,7 +39,7 @@
32369 * A tmem host implementation must use this function to register callbacks
32370 * for memory allocation.
32371 */
32372-static struct tmem_hostops tmem_hostops;
32373+static tmem_hostops_no_const tmem_hostops;
32374
32375 static void tmem_objnode_tree_init(void);
32376
32377@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_h
32378 * A tmem host implementation must use this function to register
32379 * callbacks for a page-accessible memory (PAM) implementation
32380 */
32381-static struct tmem_pamops tmem_pamops;
32382+static tmem_pamops_no_const tmem_pamops;
32383
32384 void tmem_register_pamops(struct tmem_pamops *m)
32385 {
32386diff -urNp linux-3.0.4/drivers/staging/zcache/tmem.h linux-3.0.4/drivers/staging/zcache/tmem.h
32387--- linux-3.0.4/drivers/staging/zcache/tmem.h 2011-07-21 22:17:23.000000000 -0400
32388+++ linux-3.0.4/drivers/staging/zcache/tmem.h 2011-08-23 21:47:56.000000000 -0400
32389@@ -171,6 +171,7 @@ struct tmem_pamops {
32390 int (*get_data)(struct page *, void *, struct tmem_pool *);
32391 void (*free)(void *, struct tmem_pool *);
32392 };
32393+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
32394 extern void tmem_register_pamops(struct tmem_pamops *m);
32395
32396 /* memory allocation methods provided by the host implementation */
32397@@ -180,6 +181,7 @@ struct tmem_hostops {
32398 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
32399 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
32400 };
32401+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
32402 extern void tmem_register_hostops(struct tmem_hostops *m);
32403
32404 /* core tmem accessor functions */
32405diff -urNp linux-3.0.4/drivers/target/target_core_alua.c linux-3.0.4/drivers/target/target_core_alua.c
32406--- linux-3.0.4/drivers/target/target_core_alua.c 2011-07-21 22:17:23.000000000 -0400
32407+++ linux-3.0.4/drivers/target/target_core_alua.c 2011-08-23 21:48:14.000000000 -0400
32408@@ -675,6 +675,8 @@ static int core_alua_update_tpg_primary_
32409 char path[ALUA_METADATA_PATH_LEN];
32410 int len;
32411
32412+ pax_track_stack();
32413+
32414 memset(path, 0, ALUA_METADATA_PATH_LEN);
32415
32416 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
32417@@ -938,6 +940,8 @@ static int core_alua_update_tpg_secondar
32418 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
32419 int len;
32420
32421+ pax_track_stack();
32422+
32423 memset(path, 0, ALUA_METADATA_PATH_LEN);
32424 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
32425
32426diff -urNp linux-3.0.4/drivers/target/target_core_cdb.c linux-3.0.4/drivers/target/target_core_cdb.c
32427--- linux-3.0.4/drivers/target/target_core_cdb.c 2011-07-21 22:17:23.000000000 -0400
32428+++ linux-3.0.4/drivers/target/target_core_cdb.c 2011-08-23 21:48:14.000000000 -0400
32429@@ -838,6 +838,8 @@ target_emulate_modesense(struct se_cmd *
32430 int length = 0;
32431 unsigned char buf[SE_MODE_PAGE_BUF];
32432
32433+ pax_track_stack();
32434+
32435 memset(buf, 0, SE_MODE_PAGE_BUF);
32436
32437 switch (cdb[2] & 0x3f) {
32438diff -urNp linux-3.0.4/drivers/target/target_core_configfs.c linux-3.0.4/drivers/target/target_core_configfs.c
32439--- linux-3.0.4/drivers/target/target_core_configfs.c 2011-07-21 22:17:23.000000000 -0400
32440+++ linux-3.0.4/drivers/target/target_core_configfs.c 2011-08-23 21:48:14.000000000 -0400
32441@@ -1276,6 +1276,8 @@ static ssize_t target_core_dev_pr_show_a
32442 ssize_t len = 0;
32443 int reg_count = 0, prf_isid;
32444
32445+ pax_track_stack();
32446+
32447 if (!(su_dev->se_dev_ptr))
32448 return -ENODEV;
32449
32450diff -urNp linux-3.0.4/drivers/target/target_core_pr.c linux-3.0.4/drivers/target/target_core_pr.c
32451--- linux-3.0.4/drivers/target/target_core_pr.c 2011-07-21 22:17:23.000000000 -0400
32452+++ linux-3.0.4/drivers/target/target_core_pr.c 2011-08-23 21:48:14.000000000 -0400
32453@@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_regi
32454 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
32455 u16 tpgt;
32456
32457+ pax_track_stack();
32458+
32459 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
32460 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
32461 /*
32462@@ -1861,6 +1863,8 @@ static int __core_scsi3_update_aptpl_buf
32463 ssize_t len = 0;
32464 int reg_count = 0;
32465
32466+ pax_track_stack();
32467+
32468 memset(buf, 0, pr_aptpl_buf_len);
32469 /*
32470 * Called to clear metadata once APTPL has been deactivated.
32471@@ -1983,6 +1987,8 @@ static int __core_scsi3_write_aptpl_to_f
32472 char path[512];
32473 int ret;
32474
32475+ pax_track_stack();
32476+
32477 memset(iov, 0, sizeof(struct iovec));
32478 memset(path, 0, 512);
32479
32480diff -urNp linux-3.0.4/drivers/target/target_core_tmr.c linux-3.0.4/drivers/target/target_core_tmr.c
32481--- linux-3.0.4/drivers/target/target_core_tmr.c 2011-07-21 22:17:23.000000000 -0400
32482+++ linux-3.0.4/drivers/target/target_core_tmr.c 2011-08-23 21:47:56.000000000 -0400
32483@@ -269,7 +269,7 @@ int core_tmr_lun_reset(
32484 CMD_TFO(cmd)->get_task_tag(cmd), cmd->pr_res_key,
32485 T_TASK(cmd)->t_task_cdbs,
32486 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
32487- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
32488+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
32489 atomic_read(&T_TASK(cmd)->t_transport_active),
32490 atomic_read(&T_TASK(cmd)->t_transport_stop),
32491 atomic_read(&T_TASK(cmd)->t_transport_sent));
32492@@ -311,7 +311,7 @@ int core_tmr_lun_reset(
32493 DEBUG_LR("LUN_RESET: got t_transport_active = 1 for"
32494 " task: %p, t_fe_count: %d dev: %p\n", task,
32495 fe_count, dev);
32496- atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
32497+ atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
32498 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock,
32499 flags);
32500 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
32501@@ -321,7 +321,7 @@ int core_tmr_lun_reset(
32502 }
32503 DEBUG_LR("LUN_RESET: Got t_transport_active = 0 for task: %p,"
32504 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
32505- atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
32506+ atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
32507 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
32508 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
32509
32510diff -urNp linux-3.0.4/drivers/target/target_core_transport.c linux-3.0.4/drivers/target/target_core_transport.c
32511--- linux-3.0.4/drivers/target/target_core_transport.c 2011-07-21 22:17:23.000000000 -0400
32512+++ linux-3.0.4/drivers/target/target_core_transport.c 2011-08-23 21:47:56.000000000 -0400
32513@@ -1681,7 +1681,7 @@ struct se_device *transport_add_device_t
32514
32515 dev->queue_depth = dev_limits->queue_depth;
32516 atomic_set(&dev->depth_left, dev->queue_depth);
32517- atomic_set(&dev->dev_ordered_id, 0);
32518+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
32519
32520 se_dev_set_default_attribs(dev, dev_limits);
32521
32522@@ -1882,7 +1882,7 @@ static int transport_check_alloc_task_at
32523 * Used to determine when ORDERED commands should go from
32524 * Dormant to Active status.
32525 */
32526- cmd->se_ordered_id = atomic_inc_return(&SE_DEV(cmd)->dev_ordered_id);
32527+ cmd->se_ordered_id = atomic_inc_return_unchecked(&SE_DEV(cmd)->dev_ordered_id);
32528 smp_mb__after_atomic_inc();
32529 DEBUG_STA("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
32530 cmd->se_ordered_id, cmd->sam_task_attr,
32531@@ -2169,7 +2169,7 @@ static void transport_generic_request_fa
32532 " t_transport_active: %d t_transport_stop: %d"
32533 " t_transport_sent: %d\n", T_TASK(cmd)->t_task_cdbs,
32534 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
32535- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
32536+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
32537 atomic_read(&T_TASK(cmd)->t_task_cdbs_ex_left),
32538 atomic_read(&T_TASK(cmd)->t_transport_active),
32539 atomic_read(&T_TASK(cmd)->t_transport_stop),
32540@@ -2673,9 +2673,9 @@ check_depth:
32541 spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
32542 atomic_set(&task->task_active, 1);
32543 atomic_set(&task->task_sent, 1);
32544- atomic_inc(&T_TASK(cmd)->t_task_cdbs_sent);
32545+ atomic_inc_unchecked(&T_TASK(cmd)->t_task_cdbs_sent);
32546
32547- if (atomic_read(&T_TASK(cmd)->t_task_cdbs_sent) ==
32548+ if (atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent) ==
32549 T_TASK(cmd)->t_task_cdbs)
32550 atomic_set(&cmd->transport_sent, 1);
32551
32552@@ -5568,7 +5568,7 @@ static void transport_generic_wait_for_t
32553 atomic_set(&T_TASK(cmd)->transport_lun_stop, 0);
32554 }
32555 if (!atomic_read(&T_TASK(cmd)->t_transport_active) ||
32556- atomic_read(&T_TASK(cmd)->t_transport_aborted))
32557+ atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted))
32558 goto remove;
32559
32560 atomic_set(&T_TASK(cmd)->t_transport_stop, 1);
32561@@ -5797,7 +5797,7 @@ int transport_check_aborted_status(struc
32562 {
32563 int ret = 0;
32564
32565- if (atomic_read(&T_TASK(cmd)->t_transport_aborted) != 0) {
32566+ if (atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted) != 0) {
32567 if (!(send_status) ||
32568 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
32569 return 1;
32570@@ -5825,7 +5825,7 @@ void transport_send_task_abort(struct se
32571 */
32572 if (cmd->data_direction == DMA_TO_DEVICE) {
32573 if (CMD_TFO(cmd)->write_pending_status(cmd) != 0) {
32574- atomic_inc(&T_TASK(cmd)->t_transport_aborted);
32575+ atomic_inc_unchecked(&T_TASK(cmd)->t_transport_aborted);
32576 smp_mb__after_atomic_inc();
32577 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
32578 transport_new_cmd_failure(cmd);
32579@@ -5949,7 +5949,7 @@ static void transport_processing_shutdow
32580 CMD_TFO(cmd)->get_task_tag(cmd),
32581 T_TASK(cmd)->t_task_cdbs,
32582 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
32583- atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
32584+ atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
32585 atomic_read(&T_TASK(cmd)->t_transport_active),
32586 atomic_read(&T_TASK(cmd)->t_transport_stop),
32587 atomic_read(&T_TASK(cmd)->t_transport_sent));
32588diff -urNp linux-3.0.4/drivers/telephony/ixj.c linux-3.0.4/drivers/telephony/ixj.c
32589--- linux-3.0.4/drivers/telephony/ixj.c 2011-07-21 22:17:23.000000000 -0400
32590+++ linux-3.0.4/drivers/telephony/ixj.c 2011-08-23 21:48:14.000000000 -0400
32591@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
32592 bool mContinue;
32593 char *pIn, *pOut;
32594
32595+ pax_track_stack();
32596+
32597 if (!SCI_Prepare(j))
32598 return 0;
32599
32600diff -urNp linux-3.0.4/drivers/tty/hvc/hvcs.c linux-3.0.4/drivers/tty/hvc/hvcs.c
32601--- linux-3.0.4/drivers/tty/hvc/hvcs.c 2011-07-21 22:17:23.000000000 -0400
32602+++ linux-3.0.4/drivers/tty/hvc/hvcs.c 2011-08-23 21:47:56.000000000 -0400
32603@@ -83,6 +83,7 @@
32604 #include <asm/hvcserver.h>
32605 #include <asm/uaccess.h>
32606 #include <asm/vio.h>
32607+#include <asm/local.h>
32608
32609 /*
32610 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
32611@@ -270,7 +271,7 @@ struct hvcs_struct {
32612 unsigned int index;
32613
32614 struct tty_struct *tty;
32615- int open_count;
32616+ local_t open_count;
32617
32618 /*
32619 * Used to tell the driver kernel_thread what operations need to take
32620@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(st
32621
32622 spin_lock_irqsave(&hvcsd->lock, flags);
32623
32624- if (hvcsd->open_count > 0) {
32625+ if (local_read(&hvcsd->open_count) > 0) {
32626 spin_unlock_irqrestore(&hvcsd->lock, flags);
32627 printk(KERN_INFO "HVCS: vterm state unchanged. "
32628 "The hvcs device node is still in use.\n");
32629@@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *
32630 if ((retval = hvcs_partner_connect(hvcsd)))
32631 goto error_release;
32632
32633- hvcsd->open_count = 1;
32634+ local_set(&hvcsd->open_count, 1);
32635 hvcsd->tty = tty;
32636 tty->driver_data = hvcsd;
32637
32638@@ -1179,7 +1180,7 @@ fast_open:
32639
32640 spin_lock_irqsave(&hvcsd->lock, flags);
32641 kref_get(&hvcsd->kref);
32642- hvcsd->open_count++;
32643+ local_inc(&hvcsd->open_count);
32644 hvcsd->todo_mask |= HVCS_SCHED_READ;
32645 spin_unlock_irqrestore(&hvcsd->lock, flags);
32646
32647@@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct
32648 hvcsd = tty->driver_data;
32649
32650 spin_lock_irqsave(&hvcsd->lock, flags);
32651- if (--hvcsd->open_count == 0) {
32652+ if (local_dec_and_test(&hvcsd->open_count)) {
32653
32654 vio_disable_interrupts(hvcsd->vdev);
32655
32656@@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct
32657 free_irq(irq, hvcsd);
32658 kref_put(&hvcsd->kref, destroy_hvcs_struct);
32659 return;
32660- } else if (hvcsd->open_count < 0) {
32661+ } else if (local_read(&hvcsd->open_count) < 0) {
32662 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
32663 " is missmanaged.\n",
32664- hvcsd->vdev->unit_address, hvcsd->open_count);
32665+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
32666 }
32667
32668 spin_unlock_irqrestore(&hvcsd->lock, flags);
32669@@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struc
32670
32671 spin_lock_irqsave(&hvcsd->lock, flags);
32672 /* Preserve this so that we know how many kref refs to put */
32673- temp_open_count = hvcsd->open_count;
32674+ temp_open_count = local_read(&hvcsd->open_count);
32675
32676 /*
32677 * Don't kref put inside the spinlock because the destruction
32678@@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struc
32679 hvcsd->tty->driver_data = NULL;
32680 hvcsd->tty = NULL;
32681
32682- hvcsd->open_count = 0;
32683+ local_set(&hvcsd->open_count, 0);
32684
32685 /* This will drop any buffered data on the floor which is OK in a hangup
32686 * scenario. */
32687@@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct
32688 * the middle of a write operation? This is a crummy place to do this
32689 * but we want to keep it all in the spinlock.
32690 */
32691- if (hvcsd->open_count <= 0) {
32692+ if (local_read(&hvcsd->open_count) <= 0) {
32693 spin_unlock_irqrestore(&hvcsd->lock, flags);
32694 return -ENODEV;
32695 }
32696@@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_st
32697 {
32698 struct hvcs_struct *hvcsd = tty->driver_data;
32699
32700- if (!hvcsd || hvcsd->open_count <= 0)
32701+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
32702 return 0;
32703
32704 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
32705diff -urNp linux-3.0.4/drivers/tty/ipwireless/tty.c linux-3.0.4/drivers/tty/ipwireless/tty.c
32706--- linux-3.0.4/drivers/tty/ipwireless/tty.c 2011-07-21 22:17:23.000000000 -0400
32707+++ linux-3.0.4/drivers/tty/ipwireless/tty.c 2011-08-23 21:47:56.000000000 -0400
32708@@ -29,6 +29,7 @@
32709 #include <linux/tty_driver.h>
32710 #include <linux/tty_flip.h>
32711 #include <linux/uaccess.h>
32712+#include <asm/local.h>
32713
32714 #include "tty.h"
32715 #include "network.h"
32716@@ -51,7 +52,7 @@ struct ipw_tty {
32717 int tty_type;
32718 struct ipw_network *network;
32719 struct tty_struct *linux_tty;
32720- int open_count;
32721+ local_t open_count;
32722 unsigned int control_lines;
32723 struct mutex ipw_tty_mutex;
32724 int tx_bytes_queued;
32725@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
32726 mutex_unlock(&tty->ipw_tty_mutex);
32727 return -ENODEV;
32728 }
32729- if (tty->open_count == 0)
32730+ if (local_read(&tty->open_count) == 0)
32731 tty->tx_bytes_queued = 0;
32732
32733- tty->open_count++;
32734+ local_inc(&tty->open_count);
32735
32736 tty->linux_tty = linux_tty;
32737 linux_tty->driver_data = tty;
32738@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
32739
32740 static void do_ipw_close(struct ipw_tty *tty)
32741 {
32742- tty->open_count--;
32743-
32744- if (tty->open_count == 0) {
32745+ if (local_dec_return(&tty->open_count) == 0) {
32746 struct tty_struct *linux_tty = tty->linux_tty;
32747
32748 if (linux_tty != NULL) {
32749@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
32750 return;
32751
32752 mutex_lock(&tty->ipw_tty_mutex);
32753- if (tty->open_count == 0) {
32754+ if (local_read(&tty->open_count) == 0) {
32755 mutex_unlock(&tty->ipw_tty_mutex);
32756 return;
32757 }
32758@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
32759 return;
32760 }
32761
32762- if (!tty->open_count) {
32763+ if (!local_read(&tty->open_count)) {
32764 mutex_unlock(&tty->ipw_tty_mutex);
32765 return;
32766 }
32767@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
32768 return -ENODEV;
32769
32770 mutex_lock(&tty->ipw_tty_mutex);
32771- if (!tty->open_count) {
32772+ if (!local_read(&tty->open_count)) {
32773 mutex_unlock(&tty->ipw_tty_mutex);
32774 return -EINVAL;
32775 }
32776@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
32777 if (!tty)
32778 return -ENODEV;
32779
32780- if (!tty->open_count)
32781+ if (!local_read(&tty->open_count))
32782 return -EINVAL;
32783
32784 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
32785@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
32786 if (!tty)
32787 return 0;
32788
32789- if (!tty->open_count)
32790+ if (!local_read(&tty->open_count))
32791 return 0;
32792
32793 return tty->tx_bytes_queued;
32794@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
32795 if (!tty)
32796 return -ENODEV;
32797
32798- if (!tty->open_count)
32799+ if (!local_read(&tty->open_count))
32800 return -EINVAL;
32801
32802 return get_control_lines(tty);
32803@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
32804 if (!tty)
32805 return -ENODEV;
32806
32807- if (!tty->open_count)
32808+ if (!local_read(&tty->open_count))
32809 return -EINVAL;
32810
32811 return set_control_lines(tty, set, clear);
32812@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
32813 if (!tty)
32814 return -ENODEV;
32815
32816- if (!tty->open_count)
32817+ if (!local_read(&tty->open_count))
32818 return -EINVAL;
32819
32820 /* FIXME: Exactly how is the tty object locked here .. */
32821@@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty
32822 against a parallel ioctl etc */
32823 mutex_lock(&ttyj->ipw_tty_mutex);
32824 }
32825- while (ttyj->open_count)
32826+ while (local_read(&ttyj->open_count))
32827 do_ipw_close(ttyj);
32828 ipwireless_disassociate_network_ttys(network,
32829 ttyj->channel_idx);
32830diff -urNp linux-3.0.4/drivers/tty/n_gsm.c linux-3.0.4/drivers/tty/n_gsm.c
32831--- linux-3.0.4/drivers/tty/n_gsm.c 2011-08-23 21:44:40.000000000 -0400
32832+++ linux-3.0.4/drivers/tty/n_gsm.c 2011-08-23 21:47:56.000000000 -0400
32833@@ -1589,7 +1589,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
32834 return NULL;
32835 spin_lock_init(&dlci->lock);
32836 dlci->fifo = &dlci->_fifo;
32837- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
32838+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
32839 kfree(dlci);
32840 return NULL;
32841 }
32842diff -urNp linux-3.0.4/drivers/tty/n_tty.c linux-3.0.4/drivers/tty/n_tty.c
32843--- linux-3.0.4/drivers/tty/n_tty.c 2011-07-21 22:17:23.000000000 -0400
32844+++ linux-3.0.4/drivers/tty/n_tty.c 2011-08-23 21:47:56.000000000 -0400
32845@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
32846 {
32847 *ops = tty_ldisc_N_TTY;
32848 ops->owner = NULL;
32849- ops->refcount = ops->flags = 0;
32850+ atomic_set(&ops->refcount, 0);
32851+ ops->flags = 0;
32852 }
32853 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
32854diff -urNp linux-3.0.4/drivers/tty/pty.c linux-3.0.4/drivers/tty/pty.c
32855--- linux-3.0.4/drivers/tty/pty.c 2011-07-21 22:17:23.000000000 -0400
32856+++ linux-3.0.4/drivers/tty/pty.c 2011-08-23 21:47:56.000000000 -0400
32857@@ -754,8 +754,10 @@ static void __init unix98_pty_init(void)
32858 register_sysctl_table(pty_root_table);
32859
32860 /* Now create the /dev/ptmx special device */
32861+ pax_open_kernel();
32862 tty_default_fops(&ptmx_fops);
32863- ptmx_fops.open = ptmx_open;
32864+ *(void **)&ptmx_fops.open = ptmx_open;
32865+ pax_close_kernel();
32866
32867 cdev_init(&ptmx_cdev, &ptmx_fops);
32868 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
32869diff -urNp linux-3.0.4/drivers/tty/rocket.c linux-3.0.4/drivers/tty/rocket.c
32870--- linux-3.0.4/drivers/tty/rocket.c 2011-07-21 22:17:23.000000000 -0400
32871+++ linux-3.0.4/drivers/tty/rocket.c 2011-08-23 21:48:14.000000000 -0400
32872@@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info
32873 struct rocket_ports tmp;
32874 int board;
32875
32876+ pax_track_stack();
32877+
32878 if (!retports)
32879 return -EFAULT;
32880 memset(&tmp, 0, sizeof (tmp));
32881diff -urNp linux-3.0.4/drivers/tty/serial/kgdboc.c linux-3.0.4/drivers/tty/serial/kgdboc.c
32882--- linux-3.0.4/drivers/tty/serial/kgdboc.c 2011-07-21 22:17:23.000000000 -0400
32883+++ linux-3.0.4/drivers/tty/serial/kgdboc.c 2011-08-23 21:47:56.000000000 -0400
32884@@ -23,8 +23,9 @@
32885 #define MAX_CONFIG_LEN 40
32886
32887 static struct kgdb_io kgdboc_io_ops;
32888+static struct kgdb_io kgdboc_io_ops_console;
32889
32890-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
32891+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
32892 static int configured = -1;
32893
32894 static char config[MAX_CONFIG_LEN];
32895@@ -147,6 +148,8 @@ static void cleanup_kgdboc(void)
32896 kgdboc_unregister_kbd();
32897 if (configured == 1)
32898 kgdb_unregister_io_module(&kgdboc_io_ops);
32899+ else if (configured == 2)
32900+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
32901 }
32902
32903 static int configure_kgdboc(void)
32904@@ -156,13 +159,13 @@ static int configure_kgdboc(void)
32905 int err;
32906 char *cptr = config;
32907 struct console *cons;
32908+ int is_console = 0;
32909
32910 err = kgdboc_option_setup(config);
32911 if (err || !strlen(config) || isspace(config[0]))
32912 goto noconfig;
32913
32914 err = -ENODEV;
32915- kgdboc_io_ops.is_console = 0;
32916 kgdb_tty_driver = NULL;
32917
32918 kgdboc_use_kms = 0;
32919@@ -183,7 +186,7 @@ static int configure_kgdboc(void)
32920 int idx;
32921 if (cons->device && cons->device(cons, &idx) == p &&
32922 idx == tty_line) {
32923- kgdboc_io_ops.is_console = 1;
32924+ is_console = 1;
32925 break;
32926 }
32927 cons = cons->next;
32928@@ -193,12 +196,16 @@ static int configure_kgdboc(void)
32929 kgdb_tty_line = tty_line;
32930
32931 do_register:
32932- err = kgdb_register_io_module(&kgdboc_io_ops);
32933+ if (is_console) {
32934+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
32935+ configured = 2;
32936+ } else {
32937+ err = kgdb_register_io_module(&kgdboc_io_ops);
32938+ configured = 1;
32939+ }
32940 if (err)
32941 goto noconfig;
32942
32943- configured = 1;
32944-
32945 return 0;
32946
32947 noconfig:
32948@@ -212,7 +219,7 @@ noconfig:
32949 static int __init init_kgdboc(void)
32950 {
32951 /* Already configured? */
32952- if (configured == 1)
32953+ if (configured >= 1)
32954 return 0;
32955
32956 return configure_kgdboc();
32957@@ -261,7 +268,7 @@ static int param_set_kgdboc_var(const ch
32958 if (config[len - 1] == '\n')
32959 config[len - 1] = '\0';
32960
32961- if (configured == 1)
32962+ if (configured >= 1)
32963 cleanup_kgdboc();
32964
32965 /* Go and configure with the new params. */
32966@@ -301,6 +308,15 @@ static struct kgdb_io kgdboc_io_ops = {
32967 .post_exception = kgdboc_post_exp_handler,
32968 };
32969
32970+static struct kgdb_io kgdboc_io_ops_console = {
32971+ .name = "kgdboc",
32972+ .read_char = kgdboc_get_char,
32973+ .write_char = kgdboc_put_char,
32974+ .pre_exception = kgdboc_pre_exp_handler,
32975+ .post_exception = kgdboc_post_exp_handler,
32976+ .is_console = 1
32977+};
32978+
32979 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
32980 /* This is only available if kgdboc is a built in for early debugging */
32981 static int __init kgdboc_early_init(char *opt)
32982diff -urNp linux-3.0.4/drivers/tty/serial/mrst_max3110.c linux-3.0.4/drivers/tty/serial/mrst_max3110.c
32983--- linux-3.0.4/drivers/tty/serial/mrst_max3110.c 2011-07-21 22:17:23.000000000 -0400
32984+++ linux-3.0.4/drivers/tty/serial/mrst_max3110.c 2011-08-23 21:48:14.000000000 -0400
32985@@ -393,6 +393,8 @@ static void max3110_con_receive(struct u
32986 int loop = 1, num, total = 0;
32987 u8 recv_buf[512], *pbuf;
32988
32989+ pax_track_stack();
32990+
32991 pbuf = recv_buf;
32992 do {
32993 num = max3110_read_multi(max, pbuf);
32994diff -urNp linux-3.0.4/drivers/tty/tty_io.c linux-3.0.4/drivers/tty/tty_io.c
32995--- linux-3.0.4/drivers/tty/tty_io.c 2011-07-21 22:17:23.000000000 -0400
32996+++ linux-3.0.4/drivers/tty/tty_io.c 2011-08-23 21:47:56.000000000 -0400
32997@@ -3215,7 +3215,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
32998
32999 void tty_default_fops(struct file_operations *fops)
33000 {
33001- *fops = tty_fops;
33002+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
33003 }
33004
33005 /*
33006diff -urNp linux-3.0.4/drivers/tty/tty_ldisc.c linux-3.0.4/drivers/tty/tty_ldisc.c
33007--- linux-3.0.4/drivers/tty/tty_ldisc.c 2011-07-21 22:17:23.000000000 -0400
33008+++ linux-3.0.4/drivers/tty/tty_ldisc.c 2011-08-23 21:47:56.000000000 -0400
33009@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
33010 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
33011 struct tty_ldisc_ops *ldo = ld->ops;
33012
33013- ldo->refcount--;
33014+ atomic_dec(&ldo->refcount);
33015 module_put(ldo->owner);
33016 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
33017
33018@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
33019 spin_lock_irqsave(&tty_ldisc_lock, flags);
33020 tty_ldiscs[disc] = new_ldisc;
33021 new_ldisc->num = disc;
33022- new_ldisc->refcount = 0;
33023+ atomic_set(&new_ldisc->refcount, 0);
33024 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
33025
33026 return ret;
33027@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
33028 return -EINVAL;
33029
33030 spin_lock_irqsave(&tty_ldisc_lock, flags);
33031- if (tty_ldiscs[disc]->refcount)
33032+ if (atomic_read(&tty_ldiscs[disc]->refcount))
33033 ret = -EBUSY;
33034 else
33035 tty_ldiscs[disc] = NULL;
33036@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
33037 if (ldops) {
33038 ret = ERR_PTR(-EAGAIN);
33039 if (try_module_get(ldops->owner)) {
33040- ldops->refcount++;
33041+ atomic_inc(&ldops->refcount);
33042 ret = ldops;
33043 }
33044 }
33045@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
33046 unsigned long flags;
33047
33048 spin_lock_irqsave(&tty_ldisc_lock, flags);
33049- ldops->refcount--;
33050+ atomic_dec(&ldops->refcount);
33051 module_put(ldops->owner);
33052 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
33053 }
33054diff -urNp linux-3.0.4/drivers/tty/vt/keyboard.c linux-3.0.4/drivers/tty/vt/keyboard.c
33055--- linux-3.0.4/drivers/tty/vt/keyboard.c 2011-07-21 22:17:23.000000000 -0400
33056+++ linux-3.0.4/drivers/tty/vt/keyboard.c 2011-08-23 21:48:14.000000000 -0400
33057@@ -656,6 +656,16 @@ static void k_spec(struct vc_data *vc, u
33058 kbd->kbdmode == VC_OFF) &&
33059 value != KVAL(K_SAK))
33060 return; /* SAK is allowed even in raw mode */
33061+
33062+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33063+ {
33064+ void *func = fn_handler[value];
33065+ if (func == fn_show_state || func == fn_show_ptregs ||
33066+ func == fn_show_mem)
33067+ return;
33068+ }
33069+#endif
33070+
33071 fn_handler[value](vc);
33072 }
33073
33074diff -urNp linux-3.0.4/drivers/tty/vt/vt.c linux-3.0.4/drivers/tty/vt/vt.c
33075--- linux-3.0.4/drivers/tty/vt/vt.c 2011-07-21 22:17:23.000000000 -0400
33076+++ linux-3.0.4/drivers/tty/vt/vt.c 2011-08-23 21:47:56.000000000 -0400
33077@@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
33078
33079 static void notify_write(struct vc_data *vc, unsigned int unicode)
33080 {
33081- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
33082+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
33083 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
33084 }
33085
33086diff -urNp linux-3.0.4/drivers/tty/vt/vt_ioctl.c linux-3.0.4/drivers/tty/vt/vt_ioctl.c
33087--- linux-3.0.4/drivers/tty/vt/vt_ioctl.c 2011-07-21 22:17:23.000000000 -0400
33088+++ linux-3.0.4/drivers/tty/vt/vt_ioctl.c 2011-08-23 21:48:14.000000000 -0400
33089@@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
33090 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
33091 return -EFAULT;
33092
33093- if (!capable(CAP_SYS_TTY_CONFIG))
33094- perm = 0;
33095-
33096 switch (cmd) {
33097 case KDGKBENT:
33098 key_map = key_maps[s];
33099@@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
33100 val = (i ? K_HOLE : K_NOSUCHMAP);
33101 return put_user(val, &user_kbe->kb_value);
33102 case KDSKBENT:
33103+ if (!capable(CAP_SYS_TTY_CONFIG))
33104+ perm = 0;
33105+
33106 if (!perm)
33107 return -EPERM;
33108 if (!i && v == K_NOSUCHMAP) {
33109@@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
33110 int i, j, k;
33111 int ret;
33112
33113- if (!capable(CAP_SYS_TTY_CONFIG))
33114- perm = 0;
33115-
33116 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
33117 if (!kbs) {
33118 ret = -ENOMEM;
33119@@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
33120 kfree(kbs);
33121 return ((p && *p) ? -EOVERFLOW : 0);
33122 case KDSKBSENT:
33123+ if (!capable(CAP_SYS_TTY_CONFIG))
33124+ perm = 0;
33125+
33126 if (!perm) {
33127 ret = -EPERM;
33128 goto reterr;
33129diff -urNp linux-3.0.4/drivers/uio/uio.c linux-3.0.4/drivers/uio/uio.c
33130--- linux-3.0.4/drivers/uio/uio.c 2011-07-21 22:17:23.000000000 -0400
33131+++ linux-3.0.4/drivers/uio/uio.c 2011-08-23 21:47:56.000000000 -0400
33132@@ -25,6 +25,7 @@
33133 #include <linux/kobject.h>
33134 #include <linux/cdev.h>
33135 #include <linux/uio_driver.h>
33136+#include <asm/local.h>
33137
33138 #define UIO_MAX_DEVICES (1U << MINORBITS)
33139
33140@@ -32,10 +33,10 @@ struct uio_device {
33141 struct module *owner;
33142 struct device *dev;
33143 int minor;
33144- atomic_t event;
33145+ atomic_unchecked_t event;
33146 struct fasync_struct *async_queue;
33147 wait_queue_head_t wait;
33148- int vma_count;
33149+ local_t vma_count;
33150 struct uio_info *info;
33151 struct kobject *map_dir;
33152 struct kobject *portio_dir;
33153@@ -242,7 +243,7 @@ static ssize_t show_event(struct device
33154 struct device_attribute *attr, char *buf)
33155 {
33156 struct uio_device *idev = dev_get_drvdata(dev);
33157- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
33158+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
33159 }
33160
33161 static struct device_attribute uio_class_attributes[] = {
33162@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *i
33163 {
33164 struct uio_device *idev = info->uio_dev;
33165
33166- atomic_inc(&idev->event);
33167+ atomic_inc_unchecked(&idev->event);
33168 wake_up_interruptible(&idev->wait);
33169 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
33170 }
33171@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode,
33172 }
33173
33174 listener->dev = idev;
33175- listener->event_count = atomic_read(&idev->event);
33176+ listener->event_count = atomic_read_unchecked(&idev->event);
33177 filep->private_data = listener;
33178
33179 if (idev->info->open) {
33180@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file
33181 return -EIO;
33182
33183 poll_wait(filep, &idev->wait, wait);
33184- if (listener->event_count != atomic_read(&idev->event))
33185+ if (listener->event_count != atomic_read_unchecked(&idev->event))
33186 return POLLIN | POLLRDNORM;
33187 return 0;
33188 }
33189@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *fil
33190 do {
33191 set_current_state(TASK_INTERRUPTIBLE);
33192
33193- event_count = atomic_read(&idev->event);
33194+ event_count = atomic_read_unchecked(&idev->event);
33195 if (event_count != listener->event_count) {
33196 if (copy_to_user(buf, &event_count, count))
33197 retval = -EFAULT;
33198@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_
33199 static void uio_vma_open(struct vm_area_struct *vma)
33200 {
33201 struct uio_device *idev = vma->vm_private_data;
33202- idev->vma_count++;
33203+ local_inc(&idev->vma_count);
33204 }
33205
33206 static void uio_vma_close(struct vm_area_struct *vma)
33207 {
33208 struct uio_device *idev = vma->vm_private_data;
33209- idev->vma_count--;
33210+ local_dec(&idev->vma_count);
33211 }
33212
33213 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33214@@ -823,7 +824,7 @@ int __uio_register_device(struct module
33215 idev->owner = owner;
33216 idev->info = info;
33217 init_waitqueue_head(&idev->wait);
33218- atomic_set(&idev->event, 0);
33219+ atomic_set_unchecked(&idev->event, 0);
33220
33221 ret = uio_get_minor(idev);
33222 if (ret)
33223diff -urNp linux-3.0.4/drivers/usb/atm/cxacru.c linux-3.0.4/drivers/usb/atm/cxacru.c
33224--- linux-3.0.4/drivers/usb/atm/cxacru.c 2011-07-21 22:17:23.000000000 -0400
33225+++ linux-3.0.4/drivers/usb/atm/cxacru.c 2011-08-23 21:47:56.000000000 -0400
33226@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
33227 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
33228 if (ret < 2)
33229 return -EINVAL;
33230- if (index < 0 || index > 0x7f)
33231+ if (index > 0x7f)
33232 return -EINVAL;
33233 pos += tmp;
33234
33235diff -urNp linux-3.0.4/drivers/usb/atm/usbatm.c linux-3.0.4/drivers/usb/atm/usbatm.c
33236--- linux-3.0.4/drivers/usb/atm/usbatm.c 2011-07-21 22:17:23.000000000 -0400
33237+++ linux-3.0.4/drivers/usb/atm/usbatm.c 2011-08-23 21:47:56.000000000 -0400
33238@@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
33239 if (printk_ratelimit())
33240 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
33241 __func__, vpi, vci);
33242- atomic_inc(&vcc->stats->rx_err);
33243+ atomic_inc_unchecked(&vcc->stats->rx_err);
33244 return;
33245 }
33246
33247@@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
33248 if (length > ATM_MAX_AAL5_PDU) {
33249 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
33250 __func__, length, vcc);
33251- atomic_inc(&vcc->stats->rx_err);
33252+ atomic_inc_unchecked(&vcc->stats->rx_err);
33253 goto out;
33254 }
33255
33256@@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
33257 if (sarb->len < pdu_length) {
33258 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
33259 __func__, pdu_length, sarb->len, vcc);
33260- atomic_inc(&vcc->stats->rx_err);
33261+ atomic_inc_unchecked(&vcc->stats->rx_err);
33262 goto out;
33263 }
33264
33265 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
33266 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
33267 __func__, vcc);
33268- atomic_inc(&vcc->stats->rx_err);
33269+ atomic_inc_unchecked(&vcc->stats->rx_err);
33270 goto out;
33271 }
33272
33273@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
33274 if (printk_ratelimit())
33275 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
33276 __func__, length);
33277- atomic_inc(&vcc->stats->rx_drop);
33278+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33279 goto out;
33280 }
33281
33282@@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
33283
33284 vcc->push(vcc, skb);
33285
33286- atomic_inc(&vcc->stats->rx);
33287+ atomic_inc_unchecked(&vcc->stats->rx);
33288 out:
33289 skb_trim(sarb, 0);
33290 }
33291@@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
33292 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
33293
33294 usbatm_pop(vcc, skb);
33295- atomic_inc(&vcc->stats->tx);
33296+ atomic_inc_unchecked(&vcc->stats->tx);
33297
33298 skb = skb_dequeue(&instance->sndqueue);
33299 }
33300@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
33301 if (!left--)
33302 return sprintf(page,
33303 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
33304- atomic_read(&atm_dev->stats.aal5.tx),
33305- atomic_read(&atm_dev->stats.aal5.tx_err),
33306- atomic_read(&atm_dev->stats.aal5.rx),
33307- atomic_read(&atm_dev->stats.aal5.rx_err),
33308- atomic_read(&atm_dev->stats.aal5.rx_drop));
33309+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
33310+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
33311+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
33312+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
33313+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
33314
33315 if (!left--) {
33316 if (instance->disconnected)
33317diff -urNp linux-3.0.4/drivers/usb/core/devices.c linux-3.0.4/drivers/usb/core/devices.c
33318--- linux-3.0.4/drivers/usb/core/devices.c 2011-07-21 22:17:23.000000000 -0400
33319+++ linux-3.0.4/drivers/usb/core/devices.c 2011-08-23 21:47:56.000000000 -0400
33320@@ -126,7 +126,7 @@ static const char format_endpt[] =
33321 * time it gets called.
33322 */
33323 static struct device_connect_event {
33324- atomic_t count;
33325+ atomic_unchecked_t count;
33326 wait_queue_head_t wait;
33327 } device_event = {
33328 .count = ATOMIC_INIT(1),
33329@@ -164,7 +164,7 @@ static const struct class_info clas_info
33330
33331 void usbfs_conn_disc_event(void)
33332 {
33333- atomic_add(2, &device_event.count);
33334+ atomic_add_unchecked(2, &device_event.count);
33335 wake_up(&device_event.wait);
33336 }
33337
33338@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(stru
33339
33340 poll_wait(file, &device_event.wait, wait);
33341
33342- event_count = atomic_read(&device_event.count);
33343+ event_count = atomic_read_unchecked(&device_event.count);
33344 if (file->f_version != event_count) {
33345 file->f_version = event_count;
33346 return POLLIN | POLLRDNORM;
33347diff -urNp linux-3.0.4/drivers/usb/core/message.c linux-3.0.4/drivers/usb/core/message.c
33348--- linux-3.0.4/drivers/usb/core/message.c 2011-07-21 22:17:23.000000000 -0400
33349+++ linux-3.0.4/drivers/usb/core/message.c 2011-08-23 21:47:56.000000000 -0400
33350@@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
33351 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
33352 if (buf) {
33353 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
33354- if (len > 0) {
33355- smallbuf = kmalloc(++len, GFP_NOIO);
33356+ if (len++ > 0) {
33357+ smallbuf = kmalloc(len, GFP_NOIO);
33358 if (!smallbuf)
33359 return buf;
33360 memcpy(smallbuf, buf, len);
33361diff -urNp linux-3.0.4/drivers/usb/early/ehci-dbgp.c linux-3.0.4/drivers/usb/early/ehci-dbgp.c
33362--- linux-3.0.4/drivers/usb/early/ehci-dbgp.c 2011-07-21 22:17:23.000000000 -0400
33363+++ linux-3.0.4/drivers/usb/early/ehci-dbgp.c 2011-08-23 21:47:56.000000000 -0400
33364@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x,
33365
33366 #ifdef CONFIG_KGDB
33367 static struct kgdb_io kgdbdbgp_io_ops;
33368-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
33369+static struct kgdb_io kgdbdbgp_io_ops_console;
33370+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
33371 #else
33372 #define dbgp_kgdb_mode (0)
33373 #endif
33374@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops =
33375 .write_char = kgdbdbgp_write_char,
33376 };
33377
33378+static struct kgdb_io kgdbdbgp_io_ops_console = {
33379+ .name = "kgdbdbgp",
33380+ .read_char = kgdbdbgp_read_char,
33381+ .write_char = kgdbdbgp_write_char,
33382+ .is_console = 1
33383+};
33384+
33385 static int kgdbdbgp_wait_time;
33386
33387 static int __init kgdbdbgp_parse_config(char *str)
33388@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(
33389 ptr++;
33390 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
33391 }
33392- kgdb_register_io_module(&kgdbdbgp_io_ops);
33393- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
33394+ if (early_dbgp_console.index != -1)
33395+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
33396+ else
33397+ kgdb_register_io_module(&kgdbdbgp_io_ops);
33398
33399 return 0;
33400 }
33401diff -urNp linux-3.0.4/drivers/usb/host/xhci-mem.c linux-3.0.4/drivers/usb/host/xhci-mem.c
33402--- linux-3.0.4/drivers/usb/host/xhci-mem.c 2011-07-21 22:17:23.000000000 -0400
33403+++ linux-3.0.4/drivers/usb/host/xhci-mem.c 2011-08-23 21:48:14.000000000 -0400
33404@@ -1685,6 +1685,8 @@ static int xhci_check_trb_in_td_math(str
33405 unsigned int num_tests;
33406 int i, ret;
33407
33408+ pax_track_stack();
33409+
33410 num_tests = ARRAY_SIZE(simple_test_vector);
33411 for (i = 0; i < num_tests; i++) {
33412 ret = xhci_test_trb_in_td(xhci,
33413diff -urNp linux-3.0.4/drivers/usb/wusbcore/wa-hc.h linux-3.0.4/drivers/usb/wusbcore/wa-hc.h
33414--- linux-3.0.4/drivers/usb/wusbcore/wa-hc.h 2011-07-21 22:17:23.000000000 -0400
33415+++ linux-3.0.4/drivers/usb/wusbcore/wa-hc.h 2011-08-23 21:47:56.000000000 -0400
33416@@ -192,7 +192,7 @@ struct wahc {
33417 struct list_head xfer_delayed_list;
33418 spinlock_t xfer_list_lock;
33419 struct work_struct xfer_work;
33420- atomic_t xfer_id_count;
33421+ atomic_unchecked_t xfer_id_count;
33422 };
33423
33424
33425@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
33426 INIT_LIST_HEAD(&wa->xfer_delayed_list);
33427 spin_lock_init(&wa->xfer_list_lock);
33428 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
33429- atomic_set(&wa->xfer_id_count, 1);
33430+ atomic_set_unchecked(&wa->xfer_id_count, 1);
33431 }
33432
33433 /**
33434diff -urNp linux-3.0.4/drivers/usb/wusbcore/wa-xfer.c linux-3.0.4/drivers/usb/wusbcore/wa-xfer.c
33435--- linux-3.0.4/drivers/usb/wusbcore/wa-xfer.c 2011-07-21 22:17:23.000000000 -0400
33436+++ linux-3.0.4/drivers/usb/wusbcore/wa-xfer.c 2011-08-23 21:47:56.000000000 -0400
33437@@ -294,7 +294,7 @@ out:
33438 */
33439 static void wa_xfer_id_init(struct wa_xfer *xfer)
33440 {
33441- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
33442+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
33443 }
33444
33445 /*
33446diff -urNp linux-3.0.4/drivers/vhost/vhost.c linux-3.0.4/drivers/vhost/vhost.c
33447--- linux-3.0.4/drivers/vhost/vhost.c 2011-07-21 22:17:23.000000000 -0400
33448+++ linux-3.0.4/drivers/vhost/vhost.c 2011-08-23 21:47:56.000000000 -0400
33449@@ -589,7 +589,7 @@ static int init_used(struct vhost_virtqu
33450 return get_user(vq->last_used_idx, &used->idx);
33451 }
33452
33453-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
33454+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
33455 {
33456 struct file *eventfp, *filep = NULL,
33457 *pollstart = NULL, *pollstop = NULL;
33458diff -urNp linux-3.0.4/drivers/video/fbcmap.c linux-3.0.4/drivers/video/fbcmap.c
33459--- linux-3.0.4/drivers/video/fbcmap.c 2011-07-21 22:17:23.000000000 -0400
33460+++ linux-3.0.4/drivers/video/fbcmap.c 2011-08-23 21:47:56.000000000 -0400
33461@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
33462 rc = -ENODEV;
33463 goto out;
33464 }
33465- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
33466- !info->fbops->fb_setcmap)) {
33467+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
33468 rc = -EINVAL;
33469 goto out1;
33470 }
33471diff -urNp linux-3.0.4/drivers/video/fbmem.c linux-3.0.4/drivers/video/fbmem.c
33472--- linux-3.0.4/drivers/video/fbmem.c 2011-07-21 22:17:23.000000000 -0400
33473+++ linux-3.0.4/drivers/video/fbmem.c 2011-08-23 21:48:14.000000000 -0400
33474@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_in
33475 image->dx += image->width + 8;
33476 }
33477 } else if (rotate == FB_ROTATE_UD) {
33478- for (x = 0; x < num && image->dx >= 0; x++) {
33479+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
33480 info->fbops->fb_imageblit(info, image);
33481 image->dx -= image->width + 8;
33482 }
33483@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_in
33484 image->dy += image->height + 8;
33485 }
33486 } else if (rotate == FB_ROTATE_CCW) {
33487- for (x = 0; x < num && image->dy >= 0; x++) {
33488+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
33489 info->fbops->fb_imageblit(info, image);
33490 image->dy -= image->height + 8;
33491 }
33492@@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct
33493 int flags = info->flags;
33494 int ret = 0;
33495
33496+ pax_track_stack();
33497+
33498 if (var->activate & FB_ACTIVATE_INV_MODE) {
33499 struct fb_videomode mode1, mode2;
33500
33501@@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *
33502 void __user *argp = (void __user *)arg;
33503 long ret = 0;
33504
33505+ pax_track_stack();
33506+
33507 switch (cmd) {
33508 case FBIOGET_VSCREENINFO:
33509 if (!lock_fb_info(info))
33510@@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *
33511 return -EFAULT;
33512 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
33513 return -EINVAL;
33514- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
33515+ if (con2fb.framebuffer >= FB_MAX)
33516 return -EINVAL;
33517 if (!registered_fb[con2fb.framebuffer])
33518 request_module("fb%d", con2fb.framebuffer);
33519diff -urNp linux-3.0.4/drivers/video/i810/i810_accel.c linux-3.0.4/drivers/video/i810/i810_accel.c
33520--- linux-3.0.4/drivers/video/i810/i810_accel.c 2011-07-21 22:17:23.000000000 -0400
33521+++ linux-3.0.4/drivers/video/i810/i810_accel.c 2011-08-23 21:47:56.000000000 -0400
33522@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
33523 }
33524 }
33525 printk("ringbuffer lockup!!!\n");
33526+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
33527 i810_report_error(mmio);
33528 par->dev_flags |= LOCKUP;
33529 info->pixmap.scan_align = 1;
33530diff -urNp linux-3.0.4/drivers/video/logo/logo_linux_clut224.ppm linux-3.0.4/drivers/video/logo/logo_linux_clut224.ppm
33531--- linux-3.0.4/drivers/video/logo/logo_linux_clut224.ppm 2011-07-21 22:17:23.000000000 -0400
33532+++ linux-3.0.4/drivers/video/logo/logo_linux_clut224.ppm 2011-08-29 23:49:40.000000000 -0400
33533@@ -1,1604 +1,1123 @@
33534 P3
33535-# Standard 224-color Linux logo
33536 80 80
33537 255
33538- 0 0 0 0 0 0 0 0 0 0 0 0
33539- 0 0 0 0 0 0 0 0 0 0 0 0
33540- 0 0 0 0 0 0 0 0 0 0 0 0
33541- 0 0 0 0 0 0 0 0 0 0 0 0
33542- 0 0 0 0 0 0 0 0 0 0 0 0
33543- 0 0 0 0 0 0 0 0 0 0 0 0
33544- 0 0 0 0 0 0 0 0 0 0 0 0
33545- 0 0 0 0 0 0 0 0 0 0 0 0
33546- 0 0 0 0 0 0 0 0 0 0 0 0
33547- 6 6 6 6 6 6 10 10 10 10 10 10
33548- 10 10 10 6 6 6 6 6 6 6 6 6
33549- 0 0 0 0 0 0 0 0 0 0 0 0
33550- 0 0 0 0 0 0 0 0 0 0 0 0
33551- 0 0 0 0 0 0 0 0 0 0 0 0
33552- 0 0 0 0 0 0 0 0 0 0 0 0
33553- 0 0 0 0 0 0 0 0 0 0 0 0
33554- 0 0 0 0 0 0 0 0 0 0 0 0
33555- 0 0 0 0 0 0 0 0 0 0 0 0
33556- 0 0 0 0 0 0 0 0 0 0 0 0
33557- 0 0 0 0 0 0 0 0 0 0 0 0
33558- 0 0 0 0 0 0 0 0 0 0 0 0
33559- 0 0 0 0 0 0 0 0 0 0 0 0
33560- 0 0 0 0 0 0 0 0 0 0 0 0
33561- 0 0 0 0 0 0 0 0 0 0 0 0
33562- 0 0 0 0 0 0 0 0 0 0 0 0
33563- 0 0 0 0 0 0 0 0 0 0 0 0
33564- 0 0 0 0 0 0 0 0 0 0 0 0
33565- 0 0 0 0 0 0 0 0 0 0 0 0
33566- 0 0 0 6 6 6 10 10 10 14 14 14
33567- 22 22 22 26 26 26 30 30 30 34 34 34
33568- 30 30 30 30 30 30 26 26 26 18 18 18
33569- 14 14 14 10 10 10 6 6 6 0 0 0
33570- 0 0 0 0 0 0 0 0 0 0 0 0
33571- 0 0 0 0 0 0 0 0 0 0 0 0
33572- 0 0 0 0 0 0 0 0 0 0 0 0
33573- 0 0 0 0 0 0 0 0 0 0 0 0
33574- 0 0 0 0 0 0 0 0 0 0 0 0
33575- 0 0 0 0 0 0 0 0 0 0 0 0
33576- 0 0 0 0 0 0 0 0 0 0 0 0
33577- 0 0 0 0 0 0 0 0 0 0 0 0
33578- 0 0 0 0 0 0 0 0 0 0 0 0
33579- 0 0 0 0 0 1 0 0 1 0 0 0
33580- 0 0 0 0 0 0 0 0 0 0 0 0
33581- 0 0 0 0 0 0 0 0 0 0 0 0
33582- 0 0 0 0 0 0 0 0 0 0 0 0
33583- 0 0 0 0 0 0 0 0 0 0 0 0
33584- 0 0 0 0 0 0 0 0 0 0 0 0
33585- 0 0 0 0 0 0 0 0 0 0 0 0
33586- 6 6 6 14 14 14 26 26 26 42 42 42
33587- 54 54 54 66 66 66 78 78 78 78 78 78
33588- 78 78 78 74 74 74 66 66 66 54 54 54
33589- 42 42 42 26 26 26 18 18 18 10 10 10
33590- 6 6 6 0 0 0 0 0 0 0 0 0
33591- 0 0 0 0 0 0 0 0 0 0 0 0
33592- 0 0 0 0 0 0 0 0 0 0 0 0
33593- 0 0 0 0 0 0 0 0 0 0 0 0
33594- 0 0 0 0 0 0 0 0 0 0 0 0
33595- 0 0 0 0 0 0 0 0 0 0 0 0
33596- 0 0 0 0 0 0 0 0 0 0 0 0
33597- 0 0 0 0 0 0 0 0 0 0 0 0
33598- 0 0 0 0 0 0 0 0 0 0 0 0
33599- 0 0 1 0 0 0 0 0 0 0 0 0
33600- 0 0 0 0 0 0 0 0 0 0 0 0
33601- 0 0 0 0 0 0 0 0 0 0 0 0
33602- 0 0 0 0 0 0 0 0 0 0 0 0
33603- 0 0 0 0 0 0 0 0 0 0 0 0
33604- 0 0 0 0 0 0 0 0 0 0 0 0
33605- 0 0 0 0 0 0 0 0 0 10 10 10
33606- 22 22 22 42 42 42 66 66 66 86 86 86
33607- 66 66 66 38 38 38 38 38 38 22 22 22
33608- 26 26 26 34 34 34 54 54 54 66 66 66
33609- 86 86 86 70 70 70 46 46 46 26 26 26
33610- 14 14 14 6 6 6 0 0 0 0 0 0
33611- 0 0 0 0 0 0 0 0 0 0 0 0
33612- 0 0 0 0 0 0 0 0 0 0 0 0
33613- 0 0 0 0 0 0 0 0 0 0 0 0
33614- 0 0 0 0 0 0 0 0 0 0 0 0
33615- 0 0 0 0 0 0 0 0 0 0 0 0
33616- 0 0 0 0 0 0 0 0 0 0 0 0
33617- 0 0 0 0 0 0 0 0 0 0 0 0
33618- 0 0 0 0 0 0 0 0 0 0 0 0
33619- 0 0 1 0 0 1 0 0 1 0 0 0
33620- 0 0 0 0 0 0 0 0 0 0 0 0
33621- 0 0 0 0 0 0 0 0 0 0 0 0
33622- 0 0 0 0 0 0 0 0 0 0 0 0
33623- 0 0 0 0 0 0 0 0 0 0 0 0
33624- 0 0 0 0 0 0 0 0 0 0 0 0
33625- 0 0 0 0 0 0 10 10 10 26 26 26
33626- 50 50 50 82 82 82 58 58 58 6 6 6
33627- 2 2 6 2 2 6 2 2 6 2 2 6
33628- 2 2 6 2 2 6 2 2 6 2 2 6
33629- 6 6 6 54 54 54 86 86 86 66 66 66
33630- 38 38 38 18 18 18 6 6 6 0 0 0
33631- 0 0 0 0 0 0 0 0 0 0 0 0
33632- 0 0 0 0 0 0 0 0 0 0 0 0
33633- 0 0 0 0 0 0 0 0 0 0 0 0
33634- 0 0 0 0 0 0 0 0 0 0 0 0
33635- 0 0 0 0 0 0 0 0 0 0 0 0
33636- 0 0 0 0 0 0 0 0 0 0 0 0
33637- 0 0 0 0 0 0 0 0 0 0 0 0
33638- 0 0 0 0 0 0 0 0 0 0 0 0
33639- 0 0 0 0 0 0 0 0 0 0 0 0
33640- 0 0 0 0 0 0 0 0 0 0 0 0
33641- 0 0 0 0 0 0 0 0 0 0 0 0
33642- 0 0 0 0 0 0 0 0 0 0 0 0
33643- 0 0 0 0 0 0 0 0 0 0 0 0
33644- 0 0 0 0 0 0 0 0 0 0 0 0
33645- 0 0 0 6 6 6 22 22 22 50 50 50
33646- 78 78 78 34 34 34 2 2 6 2 2 6
33647- 2 2 6 2 2 6 2 2 6 2 2 6
33648- 2 2 6 2 2 6 2 2 6 2 2 6
33649- 2 2 6 2 2 6 6 6 6 70 70 70
33650- 78 78 78 46 46 46 22 22 22 6 6 6
33651- 0 0 0 0 0 0 0 0 0 0 0 0
33652- 0 0 0 0 0 0 0 0 0 0 0 0
33653- 0 0 0 0 0 0 0 0 0 0 0 0
33654- 0 0 0 0 0 0 0 0 0 0 0 0
33655- 0 0 0 0 0 0 0 0 0 0 0 0
33656- 0 0 0 0 0 0 0 0 0 0 0 0
33657- 0 0 0 0 0 0 0 0 0 0 0 0
33658- 0 0 0 0 0 0 0 0 0 0 0 0
33659- 0 0 1 0 0 1 0 0 1 0 0 0
33660- 0 0 0 0 0 0 0 0 0 0 0 0
33661- 0 0 0 0 0 0 0 0 0 0 0 0
33662- 0 0 0 0 0 0 0 0 0 0 0 0
33663- 0 0 0 0 0 0 0 0 0 0 0 0
33664- 0 0 0 0 0 0 0 0 0 0 0 0
33665- 6 6 6 18 18 18 42 42 42 82 82 82
33666- 26 26 26 2 2 6 2 2 6 2 2 6
33667- 2 2 6 2 2 6 2 2 6 2 2 6
33668- 2 2 6 2 2 6 2 2 6 14 14 14
33669- 46 46 46 34 34 34 6 6 6 2 2 6
33670- 42 42 42 78 78 78 42 42 42 18 18 18
33671- 6 6 6 0 0 0 0 0 0 0 0 0
33672- 0 0 0 0 0 0 0 0 0 0 0 0
33673- 0 0 0 0 0 0 0 0 0 0 0 0
33674- 0 0 0 0 0 0 0 0 0 0 0 0
33675- 0 0 0 0 0 0 0 0 0 0 0 0
33676- 0 0 0 0 0 0 0 0 0 0 0 0
33677- 0 0 0 0 0 0 0 0 0 0 0 0
33678- 0 0 0 0 0 0 0 0 0 0 0 0
33679- 0 0 1 0 0 0 0 0 1 0 0 0
33680- 0 0 0 0 0 0 0 0 0 0 0 0
33681- 0 0 0 0 0 0 0 0 0 0 0 0
33682- 0 0 0 0 0 0 0 0 0 0 0 0
33683- 0 0 0 0 0 0 0 0 0 0 0 0
33684- 0 0 0 0 0 0 0 0 0 0 0 0
33685- 10 10 10 30 30 30 66 66 66 58 58 58
33686- 2 2 6 2 2 6 2 2 6 2 2 6
33687- 2 2 6 2 2 6 2 2 6 2 2 6
33688- 2 2 6 2 2 6 2 2 6 26 26 26
33689- 86 86 86 101 101 101 46 46 46 10 10 10
33690- 2 2 6 58 58 58 70 70 70 34 34 34
33691- 10 10 10 0 0 0 0 0 0 0 0 0
33692- 0 0 0 0 0 0 0 0 0 0 0 0
33693- 0 0 0 0 0 0 0 0 0 0 0 0
33694- 0 0 0 0 0 0 0 0 0 0 0 0
33695- 0 0 0 0 0 0 0 0 0 0 0 0
33696- 0 0 0 0 0 0 0 0 0 0 0 0
33697- 0 0 0 0 0 0 0 0 0 0 0 0
33698- 0 0 0 0 0 0 0 0 0 0 0 0
33699- 0 0 1 0 0 1 0 0 1 0 0 0
33700- 0 0 0 0 0 0 0 0 0 0 0 0
33701- 0 0 0 0 0 0 0 0 0 0 0 0
33702- 0 0 0 0 0 0 0 0 0 0 0 0
33703- 0 0 0 0 0 0 0 0 0 0 0 0
33704- 0 0 0 0 0 0 0 0 0 0 0 0
33705- 14 14 14 42 42 42 86 86 86 10 10 10
33706- 2 2 6 2 2 6 2 2 6 2 2 6
33707- 2 2 6 2 2 6 2 2 6 2 2 6
33708- 2 2 6 2 2 6 2 2 6 30 30 30
33709- 94 94 94 94 94 94 58 58 58 26 26 26
33710- 2 2 6 6 6 6 78 78 78 54 54 54
33711- 22 22 22 6 6 6 0 0 0 0 0 0
33712- 0 0 0 0 0 0 0 0 0 0 0 0
33713- 0 0 0 0 0 0 0 0 0 0 0 0
33714- 0 0 0 0 0 0 0 0 0 0 0 0
33715- 0 0 0 0 0 0 0 0 0 0 0 0
33716- 0 0 0 0 0 0 0 0 0 0 0 0
33717- 0 0 0 0 0 0 0 0 0 0 0 0
33718- 0 0 0 0 0 0 0 0 0 0 0 0
33719- 0 0 0 0 0 0 0 0 0 0 0 0
33720- 0 0 0 0 0 0 0 0 0 0 0 0
33721- 0 0 0 0 0 0 0 0 0 0 0 0
33722- 0 0 0 0 0 0 0 0 0 0 0 0
33723- 0 0 0 0 0 0 0 0 0 0 0 0
33724- 0 0 0 0 0 0 0 0 0 6 6 6
33725- 22 22 22 62 62 62 62 62 62 2 2 6
33726- 2 2 6 2 2 6 2 2 6 2 2 6
33727- 2 2 6 2 2 6 2 2 6 2 2 6
33728- 2 2 6 2 2 6 2 2 6 26 26 26
33729- 54 54 54 38 38 38 18 18 18 10 10 10
33730- 2 2 6 2 2 6 34 34 34 82 82 82
33731- 38 38 38 14 14 14 0 0 0 0 0 0
33732- 0 0 0 0 0 0 0 0 0 0 0 0
33733- 0 0 0 0 0 0 0 0 0 0 0 0
33734- 0 0 0 0 0 0 0 0 0 0 0 0
33735- 0 0 0 0 0 0 0 0 0 0 0 0
33736- 0 0 0 0 0 0 0 0 0 0 0 0
33737- 0 0 0 0 0 0 0 0 0 0 0 0
33738- 0 0 0 0 0 0 0 0 0 0 0 0
33739- 0 0 0 0 0 1 0 0 1 0 0 0
33740- 0 0 0 0 0 0 0 0 0 0 0 0
33741- 0 0 0 0 0 0 0 0 0 0 0 0
33742- 0 0 0 0 0 0 0 0 0 0 0 0
33743- 0 0 0 0 0 0 0 0 0 0 0 0
33744- 0 0 0 0 0 0 0 0 0 6 6 6
33745- 30 30 30 78 78 78 30 30 30 2 2 6
33746- 2 2 6 2 2 6 2 2 6 2 2 6
33747- 2 2 6 2 2 6 2 2 6 2 2 6
33748- 2 2 6 2 2 6 2 2 6 10 10 10
33749- 10 10 10 2 2 6 2 2 6 2 2 6
33750- 2 2 6 2 2 6 2 2 6 78 78 78
33751- 50 50 50 18 18 18 6 6 6 0 0 0
33752- 0 0 0 0 0 0 0 0 0 0 0 0
33753- 0 0 0 0 0 0 0 0 0 0 0 0
33754- 0 0 0 0 0 0 0 0 0 0 0 0
33755- 0 0 0 0 0 0 0 0 0 0 0 0
33756- 0 0 0 0 0 0 0 0 0 0 0 0
33757- 0 0 0 0 0 0 0 0 0 0 0 0
33758- 0 0 0 0 0 0 0 0 0 0 0 0
33759- 0 0 1 0 0 0 0 0 0 0 0 0
33760- 0 0 0 0 0 0 0 0 0 0 0 0
33761- 0 0 0 0 0 0 0 0 0 0 0 0
33762- 0 0 0 0 0 0 0 0 0 0 0 0
33763- 0 0 0 0 0 0 0 0 0 0 0 0
33764- 0 0 0 0 0 0 0 0 0 10 10 10
33765- 38 38 38 86 86 86 14 14 14 2 2 6
33766- 2 2 6 2 2 6 2 2 6 2 2 6
33767- 2 2 6 2 2 6 2 2 6 2 2 6
33768- 2 2 6 2 2 6 2 2 6 2 2 6
33769- 2 2 6 2 2 6 2 2 6 2 2 6
33770- 2 2 6 2 2 6 2 2 6 54 54 54
33771- 66 66 66 26 26 26 6 6 6 0 0 0
33772- 0 0 0 0 0 0 0 0 0 0 0 0
33773- 0 0 0 0 0 0 0 0 0 0 0 0
33774- 0 0 0 0 0 0 0 0 0 0 0 0
33775- 0 0 0 0 0 0 0 0 0 0 0 0
33776- 0 0 0 0 0 0 0 0 0 0 0 0
33777- 0 0 0 0 0 0 0 0 0 0 0 0
33778- 0 0 0 0 0 0 0 0 0 0 0 0
33779- 0 0 0 0 0 1 0 0 1 0 0 0
33780- 0 0 0 0 0 0 0 0 0 0 0 0
33781- 0 0 0 0 0 0 0 0 0 0 0 0
33782- 0 0 0 0 0 0 0 0 0 0 0 0
33783- 0 0 0 0 0 0 0 0 0 0 0 0
33784- 0 0 0 0 0 0 0 0 0 14 14 14
33785- 42 42 42 82 82 82 2 2 6 2 2 6
33786- 2 2 6 6 6 6 10 10 10 2 2 6
33787- 2 2 6 2 2 6 2 2 6 2 2 6
33788- 2 2 6 2 2 6 2 2 6 6 6 6
33789- 14 14 14 10 10 10 2 2 6 2 2 6
33790- 2 2 6 2 2 6 2 2 6 18 18 18
33791- 82 82 82 34 34 34 10 10 10 0 0 0
33792- 0 0 0 0 0 0 0 0 0 0 0 0
33793- 0 0 0 0 0 0 0 0 0 0 0 0
33794- 0 0 0 0 0 0 0 0 0 0 0 0
33795- 0 0 0 0 0 0 0 0 0 0 0 0
33796- 0 0 0 0 0 0 0 0 0 0 0 0
33797- 0 0 0 0 0 0 0 0 0 0 0 0
33798- 0 0 0 0 0 0 0 0 0 0 0 0
33799- 0 0 1 0 0 0 0 0 0 0 0 0
33800- 0 0 0 0 0 0 0 0 0 0 0 0
33801- 0 0 0 0 0 0 0 0 0 0 0 0
33802- 0 0 0 0 0 0 0 0 0 0 0 0
33803- 0 0 0 0 0 0 0 0 0 0 0 0
33804- 0 0 0 0 0 0 0 0 0 14 14 14
33805- 46 46 46 86 86 86 2 2 6 2 2 6
33806- 6 6 6 6 6 6 22 22 22 34 34 34
33807- 6 6 6 2 2 6 2 2 6 2 2 6
33808- 2 2 6 2 2 6 18 18 18 34 34 34
33809- 10 10 10 50 50 50 22 22 22 2 2 6
33810- 2 2 6 2 2 6 2 2 6 10 10 10
33811- 86 86 86 42 42 42 14 14 14 0 0 0
33812- 0 0 0 0 0 0 0 0 0 0 0 0
33813- 0 0 0 0 0 0 0 0 0 0 0 0
33814- 0 0 0 0 0 0 0 0 0 0 0 0
33815- 0 0 0 0 0 0 0 0 0 0 0 0
33816- 0 0 0 0 0 0 0 0 0 0 0 0
33817- 0 0 0 0 0 0 0 0 0 0 0 0
33818- 0 0 0 0 0 0 0 0 0 0 0 0
33819- 0 0 1 0 0 1 0 0 1 0 0 0
33820- 0 0 0 0 0 0 0 0 0 0 0 0
33821- 0 0 0 0 0 0 0 0 0 0 0 0
33822- 0 0 0 0 0 0 0 0 0 0 0 0
33823- 0 0 0 0 0 0 0 0 0 0 0 0
33824- 0 0 0 0 0 0 0 0 0 14 14 14
33825- 46 46 46 86 86 86 2 2 6 2 2 6
33826- 38 38 38 116 116 116 94 94 94 22 22 22
33827- 22 22 22 2 2 6 2 2 6 2 2 6
33828- 14 14 14 86 86 86 138 138 138 162 162 162
33829-154 154 154 38 38 38 26 26 26 6 6 6
33830- 2 2 6 2 2 6 2 2 6 2 2 6
33831- 86 86 86 46 46 46 14 14 14 0 0 0
33832- 0 0 0 0 0 0 0 0 0 0 0 0
33833- 0 0 0 0 0 0 0 0 0 0 0 0
33834- 0 0 0 0 0 0 0 0 0 0 0 0
33835- 0 0 0 0 0 0 0 0 0 0 0 0
33836- 0 0 0 0 0 0 0 0 0 0 0 0
33837- 0 0 0 0 0 0 0 0 0 0 0 0
33838- 0 0 0 0 0 0 0 0 0 0 0 0
33839- 0 0 0 0 0 0 0 0 0 0 0 0
33840- 0 0 0 0 0 0 0 0 0 0 0 0
33841- 0 0 0 0 0 0 0 0 0 0 0 0
33842- 0 0 0 0 0 0 0 0 0 0 0 0
33843- 0 0 0 0 0 0 0 0 0 0 0 0
33844- 0 0 0 0 0 0 0 0 0 14 14 14
33845- 46 46 46 86 86 86 2 2 6 14 14 14
33846-134 134 134 198 198 198 195 195 195 116 116 116
33847- 10 10 10 2 2 6 2 2 6 6 6 6
33848-101 98 89 187 187 187 210 210 210 218 218 218
33849-214 214 214 134 134 134 14 14 14 6 6 6
33850- 2 2 6 2 2 6 2 2 6 2 2 6
33851- 86 86 86 50 50 50 18 18 18 6 6 6
33852- 0 0 0 0 0 0 0 0 0 0 0 0
33853- 0 0 0 0 0 0 0 0 0 0 0 0
33854- 0 0 0 0 0 0 0 0 0 0 0 0
33855- 0 0 0 0 0 0 0 0 0 0 0 0
33856- 0 0 0 0 0 0 0 0 0 0 0 0
33857- 0 0 0 0 0 0 0 0 0 0 0 0
33858- 0 0 0 0 0 0 0 0 1 0 0 0
33859- 0 0 1 0 0 1 0 0 1 0 0 0
33860- 0 0 0 0 0 0 0 0 0 0 0 0
33861- 0 0 0 0 0 0 0 0 0 0 0 0
33862- 0 0 0 0 0 0 0 0 0 0 0 0
33863- 0 0 0 0 0 0 0 0 0 0 0 0
33864- 0 0 0 0 0 0 0 0 0 14 14 14
33865- 46 46 46 86 86 86 2 2 6 54 54 54
33866-218 218 218 195 195 195 226 226 226 246 246 246
33867- 58 58 58 2 2 6 2 2 6 30 30 30
33868-210 210 210 253 253 253 174 174 174 123 123 123
33869-221 221 221 234 234 234 74 74 74 2 2 6
33870- 2 2 6 2 2 6 2 2 6 2 2 6
33871- 70 70 70 58 58 58 22 22 22 6 6 6
33872- 0 0 0 0 0 0 0 0 0 0 0 0
33873- 0 0 0 0 0 0 0 0 0 0 0 0
33874- 0 0 0 0 0 0 0 0 0 0 0 0
33875- 0 0 0 0 0 0 0 0 0 0 0 0
33876- 0 0 0 0 0 0 0 0 0 0 0 0
33877- 0 0 0 0 0 0 0 0 0 0 0 0
33878- 0 0 0 0 0 0 0 0 0 0 0 0
33879- 0 0 0 0 0 0 0 0 0 0 0 0
33880- 0 0 0 0 0 0 0 0 0 0 0 0
33881- 0 0 0 0 0 0 0 0 0 0 0 0
33882- 0 0 0 0 0 0 0 0 0 0 0 0
33883- 0 0 0 0 0 0 0 0 0 0 0 0
33884- 0 0 0 0 0 0 0 0 0 14 14 14
33885- 46 46 46 82 82 82 2 2 6 106 106 106
33886-170 170 170 26 26 26 86 86 86 226 226 226
33887-123 123 123 10 10 10 14 14 14 46 46 46
33888-231 231 231 190 190 190 6 6 6 70 70 70
33889- 90 90 90 238 238 238 158 158 158 2 2 6
33890- 2 2 6 2 2 6 2 2 6 2 2 6
33891- 70 70 70 58 58 58 22 22 22 6 6 6
33892- 0 0 0 0 0 0 0 0 0 0 0 0
33893- 0 0 0 0 0 0 0 0 0 0 0 0
33894- 0 0 0 0 0 0 0 0 0 0 0 0
33895- 0 0 0 0 0 0 0 0 0 0 0 0
33896- 0 0 0 0 0 0 0 0 0 0 0 0
33897- 0 0 0 0 0 0 0 0 0 0 0 0
33898- 0 0 0 0 0 0 0 0 1 0 0 0
33899- 0 0 1 0 0 1 0 0 1 0 0 0
33900- 0 0 0 0 0 0 0 0 0 0 0 0
33901- 0 0 0 0 0 0 0 0 0 0 0 0
33902- 0 0 0 0 0 0 0 0 0 0 0 0
33903- 0 0 0 0 0 0 0 0 0 0 0 0
33904- 0 0 0 0 0 0 0 0 0 14 14 14
33905- 42 42 42 86 86 86 6 6 6 116 116 116
33906-106 106 106 6 6 6 70 70 70 149 149 149
33907-128 128 128 18 18 18 38 38 38 54 54 54
33908-221 221 221 106 106 106 2 2 6 14 14 14
33909- 46 46 46 190 190 190 198 198 198 2 2 6
33910- 2 2 6 2 2 6 2 2 6 2 2 6
33911- 74 74 74 62 62 62 22 22 22 6 6 6
33912- 0 0 0 0 0 0 0 0 0 0 0 0
33913- 0 0 0 0 0 0 0 0 0 0 0 0
33914- 0 0 0 0 0 0 0 0 0 0 0 0
33915- 0 0 0 0 0 0 0 0 0 0 0 0
33916- 0 0 0 0 0 0 0 0 0 0 0 0
33917- 0 0 0 0 0 0 0 0 0 0 0 0
33918- 0 0 0 0 0 0 0 0 1 0 0 0
33919- 0 0 1 0 0 0 0 0 1 0 0 0
33920- 0 0 0 0 0 0 0 0 0 0 0 0
33921- 0 0 0 0 0 0 0 0 0 0 0 0
33922- 0 0 0 0 0 0 0 0 0 0 0 0
33923- 0 0 0 0 0 0 0 0 0 0 0 0
33924- 0 0 0 0 0 0 0 0 0 14 14 14
33925- 42 42 42 94 94 94 14 14 14 101 101 101
33926-128 128 128 2 2 6 18 18 18 116 116 116
33927-118 98 46 121 92 8 121 92 8 98 78 10
33928-162 162 162 106 106 106 2 2 6 2 2 6
33929- 2 2 6 195 195 195 195 195 195 6 6 6
33930- 2 2 6 2 2 6 2 2 6 2 2 6
33931- 74 74 74 62 62 62 22 22 22 6 6 6
33932- 0 0 0 0 0 0 0 0 0 0 0 0
33933- 0 0 0 0 0 0 0 0 0 0 0 0
33934- 0 0 0 0 0 0 0 0 0 0 0 0
33935- 0 0 0 0 0 0 0 0 0 0 0 0
33936- 0 0 0 0 0 0 0 0 0 0 0 0
33937- 0 0 0 0 0 0 0 0 0 0 0 0
33938- 0 0 0 0 0 0 0 0 1 0 0 1
33939- 0 0 1 0 0 0 0 0 1 0 0 0
33940- 0 0 0 0 0 0 0 0 0 0 0 0
33941- 0 0 0 0 0 0 0 0 0 0 0 0
33942- 0 0 0 0 0 0 0 0 0 0 0 0
33943- 0 0 0 0 0 0 0 0 0 0 0 0
33944- 0 0 0 0 0 0 0 0 0 10 10 10
33945- 38 38 38 90 90 90 14 14 14 58 58 58
33946-210 210 210 26 26 26 54 38 6 154 114 10
33947-226 170 11 236 186 11 225 175 15 184 144 12
33948-215 174 15 175 146 61 37 26 9 2 2 6
33949- 70 70 70 246 246 246 138 138 138 2 2 6
33950- 2 2 6 2 2 6 2 2 6 2 2 6
33951- 70 70 70 66 66 66 26 26 26 6 6 6
33952- 0 0 0 0 0 0 0 0 0 0 0 0
33953- 0 0 0 0 0 0 0 0 0 0 0 0
33954- 0 0 0 0 0 0 0 0 0 0 0 0
33955- 0 0 0 0 0 0 0 0 0 0 0 0
33956- 0 0 0 0 0 0 0 0 0 0 0 0
33957- 0 0 0 0 0 0 0 0 0 0 0 0
33958- 0 0 0 0 0 0 0 0 0 0 0 0
33959- 0 0 0 0 0 0 0 0 0 0 0 0
33960- 0 0 0 0 0 0 0 0 0 0 0 0
33961- 0 0 0 0 0 0 0 0 0 0 0 0
33962- 0 0 0 0 0 0 0 0 0 0 0 0
33963- 0 0 0 0 0 0 0 0 0 0 0 0
33964- 0 0 0 0 0 0 0 0 0 10 10 10
33965- 38 38 38 86 86 86 14 14 14 10 10 10
33966-195 195 195 188 164 115 192 133 9 225 175 15
33967-239 182 13 234 190 10 232 195 16 232 200 30
33968-245 207 45 241 208 19 232 195 16 184 144 12
33969-218 194 134 211 206 186 42 42 42 2 2 6
33970- 2 2 6 2 2 6 2 2 6 2 2 6
33971- 50 50 50 74 74 74 30 30 30 6 6 6
33972- 0 0 0 0 0 0 0 0 0 0 0 0
33973- 0 0 0 0 0 0 0 0 0 0 0 0
33974- 0 0 0 0 0 0 0 0 0 0 0 0
33975- 0 0 0 0 0 0 0 0 0 0 0 0
33976- 0 0 0 0 0 0 0 0 0 0 0 0
33977- 0 0 0 0 0 0 0 0 0 0 0 0
33978- 0 0 0 0 0 0 0 0 0 0 0 0
33979- 0 0 0 0 0 0 0 0 0 0 0 0
33980- 0 0 0 0 0 0 0 0 0 0 0 0
33981- 0 0 0 0 0 0 0 0 0 0 0 0
33982- 0 0 0 0 0 0 0 0 0 0 0 0
33983- 0 0 0 0 0 0 0 0 0 0 0 0
33984- 0 0 0 0 0 0 0 0 0 10 10 10
33985- 34 34 34 86 86 86 14 14 14 2 2 6
33986-121 87 25 192 133 9 219 162 10 239 182 13
33987-236 186 11 232 195 16 241 208 19 244 214 54
33988-246 218 60 246 218 38 246 215 20 241 208 19
33989-241 208 19 226 184 13 121 87 25 2 2 6
33990- 2 2 6 2 2 6 2 2 6 2 2 6
33991- 50 50 50 82 82 82 34 34 34 10 10 10
33992- 0 0 0 0 0 0 0 0 0 0 0 0
33993- 0 0 0 0 0 0 0 0 0 0 0 0
33994- 0 0 0 0 0 0 0 0 0 0 0 0
33995- 0 0 0 0 0 0 0 0 0 0 0 0
33996- 0 0 0 0 0 0 0 0 0 0 0 0
33997- 0 0 0 0 0 0 0 0 0 0 0 0
33998- 0 0 0 0 0 0 0 0 0 0 0 0
33999- 0 0 0 0 0 0 0 0 0 0 0 0
34000- 0 0 0 0 0 0 0 0 0 0 0 0
34001- 0 0 0 0 0 0 0 0 0 0 0 0
34002- 0 0 0 0 0 0 0 0 0 0 0 0
34003- 0 0 0 0 0 0 0 0 0 0 0 0
34004- 0 0 0 0 0 0 0 0 0 10 10 10
34005- 34 34 34 82 82 82 30 30 30 61 42 6
34006-180 123 7 206 145 10 230 174 11 239 182 13
34007-234 190 10 238 202 15 241 208 19 246 218 74
34008-246 218 38 246 215 20 246 215 20 246 215 20
34009-226 184 13 215 174 15 184 144 12 6 6 6
34010- 2 2 6 2 2 6 2 2 6 2 2 6
34011- 26 26 26 94 94 94 42 42 42 14 14 14
34012- 0 0 0 0 0 0 0 0 0 0 0 0
34013- 0 0 0 0 0 0 0 0 0 0 0 0
34014- 0 0 0 0 0 0 0 0 0 0 0 0
34015- 0 0 0 0 0 0 0 0 0 0 0 0
34016- 0 0 0 0 0 0 0 0 0 0 0 0
34017- 0 0 0 0 0 0 0 0 0 0 0 0
34018- 0 0 0 0 0 0 0 0 0 0 0 0
34019- 0 0 0 0 0 0 0 0 0 0 0 0
34020- 0 0 0 0 0 0 0 0 0 0 0 0
34021- 0 0 0 0 0 0 0 0 0 0 0 0
34022- 0 0 0 0 0 0 0 0 0 0 0 0
34023- 0 0 0 0 0 0 0 0 0 0 0 0
34024- 0 0 0 0 0 0 0 0 0 10 10 10
34025- 30 30 30 78 78 78 50 50 50 104 69 6
34026-192 133 9 216 158 10 236 178 12 236 186 11
34027-232 195 16 241 208 19 244 214 54 245 215 43
34028-246 215 20 246 215 20 241 208 19 198 155 10
34029-200 144 11 216 158 10 156 118 10 2 2 6
34030- 2 2 6 2 2 6 2 2 6 2 2 6
34031- 6 6 6 90 90 90 54 54 54 18 18 18
34032- 6 6 6 0 0 0 0 0 0 0 0 0
34033- 0 0 0 0 0 0 0 0 0 0 0 0
34034- 0 0 0 0 0 0 0 0 0 0 0 0
34035- 0 0 0 0 0 0 0 0 0 0 0 0
34036- 0 0 0 0 0 0 0 0 0 0 0 0
34037- 0 0 0 0 0 0 0 0 0 0 0 0
34038- 0 0 0 0 0 0 0 0 0 0 0 0
34039- 0 0 0 0 0 0 0 0 0 0 0 0
34040- 0 0 0 0 0 0 0 0 0 0 0 0
34041- 0 0 0 0 0 0 0 0 0 0 0 0
34042- 0 0 0 0 0 0 0 0 0 0 0 0
34043- 0 0 0 0 0 0 0 0 0 0 0 0
34044- 0 0 0 0 0 0 0 0 0 10 10 10
34045- 30 30 30 78 78 78 46 46 46 22 22 22
34046-137 92 6 210 162 10 239 182 13 238 190 10
34047-238 202 15 241 208 19 246 215 20 246 215 20
34048-241 208 19 203 166 17 185 133 11 210 150 10
34049-216 158 10 210 150 10 102 78 10 2 2 6
34050- 6 6 6 54 54 54 14 14 14 2 2 6
34051- 2 2 6 62 62 62 74 74 74 30 30 30
34052- 10 10 10 0 0 0 0 0 0 0 0 0
34053- 0 0 0 0 0 0 0 0 0 0 0 0
34054- 0 0 0 0 0 0 0 0 0 0 0 0
34055- 0 0 0 0 0 0 0 0 0 0 0 0
34056- 0 0 0 0 0 0 0 0 0 0 0 0
34057- 0 0 0 0 0 0 0 0 0 0 0 0
34058- 0 0 0 0 0 0 0 0 0 0 0 0
34059- 0 0 0 0 0 0 0 0 0 0 0 0
34060- 0 0 0 0 0 0 0 0 0 0 0 0
34061- 0 0 0 0 0 0 0 0 0 0 0 0
34062- 0 0 0 0 0 0 0 0 0 0 0 0
34063- 0 0 0 0 0 0 0 0 0 0 0 0
34064- 0 0 0 0 0 0 0 0 0 10 10 10
34065- 34 34 34 78 78 78 50 50 50 6 6 6
34066- 94 70 30 139 102 15 190 146 13 226 184 13
34067-232 200 30 232 195 16 215 174 15 190 146 13
34068-168 122 10 192 133 9 210 150 10 213 154 11
34069-202 150 34 182 157 106 101 98 89 2 2 6
34070- 2 2 6 78 78 78 116 116 116 58 58 58
34071- 2 2 6 22 22 22 90 90 90 46 46 46
34072- 18 18 18 6 6 6 0 0 0 0 0 0
34073- 0 0 0 0 0 0 0 0 0 0 0 0
34074- 0 0 0 0 0 0 0 0 0 0 0 0
34075- 0 0 0 0 0 0 0 0 0 0 0 0
34076- 0 0 0 0 0 0 0 0 0 0 0 0
34077- 0 0 0 0 0 0 0 0 0 0 0 0
34078- 0 0 0 0 0 0 0 0 0 0 0 0
34079- 0 0 0 0 0 0 0 0 0 0 0 0
34080- 0 0 0 0 0 0 0 0 0 0 0 0
34081- 0 0 0 0 0 0 0 0 0 0 0 0
34082- 0 0 0 0 0 0 0 0 0 0 0 0
34083- 0 0 0 0 0 0 0 0 0 0 0 0
34084- 0 0 0 0 0 0 0 0 0 10 10 10
34085- 38 38 38 86 86 86 50 50 50 6 6 6
34086-128 128 128 174 154 114 156 107 11 168 122 10
34087-198 155 10 184 144 12 197 138 11 200 144 11
34088-206 145 10 206 145 10 197 138 11 188 164 115
34089-195 195 195 198 198 198 174 174 174 14 14 14
34090- 2 2 6 22 22 22 116 116 116 116 116 116
34091- 22 22 22 2 2 6 74 74 74 70 70 70
34092- 30 30 30 10 10 10 0 0 0 0 0 0
34093- 0 0 0 0 0 0 0 0 0 0 0 0
34094- 0 0 0 0 0 0 0 0 0 0 0 0
34095- 0 0 0 0 0 0 0 0 0 0 0 0
34096- 0 0 0 0 0 0 0 0 0 0 0 0
34097- 0 0 0 0 0 0 0 0 0 0 0 0
34098- 0 0 0 0 0 0 0 0 0 0 0 0
34099- 0 0 0 0 0 0 0 0 0 0 0 0
34100- 0 0 0 0 0 0 0 0 0 0 0 0
34101- 0 0 0 0 0 0 0 0 0 0 0 0
34102- 0 0 0 0 0 0 0 0 0 0 0 0
34103- 0 0 0 0 0 0 0 0 0 0 0 0
34104- 0 0 0 0 0 0 6 6 6 18 18 18
34105- 50 50 50 101 101 101 26 26 26 10 10 10
34106-138 138 138 190 190 190 174 154 114 156 107 11
34107-197 138 11 200 144 11 197 138 11 192 133 9
34108-180 123 7 190 142 34 190 178 144 187 187 187
34109-202 202 202 221 221 221 214 214 214 66 66 66
34110- 2 2 6 2 2 6 50 50 50 62 62 62
34111- 6 6 6 2 2 6 10 10 10 90 90 90
34112- 50 50 50 18 18 18 6 6 6 0 0 0
34113- 0 0 0 0 0 0 0 0 0 0 0 0
34114- 0 0 0 0 0 0 0 0 0 0 0 0
34115- 0 0 0 0 0 0 0 0 0 0 0 0
34116- 0 0 0 0 0 0 0 0 0 0 0 0
34117- 0 0 0 0 0 0 0 0 0 0 0 0
34118- 0 0 0 0 0 0 0 0 0 0 0 0
34119- 0 0 0 0 0 0 0 0 0 0 0 0
34120- 0 0 0 0 0 0 0 0 0 0 0 0
34121- 0 0 0 0 0 0 0 0 0 0 0 0
34122- 0 0 0 0 0 0 0 0 0 0 0 0
34123- 0 0 0 0 0 0 0 0 0 0 0 0
34124- 0 0 0 0 0 0 10 10 10 34 34 34
34125- 74 74 74 74 74 74 2 2 6 6 6 6
34126-144 144 144 198 198 198 190 190 190 178 166 146
34127-154 121 60 156 107 11 156 107 11 168 124 44
34128-174 154 114 187 187 187 190 190 190 210 210 210
34129-246 246 246 253 253 253 253 253 253 182 182 182
34130- 6 6 6 2 2 6 2 2 6 2 2 6
34131- 2 2 6 2 2 6 2 2 6 62 62 62
34132- 74 74 74 34 34 34 14 14 14 0 0 0
34133- 0 0 0 0 0 0 0 0 0 0 0 0
34134- 0 0 0 0 0 0 0 0 0 0 0 0
34135- 0 0 0 0 0 0 0 0 0 0 0 0
34136- 0 0 0 0 0 0 0 0 0 0 0 0
34137- 0 0 0 0 0 0 0 0 0 0 0 0
34138- 0 0 0 0 0 0 0 0 0 0 0 0
34139- 0 0 0 0 0 0 0 0 0 0 0 0
34140- 0 0 0 0 0 0 0 0 0 0 0 0
34141- 0 0 0 0 0 0 0 0 0 0 0 0
34142- 0 0 0 0 0 0 0 0 0 0 0 0
34143- 0 0 0 0 0 0 0 0 0 0 0 0
34144- 0 0 0 10 10 10 22 22 22 54 54 54
34145- 94 94 94 18 18 18 2 2 6 46 46 46
34146-234 234 234 221 221 221 190 190 190 190 190 190
34147-190 190 190 187 187 187 187 187 187 190 190 190
34148-190 190 190 195 195 195 214 214 214 242 242 242
34149-253 253 253 253 253 253 253 253 253 253 253 253
34150- 82 82 82 2 2 6 2 2 6 2 2 6
34151- 2 2 6 2 2 6 2 2 6 14 14 14
34152- 86 86 86 54 54 54 22 22 22 6 6 6
34153- 0 0 0 0 0 0 0 0 0 0 0 0
34154- 0 0 0 0 0 0 0 0 0 0 0 0
34155- 0 0 0 0 0 0 0 0 0 0 0 0
34156- 0 0 0 0 0 0 0 0 0 0 0 0
34157- 0 0 0 0 0 0 0 0 0 0 0 0
34158- 0 0 0 0 0 0 0 0 0 0 0 0
34159- 0 0 0 0 0 0 0 0 0 0 0 0
34160- 0 0 0 0 0 0 0 0 0 0 0 0
34161- 0 0 0 0 0 0 0 0 0 0 0 0
34162- 0 0 0 0 0 0 0 0 0 0 0 0
34163- 0 0 0 0 0 0 0 0 0 0 0 0
34164- 6 6 6 18 18 18 46 46 46 90 90 90
34165- 46 46 46 18 18 18 6 6 6 182 182 182
34166-253 253 253 246 246 246 206 206 206 190 190 190
34167-190 190 190 190 190 190 190 190 190 190 190 190
34168-206 206 206 231 231 231 250 250 250 253 253 253
34169-253 253 253 253 253 253 253 253 253 253 253 253
34170-202 202 202 14 14 14 2 2 6 2 2 6
34171- 2 2 6 2 2 6 2 2 6 2 2 6
34172- 42 42 42 86 86 86 42 42 42 18 18 18
34173- 6 6 6 0 0 0 0 0 0 0 0 0
34174- 0 0 0 0 0 0 0 0 0 0 0 0
34175- 0 0 0 0 0 0 0 0 0 0 0 0
34176- 0 0 0 0 0 0 0 0 0 0 0 0
34177- 0 0 0 0 0 0 0 0 0 0 0 0
34178- 0 0 0 0 0 0 0 0 0 0 0 0
34179- 0 0 0 0 0 0 0 0 0 0 0 0
34180- 0 0 0 0 0 0 0 0 0 0 0 0
34181- 0 0 0 0 0 0 0 0 0 0 0 0
34182- 0 0 0 0 0 0 0 0 0 0 0 0
34183- 0 0 0 0 0 0 0 0 0 6 6 6
34184- 14 14 14 38 38 38 74 74 74 66 66 66
34185- 2 2 6 6 6 6 90 90 90 250 250 250
34186-253 253 253 253 253 253 238 238 238 198 198 198
34187-190 190 190 190 190 190 195 195 195 221 221 221
34188-246 246 246 253 253 253 253 253 253 253 253 253
34189-253 253 253 253 253 253 253 253 253 253 253 253
34190-253 253 253 82 82 82 2 2 6 2 2 6
34191- 2 2 6 2 2 6 2 2 6 2 2 6
34192- 2 2 6 78 78 78 70 70 70 34 34 34
34193- 14 14 14 6 6 6 0 0 0 0 0 0
34194- 0 0 0 0 0 0 0 0 0 0 0 0
34195- 0 0 0 0 0 0 0 0 0 0 0 0
34196- 0 0 0 0 0 0 0 0 0 0 0 0
34197- 0 0 0 0 0 0 0 0 0 0 0 0
34198- 0 0 0 0 0 0 0 0 0 0 0 0
34199- 0 0 0 0 0 0 0 0 0 0 0 0
34200- 0 0 0 0 0 0 0 0 0 0 0 0
34201- 0 0 0 0 0 0 0 0 0 0 0 0
34202- 0 0 0 0 0 0 0 0 0 0 0 0
34203- 0 0 0 0 0 0 0 0 0 14 14 14
34204- 34 34 34 66 66 66 78 78 78 6 6 6
34205- 2 2 6 18 18 18 218 218 218 253 253 253
34206-253 253 253 253 253 253 253 253 253 246 246 246
34207-226 226 226 231 231 231 246 246 246 253 253 253
34208-253 253 253 253 253 253 253 253 253 253 253 253
34209-253 253 253 253 253 253 253 253 253 253 253 253
34210-253 253 253 178 178 178 2 2 6 2 2 6
34211- 2 2 6 2 2 6 2 2 6 2 2 6
34212- 2 2 6 18 18 18 90 90 90 62 62 62
34213- 30 30 30 10 10 10 0 0 0 0 0 0
34214- 0 0 0 0 0 0 0 0 0 0 0 0
34215- 0 0 0 0 0 0 0 0 0 0 0 0
34216- 0 0 0 0 0 0 0 0 0 0 0 0
34217- 0 0 0 0 0 0 0 0 0 0 0 0
34218- 0 0 0 0 0 0 0 0 0 0 0 0
34219- 0 0 0 0 0 0 0 0 0 0 0 0
34220- 0 0 0 0 0 0 0 0 0 0 0 0
34221- 0 0 0 0 0 0 0 0 0 0 0 0
34222- 0 0 0 0 0 0 0 0 0 0 0 0
34223- 0 0 0 0 0 0 10 10 10 26 26 26
34224- 58 58 58 90 90 90 18 18 18 2 2 6
34225- 2 2 6 110 110 110 253 253 253 253 253 253
34226-253 253 253 253 253 253 253 253 253 253 253 253
34227-250 250 250 253 253 253 253 253 253 253 253 253
34228-253 253 253 253 253 253 253 253 253 253 253 253
34229-253 253 253 253 253 253 253 253 253 253 253 253
34230-253 253 253 231 231 231 18 18 18 2 2 6
34231- 2 2 6 2 2 6 2 2 6 2 2 6
34232- 2 2 6 2 2 6 18 18 18 94 94 94
34233- 54 54 54 26 26 26 10 10 10 0 0 0
34234- 0 0 0 0 0 0 0 0 0 0 0 0
34235- 0 0 0 0 0 0 0 0 0 0 0 0
34236- 0 0 0 0 0 0 0 0 0 0 0 0
34237- 0 0 0 0 0 0 0 0 0 0 0 0
34238- 0 0 0 0 0 0 0 0 0 0 0 0
34239- 0 0 0 0 0 0 0 0 0 0 0 0
34240- 0 0 0 0 0 0 0 0 0 0 0 0
34241- 0 0 0 0 0 0 0 0 0 0 0 0
34242- 0 0 0 0 0 0 0 0 0 0 0 0
34243- 0 0 0 6 6 6 22 22 22 50 50 50
34244- 90 90 90 26 26 26 2 2 6 2 2 6
34245- 14 14 14 195 195 195 250 250 250 253 253 253
34246-253 253 253 253 253 253 253 253 253 253 253 253
34247-253 253 253 253 253 253 253 253 253 253 253 253
34248-253 253 253 253 253 253 253 253 253 253 253 253
34249-253 253 253 253 253 253 253 253 253 253 253 253
34250-250 250 250 242 242 242 54 54 54 2 2 6
34251- 2 2 6 2 2 6 2 2 6 2 2 6
34252- 2 2 6 2 2 6 2 2 6 38 38 38
34253- 86 86 86 50 50 50 22 22 22 6 6 6
34254- 0 0 0 0 0 0 0 0 0 0 0 0
34255- 0 0 0 0 0 0 0 0 0 0 0 0
34256- 0 0 0 0 0 0 0 0 0 0 0 0
34257- 0 0 0 0 0 0 0 0 0 0 0 0
34258- 0 0 0 0 0 0 0 0 0 0 0 0
34259- 0 0 0 0 0 0 0 0 0 0 0 0
34260- 0 0 0 0 0 0 0 0 0 0 0 0
34261- 0 0 0 0 0 0 0 0 0 0 0 0
34262- 0 0 0 0 0 0 0 0 0 0 0 0
34263- 6 6 6 14 14 14 38 38 38 82 82 82
34264- 34 34 34 2 2 6 2 2 6 2 2 6
34265- 42 42 42 195 195 195 246 246 246 253 253 253
34266-253 253 253 253 253 253 253 253 253 250 250 250
34267-242 242 242 242 242 242 250 250 250 253 253 253
34268-253 253 253 253 253 253 253 253 253 253 253 253
34269-253 253 253 250 250 250 246 246 246 238 238 238
34270-226 226 226 231 231 231 101 101 101 6 6 6
34271- 2 2 6 2 2 6 2 2 6 2 2 6
34272- 2 2 6 2 2 6 2 2 6 2 2 6
34273- 38 38 38 82 82 82 42 42 42 14 14 14
34274- 6 6 6 0 0 0 0 0 0 0 0 0
34275- 0 0 0 0 0 0 0 0 0 0 0 0
34276- 0 0 0 0 0 0 0 0 0 0 0 0
34277- 0 0 0 0 0 0 0 0 0 0 0 0
34278- 0 0 0 0 0 0 0 0 0 0 0 0
34279- 0 0 0 0 0 0 0 0 0 0 0 0
34280- 0 0 0 0 0 0 0 0 0 0 0 0
34281- 0 0 0 0 0 0 0 0 0 0 0 0
34282- 0 0 0 0 0 0 0 0 0 0 0 0
34283- 10 10 10 26 26 26 62 62 62 66 66 66
34284- 2 2 6 2 2 6 2 2 6 6 6 6
34285- 70 70 70 170 170 170 206 206 206 234 234 234
34286-246 246 246 250 250 250 250 250 250 238 238 238
34287-226 226 226 231 231 231 238 238 238 250 250 250
34288-250 250 250 250 250 250 246 246 246 231 231 231
34289-214 214 214 206 206 206 202 202 202 202 202 202
34290-198 198 198 202 202 202 182 182 182 18 18 18
34291- 2 2 6 2 2 6 2 2 6 2 2 6
34292- 2 2 6 2 2 6 2 2 6 2 2 6
34293- 2 2 6 62 62 62 66 66 66 30 30 30
34294- 10 10 10 0 0 0 0 0 0 0 0 0
34295- 0 0 0 0 0 0 0 0 0 0 0 0
34296- 0 0 0 0 0 0 0 0 0 0 0 0
34297- 0 0 0 0 0 0 0 0 0 0 0 0
34298- 0 0 0 0 0 0 0 0 0 0 0 0
34299- 0 0 0 0 0 0 0 0 0 0 0 0
34300- 0 0 0 0 0 0 0 0 0 0 0 0
34301- 0 0 0 0 0 0 0 0 0 0 0 0
34302- 0 0 0 0 0 0 0 0 0 0 0 0
34303- 14 14 14 42 42 42 82 82 82 18 18 18
34304- 2 2 6 2 2 6 2 2 6 10 10 10
34305- 94 94 94 182 182 182 218 218 218 242 242 242
34306-250 250 250 253 253 253 253 253 253 250 250 250
34307-234 234 234 253 253 253 253 253 253 253 253 253
34308-253 253 253 253 253 253 253 253 253 246 246 246
34309-238 238 238 226 226 226 210 210 210 202 202 202
34310-195 195 195 195 195 195 210 210 210 158 158 158
34311- 6 6 6 14 14 14 50 50 50 14 14 14
34312- 2 2 6 2 2 6 2 2 6 2 2 6
34313- 2 2 6 6 6 6 86 86 86 46 46 46
34314- 18 18 18 6 6 6 0 0 0 0 0 0
34315- 0 0 0 0 0 0 0 0 0 0 0 0
34316- 0 0 0 0 0 0 0 0 0 0 0 0
34317- 0 0 0 0 0 0 0 0 0 0 0 0
34318- 0 0 0 0 0 0 0 0 0 0 0 0
34319- 0 0 0 0 0 0 0 0 0 0 0 0
34320- 0 0 0 0 0 0 0 0 0 0 0 0
34321- 0 0 0 0 0 0 0 0 0 0 0 0
34322- 0 0 0 0 0 0 0 0 0 6 6 6
34323- 22 22 22 54 54 54 70 70 70 2 2 6
34324- 2 2 6 10 10 10 2 2 6 22 22 22
34325-166 166 166 231 231 231 250 250 250 253 253 253
34326-253 253 253 253 253 253 253 253 253 250 250 250
34327-242 242 242 253 253 253 253 253 253 253 253 253
34328-253 253 253 253 253 253 253 253 253 253 253 253
34329-253 253 253 253 253 253 253 253 253 246 246 246
34330-231 231 231 206 206 206 198 198 198 226 226 226
34331- 94 94 94 2 2 6 6 6 6 38 38 38
34332- 30 30 30 2 2 6 2 2 6 2 2 6
34333- 2 2 6 2 2 6 62 62 62 66 66 66
34334- 26 26 26 10 10 10 0 0 0 0 0 0
34335- 0 0 0 0 0 0 0 0 0 0 0 0
34336- 0 0 0 0 0 0 0 0 0 0 0 0
34337- 0 0 0 0 0 0 0 0 0 0 0 0
34338- 0 0 0 0 0 0 0 0 0 0 0 0
34339- 0 0 0 0 0 0 0 0 0 0 0 0
34340- 0 0 0 0 0 0 0 0 0 0 0 0
34341- 0 0 0 0 0 0 0 0 0 0 0 0
34342- 0 0 0 0 0 0 0 0 0 10 10 10
34343- 30 30 30 74 74 74 50 50 50 2 2 6
34344- 26 26 26 26 26 26 2 2 6 106 106 106
34345-238 238 238 253 253 253 253 253 253 253 253 253
34346-253 253 253 253 253 253 253 253 253 253 253 253
34347-253 253 253 253 253 253 253 253 253 253 253 253
34348-253 253 253 253 253 253 253 253 253 253 253 253
34349-253 253 253 253 253 253 253 253 253 253 253 253
34350-253 253 253 246 246 246 218 218 218 202 202 202
34351-210 210 210 14 14 14 2 2 6 2 2 6
34352- 30 30 30 22 22 22 2 2 6 2 2 6
34353- 2 2 6 2 2 6 18 18 18 86 86 86
34354- 42 42 42 14 14 14 0 0 0 0 0 0
34355- 0 0 0 0 0 0 0 0 0 0 0 0
34356- 0 0 0 0 0 0 0 0 0 0 0 0
34357- 0 0 0 0 0 0 0 0 0 0 0 0
34358- 0 0 0 0 0 0 0 0 0 0 0 0
34359- 0 0 0 0 0 0 0 0 0 0 0 0
34360- 0 0 0 0 0 0 0 0 0 0 0 0
34361- 0 0 0 0 0 0 0 0 0 0 0 0
34362- 0 0 0 0 0 0 0 0 0 14 14 14
34363- 42 42 42 90 90 90 22 22 22 2 2 6
34364- 42 42 42 2 2 6 18 18 18 218 218 218
34365-253 253 253 253 253 253 253 253 253 253 253 253
34366-253 253 253 253 253 253 253 253 253 253 253 253
34367-253 253 253 253 253 253 253 253 253 253 253 253
34368-253 253 253 253 253 253 253 253 253 253 253 253
34369-253 253 253 253 253 253 253 253 253 253 253 253
34370-253 253 253 253 253 253 250 250 250 221 221 221
34371-218 218 218 101 101 101 2 2 6 14 14 14
34372- 18 18 18 38 38 38 10 10 10 2 2 6
34373- 2 2 6 2 2 6 2 2 6 78 78 78
34374- 58 58 58 22 22 22 6 6 6 0 0 0
34375- 0 0 0 0 0 0 0 0 0 0 0 0
34376- 0 0 0 0 0 0 0 0 0 0 0 0
34377- 0 0 0 0 0 0 0 0 0 0 0 0
34378- 0 0 0 0 0 0 0 0 0 0 0 0
34379- 0 0 0 0 0 0 0 0 0 0 0 0
34380- 0 0 0 0 0 0 0 0 0 0 0 0
34381- 0 0 0 0 0 0 0 0 0 0 0 0
34382- 0 0 0 0 0 0 6 6 6 18 18 18
34383- 54 54 54 82 82 82 2 2 6 26 26 26
34384- 22 22 22 2 2 6 123 123 123 253 253 253
34385-253 253 253 253 253 253 253 253 253 253 253 253
34386-253 253 253 253 253 253 253 253 253 253 253 253
34387-253 253 253 253 253 253 253 253 253 253 253 253
34388-253 253 253 253 253 253 253 253 253 253 253 253
34389-253 253 253 253 253 253 253 253 253 253 253 253
34390-253 253 253 253 253 253 253 253 253 250 250 250
34391-238 238 238 198 198 198 6 6 6 38 38 38
34392- 58 58 58 26 26 26 38 38 38 2 2 6
34393- 2 2 6 2 2 6 2 2 6 46 46 46
34394- 78 78 78 30 30 30 10 10 10 0 0 0
34395- 0 0 0 0 0 0 0 0 0 0 0 0
34396- 0 0 0 0 0 0 0 0 0 0 0 0
34397- 0 0 0 0 0 0 0 0 0 0 0 0
34398- 0 0 0 0 0 0 0 0 0 0 0 0
34399- 0 0 0 0 0 0 0 0 0 0 0 0
34400- 0 0 0 0 0 0 0 0 0 0 0 0
34401- 0 0 0 0 0 0 0 0 0 0 0 0
34402- 0 0 0 0 0 0 10 10 10 30 30 30
34403- 74 74 74 58 58 58 2 2 6 42 42 42
34404- 2 2 6 22 22 22 231 231 231 253 253 253
34405-253 253 253 253 253 253 253 253 253 253 253 253
34406-253 253 253 253 253 253 253 253 253 250 250 250
34407-253 253 253 253 253 253 253 253 253 253 253 253
34408-253 253 253 253 253 253 253 253 253 253 253 253
34409-253 253 253 253 253 253 253 253 253 253 253 253
34410-253 253 253 253 253 253 253 253 253 253 253 253
34411-253 253 253 246 246 246 46 46 46 38 38 38
34412- 42 42 42 14 14 14 38 38 38 14 14 14
34413- 2 2 6 2 2 6 2 2 6 6 6 6
34414- 86 86 86 46 46 46 14 14 14 0 0 0
34415- 0 0 0 0 0 0 0 0 0 0 0 0
34416- 0 0 0 0 0 0 0 0 0 0 0 0
34417- 0 0 0 0 0 0 0 0 0 0 0 0
34418- 0 0 0 0 0 0 0 0 0 0 0 0
34419- 0 0 0 0 0 0 0 0 0 0 0 0
34420- 0 0 0 0 0 0 0 0 0 0 0 0
34421- 0 0 0 0 0 0 0 0 0 0 0 0
34422- 0 0 0 6 6 6 14 14 14 42 42 42
34423- 90 90 90 18 18 18 18 18 18 26 26 26
34424- 2 2 6 116 116 116 253 253 253 253 253 253
34425-253 253 253 253 253 253 253 253 253 253 253 253
34426-253 253 253 253 253 253 250 250 250 238 238 238
34427-253 253 253 253 253 253 253 253 253 253 253 253
34428-253 253 253 253 253 253 253 253 253 253 253 253
34429-253 253 253 253 253 253 253 253 253 253 253 253
34430-253 253 253 253 253 253 253 253 253 253 253 253
34431-253 253 253 253 253 253 94 94 94 6 6 6
34432- 2 2 6 2 2 6 10 10 10 34 34 34
34433- 2 2 6 2 2 6 2 2 6 2 2 6
34434- 74 74 74 58 58 58 22 22 22 6 6 6
34435- 0 0 0 0 0 0 0 0 0 0 0 0
34436- 0 0 0 0 0 0 0 0 0 0 0 0
34437- 0 0 0 0 0 0 0 0 0 0 0 0
34438- 0 0 0 0 0 0 0 0 0 0 0 0
34439- 0 0 0 0 0 0 0 0 0 0 0 0
34440- 0 0 0 0 0 0 0 0 0 0 0 0
34441- 0 0 0 0 0 0 0 0 0 0 0 0
34442- 0 0 0 10 10 10 26 26 26 66 66 66
34443- 82 82 82 2 2 6 38 38 38 6 6 6
34444- 14 14 14 210 210 210 253 253 253 253 253 253
34445-253 253 253 253 253 253 253 253 253 253 253 253
34446-253 253 253 253 253 253 246 246 246 242 242 242
34447-253 253 253 253 253 253 253 253 253 253 253 253
34448-253 253 253 253 253 253 253 253 253 253 253 253
34449-253 253 253 253 253 253 253 253 253 253 253 253
34450-253 253 253 253 253 253 253 253 253 253 253 253
34451-253 253 253 253 253 253 144 144 144 2 2 6
34452- 2 2 6 2 2 6 2 2 6 46 46 46
34453- 2 2 6 2 2 6 2 2 6 2 2 6
34454- 42 42 42 74 74 74 30 30 30 10 10 10
34455- 0 0 0 0 0 0 0 0 0 0 0 0
34456- 0 0 0 0 0 0 0 0 0 0 0 0
34457- 0 0 0 0 0 0 0 0 0 0 0 0
34458- 0 0 0 0 0 0 0 0 0 0 0 0
34459- 0 0 0 0 0 0 0 0 0 0 0 0
34460- 0 0 0 0 0 0 0 0 0 0 0 0
34461- 0 0 0 0 0 0 0 0 0 0 0 0
34462- 6 6 6 14 14 14 42 42 42 90 90 90
34463- 26 26 26 6 6 6 42 42 42 2 2 6
34464- 74 74 74 250 250 250 253 253 253 253 253 253
34465-253 253 253 253 253 253 253 253 253 253 253 253
34466-253 253 253 253 253 253 242 242 242 242 242 242
34467-253 253 253 253 253 253 253 253 253 253 253 253
34468-253 253 253 253 253 253 253 253 253 253 253 253
34469-253 253 253 253 253 253 253 253 253 253 253 253
34470-253 253 253 253 253 253 253 253 253 253 253 253
34471-253 253 253 253 253 253 182 182 182 2 2 6
34472- 2 2 6 2 2 6 2 2 6 46 46 46
34473- 2 2 6 2 2 6 2 2 6 2 2 6
34474- 10 10 10 86 86 86 38 38 38 10 10 10
34475- 0 0 0 0 0 0 0 0 0 0 0 0
34476- 0 0 0 0 0 0 0 0 0 0 0 0
34477- 0 0 0 0 0 0 0 0 0 0 0 0
34478- 0 0 0 0 0 0 0 0 0 0 0 0
34479- 0 0 0 0 0 0 0 0 0 0 0 0
34480- 0 0 0 0 0 0 0 0 0 0 0 0
34481- 0 0 0 0 0 0 0 0 0 0 0 0
34482- 10 10 10 26 26 26 66 66 66 82 82 82
34483- 2 2 6 22 22 22 18 18 18 2 2 6
34484-149 149 149 253 253 253 253 253 253 253 253 253
34485-253 253 253 253 253 253 253 253 253 253 253 253
34486-253 253 253 253 253 253 234 234 234 242 242 242
34487-253 253 253 253 253 253 253 253 253 253 253 253
34488-253 253 253 253 253 253 253 253 253 253 253 253
34489-253 253 253 253 253 253 253 253 253 253 253 253
34490-253 253 253 253 253 253 253 253 253 253 253 253
34491-253 253 253 253 253 253 206 206 206 2 2 6
34492- 2 2 6 2 2 6 2 2 6 38 38 38
34493- 2 2 6 2 2 6 2 2 6 2 2 6
34494- 6 6 6 86 86 86 46 46 46 14 14 14
34495- 0 0 0 0 0 0 0 0 0 0 0 0
34496- 0 0 0 0 0 0 0 0 0 0 0 0
34497- 0 0 0 0 0 0 0 0 0 0 0 0
34498- 0 0 0 0 0 0 0 0 0 0 0 0
34499- 0 0 0 0 0 0 0 0 0 0 0 0
34500- 0 0 0 0 0 0 0 0 0 0 0 0
34501- 0 0 0 0 0 0 0 0 0 6 6 6
34502- 18 18 18 46 46 46 86 86 86 18 18 18
34503- 2 2 6 34 34 34 10 10 10 6 6 6
34504-210 210 210 253 253 253 253 253 253 253 253 253
34505-253 253 253 253 253 253 253 253 253 253 253 253
34506-253 253 253 253 253 253 234 234 234 242 242 242
34507-253 253 253 253 253 253 253 253 253 253 253 253
34508-253 253 253 253 253 253 253 253 253 253 253 253
34509-253 253 253 253 253 253 253 253 253 253 253 253
34510-253 253 253 253 253 253 253 253 253 253 253 253
34511-253 253 253 253 253 253 221 221 221 6 6 6
34512- 2 2 6 2 2 6 6 6 6 30 30 30
34513- 2 2 6 2 2 6 2 2 6 2 2 6
34514- 2 2 6 82 82 82 54 54 54 18 18 18
34515- 6 6 6 0 0 0 0 0 0 0 0 0
34516- 0 0 0 0 0 0 0 0 0 0 0 0
34517- 0 0 0 0 0 0 0 0 0 0 0 0
34518- 0 0 0 0 0 0 0 0 0 0 0 0
34519- 0 0 0 0 0 0 0 0 0 0 0 0
34520- 0 0 0 0 0 0 0 0 0 0 0 0
34521- 0 0 0 0 0 0 0 0 0 10 10 10
34522- 26 26 26 66 66 66 62 62 62 2 2 6
34523- 2 2 6 38 38 38 10 10 10 26 26 26
34524-238 238 238 253 253 253 253 253 253 253 253 253
34525-253 253 253 253 253 253 253 253 253 253 253 253
34526-253 253 253 253 253 253 231 231 231 238 238 238
34527-253 253 253 253 253 253 253 253 253 253 253 253
34528-253 253 253 253 253 253 253 253 253 253 253 253
34529-253 253 253 253 253 253 253 253 253 253 253 253
34530-253 253 253 253 253 253 253 253 253 253 253 253
34531-253 253 253 253 253 253 231 231 231 6 6 6
34532- 2 2 6 2 2 6 10 10 10 30 30 30
34533- 2 2 6 2 2 6 2 2 6 2 2 6
34534- 2 2 6 66 66 66 58 58 58 22 22 22
34535- 6 6 6 0 0 0 0 0 0 0 0 0
34536- 0 0 0 0 0 0 0 0 0 0 0 0
34537- 0 0 0 0 0 0 0 0 0 0 0 0
34538- 0 0 0 0 0 0 0 0 0 0 0 0
34539- 0 0 0 0 0 0 0 0 0 0 0 0
34540- 0 0 0 0 0 0 0 0 0 0 0 0
34541- 0 0 0 0 0 0 0 0 0 10 10 10
34542- 38 38 38 78 78 78 6 6 6 2 2 6
34543- 2 2 6 46 46 46 14 14 14 42 42 42
34544-246 246 246 253 253 253 253 253 253 253 253 253
34545-253 253 253 253 253 253 253 253 253 253 253 253
34546-253 253 253 253 253 253 231 231 231 242 242 242
34547-253 253 253 253 253 253 253 253 253 253 253 253
34548-253 253 253 253 253 253 253 253 253 253 253 253
34549-253 253 253 253 253 253 253 253 253 253 253 253
34550-253 253 253 253 253 253 253 253 253 253 253 253
34551-253 253 253 253 253 253 234 234 234 10 10 10
34552- 2 2 6 2 2 6 22 22 22 14 14 14
34553- 2 2 6 2 2 6 2 2 6 2 2 6
34554- 2 2 6 66 66 66 62 62 62 22 22 22
34555- 6 6 6 0 0 0 0 0 0 0 0 0
34556- 0 0 0 0 0 0 0 0 0 0 0 0
34557- 0 0 0 0 0 0 0 0 0 0 0 0
34558- 0 0 0 0 0 0 0 0 0 0 0 0
34559- 0 0 0 0 0 0 0 0 0 0 0 0
34560- 0 0 0 0 0 0 0 0 0 0 0 0
34561- 0 0 0 0 0 0 6 6 6 18 18 18
34562- 50 50 50 74 74 74 2 2 6 2 2 6
34563- 14 14 14 70 70 70 34 34 34 62 62 62
34564-250 250 250 253 253 253 253 253 253 253 253 253
34565-253 253 253 253 253 253 253 253 253 253 253 253
34566-253 253 253 253 253 253 231 231 231 246 246 246
34567-253 253 253 253 253 253 253 253 253 253 253 253
34568-253 253 253 253 253 253 253 253 253 253 253 253
34569-253 253 253 253 253 253 253 253 253 253 253 253
34570-253 253 253 253 253 253 253 253 253 253 253 253
34571-253 253 253 253 253 253 234 234 234 14 14 14
34572- 2 2 6 2 2 6 30 30 30 2 2 6
34573- 2 2 6 2 2 6 2 2 6 2 2 6
34574- 2 2 6 66 66 66 62 62 62 22 22 22
34575- 6 6 6 0 0 0 0 0 0 0 0 0
34576- 0 0 0 0 0 0 0 0 0 0 0 0
34577- 0 0 0 0 0 0 0 0 0 0 0 0
34578- 0 0 0 0 0 0 0 0 0 0 0 0
34579- 0 0 0 0 0 0 0 0 0 0 0 0
34580- 0 0 0 0 0 0 0 0 0 0 0 0
34581- 0 0 0 0 0 0 6 6 6 18 18 18
34582- 54 54 54 62 62 62 2 2 6 2 2 6
34583- 2 2 6 30 30 30 46 46 46 70 70 70
34584-250 250 250 253 253 253 253 253 253 253 253 253
34585-253 253 253 253 253 253 253 253 253 253 253 253
34586-253 253 253 253 253 253 231 231 231 246 246 246
34587-253 253 253 253 253 253 253 253 253 253 253 253
34588-253 253 253 253 253 253 253 253 253 253 253 253
34589-253 253 253 253 253 253 253 253 253 253 253 253
34590-253 253 253 253 253 253 253 253 253 253 253 253
34591-253 253 253 253 253 253 226 226 226 10 10 10
34592- 2 2 6 6 6 6 30 30 30 2 2 6
34593- 2 2 6 2 2 6 2 2 6 2 2 6
34594- 2 2 6 66 66 66 58 58 58 22 22 22
34595- 6 6 6 0 0 0 0 0 0 0 0 0
34596- 0 0 0 0 0 0 0 0 0 0 0 0
34597- 0 0 0 0 0 0 0 0 0 0 0 0
34598- 0 0 0 0 0 0 0 0 0 0 0 0
34599- 0 0 0 0 0 0 0 0 0 0 0 0
34600- 0 0 0 0 0 0 0 0 0 0 0 0
34601- 0 0 0 0 0 0 6 6 6 22 22 22
34602- 58 58 58 62 62 62 2 2 6 2 2 6
34603- 2 2 6 2 2 6 30 30 30 78 78 78
34604-250 250 250 253 253 253 253 253 253 253 253 253
34605-253 253 253 253 253 253 253 253 253 253 253 253
34606-253 253 253 253 253 253 231 231 231 246 246 246
34607-253 253 253 253 253 253 253 253 253 253 253 253
34608-253 253 253 253 253 253 253 253 253 253 253 253
34609-253 253 253 253 253 253 253 253 253 253 253 253
34610-253 253 253 253 253 253 253 253 253 253 253 253
34611-253 253 253 253 253 253 206 206 206 2 2 6
34612- 22 22 22 34 34 34 18 14 6 22 22 22
34613- 26 26 26 18 18 18 6 6 6 2 2 6
34614- 2 2 6 82 82 82 54 54 54 18 18 18
34615- 6 6 6 0 0 0 0 0 0 0 0 0
34616- 0 0 0 0 0 0 0 0 0 0 0 0
34617- 0 0 0 0 0 0 0 0 0 0 0 0
34618- 0 0 0 0 0 0 0 0 0 0 0 0
34619- 0 0 0 0 0 0 0 0 0 0 0 0
34620- 0 0 0 0 0 0 0 0 0 0 0 0
34621- 0 0 0 0 0 0 6 6 6 26 26 26
34622- 62 62 62 106 106 106 74 54 14 185 133 11
34623-210 162 10 121 92 8 6 6 6 62 62 62
34624-238 238 238 253 253 253 253 253 253 253 253 253
34625-253 253 253 253 253 253 253 253 253 253 253 253
34626-253 253 253 253 253 253 231 231 231 246 246 246
34627-253 253 253 253 253 253 253 253 253 253 253 253
34628-253 253 253 253 253 253 253 253 253 253 253 253
34629-253 253 253 253 253 253 253 253 253 253 253 253
34630-253 253 253 253 253 253 253 253 253 253 253 253
34631-253 253 253 253 253 253 158 158 158 18 18 18
34632- 14 14 14 2 2 6 2 2 6 2 2 6
34633- 6 6 6 18 18 18 66 66 66 38 38 38
34634- 6 6 6 94 94 94 50 50 50 18 18 18
34635- 6 6 6 0 0 0 0 0 0 0 0 0
34636- 0 0 0 0 0 0 0 0 0 0 0 0
34637- 0 0 0 0 0 0 0 0 0 0 0 0
34638- 0 0 0 0 0 0 0 0 0 0 0 0
34639- 0 0 0 0 0 0 0 0 0 0 0 0
34640- 0 0 0 0 0 0 0 0 0 6 6 6
34641- 10 10 10 10 10 10 18 18 18 38 38 38
34642- 78 78 78 142 134 106 216 158 10 242 186 14
34643-246 190 14 246 190 14 156 118 10 10 10 10
34644- 90 90 90 238 238 238 253 253 253 253 253 253
34645-253 253 253 253 253 253 253 253 253 253 253 253
34646-253 253 253 253 253 253 231 231 231 250 250 250
34647-253 253 253 253 253 253 253 253 253 253 253 253
34648-253 253 253 253 253 253 253 253 253 253 253 253
34649-253 253 253 253 253 253 253 253 253 253 253 253
34650-253 253 253 253 253 253 253 253 253 246 230 190
34651-238 204 91 238 204 91 181 142 44 37 26 9
34652- 2 2 6 2 2 6 2 2 6 2 2 6
34653- 2 2 6 2 2 6 38 38 38 46 46 46
34654- 26 26 26 106 106 106 54 54 54 18 18 18
34655- 6 6 6 0 0 0 0 0 0 0 0 0
34656- 0 0 0 0 0 0 0 0 0 0 0 0
34657- 0 0 0 0 0 0 0 0 0 0 0 0
34658- 0 0 0 0 0 0 0 0 0 0 0 0
34659- 0 0 0 0 0 0 0 0 0 0 0 0
34660- 0 0 0 6 6 6 14 14 14 22 22 22
34661- 30 30 30 38 38 38 50 50 50 70 70 70
34662-106 106 106 190 142 34 226 170 11 242 186 14
34663-246 190 14 246 190 14 246 190 14 154 114 10
34664- 6 6 6 74 74 74 226 226 226 253 253 253
34665-253 253 253 253 253 253 253 253 253 253 253 253
34666-253 253 253 253 253 253 231 231 231 250 250 250
34667-253 253 253 253 253 253 253 253 253 253 253 253
34668-253 253 253 253 253 253 253 253 253 253 253 253
34669-253 253 253 253 253 253 253 253 253 253 253 253
34670-253 253 253 253 253 253 253 253 253 228 184 62
34671-241 196 14 241 208 19 232 195 16 38 30 10
34672- 2 2 6 2 2 6 2 2 6 2 2 6
34673- 2 2 6 6 6 6 30 30 30 26 26 26
34674-203 166 17 154 142 90 66 66 66 26 26 26
34675- 6 6 6 0 0 0 0 0 0 0 0 0
34676- 0 0 0 0 0 0 0 0 0 0 0 0
34677- 0 0 0 0 0 0 0 0 0 0 0 0
34678- 0 0 0 0 0 0 0 0 0 0 0 0
34679- 0 0 0 0 0 0 0 0 0 0 0 0
34680- 6 6 6 18 18 18 38 38 38 58 58 58
34681- 78 78 78 86 86 86 101 101 101 123 123 123
34682-175 146 61 210 150 10 234 174 13 246 186 14
34683-246 190 14 246 190 14 246 190 14 238 190 10
34684-102 78 10 2 2 6 46 46 46 198 198 198
34685-253 253 253 253 253 253 253 253 253 253 253 253
34686-253 253 253 253 253 253 234 234 234 242 242 242
34687-253 253 253 253 253 253 253 253 253 253 253 253
34688-253 253 253 253 253 253 253 253 253 253 253 253
34689-253 253 253 253 253 253 253 253 253 253 253 253
34690-253 253 253 253 253 253 253 253 253 224 178 62
34691-242 186 14 241 196 14 210 166 10 22 18 6
34692- 2 2 6 2 2 6 2 2 6 2 2 6
34693- 2 2 6 2 2 6 6 6 6 121 92 8
34694-238 202 15 232 195 16 82 82 82 34 34 34
34695- 10 10 10 0 0 0 0 0 0 0 0 0
34696- 0 0 0 0 0 0 0 0 0 0 0 0
34697- 0 0 0 0 0 0 0 0 0 0 0 0
34698- 0 0 0 0 0 0 0 0 0 0 0 0
34699- 0 0 0 0 0 0 0 0 0 0 0 0
34700- 14 14 14 38 38 38 70 70 70 154 122 46
34701-190 142 34 200 144 11 197 138 11 197 138 11
34702-213 154 11 226 170 11 242 186 14 246 190 14
34703-246 190 14 246 190 14 246 190 14 246 190 14
34704-225 175 15 46 32 6 2 2 6 22 22 22
34705-158 158 158 250 250 250 253 253 253 253 253 253
34706-253 253 253 253 253 253 253 253 253 253 253 253
34707-253 253 253 253 253 253 253 253 253 253 253 253
34708-253 253 253 253 253 253 253 253 253 253 253 253
34709-253 253 253 253 253 253 253 253 253 253 253 253
34710-253 253 253 250 250 250 242 242 242 224 178 62
34711-239 182 13 236 186 11 213 154 11 46 32 6
34712- 2 2 6 2 2 6 2 2 6 2 2 6
34713- 2 2 6 2 2 6 61 42 6 225 175 15
34714-238 190 10 236 186 11 112 100 78 42 42 42
34715- 14 14 14 0 0 0 0 0 0 0 0 0
34716- 0 0 0 0 0 0 0 0 0 0 0 0
34717- 0 0 0 0 0 0 0 0 0 0 0 0
34718- 0 0 0 0 0 0 0 0 0 0 0 0
34719- 0 0 0 0 0 0 0 0 0 6 6 6
34720- 22 22 22 54 54 54 154 122 46 213 154 11
34721-226 170 11 230 174 11 226 170 11 226 170 11
34722-236 178 12 242 186 14 246 190 14 246 190 14
34723-246 190 14 246 190 14 246 190 14 246 190 14
34724-241 196 14 184 144 12 10 10 10 2 2 6
34725- 6 6 6 116 116 116 242 242 242 253 253 253
34726-253 253 253 253 253 253 253 253 253 253 253 253
34727-253 253 253 253 253 253 253 253 253 253 253 253
34728-253 253 253 253 253 253 253 253 253 253 253 253
34729-253 253 253 253 253 253 253 253 253 253 253 253
34730-253 253 253 231 231 231 198 198 198 214 170 54
34731-236 178 12 236 178 12 210 150 10 137 92 6
34732- 18 14 6 2 2 6 2 2 6 2 2 6
34733- 6 6 6 70 47 6 200 144 11 236 178 12
34734-239 182 13 239 182 13 124 112 88 58 58 58
34735- 22 22 22 6 6 6 0 0 0 0 0 0
34736- 0 0 0 0 0 0 0 0 0 0 0 0
34737- 0 0 0 0 0 0 0 0 0 0 0 0
34738- 0 0 0 0 0 0 0 0 0 0 0 0
34739- 0 0 0 0 0 0 0 0 0 10 10 10
34740- 30 30 30 70 70 70 180 133 36 226 170 11
34741-239 182 13 242 186 14 242 186 14 246 186 14
34742-246 190 14 246 190 14 246 190 14 246 190 14
34743-246 190 14 246 190 14 246 190 14 246 190 14
34744-246 190 14 232 195 16 98 70 6 2 2 6
34745- 2 2 6 2 2 6 66 66 66 221 221 221
34746-253 253 253 253 253 253 253 253 253 253 253 253
34747-253 253 253 253 253 253 253 253 253 253 253 253
34748-253 253 253 253 253 253 253 253 253 253 253 253
34749-253 253 253 253 253 253 253 253 253 253 253 253
34750-253 253 253 206 206 206 198 198 198 214 166 58
34751-230 174 11 230 174 11 216 158 10 192 133 9
34752-163 110 8 116 81 8 102 78 10 116 81 8
34753-167 114 7 197 138 11 226 170 11 239 182 13
34754-242 186 14 242 186 14 162 146 94 78 78 78
34755- 34 34 34 14 14 14 6 6 6 0 0 0
34756- 0 0 0 0 0 0 0 0 0 0 0 0
34757- 0 0 0 0 0 0 0 0 0 0 0 0
34758- 0 0 0 0 0 0 0 0 0 0 0 0
34759- 0 0 0 0 0 0 0 0 0 6 6 6
34760- 30 30 30 78 78 78 190 142 34 226 170 11
34761-239 182 13 246 190 14 246 190 14 246 190 14
34762-246 190 14 246 190 14 246 190 14 246 190 14
34763-246 190 14 246 190 14 246 190 14 246 190 14
34764-246 190 14 241 196 14 203 166 17 22 18 6
34765- 2 2 6 2 2 6 2 2 6 38 38 38
34766-218 218 218 253 253 253 253 253 253 253 253 253
34767-253 253 253 253 253 253 253 253 253 253 253 253
34768-253 253 253 253 253 253 253 253 253 253 253 253
34769-253 253 253 253 253 253 253 253 253 253 253 253
34770-250 250 250 206 206 206 198 198 198 202 162 69
34771-226 170 11 236 178 12 224 166 10 210 150 10
34772-200 144 11 197 138 11 192 133 9 197 138 11
34773-210 150 10 226 170 11 242 186 14 246 190 14
34774-246 190 14 246 186 14 225 175 15 124 112 88
34775- 62 62 62 30 30 30 14 14 14 6 6 6
34776- 0 0 0 0 0 0 0 0 0 0 0 0
34777- 0 0 0 0 0 0 0 0 0 0 0 0
34778- 0 0 0 0 0 0 0 0 0 0 0 0
34779- 0 0 0 0 0 0 0 0 0 10 10 10
34780- 30 30 30 78 78 78 174 135 50 224 166 10
34781-239 182 13 246 190 14 246 190 14 246 190 14
34782-246 190 14 246 190 14 246 190 14 246 190 14
34783-246 190 14 246 190 14 246 190 14 246 190 14
34784-246 190 14 246 190 14 241 196 14 139 102 15
34785- 2 2 6 2 2 6 2 2 6 2 2 6
34786- 78 78 78 250 250 250 253 253 253 253 253 253
34787-253 253 253 253 253 253 253 253 253 253 253 253
34788-253 253 253 253 253 253 253 253 253 253 253 253
34789-253 253 253 253 253 253 253 253 253 253 253 253
34790-250 250 250 214 214 214 198 198 198 190 150 46
34791-219 162 10 236 178 12 234 174 13 224 166 10
34792-216 158 10 213 154 11 213 154 11 216 158 10
34793-226 170 11 239 182 13 246 190 14 246 190 14
34794-246 190 14 246 190 14 242 186 14 206 162 42
34795-101 101 101 58 58 58 30 30 30 14 14 14
34796- 6 6 6 0 0 0 0 0 0 0 0 0
34797- 0 0 0 0 0 0 0 0 0 0 0 0
34798- 0 0 0 0 0 0 0 0 0 0 0 0
34799- 0 0 0 0 0 0 0 0 0 10 10 10
34800- 30 30 30 74 74 74 174 135 50 216 158 10
34801-236 178 12 246 190 14 246 190 14 246 190 14
34802-246 190 14 246 190 14 246 190 14 246 190 14
34803-246 190 14 246 190 14 246 190 14 246 190 14
34804-246 190 14 246 190 14 241 196 14 226 184 13
34805- 61 42 6 2 2 6 2 2 6 2 2 6
34806- 22 22 22 238 238 238 253 253 253 253 253 253
34807-253 253 253 253 253 253 253 253 253 253 253 253
34808-253 253 253 253 253 253 253 253 253 253 253 253
34809-253 253 253 253 253 253 253 253 253 253 253 253
34810-253 253 253 226 226 226 187 187 187 180 133 36
34811-216 158 10 236 178 12 239 182 13 236 178 12
34812-230 174 11 226 170 11 226 170 11 230 174 11
34813-236 178 12 242 186 14 246 190 14 246 190 14
34814-246 190 14 246 190 14 246 186 14 239 182 13
34815-206 162 42 106 106 106 66 66 66 34 34 34
34816- 14 14 14 6 6 6 0 0 0 0 0 0
34817- 0 0 0 0 0 0 0 0 0 0 0 0
34818- 0 0 0 0 0 0 0 0 0 0 0 0
34819- 0 0 0 0 0 0 0 0 0 6 6 6
34820- 26 26 26 70 70 70 163 133 67 213 154 11
34821-236 178 12 246 190 14 246 190 14 246 190 14
34822-246 190 14 246 190 14 246 190 14 246 190 14
34823-246 190 14 246 190 14 246 190 14 246 190 14
34824-246 190 14 246 190 14 246 190 14 241 196 14
34825-190 146 13 18 14 6 2 2 6 2 2 6
34826- 46 46 46 246 246 246 253 253 253 253 253 253
34827-253 253 253 253 253 253 253 253 253 253 253 253
34828-253 253 253 253 253 253 253 253 253 253 253 253
34829-253 253 253 253 253 253 253 253 253 253 253 253
34830-253 253 253 221 221 221 86 86 86 156 107 11
34831-216 158 10 236 178 12 242 186 14 246 186 14
34832-242 186 14 239 182 13 239 182 13 242 186 14
34833-242 186 14 246 186 14 246 190 14 246 190 14
34834-246 190 14 246 190 14 246 190 14 246 190 14
34835-242 186 14 225 175 15 142 122 72 66 66 66
34836- 30 30 30 10 10 10 0 0 0 0 0 0
34837- 0 0 0 0 0 0 0 0 0 0 0 0
34838- 0 0 0 0 0 0 0 0 0 0 0 0
34839- 0 0 0 0 0 0 0 0 0 6 6 6
34840- 26 26 26 70 70 70 163 133 67 210 150 10
34841-236 178 12 246 190 14 246 190 14 246 190 14
34842-246 190 14 246 190 14 246 190 14 246 190 14
34843-246 190 14 246 190 14 246 190 14 246 190 14
34844-246 190 14 246 190 14 246 190 14 246 190 14
34845-232 195 16 121 92 8 34 34 34 106 106 106
34846-221 221 221 253 253 253 253 253 253 253 253 253
34847-253 253 253 253 253 253 253 253 253 253 253 253
34848-253 253 253 253 253 253 253 253 253 253 253 253
34849-253 253 253 253 253 253 253 253 253 253 253 253
34850-242 242 242 82 82 82 18 14 6 163 110 8
34851-216 158 10 236 178 12 242 186 14 246 190 14
34852-246 190 14 246 190 14 246 190 14 246 190 14
34853-246 190 14 246 190 14 246 190 14 246 190 14
34854-246 190 14 246 190 14 246 190 14 246 190 14
34855-246 190 14 246 190 14 242 186 14 163 133 67
34856- 46 46 46 18 18 18 6 6 6 0 0 0
34857- 0 0 0 0 0 0 0 0 0 0 0 0
34858- 0 0 0 0 0 0 0 0 0 0 0 0
34859- 0 0 0 0 0 0 0 0 0 10 10 10
34860- 30 30 30 78 78 78 163 133 67 210 150 10
34861-236 178 12 246 186 14 246 190 14 246 190 14
34862-246 190 14 246 190 14 246 190 14 246 190 14
34863-246 190 14 246 190 14 246 190 14 246 190 14
34864-246 190 14 246 190 14 246 190 14 246 190 14
34865-241 196 14 215 174 15 190 178 144 253 253 253
34866-253 253 253 253 253 253 253 253 253 253 253 253
34867-253 253 253 253 253 253 253 253 253 253 253 253
34868-253 253 253 253 253 253 253 253 253 253 253 253
34869-253 253 253 253 253 253 253 253 253 218 218 218
34870- 58 58 58 2 2 6 22 18 6 167 114 7
34871-216 158 10 236 178 12 246 186 14 246 190 14
34872-246 190 14 246 190 14 246 190 14 246 190 14
34873-246 190 14 246 190 14 246 190 14 246 190 14
34874-246 190 14 246 190 14 246 190 14 246 190 14
34875-246 190 14 246 186 14 242 186 14 190 150 46
34876- 54 54 54 22 22 22 6 6 6 0 0 0
34877- 0 0 0 0 0 0 0 0 0 0 0 0
34878- 0 0 0 0 0 0 0 0 0 0 0 0
34879- 0 0 0 0 0 0 0 0 0 14 14 14
34880- 38 38 38 86 86 86 180 133 36 213 154 11
34881-236 178 12 246 186 14 246 190 14 246 190 14
34882-246 190 14 246 190 14 246 190 14 246 190 14
34883-246 190 14 246 190 14 246 190 14 246 190 14
34884-246 190 14 246 190 14 246 190 14 246 190 14
34885-246 190 14 232 195 16 190 146 13 214 214 214
34886-253 253 253 253 253 253 253 253 253 253 253 253
34887-253 253 253 253 253 253 253 253 253 253 253 253
34888-253 253 253 253 253 253 253 253 253 253 253 253
34889-253 253 253 250 250 250 170 170 170 26 26 26
34890- 2 2 6 2 2 6 37 26 9 163 110 8
34891-219 162 10 239 182 13 246 186 14 246 190 14
34892-246 190 14 246 190 14 246 190 14 246 190 14
34893-246 190 14 246 190 14 246 190 14 246 190 14
34894-246 190 14 246 190 14 246 190 14 246 190 14
34895-246 186 14 236 178 12 224 166 10 142 122 72
34896- 46 46 46 18 18 18 6 6 6 0 0 0
34897- 0 0 0 0 0 0 0 0 0 0 0 0
34898- 0 0 0 0 0 0 0 0 0 0 0 0
34899- 0 0 0 0 0 0 6 6 6 18 18 18
34900- 50 50 50 109 106 95 192 133 9 224 166 10
34901-242 186 14 246 190 14 246 190 14 246 190 14
34902-246 190 14 246 190 14 246 190 14 246 190 14
34903-246 190 14 246 190 14 246 190 14 246 190 14
34904-246 190 14 246 190 14 246 190 14 246 190 14
34905-242 186 14 226 184 13 210 162 10 142 110 46
34906-226 226 226 253 253 253 253 253 253 253 253 253
34907-253 253 253 253 253 253 253 253 253 253 253 253
34908-253 253 253 253 253 253 253 253 253 253 253 253
34909-198 198 198 66 66 66 2 2 6 2 2 6
34910- 2 2 6 2 2 6 50 34 6 156 107 11
34911-219 162 10 239 182 13 246 186 14 246 190 14
34912-246 190 14 246 190 14 246 190 14 246 190 14
34913-246 190 14 246 190 14 246 190 14 246 190 14
34914-246 190 14 246 190 14 246 190 14 242 186 14
34915-234 174 13 213 154 11 154 122 46 66 66 66
34916- 30 30 30 10 10 10 0 0 0 0 0 0
34917- 0 0 0 0 0 0 0 0 0 0 0 0
34918- 0 0 0 0 0 0 0 0 0 0 0 0
34919- 0 0 0 0 0 0 6 6 6 22 22 22
34920- 58 58 58 154 121 60 206 145 10 234 174 13
34921-242 186 14 246 186 14 246 190 14 246 190 14
34922-246 190 14 246 190 14 246 190 14 246 190 14
34923-246 190 14 246 190 14 246 190 14 246 190 14
34924-246 190 14 246 190 14 246 190 14 246 190 14
34925-246 186 14 236 178 12 210 162 10 163 110 8
34926- 61 42 6 138 138 138 218 218 218 250 250 250
34927-253 253 253 253 253 253 253 253 253 250 250 250
34928-242 242 242 210 210 210 144 144 144 66 66 66
34929- 6 6 6 2 2 6 2 2 6 2 2 6
34930- 2 2 6 2 2 6 61 42 6 163 110 8
34931-216 158 10 236 178 12 246 190 14 246 190 14
34932-246 190 14 246 190 14 246 190 14 246 190 14
34933-246 190 14 246 190 14 246 190 14 246 190 14
34934-246 190 14 239 182 13 230 174 11 216 158 10
34935-190 142 34 124 112 88 70 70 70 38 38 38
34936- 18 18 18 6 6 6 0 0 0 0 0 0
34937- 0 0 0 0 0 0 0 0 0 0 0 0
34938- 0 0 0 0 0 0 0 0 0 0 0 0
34939- 0 0 0 0 0 0 6 6 6 22 22 22
34940- 62 62 62 168 124 44 206 145 10 224 166 10
34941-236 178 12 239 182 13 242 186 14 242 186 14
34942-246 186 14 246 190 14 246 190 14 246 190 14
34943-246 190 14 246 190 14 246 190 14 246 190 14
34944-246 190 14 246 190 14 246 190 14 246 190 14
34945-246 190 14 236 178 12 216 158 10 175 118 6
34946- 80 54 7 2 2 6 6 6 6 30 30 30
34947- 54 54 54 62 62 62 50 50 50 38 38 38
34948- 14 14 14 2 2 6 2 2 6 2 2 6
34949- 2 2 6 2 2 6 2 2 6 2 2 6
34950- 2 2 6 6 6 6 80 54 7 167 114 7
34951-213 154 11 236 178 12 246 190 14 246 190 14
34952-246 190 14 246 190 14 246 190 14 246 190 14
34953-246 190 14 242 186 14 239 182 13 239 182 13
34954-230 174 11 210 150 10 174 135 50 124 112 88
34955- 82 82 82 54 54 54 34 34 34 18 18 18
34956- 6 6 6 0 0 0 0 0 0 0 0 0
34957- 0 0 0 0 0 0 0 0 0 0 0 0
34958- 0 0 0 0 0 0 0 0 0 0 0 0
34959- 0 0 0 0 0 0 6 6 6 18 18 18
34960- 50 50 50 158 118 36 192 133 9 200 144 11
34961-216 158 10 219 162 10 224 166 10 226 170 11
34962-230 174 11 236 178 12 239 182 13 239 182 13
34963-242 186 14 246 186 14 246 190 14 246 190 14
34964-246 190 14 246 190 14 246 190 14 246 190 14
34965-246 186 14 230 174 11 210 150 10 163 110 8
34966-104 69 6 10 10 10 2 2 6 2 2 6
34967- 2 2 6 2 2 6 2 2 6 2 2 6
34968- 2 2 6 2 2 6 2 2 6 2 2 6
34969- 2 2 6 2 2 6 2 2 6 2 2 6
34970- 2 2 6 6 6 6 91 60 6 167 114 7
34971-206 145 10 230 174 11 242 186 14 246 190 14
34972-246 190 14 246 190 14 246 186 14 242 186 14
34973-239 182 13 230 174 11 224 166 10 213 154 11
34974-180 133 36 124 112 88 86 86 86 58 58 58
34975- 38 38 38 22 22 22 10 10 10 6 6 6
34976- 0 0 0 0 0 0 0 0 0 0 0 0
34977- 0 0 0 0 0 0 0 0 0 0 0 0
34978- 0 0 0 0 0 0 0 0 0 0 0 0
34979- 0 0 0 0 0 0 0 0 0 14 14 14
34980- 34 34 34 70 70 70 138 110 50 158 118 36
34981-167 114 7 180 123 7 192 133 9 197 138 11
34982-200 144 11 206 145 10 213 154 11 219 162 10
34983-224 166 10 230 174 11 239 182 13 242 186 14
34984-246 186 14 246 186 14 246 186 14 246 186 14
34985-239 182 13 216 158 10 185 133 11 152 99 6
34986-104 69 6 18 14 6 2 2 6 2 2 6
34987- 2 2 6 2 2 6 2 2 6 2 2 6
34988- 2 2 6 2 2 6 2 2 6 2 2 6
34989- 2 2 6 2 2 6 2 2 6 2 2 6
34990- 2 2 6 6 6 6 80 54 7 152 99 6
34991-192 133 9 219 162 10 236 178 12 239 182 13
34992-246 186 14 242 186 14 239 182 13 236 178 12
34993-224 166 10 206 145 10 192 133 9 154 121 60
34994- 94 94 94 62 62 62 42 42 42 22 22 22
34995- 14 14 14 6 6 6 0 0 0 0 0 0
34996- 0 0 0 0 0 0 0 0 0 0 0 0
34997- 0 0 0 0 0 0 0 0 0 0 0 0
34998- 0 0 0 0 0 0 0 0 0 0 0 0
34999- 0 0 0 0 0 0 0 0 0 6 6 6
35000- 18 18 18 34 34 34 58 58 58 78 78 78
35001-101 98 89 124 112 88 142 110 46 156 107 11
35002-163 110 8 167 114 7 175 118 6 180 123 7
35003-185 133 11 197 138 11 210 150 10 219 162 10
35004-226 170 11 236 178 12 236 178 12 234 174 13
35005-219 162 10 197 138 11 163 110 8 130 83 6
35006- 91 60 6 10 10 10 2 2 6 2 2 6
35007- 18 18 18 38 38 38 38 38 38 38 38 38
35008- 38 38 38 38 38 38 38 38 38 38 38 38
35009- 38 38 38 38 38 38 26 26 26 2 2 6
35010- 2 2 6 6 6 6 70 47 6 137 92 6
35011-175 118 6 200 144 11 219 162 10 230 174 11
35012-234 174 13 230 174 11 219 162 10 210 150 10
35013-192 133 9 163 110 8 124 112 88 82 82 82
35014- 50 50 50 30 30 30 14 14 14 6 6 6
35015- 0 0 0 0 0 0 0 0 0 0 0 0
35016- 0 0 0 0 0 0 0 0 0 0 0 0
35017- 0 0 0 0 0 0 0 0 0 0 0 0
35018- 0 0 0 0 0 0 0 0 0 0 0 0
35019- 0 0 0 0 0 0 0 0 0 0 0 0
35020- 6 6 6 14 14 14 22 22 22 34 34 34
35021- 42 42 42 58 58 58 74 74 74 86 86 86
35022-101 98 89 122 102 70 130 98 46 121 87 25
35023-137 92 6 152 99 6 163 110 8 180 123 7
35024-185 133 11 197 138 11 206 145 10 200 144 11
35025-180 123 7 156 107 11 130 83 6 104 69 6
35026- 50 34 6 54 54 54 110 110 110 101 98 89
35027- 86 86 86 82 82 82 78 78 78 78 78 78
35028- 78 78 78 78 78 78 78 78 78 78 78 78
35029- 78 78 78 82 82 82 86 86 86 94 94 94
35030-106 106 106 101 101 101 86 66 34 124 80 6
35031-156 107 11 180 123 7 192 133 9 200 144 11
35032-206 145 10 200 144 11 192 133 9 175 118 6
35033-139 102 15 109 106 95 70 70 70 42 42 42
35034- 22 22 22 10 10 10 0 0 0 0 0 0
35035- 0 0 0 0 0 0 0 0 0 0 0 0
35036- 0 0 0 0 0 0 0 0 0 0 0 0
35037- 0 0 0 0 0 0 0 0 0 0 0 0
35038- 0 0 0 0 0 0 0 0 0 0 0 0
35039- 0 0 0 0 0 0 0 0 0 0 0 0
35040- 0 0 0 0 0 0 6 6 6 10 10 10
35041- 14 14 14 22 22 22 30 30 30 38 38 38
35042- 50 50 50 62 62 62 74 74 74 90 90 90
35043-101 98 89 112 100 78 121 87 25 124 80 6
35044-137 92 6 152 99 6 152 99 6 152 99 6
35045-138 86 6 124 80 6 98 70 6 86 66 30
35046-101 98 89 82 82 82 58 58 58 46 46 46
35047- 38 38 38 34 34 34 34 34 34 34 34 34
35048- 34 34 34 34 34 34 34 34 34 34 34 34
35049- 34 34 34 34 34 34 38 38 38 42 42 42
35050- 54 54 54 82 82 82 94 86 76 91 60 6
35051-134 86 6 156 107 11 167 114 7 175 118 6
35052-175 118 6 167 114 7 152 99 6 121 87 25
35053-101 98 89 62 62 62 34 34 34 18 18 18
35054- 6 6 6 0 0 0 0 0 0 0 0 0
35055- 0 0 0 0 0 0 0 0 0 0 0 0
35056- 0 0 0 0 0 0 0 0 0 0 0 0
35057- 0 0 0 0 0 0 0 0 0 0 0 0
35058- 0 0 0 0 0 0 0 0 0 0 0 0
35059- 0 0 0 0 0 0 0 0 0 0 0 0
35060- 0 0 0 0 0 0 0 0 0 0 0 0
35061- 0 0 0 6 6 6 6 6 6 10 10 10
35062- 18 18 18 22 22 22 30 30 30 42 42 42
35063- 50 50 50 66 66 66 86 86 86 101 98 89
35064-106 86 58 98 70 6 104 69 6 104 69 6
35065-104 69 6 91 60 6 82 62 34 90 90 90
35066- 62 62 62 38 38 38 22 22 22 14 14 14
35067- 10 10 10 10 10 10 10 10 10 10 10 10
35068- 10 10 10 10 10 10 6 6 6 10 10 10
35069- 10 10 10 10 10 10 10 10 10 14 14 14
35070- 22 22 22 42 42 42 70 70 70 89 81 66
35071- 80 54 7 104 69 6 124 80 6 137 92 6
35072-134 86 6 116 81 8 100 82 52 86 86 86
35073- 58 58 58 30 30 30 14 14 14 6 6 6
35074- 0 0 0 0 0 0 0 0 0 0 0 0
35075- 0 0 0 0 0 0 0 0 0 0 0 0
35076- 0 0 0 0 0 0 0 0 0 0 0 0
35077- 0 0 0 0 0 0 0 0 0 0 0 0
35078- 0 0 0 0 0 0 0 0 0 0 0 0
35079- 0 0 0 0 0 0 0 0 0 0 0 0
35080- 0 0 0 0 0 0 0 0 0 0 0 0
35081- 0 0 0 0 0 0 0 0 0 0 0 0
35082- 0 0 0 6 6 6 10 10 10 14 14 14
35083- 18 18 18 26 26 26 38 38 38 54 54 54
35084- 70 70 70 86 86 86 94 86 76 89 81 66
35085- 89 81 66 86 86 86 74 74 74 50 50 50
35086- 30 30 30 14 14 14 6 6 6 0 0 0
35087- 0 0 0 0 0 0 0 0 0 0 0 0
35088- 0 0 0 0 0 0 0 0 0 0 0 0
35089- 0 0 0 0 0 0 0 0 0 0 0 0
35090- 6 6 6 18 18 18 34 34 34 58 58 58
35091- 82 82 82 89 81 66 89 81 66 89 81 66
35092- 94 86 66 94 86 76 74 74 74 50 50 50
35093- 26 26 26 14 14 14 6 6 6 0 0 0
35094- 0 0 0 0 0 0 0 0 0 0 0 0
35095- 0 0 0 0 0 0 0 0 0 0 0 0
35096- 0 0 0 0 0 0 0 0 0 0 0 0
35097- 0 0 0 0 0 0 0 0 0 0 0 0
35098- 0 0 0 0 0 0 0 0 0 0 0 0
35099- 0 0 0 0 0 0 0 0 0 0 0 0
35100- 0 0 0 0 0 0 0 0 0 0 0 0
35101- 0 0 0 0 0 0 0 0 0 0 0 0
35102- 0 0 0 0 0 0 0 0 0 0 0 0
35103- 6 6 6 6 6 6 14 14 14 18 18 18
35104- 30 30 30 38 38 38 46 46 46 54 54 54
35105- 50 50 50 42 42 42 30 30 30 18 18 18
35106- 10 10 10 0 0 0 0 0 0 0 0 0
35107- 0 0 0 0 0 0 0 0 0 0 0 0
35108- 0 0 0 0 0 0 0 0 0 0 0 0
35109- 0 0 0 0 0 0 0 0 0 0 0 0
35110- 0 0 0 6 6 6 14 14 14 26 26 26
35111- 38 38 38 50 50 50 58 58 58 58 58 58
35112- 54 54 54 42 42 42 30 30 30 18 18 18
35113- 10 10 10 0 0 0 0 0 0 0 0 0
35114- 0 0 0 0 0 0 0 0 0 0 0 0
35115- 0 0 0 0 0 0 0 0 0 0 0 0
35116- 0 0 0 0 0 0 0 0 0 0 0 0
35117- 0 0 0 0 0 0 0 0 0 0 0 0
35118- 0 0 0 0 0 0 0 0 0 0 0 0
35119- 0 0 0 0 0 0 0 0 0 0 0 0
35120- 0 0 0 0 0 0 0 0 0 0 0 0
35121- 0 0 0 0 0 0 0 0 0 0 0 0
35122- 0 0 0 0 0 0 0 0 0 0 0 0
35123- 0 0 0 0 0 0 0 0 0 6 6 6
35124- 6 6 6 10 10 10 14 14 14 18 18 18
35125- 18 18 18 14 14 14 10 10 10 6 6 6
35126- 0 0 0 0 0 0 0 0 0 0 0 0
35127- 0 0 0 0 0 0 0 0 0 0 0 0
35128- 0 0 0 0 0 0 0 0 0 0 0 0
35129- 0 0 0 0 0 0 0 0 0 0 0 0
35130- 0 0 0 0 0 0 0 0 0 6 6 6
35131- 14 14 14 18 18 18 22 22 22 22 22 22
35132- 18 18 18 14 14 14 10 10 10 6 6 6
35133- 0 0 0 0 0 0 0 0 0 0 0 0
35134- 0 0 0 0 0 0 0 0 0 0 0 0
35135- 0 0 0 0 0 0 0 0 0 0 0 0
35136- 0 0 0 0 0 0 0 0 0 0 0 0
35137- 0 0 0 0 0 0 0 0 0 0 0 0
35138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35151+4 4 4 4 4 4
35152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35165+4 4 4 4 4 4
35166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35179+4 4 4 4 4 4
35180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35193+4 4 4 4 4 4
35194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35207+4 4 4 4 4 4
35208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35221+4 4 4 4 4 4
35222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35226+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
35227+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
35228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35231+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
35232+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
35233+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
35234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35235+4 4 4 4 4 4
35236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35240+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
35241+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
35242+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35245+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
35246+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
35247+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
35248+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35249+4 4 4 4 4 4
35250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35254+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
35255+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
35256+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
35257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35259+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
35260+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
35261+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
35262+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
35263+4 4 4 4 4 4
35264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35267+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
35268+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
35269+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
35270+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
35271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35272+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
35273+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
35274+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
35275+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
35276+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
35277+4 4 4 4 4 4
35278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35281+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
35282+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
35283+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
35284+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
35285+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
35286+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
35287+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
35288+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
35289+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
35290+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
35291+4 4 4 4 4 4
35292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
35295+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
35296+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
35297+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
35298+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
35299+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
35300+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
35301+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
35302+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
35303+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
35304+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
35305+4 4 4 4 4 4
35306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35308+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
35309+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
35310+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
35311+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
35312+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
35313+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
35314+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
35315+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
35316+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
35317+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
35318+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
35319+4 4 4 4 4 4
35320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35322+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
35323+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
35324+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
35325+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
35326+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
35327+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
35328+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
35329+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
35330+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
35331+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
35332+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
35333+4 4 4 4 4 4
35334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35336+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
35337+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
35338+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
35339+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
35340+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
35341+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
35342+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
35343+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
35344+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
35345+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
35346+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
35347+4 4 4 4 4 4
35348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35350+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
35351+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
35352+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
35353+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
35354+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
35355+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
35356+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
35357+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
35358+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
35359+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
35360+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
35361+4 4 4 4 4 4
35362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35363+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
35364+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
35365+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
35366+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
35367+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
35368+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
35369+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
35370+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
35371+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
35372+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
35373+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
35374+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
35375+4 4 4 4 4 4
35376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35377+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
35378+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
35379+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
35380+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
35381+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
35382+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
35383+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
35384+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
35385+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
35386+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
35387+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
35388+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
35389+0 0 0 4 4 4
35390+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
35391+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
35392+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
35393+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
35394+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
35395+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
35396+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
35397+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
35398+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
35399+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
35400+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
35401+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
35402+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
35403+2 0 0 0 0 0
35404+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
35405+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
35406+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
35407+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
35408+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
35409+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
35410+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
35411+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
35412+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
35413+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
35414+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
35415+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
35416+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
35417+37 38 37 0 0 0
35418+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
35419+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
35420+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
35421+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
35422+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
35423+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
35424+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
35425+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
35426+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
35427+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
35428+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
35429+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
35430+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
35431+85 115 134 4 0 0
35432+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
35433+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
35434+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
35435+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
35436+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
35437+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
35438+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
35439+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
35440+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
35441+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
35442+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
35443+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
35444+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
35445+60 73 81 4 0 0
35446+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
35447+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
35448+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
35449+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
35450+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
35451+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
35452+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
35453+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
35454+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
35455+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
35456+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
35457+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
35458+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
35459+16 19 21 4 0 0
35460+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
35461+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
35462+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
35463+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
35464+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
35465+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
35466+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
35467+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
35468+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
35469+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
35470+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
35471+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
35472+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
35473+4 0 0 4 3 3
35474+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
35475+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
35476+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
35477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
35478+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
35479+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
35480+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
35481+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
35482+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
35483+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
35484+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
35485+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
35486+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
35487+3 2 2 4 4 4
35488+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
35489+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
35490+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
35491+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
35492+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
35493+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
35494+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
35495+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
35496+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
35497+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
35498+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
35499+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
35500+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
35501+4 4 4 4 4 4
35502+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
35503+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
35504+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
35505+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
35506+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
35507+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
35508+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
35509+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
35510+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
35511+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
35512+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
35513+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
35514+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
35515+4 4 4 4 4 4
35516+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
35517+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
35518+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
35519+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
35520+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
35521+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
35522+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
35523+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
35524+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
35525+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
35526+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
35527+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
35528+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
35529+5 5 5 5 5 5
35530+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
35531+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
35532+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
35533+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
35534+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
35535+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
35536+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
35537+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
35538+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
35539+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
35540+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
35541+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
35542+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
35543+5 5 5 4 4 4
35544+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
35545+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
35546+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
35547+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
35548+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
35549+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
35550+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
35551+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
35552+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
35553+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
35554+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
35555+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
35556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35557+4 4 4 4 4 4
35558+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
35559+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
35560+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
35561+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
35562+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
35563+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
35564+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
35565+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
35566+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
35567+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
35568+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
35569+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
35570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35571+4 4 4 4 4 4
35572+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
35573+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
35574+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
35575+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
35576+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
35577+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
35578+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
35579+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
35580+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
35581+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
35582+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
35583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35585+4 4 4 4 4 4
35586+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
35587+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
35588+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
35589+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
35590+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
35591+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
35592+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
35593+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
35594+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
35595+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
35596+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
35597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35599+4 4 4 4 4 4
35600+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
35601+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
35602+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
35603+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
35604+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
35605+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
35606+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
35607+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
35608+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
35609+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
35610+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35613+4 4 4 4 4 4
35614+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
35615+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
35616+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
35617+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
35618+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
35619+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
35620+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
35621+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
35622+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
35623+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
35624+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
35625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35627+4 4 4 4 4 4
35628+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
35629+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
35630+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
35631+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
35632+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
35633+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
35634+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
35635+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
35636+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
35637+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
35638+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
35639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35641+4 4 4 4 4 4
35642+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
35643+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
35644+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
35645+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
35646+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
35647+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
35648+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
35649+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
35650+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
35651+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
35652+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35655+4 4 4 4 4 4
35656+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
35657+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
35658+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
35659+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
35660+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
35661+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
35662+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
35663+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
35664+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
35665+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
35666+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35669+4 4 4 4 4 4
35670+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
35671+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
35672+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
35673+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
35674+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
35675+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
35676+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
35677+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
35678+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
35679+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
35680+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35683+4 4 4 4 4 4
35684+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
35685+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
35686+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
35687+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
35688+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
35689+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
35690+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
35691+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
35692+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
35693+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35694+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35697+4 4 4 4 4 4
35698+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
35699+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
35700+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
35701+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
35702+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
35703+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
35704+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
35705+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
35706+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
35707+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35708+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35711+4 4 4 4 4 4
35712+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
35713+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
35714+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
35715+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
35716+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
35717+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
35718+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
35719+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
35720+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
35721+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35722+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35725+4 4 4 4 4 4
35726+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
35727+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
35728+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
35729+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
35730+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
35731+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
35732+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
35733+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
35734+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
35735+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35736+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35739+4 4 4 4 4 4
35740+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
35741+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
35742+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
35743+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
35744+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
35745+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
35746+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
35747+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
35748+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
35749+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35750+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35753+4 4 4 4 4 4
35754+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
35755+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
35756+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
35757+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
35758+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
35759+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
35760+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
35761+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
35762+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
35763+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35764+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35767+4 4 4 4 4 4
35768+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
35769+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
35770+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
35771+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
35772+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
35773+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
35774+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
35775+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
35776+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
35777+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35778+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35781+4 4 4 4 4 4
35782+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
35783+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
35784+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
35785+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
35786+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
35787+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
35788+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
35789+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
35790+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
35791+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35792+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35795+4 4 4 4 4 4
35796+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
35797+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
35798+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
35799+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
35800+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
35801+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
35802+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
35803+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
35804+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
35805+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35806+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35809+4 4 4 4 4 4
35810+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
35811+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
35812+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
35813+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
35814+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
35815+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
35816+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
35817+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
35818+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
35819+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35820+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35823+4 4 4 4 4 4
35824+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
35825+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
35826+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
35827+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
35828+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
35829+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
35830+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
35831+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
35832+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
35833+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35834+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35837+4 4 4 4 4 4
35838+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
35839+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
35840+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
35841+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
35842+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
35843+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
35844+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
35845+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
35846+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
35847+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35848+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35851+4 4 4 4 4 4
35852+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
35853+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
35854+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
35855+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
35856+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
35857+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
35858+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
35859+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
35860+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
35861+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35862+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35865+4 4 4 4 4 4
35866+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
35867+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
35868+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
35869+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
35870+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
35871+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
35872+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
35873+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
35874+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
35875+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35876+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35879+4 4 4 4 4 4
35880+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
35881+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
35882+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
35883+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
35884+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
35885+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
35886+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
35887+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
35888+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
35889+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
35890+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35893+4 4 4 4 4 4
35894+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
35895+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
35896+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
35897+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
35898+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
35899+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
35900+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
35901+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
35902+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
35903+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
35904+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
35905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35907+4 4 4 4 4 4
35908+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
35909+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
35910+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
35911+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
35912+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
35913+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
35914+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
35915+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
35916+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
35917+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
35918+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35921+4 4 4 4 4 4
35922+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
35923+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
35924+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
35925+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
35926+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
35927+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
35928+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35929+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
35930+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
35931+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
35932+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
35933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35935+4 4 4 4 4 4
35936+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
35937+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
35938+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
35939+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
35940+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
35941+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
35942+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
35943+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
35944+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
35945+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
35946+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35949+4 4 4 4 4 4
35950+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
35951+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
35952+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
35953+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
35954+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
35955+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
35956+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
35957+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
35958+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
35959+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
35960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35963+4 4 4 4 4 4
35964+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
35965+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
35966+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
35967+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
35968+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
35969+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
35970+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
35971+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
35972+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
35973+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
35974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35977+4 4 4 4 4 4
35978+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
35979+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
35980+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
35981+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
35982+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
35983+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
35984+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
35985+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
35986+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
35987+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
35988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
35991+4 4 4 4 4 4
35992+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
35993+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
35994+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
35995+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
35996+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
35997+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
35998+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
35999+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
36000+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
36001+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
36002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36005+4 4 4 4 4 4
36006+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
36007+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
36008+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
36009+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
36010+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
36011+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
36012+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
36013+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
36014+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
36015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36019+4 4 4 4 4 4
36020+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
36021+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
36022+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
36023+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
36024+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
36025+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
36026+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
36027+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
36028+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
36029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36033+4 4 4 4 4 4
36034+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
36035+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
36036+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
36037+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
36038+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
36039+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
36040+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
36041+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
36042+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36047+4 4 4 4 4 4
36048+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
36049+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
36050+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
36051+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
36052+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
36053+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
36054+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
36055+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
36056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36061+4 4 4 4 4 4
36062+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
36063+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
36064+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
36065+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
36066+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
36067+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
36068+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
36069+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
36070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36075+4 4 4 4 4 4
36076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
36077+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
36078+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
36079+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
36080+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
36081+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
36082+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
36083+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
36084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36089+4 4 4 4 4 4
36090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36091+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
36092+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
36093+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
36094+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
36095+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
36096+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
36097+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
36098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36103+4 4 4 4 4 4
36104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36105+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
36106+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
36107+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
36108+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
36109+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
36110+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
36111+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
36112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36117+4 4 4 4 4 4
36118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36120+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
36121+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
36122+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
36123+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
36124+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
36125+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
36126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36131+4 4 4 4 4 4
36132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
36135+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
36136+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
36137+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
36138+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
36139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36145+4 4 4 4 4 4
36146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36149+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
36150+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
36151+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
36152+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
36153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36159+4 4 4 4 4 4
36160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36163+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
36164+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
36165+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
36166+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
36167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36173+4 4 4 4 4 4
36174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36177+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
36178+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
36179+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
36180+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
36181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36187+4 4 4 4 4 4
36188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
36192+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
36193+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
36194+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
36195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36201+4 4 4 4 4 4
36202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36206+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
36207+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
36208+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
36209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36215+4 4 4 4 4 4
36216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36220+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
36221+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
36222+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36229+4 4 4 4 4 4
36230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36234+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
36235+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
36236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36243+4 4 4 4 4 4
36244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36248+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
36249+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
36250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
36257+4 4 4 4 4 4
36258diff -urNp linux-3.0.4/drivers/video/udlfb.c linux-3.0.4/drivers/video/udlfb.c
36259--- linux-3.0.4/drivers/video/udlfb.c 2011-07-21 22:17:23.000000000 -0400
36260+++ linux-3.0.4/drivers/video/udlfb.c 2011-08-23 21:47:56.000000000 -0400
36261@@ -586,11 +586,11 @@ int dlfb_handle_damage(struct dlfb_data
36262 dlfb_urb_completion(urb);
36263
36264 error:
36265- atomic_add(bytes_sent, &dev->bytes_sent);
36266- atomic_add(bytes_identical, &dev->bytes_identical);
36267- atomic_add(width*height*2, &dev->bytes_rendered);
36268+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
36269+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
36270+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
36271 end_cycles = get_cycles();
36272- atomic_add(((unsigned int) ((end_cycles - start_cycles)
36273+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
36274 >> 10)), /* Kcycles */
36275 &dev->cpu_kcycles_used);
36276
36277@@ -711,11 +711,11 @@ static void dlfb_dpy_deferred_io(struct
36278 dlfb_urb_completion(urb);
36279
36280 error:
36281- atomic_add(bytes_sent, &dev->bytes_sent);
36282- atomic_add(bytes_identical, &dev->bytes_identical);
36283- atomic_add(bytes_rendered, &dev->bytes_rendered);
36284+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
36285+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
36286+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
36287 end_cycles = get_cycles();
36288- atomic_add(((unsigned int) ((end_cycles - start_cycles)
36289+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
36290 >> 10)), /* Kcycles */
36291 &dev->cpu_kcycles_used);
36292 }
36293@@ -1307,7 +1307,7 @@ static ssize_t metrics_bytes_rendered_sh
36294 struct fb_info *fb_info = dev_get_drvdata(fbdev);
36295 struct dlfb_data *dev = fb_info->par;
36296 return snprintf(buf, PAGE_SIZE, "%u\n",
36297- atomic_read(&dev->bytes_rendered));
36298+ atomic_read_unchecked(&dev->bytes_rendered));
36299 }
36300
36301 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
36302@@ -1315,7 +1315,7 @@ static ssize_t metrics_bytes_identical_s
36303 struct fb_info *fb_info = dev_get_drvdata(fbdev);
36304 struct dlfb_data *dev = fb_info->par;
36305 return snprintf(buf, PAGE_SIZE, "%u\n",
36306- atomic_read(&dev->bytes_identical));
36307+ atomic_read_unchecked(&dev->bytes_identical));
36308 }
36309
36310 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
36311@@ -1323,7 +1323,7 @@ static ssize_t metrics_bytes_sent_show(s
36312 struct fb_info *fb_info = dev_get_drvdata(fbdev);
36313 struct dlfb_data *dev = fb_info->par;
36314 return snprintf(buf, PAGE_SIZE, "%u\n",
36315- atomic_read(&dev->bytes_sent));
36316+ atomic_read_unchecked(&dev->bytes_sent));
36317 }
36318
36319 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
36320@@ -1331,7 +1331,7 @@ static ssize_t metrics_cpu_kcycles_used_
36321 struct fb_info *fb_info = dev_get_drvdata(fbdev);
36322 struct dlfb_data *dev = fb_info->par;
36323 return snprintf(buf, PAGE_SIZE, "%u\n",
36324- atomic_read(&dev->cpu_kcycles_used));
36325+ atomic_read_unchecked(&dev->cpu_kcycles_used));
36326 }
36327
36328 static ssize_t edid_show(
36329@@ -1388,10 +1388,10 @@ static ssize_t metrics_reset_store(struc
36330 struct fb_info *fb_info = dev_get_drvdata(fbdev);
36331 struct dlfb_data *dev = fb_info->par;
36332
36333- atomic_set(&dev->bytes_rendered, 0);
36334- atomic_set(&dev->bytes_identical, 0);
36335- atomic_set(&dev->bytes_sent, 0);
36336- atomic_set(&dev->cpu_kcycles_used, 0);
36337+ atomic_set_unchecked(&dev->bytes_rendered, 0);
36338+ atomic_set_unchecked(&dev->bytes_identical, 0);
36339+ atomic_set_unchecked(&dev->bytes_sent, 0);
36340+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
36341
36342 return count;
36343 }
36344diff -urNp linux-3.0.4/drivers/video/uvesafb.c linux-3.0.4/drivers/video/uvesafb.c
36345--- linux-3.0.4/drivers/video/uvesafb.c 2011-07-21 22:17:23.000000000 -0400
36346+++ linux-3.0.4/drivers/video/uvesafb.c 2011-08-23 21:47:56.000000000 -0400
36347@@ -19,6 +19,7 @@
36348 #include <linux/io.h>
36349 #include <linux/mutex.h>
36350 #include <linux/slab.h>
36351+#include <linux/moduleloader.h>
36352 #include <video/edid.h>
36353 #include <video/uvesafb.h>
36354 #ifdef CONFIG_X86
36355@@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
36356 NULL,
36357 };
36358
36359- return call_usermodehelper(v86d_path, argv, envp, 1);
36360+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
36361 }
36362
36363 /*
36364@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
36365 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
36366 par->pmi_setpal = par->ypan = 0;
36367 } else {
36368+
36369+#ifdef CONFIG_PAX_KERNEXEC
36370+#ifdef CONFIG_MODULES
36371+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
36372+#endif
36373+ if (!par->pmi_code) {
36374+ par->pmi_setpal = par->ypan = 0;
36375+ return 0;
36376+ }
36377+#endif
36378+
36379 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
36380 + task->t.regs.edi);
36381+
36382+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36383+ pax_open_kernel();
36384+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
36385+ pax_close_kernel();
36386+
36387+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
36388+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
36389+#else
36390 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
36391 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
36392+#endif
36393+
36394 printk(KERN_INFO "uvesafb: protected mode interface info at "
36395 "%04x:%04x\n",
36396 (u16)task->t.regs.es, (u16)task->t.regs.edi);
36397@@ -1821,6 +1844,11 @@ out:
36398 if (par->vbe_modes)
36399 kfree(par->vbe_modes);
36400
36401+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36402+ if (par->pmi_code)
36403+ module_free_exec(NULL, par->pmi_code);
36404+#endif
36405+
36406 framebuffer_release(info);
36407 return err;
36408 }
36409@@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platfor
36410 kfree(par->vbe_state_orig);
36411 if (par->vbe_state_saved)
36412 kfree(par->vbe_state_saved);
36413+
36414+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36415+ if (par->pmi_code)
36416+ module_free_exec(NULL, par->pmi_code);
36417+#endif
36418+
36419 }
36420
36421 framebuffer_release(info);
36422diff -urNp linux-3.0.4/drivers/video/vesafb.c linux-3.0.4/drivers/video/vesafb.c
36423--- linux-3.0.4/drivers/video/vesafb.c 2011-07-21 22:17:23.000000000 -0400
36424+++ linux-3.0.4/drivers/video/vesafb.c 2011-08-23 21:47:56.000000000 -0400
36425@@ -9,6 +9,7 @@
36426 */
36427
36428 #include <linux/module.h>
36429+#include <linux/moduleloader.h>
36430 #include <linux/kernel.h>
36431 #include <linux/errno.h>
36432 #include <linux/string.h>
36433@@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
36434 static int vram_total __initdata; /* Set total amount of memory */
36435 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
36436 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
36437-static void (*pmi_start)(void) __read_mostly;
36438-static void (*pmi_pal) (void) __read_mostly;
36439+static void (*pmi_start)(void) __read_only;
36440+static void (*pmi_pal) (void) __read_only;
36441 static int depth __read_mostly;
36442 static int vga_compat __read_mostly;
36443 /* --------------------------------------------------------------------- */
36444@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct pl
36445 unsigned int size_vmode;
36446 unsigned int size_remap;
36447 unsigned int size_total;
36448+ void *pmi_code = NULL;
36449
36450 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
36451 return -ENODEV;
36452@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct pl
36453 size_remap = size_total;
36454 vesafb_fix.smem_len = size_remap;
36455
36456-#ifndef __i386__
36457- screen_info.vesapm_seg = 0;
36458-#endif
36459-
36460 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
36461 printk(KERN_WARNING
36462 "vesafb: cannot reserve video memory at 0x%lx\n",
36463@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct pl
36464 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
36465 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
36466
36467+#ifdef __i386__
36468+
36469+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36470+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
36471+ if (!pmi_code)
36472+#elif !defined(CONFIG_PAX_KERNEXEC)
36473+ if (0)
36474+#endif
36475+
36476+#endif
36477+ screen_info.vesapm_seg = 0;
36478+
36479 if (screen_info.vesapm_seg) {
36480- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
36481- screen_info.vesapm_seg,screen_info.vesapm_off);
36482+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
36483+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
36484 }
36485
36486 if (screen_info.vesapm_seg < 0xc000)
36487@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct pl
36488
36489 if (ypan || pmi_setpal) {
36490 unsigned short *pmi_base;
36491+
36492 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
36493- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
36494- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
36495+
36496+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36497+ pax_open_kernel();
36498+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
36499+#else
36500+ pmi_code = pmi_base;
36501+#endif
36502+
36503+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
36504+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
36505+
36506+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36507+ pmi_start = ktva_ktla(pmi_start);
36508+ pmi_pal = ktva_ktla(pmi_pal);
36509+ pax_close_kernel();
36510+#endif
36511+
36512 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
36513 if (pmi_base[3]) {
36514 printk(KERN_INFO "vesafb: pmi: ports = ");
36515@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct pl
36516 info->node, info->fix.id);
36517 return 0;
36518 err:
36519+
36520+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
36521+ module_free_exec(NULL, pmi_code);
36522+#endif
36523+
36524 if (info->screen_base)
36525 iounmap(info->screen_base);
36526 framebuffer_release(info);
36527diff -urNp linux-3.0.4/drivers/video/via/via_clock.h linux-3.0.4/drivers/video/via/via_clock.h
36528--- linux-3.0.4/drivers/video/via/via_clock.h 2011-07-21 22:17:23.000000000 -0400
36529+++ linux-3.0.4/drivers/video/via/via_clock.h 2011-08-23 21:47:56.000000000 -0400
36530@@ -56,7 +56,7 @@ struct via_clock {
36531
36532 void (*set_engine_pll_state)(u8 state);
36533 void (*set_engine_pll)(struct via_pll_config config);
36534-};
36535+} __no_const;
36536
36537
36538 static inline u32 get_pll_internal_frequency(u32 ref_freq,
36539diff -urNp linux-3.0.4/drivers/virtio/virtio_balloon.c linux-3.0.4/drivers/virtio/virtio_balloon.c
36540--- linux-3.0.4/drivers/virtio/virtio_balloon.c 2011-07-21 22:17:23.000000000 -0400
36541+++ linux-3.0.4/drivers/virtio/virtio_balloon.c 2011-08-23 21:48:14.000000000 -0400
36542@@ -174,6 +174,8 @@ static void update_balloon_stats(struct
36543 struct sysinfo i;
36544 int idx = 0;
36545
36546+ pax_track_stack();
36547+
36548 all_vm_events(events);
36549 si_meminfo(&i);
36550
36551diff -urNp linux-3.0.4/fs/9p/vfs_inode.c linux-3.0.4/fs/9p/vfs_inode.c
36552--- linux-3.0.4/fs/9p/vfs_inode.c 2011-07-21 22:17:23.000000000 -0400
36553+++ linux-3.0.4/fs/9p/vfs_inode.c 2011-08-23 21:47:56.000000000 -0400
36554@@ -1210,7 +1210,7 @@ static void *v9fs_vfs_follow_link(struct
36555 void
36556 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
36557 {
36558- char *s = nd_get_link(nd);
36559+ const char *s = nd_get_link(nd);
36560
36561 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
36562 IS_ERR(s) ? "<error>" : s);
36563diff -urNp linux-3.0.4/fs/aio.c linux-3.0.4/fs/aio.c
36564--- linux-3.0.4/fs/aio.c 2011-07-21 22:17:23.000000000 -0400
36565+++ linux-3.0.4/fs/aio.c 2011-08-23 21:48:14.000000000 -0400
36566@@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx
36567 size += sizeof(struct io_event) * nr_events;
36568 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
36569
36570- if (nr_pages < 0)
36571+ if (nr_pages <= 0)
36572 return -EINVAL;
36573
36574 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
36575@@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ct
36576 struct aio_timeout to;
36577 int retry = 0;
36578
36579+ pax_track_stack();
36580+
36581 /* needed to zero any padding within an entry (there shouldn't be
36582 * any, but C is fun!
36583 */
36584@@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *i
36585 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
36586 {
36587 ssize_t ret;
36588+ struct iovec iovstack;
36589
36590 #ifdef CONFIG_COMPAT
36591 if (compat)
36592 ret = compat_rw_copy_check_uvector(type,
36593 (struct compat_iovec __user *)kiocb->ki_buf,
36594- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
36595+ kiocb->ki_nbytes, 1, &iovstack,
36596 &kiocb->ki_iovec);
36597 else
36598 #endif
36599 ret = rw_copy_check_uvector(type,
36600 (struct iovec __user *)kiocb->ki_buf,
36601- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
36602+ kiocb->ki_nbytes, 1, &iovstack,
36603 &kiocb->ki_iovec);
36604 if (ret < 0)
36605 goto out;
36606
36607+ if (kiocb->ki_iovec == &iovstack) {
36608+ kiocb->ki_inline_vec = iovstack;
36609+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
36610+ }
36611 kiocb->ki_nr_segs = kiocb->ki_nbytes;
36612 kiocb->ki_cur_seg = 0;
36613 /* ki_nbytes/left now reflect bytes instead of segs */
36614diff -urNp linux-3.0.4/fs/attr.c linux-3.0.4/fs/attr.c
36615--- linux-3.0.4/fs/attr.c 2011-07-21 22:17:23.000000000 -0400
36616+++ linux-3.0.4/fs/attr.c 2011-08-23 21:48:14.000000000 -0400
36617@@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
36618 unsigned long limit;
36619
36620 limit = rlimit(RLIMIT_FSIZE);
36621+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
36622 if (limit != RLIM_INFINITY && offset > limit)
36623 goto out_sig;
36624 if (offset > inode->i_sb->s_maxbytes)
36625diff -urNp linux-3.0.4/fs/befs/linuxvfs.c linux-3.0.4/fs/befs/linuxvfs.c
36626--- linux-3.0.4/fs/befs/linuxvfs.c 2011-08-29 23:26:13.000000000 -0400
36627+++ linux-3.0.4/fs/befs/linuxvfs.c 2011-08-29 23:26:27.000000000 -0400
36628@@ -503,7 +503,7 @@ static void befs_put_link(struct dentry
36629 {
36630 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
36631 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
36632- char *link = nd_get_link(nd);
36633+ const char *link = nd_get_link(nd);
36634 if (!IS_ERR(link))
36635 kfree(link);
36636 }
36637diff -urNp linux-3.0.4/fs/binfmt_aout.c linux-3.0.4/fs/binfmt_aout.c
36638--- linux-3.0.4/fs/binfmt_aout.c 2011-07-21 22:17:23.000000000 -0400
36639+++ linux-3.0.4/fs/binfmt_aout.c 2011-08-23 21:48:14.000000000 -0400
36640@@ -16,6 +16,7 @@
36641 #include <linux/string.h>
36642 #include <linux/fs.h>
36643 #include <linux/file.h>
36644+#include <linux/security.h>
36645 #include <linux/stat.h>
36646 #include <linux/fcntl.h>
36647 #include <linux/ptrace.h>
36648@@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
36649 #endif
36650 # define START_STACK(u) ((void __user *)u.start_stack)
36651
36652+ memset(&dump, 0, sizeof(dump));
36653+
36654 fs = get_fs();
36655 set_fs(KERNEL_DS);
36656 has_dumped = 1;
36657@@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
36658
36659 /* If the size of the dump file exceeds the rlimit, then see what would happen
36660 if we wrote the stack, but not the data area. */
36661+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
36662 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
36663 dump.u_dsize = 0;
36664
36665 /* Make sure we have enough room to write the stack and data areas. */
36666+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
36667 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
36668 dump.u_ssize = 0;
36669
36670@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
36671 rlim = rlimit(RLIMIT_DATA);
36672 if (rlim >= RLIM_INFINITY)
36673 rlim = ~0;
36674+
36675+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
36676 if (ex.a_data + ex.a_bss > rlim)
36677 return -ENOMEM;
36678
36679@@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
36680 install_exec_creds(bprm);
36681 current->flags &= ~PF_FORKNOEXEC;
36682
36683+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
36684+ current->mm->pax_flags = 0UL;
36685+#endif
36686+
36687+#ifdef CONFIG_PAX_PAGEEXEC
36688+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
36689+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
36690+
36691+#ifdef CONFIG_PAX_EMUTRAMP
36692+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
36693+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
36694+#endif
36695+
36696+#ifdef CONFIG_PAX_MPROTECT
36697+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
36698+ current->mm->pax_flags |= MF_PAX_MPROTECT;
36699+#endif
36700+
36701+ }
36702+#endif
36703+
36704 if (N_MAGIC(ex) == OMAGIC) {
36705 unsigned long text_addr, map_size;
36706 loff_t pos;
36707@@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
36708
36709 down_write(&current->mm->mmap_sem);
36710 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
36711- PROT_READ | PROT_WRITE | PROT_EXEC,
36712+ PROT_READ | PROT_WRITE,
36713 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
36714 fd_offset + ex.a_text);
36715 up_write(&current->mm->mmap_sem);
36716diff -urNp linux-3.0.4/fs/binfmt_elf.c linux-3.0.4/fs/binfmt_elf.c
36717--- linux-3.0.4/fs/binfmt_elf.c 2011-07-21 22:17:23.000000000 -0400
36718+++ linux-3.0.4/fs/binfmt_elf.c 2011-08-23 21:48:14.000000000 -0400
36719@@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
36720 #define elf_core_dump NULL
36721 #endif
36722
36723+#ifdef CONFIG_PAX_MPROTECT
36724+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
36725+#endif
36726+
36727 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
36728 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
36729 #else
36730@@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
36731 .load_binary = load_elf_binary,
36732 .load_shlib = load_elf_library,
36733 .core_dump = elf_core_dump,
36734+
36735+#ifdef CONFIG_PAX_MPROTECT
36736+ .handle_mprotect= elf_handle_mprotect,
36737+#endif
36738+
36739 .min_coredump = ELF_EXEC_PAGESIZE,
36740 };
36741
36742@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
36743
36744 static int set_brk(unsigned long start, unsigned long end)
36745 {
36746+ unsigned long e = end;
36747+
36748 start = ELF_PAGEALIGN(start);
36749 end = ELF_PAGEALIGN(end);
36750 if (end > start) {
36751@@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
36752 if (BAD_ADDR(addr))
36753 return addr;
36754 }
36755- current->mm->start_brk = current->mm->brk = end;
36756+ current->mm->start_brk = current->mm->brk = e;
36757 return 0;
36758 }
36759
36760@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
36761 elf_addr_t __user *u_rand_bytes;
36762 const char *k_platform = ELF_PLATFORM;
36763 const char *k_base_platform = ELF_BASE_PLATFORM;
36764- unsigned char k_rand_bytes[16];
36765+ u32 k_rand_bytes[4];
36766 int items;
36767 elf_addr_t *elf_info;
36768 int ei_index = 0;
36769 const struct cred *cred = current_cred();
36770 struct vm_area_struct *vma;
36771+ unsigned long saved_auxv[AT_VECTOR_SIZE];
36772+
36773+ pax_track_stack();
36774
36775 /*
36776 * In some cases (e.g. Hyper-Threading), we want to avoid L1
36777@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
36778 * Generate 16 random bytes for userspace PRNG seeding.
36779 */
36780 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
36781- u_rand_bytes = (elf_addr_t __user *)
36782- STACK_ALLOC(p, sizeof(k_rand_bytes));
36783+ srandom32(k_rand_bytes[0] ^ random32());
36784+ srandom32(k_rand_bytes[1] ^ random32());
36785+ srandom32(k_rand_bytes[2] ^ random32());
36786+ srandom32(k_rand_bytes[3] ^ random32());
36787+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
36788+ u_rand_bytes = (elf_addr_t __user *) p;
36789 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
36790 return -EFAULT;
36791
36792@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
36793 return -EFAULT;
36794 current->mm->env_end = p;
36795
36796+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
36797+
36798 /* Put the elf_info on the stack in the right place. */
36799 sp = (elf_addr_t __user *)envp + 1;
36800- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
36801+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
36802 return -EFAULT;
36803 return 0;
36804 }
36805@@ -381,10 +401,10 @@ static unsigned long load_elf_interp(str
36806 {
36807 struct elf_phdr *elf_phdata;
36808 struct elf_phdr *eppnt;
36809- unsigned long load_addr = 0;
36810+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
36811 int load_addr_set = 0;
36812 unsigned long last_bss = 0, elf_bss = 0;
36813- unsigned long error = ~0UL;
36814+ unsigned long error = -EINVAL;
36815 unsigned long total_size;
36816 int retval, i, size;
36817
36818@@ -430,6 +450,11 @@ static unsigned long load_elf_interp(str
36819 goto out_close;
36820 }
36821
36822+#ifdef CONFIG_PAX_SEGMEXEC
36823+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
36824+ pax_task_size = SEGMEXEC_TASK_SIZE;
36825+#endif
36826+
36827 eppnt = elf_phdata;
36828 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
36829 if (eppnt->p_type == PT_LOAD) {
36830@@ -473,8 +498,8 @@ static unsigned long load_elf_interp(str
36831 k = load_addr + eppnt->p_vaddr;
36832 if (BAD_ADDR(k) ||
36833 eppnt->p_filesz > eppnt->p_memsz ||
36834- eppnt->p_memsz > TASK_SIZE ||
36835- TASK_SIZE - eppnt->p_memsz < k) {
36836+ eppnt->p_memsz > pax_task_size ||
36837+ pax_task_size - eppnt->p_memsz < k) {
36838 error = -ENOMEM;
36839 goto out_close;
36840 }
36841@@ -528,6 +553,193 @@ out:
36842 return error;
36843 }
36844
36845+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
36846+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
36847+{
36848+ unsigned long pax_flags = 0UL;
36849+
36850+#ifdef CONFIG_PAX_PAGEEXEC
36851+ if (elf_phdata->p_flags & PF_PAGEEXEC)
36852+ pax_flags |= MF_PAX_PAGEEXEC;
36853+#endif
36854+
36855+#ifdef CONFIG_PAX_SEGMEXEC
36856+ if (elf_phdata->p_flags & PF_SEGMEXEC)
36857+ pax_flags |= MF_PAX_SEGMEXEC;
36858+#endif
36859+
36860+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
36861+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36862+ if ((__supported_pte_mask & _PAGE_NX))
36863+ pax_flags &= ~MF_PAX_SEGMEXEC;
36864+ else
36865+ pax_flags &= ~MF_PAX_PAGEEXEC;
36866+ }
36867+#endif
36868+
36869+#ifdef CONFIG_PAX_EMUTRAMP
36870+ if (elf_phdata->p_flags & PF_EMUTRAMP)
36871+ pax_flags |= MF_PAX_EMUTRAMP;
36872+#endif
36873+
36874+#ifdef CONFIG_PAX_MPROTECT
36875+ if (elf_phdata->p_flags & PF_MPROTECT)
36876+ pax_flags |= MF_PAX_MPROTECT;
36877+#endif
36878+
36879+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
36880+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
36881+ pax_flags |= MF_PAX_RANDMMAP;
36882+#endif
36883+
36884+ return pax_flags;
36885+}
36886+#endif
36887+
36888+#ifdef CONFIG_PAX_PT_PAX_FLAGS
36889+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
36890+{
36891+ unsigned long pax_flags = 0UL;
36892+
36893+#ifdef CONFIG_PAX_PAGEEXEC
36894+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
36895+ pax_flags |= MF_PAX_PAGEEXEC;
36896+#endif
36897+
36898+#ifdef CONFIG_PAX_SEGMEXEC
36899+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
36900+ pax_flags |= MF_PAX_SEGMEXEC;
36901+#endif
36902+
36903+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
36904+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36905+ if ((__supported_pte_mask & _PAGE_NX))
36906+ pax_flags &= ~MF_PAX_SEGMEXEC;
36907+ else
36908+ pax_flags &= ~MF_PAX_PAGEEXEC;
36909+ }
36910+#endif
36911+
36912+#ifdef CONFIG_PAX_EMUTRAMP
36913+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
36914+ pax_flags |= MF_PAX_EMUTRAMP;
36915+#endif
36916+
36917+#ifdef CONFIG_PAX_MPROTECT
36918+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
36919+ pax_flags |= MF_PAX_MPROTECT;
36920+#endif
36921+
36922+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
36923+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
36924+ pax_flags |= MF_PAX_RANDMMAP;
36925+#endif
36926+
36927+ return pax_flags;
36928+}
36929+#endif
36930+
36931+#ifdef CONFIG_PAX_EI_PAX
36932+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
36933+{
36934+ unsigned long pax_flags = 0UL;
36935+
36936+#ifdef CONFIG_PAX_PAGEEXEC
36937+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
36938+ pax_flags |= MF_PAX_PAGEEXEC;
36939+#endif
36940+
36941+#ifdef CONFIG_PAX_SEGMEXEC
36942+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
36943+ pax_flags |= MF_PAX_SEGMEXEC;
36944+#endif
36945+
36946+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
36947+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36948+ if ((__supported_pte_mask & _PAGE_NX))
36949+ pax_flags &= ~MF_PAX_SEGMEXEC;
36950+ else
36951+ pax_flags &= ~MF_PAX_PAGEEXEC;
36952+ }
36953+#endif
36954+
36955+#ifdef CONFIG_PAX_EMUTRAMP
36956+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
36957+ pax_flags |= MF_PAX_EMUTRAMP;
36958+#endif
36959+
36960+#ifdef CONFIG_PAX_MPROTECT
36961+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
36962+ pax_flags |= MF_PAX_MPROTECT;
36963+#endif
36964+
36965+#ifdef CONFIG_PAX_ASLR
36966+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
36967+ pax_flags |= MF_PAX_RANDMMAP;
36968+#endif
36969+
36970+ return pax_flags;
36971+}
36972+#endif
36973+
36974+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
36975+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
36976+{
36977+ unsigned long pax_flags = 0UL;
36978+
36979+#ifdef CONFIG_PAX_PT_PAX_FLAGS
36980+ unsigned long i;
36981+ int found_flags = 0;
36982+#endif
36983+
36984+#ifdef CONFIG_PAX_EI_PAX
36985+ pax_flags = pax_parse_ei_pax(elf_ex);
36986+#endif
36987+
36988+#ifdef CONFIG_PAX_PT_PAX_FLAGS
36989+ for (i = 0UL; i < elf_ex->e_phnum; i++)
36990+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
36991+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
36992+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
36993+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
36994+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
36995+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
36996+ return -EINVAL;
36997+
36998+#ifdef CONFIG_PAX_SOFTMODE
36999+ if (pax_softmode)
37000+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
37001+ else
37002+#endif
37003+
37004+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
37005+ found_flags = 1;
37006+ break;
37007+ }
37008+#endif
37009+
37010+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
37011+ if (found_flags == 0) {
37012+ struct elf_phdr phdr;
37013+ memset(&phdr, 0, sizeof(phdr));
37014+ phdr.p_flags = PF_NOEMUTRAMP;
37015+#ifdef CONFIG_PAX_SOFTMODE
37016+ if (pax_softmode)
37017+ pax_flags = pax_parse_softmode(&phdr);
37018+ else
37019+#endif
37020+ pax_flags = pax_parse_hardmode(&phdr);
37021+ }
37022+#endif
37023+
37024+ if (0 > pax_check_flags(&pax_flags))
37025+ return -EINVAL;
37026+
37027+ current->mm->pax_flags = pax_flags;
37028+ return 0;
37029+}
37030+#endif
37031+
37032 /*
37033 * These are the functions used to load ELF style executables and shared
37034 * libraries. There is no binary dependent code anywhere else.
37035@@ -544,6 +756,11 @@ static unsigned long randomize_stack_top
37036 {
37037 unsigned int random_variable = 0;
37038
37039+#ifdef CONFIG_PAX_RANDUSTACK
37040+ if (randomize_va_space)
37041+ return stack_top - current->mm->delta_stack;
37042+#endif
37043+
37044 if ((current->flags & PF_RANDOMIZE) &&
37045 !(current->personality & ADDR_NO_RANDOMIZE)) {
37046 random_variable = get_random_int() & STACK_RND_MASK;
37047@@ -562,7 +779,7 @@ static int load_elf_binary(struct linux_
37048 unsigned long load_addr = 0, load_bias = 0;
37049 int load_addr_set = 0;
37050 char * elf_interpreter = NULL;
37051- unsigned long error;
37052+ unsigned long error = 0;
37053 struct elf_phdr *elf_ppnt, *elf_phdata;
37054 unsigned long elf_bss, elf_brk;
37055 int retval, i;
37056@@ -572,11 +789,11 @@ static int load_elf_binary(struct linux_
37057 unsigned long start_code, end_code, start_data, end_data;
37058 unsigned long reloc_func_desc __maybe_unused = 0;
37059 int executable_stack = EXSTACK_DEFAULT;
37060- unsigned long def_flags = 0;
37061 struct {
37062 struct elfhdr elf_ex;
37063 struct elfhdr interp_elf_ex;
37064 } *loc;
37065+ unsigned long pax_task_size = TASK_SIZE;
37066
37067 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
37068 if (!loc) {
37069@@ -714,11 +931,81 @@ static int load_elf_binary(struct linux_
37070
37071 /* OK, This is the point of no return */
37072 current->flags &= ~PF_FORKNOEXEC;
37073- current->mm->def_flags = def_flags;
37074+
37075+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
37076+ current->mm->pax_flags = 0UL;
37077+#endif
37078+
37079+#ifdef CONFIG_PAX_DLRESOLVE
37080+ current->mm->call_dl_resolve = 0UL;
37081+#endif
37082+
37083+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
37084+ current->mm->call_syscall = 0UL;
37085+#endif
37086+
37087+#ifdef CONFIG_PAX_ASLR
37088+ current->mm->delta_mmap = 0UL;
37089+ current->mm->delta_stack = 0UL;
37090+#endif
37091+
37092+ current->mm->def_flags = 0;
37093+
37094+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
37095+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
37096+ send_sig(SIGKILL, current, 0);
37097+ goto out_free_dentry;
37098+ }
37099+#endif
37100+
37101+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
37102+ pax_set_initial_flags(bprm);
37103+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
37104+ if (pax_set_initial_flags_func)
37105+ (pax_set_initial_flags_func)(bprm);
37106+#endif
37107+
37108+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
37109+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
37110+ current->mm->context.user_cs_limit = PAGE_SIZE;
37111+ current->mm->def_flags |= VM_PAGEEXEC;
37112+ }
37113+#endif
37114+
37115+#ifdef CONFIG_PAX_SEGMEXEC
37116+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
37117+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
37118+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
37119+ pax_task_size = SEGMEXEC_TASK_SIZE;
37120+ current->mm->def_flags |= VM_NOHUGEPAGE;
37121+ }
37122+#endif
37123+
37124+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
37125+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
37126+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
37127+ put_cpu();
37128+ }
37129+#endif
37130
37131 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
37132 may depend on the personality. */
37133 SET_PERSONALITY(loc->elf_ex);
37134+
37135+#ifdef CONFIG_PAX_ASLR
37136+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
37137+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
37138+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
37139+ }
37140+#endif
37141+
37142+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
37143+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
37144+ executable_stack = EXSTACK_DISABLE_X;
37145+ current->personality &= ~READ_IMPLIES_EXEC;
37146+ } else
37147+#endif
37148+
37149 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
37150 current->personality |= READ_IMPLIES_EXEC;
37151
37152@@ -800,6 +1087,20 @@ static int load_elf_binary(struct linux_
37153 #else
37154 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
37155 #endif
37156+
37157+#ifdef CONFIG_PAX_RANDMMAP
37158+ /* PaX: randomize base address at the default exe base if requested */
37159+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
37160+#ifdef CONFIG_SPARC64
37161+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
37162+#else
37163+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
37164+#endif
37165+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
37166+ elf_flags |= MAP_FIXED;
37167+ }
37168+#endif
37169+
37170 }
37171
37172 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
37173@@ -832,9 +1133,9 @@ static int load_elf_binary(struct linux_
37174 * allowed task size. Note that p_filesz must always be
37175 * <= p_memsz so it is only necessary to check p_memsz.
37176 */
37177- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
37178- elf_ppnt->p_memsz > TASK_SIZE ||
37179- TASK_SIZE - elf_ppnt->p_memsz < k) {
37180+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
37181+ elf_ppnt->p_memsz > pax_task_size ||
37182+ pax_task_size - elf_ppnt->p_memsz < k) {
37183 /* set_brk can never work. Avoid overflows. */
37184 send_sig(SIGKILL, current, 0);
37185 retval = -EINVAL;
37186@@ -862,6 +1163,11 @@ static int load_elf_binary(struct linux_
37187 start_data += load_bias;
37188 end_data += load_bias;
37189
37190+#ifdef CONFIG_PAX_RANDMMAP
37191+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
37192+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
37193+#endif
37194+
37195 /* Calling set_brk effectively mmaps the pages that we need
37196 * for the bss and break sections. We must do this before
37197 * mapping in the interpreter, to make sure it doesn't wind
37198@@ -873,9 +1179,11 @@ static int load_elf_binary(struct linux_
37199 goto out_free_dentry;
37200 }
37201 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
37202- send_sig(SIGSEGV, current, 0);
37203- retval = -EFAULT; /* Nobody gets to see this, but.. */
37204- goto out_free_dentry;
37205+ /*
37206+ * This bss-zeroing can fail if the ELF
37207+ * file specifies odd protections. So
37208+ * we don't check the return value
37209+ */
37210 }
37211
37212 if (elf_interpreter) {
37213@@ -1090,7 +1398,7 @@ out:
37214 * Decide what to dump of a segment, part, all or none.
37215 */
37216 static unsigned long vma_dump_size(struct vm_area_struct *vma,
37217- unsigned long mm_flags)
37218+ unsigned long mm_flags, long signr)
37219 {
37220 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
37221
37222@@ -1124,7 +1432,7 @@ static unsigned long vma_dump_size(struc
37223 if (vma->vm_file == NULL)
37224 return 0;
37225
37226- if (FILTER(MAPPED_PRIVATE))
37227+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
37228 goto whole;
37229
37230 /*
37231@@ -1346,9 +1654,9 @@ static void fill_auxv_note(struct memelf
37232 {
37233 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
37234 int i = 0;
37235- do
37236+ do {
37237 i += 2;
37238- while (auxv[i - 2] != AT_NULL);
37239+ } while (auxv[i - 2] != AT_NULL);
37240 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
37241 }
37242
37243@@ -1854,14 +2162,14 @@ static void fill_extnum_info(struct elfh
37244 }
37245
37246 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
37247- unsigned long mm_flags)
37248+ struct coredump_params *cprm)
37249 {
37250 struct vm_area_struct *vma;
37251 size_t size = 0;
37252
37253 for (vma = first_vma(current, gate_vma); vma != NULL;
37254 vma = next_vma(vma, gate_vma))
37255- size += vma_dump_size(vma, mm_flags);
37256+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
37257 return size;
37258 }
37259
37260@@ -1955,7 +2263,7 @@ static int elf_core_dump(struct coredump
37261
37262 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
37263
37264- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
37265+ offset += elf_core_vma_data_size(gate_vma, cprm);
37266 offset += elf_core_extra_data_size();
37267 e_shoff = offset;
37268
37269@@ -1969,10 +2277,12 @@ static int elf_core_dump(struct coredump
37270 offset = dataoff;
37271
37272 size += sizeof(*elf);
37273+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
37274 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
37275 goto end_coredump;
37276
37277 size += sizeof(*phdr4note);
37278+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
37279 if (size > cprm->limit
37280 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
37281 goto end_coredump;
37282@@ -1986,7 +2296,7 @@ static int elf_core_dump(struct coredump
37283 phdr.p_offset = offset;
37284 phdr.p_vaddr = vma->vm_start;
37285 phdr.p_paddr = 0;
37286- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
37287+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
37288 phdr.p_memsz = vma->vm_end - vma->vm_start;
37289 offset += phdr.p_filesz;
37290 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
37291@@ -1997,6 +2307,7 @@ static int elf_core_dump(struct coredump
37292 phdr.p_align = ELF_EXEC_PAGESIZE;
37293
37294 size += sizeof(phdr);
37295+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
37296 if (size > cprm->limit
37297 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
37298 goto end_coredump;
37299@@ -2021,7 +2332,7 @@ static int elf_core_dump(struct coredump
37300 unsigned long addr;
37301 unsigned long end;
37302
37303- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
37304+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
37305
37306 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
37307 struct page *page;
37308@@ -2030,6 +2341,7 @@ static int elf_core_dump(struct coredump
37309 page = get_dump_page(addr);
37310 if (page) {
37311 void *kaddr = kmap(page);
37312+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
37313 stop = ((size += PAGE_SIZE) > cprm->limit) ||
37314 !dump_write(cprm->file, kaddr,
37315 PAGE_SIZE);
37316@@ -2047,6 +2359,7 @@ static int elf_core_dump(struct coredump
37317
37318 if (e_phnum == PN_XNUM) {
37319 size += sizeof(*shdr4extnum);
37320+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
37321 if (size > cprm->limit
37322 || !dump_write(cprm->file, shdr4extnum,
37323 sizeof(*shdr4extnum)))
37324@@ -2067,6 +2380,97 @@ out:
37325
37326 #endif /* CONFIG_ELF_CORE */
37327
37328+#ifdef CONFIG_PAX_MPROTECT
37329+/* PaX: non-PIC ELF libraries need relocations on their executable segments
37330+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
37331+ * we'll remove VM_MAYWRITE for good on RELRO segments.
37332+ *
37333+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
37334+ * basis because we want to allow the common case and not the special ones.
37335+ */
37336+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
37337+{
37338+ struct elfhdr elf_h;
37339+ struct elf_phdr elf_p;
37340+ unsigned long i;
37341+ unsigned long oldflags;
37342+ bool is_textrel_rw, is_textrel_rx, is_relro;
37343+
37344+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
37345+ return;
37346+
37347+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
37348+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
37349+
37350+#ifdef CONFIG_PAX_ELFRELOCS
37351+ /* possible TEXTREL */
37352+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
37353+ 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);
37354+#else
37355+ is_textrel_rw = false;
37356+ is_textrel_rx = false;
37357+#endif
37358+
37359+ /* possible RELRO */
37360+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
37361+
37362+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
37363+ return;
37364+
37365+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
37366+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
37367+
37368+#ifdef CONFIG_PAX_ETEXECRELOCS
37369+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
37370+#else
37371+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
37372+#endif
37373+
37374+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
37375+ !elf_check_arch(&elf_h) ||
37376+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
37377+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
37378+ return;
37379+
37380+ for (i = 0UL; i < elf_h.e_phnum; i++) {
37381+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
37382+ return;
37383+ switch (elf_p.p_type) {
37384+ case PT_DYNAMIC:
37385+ if (!is_textrel_rw && !is_textrel_rx)
37386+ continue;
37387+ i = 0UL;
37388+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
37389+ elf_dyn dyn;
37390+
37391+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
37392+ return;
37393+ if (dyn.d_tag == DT_NULL)
37394+ return;
37395+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
37396+ gr_log_textrel(vma);
37397+ if (is_textrel_rw)
37398+ vma->vm_flags |= VM_MAYWRITE;
37399+ else
37400+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
37401+ vma->vm_flags &= ~VM_MAYWRITE;
37402+ return;
37403+ }
37404+ i++;
37405+ }
37406+ return;
37407+
37408+ case PT_GNU_RELRO:
37409+ if (!is_relro)
37410+ continue;
37411+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
37412+ vma->vm_flags &= ~VM_MAYWRITE;
37413+ return;
37414+ }
37415+ }
37416+}
37417+#endif
37418+
37419 static int __init init_elf_binfmt(void)
37420 {
37421 return register_binfmt(&elf_format);
37422diff -urNp linux-3.0.4/fs/binfmt_flat.c linux-3.0.4/fs/binfmt_flat.c
37423--- linux-3.0.4/fs/binfmt_flat.c 2011-07-21 22:17:23.000000000 -0400
37424+++ linux-3.0.4/fs/binfmt_flat.c 2011-08-23 21:47:56.000000000 -0400
37425@@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
37426 realdatastart = (unsigned long) -ENOMEM;
37427 printk("Unable to allocate RAM for process data, errno %d\n",
37428 (int)-realdatastart);
37429+ down_write(&current->mm->mmap_sem);
37430 do_munmap(current->mm, textpos, text_len);
37431+ up_write(&current->mm->mmap_sem);
37432 ret = realdatastart;
37433 goto err;
37434 }
37435@@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
37436 }
37437 if (IS_ERR_VALUE(result)) {
37438 printk("Unable to read data+bss, errno %d\n", (int)-result);
37439+ down_write(&current->mm->mmap_sem);
37440 do_munmap(current->mm, textpos, text_len);
37441 do_munmap(current->mm, realdatastart, len);
37442+ up_write(&current->mm->mmap_sem);
37443 ret = result;
37444 goto err;
37445 }
37446@@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
37447 }
37448 if (IS_ERR_VALUE(result)) {
37449 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
37450+ down_write(&current->mm->mmap_sem);
37451 do_munmap(current->mm, textpos, text_len + data_len + extra +
37452 MAX_SHARED_LIBS * sizeof(unsigned long));
37453+ up_write(&current->mm->mmap_sem);
37454 ret = result;
37455 goto err;
37456 }
37457diff -urNp linux-3.0.4/fs/bio.c linux-3.0.4/fs/bio.c
37458--- linux-3.0.4/fs/bio.c 2011-07-21 22:17:23.000000000 -0400
37459+++ linux-3.0.4/fs/bio.c 2011-08-23 21:47:56.000000000 -0400
37460@@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
37461 const int read = bio_data_dir(bio) == READ;
37462 struct bio_map_data *bmd = bio->bi_private;
37463 int i;
37464- char *p = bmd->sgvecs[0].iov_base;
37465+ char *p = (__force char *)bmd->sgvecs[0].iov_base;
37466
37467 __bio_for_each_segment(bvec, bio, i, 0) {
37468 char *addr = page_address(bvec->bv_page);
37469diff -urNp linux-3.0.4/fs/block_dev.c linux-3.0.4/fs/block_dev.c
37470--- linux-3.0.4/fs/block_dev.c 2011-07-21 22:17:23.000000000 -0400
37471+++ linux-3.0.4/fs/block_dev.c 2011-08-23 21:47:56.000000000 -0400
37472@@ -671,7 +671,7 @@ static bool bd_may_claim(struct block_de
37473 else if (bdev->bd_contains == bdev)
37474 return true; /* is a whole device which isn't held */
37475
37476- else if (whole->bd_holder == bd_may_claim)
37477+ else if (whole->bd_holder == (void *)bd_may_claim)
37478 return true; /* is a partition of a device that is being partitioned */
37479 else if (whole->bd_holder != NULL)
37480 return false; /* is a partition of a held device */
37481diff -urNp linux-3.0.4/fs/btrfs/ctree.c linux-3.0.4/fs/btrfs/ctree.c
37482--- linux-3.0.4/fs/btrfs/ctree.c 2011-07-21 22:17:23.000000000 -0400
37483+++ linux-3.0.4/fs/btrfs/ctree.c 2011-08-23 21:47:56.000000000 -0400
37484@@ -454,9 +454,12 @@ static noinline int __btrfs_cow_block(st
37485 free_extent_buffer(buf);
37486 add_root_to_dirty_list(root);
37487 } else {
37488- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
37489- parent_start = parent->start;
37490- else
37491+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
37492+ if (parent)
37493+ parent_start = parent->start;
37494+ else
37495+ parent_start = 0;
37496+ } else
37497 parent_start = 0;
37498
37499 WARN_ON(trans->transid != btrfs_header_generation(parent));
37500diff -urNp linux-3.0.4/fs/btrfs/inode.c linux-3.0.4/fs/btrfs/inode.c
37501--- linux-3.0.4/fs/btrfs/inode.c 2011-07-21 22:17:23.000000000 -0400
37502+++ linux-3.0.4/fs/btrfs/inode.c 2011-08-23 21:48:14.000000000 -0400
37503@@ -6895,7 +6895,7 @@ fail:
37504 return -ENOMEM;
37505 }
37506
37507-static int btrfs_getattr(struct vfsmount *mnt,
37508+int btrfs_getattr(struct vfsmount *mnt,
37509 struct dentry *dentry, struct kstat *stat)
37510 {
37511 struct inode *inode = dentry->d_inode;
37512@@ -6907,6 +6907,14 @@ static int btrfs_getattr(struct vfsmount
37513 return 0;
37514 }
37515
37516+EXPORT_SYMBOL(btrfs_getattr);
37517+
37518+dev_t get_btrfs_dev_from_inode(struct inode *inode)
37519+{
37520+ return BTRFS_I(inode)->root->anon_super.s_dev;
37521+}
37522+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
37523+
37524 /*
37525 * If a file is moved, it will inherit the cow and compression flags of the new
37526 * directory.
37527diff -urNp linux-3.0.4/fs/btrfs/ioctl.c linux-3.0.4/fs/btrfs/ioctl.c
37528--- linux-3.0.4/fs/btrfs/ioctl.c 2011-07-21 22:17:23.000000000 -0400
37529+++ linux-3.0.4/fs/btrfs/ioctl.c 2011-08-23 21:48:14.000000000 -0400
37530@@ -2676,9 +2676,12 @@ long btrfs_ioctl_space_info(struct btrfs
37531 for (i = 0; i < num_types; i++) {
37532 struct btrfs_space_info *tmp;
37533
37534+ /* Don't copy in more than we allocated */
37535 if (!slot_count)
37536 break;
37537
37538+ slot_count--;
37539+
37540 info = NULL;
37541 rcu_read_lock();
37542 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
37543@@ -2700,10 +2703,7 @@ long btrfs_ioctl_space_info(struct btrfs
37544 memcpy(dest, &space, sizeof(space));
37545 dest++;
37546 space_args.total_spaces++;
37547- slot_count--;
37548 }
37549- if (!slot_count)
37550- break;
37551 }
37552 up_read(&info->groups_sem);
37553 }
37554diff -urNp linux-3.0.4/fs/btrfs/relocation.c linux-3.0.4/fs/btrfs/relocation.c
37555--- linux-3.0.4/fs/btrfs/relocation.c 2011-07-21 22:17:23.000000000 -0400
37556+++ linux-3.0.4/fs/btrfs/relocation.c 2011-08-23 21:47:56.000000000 -0400
37557@@ -1242,7 +1242,7 @@ static int __update_reloc_root(struct bt
37558 }
37559 spin_unlock(&rc->reloc_root_tree.lock);
37560
37561- BUG_ON((struct btrfs_root *)node->data != root);
37562+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
37563
37564 if (!del) {
37565 spin_lock(&rc->reloc_root_tree.lock);
37566diff -urNp linux-3.0.4/fs/cachefiles/bind.c linux-3.0.4/fs/cachefiles/bind.c
37567--- linux-3.0.4/fs/cachefiles/bind.c 2011-07-21 22:17:23.000000000 -0400
37568+++ linux-3.0.4/fs/cachefiles/bind.c 2011-08-23 21:47:56.000000000 -0400
37569@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
37570 args);
37571
37572 /* start by checking things over */
37573- ASSERT(cache->fstop_percent >= 0 &&
37574- cache->fstop_percent < cache->fcull_percent &&
37575+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
37576 cache->fcull_percent < cache->frun_percent &&
37577 cache->frun_percent < 100);
37578
37579- ASSERT(cache->bstop_percent >= 0 &&
37580- cache->bstop_percent < cache->bcull_percent &&
37581+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
37582 cache->bcull_percent < cache->brun_percent &&
37583 cache->brun_percent < 100);
37584
37585diff -urNp linux-3.0.4/fs/cachefiles/daemon.c linux-3.0.4/fs/cachefiles/daemon.c
37586--- linux-3.0.4/fs/cachefiles/daemon.c 2011-07-21 22:17:23.000000000 -0400
37587+++ linux-3.0.4/fs/cachefiles/daemon.c 2011-08-23 21:47:56.000000000 -0400
37588@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
37589 if (n > buflen)
37590 return -EMSGSIZE;
37591
37592- if (copy_to_user(_buffer, buffer, n) != 0)
37593+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
37594 return -EFAULT;
37595
37596 return n;
37597@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
37598 if (test_bit(CACHEFILES_DEAD, &cache->flags))
37599 return -EIO;
37600
37601- if (datalen < 0 || datalen > PAGE_SIZE - 1)
37602+ if (datalen > PAGE_SIZE - 1)
37603 return -EOPNOTSUPP;
37604
37605 /* drag the command string into the kernel so we can parse it */
37606@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
37607 if (args[0] != '%' || args[1] != '\0')
37608 return -EINVAL;
37609
37610- if (fstop < 0 || fstop >= cache->fcull_percent)
37611+ if (fstop >= cache->fcull_percent)
37612 return cachefiles_daemon_range_error(cache, args);
37613
37614 cache->fstop_percent = fstop;
37615@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
37616 if (args[0] != '%' || args[1] != '\0')
37617 return -EINVAL;
37618
37619- if (bstop < 0 || bstop >= cache->bcull_percent)
37620+ if (bstop >= cache->bcull_percent)
37621 return cachefiles_daemon_range_error(cache, args);
37622
37623 cache->bstop_percent = bstop;
37624diff -urNp linux-3.0.4/fs/cachefiles/internal.h linux-3.0.4/fs/cachefiles/internal.h
37625--- linux-3.0.4/fs/cachefiles/internal.h 2011-07-21 22:17:23.000000000 -0400
37626+++ linux-3.0.4/fs/cachefiles/internal.h 2011-08-23 21:47:56.000000000 -0400
37627@@ -57,7 +57,7 @@ struct cachefiles_cache {
37628 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
37629 struct rb_root active_nodes; /* active nodes (can't be culled) */
37630 rwlock_t active_lock; /* lock for active_nodes */
37631- atomic_t gravecounter; /* graveyard uniquifier */
37632+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
37633 unsigned frun_percent; /* when to stop culling (% files) */
37634 unsigned fcull_percent; /* when to start culling (% files) */
37635 unsigned fstop_percent; /* when to stop allocating (% files) */
37636@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struc
37637 * proc.c
37638 */
37639 #ifdef CONFIG_CACHEFILES_HISTOGRAM
37640-extern atomic_t cachefiles_lookup_histogram[HZ];
37641-extern atomic_t cachefiles_mkdir_histogram[HZ];
37642-extern atomic_t cachefiles_create_histogram[HZ];
37643+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
37644+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
37645+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
37646
37647 extern int __init cachefiles_proc_init(void);
37648 extern void cachefiles_proc_cleanup(void);
37649 static inline
37650-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
37651+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
37652 {
37653 unsigned long jif = jiffies - start_jif;
37654 if (jif >= HZ)
37655 jif = HZ - 1;
37656- atomic_inc(&histogram[jif]);
37657+ atomic_inc_unchecked(&histogram[jif]);
37658 }
37659
37660 #else
37661diff -urNp linux-3.0.4/fs/cachefiles/namei.c linux-3.0.4/fs/cachefiles/namei.c
37662--- linux-3.0.4/fs/cachefiles/namei.c 2011-07-21 22:17:23.000000000 -0400
37663+++ linux-3.0.4/fs/cachefiles/namei.c 2011-08-23 21:47:56.000000000 -0400
37664@@ -318,7 +318,7 @@ try_again:
37665 /* first step is to make up a grave dentry in the graveyard */
37666 sprintf(nbuffer, "%08x%08x",
37667 (uint32_t) get_seconds(),
37668- (uint32_t) atomic_inc_return(&cache->gravecounter));
37669+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
37670
37671 /* do the multiway lock magic */
37672 trap = lock_rename(cache->graveyard, dir);
37673diff -urNp linux-3.0.4/fs/cachefiles/proc.c linux-3.0.4/fs/cachefiles/proc.c
37674--- linux-3.0.4/fs/cachefiles/proc.c 2011-07-21 22:17:23.000000000 -0400
37675+++ linux-3.0.4/fs/cachefiles/proc.c 2011-08-23 21:47:56.000000000 -0400
37676@@ -14,9 +14,9 @@
37677 #include <linux/seq_file.h>
37678 #include "internal.h"
37679
37680-atomic_t cachefiles_lookup_histogram[HZ];
37681-atomic_t cachefiles_mkdir_histogram[HZ];
37682-atomic_t cachefiles_create_histogram[HZ];
37683+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
37684+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
37685+atomic_unchecked_t cachefiles_create_histogram[HZ];
37686
37687 /*
37688 * display the latency histogram
37689@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
37690 return 0;
37691 default:
37692 index = (unsigned long) v - 3;
37693- x = atomic_read(&cachefiles_lookup_histogram[index]);
37694- y = atomic_read(&cachefiles_mkdir_histogram[index]);
37695- z = atomic_read(&cachefiles_create_histogram[index]);
37696+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
37697+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
37698+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
37699 if (x == 0 && y == 0 && z == 0)
37700 return 0;
37701
37702diff -urNp linux-3.0.4/fs/cachefiles/rdwr.c linux-3.0.4/fs/cachefiles/rdwr.c
37703--- linux-3.0.4/fs/cachefiles/rdwr.c 2011-07-21 22:17:23.000000000 -0400
37704+++ linux-3.0.4/fs/cachefiles/rdwr.c 2011-08-23 21:47:56.000000000 -0400
37705@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
37706 old_fs = get_fs();
37707 set_fs(KERNEL_DS);
37708 ret = file->f_op->write(
37709- file, (const void __user *) data, len, &pos);
37710+ file, (__force const void __user *) data, len, &pos);
37711 set_fs(old_fs);
37712 kunmap(page);
37713 if (ret != len)
37714diff -urNp linux-3.0.4/fs/ceph/dir.c linux-3.0.4/fs/ceph/dir.c
37715--- linux-3.0.4/fs/ceph/dir.c 2011-07-21 22:17:23.000000000 -0400
37716+++ linux-3.0.4/fs/ceph/dir.c 2011-08-23 21:47:56.000000000 -0400
37717@@ -226,7 +226,7 @@ static int ceph_readdir(struct file *fil
37718 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
37719 struct ceph_mds_client *mdsc = fsc->mdsc;
37720 unsigned frag = fpos_frag(filp->f_pos);
37721- int off = fpos_off(filp->f_pos);
37722+ unsigned int off = fpos_off(filp->f_pos);
37723 int err;
37724 u32 ftype;
37725 struct ceph_mds_reply_info_parsed *rinfo;
37726diff -urNp linux-3.0.4/fs/cifs/cifs_debug.c linux-3.0.4/fs/cifs/cifs_debug.c
37727--- linux-3.0.4/fs/cifs/cifs_debug.c 2011-07-21 22:17:23.000000000 -0400
37728+++ linux-3.0.4/fs/cifs/cifs_debug.c 2011-08-25 17:18:05.000000000 -0400
37729@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(str
37730
37731 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
37732 #ifdef CONFIG_CIFS_STATS2
37733- atomic_set(&totBufAllocCount, 0);
37734- atomic_set(&totSmBufAllocCount, 0);
37735+ atomic_set_unchecked(&totBufAllocCount, 0);
37736+ atomic_set_unchecked(&totSmBufAllocCount, 0);
37737 #endif /* CONFIG_CIFS_STATS2 */
37738 spin_lock(&cifs_tcp_ses_lock);
37739 list_for_each(tmp1, &cifs_tcp_ses_list) {
37740@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(str
37741 tcon = list_entry(tmp3,
37742 struct cifs_tcon,
37743 tcon_list);
37744- atomic_set(&tcon->num_smbs_sent, 0);
37745- atomic_set(&tcon->num_writes, 0);
37746- atomic_set(&tcon->num_reads, 0);
37747- atomic_set(&tcon->num_oplock_brks, 0);
37748- atomic_set(&tcon->num_opens, 0);
37749- atomic_set(&tcon->num_posixopens, 0);
37750- atomic_set(&tcon->num_posixmkdirs, 0);
37751- atomic_set(&tcon->num_closes, 0);
37752- atomic_set(&tcon->num_deletes, 0);
37753- atomic_set(&tcon->num_mkdirs, 0);
37754- atomic_set(&tcon->num_rmdirs, 0);
37755- atomic_set(&tcon->num_renames, 0);
37756- atomic_set(&tcon->num_t2renames, 0);
37757- atomic_set(&tcon->num_ffirst, 0);
37758- atomic_set(&tcon->num_fnext, 0);
37759- atomic_set(&tcon->num_fclose, 0);
37760- atomic_set(&tcon->num_hardlinks, 0);
37761- atomic_set(&tcon->num_symlinks, 0);
37762- atomic_set(&tcon->num_locks, 0);
37763+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
37764+ atomic_set_unchecked(&tcon->num_writes, 0);
37765+ atomic_set_unchecked(&tcon->num_reads, 0);
37766+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
37767+ atomic_set_unchecked(&tcon->num_opens, 0);
37768+ atomic_set_unchecked(&tcon->num_posixopens, 0);
37769+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
37770+ atomic_set_unchecked(&tcon->num_closes, 0);
37771+ atomic_set_unchecked(&tcon->num_deletes, 0);
37772+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
37773+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
37774+ atomic_set_unchecked(&tcon->num_renames, 0);
37775+ atomic_set_unchecked(&tcon->num_t2renames, 0);
37776+ atomic_set_unchecked(&tcon->num_ffirst, 0);
37777+ atomic_set_unchecked(&tcon->num_fnext, 0);
37778+ atomic_set_unchecked(&tcon->num_fclose, 0);
37779+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
37780+ atomic_set_unchecked(&tcon->num_symlinks, 0);
37781+ atomic_set_unchecked(&tcon->num_locks, 0);
37782 }
37783 }
37784 }
37785@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct s
37786 smBufAllocCount.counter, cifs_min_small);
37787 #ifdef CONFIG_CIFS_STATS2
37788 seq_printf(m, "Total Large %d Small %d Allocations\n",
37789- atomic_read(&totBufAllocCount),
37790- atomic_read(&totSmBufAllocCount));
37791+ atomic_read_unchecked(&totBufAllocCount),
37792+ atomic_read_unchecked(&totSmBufAllocCount));
37793 #endif /* CONFIG_CIFS_STATS2 */
37794
37795 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
37796@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct s
37797 if (tcon->need_reconnect)
37798 seq_puts(m, "\tDISCONNECTED ");
37799 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
37800- atomic_read(&tcon->num_smbs_sent),
37801- atomic_read(&tcon->num_oplock_brks));
37802+ atomic_read_unchecked(&tcon->num_smbs_sent),
37803+ atomic_read_unchecked(&tcon->num_oplock_brks));
37804 seq_printf(m, "\nReads: %d Bytes: %lld",
37805- atomic_read(&tcon->num_reads),
37806+ atomic_read_unchecked(&tcon->num_reads),
37807 (long long)(tcon->bytes_read));
37808 seq_printf(m, "\nWrites: %d Bytes: %lld",
37809- atomic_read(&tcon->num_writes),
37810+ atomic_read_unchecked(&tcon->num_writes),
37811 (long long)(tcon->bytes_written));
37812 seq_printf(m, "\nFlushes: %d",
37813- atomic_read(&tcon->num_flushes));
37814+ atomic_read_unchecked(&tcon->num_flushes));
37815 seq_printf(m, "\nLocks: %d HardLinks: %d "
37816 "Symlinks: %d",
37817- atomic_read(&tcon->num_locks),
37818- atomic_read(&tcon->num_hardlinks),
37819- atomic_read(&tcon->num_symlinks));
37820+ atomic_read_unchecked(&tcon->num_locks),
37821+ atomic_read_unchecked(&tcon->num_hardlinks),
37822+ atomic_read_unchecked(&tcon->num_symlinks));
37823 seq_printf(m, "\nOpens: %d Closes: %d "
37824 "Deletes: %d",
37825- atomic_read(&tcon->num_opens),
37826- atomic_read(&tcon->num_closes),
37827- atomic_read(&tcon->num_deletes));
37828+ atomic_read_unchecked(&tcon->num_opens),
37829+ atomic_read_unchecked(&tcon->num_closes),
37830+ atomic_read_unchecked(&tcon->num_deletes));
37831 seq_printf(m, "\nPosix Opens: %d "
37832 "Posix Mkdirs: %d",
37833- atomic_read(&tcon->num_posixopens),
37834- atomic_read(&tcon->num_posixmkdirs));
37835+ atomic_read_unchecked(&tcon->num_posixopens),
37836+ atomic_read_unchecked(&tcon->num_posixmkdirs));
37837 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
37838- atomic_read(&tcon->num_mkdirs),
37839- atomic_read(&tcon->num_rmdirs));
37840+ atomic_read_unchecked(&tcon->num_mkdirs),
37841+ atomic_read_unchecked(&tcon->num_rmdirs));
37842 seq_printf(m, "\nRenames: %d T2 Renames %d",
37843- atomic_read(&tcon->num_renames),
37844- atomic_read(&tcon->num_t2renames));
37845+ atomic_read_unchecked(&tcon->num_renames),
37846+ atomic_read_unchecked(&tcon->num_t2renames));
37847 seq_printf(m, "\nFindFirst: %d FNext %d "
37848 "FClose %d",
37849- atomic_read(&tcon->num_ffirst),
37850- atomic_read(&tcon->num_fnext),
37851- atomic_read(&tcon->num_fclose));
37852+ atomic_read_unchecked(&tcon->num_ffirst),
37853+ atomic_read_unchecked(&tcon->num_fnext),
37854+ atomic_read_unchecked(&tcon->num_fclose));
37855 }
37856 }
37857 }
37858diff -urNp linux-3.0.4/fs/cifs/cifsfs.c linux-3.0.4/fs/cifs/cifsfs.c
37859--- linux-3.0.4/fs/cifs/cifsfs.c 2011-08-23 21:44:40.000000000 -0400
37860+++ linux-3.0.4/fs/cifs/cifsfs.c 2011-08-25 17:18:05.000000000 -0400
37861@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
37862 cifs_req_cachep = kmem_cache_create("cifs_request",
37863 CIFSMaxBufSize +
37864 MAX_CIFS_HDR_SIZE, 0,
37865- SLAB_HWCACHE_ALIGN, NULL);
37866+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
37867 if (cifs_req_cachep == NULL)
37868 return -ENOMEM;
37869
37870@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
37871 efficient to alloc 1 per page off the slab compared to 17K (5page)
37872 alloc of large cifs buffers even when page debugging is on */
37873 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
37874- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
37875+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
37876 NULL);
37877 if (cifs_sm_req_cachep == NULL) {
37878 mempool_destroy(cifs_req_poolp);
37879@@ -1106,8 +1106,8 @@ init_cifs(void)
37880 atomic_set(&bufAllocCount, 0);
37881 atomic_set(&smBufAllocCount, 0);
37882 #ifdef CONFIG_CIFS_STATS2
37883- atomic_set(&totBufAllocCount, 0);
37884- atomic_set(&totSmBufAllocCount, 0);
37885+ atomic_set_unchecked(&totBufAllocCount, 0);
37886+ atomic_set_unchecked(&totSmBufAllocCount, 0);
37887 #endif /* CONFIG_CIFS_STATS2 */
37888
37889 atomic_set(&midCount, 0);
37890diff -urNp linux-3.0.4/fs/cifs/cifsglob.h linux-3.0.4/fs/cifs/cifsglob.h
37891--- linux-3.0.4/fs/cifs/cifsglob.h 2011-07-21 22:17:23.000000000 -0400
37892+++ linux-3.0.4/fs/cifs/cifsglob.h 2011-08-25 17:18:05.000000000 -0400
37893@@ -381,28 +381,28 @@ struct cifs_tcon {
37894 __u16 Flags; /* optional support bits */
37895 enum statusEnum tidStatus;
37896 #ifdef CONFIG_CIFS_STATS
37897- atomic_t num_smbs_sent;
37898- atomic_t num_writes;
37899- atomic_t num_reads;
37900- atomic_t num_flushes;
37901- atomic_t num_oplock_brks;
37902- atomic_t num_opens;
37903- atomic_t num_closes;
37904- atomic_t num_deletes;
37905- atomic_t num_mkdirs;
37906- atomic_t num_posixopens;
37907- atomic_t num_posixmkdirs;
37908- atomic_t num_rmdirs;
37909- atomic_t num_renames;
37910- atomic_t num_t2renames;
37911- atomic_t num_ffirst;
37912- atomic_t num_fnext;
37913- atomic_t num_fclose;
37914- atomic_t num_hardlinks;
37915- atomic_t num_symlinks;
37916- atomic_t num_locks;
37917- atomic_t num_acl_get;
37918- atomic_t num_acl_set;
37919+ atomic_unchecked_t num_smbs_sent;
37920+ atomic_unchecked_t num_writes;
37921+ atomic_unchecked_t num_reads;
37922+ atomic_unchecked_t num_flushes;
37923+ atomic_unchecked_t num_oplock_brks;
37924+ atomic_unchecked_t num_opens;
37925+ atomic_unchecked_t num_closes;
37926+ atomic_unchecked_t num_deletes;
37927+ atomic_unchecked_t num_mkdirs;
37928+ atomic_unchecked_t num_posixopens;
37929+ atomic_unchecked_t num_posixmkdirs;
37930+ atomic_unchecked_t num_rmdirs;
37931+ atomic_unchecked_t num_renames;
37932+ atomic_unchecked_t num_t2renames;
37933+ atomic_unchecked_t num_ffirst;
37934+ atomic_unchecked_t num_fnext;
37935+ atomic_unchecked_t num_fclose;
37936+ atomic_unchecked_t num_hardlinks;
37937+ atomic_unchecked_t num_symlinks;
37938+ atomic_unchecked_t num_locks;
37939+ atomic_unchecked_t num_acl_get;
37940+ atomic_unchecked_t num_acl_set;
37941 #ifdef CONFIG_CIFS_STATS2
37942 unsigned long long time_writes;
37943 unsigned long long time_reads;
37944@@ -613,7 +613,7 @@ convert_delimiter(char *path, char delim
37945 }
37946
37947 #ifdef CONFIG_CIFS_STATS
37948-#define cifs_stats_inc atomic_inc
37949+#define cifs_stats_inc atomic_inc_unchecked
37950
37951 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
37952 unsigned int bytes)
37953@@ -911,8 +911,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnect
37954 /* Various Debug counters */
37955 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
37956 #ifdef CONFIG_CIFS_STATS2
37957-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
37958-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
37959+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
37960+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
37961 #endif
37962 GLOBAL_EXTERN atomic_t smBufAllocCount;
37963 GLOBAL_EXTERN atomic_t midCount;
37964diff -urNp linux-3.0.4/fs/cifs/link.c linux-3.0.4/fs/cifs/link.c
37965--- linux-3.0.4/fs/cifs/link.c 2011-07-21 22:17:23.000000000 -0400
37966+++ linux-3.0.4/fs/cifs/link.c 2011-08-23 21:47:56.000000000 -0400
37967@@ -587,7 +587,7 @@ symlink_exit:
37968
37969 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
37970 {
37971- char *p = nd_get_link(nd);
37972+ const char *p = nd_get_link(nd);
37973 if (!IS_ERR(p))
37974 kfree(p);
37975 }
37976diff -urNp linux-3.0.4/fs/cifs/misc.c linux-3.0.4/fs/cifs/misc.c
37977--- linux-3.0.4/fs/cifs/misc.c 2011-07-21 22:17:23.000000000 -0400
37978+++ linux-3.0.4/fs/cifs/misc.c 2011-08-25 17:18:05.000000000 -0400
37979@@ -156,7 +156,7 @@ cifs_buf_get(void)
37980 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
37981 atomic_inc(&bufAllocCount);
37982 #ifdef CONFIG_CIFS_STATS2
37983- atomic_inc(&totBufAllocCount);
37984+ atomic_inc_unchecked(&totBufAllocCount);
37985 #endif /* CONFIG_CIFS_STATS2 */
37986 }
37987
37988@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
37989 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
37990 atomic_inc(&smBufAllocCount);
37991 #ifdef CONFIG_CIFS_STATS2
37992- atomic_inc(&totSmBufAllocCount);
37993+ atomic_inc_unchecked(&totSmBufAllocCount);
37994 #endif /* CONFIG_CIFS_STATS2 */
37995
37996 }
37997diff -urNp linux-3.0.4/fs/coda/cache.c linux-3.0.4/fs/coda/cache.c
37998--- linux-3.0.4/fs/coda/cache.c 2011-07-21 22:17:23.000000000 -0400
37999+++ linux-3.0.4/fs/coda/cache.c 2011-08-23 21:47:56.000000000 -0400
38000@@ -24,7 +24,7 @@
38001 #include "coda_linux.h"
38002 #include "coda_cache.h"
38003
38004-static atomic_t permission_epoch = ATOMIC_INIT(0);
38005+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
38006
38007 /* replace or extend an acl cache hit */
38008 void coda_cache_enter(struct inode *inode, int mask)
38009@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inod
38010 struct coda_inode_info *cii = ITOC(inode);
38011
38012 spin_lock(&cii->c_lock);
38013- cii->c_cached_epoch = atomic_read(&permission_epoch);
38014+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
38015 if (cii->c_uid != current_fsuid()) {
38016 cii->c_uid = current_fsuid();
38017 cii->c_cached_perm = mask;
38018@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode
38019 {
38020 struct coda_inode_info *cii = ITOC(inode);
38021 spin_lock(&cii->c_lock);
38022- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
38023+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
38024 spin_unlock(&cii->c_lock);
38025 }
38026
38027 /* remove all acl caches */
38028 void coda_cache_clear_all(struct super_block *sb)
38029 {
38030- atomic_inc(&permission_epoch);
38031+ atomic_inc_unchecked(&permission_epoch);
38032 }
38033
38034
38035@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode
38036 spin_lock(&cii->c_lock);
38037 hit = (mask & cii->c_cached_perm) == mask &&
38038 cii->c_uid == current_fsuid() &&
38039- cii->c_cached_epoch == atomic_read(&permission_epoch);
38040+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
38041 spin_unlock(&cii->c_lock);
38042
38043 return hit;
38044diff -urNp linux-3.0.4/fs/compat_binfmt_elf.c linux-3.0.4/fs/compat_binfmt_elf.c
38045--- linux-3.0.4/fs/compat_binfmt_elf.c 2011-07-21 22:17:23.000000000 -0400
38046+++ linux-3.0.4/fs/compat_binfmt_elf.c 2011-08-23 21:47:56.000000000 -0400
38047@@ -30,11 +30,13 @@
38048 #undef elf_phdr
38049 #undef elf_shdr
38050 #undef elf_note
38051+#undef elf_dyn
38052 #undef elf_addr_t
38053 #define elfhdr elf32_hdr
38054 #define elf_phdr elf32_phdr
38055 #define elf_shdr elf32_shdr
38056 #define elf_note elf32_note
38057+#define elf_dyn Elf32_Dyn
38058 #define elf_addr_t Elf32_Addr
38059
38060 /*
38061diff -urNp linux-3.0.4/fs/compat.c linux-3.0.4/fs/compat.c
38062--- linux-3.0.4/fs/compat.c 2011-07-21 22:17:23.000000000 -0400
38063+++ linux-3.0.4/fs/compat.c 2011-08-23 22:49:33.000000000 -0400
38064@@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int
38065 goto out;
38066
38067 ret = -EINVAL;
38068- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
38069+ if (nr_segs > UIO_MAXIOV)
38070 goto out;
38071 if (nr_segs > fast_segs) {
38072 ret = -ENOMEM;
38073@@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
38074
38075 struct compat_readdir_callback {
38076 struct compat_old_linux_dirent __user *dirent;
38077+ struct file * file;
38078 int result;
38079 };
38080
38081@@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf
38082 buf->result = -EOVERFLOW;
38083 return -EOVERFLOW;
38084 }
38085+
38086+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
38087+ return 0;
38088+
38089 buf->result++;
38090 dirent = buf->dirent;
38091 if (!access_ok(VERIFY_WRITE, dirent,
38092@@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(u
38093
38094 buf.result = 0;
38095 buf.dirent = dirent;
38096+ buf.file = file;
38097
38098 error = vfs_readdir(file, compat_fillonedir, &buf);
38099 if (buf.result)
38100@@ -917,6 +923,7 @@ struct compat_linux_dirent {
38101 struct compat_getdents_callback {
38102 struct compat_linux_dirent __user *current_dir;
38103 struct compat_linux_dirent __user *previous;
38104+ struct file * file;
38105 int count;
38106 int error;
38107 };
38108@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, c
38109 buf->error = -EOVERFLOW;
38110 return -EOVERFLOW;
38111 }
38112+
38113+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
38114+ return 0;
38115+
38116 dirent = buf->previous;
38117 if (dirent) {
38118 if (__put_user(offset, &dirent->d_off))
38119@@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsi
38120 buf.previous = NULL;
38121 buf.count = count;
38122 buf.error = 0;
38123+ buf.file = file;
38124
38125 error = vfs_readdir(file, compat_filldir, &buf);
38126 if (error >= 0)
38127@@ -1006,6 +1018,7 @@ out:
38128 struct compat_getdents_callback64 {
38129 struct linux_dirent64 __user *current_dir;
38130 struct linux_dirent64 __user *previous;
38131+ struct file * file;
38132 int count;
38133 int error;
38134 };
38135@@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf
38136 buf->error = -EINVAL; /* only used if we fail.. */
38137 if (reclen > buf->count)
38138 return -EINVAL;
38139+
38140+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
38141+ return 0;
38142+
38143 dirent = buf->previous;
38144
38145 if (dirent) {
38146@@ -1073,6 +1090,7 @@ asmlinkage long compat_sys_getdents64(un
38147 buf.previous = NULL;
38148 buf.count = count;
38149 buf.error = 0;
38150+ buf.file = file;
38151
38152 error = vfs_readdir(file, compat_filldir64, &buf);
38153 if (error >= 0)
38154@@ -1446,6 +1464,8 @@ int compat_core_sys_select(int n, compat
38155 struct fdtable *fdt;
38156 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
38157
38158+ pax_track_stack();
38159+
38160 if (n < 0)
38161 goto out_nofds;
38162
38163diff -urNp linux-3.0.4/fs/compat_ioctl.c linux-3.0.4/fs/compat_ioctl.c
38164--- linux-3.0.4/fs/compat_ioctl.c 2011-07-21 22:17:23.000000000 -0400
38165+++ linux-3.0.4/fs/compat_ioctl.c 2011-08-23 21:47:56.000000000 -0400
38166@@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
38167
38168 err = get_user(palp, &up->palette);
38169 err |= get_user(length, &up->length);
38170+ if (err)
38171+ return -EFAULT;
38172
38173 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
38174 err = put_user(compat_ptr(palp), &up_native->palette);
38175@@ -1638,8 +1640,8 @@ asmlinkage long compat_sys_ioctl(unsigne
38176 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
38177 {
38178 unsigned int a, b;
38179- a = *(unsigned int *)p;
38180- b = *(unsigned int *)q;
38181+ a = *(const unsigned int *)p;
38182+ b = *(const unsigned int *)q;
38183 if (a > b)
38184 return 1;
38185 if (a < b)
38186diff -urNp linux-3.0.4/fs/configfs/dir.c linux-3.0.4/fs/configfs/dir.c
38187--- linux-3.0.4/fs/configfs/dir.c 2011-07-21 22:17:23.000000000 -0400
38188+++ linux-3.0.4/fs/configfs/dir.c 2011-08-23 21:47:56.000000000 -0400
38189@@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file
38190 }
38191 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
38192 struct configfs_dirent *next;
38193- const char * name;
38194+ const unsigned char * name;
38195+ char d_name[sizeof(next->s_dentry->d_iname)];
38196 int len;
38197 struct inode *inode = NULL;
38198
38199@@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file
38200 continue;
38201
38202 name = configfs_get_name(next);
38203- len = strlen(name);
38204+ if (next->s_dentry && name == next->s_dentry->d_iname) {
38205+ len = next->s_dentry->d_name.len;
38206+ memcpy(d_name, name, len);
38207+ name = d_name;
38208+ } else
38209+ len = strlen(name);
38210
38211 /*
38212 * We'll have a dentry and an inode for
38213diff -urNp linux-3.0.4/fs/dcache.c linux-3.0.4/fs/dcache.c
38214--- linux-3.0.4/fs/dcache.c 2011-07-21 22:17:23.000000000 -0400
38215+++ linux-3.0.4/fs/dcache.c 2011-08-23 21:47:56.000000000 -0400
38216@@ -3089,7 +3089,7 @@ void __init vfs_caches_init(unsigned lon
38217 mempages -= reserve;
38218
38219 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
38220- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
38221+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
38222
38223 dcache_init();
38224 inode_init();
38225diff -urNp linux-3.0.4/fs/ecryptfs/inode.c linux-3.0.4/fs/ecryptfs/inode.c
38226--- linux-3.0.4/fs/ecryptfs/inode.c 2011-08-23 21:44:40.000000000 -0400
38227+++ linux-3.0.4/fs/ecryptfs/inode.c 2011-08-23 21:47:56.000000000 -0400
38228@@ -704,7 +704,7 @@ static int ecryptfs_readlink_lower(struc
38229 old_fs = get_fs();
38230 set_fs(get_ds());
38231 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
38232- (char __user *)lower_buf,
38233+ (__force char __user *)lower_buf,
38234 lower_bufsiz);
38235 set_fs(old_fs);
38236 if (rc < 0)
38237@@ -750,7 +750,7 @@ static void *ecryptfs_follow_link(struct
38238 }
38239 old_fs = get_fs();
38240 set_fs(get_ds());
38241- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
38242+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
38243 set_fs(old_fs);
38244 if (rc < 0) {
38245 kfree(buf);
38246@@ -765,7 +765,7 @@ out:
38247 static void
38248 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
38249 {
38250- char *buf = nd_get_link(nd);
38251+ const char *buf = nd_get_link(nd);
38252 if (!IS_ERR(buf)) {
38253 /* Free the char* */
38254 kfree(buf);
38255diff -urNp linux-3.0.4/fs/ecryptfs/miscdev.c linux-3.0.4/fs/ecryptfs/miscdev.c
38256--- linux-3.0.4/fs/ecryptfs/miscdev.c 2011-07-21 22:17:23.000000000 -0400
38257+++ linux-3.0.4/fs/ecryptfs/miscdev.c 2011-08-23 21:47:56.000000000 -0400
38258@@ -328,7 +328,7 @@ check_list:
38259 goto out_unlock_msg_ctx;
38260 i = 5;
38261 if (msg_ctx->msg) {
38262- if (copy_to_user(&buf[i], packet_length, packet_length_size))
38263+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
38264 goto out_unlock_msg_ctx;
38265 i += packet_length_size;
38266 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
38267diff -urNp linux-3.0.4/fs/exec.c linux-3.0.4/fs/exec.c
38268--- linux-3.0.4/fs/exec.c 2011-07-21 22:17:23.000000000 -0400
38269+++ linux-3.0.4/fs/exec.c 2011-08-25 17:26:58.000000000 -0400
38270@@ -55,12 +55,24 @@
38271 #include <linux/pipe_fs_i.h>
38272 #include <linux/oom.h>
38273 #include <linux/compat.h>
38274+#include <linux/random.h>
38275+#include <linux/seq_file.h>
38276+
38277+#ifdef CONFIG_PAX_REFCOUNT
38278+#include <linux/kallsyms.h>
38279+#include <linux/kdebug.h>
38280+#endif
38281
38282 #include <asm/uaccess.h>
38283 #include <asm/mmu_context.h>
38284 #include <asm/tlb.h>
38285 #include "internal.h"
38286
38287+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
38288+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
38289+EXPORT_SYMBOL(pax_set_initial_flags_func);
38290+#endif
38291+
38292 int core_uses_pid;
38293 char core_pattern[CORENAME_MAX_SIZE] = "core";
38294 unsigned int core_pipe_limit;
38295@@ -70,7 +82,7 @@ struct core_name {
38296 char *corename;
38297 int used, size;
38298 };
38299-static atomic_t call_count = ATOMIC_INIT(1);
38300+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
38301
38302 /* The maximal length of core_pattern is also specified in sysctl.c */
38303
38304@@ -116,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __use
38305 char *tmp = getname(library);
38306 int error = PTR_ERR(tmp);
38307 static const struct open_flags uselib_flags = {
38308- .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
38309+ .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
38310 .acc_mode = MAY_READ | MAY_EXEC | MAY_OPEN,
38311 .intent = LOOKUP_OPEN
38312 };
38313@@ -195,18 +207,10 @@ static struct page *get_arg_page(struct
38314 int write)
38315 {
38316 struct page *page;
38317- int ret;
38318
38319-#ifdef CONFIG_STACK_GROWSUP
38320- if (write) {
38321- ret = expand_downwards(bprm->vma, pos);
38322- if (ret < 0)
38323- return NULL;
38324- }
38325-#endif
38326- ret = get_user_pages(current, bprm->mm, pos,
38327- 1, write, 1, &page, NULL);
38328- if (ret <= 0)
38329+ if (0 > expand_downwards(bprm->vma, pos))
38330+ return NULL;
38331+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
38332 return NULL;
38333
38334 if (write) {
38335@@ -281,6 +285,11 @@ static int __bprm_mm_init(struct linux_b
38336 vma->vm_end = STACK_TOP_MAX;
38337 vma->vm_start = vma->vm_end - PAGE_SIZE;
38338 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
38339+
38340+#ifdef CONFIG_PAX_SEGMEXEC
38341+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
38342+#endif
38343+
38344 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
38345 INIT_LIST_HEAD(&vma->anon_vma_chain);
38346
38347@@ -295,6 +304,12 @@ static int __bprm_mm_init(struct linux_b
38348 mm->stack_vm = mm->total_vm = 1;
38349 up_write(&mm->mmap_sem);
38350 bprm->p = vma->vm_end - sizeof(void *);
38351+
38352+#ifdef CONFIG_PAX_RANDUSTACK
38353+ if (randomize_va_space)
38354+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
38355+#endif
38356+
38357 return 0;
38358 err:
38359 up_write(&mm->mmap_sem);
38360@@ -403,19 +418,7 @@ err:
38361 return err;
38362 }
38363
38364-struct user_arg_ptr {
38365-#ifdef CONFIG_COMPAT
38366- bool is_compat;
38367-#endif
38368- union {
38369- const char __user *const __user *native;
38370-#ifdef CONFIG_COMPAT
38371- compat_uptr_t __user *compat;
38372-#endif
38373- } ptr;
38374-};
38375-
38376-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
38377+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
38378 {
38379 const char __user *native;
38380
38381@@ -566,7 +569,7 @@ int copy_strings_kernel(int argc, const
38382 int r;
38383 mm_segment_t oldfs = get_fs();
38384 struct user_arg_ptr argv = {
38385- .ptr.native = (const char __user *const __user *)__argv,
38386+ .ptr.native = (__force const char __user *const __user *)__argv,
38387 };
38388
38389 set_fs(KERNEL_DS);
38390@@ -601,7 +604,8 @@ static int shift_arg_pages(struct vm_are
38391 unsigned long new_end = old_end - shift;
38392 struct mmu_gather tlb;
38393
38394- BUG_ON(new_start > new_end);
38395+ if (new_start >= new_end || new_start < mmap_min_addr)
38396+ return -ENOMEM;
38397
38398 /*
38399 * ensure there are no vmas between where we want to go
38400@@ -610,6 +614,10 @@ static int shift_arg_pages(struct vm_are
38401 if (vma != find_vma(mm, new_start))
38402 return -EFAULT;
38403
38404+#ifdef CONFIG_PAX_SEGMEXEC
38405+ BUG_ON(pax_find_mirror_vma(vma));
38406+#endif
38407+
38408 /*
38409 * cover the whole range: [new_start, old_end)
38410 */
38411@@ -690,10 +698,6 @@ int setup_arg_pages(struct linux_binprm
38412 stack_top = arch_align_stack(stack_top);
38413 stack_top = PAGE_ALIGN(stack_top);
38414
38415- if (unlikely(stack_top < mmap_min_addr) ||
38416- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
38417- return -ENOMEM;
38418-
38419 stack_shift = vma->vm_end - stack_top;
38420
38421 bprm->p -= stack_shift;
38422@@ -705,8 +709,28 @@ int setup_arg_pages(struct linux_binprm
38423 bprm->exec -= stack_shift;
38424
38425 down_write(&mm->mmap_sem);
38426+
38427+ /* Move stack pages down in memory. */
38428+ if (stack_shift) {
38429+ ret = shift_arg_pages(vma, stack_shift);
38430+ if (ret)
38431+ goto out_unlock;
38432+ }
38433+
38434 vm_flags = VM_STACK_FLAGS;
38435
38436+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
38437+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
38438+ vm_flags &= ~VM_EXEC;
38439+
38440+#ifdef CONFIG_PAX_MPROTECT
38441+ if (mm->pax_flags & MF_PAX_MPROTECT)
38442+ vm_flags &= ~VM_MAYEXEC;
38443+#endif
38444+
38445+ }
38446+#endif
38447+
38448 /*
38449 * Adjust stack execute permissions; explicitly enable for
38450 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
38451@@ -725,13 +749,6 @@ int setup_arg_pages(struct linux_binprm
38452 goto out_unlock;
38453 BUG_ON(prev != vma);
38454
38455- /* Move stack pages down in memory. */
38456- if (stack_shift) {
38457- ret = shift_arg_pages(vma, stack_shift);
38458- if (ret)
38459- goto out_unlock;
38460- }
38461-
38462 /* mprotect_fixup is overkill to remove the temporary stack flags */
38463 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
38464
38465@@ -771,7 +788,7 @@ struct file *open_exec(const char *name)
38466 struct file *file;
38467 int err;
38468 static const struct open_flags open_exec_flags = {
38469- .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
38470+ .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
38471 .acc_mode = MAY_EXEC | MAY_OPEN,
38472 .intent = LOOKUP_OPEN
38473 };
38474@@ -812,7 +829,7 @@ int kernel_read(struct file *file, loff_
38475 old_fs = get_fs();
38476 set_fs(get_ds());
38477 /* The cast to a user pointer is valid due to the set_fs() */
38478- result = vfs_read(file, (void __user *)addr, count, &pos);
38479+ result = vfs_read(file, (__force void __user *)addr, count, &pos);
38480 set_fs(old_fs);
38481 return result;
38482 }
38483@@ -1236,7 +1253,7 @@ int check_unsafe_exec(struct linux_binpr
38484 }
38485 rcu_read_unlock();
38486
38487- if (p->fs->users > n_fs) {
38488+ if (atomic_read(&p->fs->users) > n_fs) {
38489 bprm->unsafe |= LSM_UNSAFE_SHARE;
38490 } else {
38491 res = -EAGAIN;
38492@@ -1428,11 +1445,35 @@ static int do_execve_common(const char *
38493 struct user_arg_ptr envp,
38494 struct pt_regs *regs)
38495 {
38496+#ifdef CONFIG_GRKERNSEC
38497+ struct file *old_exec_file;
38498+ struct acl_subject_label *old_acl;
38499+ struct rlimit old_rlim[RLIM_NLIMITS];
38500+#endif
38501 struct linux_binprm *bprm;
38502 struct file *file;
38503 struct files_struct *displaced;
38504 bool clear_in_exec;
38505 int retval;
38506+ const struct cred *cred = current_cred();
38507+
38508+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
38509+
38510+ /*
38511+ * We move the actual failure in case of RLIMIT_NPROC excess from
38512+ * set*uid() to execve() because too many poorly written programs
38513+ * don't check setuid() return code. Here we additionally recheck
38514+ * whether NPROC limit is still exceeded.
38515+ */
38516+ if ((current->flags & PF_NPROC_EXCEEDED) &&
38517+ atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) {
38518+ retval = -EAGAIN;
38519+ goto out_ret;
38520+ }
38521+
38522+ /* We're below the limit (still or again), so we don't want to make
38523+ * further execve() calls fail. */
38524+ current->flags &= ~PF_NPROC_EXCEEDED;
38525
38526 retval = unshare_files(&displaced);
38527 if (retval)
38528@@ -1464,6 +1505,16 @@ static int do_execve_common(const char *
38529 bprm->filename = filename;
38530 bprm->interp = filename;
38531
38532+ if (gr_process_user_ban()) {
38533+ retval = -EPERM;
38534+ goto out_file;
38535+ }
38536+
38537+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
38538+ retval = -EACCES;
38539+ goto out_file;
38540+ }
38541+
38542 retval = bprm_mm_init(bprm);
38543 if (retval)
38544 goto out_file;
38545@@ -1493,9 +1544,40 @@ static int do_execve_common(const char *
38546 if (retval < 0)
38547 goto out;
38548
38549+ if (!gr_tpe_allow(file)) {
38550+ retval = -EACCES;
38551+ goto out;
38552+ }
38553+
38554+ if (gr_check_crash_exec(file)) {
38555+ retval = -EACCES;
38556+ goto out;
38557+ }
38558+
38559+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
38560+
38561+ gr_handle_exec_args(bprm, argv);
38562+
38563+#ifdef CONFIG_GRKERNSEC
38564+ old_acl = current->acl;
38565+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
38566+ old_exec_file = current->exec_file;
38567+ get_file(file);
38568+ current->exec_file = file;
38569+#endif
38570+
38571+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
38572+ bprm->unsafe & LSM_UNSAFE_SHARE);
38573+ if (retval < 0)
38574+ goto out_fail;
38575+
38576 retval = search_binary_handler(bprm,regs);
38577 if (retval < 0)
38578- goto out;
38579+ goto out_fail;
38580+#ifdef CONFIG_GRKERNSEC
38581+ if (old_exec_file)
38582+ fput(old_exec_file);
38583+#endif
38584
38585 /* execve succeeded */
38586 current->fs->in_exec = 0;
38587@@ -1506,6 +1588,14 @@ static int do_execve_common(const char *
38588 put_files_struct(displaced);
38589 return retval;
38590
38591+out_fail:
38592+#ifdef CONFIG_GRKERNSEC
38593+ current->acl = old_acl;
38594+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
38595+ fput(current->exec_file);
38596+ current->exec_file = old_exec_file;
38597+#endif
38598+
38599 out:
38600 if (bprm->mm) {
38601 acct_arg_size(bprm, 0);
38602@@ -1579,7 +1669,7 @@ static int expand_corename(struct core_n
38603 {
38604 char *old_corename = cn->corename;
38605
38606- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
38607+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
38608 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
38609
38610 if (!cn->corename) {
38611@@ -1667,7 +1757,7 @@ static int format_corename(struct core_n
38612 int pid_in_pattern = 0;
38613 int err = 0;
38614
38615- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
38616+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
38617 cn->corename = kmalloc(cn->size, GFP_KERNEL);
38618 cn->used = 0;
38619
38620@@ -1758,6 +1848,219 @@ out:
38621 return ispipe;
38622 }
38623
38624+int pax_check_flags(unsigned long *flags)
38625+{
38626+ int retval = 0;
38627+
38628+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
38629+ if (*flags & MF_PAX_SEGMEXEC)
38630+ {
38631+ *flags &= ~MF_PAX_SEGMEXEC;
38632+ retval = -EINVAL;
38633+ }
38634+#endif
38635+
38636+ if ((*flags & MF_PAX_PAGEEXEC)
38637+
38638+#ifdef CONFIG_PAX_PAGEEXEC
38639+ && (*flags & MF_PAX_SEGMEXEC)
38640+#endif
38641+
38642+ )
38643+ {
38644+ *flags &= ~MF_PAX_PAGEEXEC;
38645+ retval = -EINVAL;
38646+ }
38647+
38648+ if ((*flags & MF_PAX_MPROTECT)
38649+
38650+#ifdef CONFIG_PAX_MPROTECT
38651+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
38652+#endif
38653+
38654+ )
38655+ {
38656+ *flags &= ~MF_PAX_MPROTECT;
38657+ retval = -EINVAL;
38658+ }
38659+
38660+ if ((*flags & MF_PAX_EMUTRAMP)
38661+
38662+#ifdef CONFIG_PAX_EMUTRAMP
38663+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
38664+#endif
38665+
38666+ )
38667+ {
38668+ *flags &= ~MF_PAX_EMUTRAMP;
38669+ retval = -EINVAL;
38670+ }
38671+
38672+ return retval;
38673+}
38674+
38675+EXPORT_SYMBOL(pax_check_flags);
38676+
38677+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
38678+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
38679+{
38680+ struct task_struct *tsk = current;
38681+ struct mm_struct *mm = current->mm;
38682+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
38683+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
38684+ char *path_exec = NULL;
38685+ char *path_fault = NULL;
38686+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
38687+
38688+ if (buffer_exec && buffer_fault) {
38689+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
38690+
38691+ down_read(&mm->mmap_sem);
38692+ vma = mm->mmap;
38693+ while (vma && (!vma_exec || !vma_fault)) {
38694+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
38695+ vma_exec = vma;
38696+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
38697+ vma_fault = vma;
38698+ vma = vma->vm_next;
38699+ }
38700+ if (vma_exec) {
38701+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
38702+ if (IS_ERR(path_exec))
38703+ path_exec = "<path too long>";
38704+ else {
38705+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
38706+ if (path_exec) {
38707+ *path_exec = 0;
38708+ path_exec = buffer_exec;
38709+ } else
38710+ path_exec = "<path too long>";
38711+ }
38712+ }
38713+ if (vma_fault) {
38714+ start = vma_fault->vm_start;
38715+ end = vma_fault->vm_end;
38716+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
38717+ if (vma_fault->vm_file) {
38718+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
38719+ if (IS_ERR(path_fault))
38720+ path_fault = "<path too long>";
38721+ else {
38722+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
38723+ if (path_fault) {
38724+ *path_fault = 0;
38725+ path_fault = buffer_fault;
38726+ } else
38727+ path_fault = "<path too long>";
38728+ }
38729+ } else
38730+ path_fault = "<anonymous mapping>";
38731+ }
38732+ up_read(&mm->mmap_sem);
38733+ }
38734+ if (tsk->signal->curr_ip)
38735+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
38736+ else
38737+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
38738+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
38739+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
38740+ task_uid(tsk), task_euid(tsk), pc, sp);
38741+ free_page((unsigned long)buffer_exec);
38742+ free_page((unsigned long)buffer_fault);
38743+ pax_report_insns(pc, sp);
38744+ do_coredump(SIGKILL, SIGKILL, regs);
38745+}
38746+#endif
38747+
38748+#ifdef CONFIG_PAX_REFCOUNT
38749+void pax_report_refcount_overflow(struct pt_regs *regs)
38750+{
38751+ if (current->signal->curr_ip)
38752+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
38753+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
38754+ else
38755+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
38756+ current->comm, task_pid_nr(current), current_uid(), current_euid());
38757+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
38758+ show_regs(regs);
38759+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
38760+}
38761+#endif
38762+
38763+#ifdef CONFIG_PAX_USERCOPY
38764+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
38765+int object_is_on_stack(const void *obj, unsigned long len)
38766+{
38767+ const void * const stack = task_stack_page(current);
38768+ const void * const stackend = stack + THREAD_SIZE;
38769+
38770+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
38771+ const void *frame = NULL;
38772+ const void *oldframe;
38773+#endif
38774+
38775+ if (obj + len < obj)
38776+ return -1;
38777+
38778+ if (obj + len <= stack || stackend <= obj)
38779+ return 0;
38780+
38781+ if (obj < stack || stackend < obj + len)
38782+ return -1;
38783+
38784+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
38785+ oldframe = __builtin_frame_address(1);
38786+ if (oldframe)
38787+ frame = __builtin_frame_address(2);
38788+ /*
38789+ low ----------------------------------------------> high
38790+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
38791+ ^----------------^
38792+ allow copies only within here
38793+ */
38794+ while (stack <= frame && frame < stackend) {
38795+ /* if obj + len extends past the last frame, this
38796+ check won't pass and the next frame will be 0,
38797+ causing us to bail out and correctly report
38798+ the copy as invalid
38799+ */
38800+ if (obj + len <= frame)
38801+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
38802+ oldframe = frame;
38803+ frame = *(const void * const *)frame;
38804+ }
38805+ return -1;
38806+#else
38807+ return 1;
38808+#endif
38809+}
38810+
38811+
38812+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
38813+{
38814+ if (current->signal->curr_ip)
38815+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
38816+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
38817+ else
38818+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
38819+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
38820+ dump_stack();
38821+ gr_handle_kernel_exploit();
38822+ do_group_exit(SIGKILL);
38823+}
38824+#endif
38825+
38826+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
38827+void pax_track_stack(void)
38828+{
38829+ unsigned long sp = (unsigned long)&sp;
38830+ if (sp < current_thread_info()->lowest_stack &&
38831+ sp > (unsigned long)task_stack_page(current))
38832+ current_thread_info()->lowest_stack = sp;
38833+}
38834+EXPORT_SYMBOL(pax_track_stack);
38835+#endif
38836+
38837 static int zap_process(struct task_struct *start, int exit_code)
38838 {
38839 struct task_struct *t;
38840@@ -1969,17 +2272,17 @@ static void wait_for_dump_helpers(struct
38841 pipe = file->f_path.dentry->d_inode->i_pipe;
38842
38843 pipe_lock(pipe);
38844- pipe->readers++;
38845- pipe->writers--;
38846+ atomic_inc(&pipe->readers);
38847+ atomic_dec(&pipe->writers);
38848
38849- while ((pipe->readers > 1) && (!signal_pending(current))) {
38850+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
38851 wake_up_interruptible_sync(&pipe->wait);
38852 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
38853 pipe_wait(pipe);
38854 }
38855
38856- pipe->readers--;
38857- pipe->writers++;
38858+ atomic_dec(&pipe->readers);
38859+ atomic_inc(&pipe->writers);
38860 pipe_unlock(pipe);
38861
38862 }
38863@@ -2040,7 +2343,7 @@ void do_coredump(long signr, int exit_co
38864 int retval = 0;
38865 int flag = 0;
38866 int ispipe;
38867- static atomic_t core_dump_count = ATOMIC_INIT(0);
38868+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
38869 struct coredump_params cprm = {
38870 .signr = signr,
38871 .regs = regs,
38872@@ -2055,6 +2358,9 @@ void do_coredump(long signr, int exit_co
38873
38874 audit_core_dumps(signr);
38875
38876+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
38877+ gr_handle_brute_attach(current, cprm.mm_flags);
38878+
38879 binfmt = mm->binfmt;
38880 if (!binfmt || !binfmt->core_dump)
38881 goto fail;
38882@@ -2095,6 +2401,8 @@ void do_coredump(long signr, int exit_co
38883 goto fail_corename;
38884 }
38885
38886+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
38887+
38888 if (ispipe) {
38889 int dump_count;
38890 char **helper_argv;
38891@@ -2122,7 +2430,7 @@ void do_coredump(long signr, int exit_co
38892 }
38893 cprm.limit = RLIM_INFINITY;
38894
38895- dump_count = atomic_inc_return(&core_dump_count);
38896+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
38897 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
38898 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
38899 task_tgid_vnr(current), current->comm);
38900@@ -2192,7 +2500,7 @@ close_fail:
38901 filp_close(cprm.file, NULL);
38902 fail_dropcount:
38903 if (ispipe)
38904- atomic_dec(&core_dump_count);
38905+ atomic_dec_unchecked(&core_dump_count);
38906 fail_unlock:
38907 kfree(cn.corename);
38908 fail_corename:
38909diff -urNp linux-3.0.4/fs/ext2/balloc.c linux-3.0.4/fs/ext2/balloc.c
38910--- linux-3.0.4/fs/ext2/balloc.c 2011-07-21 22:17:23.000000000 -0400
38911+++ linux-3.0.4/fs/ext2/balloc.c 2011-08-23 21:48:14.000000000 -0400
38912@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
38913
38914 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
38915 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
38916- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
38917+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
38918 sbi->s_resuid != current_fsuid() &&
38919 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
38920 return 0;
38921diff -urNp linux-3.0.4/fs/ext3/balloc.c linux-3.0.4/fs/ext3/balloc.c
38922--- linux-3.0.4/fs/ext3/balloc.c 2011-07-21 22:17:23.000000000 -0400
38923+++ linux-3.0.4/fs/ext3/balloc.c 2011-08-23 21:48:14.000000000 -0400
38924@@ -1441,7 +1441,7 @@ static int ext3_has_free_blocks(struct e
38925
38926 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
38927 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
38928- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
38929+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
38930 sbi->s_resuid != current_fsuid() &&
38931 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
38932 return 0;
38933diff -urNp linux-3.0.4/fs/ext4/balloc.c linux-3.0.4/fs/ext4/balloc.c
38934--- linux-3.0.4/fs/ext4/balloc.c 2011-07-21 22:17:23.000000000 -0400
38935+++ linux-3.0.4/fs/ext4/balloc.c 2011-08-23 21:48:14.000000000 -0400
38936@@ -394,8 +394,8 @@ static int ext4_has_free_blocks(struct e
38937 /* Hm, nope. Are (enough) root reserved blocks available? */
38938 if (sbi->s_resuid == current_fsuid() ||
38939 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
38940- capable(CAP_SYS_RESOURCE) ||
38941- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
38942+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
38943+ capable_nolog(CAP_SYS_RESOURCE)) {
38944
38945 if (free_blocks >= (nblocks + dirty_blocks))
38946 return 1;
38947diff -urNp linux-3.0.4/fs/ext4/ext4.h linux-3.0.4/fs/ext4/ext4.h
38948--- linux-3.0.4/fs/ext4/ext4.h 2011-08-23 21:44:40.000000000 -0400
38949+++ linux-3.0.4/fs/ext4/ext4.h 2011-08-23 21:47:56.000000000 -0400
38950@@ -1177,19 +1177,19 @@ struct ext4_sb_info {
38951 unsigned long s_mb_last_start;
38952
38953 /* stats for buddy allocator */
38954- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
38955- atomic_t s_bal_success; /* we found long enough chunks */
38956- atomic_t s_bal_allocated; /* in blocks */
38957- atomic_t s_bal_ex_scanned; /* total extents scanned */
38958- atomic_t s_bal_goals; /* goal hits */
38959- atomic_t s_bal_breaks; /* too long searches */
38960- atomic_t s_bal_2orders; /* 2^order hits */
38961+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
38962+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
38963+ atomic_unchecked_t s_bal_allocated; /* in blocks */
38964+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
38965+ atomic_unchecked_t s_bal_goals; /* goal hits */
38966+ atomic_unchecked_t s_bal_breaks; /* too long searches */
38967+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
38968 spinlock_t s_bal_lock;
38969 unsigned long s_mb_buddies_generated;
38970 unsigned long long s_mb_generation_time;
38971- atomic_t s_mb_lost_chunks;
38972- atomic_t s_mb_preallocated;
38973- atomic_t s_mb_discarded;
38974+ atomic_unchecked_t s_mb_lost_chunks;
38975+ atomic_unchecked_t s_mb_preallocated;
38976+ atomic_unchecked_t s_mb_discarded;
38977 atomic_t s_lock_busy;
38978
38979 /* locality groups */
38980diff -urNp linux-3.0.4/fs/ext4/mballoc.c linux-3.0.4/fs/ext4/mballoc.c
38981--- linux-3.0.4/fs/ext4/mballoc.c 2011-08-23 21:44:40.000000000 -0400
38982+++ linux-3.0.4/fs/ext4/mballoc.c 2011-08-23 21:48:14.000000000 -0400
38983@@ -1793,7 +1793,7 @@ void ext4_mb_simple_scan_group(struct ex
38984 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
38985
38986 if (EXT4_SB(sb)->s_mb_stats)
38987- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
38988+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
38989
38990 break;
38991 }
38992@@ -2087,7 +2087,7 @@ repeat:
38993 ac->ac_status = AC_STATUS_CONTINUE;
38994 ac->ac_flags |= EXT4_MB_HINT_FIRST;
38995 cr = 3;
38996- atomic_inc(&sbi->s_mb_lost_chunks);
38997+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
38998 goto repeat;
38999 }
39000 }
39001@@ -2130,6 +2130,8 @@ static int ext4_mb_seq_groups_show(struc
39002 ext4_grpblk_t counters[16];
39003 } sg;
39004
39005+ pax_track_stack();
39006+
39007 group--;
39008 if (group == 0)
39009 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
39010@@ -2553,25 +2555,25 @@ int ext4_mb_release(struct super_block *
39011 if (sbi->s_mb_stats) {
39012 printk(KERN_INFO
39013 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
39014- atomic_read(&sbi->s_bal_allocated),
39015- atomic_read(&sbi->s_bal_reqs),
39016- atomic_read(&sbi->s_bal_success));
39017+ atomic_read_unchecked(&sbi->s_bal_allocated),
39018+ atomic_read_unchecked(&sbi->s_bal_reqs),
39019+ atomic_read_unchecked(&sbi->s_bal_success));
39020 printk(KERN_INFO
39021 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
39022 "%u 2^N hits, %u breaks, %u lost\n",
39023- atomic_read(&sbi->s_bal_ex_scanned),
39024- atomic_read(&sbi->s_bal_goals),
39025- atomic_read(&sbi->s_bal_2orders),
39026- atomic_read(&sbi->s_bal_breaks),
39027- atomic_read(&sbi->s_mb_lost_chunks));
39028+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
39029+ atomic_read_unchecked(&sbi->s_bal_goals),
39030+ atomic_read_unchecked(&sbi->s_bal_2orders),
39031+ atomic_read_unchecked(&sbi->s_bal_breaks),
39032+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
39033 printk(KERN_INFO
39034 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
39035 sbi->s_mb_buddies_generated++,
39036 sbi->s_mb_generation_time);
39037 printk(KERN_INFO
39038 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
39039- atomic_read(&sbi->s_mb_preallocated),
39040- atomic_read(&sbi->s_mb_discarded));
39041+ atomic_read_unchecked(&sbi->s_mb_preallocated),
39042+ atomic_read_unchecked(&sbi->s_mb_discarded));
39043 }
39044
39045 free_percpu(sbi->s_locality_groups);
39046@@ -3041,16 +3043,16 @@ static void ext4_mb_collect_stats(struct
39047 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
39048
39049 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
39050- atomic_inc(&sbi->s_bal_reqs);
39051- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
39052+ atomic_inc_unchecked(&sbi->s_bal_reqs);
39053+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
39054 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
39055- atomic_inc(&sbi->s_bal_success);
39056- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
39057+ atomic_inc_unchecked(&sbi->s_bal_success);
39058+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
39059 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
39060 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
39061- atomic_inc(&sbi->s_bal_goals);
39062+ atomic_inc_unchecked(&sbi->s_bal_goals);
39063 if (ac->ac_found > sbi->s_mb_max_to_scan)
39064- atomic_inc(&sbi->s_bal_breaks);
39065+ atomic_inc_unchecked(&sbi->s_bal_breaks);
39066 }
39067
39068 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
39069@@ -3448,7 +3450,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
39070 trace_ext4_mb_new_inode_pa(ac, pa);
39071
39072 ext4_mb_use_inode_pa(ac, pa);
39073- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
39074+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
39075
39076 ei = EXT4_I(ac->ac_inode);
39077 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
39078@@ -3508,7 +3510,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
39079 trace_ext4_mb_new_group_pa(ac, pa);
39080
39081 ext4_mb_use_group_pa(ac, pa);
39082- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
39083+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
39084
39085 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
39086 lg = ac->ac_lg;
39087@@ -3595,7 +3597,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
39088 * from the bitmap and continue.
39089 */
39090 }
39091- atomic_add(free, &sbi->s_mb_discarded);
39092+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
39093
39094 return err;
39095 }
39096@@ -3613,7 +3615,7 @@ ext4_mb_release_group_pa(struct ext4_bud
39097 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
39098 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
39099 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
39100- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
39101+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
39102 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
39103
39104 return 0;
39105diff -urNp linux-3.0.4/fs/fcntl.c linux-3.0.4/fs/fcntl.c
39106--- linux-3.0.4/fs/fcntl.c 2011-07-21 22:17:23.000000000 -0400
39107+++ linux-3.0.4/fs/fcntl.c 2011-08-23 21:48:14.000000000 -0400
39108@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
39109 if (err)
39110 return err;
39111
39112+ if (gr_handle_chroot_fowner(pid, type))
39113+ return -ENOENT;
39114+ if (gr_check_protected_task_fowner(pid, type))
39115+ return -EACCES;
39116+
39117 f_modown(filp, pid, type, force);
39118 return 0;
39119 }
39120@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
39121 switch (cmd) {
39122 case F_DUPFD:
39123 case F_DUPFD_CLOEXEC:
39124+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
39125 if (arg >= rlimit(RLIMIT_NOFILE))
39126 break;
39127 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
39128@@ -835,14 +841,14 @@ static int __init fcntl_init(void)
39129 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
39130 * is defined as O_NONBLOCK on some platforms and not on others.
39131 */
39132- BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
39133+ BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
39134 O_RDONLY | O_WRONLY | O_RDWR |
39135 O_CREAT | O_EXCL | O_NOCTTY |
39136 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
39137 __O_SYNC | O_DSYNC | FASYNC |
39138 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
39139 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
39140- __FMODE_EXEC | O_PATH
39141+ __FMODE_EXEC | O_PATH | FMODE_GREXEC
39142 ));
39143
39144 fasync_cache = kmem_cache_create("fasync_cache",
39145diff -urNp linux-3.0.4/fs/fifo.c linux-3.0.4/fs/fifo.c
39146--- linux-3.0.4/fs/fifo.c 2011-07-21 22:17:23.000000000 -0400
39147+++ linux-3.0.4/fs/fifo.c 2011-08-23 21:47:56.000000000 -0400
39148@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
39149 */
39150 filp->f_op = &read_pipefifo_fops;
39151 pipe->r_counter++;
39152- if (pipe->readers++ == 0)
39153+ if (atomic_inc_return(&pipe->readers) == 1)
39154 wake_up_partner(inode);
39155
39156- if (!pipe->writers) {
39157+ if (!atomic_read(&pipe->writers)) {
39158 if ((filp->f_flags & O_NONBLOCK)) {
39159 /* suppress POLLHUP until we have
39160 * seen a writer */
39161@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode
39162 * errno=ENXIO when there is no process reading the FIFO.
39163 */
39164 ret = -ENXIO;
39165- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
39166+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
39167 goto err;
39168
39169 filp->f_op = &write_pipefifo_fops;
39170 pipe->w_counter++;
39171- if (!pipe->writers++)
39172+ if (atomic_inc_return(&pipe->writers) == 1)
39173 wake_up_partner(inode);
39174
39175- if (!pipe->readers) {
39176+ if (!atomic_read(&pipe->readers)) {
39177 wait_for_partner(inode, &pipe->r_counter);
39178 if (signal_pending(current))
39179 goto err_wr;
39180@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode
39181 */
39182 filp->f_op = &rdwr_pipefifo_fops;
39183
39184- pipe->readers++;
39185- pipe->writers++;
39186+ atomic_inc(&pipe->readers);
39187+ atomic_inc(&pipe->writers);
39188 pipe->r_counter++;
39189 pipe->w_counter++;
39190- if (pipe->readers == 1 || pipe->writers == 1)
39191+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
39192 wake_up_partner(inode);
39193 break;
39194
39195@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode
39196 return 0;
39197
39198 err_rd:
39199- if (!--pipe->readers)
39200+ if (atomic_dec_and_test(&pipe->readers))
39201 wake_up_interruptible(&pipe->wait);
39202 ret = -ERESTARTSYS;
39203 goto err;
39204
39205 err_wr:
39206- if (!--pipe->writers)
39207+ if (atomic_dec_and_test(&pipe->writers))
39208 wake_up_interruptible(&pipe->wait);
39209 ret = -ERESTARTSYS;
39210 goto err;
39211
39212 err:
39213- if (!pipe->readers && !pipe->writers)
39214+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
39215 free_pipe_info(inode);
39216
39217 err_nocleanup:
39218diff -urNp linux-3.0.4/fs/file.c linux-3.0.4/fs/file.c
39219--- linux-3.0.4/fs/file.c 2011-07-21 22:17:23.000000000 -0400
39220+++ linux-3.0.4/fs/file.c 2011-08-23 21:48:14.000000000 -0400
39221@@ -15,6 +15,7 @@
39222 #include <linux/slab.h>
39223 #include <linux/vmalloc.h>
39224 #include <linux/file.h>
39225+#include <linux/security.h>
39226 #include <linux/fdtable.h>
39227 #include <linux/bitops.h>
39228 #include <linux/interrupt.h>
39229@@ -254,6 +255,7 @@ int expand_files(struct files_struct *fi
39230 * N.B. For clone tasks sharing a files structure, this test
39231 * will limit the total number of files that can be opened.
39232 */
39233+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
39234 if (nr >= rlimit(RLIMIT_NOFILE))
39235 return -EMFILE;
39236
39237diff -urNp linux-3.0.4/fs/filesystems.c linux-3.0.4/fs/filesystems.c
39238--- linux-3.0.4/fs/filesystems.c 2011-07-21 22:17:23.000000000 -0400
39239+++ linux-3.0.4/fs/filesystems.c 2011-08-23 21:48:14.000000000 -0400
39240@@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(con
39241 int len = dot ? dot - name : strlen(name);
39242
39243 fs = __get_fs_type(name, len);
39244+
39245+#ifdef CONFIG_GRKERNSEC_MODHARDEN
39246+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
39247+#else
39248 if (!fs && (request_module("%.*s", len, name) == 0))
39249+#endif
39250 fs = __get_fs_type(name, len);
39251
39252 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
39253diff -urNp linux-3.0.4/fs/fscache/cookie.c linux-3.0.4/fs/fscache/cookie.c
39254--- linux-3.0.4/fs/fscache/cookie.c 2011-07-21 22:17:23.000000000 -0400
39255+++ linux-3.0.4/fs/fscache/cookie.c 2011-08-23 21:47:56.000000000 -0400
39256@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
39257 parent ? (char *) parent->def->name : "<no-parent>",
39258 def->name, netfs_data);
39259
39260- fscache_stat(&fscache_n_acquires);
39261+ fscache_stat_unchecked(&fscache_n_acquires);
39262
39263 /* if there's no parent cookie, then we don't create one here either */
39264 if (!parent) {
39265- fscache_stat(&fscache_n_acquires_null);
39266+ fscache_stat_unchecked(&fscache_n_acquires_null);
39267 _leave(" [no parent]");
39268 return NULL;
39269 }
39270@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
39271 /* allocate and initialise a cookie */
39272 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
39273 if (!cookie) {
39274- fscache_stat(&fscache_n_acquires_oom);
39275+ fscache_stat_unchecked(&fscache_n_acquires_oom);
39276 _leave(" [ENOMEM]");
39277 return NULL;
39278 }
39279@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
39280
39281 switch (cookie->def->type) {
39282 case FSCACHE_COOKIE_TYPE_INDEX:
39283- fscache_stat(&fscache_n_cookie_index);
39284+ fscache_stat_unchecked(&fscache_n_cookie_index);
39285 break;
39286 case FSCACHE_COOKIE_TYPE_DATAFILE:
39287- fscache_stat(&fscache_n_cookie_data);
39288+ fscache_stat_unchecked(&fscache_n_cookie_data);
39289 break;
39290 default:
39291- fscache_stat(&fscache_n_cookie_special);
39292+ fscache_stat_unchecked(&fscache_n_cookie_special);
39293 break;
39294 }
39295
39296@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
39297 if (fscache_acquire_non_index_cookie(cookie) < 0) {
39298 atomic_dec(&parent->n_children);
39299 __fscache_cookie_put(cookie);
39300- fscache_stat(&fscache_n_acquires_nobufs);
39301+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
39302 _leave(" = NULL");
39303 return NULL;
39304 }
39305 }
39306
39307- fscache_stat(&fscache_n_acquires_ok);
39308+ fscache_stat_unchecked(&fscache_n_acquires_ok);
39309 _leave(" = %p", cookie);
39310 return cookie;
39311 }
39312@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
39313 cache = fscache_select_cache_for_object(cookie->parent);
39314 if (!cache) {
39315 up_read(&fscache_addremove_sem);
39316- fscache_stat(&fscache_n_acquires_no_cache);
39317+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
39318 _leave(" = -ENOMEDIUM [no cache]");
39319 return -ENOMEDIUM;
39320 }
39321@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
39322 object = cache->ops->alloc_object(cache, cookie);
39323 fscache_stat_d(&fscache_n_cop_alloc_object);
39324 if (IS_ERR(object)) {
39325- fscache_stat(&fscache_n_object_no_alloc);
39326+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
39327 ret = PTR_ERR(object);
39328 goto error;
39329 }
39330
39331- fscache_stat(&fscache_n_object_alloc);
39332+ fscache_stat_unchecked(&fscache_n_object_alloc);
39333
39334 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
39335
39336@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
39337 struct fscache_object *object;
39338 struct hlist_node *_p;
39339
39340- fscache_stat(&fscache_n_updates);
39341+ fscache_stat_unchecked(&fscache_n_updates);
39342
39343 if (!cookie) {
39344- fscache_stat(&fscache_n_updates_null);
39345+ fscache_stat_unchecked(&fscache_n_updates_null);
39346 _leave(" [no cookie]");
39347 return;
39348 }
39349@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
39350 struct fscache_object *object;
39351 unsigned long event;
39352
39353- fscache_stat(&fscache_n_relinquishes);
39354+ fscache_stat_unchecked(&fscache_n_relinquishes);
39355 if (retire)
39356- fscache_stat(&fscache_n_relinquishes_retire);
39357+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
39358
39359 if (!cookie) {
39360- fscache_stat(&fscache_n_relinquishes_null);
39361+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
39362 _leave(" [no cookie]");
39363 return;
39364 }
39365@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
39366
39367 /* wait for the cookie to finish being instantiated (or to fail) */
39368 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
39369- fscache_stat(&fscache_n_relinquishes_waitcrt);
39370+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
39371 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
39372 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
39373 }
39374diff -urNp linux-3.0.4/fs/fscache/internal.h linux-3.0.4/fs/fscache/internal.h
39375--- linux-3.0.4/fs/fscache/internal.h 2011-07-21 22:17:23.000000000 -0400
39376+++ linux-3.0.4/fs/fscache/internal.h 2011-08-23 21:47:56.000000000 -0400
39377@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
39378 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
39379 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
39380
39381-extern atomic_t fscache_n_op_pend;
39382-extern atomic_t fscache_n_op_run;
39383-extern atomic_t fscache_n_op_enqueue;
39384-extern atomic_t fscache_n_op_deferred_release;
39385-extern atomic_t fscache_n_op_release;
39386-extern atomic_t fscache_n_op_gc;
39387-extern atomic_t fscache_n_op_cancelled;
39388-extern atomic_t fscache_n_op_rejected;
39389-
39390-extern atomic_t fscache_n_attr_changed;
39391-extern atomic_t fscache_n_attr_changed_ok;
39392-extern atomic_t fscache_n_attr_changed_nobufs;
39393-extern atomic_t fscache_n_attr_changed_nomem;
39394-extern atomic_t fscache_n_attr_changed_calls;
39395-
39396-extern atomic_t fscache_n_allocs;
39397-extern atomic_t fscache_n_allocs_ok;
39398-extern atomic_t fscache_n_allocs_wait;
39399-extern atomic_t fscache_n_allocs_nobufs;
39400-extern atomic_t fscache_n_allocs_intr;
39401-extern atomic_t fscache_n_allocs_object_dead;
39402-extern atomic_t fscache_n_alloc_ops;
39403-extern atomic_t fscache_n_alloc_op_waits;
39404-
39405-extern atomic_t fscache_n_retrievals;
39406-extern atomic_t fscache_n_retrievals_ok;
39407-extern atomic_t fscache_n_retrievals_wait;
39408-extern atomic_t fscache_n_retrievals_nodata;
39409-extern atomic_t fscache_n_retrievals_nobufs;
39410-extern atomic_t fscache_n_retrievals_intr;
39411-extern atomic_t fscache_n_retrievals_nomem;
39412-extern atomic_t fscache_n_retrievals_object_dead;
39413-extern atomic_t fscache_n_retrieval_ops;
39414-extern atomic_t fscache_n_retrieval_op_waits;
39415-
39416-extern atomic_t fscache_n_stores;
39417-extern atomic_t fscache_n_stores_ok;
39418-extern atomic_t fscache_n_stores_again;
39419-extern atomic_t fscache_n_stores_nobufs;
39420-extern atomic_t fscache_n_stores_oom;
39421-extern atomic_t fscache_n_store_ops;
39422-extern atomic_t fscache_n_store_calls;
39423-extern atomic_t fscache_n_store_pages;
39424-extern atomic_t fscache_n_store_radix_deletes;
39425-extern atomic_t fscache_n_store_pages_over_limit;
39426-
39427-extern atomic_t fscache_n_store_vmscan_not_storing;
39428-extern atomic_t fscache_n_store_vmscan_gone;
39429-extern atomic_t fscache_n_store_vmscan_busy;
39430-extern atomic_t fscache_n_store_vmscan_cancelled;
39431-
39432-extern atomic_t fscache_n_marks;
39433-extern atomic_t fscache_n_uncaches;
39434-
39435-extern atomic_t fscache_n_acquires;
39436-extern atomic_t fscache_n_acquires_null;
39437-extern atomic_t fscache_n_acquires_no_cache;
39438-extern atomic_t fscache_n_acquires_ok;
39439-extern atomic_t fscache_n_acquires_nobufs;
39440-extern atomic_t fscache_n_acquires_oom;
39441-
39442-extern atomic_t fscache_n_updates;
39443-extern atomic_t fscache_n_updates_null;
39444-extern atomic_t fscache_n_updates_run;
39445-
39446-extern atomic_t fscache_n_relinquishes;
39447-extern atomic_t fscache_n_relinquishes_null;
39448-extern atomic_t fscache_n_relinquishes_waitcrt;
39449-extern atomic_t fscache_n_relinquishes_retire;
39450-
39451-extern atomic_t fscache_n_cookie_index;
39452-extern atomic_t fscache_n_cookie_data;
39453-extern atomic_t fscache_n_cookie_special;
39454-
39455-extern atomic_t fscache_n_object_alloc;
39456-extern atomic_t fscache_n_object_no_alloc;
39457-extern atomic_t fscache_n_object_lookups;
39458-extern atomic_t fscache_n_object_lookups_negative;
39459-extern atomic_t fscache_n_object_lookups_positive;
39460-extern atomic_t fscache_n_object_lookups_timed_out;
39461-extern atomic_t fscache_n_object_created;
39462-extern atomic_t fscache_n_object_avail;
39463-extern atomic_t fscache_n_object_dead;
39464-
39465-extern atomic_t fscache_n_checkaux_none;
39466-extern atomic_t fscache_n_checkaux_okay;
39467-extern atomic_t fscache_n_checkaux_update;
39468-extern atomic_t fscache_n_checkaux_obsolete;
39469+extern atomic_unchecked_t fscache_n_op_pend;
39470+extern atomic_unchecked_t fscache_n_op_run;
39471+extern atomic_unchecked_t fscache_n_op_enqueue;
39472+extern atomic_unchecked_t fscache_n_op_deferred_release;
39473+extern atomic_unchecked_t fscache_n_op_release;
39474+extern atomic_unchecked_t fscache_n_op_gc;
39475+extern atomic_unchecked_t fscache_n_op_cancelled;
39476+extern atomic_unchecked_t fscache_n_op_rejected;
39477+
39478+extern atomic_unchecked_t fscache_n_attr_changed;
39479+extern atomic_unchecked_t fscache_n_attr_changed_ok;
39480+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
39481+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
39482+extern atomic_unchecked_t fscache_n_attr_changed_calls;
39483+
39484+extern atomic_unchecked_t fscache_n_allocs;
39485+extern atomic_unchecked_t fscache_n_allocs_ok;
39486+extern atomic_unchecked_t fscache_n_allocs_wait;
39487+extern atomic_unchecked_t fscache_n_allocs_nobufs;
39488+extern atomic_unchecked_t fscache_n_allocs_intr;
39489+extern atomic_unchecked_t fscache_n_allocs_object_dead;
39490+extern atomic_unchecked_t fscache_n_alloc_ops;
39491+extern atomic_unchecked_t fscache_n_alloc_op_waits;
39492+
39493+extern atomic_unchecked_t fscache_n_retrievals;
39494+extern atomic_unchecked_t fscache_n_retrievals_ok;
39495+extern atomic_unchecked_t fscache_n_retrievals_wait;
39496+extern atomic_unchecked_t fscache_n_retrievals_nodata;
39497+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
39498+extern atomic_unchecked_t fscache_n_retrievals_intr;
39499+extern atomic_unchecked_t fscache_n_retrievals_nomem;
39500+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
39501+extern atomic_unchecked_t fscache_n_retrieval_ops;
39502+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
39503+
39504+extern atomic_unchecked_t fscache_n_stores;
39505+extern atomic_unchecked_t fscache_n_stores_ok;
39506+extern atomic_unchecked_t fscache_n_stores_again;
39507+extern atomic_unchecked_t fscache_n_stores_nobufs;
39508+extern atomic_unchecked_t fscache_n_stores_oom;
39509+extern atomic_unchecked_t fscache_n_store_ops;
39510+extern atomic_unchecked_t fscache_n_store_calls;
39511+extern atomic_unchecked_t fscache_n_store_pages;
39512+extern atomic_unchecked_t fscache_n_store_radix_deletes;
39513+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
39514+
39515+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
39516+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
39517+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
39518+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
39519+
39520+extern atomic_unchecked_t fscache_n_marks;
39521+extern atomic_unchecked_t fscache_n_uncaches;
39522+
39523+extern atomic_unchecked_t fscache_n_acquires;
39524+extern atomic_unchecked_t fscache_n_acquires_null;
39525+extern atomic_unchecked_t fscache_n_acquires_no_cache;
39526+extern atomic_unchecked_t fscache_n_acquires_ok;
39527+extern atomic_unchecked_t fscache_n_acquires_nobufs;
39528+extern atomic_unchecked_t fscache_n_acquires_oom;
39529+
39530+extern atomic_unchecked_t fscache_n_updates;
39531+extern atomic_unchecked_t fscache_n_updates_null;
39532+extern atomic_unchecked_t fscache_n_updates_run;
39533+
39534+extern atomic_unchecked_t fscache_n_relinquishes;
39535+extern atomic_unchecked_t fscache_n_relinquishes_null;
39536+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
39537+extern atomic_unchecked_t fscache_n_relinquishes_retire;
39538+
39539+extern atomic_unchecked_t fscache_n_cookie_index;
39540+extern atomic_unchecked_t fscache_n_cookie_data;
39541+extern atomic_unchecked_t fscache_n_cookie_special;
39542+
39543+extern atomic_unchecked_t fscache_n_object_alloc;
39544+extern atomic_unchecked_t fscache_n_object_no_alloc;
39545+extern atomic_unchecked_t fscache_n_object_lookups;
39546+extern atomic_unchecked_t fscache_n_object_lookups_negative;
39547+extern atomic_unchecked_t fscache_n_object_lookups_positive;
39548+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
39549+extern atomic_unchecked_t fscache_n_object_created;
39550+extern atomic_unchecked_t fscache_n_object_avail;
39551+extern atomic_unchecked_t fscache_n_object_dead;
39552+
39553+extern atomic_unchecked_t fscache_n_checkaux_none;
39554+extern atomic_unchecked_t fscache_n_checkaux_okay;
39555+extern atomic_unchecked_t fscache_n_checkaux_update;
39556+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
39557
39558 extern atomic_t fscache_n_cop_alloc_object;
39559 extern atomic_t fscache_n_cop_lookup_object;
39560@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t
39561 atomic_inc(stat);
39562 }
39563
39564+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
39565+{
39566+ atomic_inc_unchecked(stat);
39567+}
39568+
39569 static inline void fscache_stat_d(atomic_t *stat)
39570 {
39571 atomic_dec(stat);
39572@@ -267,6 +272,7 @@ extern const struct file_operations fsca
39573
39574 #define __fscache_stat(stat) (NULL)
39575 #define fscache_stat(stat) do {} while (0)
39576+#define fscache_stat_unchecked(stat) do {} while (0)
39577 #define fscache_stat_d(stat) do {} while (0)
39578 #endif
39579
39580diff -urNp linux-3.0.4/fs/fscache/object.c linux-3.0.4/fs/fscache/object.c
39581--- linux-3.0.4/fs/fscache/object.c 2011-07-21 22:17:23.000000000 -0400
39582+++ linux-3.0.4/fs/fscache/object.c 2011-08-23 21:47:56.000000000 -0400
39583@@ -128,7 +128,7 @@ static void fscache_object_state_machine
39584 /* update the object metadata on disk */
39585 case FSCACHE_OBJECT_UPDATING:
39586 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
39587- fscache_stat(&fscache_n_updates_run);
39588+ fscache_stat_unchecked(&fscache_n_updates_run);
39589 fscache_stat(&fscache_n_cop_update_object);
39590 object->cache->ops->update_object(object);
39591 fscache_stat_d(&fscache_n_cop_update_object);
39592@@ -217,7 +217,7 @@ static void fscache_object_state_machine
39593 spin_lock(&object->lock);
39594 object->state = FSCACHE_OBJECT_DEAD;
39595 spin_unlock(&object->lock);
39596- fscache_stat(&fscache_n_object_dead);
39597+ fscache_stat_unchecked(&fscache_n_object_dead);
39598 goto terminal_transit;
39599
39600 /* handle the parent cache of this object being withdrawn from
39601@@ -232,7 +232,7 @@ static void fscache_object_state_machine
39602 spin_lock(&object->lock);
39603 object->state = FSCACHE_OBJECT_DEAD;
39604 spin_unlock(&object->lock);
39605- fscache_stat(&fscache_n_object_dead);
39606+ fscache_stat_unchecked(&fscache_n_object_dead);
39607 goto terminal_transit;
39608
39609 /* complain about the object being woken up once it is
39610@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct
39611 parent->cookie->def->name, cookie->def->name,
39612 object->cache->tag->name);
39613
39614- fscache_stat(&fscache_n_object_lookups);
39615+ fscache_stat_unchecked(&fscache_n_object_lookups);
39616 fscache_stat(&fscache_n_cop_lookup_object);
39617 ret = object->cache->ops->lookup_object(object);
39618 fscache_stat_d(&fscache_n_cop_lookup_object);
39619@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct
39620 if (ret == -ETIMEDOUT) {
39621 /* probably stuck behind another object, so move this one to
39622 * the back of the queue */
39623- fscache_stat(&fscache_n_object_lookups_timed_out);
39624+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
39625 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
39626 }
39627
39628@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(stru
39629
39630 spin_lock(&object->lock);
39631 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
39632- fscache_stat(&fscache_n_object_lookups_negative);
39633+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
39634
39635 /* transit here to allow write requests to begin stacking up
39636 * and read requests to begin returning ENODATA */
39637@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fsca
39638 * result, in which case there may be data available */
39639 spin_lock(&object->lock);
39640 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
39641- fscache_stat(&fscache_n_object_lookups_positive);
39642+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
39643
39644 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
39645
39646@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fsca
39647 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
39648 } else {
39649 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
39650- fscache_stat(&fscache_n_object_created);
39651+ fscache_stat_unchecked(&fscache_n_object_created);
39652
39653 object->state = FSCACHE_OBJECT_AVAILABLE;
39654 spin_unlock(&object->lock);
39655@@ -602,7 +602,7 @@ static void fscache_object_available(str
39656 fscache_enqueue_dependents(object);
39657
39658 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
39659- fscache_stat(&fscache_n_object_avail);
39660+ fscache_stat_unchecked(&fscache_n_object_avail);
39661
39662 _leave("");
39663 }
39664@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
39665 enum fscache_checkaux result;
39666
39667 if (!object->cookie->def->check_aux) {
39668- fscache_stat(&fscache_n_checkaux_none);
39669+ fscache_stat_unchecked(&fscache_n_checkaux_none);
39670 return FSCACHE_CHECKAUX_OKAY;
39671 }
39672
39673@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
39674 switch (result) {
39675 /* entry okay as is */
39676 case FSCACHE_CHECKAUX_OKAY:
39677- fscache_stat(&fscache_n_checkaux_okay);
39678+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
39679 break;
39680
39681 /* entry requires update */
39682 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
39683- fscache_stat(&fscache_n_checkaux_update);
39684+ fscache_stat_unchecked(&fscache_n_checkaux_update);
39685 break;
39686
39687 /* entry requires deletion */
39688 case FSCACHE_CHECKAUX_OBSOLETE:
39689- fscache_stat(&fscache_n_checkaux_obsolete);
39690+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
39691 break;
39692
39693 default:
39694diff -urNp linux-3.0.4/fs/fscache/operation.c linux-3.0.4/fs/fscache/operation.c
39695--- linux-3.0.4/fs/fscache/operation.c 2011-07-21 22:17:23.000000000 -0400
39696+++ linux-3.0.4/fs/fscache/operation.c 2011-08-23 21:47:56.000000000 -0400
39697@@ -17,7 +17,7 @@
39698 #include <linux/slab.h>
39699 #include "internal.h"
39700
39701-atomic_t fscache_op_debug_id;
39702+atomic_unchecked_t fscache_op_debug_id;
39703 EXPORT_SYMBOL(fscache_op_debug_id);
39704
39705 /**
39706@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fs
39707 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
39708 ASSERTCMP(atomic_read(&op->usage), >, 0);
39709
39710- fscache_stat(&fscache_n_op_enqueue);
39711+ fscache_stat_unchecked(&fscache_n_op_enqueue);
39712 switch (op->flags & FSCACHE_OP_TYPE) {
39713 case FSCACHE_OP_ASYNC:
39714 _debug("queue async");
39715@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscach
39716 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
39717 if (op->processor)
39718 fscache_enqueue_operation(op);
39719- fscache_stat(&fscache_n_op_run);
39720+ fscache_stat_unchecked(&fscache_n_op_run);
39721 }
39722
39723 /*
39724@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct f
39725 if (object->n_ops > 1) {
39726 atomic_inc(&op->usage);
39727 list_add_tail(&op->pend_link, &object->pending_ops);
39728- fscache_stat(&fscache_n_op_pend);
39729+ fscache_stat_unchecked(&fscache_n_op_pend);
39730 } else if (!list_empty(&object->pending_ops)) {
39731 atomic_inc(&op->usage);
39732 list_add_tail(&op->pend_link, &object->pending_ops);
39733- fscache_stat(&fscache_n_op_pend);
39734+ fscache_stat_unchecked(&fscache_n_op_pend);
39735 fscache_start_operations(object);
39736 } else {
39737 ASSERTCMP(object->n_in_progress, ==, 0);
39738@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct f
39739 object->n_exclusive++; /* reads and writes must wait */
39740 atomic_inc(&op->usage);
39741 list_add_tail(&op->pend_link, &object->pending_ops);
39742- fscache_stat(&fscache_n_op_pend);
39743+ fscache_stat_unchecked(&fscache_n_op_pend);
39744 ret = 0;
39745 } else {
39746 /* not allowed to submit ops in any other state */
39747@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_obj
39748 if (object->n_exclusive > 0) {
39749 atomic_inc(&op->usage);
39750 list_add_tail(&op->pend_link, &object->pending_ops);
39751- fscache_stat(&fscache_n_op_pend);
39752+ fscache_stat_unchecked(&fscache_n_op_pend);
39753 } else if (!list_empty(&object->pending_ops)) {
39754 atomic_inc(&op->usage);
39755 list_add_tail(&op->pend_link, &object->pending_ops);
39756- fscache_stat(&fscache_n_op_pend);
39757+ fscache_stat_unchecked(&fscache_n_op_pend);
39758 fscache_start_operations(object);
39759 } else {
39760 ASSERTCMP(object->n_exclusive, ==, 0);
39761@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_obj
39762 object->n_ops++;
39763 atomic_inc(&op->usage);
39764 list_add_tail(&op->pend_link, &object->pending_ops);
39765- fscache_stat(&fscache_n_op_pend);
39766+ fscache_stat_unchecked(&fscache_n_op_pend);
39767 ret = 0;
39768 } else if (object->state == FSCACHE_OBJECT_DYING ||
39769 object->state == FSCACHE_OBJECT_LC_DYING ||
39770 object->state == FSCACHE_OBJECT_WITHDRAWING) {
39771- fscache_stat(&fscache_n_op_rejected);
39772+ fscache_stat_unchecked(&fscache_n_op_rejected);
39773 ret = -ENOBUFS;
39774 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
39775 fscache_report_unexpected_submission(object, op, ostate);
39776@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_ope
39777
39778 ret = -EBUSY;
39779 if (!list_empty(&op->pend_link)) {
39780- fscache_stat(&fscache_n_op_cancelled);
39781+ fscache_stat_unchecked(&fscache_n_op_cancelled);
39782 list_del_init(&op->pend_link);
39783 object->n_ops--;
39784 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
39785@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscach
39786 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
39787 BUG();
39788
39789- fscache_stat(&fscache_n_op_release);
39790+ fscache_stat_unchecked(&fscache_n_op_release);
39791
39792 if (op->release) {
39793 op->release(op);
39794@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscach
39795 * lock, and defer it otherwise */
39796 if (!spin_trylock(&object->lock)) {
39797 _debug("defer put");
39798- fscache_stat(&fscache_n_op_deferred_release);
39799+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
39800
39801 cache = object->cache;
39802 spin_lock(&cache->op_gc_list_lock);
39803@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_st
39804
39805 _debug("GC DEFERRED REL OBJ%x OP%x",
39806 object->debug_id, op->debug_id);
39807- fscache_stat(&fscache_n_op_gc);
39808+ fscache_stat_unchecked(&fscache_n_op_gc);
39809
39810 ASSERTCMP(atomic_read(&op->usage), ==, 0);
39811
39812diff -urNp linux-3.0.4/fs/fscache/page.c linux-3.0.4/fs/fscache/page.c
39813--- linux-3.0.4/fs/fscache/page.c 2011-07-21 22:17:23.000000000 -0400
39814+++ linux-3.0.4/fs/fscache/page.c 2011-08-23 21:47:56.000000000 -0400
39815@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct
39816 val = radix_tree_lookup(&cookie->stores, page->index);
39817 if (!val) {
39818 rcu_read_unlock();
39819- fscache_stat(&fscache_n_store_vmscan_not_storing);
39820+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
39821 __fscache_uncache_page(cookie, page);
39822 return true;
39823 }
39824@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct
39825 spin_unlock(&cookie->stores_lock);
39826
39827 if (xpage) {
39828- fscache_stat(&fscache_n_store_vmscan_cancelled);
39829- fscache_stat(&fscache_n_store_radix_deletes);
39830+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
39831+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
39832 ASSERTCMP(xpage, ==, page);
39833 } else {
39834- fscache_stat(&fscache_n_store_vmscan_gone);
39835+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
39836 }
39837
39838 wake_up_bit(&cookie->flags, 0);
39839@@ -107,7 +107,7 @@ page_busy:
39840 /* we might want to wait here, but that could deadlock the allocator as
39841 * the work threads writing to the cache may all end up sleeping
39842 * on memory allocation */
39843- fscache_stat(&fscache_n_store_vmscan_busy);
39844+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
39845 return false;
39846 }
39847 EXPORT_SYMBOL(__fscache_maybe_release_page);
39848@@ -131,7 +131,7 @@ static void fscache_end_page_write(struc
39849 FSCACHE_COOKIE_STORING_TAG);
39850 if (!radix_tree_tag_get(&cookie->stores, page->index,
39851 FSCACHE_COOKIE_PENDING_TAG)) {
39852- fscache_stat(&fscache_n_store_radix_deletes);
39853+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
39854 xpage = radix_tree_delete(&cookie->stores, page->index);
39855 }
39856 spin_unlock(&cookie->stores_lock);
39857@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(stru
39858
39859 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
39860
39861- fscache_stat(&fscache_n_attr_changed_calls);
39862+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
39863
39864 if (fscache_object_is_active(object)) {
39865 fscache_stat(&fscache_n_cop_attr_changed);
39866@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscach
39867
39868 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
39869
39870- fscache_stat(&fscache_n_attr_changed);
39871+ fscache_stat_unchecked(&fscache_n_attr_changed);
39872
39873 op = kzalloc(sizeof(*op), GFP_KERNEL);
39874 if (!op) {
39875- fscache_stat(&fscache_n_attr_changed_nomem);
39876+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
39877 _leave(" = -ENOMEM");
39878 return -ENOMEM;
39879 }
39880@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscach
39881 if (fscache_submit_exclusive_op(object, op) < 0)
39882 goto nobufs;
39883 spin_unlock(&cookie->lock);
39884- fscache_stat(&fscache_n_attr_changed_ok);
39885+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
39886 fscache_put_operation(op);
39887 _leave(" = 0");
39888 return 0;
39889@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscach
39890 nobufs:
39891 spin_unlock(&cookie->lock);
39892 kfree(op);
39893- fscache_stat(&fscache_n_attr_changed_nobufs);
39894+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
39895 _leave(" = %d", -ENOBUFS);
39896 return -ENOBUFS;
39897 }
39898@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache
39899 /* allocate a retrieval operation and attempt to submit it */
39900 op = kzalloc(sizeof(*op), GFP_NOIO);
39901 if (!op) {
39902- fscache_stat(&fscache_n_retrievals_nomem);
39903+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
39904 return NULL;
39905 }
39906
39907@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_loo
39908 return 0;
39909 }
39910
39911- fscache_stat(&fscache_n_retrievals_wait);
39912+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
39913
39914 jif = jiffies;
39915 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
39916 fscache_wait_bit_interruptible,
39917 TASK_INTERRUPTIBLE) != 0) {
39918- fscache_stat(&fscache_n_retrievals_intr);
39919+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
39920 _leave(" = -ERESTARTSYS");
39921 return -ERESTARTSYS;
39922 }
39923@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_loo
39924 */
39925 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
39926 struct fscache_retrieval *op,
39927- atomic_t *stat_op_waits,
39928- atomic_t *stat_object_dead)
39929+ atomic_unchecked_t *stat_op_waits,
39930+ atomic_unchecked_t *stat_object_dead)
39931 {
39932 int ret;
39933
39934@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_ac
39935 goto check_if_dead;
39936
39937 _debug(">>> WT");
39938- fscache_stat(stat_op_waits);
39939+ fscache_stat_unchecked(stat_op_waits);
39940 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
39941 fscache_wait_bit_interruptible,
39942 TASK_INTERRUPTIBLE) < 0) {
39943@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_ac
39944
39945 check_if_dead:
39946 if (unlikely(fscache_object_is_dead(object))) {
39947- fscache_stat(stat_object_dead);
39948+ fscache_stat_unchecked(stat_object_dead);
39949 return -ENOBUFS;
39950 }
39951 return 0;
39952@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct
39953
39954 _enter("%p,%p,,,", cookie, page);
39955
39956- fscache_stat(&fscache_n_retrievals);
39957+ fscache_stat_unchecked(&fscache_n_retrievals);
39958
39959 if (hlist_empty(&cookie->backing_objects))
39960 goto nobufs;
39961@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct
39962 goto nobufs_unlock;
39963 spin_unlock(&cookie->lock);
39964
39965- fscache_stat(&fscache_n_retrieval_ops);
39966+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
39967
39968 /* pin the netfs read context in case we need to do the actual netfs
39969 * read because we've encountered a cache read failure */
39970@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct
39971
39972 error:
39973 if (ret == -ENOMEM)
39974- fscache_stat(&fscache_n_retrievals_nomem);
39975+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
39976 else if (ret == -ERESTARTSYS)
39977- fscache_stat(&fscache_n_retrievals_intr);
39978+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
39979 else if (ret == -ENODATA)
39980- fscache_stat(&fscache_n_retrievals_nodata);
39981+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
39982 else if (ret < 0)
39983- fscache_stat(&fscache_n_retrievals_nobufs);
39984+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
39985 else
39986- fscache_stat(&fscache_n_retrievals_ok);
39987+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
39988
39989 fscache_put_retrieval(op);
39990 _leave(" = %d", ret);
39991@@ -429,7 +429,7 @@ nobufs_unlock:
39992 spin_unlock(&cookie->lock);
39993 kfree(op);
39994 nobufs:
39995- fscache_stat(&fscache_n_retrievals_nobufs);
39996+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
39997 _leave(" = -ENOBUFS");
39998 return -ENOBUFS;
39999 }
40000@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct
40001
40002 _enter("%p,,%d,,,", cookie, *nr_pages);
40003
40004- fscache_stat(&fscache_n_retrievals);
40005+ fscache_stat_unchecked(&fscache_n_retrievals);
40006
40007 if (hlist_empty(&cookie->backing_objects))
40008 goto nobufs;
40009@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct
40010 goto nobufs_unlock;
40011 spin_unlock(&cookie->lock);
40012
40013- fscache_stat(&fscache_n_retrieval_ops);
40014+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
40015
40016 /* pin the netfs read context in case we need to do the actual netfs
40017 * read because we've encountered a cache read failure */
40018@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct
40019
40020 error:
40021 if (ret == -ENOMEM)
40022- fscache_stat(&fscache_n_retrievals_nomem);
40023+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
40024 else if (ret == -ERESTARTSYS)
40025- fscache_stat(&fscache_n_retrievals_intr);
40026+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
40027 else if (ret == -ENODATA)
40028- fscache_stat(&fscache_n_retrievals_nodata);
40029+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
40030 else if (ret < 0)
40031- fscache_stat(&fscache_n_retrievals_nobufs);
40032+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
40033 else
40034- fscache_stat(&fscache_n_retrievals_ok);
40035+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
40036
40037 fscache_put_retrieval(op);
40038 _leave(" = %d", ret);
40039@@ -545,7 +545,7 @@ nobufs_unlock:
40040 spin_unlock(&cookie->lock);
40041 kfree(op);
40042 nobufs:
40043- fscache_stat(&fscache_n_retrievals_nobufs);
40044+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
40045 _leave(" = -ENOBUFS");
40046 return -ENOBUFS;
40047 }
40048@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_
40049
40050 _enter("%p,%p,,,", cookie, page);
40051
40052- fscache_stat(&fscache_n_allocs);
40053+ fscache_stat_unchecked(&fscache_n_allocs);
40054
40055 if (hlist_empty(&cookie->backing_objects))
40056 goto nobufs;
40057@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_
40058 goto nobufs_unlock;
40059 spin_unlock(&cookie->lock);
40060
40061- fscache_stat(&fscache_n_alloc_ops);
40062+ fscache_stat_unchecked(&fscache_n_alloc_ops);
40063
40064 ret = fscache_wait_for_retrieval_activation(
40065 object, op,
40066@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_
40067
40068 error:
40069 if (ret == -ERESTARTSYS)
40070- fscache_stat(&fscache_n_allocs_intr);
40071+ fscache_stat_unchecked(&fscache_n_allocs_intr);
40072 else if (ret < 0)
40073- fscache_stat(&fscache_n_allocs_nobufs);
40074+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
40075 else
40076- fscache_stat(&fscache_n_allocs_ok);
40077+ fscache_stat_unchecked(&fscache_n_allocs_ok);
40078
40079 fscache_put_retrieval(op);
40080 _leave(" = %d", ret);
40081@@ -625,7 +625,7 @@ nobufs_unlock:
40082 spin_unlock(&cookie->lock);
40083 kfree(op);
40084 nobufs:
40085- fscache_stat(&fscache_n_allocs_nobufs);
40086+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
40087 _leave(" = -ENOBUFS");
40088 return -ENOBUFS;
40089 }
40090@@ -666,7 +666,7 @@ static void fscache_write_op(struct fsca
40091
40092 spin_lock(&cookie->stores_lock);
40093
40094- fscache_stat(&fscache_n_store_calls);
40095+ fscache_stat_unchecked(&fscache_n_store_calls);
40096
40097 /* find a page to store */
40098 page = NULL;
40099@@ -677,7 +677,7 @@ static void fscache_write_op(struct fsca
40100 page = results[0];
40101 _debug("gang %d [%lx]", n, page->index);
40102 if (page->index > op->store_limit) {
40103- fscache_stat(&fscache_n_store_pages_over_limit);
40104+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
40105 goto superseded;
40106 }
40107
40108@@ -689,7 +689,7 @@ static void fscache_write_op(struct fsca
40109 spin_unlock(&cookie->stores_lock);
40110 spin_unlock(&object->lock);
40111
40112- fscache_stat(&fscache_n_store_pages);
40113+ fscache_stat_unchecked(&fscache_n_store_pages);
40114 fscache_stat(&fscache_n_cop_write_page);
40115 ret = object->cache->ops->write_page(op, page);
40116 fscache_stat_d(&fscache_n_cop_write_page);
40117@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_
40118 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
40119 ASSERT(PageFsCache(page));
40120
40121- fscache_stat(&fscache_n_stores);
40122+ fscache_stat_unchecked(&fscache_n_stores);
40123
40124 op = kzalloc(sizeof(*op), GFP_NOIO);
40125 if (!op)
40126@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_
40127 spin_unlock(&cookie->stores_lock);
40128 spin_unlock(&object->lock);
40129
40130- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
40131+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
40132 op->store_limit = object->store_limit;
40133
40134 if (fscache_submit_op(object, &op->op) < 0)
40135@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_
40136
40137 spin_unlock(&cookie->lock);
40138 radix_tree_preload_end();
40139- fscache_stat(&fscache_n_store_ops);
40140- fscache_stat(&fscache_n_stores_ok);
40141+ fscache_stat_unchecked(&fscache_n_store_ops);
40142+ fscache_stat_unchecked(&fscache_n_stores_ok);
40143
40144 /* the work queue now carries its own ref on the object */
40145 fscache_put_operation(&op->op);
40146@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_
40147 return 0;
40148
40149 already_queued:
40150- fscache_stat(&fscache_n_stores_again);
40151+ fscache_stat_unchecked(&fscache_n_stores_again);
40152 already_pending:
40153 spin_unlock(&cookie->stores_lock);
40154 spin_unlock(&object->lock);
40155 spin_unlock(&cookie->lock);
40156 radix_tree_preload_end();
40157 kfree(op);
40158- fscache_stat(&fscache_n_stores_ok);
40159+ fscache_stat_unchecked(&fscache_n_stores_ok);
40160 _leave(" = 0");
40161 return 0;
40162
40163@@ -851,14 +851,14 @@ nobufs:
40164 spin_unlock(&cookie->lock);
40165 radix_tree_preload_end();
40166 kfree(op);
40167- fscache_stat(&fscache_n_stores_nobufs);
40168+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
40169 _leave(" = -ENOBUFS");
40170 return -ENOBUFS;
40171
40172 nomem_free:
40173 kfree(op);
40174 nomem:
40175- fscache_stat(&fscache_n_stores_oom);
40176+ fscache_stat_unchecked(&fscache_n_stores_oom);
40177 _leave(" = -ENOMEM");
40178 return -ENOMEM;
40179 }
40180@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscac
40181 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
40182 ASSERTCMP(page, !=, NULL);
40183
40184- fscache_stat(&fscache_n_uncaches);
40185+ fscache_stat_unchecked(&fscache_n_uncaches);
40186
40187 /* cache withdrawal may beat us to it */
40188 if (!PageFsCache(page))
40189@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fs
40190 unsigned long loop;
40191
40192 #ifdef CONFIG_FSCACHE_STATS
40193- atomic_add(pagevec->nr, &fscache_n_marks);
40194+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
40195 #endif
40196
40197 for (loop = 0; loop < pagevec->nr; loop++) {
40198diff -urNp linux-3.0.4/fs/fscache/stats.c linux-3.0.4/fs/fscache/stats.c
40199--- linux-3.0.4/fs/fscache/stats.c 2011-07-21 22:17:23.000000000 -0400
40200+++ linux-3.0.4/fs/fscache/stats.c 2011-08-23 21:47:56.000000000 -0400
40201@@ -18,95 +18,95 @@
40202 /*
40203 * operation counters
40204 */
40205-atomic_t fscache_n_op_pend;
40206-atomic_t fscache_n_op_run;
40207-atomic_t fscache_n_op_enqueue;
40208-atomic_t fscache_n_op_requeue;
40209-atomic_t fscache_n_op_deferred_release;
40210-atomic_t fscache_n_op_release;
40211-atomic_t fscache_n_op_gc;
40212-atomic_t fscache_n_op_cancelled;
40213-atomic_t fscache_n_op_rejected;
40214-
40215-atomic_t fscache_n_attr_changed;
40216-atomic_t fscache_n_attr_changed_ok;
40217-atomic_t fscache_n_attr_changed_nobufs;
40218-atomic_t fscache_n_attr_changed_nomem;
40219-atomic_t fscache_n_attr_changed_calls;
40220-
40221-atomic_t fscache_n_allocs;
40222-atomic_t fscache_n_allocs_ok;
40223-atomic_t fscache_n_allocs_wait;
40224-atomic_t fscache_n_allocs_nobufs;
40225-atomic_t fscache_n_allocs_intr;
40226-atomic_t fscache_n_allocs_object_dead;
40227-atomic_t fscache_n_alloc_ops;
40228-atomic_t fscache_n_alloc_op_waits;
40229-
40230-atomic_t fscache_n_retrievals;
40231-atomic_t fscache_n_retrievals_ok;
40232-atomic_t fscache_n_retrievals_wait;
40233-atomic_t fscache_n_retrievals_nodata;
40234-atomic_t fscache_n_retrievals_nobufs;
40235-atomic_t fscache_n_retrievals_intr;
40236-atomic_t fscache_n_retrievals_nomem;
40237-atomic_t fscache_n_retrievals_object_dead;
40238-atomic_t fscache_n_retrieval_ops;
40239-atomic_t fscache_n_retrieval_op_waits;
40240-
40241-atomic_t fscache_n_stores;
40242-atomic_t fscache_n_stores_ok;
40243-atomic_t fscache_n_stores_again;
40244-atomic_t fscache_n_stores_nobufs;
40245-atomic_t fscache_n_stores_oom;
40246-atomic_t fscache_n_store_ops;
40247-atomic_t fscache_n_store_calls;
40248-atomic_t fscache_n_store_pages;
40249-atomic_t fscache_n_store_radix_deletes;
40250-atomic_t fscache_n_store_pages_over_limit;
40251-
40252-atomic_t fscache_n_store_vmscan_not_storing;
40253-atomic_t fscache_n_store_vmscan_gone;
40254-atomic_t fscache_n_store_vmscan_busy;
40255-atomic_t fscache_n_store_vmscan_cancelled;
40256-
40257-atomic_t fscache_n_marks;
40258-atomic_t fscache_n_uncaches;
40259-
40260-atomic_t fscache_n_acquires;
40261-atomic_t fscache_n_acquires_null;
40262-atomic_t fscache_n_acquires_no_cache;
40263-atomic_t fscache_n_acquires_ok;
40264-atomic_t fscache_n_acquires_nobufs;
40265-atomic_t fscache_n_acquires_oom;
40266-
40267-atomic_t fscache_n_updates;
40268-atomic_t fscache_n_updates_null;
40269-atomic_t fscache_n_updates_run;
40270-
40271-atomic_t fscache_n_relinquishes;
40272-atomic_t fscache_n_relinquishes_null;
40273-atomic_t fscache_n_relinquishes_waitcrt;
40274-atomic_t fscache_n_relinquishes_retire;
40275-
40276-atomic_t fscache_n_cookie_index;
40277-atomic_t fscache_n_cookie_data;
40278-atomic_t fscache_n_cookie_special;
40279-
40280-atomic_t fscache_n_object_alloc;
40281-atomic_t fscache_n_object_no_alloc;
40282-atomic_t fscache_n_object_lookups;
40283-atomic_t fscache_n_object_lookups_negative;
40284-atomic_t fscache_n_object_lookups_positive;
40285-atomic_t fscache_n_object_lookups_timed_out;
40286-atomic_t fscache_n_object_created;
40287-atomic_t fscache_n_object_avail;
40288-atomic_t fscache_n_object_dead;
40289-
40290-atomic_t fscache_n_checkaux_none;
40291-atomic_t fscache_n_checkaux_okay;
40292-atomic_t fscache_n_checkaux_update;
40293-atomic_t fscache_n_checkaux_obsolete;
40294+atomic_unchecked_t fscache_n_op_pend;
40295+atomic_unchecked_t fscache_n_op_run;
40296+atomic_unchecked_t fscache_n_op_enqueue;
40297+atomic_unchecked_t fscache_n_op_requeue;
40298+atomic_unchecked_t fscache_n_op_deferred_release;
40299+atomic_unchecked_t fscache_n_op_release;
40300+atomic_unchecked_t fscache_n_op_gc;
40301+atomic_unchecked_t fscache_n_op_cancelled;
40302+atomic_unchecked_t fscache_n_op_rejected;
40303+
40304+atomic_unchecked_t fscache_n_attr_changed;
40305+atomic_unchecked_t fscache_n_attr_changed_ok;
40306+atomic_unchecked_t fscache_n_attr_changed_nobufs;
40307+atomic_unchecked_t fscache_n_attr_changed_nomem;
40308+atomic_unchecked_t fscache_n_attr_changed_calls;
40309+
40310+atomic_unchecked_t fscache_n_allocs;
40311+atomic_unchecked_t fscache_n_allocs_ok;
40312+atomic_unchecked_t fscache_n_allocs_wait;
40313+atomic_unchecked_t fscache_n_allocs_nobufs;
40314+atomic_unchecked_t fscache_n_allocs_intr;
40315+atomic_unchecked_t fscache_n_allocs_object_dead;
40316+atomic_unchecked_t fscache_n_alloc_ops;
40317+atomic_unchecked_t fscache_n_alloc_op_waits;
40318+
40319+atomic_unchecked_t fscache_n_retrievals;
40320+atomic_unchecked_t fscache_n_retrievals_ok;
40321+atomic_unchecked_t fscache_n_retrievals_wait;
40322+atomic_unchecked_t fscache_n_retrievals_nodata;
40323+atomic_unchecked_t fscache_n_retrievals_nobufs;
40324+atomic_unchecked_t fscache_n_retrievals_intr;
40325+atomic_unchecked_t fscache_n_retrievals_nomem;
40326+atomic_unchecked_t fscache_n_retrievals_object_dead;
40327+atomic_unchecked_t fscache_n_retrieval_ops;
40328+atomic_unchecked_t fscache_n_retrieval_op_waits;
40329+
40330+atomic_unchecked_t fscache_n_stores;
40331+atomic_unchecked_t fscache_n_stores_ok;
40332+atomic_unchecked_t fscache_n_stores_again;
40333+atomic_unchecked_t fscache_n_stores_nobufs;
40334+atomic_unchecked_t fscache_n_stores_oom;
40335+atomic_unchecked_t fscache_n_store_ops;
40336+atomic_unchecked_t fscache_n_store_calls;
40337+atomic_unchecked_t fscache_n_store_pages;
40338+atomic_unchecked_t fscache_n_store_radix_deletes;
40339+atomic_unchecked_t fscache_n_store_pages_over_limit;
40340+
40341+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
40342+atomic_unchecked_t fscache_n_store_vmscan_gone;
40343+atomic_unchecked_t fscache_n_store_vmscan_busy;
40344+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
40345+
40346+atomic_unchecked_t fscache_n_marks;
40347+atomic_unchecked_t fscache_n_uncaches;
40348+
40349+atomic_unchecked_t fscache_n_acquires;
40350+atomic_unchecked_t fscache_n_acquires_null;
40351+atomic_unchecked_t fscache_n_acquires_no_cache;
40352+atomic_unchecked_t fscache_n_acquires_ok;
40353+atomic_unchecked_t fscache_n_acquires_nobufs;
40354+atomic_unchecked_t fscache_n_acquires_oom;
40355+
40356+atomic_unchecked_t fscache_n_updates;
40357+atomic_unchecked_t fscache_n_updates_null;
40358+atomic_unchecked_t fscache_n_updates_run;
40359+
40360+atomic_unchecked_t fscache_n_relinquishes;
40361+atomic_unchecked_t fscache_n_relinquishes_null;
40362+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
40363+atomic_unchecked_t fscache_n_relinquishes_retire;
40364+
40365+atomic_unchecked_t fscache_n_cookie_index;
40366+atomic_unchecked_t fscache_n_cookie_data;
40367+atomic_unchecked_t fscache_n_cookie_special;
40368+
40369+atomic_unchecked_t fscache_n_object_alloc;
40370+atomic_unchecked_t fscache_n_object_no_alloc;
40371+atomic_unchecked_t fscache_n_object_lookups;
40372+atomic_unchecked_t fscache_n_object_lookups_negative;
40373+atomic_unchecked_t fscache_n_object_lookups_positive;
40374+atomic_unchecked_t fscache_n_object_lookups_timed_out;
40375+atomic_unchecked_t fscache_n_object_created;
40376+atomic_unchecked_t fscache_n_object_avail;
40377+atomic_unchecked_t fscache_n_object_dead;
40378+
40379+atomic_unchecked_t fscache_n_checkaux_none;
40380+atomic_unchecked_t fscache_n_checkaux_okay;
40381+atomic_unchecked_t fscache_n_checkaux_update;
40382+atomic_unchecked_t fscache_n_checkaux_obsolete;
40383
40384 atomic_t fscache_n_cop_alloc_object;
40385 atomic_t fscache_n_cop_lookup_object;
40386@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
40387 seq_puts(m, "FS-Cache statistics\n");
40388
40389 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
40390- atomic_read(&fscache_n_cookie_index),
40391- atomic_read(&fscache_n_cookie_data),
40392- atomic_read(&fscache_n_cookie_special));
40393+ atomic_read_unchecked(&fscache_n_cookie_index),
40394+ atomic_read_unchecked(&fscache_n_cookie_data),
40395+ atomic_read_unchecked(&fscache_n_cookie_special));
40396
40397 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
40398- atomic_read(&fscache_n_object_alloc),
40399- atomic_read(&fscache_n_object_no_alloc),
40400- atomic_read(&fscache_n_object_avail),
40401- atomic_read(&fscache_n_object_dead));
40402+ atomic_read_unchecked(&fscache_n_object_alloc),
40403+ atomic_read_unchecked(&fscache_n_object_no_alloc),
40404+ atomic_read_unchecked(&fscache_n_object_avail),
40405+ atomic_read_unchecked(&fscache_n_object_dead));
40406 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
40407- atomic_read(&fscache_n_checkaux_none),
40408- atomic_read(&fscache_n_checkaux_okay),
40409- atomic_read(&fscache_n_checkaux_update),
40410- atomic_read(&fscache_n_checkaux_obsolete));
40411+ atomic_read_unchecked(&fscache_n_checkaux_none),
40412+ atomic_read_unchecked(&fscache_n_checkaux_okay),
40413+ atomic_read_unchecked(&fscache_n_checkaux_update),
40414+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
40415
40416 seq_printf(m, "Pages : mrk=%u unc=%u\n",
40417- atomic_read(&fscache_n_marks),
40418- atomic_read(&fscache_n_uncaches));
40419+ atomic_read_unchecked(&fscache_n_marks),
40420+ atomic_read_unchecked(&fscache_n_uncaches));
40421
40422 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
40423 " oom=%u\n",
40424- atomic_read(&fscache_n_acquires),
40425- atomic_read(&fscache_n_acquires_null),
40426- atomic_read(&fscache_n_acquires_no_cache),
40427- atomic_read(&fscache_n_acquires_ok),
40428- atomic_read(&fscache_n_acquires_nobufs),
40429- atomic_read(&fscache_n_acquires_oom));
40430+ atomic_read_unchecked(&fscache_n_acquires),
40431+ atomic_read_unchecked(&fscache_n_acquires_null),
40432+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
40433+ atomic_read_unchecked(&fscache_n_acquires_ok),
40434+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
40435+ atomic_read_unchecked(&fscache_n_acquires_oom));
40436
40437 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
40438- atomic_read(&fscache_n_object_lookups),
40439- atomic_read(&fscache_n_object_lookups_negative),
40440- atomic_read(&fscache_n_object_lookups_positive),
40441- atomic_read(&fscache_n_object_created),
40442- atomic_read(&fscache_n_object_lookups_timed_out));
40443+ atomic_read_unchecked(&fscache_n_object_lookups),
40444+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
40445+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
40446+ atomic_read_unchecked(&fscache_n_object_created),
40447+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
40448
40449 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
40450- atomic_read(&fscache_n_updates),
40451- atomic_read(&fscache_n_updates_null),
40452- atomic_read(&fscache_n_updates_run));
40453+ atomic_read_unchecked(&fscache_n_updates),
40454+ atomic_read_unchecked(&fscache_n_updates_null),
40455+ atomic_read_unchecked(&fscache_n_updates_run));
40456
40457 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
40458- atomic_read(&fscache_n_relinquishes),
40459- atomic_read(&fscache_n_relinquishes_null),
40460- atomic_read(&fscache_n_relinquishes_waitcrt),
40461- atomic_read(&fscache_n_relinquishes_retire));
40462+ atomic_read_unchecked(&fscache_n_relinquishes),
40463+ atomic_read_unchecked(&fscache_n_relinquishes_null),
40464+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
40465+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
40466
40467 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
40468- atomic_read(&fscache_n_attr_changed),
40469- atomic_read(&fscache_n_attr_changed_ok),
40470- atomic_read(&fscache_n_attr_changed_nobufs),
40471- atomic_read(&fscache_n_attr_changed_nomem),
40472- atomic_read(&fscache_n_attr_changed_calls));
40473+ atomic_read_unchecked(&fscache_n_attr_changed),
40474+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
40475+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
40476+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
40477+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
40478
40479 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
40480- atomic_read(&fscache_n_allocs),
40481- atomic_read(&fscache_n_allocs_ok),
40482- atomic_read(&fscache_n_allocs_wait),
40483- atomic_read(&fscache_n_allocs_nobufs),
40484- atomic_read(&fscache_n_allocs_intr));
40485+ atomic_read_unchecked(&fscache_n_allocs),
40486+ atomic_read_unchecked(&fscache_n_allocs_ok),
40487+ atomic_read_unchecked(&fscache_n_allocs_wait),
40488+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
40489+ atomic_read_unchecked(&fscache_n_allocs_intr));
40490 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
40491- atomic_read(&fscache_n_alloc_ops),
40492- atomic_read(&fscache_n_alloc_op_waits),
40493- atomic_read(&fscache_n_allocs_object_dead));
40494+ atomic_read_unchecked(&fscache_n_alloc_ops),
40495+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
40496+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
40497
40498 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
40499 " int=%u oom=%u\n",
40500- atomic_read(&fscache_n_retrievals),
40501- atomic_read(&fscache_n_retrievals_ok),
40502- atomic_read(&fscache_n_retrievals_wait),
40503- atomic_read(&fscache_n_retrievals_nodata),
40504- atomic_read(&fscache_n_retrievals_nobufs),
40505- atomic_read(&fscache_n_retrievals_intr),
40506- atomic_read(&fscache_n_retrievals_nomem));
40507+ atomic_read_unchecked(&fscache_n_retrievals),
40508+ atomic_read_unchecked(&fscache_n_retrievals_ok),
40509+ atomic_read_unchecked(&fscache_n_retrievals_wait),
40510+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
40511+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
40512+ atomic_read_unchecked(&fscache_n_retrievals_intr),
40513+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
40514 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
40515- atomic_read(&fscache_n_retrieval_ops),
40516- atomic_read(&fscache_n_retrieval_op_waits),
40517- atomic_read(&fscache_n_retrievals_object_dead));
40518+ atomic_read_unchecked(&fscache_n_retrieval_ops),
40519+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
40520+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
40521
40522 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
40523- atomic_read(&fscache_n_stores),
40524- atomic_read(&fscache_n_stores_ok),
40525- atomic_read(&fscache_n_stores_again),
40526- atomic_read(&fscache_n_stores_nobufs),
40527- atomic_read(&fscache_n_stores_oom));
40528+ atomic_read_unchecked(&fscache_n_stores),
40529+ atomic_read_unchecked(&fscache_n_stores_ok),
40530+ atomic_read_unchecked(&fscache_n_stores_again),
40531+ atomic_read_unchecked(&fscache_n_stores_nobufs),
40532+ atomic_read_unchecked(&fscache_n_stores_oom));
40533 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
40534- atomic_read(&fscache_n_store_ops),
40535- atomic_read(&fscache_n_store_calls),
40536- atomic_read(&fscache_n_store_pages),
40537- atomic_read(&fscache_n_store_radix_deletes),
40538- atomic_read(&fscache_n_store_pages_over_limit));
40539+ atomic_read_unchecked(&fscache_n_store_ops),
40540+ atomic_read_unchecked(&fscache_n_store_calls),
40541+ atomic_read_unchecked(&fscache_n_store_pages),
40542+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
40543+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
40544
40545 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
40546- atomic_read(&fscache_n_store_vmscan_not_storing),
40547- atomic_read(&fscache_n_store_vmscan_gone),
40548- atomic_read(&fscache_n_store_vmscan_busy),
40549- atomic_read(&fscache_n_store_vmscan_cancelled));
40550+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
40551+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
40552+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
40553+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
40554
40555 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
40556- atomic_read(&fscache_n_op_pend),
40557- atomic_read(&fscache_n_op_run),
40558- atomic_read(&fscache_n_op_enqueue),
40559- atomic_read(&fscache_n_op_cancelled),
40560- atomic_read(&fscache_n_op_rejected));
40561+ atomic_read_unchecked(&fscache_n_op_pend),
40562+ atomic_read_unchecked(&fscache_n_op_run),
40563+ atomic_read_unchecked(&fscache_n_op_enqueue),
40564+ atomic_read_unchecked(&fscache_n_op_cancelled),
40565+ atomic_read_unchecked(&fscache_n_op_rejected));
40566 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
40567- atomic_read(&fscache_n_op_deferred_release),
40568- atomic_read(&fscache_n_op_release),
40569- atomic_read(&fscache_n_op_gc));
40570+ atomic_read_unchecked(&fscache_n_op_deferred_release),
40571+ atomic_read_unchecked(&fscache_n_op_release),
40572+ atomic_read_unchecked(&fscache_n_op_gc));
40573
40574 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
40575 atomic_read(&fscache_n_cop_alloc_object),
40576diff -urNp linux-3.0.4/fs/fs_struct.c linux-3.0.4/fs/fs_struct.c
40577--- linux-3.0.4/fs/fs_struct.c 2011-07-21 22:17:23.000000000 -0400
40578+++ linux-3.0.4/fs/fs_struct.c 2011-08-23 21:48:14.000000000 -0400
40579@@ -4,6 +4,7 @@
40580 #include <linux/path.h>
40581 #include <linux/slab.h>
40582 #include <linux/fs_struct.h>
40583+#include <linux/grsecurity.h>
40584 #include "internal.h"
40585
40586 static inline void path_get_longterm(struct path *path)
40587@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, s
40588 old_root = fs->root;
40589 fs->root = *path;
40590 path_get_longterm(path);
40591+ gr_set_chroot_entries(current, path);
40592 write_seqcount_end(&fs->seq);
40593 spin_unlock(&fs->lock);
40594 if (old_root.dentry)
40595@@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_roo
40596 && fs->root.mnt == old_root->mnt) {
40597 path_get_longterm(new_root);
40598 fs->root = *new_root;
40599+ gr_set_chroot_entries(p, new_root);
40600 count++;
40601 }
40602 if (fs->pwd.dentry == old_root->dentry
40603@@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
40604 spin_lock(&fs->lock);
40605 write_seqcount_begin(&fs->seq);
40606 tsk->fs = NULL;
40607- kill = !--fs->users;
40608+ gr_clear_chroot_entries(tsk);
40609+ kill = !atomic_dec_return(&fs->users);
40610 write_seqcount_end(&fs->seq);
40611 spin_unlock(&fs->lock);
40612 task_unlock(tsk);
40613@@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct
40614 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
40615 /* We don't need to lock fs - think why ;-) */
40616 if (fs) {
40617- fs->users = 1;
40618+ atomic_set(&fs->users, 1);
40619 fs->in_exec = 0;
40620 spin_lock_init(&fs->lock);
40621 seqcount_init(&fs->seq);
40622@@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct
40623 spin_lock(&old->lock);
40624 fs->root = old->root;
40625 path_get_longterm(&fs->root);
40626+ /* instead of calling gr_set_chroot_entries here,
40627+ we call it from every caller of this function
40628+ */
40629 fs->pwd = old->pwd;
40630 path_get_longterm(&fs->pwd);
40631 spin_unlock(&old->lock);
40632@@ -150,8 +157,9 @@ int unshare_fs_struct(void)
40633
40634 task_lock(current);
40635 spin_lock(&fs->lock);
40636- kill = !--fs->users;
40637+ kill = !atomic_dec_return(&fs->users);
40638 current->fs = new_fs;
40639+ gr_set_chroot_entries(current, &new_fs->root);
40640 spin_unlock(&fs->lock);
40641 task_unlock(current);
40642
40643@@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
40644
40645 /* to be mentioned only in INIT_TASK */
40646 struct fs_struct init_fs = {
40647- .users = 1,
40648+ .users = ATOMIC_INIT(1),
40649 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
40650 .seq = SEQCNT_ZERO,
40651 .umask = 0022,
40652@@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
40653 task_lock(current);
40654
40655 spin_lock(&init_fs.lock);
40656- init_fs.users++;
40657+ atomic_inc(&init_fs.users);
40658 spin_unlock(&init_fs.lock);
40659
40660 spin_lock(&fs->lock);
40661 current->fs = &init_fs;
40662- kill = !--fs->users;
40663+ gr_set_chroot_entries(current, &current->fs->root);
40664+ kill = !atomic_dec_return(&fs->users);
40665 spin_unlock(&fs->lock);
40666
40667 task_unlock(current);
40668diff -urNp linux-3.0.4/fs/fuse/cuse.c linux-3.0.4/fs/fuse/cuse.c
40669--- linux-3.0.4/fs/fuse/cuse.c 2011-07-21 22:17:23.000000000 -0400
40670+++ linux-3.0.4/fs/fuse/cuse.c 2011-08-23 21:47:56.000000000 -0400
40671@@ -586,10 +586,12 @@ static int __init cuse_init(void)
40672 INIT_LIST_HEAD(&cuse_conntbl[i]);
40673
40674 /* inherit and extend fuse_dev_operations */
40675- cuse_channel_fops = fuse_dev_operations;
40676- cuse_channel_fops.owner = THIS_MODULE;
40677- cuse_channel_fops.open = cuse_channel_open;
40678- cuse_channel_fops.release = cuse_channel_release;
40679+ pax_open_kernel();
40680+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
40681+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
40682+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
40683+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
40684+ pax_close_kernel();
40685
40686 cuse_class = class_create(THIS_MODULE, "cuse");
40687 if (IS_ERR(cuse_class))
40688diff -urNp linux-3.0.4/fs/fuse/dev.c linux-3.0.4/fs/fuse/dev.c
40689--- linux-3.0.4/fs/fuse/dev.c 2011-08-29 23:26:14.000000000 -0400
40690+++ linux-3.0.4/fs/fuse/dev.c 2011-08-29 23:26:27.000000000 -0400
40691@@ -1238,7 +1238,7 @@ static ssize_t fuse_dev_splice_read(stru
40692 ret = 0;
40693 pipe_lock(pipe);
40694
40695- if (!pipe->readers) {
40696+ if (!atomic_read(&pipe->readers)) {
40697 send_sig(SIGPIPE, current, 0);
40698 if (!ret)
40699 ret = -EPIPE;
40700diff -urNp linux-3.0.4/fs/fuse/dir.c linux-3.0.4/fs/fuse/dir.c
40701--- linux-3.0.4/fs/fuse/dir.c 2011-07-21 22:17:23.000000000 -0400
40702+++ linux-3.0.4/fs/fuse/dir.c 2011-08-23 21:47:56.000000000 -0400
40703@@ -1148,7 +1148,7 @@ static char *read_link(struct dentry *de
40704 return link;
40705 }
40706
40707-static void free_link(char *link)
40708+static void free_link(const char *link)
40709 {
40710 if (!IS_ERR(link))
40711 free_page((unsigned long) link);
40712diff -urNp linux-3.0.4/fs/gfs2/inode.c linux-3.0.4/fs/gfs2/inode.c
40713--- linux-3.0.4/fs/gfs2/inode.c 2011-07-21 22:17:23.000000000 -0400
40714+++ linux-3.0.4/fs/gfs2/inode.c 2011-08-23 21:47:56.000000000 -0400
40715@@ -1525,7 +1525,7 @@ out:
40716
40717 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40718 {
40719- char *s = nd_get_link(nd);
40720+ const char *s = nd_get_link(nd);
40721 if (!IS_ERR(s))
40722 kfree(s);
40723 }
40724diff -urNp linux-3.0.4/fs/hfsplus/catalog.c linux-3.0.4/fs/hfsplus/catalog.c
40725--- linux-3.0.4/fs/hfsplus/catalog.c 2011-07-21 22:17:23.000000000 -0400
40726+++ linux-3.0.4/fs/hfsplus/catalog.c 2011-08-23 21:48:14.000000000 -0400
40727@@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block
40728 int err;
40729 u16 type;
40730
40731+ pax_track_stack();
40732+
40733 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
40734 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
40735 if (err)
40736@@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct
40737 int entry_size;
40738 int err;
40739
40740+ pax_track_stack();
40741+
40742 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
40743 str->name, cnid, inode->i_nlink);
40744 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
40745@@ -349,6 +353,8 @@ int hfsplus_rename_cat(u32 cnid,
40746 int entry_size, type;
40747 int err = 0;
40748
40749+ pax_track_stack();
40750+
40751 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
40752 cnid, src_dir->i_ino, src_name->name,
40753 dst_dir->i_ino, dst_name->name);
40754diff -urNp linux-3.0.4/fs/hfsplus/dir.c linux-3.0.4/fs/hfsplus/dir.c
40755--- linux-3.0.4/fs/hfsplus/dir.c 2011-07-21 22:17:23.000000000 -0400
40756+++ linux-3.0.4/fs/hfsplus/dir.c 2011-08-23 21:48:14.000000000 -0400
40757@@ -129,6 +129,8 @@ static int hfsplus_readdir(struct file *
40758 struct hfsplus_readdir_data *rd;
40759 u16 type;
40760
40761+ pax_track_stack();
40762+
40763 if (filp->f_pos >= inode->i_size)
40764 return 0;
40765
40766diff -urNp linux-3.0.4/fs/hfsplus/inode.c linux-3.0.4/fs/hfsplus/inode.c
40767--- linux-3.0.4/fs/hfsplus/inode.c 2011-07-21 22:17:23.000000000 -0400
40768+++ linux-3.0.4/fs/hfsplus/inode.c 2011-08-23 21:48:14.000000000 -0400
40769@@ -489,6 +489,8 @@ int hfsplus_cat_read_inode(struct inode
40770 int res = 0;
40771 u16 type;
40772
40773+ pax_track_stack();
40774+
40775 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
40776
40777 HFSPLUS_I(inode)->linkid = 0;
40778@@ -552,6 +554,8 @@ int hfsplus_cat_write_inode(struct inode
40779 struct hfs_find_data fd;
40780 hfsplus_cat_entry entry;
40781
40782+ pax_track_stack();
40783+
40784 if (HFSPLUS_IS_RSRC(inode))
40785 main_inode = HFSPLUS_I(inode)->rsrc_inode;
40786
40787diff -urNp linux-3.0.4/fs/hfsplus/ioctl.c linux-3.0.4/fs/hfsplus/ioctl.c
40788--- linux-3.0.4/fs/hfsplus/ioctl.c 2011-07-21 22:17:23.000000000 -0400
40789+++ linux-3.0.4/fs/hfsplus/ioctl.c 2011-08-23 21:48:14.000000000 -0400
40790@@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dent
40791 struct hfsplus_cat_file *file;
40792 int res;
40793
40794+ pax_track_stack();
40795+
40796 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
40797 return -EOPNOTSUPP;
40798
40799@@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *
40800 struct hfsplus_cat_file *file;
40801 ssize_t res = 0;
40802
40803+ pax_track_stack();
40804+
40805 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
40806 return -EOPNOTSUPP;
40807
40808diff -urNp linux-3.0.4/fs/hfsplus/super.c linux-3.0.4/fs/hfsplus/super.c
40809--- linux-3.0.4/fs/hfsplus/super.c 2011-07-21 22:17:23.000000000 -0400
40810+++ linux-3.0.4/fs/hfsplus/super.c 2011-08-23 21:48:14.000000000 -0400
40811@@ -340,6 +340,8 @@ static int hfsplus_fill_super(struct sup
40812 struct nls_table *nls = NULL;
40813 int err;
40814
40815+ pax_track_stack();
40816+
40817 err = -EINVAL;
40818 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
40819 if (!sbi)
40820diff -urNp linux-3.0.4/fs/hugetlbfs/inode.c linux-3.0.4/fs/hugetlbfs/inode.c
40821--- linux-3.0.4/fs/hugetlbfs/inode.c 2011-07-21 22:17:23.000000000 -0400
40822+++ linux-3.0.4/fs/hugetlbfs/inode.c 2011-08-23 21:48:14.000000000 -0400
40823@@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs
40824 .kill_sb = kill_litter_super,
40825 };
40826
40827-static struct vfsmount *hugetlbfs_vfsmount;
40828+struct vfsmount *hugetlbfs_vfsmount;
40829
40830 static int can_do_hugetlb_shm(void)
40831 {
40832diff -urNp linux-3.0.4/fs/inode.c linux-3.0.4/fs/inode.c
40833--- linux-3.0.4/fs/inode.c 2011-07-21 22:17:23.000000000 -0400
40834+++ linux-3.0.4/fs/inode.c 2011-08-23 21:47:56.000000000 -0400
40835@@ -829,8 +829,8 @@ unsigned int get_next_ino(void)
40836
40837 #ifdef CONFIG_SMP
40838 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
40839- static atomic_t shared_last_ino;
40840- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
40841+ static atomic_unchecked_t shared_last_ino;
40842+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
40843
40844 res = next - LAST_INO_BATCH;
40845 }
40846diff -urNp linux-3.0.4/fs/jbd/checkpoint.c linux-3.0.4/fs/jbd/checkpoint.c
40847--- linux-3.0.4/fs/jbd/checkpoint.c 2011-07-21 22:17:23.000000000 -0400
40848+++ linux-3.0.4/fs/jbd/checkpoint.c 2011-08-23 21:48:14.000000000 -0400
40849@@ -350,6 +350,8 @@ int log_do_checkpoint(journal_t *journal
40850 tid_t this_tid;
40851 int result;
40852
40853+ pax_track_stack();
40854+
40855 jbd_debug(1, "Start checkpoint\n");
40856
40857 /*
40858diff -urNp linux-3.0.4/fs/jffs2/compr_rtime.c linux-3.0.4/fs/jffs2/compr_rtime.c
40859--- linux-3.0.4/fs/jffs2/compr_rtime.c 2011-07-21 22:17:23.000000000 -0400
40860+++ linux-3.0.4/fs/jffs2/compr_rtime.c 2011-08-23 21:48:14.000000000 -0400
40861@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
40862 int outpos = 0;
40863 int pos=0;
40864
40865+ pax_track_stack();
40866+
40867 memset(positions,0,sizeof(positions));
40868
40869 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
40870@@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsign
40871 int outpos = 0;
40872 int pos=0;
40873
40874+ pax_track_stack();
40875+
40876 memset(positions,0,sizeof(positions));
40877
40878 while (outpos<destlen) {
40879diff -urNp linux-3.0.4/fs/jffs2/compr_rubin.c linux-3.0.4/fs/jffs2/compr_rubin.c
40880--- linux-3.0.4/fs/jffs2/compr_rubin.c 2011-07-21 22:17:23.000000000 -0400
40881+++ linux-3.0.4/fs/jffs2/compr_rubin.c 2011-08-23 21:48:14.000000000 -0400
40882@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
40883 int ret;
40884 uint32_t mysrclen, mydstlen;
40885
40886+ pax_track_stack();
40887+
40888 mysrclen = *sourcelen;
40889 mydstlen = *dstlen - 8;
40890
40891diff -urNp linux-3.0.4/fs/jffs2/erase.c linux-3.0.4/fs/jffs2/erase.c
40892--- linux-3.0.4/fs/jffs2/erase.c 2011-07-21 22:17:23.000000000 -0400
40893+++ linux-3.0.4/fs/jffs2/erase.c 2011-08-23 21:47:56.000000000 -0400
40894@@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
40895 struct jffs2_unknown_node marker = {
40896 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
40897 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
40898- .totlen = cpu_to_je32(c->cleanmarker_size)
40899+ .totlen = cpu_to_je32(c->cleanmarker_size),
40900+ .hdr_crc = cpu_to_je32(0)
40901 };
40902
40903 jffs2_prealloc_raw_node_refs(c, jeb, 1);
40904diff -urNp linux-3.0.4/fs/jffs2/wbuf.c linux-3.0.4/fs/jffs2/wbuf.c
40905--- linux-3.0.4/fs/jffs2/wbuf.c 2011-07-21 22:17:23.000000000 -0400
40906+++ linux-3.0.4/fs/jffs2/wbuf.c 2011-08-23 21:47:56.000000000 -0400
40907@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
40908 {
40909 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
40910 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
40911- .totlen = constant_cpu_to_je32(8)
40912+ .totlen = constant_cpu_to_je32(8),
40913+ .hdr_crc = constant_cpu_to_je32(0)
40914 };
40915
40916 /*
40917diff -urNp linux-3.0.4/fs/jffs2/xattr.c linux-3.0.4/fs/jffs2/xattr.c
40918--- linux-3.0.4/fs/jffs2/xattr.c 2011-07-21 22:17:23.000000000 -0400
40919+++ linux-3.0.4/fs/jffs2/xattr.c 2011-08-23 21:48:14.000000000 -0400
40920@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
40921
40922 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
40923
40924+ pax_track_stack();
40925+
40926 /* Phase.1 : Merge same xref */
40927 for (i=0; i < XREF_TMPHASH_SIZE; i++)
40928 xref_tmphash[i] = NULL;
40929diff -urNp linux-3.0.4/fs/jfs/super.c linux-3.0.4/fs/jfs/super.c
40930--- linux-3.0.4/fs/jfs/super.c 2011-07-21 22:17:23.000000000 -0400
40931+++ linux-3.0.4/fs/jfs/super.c 2011-08-23 21:47:56.000000000 -0400
40932@@ -803,7 +803,7 @@ static int __init init_jfs_fs(void)
40933
40934 jfs_inode_cachep =
40935 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
40936- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
40937+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
40938 init_once);
40939 if (jfs_inode_cachep == NULL)
40940 return -ENOMEM;
40941diff -urNp linux-3.0.4/fs/Kconfig.binfmt linux-3.0.4/fs/Kconfig.binfmt
40942--- linux-3.0.4/fs/Kconfig.binfmt 2011-07-21 22:17:23.000000000 -0400
40943+++ linux-3.0.4/fs/Kconfig.binfmt 2011-08-23 21:47:56.000000000 -0400
40944@@ -86,7 +86,7 @@ config HAVE_AOUT
40945
40946 config BINFMT_AOUT
40947 tristate "Kernel support for a.out and ECOFF binaries"
40948- depends on HAVE_AOUT
40949+ depends on HAVE_AOUT && BROKEN
40950 ---help---
40951 A.out (Assembler.OUTput) is a set of formats for libraries and
40952 executables used in the earliest versions of UNIX. Linux used
40953diff -urNp linux-3.0.4/fs/libfs.c linux-3.0.4/fs/libfs.c
40954--- linux-3.0.4/fs/libfs.c 2011-07-21 22:17:23.000000000 -0400
40955+++ linux-3.0.4/fs/libfs.c 2011-08-23 21:47:56.000000000 -0400
40956@@ -163,6 +163,9 @@ int dcache_readdir(struct file * filp, v
40957
40958 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
40959 struct dentry *next;
40960+ char d_name[sizeof(next->d_iname)];
40961+ const unsigned char *name;
40962+
40963 next = list_entry(p, struct dentry, d_u.d_child);
40964 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
40965 if (!simple_positive(next)) {
40966@@ -172,7 +175,12 @@ int dcache_readdir(struct file * filp, v
40967
40968 spin_unlock(&next->d_lock);
40969 spin_unlock(&dentry->d_lock);
40970- if (filldir(dirent, next->d_name.name,
40971+ name = next->d_name.name;
40972+ if (name == next->d_iname) {
40973+ memcpy(d_name, name, next->d_name.len);
40974+ name = d_name;
40975+ }
40976+ if (filldir(dirent, name,
40977 next->d_name.len, filp->f_pos,
40978 next->d_inode->i_ino,
40979 dt_type(next->d_inode)) < 0)
40980diff -urNp linux-3.0.4/fs/lockd/clntproc.c linux-3.0.4/fs/lockd/clntproc.c
40981--- linux-3.0.4/fs/lockd/clntproc.c 2011-07-21 22:17:23.000000000 -0400
40982+++ linux-3.0.4/fs/lockd/clntproc.c 2011-08-23 21:48:14.000000000 -0400
40983@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
40984 /*
40985 * Cookie counter for NLM requests
40986 */
40987-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
40988+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
40989
40990 void nlmclnt_next_cookie(struct nlm_cookie *c)
40991 {
40992- u32 cookie = atomic_inc_return(&nlm_cookie);
40993+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
40994
40995 memcpy(c->data, &cookie, 4);
40996 c->len=4;
40997@@ -620,6 +620,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
40998 struct nlm_rqst reqst, *req;
40999 int status;
41000
41001+ pax_track_stack();
41002+
41003 req = &reqst;
41004 memset(req, 0, sizeof(*req));
41005 locks_init_lock(&req->a_args.lock.fl);
41006diff -urNp linux-3.0.4/fs/locks.c linux-3.0.4/fs/locks.c
41007--- linux-3.0.4/fs/locks.c 2011-07-21 22:17:23.000000000 -0400
41008+++ linux-3.0.4/fs/locks.c 2011-08-23 21:47:56.000000000 -0400
41009@@ -2043,16 +2043,16 @@ void locks_remove_flock(struct file *fil
41010 return;
41011
41012 if (filp->f_op && filp->f_op->flock) {
41013- struct file_lock fl = {
41014+ struct file_lock flock = {
41015 .fl_pid = current->tgid,
41016 .fl_file = filp,
41017 .fl_flags = FL_FLOCK,
41018 .fl_type = F_UNLCK,
41019 .fl_end = OFFSET_MAX,
41020 };
41021- filp->f_op->flock(filp, F_SETLKW, &fl);
41022- if (fl.fl_ops && fl.fl_ops->fl_release_private)
41023- fl.fl_ops->fl_release_private(&fl);
41024+ filp->f_op->flock(filp, F_SETLKW, &flock);
41025+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
41026+ flock.fl_ops->fl_release_private(&flock);
41027 }
41028
41029 lock_flocks();
41030diff -urNp linux-3.0.4/fs/logfs/super.c linux-3.0.4/fs/logfs/super.c
41031--- linux-3.0.4/fs/logfs/super.c 2011-07-21 22:17:23.000000000 -0400
41032+++ linux-3.0.4/fs/logfs/super.c 2011-08-23 21:48:14.000000000 -0400
41033@@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super
41034 struct logfs_disk_super _ds1, *ds1 = &_ds1;
41035 int err, valid0, valid1;
41036
41037+ pax_track_stack();
41038+
41039 /* read first superblock */
41040 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
41041 if (err)
41042diff -urNp linux-3.0.4/fs/namei.c linux-3.0.4/fs/namei.c
41043--- linux-3.0.4/fs/namei.c 2011-07-21 22:17:23.000000000 -0400
41044+++ linux-3.0.4/fs/namei.c 2011-08-23 21:48:14.000000000 -0400
41045@@ -237,21 +237,31 @@ int generic_permission(struct inode *ino
41046 return ret;
41047
41048 /*
41049- * Read/write DACs are always overridable.
41050- * Executable DACs are overridable for all directories and
41051- * for non-directories that have least one exec bit set.
41052+ * Searching includes executable on directories, else just read.
41053 */
41054- if (!(mask & MAY_EXEC) || execute_ok(inode))
41055- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
41056+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
41057+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) {
41058+#ifdef CONFIG_GRKERNSEC
41059+ if (flags & IPERM_FLAG_RCU)
41060+ return -ECHILD;
41061+#endif
41062+ if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
41063 return 0;
41064+ }
41065
41066 /*
41067- * Searching includes executable on directories, else just read.
41068+ * Read/write DACs are always overridable.
41069+ * Executable DACs are overridable for all directories and
41070+ * for non-directories that have least one exec bit set.
41071 */
41072- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
41073- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
41074- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
41075+ if (!(mask & MAY_EXEC) || execute_ok(inode)) {
41076+#ifdef CONFIG_GRKERNSEC
41077+ if (flags & IPERM_FLAG_RCU)
41078+ return -ECHILD;
41079+#endif
41080+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
41081 return 0;
41082+ }
41083
41084 return -EACCES;
41085 }
41086@@ -547,6 +557,9 @@ static int complete_walk(struct nameidat
41087 br_read_unlock(vfsmount_lock);
41088 }
41089
41090+ if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
41091+ return -ENOENT;
41092+
41093 if (likely(!(nd->flags & LOOKUP_JUMPED)))
41094 return 0;
41095
41096@@ -593,9 +606,16 @@ static inline int exec_permission(struct
41097 if (ret == -ECHILD)
41098 return ret;
41099
41100- if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
41101- ns_capable(ns, CAP_DAC_READ_SEARCH))
41102+ if (ns_capable_nolog(ns, CAP_DAC_OVERRIDE))
41103 goto ok;
41104+ else {
41105+#ifdef CONFIG_GRKERNSEC
41106+ if (flags & IPERM_FLAG_RCU)
41107+ return -ECHILD;
41108+#endif
41109+ if (ns_capable(ns, CAP_DAC_READ_SEARCH) || ns_capable(ns, CAP_DAC_OVERRIDE))
41110+ goto ok;
41111+ }
41112
41113 return ret;
41114 ok:
41115@@ -703,11 +723,19 @@ follow_link(struct path *link, struct na
41116 return error;
41117 }
41118
41119+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
41120+ dentry->d_inode, dentry, nd->path.mnt)) {
41121+ error = -EACCES;
41122+ *p = ERR_PTR(error); /* no ->put_link(), please */
41123+ path_put(&nd->path);
41124+ return error;
41125+ }
41126+
41127 nd->last_type = LAST_BIND;
41128 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
41129 error = PTR_ERR(*p);
41130 if (!IS_ERR(*p)) {
41131- char *s = nd_get_link(nd);
41132+ const char *s = nd_get_link(nd);
41133 error = 0;
41134 if (s)
41135 error = __vfs_follow_link(nd, s);
41136@@ -1625,6 +1653,9 @@ static int do_path_lookup(int dfd, const
41137 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
41138
41139 if (likely(!retval)) {
41140+ if (*name != '/' && nd->path.dentry && nd->inode && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
41141+ return -ENOENT;
41142+
41143 if (unlikely(!audit_dummy_context())) {
41144 if (nd->path.dentry && nd->inode)
41145 audit_inode(name, nd->path.dentry);
41146@@ -1935,6 +1966,30 @@ int vfs_create(struct inode *dir, struct
41147 return error;
41148 }
41149
41150+/*
41151+ * Note that while the flag value (low two bits) for sys_open means:
41152+ * 00 - read-only
41153+ * 01 - write-only
41154+ * 10 - read-write
41155+ * 11 - special
41156+ * it is changed into
41157+ * 00 - no permissions needed
41158+ * 01 - read-permission
41159+ * 10 - write-permission
41160+ * 11 - read-write
41161+ * for the internal routines (ie open_namei()/follow_link() etc)
41162+ * This is more logical, and also allows the 00 "no perm needed"
41163+ * to be used for symlinks (where the permissions are checked
41164+ * later).
41165+ *
41166+*/
41167+static inline int open_to_namei_flags(int flag)
41168+{
41169+ if ((flag+1) & O_ACCMODE)
41170+ flag++;
41171+ return flag;
41172+}
41173+
41174 static int may_open(struct path *path, int acc_mode, int flag)
41175 {
41176 struct dentry *dentry = path->dentry;
41177@@ -1987,7 +2042,27 @@ static int may_open(struct path *path, i
41178 /*
41179 * Ensure there are no outstanding leases on the file.
41180 */
41181- return break_lease(inode, flag);
41182+ error = break_lease(inode, flag);
41183+
41184+ if (error)
41185+ return error;
41186+
41187+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
41188+ error = -EPERM;
41189+ goto exit;
41190+ }
41191+
41192+ if (gr_handle_rawio(inode)) {
41193+ error = -EPERM;
41194+ goto exit;
41195+ }
41196+
41197+ if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
41198+ error = -EACCES;
41199+ goto exit;
41200+ }
41201+exit:
41202+ return error;
41203 }
41204
41205 static int handle_truncate(struct file *filp)
41206@@ -2013,30 +2088,6 @@ static int handle_truncate(struct file *
41207 }
41208
41209 /*
41210- * Note that while the flag value (low two bits) for sys_open means:
41211- * 00 - read-only
41212- * 01 - write-only
41213- * 10 - read-write
41214- * 11 - special
41215- * it is changed into
41216- * 00 - no permissions needed
41217- * 01 - read-permission
41218- * 10 - write-permission
41219- * 11 - read-write
41220- * for the internal routines (ie open_namei()/follow_link() etc)
41221- * This is more logical, and also allows the 00 "no perm needed"
41222- * to be used for symlinks (where the permissions are checked
41223- * later).
41224- *
41225-*/
41226-static inline int open_to_namei_flags(int flag)
41227-{
41228- if ((flag+1) & O_ACCMODE)
41229- flag++;
41230- return flag;
41231-}
41232-
41233-/*
41234 * Handle the last step of open()
41235 */
41236 static struct file *do_last(struct nameidata *nd, struct path *path,
41237@@ -2045,6 +2096,7 @@ static struct file *do_last(struct namei
41238 struct dentry *dir = nd->path.dentry;
41239 struct dentry *dentry;
41240 int open_flag = op->open_flag;
41241+ int flag = open_to_namei_flags(open_flag);
41242 int will_truncate = open_flag & O_TRUNC;
41243 int want_write = 0;
41244 int acc_mode = op->acc_mode;
41245@@ -2132,6 +2184,12 @@ static struct file *do_last(struct namei
41246 /* Negative dentry, just create the file */
41247 if (!dentry->d_inode) {
41248 int mode = op->mode;
41249+
41250+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, flag, mode)) {
41251+ error = -EACCES;
41252+ goto exit_mutex_unlock;
41253+ }
41254+
41255 if (!IS_POSIXACL(dir->d_inode))
41256 mode &= ~current_umask();
41257 /*
41258@@ -2155,6 +2213,8 @@ static struct file *do_last(struct namei
41259 error = vfs_create(dir->d_inode, dentry, mode, nd);
41260 if (error)
41261 goto exit_mutex_unlock;
41262+ else
41263+ gr_handle_create(path->dentry, path->mnt);
41264 mutex_unlock(&dir->d_inode->i_mutex);
41265 dput(nd->path.dentry);
41266 nd->path.dentry = dentry;
41267@@ -2164,6 +2224,14 @@ static struct file *do_last(struct namei
41268 /*
41269 * It already exists.
41270 */
41271+
41272+ /* only check if O_CREAT is specified, all other checks need to go
41273+ into may_open */
41274+ if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
41275+ error = -EACCES;
41276+ goto exit_mutex_unlock;
41277+ }
41278+
41279 mutex_unlock(&dir->d_inode->i_mutex);
41280 audit_inode(pathname, path->dentry);
41281
41282@@ -2450,6 +2518,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
41283 error = may_mknod(mode);
41284 if (error)
41285 goto out_dput;
41286+
41287+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
41288+ error = -EPERM;
41289+ goto out_dput;
41290+ }
41291+
41292+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
41293+ error = -EACCES;
41294+ goto out_dput;
41295+ }
41296+
41297 error = mnt_want_write(nd.path.mnt);
41298 if (error)
41299 goto out_dput;
41300@@ -2470,6 +2549,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
41301 }
41302 out_drop_write:
41303 mnt_drop_write(nd.path.mnt);
41304+
41305+ if (!error)
41306+ gr_handle_create(dentry, nd.path.mnt);
41307 out_dput:
41308 dput(dentry);
41309 out_unlock:
41310@@ -2522,6 +2604,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
41311 if (IS_ERR(dentry))
41312 goto out_unlock;
41313
41314+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
41315+ error = -EACCES;
41316+ goto out_dput;
41317+ }
41318+
41319 if (!IS_POSIXACL(nd.path.dentry->d_inode))
41320 mode &= ~current_umask();
41321 error = mnt_want_write(nd.path.mnt);
41322@@ -2533,6 +2620,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
41323 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
41324 out_drop_write:
41325 mnt_drop_write(nd.path.mnt);
41326+
41327+ if (!error)
41328+ gr_handle_create(dentry, nd.path.mnt);
41329+
41330 out_dput:
41331 dput(dentry);
41332 out_unlock:
41333@@ -2613,6 +2704,8 @@ static long do_rmdir(int dfd, const char
41334 char * name;
41335 struct dentry *dentry;
41336 struct nameidata nd;
41337+ ino_t saved_ino = 0;
41338+ dev_t saved_dev = 0;
41339
41340 error = user_path_parent(dfd, pathname, &nd, &name);
41341 if (error)
41342@@ -2641,6 +2734,17 @@ static long do_rmdir(int dfd, const char
41343 error = -ENOENT;
41344 goto exit3;
41345 }
41346+
41347+ if (dentry->d_inode->i_nlink <= 1) {
41348+ saved_ino = dentry->d_inode->i_ino;
41349+ saved_dev = gr_get_dev_from_dentry(dentry);
41350+ }
41351+
41352+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
41353+ error = -EACCES;
41354+ goto exit3;
41355+ }
41356+
41357 error = mnt_want_write(nd.path.mnt);
41358 if (error)
41359 goto exit3;
41360@@ -2648,6 +2752,8 @@ static long do_rmdir(int dfd, const char
41361 if (error)
41362 goto exit4;
41363 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
41364+ if (!error && (saved_dev || saved_ino))
41365+ gr_handle_delete(saved_ino, saved_dev);
41366 exit4:
41367 mnt_drop_write(nd.path.mnt);
41368 exit3:
41369@@ -2710,6 +2816,8 @@ static long do_unlinkat(int dfd, const c
41370 struct dentry *dentry;
41371 struct nameidata nd;
41372 struct inode *inode = NULL;
41373+ ino_t saved_ino = 0;
41374+ dev_t saved_dev = 0;
41375
41376 error = user_path_parent(dfd, pathname, &nd, &name);
41377 if (error)
41378@@ -2732,6 +2840,16 @@ static long do_unlinkat(int dfd, const c
41379 if (!inode)
41380 goto slashes;
41381 ihold(inode);
41382+
41383+ if (inode->i_nlink <= 1) {
41384+ saved_ino = inode->i_ino;
41385+ saved_dev = gr_get_dev_from_dentry(dentry);
41386+ }
41387+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
41388+ error = -EACCES;
41389+ goto exit2;
41390+ }
41391+
41392 error = mnt_want_write(nd.path.mnt);
41393 if (error)
41394 goto exit2;
41395@@ -2739,6 +2857,8 @@ static long do_unlinkat(int dfd, const c
41396 if (error)
41397 goto exit3;
41398 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
41399+ if (!error && (saved_ino || saved_dev))
41400+ gr_handle_delete(saved_ino, saved_dev);
41401 exit3:
41402 mnt_drop_write(nd.path.mnt);
41403 exit2:
41404@@ -2816,6 +2936,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
41405 if (IS_ERR(dentry))
41406 goto out_unlock;
41407
41408+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
41409+ error = -EACCES;
41410+ goto out_dput;
41411+ }
41412+
41413 error = mnt_want_write(nd.path.mnt);
41414 if (error)
41415 goto out_dput;
41416@@ -2823,6 +2948,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
41417 if (error)
41418 goto out_drop_write;
41419 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
41420+ if (!error)
41421+ gr_handle_create(dentry, nd.path.mnt);
41422 out_drop_write:
41423 mnt_drop_write(nd.path.mnt);
41424 out_dput:
41425@@ -2931,6 +3058,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
41426 error = PTR_ERR(new_dentry);
41427 if (IS_ERR(new_dentry))
41428 goto out_unlock;
41429+
41430+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
41431+ old_path.dentry->d_inode,
41432+ old_path.dentry->d_inode->i_mode, to)) {
41433+ error = -EACCES;
41434+ goto out_dput;
41435+ }
41436+
41437+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
41438+ old_path.dentry, old_path.mnt, to)) {
41439+ error = -EACCES;
41440+ goto out_dput;
41441+ }
41442+
41443 error = mnt_want_write(nd.path.mnt);
41444 if (error)
41445 goto out_dput;
41446@@ -2938,6 +3079,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
41447 if (error)
41448 goto out_drop_write;
41449 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
41450+ if (!error)
41451+ gr_handle_create(new_dentry, nd.path.mnt);
41452 out_drop_write:
41453 mnt_drop_write(nd.path.mnt);
41454 out_dput:
41455@@ -3113,6 +3256,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
41456 char *to;
41457 int error;
41458
41459+ pax_track_stack();
41460+
41461 error = user_path_parent(olddfd, oldname, &oldnd, &from);
41462 if (error)
41463 goto exit;
41464@@ -3169,6 +3314,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
41465 if (new_dentry == trap)
41466 goto exit5;
41467
41468+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
41469+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
41470+ to);
41471+ if (error)
41472+ goto exit5;
41473+
41474 error = mnt_want_write(oldnd.path.mnt);
41475 if (error)
41476 goto exit5;
41477@@ -3178,6 +3329,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
41478 goto exit6;
41479 error = vfs_rename(old_dir->d_inode, old_dentry,
41480 new_dir->d_inode, new_dentry);
41481+ if (!error)
41482+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
41483+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
41484 exit6:
41485 mnt_drop_write(oldnd.path.mnt);
41486 exit5:
41487@@ -3203,6 +3357,8 @@ SYSCALL_DEFINE2(rename, const char __use
41488
41489 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
41490 {
41491+ char tmpbuf[64];
41492+ const char *newlink;
41493 int len;
41494
41495 len = PTR_ERR(link);
41496@@ -3212,7 +3368,14 @@ int vfs_readlink(struct dentry *dentry,
41497 len = strlen(link);
41498 if (len > (unsigned) buflen)
41499 len = buflen;
41500- if (copy_to_user(buffer, link, len))
41501+
41502+ if (len < sizeof(tmpbuf)) {
41503+ memcpy(tmpbuf, link, len);
41504+ newlink = tmpbuf;
41505+ } else
41506+ newlink = link;
41507+
41508+ if (copy_to_user(buffer, newlink, len))
41509 len = -EFAULT;
41510 out:
41511 return len;
41512diff -urNp linux-3.0.4/fs/namespace.c linux-3.0.4/fs/namespace.c
41513--- linux-3.0.4/fs/namespace.c 2011-07-21 22:17:23.000000000 -0400
41514+++ linux-3.0.4/fs/namespace.c 2011-08-23 21:48:14.000000000 -0400
41515@@ -1328,6 +1328,9 @@ static int do_umount(struct vfsmount *mn
41516 if (!(sb->s_flags & MS_RDONLY))
41517 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
41518 up_write(&sb->s_umount);
41519+
41520+ gr_log_remount(mnt->mnt_devname, retval);
41521+
41522 return retval;
41523 }
41524
41525@@ -1347,6 +1350,9 @@ static int do_umount(struct vfsmount *mn
41526 br_write_unlock(vfsmount_lock);
41527 up_write(&namespace_sem);
41528 release_mounts(&umount_list);
41529+
41530+ gr_log_unmount(mnt->mnt_devname, retval);
41531+
41532 return retval;
41533 }
41534
41535@@ -2338,6 +2344,16 @@ long do_mount(char *dev_name, char *dir_
41536 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
41537 MS_STRICTATIME);
41538
41539+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
41540+ retval = -EPERM;
41541+ goto dput_out;
41542+ }
41543+
41544+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
41545+ retval = -EPERM;
41546+ goto dput_out;
41547+ }
41548+
41549 if (flags & MS_REMOUNT)
41550 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
41551 data_page);
41552@@ -2352,6 +2368,9 @@ long do_mount(char *dev_name, char *dir_
41553 dev_name, data_page);
41554 dput_out:
41555 path_put(&path);
41556+
41557+ gr_log_mount(dev_name, dir_name, retval);
41558+
41559 return retval;
41560 }
41561
41562@@ -2575,6 +2594,11 @@ SYSCALL_DEFINE2(pivot_root, const char _
41563 if (error)
41564 goto out2;
41565
41566+ if (gr_handle_chroot_pivot()) {
41567+ error = -EPERM;
41568+ goto out2;
41569+ }
41570+
41571 get_fs_root(current->fs, &root);
41572 error = lock_mount(&old);
41573 if (error)
41574diff -urNp linux-3.0.4/fs/ncpfs/dir.c linux-3.0.4/fs/ncpfs/dir.c
41575--- linux-3.0.4/fs/ncpfs/dir.c 2011-07-21 22:17:23.000000000 -0400
41576+++ linux-3.0.4/fs/ncpfs/dir.c 2011-08-23 21:48:14.000000000 -0400
41577@@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentr
41578 int res, val = 0, len;
41579 __u8 __name[NCP_MAXPATHLEN + 1];
41580
41581+ pax_track_stack();
41582+
41583 if (dentry == dentry->d_sb->s_root)
41584 return 1;
41585
41586@@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct
41587 int error, res, len;
41588 __u8 __name[NCP_MAXPATHLEN + 1];
41589
41590+ pax_track_stack();
41591+
41592 error = -EIO;
41593 if (!ncp_conn_valid(server))
41594 goto finished;
41595@@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, st
41596 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
41597 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
41598
41599+ pax_track_stack();
41600+
41601 ncp_age_dentry(server, dentry);
41602 len = sizeof(__name);
41603 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
41604@@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir,
41605 int error, len;
41606 __u8 __name[NCP_MAXPATHLEN + 1];
41607
41608+ pax_track_stack();
41609+
41610 DPRINTK("ncp_mkdir: making %s/%s\n",
41611 dentry->d_parent->d_name.name, dentry->d_name.name);
41612
41613@@ -1140,6 +1148,8 @@ static int ncp_rename(struct inode *old_
41614 int old_len, new_len;
41615 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
41616
41617+ pax_track_stack();
41618+
41619 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
41620 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
41621 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
41622diff -urNp linux-3.0.4/fs/ncpfs/inode.c linux-3.0.4/fs/ncpfs/inode.c
41623--- linux-3.0.4/fs/ncpfs/inode.c 2011-07-21 22:17:23.000000000 -0400
41624+++ linux-3.0.4/fs/ncpfs/inode.c 2011-08-23 21:48:14.000000000 -0400
41625@@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_b
41626 #endif
41627 struct ncp_entry_info finfo;
41628
41629+ pax_track_stack();
41630+
41631 memset(&data, 0, sizeof(data));
41632 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
41633 if (!server)
41634diff -urNp linux-3.0.4/fs/nfs/inode.c linux-3.0.4/fs/nfs/inode.c
41635--- linux-3.0.4/fs/nfs/inode.c 2011-07-21 22:17:23.000000000 -0400
41636+++ linux-3.0.4/fs/nfs/inode.c 2011-08-23 21:47:56.000000000 -0400
41637@@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct
41638 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
41639 nfsi->attrtimeo_timestamp = jiffies;
41640
41641- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
41642+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
41643 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
41644 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
41645 else
41646@@ -1000,16 +1000,16 @@ static int nfs_size_need_update(const st
41647 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
41648 }
41649
41650-static atomic_long_t nfs_attr_generation_counter;
41651+static atomic_long_unchecked_t nfs_attr_generation_counter;
41652
41653 static unsigned long nfs_read_attr_generation_counter(void)
41654 {
41655- return atomic_long_read(&nfs_attr_generation_counter);
41656+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
41657 }
41658
41659 unsigned long nfs_inc_attr_generation_counter(void)
41660 {
41661- return atomic_long_inc_return(&nfs_attr_generation_counter);
41662+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
41663 }
41664
41665 void nfs_fattr_init(struct nfs_fattr *fattr)
41666diff -urNp linux-3.0.4/fs/nfsd/nfs4state.c linux-3.0.4/fs/nfsd/nfs4state.c
41667--- linux-3.0.4/fs/nfsd/nfs4state.c 2011-08-23 21:44:40.000000000 -0400
41668+++ linux-3.0.4/fs/nfsd/nfs4state.c 2011-08-23 21:48:14.000000000 -0400
41669@@ -3794,6 +3794,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
41670 unsigned int strhashval;
41671 int err;
41672
41673+ pax_track_stack();
41674+
41675 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
41676 (long long) lock->lk_offset,
41677 (long long) lock->lk_length);
41678diff -urNp linux-3.0.4/fs/nfsd/nfs4xdr.c linux-3.0.4/fs/nfsd/nfs4xdr.c
41679--- linux-3.0.4/fs/nfsd/nfs4xdr.c 2011-07-21 22:17:23.000000000 -0400
41680+++ linux-3.0.4/fs/nfsd/nfs4xdr.c 2011-08-23 21:48:14.000000000 -0400
41681@@ -1788,6 +1788,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
41682 .dentry = dentry,
41683 };
41684
41685+ pax_track_stack();
41686+
41687 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
41688 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
41689 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
41690diff -urNp linux-3.0.4/fs/nfsd/vfs.c linux-3.0.4/fs/nfsd/vfs.c
41691--- linux-3.0.4/fs/nfsd/vfs.c 2011-07-21 22:17:23.000000000 -0400
41692+++ linux-3.0.4/fs/nfsd/vfs.c 2011-08-23 21:47:56.000000000 -0400
41693@@ -896,7 +896,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
41694 } else {
41695 oldfs = get_fs();
41696 set_fs(KERNEL_DS);
41697- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
41698+ host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
41699 set_fs(oldfs);
41700 }
41701
41702@@ -1000,7 +1000,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
41703
41704 /* Write the data. */
41705 oldfs = get_fs(); set_fs(KERNEL_DS);
41706- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
41707+ host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
41708 set_fs(oldfs);
41709 if (host_err < 0)
41710 goto out_nfserr;
41711@@ -1535,7 +1535,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
41712 */
41713
41714 oldfs = get_fs(); set_fs(KERNEL_DS);
41715- host_err = inode->i_op->readlink(dentry, buf, *lenp);
41716+ host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
41717 set_fs(oldfs);
41718
41719 if (host_err < 0)
41720diff -urNp linux-3.0.4/fs/notify/fanotify/fanotify_user.c linux-3.0.4/fs/notify/fanotify/fanotify_user.c
41721--- linux-3.0.4/fs/notify/fanotify/fanotify_user.c 2011-07-21 22:17:23.000000000 -0400
41722+++ linux-3.0.4/fs/notify/fanotify/fanotify_user.c 2011-08-23 21:48:14.000000000 -0400
41723@@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct
41724 goto out_close_fd;
41725
41726 ret = -EFAULT;
41727- if (copy_to_user(buf, &fanotify_event_metadata,
41728+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
41729+ copy_to_user(buf, &fanotify_event_metadata,
41730 fanotify_event_metadata.event_len))
41731 goto out_kill_access_response;
41732
41733diff -urNp linux-3.0.4/fs/notify/notification.c linux-3.0.4/fs/notify/notification.c
41734--- linux-3.0.4/fs/notify/notification.c 2011-07-21 22:17:23.000000000 -0400
41735+++ linux-3.0.4/fs/notify/notification.c 2011-08-23 21:47:56.000000000 -0400
41736@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
41737 * get set to 0 so it will never get 'freed'
41738 */
41739 static struct fsnotify_event *q_overflow_event;
41740-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
41741+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
41742
41743 /**
41744 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
41745@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
41746 */
41747 u32 fsnotify_get_cookie(void)
41748 {
41749- return atomic_inc_return(&fsnotify_sync_cookie);
41750+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
41751 }
41752 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
41753
41754diff -urNp linux-3.0.4/fs/ntfs/dir.c linux-3.0.4/fs/ntfs/dir.c
41755--- linux-3.0.4/fs/ntfs/dir.c 2011-07-21 22:17:23.000000000 -0400
41756+++ linux-3.0.4/fs/ntfs/dir.c 2011-08-23 21:47:56.000000000 -0400
41757@@ -1329,7 +1329,7 @@ find_next_index_buffer:
41758 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
41759 ~(s64)(ndir->itype.index.block_size - 1)));
41760 /* Bounds checks. */
41761- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
41762+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
41763 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
41764 "inode 0x%lx or driver bug.", vdir->i_ino);
41765 goto err_out;
41766diff -urNp linux-3.0.4/fs/ntfs/file.c linux-3.0.4/fs/ntfs/file.c
41767--- linux-3.0.4/fs/ntfs/file.c 2011-07-21 22:17:23.000000000 -0400
41768+++ linux-3.0.4/fs/ntfs/file.c 2011-08-23 21:47:56.000000000 -0400
41769@@ -2222,6 +2222,6 @@ const struct inode_operations ntfs_file_
41770 #endif /* NTFS_RW */
41771 };
41772
41773-const struct file_operations ntfs_empty_file_ops = {};
41774+const struct file_operations ntfs_empty_file_ops __read_only;
41775
41776-const struct inode_operations ntfs_empty_inode_ops = {};
41777+const struct inode_operations ntfs_empty_inode_ops __read_only;
41778diff -urNp linux-3.0.4/fs/ocfs2/localalloc.c linux-3.0.4/fs/ocfs2/localalloc.c
41779--- linux-3.0.4/fs/ocfs2/localalloc.c 2011-07-21 22:17:23.000000000 -0400
41780+++ linux-3.0.4/fs/ocfs2/localalloc.c 2011-08-23 21:47:56.000000000 -0400
41781@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_windo
41782 goto bail;
41783 }
41784
41785- atomic_inc(&osb->alloc_stats.moves);
41786+ atomic_inc_unchecked(&osb->alloc_stats.moves);
41787
41788 bail:
41789 if (handle)
41790diff -urNp linux-3.0.4/fs/ocfs2/namei.c linux-3.0.4/fs/ocfs2/namei.c
41791--- linux-3.0.4/fs/ocfs2/namei.c 2011-07-21 22:17:23.000000000 -0400
41792+++ linux-3.0.4/fs/ocfs2/namei.c 2011-08-23 21:48:14.000000000 -0400
41793@@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *ol
41794 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
41795 struct ocfs2_dir_lookup_result target_insert = { NULL, };
41796
41797+ pax_track_stack();
41798+
41799 /* At some point it might be nice to break this function up a
41800 * bit. */
41801
41802diff -urNp linux-3.0.4/fs/ocfs2/ocfs2.h linux-3.0.4/fs/ocfs2/ocfs2.h
41803--- linux-3.0.4/fs/ocfs2/ocfs2.h 2011-07-21 22:17:23.000000000 -0400
41804+++ linux-3.0.4/fs/ocfs2/ocfs2.h 2011-08-23 21:47:56.000000000 -0400
41805@@ -235,11 +235,11 @@ enum ocfs2_vol_state
41806
41807 struct ocfs2_alloc_stats
41808 {
41809- atomic_t moves;
41810- atomic_t local_data;
41811- atomic_t bitmap_data;
41812- atomic_t bg_allocs;
41813- atomic_t bg_extends;
41814+ atomic_unchecked_t moves;
41815+ atomic_unchecked_t local_data;
41816+ atomic_unchecked_t bitmap_data;
41817+ atomic_unchecked_t bg_allocs;
41818+ atomic_unchecked_t bg_extends;
41819 };
41820
41821 enum ocfs2_local_alloc_state
41822diff -urNp linux-3.0.4/fs/ocfs2/suballoc.c linux-3.0.4/fs/ocfs2/suballoc.c
41823--- linux-3.0.4/fs/ocfs2/suballoc.c 2011-07-21 22:17:23.000000000 -0400
41824+++ linux-3.0.4/fs/ocfs2/suballoc.c 2011-08-23 21:47:56.000000000 -0400
41825@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(s
41826 mlog_errno(status);
41827 goto bail;
41828 }
41829- atomic_inc(&osb->alloc_stats.bg_extends);
41830+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
41831
41832 /* You should never ask for this much metadata */
41833 BUG_ON(bits_wanted >
41834@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handl
41835 mlog_errno(status);
41836 goto bail;
41837 }
41838- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
41839+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
41840
41841 *suballoc_loc = res.sr_bg_blkno;
41842 *suballoc_bit_start = res.sr_bit_offset;
41843@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_
41844 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
41845 res->sr_bits);
41846
41847- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
41848+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
41849
41850 BUG_ON(res->sr_bits != 1);
41851
41852@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *hand
41853 mlog_errno(status);
41854 goto bail;
41855 }
41856- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
41857+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
41858
41859 BUG_ON(res.sr_bits != 1);
41860
41861@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *han
41862 cluster_start,
41863 num_clusters);
41864 if (!status)
41865- atomic_inc(&osb->alloc_stats.local_data);
41866+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
41867 } else {
41868 if (min_clusters > (osb->bitmap_cpg - 1)) {
41869 /* The only paths asking for contiguousness
41870@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *han
41871 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
41872 res.sr_bg_blkno,
41873 res.sr_bit_offset);
41874- atomic_inc(&osb->alloc_stats.bitmap_data);
41875+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
41876 *num_clusters = res.sr_bits;
41877 }
41878 }
41879diff -urNp linux-3.0.4/fs/ocfs2/super.c linux-3.0.4/fs/ocfs2/super.c
41880--- linux-3.0.4/fs/ocfs2/super.c 2011-07-21 22:17:23.000000000 -0400
41881+++ linux-3.0.4/fs/ocfs2/super.c 2011-08-23 21:47:56.000000000 -0400
41882@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
41883 "%10s => GlobalAllocs: %d LocalAllocs: %d "
41884 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
41885 "Stats",
41886- atomic_read(&osb->alloc_stats.bitmap_data),
41887- atomic_read(&osb->alloc_stats.local_data),
41888- atomic_read(&osb->alloc_stats.bg_allocs),
41889- atomic_read(&osb->alloc_stats.moves),
41890- atomic_read(&osb->alloc_stats.bg_extends));
41891+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
41892+ atomic_read_unchecked(&osb->alloc_stats.local_data),
41893+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
41894+ atomic_read_unchecked(&osb->alloc_stats.moves),
41895+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
41896
41897 out += snprintf(buf + out, len - out,
41898 "%10s => State: %u Descriptor: %llu Size: %u bits "
41899@@ -2112,11 +2112,11 @@ static int ocfs2_initialize_super(struct
41900 spin_lock_init(&osb->osb_xattr_lock);
41901 ocfs2_init_steal_slots(osb);
41902
41903- atomic_set(&osb->alloc_stats.moves, 0);
41904- atomic_set(&osb->alloc_stats.local_data, 0);
41905- atomic_set(&osb->alloc_stats.bitmap_data, 0);
41906- atomic_set(&osb->alloc_stats.bg_allocs, 0);
41907- atomic_set(&osb->alloc_stats.bg_extends, 0);
41908+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
41909+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
41910+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
41911+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
41912+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
41913
41914 /* Copy the blockcheck stats from the superblock probe */
41915 osb->osb_ecc_stats = *stats;
41916diff -urNp linux-3.0.4/fs/ocfs2/symlink.c linux-3.0.4/fs/ocfs2/symlink.c
41917--- linux-3.0.4/fs/ocfs2/symlink.c 2011-07-21 22:17:23.000000000 -0400
41918+++ linux-3.0.4/fs/ocfs2/symlink.c 2011-08-23 21:47:56.000000000 -0400
41919@@ -142,7 +142,7 @@ bail:
41920
41921 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
41922 {
41923- char *link = nd_get_link(nd);
41924+ const char *link = nd_get_link(nd);
41925 if (!IS_ERR(link))
41926 kfree(link);
41927 }
41928diff -urNp linux-3.0.4/fs/open.c linux-3.0.4/fs/open.c
41929--- linux-3.0.4/fs/open.c 2011-07-21 22:17:23.000000000 -0400
41930+++ linux-3.0.4/fs/open.c 2011-08-23 21:48:14.000000000 -0400
41931@@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
41932 error = locks_verify_truncate(inode, NULL, length);
41933 if (!error)
41934 error = security_path_truncate(&path);
41935+
41936+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
41937+ error = -EACCES;
41938+
41939 if (!error)
41940 error = do_truncate(path.dentry, length, 0, NULL);
41941
41942@@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
41943 if (__mnt_is_readonly(path.mnt))
41944 res = -EROFS;
41945
41946+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
41947+ res = -EACCES;
41948+
41949 out_path_release:
41950 path_put(&path);
41951 out:
41952@@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user
41953 if (error)
41954 goto dput_and_out;
41955
41956+ gr_log_chdir(path.dentry, path.mnt);
41957+
41958 set_fs_pwd(current->fs, &path);
41959
41960 dput_and_out:
41961@@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
41962 goto out_putf;
41963
41964 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
41965+
41966+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
41967+ error = -EPERM;
41968+
41969+ if (!error)
41970+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
41971+
41972 if (!error)
41973 set_fs_pwd(current->fs, &file->f_path);
41974 out_putf:
41975@@ -438,7 +454,18 @@ SYSCALL_DEFINE1(chroot, const char __use
41976 if (error)
41977 goto dput_and_out;
41978
41979+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
41980+ goto dput_and_out;
41981+
41982+ if (gr_handle_chroot_caps(&path)) {
41983+ error = -ENOMEM;
41984+ goto dput_and_out;
41985+ }
41986+
41987 set_fs_root(current->fs, &path);
41988+
41989+ gr_handle_chroot_chdir(&path);
41990+
41991 error = 0;
41992 dput_and_out:
41993 path_put(&path);
41994@@ -466,12 +493,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
41995 err = mnt_want_write_file(file);
41996 if (err)
41997 goto out_putf;
41998+
41999 mutex_lock(&inode->i_mutex);
42000+
42001+ if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
42002+ err = -EACCES;
42003+ goto out_unlock;
42004+ }
42005+
42006 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
42007 if (err)
42008 goto out_unlock;
42009 if (mode == (mode_t) -1)
42010 mode = inode->i_mode;
42011+
42012+ if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
42013+ err = -EACCES;
42014+ goto out_unlock;
42015+ }
42016+
42017 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
42018 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
42019 err = notify_change(dentry, &newattrs);
42020@@ -499,12 +539,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
42021 error = mnt_want_write(path.mnt);
42022 if (error)
42023 goto dput_and_out;
42024+
42025 mutex_lock(&inode->i_mutex);
42026+
42027+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
42028+ error = -EACCES;
42029+ goto out_unlock;
42030+ }
42031+
42032 error = security_path_chmod(path.dentry, path.mnt, mode);
42033 if (error)
42034 goto out_unlock;
42035 if (mode == (mode_t) -1)
42036 mode = inode->i_mode;
42037+
42038+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
42039+ error = -EACCES;
42040+ goto out_unlock;
42041+ }
42042+
42043 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
42044 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
42045 error = notify_change(path.dentry, &newattrs);
42046@@ -528,6 +581,9 @@ static int chown_common(struct path *pat
42047 int error;
42048 struct iattr newattrs;
42049
42050+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
42051+ return -EACCES;
42052+
42053 newattrs.ia_valid = ATTR_CTIME;
42054 if (user != (uid_t) -1) {
42055 newattrs.ia_valid |= ATTR_UID;
42056@@ -998,7 +1054,10 @@ long do_sys_open(int dfd, const char __u
42057 if (!IS_ERR(tmp)) {
42058 fd = get_unused_fd_flags(flags);
42059 if (fd >= 0) {
42060- struct file *f = do_filp_open(dfd, tmp, &op, lookup);
42061+ struct file *f;
42062+ /* don't allow to be set by userland */
42063+ flags &= ~FMODE_GREXEC;
42064+ f = do_filp_open(dfd, tmp, &op, lookup);
42065 if (IS_ERR(f)) {
42066 put_unused_fd(fd);
42067 fd = PTR_ERR(f);
42068diff -urNp linux-3.0.4/fs/partitions/ldm.c linux-3.0.4/fs/partitions/ldm.c
42069--- linux-3.0.4/fs/partitions/ldm.c 2011-07-21 22:17:23.000000000 -0400
42070+++ linux-3.0.4/fs/partitions/ldm.c 2011-08-23 21:48:14.000000000 -0400
42071@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
42072 ldm_error ("A VBLK claims to have %d parts.", num);
42073 return false;
42074 }
42075+
42076 if (rec >= num) {
42077 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
42078 return false;
42079@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
42080 goto found;
42081 }
42082
42083- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
42084+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
42085 if (!f) {
42086 ldm_crit ("Out of memory.");
42087 return false;
42088diff -urNp linux-3.0.4/fs/pipe.c linux-3.0.4/fs/pipe.c
42089--- linux-3.0.4/fs/pipe.c 2011-07-21 22:17:23.000000000 -0400
42090+++ linux-3.0.4/fs/pipe.c 2011-08-23 21:48:14.000000000 -0400
42091@@ -420,9 +420,9 @@ redo:
42092 }
42093 if (bufs) /* More to do? */
42094 continue;
42095- if (!pipe->writers)
42096+ if (!atomic_read(&pipe->writers))
42097 break;
42098- if (!pipe->waiting_writers) {
42099+ if (!atomic_read(&pipe->waiting_writers)) {
42100 /* syscall merging: Usually we must not sleep
42101 * if O_NONBLOCK is set, or if we got some data.
42102 * But if a writer sleeps in kernel space, then
42103@@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
42104 mutex_lock(&inode->i_mutex);
42105 pipe = inode->i_pipe;
42106
42107- if (!pipe->readers) {
42108+ if (!atomic_read(&pipe->readers)) {
42109 send_sig(SIGPIPE, current, 0);
42110 ret = -EPIPE;
42111 goto out;
42112@@ -530,7 +530,7 @@ redo1:
42113 for (;;) {
42114 int bufs;
42115
42116- if (!pipe->readers) {
42117+ if (!atomic_read(&pipe->readers)) {
42118 send_sig(SIGPIPE, current, 0);
42119 if (!ret)
42120 ret = -EPIPE;
42121@@ -616,9 +616,9 @@ redo2:
42122 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
42123 do_wakeup = 0;
42124 }
42125- pipe->waiting_writers++;
42126+ atomic_inc(&pipe->waiting_writers);
42127 pipe_wait(pipe);
42128- pipe->waiting_writers--;
42129+ atomic_dec(&pipe->waiting_writers);
42130 }
42131 out:
42132 mutex_unlock(&inode->i_mutex);
42133@@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
42134 mask = 0;
42135 if (filp->f_mode & FMODE_READ) {
42136 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
42137- if (!pipe->writers && filp->f_version != pipe->w_counter)
42138+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
42139 mask |= POLLHUP;
42140 }
42141
42142@@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
42143 * Most Unices do not set POLLERR for FIFOs but on Linux they
42144 * behave exactly like pipes for poll().
42145 */
42146- if (!pipe->readers)
42147+ if (!atomic_read(&pipe->readers))
42148 mask |= POLLERR;
42149 }
42150
42151@@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
42152
42153 mutex_lock(&inode->i_mutex);
42154 pipe = inode->i_pipe;
42155- pipe->readers -= decr;
42156- pipe->writers -= decw;
42157+ atomic_sub(decr, &pipe->readers);
42158+ atomic_sub(decw, &pipe->writers);
42159
42160- if (!pipe->readers && !pipe->writers) {
42161+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
42162 free_pipe_info(inode);
42163 } else {
42164 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
42165@@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
42166
42167 if (inode->i_pipe) {
42168 ret = 0;
42169- inode->i_pipe->readers++;
42170+ atomic_inc(&inode->i_pipe->readers);
42171 }
42172
42173 mutex_unlock(&inode->i_mutex);
42174@@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
42175
42176 if (inode->i_pipe) {
42177 ret = 0;
42178- inode->i_pipe->writers++;
42179+ atomic_inc(&inode->i_pipe->writers);
42180 }
42181
42182 mutex_unlock(&inode->i_mutex);
42183@@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
42184 if (inode->i_pipe) {
42185 ret = 0;
42186 if (filp->f_mode & FMODE_READ)
42187- inode->i_pipe->readers++;
42188+ atomic_inc(&inode->i_pipe->readers);
42189 if (filp->f_mode & FMODE_WRITE)
42190- inode->i_pipe->writers++;
42191+ atomic_inc(&inode->i_pipe->writers);
42192 }
42193
42194 mutex_unlock(&inode->i_mutex);
42195@@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
42196 inode->i_pipe = NULL;
42197 }
42198
42199-static struct vfsmount *pipe_mnt __read_mostly;
42200+struct vfsmount *pipe_mnt __read_mostly;
42201
42202 /*
42203 * pipefs_dname() is called from d_path().
42204@@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
42205 goto fail_iput;
42206 inode->i_pipe = pipe;
42207
42208- pipe->readers = pipe->writers = 1;
42209+ atomic_set(&pipe->readers, 1);
42210+ atomic_set(&pipe->writers, 1);
42211 inode->i_fop = &rdwr_pipefifo_fops;
42212
42213 /*
42214diff -urNp linux-3.0.4/fs/proc/array.c linux-3.0.4/fs/proc/array.c
42215--- linux-3.0.4/fs/proc/array.c 2011-07-21 22:17:23.000000000 -0400
42216+++ linux-3.0.4/fs/proc/array.c 2011-08-23 21:48:14.000000000 -0400
42217@@ -60,6 +60,7 @@
42218 #include <linux/tty.h>
42219 #include <linux/string.h>
42220 #include <linux/mman.h>
42221+#include <linux/grsecurity.h>
42222 #include <linux/proc_fs.h>
42223 #include <linux/ioport.h>
42224 #include <linux/uaccess.h>
42225@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
42226 seq_putc(m, '\n');
42227 }
42228
42229+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42230+static inline void task_pax(struct seq_file *m, struct task_struct *p)
42231+{
42232+ if (p->mm)
42233+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
42234+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
42235+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
42236+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
42237+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
42238+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
42239+ else
42240+ seq_printf(m, "PaX:\t-----\n");
42241+}
42242+#endif
42243+
42244 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
42245 struct pid *pid, struct task_struct *task)
42246 {
42247@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
42248 task_cpus_allowed(m, task);
42249 cpuset_task_status_allowed(m, task);
42250 task_context_switch_counts(m, task);
42251+
42252+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42253+ task_pax(m, task);
42254+#endif
42255+
42256+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
42257+ task_grsec_rbac(m, task);
42258+#endif
42259+
42260 return 0;
42261 }
42262
42263+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42264+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
42265+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
42266+ _mm->pax_flags & MF_PAX_SEGMEXEC))
42267+#endif
42268+
42269 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
42270 struct pid *pid, struct task_struct *task, int whole)
42271 {
42272@@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
42273 cputime_t cutime, cstime, utime, stime;
42274 cputime_t cgtime, gtime;
42275 unsigned long rsslim = 0;
42276- char tcomm[sizeof(task->comm)];
42277+ char tcomm[sizeof(task->comm)] = { 0 };
42278 unsigned long flags;
42279
42280+ pax_track_stack();
42281+
42282 state = *get_task_state(task);
42283 vsize = eip = esp = 0;
42284 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
42285@@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
42286 gtime = task->gtime;
42287 }
42288
42289+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42290+ if (PAX_RAND_FLAGS(mm)) {
42291+ eip = 0;
42292+ esp = 0;
42293+ wchan = 0;
42294+ }
42295+#endif
42296+#ifdef CONFIG_GRKERNSEC_HIDESYM
42297+ wchan = 0;
42298+ eip =0;
42299+ esp =0;
42300+#endif
42301+
42302 /* scale priority and nice values from timeslices to -20..20 */
42303 /* to make it look like a "normal" Unix priority/nice value */
42304 priority = task_prio(task);
42305@@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
42306 vsize,
42307 mm ? get_mm_rss(mm) : 0,
42308 rsslim,
42309+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42310+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
42311+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
42312+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
42313+#else
42314 mm ? (permitted ? mm->start_code : 1) : 0,
42315 mm ? (permitted ? mm->end_code : 1) : 0,
42316 (permitted && mm) ? mm->start_stack : 0,
42317+#endif
42318 esp,
42319 eip,
42320 /* The signal information here is obsolete.
42321@@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
42322
42323 return 0;
42324 }
42325+
42326+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42327+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
42328+{
42329+ u32 curr_ip = 0;
42330+ unsigned long flags;
42331+
42332+ if (lock_task_sighand(task, &flags)) {
42333+ curr_ip = task->signal->curr_ip;
42334+ unlock_task_sighand(task, &flags);
42335+ }
42336+
42337+ return sprintf(buffer, "%pI4\n", &curr_ip);
42338+}
42339+#endif
42340diff -urNp linux-3.0.4/fs/proc/base.c linux-3.0.4/fs/proc/base.c
42341--- linux-3.0.4/fs/proc/base.c 2011-08-23 21:44:40.000000000 -0400
42342+++ linux-3.0.4/fs/proc/base.c 2011-08-23 21:48:14.000000000 -0400
42343@@ -107,6 +107,22 @@ struct pid_entry {
42344 union proc_op op;
42345 };
42346
42347+struct getdents_callback {
42348+ struct linux_dirent __user * current_dir;
42349+ struct linux_dirent __user * previous;
42350+ struct file * file;
42351+ int count;
42352+ int error;
42353+};
42354+
42355+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
42356+ loff_t offset, u64 ino, unsigned int d_type)
42357+{
42358+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
42359+ buf->error = -EINVAL;
42360+ return 0;
42361+}
42362+
42363 #define NOD(NAME, MODE, IOP, FOP, OP) { \
42364 .name = (NAME), \
42365 .len = sizeof(NAME) - 1, \
42366@@ -209,6 +225,9 @@ static struct mm_struct *__check_mem_per
42367 if (task == current)
42368 return mm;
42369
42370+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
42371+ return ERR_PTR(-EPERM);
42372+
42373 /*
42374 * If current is actively ptrace'ing, and would also be
42375 * permitted to freshly attach with ptrace now, permit it.
42376@@ -282,6 +301,9 @@ static int proc_pid_cmdline(struct task_
42377 if (!mm->arg_end)
42378 goto out_mm; /* Shh! No looking before we're done */
42379
42380+ if (gr_acl_handle_procpidmem(task))
42381+ goto out_mm;
42382+
42383 len = mm->arg_end - mm->arg_start;
42384
42385 if (len > PAGE_SIZE)
42386@@ -309,12 +331,28 @@ out:
42387 return res;
42388 }
42389
42390+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42391+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
42392+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
42393+ _mm->pax_flags & MF_PAX_SEGMEXEC))
42394+#endif
42395+
42396 static int proc_pid_auxv(struct task_struct *task, char *buffer)
42397 {
42398 struct mm_struct *mm = mm_for_maps(task);
42399 int res = PTR_ERR(mm);
42400 if (mm && !IS_ERR(mm)) {
42401 unsigned int nwords = 0;
42402+
42403+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42404+ /* allow if we're currently ptracing this task */
42405+ if (PAX_RAND_FLAGS(mm) &&
42406+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
42407+ mmput(mm);
42408+ return res;
42409+ }
42410+#endif
42411+
42412 do {
42413 nwords += 2;
42414 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
42415@@ -328,7 +366,7 @@ static int proc_pid_auxv(struct task_str
42416 }
42417
42418
42419-#ifdef CONFIG_KALLSYMS
42420+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42421 /*
42422 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
42423 * Returns the resolved symbol. If that fails, simply return the address.
42424@@ -367,7 +405,7 @@ static void unlock_trace(struct task_str
42425 mutex_unlock(&task->signal->cred_guard_mutex);
42426 }
42427
42428-#ifdef CONFIG_STACKTRACE
42429+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42430
42431 #define MAX_STACK_TRACE_DEPTH 64
42432
42433@@ -558,7 +596,7 @@ static int proc_pid_limits(struct task_s
42434 return count;
42435 }
42436
42437-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42438+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42439 static int proc_pid_syscall(struct task_struct *task, char *buffer)
42440 {
42441 long nr;
42442@@ -587,7 +625,7 @@ static int proc_pid_syscall(struct task_
42443 /************************************************************************/
42444
42445 /* permission checks */
42446-static int proc_fd_access_allowed(struct inode *inode)
42447+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
42448 {
42449 struct task_struct *task;
42450 int allowed = 0;
42451@@ -597,7 +635,10 @@ static int proc_fd_access_allowed(struct
42452 */
42453 task = get_proc_task(inode);
42454 if (task) {
42455- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
42456+ if (log)
42457+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
42458+ else
42459+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
42460 put_task_struct(task);
42461 }
42462 return allowed;
42463@@ -978,6 +1019,9 @@ static ssize_t environ_read(struct file
42464 if (!task)
42465 goto out_no_task;
42466
42467+ if (gr_acl_handle_procpidmem(task))
42468+ goto out;
42469+
42470 ret = -ENOMEM;
42471 page = (char *)__get_free_page(GFP_TEMPORARY);
42472 if (!page)
42473@@ -1614,7 +1658,7 @@ static void *proc_pid_follow_link(struct
42474 path_put(&nd->path);
42475
42476 /* Are we allowed to snoop on the tasks file descriptors? */
42477- if (!proc_fd_access_allowed(inode))
42478+ if (!proc_fd_access_allowed(inode,0))
42479 goto out;
42480
42481 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
42482@@ -1653,8 +1697,18 @@ static int proc_pid_readlink(struct dent
42483 struct path path;
42484
42485 /* Are we allowed to snoop on the tasks file descriptors? */
42486- if (!proc_fd_access_allowed(inode))
42487- goto out;
42488+ /* logging this is needed for learning on chromium to work properly,
42489+ but we don't want to flood the logs from 'ps' which does a readlink
42490+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
42491+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
42492+ */
42493+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
42494+ if (!proc_fd_access_allowed(inode,0))
42495+ goto out;
42496+ } else {
42497+ if (!proc_fd_access_allowed(inode,1))
42498+ goto out;
42499+ }
42500
42501 error = PROC_I(inode)->op.proc_get_link(inode, &path);
42502 if (error)
42503@@ -1719,7 +1773,11 @@ struct inode *proc_pid_make_inode(struct
42504 rcu_read_lock();
42505 cred = __task_cred(task);
42506 inode->i_uid = cred->euid;
42507+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42508+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42509+#else
42510 inode->i_gid = cred->egid;
42511+#endif
42512 rcu_read_unlock();
42513 }
42514 security_task_to_inode(task, inode);
42515@@ -1737,6 +1795,9 @@ int pid_getattr(struct vfsmount *mnt, st
42516 struct inode *inode = dentry->d_inode;
42517 struct task_struct *task;
42518 const struct cred *cred;
42519+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42520+ const struct cred *tmpcred = current_cred();
42521+#endif
42522
42523 generic_fillattr(inode, stat);
42524
42525@@ -1744,13 +1805,41 @@ int pid_getattr(struct vfsmount *mnt, st
42526 stat->uid = 0;
42527 stat->gid = 0;
42528 task = pid_task(proc_pid(inode), PIDTYPE_PID);
42529+
42530+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
42531+ rcu_read_unlock();
42532+ return -ENOENT;
42533+ }
42534+
42535 if (task) {
42536+ cred = __task_cred(task);
42537+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42538+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
42539+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42540+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
42541+#endif
42542+ ) {
42543+#endif
42544 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
42545+#ifdef CONFIG_GRKERNSEC_PROC_USER
42546+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
42547+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42548+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
42549+#endif
42550 task_dumpable(task)) {
42551- cred = __task_cred(task);
42552 stat->uid = cred->euid;
42553+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42554+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
42555+#else
42556 stat->gid = cred->egid;
42557+#endif
42558 }
42559+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42560+ } else {
42561+ rcu_read_unlock();
42562+ return -ENOENT;
42563+ }
42564+#endif
42565 }
42566 rcu_read_unlock();
42567 return 0;
42568@@ -1787,11 +1876,20 @@ int pid_revalidate(struct dentry *dentry
42569
42570 if (task) {
42571 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
42572+#ifdef CONFIG_GRKERNSEC_PROC_USER
42573+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
42574+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42575+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
42576+#endif
42577 task_dumpable(task)) {
42578 rcu_read_lock();
42579 cred = __task_cred(task);
42580 inode->i_uid = cred->euid;
42581+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42582+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42583+#else
42584 inode->i_gid = cred->egid;
42585+#endif
42586 rcu_read_unlock();
42587 } else {
42588 inode->i_uid = 0;
42589@@ -1909,7 +2007,8 @@ static int proc_fd_info(struct inode *in
42590 int fd = proc_fd(inode);
42591
42592 if (task) {
42593- files = get_files_struct(task);
42594+ if (!gr_acl_handle_procpidmem(task))
42595+ files = get_files_struct(task);
42596 put_task_struct(task);
42597 }
42598 if (files) {
42599@@ -2169,11 +2268,21 @@ static const struct file_operations proc
42600 */
42601 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
42602 {
42603+ struct task_struct *task;
42604 int rv = generic_permission(inode, mask, flags, NULL);
42605- if (rv == 0)
42606- return 0;
42607+
42608 if (task_pid(current) == proc_pid(inode))
42609 rv = 0;
42610+
42611+ task = get_proc_task(inode);
42612+ if (task == NULL)
42613+ return rv;
42614+
42615+ if (gr_acl_handle_procpidmem(task))
42616+ rv = -EACCES;
42617+
42618+ put_task_struct(task);
42619+
42620 return rv;
42621 }
42622
42623@@ -2283,6 +2392,9 @@ static struct dentry *proc_pident_lookup
42624 if (!task)
42625 goto out_no_task;
42626
42627+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42628+ goto out;
42629+
42630 /*
42631 * Yes, it does not scale. And it should not. Don't add
42632 * new entries into /proc/<tgid>/ without very good reasons.
42633@@ -2327,6 +2439,9 @@ static int proc_pident_readdir(struct fi
42634 if (!task)
42635 goto out_no_task;
42636
42637+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42638+ goto out;
42639+
42640 ret = 0;
42641 i = filp->f_pos;
42642 switch (i) {
42643@@ -2597,7 +2712,7 @@ static void *proc_self_follow_link(struc
42644 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
42645 void *cookie)
42646 {
42647- char *s = nd_get_link(nd);
42648+ const char *s = nd_get_link(nd);
42649 if (!IS_ERR(s))
42650 __putname(s);
42651 }
42652@@ -2795,7 +2910,7 @@ static const struct pid_entry tgid_base_
42653 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
42654 #endif
42655 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
42656-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42657+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42658 INF("syscall", S_IRUGO, proc_pid_syscall),
42659 #endif
42660 INF("cmdline", S_IRUGO, proc_pid_cmdline),
42661@@ -2820,10 +2935,10 @@ static const struct pid_entry tgid_base_
42662 #ifdef CONFIG_SECURITY
42663 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
42664 #endif
42665-#ifdef CONFIG_KALLSYMS
42666+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42667 INF("wchan", S_IRUGO, proc_pid_wchan),
42668 #endif
42669-#ifdef CONFIG_STACKTRACE
42670+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42671 ONE("stack", S_IRUGO, proc_pid_stack),
42672 #endif
42673 #ifdef CONFIG_SCHEDSTATS
42674@@ -2857,6 +2972,9 @@ static const struct pid_entry tgid_base_
42675 #ifdef CONFIG_HARDWALL
42676 INF("hardwall", S_IRUGO, proc_pid_hardwall),
42677 #endif
42678+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42679+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
42680+#endif
42681 };
42682
42683 static int proc_tgid_base_readdir(struct file * filp,
42684@@ -2982,7 +3100,14 @@ static struct dentry *proc_pid_instantia
42685 if (!inode)
42686 goto out;
42687
42688+#ifdef CONFIG_GRKERNSEC_PROC_USER
42689+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
42690+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42691+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42692+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
42693+#else
42694 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
42695+#endif
42696 inode->i_op = &proc_tgid_base_inode_operations;
42697 inode->i_fop = &proc_tgid_base_operations;
42698 inode->i_flags|=S_IMMUTABLE;
42699@@ -3024,7 +3149,11 @@ struct dentry *proc_pid_lookup(struct in
42700 if (!task)
42701 goto out;
42702
42703+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42704+ goto out_put_task;
42705+
42706 result = proc_pid_instantiate(dir, dentry, task, NULL);
42707+out_put_task:
42708 put_task_struct(task);
42709 out:
42710 return result;
42711@@ -3089,6 +3218,11 @@ int proc_pid_readdir(struct file * filp,
42712 {
42713 unsigned int nr;
42714 struct task_struct *reaper;
42715+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42716+ const struct cred *tmpcred = current_cred();
42717+ const struct cred *itercred;
42718+#endif
42719+ filldir_t __filldir = filldir;
42720 struct tgid_iter iter;
42721 struct pid_namespace *ns;
42722
42723@@ -3112,8 +3246,27 @@ int proc_pid_readdir(struct file * filp,
42724 for (iter = next_tgid(ns, iter);
42725 iter.task;
42726 iter.tgid += 1, iter = next_tgid(ns, iter)) {
42727+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42728+ rcu_read_lock();
42729+ itercred = __task_cred(iter.task);
42730+#endif
42731+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
42732+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42733+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
42734+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42735+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
42736+#endif
42737+ )
42738+#endif
42739+ )
42740+ __filldir = &gr_fake_filldir;
42741+ else
42742+ __filldir = filldir;
42743+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42744+ rcu_read_unlock();
42745+#endif
42746 filp->f_pos = iter.tgid + TGID_OFFSET;
42747- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
42748+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
42749 put_task_struct(iter.task);
42750 goto out;
42751 }
42752@@ -3141,7 +3294,7 @@ static const struct pid_entry tid_base_s
42753 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
42754 #endif
42755 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
42756-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42757+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42758 INF("syscall", S_IRUGO, proc_pid_syscall),
42759 #endif
42760 INF("cmdline", S_IRUGO, proc_pid_cmdline),
42761@@ -3165,10 +3318,10 @@ static const struct pid_entry tid_base_s
42762 #ifdef CONFIG_SECURITY
42763 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
42764 #endif
42765-#ifdef CONFIG_KALLSYMS
42766+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42767 INF("wchan", S_IRUGO, proc_pid_wchan),
42768 #endif
42769-#ifdef CONFIG_STACKTRACE
42770+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42771 ONE("stack", S_IRUGO, proc_pid_stack),
42772 #endif
42773 #ifdef CONFIG_SCHEDSTATS
42774diff -urNp linux-3.0.4/fs/proc/cmdline.c linux-3.0.4/fs/proc/cmdline.c
42775--- linux-3.0.4/fs/proc/cmdline.c 2011-07-21 22:17:23.000000000 -0400
42776+++ linux-3.0.4/fs/proc/cmdline.c 2011-08-23 21:48:14.000000000 -0400
42777@@ -23,7 +23,11 @@ static const struct file_operations cmdl
42778
42779 static int __init proc_cmdline_init(void)
42780 {
42781+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42782+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
42783+#else
42784 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
42785+#endif
42786 return 0;
42787 }
42788 module_init(proc_cmdline_init);
42789diff -urNp linux-3.0.4/fs/proc/devices.c linux-3.0.4/fs/proc/devices.c
42790--- linux-3.0.4/fs/proc/devices.c 2011-07-21 22:17:23.000000000 -0400
42791+++ linux-3.0.4/fs/proc/devices.c 2011-08-23 21:48:14.000000000 -0400
42792@@ -64,7 +64,11 @@ static const struct file_operations proc
42793
42794 static int __init proc_devices_init(void)
42795 {
42796+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42797+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
42798+#else
42799 proc_create("devices", 0, NULL, &proc_devinfo_operations);
42800+#endif
42801 return 0;
42802 }
42803 module_init(proc_devices_init);
42804diff -urNp linux-3.0.4/fs/proc/inode.c linux-3.0.4/fs/proc/inode.c
42805--- linux-3.0.4/fs/proc/inode.c 2011-07-21 22:17:23.000000000 -0400
42806+++ linux-3.0.4/fs/proc/inode.c 2011-08-23 21:48:14.000000000 -0400
42807@@ -440,7 +440,11 @@ struct inode *proc_get_inode(struct supe
42808 if (de->mode) {
42809 inode->i_mode = de->mode;
42810 inode->i_uid = de->uid;
42811+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42812+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42813+#else
42814 inode->i_gid = de->gid;
42815+#endif
42816 }
42817 if (de->size)
42818 inode->i_size = de->size;
42819diff -urNp linux-3.0.4/fs/proc/internal.h linux-3.0.4/fs/proc/internal.h
42820--- linux-3.0.4/fs/proc/internal.h 2011-07-21 22:17:23.000000000 -0400
42821+++ linux-3.0.4/fs/proc/internal.h 2011-08-23 21:48:14.000000000 -0400
42822@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
42823 struct pid *pid, struct task_struct *task);
42824 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
42825 struct pid *pid, struct task_struct *task);
42826+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42827+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
42828+#endif
42829 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
42830
42831 extern const struct file_operations proc_maps_operations;
42832diff -urNp linux-3.0.4/fs/proc/Kconfig linux-3.0.4/fs/proc/Kconfig
42833--- linux-3.0.4/fs/proc/Kconfig 2011-07-21 22:17:23.000000000 -0400
42834+++ linux-3.0.4/fs/proc/Kconfig 2011-08-23 21:48:14.000000000 -0400
42835@@ -30,12 +30,12 @@ config PROC_FS
42836
42837 config PROC_KCORE
42838 bool "/proc/kcore support" if !ARM
42839- depends on PROC_FS && MMU
42840+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
42841
42842 config PROC_VMCORE
42843 bool "/proc/vmcore support"
42844- depends on PROC_FS && CRASH_DUMP
42845- default y
42846+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
42847+ default n
42848 help
42849 Exports the dump image of crashed kernel in ELF format.
42850
42851@@ -59,8 +59,8 @@ config PROC_SYSCTL
42852 limited in memory.
42853
42854 config PROC_PAGE_MONITOR
42855- default y
42856- depends on PROC_FS && MMU
42857+ default n
42858+ depends on PROC_FS && MMU && !GRKERNSEC
42859 bool "Enable /proc page monitoring" if EXPERT
42860 help
42861 Various /proc files exist to monitor process memory utilization:
42862diff -urNp linux-3.0.4/fs/proc/kcore.c linux-3.0.4/fs/proc/kcore.c
42863--- linux-3.0.4/fs/proc/kcore.c 2011-07-21 22:17:23.000000000 -0400
42864+++ linux-3.0.4/fs/proc/kcore.c 2011-08-23 21:48:14.000000000 -0400
42865@@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
42866 off_t offset = 0;
42867 struct kcore_list *m;
42868
42869+ pax_track_stack();
42870+
42871 /* setup ELF header */
42872 elf = (struct elfhdr *) bufp;
42873 bufp += sizeof(struct elfhdr);
42874@@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
42875 * the addresses in the elf_phdr on our list.
42876 */
42877 start = kc_offset_to_vaddr(*fpos - elf_buflen);
42878- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
42879+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
42880+ if (tsz > buflen)
42881 tsz = buflen;
42882-
42883+
42884 while (buflen) {
42885 struct kcore_list *m;
42886
42887@@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
42888 kfree(elf_buf);
42889 } else {
42890 if (kern_addr_valid(start)) {
42891- unsigned long n;
42892+ char *elf_buf;
42893+ mm_segment_t oldfs;
42894
42895- n = copy_to_user(buffer, (char *)start, tsz);
42896- /*
42897- * We cannot distingush between fault on source
42898- * and fault on destination. When this happens
42899- * we clear too and hope it will trigger the
42900- * EFAULT again.
42901- */
42902- if (n) {
42903- if (clear_user(buffer + tsz - n,
42904- n))
42905+ elf_buf = kmalloc(tsz, GFP_KERNEL);
42906+ if (!elf_buf)
42907+ return -ENOMEM;
42908+ oldfs = get_fs();
42909+ set_fs(KERNEL_DS);
42910+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
42911+ set_fs(oldfs);
42912+ if (copy_to_user(buffer, elf_buf, tsz)) {
42913+ kfree(elf_buf);
42914 return -EFAULT;
42915+ }
42916 }
42917+ set_fs(oldfs);
42918+ kfree(elf_buf);
42919 } else {
42920 if (clear_user(buffer, tsz))
42921 return -EFAULT;
42922@@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
42923
42924 static int open_kcore(struct inode *inode, struct file *filp)
42925 {
42926+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
42927+ return -EPERM;
42928+#endif
42929 if (!capable(CAP_SYS_RAWIO))
42930 return -EPERM;
42931 if (kcore_need_update)
42932diff -urNp linux-3.0.4/fs/proc/meminfo.c linux-3.0.4/fs/proc/meminfo.c
42933--- linux-3.0.4/fs/proc/meminfo.c 2011-07-21 22:17:23.000000000 -0400
42934+++ linux-3.0.4/fs/proc/meminfo.c 2011-08-23 21:48:14.000000000 -0400
42935@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
42936 unsigned long pages[NR_LRU_LISTS];
42937 int lru;
42938
42939+ pax_track_stack();
42940+
42941 /*
42942 * display in kilobytes.
42943 */
42944@@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
42945 vmi.used >> 10,
42946 vmi.largest_chunk >> 10
42947 #ifdef CONFIG_MEMORY_FAILURE
42948- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
42949+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
42950 #endif
42951 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
42952 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
42953diff -urNp linux-3.0.4/fs/proc/nommu.c linux-3.0.4/fs/proc/nommu.c
42954--- linux-3.0.4/fs/proc/nommu.c 2011-07-21 22:17:23.000000000 -0400
42955+++ linux-3.0.4/fs/proc/nommu.c 2011-08-23 21:47:56.000000000 -0400
42956@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
42957 if (len < 1)
42958 len = 1;
42959 seq_printf(m, "%*c", len, ' ');
42960- seq_path(m, &file->f_path, "");
42961+ seq_path(m, &file->f_path, "\n\\");
42962 }
42963
42964 seq_putc(m, '\n');
42965diff -urNp linux-3.0.4/fs/proc/proc_net.c linux-3.0.4/fs/proc/proc_net.c
42966--- linux-3.0.4/fs/proc/proc_net.c 2011-07-21 22:17:23.000000000 -0400
42967+++ linux-3.0.4/fs/proc/proc_net.c 2011-08-23 21:48:14.000000000 -0400
42968@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
42969 struct task_struct *task;
42970 struct nsproxy *ns;
42971 struct net *net = NULL;
42972+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42973+ const struct cred *cred = current_cred();
42974+#endif
42975+
42976+#ifdef CONFIG_GRKERNSEC_PROC_USER
42977+ if (cred->fsuid)
42978+ return net;
42979+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42980+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
42981+ return net;
42982+#endif
42983
42984 rcu_read_lock();
42985 task = pid_task(proc_pid(dir), PIDTYPE_PID);
42986diff -urNp linux-3.0.4/fs/proc/proc_sysctl.c linux-3.0.4/fs/proc/proc_sysctl.c
42987--- linux-3.0.4/fs/proc/proc_sysctl.c 2011-07-21 22:17:23.000000000 -0400
42988+++ linux-3.0.4/fs/proc/proc_sysctl.c 2011-08-23 21:48:14.000000000 -0400
42989@@ -8,6 +8,8 @@
42990 #include <linux/namei.h>
42991 #include "internal.h"
42992
42993+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
42994+
42995 static const struct dentry_operations proc_sys_dentry_operations;
42996 static const struct file_operations proc_sys_file_operations;
42997 static const struct inode_operations proc_sys_inode_operations;
42998@@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
42999 if (!p)
43000 goto out;
43001
43002+ if (gr_handle_sysctl(p, MAY_EXEC))
43003+ goto out;
43004+
43005 err = ERR_PTR(-ENOMEM);
43006 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
43007 if (h)
43008@@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
43009 if (*pos < file->f_pos)
43010 continue;
43011
43012+ if (gr_handle_sysctl(table, 0))
43013+ continue;
43014+
43015 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
43016 if (res)
43017 return res;
43018@@ -355,6 +363,9 @@ static int proc_sys_getattr(struct vfsmo
43019 if (IS_ERR(head))
43020 return PTR_ERR(head);
43021
43022+ if (table && gr_handle_sysctl(table, MAY_EXEC))
43023+ return -ENOENT;
43024+
43025 generic_fillattr(inode, stat);
43026 if (table)
43027 stat->mode = (stat->mode & S_IFMT) | table->mode;
43028diff -urNp linux-3.0.4/fs/proc/root.c linux-3.0.4/fs/proc/root.c
43029--- linux-3.0.4/fs/proc/root.c 2011-07-21 22:17:23.000000000 -0400
43030+++ linux-3.0.4/fs/proc/root.c 2011-08-23 21:48:14.000000000 -0400
43031@@ -123,7 +123,15 @@ void __init proc_root_init(void)
43032 #ifdef CONFIG_PROC_DEVICETREE
43033 proc_device_tree_init();
43034 #endif
43035+#ifdef CONFIG_GRKERNSEC_PROC_ADD
43036+#ifdef CONFIG_GRKERNSEC_PROC_USER
43037+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
43038+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
43039+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
43040+#endif
43041+#else
43042 proc_mkdir("bus", NULL);
43043+#endif
43044 proc_sys_init();
43045 }
43046
43047diff -urNp linux-3.0.4/fs/proc/task_mmu.c linux-3.0.4/fs/proc/task_mmu.c
43048--- linux-3.0.4/fs/proc/task_mmu.c 2011-07-21 22:17:23.000000000 -0400
43049+++ linux-3.0.4/fs/proc/task_mmu.c 2011-08-23 21:48:14.000000000 -0400
43050@@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
43051 "VmExe:\t%8lu kB\n"
43052 "VmLib:\t%8lu kB\n"
43053 "VmPTE:\t%8lu kB\n"
43054- "VmSwap:\t%8lu kB\n",
43055- hiwater_vm << (PAGE_SHIFT-10),
43056+ "VmSwap:\t%8lu kB\n"
43057+
43058+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43059+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
43060+#endif
43061+
43062+ ,hiwater_vm << (PAGE_SHIFT-10),
43063 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
43064 mm->locked_vm << (PAGE_SHIFT-10),
43065 hiwater_rss << (PAGE_SHIFT-10),
43066@@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
43067 data << (PAGE_SHIFT-10),
43068 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
43069 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
43070- swap << (PAGE_SHIFT-10));
43071+ swap << (PAGE_SHIFT-10)
43072+
43073+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43074+ , mm->context.user_cs_base, mm->context.user_cs_limit
43075+#endif
43076+
43077+ );
43078 }
43079
43080 unsigned long task_vsize(struct mm_struct *mm)
43081@@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
43082 return ret;
43083 }
43084
43085+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43086+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
43087+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
43088+ _mm->pax_flags & MF_PAX_SEGMEXEC))
43089+#endif
43090+
43091 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
43092 {
43093 struct mm_struct *mm = vma->vm_mm;
43094@@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
43095 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
43096 }
43097
43098- /* We don't show the stack guard page in /proc/maps */
43099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43100+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
43101+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
43102+#else
43103 start = vma->vm_start;
43104- if (stack_guard_page_start(vma, start))
43105- start += PAGE_SIZE;
43106 end = vma->vm_end;
43107- if (stack_guard_page_end(vma, end))
43108- end -= PAGE_SIZE;
43109+#endif
43110
43111 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
43112 start,
43113@@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
43114 flags & VM_WRITE ? 'w' : '-',
43115 flags & VM_EXEC ? 'x' : '-',
43116 flags & VM_MAYSHARE ? 's' : 'p',
43117+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43118+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
43119+#else
43120 pgoff,
43121+#endif
43122 MAJOR(dev), MINOR(dev), ino, &len);
43123
43124 /*
43125@@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
43126 */
43127 if (file) {
43128 pad_len_spaces(m, len);
43129- seq_path(m, &file->f_path, "\n");
43130+ seq_path(m, &file->f_path, "\n\\");
43131 } else {
43132 const char *name = arch_vma_name(vma);
43133 if (!name) {
43134@@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
43135 if (vma->vm_start <= mm->brk &&
43136 vma->vm_end >= mm->start_brk) {
43137 name = "[heap]";
43138- } else if (vma->vm_start <= mm->start_stack &&
43139- vma->vm_end >= mm->start_stack) {
43140+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
43141+ (vma->vm_start <= mm->start_stack &&
43142+ vma->vm_end >= mm->start_stack)) {
43143 name = "[stack]";
43144 }
43145 } else {
43146@@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
43147 };
43148
43149 memset(&mss, 0, sizeof mss);
43150- mss.vma = vma;
43151- /* mmap_sem is held in m_start */
43152- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
43153- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
43154-
43155+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43156+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
43157+#endif
43158+ mss.vma = vma;
43159+ /* mmap_sem is held in m_start */
43160+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
43161+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
43162+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43163+ }
43164+#endif
43165 show_map_vma(m, vma);
43166
43167 seq_printf(m,
43168@@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
43169 "KernelPageSize: %8lu kB\n"
43170 "MMUPageSize: %8lu kB\n"
43171 "Locked: %8lu kB\n",
43172+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43173+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
43174+#else
43175 (vma->vm_end - vma->vm_start) >> 10,
43176+#endif
43177 mss.resident >> 10,
43178 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
43179 mss.shared_clean >> 10,
43180@@ -1001,7 +1032,7 @@ static int show_numa_map(struct seq_file
43181
43182 if (file) {
43183 seq_printf(m, " file=");
43184- seq_path(m, &file->f_path, "\n\t= ");
43185+ seq_path(m, &file->f_path, "\n\t\\= ");
43186 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
43187 seq_printf(m, " heap");
43188 } else if (vma->vm_start <= mm->start_stack &&
43189diff -urNp linux-3.0.4/fs/proc/task_nommu.c linux-3.0.4/fs/proc/task_nommu.c
43190--- linux-3.0.4/fs/proc/task_nommu.c 2011-07-21 22:17:23.000000000 -0400
43191+++ linux-3.0.4/fs/proc/task_nommu.c 2011-08-23 21:47:56.000000000 -0400
43192@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
43193 else
43194 bytes += kobjsize(mm);
43195
43196- if (current->fs && current->fs->users > 1)
43197+ if (current->fs && atomic_read(&current->fs->users) > 1)
43198 sbytes += kobjsize(current->fs);
43199 else
43200 bytes += kobjsize(current->fs);
43201@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
43202
43203 if (file) {
43204 pad_len_spaces(m, len);
43205- seq_path(m, &file->f_path, "");
43206+ seq_path(m, &file->f_path, "\n\\");
43207 } else if (mm) {
43208 if (vma->vm_start <= mm->start_stack &&
43209 vma->vm_end >= mm->start_stack) {
43210diff -urNp linux-3.0.4/fs/quota/netlink.c linux-3.0.4/fs/quota/netlink.c
43211--- linux-3.0.4/fs/quota/netlink.c 2011-07-21 22:17:23.000000000 -0400
43212+++ linux-3.0.4/fs/quota/netlink.c 2011-08-23 21:47:56.000000000 -0400
43213@@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
43214 void quota_send_warning(short type, unsigned int id, dev_t dev,
43215 const char warntype)
43216 {
43217- static atomic_t seq;
43218+ static atomic_unchecked_t seq;
43219 struct sk_buff *skb;
43220 void *msg_head;
43221 int ret;
43222@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
43223 "VFS: Not enough memory to send quota warning.\n");
43224 return;
43225 }
43226- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
43227+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
43228 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
43229 if (!msg_head) {
43230 printk(KERN_ERR
43231diff -urNp linux-3.0.4/fs/readdir.c linux-3.0.4/fs/readdir.c
43232--- linux-3.0.4/fs/readdir.c 2011-07-21 22:17:23.000000000 -0400
43233+++ linux-3.0.4/fs/readdir.c 2011-08-23 21:48:14.000000000 -0400
43234@@ -17,6 +17,7 @@
43235 #include <linux/security.h>
43236 #include <linux/syscalls.h>
43237 #include <linux/unistd.h>
43238+#include <linux/namei.h>
43239
43240 #include <asm/uaccess.h>
43241
43242@@ -67,6 +68,7 @@ struct old_linux_dirent {
43243
43244 struct readdir_callback {
43245 struct old_linux_dirent __user * dirent;
43246+ struct file * file;
43247 int result;
43248 };
43249
43250@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
43251 buf->result = -EOVERFLOW;
43252 return -EOVERFLOW;
43253 }
43254+
43255+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43256+ return 0;
43257+
43258 buf->result++;
43259 dirent = buf->dirent;
43260 if (!access_ok(VERIFY_WRITE, dirent,
43261@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
43262
43263 buf.result = 0;
43264 buf.dirent = dirent;
43265+ buf.file = file;
43266
43267 error = vfs_readdir(file, fillonedir, &buf);
43268 if (buf.result)
43269@@ -142,6 +149,7 @@ struct linux_dirent {
43270 struct getdents_callback {
43271 struct linux_dirent __user * current_dir;
43272 struct linux_dirent __user * previous;
43273+ struct file * file;
43274 int count;
43275 int error;
43276 };
43277@@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
43278 buf->error = -EOVERFLOW;
43279 return -EOVERFLOW;
43280 }
43281+
43282+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43283+ return 0;
43284+
43285 dirent = buf->previous;
43286 if (dirent) {
43287 if (__put_user(offset, &dirent->d_off))
43288@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
43289 buf.previous = NULL;
43290 buf.count = count;
43291 buf.error = 0;
43292+ buf.file = file;
43293
43294 error = vfs_readdir(file, filldir, &buf);
43295 if (error >= 0)
43296@@ -229,6 +242,7 @@ out:
43297 struct getdents_callback64 {
43298 struct linux_dirent64 __user * current_dir;
43299 struct linux_dirent64 __user * previous;
43300+ struct file *file;
43301 int count;
43302 int error;
43303 };
43304@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
43305 buf->error = -EINVAL; /* only used if we fail.. */
43306 if (reclen > buf->count)
43307 return -EINVAL;
43308+
43309+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43310+ return 0;
43311+
43312 dirent = buf->previous;
43313 if (dirent) {
43314 if (__put_user(offset, &dirent->d_off))
43315@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
43316
43317 buf.current_dir = dirent;
43318 buf.previous = NULL;
43319+ buf.file = file;
43320 buf.count = count;
43321 buf.error = 0;
43322
43323diff -urNp linux-3.0.4/fs/reiserfs/dir.c linux-3.0.4/fs/reiserfs/dir.c
43324--- linux-3.0.4/fs/reiserfs/dir.c 2011-07-21 22:17:23.000000000 -0400
43325+++ linux-3.0.4/fs/reiserfs/dir.c 2011-08-23 21:48:14.000000000 -0400
43326@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
43327 struct reiserfs_dir_entry de;
43328 int ret = 0;
43329
43330+ pax_track_stack();
43331+
43332 reiserfs_write_lock(inode->i_sb);
43333
43334 reiserfs_check_lock_depth(inode->i_sb, "readdir");
43335diff -urNp linux-3.0.4/fs/reiserfs/do_balan.c linux-3.0.4/fs/reiserfs/do_balan.c
43336--- linux-3.0.4/fs/reiserfs/do_balan.c 2011-07-21 22:17:23.000000000 -0400
43337+++ linux-3.0.4/fs/reiserfs/do_balan.c 2011-08-23 21:47:56.000000000 -0400
43338@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
43339 return;
43340 }
43341
43342- atomic_inc(&(fs_generation(tb->tb_sb)));
43343+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
43344 do_balance_starts(tb);
43345
43346 /* balance leaf returns 0 except if combining L R and S into
43347diff -urNp linux-3.0.4/fs/reiserfs/journal.c linux-3.0.4/fs/reiserfs/journal.c
43348--- linux-3.0.4/fs/reiserfs/journal.c 2011-07-21 22:17:23.000000000 -0400
43349+++ linux-3.0.4/fs/reiserfs/journal.c 2011-08-23 21:48:14.000000000 -0400
43350@@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
43351 struct buffer_head *bh;
43352 int i, j;
43353
43354+ pax_track_stack();
43355+
43356 bh = __getblk(dev, block, bufsize);
43357 if (buffer_uptodate(bh))
43358 return (bh);
43359diff -urNp linux-3.0.4/fs/reiserfs/namei.c linux-3.0.4/fs/reiserfs/namei.c
43360--- linux-3.0.4/fs/reiserfs/namei.c 2011-07-21 22:17:23.000000000 -0400
43361+++ linux-3.0.4/fs/reiserfs/namei.c 2011-08-23 21:48:14.000000000 -0400
43362@@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
43363 unsigned long savelink = 1;
43364 struct timespec ctime;
43365
43366+ pax_track_stack();
43367+
43368 /* three balancings: (1) old name removal, (2) new name insertion
43369 and (3) maybe "save" link insertion
43370 stat data updates: (1) old directory,
43371diff -urNp linux-3.0.4/fs/reiserfs/procfs.c linux-3.0.4/fs/reiserfs/procfs.c
43372--- linux-3.0.4/fs/reiserfs/procfs.c 2011-07-21 22:17:23.000000000 -0400
43373+++ linux-3.0.4/fs/reiserfs/procfs.c 2011-08-23 21:48:14.000000000 -0400
43374@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
43375 "SMALL_TAILS " : "NO_TAILS ",
43376 replay_only(sb) ? "REPLAY_ONLY " : "",
43377 convert_reiserfs(sb) ? "CONV " : "",
43378- atomic_read(&r->s_generation_counter),
43379+ atomic_read_unchecked(&r->s_generation_counter),
43380 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
43381 SF(s_do_balance), SF(s_unneeded_left_neighbor),
43382 SF(s_good_search_by_key_reada), SF(s_bmaps),
43383@@ -299,6 +299,8 @@ static int show_journal(struct seq_file
43384 struct journal_params *jp = &rs->s_v1.s_journal;
43385 char b[BDEVNAME_SIZE];
43386
43387+ pax_track_stack();
43388+
43389 seq_printf(m, /* on-disk fields */
43390 "jp_journal_1st_block: \t%i\n"
43391 "jp_journal_dev: \t%s[%x]\n"
43392diff -urNp linux-3.0.4/fs/reiserfs/stree.c linux-3.0.4/fs/reiserfs/stree.c
43393--- linux-3.0.4/fs/reiserfs/stree.c 2011-07-21 22:17:23.000000000 -0400
43394+++ linux-3.0.4/fs/reiserfs/stree.c 2011-08-23 21:48:14.000000000 -0400
43395@@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
43396 int iter = 0;
43397 #endif
43398
43399+ pax_track_stack();
43400+
43401 BUG_ON(!th->t_trans_id);
43402
43403 init_tb_struct(th, &s_del_balance, sb, path,
43404@@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
43405 int retval;
43406 int quota_cut_bytes = 0;
43407
43408+ pax_track_stack();
43409+
43410 BUG_ON(!th->t_trans_id);
43411
43412 le_key2cpu_key(&cpu_key, key);
43413@@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
43414 int quota_cut_bytes;
43415 loff_t tail_pos = 0;
43416
43417+ pax_track_stack();
43418+
43419 BUG_ON(!th->t_trans_id);
43420
43421 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
43422@@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
43423 int retval;
43424 int fs_gen;
43425
43426+ pax_track_stack();
43427+
43428 BUG_ON(!th->t_trans_id);
43429
43430 fs_gen = get_generation(inode->i_sb);
43431@@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
43432 int fs_gen = 0;
43433 int quota_bytes = 0;
43434
43435+ pax_track_stack();
43436+
43437 BUG_ON(!th->t_trans_id);
43438
43439 if (inode) { /* Do we count quotas for item? */
43440diff -urNp linux-3.0.4/fs/reiserfs/super.c linux-3.0.4/fs/reiserfs/super.c
43441--- linux-3.0.4/fs/reiserfs/super.c 2011-07-21 22:17:23.000000000 -0400
43442+++ linux-3.0.4/fs/reiserfs/super.c 2011-08-23 21:48:14.000000000 -0400
43443@@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
43444 {.option_name = NULL}
43445 };
43446
43447+ pax_track_stack();
43448+
43449 *blocks = 0;
43450 if (!options || !*options)
43451 /* use default configuration: create tails, journaling on, no
43452diff -urNp linux-3.0.4/fs/select.c linux-3.0.4/fs/select.c
43453--- linux-3.0.4/fs/select.c 2011-07-21 22:17:23.000000000 -0400
43454+++ linux-3.0.4/fs/select.c 2011-08-23 21:48:14.000000000 -0400
43455@@ -20,6 +20,7 @@
43456 #include <linux/module.h>
43457 #include <linux/slab.h>
43458 #include <linux/poll.h>
43459+#include <linux/security.h>
43460 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
43461 #include <linux/file.h>
43462 #include <linux/fdtable.h>
43463@@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
43464 int retval, i, timed_out = 0;
43465 unsigned long slack = 0;
43466
43467+ pax_track_stack();
43468+
43469 rcu_read_lock();
43470 retval = max_select_fd(n, fds);
43471 rcu_read_unlock();
43472@@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
43473 /* Allocate small arguments on the stack to save memory and be faster */
43474 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
43475
43476+ pax_track_stack();
43477+
43478 ret = -EINVAL;
43479 if (n < 0)
43480 goto out_nofds;
43481@@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
43482 struct poll_list *walk = head;
43483 unsigned long todo = nfds;
43484
43485+ pax_track_stack();
43486+
43487+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
43488 if (nfds > rlimit(RLIMIT_NOFILE))
43489 return -EINVAL;
43490
43491diff -urNp linux-3.0.4/fs/seq_file.c linux-3.0.4/fs/seq_file.c
43492--- linux-3.0.4/fs/seq_file.c 2011-07-21 22:17:23.000000000 -0400
43493+++ linux-3.0.4/fs/seq_file.c 2011-08-23 21:47:56.000000000 -0400
43494@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
43495 return 0;
43496 }
43497 if (!m->buf) {
43498- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
43499+ m->size = PAGE_SIZE;
43500+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
43501 if (!m->buf)
43502 return -ENOMEM;
43503 }
43504@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
43505 Eoverflow:
43506 m->op->stop(m, p);
43507 kfree(m->buf);
43508- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
43509+ m->size <<= 1;
43510+ m->buf = kmalloc(m->size, GFP_KERNEL);
43511 return !m->buf ? -ENOMEM : -EAGAIN;
43512 }
43513
43514@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
43515 m->version = file->f_version;
43516 /* grab buffer if we didn't have one */
43517 if (!m->buf) {
43518- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
43519+ m->size = PAGE_SIZE;
43520+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
43521 if (!m->buf)
43522 goto Enomem;
43523 }
43524@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
43525 goto Fill;
43526 m->op->stop(m, p);
43527 kfree(m->buf);
43528- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
43529+ m->size <<= 1;
43530+ m->buf = kmalloc(m->size, GFP_KERNEL);
43531 if (!m->buf)
43532 goto Enomem;
43533 m->count = 0;
43534@@ -549,7 +553,7 @@ static void single_stop(struct seq_file
43535 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
43536 void *data)
43537 {
43538- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
43539+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
43540 int res = -ENOMEM;
43541
43542 if (op) {
43543diff -urNp linux-3.0.4/fs/splice.c linux-3.0.4/fs/splice.c
43544--- linux-3.0.4/fs/splice.c 2011-07-21 22:17:23.000000000 -0400
43545+++ linux-3.0.4/fs/splice.c 2011-08-23 21:48:14.000000000 -0400
43546@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode
43547 pipe_lock(pipe);
43548
43549 for (;;) {
43550- if (!pipe->readers) {
43551+ if (!atomic_read(&pipe->readers)) {
43552 send_sig(SIGPIPE, current, 0);
43553 if (!ret)
43554 ret = -EPIPE;
43555@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode
43556 do_wakeup = 0;
43557 }
43558
43559- pipe->waiting_writers++;
43560+ atomic_inc(&pipe->waiting_writers);
43561 pipe_wait(pipe);
43562- pipe->waiting_writers--;
43563+ atomic_dec(&pipe->waiting_writers);
43564 }
43565
43566 pipe_unlock(pipe);
43567@@ -320,6 +320,8 @@ __generic_file_splice_read(struct file *
43568 .spd_release = spd_release_page,
43569 };
43570
43571+ pax_track_stack();
43572+
43573 if (splice_grow_spd(pipe, &spd))
43574 return -ENOMEM;
43575
43576@@ -560,7 +562,7 @@ static ssize_t kernel_readv(struct file
43577 old_fs = get_fs();
43578 set_fs(get_ds());
43579 /* The cast to a user pointer is valid due to the set_fs() */
43580- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
43581+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
43582 set_fs(old_fs);
43583
43584 return res;
43585@@ -575,7 +577,7 @@ static ssize_t kernel_write(struct file
43586 old_fs = get_fs();
43587 set_fs(get_ds());
43588 /* The cast to a user pointer is valid due to the set_fs() */
43589- res = vfs_write(file, (const char __user *)buf, count, &pos);
43590+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
43591 set_fs(old_fs);
43592
43593 return res;
43594@@ -603,6 +605,8 @@ ssize_t default_file_splice_read(struct
43595 .spd_release = spd_release_page,
43596 };
43597
43598+ pax_track_stack();
43599+
43600 if (splice_grow_spd(pipe, &spd))
43601 return -ENOMEM;
43602
43603@@ -626,7 +630,7 @@ ssize_t default_file_splice_read(struct
43604 goto err;
43605
43606 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
43607- vec[i].iov_base = (void __user *) page_address(page);
43608+ vec[i].iov_base = (__force void __user *) page_address(page);
43609 vec[i].iov_len = this_len;
43610 spd.pages[i] = page;
43611 spd.nr_pages++;
43612@@ -846,10 +850,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
43613 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
43614 {
43615 while (!pipe->nrbufs) {
43616- if (!pipe->writers)
43617+ if (!atomic_read(&pipe->writers))
43618 return 0;
43619
43620- if (!pipe->waiting_writers && sd->num_spliced)
43621+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
43622 return 0;
43623
43624 if (sd->flags & SPLICE_F_NONBLOCK)
43625@@ -1182,7 +1186,7 @@ ssize_t splice_direct_to_actor(struct fi
43626 * out of the pipe right after the splice_to_pipe(). So set
43627 * PIPE_READERS appropriately.
43628 */
43629- pipe->readers = 1;
43630+ atomic_set(&pipe->readers, 1);
43631
43632 current->splice_pipe = pipe;
43633 }
43634@@ -1619,6 +1623,8 @@ static long vmsplice_to_pipe(struct file
43635 };
43636 long ret;
43637
43638+ pax_track_stack();
43639+
43640 pipe = get_pipe_info(file);
43641 if (!pipe)
43642 return -EBADF;
43643@@ -1734,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_
43644 ret = -ERESTARTSYS;
43645 break;
43646 }
43647- if (!pipe->writers)
43648+ if (!atomic_read(&pipe->writers))
43649 break;
43650- if (!pipe->waiting_writers) {
43651+ if (!atomic_read(&pipe->waiting_writers)) {
43652 if (flags & SPLICE_F_NONBLOCK) {
43653 ret = -EAGAIN;
43654 break;
43655@@ -1768,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_
43656 pipe_lock(pipe);
43657
43658 while (pipe->nrbufs >= pipe->buffers) {
43659- if (!pipe->readers) {
43660+ if (!atomic_read(&pipe->readers)) {
43661 send_sig(SIGPIPE, current, 0);
43662 ret = -EPIPE;
43663 break;
43664@@ -1781,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_
43665 ret = -ERESTARTSYS;
43666 break;
43667 }
43668- pipe->waiting_writers++;
43669+ atomic_inc(&pipe->waiting_writers);
43670 pipe_wait(pipe);
43671- pipe->waiting_writers--;
43672+ atomic_dec(&pipe->waiting_writers);
43673 }
43674
43675 pipe_unlock(pipe);
43676@@ -1819,14 +1825,14 @@ retry:
43677 pipe_double_lock(ipipe, opipe);
43678
43679 do {
43680- if (!opipe->readers) {
43681+ if (!atomic_read(&opipe->readers)) {
43682 send_sig(SIGPIPE, current, 0);
43683 if (!ret)
43684 ret = -EPIPE;
43685 break;
43686 }
43687
43688- if (!ipipe->nrbufs && !ipipe->writers)
43689+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
43690 break;
43691
43692 /*
43693@@ -1923,7 +1929,7 @@ static int link_pipe(struct pipe_inode_i
43694 pipe_double_lock(ipipe, opipe);
43695
43696 do {
43697- if (!opipe->readers) {
43698+ if (!atomic_read(&opipe->readers)) {
43699 send_sig(SIGPIPE, current, 0);
43700 if (!ret)
43701 ret = -EPIPE;
43702@@ -1968,7 +1974,7 @@ static int link_pipe(struct pipe_inode_i
43703 * return EAGAIN if we have the potential of some data in the
43704 * future, otherwise just return 0
43705 */
43706- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
43707+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
43708 ret = -EAGAIN;
43709
43710 pipe_unlock(ipipe);
43711diff -urNp linux-3.0.4/fs/sysfs/file.c linux-3.0.4/fs/sysfs/file.c
43712--- linux-3.0.4/fs/sysfs/file.c 2011-07-21 22:17:23.000000000 -0400
43713+++ linux-3.0.4/fs/sysfs/file.c 2011-08-23 21:47:56.000000000 -0400
43714@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
43715
43716 struct sysfs_open_dirent {
43717 atomic_t refcnt;
43718- atomic_t event;
43719+ atomic_unchecked_t event;
43720 wait_queue_head_t poll;
43721 struct list_head buffers; /* goes through sysfs_buffer.list */
43722 };
43723@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentr
43724 if (!sysfs_get_active(attr_sd))
43725 return -ENODEV;
43726
43727- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
43728+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
43729 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
43730
43731 sysfs_put_active(attr_sd);
43732@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct
43733 return -ENOMEM;
43734
43735 atomic_set(&new_od->refcnt, 0);
43736- atomic_set(&new_od->event, 1);
43737+ atomic_set_unchecked(&new_od->event, 1);
43738 init_waitqueue_head(&new_od->poll);
43739 INIT_LIST_HEAD(&new_od->buffers);
43740 goto retry;
43741@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct fi
43742
43743 sysfs_put_active(attr_sd);
43744
43745- if (buffer->event != atomic_read(&od->event))
43746+ if (buffer->event != atomic_read_unchecked(&od->event))
43747 goto trigger;
43748
43749 return DEFAULT_POLLMASK;
43750@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_di
43751
43752 od = sd->s_attr.open;
43753 if (od) {
43754- atomic_inc(&od->event);
43755+ atomic_inc_unchecked(&od->event);
43756 wake_up_interruptible(&od->poll);
43757 }
43758
43759diff -urNp linux-3.0.4/fs/sysfs/mount.c linux-3.0.4/fs/sysfs/mount.c
43760--- linux-3.0.4/fs/sysfs/mount.c 2011-07-21 22:17:23.000000000 -0400
43761+++ linux-3.0.4/fs/sysfs/mount.c 2011-08-23 21:48:14.000000000 -0400
43762@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
43763 .s_name = "",
43764 .s_count = ATOMIC_INIT(1),
43765 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
43766+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43767+ .s_mode = S_IFDIR | S_IRWXU,
43768+#else
43769 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43770+#endif
43771 .s_ino = 1,
43772 };
43773
43774diff -urNp linux-3.0.4/fs/sysfs/symlink.c linux-3.0.4/fs/sysfs/symlink.c
43775--- linux-3.0.4/fs/sysfs/symlink.c 2011-07-21 22:17:23.000000000 -0400
43776+++ linux-3.0.4/fs/sysfs/symlink.c 2011-08-23 21:47:56.000000000 -0400
43777@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
43778
43779 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
43780 {
43781- char *page = nd_get_link(nd);
43782+ const char *page = nd_get_link(nd);
43783 if (!IS_ERR(page))
43784 free_page((unsigned long)page);
43785 }
43786diff -urNp linux-3.0.4/fs/udf/inode.c linux-3.0.4/fs/udf/inode.c
43787--- linux-3.0.4/fs/udf/inode.c 2011-07-21 22:17:23.000000000 -0400
43788+++ linux-3.0.4/fs/udf/inode.c 2011-08-23 21:48:14.000000000 -0400
43789@@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
43790 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
43791 int lastblock = 0;
43792
43793+ pax_track_stack();
43794+
43795 prev_epos.offset = udf_file_entry_alloc_offset(inode);
43796 prev_epos.block = iinfo->i_location;
43797 prev_epos.bh = NULL;
43798diff -urNp linux-3.0.4/fs/udf/misc.c linux-3.0.4/fs/udf/misc.c
43799--- linux-3.0.4/fs/udf/misc.c 2011-07-21 22:17:23.000000000 -0400
43800+++ linux-3.0.4/fs/udf/misc.c 2011-08-23 21:47:56.000000000 -0400
43801@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
43802
43803 u8 udf_tag_checksum(const struct tag *t)
43804 {
43805- u8 *data = (u8 *)t;
43806+ const u8 *data = (const u8 *)t;
43807 u8 checksum = 0;
43808 int i;
43809 for (i = 0; i < sizeof(struct tag); ++i)
43810diff -urNp linux-3.0.4/fs/utimes.c linux-3.0.4/fs/utimes.c
43811--- linux-3.0.4/fs/utimes.c 2011-07-21 22:17:23.000000000 -0400
43812+++ linux-3.0.4/fs/utimes.c 2011-08-23 21:48:14.000000000 -0400
43813@@ -1,6 +1,7 @@
43814 #include <linux/compiler.h>
43815 #include <linux/file.h>
43816 #include <linux/fs.h>
43817+#include <linux/security.h>
43818 #include <linux/linkage.h>
43819 #include <linux/mount.h>
43820 #include <linux/namei.h>
43821@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
43822 goto mnt_drop_write_and_out;
43823 }
43824 }
43825+
43826+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
43827+ error = -EACCES;
43828+ goto mnt_drop_write_and_out;
43829+ }
43830+
43831 mutex_lock(&inode->i_mutex);
43832 error = notify_change(path->dentry, &newattrs);
43833 mutex_unlock(&inode->i_mutex);
43834diff -urNp linux-3.0.4/fs/xattr_acl.c linux-3.0.4/fs/xattr_acl.c
43835--- linux-3.0.4/fs/xattr_acl.c 2011-07-21 22:17:23.000000000 -0400
43836+++ linux-3.0.4/fs/xattr_acl.c 2011-08-23 21:47:56.000000000 -0400
43837@@ -17,8 +17,8 @@
43838 struct posix_acl *
43839 posix_acl_from_xattr(const void *value, size_t size)
43840 {
43841- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
43842- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
43843+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
43844+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
43845 int count;
43846 struct posix_acl *acl;
43847 struct posix_acl_entry *acl_e;
43848diff -urNp linux-3.0.4/fs/xattr.c linux-3.0.4/fs/xattr.c
43849--- linux-3.0.4/fs/xattr.c 2011-07-21 22:17:23.000000000 -0400
43850+++ linux-3.0.4/fs/xattr.c 2011-08-23 21:48:14.000000000 -0400
43851@@ -254,7 +254,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
43852 * Extended attribute SET operations
43853 */
43854 static long
43855-setxattr(struct dentry *d, const char __user *name, const void __user *value,
43856+setxattr(struct path *path, const char __user *name, const void __user *value,
43857 size_t size, int flags)
43858 {
43859 int error;
43860@@ -278,7 +278,13 @@ setxattr(struct dentry *d, const char __
43861 return PTR_ERR(kvalue);
43862 }
43863
43864- error = vfs_setxattr(d, kname, kvalue, size, flags);
43865+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
43866+ error = -EACCES;
43867+ goto out;
43868+ }
43869+
43870+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
43871+out:
43872 kfree(kvalue);
43873 return error;
43874 }
43875@@ -295,7 +301,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
43876 return error;
43877 error = mnt_want_write(path.mnt);
43878 if (!error) {
43879- error = setxattr(path.dentry, name, value, size, flags);
43880+ error = setxattr(&path, name, value, size, flags);
43881 mnt_drop_write(path.mnt);
43882 }
43883 path_put(&path);
43884@@ -314,7 +320,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
43885 return error;
43886 error = mnt_want_write(path.mnt);
43887 if (!error) {
43888- error = setxattr(path.dentry, name, value, size, flags);
43889+ error = setxattr(&path, name, value, size, flags);
43890 mnt_drop_write(path.mnt);
43891 }
43892 path_put(&path);
43893@@ -325,17 +331,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
43894 const void __user *,value, size_t, size, int, flags)
43895 {
43896 struct file *f;
43897- struct dentry *dentry;
43898 int error = -EBADF;
43899
43900 f = fget(fd);
43901 if (!f)
43902 return error;
43903- dentry = f->f_path.dentry;
43904- audit_inode(NULL, dentry);
43905+ audit_inode(NULL, f->f_path.dentry);
43906 error = mnt_want_write_file(f);
43907 if (!error) {
43908- error = setxattr(dentry, name, value, size, flags);
43909+ error = setxattr(&f->f_path, name, value, size, flags);
43910 mnt_drop_write(f->f_path.mnt);
43911 }
43912 fput(f);
43913diff -urNp linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl32.c linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl32.c
43914--- linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-07-21 22:17:23.000000000 -0400
43915+++ linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-08-23 21:48:14.000000000 -0400
43916@@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
43917 xfs_fsop_geom_t fsgeo;
43918 int error;
43919
43920+ memset(&fsgeo, 0, sizeof(fsgeo));
43921 error = xfs_fs_geometry(mp, &fsgeo, 3);
43922 if (error)
43923 return -error;
43924diff -urNp linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c
43925--- linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c 2011-07-21 22:17:23.000000000 -0400
43926+++ linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c 2011-08-23 21:47:56.000000000 -0400
43927@@ -128,7 +128,7 @@ xfs_find_handle(
43928 }
43929
43930 error = -EFAULT;
43931- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
43932+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
43933 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
43934 goto out_put;
43935
43936diff -urNp linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c
43937--- linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c 2011-07-21 22:17:23.000000000 -0400
43938+++ linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c 2011-08-23 21:47:56.000000000 -0400
43939@@ -437,7 +437,7 @@ xfs_vn_put_link(
43940 struct nameidata *nd,
43941 void *p)
43942 {
43943- char *s = nd_get_link(nd);
43944+ const char *s = nd_get_link(nd);
43945
43946 if (!IS_ERR(s))
43947 kfree(s);
43948diff -urNp linux-3.0.4/fs/xfs/xfs_bmap.c linux-3.0.4/fs/xfs/xfs_bmap.c
43949--- linux-3.0.4/fs/xfs/xfs_bmap.c 2011-07-21 22:17:23.000000000 -0400
43950+++ linux-3.0.4/fs/xfs/xfs_bmap.c 2011-08-23 21:47:56.000000000 -0400
43951@@ -253,7 +253,7 @@ xfs_bmap_validate_ret(
43952 int nmap,
43953 int ret_nmap);
43954 #else
43955-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
43956+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
43957 #endif /* DEBUG */
43958
43959 STATIC int
43960diff -urNp linux-3.0.4/fs/xfs/xfs_dir2_sf.c linux-3.0.4/fs/xfs/xfs_dir2_sf.c
43961--- linux-3.0.4/fs/xfs/xfs_dir2_sf.c 2011-07-21 22:17:23.000000000 -0400
43962+++ linux-3.0.4/fs/xfs/xfs_dir2_sf.c 2011-08-23 21:47:56.000000000 -0400
43963@@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
43964 }
43965
43966 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
43967- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
43968+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
43969+ char name[sfep->namelen];
43970+ memcpy(name, sfep->name, sfep->namelen);
43971+ if (filldir(dirent, name, sfep->namelen,
43972+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
43973+ *offset = off & 0x7fffffff;
43974+ return 0;
43975+ }
43976+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
43977 off & 0x7fffffff, ino, DT_UNKNOWN)) {
43978 *offset = off & 0x7fffffff;
43979 return 0;
43980diff -urNp linux-3.0.4/grsecurity/gracl_alloc.c linux-3.0.4/grsecurity/gracl_alloc.c
43981--- linux-3.0.4/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
43982+++ linux-3.0.4/grsecurity/gracl_alloc.c 2011-08-23 21:48:14.000000000 -0400
43983@@ -0,0 +1,105 @@
43984+#include <linux/kernel.h>
43985+#include <linux/mm.h>
43986+#include <linux/slab.h>
43987+#include <linux/vmalloc.h>
43988+#include <linux/gracl.h>
43989+#include <linux/grsecurity.h>
43990+
43991+static unsigned long alloc_stack_next = 1;
43992+static unsigned long alloc_stack_size = 1;
43993+static void **alloc_stack;
43994+
43995+static __inline__ int
43996+alloc_pop(void)
43997+{
43998+ if (alloc_stack_next == 1)
43999+ return 0;
44000+
44001+ kfree(alloc_stack[alloc_stack_next - 2]);
44002+
44003+ alloc_stack_next--;
44004+
44005+ return 1;
44006+}
44007+
44008+static __inline__ int
44009+alloc_push(void *buf)
44010+{
44011+ if (alloc_stack_next >= alloc_stack_size)
44012+ return 1;
44013+
44014+ alloc_stack[alloc_stack_next - 1] = buf;
44015+
44016+ alloc_stack_next++;
44017+
44018+ return 0;
44019+}
44020+
44021+void *
44022+acl_alloc(unsigned long len)
44023+{
44024+ void *ret = NULL;
44025+
44026+ if (!len || len > PAGE_SIZE)
44027+ goto out;
44028+
44029+ ret = kmalloc(len, GFP_KERNEL);
44030+
44031+ if (ret) {
44032+ if (alloc_push(ret)) {
44033+ kfree(ret);
44034+ ret = NULL;
44035+ }
44036+ }
44037+
44038+out:
44039+ return ret;
44040+}
44041+
44042+void *
44043+acl_alloc_num(unsigned long num, unsigned long len)
44044+{
44045+ if (!len || (num > (PAGE_SIZE / len)))
44046+ return NULL;
44047+
44048+ return acl_alloc(num * len);
44049+}
44050+
44051+void
44052+acl_free_all(void)
44053+{
44054+ if (gr_acl_is_enabled() || !alloc_stack)
44055+ return;
44056+
44057+ while (alloc_pop()) ;
44058+
44059+ if (alloc_stack) {
44060+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
44061+ kfree(alloc_stack);
44062+ else
44063+ vfree(alloc_stack);
44064+ }
44065+
44066+ alloc_stack = NULL;
44067+ alloc_stack_size = 1;
44068+ alloc_stack_next = 1;
44069+
44070+ return;
44071+}
44072+
44073+int
44074+acl_alloc_stack_init(unsigned long size)
44075+{
44076+ if ((size * sizeof (void *)) <= PAGE_SIZE)
44077+ alloc_stack =
44078+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
44079+ else
44080+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
44081+
44082+ alloc_stack_size = size;
44083+
44084+ if (!alloc_stack)
44085+ return 0;
44086+ else
44087+ return 1;
44088+}
44089diff -urNp linux-3.0.4/grsecurity/gracl.c linux-3.0.4/grsecurity/gracl.c
44090--- linux-3.0.4/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
44091+++ linux-3.0.4/grsecurity/gracl.c 2011-08-23 21:48:14.000000000 -0400
44092@@ -0,0 +1,4106 @@
44093+#include <linux/kernel.h>
44094+#include <linux/module.h>
44095+#include <linux/sched.h>
44096+#include <linux/mm.h>
44097+#include <linux/file.h>
44098+#include <linux/fs.h>
44099+#include <linux/namei.h>
44100+#include <linux/mount.h>
44101+#include <linux/tty.h>
44102+#include <linux/proc_fs.h>
44103+#include <linux/lglock.h>
44104+#include <linux/slab.h>
44105+#include <linux/vmalloc.h>
44106+#include <linux/types.h>
44107+#include <linux/sysctl.h>
44108+#include <linux/netdevice.h>
44109+#include <linux/ptrace.h>
44110+#include <linux/gracl.h>
44111+#include <linux/gralloc.h>
44112+#include <linux/grsecurity.h>
44113+#include <linux/grinternal.h>
44114+#include <linux/pid_namespace.h>
44115+#include <linux/fdtable.h>
44116+#include <linux/percpu.h>
44117+
44118+#include <asm/uaccess.h>
44119+#include <asm/errno.h>
44120+#include <asm/mman.h>
44121+
44122+static struct acl_role_db acl_role_set;
44123+static struct name_db name_set;
44124+static struct inodev_db inodev_set;
44125+
44126+/* for keeping track of userspace pointers used for subjects, so we
44127+ can share references in the kernel as well
44128+*/
44129+
44130+static struct path real_root;
44131+
44132+static struct acl_subj_map_db subj_map_set;
44133+
44134+static struct acl_role_label *default_role;
44135+
44136+static struct acl_role_label *role_list;
44137+
44138+static u16 acl_sp_role_value;
44139+
44140+extern char *gr_shared_page[4];
44141+static DEFINE_MUTEX(gr_dev_mutex);
44142+DEFINE_RWLOCK(gr_inode_lock);
44143+
44144+struct gr_arg *gr_usermode;
44145+
44146+static unsigned int gr_status __read_only = GR_STATUS_INIT;
44147+
44148+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
44149+extern void gr_clear_learn_entries(void);
44150+
44151+#ifdef CONFIG_GRKERNSEC_RESLOG
44152+extern void gr_log_resource(const struct task_struct *task,
44153+ const int res, const unsigned long wanted, const int gt);
44154+#endif
44155+
44156+unsigned char *gr_system_salt;
44157+unsigned char *gr_system_sum;
44158+
44159+static struct sprole_pw **acl_special_roles = NULL;
44160+static __u16 num_sprole_pws = 0;
44161+
44162+static struct acl_role_label *kernel_role = NULL;
44163+
44164+static unsigned int gr_auth_attempts = 0;
44165+static unsigned long gr_auth_expires = 0UL;
44166+
44167+#ifdef CONFIG_NET
44168+extern struct vfsmount *sock_mnt;
44169+#endif
44170+
44171+extern struct vfsmount *pipe_mnt;
44172+extern struct vfsmount *shm_mnt;
44173+#ifdef CONFIG_HUGETLBFS
44174+extern struct vfsmount *hugetlbfs_vfsmount;
44175+#endif
44176+
44177+static struct acl_object_label *fakefs_obj_rw;
44178+static struct acl_object_label *fakefs_obj_rwx;
44179+
44180+extern int gr_init_uidset(void);
44181+extern void gr_free_uidset(void);
44182+extern void gr_remove_uid(uid_t uid);
44183+extern int gr_find_uid(uid_t uid);
44184+
44185+DECLARE_BRLOCK(vfsmount_lock);
44186+
44187+__inline__ int
44188+gr_acl_is_enabled(void)
44189+{
44190+ return (gr_status & GR_READY);
44191+}
44192+
44193+#ifdef CONFIG_BTRFS_FS
44194+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
44195+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
44196+#endif
44197+
44198+static inline dev_t __get_dev(const struct dentry *dentry)
44199+{
44200+#ifdef CONFIG_BTRFS_FS
44201+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
44202+ return get_btrfs_dev_from_inode(dentry->d_inode);
44203+ else
44204+#endif
44205+ return dentry->d_inode->i_sb->s_dev;
44206+}
44207+
44208+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
44209+{
44210+ return __get_dev(dentry);
44211+}
44212+
44213+static char gr_task_roletype_to_char(struct task_struct *task)
44214+{
44215+ switch (task->role->roletype &
44216+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
44217+ GR_ROLE_SPECIAL)) {
44218+ case GR_ROLE_DEFAULT:
44219+ return 'D';
44220+ case GR_ROLE_USER:
44221+ return 'U';
44222+ case GR_ROLE_GROUP:
44223+ return 'G';
44224+ case GR_ROLE_SPECIAL:
44225+ return 'S';
44226+ }
44227+
44228+ return 'X';
44229+}
44230+
44231+char gr_roletype_to_char(void)
44232+{
44233+ return gr_task_roletype_to_char(current);
44234+}
44235+
44236+__inline__ int
44237+gr_acl_tpe_check(void)
44238+{
44239+ if (unlikely(!(gr_status & GR_READY)))
44240+ return 0;
44241+ if (current->role->roletype & GR_ROLE_TPE)
44242+ return 1;
44243+ else
44244+ return 0;
44245+}
44246+
44247+int
44248+gr_handle_rawio(const struct inode *inode)
44249+{
44250+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
44251+ if (inode && S_ISBLK(inode->i_mode) &&
44252+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
44253+ !capable(CAP_SYS_RAWIO))
44254+ return 1;
44255+#endif
44256+ return 0;
44257+}
44258+
44259+static int
44260+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
44261+{
44262+ if (likely(lena != lenb))
44263+ return 0;
44264+
44265+ return !memcmp(a, b, lena);
44266+}
44267+
44268+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
44269+{
44270+ *buflen -= namelen;
44271+ if (*buflen < 0)
44272+ return -ENAMETOOLONG;
44273+ *buffer -= namelen;
44274+ memcpy(*buffer, str, namelen);
44275+ return 0;
44276+}
44277+
44278+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
44279+{
44280+ return prepend(buffer, buflen, name->name, name->len);
44281+}
44282+
44283+static int prepend_path(const struct path *path, struct path *root,
44284+ char **buffer, int *buflen)
44285+{
44286+ struct dentry *dentry = path->dentry;
44287+ struct vfsmount *vfsmnt = path->mnt;
44288+ bool slash = false;
44289+ int error = 0;
44290+
44291+ while (dentry != root->dentry || vfsmnt != root->mnt) {
44292+ struct dentry * parent;
44293+
44294+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
44295+ /* Global root? */
44296+ if (vfsmnt->mnt_parent == vfsmnt) {
44297+ goto out;
44298+ }
44299+ dentry = vfsmnt->mnt_mountpoint;
44300+ vfsmnt = vfsmnt->mnt_parent;
44301+ continue;
44302+ }
44303+ parent = dentry->d_parent;
44304+ prefetch(parent);
44305+ spin_lock(&dentry->d_lock);
44306+ error = prepend_name(buffer, buflen, &dentry->d_name);
44307+ spin_unlock(&dentry->d_lock);
44308+ if (!error)
44309+ error = prepend(buffer, buflen, "/", 1);
44310+ if (error)
44311+ break;
44312+
44313+ slash = true;
44314+ dentry = parent;
44315+ }
44316+
44317+out:
44318+ if (!error && !slash)
44319+ error = prepend(buffer, buflen, "/", 1);
44320+
44321+ return error;
44322+}
44323+
44324+/* this must be called with vfsmount_lock and rename_lock held */
44325+
44326+static char *__our_d_path(const struct path *path, struct path *root,
44327+ char *buf, int buflen)
44328+{
44329+ char *res = buf + buflen;
44330+ int error;
44331+
44332+ prepend(&res, &buflen, "\0", 1);
44333+ error = prepend_path(path, root, &res, &buflen);
44334+ if (error)
44335+ return ERR_PTR(error);
44336+
44337+ return res;
44338+}
44339+
44340+static char *
44341+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
44342+{
44343+ char *retval;
44344+
44345+ retval = __our_d_path(path, root, buf, buflen);
44346+ if (unlikely(IS_ERR(retval)))
44347+ retval = strcpy(buf, "<path too long>");
44348+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
44349+ retval[1] = '\0';
44350+
44351+ return retval;
44352+}
44353+
44354+static char *
44355+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
44356+ char *buf, int buflen)
44357+{
44358+ struct path path;
44359+ char *res;
44360+
44361+ path.dentry = (struct dentry *)dentry;
44362+ path.mnt = (struct vfsmount *)vfsmnt;
44363+
44364+ /* we can use real_root.dentry, real_root.mnt, because this is only called
44365+ by the RBAC system */
44366+ res = gen_full_path(&path, &real_root, buf, buflen);
44367+
44368+ return res;
44369+}
44370+
44371+static char *
44372+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
44373+ char *buf, int buflen)
44374+{
44375+ char *res;
44376+ struct path path;
44377+ struct path root;
44378+ struct task_struct *reaper = &init_task;
44379+
44380+ path.dentry = (struct dentry *)dentry;
44381+ path.mnt = (struct vfsmount *)vfsmnt;
44382+
44383+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
44384+ get_fs_root(reaper->fs, &root);
44385+
44386+ write_seqlock(&rename_lock);
44387+ br_read_lock(vfsmount_lock);
44388+ res = gen_full_path(&path, &root, buf, buflen);
44389+ br_read_unlock(vfsmount_lock);
44390+ write_sequnlock(&rename_lock);
44391+
44392+ path_put(&root);
44393+ return res;
44394+}
44395+
44396+static char *
44397+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
44398+{
44399+ char *ret;
44400+ write_seqlock(&rename_lock);
44401+ br_read_lock(vfsmount_lock);
44402+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
44403+ PAGE_SIZE);
44404+ br_read_unlock(vfsmount_lock);
44405+ write_sequnlock(&rename_lock);
44406+ return ret;
44407+}
44408+
44409+char *
44410+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
44411+{
44412+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
44413+ PAGE_SIZE);
44414+}
44415+
44416+char *
44417+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
44418+{
44419+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
44420+ PAGE_SIZE);
44421+}
44422+
44423+char *
44424+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
44425+{
44426+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
44427+ PAGE_SIZE);
44428+}
44429+
44430+char *
44431+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
44432+{
44433+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
44434+ PAGE_SIZE);
44435+}
44436+
44437+char *
44438+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
44439+{
44440+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
44441+ PAGE_SIZE);
44442+}
44443+
44444+__inline__ __u32
44445+to_gr_audit(const __u32 reqmode)
44446+{
44447+ /* masks off auditable permission flags, then shifts them to create
44448+ auditing flags, and adds the special case of append auditing if
44449+ we're requesting write */
44450+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
44451+}
44452+
44453+struct acl_subject_label *
44454+lookup_subject_map(const struct acl_subject_label *userp)
44455+{
44456+ unsigned int index = shash(userp, subj_map_set.s_size);
44457+ struct subject_map *match;
44458+
44459+ match = subj_map_set.s_hash[index];
44460+
44461+ while (match && match->user != userp)
44462+ match = match->next;
44463+
44464+ if (match != NULL)
44465+ return match->kernel;
44466+ else
44467+ return NULL;
44468+}
44469+
44470+static void
44471+insert_subj_map_entry(struct subject_map *subjmap)
44472+{
44473+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
44474+ struct subject_map **curr;
44475+
44476+ subjmap->prev = NULL;
44477+
44478+ curr = &subj_map_set.s_hash[index];
44479+ if (*curr != NULL)
44480+ (*curr)->prev = subjmap;
44481+
44482+ subjmap->next = *curr;
44483+ *curr = subjmap;
44484+
44485+ return;
44486+}
44487+
44488+static struct acl_role_label *
44489+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
44490+ const gid_t gid)
44491+{
44492+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
44493+ struct acl_role_label *match;
44494+ struct role_allowed_ip *ipp;
44495+ unsigned int x;
44496+ u32 curr_ip = task->signal->curr_ip;
44497+
44498+ task->signal->saved_ip = curr_ip;
44499+
44500+ match = acl_role_set.r_hash[index];
44501+
44502+ while (match) {
44503+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
44504+ for (x = 0; x < match->domain_child_num; x++) {
44505+ if (match->domain_children[x] == uid)
44506+ goto found;
44507+ }
44508+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
44509+ break;
44510+ match = match->next;
44511+ }
44512+found:
44513+ if (match == NULL) {
44514+ try_group:
44515+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
44516+ match = acl_role_set.r_hash[index];
44517+
44518+ while (match) {
44519+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
44520+ for (x = 0; x < match->domain_child_num; x++) {
44521+ if (match->domain_children[x] == gid)
44522+ goto found2;
44523+ }
44524+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
44525+ break;
44526+ match = match->next;
44527+ }
44528+found2:
44529+ if (match == NULL)
44530+ match = default_role;
44531+ if (match->allowed_ips == NULL)
44532+ return match;
44533+ else {
44534+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
44535+ if (likely
44536+ ((ntohl(curr_ip) & ipp->netmask) ==
44537+ (ntohl(ipp->addr) & ipp->netmask)))
44538+ return match;
44539+ }
44540+ match = default_role;
44541+ }
44542+ } else if (match->allowed_ips == NULL) {
44543+ return match;
44544+ } else {
44545+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
44546+ if (likely
44547+ ((ntohl(curr_ip) & ipp->netmask) ==
44548+ (ntohl(ipp->addr) & ipp->netmask)))
44549+ return match;
44550+ }
44551+ goto try_group;
44552+ }
44553+
44554+ return match;
44555+}
44556+
44557+struct acl_subject_label *
44558+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
44559+ const struct acl_role_label *role)
44560+{
44561+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
44562+ struct acl_subject_label *match;
44563+
44564+ match = role->subj_hash[index];
44565+
44566+ while (match && (match->inode != ino || match->device != dev ||
44567+ (match->mode & GR_DELETED))) {
44568+ match = match->next;
44569+ }
44570+
44571+ if (match && !(match->mode & GR_DELETED))
44572+ return match;
44573+ else
44574+ return NULL;
44575+}
44576+
44577+struct acl_subject_label *
44578+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
44579+ const struct acl_role_label *role)
44580+{
44581+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
44582+ struct acl_subject_label *match;
44583+
44584+ match = role->subj_hash[index];
44585+
44586+ while (match && (match->inode != ino || match->device != dev ||
44587+ !(match->mode & GR_DELETED))) {
44588+ match = match->next;
44589+ }
44590+
44591+ if (match && (match->mode & GR_DELETED))
44592+ return match;
44593+ else
44594+ return NULL;
44595+}
44596+
44597+static struct acl_object_label *
44598+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
44599+ const struct acl_subject_label *subj)
44600+{
44601+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
44602+ struct acl_object_label *match;
44603+
44604+ match = subj->obj_hash[index];
44605+
44606+ while (match && (match->inode != ino || match->device != dev ||
44607+ (match->mode & GR_DELETED))) {
44608+ match = match->next;
44609+ }
44610+
44611+ if (match && !(match->mode & GR_DELETED))
44612+ return match;
44613+ else
44614+ return NULL;
44615+}
44616+
44617+static struct acl_object_label *
44618+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
44619+ const struct acl_subject_label *subj)
44620+{
44621+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
44622+ struct acl_object_label *match;
44623+
44624+ match = subj->obj_hash[index];
44625+
44626+ while (match && (match->inode != ino || match->device != dev ||
44627+ !(match->mode & GR_DELETED))) {
44628+ match = match->next;
44629+ }
44630+
44631+ if (match && (match->mode & GR_DELETED))
44632+ return match;
44633+
44634+ match = subj->obj_hash[index];
44635+
44636+ while (match && (match->inode != ino || match->device != dev ||
44637+ (match->mode & GR_DELETED))) {
44638+ match = match->next;
44639+ }
44640+
44641+ if (match && !(match->mode & GR_DELETED))
44642+ return match;
44643+ else
44644+ return NULL;
44645+}
44646+
44647+static struct name_entry *
44648+lookup_name_entry(const char *name)
44649+{
44650+ unsigned int len = strlen(name);
44651+ unsigned int key = full_name_hash(name, len);
44652+ unsigned int index = key % name_set.n_size;
44653+ struct name_entry *match;
44654+
44655+ match = name_set.n_hash[index];
44656+
44657+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
44658+ match = match->next;
44659+
44660+ return match;
44661+}
44662+
44663+static struct name_entry *
44664+lookup_name_entry_create(const char *name)
44665+{
44666+ unsigned int len = strlen(name);
44667+ unsigned int key = full_name_hash(name, len);
44668+ unsigned int index = key % name_set.n_size;
44669+ struct name_entry *match;
44670+
44671+ match = name_set.n_hash[index];
44672+
44673+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
44674+ !match->deleted))
44675+ match = match->next;
44676+
44677+ if (match && match->deleted)
44678+ return match;
44679+
44680+ match = name_set.n_hash[index];
44681+
44682+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
44683+ match->deleted))
44684+ match = match->next;
44685+
44686+ if (match && !match->deleted)
44687+ return match;
44688+ else
44689+ return NULL;
44690+}
44691+
44692+static struct inodev_entry *
44693+lookup_inodev_entry(const ino_t ino, const dev_t dev)
44694+{
44695+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
44696+ struct inodev_entry *match;
44697+
44698+ match = inodev_set.i_hash[index];
44699+
44700+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
44701+ match = match->next;
44702+
44703+ return match;
44704+}
44705+
44706+static void
44707+insert_inodev_entry(struct inodev_entry *entry)
44708+{
44709+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
44710+ inodev_set.i_size);
44711+ struct inodev_entry **curr;
44712+
44713+ entry->prev = NULL;
44714+
44715+ curr = &inodev_set.i_hash[index];
44716+ if (*curr != NULL)
44717+ (*curr)->prev = entry;
44718+
44719+ entry->next = *curr;
44720+ *curr = entry;
44721+
44722+ return;
44723+}
44724+
44725+static void
44726+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
44727+{
44728+ unsigned int index =
44729+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
44730+ struct acl_role_label **curr;
44731+ struct acl_role_label *tmp;
44732+
44733+ curr = &acl_role_set.r_hash[index];
44734+
44735+ /* if role was already inserted due to domains and already has
44736+ a role in the same bucket as it attached, then we need to
44737+ combine these two buckets
44738+ */
44739+ if (role->next) {
44740+ tmp = role->next;
44741+ while (tmp->next)
44742+ tmp = tmp->next;
44743+ tmp->next = *curr;
44744+ } else
44745+ role->next = *curr;
44746+ *curr = role;
44747+
44748+ return;
44749+}
44750+
44751+static void
44752+insert_acl_role_label(struct acl_role_label *role)
44753+{
44754+ int i;
44755+
44756+ if (role_list == NULL) {
44757+ role_list = role;
44758+ role->prev = NULL;
44759+ } else {
44760+ role->prev = role_list;
44761+ role_list = role;
44762+ }
44763+
44764+ /* used for hash chains */
44765+ role->next = NULL;
44766+
44767+ if (role->roletype & GR_ROLE_DOMAIN) {
44768+ for (i = 0; i < role->domain_child_num; i++)
44769+ __insert_acl_role_label(role, role->domain_children[i]);
44770+ } else
44771+ __insert_acl_role_label(role, role->uidgid);
44772+}
44773+
44774+static int
44775+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
44776+{
44777+ struct name_entry **curr, *nentry;
44778+ struct inodev_entry *ientry;
44779+ unsigned int len = strlen(name);
44780+ unsigned int key = full_name_hash(name, len);
44781+ unsigned int index = key % name_set.n_size;
44782+
44783+ curr = &name_set.n_hash[index];
44784+
44785+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
44786+ curr = &((*curr)->next);
44787+
44788+ if (*curr != NULL)
44789+ return 1;
44790+
44791+ nentry = acl_alloc(sizeof (struct name_entry));
44792+ if (nentry == NULL)
44793+ return 0;
44794+ ientry = acl_alloc(sizeof (struct inodev_entry));
44795+ if (ientry == NULL)
44796+ return 0;
44797+ ientry->nentry = nentry;
44798+
44799+ nentry->key = key;
44800+ nentry->name = name;
44801+ nentry->inode = inode;
44802+ nentry->device = device;
44803+ nentry->len = len;
44804+ nentry->deleted = deleted;
44805+
44806+ nentry->prev = NULL;
44807+ curr = &name_set.n_hash[index];
44808+ if (*curr != NULL)
44809+ (*curr)->prev = nentry;
44810+ nentry->next = *curr;
44811+ *curr = nentry;
44812+
44813+ /* insert us into the table searchable by inode/dev */
44814+ insert_inodev_entry(ientry);
44815+
44816+ return 1;
44817+}
44818+
44819+static void
44820+insert_acl_obj_label(struct acl_object_label *obj,
44821+ struct acl_subject_label *subj)
44822+{
44823+ unsigned int index =
44824+ fhash(obj->inode, obj->device, subj->obj_hash_size);
44825+ struct acl_object_label **curr;
44826+
44827+
44828+ obj->prev = NULL;
44829+
44830+ curr = &subj->obj_hash[index];
44831+ if (*curr != NULL)
44832+ (*curr)->prev = obj;
44833+
44834+ obj->next = *curr;
44835+ *curr = obj;
44836+
44837+ return;
44838+}
44839+
44840+static void
44841+insert_acl_subj_label(struct acl_subject_label *obj,
44842+ struct acl_role_label *role)
44843+{
44844+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
44845+ struct acl_subject_label **curr;
44846+
44847+ obj->prev = NULL;
44848+
44849+ curr = &role->subj_hash[index];
44850+ if (*curr != NULL)
44851+ (*curr)->prev = obj;
44852+
44853+ obj->next = *curr;
44854+ *curr = obj;
44855+
44856+ return;
44857+}
44858+
44859+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
44860+
44861+static void *
44862+create_table(__u32 * len, int elementsize)
44863+{
44864+ unsigned int table_sizes[] = {
44865+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
44866+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
44867+ 4194301, 8388593, 16777213, 33554393, 67108859
44868+ };
44869+ void *newtable = NULL;
44870+ unsigned int pwr = 0;
44871+
44872+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
44873+ table_sizes[pwr] <= *len)
44874+ pwr++;
44875+
44876+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
44877+ return newtable;
44878+
44879+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
44880+ newtable =
44881+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
44882+ else
44883+ newtable = vmalloc(table_sizes[pwr] * elementsize);
44884+
44885+ *len = table_sizes[pwr];
44886+
44887+ return newtable;
44888+}
44889+
44890+static int
44891+init_variables(const struct gr_arg *arg)
44892+{
44893+ struct task_struct *reaper = &init_task;
44894+ unsigned int stacksize;
44895+
44896+ subj_map_set.s_size = arg->role_db.num_subjects;
44897+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
44898+ name_set.n_size = arg->role_db.num_objects;
44899+ inodev_set.i_size = arg->role_db.num_objects;
44900+
44901+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
44902+ !name_set.n_size || !inodev_set.i_size)
44903+ return 1;
44904+
44905+ if (!gr_init_uidset())
44906+ return 1;
44907+
44908+ /* set up the stack that holds allocation info */
44909+
44910+ stacksize = arg->role_db.num_pointers + 5;
44911+
44912+ if (!acl_alloc_stack_init(stacksize))
44913+ return 1;
44914+
44915+ /* grab reference for the real root dentry and vfsmount */
44916+ get_fs_root(reaper->fs, &real_root);
44917+
44918+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
44919+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
44920+#endif
44921+
44922+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
44923+ if (fakefs_obj_rw == NULL)
44924+ return 1;
44925+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
44926+
44927+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
44928+ if (fakefs_obj_rwx == NULL)
44929+ return 1;
44930+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
44931+
44932+ subj_map_set.s_hash =
44933+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
44934+ acl_role_set.r_hash =
44935+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
44936+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
44937+ inodev_set.i_hash =
44938+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
44939+
44940+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
44941+ !name_set.n_hash || !inodev_set.i_hash)
44942+ return 1;
44943+
44944+ memset(subj_map_set.s_hash, 0,
44945+ sizeof(struct subject_map *) * subj_map_set.s_size);
44946+ memset(acl_role_set.r_hash, 0,
44947+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
44948+ memset(name_set.n_hash, 0,
44949+ sizeof (struct name_entry *) * name_set.n_size);
44950+ memset(inodev_set.i_hash, 0,
44951+ sizeof (struct inodev_entry *) * inodev_set.i_size);
44952+
44953+ return 0;
44954+}
44955+
44956+/* free information not needed after startup
44957+ currently contains user->kernel pointer mappings for subjects
44958+*/
44959+
44960+static void
44961+free_init_variables(void)
44962+{
44963+ __u32 i;
44964+
44965+ if (subj_map_set.s_hash) {
44966+ for (i = 0; i < subj_map_set.s_size; i++) {
44967+ if (subj_map_set.s_hash[i]) {
44968+ kfree(subj_map_set.s_hash[i]);
44969+ subj_map_set.s_hash[i] = NULL;
44970+ }
44971+ }
44972+
44973+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
44974+ PAGE_SIZE)
44975+ kfree(subj_map_set.s_hash);
44976+ else
44977+ vfree(subj_map_set.s_hash);
44978+ }
44979+
44980+ return;
44981+}
44982+
44983+static void
44984+free_variables(void)
44985+{
44986+ struct acl_subject_label *s;
44987+ struct acl_role_label *r;
44988+ struct task_struct *task, *task2;
44989+ unsigned int x;
44990+
44991+ gr_clear_learn_entries();
44992+
44993+ read_lock(&tasklist_lock);
44994+ do_each_thread(task2, task) {
44995+ task->acl_sp_role = 0;
44996+ task->acl_role_id = 0;
44997+ task->acl = NULL;
44998+ task->role = NULL;
44999+ } while_each_thread(task2, task);
45000+ read_unlock(&tasklist_lock);
45001+
45002+ /* release the reference to the real root dentry and vfsmount */
45003+ path_put(&real_root);
45004+
45005+ /* free all object hash tables */
45006+
45007+ FOR_EACH_ROLE_START(r)
45008+ if (r->subj_hash == NULL)
45009+ goto next_role;
45010+ FOR_EACH_SUBJECT_START(r, s, x)
45011+ if (s->obj_hash == NULL)
45012+ break;
45013+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
45014+ kfree(s->obj_hash);
45015+ else
45016+ vfree(s->obj_hash);
45017+ FOR_EACH_SUBJECT_END(s, x)
45018+ FOR_EACH_NESTED_SUBJECT_START(r, s)
45019+ if (s->obj_hash == NULL)
45020+ break;
45021+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
45022+ kfree(s->obj_hash);
45023+ else
45024+ vfree(s->obj_hash);
45025+ FOR_EACH_NESTED_SUBJECT_END(s)
45026+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
45027+ kfree(r->subj_hash);
45028+ else
45029+ vfree(r->subj_hash);
45030+ r->subj_hash = NULL;
45031+next_role:
45032+ FOR_EACH_ROLE_END(r)
45033+
45034+ acl_free_all();
45035+
45036+ if (acl_role_set.r_hash) {
45037+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
45038+ PAGE_SIZE)
45039+ kfree(acl_role_set.r_hash);
45040+ else
45041+ vfree(acl_role_set.r_hash);
45042+ }
45043+ if (name_set.n_hash) {
45044+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
45045+ PAGE_SIZE)
45046+ kfree(name_set.n_hash);
45047+ else
45048+ vfree(name_set.n_hash);
45049+ }
45050+
45051+ if (inodev_set.i_hash) {
45052+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
45053+ PAGE_SIZE)
45054+ kfree(inodev_set.i_hash);
45055+ else
45056+ vfree(inodev_set.i_hash);
45057+ }
45058+
45059+ gr_free_uidset();
45060+
45061+ memset(&name_set, 0, sizeof (struct name_db));
45062+ memset(&inodev_set, 0, sizeof (struct inodev_db));
45063+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
45064+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
45065+
45066+ default_role = NULL;
45067+ role_list = NULL;
45068+
45069+ return;
45070+}
45071+
45072+static __u32
45073+count_user_objs(struct acl_object_label *userp)
45074+{
45075+ struct acl_object_label o_tmp;
45076+ __u32 num = 0;
45077+
45078+ while (userp) {
45079+ if (copy_from_user(&o_tmp, userp,
45080+ sizeof (struct acl_object_label)))
45081+ break;
45082+
45083+ userp = o_tmp.prev;
45084+ num++;
45085+ }
45086+
45087+ return num;
45088+}
45089+
45090+static struct acl_subject_label *
45091+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
45092+
45093+static int
45094+copy_user_glob(struct acl_object_label *obj)
45095+{
45096+ struct acl_object_label *g_tmp, **guser;
45097+ unsigned int len;
45098+ char *tmp;
45099+
45100+ if (obj->globbed == NULL)
45101+ return 0;
45102+
45103+ guser = &obj->globbed;
45104+ while (*guser) {
45105+ g_tmp = (struct acl_object_label *)
45106+ acl_alloc(sizeof (struct acl_object_label));
45107+ if (g_tmp == NULL)
45108+ return -ENOMEM;
45109+
45110+ if (copy_from_user(g_tmp, *guser,
45111+ sizeof (struct acl_object_label)))
45112+ return -EFAULT;
45113+
45114+ len = strnlen_user(g_tmp->filename, PATH_MAX);
45115+
45116+ if (!len || len >= PATH_MAX)
45117+ return -EINVAL;
45118+
45119+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45120+ return -ENOMEM;
45121+
45122+ if (copy_from_user(tmp, g_tmp->filename, len))
45123+ return -EFAULT;
45124+ tmp[len-1] = '\0';
45125+ g_tmp->filename = tmp;
45126+
45127+ *guser = g_tmp;
45128+ guser = &(g_tmp->next);
45129+ }
45130+
45131+ return 0;
45132+}
45133+
45134+static int
45135+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
45136+ struct acl_role_label *role)
45137+{
45138+ struct acl_object_label *o_tmp;
45139+ unsigned int len;
45140+ int ret;
45141+ char *tmp;
45142+
45143+ while (userp) {
45144+ if ((o_tmp = (struct acl_object_label *)
45145+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
45146+ return -ENOMEM;
45147+
45148+ if (copy_from_user(o_tmp, userp,
45149+ sizeof (struct acl_object_label)))
45150+ return -EFAULT;
45151+
45152+ userp = o_tmp->prev;
45153+
45154+ len = strnlen_user(o_tmp->filename, PATH_MAX);
45155+
45156+ if (!len || len >= PATH_MAX)
45157+ return -EINVAL;
45158+
45159+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45160+ return -ENOMEM;
45161+
45162+ if (copy_from_user(tmp, o_tmp->filename, len))
45163+ return -EFAULT;
45164+ tmp[len-1] = '\0';
45165+ o_tmp->filename = tmp;
45166+
45167+ insert_acl_obj_label(o_tmp, subj);
45168+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
45169+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
45170+ return -ENOMEM;
45171+
45172+ ret = copy_user_glob(o_tmp);
45173+ if (ret)
45174+ return ret;
45175+
45176+ if (o_tmp->nested) {
45177+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
45178+ if (IS_ERR(o_tmp->nested))
45179+ return PTR_ERR(o_tmp->nested);
45180+
45181+ /* insert into nested subject list */
45182+ o_tmp->nested->next = role->hash->first;
45183+ role->hash->first = o_tmp->nested;
45184+ }
45185+ }
45186+
45187+ return 0;
45188+}
45189+
45190+static __u32
45191+count_user_subjs(struct acl_subject_label *userp)
45192+{
45193+ struct acl_subject_label s_tmp;
45194+ __u32 num = 0;
45195+
45196+ while (userp) {
45197+ if (copy_from_user(&s_tmp, userp,
45198+ sizeof (struct acl_subject_label)))
45199+ break;
45200+
45201+ userp = s_tmp.prev;
45202+ /* do not count nested subjects against this count, since
45203+ they are not included in the hash table, but are
45204+ attached to objects. We have already counted
45205+ the subjects in userspace for the allocation
45206+ stack
45207+ */
45208+ if (!(s_tmp.mode & GR_NESTED))
45209+ num++;
45210+ }
45211+
45212+ return num;
45213+}
45214+
45215+static int
45216+copy_user_allowedips(struct acl_role_label *rolep)
45217+{
45218+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
45219+
45220+ ruserip = rolep->allowed_ips;
45221+
45222+ while (ruserip) {
45223+ rlast = rtmp;
45224+
45225+ if ((rtmp = (struct role_allowed_ip *)
45226+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
45227+ return -ENOMEM;
45228+
45229+ if (copy_from_user(rtmp, ruserip,
45230+ sizeof (struct role_allowed_ip)))
45231+ return -EFAULT;
45232+
45233+ ruserip = rtmp->prev;
45234+
45235+ if (!rlast) {
45236+ rtmp->prev = NULL;
45237+ rolep->allowed_ips = rtmp;
45238+ } else {
45239+ rlast->next = rtmp;
45240+ rtmp->prev = rlast;
45241+ }
45242+
45243+ if (!ruserip)
45244+ rtmp->next = NULL;
45245+ }
45246+
45247+ return 0;
45248+}
45249+
45250+static int
45251+copy_user_transitions(struct acl_role_label *rolep)
45252+{
45253+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
45254+
45255+ unsigned int len;
45256+ char *tmp;
45257+
45258+ rusertp = rolep->transitions;
45259+
45260+ while (rusertp) {
45261+ rlast = rtmp;
45262+
45263+ if ((rtmp = (struct role_transition *)
45264+ acl_alloc(sizeof (struct role_transition))) == NULL)
45265+ return -ENOMEM;
45266+
45267+ if (copy_from_user(rtmp, rusertp,
45268+ sizeof (struct role_transition)))
45269+ return -EFAULT;
45270+
45271+ rusertp = rtmp->prev;
45272+
45273+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
45274+
45275+ if (!len || len >= GR_SPROLE_LEN)
45276+ return -EINVAL;
45277+
45278+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45279+ return -ENOMEM;
45280+
45281+ if (copy_from_user(tmp, rtmp->rolename, len))
45282+ return -EFAULT;
45283+ tmp[len-1] = '\0';
45284+ rtmp->rolename = tmp;
45285+
45286+ if (!rlast) {
45287+ rtmp->prev = NULL;
45288+ rolep->transitions = rtmp;
45289+ } else {
45290+ rlast->next = rtmp;
45291+ rtmp->prev = rlast;
45292+ }
45293+
45294+ if (!rusertp)
45295+ rtmp->next = NULL;
45296+ }
45297+
45298+ return 0;
45299+}
45300+
45301+static struct acl_subject_label *
45302+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
45303+{
45304+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
45305+ unsigned int len;
45306+ char *tmp;
45307+ __u32 num_objs;
45308+ struct acl_ip_label **i_tmp, *i_utmp2;
45309+ struct gr_hash_struct ghash;
45310+ struct subject_map *subjmap;
45311+ unsigned int i_num;
45312+ int err;
45313+
45314+ s_tmp = lookup_subject_map(userp);
45315+
45316+ /* we've already copied this subject into the kernel, just return
45317+ the reference to it, and don't copy it over again
45318+ */
45319+ if (s_tmp)
45320+ return(s_tmp);
45321+
45322+ if ((s_tmp = (struct acl_subject_label *)
45323+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
45324+ return ERR_PTR(-ENOMEM);
45325+
45326+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
45327+ if (subjmap == NULL)
45328+ return ERR_PTR(-ENOMEM);
45329+
45330+ subjmap->user = userp;
45331+ subjmap->kernel = s_tmp;
45332+ insert_subj_map_entry(subjmap);
45333+
45334+ if (copy_from_user(s_tmp, userp,
45335+ sizeof (struct acl_subject_label)))
45336+ return ERR_PTR(-EFAULT);
45337+
45338+ len = strnlen_user(s_tmp->filename, PATH_MAX);
45339+
45340+ if (!len || len >= PATH_MAX)
45341+ return ERR_PTR(-EINVAL);
45342+
45343+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45344+ return ERR_PTR(-ENOMEM);
45345+
45346+ if (copy_from_user(tmp, s_tmp->filename, len))
45347+ return ERR_PTR(-EFAULT);
45348+ tmp[len-1] = '\0';
45349+ s_tmp->filename = tmp;
45350+
45351+ if (!strcmp(s_tmp->filename, "/"))
45352+ role->root_label = s_tmp;
45353+
45354+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
45355+ return ERR_PTR(-EFAULT);
45356+
45357+ /* copy user and group transition tables */
45358+
45359+ if (s_tmp->user_trans_num) {
45360+ uid_t *uidlist;
45361+
45362+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
45363+ if (uidlist == NULL)
45364+ return ERR_PTR(-ENOMEM);
45365+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
45366+ return ERR_PTR(-EFAULT);
45367+
45368+ s_tmp->user_transitions = uidlist;
45369+ }
45370+
45371+ if (s_tmp->group_trans_num) {
45372+ gid_t *gidlist;
45373+
45374+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
45375+ if (gidlist == NULL)
45376+ return ERR_PTR(-ENOMEM);
45377+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
45378+ return ERR_PTR(-EFAULT);
45379+
45380+ s_tmp->group_transitions = gidlist;
45381+ }
45382+
45383+ /* set up object hash table */
45384+ num_objs = count_user_objs(ghash.first);
45385+
45386+ s_tmp->obj_hash_size = num_objs;
45387+ s_tmp->obj_hash =
45388+ (struct acl_object_label **)
45389+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
45390+
45391+ if (!s_tmp->obj_hash)
45392+ return ERR_PTR(-ENOMEM);
45393+
45394+ memset(s_tmp->obj_hash, 0,
45395+ s_tmp->obj_hash_size *
45396+ sizeof (struct acl_object_label *));
45397+
45398+ /* add in objects */
45399+ err = copy_user_objs(ghash.first, s_tmp, role);
45400+
45401+ if (err)
45402+ return ERR_PTR(err);
45403+
45404+ /* set pointer for parent subject */
45405+ if (s_tmp->parent_subject) {
45406+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
45407+
45408+ if (IS_ERR(s_tmp2))
45409+ return s_tmp2;
45410+
45411+ s_tmp->parent_subject = s_tmp2;
45412+ }
45413+
45414+ /* add in ip acls */
45415+
45416+ if (!s_tmp->ip_num) {
45417+ s_tmp->ips = NULL;
45418+ goto insert;
45419+ }
45420+
45421+ i_tmp =
45422+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
45423+ sizeof (struct acl_ip_label *));
45424+
45425+ if (!i_tmp)
45426+ return ERR_PTR(-ENOMEM);
45427+
45428+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
45429+ *(i_tmp + i_num) =
45430+ (struct acl_ip_label *)
45431+ acl_alloc(sizeof (struct acl_ip_label));
45432+ if (!*(i_tmp + i_num))
45433+ return ERR_PTR(-ENOMEM);
45434+
45435+ if (copy_from_user
45436+ (&i_utmp2, s_tmp->ips + i_num,
45437+ sizeof (struct acl_ip_label *)))
45438+ return ERR_PTR(-EFAULT);
45439+
45440+ if (copy_from_user
45441+ (*(i_tmp + i_num), i_utmp2,
45442+ sizeof (struct acl_ip_label)))
45443+ return ERR_PTR(-EFAULT);
45444+
45445+ if ((*(i_tmp + i_num))->iface == NULL)
45446+ continue;
45447+
45448+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
45449+ if (!len || len >= IFNAMSIZ)
45450+ return ERR_PTR(-EINVAL);
45451+ tmp = acl_alloc(len);
45452+ if (tmp == NULL)
45453+ return ERR_PTR(-ENOMEM);
45454+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
45455+ return ERR_PTR(-EFAULT);
45456+ (*(i_tmp + i_num))->iface = tmp;
45457+ }
45458+
45459+ s_tmp->ips = i_tmp;
45460+
45461+insert:
45462+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
45463+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
45464+ return ERR_PTR(-ENOMEM);
45465+
45466+ return s_tmp;
45467+}
45468+
45469+static int
45470+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
45471+{
45472+ struct acl_subject_label s_pre;
45473+ struct acl_subject_label * ret;
45474+ int err;
45475+
45476+ while (userp) {
45477+ if (copy_from_user(&s_pre, userp,
45478+ sizeof (struct acl_subject_label)))
45479+ return -EFAULT;
45480+
45481+ /* do not add nested subjects here, add
45482+ while parsing objects
45483+ */
45484+
45485+ if (s_pre.mode & GR_NESTED) {
45486+ userp = s_pre.prev;
45487+ continue;
45488+ }
45489+
45490+ ret = do_copy_user_subj(userp, role);
45491+
45492+ err = PTR_ERR(ret);
45493+ if (IS_ERR(ret))
45494+ return err;
45495+
45496+ insert_acl_subj_label(ret, role);
45497+
45498+ userp = s_pre.prev;
45499+ }
45500+
45501+ return 0;
45502+}
45503+
45504+static int
45505+copy_user_acl(struct gr_arg *arg)
45506+{
45507+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
45508+ struct sprole_pw *sptmp;
45509+ struct gr_hash_struct *ghash;
45510+ uid_t *domainlist;
45511+ unsigned int r_num;
45512+ unsigned int len;
45513+ char *tmp;
45514+ int err = 0;
45515+ __u16 i;
45516+ __u32 num_subjs;
45517+
45518+ /* we need a default and kernel role */
45519+ if (arg->role_db.num_roles < 2)
45520+ return -EINVAL;
45521+
45522+ /* copy special role authentication info from userspace */
45523+
45524+ num_sprole_pws = arg->num_sprole_pws;
45525+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
45526+
45527+ if (!acl_special_roles) {
45528+ err = -ENOMEM;
45529+ goto cleanup;
45530+ }
45531+
45532+ for (i = 0; i < num_sprole_pws; i++) {
45533+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
45534+ if (!sptmp) {
45535+ err = -ENOMEM;
45536+ goto cleanup;
45537+ }
45538+ if (copy_from_user(sptmp, arg->sprole_pws + i,
45539+ sizeof (struct sprole_pw))) {
45540+ err = -EFAULT;
45541+ goto cleanup;
45542+ }
45543+
45544+ len =
45545+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
45546+
45547+ if (!len || len >= GR_SPROLE_LEN) {
45548+ err = -EINVAL;
45549+ goto cleanup;
45550+ }
45551+
45552+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
45553+ err = -ENOMEM;
45554+ goto cleanup;
45555+ }
45556+
45557+ if (copy_from_user(tmp, sptmp->rolename, len)) {
45558+ err = -EFAULT;
45559+ goto cleanup;
45560+ }
45561+ tmp[len-1] = '\0';
45562+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
45563+ printk(KERN_ALERT "Copying special role %s\n", tmp);
45564+#endif
45565+ sptmp->rolename = tmp;
45566+ acl_special_roles[i] = sptmp;
45567+ }
45568+
45569+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
45570+
45571+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
45572+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
45573+
45574+ if (!r_tmp) {
45575+ err = -ENOMEM;
45576+ goto cleanup;
45577+ }
45578+
45579+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
45580+ sizeof (struct acl_role_label *))) {
45581+ err = -EFAULT;
45582+ goto cleanup;
45583+ }
45584+
45585+ if (copy_from_user(r_tmp, r_utmp2,
45586+ sizeof (struct acl_role_label))) {
45587+ err = -EFAULT;
45588+ goto cleanup;
45589+ }
45590+
45591+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
45592+
45593+ if (!len || len >= PATH_MAX) {
45594+ err = -EINVAL;
45595+ goto cleanup;
45596+ }
45597+
45598+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
45599+ err = -ENOMEM;
45600+ goto cleanup;
45601+ }
45602+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
45603+ err = -EFAULT;
45604+ goto cleanup;
45605+ }
45606+ tmp[len-1] = '\0';
45607+ r_tmp->rolename = tmp;
45608+
45609+ if (!strcmp(r_tmp->rolename, "default")
45610+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
45611+ default_role = r_tmp;
45612+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
45613+ kernel_role = r_tmp;
45614+ }
45615+
45616+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
45617+ err = -ENOMEM;
45618+ goto cleanup;
45619+ }
45620+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
45621+ err = -EFAULT;
45622+ goto cleanup;
45623+ }
45624+
45625+ r_tmp->hash = ghash;
45626+
45627+ num_subjs = count_user_subjs(r_tmp->hash->first);
45628+
45629+ r_tmp->subj_hash_size = num_subjs;
45630+ r_tmp->subj_hash =
45631+ (struct acl_subject_label **)
45632+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
45633+
45634+ if (!r_tmp->subj_hash) {
45635+ err = -ENOMEM;
45636+ goto cleanup;
45637+ }
45638+
45639+ err = copy_user_allowedips(r_tmp);
45640+ if (err)
45641+ goto cleanup;
45642+
45643+ /* copy domain info */
45644+ if (r_tmp->domain_children != NULL) {
45645+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
45646+ if (domainlist == NULL) {
45647+ err = -ENOMEM;
45648+ goto cleanup;
45649+ }
45650+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
45651+ err = -EFAULT;
45652+ goto cleanup;
45653+ }
45654+ r_tmp->domain_children = domainlist;
45655+ }
45656+
45657+ err = copy_user_transitions(r_tmp);
45658+ if (err)
45659+ goto cleanup;
45660+
45661+ memset(r_tmp->subj_hash, 0,
45662+ r_tmp->subj_hash_size *
45663+ sizeof (struct acl_subject_label *));
45664+
45665+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
45666+
45667+ if (err)
45668+ goto cleanup;
45669+
45670+ /* set nested subject list to null */
45671+ r_tmp->hash->first = NULL;
45672+
45673+ insert_acl_role_label(r_tmp);
45674+ }
45675+
45676+ goto return_err;
45677+ cleanup:
45678+ free_variables();
45679+ return_err:
45680+ return err;
45681+
45682+}
45683+
45684+static int
45685+gracl_init(struct gr_arg *args)
45686+{
45687+ int error = 0;
45688+
45689+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
45690+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
45691+
45692+ if (init_variables(args)) {
45693+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
45694+ error = -ENOMEM;
45695+ free_variables();
45696+ goto out;
45697+ }
45698+
45699+ error = copy_user_acl(args);
45700+ free_init_variables();
45701+ if (error) {
45702+ free_variables();
45703+ goto out;
45704+ }
45705+
45706+ if ((error = gr_set_acls(0))) {
45707+ free_variables();
45708+ goto out;
45709+ }
45710+
45711+ pax_open_kernel();
45712+ gr_status |= GR_READY;
45713+ pax_close_kernel();
45714+
45715+ out:
45716+ return error;
45717+}
45718+
45719+/* derived from glibc fnmatch() 0: match, 1: no match*/
45720+
45721+static int
45722+glob_match(const char *p, const char *n)
45723+{
45724+ char c;
45725+
45726+ while ((c = *p++) != '\0') {
45727+ switch (c) {
45728+ case '?':
45729+ if (*n == '\0')
45730+ return 1;
45731+ else if (*n == '/')
45732+ return 1;
45733+ break;
45734+ case '\\':
45735+ if (*n != c)
45736+ return 1;
45737+ break;
45738+ case '*':
45739+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
45740+ if (*n == '/')
45741+ return 1;
45742+ else if (c == '?') {
45743+ if (*n == '\0')
45744+ return 1;
45745+ else
45746+ ++n;
45747+ }
45748+ }
45749+ if (c == '\0') {
45750+ return 0;
45751+ } else {
45752+ const char *endp;
45753+
45754+ if ((endp = strchr(n, '/')) == NULL)
45755+ endp = n + strlen(n);
45756+
45757+ if (c == '[') {
45758+ for (--p; n < endp; ++n)
45759+ if (!glob_match(p, n))
45760+ return 0;
45761+ } else if (c == '/') {
45762+ while (*n != '\0' && *n != '/')
45763+ ++n;
45764+ if (*n == '/' && !glob_match(p, n + 1))
45765+ return 0;
45766+ } else {
45767+ for (--p; n < endp; ++n)
45768+ if (*n == c && !glob_match(p, n))
45769+ return 0;
45770+ }
45771+
45772+ return 1;
45773+ }
45774+ case '[':
45775+ {
45776+ int not;
45777+ char cold;
45778+
45779+ if (*n == '\0' || *n == '/')
45780+ return 1;
45781+
45782+ not = (*p == '!' || *p == '^');
45783+ if (not)
45784+ ++p;
45785+
45786+ c = *p++;
45787+ for (;;) {
45788+ unsigned char fn = (unsigned char)*n;
45789+
45790+ if (c == '\0')
45791+ return 1;
45792+ else {
45793+ if (c == fn)
45794+ goto matched;
45795+ cold = c;
45796+ c = *p++;
45797+
45798+ if (c == '-' && *p != ']') {
45799+ unsigned char cend = *p++;
45800+
45801+ if (cend == '\0')
45802+ return 1;
45803+
45804+ if (cold <= fn && fn <= cend)
45805+ goto matched;
45806+
45807+ c = *p++;
45808+ }
45809+ }
45810+
45811+ if (c == ']')
45812+ break;
45813+ }
45814+ if (!not)
45815+ return 1;
45816+ break;
45817+ matched:
45818+ while (c != ']') {
45819+ if (c == '\0')
45820+ return 1;
45821+
45822+ c = *p++;
45823+ }
45824+ if (not)
45825+ return 1;
45826+ }
45827+ break;
45828+ default:
45829+ if (c != *n)
45830+ return 1;
45831+ }
45832+
45833+ ++n;
45834+ }
45835+
45836+ if (*n == '\0')
45837+ return 0;
45838+
45839+ if (*n == '/')
45840+ return 0;
45841+
45842+ return 1;
45843+}
45844+
45845+static struct acl_object_label *
45846+chk_glob_label(struct acl_object_label *globbed,
45847+ struct dentry *dentry, struct vfsmount *mnt, char **path)
45848+{
45849+ struct acl_object_label *tmp;
45850+
45851+ if (*path == NULL)
45852+ *path = gr_to_filename_nolock(dentry, mnt);
45853+
45854+ tmp = globbed;
45855+
45856+ while (tmp) {
45857+ if (!glob_match(tmp->filename, *path))
45858+ return tmp;
45859+ tmp = tmp->next;
45860+ }
45861+
45862+ return NULL;
45863+}
45864+
45865+static struct acl_object_label *
45866+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
45867+ const ino_t curr_ino, const dev_t curr_dev,
45868+ const struct acl_subject_label *subj, char **path, const int checkglob)
45869+{
45870+ struct acl_subject_label *tmpsubj;
45871+ struct acl_object_label *retval;
45872+ struct acl_object_label *retval2;
45873+
45874+ tmpsubj = (struct acl_subject_label *) subj;
45875+ read_lock(&gr_inode_lock);
45876+ do {
45877+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
45878+ if (retval) {
45879+ if (checkglob && retval->globbed) {
45880+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
45881+ (struct vfsmount *)orig_mnt, path);
45882+ if (retval2)
45883+ retval = retval2;
45884+ }
45885+ break;
45886+ }
45887+ } while ((tmpsubj = tmpsubj->parent_subject));
45888+ read_unlock(&gr_inode_lock);
45889+
45890+ return retval;
45891+}
45892+
45893+static __inline__ struct acl_object_label *
45894+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
45895+ struct dentry *curr_dentry,
45896+ const struct acl_subject_label *subj, char **path, const int checkglob)
45897+{
45898+ int newglob = checkglob;
45899+ ino_t inode;
45900+ dev_t device;
45901+
45902+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
45903+ as we don't want a / * rule to match instead of the / object
45904+ don't do this for create lookups that call this function though, since they're looking up
45905+ on the parent and thus need globbing checks on all paths
45906+ */
45907+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
45908+ newglob = GR_NO_GLOB;
45909+
45910+ spin_lock(&curr_dentry->d_lock);
45911+ inode = curr_dentry->d_inode->i_ino;
45912+ device = __get_dev(curr_dentry);
45913+ spin_unlock(&curr_dentry->d_lock);
45914+
45915+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
45916+}
45917+
45918+static struct acl_object_label *
45919+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45920+ const struct acl_subject_label *subj, char *path, const int checkglob)
45921+{
45922+ struct dentry *dentry = (struct dentry *) l_dentry;
45923+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
45924+ struct acl_object_label *retval;
45925+ struct dentry *parent;
45926+
45927+ write_seqlock(&rename_lock);
45928+ br_read_lock(vfsmount_lock);
45929+
45930+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
45931+#ifdef CONFIG_NET
45932+ mnt == sock_mnt ||
45933+#endif
45934+#ifdef CONFIG_HUGETLBFS
45935+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
45936+#endif
45937+ /* ignore Eric Biederman */
45938+ IS_PRIVATE(l_dentry->d_inode))) {
45939+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
45940+ goto out;
45941+ }
45942+
45943+ for (;;) {
45944+ if (dentry == real_root.dentry && mnt == real_root.mnt)
45945+ break;
45946+
45947+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
45948+ if (mnt->mnt_parent == mnt)
45949+ break;
45950+
45951+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45952+ if (retval != NULL)
45953+ goto out;
45954+
45955+ dentry = mnt->mnt_mountpoint;
45956+ mnt = mnt->mnt_parent;
45957+ continue;
45958+ }
45959+
45960+ parent = dentry->d_parent;
45961+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45962+ if (retval != NULL)
45963+ goto out;
45964+
45965+ dentry = parent;
45966+ }
45967+
45968+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45969+
45970+ /* real_root is pinned so we don't have to hold a reference */
45971+ if (retval == NULL)
45972+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
45973+out:
45974+ br_read_unlock(vfsmount_lock);
45975+ write_sequnlock(&rename_lock);
45976+
45977+ BUG_ON(retval == NULL);
45978+
45979+ return retval;
45980+}
45981+
45982+static __inline__ struct acl_object_label *
45983+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45984+ const struct acl_subject_label *subj)
45985+{
45986+ char *path = NULL;
45987+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
45988+}
45989+
45990+static __inline__ struct acl_object_label *
45991+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45992+ const struct acl_subject_label *subj)
45993+{
45994+ char *path = NULL;
45995+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
45996+}
45997+
45998+static __inline__ struct acl_object_label *
45999+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
46000+ const struct acl_subject_label *subj, char *path)
46001+{
46002+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
46003+}
46004+
46005+static struct acl_subject_label *
46006+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
46007+ const struct acl_role_label *role)
46008+{
46009+ struct dentry *dentry = (struct dentry *) l_dentry;
46010+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
46011+ struct acl_subject_label *retval;
46012+ struct dentry *parent;
46013+
46014+ write_seqlock(&rename_lock);
46015+ br_read_lock(vfsmount_lock);
46016+
46017+ for (;;) {
46018+ if (dentry == real_root.dentry && mnt == real_root.mnt)
46019+ break;
46020+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
46021+ if (mnt->mnt_parent == mnt)
46022+ break;
46023+
46024+ spin_lock(&dentry->d_lock);
46025+ read_lock(&gr_inode_lock);
46026+ retval =
46027+ lookup_acl_subj_label(dentry->d_inode->i_ino,
46028+ __get_dev(dentry), role);
46029+ read_unlock(&gr_inode_lock);
46030+ spin_unlock(&dentry->d_lock);
46031+ if (retval != NULL)
46032+ goto out;
46033+
46034+ dentry = mnt->mnt_mountpoint;
46035+ mnt = mnt->mnt_parent;
46036+ continue;
46037+ }
46038+
46039+ spin_lock(&dentry->d_lock);
46040+ read_lock(&gr_inode_lock);
46041+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
46042+ __get_dev(dentry), role);
46043+ read_unlock(&gr_inode_lock);
46044+ parent = dentry->d_parent;
46045+ spin_unlock(&dentry->d_lock);
46046+
46047+ if (retval != NULL)
46048+ goto out;
46049+
46050+ dentry = parent;
46051+ }
46052+
46053+ spin_lock(&dentry->d_lock);
46054+ read_lock(&gr_inode_lock);
46055+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
46056+ __get_dev(dentry), role);
46057+ read_unlock(&gr_inode_lock);
46058+ spin_unlock(&dentry->d_lock);
46059+
46060+ if (unlikely(retval == NULL)) {
46061+ /* real_root is pinned, we don't need to hold a reference */
46062+ read_lock(&gr_inode_lock);
46063+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
46064+ __get_dev(real_root.dentry), role);
46065+ read_unlock(&gr_inode_lock);
46066+ }
46067+out:
46068+ br_read_unlock(vfsmount_lock);
46069+ write_sequnlock(&rename_lock);
46070+
46071+ BUG_ON(retval == NULL);
46072+
46073+ return retval;
46074+}
46075+
46076+static void
46077+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
46078+{
46079+ struct task_struct *task = current;
46080+ const struct cred *cred = current_cred();
46081+
46082+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
46083+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
46084+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
46085+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
46086+
46087+ return;
46088+}
46089+
46090+static void
46091+gr_log_learn_sysctl(const char *path, const __u32 mode)
46092+{
46093+ struct task_struct *task = current;
46094+ const struct cred *cred = current_cred();
46095+
46096+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
46097+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
46098+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
46099+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
46100+
46101+ return;
46102+}
46103+
46104+static void
46105+gr_log_learn_id_change(const char type, const unsigned int real,
46106+ const unsigned int effective, const unsigned int fs)
46107+{
46108+ struct task_struct *task = current;
46109+ const struct cred *cred = current_cred();
46110+
46111+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
46112+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
46113+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
46114+ type, real, effective, fs, &task->signal->saved_ip);
46115+
46116+ return;
46117+}
46118+
46119+__u32
46120+gr_check_link(const struct dentry * new_dentry,
46121+ const struct dentry * parent_dentry,
46122+ const struct vfsmount * parent_mnt,
46123+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
46124+{
46125+ struct acl_object_label *obj;
46126+ __u32 oldmode, newmode;
46127+ __u32 needmode;
46128+
46129+ if (unlikely(!(gr_status & GR_READY)))
46130+ return (GR_CREATE | GR_LINK);
46131+
46132+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
46133+ oldmode = obj->mode;
46134+
46135+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
46136+ oldmode |= (GR_CREATE | GR_LINK);
46137+
46138+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
46139+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
46140+ needmode |= GR_SETID | GR_AUDIT_SETID;
46141+
46142+ newmode =
46143+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
46144+ oldmode | needmode);
46145+
46146+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
46147+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
46148+ GR_INHERIT | GR_AUDIT_INHERIT);
46149+
46150+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
46151+ goto bad;
46152+
46153+ if ((oldmode & needmode) != needmode)
46154+ goto bad;
46155+
46156+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
46157+ if ((newmode & needmode) != needmode)
46158+ goto bad;
46159+
46160+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
46161+ return newmode;
46162+bad:
46163+ needmode = oldmode;
46164+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
46165+ needmode |= GR_SETID;
46166+
46167+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
46168+ gr_log_learn(old_dentry, old_mnt, needmode);
46169+ return (GR_CREATE | GR_LINK);
46170+ } else if (newmode & GR_SUPPRESS)
46171+ return GR_SUPPRESS;
46172+ else
46173+ return 0;
46174+}
46175+
46176+__u32
46177+gr_search_file(const struct dentry * dentry, const __u32 mode,
46178+ const struct vfsmount * mnt)
46179+{
46180+ __u32 retval = mode;
46181+ struct acl_subject_label *curracl;
46182+ struct acl_object_label *currobj;
46183+
46184+ if (unlikely(!(gr_status & GR_READY)))
46185+ return (mode & ~GR_AUDITS);
46186+
46187+ curracl = current->acl;
46188+
46189+ currobj = chk_obj_label(dentry, mnt, curracl);
46190+ retval = currobj->mode & mode;
46191+
46192+ /* if we're opening a specified transfer file for writing
46193+ (e.g. /dev/initctl), then transfer our role to init
46194+ */
46195+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
46196+ current->role->roletype & GR_ROLE_PERSIST)) {
46197+ struct task_struct *task = init_pid_ns.child_reaper;
46198+
46199+ if (task->role != current->role) {
46200+ task->acl_sp_role = 0;
46201+ task->acl_role_id = current->acl_role_id;
46202+ task->role = current->role;
46203+ rcu_read_lock();
46204+ read_lock(&grsec_exec_file_lock);
46205+ gr_apply_subject_to_task(task);
46206+ read_unlock(&grsec_exec_file_lock);
46207+ rcu_read_unlock();
46208+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
46209+ }
46210+ }
46211+
46212+ if (unlikely
46213+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
46214+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
46215+ __u32 new_mode = mode;
46216+
46217+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
46218+
46219+ retval = new_mode;
46220+
46221+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
46222+ new_mode |= GR_INHERIT;
46223+
46224+ if (!(mode & GR_NOLEARN))
46225+ gr_log_learn(dentry, mnt, new_mode);
46226+ }
46227+
46228+ return retval;
46229+}
46230+
46231+__u32
46232+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
46233+ const struct vfsmount * mnt, const __u32 mode)
46234+{
46235+ struct name_entry *match;
46236+ struct acl_object_label *matchpo;
46237+ struct acl_subject_label *curracl;
46238+ char *path;
46239+ __u32 retval;
46240+
46241+ if (unlikely(!(gr_status & GR_READY)))
46242+ return (mode & ~GR_AUDITS);
46243+
46244+ preempt_disable();
46245+ path = gr_to_filename_rbac(new_dentry, mnt);
46246+ match = lookup_name_entry_create(path);
46247+
46248+ if (!match)
46249+ goto check_parent;
46250+
46251+ curracl = current->acl;
46252+
46253+ read_lock(&gr_inode_lock);
46254+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
46255+ read_unlock(&gr_inode_lock);
46256+
46257+ if (matchpo) {
46258+ if ((matchpo->mode & mode) !=
46259+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
46260+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
46261+ __u32 new_mode = mode;
46262+
46263+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
46264+
46265+ gr_log_learn(new_dentry, mnt, new_mode);
46266+
46267+ preempt_enable();
46268+ return new_mode;
46269+ }
46270+ preempt_enable();
46271+ return (matchpo->mode & mode);
46272+ }
46273+
46274+ check_parent:
46275+ curracl = current->acl;
46276+
46277+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
46278+ retval = matchpo->mode & mode;
46279+
46280+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
46281+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
46282+ __u32 new_mode = mode;
46283+
46284+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
46285+
46286+ gr_log_learn(new_dentry, mnt, new_mode);
46287+ preempt_enable();
46288+ return new_mode;
46289+ }
46290+
46291+ preempt_enable();
46292+ return retval;
46293+}
46294+
46295+int
46296+gr_check_hidden_task(const struct task_struct *task)
46297+{
46298+ if (unlikely(!(gr_status & GR_READY)))
46299+ return 0;
46300+
46301+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
46302+ return 1;
46303+
46304+ return 0;
46305+}
46306+
46307+int
46308+gr_check_protected_task(const struct task_struct *task)
46309+{
46310+ if (unlikely(!(gr_status & GR_READY) || !task))
46311+ return 0;
46312+
46313+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
46314+ task->acl != current->acl)
46315+ return 1;
46316+
46317+ return 0;
46318+}
46319+
46320+int
46321+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
46322+{
46323+ struct task_struct *p;
46324+ int ret = 0;
46325+
46326+ if (unlikely(!(gr_status & GR_READY) || !pid))
46327+ return ret;
46328+
46329+ read_lock(&tasklist_lock);
46330+ do_each_pid_task(pid, type, p) {
46331+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
46332+ p->acl != current->acl) {
46333+ ret = 1;
46334+ goto out;
46335+ }
46336+ } while_each_pid_task(pid, type, p);
46337+out:
46338+ read_unlock(&tasklist_lock);
46339+
46340+ return ret;
46341+}
46342+
46343+void
46344+gr_copy_label(struct task_struct *tsk)
46345+{
46346+ tsk->signal->used_accept = 0;
46347+ tsk->acl_sp_role = 0;
46348+ tsk->acl_role_id = current->acl_role_id;
46349+ tsk->acl = current->acl;
46350+ tsk->role = current->role;
46351+ tsk->signal->curr_ip = current->signal->curr_ip;
46352+ tsk->signal->saved_ip = current->signal->saved_ip;
46353+ if (current->exec_file)
46354+ get_file(current->exec_file);
46355+ tsk->exec_file = current->exec_file;
46356+ tsk->is_writable = current->is_writable;
46357+ if (unlikely(current->signal->used_accept)) {
46358+ current->signal->curr_ip = 0;
46359+ current->signal->saved_ip = 0;
46360+ }
46361+
46362+ return;
46363+}
46364+
46365+static void
46366+gr_set_proc_res(struct task_struct *task)
46367+{
46368+ struct acl_subject_label *proc;
46369+ unsigned short i;
46370+
46371+ proc = task->acl;
46372+
46373+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
46374+ return;
46375+
46376+ for (i = 0; i < RLIM_NLIMITS; i++) {
46377+ if (!(proc->resmask & (1 << i)))
46378+ continue;
46379+
46380+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
46381+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
46382+ }
46383+
46384+ return;
46385+}
46386+
46387+extern int __gr_process_user_ban(struct user_struct *user);
46388+
46389+int
46390+gr_check_user_change(int real, int effective, int fs)
46391+{
46392+ unsigned int i;
46393+ __u16 num;
46394+ uid_t *uidlist;
46395+ int curuid;
46396+ int realok = 0;
46397+ int effectiveok = 0;
46398+ int fsok = 0;
46399+
46400+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
46401+ struct user_struct *user;
46402+
46403+ if (real == -1)
46404+ goto skipit;
46405+
46406+ user = find_user(real);
46407+ if (user == NULL)
46408+ goto skipit;
46409+
46410+ if (__gr_process_user_ban(user)) {
46411+ /* for find_user */
46412+ free_uid(user);
46413+ return 1;
46414+ }
46415+
46416+ /* for find_user */
46417+ free_uid(user);
46418+
46419+skipit:
46420+#endif
46421+
46422+ if (unlikely(!(gr_status & GR_READY)))
46423+ return 0;
46424+
46425+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
46426+ gr_log_learn_id_change('u', real, effective, fs);
46427+
46428+ num = current->acl->user_trans_num;
46429+ uidlist = current->acl->user_transitions;
46430+
46431+ if (uidlist == NULL)
46432+ return 0;
46433+
46434+ if (real == -1)
46435+ realok = 1;
46436+ if (effective == -1)
46437+ effectiveok = 1;
46438+ if (fs == -1)
46439+ fsok = 1;
46440+
46441+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
46442+ for (i = 0; i < num; i++) {
46443+ curuid = (int)uidlist[i];
46444+ if (real == curuid)
46445+ realok = 1;
46446+ if (effective == curuid)
46447+ effectiveok = 1;
46448+ if (fs == curuid)
46449+ fsok = 1;
46450+ }
46451+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
46452+ for (i = 0; i < num; i++) {
46453+ curuid = (int)uidlist[i];
46454+ if (real == curuid)
46455+ break;
46456+ if (effective == curuid)
46457+ break;
46458+ if (fs == curuid)
46459+ break;
46460+ }
46461+ /* not in deny list */
46462+ if (i == num) {
46463+ realok = 1;
46464+ effectiveok = 1;
46465+ fsok = 1;
46466+ }
46467+ }
46468+
46469+ if (realok && effectiveok && fsok)
46470+ return 0;
46471+ else {
46472+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
46473+ return 1;
46474+ }
46475+}
46476+
46477+int
46478+gr_check_group_change(int real, int effective, int fs)
46479+{
46480+ unsigned int i;
46481+ __u16 num;
46482+ gid_t *gidlist;
46483+ int curgid;
46484+ int realok = 0;
46485+ int effectiveok = 0;
46486+ int fsok = 0;
46487+
46488+ if (unlikely(!(gr_status & GR_READY)))
46489+ return 0;
46490+
46491+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
46492+ gr_log_learn_id_change('g', real, effective, fs);
46493+
46494+ num = current->acl->group_trans_num;
46495+ gidlist = current->acl->group_transitions;
46496+
46497+ if (gidlist == NULL)
46498+ return 0;
46499+
46500+ if (real == -1)
46501+ realok = 1;
46502+ if (effective == -1)
46503+ effectiveok = 1;
46504+ if (fs == -1)
46505+ fsok = 1;
46506+
46507+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
46508+ for (i = 0; i < num; i++) {
46509+ curgid = (int)gidlist[i];
46510+ if (real == curgid)
46511+ realok = 1;
46512+ if (effective == curgid)
46513+ effectiveok = 1;
46514+ if (fs == curgid)
46515+ fsok = 1;
46516+ }
46517+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
46518+ for (i = 0; i < num; i++) {
46519+ curgid = (int)gidlist[i];
46520+ if (real == curgid)
46521+ break;
46522+ if (effective == curgid)
46523+ break;
46524+ if (fs == curgid)
46525+ break;
46526+ }
46527+ /* not in deny list */
46528+ if (i == num) {
46529+ realok = 1;
46530+ effectiveok = 1;
46531+ fsok = 1;
46532+ }
46533+ }
46534+
46535+ if (realok && effectiveok && fsok)
46536+ return 0;
46537+ else {
46538+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
46539+ return 1;
46540+ }
46541+}
46542+
46543+void
46544+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
46545+{
46546+ struct acl_role_label *role = task->role;
46547+ struct acl_subject_label *subj = NULL;
46548+ struct acl_object_label *obj;
46549+ struct file *filp;
46550+
46551+ if (unlikely(!(gr_status & GR_READY)))
46552+ return;
46553+
46554+ filp = task->exec_file;
46555+
46556+ /* kernel process, we'll give them the kernel role */
46557+ if (unlikely(!filp)) {
46558+ task->role = kernel_role;
46559+ task->acl = kernel_role->root_label;
46560+ return;
46561+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
46562+ role = lookup_acl_role_label(task, uid, gid);
46563+
46564+ /* perform subject lookup in possibly new role
46565+ we can use this result below in the case where role == task->role
46566+ */
46567+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
46568+
46569+ /* if we changed uid/gid, but result in the same role
46570+ and are using inheritance, don't lose the inherited subject
46571+ if current subject is other than what normal lookup
46572+ would result in, we arrived via inheritance, don't
46573+ lose subject
46574+ */
46575+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
46576+ (subj == task->acl)))
46577+ task->acl = subj;
46578+
46579+ task->role = role;
46580+
46581+ task->is_writable = 0;
46582+
46583+ /* ignore additional mmap checks for processes that are writable
46584+ by the default ACL */
46585+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
46586+ if (unlikely(obj->mode & GR_WRITE))
46587+ task->is_writable = 1;
46588+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
46589+ if (unlikely(obj->mode & GR_WRITE))
46590+ task->is_writable = 1;
46591+
46592+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46593+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46594+#endif
46595+
46596+ gr_set_proc_res(task);
46597+
46598+ return;
46599+}
46600+
46601+int
46602+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
46603+ const int unsafe_share)
46604+{
46605+ struct task_struct *task = current;
46606+ struct acl_subject_label *newacl;
46607+ struct acl_object_label *obj;
46608+ __u32 retmode;
46609+
46610+ if (unlikely(!(gr_status & GR_READY)))
46611+ return 0;
46612+
46613+ newacl = chk_subj_label(dentry, mnt, task->role);
46614+
46615+ task_lock(task);
46616+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
46617+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
46618+ !(task->role->roletype & GR_ROLE_GOD) &&
46619+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
46620+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
46621+ task_unlock(task);
46622+ if (unsafe_share)
46623+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
46624+ else
46625+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
46626+ return -EACCES;
46627+ }
46628+ task_unlock(task);
46629+
46630+ obj = chk_obj_label(dentry, mnt, task->acl);
46631+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
46632+
46633+ if (!(task->acl->mode & GR_INHERITLEARN) &&
46634+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
46635+ if (obj->nested)
46636+ task->acl = obj->nested;
46637+ else
46638+ task->acl = newacl;
46639+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
46640+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
46641+
46642+ task->is_writable = 0;
46643+
46644+ /* ignore additional mmap checks for processes that are writable
46645+ by the default ACL */
46646+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
46647+ if (unlikely(obj->mode & GR_WRITE))
46648+ task->is_writable = 1;
46649+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
46650+ if (unlikely(obj->mode & GR_WRITE))
46651+ task->is_writable = 1;
46652+
46653+ gr_set_proc_res(task);
46654+
46655+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46656+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46657+#endif
46658+ return 0;
46659+}
46660+
46661+/* always called with valid inodev ptr */
46662+static void
46663+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
46664+{
46665+ struct acl_object_label *matchpo;
46666+ struct acl_subject_label *matchps;
46667+ struct acl_subject_label *subj;
46668+ struct acl_role_label *role;
46669+ unsigned int x;
46670+
46671+ FOR_EACH_ROLE_START(role)
46672+ FOR_EACH_SUBJECT_START(role, subj, x)
46673+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
46674+ matchpo->mode |= GR_DELETED;
46675+ FOR_EACH_SUBJECT_END(subj,x)
46676+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
46677+ if (subj->inode == ino && subj->device == dev)
46678+ subj->mode |= GR_DELETED;
46679+ FOR_EACH_NESTED_SUBJECT_END(subj)
46680+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
46681+ matchps->mode |= GR_DELETED;
46682+ FOR_EACH_ROLE_END(role)
46683+
46684+ inodev->nentry->deleted = 1;
46685+
46686+ return;
46687+}
46688+
46689+void
46690+gr_handle_delete(const ino_t ino, const dev_t dev)
46691+{
46692+ struct inodev_entry *inodev;
46693+
46694+ if (unlikely(!(gr_status & GR_READY)))
46695+ return;
46696+
46697+ write_lock(&gr_inode_lock);
46698+ inodev = lookup_inodev_entry(ino, dev);
46699+ if (inodev != NULL)
46700+ do_handle_delete(inodev, ino, dev);
46701+ write_unlock(&gr_inode_lock);
46702+
46703+ return;
46704+}
46705+
46706+static void
46707+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
46708+ const ino_t newinode, const dev_t newdevice,
46709+ struct acl_subject_label *subj)
46710+{
46711+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
46712+ struct acl_object_label *match;
46713+
46714+ match = subj->obj_hash[index];
46715+
46716+ while (match && (match->inode != oldinode ||
46717+ match->device != olddevice ||
46718+ !(match->mode & GR_DELETED)))
46719+ match = match->next;
46720+
46721+ if (match && (match->inode == oldinode)
46722+ && (match->device == olddevice)
46723+ && (match->mode & GR_DELETED)) {
46724+ if (match->prev == NULL) {
46725+ subj->obj_hash[index] = match->next;
46726+ if (match->next != NULL)
46727+ match->next->prev = NULL;
46728+ } else {
46729+ match->prev->next = match->next;
46730+ if (match->next != NULL)
46731+ match->next->prev = match->prev;
46732+ }
46733+ match->prev = NULL;
46734+ match->next = NULL;
46735+ match->inode = newinode;
46736+ match->device = newdevice;
46737+ match->mode &= ~GR_DELETED;
46738+
46739+ insert_acl_obj_label(match, subj);
46740+ }
46741+
46742+ return;
46743+}
46744+
46745+static void
46746+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
46747+ const ino_t newinode, const dev_t newdevice,
46748+ struct acl_role_label *role)
46749+{
46750+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
46751+ struct acl_subject_label *match;
46752+
46753+ match = role->subj_hash[index];
46754+
46755+ while (match && (match->inode != oldinode ||
46756+ match->device != olddevice ||
46757+ !(match->mode & GR_DELETED)))
46758+ match = match->next;
46759+
46760+ if (match && (match->inode == oldinode)
46761+ && (match->device == olddevice)
46762+ && (match->mode & GR_DELETED)) {
46763+ if (match->prev == NULL) {
46764+ role->subj_hash[index] = match->next;
46765+ if (match->next != NULL)
46766+ match->next->prev = NULL;
46767+ } else {
46768+ match->prev->next = match->next;
46769+ if (match->next != NULL)
46770+ match->next->prev = match->prev;
46771+ }
46772+ match->prev = NULL;
46773+ match->next = NULL;
46774+ match->inode = newinode;
46775+ match->device = newdevice;
46776+ match->mode &= ~GR_DELETED;
46777+
46778+ insert_acl_subj_label(match, role);
46779+ }
46780+
46781+ return;
46782+}
46783+
46784+static void
46785+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
46786+ const ino_t newinode, const dev_t newdevice)
46787+{
46788+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
46789+ struct inodev_entry *match;
46790+
46791+ match = inodev_set.i_hash[index];
46792+
46793+ while (match && (match->nentry->inode != oldinode ||
46794+ match->nentry->device != olddevice || !match->nentry->deleted))
46795+ match = match->next;
46796+
46797+ if (match && (match->nentry->inode == oldinode)
46798+ && (match->nentry->device == olddevice) &&
46799+ match->nentry->deleted) {
46800+ if (match->prev == NULL) {
46801+ inodev_set.i_hash[index] = match->next;
46802+ if (match->next != NULL)
46803+ match->next->prev = NULL;
46804+ } else {
46805+ match->prev->next = match->next;
46806+ if (match->next != NULL)
46807+ match->next->prev = match->prev;
46808+ }
46809+ match->prev = NULL;
46810+ match->next = NULL;
46811+ match->nentry->inode = newinode;
46812+ match->nentry->device = newdevice;
46813+ match->nentry->deleted = 0;
46814+
46815+ insert_inodev_entry(match);
46816+ }
46817+
46818+ return;
46819+}
46820+
46821+static void
46822+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
46823+ const struct vfsmount *mnt)
46824+{
46825+ struct acl_subject_label *subj;
46826+ struct acl_role_label *role;
46827+ unsigned int x;
46828+ ino_t ino = dentry->d_inode->i_ino;
46829+ dev_t dev = __get_dev(dentry);
46830+
46831+ FOR_EACH_ROLE_START(role)
46832+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
46833+
46834+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
46835+ if ((subj->inode == ino) && (subj->device == dev)) {
46836+ subj->inode = ino;
46837+ subj->device = dev;
46838+ }
46839+ FOR_EACH_NESTED_SUBJECT_END(subj)
46840+ FOR_EACH_SUBJECT_START(role, subj, x)
46841+ update_acl_obj_label(matchn->inode, matchn->device,
46842+ ino, dev, subj);
46843+ FOR_EACH_SUBJECT_END(subj,x)
46844+ FOR_EACH_ROLE_END(role)
46845+
46846+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
46847+
46848+ return;
46849+}
46850+
46851+void
46852+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
46853+{
46854+ struct name_entry *matchn;
46855+
46856+ if (unlikely(!(gr_status & GR_READY)))
46857+ return;
46858+
46859+ preempt_disable();
46860+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
46861+
46862+ if (unlikely((unsigned long)matchn)) {
46863+ write_lock(&gr_inode_lock);
46864+ do_handle_create(matchn, dentry, mnt);
46865+ write_unlock(&gr_inode_lock);
46866+ }
46867+ preempt_enable();
46868+
46869+ return;
46870+}
46871+
46872+void
46873+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
46874+ struct dentry *old_dentry,
46875+ struct dentry *new_dentry,
46876+ struct vfsmount *mnt, const __u8 replace)
46877+{
46878+ struct name_entry *matchn;
46879+ struct inodev_entry *inodev;
46880+ ino_t old_ino = old_dentry->d_inode->i_ino;
46881+ dev_t old_dev = __get_dev(old_dentry);
46882+
46883+ /* vfs_rename swaps the name and parent link for old_dentry and
46884+ new_dentry
46885+ at this point, old_dentry has the new name, parent link, and inode
46886+ for the renamed file
46887+ if a file is being replaced by a rename, new_dentry has the inode
46888+ and name for the replaced file
46889+ */
46890+
46891+ if (unlikely(!(gr_status & GR_READY)))
46892+ return;
46893+
46894+ preempt_disable();
46895+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
46896+
46897+ /* we wouldn't have to check d_inode if it weren't for
46898+ NFS silly-renaming
46899+ */
46900+
46901+ write_lock(&gr_inode_lock);
46902+ if (unlikely(replace && new_dentry->d_inode)) {
46903+ ino_t new_ino = new_dentry->d_inode->i_ino;
46904+ dev_t new_dev = __get_dev(new_dentry);
46905+
46906+ inodev = lookup_inodev_entry(new_ino, new_dev);
46907+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
46908+ do_handle_delete(inodev, new_ino, new_dev);
46909+ }
46910+
46911+ inodev = lookup_inodev_entry(old_ino, old_dev);
46912+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
46913+ do_handle_delete(inodev, old_ino, old_dev);
46914+
46915+ if (unlikely((unsigned long)matchn))
46916+ do_handle_create(matchn, old_dentry, mnt);
46917+
46918+ write_unlock(&gr_inode_lock);
46919+ preempt_enable();
46920+
46921+ return;
46922+}
46923+
46924+static int
46925+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
46926+ unsigned char **sum)
46927+{
46928+ struct acl_role_label *r;
46929+ struct role_allowed_ip *ipp;
46930+ struct role_transition *trans;
46931+ unsigned int i;
46932+ int found = 0;
46933+ u32 curr_ip = current->signal->curr_ip;
46934+
46935+ current->signal->saved_ip = curr_ip;
46936+
46937+ /* check transition table */
46938+
46939+ for (trans = current->role->transitions; trans; trans = trans->next) {
46940+ if (!strcmp(rolename, trans->rolename)) {
46941+ found = 1;
46942+ break;
46943+ }
46944+ }
46945+
46946+ if (!found)
46947+ return 0;
46948+
46949+ /* handle special roles that do not require authentication
46950+ and check ip */
46951+
46952+ FOR_EACH_ROLE_START(r)
46953+ if (!strcmp(rolename, r->rolename) &&
46954+ (r->roletype & GR_ROLE_SPECIAL)) {
46955+ found = 0;
46956+ if (r->allowed_ips != NULL) {
46957+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
46958+ if ((ntohl(curr_ip) & ipp->netmask) ==
46959+ (ntohl(ipp->addr) & ipp->netmask))
46960+ found = 1;
46961+ }
46962+ } else
46963+ found = 2;
46964+ if (!found)
46965+ return 0;
46966+
46967+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
46968+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
46969+ *salt = NULL;
46970+ *sum = NULL;
46971+ return 1;
46972+ }
46973+ }
46974+ FOR_EACH_ROLE_END(r)
46975+
46976+ for (i = 0; i < num_sprole_pws; i++) {
46977+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
46978+ *salt = acl_special_roles[i]->salt;
46979+ *sum = acl_special_roles[i]->sum;
46980+ return 1;
46981+ }
46982+ }
46983+
46984+ return 0;
46985+}
46986+
46987+static void
46988+assign_special_role(char *rolename)
46989+{
46990+ struct acl_object_label *obj;
46991+ struct acl_role_label *r;
46992+ struct acl_role_label *assigned = NULL;
46993+ struct task_struct *tsk;
46994+ struct file *filp;
46995+
46996+ FOR_EACH_ROLE_START(r)
46997+ if (!strcmp(rolename, r->rolename) &&
46998+ (r->roletype & GR_ROLE_SPECIAL)) {
46999+ assigned = r;
47000+ break;
47001+ }
47002+ FOR_EACH_ROLE_END(r)
47003+
47004+ if (!assigned)
47005+ return;
47006+
47007+ read_lock(&tasklist_lock);
47008+ read_lock(&grsec_exec_file_lock);
47009+
47010+ tsk = current->real_parent;
47011+ if (tsk == NULL)
47012+ goto out_unlock;
47013+
47014+ filp = tsk->exec_file;
47015+ if (filp == NULL)
47016+ goto out_unlock;
47017+
47018+ tsk->is_writable = 0;
47019+
47020+ tsk->acl_sp_role = 1;
47021+ tsk->acl_role_id = ++acl_sp_role_value;
47022+ tsk->role = assigned;
47023+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
47024+
47025+ /* ignore additional mmap checks for processes that are writable
47026+ by the default ACL */
47027+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47028+ if (unlikely(obj->mode & GR_WRITE))
47029+ tsk->is_writable = 1;
47030+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
47031+ if (unlikely(obj->mode & GR_WRITE))
47032+ tsk->is_writable = 1;
47033+
47034+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
47035+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
47036+#endif
47037+
47038+out_unlock:
47039+ read_unlock(&grsec_exec_file_lock);
47040+ read_unlock(&tasklist_lock);
47041+ return;
47042+}
47043+
47044+int gr_check_secure_terminal(struct task_struct *task)
47045+{
47046+ struct task_struct *p, *p2, *p3;
47047+ struct files_struct *files;
47048+ struct fdtable *fdt;
47049+ struct file *our_file = NULL, *file;
47050+ int i;
47051+
47052+ if (task->signal->tty == NULL)
47053+ return 1;
47054+
47055+ files = get_files_struct(task);
47056+ if (files != NULL) {
47057+ rcu_read_lock();
47058+ fdt = files_fdtable(files);
47059+ for (i=0; i < fdt->max_fds; i++) {
47060+ file = fcheck_files(files, i);
47061+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
47062+ get_file(file);
47063+ our_file = file;
47064+ }
47065+ }
47066+ rcu_read_unlock();
47067+ put_files_struct(files);
47068+ }
47069+
47070+ if (our_file == NULL)
47071+ return 1;
47072+
47073+ read_lock(&tasklist_lock);
47074+ do_each_thread(p2, p) {
47075+ files = get_files_struct(p);
47076+ if (files == NULL ||
47077+ (p->signal && p->signal->tty == task->signal->tty)) {
47078+ if (files != NULL)
47079+ put_files_struct(files);
47080+ continue;
47081+ }
47082+ rcu_read_lock();
47083+ fdt = files_fdtable(files);
47084+ for (i=0; i < fdt->max_fds; i++) {
47085+ file = fcheck_files(files, i);
47086+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
47087+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
47088+ p3 = task;
47089+ while (p3->pid > 0) {
47090+ if (p3 == p)
47091+ break;
47092+ p3 = p3->real_parent;
47093+ }
47094+ if (p3 == p)
47095+ break;
47096+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
47097+ gr_handle_alertkill(p);
47098+ rcu_read_unlock();
47099+ put_files_struct(files);
47100+ read_unlock(&tasklist_lock);
47101+ fput(our_file);
47102+ return 0;
47103+ }
47104+ }
47105+ rcu_read_unlock();
47106+ put_files_struct(files);
47107+ } while_each_thread(p2, p);
47108+ read_unlock(&tasklist_lock);
47109+
47110+ fput(our_file);
47111+ return 1;
47112+}
47113+
47114+ssize_t
47115+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
47116+{
47117+ struct gr_arg_wrapper uwrap;
47118+ unsigned char *sprole_salt = NULL;
47119+ unsigned char *sprole_sum = NULL;
47120+ int error = sizeof (struct gr_arg_wrapper);
47121+ int error2 = 0;
47122+
47123+ mutex_lock(&gr_dev_mutex);
47124+
47125+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
47126+ error = -EPERM;
47127+ goto out;
47128+ }
47129+
47130+ if (count != sizeof (struct gr_arg_wrapper)) {
47131+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
47132+ error = -EINVAL;
47133+ goto out;
47134+ }
47135+
47136+
47137+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
47138+ gr_auth_expires = 0;
47139+ gr_auth_attempts = 0;
47140+ }
47141+
47142+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
47143+ error = -EFAULT;
47144+ goto out;
47145+ }
47146+
47147+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
47148+ error = -EINVAL;
47149+ goto out;
47150+ }
47151+
47152+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
47153+ error = -EFAULT;
47154+ goto out;
47155+ }
47156+
47157+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
47158+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
47159+ time_after(gr_auth_expires, get_seconds())) {
47160+ error = -EBUSY;
47161+ goto out;
47162+ }
47163+
47164+ /* if non-root trying to do anything other than use a special role,
47165+ do not attempt authentication, do not count towards authentication
47166+ locking
47167+ */
47168+
47169+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
47170+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
47171+ current_uid()) {
47172+ error = -EPERM;
47173+ goto out;
47174+ }
47175+
47176+ /* ensure pw and special role name are null terminated */
47177+
47178+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
47179+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
47180+
47181+ /* Okay.
47182+ * We have our enough of the argument structure..(we have yet
47183+ * to copy_from_user the tables themselves) . Copy the tables
47184+ * only if we need them, i.e. for loading operations. */
47185+
47186+ switch (gr_usermode->mode) {
47187+ case GR_STATUS:
47188+ if (gr_status & GR_READY) {
47189+ error = 1;
47190+ if (!gr_check_secure_terminal(current))
47191+ error = 3;
47192+ } else
47193+ error = 2;
47194+ goto out;
47195+ case GR_SHUTDOWN:
47196+ if ((gr_status & GR_READY)
47197+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
47198+ pax_open_kernel();
47199+ gr_status &= ~GR_READY;
47200+ pax_close_kernel();
47201+
47202+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
47203+ free_variables();
47204+ memset(gr_usermode, 0, sizeof (struct gr_arg));
47205+ memset(gr_system_salt, 0, GR_SALT_LEN);
47206+ memset(gr_system_sum, 0, GR_SHA_LEN);
47207+ } else if (gr_status & GR_READY) {
47208+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
47209+ error = -EPERM;
47210+ } else {
47211+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
47212+ error = -EAGAIN;
47213+ }
47214+ break;
47215+ case GR_ENABLE:
47216+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
47217+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
47218+ else {
47219+ if (gr_status & GR_READY)
47220+ error = -EAGAIN;
47221+ else
47222+ error = error2;
47223+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
47224+ }
47225+ break;
47226+ case GR_RELOAD:
47227+ if (!(gr_status & GR_READY)) {
47228+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
47229+ error = -EAGAIN;
47230+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
47231+ preempt_disable();
47232+
47233+ pax_open_kernel();
47234+ gr_status &= ~GR_READY;
47235+ pax_close_kernel();
47236+
47237+ free_variables();
47238+ if (!(error2 = gracl_init(gr_usermode))) {
47239+ preempt_enable();
47240+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
47241+ } else {
47242+ preempt_enable();
47243+ error = error2;
47244+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
47245+ }
47246+ } else {
47247+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
47248+ error = -EPERM;
47249+ }
47250+ break;
47251+ case GR_SEGVMOD:
47252+ if (unlikely(!(gr_status & GR_READY))) {
47253+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
47254+ error = -EAGAIN;
47255+ break;
47256+ }
47257+
47258+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
47259+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
47260+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
47261+ struct acl_subject_label *segvacl;
47262+ segvacl =
47263+ lookup_acl_subj_label(gr_usermode->segv_inode,
47264+ gr_usermode->segv_device,
47265+ current->role);
47266+ if (segvacl) {
47267+ segvacl->crashes = 0;
47268+ segvacl->expires = 0;
47269+ }
47270+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
47271+ gr_remove_uid(gr_usermode->segv_uid);
47272+ }
47273+ } else {
47274+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
47275+ error = -EPERM;
47276+ }
47277+ break;
47278+ case GR_SPROLE:
47279+ case GR_SPROLEPAM:
47280+ if (unlikely(!(gr_status & GR_READY))) {
47281+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
47282+ error = -EAGAIN;
47283+ break;
47284+ }
47285+
47286+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
47287+ current->role->expires = 0;
47288+ current->role->auth_attempts = 0;
47289+ }
47290+
47291+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
47292+ time_after(current->role->expires, get_seconds())) {
47293+ error = -EBUSY;
47294+ goto out;
47295+ }
47296+
47297+ if (lookup_special_role_auth
47298+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
47299+ && ((!sprole_salt && !sprole_sum)
47300+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
47301+ char *p = "";
47302+ assign_special_role(gr_usermode->sp_role);
47303+ read_lock(&tasklist_lock);
47304+ if (current->real_parent)
47305+ p = current->real_parent->role->rolename;
47306+ read_unlock(&tasklist_lock);
47307+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
47308+ p, acl_sp_role_value);
47309+ } else {
47310+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
47311+ error = -EPERM;
47312+ if(!(current->role->auth_attempts++))
47313+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
47314+
47315+ goto out;
47316+ }
47317+ break;
47318+ case GR_UNSPROLE:
47319+ if (unlikely(!(gr_status & GR_READY))) {
47320+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
47321+ error = -EAGAIN;
47322+ break;
47323+ }
47324+
47325+ if (current->role->roletype & GR_ROLE_SPECIAL) {
47326+ char *p = "";
47327+ int i = 0;
47328+
47329+ read_lock(&tasklist_lock);
47330+ if (current->real_parent) {
47331+ p = current->real_parent->role->rolename;
47332+ i = current->real_parent->acl_role_id;
47333+ }
47334+ read_unlock(&tasklist_lock);
47335+
47336+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
47337+ gr_set_acls(1);
47338+ } else {
47339+ error = -EPERM;
47340+ goto out;
47341+ }
47342+ break;
47343+ default:
47344+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
47345+ error = -EINVAL;
47346+ break;
47347+ }
47348+
47349+ if (error != -EPERM)
47350+ goto out;
47351+
47352+ if(!(gr_auth_attempts++))
47353+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
47354+
47355+ out:
47356+ mutex_unlock(&gr_dev_mutex);
47357+ return error;
47358+}
47359+
47360+/* must be called with
47361+ rcu_read_lock();
47362+ read_lock(&tasklist_lock);
47363+ read_lock(&grsec_exec_file_lock);
47364+*/
47365+int gr_apply_subject_to_task(struct task_struct *task)
47366+{
47367+ struct acl_object_label *obj;
47368+ char *tmpname;
47369+ struct acl_subject_label *tmpsubj;
47370+ struct file *filp;
47371+ struct name_entry *nmatch;
47372+
47373+ filp = task->exec_file;
47374+ if (filp == NULL)
47375+ return 0;
47376+
47377+ /* the following is to apply the correct subject
47378+ on binaries running when the RBAC system
47379+ is enabled, when the binaries have been
47380+ replaced or deleted since their execution
47381+ -----
47382+ when the RBAC system starts, the inode/dev
47383+ from exec_file will be one the RBAC system
47384+ is unaware of. It only knows the inode/dev
47385+ of the present file on disk, or the absence
47386+ of it.
47387+ */
47388+ preempt_disable();
47389+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
47390+
47391+ nmatch = lookup_name_entry(tmpname);
47392+ preempt_enable();
47393+ tmpsubj = NULL;
47394+ if (nmatch) {
47395+ if (nmatch->deleted)
47396+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
47397+ else
47398+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
47399+ if (tmpsubj != NULL)
47400+ task->acl = tmpsubj;
47401+ }
47402+ if (tmpsubj == NULL)
47403+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
47404+ task->role);
47405+ if (task->acl) {
47406+ task->is_writable = 0;
47407+ /* ignore additional mmap checks for processes that are writable
47408+ by the default ACL */
47409+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47410+ if (unlikely(obj->mode & GR_WRITE))
47411+ task->is_writable = 1;
47412+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
47413+ if (unlikely(obj->mode & GR_WRITE))
47414+ task->is_writable = 1;
47415+
47416+ gr_set_proc_res(task);
47417+
47418+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
47419+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
47420+#endif
47421+ } else {
47422+ return 1;
47423+ }
47424+
47425+ return 0;
47426+}
47427+
47428+int
47429+gr_set_acls(const int type)
47430+{
47431+ struct task_struct *task, *task2;
47432+ struct acl_role_label *role = current->role;
47433+ __u16 acl_role_id = current->acl_role_id;
47434+ const struct cred *cred;
47435+ int ret;
47436+
47437+ rcu_read_lock();
47438+ read_lock(&tasklist_lock);
47439+ read_lock(&grsec_exec_file_lock);
47440+ do_each_thread(task2, task) {
47441+ /* check to see if we're called from the exit handler,
47442+ if so, only replace ACLs that have inherited the admin
47443+ ACL */
47444+
47445+ if (type && (task->role != role ||
47446+ task->acl_role_id != acl_role_id))
47447+ continue;
47448+
47449+ task->acl_role_id = 0;
47450+ task->acl_sp_role = 0;
47451+
47452+ if (task->exec_file) {
47453+ cred = __task_cred(task);
47454+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
47455+ ret = gr_apply_subject_to_task(task);
47456+ if (ret) {
47457+ read_unlock(&grsec_exec_file_lock);
47458+ read_unlock(&tasklist_lock);
47459+ rcu_read_unlock();
47460+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
47461+ return ret;
47462+ }
47463+ } else {
47464+ // it's a kernel process
47465+ task->role = kernel_role;
47466+ task->acl = kernel_role->root_label;
47467+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
47468+ task->acl->mode &= ~GR_PROCFIND;
47469+#endif
47470+ }
47471+ } while_each_thread(task2, task);
47472+ read_unlock(&grsec_exec_file_lock);
47473+ read_unlock(&tasklist_lock);
47474+ rcu_read_unlock();
47475+
47476+ return 0;
47477+}
47478+
47479+void
47480+gr_learn_resource(const struct task_struct *task,
47481+ const int res, const unsigned long wanted, const int gt)
47482+{
47483+ struct acl_subject_label *acl;
47484+ const struct cred *cred;
47485+
47486+ if (unlikely((gr_status & GR_READY) &&
47487+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
47488+ goto skip_reslog;
47489+
47490+#ifdef CONFIG_GRKERNSEC_RESLOG
47491+ gr_log_resource(task, res, wanted, gt);
47492+#endif
47493+ skip_reslog:
47494+
47495+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
47496+ return;
47497+
47498+ acl = task->acl;
47499+
47500+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
47501+ !(acl->resmask & (1 << (unsigned short) res))))
47502+ return;
47503+
47504+ if (wanted >= acl->res[res].rlim_cur) {
47505+ unsigned long res_add;
47506+
47507+ res_add = wanted;
47508+ switch (res) {
47509+ case RLIMIT_CPU:
47510+ res_add += GR_RLIM_CPU_BUMP;
47511+ break;
47512+ case RLIMIT_FSIZE:
47513+ res_add += GR_RLIM_FSIZE_BUMP;
47514+ break;
47515+ case RLIMIT_DATA:
47516+ res_add += GR_RLIM_DATA_BUMP;
47517+ break;
47518+ case RLIMIT_STACK:
47519+ res_add += GR_RLIM_STACK_BUMP;
47520+ break;
47521+ case RLIMIT_CORE:
47522+ res_add += GR_RLIM_CORE_BUMP;
47523+ break;
47524+ case RLIMIT_RSS:
47525+ res_add += GR_RLIM_RSS_BUMP;
47526+ break;
47527+ case RLIMIT_NPROC:
47528+ res_add += GR_RLIM_NPROC_BUMP;
47529+ break;
47530+ case RLIMIT_NOFILE:
47531+ res_add += GR_RLIM_NOFILE_BUMP;
47532+ break;
47533+ case RLIMIT_MEMLOCK:
47534+ res_add += GR_RLIM_MEMLOCK_BUMP;
47535+ break;
47536+ case RLIMIT_AS:
47537+ res_add += GR_RLIM_AS_BUMP;
47538+ break;
47539+ case RLIMIT_LOCKS:
47540+ res_add += GR_RLIM_LOCKS_BUMP;
47541+ break;
47542+ case RLIMIT_SIGPENDING:
47543+ res_add += GR_RLIM_SIGPENDING_BUMP;
47544+ break;
47545+ case RLIMIT_MSGQUEUE:
47546+ res_add += GR_RLIM_MSGQUEUE_BUMP;
47547+ break;
47548+ case RLIMIT_NICE:
47549+ res_add += GR_RLIM_NICE_BUMP;
47550+ break;
47551+ case RLIMIT_RTPRIO:
47552+ res_add += GR_RLIM_RTPRIO_BUMP;
47553+ break;
47554+ case RLIMIT_RTTIME:
47555+ res_add += GR_RLIM_RTTIME_BUMP;
47556+ break;
47557+ }
47558+
47559+ acl->res[res].rlim_cur = res_add;
47560+
47561+ if (wanted > acl->res[res].rlim_max)
47562+ acl->res[res].rlim_max = res_add;
47563+
47564+ /* only log the subject filename, since resource logging is supported for
47565+ single-subject learning only */
47566+ rcu_read_lock();
47567+ cred = __task_cred(task);
47568+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
47569+ task->role->roletype, cred->uid, cred->gid, acl->filename,
47570+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
47571+ "", (unsigned long) res, &task->signal->saved_ip);
47572+ rcu_read_unlock();
47573+ }
47574+
47575+ return;
47576+}
47577+
47578+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
47579+void
47580+pax_set_initial_flags(struct linux_binprm *bprm)
47581+{
47582+ struct task_struct *task = current;
47583+ struct acl_subject_label *proc;
47584+ unsigned long flags;
47585+
47586+ if (unlikely(!(gr_status & GR_READY)))
47587+ return;
47588+
47589+ flags = pax_get_flags(task);
47590+
47591+ proc = task->acl;
47592+
47593+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
47594+ flags &= ~MF_PAX_PAGEEXEC;
47595+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
47596+ flags &= ~MF_PAX_SEGMEXEC;
47597+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
47598+ flags &= ~MF_PAX_RANDMMAP;
47599+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
47600+ flags &= ~MF_PAX_EMUTRAMP;
47601+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
47602+ flags &= ~MF_PAX_MPROTECT;
47603+
47604+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
47605+ flags |= MF_PAX_PAGEEXEC;
47606+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
47607+ flags |= MF_PAX_SEGMEXEC;
47608+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
47609+ flags |= MF_PAX_RANDMMAP;
47610+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
47611+ flags |= MF_PAX_EMUTRAMP;
47612+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
47613+ flags |= MF_PAX_MPROTECT;
47614+
47615+ pax_set_flags(task, flags);
47616+
47617+ return;
47618+}
47619+#endif
47620+
47621+#ifdef CONFIG_SYSCTL
47622+/* Eric Biederman likes breaking userland ABI and every inode-based security
47623+ system to save 35kb of memory */
47624+
47625+/* we modify the passed in filename, but adjust it back before returning */
47626+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
47627+{
47628+ struct name_entry *nmatch;
47629+ char *p, *lastp = NULL;
47630+ struct acl_object_label *obj = NULL, *tmp;
47631+ struct acl_subject_label *tmpsubj;
47632+ char c = '\0';
47633+
47634+ read_lock(&gr_inode_lock);
47635+
47636+ p = name + len - 1;
47637+ do {
47638+ nmatch = lookup_name_entry(name);
47639+ if (lastp != NULL)
47640+ *lastp = c;
47641+
47642+ if (nmatch == NULL)
47643+ goto next_component;
47644+ tmpsubj = current->acl;
47645+ do {
47646+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
47647+ if (obj != NULL) {
47648+ tmp = obj->globbed;
47649+ while (tmp) {
47650+ if (!glob_match(tmp->filename, name)) {
47651+ obj = tmp;
47652+ goto found_obj;
47653+ }
47654+ tmp = tmp->next;
47655+ }
47656+ goto found_obj;
47657+ }
47658+ } while ((tmpsubj = tmpsubj->parent_subject));
47659+next_component:
47660+ /* end case */
47661+ if (p == name)
47662+ break;
47663+
47664+ while (*p != '/')
47665+ p--;
47666+ if (p == name)
47667+ lastp = p + 1;
47668+ else {
47669+ lastp = p;
47670+ p--;
47671+ }
47672+ c = *lastp;
47673+ *lastp = '\0';
47674+ } while (1);
47675+found_obj:
47676+ read_unlock(&gr_inode_lock);
47677+ /* obj returned will always be non-null */
47678+ return obj;
47679+}
47680+
47681+/* returns 0 when allowing, non-zero on error
47682+ op of 0 is used for readdir, so we don't log the names of hidden files
47683+*/
47684+__u32
47685+gr_handle_sysctl(const struct ctl_table *table, const int op)
47686+{
47687+ struct ctl_table *tmp;
47688+ const char *proc_sys = "/proc/sys";
47689+ char *path;
47690+ struct acl_object_label *obj;
47691+ unsigned short len = 0, pos = 0, depth = 0, i;
47692+ __u32 err = 0;
47693+ __u32 mode = 0;
47694+
47695+ if (unlikely(!(gr_status & GR_READY)))
47696+ return 0;
47697+
47698+ /* for now, ignore operations on non-sysctl entries if it's not a
47699+ readdir*/
47700+ if (table->child != NULL && op != 0)
47701+ return 0;
47702+
47703+ mode |= GR_FIND;
47704+ /* it's only a read if it's an entry, read on dirs is for readdir */
47705+ if (op & MAY_READ)
47706+ mode |= GR_READ;
47707+ if (op & MAY_WRITE)
47708+ mode |= GR_WRITE;
47709+
47710+ preempt_disable();
47711+
47712+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
47713+
47714+ /* it's only a read/write if it's an actual entry, not a dir
47715+ (which are opened for readdir)
47716+ */
47717+
47718+ /* convert the requested sysctl entry into a pathname */
47719+
47720+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
47721+ len += strlen(tmp->procname);
47722+ len++;
47723+ depth++;
47724+ }
47725+
47726+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
47727+ /* deny */
47728+ goto out;
47729+ }
47730+
47731+ memset(path, 0, PAGE_SIZE);
47732+
47733+ memcpy(path, proc_sys, strlen(proc_sys));
47734+
47735+ pos += strlen(proc_sys);
47736+
47737+ for (; depth > 0; depth--) {
47738+ path[pos] = '/';
47739+ pos++;
47740+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
47741+ if (depth == i) {
47742+ memcpy(path + pos, tmp->procname,
47743+ strlen(tmp->procname));
47744+ pos += strlen(tmp->procname);
47745+ }
47746+ i++;
47747+ }
47748+ }
47749+
47750+ obj = gr_lookup_by_name(path, pos);
47751+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
47752+
47753+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
47754+ ((err & mode) != mode))) {
47755+ __u32 new_mode = mode;
47756+
47757+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
47758+
47759+ err = 0;
47760+ gr_log_learn_sysctl(path, new_mode);
47761+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
47762+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
47763+ err = -ENOENT;
47764+ } else if (!(err & GR_FIND)) {
47765+ err = -ENOENT;
47766+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
47767+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
47768+ path, (mode & GR_READ) ? " reading" : "",
47769+ (mode & GR_WRITE) ? " writing" : "");
47770+ err = -EACCES;
47771+ } else if ((err & mode) != mode) {
47772+ err = -EACCES;
47773+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
47774+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
47775+ path, (mode & GR_READ) ? " reading" : "",
47776+ (mode & GR_WRITE) ? " writing" : "");
47777+ err = 0;
47778+ } else
47779+ err = 0;
47780+
47781+ out:
47782+ preempt_enable();
47783+
47784+ return err;
47785+}
47786+#endif
47787+
47788+int
47789+gr_handle_proc_ptrace(struct task_struct *task)
47790+{
47791+ struct file *filp;
47792+ struct task_struct *tmp = task;
47793+ struct task_struct *curtemp = current;
47794+ __u32 retmode;
47795+
47796+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
47797+ if (unlikely(!(gr_status & GR_READY)))
47798+ return 0;
47799+#endif
47800+
47801+ read_lock(&tasklist_lock);
47802+ read_lock(&grsec_exec_file_lock);
47803+ filp = task->exec_file;
47804+
47805+ while (tmp->pid > 0) {
47806+ if (tmp == curtemp)
47807+ break;
47808+ tmp = tmp->real_parent;
47809+ }
47810+
47811+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
47812+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
47813+ read_unlock(&grsec_exec_file_lock);
47814+ read_unlock(&tasklist_lock);
47815+ return 1;
47816+ }
47817+
47818+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
47819+ if (!(gr_status & GR_READY)) {
47820+ read_unlock(&grsec_exec_file_lock);
47821+ read_unlock(&tasklist_lock);
47822+ return 0;
47823+ }
47824+#endif
47825+
47826+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
47827+ read_unlock(&grsec_exec_file_lock);
47828+ read_unlock(&tasklist_lock);
47829+
47830+ if (retmode & GR_NOPTRACE)
47831+ return 1;
47832+
47833+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
47834+ && (current->acl != task->acl || (current->acl != current->role->root_label
47835+ && current->pid != task->pid)))
47836+ return 1;
47837+
47838+ return 0;
47839+}
47840+
47841+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
47842+{
47843+ if (unlikely(!(gr_status & GR_READY)))
47844+ return;
47845+
47846+ if (!(current->role->roletype & GR_ROLE_GOD))
47847+ return;
47848+
47849+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
47850+ p->role->rolename, gr_task_roletype_to_char(p),
47851+ p->acl->filename);
47852+}
47853+
47854+int
47855+gr_handle_ptrace(struct task_struct *task, const long request)
47856+{
47857+ struct task_struct *tmp = task;
47858+ struct task_struct *curtemp = current;
47859+ __u32 retmode;
47860+
47861+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
47862+ if (unlikely(!(gr_status & GR_READY)))
47863+ return 0;
47864+#endif
47865+
47866+ read_lock(&tasklist_lock);
47867+ while (tmp->pid > 0) {
47868+ if (tmp == curtemp)
47869+ break;
47870+ tmp = tmp->real_parent;
47871+ }
47872+
47873+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
47874+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
47875+ read_unlock(&tasklist_lock);
47876+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47877+ return 1;
47878+ }
47879+ read_unlock(&tasklist_lock);
47880+
47881+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
47882+ if (!(gr_status & GR_READY))
47883+ return 0;
47884+#endif
47885+
47886+ read_lock(&grsec_exec_file_lock);
47887+ if (unlikely(!task->exec_file)) {
47888+ read_unlock(&grsec_exec_file_lock);
47889+ return 0;
47890+ }
47891+
47892+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
47893+ read_unlock(&grsec_exec_file_lock);
47894+
47895+ if (retmode & GR_NOPTRACE) {
47896+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47897+ return 1;
47898+ }
47899+
47900+ if (retmode & GR_PTRACERD) {
47901+ switch (request) {
47902+ case PTRACE_POKETEXT:
47903+ case PTRACE_POKEDATA:
47904+ case PTRACE_POKEUSR:
47905+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
47906+ case PTRACE_SETREGS:
47907+ case PTRACE_SETFPREGS:
47908+#endif
47909+#ifdef CONFIG_X86
47910+ case PTRACE_SETFPXREGS:
47911+#endif
47912+#ifdef CONFIG_ALTIVEC
47913+ case PTRACE_SETVRREGS:
47914+#endif
47915+ return 1;
47916+ default:
47917+ return 0;
47918+ }
47919+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
47920+ !(current->role->roletype & GR_ROLE_GOD) &&
47921+ (current->acl != task->acl)) {
47922+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47923+ return 1;
47924+ }
47925+
47926+ return 0;
47927+}
47928+
47929+static int is_writable_mmap(const struct file *filp)
47930+{
47931+ struct task_struct *task = current;
47932+ struct acl_object_label *obj, *obj2;
47933+
47934+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
47935+ !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))) {
47936+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47937+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
47938+ task->role->root_label);
47939+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
47940+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
47941+ return 1;
47942+ }
47943+ }
47944+ return 0;
47945+}
47946+
47947+int
47948+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
47949+{
47950+ __u32 mode;
47951+
47952+ if (unlikely(!file || !(prot & PROT_EXEC)))
47953+ return 1;
47954+
47955+ if (is_writable_mmap(file))
47956+ return 0;
47957+
47958+ mode =
47959+ gr_search_file(file->f_path.dentry,
47960+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
47961+ file->f_path.mnt);
47962+
47963+ if (!gr_tpe_allow(file))
47964+ return 0;
47965+
47966+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
47967+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47968+ return 0;
47969+ } else if (unlikely(!(mode & GR_EXEC))) {
47970+ return 0;
47971+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
47972+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47973+ return 1;
47974+ }
47975+
47976+ return 1;
47977+}
47978+
47979+int
47980+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
47981+{
47982+ __u32 mode;
47983+
47984+ if (unlikely(!file || !(prot & PROT_EXEC)))
47985+ return 1;
47986+
47987+ if (is_writable_mmap(file))
47988+ return 0;
47989+
47990+ mode =
47991+ gr_search_file(file->f_path.dentry,
47992+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
47993+ file->f_path.mnt);
47994+
47995+ if (!gr_tpe_allow(file))
47996+ return 0;
47997+
47998+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
47999+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
48000+ return 0;
48001+ } else if (unlikely(!(mode & GR_EXEC))) {
48002+ return 0;
48003+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
48004+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
48005+ return 1;
48006+ }
48007+
48008+ return 1;
48009+}
48010+
48011+void
48012+gr_acl_handle_psacct(struct task_struct *task, const long code)
48013+{
48014+ unsigned long runtime;
48015+ unsigned long cputime;
48016+ unsigned int wday, cday;
48017+ __u8 whr, chr;
48018+ __u8 wmin, cmin;
48019+ __u8 wsec, csec;
48020+ struct timespec timeval;
48021+
48022+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
48023+ !(task->acl->mode & GR_PROCACCT)))
48024+ return;
48025+
48026+ do_posix_clock_monotonic_gettime(&timeval);
48027+ runtime = timeval.tv_sec - task->start_time.tv_sec;
48028+ wday = runtime / (3600 * 24);
48029+ runtime -= wday * (3600 * 24);
48030+ whr = runtime / 3600;
48031+ runtime -= whr * 3600;
48032+ wmin = runtime / 60;
48033+ runtime -= wmin * 60;
48034+ wsec = runtime;
48035+
48036+ cputime = (task->utime + task->stime) / HZ;
48037+ cday = cputime / (3600 * 24);
48038+ cputime -= cday * (3600 * 24);
48039+ chr = cputime / 3600;
48040+ cputime -= chr * 3600;
48041+ cmin = cputime / 60;
48042+ cputime -= cmin * 60;
48043+ csec = cputime;
48044+
48045+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
48046+
48047+ return;
48048+}
48049+
48050+void gr_set_kernel_label(struct task_struct *task)
48051+{
48052+ if (gr_status & GR_READY) {
48053+ task->role = kernel_role;
48054+ task->acl = kernel_role->root_label;
48055+ }
48056+ return;
48057+}
48058+
48059+#ifdef CONFIG_TASKSTATS
48060+int gr_is_taskstats_denied(int pid)
48061+{
48062+ struct task_struct *task;
48063+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48064+ const struct cred *cred;
48065+#endif
48066+ int ret = 0;
48067+
48068+ /* restrict taskstats viewing to un-chrooted root users
48069+ who have the 'view' subject flag if the RBAC system is enabled
48070+ */
48071+
48072+ rcu_read_lock();
48073+ read_lock(&tasklist_lock);
48074+ task = find_task_by_vpid(pid);
48075+ if (task) {
48076+#ifdef CONFIG_GRKERNSEC_CHROOT
48077+ if (proc_is_chrooted(task))
48078+ ret = -EACCES;
48079+#endif
48080+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48081+ cred = __task_cred(task);
48082+#ifdef CONFIG_GRKERNSEC_PROC_USER
48083+ if (cred->uid != 0)
48084+ ret = -EACCES;
48085+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48086+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
48087+ ret = -EACCES;
48088+#endif
48089+#endif
48090+ if (gr_status & GR_READY) {
48091+ if (!(task->acl->mode & GR_VIEW))
48092+ ret = -EACCES;
48093+ }
48094+ } else
48095+ ret = -ENOENT;
48096+
48097+ read_unlock(&tasklist_lock);
48098+ rcu_read_unlock();
48099+
48100+ return ret;
48101+}
48102+#endif
48103+
48104+/* AUXV entries are filled via a descendant of search_binary_handler
48105+ after we've already applied the subject for the target
48106+*/
48107+int gr_acl_enable_at_secure(void)
48108+{
48109+ if (unlikely(!(gr_status & GR_READY)))
48110+ return 0;
48111+
48112+ if (current->acl->mode & GR_ATSECURE)
48113+ return 1;
48114+
48115+ return 0;
48116+}
48117+
48118+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
48119+{
48120+ struct task_struct *task = current;
48121+ struct dentry *dentry = file->f_path.dentry;
48122+ struct vfsmount *mnt = file->f_path.mnt;
48123+ struct acl_object_label *obj, *tmp;
48124+ struct acl_subject_label *subj;
48125+ unsigned int bufsize;
48126+ int is_not_root;
48127+ char *path;
48128+ dev_t dev = __get_dev(dentry);
48129+
48130+ if (unlikely(!(gr_status & GR_READY)))
48131+ return 1;
48132+
48133+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
48134+ return 1;
48135+
48136+ /* ignore Eric Biederman */
48137+ if (IS_PRIVATE(dentry->d_inode))
48138+ return 1;
48139+
48140+ subj = task->acl;
48141+ do {
48142+ obj = lookup_acl_obj_label(ino, dev, subj);
48143+ if (obj != NULL)
48144+ return (obj->mode & GR_FIND) ? 1 : 0;
48145+ } while ((subj = subj->parent_subject));
48146+
48147+ /* this is purely an optimization since we're looking for an object
48148+ for the directory we're doing a readdir on
48149+ if it's possible for any globbed object to match the entry we're
48150+ filling into the directory, then the object we find here will be
48151+ an anchor point with attached globbed objects
48152+ */
48153+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
48154+ if (obj->globbed == NULL)
48155+ return (obj->mode & GR_FIND) ? 1 : 0;
48156+
48157+ is_not_root = ((obj->filename[0] == '/') &&
48158+ (obj->filename[1] == '\0')) ? 0 : 1;
48159+ bufsize = PAGE_SIZE - namelen - is_not_root;
48160+
48161+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
48162+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
48163+ return 1;
48164+
48165+ preempt_disable();
48166+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
48167+ bufsize);
48168+
48169+ bufsize = strlen(path);
48170+
48171+ /* if base is "/", don't append an additional slash */
48172+ if (is_not_root)
48173+ *(path + bufsize) = '/';
48174+ memcpy(path + bufsize + is_not_root, name, namelen);
48175+ *(path + bufsize + namelen + is_not_root) = '\0';
48176+
48177+ tmp = obj->globbed;
48178+ while (tmp) {
48179+ if (!glob_match(tmp->filename, path)) {
48180+ preempt_enable();
48181+ return (tmp->mode & GR_FIND) ? 1 : 0;
48182+ }
48183+ tmp = tmp->next;
48184+ }
48185+ preempt_enable();
48186+ return (obj->mode & GR_FIND) ? 1 : 0;
48187+}
48188+
48189+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
48190+EXPORT_SYMBOL(gr_acl_is_enabled);
48191+#endif
48192+EXPORT_SYMBOL(gr_learn_resource);
48193+EXPORT_SYMBOL(gr_set_kernel_label);
48194+#ifdef CONFIG_SECURITY
48195+EXPORT_SYMBOL(gr_check_user_change);
48196+EXPORT_SYMBOL(gr_check_group_change);
48197+#endif
48198+
48199diff -urNp linux-3.0.4/grsecurity/gracl_cap.c linux-3.0.4/grsecurity/gracl_cap.c
48200--- linux-3.0.4/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
48201+++ linux-3.0.4/grsecurity/gracl_cap.c 2011-08-23 21:48:14.000000000 -0400
48202@@ -0,0 +1,139 @@
48203+#include <linux/kernel.h>
48204+#include <linux/module.h>
48205+#include <linux/sched.h>
48206+#include <linux/gracl.h>
48207+#include <linux/grsecurity.h>
48208+#include <linux/grinternal.h>
48209+
48210+static const char *captab_log[] = {
48211+ "CAP_CHOWN",
48212+ "CAP_DAC_OVERRIDE",
48213+ "CAP_DAC_READ_SEARCH",
48214+ "CAP_FOWNER",
48215+ "CAP_FSETID",
48216+ "CAP_KILL",
48217+ "CAP_SETGID",
48218+ "CAP_SETUID",
48219+ "CAP_SETPCAP",
48220+ "CAP_LINUX_IMMUTABLE",
48221+ "CAP_NET_BIND_SERVICE",
48222+ "CAP_NET_BROADCAST",
48223+ "CAP_NET_ADMIN",
48224+ "CAP_NET_RAW",
48225+ "CAP_IPC_LOCK",
48226+ "CAP_IPC_OWNER",
48227+ "CAP_SYS_MODULE",
48228+ "CAP_SYS_RAWIO",
48229+ "CAP_SYS_CHROOT",
48230+ "CAP_SYS_PTRACE",
48231+ "CAP_SYS_PACCT",
48232+ "CAP_SYS_ADMIN",
48233+ "CAP_SYS_BOOT",
48234+ "CAP_SYS_NICE",
48235+ "CAP_SYS_RESOURCE",
48236+ "CAP_SYS_TIME",
48237+ "CAP_SYS_TTY_CONFIG",
48238+ "CAP_MKNOD",
48239+ "CAP_LEASE",
48240+ "CAP_AUDIT_WRITE",
48241+ "CAP_AUDIT_CONTROL",
48242+ "CAP_SETFCAP",
48243+ "CAP_MAC_OVERRIDE",
48244+ "CAP_MAC_ADMIN",
48245+ "CAP_SYSLOG"
48246+};
48247+
48248+EXPORT_SYMBOL(gr_is_capable);
48249+EXPORT_SYMBOL(gr_is_capable_nolog);
48250+
48251+int
48252+gr_is_capable(const int cap)
48253+{
48254+ struct task_struct *task = current;
48255+ const struct cred *cred = current_cred();
48256+ struct acl_subject_label *curracl;
48257+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
48258+ kernel_cap_t cap_audit = __cap_empty_set;
48259+
48260+ if (!gr_acl_is_enabled())
48261+ return 1;
48262+
48263+ curracl = task->acl;
48264+
48265+ cap_drop = curracl->cap_lower;
48266+ cap_mask = curracl->cap_mask;
48267+ cap_audit = curracl->cap_invert_audit;
48268+
48269+ while ((curracl = curracl->parent_subject)) {
48270+ /* if the cap isn't specified in the current computed mask but is specified in the
48271+ current level subject, and is lowered in the current level subject, then add
48272+ it to the set of dropped capabilities
48273+ otherwise, add the current level subject's mask to the current computed mask
48274+ */
48275+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
48276+ cap_raise(cap_mask, cap);
48277+ if (cap_raised(curracl->cap_lower, cap))
48278+ cap_raise(cap_drop, cap);
48279+ if (cap_raised(curracl->cap_invert_audit, cap))
48280+ cap_raise(cap_audit, cap);
48281+ }
48282+ }
48283+
48284+ if (!cap_raised(cap_drop, cap)) {
48285+ if (cap_raised(cap_audit, cap))
48286+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
48287+ return 1;
48288+ }
48289+
48290+ curracl = task->acl;
48291+
48292+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
48293+ && cap_raised(cred->cap_effective, cap)) {
48294+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
48295+ task->role->roletype, cred->uid,
48296+ cred->gid, task->exec_file ?
48297+ gr_to_filename(task->exec_file->f_path.dentry,
48298+ task->exec_file->f_path.mnt) : curracl->filename,
48299+ curracl->filename, 0UL,
48300+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
48301+ return 1;
48302+ }
48303+
48304+ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
48305+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
48306+ return 0;
48307+}
48308+
48309+int
48310+gr_is_capable_nolog(const int cap)
48311+{
48312+ struct acl_subject_label *curracl;
48313+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
48314+
48315+ if (!gr_acl_is_enabled())
48316+ return 1;
48317+
48318+ curracl = current->acl;
48319+
48320+ cap_drop = curracl->cap_lower;
48321+ cap_mask = curracl->cap_mask;
48322+
48323+ while ((curracl = curracl->parent_subject)) {
48324+ /* if the cap isn't specified in the current computed mask but is specified in the
48325+ current level subject, and is lowered in the current level subject, then add
48326+ it to the set of dropped capabilities
48327+ otherwise, add the current level subject's mask to the current computed mask
48328+ */
48329+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
48330+ cap_raise(cap_mask, cap);
48331+ if (cap_raised(curracl->cap_lower, cap))
48332+ cap_raise(cap_drop, cap);
48333+ }
48334+ }
48335+
48336+ if (!cap_raised(cap_drop, cap))
48337+ return 1;
48338+
48339+ return 0;
48340+}
48341+
48342diff -urNp linux-3.0.4/grsecurity/gracl_fs.c linux-3.0.4/grsecurity/gracl_fs.c
48343--- linux-3.0.4/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
48344+++ linux-3.0.4/grsecurity/gracl_fs.c 2011-08-23 21:48:14.000000000 -0400
48345@@ -0,0 +1,431 @@
48346+#include <linux/kernel.h>
48347+#include <linux/sched.h>
48348+#include <linux/types.h>
48349+#include <linux/fs.h>
48350+#include <linux/file.h>
48351+#include <linux/stat.h>
48352+#include <linux/grsecurity.h>
48353+#include <linux/grinternal.h>
48354+#include <linux/gracl.h>
48355+
48356+__u32
48357+gr_acl_handle_hidden_file(const struct dentry * dentry,
48358+ const struct vfsmount * mnt)
48359+{
48360+ __u32 mode;
48361+
48362+ if (unlikely(!dentry->d_inode))
48363+ return GR_FIND;
48364+
48365+ mode =
48366+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
48367+
48368+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
48369+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
48370+ return mode;
48371+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
48372+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
48373+ return 0;
48374+ } else if (unlikely(!(mode & GR_FIND)))
48375+ return 0;
48376+
48377+ return GR_FIND;
48378+}
48379+
48380+__u32
48381+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
48382+ const int fmode)
48383+{
48384+ __u32 reqmode = GR_FIND;
48385+ __u32 mode;
48386+
48387+ if (unlikely(!dentry->d_inode))
48388+ return reqmode;
48389+
48390+ if (unlikely(fmode & O_APPEND))
48391+ reqmode |= GR_APPEND;
48392+ else if (unlikely(fmode & FMODE_WRITE))
48393+ reqmode |= GR_WRITE;
48394+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
48395+ reqmode |= GR_READ;
48396+ if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
48397+ reqmode &= ~GR_READ;
48398+ mode =
48399+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
48400+ mnt);
48401+
48402+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
48403+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
48404+ reqmode & GR_READ ? " reading" : "",
48405+ reqmode & GR_WRITE ? " writing" : reqmode &
48406+ GR_APPEND ? " appending" : "");
48407+ return reqmode;
48408+ } else
48409+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
48410+ {
48411+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
48412+ reqmode & GR_READ ? " reading" : "",
48413+ reqmode & GR_WRITE ? " writing" : reqmode &
48414+ GR_APPEND ? " appending" : "");
48415+ return 0;
48416+ } else if (unlikely((mode & reqmode) != reqmode))
48417+ return 0;
48418+
48419+ return reqmode;
48420+}
48421+
48422+__u32
48423+gr_acl_handle_creat(const struct dentry * dentry,
48424+ const struct dentry * p_dentry,
48425+ const struct vfsmount * p_mnt, const int fmode,
48426+ const int imode)
48427+{
48428+ __u32 reqmode = GR_WRITE | GR_CREATE;
48429+ __u32 mode;
48430+
48431+ if (unlikely(fmode & O_APPEND))
48432+ reqmode |= GR_APPEND;
48433+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
48434+ reqmode |= GR_READ;
48435+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
48436+ reqmode |= GR_SETID;
48437+
48438+ mode =
48439+ gr_check_create(dentry, p_dentry, p_mnt,
48440+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
48441+
48442+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
48443+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
48444+ reqmode & GR_READ ? " reading" : "",
48445+ reqmode & GR_WRITE ? " writing" : reqmode &
48446+ GR_APPEND ? " appending" : "");
48447+ return reqmode;
48448+ } else
48449+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
48450+ {
48451+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
48452+ reqmode & GR_READ ? " reading" : "",
48453+ reqmode & GR_WRITE ? " writing" : reqmode &
48454+ GR_APPEND ? " appending" : "");
48455+ return 0;
48456+ } else if (unlikely((mode & reqmode) != reqmode))
48457+ return 0;
48458+
48459+ return reqmode;
48460+}
48461+
48462+__u32
48463+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
48464+ const int fmode)
48465+{
48466+ __u32 mode, reqmode = GR_FIND;
48467+
48468+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
48469+ reqmode |= GR_EXEC;
48470+ if (fmode & S_IWOTH)
48471+ reqmode |= GR_WRITE;
48472+ if (fmode & S_IROTH)
48473+ reqmode |= GR_READ;
48474+
48475+ mode =
48476+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
48477+ mnt);
48478+
48479+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
48480+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
48481+ reqmode & GR_READ ? " reading" : "",
48482+ reqmode & GR_WRITE ? " writing" : "",
48483+ reqmode & GR_EXEC ? " executing" : "");
48484+ return reqmode;
48485+ } else
48486+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
48487+ {
48488+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
48489+ reqmode & GR_READ ? " reading" : "",
48490+ reqmode & GR_WRITE ? " writing" : "",
48491+ reqmode & GR_EXEC ? " executing" : "");
48492+ return 0;
48493+ } else if (unlikely((mode & reqmode) != reqmode))
48494+ return 0;
48495+
48496+ return reqmode;
48497+}
48498+
48499+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
48500+{
48501+ __u32 mode;
48502+
48503+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
48504+
48505+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
48506+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
48507+ return mode;
48508+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
48509+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
48510+ return 0;
48511+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
48512+ return 0;
48513+
48514+ return (reqmode);
48515+}
48516+
48517+__u32
48518+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
48519+{
48520+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
48521+}
48522+
48523+__u32
48524+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
48525+{
48526+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
48527+}
48528+
48529+__u32
48530+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
48531+{
48532+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
48533+}
48534+
48535+__u32
48536+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
48537+{
48538+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
48539+}
48540+
48541+__u32
48542+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
48543+ mode_t mode)
48544+{
48545+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
48546+ return 1;
48547+
48548+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
48549+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
48550+ GR_FCHMOD_ACL_MSG);
48551+ } else {
48552+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
48553+ }
48554+}
48555+
48556+__u32
48557+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
48558+ mode_t mode)
48559+{
48560+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
48561+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
48562+ GR_CHMOD_ACL_MSG);
48563+ } else {
48564+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
48565+ }
48566+}
48567+
48568+__u32
48569+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
48570+{
48571+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
48572+}
48573+
48574+__u32
48575+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
48576+{
48577+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
48578+}
48579+
48580+__u32
48581+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
48582+{
48583+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
48584+}
48585+
48586+__u32
48587+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
48588+{
48589+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
48590+ GR_UNIXCONNECT_ACL_MSG);
48591+}
48592+
48593+/* hardlinks require at minimum create permission,
48594+ any additional privilege required is based on the
48595+ privilege of the file being linked to
48596+*/
48597+__u32
48598+gr_acl_handle_link(const struct dentry * new_dentry,
48599+ const struct dentry * parent_dentry,
48600+ const struct vfsmount * parent_mnt,
48601+ const struct dentry * old_dentry,
48602+ const struct vfsmount * old_mnt, const char *to)
48603+{
48604+ __u32 mode;
48605+ __u32 needmode = GR_CREATE | GR_LINK;
48606+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
48607+
48608+ mode =
48609+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
48610+ old_mnt);
48611+
48612+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
48613+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
48614+ return mode;
48615+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
48616+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
48617+ return 0;
48618+ } else if (unlikely((mode & needmode) != needmode))
48619+ return 0;
48620+
48621+ return 1;
48622+}
48623+
48624+__u32
48625+gr_acl_handle_symlink(const struct dentry * new_dentry,
48626+ const struct dentry * parent_dentry,
48627+ const struct vfsmount * parent_mnt, const char *from)
48628+{
48629+ __u32 needmode = GR_WRITE | GR_CREATE;
48630+ __u32 mode;
48631+
48632+ mode =
48633+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
48634+ GR_CREATE | GR_AUDIT_CREATE |
48635+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
48636+
48637+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
48638+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
48639+ return mode;
48640+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
48641+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
48642+ return 0;
48643+ } else if (unlikely((mode & needmode) != needmode))
48644+ return 0;
48645+
48646+ return (GR_WRITE | GR_CREATE);
48647+}
48648+
48649+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)
48650+{
48651+ __u32 mode;
48652+
48653+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
48654+
48655+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
48656+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
48657+ return mode;
48658+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
48659+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
48660+ return 0;
48661+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
48662+ return 0;
48663+
48664+ return (reqmode);
48665+}
48666+
48667+__u32
48668+gr_acl_handle_mknod(const struct dentry * new_dentry,
48669+ const struct dentry * parent_dentry,
48670+ const struct vfsmount * parent_mnt,
48671+ const int mode)
48672+{
48673+ __u32 reqmode = GR_WRITE | GR_CREATE;
48674+ if (unlikely(mode & (S_ISUID | S_ISGID)))
48675+ reqmode |= GR_SETID;
48676+
48677+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
48678+ reqmode, GR_MKNOD_ACL_MSG);
48679+}
48680+
48681+__u32
48682+gr_acl_handle_mkdir(const struct dentry *new_dentry,
48683+ const struct dentry *parent_dentry,
48684+ const struct vfsmount *parent_mnt)
48685+{
48686+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
48687+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
48688+}
48689+
48690+#define RENAME_CHECK_SUCCESS(old, new) \
48691+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
48692+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
48693+
48694+int
48695+gr_acl_handle_rename(struct dentry *new_dentry,
48696+ struct dentry *parent_dentry,
48697+ const struct vfsmount *parent_mnt,
48698+ struct dentry *old_dentry,
48699+ struct inode *old_parent_inode,
48700+ struct vfsmount *old_mnt, const char *newname)
48701+{
48702+ __u32 comp1, comp2;
48703+ int error = 0;
48704+
48705+ if (unlikely(!gr_acl_is_enabled()))
48706+ return 0;
48707+
48708+ if (!new_dentry->d_inode) {
48709+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
48710+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
48711+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
48712+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
48713+ GR_DELETE | GR_AUDIT_DELETE |
48714+ GR_AUDIT_READ | GR_AUDIT_WRITE |
48715+ GR_SUPPRESS, old_mnt);
48716+ } else {
48717+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
48718+ GR_CREATE | GR_DELETE |
48719+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
48720+ GR_AUDIT_READ | GR_AUDIT_WRITE |
48721+ GR_SUPPRESS, parent_mnt);
48722+ comp2 =
48723+ gr_search_file(old_dentry,
48724+ GR_READ | GR_WRITE | GR_AUDIT_READ |
48725+ GR_DELETE | GR_AUDIT_DELETE |
48726+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
48727+ }
48728+
48729+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
48730+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
48731+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
48732+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
48733+ && !(comp2 & GR_SUPPRESS)) {
48734+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
48735+ error = -EACCES;
48736+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
48737+ error = -EACCES;
48738+
48739+ return error;
48740+}
48741+
48742+void
48743+gr_acl_handle_exit(void)
48744+{
48745+ u16 id;
48746+ char *rolename;
48747+ struct file *exec_file;
48748+
48749+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
48750+ !(current->role->roletype & GR_ROLE_PERSIST))) {
48751+ id = current->acl_role_id;
48752+ rolename = current->role->rolename;
48753+ gr_set_acls(1);
48754+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
48755+ }
48756+
48757+ write_lock(&grsec_exec_file_lock);
48758+ exec_file = current->exec_file;
48759+ current->exec_file = NULL;
48760+ write_unlock(&grsec_exec_file_lock);
48761+
48762+ if (exec_file)
48763+ fput(exec_file);
48764+}
48765+
48766+int
48767+gr_acl_handle_procpidmem(const struct task_struct *task)
48768+{
48769+ if (unlikely(!gr_acl_is_enabled()))
48770+ return 0;
48771+
48772+ if (task != current && task->acl->mode & GR_PROTPROCFD)
48773+ return -EACCES;
48774+
48775+ return 0;
48776+}
48777diff -urNp linux-3.0.4/grsecurity/gracl_ip.c linux-3.0.4/grsecurity/gracl_ip.c
48778--- linux-3.0.4/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
48779+++ linux-3.0.4/grsecurity/gracl_ip.c 2011-08-23 21:48:14.000000000 -0400
48780@@ -0,0 +1,381 @@
48781+#include <linux/kernel.h>
48782+#include <asm/uaccess.h>
48783+#include <asm/errno.h>
48784+#include <net/sock.h>
48785+#include <linux/file.h>
48786+#include <linux/fs.h>
48787+#include <linux/net.h>
48788+#include <linux/in.h>
48789+#include <linux/skbuff.h>
48790+#include <linux/ip.h>
48791+#include <linux/udp.h>
48792+#include <linux/types.h>
48793+#include <linux/sched.h>
48794+#include <linux/netdevice.h>
48795+#include <linux/inetdevice.h>
48796+#include <linux/gracl.h>
48797+#include <linux/grsecurity.h>
48798+#include <linux/grinternal.h>
48799+
48800+#define GR_BIND 0x01
48801+#define GR_CONNECT 0x02
48802+#define GR_INVERT 0x04
48803+#define GR_BINDOVERRIDE 0x08
48804+#define GR_CONNECTOVERRIDE 0x10
48805+#define GR_SOCK_FAMILY 0x20
48806+
48807+static const char * gr_protocols[IPPROTO_MAX] = {
48808+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
48809+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
48810+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
48811+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
48812+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
48813+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
48814+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
48815+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
48816+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
48817+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
48818+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
48819+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
48820+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
48821+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
48822+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
48823+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
48824+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
48825+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
48826+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
48827+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
48828+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
48829+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
48830+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
48831+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
48832+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
48833+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
48834+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
48835+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
48836+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
48837+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
48838+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
48839+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
48840+ };
48841+
48842+static const char * gr_socktypes[SOCK_MAX] = {
48843+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
48844+ "unknown:7", "unknown:8", "unknown:9", "packet"
48845+ };
48846+
48847+static const char * gr_sockfamilies[AF_MAX+1] = {
48848+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
48849+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
48850+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
48851+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
48852+ };
48853+
48854+const char *
48855+gr_proto_to_name(unsigned char proto)
48856+{
48857+ return gr_protocols[proto];
48858+}
48859+
48860+const char *
48861+gr_socktype_to_name(unsigned char type)
48862+{
48863+ return gr_socktypes[type];
48864+}
48865+
48866+const char *
48867+gr_sockfamily_to_name(unsigned char family)
48868+{
48869+ return gr_sockfamilies[family];
48870+}
48871+
48872+int
48873+gr_search_socket(const int domain, const int type, const int protocol)
48874+{
48875+ struct acl_subject_label *curr;
48876+ const struct cred *cred = current_cred();
48877+
48878+ if (unlikely(!gr_acl_is_enabled()))
48879+ goto exit;
48880+
48881+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
48882+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
48883+ goto exit; // let the kernel handle it
48884+
48885+ curr = current->acl;
48886+
48887+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
48888+ /* the family is allowed, if this is PF_INET allow it only if
48889+ the extra sock type/protocol checks pass */
48890+ if (domain == PF_INET)
48891+ goto inet_check;
48892+ goto exit;
48893+ } else {
48894+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48895+ __u32 fakeip = 0;
48896+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48897+ current->role->roletype, cred->uid,
48898+ cred->gid, current->exec_file ?
48899+ gr_to_filename(current->exec_file->f_path.dentry,
48900+ current->exec_file->f_path.mnt) :
48901+ curr->filename, curr->filename,
48902+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
48903+ &current->signal->saved_ip);
48904+ goto exit;
48905+ }
48906+ goto exit_fail;
48907+ }
48908+
48909+inet_check:
48910+ /* the rest of this checking is for IPv4 only */
48911+ if (!curr->ips)
48912+ goto exit;
48913+
48914+ if ((curr->ip_type & (1 << type)) &&
48915+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
48916+ goto exit;
48917+
48918+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48919+ /* we don't place acls on raw sockets , and sometimes
48920+ dgram/ip sockets are opened for ioctl and not
48921+ bind/connect, so we'll fake a bind learn log */
48922+ if (type == SOCK_RAW || type == SOCK_PACKET) {
48923+ __u32 fakeip = 0;
48924+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48925+ current->role->roletype, cred->uid,
48926+ cred->gid, current->exec_file ?
48927+ gr_to_filename(current->exec_file->f_path.dentry,
48928+ current->exec_file->f_path.mnt) :
48929+ curr->filename, curr->filename,
48930+ &fakeip, 0, type,
48931+ protocol, GR_CONNECT, &current->signal->saved_ip);
48932+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
48933+ __u32 fakeip = 0;
48934+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48935+ current->role->roletype, cred->uid,
48936+ cred->gid, current->exec_file ?
48937+ gr_to_filename(current->exec_file->f_path.dentry,
48938+ current->exec_file->f_path.mnt) :
48939+ curr->filename, curr->filename,
48940+ &fakeip, 0, type,
48941+ protocol, GR_BIND, &current->signal->saved_ip);
48942+ }
48943+ /* we'll log when they use connect or bind */
48944+ goto exit;
48945+ }
48946+
48947+exit_fail:
48948+ if (domain == PF_INET)
48949+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
48950+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
48951+ else
48952+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
48953+ gr_socktype_to_name(type), protocol);
48954+
48955+ return 0;
48956+exit:
48957+ return 1;
48958+}
48959+
48960+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)
48961+{
48962+ if ((ip->mode & mode) &&
48963+ (ip_port >= ip->low) &&
48964+ (ip_port <= ip->high) &&
48965+ ((ntohl(ip_addr) & our_netmask) ==
48966+ (ntohl(our_addr) & our_netmask))
48967+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
48968+ && (ip->type & (1 << type))) {
48969+ if (ip->mode & GR_INVERT)
48970+ return 2; // specifically denied
48971+ else
48972+ return 1; // allowed
48973+ }
48974+
48975+ return 0; // not specifically allowed, may continue parsing
48976+}
48977+
48978+static int
48979+gr_search_connectbind(const int full_mode, struct sock *sk,
48980+ struct sockaddr_in *addr, const int type)
48981+{
48982+ char iface[IFNAMSIZ] = {0};
48983+ struct acl_subject_label *curr;
48984+ struct acl_ip_label *ip;
48985+ struct inet_sock *isk;
48986+ struct net_device *dev;
48987+ struct in_device *idev;
48988+ unsigned long i;
48989+ int ret;
48990+ int mode = full_mode & (GR_BIND | GR_CONNECT);
48991+ __u32 ip_addr = 0;
48992+ __u32 our_addr;
48993+ __u32 our_netmask;
48994+ char *p;
48995+ __u16 ip_port = 0;
48996+ const struct cred *cred = current_cred();
48997+
48998+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
48999+ return 0;
49000+
49001+ curr = current->acl;
49002+ isk = inet_sk(sk);
49003+
49004+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
49005+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
49006+ addr->sin_addr.s_addr = curr->inaddr_any_override;
49007+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
49008+ struct sockaddr_in saddr;
49009+ int err;
49010+
49011+ saddr.sin_family = AF_INET;
49012+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
49013+ saddr.sin_port = isk->inet_sport;
49014+
49015+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
49016+ if (err)
49017+ return err;
49018+
49019+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
49020+ if (err)
49021+ return err;
49022+ }
49023+
49024+ if (!curr->ips)
49025+ return 0;
49026+
49027+ ip_addr = addr->sin_addr.s_addr;
49028+ ip_port = ntohs(addr->sin_port);
49029+
49030+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
49031+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
49032+ current->role->roletype, cred->uid,
49033+ cred->gid, current->exec_file ?
49034+ gr_to_filename(current->exec_file->f_path.dentry,
49035+ current->exec_file->f_path.mnt) :
49036+ curr->filename, curr->filename,
49037+ &ip_addr, ip_port, type,
49038+ sk->sk_protocol, mode, &current->signal->saved_ip);
49039+ return 0;
49040+ }
49041+
49042+ for (i = 0; i < curr->ip_num; i++) {
49043+ ip = *(curr->ips + i);
49044+ if (ip->iface != NULL) {
49045+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
49046+ p = strchr(iface, ':');
49047+ if (p != NULL)
49048+ *p = '\0';
49049+ dev = dev_get_by_name(sock_net(sk), iface);
49050+ if (dev == NULL)
49051+ continue;
49052+ idev = in_dev_get(dev);
49053+ if (idev == NULL) {
49054+ dev_put(dev);
49055+ continue;
49056+ }
49057+ rcu_read_lock();
49058+ for_ifa(idev) {
49059+ if (!strcmp(ip->iface, ifa->ifa_label)) {
49060+ our_addr = ifa->ifa_address;
49061+ our_netmask = 0xffffffff;
49062+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
49063+ if (ret == 1) {
49064+ rcu_read_unlock();
49065+ in_dev_put(idev);
49066+ dev_put(dev);
49067+ return 0;
49068+ } else if (ret == 2) {
49069+ rcu_read_unlock();
49070+ in_dev_put(idev);
49071+ dev_put(dev);
49072+ goto denied;
49073+ }
49074+ }
49075+ } endfor_ifa(idev);
49076+ rcu_read_unlock();
49077+ in_dev_put(idev);
49078+ dev_put(dev);
49079+ } else {
49080+ our_addr = ip->addr;
49081+ our_netmask = ip->netmask;
49082+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
49083+ if (ret == 1)
49084+ return 0;
49085+ else if (ret == 2)
49086+ goto denied;
49087+ }
49088+ }
49089+
49090+denied:
49091+ if (mode == GR_BIND)
49092+ 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));
49093+ else if (mode == GR_CONNECT)
49094+ 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));
49095+
49096+ return -EACCES;
49097+}
49098+
49099+int
49100+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
49101+{
49102+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
49103+}
49104+
49105+int
49106+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
49107+{
49108+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
49109+}
49110+
49111+int gr_search_listen(struct socket *sock)
49112+{
49113+ struct sock *sk = sock->sk;
49114+ struct sockaddr_in addr;
49115+
49116+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
49117+ addr.sin_port = inet_sk(sk)->inet_sport;
49118+
49119+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
49120+}
49121+
49122+int gr_search_accept(struct socket *sock)
49123+{
49124+ struct sock *sk = sock->sk;
49125+ struct sockaddr_in addr;
49126+
49127+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
49128+ addr.sin_port = inet_sk(sk)->inet_sport;
49129+
49130+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
49131+}
49132+
49133+int
49134+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
49135+{
49136+ if (addr)
49137+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
49138+ else {
49139+ struct sockaddr_in sin;
49140+ const struct inet_sock *inet = inet_sk(sk);
49141+
49142+ sin.sin_addr.s_addr = inet->inet_daddr;
49143+ sin.sin_port = inet->inet_dport;
49144+
49145+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
49146+ }
49147+}
49148+
49149+int
49150+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
49151+{
49152+ struct sockaddr_in sin;
49153+
49154+ if (unlikely(skb->len < sizeof (struct udphdr)))
49155+ return 0; // skip this packet
49156+
49157+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
49158+ sin.sin_port = udp_hdr(skb)->source;
49159+
49160+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
49161+}
49162diff -urNp linux-3.0.4/grsecurity/gracl_learn.c linux-3.0.4/grsecurity/gracl_learn.c
49163--- linux-3.0.4/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
49164+++ linux-3.0.4/grsecurity/gracl_learn.c 2011-08-23 21:48:14.000000000 -0400
49165@@ -0,0 +1,207 @@
49166+#include <linux/kernel.h>
49167+#include <linux/mm.h>
49168+#include <linux/sched.h>
49169+#include <linux/poll.h>
49170+#include <linux/string.h>
49171+#include <linux/file.h>
49172+#include <linux/types.h>
49173+#include <linux/vmalloc.h>
49174+#include <linux/grinternal.h>
49175+
49176+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
49177+ size_t count, loff_t *ppos);
49178+extern int gr_acl_is_enabled(void);
49179+
49180+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
49181+static int gr_learn_attached;
49182+
49183+/* use a 512k buffer */
49184+#define LEARN_BUFFER_SIZE (512 * 1024)
49185+
49186+static DEFINE_SPINLOCK(gr_learn_lock);
49187+static DEFINE_MUTEX(gr_learn_user_mutex);
49188+
49189+/* we need to maintain two buffers, so that the kernel context of grlearn
49190+ uses a semaphore around the userspace copying, and the other kernel contexts
49191+ use a spinlock when copying into the buffer, since they cannot sleep
49192+*/
49193+static char *learn_buffer;
49194+static char *learn_buffer_user;
49195+static int learn_buffer_len;
49196+static int learn_buffer_user_len;
49197+
49198+static ssize_t
49199+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
49200+{
49201+ DECLARE_WAITQUEUE(wait, current);
49202+ ssize_t retval = 0;
49203+
49204+ add_wait_queue(&learn_wait, &wait);
49205+ set_current_state(TASK_INTERRUPTIBLE);
49206+ do {
49207+ mutex_lock(&gr_learn_user_mutex);
49208+ spin_lock(&gr_learn_lock);
49209+ if (learn_buffer_len)
49210+ break;
49211+ spin_unlock(&gr_learn_lock);
49212+ mutex_unlock(&gr_learn_user_mutex);
49213+ if (file->f_flags & O_NONBLOCK) {
49214+ retval = -EAGAIN;
49215+ goto out;
49216+ }
49217+ if (signal_pending(current)) {
49218+ retval = -ERESTARTSYS;
49219+ goto out;
49220+ }
49221+
49222+ schedule();
49223+ } while (1);
49224+
49225+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
49226+ learn_buffer_user_len = learn_buffer_len;
49227+ retval = learn_buffer_len;
49228+ learn_buffer_len = 0;
49229+
49230+ spin_unlock(&gr_learn_lock);
49231+
49232+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
49233+ retval = -EFAULT;
49234+
49235+ mutex_unlock(&gr_learn_user_mutex);
49236+out:
49237+ set_current_state(TASK_RUNNING);
49238+ remove_wait_queue(&learn_wait, &wait);
49239+ return retval;
49240+}
49241+
49242+static unsigned int
49243+poll_learn(struct file * file, poll_table * wait)
49244+{
49245+ poll_wait(file, &learn_wait, wait);
49246+
49247+ if (learn_buffer_len)
49248+ return (POLLIN | POLLRDNORM);
49249+
49250+ return 0;
49251+}
49252+
49253+void
49254+gr_clear_learn_entries(void)
49255+{
49256+ char *tmp;
49257+
49258+ mutex_lock(&gr_learn_user_mutex);
49259+ spin_lock(&gr_learn_lock);
49260+ tmp = learn_buffer;
49261+ learn_buffer = NULL;
49262+ spin_unlock(&gr_learn_lock);
49263+ if (tmp)
49264+ vfree(tmp);
49265+ if (learn_buffer_user != NULL) {
49266+ vfree(learn_buffer_user);
49267+ learn_buffer_user = NULL;
49268+ }
49269+ learn_buffer_len = 0;
49270+ mutex_unlock(&gr_learn_user_mutex);
49271+
49272+ return;
49273+}
49274+
49275+void
49276+gr_add_learn_entry(const char *fmt, ...)
49277+{
49278+ va_list args;
49279+ unsigned int len;
49280+
49281+ if (!gr_learn_attached)
49282+ return;
49283+
49284+ spin_lock(&gr_learn_lock);
49285+
49286+ /* leave a gap at the end so we know when it's "full" but don't have to
49287+ compute the exact length of the string we're trying to append
49288+ */
49289+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
49290+ spin_unlock(&gr_learn_lock);
49291+ wake_up_interruptible(&learn_wait);
49292+ return;
49293+ }
49294+ if (learn_buffer == NULL) {
49295+ spin_unlock(&gr_learn_lock);
49296+ return;
49297+ }
49298+
49299+ va_start(args, fmt);
49300+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
49301+ va_end(args);
49302+
49303+ learn_buffer_len += len + 1;
49304+
49305+ spin_unlock(&gr_learn_lock);
49306+ wake_up_interruptible(&learn_wait);
49307+
49308+ return;
49309+}
49310+
49311+static int
49312+open_learn(struct inode *inode, struct file *file)
49313+{
49314+ if (file->f_mode & FMODE_READ && gr_learn_attached)
49315+ return -EBUSY;
49316+ if (file->f_mode & FMODE_READ) {
49317+ int retval = 0;
49318+ mutex_lock(&gr_learn_user_mutex);
49319+ if (learn_buffer == NULL)
49320+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
49321+ if (learn_buffer_user == NULL)
49322+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
49323+ if (learn_buffer == NULL) {
49324+ retval = -ENOMEM;
49325+ goto out_error;
49326+ }
49327+ if (learn_buffer_user == NULL) {
49328+ retval = -ENOMEM;
49329+ goto out_error;
49330+ }
49331+ learn_buffer_len = 0;
49332+ learn_buffer_user_len = 0;
49333+ gr_learn_attached = 1;
49334+out_error:
49335+ mutex_unlock(&gr_learn_user_mutex);
49336+ return retval;
49337+ }
49338+ return 0;
49339+}
49340+
49341+static int
49342+close_learn(struct inode *inode, struct file *file)
49343+{
49344+ if (file->f_mode & FMODE_READ) {
49345+ char *tmp = NULL;
49346+ mutex_lock(&gr_learn_user_mutex);
49347+ spin_lock(&gr_learn_lock);
49348+ tmp = learn_buffer;
49349+ learn_buffer = NULL;
49350+ spin_unlock(&gr_learn_lock);
49351+ if (tmp)
49352+ vfree(tmp);
49353+ if (learn_buffer_user != NULL) {
49354+ vfree(learn_buffer_user);
49355+ learn_buffer_user = NULL;
49356+ }
49357+ learn_buffer_len = 0;
49358+ learn_buffer_user_len = 0;
49359+ gr_learn_attached = 0;
49360+ mutex_unlock(&gr_learn_user_mutex);
49361+ }
49362+
49363+ return 0;
49364+}
49365+
49366+const struct file_operations grsec_fops = {
49367+ .read = read_learn,
49368+ .write = write_grsec_handler,
49369+ .open = open_learn,
49370+ .release = close_learn,
49371+ .poll = poll_learn,
49372+};
49373diff -urNp linux-3.0.4/grsecurity/gracl_res.c linux-3.0.4/grsecurity/gracl_res.c
49374--- linux-3.0.4/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
49375+++ linux-3.0.4/grsecurity/gracl_res.c 2011-08-23 21:48:14.000000000 -0400
49376@@ -0,0 +1,68 @@
49377+#include <linux/kernel.h>
49378+#include <linux/sched.h>
49379+#include <linux/gracl.h>
49380+#include <linux/grinternal.h>
49381+
49382+static const char *restab_log[] = {
49383+ [RLIMIT_CPU] = "RLIMIT_CPU",
49384+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
49385+ [RLIMIT_DATA] = "RLIMIT_DATA",
49386+ [RLIMIT_STACK] = "RLIMIT_STACK",
49387+ [RLIMIT_CORE] = "RLIMIT_CORE",
49388+ [RLIMIT_RSS] = "RLIMIT_RSS",
49389+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
49390+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
49391+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
49392+ [RLIMIT_AS] = "RLIMIT_AS",
49393+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
49394+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
49395+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
49396+ [RLIMIT_NICE] = "RLIMIT_NICE",
49397+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
49398+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
49399+ [GR_CRASH_RES] = "RLIMIT_CRASH"
49400+};
49401+
49402+void
49403+gr_log_resource(const struct task_struct *task,
49404+ const int res, const unsigned long wanted, const int gt)
49405+{
49406+ const struct cred *cred;
49407+ unsigned long rlim;
49408+
49409+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
49410+ return;
49411+
49412+ // not yet supported resource
49413+ if (unlikely(!restab_log[res]))
49414+ return;
49415+
49416+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
49417+ rlim = task_rlimit_max(task, res);
49418+ else
49419+ rlim = task_rlimit(task, res);
49420+
49421+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
49422+ return;
49423+
49424+ rcu_read_lock();
49425+ cred = __task_cred(task);
49426+
49427+ if (res == RLIMIT_NPROC &&
49428+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
49429+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
49430+ goto out_rcu_unlock;
49431+ else if (res == RLIMIT_MEMLOCK &&
49432+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
49433+ goto out_rcu_unlock;
49434+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
49435+ goto out_rcu_unlock;
49436+ rcu_read_unlock();
49437+
49438+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
49439+
49440+ return;
49441+out_rcu_unlock:
49442+ rcu_read_unlock();
49443+ return;
49444+}
49445diff -urNp linux-3.0.4/grsecurity/gracl_segv.c linux-3.0.4/grsecurity/gracl_segv.c
49446--- linux-3.0.4/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
49447+++ linux-3.0.4/grsecurity/gracl_segv.c 2011-08-23 21:48:14.000000000 -0400
49448@@ -0,0 +1,299 @@
49449+#include <linux/kernel.h>
49450+#include <linux/mm.h>
49451+#include <asm/uaccess.h>
49452+#include <asm/errno.h>
49453+#include <asm/mman.h>
49454+#include <net/sock.h>
49455+#include <linux/file.h>
49456+#include <linux/fs.h>
49457+#include <linux/net.h>
49458+#include <linux/in.h>
49459+#include <linux/slab.h>
49460+#include <linux/types.h>
49461+#include <linux/sched.h>
49462+#include <linux/timer.h>
49463+#include <linux/gracl.h>
49464+#include <linux/grsecurity.h>
49465+#include <linux/grinternal.h>
49466+
49467+static struct crash_uid *uid_set;
49468+static unsigned short uid_used;
49469+static DEFINE_SPINLOCK(gr_uid_lock);
49470+extern rwlock_t gr_inode_lock;
49471+extern struct acl_subject_label *
49472+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
49473+ struct acl_role_label *role);
49474+
49475+#ifdef CONFIG_BTRFS_FS
49476+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
49477+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
49478+#endif
49479+
49480+static inline dev_t __get_dev(const struct dentry *dentry)
49481+{
49482+#ifdef CONFIG_BTRFS_FS
49483+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
49484+ return get_btrfs_dev_from_inode(dentry->d_inode);
49485+ else
49486+#endif
49487+ return dentry->d_inode->i_sb->s_dev;
49488+}
49489+
49490+int
49491+gr_init_uidset(void)
49492+{
49493+ uid_set =
49494+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
49495+ uid_used = 0;
49496+
49497+ return uid_set ? 1 : 0;
49498+}
49499+
49500+void
49501+gr_free_uidset(void)
49502+{
49503+ if (uid_set)
49504+ kfree(uid_set);
49505+
49506+ return;
49507+}
49508+
49509+int
49510+gr_find_uid(const uid_t uid)
49511+{
49512+ struct crash_uid *tmp = uid_set;
49513+ uid_t buid;
49514+ int low = 0, high = uid_used - 1, mid;
49515+
49516+ while (high >= low) {
49517+ mid = (low + high) >> 1;
49518+ buid = tmp[mid].uid;
49519+ if (buid == uid)
49520+ return mid;
49521+ if (buid > uid)
49522+ high = mid - 1;
49523+ if (buid < uid)
49524+ low = mid + 1;
49525+ }
49526+
49527+ return -1;
49528+}
49529+
49530+static __inline__ void
49531+gr_insertsort(void)
49532+{
49533+ unsigned short i, j;
49534+ struct crash_uid index;
49535+
49536+ for (i = 1; i < uid_used; i++) {
49537+ index = uid_set[i];
49538+ j = i;
49539+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
49540+ uid_set[j] = uid_set[j - 1];
49541+ j--;
49542+ }
49543+ uid_set[j] = index;
49544+ }
49545+
49546+ return;
49547+}
49548+
49549+static __inline__ void
49550+gr_insert_uid(const uid_t uid, const unsigned long expires)
49551+{
49552+ int loc;
49553+
49554+ if (uid_used == GR_UIDTABLE_MAX)
49555+ return;
49556+
49557+ loc = gr_find_uid(uid);
49558+
49559+ if (loc >= 0) {
49560+ uid_set[loc].expires = expires;
49561+ return;
49562+ }
49563+
49564+ uid_set[uid_used].uid = uid;
49565+ uid_set[uid_used].expires = expires;
49566+ uid_used++;
49567+
49568+ gr_insertsort();
49569+
49570+ return;
49571+}
49572+
49573+void
49574+gr_remove_uid(const unsigned short loc)
49575+{
49576+ unsigned short i;
49577+
49578+ for (i = loc + 1; i < uid_used; i++)
49579+ uid_set[i - 1] = uid_set[i];
49580+
49581+ uid_used--;
49582+
49583+ return;
49584+}
49585+
49586+int
49587+gr_check_crash_uid(const uid_t uid)
49588+{
49589+ int loc;
49590+ int ret = 0;
49591+
49592+ if (unlikely(!gr_acl_is_enabled()))
49593+ return 0;
49594+
49595+ spin_lock(&gr_uid_lock);
49596+ loc = gr_find_uid(uid);
49597+
49598+ if (loc < 0)
49599+ goto out_unlock;
49600+
49601+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
49602+ gr_remove_uid(loc);
49603+ else
49604+ ret = 1;
49605+
49606+out_unlock:
49607+ spin_unlock(&gr_uid_lock);
49608+ return ret;
49609+}
49610+
49611+static __inline__ int
49612+proc_is_setxid(const struct cred *cred)
49613+{
49614+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
49615+ cred->uid != cred->fsuid)
49616+ return 1;
49617+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
49618+ cred->gid != cred->fsgid)
49619+ return 1;
49620+
49621+ return 0;
49622+}
49623+
49624+extern int gr_fake_force_sig(int sig, struct task_struct *t);
49625+
49626+void
49627+gr_handle_crash(struct task_struct *task, const int sig)
49628+{
49629+ struct acl_subject_label *curr;
49630+ struct acl_subject_label *curr2;
49631+ struct task_struct *tsk, *tsk2;
49632+ const struct cred *cred;
49633+ const struct cred *cred2;
49634+
49635+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
49636+ return;
49637+
49638+ if (unlikely(!gr_acl_is_enabled()))
49639+ return;
49640+
49641+ curr = task->acl;
49642+
49643+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
49644+ return;
49645+
49646+ if (time_before_eq(curr->expires, get_seconds())) {
49647+ curr->expires = 0;
49648+ curr->crashes = 0;
49649+ }
49650+
49651+ curr->crashes++;
49652+
49653+ if (!curr->expires)
49654+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
49655+
49656+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
49657+ time_after(curr->expires, get_seconds())) {
49658+ rcu_read_lock();
49659+ cred = __task_cred(task);
49660+ if (cred->uid && proc_is_setxid(cred)) {
49661+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
49662+ spin_lock(&gr_uid_lock);
49663+ gr_insert_uid(cred->uid, curr->expires);
49664+ spin_unlock(&gr_uid_lock);
49665+ curr->expires = 0;
49666+ curr->crashes = 0;
49667+ read_lock(&tasklist_lock);
49668+ do_each_thread(tsk2, tsk) {
49669+ cred2 = __task_cred(tsk);
49670+ if (tsk != task && cred2->uid == cred->uid)
49671+ gr_fake_force_sig(SIGKILL, tsk);
49672+ } while_each_thread(tsk2, tsk);
49673+ read_unlock(&tasklist_lock);
49674+ } else {
49675+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
49676+ read_lock(&tasklist_lock);
49677+ do_each_thread(tsk2, tsk) {
49678+ if (likely(tsk != task)) {
49679+ curr2 = tsk->acl;
49680+
49681+ if (curr2->device == curr->device &&
49682+ curr2->inode == curr->inode)
49683+ gr_fake_force_sig(SIGKILL, tsk);
49684+ }
49685+ } while_each_thread(tsk2, tsk);
49686+ read_unlock(&tasklist_lock);
49687+ }
49688+ rcu_read_unlock();
49689+ }
49690+
49691+ return;
49692+}
49693+
49694+int
49695+gr_check_crash_exec(const struct file *filp)
49696+{
49697+ struct acl_subject_label *curr;
49698+
49699+ if (unlikely(!gr_acl_is_enabled()))
49700+ return 0;
49701+
49702+ read_lock(&gr_inode_lock);
49703+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
49704+ __get_dev(filp->f_path.dentry),
49705+ current->role);
49706+ read_unlock(&gr_inode_lock);
49707+
49708+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
49709+ (!curr->crashes && !curr->expires))
49710+ return 0;
49711+
49712+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
49713+ time_after(curr->expires, get_seconds()))
49714+ return 1;
49715+ else if (time_before_eq(curr->expires, get_seconds())) {
49716+ curr->crashes = 0;
49717+ curr->expires = 0;
49718+ }
49719+
49720+ return 0;
49721+}
49722+
49723+void
49724+gr_handle_alertkill(struct task_struct *task)
49725+{
49726+ struct acl_subject_label *curracl;
49727+ __u32 curr_ip;
49728+ struct task_struct *p, *p2;
49729+
49730+ if (unlikely(!gr_acl_is_enabled()))
49731+ return;
49732+
49733+ curracl = task->acl;
49734+ curr_ip = task->signal->curr_ip;
49735+
49736+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
49737+ read_lock(&tasklist_lock);
49738+ do_each_thread(p2, p) {
49739+ if (p->signal->curr_ip == curr_ip)
49740+ gr_fake_force_sig(SIGKILL, p);
49741+ } while_each_thread(p2, p);
49742+ read_unlock(&tasklist_lock);
49743+ } else if (curracl->mode & GR_KILLPROC)
49744+ gr_fake_force_sig(SIGKILL, task);
49745+
49746+ return;
49747+}
49748diff -urNp linux-3.0.4/grsecurity/gracl_shm.c linux-3.0.4/grsecurity/gracl_shm.c
49749--- linux-3.0.4/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
49750+++ linux-3.0.4/grsecurity/gracl_shm.c 2011-08-23 21:48:14.000000000 -0400
49751@@ -0,0 +1,40 @@
49752+#include <linux/kernel.h>
49753+#include <linux/mm.h>
49754+#include <linux/sched.h>
49755+#include <linux/file.h>
49756+#include <linux/ipc.h>
49757+#include <linux/gracl.h>
49758+#include <linux/grsecurity.h>
49759+#include <linux/grinternal.h>
49760+
49761+int
49762+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
49763+ const time_t shm_createtime, const uid_t cuid, const int shmid)
49764+{
49765+ struct task_struct *task;
49766+
49767+ if (!gr_acl_is_enabled())
49768+ return 1;
49769+
49770+ rcu_read_lock();
49771+ read_lock(&tasklist_lock);
49772+
49773+ task = find_task_by_vpid(shm_cprid);
49774+
49775+ if (unlikely(!task))
49776+ task = find_task_by_vpid(shm_lapid);
49777+
49778+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
49779+ (task->pid == shm_lapid)) &&
49780+ (task->acl->mode & GR_PROTSHM) &&
49781+ (task->acl != current->acl))) {
49782+ read_unlock(&tasklist_lock);
49783+ rcu_read_unlock();
49784+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
49785+ return 0;
49786+ }
49787+ read_unlock(&tasklist_lock);
49788+ rcu_read_unlock();
49789+
49790+ return 1;
49791+}
49792diff -urNp linux-3.0.4/grsecurity/grsec_chdir.c linux-3.0.4/grsecurity/grsec_chdir.c
49793--- linux-3.0.4/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
49794+++ linux-3.0.4/grsecurity/grsec_chdir.c 2011-08-23 21:48:14.000000000 -0400
49795@@ -0,0 +1,19 @@
49796+#include <linux/kernel.h>
49797+#include <linux/sched.h>
49798+#include <linux/fs.h>
49799+#include <linux/file.h>
49800+#include <linux/grsecurity.h>
49801+#include <linux/grinternal.h>
49802+
49803+void
49804+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
49805+{
49806+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
49807+ if ((grsec_enable_chdir && grsec_enable_group &&
49808+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
49809+ !grsec_enable_group)) {
49810+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
49811+ }
49812+#endif
49813+ return;
49814+}
49815diff -urNp linux-3.0.4/grsecurity/grsec_chroot.c linux-3.0.4/grsecurity/grsec_chroot.c
49816--- linux-3.0.4/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
49817+++ linux-3.0.4/grsecurity/grsec_chroot.c 2011-08-23 21:48:14.000000000 -0400
49818@@ -0,0 +1,349 @@
49819+#include <linux/kernel.h>
49820+#include <linux/module.h>
49821+#include <linux/sched.h>
49822+#include <linux/file.h>
49823+#include <linux/fs.h>
49824+#include <linux/mount.h>
49825+#include <linux/types.h>
49826+#include <linux/pid_namespace.h>
49827+#include <linux/grsecurity.h>
49828+#include <linux/grinternal.h>
49829+
49830+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
49831+{
49832+#ifdef CONFIG_GRKERNSEC
49833+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
49834+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
49835+ task->gr_is_chrooted = 1;
49836+ else
49837+ task->gr_is_chrooted = 0;
49838+
49839+ task->gr_chroot_dentry = path->dentry;
49840+#endif
49841+ return;
49842+}
49843+
49844+void gr_clear_chroot_entries(struct task_struct *task)
49845+{
49846+#ifdef CONFIG_GRKERNSEC
49847+ task->gr_is_chrooted = 0;
49848+ task->gr_chroot_dentry = NULL;
49849+#endif
49850+ return;
49851+}
49852+
49853+int
49854+gr_handle_chroot_unix(const pid_t pid)
49855+{
49856+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
49857+ struct task_struct *p;
49858+
49859+ if (unlikely(!grsec_enable_chroot_unix))
49860+ return 1;
49861+
49862+ if (likely(!proc_is_chrooted(current)))
49863+ return 1;
49864+
49865+ rcu_read_lock();
49866+ read_lock(&tasklist_lock);
49867+ p = find_task_by_vpid_unrestricted(pid);
49868+ if (unlikely(p && !have_same_root(current, p))) {
49869+ read_unlock(&tasklist_lock);
49870+ rcu_read_unlock();
49871+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
49872+ return 0;
49873+ }
49874+ read_unlock(&tasklist_lock);
49875+ rcu_read_unlock();
49876+#endif
49877+ return 1;
49878+}
49879+
49880+int
49881+gr_handle_chroot_nice(void)
49882+{
49883+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
49884+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
49885+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
49886+ return -EPERM;
49887+ }
49888+#endif
49889+ return 0;
49890+}
49891+
49892+int
49893+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
49894+{
49895+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
49896+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
49897+ && proc_is_chrooted(current)) {
49898+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
49899+ return -EACCES;
49900+ }
49901+#endif
49902+ return 0;
49903+}
49904+
49905+int
49906+gr_handle_chroot_rawio(const struct inode *inode)
49907+{
49908+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49909+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
49910+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
49911+ return 1;
49912+#endif
49913+ return 0;
49914+}
49915+
49916+int
49917+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
49918+{
49919+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
49920+ struct task_struct *p;
49921+ int ret = 0;
49922+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
49923+ return ret;
49924+
49925+ read_lock(&tasklist_lock);
49926+ do_each_pid_task(pid, type, p) {
49927+ if (!have_same_root(current, p)) {
49928+ ret = 1;
49929+ goto out;
49930+ }
49931+ } while_each_pid_task(pid, type, p);
49932+out:
49933+ read_unlock(&tasklist_lock);
49934+ return ret;
49935+#endif
49936+ return 0;
49937+}
49938+
49939+int
49940+gr_pid_is_chrooted(struct task_struct *p)
49941+{
49942+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
49943+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
49944+ return 0;
49945+
49946+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
49947+ !have_same_root(current, p)) {
49948+ return 1;
49949+ }
49950+#endif
49951+ return 0;
49952+}
49953+
49954+EXPORT_SYMBOL(gr_pid_is_chrooted);
49955+
49956+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
49957+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
49958+{
49959+ struct path path, currentroot;
49960+ int ret = 0;
49961+
49962+ path.dentry = (struct dentry *)u_dentry;
49963+ path.mnt = (struct vfsmount *)u_mnt;
49964+ get_fs_root(current->fs, &currentroot);
49965+ if (path_is_under(&path, &currentroot))
49966+ ret = 1;
49967+ path_put(&currentroot);
49968+
49969+ return ret;
49970+}
49971+#endif
49972+
49973+int
49974+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
49975+{
49976+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
49977+ if (!grsec_enable_chroot_fchdir)
49978+ return 1;
49979+
49980+ if (!proc_is_chrooted(current))
49981+ return 1;
49982+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
49983+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
49984+ return 0;
49985+ }
49986+#endif
49987+ return 1;
49988+}
49989+
49990+int
49991+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
49992+ const time_t shm_createtime)
49993+{
49994+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
49995+ struct task_struct *p;
49996+ time_t starttime;
49997+
49998+ if (unlikely(!grsec_enable_chroot_shmat))
49999+ return 1;
50000+
50001+ if (likely(!proc_is_chrooted(current)))
50002+ return 1;
50003+
50004+ rcu_read_lock();
50005+ read_lock(&tasklist_lock);
50006+
50007+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
50008+ starttime = p->start_time.tv_sec;
50009+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
50010+ if (have_same_root(current, p)) {
50011+ goto allow;
50012+ } else {
50013+ read_unlock(&tasklist_lock);
50014+ rcu_read_unlock();
50015+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
50016+ return 0;
50017+ }
50018+ }
50019+ /* creator exited, pid reuse, fall through to next check */
50020+ }
50021+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
50022+ if (unlikely(!have_same_root(current, p))) {
50023+ read_unlock(&tasklist_lock);
50024+ rcu_read_unlock();
50025+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
50026+ return 0;
50027+ }
50028+ }
50029+
50030+allow:
50031+ read_unlock(&tasklist_lock);
50032+ rcu_read_unlock();
50033+#endif
50034+ return 1;
50035+}
50036+
50037+void
50038+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
50039+{
50040+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
50041+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
50042+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
50043+#endif
50044+ return;
50045+}
50046+
50047+int
50048+gr_handle_chroot_mknod(const struct dentry *dentry,
50049+ const struct vfsmount *mnt, const int mode)
50050+{
50051+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
50052+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
50053+ proc_is_chrooted(current)) {
50054+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
50055+ return -EPERM;
50056+ }
50057+#endif
50058+ return 0;
50059+}
50060+
50061+int
50062+gr_handle_chroot_mount(const struct dentry *dentry,
50063+ const struct vfsmount *mnt, const char *dev_name)
50064+{
50065+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
50066+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
50067+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
50068+ return -EPERM;
50069+ }
50070+#endif
50071+ return 0;
50072+}
50073+
50074+int
50075+gr_handle_chroot_pivot(void)
50076+{
50077+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
50078+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
50079+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
50080+ return -EPERM;
50081+ }
50082+#endif
50083+ return 0;
50084+}
50085+
50086+int
50087+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
50088+{
50089+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
50090+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
50091+ !gr_is_outside_chroot(dentry, mnt)) {
50092+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
50093+ return -EPERM;
50094+ }
50095+#endif
50096+ return 0;
50097+}
50098+
50099+int
50100+gr_handle_chroot_caps(struct path *path)
50101+{
50102+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50103+ if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
50104+ (init_task.fs->root.dentry != path->dentry) &&
50105+ (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
50106+
50107+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
50108+ const struct cred *old = current_cred();
50109+ struct cred *new = prepare_creds();
50110+ if (new == NULL)
50111+ return 1;
50112+
50113+ new->cap_permitted = cap_drop(old->cap_permitted,
50114+ chroot_caps);
50115+ new->cap_inheritable = cap_drop(old->cap_inheritable,
50116+ chroot_caps);
50117+ new->cap_effective = cap_drop(old->cap_effective,
50118+ chroot_caps);
50119+
50120+ commit_creds(new);
50121+
50122+ return 0;
50123+ }
50124+#endif
50125+ return 0;
50126+}
50127+
50128+int
50129+gr_handle_chroot_sysctl(const int op)
50130+{
50131+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
50132+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
50133+ proc_is_chrooted(current))
50134+ return -EACCES;
50135+#endif
50136+ return 0;
50137+}
50138+
50139+void
50140+gr_handle_chroot_chdir(struct path *path)
50141+{
50142+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
50143+ if (grsec_enable_chroot_chdir)
50144+ set_fs_pwd(current->fs, path);
50145+#endif
50146+ return;
50147+}
50148+
50149+int
50150+gr_handle_chroot_chmod(const struct dentry *dentry,
50151+ const struct vfsmount *mnt, const int mode)
50152+{
50153+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
50154+ /* allow chmod +s on directories, but not files */
50155+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
50156+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
50157+ proc_is_chrooted(current)) {
50158+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
50159+ return -EPERM;
50160+ }
50161+#endif
50162+ return 0;
50163+}
50164+
50165+#ifdef CONFIG_SECURITY
50166+EXPORT_SYMBOL(gr_handle_chroot_caps);
50167+#endif
50168diff -urNp linux-3.0.4/grsecurity/grsec_disabled.c linux-3.0.4/grsecurity/grsec_disabled.c
50169--- linux-3.0.4/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
50170+++ linux-3.0.4/grsecurity/grsec_disabled.c 2011-08-23 21:48:14.000000000 -0400
50171@@ -0,0 +1,447 @@
50172+#include <linux/kernel.h>
50173+#include <linux/module.h>
50174+#include <linux/sched.h>
50175+#include <linux/file.h>
50176+#include <linux/fs.h>
50177+#include <linux/kdev_t.h>
50178+#include <linux/net.h>
50179+#include <linux/in.h>
50180+#include <linux/ip.h>
50181+#include <linux/skbuff.h>
50182+#include <linux/sysctl.h>
50183+
50184+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50185+void
50186+pax_set_initial_flags(struct linux_binprm *bprm)
50187+{
50188+ return;
50189+}
50190+#endif
50191+
50192+#ifdef CONFIG_SYSCTL
50193+__u32
50194+gr_handle_sysctl(const struct ctl_table * table, const int op)
50195+{
50196+ return 0;
50197+}
50198+#endif
50199+
50200+#ifdef CONFIG_TASKSTATS
50201+int gr_is_taskstats_denied(int pid)
50202+{
50203+ return 0;
50204+}
50205+#endif
50206+
50207+int
50208+gr_acl_is_enabled(void)
50209+{
50210+ return 0;
50211+}
50212+
50213+int
50214+gr_handle_rawio(const struct inode *inode)
50215+{
50216+ return 0;
50217+}
50218+
50219+void
50220+gr_acl_handle_psacct(struct task_struct *task, const long code)
50221+{
50222+ return;
50223+}
50224+
50225+int
50226+gr_handle_ptrace(struct task_struct *task, const long request)
50227+{
50228+ return 0;
50229+}
50230+
50231+int
50232+gr_handle_proc_ptrace(struct task_struct *task)
50233+{
50234+ return 0;
50235+}
50236+
50237+void
50238+gr_learn_resource(const struct task_struct *task,
50239+ const int res, const unsigned long wanted, const int gt)
50240+{
50241+ return;
50242+}
50243+
50244+int
50245+gr_set_acls(const int type)
50246+{
50247+ return 0;
50248+}
50249+
50250+int
50251+gr_check_hidden_task(const struct task_struct *tsk)
50252+{
50253+ return 0;
50254+}
50255+
50256+int
50257+gr_check_protected_task(const struct task_struct *task)
50258+{
50259+ return 0;
50260+}
50261+
50262+int
50263+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
50264+{
50265+ return 0;
50266+}
50267+
50268+void
50269+gr_copy_label(struct task_struct *tsk)
50270+{
50271+ return;
50272+}
50273+
50274+void
50275+gr_set_pax_flags(struct task_struct *task)
50276+{
50277+ return;
50278+}
50279+
50280+int
50281+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
50282+ const int unsafe_share)
50283+{
50284+ return 0;
50285+}
50286+
50287+void
50288+gr_handle_delete(const ino_t ino, const dev_t dev)
50289+{
50290+ return;
50291+}
50292+
50293+void
50294+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
50295+{
50296+ return;
50297+}
50298+
50299+void
50300+gr_handle_crash(struct task_struct *task, const int sig)
50301+{
50302+ return;
50303+}
50304+
50305+int
50306+gr_check_crash_exec(const struct file *filp)
50307+{
50308+ return 0;
50309+}
50310+
50311+int
50312+gr_check_crash_uid(const uid_t uid)
50313+{
50314+ return 0;
50315+}
50316+
50317+void
50318+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
50319+ struct dentry *old_dentry,
50320+ struct dentry *new_dentry,
50321+ struct vfsmount *mnt, const __u8 replace)
50322+{
50323+ return;
50324+}
50325+
50326+int
50327+gr_search_socket(const int family, const int type, const int protocol)
50328+{
50329+ return 1;
50330+}
50331+
50332+int
50333+gr_search_connectbind(const int mode, const struct socket *sock,
50334+ const struct sockaddr_in *addr)
50335+{
50336+ return 0;
50337+}
50338+
50339+int
50340+gr_is_capable(const int cap)
50341+{
50342+ return 1;
50343+}
50344+
50345+int
50346+gr_is_capable_nolog(const int cap)
50347+{
50348+ return 1;
50349+}
50350+
50351+void
50352+gr_handle_alertkill(struct task_struct *task)
50353+{
50354+ return;
50355+}
50356+
50357+__u32
50358+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
50359+{
50360+ return 1;
50361+}
50362+
50363+__u32
50364+gr_acl_handle_hidden_file(const struct dentry * dentry,
50365+ const struct vfsmount * mnt)
50366+{
50367+ return 1;
50368+}
50369+
50370+__u32
50371+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
50372+ const int fmode)
50373+{
50374+ return 1;
50375+}
50376+
50377+__u32
50378+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
50379+{
50380+ return 1;
50381+}
50382+
50383+__u32
50384+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
50385+{
50386+ return 1;
50387+}
50388+
50389+int
50390+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
50391+ unsigned int *vm_flags)
50392+{
50393+ return 1;
50394+}
50395+
50396+__u32
50397+gr_acl_handle_truncate(const struct dentry * dentry,
50398+ const struct vfsmount * mnt)
50399+{
50400+ return 1;
50401+}
50402+
50403+__u32
50404+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
50405+{
50406+ return 1;
50407+}
50408+
50409+__u32
50410+gr_acl_handle_access(const struct dentry * dentry,
50411+ const struct vfsmount * mnt, const int fmode)
50412+{
50413+ return 1;
50414+}
50415+
50416+__u32
50417+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
50418+ mode_t mode)
50419+{
50420+ return 1;
50421+}
50422+
50423+__u32
50424+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
50425+ mode_t mode)
50426+{
50427+ return 1;
50428+}
50429+
50430+__u32
50431+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
50432+{
50433+ return 1;
50434+}
50435+
50436+__u32
50437+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
50438+{
50439+ return 1;
50440+}
50441+
50442+void
50443+grsecurity_init(void)
50444+{
50445+ return;
50446+}
50447+
50448+__u32
50449+gr_acl_handle_mknod(const struct dentry * new_dentry,
50450+ const struct dentry * parent_dentry,
50451+ const struct vfsmount * parent_mnt,
50452+ const int mode)
50453+{
50454+ return 1;
50455+}
50456+
50457+__u32
50458+gr_acl_handle_mkdir(const struct dentry * new_dentry,
50459+ const struct dentry * parent_dentry,
50460+ const struct vfsmount * parent_mnt)
50461+{
50462+ return 1;
50463+}
50464+
50465+__u32
50466+gr_acl_handle_symlink(const struct dentry * new_dentry,
50467+ const struct dentry * parent_dentry,
50468+ const struct vfsmount * parent_mnt, const char *from)
50469+{
50470+ return 1;
50471+}
50472+
50473+__u32
50474+gr_acl_handle_link(const struct dentry * new_dentry,
50475+ const struct dentry * parent_dentry,
50476+ const struct vfsmount * parent_mnt,
50477+ const struct dentry * old_dentry,
50478+ const struct vfsmount * old_mnt, const char *to)
50479+{
50480+ return 1;
50481+}
50482+
50483+int
50484+gr_acl_handle_rename(const struct dentry *new_dentry,
50485+ const struct dentry *parent_dentry,
50486+ const struct vfsmount *parent_mnt,
50487+ const struct dentry *old_dentry,
50488+ const struct inode *old_parent_inode,
50489+ const struct vfsmount *old_mnt, const char *newname)
50490+{
50491+ return 0;
50492+}
50493+
50494+int
50495+gr_acl_handle_filldir(const struct file *file, const char *name,
50496+ const int namelen, const ino_t ino)
50497+{
50498+ return 1;
50499+}
50500+
50501+int
50502+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
50503+ const time_t shm_createtime, const uid_t cuid, const int shmid)
50504+{
50505+ return 1;
50506+}
50507+
50508+int
50509+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
50510+{
50511+ return 0;
50512+}
50513+
50514+int
50515+gr_search_accept(const struct socket *sock)
50516+{
50517+ return 0;
50518+}
50519+
50520+int
50521+gr_search_listen(const struct socket *sock)
50522+{
50523+ return 0;
50524+}
50525+
50526+int
50527+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
50528+{
50529+ return 0;
50530+}
50531+
50532+__u32
50533+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
50534+{
50535+ return 1;
50536+}
50537+
50538+__u32
50539+gr_acl_handle_creat(const struct dentry * dentry,
50540+ const struct dentry * p_dentry,
50541+ const struct vfsmount * p_mnt, const int fmode,
50542+ const int imode)
50543+{
50544+ return 1;
50545+}
50546+
50547+void
50548+gr_acl_handle_exit(void)
50549+{
50550+ return;
50551+}
50552+
50553+int
50554+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
50555+{
50556+ return 1;
50557+}
50558+
50559+void
50560+gr_set_role_label(const uid_t uid, const gid_t gid)
50561+{
50562+ return;
50563+}
50564+
50565+int
50566+gr_acl_handle_procpidmem(const struct task_struct *task)
50567+{
50568+ return 0;
50569+}
50570+
50571+int
50572+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
50573+{
50574+ return 0;
50575+}
50576+
50577+int
50578+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
50579+{
50580+ return 0;
50581+}
50582+
50583+void
50584+gr_set_kernel_label(struct task_struct *task)
50585+{
50586+ return;
50587+}
50588+
50589+int
50590+gr_check_user_change(int real, int effective, int fs)
50591+{
50592+ return 0;
50593+}
50594+
50595+int
50596+gr_check_group_change(int real, int effective, int fs)
50597+{
50598+ return 0;
50599+}
50600+
50601+int gr_acl_enable_at_secure(void)
50602+{
50603+ return 0;
50604+}
50605+
50606+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50607+{
50608+ return dentry->d_inode->i_sb->s_dev;
50609+}
50610+
50611+EXPORT_SYMBOL(gr_is_capable);
50612+EXPORT_SYMBOL(gr_is_capable_nolog);
50613+EXPORT_SYMBOL(gr_learn_resource);
50614+EXPORT_SYMBOL(gr_set_kernel_label);
50615+#ifdef CONFIG_SECURITY
50616+EXPORT_SYMBOL(gr_check_user_change);
50617+EXPORT_SYMBOL(gr_check_group_change);
50618+#endif
50619diff -urNp linux-3.0.4/grsecurity/grsec_exec.c linux-3.0.4/grsecurity/grsec_exec.c
50620--- linux-3.0.4/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
50621+++ linux-3.0.4/grsecurity/grsec_exec.c 2011-08-25 17:25:59.000000000 -0400
50622@@ -0,0 +1,72 @@
50623+#include <linux/kernel.h>
50624+#include <linux/sched.h>
50625+#include <linux/file.h>
50626+#include <linux/binfmts.h>
50627+#include <linux/fs.h>
50628+#include <linux/types.h>
50629+#include <linux/grdefs.h>
50630+#include <linux/grsecurity.h>
50631+#include <linux/grinternal.h>
50632+#include <linux/capability.h>
50633+
50634+#include <asm/uaccess.h>
50635+
50636+#ifdef CONFIG_GRKERNSEC_EXECLOG
50637+static char gr_exec_arg_buf[132];
50638+static DEFINE_MUTEX(gr_exec_arg_mutex);
50639+#endif
50640+
50641+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
50642+
50643+void
50644+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
50645+{
50646+#ifdef CONFIG_GRKERNSEC_EXECLOG
50647+ char *grarg = gr_exec_arg_buf;
50648+ unsigned int i, x, execlen = 0;
50649+ char c;
50650+
50651+ if (!((grsec_enable_execlog && grsec_enable_group &&
50652+ in_group_p(grsec_audit_gid))
50653+ || (grsec_enable_execlog && !grsec_enable_group)))
50654+ return;
50655+
50656+ mutex_lock(&gr_exec_arg_mutex);
50657+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
50658+
50659+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
50660+ const char __user *p;
50661+ unsigned int len;
50662+
50663+ p = get_user_arg_ptr(argv, i);
50664+ if (IS_ERR(p))
50665+ goto log;
50666+
50667+ len = strnlen_user(p, 128 - execlen);
50668+ if (len > 128 - execlen)
50669+ len = 128 - execlen;
50670+ else if (len > 0)
50671+ len--;
50672+ if (copy_from_user(grarg + execlen, p, len))
50673+ goto log;
50674+
50675+ /* rewrite unprintable characters */
50676+ for (x = 0; x < len; x++) {
50677+ c = *(grarg + execlen + x);
50678+ if (c < 32 || c > 126)
50679+ *(grarg + execlen + x) = ' ';
50680+ }
50681+
50682+ execlen += len;
50683+ *(grarg + execlen) = ' ';
50684+ *(grarg + execlen + 1) = '\0';
50685+ execlen++;
50686+ }
50687+
50688+ log:
50689+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
50690+ bprm->file->f_path.mnt, grarg);
50691+ mutex_unlock(&gr_exec_arg_mutex);
50692+#endif
50693+ return;
50694+}
50695diff -urNp linux-3.0.4/grsecurity/grsec_fifo.c linux-3.0.4/grsecurity/grsec_fifo.c
50696--- linux-3.0.4/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
50697+++ linux-3.0.4/grsecurity/grsec_fifo.c 2011-08-23 21:48:14.000000000 -0400
50698@@ -0,0 +1,24 @@
50699+#include <linux/kernel.h>
50700+#include <linux/sched.h>
50701+#include <linux/fs.h>
50702+#include <linux/file.h>
50703+#include <linux/grinternal.h>
50704+
50705+int
50706+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
50707+ const struct dentry *dir, const int flag, const int acc_mode)
50708+{
50709+#ifdef CONFIG_GRKERNSEC_FIFO
50710+ const struct cred *cred = current_cred();
50711+
50712+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
50713+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
50714+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
50715+ (cred->fsuid != dentry->d_inode->i_uid)) {
50716+ if (!inode_permission(dentry->d_inode, acc_mode))
50717+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
50718+ return -EACCES;
50719+ }
50720+#endif
50721+ return 0;
50722+}
50723diff -urNp linux-3.0.4/grsecurity/grsec_fork.c linux-3.0.4/grsecurity/grsec_fork.c
50724--- linux-3.0.4/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
50725+++ linux-3.0.4/grsecurity/grsec_fork.c 2011-08-23 21:48:14.000000000 -0400
50726@@ -0,0 +1,23 @@
50727+#include <linux/kernel.h>
50728+#include <linux/sched.h>
50729+#include <linux/grsecurity.h>
50730+#include <linux/grinternal.h>
50731+#include <linux/errno.h>
50732+
50733+void
50734+gr_log_forkfail(const int retval)
50735+{
50736+#ifdef CONFIG_GRKERNSEC_FORKFAIL
50737+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
50738+ switch (retval) {
50739+ case -EAGAIN:
50740+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
50741+ break;
50742+ case -ENOMEM:
50743+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
50744+ break;
50745+ }
50746+ }
50747+#endif
50748+ return;
50749+}
50750diff -urNp linux-3.0.4/grsecurity/grsec_init.c linux-3.0.4/grsecurity/grsec_init.c
50751--- linux-3.0.4/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
50752+++ linux-3.0.4/grsecurity/grsec_init.c 2011-08-25 17:25:12.000000000 -0400
50753@@ -0,0 +1,269 @@
50754+#include <linux/kernel.h>
50755+#include <linux/sched.h>
50756+#include <linux/mm.h>
50757+#include <linux/gracl.h>
50758+#include <linux/slab.h>
50759+#include <linux/vmalloc.h>
50760+#include <linux/percpu.h>
50761+#include <linux/module.h>
50762+
50763+int grsec_enable_brute;
50764+int grsec_enable_link;
50765+int grsec_enable_dmesg;
50766+int grsec_enable_harden_ptrace;
50767+int grsec_enable_fifo;
50768+int grsec_enable_execlog;
50769+int grsec_enable_signal;
50770+int grsec_enable_forkfail;
50771+int grsec_enable_audit_ptrace;
50772+int grsec_enable_time;
50773+int grsec_enable_audit_textrel;
50774+int grsec_enable_group;
50775+int grsec_audit_gid;
50776+int grsec_enable_chdir;
50777+int grsec_enable_mount;
50778+int grsec_enable_rofs;
50779+int grsec_enable_chroot_findtask;
50780+int grsec_enable_chroot_mount;
50781+int grsec_enable_chroot_shmat;
50782+int grsec_enable_chroot_fchdir;
50783+int grsec_enable_chroot_double;
50784+int grsec_enable_chroot_pivot;
50785+int grsec_enable_chroot_chdir;
50786+int grsec_enable_chroot_chmod;
50787+int grsec_enable_chroot_mknod;
50788+int grsec_enable_chroot_nice;
50789+int grsec_enable_chroot_execlog;
50790+int grsec_enable_chroot_caps;
50791+int grsec_enable_chroot_sysctl;
50792+int grsec_enable_chroot_unix;
50793+int grsec_enable_tpe;
50794+int grsec_tpe_gid;
50795+int grsec_enable_blackhole;
50796+#ifdef CONFIG_IPV6_MODULE
50797+EXPORT_SYMBOL(grsec_enable_blackhole);
50798+#endif
50799+int grsec_lastack_retries;
50800+int grsec_enable_tpe_all;
50801+int grsec_enable_tpe_invert;
50802+int grsec_enable_socket_all;
50803+int grsec_socket_all_gid;
50804+int grsec_enable_socket_client;
50805+int grsec_socket_client_gid;
50806+int grsec_enable_socket_server;
50807+int grsec_socket_server_gid;
50808+int grsec_resource_logging;
50809+int grsec_disable_privio;
50810+int grsec_enable_log_rwxmaps;
50811+int grsec_lock;
50812+
50813+DEFINE_SPINLOCK(grsec_alert_lock);
50814+unsigned long grsec_alert_wtime = 0;
50815+unsigned long grsec_alert_fyet = 0;
50816+
50817+DEFINE_SPINLOCK(grsec_audit_lock);
50818+
50819+DEFINE_RWLOCK(grsec_exec_file_lock);
50820+
50821+char *gr_shared_page[4];
50822+
50823+char *gr_alert_log_fmt;
50824+char *gr_audit_log_fmt;
50825+char *gr_alert_log_buf;
50826+char *gr_audit_log_buf;
50827+
50828+extern struct gr_arg *gr_usermode;
50829+extern unsigned char *gr_system_salt;
50830+extern unsigned char *gr_system_sum;
50831+
50832+void __init
50833+grsecurity_init(void)
50834+{
50835+ int j;
50836+ /* create the per-cpu shared pages */
50837+
50838+#ifdef CONFIG_X86
50839+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
50840+#endif
50841+
50842+ for (j = 0; j < 4; j++) {
50843+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
50844+ if (gr_shared_page[j] == NULL) {
50845+ panic("Unable to allocate grsecurity shared page");
50846+ return;
50847+ }
50848+ }
50849+
50850+ /* allocate log buffers */
50851+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
50852+ if (!gr_alert_log_fmt) {
50853+ panic("Unable to allocate grsecurity alert log format buffer");
50854+ return;
50855+ }
50856+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
50857+ if (!gr_audit_log_fmt) {
50858+ panic("Unable to allocate grsecurity audit log format buffer");
50859+ return;
50860+ }
50861+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
50862+ if (!gr_alert_log_buf) {
50863+ panic("Unable to allocate grsecurity alert log buffer");
50864+ return;
50865+ }
50866+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
50867+ if (!gr_audit_log_buf) {
50868+ panic("Unable to allocate grsecurity audit log buffer");
50869+ return;
50870+ }
50871+
50872+ /* allocate memory for authentication structure */
50873+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
50874+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
50875+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
50876+
50877+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
50878+ panic("Unable to allocate grsecurity authentication structure");
50879+ return;
50880+ }
50881+
50882+
50883+#ifdef CONFIG_GRKERNSEC_IO
50884+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
50885+ grsec_disable_privio = 1;
50886+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
50887+ grsec_disable_privio = 1;
50888+#else
50889+ grsec_disable_privio = 0;
50890+#endif
50891+#endif
50892+
50893+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
50894+ /* for backward compatibility, tpe_invert always defaults to on if
50895+ enabled in the kernel
50896+ */
50897+ grsec_enable_tpe_invert = 1;
50898+#endif
50899+
50900+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
50901+#ifndef CONFIG_GRKERNSEC_SYSCTL
50902+ grsec_lock = 1;
50903+#endif
50904+
50905+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
50906+ grsec_enable_audit_textrel = 1;
50907+#endif
50908+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
50909+ grsec_enable_log_rwxmaps = 1;
50910+#endif
50911+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
50912+ grsec_enable_group = 1;
50913+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
50914+#endif
50915+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
50916+ grsec_enable_chdir = 1;
50917+#endif
50918+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
50919+ grsec_enable_harden_ptrace = 1;
50920+#endif
50921+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
50922+ grsec_enable_mount = 1;
50923+#endif
50924+#ifdef CONFIG_GRKERNSEC_LINK
50925+ grsec_enable_link = 1;
50926+#endif
50927+#ifdef CONFIG_GRKERNSEC_BRUTE
50928+ grsec_enable_brute = 1;
50929+#endif
50930+#ifdef CONFIG_GRKERNSEC_DMESG
50931+ grsec_enable_dmesg = 1;
50932+#endif
50933+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
50934+ grsec_enable_blackhole = 1;
50935+ grsec_lastack_retries = 4;
50936+#endif
50937+#ifdef CONFIG_GRKERNSEC_FIFO
50938+ grsec_enable_fifo = 1;
50939+#endif
50940+#ifdef CONFIG_GRKERNSEC_EXECLOG
50941+ grsec_enable_execlog = 1;
50942+#endif
50943+#ifdef CONFIG_GRKERNSEC_SIGNAL
50944+ grsec_enable_signal = 1;
50945+#endif
50946+#ifdef CONFIG_GRKERNSEC_FORKFAIL
50947+ grsec_enable_forkfail = 1;
50948+#endif
50949+#ifdef CONFIG_GRKERNSEC_TIME
50950+ grsec_enable_time = 1;
50951+#endif
50952+#ifdef CONFIG_GRKERNSEC_RESLOG
50953+ grsec_resource_logging = 1;
50954+#endif
50955+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
50956+ grsec_enable_chroot_findtask = 1;
50957+#endif
50958+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
50959+ grsec_enable_chroot_unix = 1;
50960+#endif
50961+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
50962+ grsec_enable_chroot_mount = 1;
50963+#endif
50964+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
50965+ grsec_enable_chroot_fchdir = 1;
50966+#endif
50967+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
50968+ grsec_enable_chroot_shmat = 1;
50969+#endif
50970+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
50971+ grsec_enable_audit_ptrace = 1;
50972+#endif
50973+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
50974+ grsec_enable_chroot_double = 1;
50975+#endif
50976+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
50977+ grsec_enable_chroot_pivot = 1;
50978+#endif
50979+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
50980+ grsec_enable_chroot_chdir = 1;
50981+#endif
50982+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
50983+ grsec_enable_chroot_chmod = 1;
50984+#endif
50985+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
50986+ grsec_enable_chroot_mknod = 1;
50987+#endif
50988+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
50989+ grsec_enable_chroot_nice = 1;
50990+#endif
50991+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
50992+ grsec_enable_chroot_execlog = 1;
50993+#endif
50994+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50995+ grsec_enable_chroot_caps = 1;
50996+#endif
50997+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
50998+ grsec_enable_chroot_sysctl = 1;
50999+#endif
51000+#ifdef CONFIG_GRKERNSEC_TPE
51001+ grsec_enable_tpe = 1;
51002+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
51003+#ifdef CONFIG_GRKERNSEC_TPE_ALL
51004+ grsec_enable_tpe_all = 1;
51005+#endif
51006+#endif
51007+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
51008+ grsec_enable_socket_all = 1;
51009+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
51010+#endif
51011+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
51012+ grsec_enable_socket_client = 1;
51013+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
51014+#endif
51015+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51016+ grsec_enable_socket_server = 1;
51017+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
51018+#endif
51019+#endif
51020+
51021+ return;
51022+}
51023diff -urNp linux-3.0.4/grsecurity/grsec_link.c linux-3.0.4/grsecurity/grsec_link.c
51024--- linux-3.0.4/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
51025+++ linux-3.0.4/grsecurity/grsec_link.c 2011-08-23 21:48:14.000000000 -0400
51026@@ -0,0 +1,43 @@
51027+#include <linux/kernel.h>
51028+#include <linux/sched.h>
51029+#include <linux/fs.h>
51030+#include <linux/file.h>
51031+#include <linux/grinternal.h>
51032+
51033+int
51034+gr_handle_follow_link(const struct inode *parent,
51035+ const struct inode *inode,
51036+ const struct dentry *dentry, const struct vfsmount *mnt)
51037+{
51038+#ifdef CONFIG_GRKERNSEC_LINK
51039+ const struct cred *cred = current_cred();
51040+
51041+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
51042+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
51043+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
51044+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
51045+ return -EACCES;
51046+ }
51047+#endif
51048+ return 0;
51049+}
51050+
51051+int
51052+gr_handle_hardlink(const struct dentry *dentry,
51053+ const struct vfsmount *mnt,
51054+ struct inode *inode, const int mode, const char *to)
51055+{
51056+#ifdef CONFIG_GRKERNSEC_LINK
51057+ const struct cred *cred = current_cred();
51058+
51059+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
51060+ (!S_ISREG(mode) || (mode & S_ISUID) ||
51061+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
51062+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
51063+ !capable(CAP_FOWNER) && cred->uid) {
51064+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
51065+ return -EPERM;
51066+ }
51067+#endif
51068+ return 0;
51069+}
51070diff -urNp linux-3.0.4/grsecurity/grsec_log.c linux-3.0.4/grsecurity/grsec_log.c
51071--- linux-3.0.4/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
51072+++ linux-3.0.4/grsecurity/grsec_log.c 2011-08-23 21:48:14.000000000 -0400
51073@@ -0,0 +1,310 @@
51074+#include <linux/kernel.h>
51075+#include <linux/sched.h>
51076+#include <linux/file.h>
51077+#include <linux/tty.h>
51078+#include <linux/fs.h>
51079+#include <linux/grinternal.h>
51080+
51081+#ifdef CONFIG_TREE_PREEMPT_RCU
51082+#define DISABLE_PREEMPT() preempt_disable()
51083+#define ENABLE_PREEMPT() preempt_enable()
51084+#else
51085+#define DISABLE_PREEMPT()
51086+#define ENABLE_PREEMPT()
51087+#endif
51088+
51089+#define BEGIN_LOCKS(x) \
51090+ DISABLE_PREEMPT(); \
51091+ rcu_read_lock(); \
51092+ read_lock(&tasklist_lock); \
51093+ read_lock(&grsec_exec_file_lock); \
51094+ if (x != GR_DO_AUDIT) \
51095+ spin_lock(&grsec_alert_lock); \
51096+ else \
51097+ spin_lock(&grsec_audit_lock)
51098+
51099+#define END_LOCKS(x) \
51100+ if (x != GR_DO_AUDIT) \
51101+ spin_unlock(&grsec_alert_lock); \
51102+ else \
51103+ spin_unlock(&grsec_audit_lock); \
51104+ read_unlock(&grsec_exec_file_lock); \
51105+ read_unlock(&tasklist_lock); \
51106+ rcu_read_unlock(); \
51107+ ENABLE_PREEMPT(); \
51108+ if (x == GR_DONT_AUDIT) \
51109+ gr_handle_alertkill(current)
51110+
51111+enum {
51112+ FLOODING,
51113+ NO_FLOODING
51114+};
51115+
51116+extern char *gr_alert_log_fmt;
51117+extern char *gr_audit_log_fmt;
51118+extern char *gr_alert_log_buf;
51119+extern char *gr_audit_log_buf;
51120+
51121+static int gr_log_start(int audit)
51122+{
51123+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
51124+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
51125+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51126+
51127+ if (audit == GR_DO_AUDIT)
51128+ goto set_fmt;
51129+
51130+ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
51131+ grsec_alert_wtime = jiffies;
51132+ grsec_alert_fyet = 0;
51133+ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
51134+ grsec_alert_fyet++;
51135+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
51136+ grsec_alert_wtime = jiffies;
51137+ grsec_alert_fyet++;
51138+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
51139+ return FLOODING;
51140+ } else return FLOODING;
51141+
51142+set_fmt:
51143+ memset(buf, 0, PAGE_SIZE);
51144+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
51145+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
51146+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
51147+ } else if (current->signal->curr_ip) {
51148+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
51149+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
51150+ } else if (gr_acl_is_enabled()) {
51151+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
51152+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
51153+ } else {
51154+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
51155+ strcpy(buf, fmt);
51156+ }
51157+
51158+ return NO_FLOODING;
51159+}
51160+
51161+static void gr_log_middle(int audit, const char *msg, va_list ap)
51162+ __attribute__ ((format (printf, 2, 0)));
51163+
51164+static void gr_log_middle(int audit, const char *msg, va_list ap)
51165+{
51166+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51167+ unsigned int len = strlen(buf);
51168+
51169+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
51170+
51171+ return;
51172+}
51173+
51174+static void gr_log_middle_varargs(int audit, const char *msg, ...)
51175+ __attribute__ ((format (printf, 2, 3)));
51176+
51177+static void gr_log_middle_varargs(int audit, const char *msg, ...)
51178+{
51179+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51180+ unsigned int len = strlen(buf);
51181+ va_list ap;
51182+
51183+ va_start(ap, msg);
51184+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
51185+ va_end(ap);
51186+
51187+ return;
51188+}
51189+
51190+static void gr_log_end(int audit)
51191+{
51192+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51193+ unsigned int len = strlen(buf);
51194+
51195+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
51196+ printk("%s\n", buf);
51197+
51198+ return;
51199+}
51200+
51201+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
51202+{
51203+ int logtype;
51204+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
51205+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
51206+ void *voidptr = NULL;
51207+ int num1 = 0, num2 = 0;
51208+ unsigned long ulong1 = 0, ulong2 = 0;
51209+ struct dentry *dentry = NULL;
51210+ struct vfsmount *mnt = NULL;
51211+ struct file *file = NULL;
51212+ struct task_struct *task = NULL;
51213+ const struct cred *cred, *pcred;
51214+ va_list ap;
51215+
51216+ BEGIN_LOCKS(audit);
51217+ logtype = gr_log_start(audit);
51218+ if (logtype == FLOODING) {
51219+ END_LOCKS(audit);
51220+ return;
51221+ }
51222+ va_start(ap, argtypes);
51223+ switch (argtypes) {
51224+ case GR_TTYSNIFF:
51225+ task = va_arg(ap, struct task_struct *);
51226+ 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);
51227+ break;
51228+ case GR_SYSCTL_HIDDEN:
51229+ str1 = va_arg(ap, char *);
51230+ gr_log_middle_varargs(audit, msg, result, str1);
51231+ break;
51232+ case GR_RBAC:
51233+ dentry = va_arg(ap, struct dentry *);
51234+ mnt = va_arg(ap, struct vfsmount *);
51235+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
51236+ break;
51237+ case GR_RBAC_STR:
51238+ dentry = va_arg(ap, struct dentry *);
51239+ mnt = va_arg(ap, struct vfsmount *);
51240+ str1 = va_arg(ap, char *);
51241+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
51242+ break;
51243+ case GR_STR_RBAC:
51244+ str1 = va_arg(ap, char *);
51245+ dentry = va_arg(ap, struct dentry *);
51246+ mnt = va_arg(ap, struct vfsmount *);
51247+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
51248+ break;
51249+ case GR_RBAC_MODE2:
51250+ dentry = va_arg(ap, struct dentry *);
51251+ mnt = va_arg(ap, struct vfsmount *);
51252+ str1 = va_arg(ap, char *);
51253+ str2 = va_arg(ap, char *);
51254+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
51255+ break;
51256+ case GR_RBAC_MODE3:
51257+ dentry = va_arg(ap, struct dentry *);
51258+ mnt = va_arg(ap, struct vfsmount *);
51259+ str1 = va_arg(ap, char *);
51260+ str2 = va_arg(ap, char *);
51261+ str3 = va_arg(ap, char *);
51262+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
51263+ break;
51264+ case GR_FILENAME:
51265+ dentry = va_arg(ap, struct dentry *);
51266+ mnt = va_arg(ap, struct vfsmount *);
51267+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
51268+ break;
51269+ case GR_STR_FILENAME:
51270+ str1 = va_arg(ap, char *);
51271+ dentry = va_arg(ap, struct dentry *);
51272+ mnt = va_arg(ap, struct vfsmount *);
51273+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
51274+ break;
51275+ case GR_FILENAME_STR:
51276+ dentry = va_arg(ap, struct dentry *);
51277+ mnt = va_arg(ap, struct vfsmount *);
51278+ str1 = va_arg(ap, char *);
51279+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
51280+ break;
51281+ case GR_FILENAME_TWO_INT:
51282+ dentry = va_arg(ap, struct dentry *);
51283+ mnt = va_arg(ap, struct vfsmount *);
51284+ num1 = va_arg(ap, int);
51285+ num2 = va_arg(ap, int);
51286+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
51287+ break;
51288+ case GR_FILENAME_TWO_INT_STR:
51289+ dentry = va_arg(ap, struct dentry *);
51290+ mnt = va_arg(ap, struct vfsmount *);
51291+ num1 = va_arg(ap, int);
51292+ num2 = va_arg(ap, int);
51293+ str1 = va_arg(ap, char *);
51294+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
51295+ break;
51296+ case GR_TEXTREL:
51297+ file = va_arg(ap, struct file *);
51298+ ulong1 = va_arg(ap, unsigned long);
51299+ ulong2 = va_arg(ap, unsigned long);
51300+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
51301+ break;
51302+ case GR_PTRACE:
51303+ task = va_arg(ap, struct task_struct *);
51304+ 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);
51305+ break;
51306+ case GR_RESOURCE:
51307+ task = va_arg(ap, struct task_struct *);
51308+ cred = __task_cred(task);
51309+ pcred = __task_cred(task->real_parent);
51310+ ulong1 = va_arg(ap, unsigned long);
51311+ str1 = va_arg(ap, char *);
51312+ ulong2 = va_arg(ap, unsigned long);
51313+ 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);
51314+ break;
51315+ case GR_CAP:
51316+ task = va_arg(ap, struct task_struct *);
51317+ cred = __task_cred(task);
51318+ pcred = __task_cred(task->real_parent);
51319+ str1 = va_arg(ap, char *);
51320+ 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);
51321+ break;
51322+ case GR_SIG:
51323+ str1 = va_arg(ap, char *);
51324+ voidptr = va_arg(ap, void *);
51325+ gr_log_middle_varargs(audit, msg, str1, voidptr);
51326+ break;
51327+ case GR_SIG2:
51328+ task = va_arg(ap, struct task_struct *);
51329+ cred = __task_cred(task);
51330+ pcred = __task_cred(task->real_parent);
51331+ num1 = va_arg(ap, int);
51332+ 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);
51333+ break;
51334+ case GR_CRASH1:
51335+ task = va_arg(ap, struct task_struct *);
51336+ cred = __task_cred(task);
51337+ pcred = __task_cred(task->real_parent);
51338+ ulong1 = va_arg(ap, unsigned long);
51339+ 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);
51340+ break;
51341+ case GR_CRASH2:
51342+ task = va_arg(ap, struct task_struct *);
51343+ cred = __task_cred(task);
51344+ pcred = __task_cred(task->real_parent);
51345+ ulong1 = va_arg(ap, unsigned long);
51346+ 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);
51347+ break;
51348+ case GR_RWXMAP:
51349+ file = va_arg(ap, struct file *);
51350+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
51351+ break;
51352+ case GR_PSACCT:
51353+ {
51354+ unsigned int wday, cday;
51355+ __u8 whr, chr;
51356+ __u8 wmin, cmin;
51357+ __u8 wsec, csec;
51358+ char cur_tty[64] = { 0 };
51359+ char parent_tty[64] = { 0 };
51360+
51361+ task = va_arg(ap, struct task_struct *);
51362+ wday = va_arg(ap, unsigned int);
51363+ cday = va_arg(ap, unsigned int);
51364+ whr = va_arg(ap, int);
51365+ chr = va_arg(ap, int);
51366+ wmin = va_arg(ap, int);
51367+ cmin = va_arg(ap, int);
51368+ wsec = va_arg(ap, int);
51369+ csec = va_arg(ap, int);
51370+ ulong1 = va_arg(ap, unsigned long);
51371+ cred = __task_cred(task);
51372+ pcred = __task_cred(task->real_parent);
51373+
51374+ 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);
51375+ }
51376+ break;
51377+ default:
51378+ gr_log_middle(audit, msg, ap);
51379+ }
51380+ va_end(ap);
51381+ gr_log_end(audit);
51382+ END_LOCKS(audit);
51383+}
51384diff -urNp linux-3.0.4/grsecurity/grsec_mem.c linux-3.0.4/grsecurity/grsec_mem.c
51385--- linux-3.0.4/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
51386+++ linux-3.0.4/grsecurity/grsec_mem.c 2011-08-23 21:48:14.000000000 -0400
51387@@ -0,0 +1,33 @@
51388+#include <linux/kernel.h>
51389+#include <linux/sched.h>
51390+#include <linux/mm.h>
51391+#include <linux/mman.h>
51392+#include <linux/grinternal.h>
51393+
51394+void
51395+gr_handle_ioperm(void)
51396+{
51397+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
51398+ return;
51399+}
51400+
51401+void
51402+gr_handle_iopl(void)
51403+{
51404+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
51405+ return;
51406+}
51407+
51408+void
51409+gr_handle_mem_readwrite(u64 from, u64 to)
51410+{
51411+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
51412+ return;
51413+}
51414+
51415+void
51416+gr_handle_vm86(void)
51417+{
51418+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
51419+ return;
51420+}
51421diff -urNp linux-3.0.4/grsecurity/grsec_mount.c linux-3.0.4/grsecurity/grsec_mount.c
51422--- linux-3.0.4/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
51423+++ linux-3.0.4/grsecurity/grsec_mount.c 2011-08-23 21:48:14.000000000 -0400
51424@@ -0,0 +1,62 @@
51425+#include <linux/kernel.h>
51426+#include <linux/sched.h>
51427+#include <linux/mount.h>
51428+#include <linux/grsecurity.h>
51429+#include <linux/grinternal.h>
51430+
51431+void
51432+gr_log_remount(const char *devname, const int retval)
51433+{
51434+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51435+ if (grsec_enable_mount && (retval >= 0))
51436+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
51437+#endif
51438+ return;
51439+}
51440+
51441+void
51442+gr_log_unmount(const char *devname, const int retval)
51443+{
51444+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51445+ if (grsec_enable_mount && (retval >= 0))
51446+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
51447+#endif
51448+ return;
51449+}
51450+
51451+void
51452+gr_log_mount(const char *from, const char *to, const int retval)
51453+{
51454+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51455+ if (grsec_enable_mount && (retval >= 0))
51456+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
51457+#endif
51458+ return;
51459+}
51460+
51461+int
51462+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
51463+{
51464+#ifdef CONFIG_GRKERNSEC_ROFS
51465+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
51466+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
51467+ return -EPERM;
51468+ } else
51469+ return 0;
51470+#endif
51471+ return 0;
51472+}
51473+
51474+int
51475+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
51476+{
51477+#ifdef CONFIG_GRKERNSEC_ROFS
51478+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
51479+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
51480+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
51481+ return -EPERM;
51482+ } else
51483+ return 0;
51484+#endif
51485+ return 0;
51486+}
51487diff -urNp linux-3.0.4/grsecurity/grsec_pax.c linux-3.0.4/grsecurity/grsec_pax.c
51488--- linux-3.0.4/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
51489+++ linux-3.0.4/grsecurity/grsec_pax.c 2011-08-23 21:48:14.000000000 -0400
51490@@ -0,0 +1,36 @@
51491+#include <linux/kernel.h>
51492+#include <linux/sched.h>
51493+#include <linux/mm.h>
51494+#include <linux/file.h>
51495+#include <linux/grinternal.h>
51496+#include <linux/grsecurity.h>
51497+
51498+void
51499+gr_log_textrel(struct vm_area_struct * vma)
51500+{
51501+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
51502+ if (grsec_enable_audit_textrel)
51503+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
51504+#endif
51505+ return;
51506+}
51507+
51508+void
51509+gr_log_rwxmmap(struct file *file)
51510+{
51511+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51512+ if (grsec_enable_log_rwxmaps)
51513+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
51514+#endif
51515+ return;
51516+}
51517+
51518+void
51519+gr_log_rwxmprotect(struct file *file)
51520+{
51521+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51522+ if (grsec_enable_log_rwxmaps)
51523+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
51524+#endif
51525+ return;
51526+}
51527diff -urNp linux-3.0.4/grsecurity/grsec_ptrace.c linux-3.0.4/grsecurity/grsec_ptrace.c
51528--- linux-3.0.4/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
51529+++ linux-3.0.4/grsecurity/grsec_ptrace.c 2011-08-23 21:48:14.000000000 -0400
51530@@ -0,0 +1,14 @@
51531+#include <linux/kernel.h>
51532+#include <linux/sched.h>
51533+#include <linux/grinternal.h>
51534+#include <linux/grsecurity.h>
51535+
51536+void
51537+gr_audit_ptrace(struct task_struct *task)
51538+{
51539+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
51540+ if (grsec_enable_audit_ptrace)
51541+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
51542+#endif
51543+ return;
51544+}
51545diff -urNp linux-3.0.4/grsecurity/grsec_sig.c linux-3.0.4/grsecurity/grsec_sig.c
51546--- linux-3.0.4/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
51547+++ linux-3.0.4/grsecurity/grsec_sig.c 2011-08-23 21:48:14.000000000 -0400
51548@@ -0,0 +1,206 @@
51549+#include <linux/kernel.h>
51550+#include <linux/sched.h>
51551+#include <linux/delay.h>
51552+#include <linux/grsecurity.h>
51553+#include <linux/grinternal.h>
51554+#include <linux/hardirq.h>
51555+
51556+char *signames[] = {
51557+ [SIGSEGV] = "Segmentation fault",
51558+ [SIGILL] = "Illegal instruction",
51559+ [SIGABRT] = "Abort",
51560+ [SIGBUS] = "Invalid alignment/Bus error"
51561+};
51562+
51563+void
51564+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
51565+{
51566+#ifdef CONFIG_GRKERNSEC_SIGNAL
51567+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
51568+ (sig == SIGABRT) || (sig == SIGBUS))) {
51569+ if (t->pid == current->pid) {
51570+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
51571+ } else {
51572+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
51573+ }
51574+ }
51575+#endif
51576+ return;
51577+}
51578+
51579+int
51580+gr_handle_signal(const struct task_struct *p, const int sig)
51581+{
51582+#ifdef CONFIG_GRKERNSEC
51583+ if (current->pid > 1 && gr_check_protected_task(p)) {
51584+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
51585+ return -EPERM;
51586+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
51587+ return -EPERM;
51588+ }
51589+#endif
51590+ return 0;
51591+}
51592+
51593+#ifdef CONFIG_GRKERNSEC
51594+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
51595+
51596+int gr_fake_force_sig(int sig, struct task_struct *t)
51597+{
51598+ unsigned long int flags;
51599+ int ret, blocked, ignored;
51600+ struct k_sigaction *action;
51601+
51602+ spin_lock_irqsave(&t->sighand->siglock, flags);
51603+ action = &t->sighand->action[sig-1];
51604+ ignored = action->sa.sa_handler == SIG_IGN;
51605+ blocked = sigismember(&t->blocked, sig);
51606+ if (blocked || ignored) {
51607+ action->sa.sa_handler = SIG_DFL;
51608+ if (blocked) {
51609+ sigdelset(&t->blocked, sig);
51610+ recalc_sigpending_and_wake(t);
51611+ }
51612+ }
51613+ if (action->sa.sa_handler == SIG_DFL)
51614+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
51615+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
51616+
51617+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
51618+
51619+ return ret;
51620+}
51621+#endif
51622+
51623+#ifdef CONFIG_GRKERNSEC_BRUTE
51624+#define GR_USER_BAN_TIME (15 * 60)
51625+
51626+static int __get_dumpable(unsigned long mm_flags)
51627+{
51628+ int ret;
51629+
51630+ ret = mm_flags & MMF_DUMPABLE_MASK;
51631+ return (ret >= 2) ? 2 : ret;
51632+}
51633+#endif
51634+
51635+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
51636+{
51637+#ifdef CONFIG_GRKERNSEC_BRUTE
51638+ uid_t uid = 0;
51639+
51640+ if (!grsec_enable_brute)
51641+ return;
51642+
51643+ rcu_read_lock();
51644+ read_lock(&tasklist_lock);
51645+ read_lock(&grsec_exec_file_lock);
51646+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
51647+ p->real_parent->brute = 1;
51648+ else {
51649+ const struct cred *cred = __task_cred(p), *cred2;
51650+ struct task_struct *tsk, *tsk2;
51651+
51652+ if (!__get_dumpable(mm_flags) && cred->uid) {
51653+ struct user_struct *user;
51654+
51655+ uid = cred->uid;
51656+
51657+ /* this is put upon execution past expiration */
51658+ user = find_user(uid);
51659+ if (user == NULL)
51660+ goto unlock;
51661+ user->banned = 1;
51662+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
51663+ if (user->ban_expires == ~0UL)
51664+ user->ban_expires--;
51665+
51666+ do_each_thread(tsk2, tsk) {
51667+ cred2 = __task_cred(tsk);
51668+ if (tsk != p && cred2->uid == uid)
51669+ gr_fake_force_sig(SIGKILL, tsk);
51670+ } while_each_thread(tsk2, tsk);
51671+ }
51672+ }
51673+unlock:
51674+ read_unlock(&grsec_exec_file_lock);
51675+ read_unlock(&tasklist_lock);
51676+ rcu_read_unlock();
51677+
51678+ if (uid)
51679+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
51680+
51681+#endif
51682+ return;
51683+}
51684+
51685+void gr_handle_brute_check(void)
51686+{
51687+#ifdef CONFIG_GRKERNSEC_BRUTE
51688+ if (current->brute)
51689+ msleep(30 * 1000);
51690+#endif
51691+ return;
51692+}
51693+
51694+void gr_handle_kernel_exploit(void)
51695+{
51696+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
51697+ const struct cred *cred;
51698+ struct task_struct *tsk, *tsk2;
51699+ struct user_struct *user;
51700+ uid_t uid;
51701+
51702+ if (in_irq() || in_serving_softirq() || in_nmi())
51703+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
51704+
51705+ uid = current_uid();
51706+
51707+ if (uid == 0)
51708+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
51709+ else {
51710+ /* kill all the processes of this user, hold a reference
51711+ to their creds struct, and prevent them from creating
51712+ another process until system reset
51713+ */
51714+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
51715+ /* we intentionally leak this ref */
51716+ user = get_uid(current->cred->user);
51717+ if (user) {
51718+ user->banned = 1;
51719+ user->ban_expires = ~0UL;
51720+ }
51721+
51722+ read_lock(&tasklist_lock);
51723+ do_each_thread(tsk2, tsk) {
51724+ cred = __task_cred(tsk);
51725+ if (cred->uid == uid)
51726+ gr_fake_force_sig(SIGKILL, tsk);
51727+ } while_each_thread(tsk2, tsk);
51728+ read_unlock(&tasklist_lock);
51729+ }
51730+#endif
51731+}
51732+
51733+int __gr_process_user_ban(struct user_struct *user)
51734+{
51735+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51736+ if (unlikely(user->banned)) {
51737+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
51738+ user->banned = 0;
51739+ user->ban_expires = 0;
51740+ free_uid(user);
51741+ } else
51742+ return -EPERM;
51743+ }
51744+#endif
51745+ return 0;
51746+}
51747+
51748+int gr_process_user_ban(void)
51749+{
51750+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51751+ return __gr_process_user_ban(current->cred->user);
51752+#endif
51753+ return 0;
51754+}
51755diff -urNp linux-3.0.4/grsecurity/grsec_sock.c linux-3.0.4/grsecurity/grsec_sock.c
51756--- linux-3.0.4/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
51757+++ linux-3.0.4/grsecurity/grsec_sock.c 2011-08-23 21:48:14.000000000 -0400
51758@@ -0,0 +1,244 @@
51759+#include <linux/kernel.h>
51760+#include <linux/module.h>
51761+#include <linux/sched.h>
51762+#include <linux/file.h>
51763+#include <linux/net.h>
51764+#include <linux/in.h>
51765+#include <linux/ip.h>
51766+#include <net/sock.h>
51767+#include <net/inet_sock.h>
51768+#include <linux/grsecurity.h>
51769+#include <linux/grinternal.h>
51770+#include <linux/gracl.h>
51771+
51772+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
51773+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
51774+
51775+EXPORT_SYMBOL(gr_search_udp_recvmsg);
51776+EXPORT_SYMBOL(gr_search_udp_sendmsg);
51777+
51778+#ifdef CONFIG_UNIX_MODULE
51779+EXPORT_SYMBOL(gr_acl_handle_unix);
51780+EXPORT_SYMBOL(gr_acl_handle_mknod);
51781+EXPORT_SYMBOL(gr_handle_chroot_unix);
51782+EXPORT_SYMBOL(gr_handle_create);
51783+#endif
51784+
51785+#ifdef CONFIG_GRKERNSEC
51786+#define gr_conn_table_size 32749
51787+struct conn_table_entry {
51788+ struct conn_table_entry *next;
51789+ struct signal_struct *sig;
51790+};
51791+
51792+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
51793+DEFINE_SPINLOCK(gr_conn_table_lock);
51794+
51795+extern const char * gr_socktype_to_name(unsigned char type);
51796+extern const char * gr_proto_to_name(unsigned char proto);
51797+extern const char * gr_sockfamily_to_name(unsigned char family);
51798+
51799+static __inline__ int
51800+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
51801+{
51802+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
51803+}
51804+
51805+static __inline__ int
51806+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
51807+ __u16 sport, __u16 dport)
51808+{
51809+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
51810+ sig->gr_sport == sport && sig->gr_dport == dport))
51811+ return 1;
51812+ else
51813+ return 0;
51814+}
51815+
51816+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
51817+{
51818+ struct conn_table_entry **match;
51819+ unsigned int index;
51820+
51821+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
51822+ sig->gr_sport, sig->gr_dport,
51823+ gr_conn_table_size);
51824+
51825+ newent->sig = sig;
51826+
51827+ match = &gr_conn_table[index];
51828+ newent->next = *match;
51829+ *match = newent;
51830+
51831+ return;
51832+}
51833+
51834+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
51835+{
51836+ struct conn_table_entry *match, *last = NULL;
51837+ unsigned int index;
51838+
51839+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
51840+ sig->gr_sport, sig->gr_dport,
51841+ gr_conn_table_size);
51842+
51843+ match = gr_conn_table[index];
51844+ while (match && !conn_match(match->sig,
51845+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
51846+ sig->gr_dport)) {
51847+ last = match;
51848+ match = match->next;
51849+ }
51850+
51851+ if (match) {
51852+ if (last)
51853+ last->next = match->next;
51854+ else
51855+ gr_conn_table[index] = NULL;
51856+ kfree(match);
51857+ }
51858+
51859+ return;
51860+}
51861+
51862+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
51863+ __u16 sport, __u16 dport)
51864+{
51865+ struct conn_table_entry *match;
51866+ unsigned int index;
51867+
51868+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
51869+
51870+ match = gr_conn_table[index];
51871+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
51872+ match = match->next;
51873+
51874+ if (match)
51875+ return match->sig;
51876+ else
51877+ return NULL;
51878+}
51879+
51880+#endif
51881+
51882+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
51883+{
51884+#ifdef CONFIG_GRKERNSEC
51885+ struct signal_struct *sig = task->signal;
51886+ struct conn_table_entry *newent;
51887+
51888+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
51889+ if (newent == NULL)
51890+ return;
51891+ /* no bh lock needed since we are called with bh disabled */
51892+ spin_lock(&gr_conn_table_lock);
51893+ gr_del_task_from_ip_table_nolock(sig);
51894+ sig->gr_saddr = inet->inet_rcv_saddr;
51895+ sig->gr_daddr = inet->inet_daddr;
51896+ sig->gr_sport = inet->inet_sport;
51897+ sig->gr_dport = inet->inet_dport;
51898+ gr_add_to_task_ip_table_nolock(sig, newent);
51899+ spin_unlock(&gr_conn_table_lock);
51900+#endif
51901+ return;
51902+}
51903+
51904+void gr_del_task_from_ip_table(struct task_struct *task)
51905+{
51906+#ifdef CONFIG_GRKERNSEC
51907+ spin_lock_bh(&gr_conn_table_lock);
51908+ gr_del_task_from_ip_table_nolock(task->signal);
51909+ spin_unlock_bh(&gr_conn_table_lock);
51910+#endif
51911+ return;
51912+}
51913+
51914+void
51915+gr_attach_curr_ip(const struct sock *sk)
51916+{
51917+#ifdef CONFIG_GRKERNSEC
51918+ struct signal_struct *p, *set;
51919+ const struct inet_sock *inet = inet_sk(sk);
51920+
51921+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
51922+ return;
51923+
51924+ set = current->signal;
51925+
51926+ spin_lock_bh(&gr_conn_table_lock);
51927+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
51928+ inet->inet_dport, inet->inet_sport);
51929+ if (unlikely(p != NULL)) {
51930+ set->curr_ip = p->curr_ip;
51931+ set->used_accept = 1;
51932+ gr_del_task_from_ip_table_nolock(p);
51933+ spin_unlock_bh(&gr_conn_table_lock);
51934+ return;
51935+ }
51936+ spin_unlock_bh(&gr_conn_table_lock);
51937+
51938+ set->curr_ip = inet->inet_daddr;
51939+ set->used_accept = 1;
51940+#endif
51941+ return;
51942+}
51943+
51944+int
51945+gr_handle_sock_all(const int family, const int type, const int protocol)
51946+{
51947+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
51948+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
51949+ (family != AF_UNIX)) {
51950+ if (family == AF_INET)
51951+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
51952+ else
51953+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
51954+ return -EACCES;
51955+ }
51956+#endif
51957+ return 0;
51958+}
51959+
51960+int
51961+gr_handle_sock_server(const struct sockaddr *sck)
51962+{
51963+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51964+ if (grsec_enable_socket_server &&
51965+ in_group_p(grsec_socket_server_gid) &&
51966+ sck && (sck->sa_family != AF_UNIX) &&
51967+ (sck->sa_family != AF_LOCAL)) {
51968+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
51969+ return -EACCES;
51970+ }
51971+#endif
51972+ return 0;
51973+}
51974+
51975+int
51976+gr_handle_sock_server_other(const struct sock *sck)
51977+{
51978+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51979+ if (grsec_enable_socket_server &&
51980+ in_group_p(grsec_socket_server_gid) &&
51981+ sck && (sck->sk_family != AF_UNIX) &&
51982+ (sck->sk_family != AF_LOCAL)) {
51983+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
51984+ return -EACCES;
51985+ }
51986+#endif
51987+ return 0;
51988+}
51989+
51990+int
51991+gr_handle_sock_client(const struct sockaddr *sck)
51992+{
51993+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
51994+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
51995+ sck && (sck->sa_family != AF_UNIX) &&
51996+ (sck->sa_family != AF_LOCAL)) {
51997+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
51998+ return -EACCES;
51999+ }
52000+#endif
52001+ return 0;
52002+}
52003diff -urNp linux-3.0.4/grsecurity/grsec_sysctl.c linux-3.0.4/grsecurity/grsec_sysctl.c
52004--- linux-3.0.4/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
52005+++ linux-3.0.4/grsecurity/grsec_sysctl.c 2011-08-25 17:26:15.000000000 -0400
52006@@ -0,0 +1,433 @@
52007+#include <linux/kernel.h>
52008+#include <linux/sched.h>
52009+#include <linux/sysctl.h>
52010+#include <linux/grsecurity.h>
52011+#include <linux/grinternal.h>
52012+
52013+int
52014+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
52015+{
52016+#ifdef CONFIG_GRKERNSEC_SYSCTL
52017+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
52018+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
52019+ return -EACCES;
52020+ }
52021+#endif
52022+ return 0;
52023+}
52024+
52025+#ifdef CONFIG_GRKERNSEC_ROFS
52026+static int __maybe_unused one = 1;
52027+#endif
52028+
52029+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
52030+struct ctl_table grsecurity_table[] = {
52031+#ifdef CONFIG_GRKERNSEC_SYSCTL
52032+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
52033+#ifdef CONFIG_GRKERNSEC_IO
52034+ {
52035+ .procname = "disable_priv_io",
52036+ .data = &grsec_disable_privio,
52037+ .maxlen = sizeof(int),
52038+ .mode = 0600,
52039+ .proc_handler = &proc_dointvec,
52040+ },
52041+#endif
52042+#endif
52043+#ifdef CONFIG_GRKERNSEC_LINK
52044+ {
52045+ .procname = "linking_restrictions",
52046+ .data = &grsec_enable_link,
52047+ .maxlen = sizeof(int),
52048+ .mode = 0600,
52049+ .proc_handler = &proc_dointvec,
52050+ },
52051+#endif
52052+#ifdef CONFIG_GRKERNSEC_BRUTE
52053+ {
52054+ .procname = "deter_bruteforce",
52055+ .data = &grsec_enable_brute,
52056+ .maxlen = sizeof(int),
52057+ .mode = 0600,
52058+ .proc_handler = &proc_dointvec,
52059+ },
52060+#endif
52061+#ifdef CONFIG_GRKERNSEC_FIFO
52062+ {
52063+ .procname = "fifo_restrictions",
52064+ .data = &grsec_enable_fifo,
52065+ .maxlen = sizeof(int),
52066+ .mode = 0600,
52067+ .proc_handler = &proc_dointvec,
52068+ },
52069+#endif
52070+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
52071+ {
52072+ .procname = "ip_blackhole",
52073+ .data = &grsec_enable_blackhole,
52074+ .maxlen = sizeof(int),
52075+ .mode = 0600,
52076+ .proc_handler = &proc_dointvec,
52077+ },
52078+ {
52079+ .procname = "lastack_retries",
52080+ .data = &grsec_lastack_retries,
52081+ .maxlen = sizeof(int),
52082+ .mode = 0600,
52083+ .proc_handler = &proc_dointvec,
52084+ },
52085+#endif
52086+#ifdef CONFIG_GRKERNSEC_EXECLOG
52087+ {
52088+ .procname = "exec_logging",
52089+ .data = &grsec_enable_execlog,
52090+ .maxlen = sizeof(int),
52091+ .mode = 0600,
52092+ .proc_handler = &proc_dointvec,
52093+ },
52094+#endif
52095+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52096+ {
52097+ .procname = "rwxmap_logging",
52098+ .data = &grsec_enable_log_rwxmaps,
52099+ .maxlen = sizeof(int),
52100+ .mode = 0600,
52101+ .proc_handler = &proc_dointvec,
52102+ },
52103+#endif
52104+#ifdef CONFIG_GRKERNSEC_SIGNAL
52105+ {
52106+ .procname = "signal_logging",
52107+ .data = &grsec_enable_signal,
52108+ .maxlen = sizeof(int),
52109+ .mode = 0600,
52110+ .proc_handler = &proc_dointvec,
52111+ },
52112+#endif
52113+#ifdef CONFIG_GRKERNSEC_FORKFAIL
52114+ {
52115+ .procname = "forkfail_logging",
52116+ .data = &grsec_enable_forkfail,
52117+ .maxlen = sizeof(int),
52118+ .mode = 0600,
52119+ .proc_handler = &proc_dointvec,
52120+ },
52121+#endif
52122+#ifdef CONFIG_GRKERNSEC_TIME
52123+ {
52124+ .procname = "timechange_logging",
52125+ .data = &grsec_enable_time,
52126+ .maxlen = sizeof(int),
52127+ .mode = 0600,
52128+ .proc_handler = &proc_dointvec,
52129+ },
52130+#endif
52131+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
52132+ {
52133+ .procname = "chroot_deny_shmat",
52134+ .data = &grsec_enable_chroot_shmat,
52135+ .maxlen = sizeof(int),
52136+ .mode = 0600,
52137+ .proc_handler = &proc_dointvec,
52138+ },
52139+#endif
52140+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
52141+ {
52142+ .procname = "chroot_deny_unix",
52143+ .data = &grsec_enable_chroot_unix,
52144+ .maxlen = sizeof(int),
52145+ .mode = 0600,
52146+ .proc_handler = &proc_dointvec,
52147+ },
52148+#endif
52149+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
52150+ {
52151+ .procname = "chroot_deny_mount",
52152+ .data = &grsec_enable_chroot_mount,
52153+ .maxlen = sizeof(int),
52154+ .mode = 0600,
52155+ .proc_handler = &proc_dointvec,
52156+ },
52157+#endif
52158+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
52159+ {
52160+ .procname = "chroot_deny_fchdir",
52161+ .data = &grsec_enable_chroot_fchdir,
52162+ .maxlen = sizeof(int),
52163+ .mode = 0600,
52164+ .proc_handler = &proc_dointvec,
52165+ },
52166+#endif
52167+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
52168+ {
52169+ .procname = "chroot_deny_chroot",
52170+ .data = &grsec_enable_chroot_double,
52171+ .maxlen = sizeof(int),
52172+ .mode = 0600,
52173+ .proc_handler = &proc_dointvec,
52174+ },
52175+#endif
52176+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
52177+ {
52178+ .procname = "chroot_deny_pivot",
52179+ .data = &grsec_enable_chroot_pivot,
52180+ .maxlen = sizeof(int),
52181+ .mode = 0600,
52182+ .proc_handler = &proc_dointvec,
52183+ },
52184+#endif
52185+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
52186+ {
52187+ .procname = "chroot_enforce_chdir",
52188+ .data = &grsec_enable_chroot_chdir,
52189+ .maxlen = sizeof(int),
52190+ .mode = 0600,
52191+ .proc_handler = &proc_dointvec,
52192+ },
52193+#endif
52194+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
52195+ {
52196+ .procname = "chroot_deny_chmod",
52197+ .data = &grsec_enable_chroot_chmod,
52198+ .maxlen = sizeof(int),
52199+ .mode = 0600,
52200+ .proc_handler = &proc_dointvec,
52201+ },
52202+#endif
52203+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
52204+ {
52205+ .procname = "chroot_deny_mknod",
52206+ .data = &grsec_enable_chroot_mknod,
52207+ .maxlen = sizeof(int),
52208+ .mode = 0600,
52209+ .proc_handler = &proc_dointvec,
52210+ },
52211+#endif
52212+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
52213+ {
52214+ .procname = "chroot_restrict_nice",
52215+ .data = &grsec_enable_chroot_nice,
52216+ .maxlen = sizeof(int),
52217+ .mode = 0600,
52218+ .proc_handler = &proc_dointvec,
52219+ },
52220+#endif
52221+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
52222+ {
52223+ .procname = "chroot_execlog",
52224+ .data = &grsec_enable_chroot_execlog,
52225+ .maxlen = sizeof(int),
52226+ .mode = 0600,
52227+ .proc_handler = &proc_dointvec,
52228+ },
52229+#endif
52230+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52231+ {
52232+ .procname = "chroot_caps",
52233+ .data = &grsec_enable_chroot_caps,
52234+ .maxlen = sizeof(int),
52235+ .mode = 0600,
52236+ .proc_handler = &proc_dointvec,
52237+ },
52238+#endif
52239+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
52240+ {
52241+ .procname = "chroot_deny_sysctl",
52242+ .data = &grsec_enable_chroot_sysctl,
52243+ .maxlen = sizeof(int),
52244+ .mode = 0600,
52245+ .proc_handler = &proc_dointvec,
52246+ },
52247+#endif
52248+#ifdef CONFIG_GRKERNSEC_TPE
52249+ {
52250+ .procname = "tpe",
52251+ .data = &grsec_enable_tpe,
52252+ .maxlen = sizeof(int),
52253+ .mode = 0600,
52254+ .proc_handler = &proc_dointvec,
52255+ },
52256+ {
52257+ .procname = "tpe_gid",
52258+ .data = &grsec_tpe_gid,
52259+ .maxlen = sizeof(int),
52260+ .mode = 0600,
52261+ .proc_handler = &proc_dointvec,
52262+ },
52263+#endif
52264+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
52265+ {
52266+ .procname = "tpe_invert",
52267+ .data = &grsec_enable_tpe_invert,
52268+ .maxlen = sizeof(int),
52269+ .mode = 0600,
52270+ .proc_handler = &proc_dointvec,
52271+ },
52272+#endif
52273+#ifdef CONFIG_GRKERNSEC_TPE_ALL
52274+ {
52275+ .procname = "tpe_restrict_all",
52276+ .data = &grsec_enable_tpe_all,
52277+ .maxlen = sizeof(int),
52278+ .mode = 0600,
52279+ .proc_handler = &proc_dointvec,
52280+ },
52281+#endif
52282+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
52283+ {
52284+ .procname = "socket_all",
52285+ .data = &grsec_enable_socket_all,
52286+ .maxlen = sizeof(int),
52287+ .mode = 0600,
52288+ .proc_handler = &proc_dointvec,
52289+ },
52290+ {
52291+ .procname = "socket_all_gid",
52292+ .data = &grsec_socket_all_gid,
52293+ .maxlen = sizeof(int),
52294+ .mode = 0600,
52295+ .proc_handler = &proc_dointvec,
52296+ },
52297+#endif
52298+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
52299+ {
52300+ .procname = "socket_client",
52301+ .data = &grsec_enable_socket_client,
52302+ .maxlen = sizeof(int),
52303+ .mode = 0600,
52304+ .proc_handler = &proc_dointvec,
52305+ },
52306+ {
52307+ .procname = "socket_client_gid",
52308+ .data = &grsec_socket_client_gid,
52309+ .maxlen = sizeof(int),
52310+ .mode = 0600,
52311+ .proc_handler = &proc_dointvec,
52312+ },
52313+#endif
52314+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
52315+ {
52316+ .procname = "socket_server",
52317+ .data = &grsec_enable_socket_server,
52318+ .maxlen = sizeof(int),
52319+ .mode = 0600,
52320+ .proc_handler = &proc_dointvec,
52321+ },
52322+ {
52323+ .procname = "socket_server_gid",
52324+ .data = &grsec_socket_server_gid,
52325+ .maxlen = sizeof(int),
52326+ .mode = 0600,
52327+ .proc_handler = &proc_dointvec,
52328+ },
52329+#endif
52330+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
52331+ {
52332+ .procname = "audit_group",
52333+ .data = &grsec_enable_group,
52334+ .maxlen = sizeof(int),
52335+ .mode = 0600,
52336+ .proc_handler = &proc_dointvec,
52337+ },
52338+ {
52339+ .procname = "audit_gid",
52340+ .data = &grsec_audit_gid,
52341+ .maxlen = sizeof(int),
52342+ .mode = 0600,
52343+ .proc_handler = &proc_dointvec,
52344+ },
52345+#endif
52346+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
52347+ {
52348+ .procname = "audit_chdir",
52349+ .data = &grsec_enable_chdir,
52350+ .maxlen = sizeof(int),
52351+ .mode = 0600,
52352+ .proc_handler = &proc_dointvec,
52353+ },
52354+#endif
52355+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
52356+ {
52357+ .procname = "audit_mount",
52358+ .data = &grsec_enable_mount,
52359+ .maxlen = sizeof(int),
52360+ .mode = 0600,
52361+ .proc_handler = &proc_dointvec,
52362+ },
52363+#endif
52364+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
52365+ {
52366+ .procname = "audit_textrel",
52367+ .data = &grsec_enable_audit_textrel,
52368+ .maxlen = sizeof(int),
52369+ .mode = 0600,
52370+ .proc_handler = &proc_dointvec,
52371+ },
52372+#endif
52373+#ifdef CONFIG_GRKERNSEC_DMESG
52374+ {
52375+ .procname = "dmesg",
52376+ .data = &grsec_enable_dmesg,
52377+ .maxlen = sizeof(int),
52378+ .mode = 0600,
52379+ .proc_handler = &proc_dointvec,
52380+ },
52381+#endif
52382+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
52383+ {
52384+ .procname = "chroot_findtask",
52385+ .data = &grsec_enable_chroot_findtask,
52386+ .maxlen = sizeof(int),
52387+ .mode = 0600,
52388+ .proc_handler = &proc_dointvec,
52389+ },
52390+#endif
52391+#ifdef CONFIG_GRKERNSEC_RESLOG
52392+ {
52393+ .procname = "resource_logging",
52394+ .data = &grsec_resource_logging,
52395+ .maxlen = sizeof(int),
52396+ .mode = 0600,
52397+ .proc_handler = &proc_dointvec,
52398+ },
52399+#endif
52400+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
52401+ {
52402+ .procname = "audit_ptrace",
52403+ .data = &grsec_enable_audit_ptrace,
52404+ .maxlen = sizeof(int),
52405+ .mode = 0600,
52406+ .proc_handler = &proc_dointvec,
52407+ },
52408+#endif
52409+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52410+ {
52411+ .procname = "harden_ptrace",
52412+ .data = &grsec_enable_harden_ptrace,
52413+ .maxlen = sizeof(int),
52414+ .mode = 0600,
52415+ .proc_handler = &proc_dointvec,
52416+ },
52417+#endif
52418+ {
52419+ .procname = "grsec_lock",
52420+ .data = &grsec_lock,
52421+ .maxlen = sizeof(int),
52422+ .mode = 0600,
52423+ .proc_handler = &proc_dointvec,
52424+ },
52425+#endif
52426+#ifdef CONFIG_GRKERNSEC_ROFS
52427+ {
52428+ .procname = "romount_protect",
52429+ .data = &grsec_enable_rofs,
52430+ .maxlen = sizeof(int),
52431+ .mode = 0600,
52432+ .proc_handler = &proc_dointvec_minmax,
52433+ .extra1 = &one,
52434+ .extra2 = &one,
52435+ },
52436+#endif
52437+ { }
52438+};
52439+#endif
52440diff -urNp linux-3.0.4/grsecurity/grsec_time.c linux-3.0.4/grsecurity/grsec_time.c
52441--- linux-3.0.4/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
52442+++ linux-3.0.4/grsecurity/grsec_time.c 2011-08-23 21:48:14.000000000 -0400
52443@@ -0,0 +1,16 @@
52444+#include <linux/kernel.h>
52445+#include <linux/sched.h>
52446+#include <linux/grinternal.h>
52447+#include <linux/module.h>
52448+
52449+void
52450+gr_log_timechange(void)
52451+{
52452+#ifdef CONFIG_GRKERNSEC_TIME
52453+ if (grsec_enable_time)
52454+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
52455+#endif
52456+ return;
52457+}
52458+
52459+EXPORT_SYMBOL(gr_log_timechange);
52460diff -urNp linux-3.0.4/grsecurity/grsec_tpe.c linux-3.0.4/grsecurity/grsec_tpe.c
52461--- linux-3.0.4/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
52462+++ linux-3.0.4/grsecurity/grsec_tpe.c 2011-08-23 21:48:14.000000000 -0400
52463@@ -0,0 +1,39 @@
52464+#include <linux/kernel.h>
52465+#include <linux/sched.h>
52466+#include <linux/file.h>
52467+#include <linux/fs.h>
52468+#include <linux/grinternal.h>
52469+
52470+extern int gr_acl_tpe_check(void);
52471+
52472+int
52473+gr_tpe_allow(const struct file *file)
52474+{
52475+#ifdef CONFIG_GRKERNSEC
52476+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
52477+ const struct cred *cred = current_cred();
52478+
52479+ if (cred->uid && ((grsec_enable_tpe &&
52480+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
52481+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
52482+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
52483+#else
52484+ in_group_p(grsec_tpe_gid)
52485+#endif
52486+ ) || gr_acl_tpe_check()) &&
52487+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
52488+ (inode->i_mode & S_IWOTH))))) {
52489+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
52490+ return 0;
52491+ }
52492+#ifdef CONFIG_GRKERNSEC_TPE_ALL
52493+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
52494+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
52495+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
52496+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
52497+ return 0;
52498+ }
52499+#endif
52500+#endif
52501+ return 1;
52502+}
52503diff -urNp linux-3.0.4/grsecurity/grsum.c linux-3.0.4/grsecurity/grsum.c
52504--- linux-3.0.4/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
52505+++ linux-3.0.4/grsecurity/grsum.c 2011-08-23 21:48:14.000000000 -0400
52506@@ -0,0 +1,61 @@
52507+#include <linux/err.h>
52508+#include <linux/kernel.h>
52509+#include <linux/sched.h>
52510+#include <linux/mm.h>
52511+#include <linux/scatterlist.h>
52512+#include <linux/crypto.h>
52513+#include <linux/gracl.h>
52514+
52515+
52516+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
52517+#error "crypto and sha256 must be built into the kernel"
52518+#endif
52519+
52520+int
52521+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
52522+{
52523+ char *p;
52524+ struct crypto_hash *tfm;
52525+ struct hash_desc desc;
52526+ struct scatterlist sg;
52527+ unsigned char temp_sum[GR_SHA_LEN];
52528+ volatile int retval = 0;
52529+ volatile int dummy = 0;
52530+ unsigned int i;
52531+
52532+ sg_init_table(&sg, 1);
52533+
52534+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
52535+ if (IS_ERR(tfm)) {
52536+ /* should never happen, since sha256 should be built in */
52537+ return 1;
52538+ }
52539+
52540+ desc.tfm = tfm;
52541+ desc.flags = 0;
52542+
52543+ crypto_hash_init(&desc);
52544+
52545+ p = salt;
52546+ sg_set_buf(&sg, p, GR_SALT_LEN);
52547+ crypto_hash_update(&desc, &sg, sg.length);
52548+
52549+ p = entry->pw;
52550+ sg_set_buf(&sg, p, strlen(p));
52551+
52552+ crypto_hash_update(&desc, &sg, sg.length);
52553+
52554+ crypto_hash_final(&desc, temp_sum);
52555+
52556+ memset(entry->pw, 0, GR_PW_LEN);
52557+
52558+ for (i = 0; i < GR_SHA_LEN; i++)
52559+ if (sum[i] != temp_sum[i])
52560+ retval = 1;
52561+ else
52562+ dummy = 1; // waste a cycle
52563+
52564+ crypto_free_hash(tfm);
52565+
52566+ return retval;
52567+}
52568diff -urNp linux-3.0.4/grsecurity/Kconfig linux-3.0.4/grsecurity/Kconfig
52569--- linux-3.0.4/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
52570+++ linux-3.0.4/grsecurity/Kconfig 2011-08-25 17:25:34.000000000 -0400
52571@@ -0,0 +1,1038 @@
52572+#
52573+# grecurity configuration
52574+#
52575+
52576+menu "Grsecurity"
52577+
52578+config GRKERNSEC
52579+ bool "Grsecurity"
52580+ select CRYPTO
52581+ select CRYPTO_SHA256
52582+ help
52583+ If you say Y here, you will be able to configure many features
52584+ that will enhance the security of your system. It is highly
52585+ recommended that you say Y here and read through the help
52586+ for each option so that you fully understand the features and
52587+ can evaluate their usefulness for your machine.
52588+
52589+choice
52590+ prompt "Security Level"
52591+ depends on GRKERNSEC
52592+ default GRKERNSEC_CUSTOM
52593+
52594+config GRKERNSEC_LOW
52595+ bool "Low"
52596+ select GRKERNSEC_LINK
52597+ select GRKERNSEC_FIFO
52598+ select GRKERNSEC_RANDNET
52599+ select GRKERNSEC_DMESG
52600+ select GRKERNSEC_CHROOT
52601+ select GRKERNSEC_CHROOT_CHDIR
52602+
52603+ help
52604+ If you choose this option, several of the grsecurity options will
52605+ be enabled that will give you greater protection against a number
52606+ of attacks, while assuring that none of your software will have any
52607+ conflicts with the additional security measures. If you run a lot
52608+ of unusual software, or you are having problems with the higher
52609+ security levels, you should say Y here. With this option, the
52610+ following features are enabled:
52611+
52612+ - Linking restrictions
52613+ - FIFO restrictions
52614+ - Restricted dmesg
52615+ - Enforced chdir("/") on chroot
52616+ - Runtime module disabling
52617+
52618+config GRKERNSEC_MEDIUM
52619+ bool "Medium"
52620+ select PAX
52621+ select PAX_EI_PAX
52622+ select PAX_PT_PAX_FLAGS
52623+ select PAX_HAVE_ACL_FLAGS
52624+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
52625+ select GRKERNSEC_CHROOT
52626+ select GRKERNSEC_CHROOT_SYSCTL
52627+ select GRKERNSEC_LINK
52628+ select GRKERNSEC_FIFO
52629+ select GRKERNSEC_DMESG
52630+ select GRKERNSEC_RANDNET
52631+ select GRKERNSEC_FORKFAIL
52632+ select GRKERNSEC_TIME
52633+ select GRKERNSEC_SIGNAL
52634+ select GRKERNSEC_CHROOT
52635+ select GRKERNSEC_CHROOT_UNIX
52636+ select GRKERNSEC_CHROOT_MOUNT
52637+ select GRKERNSEC_CHROOT_PIVOT
52638+ select GRKERNSEC_CHROOT_DOUBLE
52639+ select GRKERNSEC_CHROOT_CHDIR
52640+ select GRKERNSEC_CHROOT_MKNOD
52641+ select GRKERNSEC_PROC
52642+ select GRKERNSEC_PROC_USERGROUP
52643+ select PAX_RANDUSTACK
52644+ select PAX_ASLR
52645+ select PAX_RANDMMAP
52646+ select PAX_REFCOUNT if (X86 || SPARC64)
52647+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
52648+
52649+ help
52650+ If you say Y here, several features in addition to those included
52651+ in the low additional security level will be enabled. These
52652+ features provide even more security to your system, though in rare
52653+ cases they may be incompatible with very old or poorly written
52654+ software. If you enable this option, make sure that your auth
52655+ service (identd) is running as gid 1001. With this option,
52656+ the following features (in addition to those provided in the
52657+ low additional security level) will be enabled:
52658+
52659+ - Failed fork logging
52660+ - Time change logging
52661+ - Signal logging
52662+ - Deny mounts in chroot
52663+ - Deny double chrooting
52664+ - Deny sysctl writes in chroot
52665+ - Deny mknod in chroot
52666+ - Deny access to abstract AF_UNIX sockets out of chroot
52667+ - Deny pivot_root in chroot
52668+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
52669+ - /proc restrictions with special GID set to 10 (usually wheel)
52670+ - Address Space Layout Randomization (ASLR)
52671+ - Prevent exploitation of most refcount overflows
52672+ - Bounds checking of copying between the kernel and userland
52673+
52674+config GRKERNSEC_HIGH
52675+ bool "High"
52676+ select GRKERNSEC_LINK
52677+ select GRKERNSEC_FIFO
52678+ select GRKERNSEC_DMESG
52679+ select GRKERNSEC_FORKFAIL
52680+ select GRKERNSEC_TIME
52681+ select GRKERNSEC_SIGNAL
52682+ select GRKERNSEC_CHROOT
52683+ select GRKERNSEC_CHROOT_SHMAT
52684+ select GRKERNSEC_CHROOT_UNIX
52685+ select GRKERNSEC_CHROOT_MOUNT
52686+ select GRKERNSEC_CHROOT_FCHDIR
52687+ select GRKERNSEC_CHROOT_PIVOT
52688+ select GRKERNSEC_CHROOT_DOUBLE
52689+ select GRKERNSEC_CHROOT_CHDIR
52690+ select GRKERNSEC_CHROOT_MKNOD
52691+ select GRKERNSEC_CHROOT_CAPS
52692+ select GRKERNSEC_CHROOT_SYSCTL
52693+ select GRKERNSEC_CHROOT_FINDTASK
52694+ select GRKERNSEC_SYSFS_RESTRICT
52695+ select GRKERNSEC_PROC
52696+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
52697+ select GRKERNSEC_HIDESYM
52698+ select GRKERNSEC_BRUTE
52699+ select GRKERNSEC_PROC_USERGROUP
52700+ select GRKERNSEC_KMEM
52701+ select GRKERNSEC_RESLOG
52702+ select GRKERNSEC_RANDNET
52703+ select GRKERNSEC_PROC_ADD
52704+ select GRKERNSEC_CHROOT_CHMOD
52705+ select GRKERNSEC_CHROOT_NICE
52706+ select GRKERNSEC_AUDIT_MOUNT
52707+ select GRKERNSEC_MODHARDEN if (MODULES)
52708+ select GRKERNSEC_HARDEN_PTRACE
52709+ select GRKERNSEC_VM86 if (X86_32)
52710+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
52711+ select PAX
52712+ select PAX_RANDUSTACK
52713+ select PAX_ASLR
52714+ select PAX_RANDMMAP
52715+ select PAX_NOEXEC
52716+ select PAX_MPROTECT
52717+ select PAX_EI_PAX
52718+ select PAX_PT_PAX_FLAGS
52719+ select PAX_HAVE_ACL_FLAGS
52720+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
52721+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
52722+ select PAX_RANDKSTACK if (X86_TSC && X86)
52723+ select PAX_SEGMEXEC if (X86_32)
52724+ select PAX_PAGEEXEC
52725+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
52726+ select PAX_EMUTRAMP if (PARISC)
52727+ select PAX_EMUSIGRT if (PARISC)
52728+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
52729+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
52730+ select PAX_REFCOUNT if (X86 || SPARC64)
52731+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
52732+ help
52733+ If you say Y here, many of the features of grsecurity will be
52734+ enabled, which will protect you against many kinds of attacks
52735+ against your system. The heightened security comes at a cost
52736+ of an increased chance of incompatibilities with rare software
52737+ on your machine. Since this security level enables PaX, you should
52738+ view <http://pax.grsecurity.net> and read about the PaX
52739+ project. While you are there, download chpax and run it on
52740+ binaries that cause problems with PaX. Also remember that
52741+ since the /proc restrictions are enabled, you must run your
52742+ identd as gid 1001. This security level enables the following
52743+ features in addition to those listed in the low and medium
52744+ security levels:
52745+
52746+ - Additional /proc restrictions
52747+ - Chmod restrictions in chroot
52748+ - No signals, ptrace, or viewing of processes outside of chroot
52749+ - Capability restrictions in chroot
52750+ - Deny fchdir out of chroot
52751+ - Priority restrictions in chroot
52752+ - Segmentation-based implementation of PaX
52753+ - Mprotect restrictions
52754+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
52755+ - Kernel stack randomization
52756+ - Mount/unmount/remount logging
52757+ - Kernel symbol hiding
52758+ - Prevention of memory exhaustion-based exploits
52759+ - Hardening of module auto-loading
52760+ - Ptrace restrictions
52761+ - Restricted vm86 mode
52762+ - Restricted sysfs/debugfs
52763+ - Active kernel exploit response
52764+
52765+config GRKERNSEC_CUSTOM
52766+ bool "Custom"
52767+ help
52768+ If you say Y here, you will be able to configure every grsecurity
52769+ option, which allows you to enable many more features that aren't
52770+ covered in the basic security levels. These additional features
52771+ include TPE, socket restrictions, and the sysctl system for
52772+ grsecurity. It is advised that you read through the help for
52773+ each option to determine its usefulness in your situation.
52774+
52775+endchoice
52776+
52777+menu "Address Space Protection"
52778+depends on GRKERNSEC
52779+
52780+config GRKERNSEC_KMEM
52781+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
52782+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52783+ help
52784+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52785+ be written to via mmap or otherwise to modify the running kernel.
52786+ /dev/port will also not be allowed to be opened. If you have module
52787+ support disabled, enabling this will close up four ways that are
52788+ currently used to insert malicious code into the running kernel.
52789+ Even with all these features enabled, we still highly recommend that
52790+ you use the RBAC system, as it is still possible for an attacker to
52791+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52792+ If you are not using XFree86, you may be able to stop this additional
52793+ case by enabling the 'Disable privileged I/O' option. Though nothing
52794+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52795+ but only to video memory, which is the only writing we allow in this
52796+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52797+ not be allowed to mprotect it with PROT_WRITE later.
52798+ It is highly recommended that you say Y here if you meet all the
52799+ conditions above.
52800+
52801+config GRKERNSEC_VM86
52802+ bool "Restrict VM86 mode"
52803+ depends on X86_32
52804+
52805+ help
52806+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52807+ make use of a special execution mode on 32bit x86 processors called
52808+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52809+ video cards and will still work with this option enabled. The purpose
52810+ of the option is to prevent exploitation of emulation errors in
52811+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52812+ Nearly all users should be able to enable this option.
52813+
52814+config GRKERNSEC_IO
52815+ bool "Disable privileged I/O"
52816+ depends on X86
52817+ select RTC_CLASS
52818+ select RTC_INTF_DEV
52819+ select RTC_DRV_CMOS
52820+
52821+ help
52822+ If you say Y here, all ioperm and iopl calls will return an error.
52823+ Ioperm and iopl can be used to modify the running kernel.
52824+ Unfortunately, some programs need this access to operate properly,
52825+ the most notable of which are XFree86 and hwclock. hwclock can be
52826+ remedied by having RTC support in the kernel, so real-time
52827+ clock support is enabled if this option is enabled, to ensure
52828+ that hwclock operates correctly. XFree86 still will not
52829+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52830+ IF YOU USE XFree86. If you use XFree86 and you still want to
52831+ protect your kernel against modification, use the RBAC system.
52832+
52833+config GRKERNSEC_PROC_MEMMAP
52834+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
52835+ default y if (PAX_NOEXEC || PAX_ASLR)
52836+ depends on PAX_NOEXEC || PAX_ASLR
52837+ help
52838+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52839+ give no information about the addresses of its mappings if
52840+ PaX features that rely on random addresses are enabled on the task.
52841+ If you use PaX it is greatly recommended that you say Y here as it
52842+ closes up a hole that makes the full ASLR useless for suid
52843+ binaries.
52844+
52845+config GRKERNSEC_BRUTE
52846+ bool "Deter exploit bruteforcing"
52847+ help
52848+ If you say Y here, attempts to bruteforce exploits against forking
52849+ daemons such as apache or sshd, as well as against suid/sgid binaries
52850+ will be deterred. When a child of a forking daemon is killed by PaX
52851+ or crashes due to an illegal instruction or other suspicious signal,
52852+ the parent process will be delayed 30 seconds upon every subsequent
52853+ fork until the administrator is able to assess the situation and
52854+ restart the daemon.
52855+ In the suid/sgid case, the attempt is logged, the user has all their
52856+ processes terminated, and they are prevented from executing any further
52857+ processes for 15 minutes.
52858+ It is recommended that you also enable signal logging in the auditing
52859+ section so that logs are generated when a process triggers a suspicious
52860+ signal.
52861+ If the sysctl option is enabled, a sysctl option with name
52862+ "deter_bruteforce" is created.
52863+
52864+
52865+config GRKERNSEC_MODHARDEN
52866+ bool "Harden module auto-loading"
52867+ depends on MODULES
52868+ help
52869+ If you say Y here, module auto-loading in response to use of some
52870+ feature implemented by an unloaded module will be restricted to
52871+ root users. Enabling this option helps defend against attacks
52872+ by unprivileged users who abuse the auto-loading behavior to
52873+ cause a vulnerable module to load that is then exploited.
52874+
52875+ If this option prevents a legitimate use of auto-loading for a
52876+ non-root user, the administrator can execute modprobe manually
52877+ with the exact name of the module mentioned in the alert log.
52878+ Alternatively, the administrator can add the module to the list
52879+ of modules loaded at boot by modifying init scripts.
52880+
52881+ Modification of init scripts will most likely be needed on
52882+ Ubuntu servers with encrypted home directory support enabled,
52883+ as the first non-root user logging in will cause the ecb(aes),
52884+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52885+
52886+config GRKERNSEC_HIDESYM
52887+ bool "Hide kernel symbols"
52888+ help
52889+ If you say Y here, getting information on loaded modules, and
52890+ displaying all kernel symbols through a syscall will be restricted
52891+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52892+ /proc/kallsyms will be restricted to the root user. The RBAC
52893+ system can hide that entry even from root.
52894+
52895+ This option also prevents leaking of kernel addresses through
52896+ several /proc entries.
52897+
52898+ Note that this option is only effective provided the following
52899+ conditions are met:
52900+ 1) The kernel using grsecurity is not precompiled by some distribution
52901+ 2) You have also enabled GRKERNSEC_DMESG
52902+ 3) You are using the RBAC system and hiding other files such as your
52903+ kernel image and System.map. Alternatively, enabling this option
52904+ causes the permissions on /boot, /lib/modules, and the kernel
52905+ source directory to change at compile time to prevent
52906+ reading by non-root users.
52907+ If the above conditions are met, this option will aid in providing a
52908+ useful protection against local kernel exploitation of overflows
52909+ and arbitrary read/write vulnerabilities.
52910+
52911+config GRKERNSEC_KERN_LOCKOUT
52912+ bool "Active kernel exploit response"
52913+ depends on X86 || ARM || PPC || SPARC
52914+ help
52915+ If you say Y here, when a PaX alert is triggered due to suspicious
52916+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52917+ or an OOPs occurs due to bad memory accesses, instead of just
52918+ terminating the offending process (and potentially allowing
52919+ a subsequent exploit from the same user), we will take one of two
52920+ actions:
52921+ If the user was root, we will panic the system
52922+ If the user was non-root, we will log the attempt, terminate
52923+ all processes owned by the user, then prevent them from creating
52924+ any new processes until the system is restarted
52925+ This deters repeated kernel exploitation/bruteforcing attempts
52926+ and is useful for later forensics.
52927+
52928+endmenu
52929+menu "Role Based Access Control Options"
52930+depends on GRKERNSEC
52931+
52932+config GRKERNSEC_RBAC_DEBUG
52933+ bool
52934+
52935+config GRKERNSEC_NO_RBAC
52936+ bool "Disable RBAC system"
52937+ help
52938+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52939+ preventing the RBAC system from being enabled. You should only say Y
52940+ here if you have no intention of using the RBAC system, so as to prevent
52941+ an attacker with root access from misusing the RBAC system to hide files
52942+ and processes when loadable module support and /dev/[k]mem have been
52943+ locked down.
52944+
52945+config GRKERNSEC_ACL_HIDEKERN
52946+ bool "Hide kernel processes"
52947+ help
52948+ If you say Y here, all kernel threads will be hidden to all
52949+ processes but those whose subject has the "view hidden processes"
52950+ flag.
52951+
52952+config GRKERNSEC_ACL_MAXTRIES
52953+ int "Maximum tries before password lockout"
52954+ default 3
52955+ help
52956+ This option enforces the maximum number of times a user can attempt
52957+ to authorize themselves with the grsecurity RBAC system before being
52958+ denied the ability to attempt authorization again for a specified time.
52959+ The lower the number, the harder it will be to brute-force a password.
52960+
52961+config GRKERNSEC_ACL_TIMEOUT
52962+ int "Time to wait after max password tries, in seconds"
52963+ default 30
52964+ help
52965+ This option specifies the time the user must wait after attempting to
52966+ authorize to the RBAC system with the maximum number of invalid
52967+ passwords. The higher the number, the harder it will be to brute-force
52968+ a password.
52969+
52970+endmenu
52971+menu "Filesystem Protections"
52972+depends on GRKERNSEC
52973+
52974+config GRKERNSEC_PROC
52975+ bool "Proc restrictions"
52976+ help
52977+ If you say Y here, the permissions of the /proc filesystem
52978+ will be altered to enhance system security and privacy. You MUST
52979+ choose either a user only restriction or a user and group restriction.
52980+ Depending upon the option you choose, you can either restrict users to
52981+ see only the processes they themselves run, or choose a group that can
52982+ view all processes and files normally restricted to root if you choose
52983+ the "restrict to user only" option. NOTE: If you're running identd as
52984+ a non-root user, you will have to run it as the group you specify here.
52985+
52986+config GRKERNSEC_PROC_USER
52987+ bool "Restrict /proc to user only"
52988+ depends on GRKERNSEC_PROC
52989+ help
52990+ If you say Y here, non-root users will only be able to view their own
52991+ processes, and restricts them from viewing network-related information,
52992+ and viewing kernel symbol and module information.
52993+
52994+config GRKERNSEC_PROC_USERGROUP
52995+ bool "Allow special group"
52996+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52997+ help
52998+ If you say Y here, you will be able to select a group that will be
52999+ able to view all processes and network-related information. If you've
53000+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53001+ remain hidden. This option is useful if you want to run identd as
53002+ a non-root user.
53003+
53004+config GRKERNSEC_PROC_GID
53005+ int "GID for special group"
53006+ depends on GRKERNSEC_PROC_USERGROUP
53007+ default 1001
53008+
53009+config GRKERNSEC_PROC_ADD
53010+ bool "Additional restrictions"
53011+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53012+ help
53013+ If you say Y here, additional restrictions will be placed on
53014+ /proc that keep normal users from viewing device information and
53015+ slabinfo information that could be useful for exploits.
53016+
53017+config GRKERNSEC_LINK
53018+ bool "Linking restrictions"
53019+ help
53020+ If you say Y here, /tmp race exploits will be prevented, since users
53021+ will no longer be able to follow symlinks owned by other users in
53022+ world-writable +t directories (e.g. /tmp), unless the owner of the
53023+ symlink is the owner of the directory. users will also not be
53024+ able to hardlink to files they do not own. If the sysctl option is
53025+ enabled, a sysctl option with name "linking_restrictions" is created.
53026+
53027+config GRKERNSEC_FIFO
53028+ bool "FIFO restrictions"
53029+ help
53030+ If you say Y here, users will not be able to write to FIFOs they don't
53031+ own in world-writable +t directories (e.g. /tmp), unless the owner of
53032+ the FIFO is the same owner of the directory it's held in. If the sysctl
53033+ option is enabled, a sysctl option with name "fifo_restrictions" is
53034+ created.
53035+
53036+config GRKERNSEC_SYSFS_RESTRICT
53037+ bool "Sysfs/debugfs restriction"
53038+ depends on SYSFS
53039+ help
53040+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53041+ any filesystem normally mounted under it (e.g. debugfs) will only
53042+ be accessible by root. These filesystems generally provide access
53043+ to hardware and debug information that isn't appropriate for unprivileged
53044+ users of the system. Sysfs and debugfs have also become a large source
53045+ of new vulnerabilities, ranging from infoleaks to local compromise.
53046+ There has been very little oversight with an eye toward security involved
53047+ in adding new exporters of information to these filesystems, so their
53048+ use is discouraged.
53049+ This option is equivalent to a chmod 0700 of the mount paths.
53050+
53051+config GRKERNSEC_ROFS
53052+ bool "Runtime read-only mount protection"
53053+ help
53054+ If you say Y here, a sysctl option with name "romount_protect" will
53055+ be created. By setting this option to 1 at runtime, filesystems
53056+ will be protected in the following ways:
53057+ * No new writable mounts will be allowed
53058+ * Existing read-only mounts won't be able to be remounted read/write
53059+ * Write operations will be denied on all block devices
53060+ This option acts independently of grsec_lock: once it is set to 1,
53061+ it cannot be turned off. Therefore, please be mindful of the resulting
53062+ behavior if this option is enabled in an init script on a read-only
53063+ filesystem. This feature is mainly intended for secure embedded systems.
53064+
53065+config GRKERNSEC_CHROOT
53066+ bool "Chroot jail restrictions"
53067+ help
53068+ If you say Y here, you will be able to choose several options that will
53069+ make breaking out of a chrooted jail much more difficult. If you
53070+ encounter no software incompatibilities with the following options, it
53071+ is recommended that you enable each one.
53072+
53073+config GRKERNSEC_CHROOT_MOUNT
53074+ bool "Deny mounts"
53075+ depends on GRKERNSEC_CHROOT
53076+ help
53077+ If you say Y here, processes inside a chroot will not be able to
53078+ mount or remount filesystems. If the sysctl option is enabled, a
53079+ sysctl option with name "chroot_deny_mount" is created.
53080+
53081+config GRKERNSEC_CHROOT_DOUBLE
53082+ bool "Deny double-chroots"
53083+ depends on GRKERNSEC_CHROOT
53084+ help
53085+ If you say Y here, processes inside a chroot will not be able to chroot
53086+ again outside the chroot. This is a widely used method of breaking
53087+ out of a chroot jail and should not be allowed. If the sysctl
53088+ option is enabled, a sysctl option with name
53089+ "chroot_deny_chroot" is created.
53090+
53091+config GRKERNSEC_CHROOT_PIVOT
53092+ bool "Deny pivot_root in chroot"
53093+ depends on GRKERNSEC_CHROOT
53094+ help
53095+ If you say Y here, processes inside a chroot will not be able to use
53096+ a function called pivot_root() that was introduced in Linux 2.3.41. It
53097+ works similar to chroot in that it changes the root filesystem. This
53098+ function could be misused in a chrooted process to attempt to break out
53099+ of the chroot, and therefore should not be allowed. If the sysctl
53100+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
53101+ created.
53102+
53103+config GRKERNSEC_CHROOT_CHDIR
53104+ bool "Enforce chdir(\"/\") on all chroots"
53105+ depends on GRKERNSEC_CHROOT
53106+ help
53107+ If you say Y here, the current working directory of all newly-chrooted
53108+ applications will be set to the the root directory of the chroot.
53109+ The man page on chroot(2) states:
53110+ Note that this call does not change the current working
53111+ directory, so that `.' can be outside the tree rooted at
53112+ `/'. In particular, the super-user can escape from a
53113+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53114+
53115+ It is recommended that you say Y here, since it's not known to break
53116+ any software. If the sysctl option is enabled, a sysctl option with
53117+ name "chroot_enforce_chdir" is created.
53118+
53119+config GRKERNSEC_CHROOT_CHMOD
53120+ bool "Deny (f)chmod +s"
53121+ depends on GRKERNSEC_CHROOT
53122+ help
53123+ If you say Y here, processes inside a chroot will not be able to chmod
53124+ or fchmod files to make them have suid or sgid bits. This protects
53125+ against another published method of breaking a chroot. If the sysctl
53126+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53127+ created.
53128+
53129+config GRKERNSEC_CHROOT_FCHDIR
53130+ bool "Deny fchdir out of chroot"
53131+ depends on GRKERNSEC_CHROOT
53132+ help
53133+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53134+ to a file descriptor of the chrooting process that points to a directory
53135+ outside the filesystem will be stopped. If the sysctl option
53136+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53137+
53138+config GRKERNSEC_CHROOT_MKNOD
53139+ bool "Deny mknod"
53140+ depends on GRKERNSEC_CHROOT
53141+ help
53142+ If you say Y here, processes inside a chroot will not be allowed to
53143+ mknod. The problem with using mknod inside a chroot is that it
53144+ would allow an attacker to create a device entry that is the same
53145+ as one on the physical root of your system, which could range from
53146+ anything from the console device to a device for your harddrive (which
53147+ they could then use to wipe the drive or steal data). It is recommended
53148+ that you say Y here, unless you run into software incompatibilities.
53149+ If the sysctl option is enabled, a sysctl option with name
53150+ "chroot_deny_mknod" is created.
53151+
53152+config GRKERNSEC_CHROOT_SHMAT
53153+ bool "Deny shmat() out of chroot"
53154+ depends on GRKERNSEC_CHROOT
53155+ help
53156+ If you say Y here, processes inside a chroot will not be able to attach
53157+ to shared memory segments that were created outside of the chroot jail.
53158+ It is recommended that you say Y here. If the sysctl option is enabled,
53159+ a sysctl option with name "chroot_deny_shmat" is created.
53160+
53161+config GRKERNSEC_CHROOT_UNIX
53162+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53163+ depends on GRKERNSEC_CHROOT
53164+ help
53165+ If you say Y here, processes inside a chroot will not be able to
53166+ connect to abstract (meaning not belonging to a filesystem) Unix
53167+ domain sockets that were bound outside of a chroot. It is recommended
53168+ that you say Y here. If the sysctl option is enabled, a sysctl option
53169+ with name "chroot_deny_unix" is created.
53170+
53171+config GRKERNSEC_CHROOT_FINDTASK
53172+ bool "Protect outside processes"
53173+ depends on GRKERNSEC_CHROOT
53174+ help
53175+ If you say Y here, processes inside a chroot will not be able to
53176+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53177+ getsid, or view any process outside of the chroot. If the sysctl
53178+ option is enabled, a sysctl option with name "chroot_findtask" is
53179+ created.
53180+
53181+config GRKERNSEC_CHROOT_NICE
53182+ bool "Restrict priority changes"
53183+ depends on GRKERNSEC_CHROOT
53184+ help
53185+ If you say Y here, processes inside a chroot will not be able to raise
53186+ the priority of processes in the chroot, or alter the priority of
53187+ processes outside the chroot. This provides more security than simply
53188+ removing CAP_SYS_NICE from the process' capability set. If the
53189+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53190+ is created.
53191+
53192+config GRKERNSEC_CHROOT_SYSCTL
53193+ bool "Deny sysctl writes"
53194+ depends on GRKERNSEC_CHROOT
53195+ help
53196+ If you say Y here, an attacker in a chroot will not be able to
53197+ write to sysctl entries, either by sysctl(2) or through a /proc
53198+ interface. It is strongly recommended that you say Y here. If the
53199+ sysctl option is enabled, a sysctl option with name
53200+ "chroot_deny_sysctl" is created.
53201+
53202+config GRKERNSEC_CHROOT_CAPS
53203+ bool "Capability restrictions"
53204+ depends on GRKERNSEC_CHROOT
53205+ help
53206+ If you say Y here, the capabilities on all root processes within a
53207+ chroot jail will be lowered to stop module insertion, raw i/o,
53208+ system and net admin tasks, rebooting the system, modifying immutable
53209+ files, modifying IPC owned by another, and changing the system time.
53210+ This is left an option because it can break some apps. Disable this
53211+ if your chrooted apps are having problems performing those kinds of
53212+ tasks. If the sysctl option is enabled, a sysctl option with
53213+ name "chroot_caps" is created.
53214+
53215+endmenu
53216+menu "Kernel Auditing"
53217+depends on GRKERNSEC
53218+
53219+config GRKERNSEC_AUDIT_GROUP
53220+ bool "Single group for auditing"
53221+ help
53222+ If you say Y here, the exec, chdir, and (un)mount logging features
53223+ will only operate on a group you specify. This option is recommended
53224+ if you only want to watch certain users instead of having a large
53225+ amount of logs from the entire system. If the sysctl option is enabled,
53226+ a sysctl option with name "audit_group" is created.
53227+
53228+config GRKERNSEC_AUDIT_GID
53229+ int "GID for auditing"
53230+ depends on GRKERNSEC_AUDIT_GROUP
53231+ default 1007
53232+
53233+config GRKERNSEC_EXECLOG
53234+ bool "Exec logging"
53235+ help
53236+ If you say Y here, all execve() calls will be logged (since the
53237+ other exec*() calls are frontends to execve(), all execution
53238+ will be logged). Useful for shell-servers that like to keep track
53239+ of their users. If the sysctl option is enabled, a sysctl option with
53240+ name "exec_logging" is created.
53241+ WARNING: This option when enabled will produce a LOT of logs, especially
53242+ on an active system.
53243+
53244+config GRKERNSEC_RESLOG
53245+ bool "Resource logging"
53246+ help
53247+ If you say Y here, all attempts to overstep resource limits will
53248+ be logged with the resource name, the requested size, and the current
53249+ limit. It is highly recommended that you say Y here. If the sysctl
53250+ option is enabled, a sysctl option with name "resource_logging" is
53251+ created. If the RBAC system is enabled, the sysctl value is ignored.
53252+
53253+config GRKERNSEC_CHROOT_EXECLOG
53254+ bool "Log execs within chroot"
53255+ help
53256+ If you say Y here, all executions inside a chroot jail will be logged
53257+ to syslog. This can cause a large amount of logs if certain
53258+ applications (eg. djb's daemontools) are installed on the system, and
53259+ is therefore left as an option. If the sysctl option is enabled, a
53260+ sysctl option with name "chroot_execlog" is created.
53261+
53262+config GRKERNSEC_AUDIT_PTRACE
53263+ bool "Ptrace logging"
53264+ help
53265+ If you say Y here, all attempts to attach to a process via ptrace
53266+ will be logged. If the sysctl option is enabled, a sysctl option
53267+ with name "audit_ptrace" is created.
53268+
53269+config GRKERNSEC_AUDIT_CHDIR
53270+ bool "Chdir logging"
53271+ help
53272+ If you say Y here, all chdir() calls will be logged. If the sysctl
53273+ option is enabled, a sysctl option with name "audit_chdir" is created.
53274+
53275+config GRKERNSEC_AUDIT_MOUNT
53276+ bool "(Un)Mount logging"
53277+ help
53278+ If you say Y here, all mounts and unmounts will be logged. If the
53279+ sysctl option is enabled, a sysctl option with name "audit_mount" is
53280+ created.
53281+
53282+config GRKERNSEC_SIGNAL
53283+ bool "Signal logging"
53284+ help
53285+ If you say Y here, certain important signals will be logged, such as
53286+ SIGSEGV, which will as a result inform you of when a error in a program
53287+ occurred, which in some cases could mean a possible exploit attempt.
53288+ If the sysctl option is enabled, a sysctl option with name
53289+ "signal_logging" is created.
53290+
53291+config GRKERNSEC_FORKFAIL
53292+ bool "Fork failure logging"
53293+ help
53294+ If you say Y here, all failed fork() attempts will be logged.
53295+ This could suggest a fork bomb, or someone attempting to overstep
53296+ their process limit. If the sysctl option is enabled, a sysctl option
53297+ with name "forkfail_logging" is created.
53298+
53299+config GRKERNSEC_TIME
53300+ bool "Time change logging"
53301+ help
53302+ If you say Y here, any changes of the system clock will be logged.
53303+ If the sysctl option is enabled, a sysctl option with name
53304+ "timechange_logging" is created.
53305+
53306+config GRKERNSEC_PROC_IPADDR
53307+ bool "/proc/<pid>/ipaddr support"
53308+ help
53309+ If you say Y here, a new entry will be added to each /proc/<pid>
53310+ directory that contains the IP address of the person using the task.
53311+ The IP is carried across local TCP and AF_UNIX stream sockets.
53312+ This information can be useful for IDS/IPSes to perform remote response
53313+ to a local attack. The entry is readable by only the owner of the
53314+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53315+ the RBAC system), and thus does not create privacy concerns.
53316+
53317+config GRKERNSEC_RWXMAP_LOG
53318+ bool 'Denied RWX mmap/mprotect logging'
53319+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53320+ help
53321+ If you say Y here, calls to mmap() and mprotect() with explicit
53322+ usage of PROT_WRITE and PROT_EXEC together will be logged when
53323+ denied by the PAX_MPROTECT feature. If the sysctl option is
53324+ enabled, a sysctl option with name "rwxmap_logging" is created.
53325+
53326+config GRKERNSEC_AUDIT_TEXTREL
53327+ bool 'ELF text relocations logging (READ HELP)'
53328+ depends on PAX_MPROTECT
53329+ help
53330+ If you say Y here, text relocations will be logged with the filename
53331+ of the offending library or binary. The purpose of the feature is
53332+ to help Linux distribution developers get rid of libraries and
53333+ binaries that need text relocations which hinder the future progress
53334+ of PaX. Only Linux distribution developers should say Y here, and
53335+ never on a production machine, as this option creates an information
53336+ leak that could aid an attacker in defeating the randomization of
53337+ a single memory region. If the sysctl option is enabled, a sysctl
53338+ option with name "audit_textrel" is created.
53339+
53340+endmenu
53341+
53342+menu "Executable Protections"
53343+depends on GRKERNSEC
53344+
53345+config GRKERNSEC_DMESG
53346+ bool "Dmesg(8) restriction"
53347+ help
53348+ If you say Y here, non-root users will not be able to use dmesg(8)
53349+ to view up to the last 4kb of messages in the kernel's log buffer.
53350+ The kernel's log buffer often contains kernel addresses and other
53351+ identifying information useful to an attacker in fingerprinting a
53352+ system for a targeted exploit.
53353+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
53354+ created.
53355+
53356+config GRKERNSEC_HARDEN_PTRACE
53357+ bool "Deter ptrace-based process snooping"
53358+ help
53359+ If you say Y here, TTY sniffers and other malicious monitoring
53360+ programs implemented through ptrace will be defeated. If you
53361+ have been using the RBAC system, this option has already been
53362+ enabled for several years for all users, with the ability to make
53363+ fine-grained exceptions.
53364+
53365+ This option only affects the ability of non-root users to ptrace
53366+ processes that are not a descendent of the ptracing process.
53367+ This means that strace ./binary and gdb ./binary will still work,
53368+ but attaching to arbitrary processes will not. If the sysctl
53369+ option is enabled, a sysctl option with name "harden_ptrace" is
53370+ created.
53371+
53372+config GRKERNSEC_TPE
53373+ bool "Trusted Path Execution (TPE)"
53374+ help
53375+ If you say Y here, you will be able to choose a gid to add to the
53376+ supplementary groups of users you want to mark as "untrusted."
53377+ These users will not be able to execute any files that are not in
53378+ root-owned directories writable only by root. If the sysctl option
53379+ is enabled, a sysctl option with name "tpe" is created.
53380+
53381+config GRKERNSEC_TPE_ALL
53382+ bool "Partially restrict all non-root users"
53383+ depends on GRKERNSEC_TPE
53384+ help
53385+ If you say Y here, all non-root users will be covered under
53386+ a weaker TPE restriction. This is separate from, and in addition to,
53387+ the main TPE options that you have selected elsewhere. Thus, if a
53388+ "trusted" GID is chosen, this restriction applies to even that GID.
53389+ Under this restriction, all non-root users will only be allowed to
53390+ execute files in directories they own that are not group or
53391+ world-writable, or in directories owned by root and writable only by
53392+ root. If the sysctl option is enabled, a sysctl option with name
53393+ "tpe_restrict_all" is created.
53394+
53395+config GRKERNSEC_TPE_INVERT
53396+ bool "Invert GID option"
53397+ depends on GRKERNSEC_TPE
53398+ help
53399+ If you say Y here, the group you specify in the TPE configuration will
53400+ decide what group TPE restrictions will be *disabled* for. This
53401+ option is useful if you want TPE restrictions to be applied to most
53402+ users on the system. If the sysctl option is enabled, a sysctl option
53403+ with name "tpe_invert" is created. Unlike other sysctl options, this
53404+ entry will default to on for backward-compatibility.
53405+
53406+config GRKERNSEC_TPE_GID
53407+ int "GID for untrusted users"
53408+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53409+ default 1005
53410+ help
53411+ Setting this GID determines what group TPE restrictions will be
53412+ *enabled* for. If the sysctl option is enabled, a sysctl option
53413+ with name "tpe_gid" is created.
53414+
53415+config GRKERNSEC_TPE_GID
53416+ int "GID for trusted users"
53417+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53418+ default 1005
53419+ help
53420+ Setting this GID determines what group TPE restrictions will be
53421+ *disabled* for. If the sysctl option is enabled, a sysctl option
53422+ with name "tpe_gid" is created.
53423+
53424+endmenu
53425+menu "Network Protections"
53426+depends on GRKERNSEC
53427+
53428+config GRKERNSEC_RANDNET
53429+ bool "Larger entropy pools"
53430+ help
53431+ If you say Y here, the entropy pools used for many features of Linux
53432+ and grsecurity will be doubled in size. Since several grsecurity
53433+ features use additional randomness, it is recommended that you say Y
53434+ here. Saying Y here has a similar effect as modifying
53435+ /proc/sys/kernel/random/poolsize.
53436+
53437+config GRKERNSEC_BLACKHOLE
53438+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53439+ depends on NET
53440+ help
53441+ If you say Y here, neither TCP resets nor ICMP
53442+ destination-unreachable packets will be sent in response to packets
53443+ sent to ports for which no associated listening process exists.
53444+ This feature supports both IPV4 and IPV6 and exempts the
53445+ loopback interface from blackholing. Enabling this feature
53446+ makes a host more resilient to DoS attacks and reduces network
53447+ visibility against scanners.
53448+
53449+ The blackhole feature as-implemented is equivalent to the FreeBSD
53450+ blackhole feature, as it prevents RST responses to all packets, not
53451+ just SYNs. Under most application behavior this causes no
53452+ problems, but applications (like haproxy) may not close certain
53453+ connections in a way that cleanly terminates them on the remote
53454+ end, leaving the remote host in LAST_ACK state. Because of this
53455+ side-effect and to prevent intentional LAST_ACK DoSes, this
53456+ feature also adds automatic mitigation against such attacks.
53457+ The mitigation drastically reduces the amount of time a socket
53458+ can spend in LAST_ACK state. If you're using haproxy and not
53459+ all servers it connects to have this option enabled, consider
53460+ disabling this feature on the haproxy host.
53461+
53462+ If the sysctl option is enabled, two sysctl options with names
53463+ "ip_blackhole" and "lastack_retries" will be created.
53464+ While "ip_blackhole" takes the standard zero/non-zero on/off
53465+ toggle, "lastack_retries" uses the same kinds of values as
53466+ "tcp_retries1" and "tcp_retries2". The default value of 4
53467+ prevents a socket from lasting more than 45 seconds in LAST_ACK
53468+ state.
53469+
53470+config GRKERNSEC_SOCKET
53471+ bool "Socket restrictions"
53472+ depends on NET
53473+ help
53474+ If you say Y here, you will be able to choose from several options.
53475+ If you assign a GID on your system and add it to the supplementary
53476+ groups of users you want to restrict socket access to, this patch
53477+ will perform up to three things, based on the option(s) you choose.
53478+
53479+config GRKERNSEC_SOCKET_ALL
53480+ bool "Deny any sockets to group"
53481+ depends on GRKERNSEC_SOCKET
53482+ help
53483+ If you say Y here, you will be able to choose a GID of whose users will
53484+ be unable to connect to other hosts from your machine or run server
53485+ applications from your machine. If the sysctl option is enabled, a
53486+ sysctl option with name "socket_all" is created.
53487+
53488+config GRKERNSEC_SOCKET_ALL_GID
53489+ int "GID to deny all sockets for"
53490+ depends on GRKERNSEC_SOCKET_ALL
53491+ default 1004
53492+ help
53493+ Here you can choose the GID to disable socket access for. Remember to
53494+ add the users you want socket access disabled for to the GID
53495+ specified here. If the sysctl option is enabled, a sysctl option
53496+ with name "socket_all_gid" is created.
53497+
53498+config GRKERNSEC_SOCKET_CLIENT
53499+ bool "Deny client sockets to group"
53500+ depends on GRKERNSEC_SOCKET
53501+ help
53502+ If you say Y here, you will be able to choose a GID of whose users will
53503+ be unable to connect to other hosts from your machine, but will be
53504+ able to run servers. If this option is enabled, all users in the group
53505+ you specify will have to use passive mode when initiating ftp transfers
53506+ from the shell on your machine. If the sysctl option is enabled, a
53507+ sysctl option with name "socket_client" is created.
53508+
53509+config GRKERNSEC_SOCKET_CLIENT_GID
53510+ int "GID to deny client sockets for"
53511+ depends on GRKERNSEC_SOCKET_CLIENT
53512+ default 1003
53513+ help
53514+ Here you can choose the GID to disable client socket access for.
53515+ Remember to add the users you want client socket access disabled for to
53516+ the GID specified here. If the sysctl option is enabled, a sysctl
53517+ option with name "socket_client_gid" is created.
53518+
53519+config GRKERNSEC_SOCKET_SERVER
53520+ bool "Deny server sockets to group"
53521+ depends on GRKERNSEC_SOCKET
53522+ help
53523+ If you say Y here, you will be able to choose a GID of whose users will
53524+ be unable to run server applications from your machine. If the sysctl
53525+ option is enabled, a sysctl option with name "socket_server" is created.
53526+
53527+config GRKERNSEC_SOCKET_SERVER_GID
53528+ int "GID to deny server sockets for"
53529+ depends on GRKERNSEC_SOCKET_SERVER
53530+ default 1002
53531+ help
53532+ Here you can choose the GID to disable server socket access for.
53533+ Remember to add the users you want server socket access disabled for to
53534+ the GID specified here. If the sysctl option is enabled, a sysctl
53535+ option with name "socket_server_gid" is created.
53536+
53537+endmenu
53538+menu "Sysctl support"
53539+depends on GRKERNSEC && SYSCTL
53540+
53541+config GRKERNSEC_SYSCTL
53542+ bool "Sysctl support"
53543+ help
53544+ If you say Y here, you will be able to change the options that
53545+ grsecurity runs with at bootup, without having to recompile your
53546+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53547+ to enable (1) or disable (0) various features. All the sysctl entries
53548+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53549+ All features enabled in the kernel configuration are disabled at boot
53550+ if you do not say Y to the "Turn on features by default" option.
53551+ All options should be set at startup, and the grsec_lock entry should
53552+ be set to a non-zero value after all the options are set.
53553+ *THIS IS EXTREMELY IMPORTANT*
53554+
53555+config GRKERNSEC_SYSCTL_DISTRO
53556+ bool "Extra sysctl support for distro makers (READ HELP)"
53557+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53558+ help
53559+ If you say Y here, additional sysctl options will be created
53560+ for features that affect processes running as root. Therefore,
53561+ it is critical when using this option that the grsec_lock entry be
53562+ enabled after boot. Only distros with prebuilt kernel packages
53563+ with this option enabled that can ensure grsec_lock is enabled
53564+ after boot should use this option.
53565+ *Failure to set grsec_lock after boot makes all grsec features
53566+ this option covers useless*
53567+
53568+ Currently this option creates the following sysctl entries:
53569+ "Disable Privileged I/O": "disable_priv_io"
53570+
53571+config GRKERNSEC_SYSCTL_ON
53572+ bool "Turn on features by default"
53573+ depends on GRKERNSEC_SYSCTL
53574+ help
53575+ If you say Y here, instead of having all features enabled in the
53576+ kernel configuration disabled at boot time, the features will be
53577+ enabled at boot time. It is recommended you say Y here unless
53578+ there is some reason you would want all sysctl-tunable features to
53579+ be disabled by default. As mentioned elsewhere, it is important
53580+ to enable the grsec_lock entry once you have finished modifying
53581+ the sysctl entries.
53582+
53583+endmenu
53584+menu "Logging Options"
53585+depends on GRKERNSEC
53586+
53587+config GRKERNSEC_FLOODTIME
53588+ int "Seconds in between log messages (minimum)"
53589+ default 10
53590+ help
53591+ This option allows you to enforce the number of seconds between
53592+ grsecurity log messages. The default should be suitable for most
53593+ people, however, if you choose to change it, choose a value small enough
53594+ to allow informative logs to be produced, but large enough to
53595+ prevent flooding.
53596+
53597+config GRKERNSEC_FLOODBURST
53598+ int "Number of messages in a burst (maximum)"
53599+ default 4
53600+ help
53601+ This option allows you to choose the maximum number of messages allowed
53602+ within the flood time interval you chose in a separate option. The
53603+ default should be suitable for most people, however if you find that
53604+ many of your logs are being interpreted as flooding, you may want to
53605+ raise this value.
53606+
53607+endmenu
53608+
53609+endmenu
53610diff -urNp linux-3.0.4/grsecurity/Makefile linux-3.0.4/grsecurity/Makefile
53611--- linux-3.0.4/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
53612+++ linux-3.0.4/grsecurity/Makefile 2011-08-23 21:48:14.000000000 -0400
53613@@ -0,0 +1,34 @@
53614+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53615+# during 2001-2009 it has been completely redesigned by Brad Spengler
53616+# into an RBAC system
53617+#
53618+# All code in this directory and various hooks inserted throughout the kernel
53619+# are copyright Brad Spengler - Open Source Security, Inc., and released
53620+# under the GPL v2 or higher
53621+
53622+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53623+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
53624+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53625+
53626+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53627+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53628+ gracl_learn.o grsec_log.o
53629+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53630+
53631+ifdef CONFIG_NET
53632+obj-y += grsec_sock.o
53633+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53634+endif
53635+
53636+ifndef CONFIG_GRKERNSEC
53637+obj-y += grsec_disabled.o
53638+endif
53639+
53640+ifdef CONFIG_GRKERNSEC_HIDESYM
53641+extra-y := grsec_hidesym.o
53642+$(obj)/grsec_hidesym.o:
53643+ @-chmod -f 500 /boot
53644+ @-chmod -f 500 /lib/modules
53645+ @-chmod -f 700 .
53646+ @echo ' grsec: protected kernel image paths'
53647+endif
53648diff -urNp linux-3.0.4/include/acpi/acpi_bus.h linux-3.0.4/include/acpi/acpi_bus.h
53649--- linux-3.0.4/include/acpi/acpi_bus.h 2011-07-21 22:17:23.000000000 -0400
53650+++ linux-3.0.4/include/acpi/acpi_bus.h 2011-08-23 21:47:56.000000000 -0400
53651@@ -107,7 +107,7 @@ struct acpi_device_ops {
53652 acpi_op_bind bind;
53653 acpi_op_unbind unbind;
53654 acpi_op_notify notify;
53655-};
53656+} __no_const;
53657
53658 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
53659
53660diff -urNp linux-3.0.4/include/asm-generic/atomic-long.h linux-3.0.4/include/asm-generic/atomic-long.h
53661--- linux-3.0.4/include/asm-generic/atomic-long.h 2011-07-21 22:17:23.000000000 -0400
53662+++ linux-3.0.4/include/asm-generic/atomic-long.h 2011-08-23 21:47:56.000000000 -0400
53663@@ -22,6 +22,12 @@
53664
53665 typedef atomic64_t atomic_long_t;
53666
53667+#ifdef CONFIG_PAX_REFCOUNT
53668+typedef atomic64_unchecked_t atomic_long_unchecked_t;
53669+#else
53670+typedef atomic64_t atomic_long_unchecked_t;
53671+#endif
53672+
53673 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
53674
53675 static inline long atomic_long_read(atomic_long_t *l)
53676@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
53677 return (long)atomic64_read(v);
53678 }
53679
53680+#ifdef CONFIG_PAX_REFCOUNT
53681+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
53682+{
53683+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53684+
53685+ return (long)atomic64_read_unchecked(v);
53686+}
53687+#endif
53688+
53689 static inline void atomic_long_set(atomic_long_t *l, long i)
53690 {
53691 atomic64_t *v = (atomic64_t *)l;
53692@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
53693 atomic64_set(v, i);
53694 }
53695
53696+#ifdef CONFIG_PAX_REFCOUNT
53697+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
53698+{
53699+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53700+
53701+ atomic64_set_unchecked(v, i);
53702+}
53703+#endif
53704+
53705 static inline void atomic_long_inc(atomic_long_t *l)
53706 {
53707 atomic64_t *v = (atomic64_t *)l;
53708@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
53709 atomic64_inc(v);
53710 }
53711
53712+#ifdef CONFIG_PAX_REFCOUNT
53713+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
53714+{
53715+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53716+
53717+ atomic64_inc_unchecked(v);
53718+}
53719+#endif
53720+
53721 static inline void atomic_long_dec(atomic_long_t *l)
53722 {
53723 atomic64_t *v = (atomic64_t *)l;
53724@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
53725 atomic64_dec(v);
53726 }
53727
53728+#ifdef CONFIG_PAX_REFCOUNT
53729+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
53730+{
53731+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53732+
53733+ atomic64_dec_unchecked(v);
53734+}
53735+#endif
53736+
53737 static inline void atomic_long_add(long i, atomic_long_t *l)
53738 {
53739 atomic64_t *v = (atomic64_t *)l;
53740@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
53741 atomic64_add(i, v);
53742 }
53743
53744+#ifdef CONFIG_PAX_REFCOUNT
53745+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
53746+{
53747+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53748+
53749+ atomic64_add_unchecked(i, v);
53750+}
53751+#endif
53752+
53753 static inline void atomic_long_sub(long i, atomic_long_t *l)
53754 {
53755 atomic64_t *v = (atomic64_t *)l;
53756@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
53757 atomic64_sub(i, v);
53758 }
53759
53760+#ifdef CONFIG_PAX_REFCOUNT
53761+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
53762+{
53763+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53764+
53765+ atomic64_sub_unchecked(i, v);
53766+}
53767+#endif
53768+
53769 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
53770 {
53771 atomic64_t *v = (atomic64_t *)l;
53772@@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
53773 return (long)atomic64_inc_return(v);
53774 }
53775
53776+#ifdef CONFIG_PAX_REFCOUNT
53777+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
53778+{
53779+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53780+
53781+ return (long)atomic64_inc_return_unchecked(v);
53782+}
53783+#endif
53784+
53785 static inline long atomic_long_dec_return(atomic_long_t *l)
53786 {
53787 atomic64_t *v = (atomic64_t *)l;
53788@@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
53789
53790 typedef atomic_t atomic_long_t;
53791
53792+#ifdef CONFIG_PAX_REFCOUNT
53793+typedef atomic_unchecked_t atomic_long_unchecked_t;
53794+#else
53795+typedef atomic_t atomic_long_unchecked_t;
53796+#endif
53797+
53798 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
53799 static inline long atomic_long_read(atomic_long_t *l)
53800 {
53801@@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
53802 return (long)atomic_read(v);
53803 }
53804
53805+#ifdef CONFIG_PAX_REFCOUNT
53806+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
53807+{
53808+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53809+
53810+ return (long)atomic_read_unchecked(v);
53811+}
53812+#endif
53813+
53814 static inline void atomic_long_set(atomic_long_t *l, long i)
53815 {
53816 atomic_t *v = (atomic_t *)l;
53817@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
53818 atomic_set(v, i);
53819 }
53820
53821+#ifdef CONFIG_PAX_REFCOUNT
53822+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
53823+{
53824+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53825+
53826+ atomic_set_unchecked(v, i);
53827+}
53828+#endif
53829+
53830 static inline void atomic_long_inc(atomic_long_t *l)
53831 {
53832 atomic_t *v = (atomic_t *)l;
53833@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
53834 atomic_inc(v);
53835 }
53836
53837+#ifdef CONFIG_PAX_REFCOUNT
53838+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
53839+{
53840+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53841+
53842+ atomic_inc_unchecked(v);
53843+}
53844+#endif
53845+
53846 static inline void atomic_long_dec(atomic_long_t *l)
53847 {
53848 atomic_t *v = (atomic_t *)l;
53849@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
53850 atomic_dec(v);
53851 }
53852
53853+#ifdef CONFIG_PAX_REFCOUNT
53854+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
53855+{
53856+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53857+
53858+ atomic_dec_unchecked(v);
53859+}
53860+#endif
53861+
53862 static inline void atomic_long_add(long i, atomic_long_t *l)
53863 {
53864 atomic_t *v = (atomic_t *)l;
53865@@ -176,6 +287,15 @@ static inline void atomic_long_add(long
53866 atomic_add(i, v);
53867 }
53868
53869+#ifdef CONFIG_PAX_REFCOUNT
53870+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
53871+{
53872+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53873+
53874+ atomic_add_unchecked(i, v);
53875+}
53876+#endif
53877+
53878 static inline void atomic_long_sub(long i, atomic_long_t *l)
53879 {
53880 atomic_t *v = (atomic_t *)l;
53881@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
53882 atomic_sub(i, v);
53883 }
53884
53885+#ifdef CONFIG_PAX_REFCOUNT
53886+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
53887+{
53888+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53889+
53890+ atomic_sub_unchecked(i, v);
53891+}
53892+#endif
53893+
53894 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
53895 {
53896 atomic_t *v = (atomic_t *)l;
53897@@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
53898 return (long)atomic_inc_return(v);
53899 }
53900
53901+#ifdef CONFIG_PAX_REFCOUNT
53902+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
53903+{
53904+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53905+
53906+ return (long)atomic_inc_return_unchecked(v);
53907+}
53908+#endif
53909+
53910 static inline long atomic_long_dec_return(atomic_long_t *l)
53911 {
53912 atomic_t *v = (atomic_t *)l;
53913@@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
53914
53915 #endif /* BITS_PER_LONG == 64 */
53916
53917+#ifdef CONFIG_PAX_REFCOUNT
53918+static inline void pax_refcount_needs_these_functions(void)
53919+{
53920+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
53921+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
53922+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
53923+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
53924+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
53925+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
53926+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
53927+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
53928+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
53929+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
53930+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
53931+
53932+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
53933+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
53934+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
53935+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
53936+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
53937+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
53938+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
53939+}
53940+#else
53941+#define atomic_read_unchecked(v) atomic_read(v)
53942+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
53943+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
53944+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
53945+#define atomic_inc_unchecked(v) atomic_inc(v)
53946+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
53947+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
53948+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
53949+#define atomic_dec_unchecked(v) atomic_dec(v)
53950+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
53951+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
53952+
53953+#define atomic_long_read_unchecked(v) atomic_long_read(v)
53954+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
53955+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
53956+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
53957+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
53958+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
53959+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
53960+#endif
53961+
53962 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
53963diff -urNp linux-3.0.4/include/asm-generic/cache.h linux-3.0.4/include/asm-generic/cache.h
53964--- linux-3.0.4/include/asm-generic/cache.h 2011-07-21 22:17:23.000000000 -0400
53965+++ linux-3.0.4/include/asm-generic/cache.h 2011-08-23 21:47:56.000000000 -0400
53966@@ -6,7 +6,7 @@
53967 * cache lines need to provide their own cache.h.
53968 */
53969
53970-#define L1_CACHE_SHIFT 5
53971-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
53972+#define L1_CACHE_SHIFT 5UL
53973+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
53974
53975 #endif /* __ASM_GENERIC_CACHE_H */
53976diff -urNp linux-3.0.4/include/asm-generic/int-l64.h linux-3.0.4/include/asm-generic/int-l64.h
53977--- linux-3.0.4/include/asm-generic/int-l64.h 2011-07-21 22:17:23.000000000 -0400
53978+++ linux-3.0.4/include/asm-generic/int-l64.h 2011-08-23 21:47:56.000000000 -0400
53979@@ -46,6 +46,8 @@ typedef unsigned int u32;
53980 typedef signed long s64;
53981 typedef unsigned long u64;
53982
53983+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
53984+
53985 #define S8_C(x) x
53986 #define U8_C(x) x ## U
53987 #define S16_C(x) x
53988diff -urNp linux-3.0.4/include/asm-generic/int-ll64.h linux-3.0.4/include/asm-generic/int-ll64.h
53989--- linux-3.0.4/include/asm-generic/int-ll64.h 2011-07-21 22:17:23.000000000 -0400
53990+++ linux-3.0.4/include/asm-generic/int-ll64.h 2011-08-23 21:47:56.000000000 -0400
53991@@ -51,6 +51,8 @@ typedef unsigned int u32;
53992 typedef signed long long s64;
53993 typedef unsigned long long u64;
53994
53995+typedef unsigned long long intoverflow_t;
53996+
53997 #define S8_C(x) x
53998 #define U8_C(x) x ## U
53999 #define S16_C(x) x
54000diff -urNp linux-3.0.4/include/asm-generic/kmap_types.h linux-3.0.4/include/asm-generic/kmap_types.h
54001--- linux-3.0.4/include/asm-generic/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
54002+++ linux-3.0.4/include/asm-generic/kmap_types.h 2011-08-23 21:47:56.000000000 -0400
54003@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
54004 KMAP_D(17) KM_NMI,
54005 KMAP_D(18) KM_NMI_PTE,
54006 KMAP_D(19) KM_KDB,
54007+KMAP_D(20) KM_CLEARPAGE,
54008 /*
54009 * Remember to update debug_kmap_atomic() when adding new kmap types!
54010 */
54011-KMAP_D(20) KM_TYPE_NR
54012+KMAP_D(21) KM_TYPE_NR
54013 };
54014
54015 #undef KMAP_D
54016diff -urNp linux-3.0.4/include/asm-generic/pgtable.h linux-3.0.4/include/asm-generic/pgtable.h
54017--- linux-3.0.4/include/asm-generic/pgtable.h 2011-07-21 22:17:23.000000000 -0400
54018+++ linux-3.0.4/include/asm-generic/pgtable.h 2011-08-23 21:47:56.000000000 -0400
54019@@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
54020 #endif /* __HAVE_ARCH_PMD_WRITE */
54021 #endif
54022
54023+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
54024+static inline unsigned long pax_open_kernel(void) { return 0; }
54025+#endif
54026+
54027+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
54028+static inline unsigned long pax_close_kernel(void) { return 0; }
54029+#endif
54030+
54031 #endif /* !__ASSEMBLY__ */
54032
54033 #endif /* _ASM_GENERIC_PGTABLE_H */
54034diff -urNp linux-3.0.4/include/asm-generic/pgtable-nopmd.h linux-3.0.4/include/asm-generic/pgtable-nopmd.h
54035--- linux-3.0.4/include/asm-generic/pgtable-nopmd.h 2011-07-21 22:17:23.000000000 -0400
54036+++ linux-3.0.4/include/asm-generic/pgtable-nopmd.h 2011-08-23 21:47:56.000000000 -0400
54037@@ -1,14 +1,19 @@
54038 #ifndef _PGTABLE_NOPMD_H
54039 #define _PGTABLE_NOPMD_H
54040
54041-#ifndef __ASSEMBLY__
54042-
54043 #include <asm-generic/pgtable-nopud.h>
54044
54045-struct mm_struct;
54046-
54047 #define __PAGETABLE_PMD_FOLDED
54048
54049+#define PMD_SHIFT PUD_SHIFT
54050+#define PTRS_PER_PMD 1
54051+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
54052+#define PMD_MASK (~(PMD_SIZE-1))
54053+
54054+#ifndef __ASSEMBLY__
54055+
54056+struct mm_struct;
54057+
54058 /*
54059 * Having the pmd type consist of a pud gets the size right, and allows
54060 * us to conceptually access the pud entry that this pmd is folded into
54061@@ -16,11 +21,6 @@ struct mm_struct;
54062 */
54063 typedef struct { pud_t pud; } pmd_t;
54064
54065-#define PMD_SHIFT PUD_SHIFT
54066-#define PTRS_PER_PMD 1
54067-#define PMD_SIZE (1UL << PMD_SHIFT)
54068-#define PMD_MASK (~(PMD_SIZE-1))
54069-
54070 /*
54071 * The "pud_xxx()" functions here are trivial for a folded two-level
54072 * setup: the pmd is never bad, and a pmd always exists (as it's folded
54073diff -urNp linux-3.0.4/include/asm-generic/pgtable-nopud.h linux-3.0.4/include/asm-generic/pgtable-nopud.h
54074--- linux-3.0.4/include/asm-generic/pgtable-nopud.h 2011-07-21 22:17:23.000000000 -0400
54075+++ linux-3.0.4/include/asm-generic/pgtable-nopud.h 2011-08-23 21:47:56.000000000 -0400
54076@@ -1,10 +1,15 @@
54077 #ifndef _PGTABLE_NOPUD_H
54078 #define _PGTABLE_NOPUD_H
54079
54080-#ifndef __ASSEMBLY__
54081-
54082 #define __PAGETABLE_PUD_FOLDED
54083
54084+#define PUD_SHIFT PGDIR_SHIFT
54085+#define PTRS_PER_PUD 1
54086+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
54087+#define PUD_MASK (~(PUD_SIZE-1))
54088+
54089+#ifndef __ASSEMBLY__
54090+
54091 /*
54092 * Having the pud type consist of a pgd gets the size right, and allows
54093 * us to conceptually access the pgd entry that this pud is folded into
54094@@ -12,11 +17,6 @@
54095 */
54096 typedef struct { pgd_t pgd; } pud_t;
54097
54098-#define PUD_SHIFT PGDIR_SHIFT
54099-#define PTRS_PER_PUD 1
54100-#define PUD_SIZE (1UL << PUD_SHIFT)
54101-#define PUD_MASK (~(PUD_SIZE-1))
54102-
54103 /*
54104 * The "pgd_xxx()" functions here are trivial for a folded two-level
54105 * setup: the pud is never bad, and a pud always exists (as it's folded
54106diff -urNp linux-3.0.4/include/asm-generic/vmlinux.lds.h linux-3.0.4/include/asm-generic/vmlinux.lds.h
54107--- linux-3.0.4/include/asm-generic/vmlinux.lds.h 2011-07-21 22:17:23.000000000 -0400
54108+++ linux-3.0.4/include/asm-generic/vmlinux.lds.h 2011-08-23 21:47:56.000000000 -0400
54109@@ -217,6 +217,7 @@
54110 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
54111 VMLINUX_SYMBOL(__start_rodata) = .; \
54112 *(.rodata) *(.rodata.*) \
54113+ *(.data..read_only) \
54114 *(__vermagic) /* Kernel version magic */ \
54115 . = ALIGN(8); \
54116 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
54117@@ -723,17 +724,18 @@
54118 * section in the linker script will go there too. @phdr should have
54119 * a leading colon.
54120 *
54121- * Note that this macros defines __per_cpu_load as an absolute symbol.
54122+ * Note that this macros defines per_cpu_load as an absolute symbol.
54123 * If there is no need to put the percpu section at a predetermined
54124 * address, use PERCPU_SECTION.
54125 */
54126 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
54127- VMLINUX_SYMBOL(__per_cpu_load) = .; \
54128- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
54129+ per_cpu_load = .; \
54130+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
54131 - LOAD_OFFSET) { \
54132+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
54133 PERCPU_INPUT(cacheline) \
54134 } phdr \
54135- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
54136+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
54137
54138 /**
54139 * PERCPU_SECTION - define output section for percpu area, simple version
54140diff -urNp linux-3.0.4/include/drm/drm_crtc_helper.h linux-3.0.4/include/drm/drm_crtc_helper.h
54141--- linux-3.0.4/include/drm/drm_crtc_helper.h 2011-07-21 22:17:23.000000000 -0400
54142+++ linux-3.0.4/include/drm/drm_crtc_helper.h 2011-08-23 21:47:56.000000000 -0400
54143@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
54144
54145 /* disable crtc when not in use - more explicit than dpms off */
54146 void (*disable)(struct drm_crtc *crtc);
54147-};
54148+} __no_const;
54149
54150 struct drm_encoder_helper_funcs {
54151 void (*dpms)(struct drm_encoder *encoder, int mode);
54152@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
54153 struct drm_connector *connector);
54154 /* disable encoder when not in use - more explicit than dpms off */
54155 void (*disable)(struct drm_encoder *encoder);
54156-};
54157+} __no_const;
54158
54159 struct drm_connector_helper_funcs {
54160 int (*get_modes)(struct drm_connector *connector);
54161diff -urNp linux-3.0.4/include/drm/drmP.h linux-3.0.4/include/drm/drmP.h
54162--- linux-3.0.4/include/drm/drmP.h 2011-07-21 22:17:23.000000000 -0400
54163+++ linux-3.0.4/include/drm/drmP.h 2011-08-23 21:47:56.000000000 -0400
54164@@ -73,6 +73,7 @@
54165 #include <linux/workqueue.h>
54166 #include <linux/poll.h>
54167 #include <asm/pgalloc.h>
54168+#include <asm/local.h>
54169 #include "drm.h"
54170
54171 #include <linux/idr.h>
54172@@ -1033,7 +1034,7 @@ struct drm_device {
54173
54174 /** \name Usage Counters */
54175 /*@{ */
54176- int open_count; /**< Outstanding files open */
54177+ local_t open_count; /**< Outstanding files open */
54178 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
54179 atomic_t vma_count; /**< Outstanding vma areas open */
54180 int buf_use; /**< Buffers in use -- cannot alloc */
54181@@ -1044,7 +1045,7 @@ struct drm_device {
54182 /*@{ */
54183 unsigned long counters;
54184 enum drm_stat_type types[15];
54185- atomic_t counts[15];
54186+ atomic_unchecked_t counts[15];
54187 /*@} */
54188
54189 struct list_head filelist;
54190diff -urNp linux-3.0.4/include/drm/ttm/ttm_memory.h linux-3.0.4/include/drm/ttm/ttm_memory.h
54191--- linux-3.0.4/include/drm/ttm/ttm_memory.h 2011-07-21 22:17:23.000000000 -0400
54192+++ linux-3.0.4/include/drm/ttm/ttm_memory.h 2011-08-23 21:47:56.000000000 -0400
54193@@ -47,7 +47,7 @@
54194
54195 struct ttm_mem_shrink {
54196 int (*do_shrink) (struct ttm_mem_shrink *);
54197-};
54198+} __no_const;
54199
54200 /**
54201 * struct ttm_mem_global - Global memory accounting structure.
54202diff -urNp linux-3.0.4/include/linux/a.out.h linux-3.0.4/include/linux/a.out.h
54203--- linux-3.0.4/include/linux/a.out.h 2011-07-21 22:17:23.000000000 -0400
54204+++ linux-3.0.4/include/linux/a.out.h 2011-08-23 21:47:56.000000000 -0400
54205@@ -39,6 +39,14 @@ enum machine_type {
54206 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
54207 };
54208
54209+/* Constants for the N_FLAGS field */
54210+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
54211+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
54212+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
54213+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
54214+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
54215+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
54216+
54217 #if !defined (N_MAGIC)
54218 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
54219 #endif
54220diff -urNp linux-3.0.4/include/linux/atmdev.h linux-3.0.4/include/linux/atmdev.h
54221--- linux-3.0.4/include/linux/atmdev.h 2011-07-21 22:17:23.000000000 -0400
54222+++ linux-3.0.4/include/linux/atmdev.h 2011-08-23 21:47:56.000000000 -0400
54223@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
54224 #endif
54225
54226 struct k_atm_aal_stats {
54227-#define __HANDLE_ITEM(i) atomic_t i
54228+#define __HANDLE_ITEM(i) atomic_unchecked_t i
54229 __AAL_STAT_ITEMS
54230 #undef __HANDLE_ITEM
54231 };
54232diff -urNp linux-3.0.4/include/linux/binfmts.h linux-3.0.4/include/linux/binfmts.h
54233--- linux-3.0.4/include/linux/binfmts.h 2011-07-21 22:17:23.000000000 -0400
54234+++ linux-3.0.4/include/linux/binfmts.h 2011-08-23 21:47:56.000000000 -0400
54235@@ -88,6 +88,7 @@ struct linux_binfmt {
54236 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
54237 int (*load_shlib)(struct file *);
54238 int (*core_dump)(struct coredump_params *cprm);
54239+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
54240 unsigned long min_coredump; /* minimal dump size */
54241 };
54242
54243diff -urNp linux-3.0.4/include/linux/blkdev.h linux-3.0.4/include/linux/blkdev.h
54244--- linux-3.0.4/include/linux/blkdev.h 2011-07-21 22:17:23.000000000 -0400
54245+++ linux-3.0.4/include/linux/blkdev.h 2011-08-26 19:49:56.000000000 -0400
54246@@ -1308,7 +1308,7 @@ struct block_device_operations {
54247 /* this callback is with swap_lock and sometimes page table lock held */
54248 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
54249 struct module *owner;
54250-};
54251+} __do_const;
54252
54253 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
54254 unsigned long);
54255diff -urNp linux-3.0.4/include/linux/blktrace_api.h linux-3.0.4/include/linux/blktrace_api.h
54256--- linux-3.0.4/include/linux/blktrace_api.h 2011-07-21 22:17:23.000000000 -0400
54257+++ linux-3.0.4/include/linux/blktrace_api.h 2011-08-23 21:47:56.000000000 -0400
54258@@ -161,7 +161,7 @@ struct blk_trace {
54259 struct dentry *dir;
54260 struct dentry *dropped_file;
54261 struct dentry *msg_file;
54262- atomic_t dropped;
54263+ atomic_unchecked_t dropped;
54264 };
54265
54266 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
54267diff -urNp linux-3.0.4/include/linux/byteorder/little_endian.h linux-3.0.4/include/linux/byteorder/little_endian.h
54268--- linux-3.0.4/include/linux/byteorder/little_endian.h 2011-07-21 22:17:23.000000000 -0400
54269+++ linux-3.0.4/include/linux/byteorder/little_endian.h 2011-08-23 21:47:56.000000000 -0400
54270@@ -42,51 +42,51 @@
54271
54272 static inline __le64 __cpu_to_le64p(const __u64 *p)
54273 {
54274- return (__force __le64)*p;
54275+ return (__force const __le64)*p;
54276 }
54277 static inline __u64 __le64_to_cpup(const __le64 *p)
54278 {
54279- return (__force __u64)*p;
54280+ return (__force const __u64)*p;
54281 }
54282 static inline __le32 __cpu_to_le32p(const __u32 *p)
54283 {
54284- return (__force __le32)*p;
54285+ return (__force const __le32)*p;
54286 }
54287 static inline __u32 __le32_to_cpup(const __le32 *p)
54288 {
54289- return (__force __u32)*p;
54290+ return (__force const __u32)*p;
54291 }
54292 static inline __le16 __cpu_to_le16p(const __u16 *p)
54293 {
54294- return (__force __le16)*p;
54295+ return (__force const __le16)*p;
54296 }
54297 static inline __u16 __le16_to_cpup(const __le16 *p)
54298 {
54299- return (__force __u16)*p;
54300+ return (__force const __u16)*p;
54301 }
54302 static inline __be64 __cpu_to_be64p(const __u64 *p)
54303 {
54304- return (__force __be64)__swab64p(p);
54305+ return (__force const __be64)__swab64p(p);
54306 }
54307 static inline __u64 __be64_to_cpup(const __be64 *p)
54308 {
54309- return __swab64p((__u64 *)p);
54310+ return __swab64p((const __u64 *)p);
54311 }
54312 static inline __be32 __cpu_to_be32p(const __u32 *p)
54313 {
54314- return (__force __be32)__swab32p(p);
54315+ return (__force const __be32)__swab32p(p);
54316 }
54317 static inline __u32 __be32_to_cpup(const __be32 *p)
54318 {
54319- return __swab32p((__u32 *)p);
54320+ return __swab32p((const __u32 *)p);
54321 }
54322 static inline __be16 __cpu_to_be16p(const __u16 *p)
54323 {
54324- return (__force __be16)__swab16p(p);
54325+ return (__force const __be16)__swab16p(p);
54326 }
54327 static inline __u16 __be16_to_cpup(const __be16 *p)
54328 {
54329- return __swab16p((__u16 *)p);
54330+ return __swab16p((const __u16 *)p);
54331 }
54332 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
54333 #define __le64_to_cpus(x) do { (void)(x); } while (0)
54334diff -urNp linux-3.0.4/include/linux/cache.h linux-3.0.4/include/linux/cache.h
54335--- linux-3.0.4/include/linux/cache.h 2011-07-21 22:17:23.000000000 -0400
54336+++ linux-3.0.4/include/linux/cache.h 2011-08-23 21:47:56.000000000 -0400
54337@@ -16,6 +16,10 @@
54338 #define __read_mostly
54339 #endif
54340
54341+#ifndef __read_only
54342+#define __read_only __read_mostly
54343+#endif
54344+
54345 #ifndef ____cacheline_aligned
54346 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
54347 #endif
54348diff -urNp linux-3.0.4/include/linux/capability.h linux-3.0.4/include/linux/capability.h
54349--- linux-3.0.4/include/linux/capability.h 2011-07-21 22:17:23.000000000 -0400
54350+++ linux-3.0.4/include/linux/capability.h 2011-08-23 21:48:14.000000000 -0400
54351@@ -547,6 +547,9 @@ extern bool capable(int cap);
54352 extern bool ns_capable(struct user_namespace *ns, int cap);
54353 extern bool task_ns_capable(struct task_struct *t, int cap);
54354 extern bool nsown_capable(int cap);
54355+extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
54356+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
54357+extern bool capable_nolog(int cap);
54358
54359 /* audit system wants to get cap info from files as well */
54360 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
54361diff -urNp linux-3.0.4/include/linux/cleancache.h linux-3.0.4/include/linux/cleancache.h
54362--- linux-3.0.4/include/linux/cleancache.h 2011-07-21 22:17:23.000000000 -0400
54363+++ linux-3.0.4/include/linux/cleancache.h 2011-08-23 21:47:56.000000000 -0400
54364@@ -31,7 +31,7 @@ struct cleancache_ops {
54365 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
54366 void (*flush_inode)(int, struct cleancache_filekey);
54367 void (*flush_fs)(int);
54368-};
54369+} __no_const;
54370
54371 extern struct cleancache_ops
54372 cleancache_register_ops(struct cleancache_ops *ops);
54373diff -urNp linux-3.0.4/include/linux/compiler-gcc4.h linux-3.0.4/include/linux/compiler-gcc4.h
54374--- linux-3.0.4/include/linux/compiler-gcc4.h 2011-07-21 22:17:23.000000000 -0400
54375+++ linux-3.0.4/include/linux/compiler-gcc4.h 2011-08-26 19:49:56.000000000 -0400
54376@@ -31,6 +31,12 @@
54377
54378
54379 #if __GNUC_MINOR__ >= 5
54380+
54381+#ifdef CONSTIFY_PLUGIN
54382+#define __no_const __attribute__((no_const))
54383+#define __do_const __attribute__((do_const))
54384+#endif
54385+
54386 /*
54387 * Mark a position in code as unreachable. This can be used to
54388 * suppress control flow warnings after asm blocks that transfer
54389@@ -46,6 +52,11 @@
54390 #define __noclone __attribute__((__noclone__))
54391
54392 #endif
54393+
54394+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
54395+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
54396+#define __bos0(ptr) __bos((ptr), 0)
54397+#define __bos1(ptr) __bos((ptr), 1)
54398 #endif
54399
54400 #if __GNUC_MINOR__ > 0
54401diff -urNp linux-3.0.4/include/linux/compiler.h linux-3.0.4/include/linux/compiler.h
54402--- linux-3.0.4/include/linux/compiler.h 2011-07-21 22:17:23.000000000 -0400
54403+++ linux-3.0.4/include/linux/compiler.h 2011-08-26 19:49:56.000000000 -0400
54404@@ -264,6 +264,14 @@ void ftrace_likely_update(struct ftrace_
54405 # define __attribute_const__ /* unimplemented */
54406 #endif
54407
54408+#ifndef __no_const
54409+# define __no_const
54410+#endif
54411+
54412+#ifndef __do_const
54413+# define __do_const
54414+#endif
54415+
54416 /*
54417 * Tell gcc if a function is cold. The compiler will assume any path
54418 * directly leading to the call is unlikely.
54419@@ -273,6 +281,22 @@ void ftrace_likely_update(struct ftrace_
54420 #define __cold
54421 #endif
54422
54423+#ifndef __alloc_size
54424+#define __alloc_size(...)
54425+#endif
54426+
54427+#ifndef __bos
54428+#define __bos(ptr, arg)
54429+#endif
54430+
54431+#ifndef __bos0
54432+#define __bos0(ptr)
54433+#endif
54434+
54435+#ifndef __bos1
54436+#define __bos1(ptr)
54437+#endif
54438+
54439 /* Simple shorthand for a section definition */
54440 #ifndef __section
54441 # define __section(S) __attribute__ ((__section__(#S)))
54442@@ -306,6 +330,7 @@ void ftrace_likely_update(struct ftrace_
54443 * use is to mediate communication between process-level code and irq/NMI
54444 * handlers, all running on the same CPU.
54445 */
54446-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
54447+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
54448+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
54449
54450 #endif /* __LINUX_COMPILER_H */
54451diff -urNp linux-3.0.4/include/linux/cpuset.h linux-3.0.4/include/linux/cpuset.h
54452--- linux-3.0.4/include/linux/cpuset.h 2011-07-21 22:17:23.000000000 -0400
54453+++ linux-3.0.4/include/linux/cpuset.h 2011-08-23 21:47:56.000000000 -0400
54454@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
54455 * nodemask.
54456 */
54457 smp_mb();
54458- --ACCESS_ONCE(current->mems_allowed_change_disable);
54459+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
54460 }
54461
54462 static inline void set_mems_allowed(nodemask_t nodemask)
54463diff -urNp linux-3.0.4/include/linux/crypto.h linux-3.0.4/include/linux/crypto.h
54464--- linux-3.0.4/include/linux/crypto.h 2011-07-21 22:17:23.000000000 -0400
54465+++ linux-3.0.4/include/linux/crypto.h 2011-08-23 21:47:56.000000000 -0400
54466@@ -361,7 +361,7 @@ struct cipher_tfm {
54467 const u8 *key, unsigned int keylen);
54468 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
54469 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
54470-};
54471+} __no_const;
54472
54473 struct hash_tfm {
54474 int (*init)(struct hash_desc *desc);
54475@@ -382,13 +382,13 @@ struct compress_tfm {
54476 int (*cot_decompress)(struct crypto_tfm *tfm,
54477 const u8 *src, unsigned int slen,
54478 u8 *dst, unsigned int *dlen);
54479-};
54480+} __no_const;
54481
54482 struct rng_tfm {
54483 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
54484 unsigned int dlen);
54485 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
54486-};
54487+} __no_const;
54488
54489 #define crt_ablkcipher crt_u.ablkcipher
54490 #define crt_aead crt_u.aead
54491diff -urNp linux-3.0.4/include/linux/decompress/mm.h linux-3.0.4/include/linux/decompress/mm.h
54492--- linux-3.0.4/include/linux/decompress/mm.h 2011-07-21 22:17:23.000000000 -0400
54493+++ linux-3.0.4/include/linux/decompress/mm.h 2011-08-23 21:47:56.000000000 -0400
54494@@ -77,7 +77,7 @@ static void free(void *where)
54495 * warnings when not needed (indeed large_malloc / large_free are not
54496 * needed by inflate */
54497
54498-#define malloc(a) kmalloc(a, GFP_KERNEL)
54499+#define malloc(a) kmalloc((a), GFP_KERNEL)
54500 #define free(a) kfree(a)
54501
54502 #define large_malloc(a) vmalloc(a)
54503diff -urNp linux-3.0.4/include/linux/dma-mapping.h linux-3.0.4/include/linux/dma-mapping.h
54504--- linux-3.0.4/include/linux/dma-mapping.h 2011-07-21 22:17:23.000000000 -0400
54505+++ linux-3.0.4/include/linux/dma-mapping.h 2011-08-26 19:49:56.000000000 -0400
54506@@ -50,7 +50,7 @@ struct dma_map_ops {
54507 int (*dma_supported)(struct device *dev, u64 mask);
54508 int (*set_dma_mask)(struct device *dev, u64 mask);
54509 int is_phys;
54510-};
54511+} __do_const;
54512
54513 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
54514
54515diff -urNp linux-3.0.4/include/linux/efi.h linux-3.0.4/include/linux/efi.h
54516--- linux-3.0.4/include/linux/efi.h 2011-07-21 22:17:23.000000000 -0400
54517+++ linux-3.0.4/include/linux/efi.h 2011-08-23 21:47:56.000000000 -0400
54518@@ -410,7 +410,7 @@ struct efivar_operations {
54519 efi_get_variable_t *get_variable;
54520 efi_get_next_variable_t *get_next_variable;
54521 efi_set_variable_t *set_variable;
54522-};
54523+} __no_const;
54524
54525 struct efivars {
54526 /*
54527diff -urNp linux-3.0.4/include/linux/elf.h linux-3.0.4/include/linux/elf.h
54528--- linux-3.0.4/include/linux/elf.h 2011-07-21 22:17:23.000000000 -0400
54529+++ linux-3.0.4/include/linux/elf.h 2011-08-23 21:47:56.000000000 -0400
54530@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
54531 #define PT_GNU_EH_FRAME 0x6474e550
54532
54533 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
54534+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
54535+
54536+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
54537+
54538+/* Constants for the e_flags field */
54539+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
54540+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
54541+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
54542+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
54543+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
54544+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
54545
54546 /*
54547 * Extended Numbering
54548@@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
54549 #define DT_DEBUG 21
54550 #define DT_TEXTREL 22
54551 #define DT_JMPREL 23
54552+#define DT_FLAGS 30
54553+ #define DF_TEXTREL 0x00000004
54554 #define DT_ENCODING 32
54555 #define OLD_DT_LOOS 0x60000000
54556 #define DT_LOOS 0x6000000d
54557@@ -252,6 +265,19 @@ typedef struct elf64_hdr {
54558 #define PF_W 0x2
54559 #define PF_X 0x1
54560
54561+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
54562+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
54563+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
54564+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
54565+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
54566+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
54567+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
54568+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
54569+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
54570+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
54571+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
54572+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
54573+
54574 typedef struct elf32_phdr{
54575 Elf32_Word p_type;
54576 Elf32_Off p_offset;
54577@@ -344,6 +370,8 @@ typedef struct elf64_shdr {
54578 #define EI_OSABI 7
54579 #define EI_PAD 8
54580
54581+#define EI_PAX 14
54582+
54583 #define ELFMAG0 0x7f /* EI_MAG */
54584 #define ELFMAG1 'E'
54585 #define ELFMAG2 'L'
54586@@ -422,6 +450,7 @@ extern Elf32_Dyn _DYNAMIC [];
54587 #define elf_note elf32_note
54588 #define elf_addr_t Elf32_Off
54589 #define Elf_Half Elf32_Half
54590+#define elf_dyn Elf32_Dyn
54591
54592 #else
54593
54594@@ -432,6 +461,7 @@ extern Elf64_Dyn _DYNAMIC [];
54595 #define elf_note elf64_note
54596 #define elf_addr_t Elf64_Off
54597 #define Elf_Half Elf64_Half
54598+#define elf_dyn Elf64_Dyn
54599
54600 #endif
54601
54602diff -urNp linux-3.0.4/include/linux/firewire.h linux-3.0.4/include/linux/firewire.h
54603--- linux-3.0.4/include/linux/firewire.h 2011-07-21 22:17:23.000000000 -0400
54604+++ linux-3.0.4/include/linux/firewire.h 2011-08-23 21:47:56.000000000 -0400
54605@@ -428,7 +428,7 @@ struct fw_iso_context {
54606 union {
54607 fw_iso_callback_t sc;
54608 fw_iso_mc_callback_t mc;
54609- } callback;
54610+ } __no_const callback;
54611 void *callback_data;
54612 };
54613
54614diff -urNp linux-3.0.4/include/linux/fscache-cache.h linux-3.0.4/include/linux/fscache-cache.h
54615--- linux-3.0.4/include/linux/fscache-cache.h 2011-07-21 22:17:23.000000000 -0400
54616+++ linux-3.0.4/include/linux/fscache-cache.h 2011-08-23 21:47:56.000000000 -0400
54617@@ -102,7 +102,7 @@ struct fscache_operation {
54618 fscache_operation_release_t release;
54619 };
54620
54621-extern atomic_t fscache_op_debug_id;
54622+extern atomic_unchecked_t fscache_op_debug_id;
54623 extern void fscache_op_work_func(struct work_struct *work);
54624
54625 extern void fscache_enqueue_operation(struct fscache_operation *);
54626@@ -122,7 +122,7 @@ static inline void fscache_operation_ini
54627 {
54628 INIT_WORK(&op->work, fscache_op_work_func);
54629 atomic_set(&op->usage, 1);
54630- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
54631+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
54632 op->processor = processor;
54633 op->release = release;
54634 INIT_LIST_HEAD(&op->pend_link);
54635diff -urNp linux-3.0.4/include/linux/fs.h linux-3.0.4/include/linux/fs.h
54636--- linux-3.0.4/include/linux/fs.h 2011-07-21 22:17:23.000000000 -0400
54637+++ linux-3.0.4/include/linux/fs.h 2011-08-26 19:49:56.000000000 -0400
54638@@ -109,6 +109,11 @@ struct inodes_stat_t {
54639 /* File was opened by fanotify and shouldn't generate fanotify events */
54640 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
54641
54642+/* Hack for grsec so as not to require read permission simply to execute
54643+ * a binary
54644+ */
54645+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
54646+
54647 /*
54648 * The below are the various read and write types that we support. Some of
54649 * them include behavioral modifiers that send information down to the
54650@@ -1571,7 +1576,8 @@ struct file_operations {
54651 int (*setlease)(struct file *, long, struct file_lock **);
54652 long (*fallocate)(struct file *file, int mode, loff_t offset,
54653 loff_t len);
54654-};
54655+} __do_const;
54656+typedef struct file_operations __no_const file_operations_no_const;
54657
54658 #define IPERM_FLAG_RCU 0x0001
54659
54660diff -urNp linux-3.0.4/include/linux/fsnotify.h linux-3.0.4/include/linux/fsnotify.h
54661--- linux-3.0.4/include/linux/fsnotify.h 2011-07-21 22:17:23.000000000 -0400
54662+++ linux-3.0.4/include/linux/fsnotify.h 2011-08-24 18:10:29.000000000 -0400
54663@@ -314,7 +314,7 @@ static inline void fsnotify_change(struc
54664 */
54665 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
54666 {
54667- return kstrdup(name, GFP_KERNEL);
54668+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
54669 }
54670
54671 /*
54672diff -urNp linux-3.0.4/include/linux/fs_struct.h linux-3.0.4/include/linux/fs_struct.h
54673--- linux-3.0.4/include/linux/fs_struct.h 2011-07-21 22:17:23.000000000 -0400
54674+++ linux-3.0.4/include/linux/fs_struct.h 2011-08-23 21:47:56.000000000 -0400
54675@@ -6,7 +6,7 @@
54676 #include <linux/seqlock.h>
54677
54678 struct fs_struct {
54679- int users;
54680+ atomic_t users;
54681 spinlock_t lock;
54682 seqcount_t seq;
54683 int umask;
54684diff -urNp linux-3.0.4/include/linux/ftrace_event.h linux-3.0.4/include/linux/ftrace_event.h
54685--- linux-3.0.4/include/linux/ftrace_event.h 2011-07-21 22:17:23.000000000 -0400
54686+++ linux-3.0.4/include/linux/ftrace_event.h 2011-08-23 21:47:56.000000000 -0400
54687@@ -96,7 +96,7 @@ struct trace_event_functions {
54688 trace_print_func raw;
54689 trace_print_func hex;
54690 trace_print_func binary;
54691-};
54692+} __no_const;
54693
54694 struct trace_event {
54695 struct hlist_node node;
54696@@ -247,7 +247,7 @@ extern int trace_define_field(struct ftr
54697 extern int trace_add_event_call(struct ftrace_event_call *call);
54698 extern void trace_remove_event_call(struct ftrace_event_call *call);
54699
54700-#define is_signed_type(type) (((type)(-1)) < 0)
54701+#define is_signed_type(type) (((type)(-1)) < (type)1)
54702
54703 int trace_set_clr_event(const char *system, const char *event, int set);
54704
54705diff -urNp linux-3.0.4/include/linux/genhd.h linux-3.0.4/include/linux/genhd.h
54706--- linux-3.0.4/include/linux/genhd.h 2011-07-21 22:17:23.000000000 -0400
54707+++ linux-3.0.4/include/linux/genhd.h 2011-08-23 21:47:56.000000000 -0400
54708@@ -184,7 +184,7 @@ struct gendisk {
54709 struct kobject *slave_dir;
54710
54711 struct timer_rand_state *random;
54712- atomic_t sync_io; /* RAID */
54713+ atomic_unchecked_t sync_io; /* RAID */
54714 struct disk_events *ev;
54715 #ifdef CONFIG_BLK_DEV_INTEGRITY
54716 struct blk_integrity *integrity;
54717diff -urNp linux-3.0.4/include/linux/gracl.h linux-3.0.4/include/linux/gracl.h
54718--- linux-3.0.4/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
54719+++ linux-3.0.4/include/linux/gracl.h 2011-08-23 21:48:14.000000000 -0400
54720@@ -0,0 +1,317 @@
54721+#ifndef GR_ACL_H
54722+#define GR_ACL_H
54723+
54724+#include <linux/grdefs.h>
54725+#include <linux/resource.h>
54726+#include <linux/capability.h>
54727+#include <linux/dcache.h>
54728+#include <asm/resource.h>
54729+
54730+/* Major status information */
54731+
54732+#define GR_VERSION "grsecurity 2.2.2"
54733+#define GRSECURITY_VERSION 0x2202
54734+
54735+enum {
54736+ GR_SHUTDOWN = 0,
54737+ GR_ENABLE = 1,
54738+ GR_SPROLE = 2,
54739+ GR_RELOAD = 3,
54740+ GR_SEGVMOD = 4,
54741+ GR_STATUS = 5,
54742+ GR_UNSPROLE = 6,
54743+ GR_PASSSET = 7,
54744+ GR_SPROLEPAM = 8,
54745+};
54746+
54747+/* Password setup definitions
54748+ * kernel/grhash.c */
54749+enum {
54750+ GR_PW_LEN = 128,
54751+ GR_SALT_LEN = 16,
54752+ GR_SHA_LEN = 32,
54753+};
54754+
54755+enum {
54756+ GR_SPROLE_LEN = 64,
54757+};
54758+
54759+enum {
54760+ GR_NO_GLOB = 0,
54761+ GR_REG_GLOB,
54762+ GR_CREATE_GLOB
54763+};
54764+
54765+#define GR_NLIMITS 32
54766+
54767+/* Begin Data Structures */
54768+
54769+struct sprole_pw {
54770+ unsigned char *rolename;
54771+ unsigned char salt[GR_SALT_LEN];
54772+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
54773+};
54774+
54775+struct name_entry {
54776+ __u32 key;
54777+ ino_t inode;
54778+ dev_t device;
54779+ char *name;
54780+ __u16 len;
54781+ __u8 deleted;
54782+ struct name_entry *prev;
54783+ struct name_entry *next;
54784+};
54785+
54786+struct inodev_entry {
54787+ struct name_entry *nentry;
54788+ struct inodev_entry *prev;
54789+ struct inodev_entry *next;
54790+};
54791+
54792+struct acl_role_db {
54793+ struct acl_role_label **r_hash;
54794+ __u32 r_size;
54795+};
54796+
54797+struct inodev_db {
54798+ struct inodev_entry **i_hash;
54799+ __u32 i_size;
54800+};
54801+
54802+struct name_db {
54803+ struct name_entry **n_hash;
54804+ __u32 n_size;
54805+};
54806+
54807+struct crash_uid {
54808+ uid_t uid;
54809+ unsigned long expires;
54810+};
54811+
54812+struct gr_hash_struct {
54813+ void **table;
54814+ void **nametable;
54815+ void *first;
54816+ __u32 table_size;
54817+ __u32 used_size;
54818+ int type;
54819+};
54820+
54821+/* Userspace Grsecurity ACL data structures */
54822+
54823+struct acl_subject_label {
54824+ char *filename;
54825+ ino_t inode;
54826+ dev_t device;
54827+ __u32 mode;
54828+ kernel_cap_t cap_mask;
54829+ kernel_cap_t cap_lower;
54830+ kernel_cap_t cap_invert_audit;
54831+
54832+ struct rlimit res[GR_NLIMITS];
54833+ __u32 resmask;
54834+
54835+ __u8 user_trans_type;
54836+ __u8 group_trans_type;
54837+ uid_t *user_transitions;
54838+ gid_t *group_transitions;
54839+ __u16 user_trans_num;
54840+ __u16 group_trans_num;
54841+
54842+ __u32 sock_families[2];
54843+ __u32 ip_proto[8];
54844+ __u32 ip_type;
54845+ struct acl_ip_label **ips;
54846+ __u32 ip_num;
54847+ __u32 inaddr_any_override;
54848+
54849+ __u32 crashes;
54850+ unsigned long expires;
54851+
54852+ struct acl_subject_label *parent_subject;
54853+ struct gr_hash_struct *hash;
54854+ struct acl_subject_label *prev;
54855+ struct acl_subject_label *next;
54856+
54857+ struct acl_object_label **obj_hash;
54858+ __u32 obj_hash_size;
54859+ __u16 pax_flags;
54860+};
54861+
54862+struct role_allowed_ip {
54863+ __u32 addr;
54864+ __u32 netmask;
54865+
54866+ struct role_allowed_ip *prev;
54867+ struct role_allowed_ip *next;
54868+};
54869+
54870+struct role_transition {
54871+ char *rolename;
54872+
54873+ struct role_transition *prev;
54874+ struct role_transition *next;
54875+};
54876+
54877+struct acl_role_label {
54878+ char *rolename;
54879+ uid_t uidgid;
54880+ __u16 roletype;
54881+
54882+ __u16 auth_attempts;
54883+ unsigned long expires;
54884+
54885+ struct acl_subject_label *root_label;
54886+ struct gr_hash_struct *hash;
54887+
54888+ struct acl_role_label *prev;
54889+ struct acl_role_label *next;
54890+
54891+ struct role_transition *transitions;
54892+ struct role_allowed_ip *allowed_ips;
54893+ uid_t *domain_children;
54894+ __u16 domain_child_num;
54895+
54896+ struct acl_subject_label **subj_hash;
54897+ __u32 subj_hash_size;
54898+};
54899+
54900+struct user_acl_role_db {
54901+ struct acl_role_label **r_table;
54902+ __u32 num_pointers; /* Number of allocations to track */
54903+ __u32 num_roles; /* Number of roles */
54904+ __u32 num_domain_children; /* Number of domain children */
54905+ __u32 num_subjects; /* Number of subjects */
54906+ __u32 num_objects; /* Number of objects */
54907+};
54908+
54909+struct acl_object_label {
54910+ char *filename;
54911+ ino_t inode;
54912+ dev_t device;
54913+ __u32 mode;
54914+
54915+ struct acl_subject_label *nested;
54916+ struct acl_object_label *globbed;
54917+
54918+ /* next two structures not used */
54919+
54920+ struct acl_object_label *prev;
54921+ struct acl_object_label *next;
54922+};
54923+
54924+struct acl_ip_label {
54925+ char *iface;
54926+ __u32 addr;
54927+ __u32 netmask;
54928+ __u16 low, high;
54929+ __u8 mode;
54930+ __u32 type;
54931+ __u32 proto[8];
54932+
54933+ /* next two structures not used */
54934+
54935+ struct acl_ip_label *prev;
54936+ struct acl_ip_label *next;
54937+};
54938+
54939+struct gr_arg {
54940+ struct user_acl_role_db role_db;
54941+ unsigned char pw[GR_PW_LEN];
54942+ unsigned char salt[GR_SALT_LEN];
54943+ unsigned char sum[GR_SHA_LEN];
54944+ unsigned char sp_role[GR_SPROLE_LEN];
54945+ struct sprole_pw *sprole_pws;
54946+ dev_t segv_device;
54947+ ino_t segv_inode;
54948+ uid_t segv_uid;
54949+ __u16 num_sprole_pws;
54950+ __u16 mode;
54951+};
54952+
54953+struct gr_arg_wrapper {
54954+ struct gr_arg *arg;
54955+ __u32 version;
54956+ __u32 size;
54957+};
54958+
54959+struct subject_map {
54960+ struct acl_subject_label *user;
54961+ struct acl_subject_label *kernel;
54962+ struct subject_map *prev;
54963+ struct subject_map *next;
54964+};
54965+
54966+struct acl_subj_map_db {
54967+ struct subject_map **s_hash;
54968+ __u32 s_size;
54969+};
54970+
54971+/* End Data Structures Section */
54972+
54973+/* Hash functions generated by empirical testing by Brad Spengler
54974+ Makes good use of the low bits of the inode. Generally 0-1 times
54975+ in loop for successful match. 0-3 for unsuccessful match.
54976+ Shift/add algorithm with modulus of table size and an XOR*/
54977+
54978+static __inline__ unsigned int
54979+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
54980+{
54981+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
54982+}
54983+
54984+ static __inline__ unsigned int
54985+shash(const struct acl_subject_label *userp, const unsigned int sz)
54986+{
54987+ return ((const unsigned long)userp % sz);
54988+}
54989+
54990+static __inline__ unsigned int
54991+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
54992+{
54993+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
54994+}
54995+
54996+static __inline__ unsigned int
54997+nhash(const char *name, const __u16 len, const unsigned int sz)
54998+{
54999+ return full_name_hash((const unsigned char *)name, len) % sz;
55000+}
55001+
55002+#define FOR_EACH_ROLE_START(role) \
55003+ role = role_list; \
55004+ while (role) {
55005+
55006+#define FOR_EACH_ROLE_END(role) \
55007+ role = role->prev; \
55008+ }
55009+
55010+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
55011+ subj = NULL; \
55012+ iter = 0; \
55013+ while (iter < role->subj_hash_size) { \
55014+ if (subj == NULL) \
55015+ subj = role->subj_hash[iter]; \
55016+ if (subj == NULL) { \
55017+ iter++; \
55018+ continue; \
55019+ }
55020+
55021+#define FOR_EACH_SUBJECT_END(subj,iter) \
55022+ subj = subj->next; \
55023+ if (subj == NULL) \
55024+ iter++; \
55025+ }
55026+
55027+
55028+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
55029+ subj = role->hash->first; \
55030+ while (subj != NULL) {
55031+
55032+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
55033+ subj = subj->next; \
55034+ }
55035+
55036+#endif
55037+
55038diff -urNp linux-3.0.4/include/linux/gralloc.h linux-3.0.4/include/linux/gralloc.h
55039--- linux-3.0.4/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
55040+++ linux-3.0.4/include/linux/gralloc.h 2011-08-23 21:48:14.000000000 -0400
55041@@ -0,0 +1,9 @@
55042+#ifndef __GRALLOC_H
55043+#define __GRALLOC_H
55044+
55045+void acl_free_all(void);
55046+int acl_alloc_stack_init(unsigned long size);
55047+void *acl_alloc(unsigned long len);
55048+void *acl_alloc_num(unsigned long num, unsigned long len);
55049+
55050+#endif
55051diff -urNp linux-3.0.4/include/linux/grdefs.h linux-3.0.4/include/linux/grdefs.h
55052--- linux-3.0.4/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
55053+++ linux-3.0.4/include/linux/grdefs.h 2011-08-23 21:48:14.000000000 -0400
55054@@ -0,0 +1,140 @@
55055+#ifndef GRDEFS_H
55056+#define GRDEFS_H
55057+
55058+/* Begin grsecurity status declarations */
55059+
55060+enum {
55061+ GR_READY = 0x01,
55062+ GR_STATUS_INIT = 0x00 // disabled state
55063+};
55064+
55065+/* Begin ACL declarations */
55066+
55067+/* Role flags */
55068+
55069+enum {
55070+ GR_ROLE_USER = 0x0001,
55071+ GR_ROLE_GROUP = 0x0002,
55072+ GR_ROLE_DEFAULT = 0x0004,
55073+ GR_ROLE_SPECIAL = 0x0008,
55074+ GR_ROLE_AUTH = 0x0010,
55075+ GR_ROLE_NOPW = 0x0020,
55076+ GR_ROLE_GOD = 0x0040,
55077+ GR_ROLE_LEARN = 0x0080,
55078+ GR_ROLE_TPE = 0x0100,
55079+ GR_ROLE_DOMAIN = 0x0200,
55080+ GR_ROLE_PAM = 0x0400,
55081+ GR_ROLE_PERSIST = 0x0800
55082+};
55083+
55084+/* ACL Subject and Object mode flags */
55085+enum {
55086+ GR_DELETED = 0x80000000
55087+};
55088+
55089+/* ACL Object-only mode flags */
55090+enum {
55091+ GR_READ = 0x00000001,
55092+ GR_APPEND = 0x00000002,
55093+ GR_WRITE = 0x00000004,
55094+ GR_EXEC = 0x00000008,
55095+ GR_FIND = 0x00000010,
55096+ GR_INHERIT = 0x00000020,
55097+ GR_SETID = 0x00000040,
55098+ GR_CREATE = 0x00000080,
55099+ GR_DELETE = 0x00000100,
55100+ GR_LINK = 0x00000200,
55101+ GR_AUDIT_READ = 0x00000400,
55102+ GR_AUDIT_APPEND = 0x00000800,
55103+ GR_AUDIT_WRITE = 0x00001000,
55104+ GR_AUDIT_EXEC = 0x00002000,
55105+ GR_AUDIT_FIND = 0x00004000,
55106+ GR_AUDIT_INHERIT= 0x00008000,
55107+ GR_AUDIT_SETID = 0x00010000,
55108+ GR_AUDIT_CREATE = 0x00020000,
55109+ GR_AUDIT_DELETE = 0x00040000,
55110+ GR_AUDIT_LINK = 0x00080000,
55111+ GR_PTRACERD = 0x00100000,
55112+ GR_NOPTRACE = 0x00200000,
55113+ GR_SUPPRESS = 0x00400000,
55114+ GR_NOLEARN = 0x00800000,
55115+ GR_INIT_TRANSFER= 0x01000000
55116+};
55117+
55118+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
55119+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
55120+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
55121+
55122+/* ACL subject-only mode flags */
55123+enum {
55124+ GR_KILL = 0x00000001,
55125+ GR_VIEW = 0x00000002,
55126+ GR_PROTECTED = 0x00000004,
55127+ GR_LEARN = 0x00000008,
55128+ GR_OVERRIDE = 0x00000010,
55129+ /* just a placeholder, this mode is only used in userspace */
55130+ GR_DUMMY = 0x00000020,
55131+ GR_PROTSHM = 0x00000040,
55132+ GR_KILLPROC = 0x00000080,
55133+ GR_KILLIPPROC = 0x00000100,
55134+ /* just a placeholder, this mode is only used in userspace */
55135+ GR_NOTROJAN = 0x00000200,
55136+ GR_PROTPROCFD = 0x00000400,
55137+ GR_PROCACCT = 0x00000800,
55138+ GR_RELAXPTRACE = 0x00001000,
55139+ GR_NESTED = 0x00002000,
55140+ GR_INHERITLEARN = 0x00004000,
55141+ GR_PROCFIND = 0x00008000,
55142+ GR_POVERRIDE = 0x00010000,
55143+ GR_KERNELAUTH = 0x00020000,
55144+ GR_ATSECURE = 0x00040000,
55145+ GR_SHMEXEC = 0x00080000
55146+};
55147+
55148+enum {
55149+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
55150+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
55151+ GR_PAX_ENABLE_MPROTECT = 0x0004,
55152+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
55153+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
55154+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
55155+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
55156+ GR_PAX_DISABLE_MPROTECT = 0x0400,
55157+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
55158+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
55159+};
55160+
55161+enum {
55162+ GR_ID_USER = 0x01,
55163+ GR_ID_GROUP = 0x02,
55164+};
55165+
55166+enum {
55167+ GR_ID_ALLOW = 0x01,
55168+ GR_ID_DENY = 0x02,
55169+};
55170+
55171+#define GR_CRASH_RES 31
55172+#define GR_UIDTABLE_MAX 500
55173+
55174+/* begin resource learning section */
55175+enum {
55176+ GR_RLIM_CPU_BUMP = 60,
55177+ GR_RLIM_FSIZE_BUMP = 50000,
55178+ GR_RLIM_DATA_BUMP = 10000,
55179+ GR_RLIM_STACK_BUMP = 1000,
55180+ GR_RLIM_CORE_BUMP = 10000,
55181+ GR_RLIM_RSS_BUMP = 500000,
55182+ GR_RLIM_NPROC_BUMP = 1,
55183+ GR_RLIM_NOFILE_BUMP = 5,
55184+ GR_RLIM_MEMLOCK_BUMP = 50000,
55185+ GR_RLIM_AS_BUMP = 500000,
55186+ GR_RLIM_LOCKS_BUMP = 2,
55187+ GR_RLIM_SIGPENDING_BUMP = 5,
55188+ GR_RLIM_MSGQUEUE_BUMP = 10000,
55189+ GR_RLIM_NICE_BUMP = 1,
55190+ GR_RLIM_RTPRIO_BUMP = 1,
55191+ GR_RLIM_RTTIME_BUMP = 1000000
55192+};
55193+
55194+#endif
55195diff -urNp linux-3.0.4/include/linux/grinternal.h linux-3.0.4/include/linux/grinternal.h
55196--- linux-3.0.4/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
55197+++ linux-3.0.4/include/linux/grinternal.h 2011-08-23 21:48:14.000000000 -0400
55198@@ -0,0 +1,219 @@
55199+#ifndef __GRINTERNAL_H
55200+#define __GRINTERNAL_H
55201+
55202+#ifdef CONFIG_GRKERNSEC
55203+
55204+#include <linux/fs.h>
55205+#include <linux/mnt_namespace.h>
55206+#include <linux/nsproxy.h>
55207+#include <linux/gracl.h>
55208+#include <linux/grdefs.h>
55209+#include <linux/grmsg.h>
55210+
55211+void gr_add_learn_entry(const char *fmt, ...)
55212+ __attribute__ ((format (printf, 1, 2)));
55213+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
55214+ const struct vfsmount *mnt);
55215+__u32 gr_check_create(const struct dentry *new_dentry,
55216+ const struct dentry *parent,
55217+ const struct vfsmount *mnt, const __u32 mode);
55218+int gr_check_protected_task(const struct task_struct *task);
55219+__u32 to_gr_audit(const __u32 reqmode);
55220+int gr_set_acls(const int type);
55221+int gr_apply_subject_to_task(struct task_struct *task);
55222+int gr_acl_is_enabled(void);
55223+char gr_roletype_to_char(void);
55224+
55225+void gr_handle_alertkill(struct task_struct *task);
55226+char *gr_to_filename(const struct dentry *dentry,
55227+ const struct vfsmount *mnt);
55228+char *gr_to_filename1(const struct dentry *dentry,
55229+ const struct vfsmount *mnt);
55230+char *gr_to_filename2(const struct dentry *dentry,
55231+ const struct vfsmount *mnt);
55232+char *gr_to_filename3(const struct dentry *dentry,
55233+ const struct vfsmount *mnt);
55234+
55235+extern int grsec_enable_harden_ptrace;
55236+extern int grsec_enable_link;
55237+extern int grsec_enable_fifo;
55238+extern int grsec_enable_execve;
55239+extern int grsec_enable_shm;
55240+extern int grsec_enable_execlog;
55241+extern int grsec_enable_signal;
55242+extern int grsec_enable_audit_ptrace;
55243+extern int grsec_enable_forkfail;
55244+extern int grsec_enable_time;
55245+extern int grsec_enable_rofs;
55246+extern int grsec_enable_chroot_shmat;
55247+extern int grsec_enable_chroot_mount;
55248+extern int grsec_enable_chroot_double;
55249+extern int grsec_enable_chroot_pivot;
55250+extern int grsec_enable_chroot_chdir;
55251+extern int grsec_enable_chroot_chmod;
55252+extern int grsec_enable_chroot_mknod;
55253+extern int grsec_enable_chroot_fchdir;
55254+extern int grsec_enable_chroot_nice;
55255+extern int grsec_enable_chroot_execlog;
55256+extern int grsec_enable_chroot_caps;
55257+extern int grsec_enable_chroot_sysctl;
55258+extern int grsec_enable_chroot_unix;
55259+extern int grsec_enable_tpe;
55260+extern int grsec_tpe_gid;
55261+extern int grsec_enable_tpe_all;
55262+extern int grsec_enable_tpe_invert;
55263+extern int grsec_enable_socket_all;
55264+extern int grsec_socket_all_gid;
55265+extern int grsec_enable_socket_client;
55266+extern int grsec_socket_client_gid;
55267+extern int grsec_enable_socket_server;
55268+extern int grsec_socket_server_gid;
55269+extern int grsec_audit_gid;
55270+extern int grsec_enable_group;
55271+extern int grsec_enable_audit_textrel;
55272+extern int grsec_enable_log_rwxmaps;
55273+extern int grsec_enable_mount;
55274+extern int grsec_enable_chdir;
55275+extern int grsec_resource_logging;
55276+extern int grsec_enable_blackhole;
55277+extern int grsec_lastack_retries;
55278+extern int grsec_enable_brute;
55279+extern int grsec_lock;
55280+
55281+extern spinlock_t grsec_alert_lock;
55282+extern unsigned long grsec_alert_wtime;
55283+extern unsigned long grsec_alert_fyet;
55284+
55285+extern spinlock_t grsec_audit_lock;
55286+
55287+extern rwlock_t grsec_exec_file_lock;
55288+
55289+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
55290+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
55291+ (tsk)->exec_file->f_vfsmnt) : "/")
55292+
55293+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
55294+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
55295+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
55296+
55297+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
55298+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
55299+ (tsk)->exec_file->f_vfsmnt) : "/")
55300+
55301+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
55302+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
55303+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
55304+
55305+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
55306+
55307+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
55308+
55309+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
55310+ (task)->pid, (cred)->uid, \
55311+ (cred)->euid, (cred)->gid, (cred)->egid, \
55312+ gr_parent_task_fullpath(task), \
55313+ (task)->real_parent->comm, (task)->real_parent->pid, \
55314+ (pcred)->uid, (pcred)->euid, \
55315+ (pcred)->gid, (pcred)->egid
55316+
55317+#define GR_CHROOT_CAPS {{ \
55318+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
55319+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
55320+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
55321+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
55322+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
55323+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
55324+
55325+#define security_learn(normal_msg,args...) \
55326+({ \
55327+ read_lock(&grsec_exec_file_lock); \
55328+ gr_add_learn_entry(normal_msg "\n", ## args); \
55329+ read_unlock(&grsec_exec_file_lock); \
55330+})
55331+
55332+enum {
55333+ GR_DO_AUDIT,
55334+ GR_DONT_AUDIT,
55335+ /* used for non-audit messages that we shouldn't kill the task on */
55336+ GR_DONT_AUDIT_GOOD
55337+};
55338+
55339+enum {
55340+ GR_TTYSNIFF,
55341+ GR_RBAC,
55342+ GR_RBAC_STR,
55343+ GR_STR_RBAC,
55344+ GR_RBAC_MODE2,
55345+ GR_RBAC_MODE3,
55346+ GR_FILENAME,
55347+ GR_SYSCTL_HIDDEN,
55348+ GR_NOARGS,
55349+ GR_ONE_INT,
55350+ GR_ONE_INT_TWO_STR,
55351+ GR_ONE_STR,
55352+ GR_STR_INT,
55353+ GR_TWO_STR_INT,
55354+ GR_TWO_INT,
55355+ GR_TWO_U64,
55356+ GR_THREE_INT,
55357+ GR_FIVE_INT_TWO_STR,
55358+ GR_TWO_STR,
55359+ GR_THREE_STR,
55360+ GR_FOUR_STR,
55361+ GR_STR_FILENAME,
55362+ GR_FILENAME_STR,
55363+ GR_FILENAME_TWO_INT,
55364+ GR_FILENAME_TWO_INT_STR,
55365+ GR_TEXTREL,
55366+ GR_PTRACE,
55367+ GR_RESOURCE,
55368+ GR_CAP,
55369+ GR_SIG,
55370+ GR_SIG2,
55371+ GR_CRASH1,
55372+ GR_CRASH2,
55373+ GR_PSACCT,
55374+ GR_RWXMAP
55375+};
55376+
55377+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
55378+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
55379+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
55380+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
55381+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
55382+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
55383+#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)
55384+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
55385+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
55386+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
55387+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
55388+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
55389+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
55390+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
55391+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
55392+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
55393+#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)
55394+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
55395+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
55396+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
55397+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
55398+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
55399+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
55400+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
55401+#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)
55402+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
55403+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
55404+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
55405+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
55406+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
55407+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
55408+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
55409+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
55410+#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)
55411+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
55412+
55413+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
55414+
55415+#endif
55416+
55417+#endif
55418diff -urNp linux-3.0.4/include/linux/grmsg.h linux-3.0.4/include/linux/grmsg.h
55419--- linux-3.0.4/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
55420+++ linux-3.0.4/include/linux/grmsg.h 2011-08-25 17:27:26.000000000 -0400
55421@@ -0,0 +1,107 @@
55422+#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"
55423+#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"
55424+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
55425+#define GR_STOPMOD_MSG "denied modification of module state by "
55426+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
55427+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
55428+#define GR_IOPERM_MSG "denied use of ioperm() by "
55429+#define GR_IOPL_MSG "denied use of iopl() by "
55430+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
55431+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
55432+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
55433+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
55434+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
55435+#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"
55436+#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"
55437+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
55438+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
55439+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
55440+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
55441+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
55442+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
55443+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
55444+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
55445+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
55446+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
55447+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
55448+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
55449+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
55450+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
55451+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
55452+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
55453+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
55454+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
55455+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
55456+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
55457+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
55458+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
55459+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
55460+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
55461+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
55462+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
55463+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
55464+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
55465+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
55466+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
55467+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
55468+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
55469+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
55470+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
55471+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
55472+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
55473+#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"
55474+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
55475+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
55476+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
55477+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
55478+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
55479+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
55480+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
55481+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
55482+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
55483+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
55484+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
55485+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
55486+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
55487+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
55488+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
55489+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
55490+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
55491+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
55492+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
55493+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
55494+#define GR_FAILFORK_MSG "failed fork with errno %s by "
55495+#define GR_NICE_CHROOT_MSG "denied priority change by "
55496+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
55497+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
55498+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
55499+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
55500+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
55501+#define GR_TIME_MSG "time set by "
55502+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
55503+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
55504+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
55505+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
55506+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
55507+#define GR_BIND_MSG "denied bind() by "
55508+#define GR_CONNECT_MSG "denied connect() by "
55509+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
55510+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
55511+#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"
55512+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
55513+#define GR_CAP_ACL_MSG "use of %s denied for "
55514+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
55515+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
55516+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
55517+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
55518+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
55519+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
55520+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
55521+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
55522+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
55523+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
55524+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
55525+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
55526+#define GR_VM86_MSG "denied use of vm86 by "
55527+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
55528+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
55529diff -urNp linux-3.0.4/include/linux/grsecurity.h linux-3.0.4/include/linux/grsecurity.h
55530--- linux-3.0.4/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
55531+++ linux-3.0.4/include/linux/grsecurity.h 2011-08-25 17:27:36.000000000 -0400
55532@@ -0,0 +1,227 @@
55533+#ifndef GR_SECURITY_H
55534+#define GR_SECURITY_H
55535+#include <linux/fs.h>
55536+#include <linux/fs_struct.h>
55537+#include <linux/binfmts.h>
55538+#include <linux/gracl.h>
55539+
55540+/* notify of brain-dead configs */
55541+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55542+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
55543+#endif
55544+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
55545+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
55546+#endif
55547+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
55548+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
55549+#endif
55550+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
55551+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
55552+#endif
55553+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
55554+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
55555+#endif
55556+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
55557+#error "CONFIG_PAX enabled, but no PaX options are enabled."
55558+#endif
55559+
55560+#include <linux/compat.h>
55561+
55562+struct user_arg_ptr {
55563+#ifdef CONFIG_COMPAT
55564+ bool is_compat;
55565+#endif
55566+ union {
55567+ const char __user *const __user *native;
55568+#ifdef CONFIG_COMPAT
55569+ compat_uptr_t __user *compat;
55570+#endif
55571+ } ptr;
55572+};
55573+
55574+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
55575+void gr_handle_brute_check(void);
55576+void gr_handle_kernel_exploit(void);
55577+int gr_process_user_ban(void);
55578+
55579+char gr_roletype_to_char(void);
55580+
55581+int gr_acl_enable_at_secure(void);
55582+
55583+int gr_check_user_change(int real, int effective, int fs);
55584+int gr_check_group_change(int real, int effective, int fs);
55585+
55586+void gr_del_task_from_ip_table(struct task_struct *p);
55587+
55588+int gr_pid_is_chrooted(struct task_struct *p);
55589+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
55590+int gr_handle_chroot_nice(void);
55591+int gr_handle_chroot_sysctl(const int op);
55592+int gr_handle_chroot_setpriority(struct task_struct *p,
55593+ const int niceval);
55594+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
55595+int gr_handle_chroot_chroot(const struct dentry *dentry,
55596+ const struct vfsmount *mnt);
55597+int gr_handle_chroot_caps(struct path *path);
55598+void gr_handle_chroot_chdir(struct path *path);
55599+int gr_handle_chroot_chmod(const struct dentry *dentry,
55600+ const struct vfsmount *mnt, const int mode);
55601+int gr_handle_chroot_mknod(const struct dentry *dentry,
55602+ const struct vfsmount *mnt, const int mode);
55603+int gr_handle_chroot_mount(const struct dentry *dentry,
55604+ const struct vfsmount *mnt,
55605+ const char *dev_name);
55606+int gr_handle_chroot_pivot(void);
55607+int gr_handle_chroot_unix(const pid_t pid);
55608+
55609+int gr_handle_rawio(const struct inode *inode);
55610+
55611+void gr_handle_ioperm(void);
55612+void gr_handle_iopl(void);
55613+
55614+int gr_tpe_allow(const struct file *file);
55615+
55616+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
55617+void gr_clear_chroot_entries(struct task_struct *task);
55618+
55619+void gr_log_forkfail(const int retval);
55620+void gr_log_timechange(void);
55621+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
55622+void gr_log_chdir(const struct dentry *dentry,
55623+ const struct vfsmount *mnt);
55624+void gr_log_chroot_exec(const struct dentry *dentry,
55625+ const struct vfsmount *mnt);
55626+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
55627+void gr_log_remount(const char *devname, const int retval);
55628+void gr_log_unmount(const char *devname, const int retval);
55629+void gr_log_mount(const char *from, const char *to, const int retval);
55630+void gr_log_textrel(struct vm_area_struct *vma);
55631+void gr_log_rwxmmap(struct file *file);
55632+void gr_log_rwxmprotect(struct file *file);
55633+
55634+int gr_handle_follow_link(const struct inode *parent,
55635+ const struct inode *inode,
55636+ const struct dentry *dentry,
55637+ const struct vfsmount *mnt);
55638+int gr_handle_fifo(const struct dentry *dentry,
55639+ const struct vfsmount *mnt,
55640+ const struct dentry *dir, const int flag,
55641+ const int acc_mode);
55642+int gr_handle_hardlink(const struct dentry *dentry,
55643+ const struct vfsmount *mnt,
55644+ struct inode *inode,
55645+ const int mode, const char *to);
55646+
55647+int gr_is_capable(const int cap);
55648+int gr_is_capable_nolog(const int cap);
55649+void gr_learn_resource(const struct task_struct *task, const int limit,
55650+ const unsigned long wanted, const int gt);
55651+void gr_copy_label(struct task_struct *tsk);
55652+void gr_handle_crash(struct task_struct *task, const int sig);
55653+int gr_handle_signal(const struct task_struct *p, const int sig);
55654+int gr_check_crash_uid(const uid_t uid);
55655+int gr_check_protected_task(const struct task_struct *task);
55656+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
55657+int gr_acl_handle_mmap(const struct file *file,
55658+ const unsigned long prot);
55659+int gr_acl_handle_mprotect(const struct file *file,
55660+ const unsigned long prot);
55661+int gr_check_hidden_task(const struct task_struct *tsk);
55662+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
55663+ const struct vfsmount *mnt);
55664+__u32 gr_acl_handle_utime(const struct dentry *dentry,
55665+ const struct vfsmount *mnt);
55666+__u32 gr_acl_handle_access(const struct dentry *dentry,
55667+ const struct vfsmount *mnt, const int fmode);
55668+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
55669+ const struct vfsmount *mnt, mode_t mode);
55670+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
55671+ const struct vfsmount *mnt, mode_t mode);
55672+__u32 gr_acl_handle_chown(const struct dentry *dentry,
55673+ const struct vfsmount *mnt);
55674+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
55675+ const struct vfsmount *mnt);
55676+int gr_handle_ptrace(struct task_struct *task, const long request);
55677+int gr_handle_proc_ptrace(struct task_struct *task);
55678+__u32 gr_acl_handle_execve(const struct dentry *dentry,
55679+ const struct vfsmount *mnt);
55680+int gr_check_crash_exec(const struct file *filp);
55681+int gr_acl_is_enabled(void);
55682+void gr_set_kernel_label(struct task_struct *task);
55683+void gr_set_role_label(struct task_struct *task, const uid_t uid,
55684+ const gid_t gid);
55685+int gr_set_proc_label(const struct dentry *dentry,
55686+ const struct vfsmount *mnt,
55687+ const int unsafe_share);
55688+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
55689+ const struct vfsmount *mnt);
55690+__u32 gr_acl_handle_open(const struct dentry *dentry,
55691+ const struct vfsmount *mnt, const int fmode);
55692+__u32 gr_acl_handle_creat(const struct dentry *dentry,
55693+ const struct dentry *p_dentry,
55694+ const struct vfsmount *p_mnt, const int fmode,
55695+ const int imode);
55696+void gr_handle_create(const struct dentry *dentry,
55697+ const struct vfsmount *mnt);
55698+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
55699+ const struct dentry *parent_dentry,
55700+ const struct vfsmount *parent_mnt,
55701+ const int mode);
55702+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
55703+ const struct dentry *parent_dentry,
55704+ const struct vfsmount *parent_mnt);
55705+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
55706+ const struct vfsmount *mnt);
55707+void gr_handle_delete(const ino_t ino, const dev_t dev);
55708+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
55709+ const struct vfsmount *mnt);
55710+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
55711+ const struct dentry *parent_dentry,
55712+ const struct vfsmount *parent_mnt,
55713+ const char *from);
55714+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
55715+ const struct dentry *parent_dentry,
55716+ const struct vfsmount *parent_mnt,
55717+ const struct dentry *old_dentry,
55718+ const struct vfsmount *old_mnt, const char *to);
55719+int gr_acl_handle_rename(struct dentry *new_dentry,
55720+ struct dentry *parent_dentry,
55721+ const struct vfsmount *parent_mnt,
55722+ struct dentry *old_dentry,
55723+ struct inode *old_parent_inode,
55724+ struct vfsmount *old_mnt, const char *newname);
55725+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55726+ struct dentry *old_dentry,
55727+ struct dentry *new_dentry,
55728+ struct vfsmount *mnt, const __u8 replace);
55729+__u32 gr_check_link(const struct dentry *new_dentry,
55730+ const struct dentry *parent_dentry,
55731+ const struct vfsmount *parent_mnt,
55732+ const struct dentry *old_dentry,
55733+ const struct vfsmount *old_mnt);
55734+int gr_acl_handle_filldir(const struct file *file, const char *name,
55735+ const unsigned int namelen, const ino_t ino);
55736+
55737+__u32 gr_acl_handle_unix(const struct dentry *dentry,
55738+ const struct vfsmount *mnt);
55739+void gr_acl_handle_exit(void);
55740+void gr_acl_handle_psacct(struct task_struct *task, const long code);
55741+int gr_acl_handle_procpidmem(const struct task_struct *task);
55742+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
55743+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
55744+void gr_audit_ptrace(struct task_struct *task);
55745+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
55746+
55747+#ifdef CONFIG_GRKERNSEC
55748+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
55749+void gr_handle_vm86(void);
55750+void gr_handle_mem_readwrite(u64 from, u64 to);
55751+
55752+extern int grsec_enable_dmesg;
55753+extern int grsec_disable_privio;
55754+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55755+extern int grsec_enable_chroot_findtask;
55756+#endif
55757+#endif
55758+
55759+#endif
55760diff -urNp linux-3.0.4/include/linux/grsock.h linux-3.0.4/include/linux/grsock.h
55761--- linux-3.0.4/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
55762+++ linux-3.0.4/include/linux/grsock.h 2011-08-23 21:48:14.000000000 -0400
55763@@ -0,0 +1,19 @@
55764+#ifndef __GRSOCK_H
55765+#define __GRSOCK_H
55766+
55767+extern void gr_attach_curr_ip(const struct sock *sk);
55768+extern int gr_handle_sock_all(const int family, const int type,
55769+ const int protocol);
55770+extern int gr_handle_sock_server(const struct sockaddr *sck);
55771+extern int gr_handle_sock_server_other(const struct sock *sck);
55772+extern int gr_handle_sock_client(const struct sockaddr *sck);
55773+extern int gr_search_connect(struct socket * sock,
55774+ struct sockaddr_in * addr);
55775+extern int gr_search_bind(struct socket * sock,
55776+ struct sockaddr_in * addr);
55777+extern int gr_search_listen(struct socket * sock);
55778+extern int gr_search_accept(struct socket * sock);
55779+extern int gr_search_socket(const int domain, const int type,
55780+ const int protocol);
55781+
55782+#endif
55783diff -urNp linux-3.0.4/include/linux/hid.h linux-3.0.4/include/linux/hid.h
55784--- linux-3.0.4/include/linux/hid.h 2011-07-21 22:17:23.000000000 -0400
55785+++ linux-3.0.4/include/linux/hid.h 2011-08-23 21:47:56.000000000 -0400
55786@@ -675,7 +675,7 @@ struct hid_ll_driver {
55787 unsigned int code, int value);
55788
55789 int (*parse)(struct hid_device *hdev);
55790-};
55791+} __no_const;
55792
55793 #define PM_HINT_FULLON 1<<5
55794 #define PM_HINT_NORMAL 1<<1
55795diff -urNp linux-3.0.4/include/linux/highmem.h linux-3.0.4/include/linux/highmem.h
55796--- linux-3.0.4/include/linux/highmem.h 2011-07-21 22:17:23.000000000 -0400
55797+++ linux-3.0.4/include/linux/highmem.h 2011-08-23 21:47:56.000000000 -0400
55798@@ -185,6 +185,18 @@ static inline void clear_highpage(struct
55799 kunmap_atomic(kaddr, KM_USER0);
55800 }
55801
55802+static inline void sanitize_highpage(struct page *page)
55803+{
55804+ void *kaddr;
55805+ unsigned long flags;
55806+
55807+ local_irq_save(flags);
55808+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
55809+ clear_page(kaddr);
55810+ kunmap_atomic(kaddr, KM_CLEARPAGE);
55811+ local_irq_restore(flags);
55812+}
55813+
55814 static inline void zero_user_segments(struct page *page,
55815 unsigned start1, unsigned end1,
55816 unsigned start2, unsigned end2)
55817diff -urNp linux-3.0.4/include/linux/i2c.h linux-3.0.4/include/linux/i2c.h
55818--- linux-3.0.4/include/linux/i2c.h 2011-07-21 22:17:23.000000000 -0400
55819+++ linux-3.0.4/include/linux/i2c.h 2011-08-23 21:47:56.000000000 -0400
55820@@ -346,6 +346,7 @@ struct i2c_algorithm {
55821 /* To determine what the adapter supports */
55822 u32 (*functionality) (struct i2c_adapter *);
55823 };
55824+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
55825
55826 /*
55827 * i2c_adapter is the structure used to identify a physical i2c bus along
55828diff -urNp linux-3.0.4/include/linux/i2o.h linux-3.0.4/include/linux/i2o.h
55829--- linux-3.0.4/include/linux/i2o.h 2011-07-21 22:17:23.000000000 -0400
55830+++ linux-3.0.4/include/linux/i2o.h 2011-08-23 21:47:56.000000000 -0400
55831@@ -564,7 +564,7 @@ struct i2o_controller {
55832 struct i2o_device *exec; /* Executive */
55833 #if BITS_PER_LONG == 64
55834 spinlock_t context_list_lock; /* lock for context_list */
55835- atomic_t context_list_counter; /* needed for unique contexts */
55836+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
55837 struct list_head context_list; /* list of context id's
55838 and pointers */
55839 #endif
55840diff -urNp linux-3.0.4/include/linux/init.h linux-3.0.4/include/linux/init.h
55841--- linux-3.0.4/include/linux/init.h 2011-07-21 22:17:23.000000000 -0400
55842+++ linux-3.0.4/include/linux/init.h 2011-08-23 21:47:56.000000000 -0400
55843@@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
55844
55845 /* Each module must use one module_init(). */
55846 #define module_init(initfn) \
55847- static inline initcall_t __inittest(void) \
55848+ static inline __used initcall_t __inittest(void) \
55849 { return initfn; } \
55850 int init_module(void) __attribute__((alias(#initfn)));
55851
55852 /* This is only required if you want to be unloadable. */
55853 #define module_exit(exitfn) \
55854- static inline exitcall_t __exittest(void) \
55855+ static inline __used exitcall_t __exittest(void) \
55856 { return exitfn; } \
55857 void cleanup_module(void) __attribute__((alias(#exitfn)));
55858
55859diff -urNp linux-3.0.4/include/linux/init_task.h linux-3.0.4/include/linux/init_task.h
55860--- linux-3.0.4/include/linux/init_task.h 2011-07-21 22:17:23.000000000 -0400
55861+++ linux-3.0.4/include/linux/init_task.h 2011-08-23 21:47:56.000000000 -0400
55862@@ -126,6 +126,12 @@ extern struct cred init_cred;
55863 # define INIT_PERF_EVENTS(tsk)
55864 #endif
55865
55866+#ifdef CONFIG_X86
55867+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
55868+#else
55869+#define INIT_TASK_THREAD_INFO
55870+#endif
55871+
55872 /*
55873 * INIT_TASK is used to set up the first task table, touch at
55874 * your own risk!. Base=0, limit=0x1fffff (=2MB)
55875@@ -164,6 +170,7 @@ extern struct cred init_cred;
55876 RCU_INIT_POINTER(.cred, &init_cred), \
55877 .comm = "swapper", \
55878 .thread = INIT_THREAD, \
55879+ INIT_TASK_THREAD_INFO \
55880 .fs = &init_fs, \
55881 .files = &init_files, \
55882 .signal = &init_signals, \
55883diff -urNp linux-3.0.4/include/linux/intel-iommu.h linux-3.0.4/include/linux/intel-iommu.h
55884--- linux-3.0.4/include/linux/intel-iommu.h 2011-07-21 22:17:23.000000000 -0400
55885+++ linux-3.0.4/include/linux/intel-iommu.h 2011-08-23 21:47:56.000000000 -0400
55886@@ -296,7 +296,7 @@ struct iommu_flush {
55887 u8 fm, u64 type);
55888 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
55889 unsigned int size_order, u64 type);
55890-};
55891+} __no_const;
55892
55893 enum {
55894 SR_DMAR_FECTL_REG,
55895diff -urNp linux-3.0.4/include/linux/interrupt.h linux-3.0.4/include/linux/interrupt.h
55896--- linux-3.0.4/include/linux/interrupt.h 2011-07-21 22:17:23.000000000 -0400
55897+++ linux-3.0.4/include/linux/interrupt.h 2011-08-23 21:47:56.000000000 -0400
55898@@ -422,7 +422,7 @@ enum
55899 /* map softirq index to softirq name. update 'softirq_to_name' in
55900 * kernel/softirq.c when adding a new softirq.
55901 */
55902-extern char *softirq_to_name[NR_SOFTIRQS];
55903+extern const char * const softirq_to_name[NR_SOFTIRQS];
55904
55905 /* softirq mask and active fields moved to irq_cpustat_t in
55906 * asm/hardirq.h to get better cache usage. KAO
55907@@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
55908
55909 struct softirq_action
55910 {
55911- void (*action)(struct softirq_action *);
55912+ void (*action)(void);
55913 };
55914
55915 asmlinkage void do_softirq(void);
55916 asmlinkage void __do_softirq(void);
55917-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
55918+extern void open_softirq(int nr, void (*action)(void));
55919 extern void softirq_init(void);
55920 static inline void __raise_softirq_irqoff(unsigned int nr)
55921 {
55922diff -urNp linux-3.0.4/include/linux/kallsyms.h linux-3.0.4/include/linux/kallsyms.h
55923--- linux-3.0.4/include/linux/kallsyms.h 2011-07-21 22:17:23.000000000 -0400
55924+++ linux-3.0.4/include/linux/kallsyms.h 2011-08-23 21:48:14.000000000 -0400
55925@@ -15,7 +15,8 @@
55926
55927 struct module;
55928
55929-#ifdef CONFIG_KALLSYMS
55930+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
55931+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55932 /* Lookup the address for a symbol. Returns 0 if not found. */
55933 unsigned long kallsyms_lookup_name(const char *name);
55934
55935@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
55936 /* Stupid that this does nothing, but I didn't create this mess. */
55937 #define __print_symbol(fmt, addr)
55938 #endif /*CONFIG_KALLSYMS*/
55939+#else /* when included by kallsyms.c, vsnprintf.c, or
55940+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
55941+extern void __print_symbol(const char *fmt, unsigned long address);
55942+extern int sprint_backtrace(char *buffer, unsigned long address);
55943+extern int sprint_symbol(char *buffer, unsigned long address);
55944+const char *kallsyms_lookup(unsigned long addr,
55945+ unsigned long *symbolsize,
55946+ unsigned long *offset,
55947+ char **modname, char *namebuf);
55948+#endif
55949
55950 /* This macro allows us to keep printk typechecking */
55951 static void __check_printsym_format(const char *fmt, ...)
55952diff -urNp linux-3.0.4/include/linux/kgdb.h linux-3.0.4/include/linux/kgdb.h
55953--- linux-3.0.4/include/linux/kgdb.h 2011-07-21 22:17:23.000000000 -0400
55954+++ linux-3.0.4/include/linux/kgdb.h 2011-08-26 19:49:56.000000000 -0400
55955@@ -53,7 +53,7 @@ extern int kgdb_connected;
55956 extern int kgdb_io_module_registered;
55957
55958 extern atomic_t kgdb_setting_breakpoint;
55959-extern atomic_t kgdb_cpu_doing_single_step;
55960+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
55961
55962 extern struct task_struct *kgdb_usethread;
55963 extern struct task_struct *kgdb_contthread;
55964@@ -251,7 +251,7 @@ struct kgdb_arch {
55965 void (*disable_hw_break)(struct pt_regs *regs);
55966 void (*remove_all_hw_break)(void);
55967 void (*correct_hw_break)(void);
55968-};
55969+} __do_const;
55970
55971 /**
55972 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
55973@@ -276,7 +276,7 @@ struct kgdb_io {
55974 void (*pre_exception) (void);
55975 void (*post_exception) (void);
55976 int is_console;
55977-};
55978+} __do_const;
55979
55980 extern struct kgdb_arch arch_kgdb_ops;
55981
55982diff -urNp linux-3.0.4/include/linux/kmod.h linux-3.0.4/include/linux/kmod.h
55983--- linux-3.0.4/include/linux/kmod.h 2011-07-21 22:17:23.000000000 -0400
55984+++ linux-3.0.4/include/linux/kmod.h 2011-08-23 21:48:14.000000000 -0400
55985@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysc
55986 * usually useless though. */
55987 extern int __request_module(bool wait, const char *name, ...) \
55988 __attribute__((format(printf, 2, 3)));
55989+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
55990+ __attribute__((format(printf, 3, 4)));
55991 #define request_module(mod...) __request_module(true, mod)
55992 #define request_module_nowait(mod...) __request_module(false, mod)
55993 #define try_then_request_module(x, mod...) \
55994diff -urNp linux-3.0.4/include/linux/kvm_host.h linux-3.0.4/include/linux/kvm_host.h
55995--- linux-3.0.4/include/linux/kvm_host.h 2011-07-21 22:17:23.000000000 -0400
55996+++ linux-3.0.4/include/linux/kvm_host.h 2011-08-23 21:47:56.000000000 -0400
55997@@ -307,7 +307,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
55998 void vcpu_load(struct kvm_vcpu *vcpu);
55999 void vcpu_put(struct kvm_vcpu *vcpu);
56000
56001-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
56002+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
56003 struct module *module);
56004 void kvm_exit(void);
56005
56006@@ -446,7 +446,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
56007 struct kvm_guest_debug *dbg);
56008 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
56009
56010-int kvm_arch_init(void *opaque);
56011+int kvm_arch_init(const void *opaque);
56012 void kvm_arch_exit(void);
56013
56014 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
56015diff -urNp linux-3.0.4/include/linux/libata.h linux-3.0.4/include/linux/libata.h
56016--- linux-3.0.4/include/linux/libata.h 2011-07-21 22:17:23.000000000 -0400
56017+++ linux-3.0.4/include/linux/libata.h 2011-08-26 19:49:56.000000000 -0400
56018@@ -899,7 +899,7 @@ struct ata_port_operations {
56019 * fields must be pointers.
56020 */
56021 const struct ata_port_operations *inherits;
56022-};
56023+} __do_const;
56024
56025 struct ata_port_info {
56026 unsigned long flags;
56027diff -urNp linux-3.0.4/include/linux/mca.h linux-3.0.4/include/linux/mca.h
56028--- linux-3.0.4/include/linux/mca.h 2011-07-21 22:17:23.000000000 -0400
56029+++ linux-3.0.4/include/linux/mca.h 2011-08-23 21:47:56.000000000 -0400
56030@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
56031 int region);
56032 void * (*mca_transform_memory)(struct mca_device *,
56033 void *memory);
56034-};
56035+} __no_const;
56036
56037 struct mca_bus {
56038 u64 default_dma_mask;
56039diff -urNp linux-3.0.4/include/linux/memory.h linux-3.0.4/include/linux/memory.h
56040--- linux-3.0.4/include/linux/memory.h 2011-07-21 22:17:23.000000000 -0400
56041+++ linux-3.0.4/include/linux/memory.h 2011-08-23 21:47:56.000000000 -0400
56042@@ -144,7 +144,7 @@ struct memory_accessor {
56043 size_t count);
56044 ssize_t (*write)(struct memory_accessor *, const char *buf,
56045 off_t offset, size_t count);
56046-};
56047+} __no_const;
56048
56049 /*
56050 * Kernel text modification mutex, used for code patching. Users of this lock
56051diff -urNp linux-3.0.4/include/linux/mfd/abx500.h linux-3.0.4/include/linux/mfd/abx500.h
56052--- linux-3.0.4/include/linux/mfd/abx500.h 2011-07-21 22:17:23.000000000 -0400
56053+++ linux-3.0.4/include/linux/mfd/abx500.h 2011-08-23 21:47:56.000000000 -0400
56054@@ -234,6 +234,7 @@ struct abx500_ops {
56055 int (*event_registers_startup_state_get) (struct device *, u8 *);
56056 int (*startup_irq_enabled) (struct device *, unsigned int);
56057 };
56058+typedef struct abx500_ops __no_const abx500_ops_no_const;
56059
56060 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
56061 void abx500_remove_ops(struct device *dev);
56062diff -urNp linux-3.0.4/include/linux/mm.h linux-3.0.4/include/linux/mm.h
56063--- linux-3.0.4/include/linux/mm.h 2011-08-23 21:44:40.000000000 -0400
56064+++ linux-3.0.4/include/linux/mm.h 2011-08-23 21:47:56.000000000 -0400
56065@@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
56066
56067 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
56068 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
56069+
56070+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
56071+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
56072+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
56073+#else
56074 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
56075+#endif
56076+
56077 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
56078 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
56079
56080@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
56081 int set_page_dirty_lock(struct page *page);
56082 int clear_page_dirty_for_io(struct page *page);
56083
56084-/* Is the vma a continuation of the stack vma above it? */
56085-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
56086-{
56087- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
56088-}
56089-
56090-static inline int stack_guard_page_start(struct vm_area_struct *vma,
56091- unsigned long addr)
56092-{
56093- return (vma->vm_flags & VM_GROWSDOWN) &&
56094- (vma->vm_start == addr) &&
56095- !vma_growsdown(vma->vm_prev, addr);
56096-}
56097-
56098-/* Is the vma a continuation of the stack vma below it? */
56099-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
56100-{
56101- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
56102-}
56103-
56104-static inline int stack_guard_page_end(struct vm_area_struct *vma,
56105- unsigned long addr)
56106-{
56107- return (vma->vm_flags & VM_GROWSUP) &&
56108- (vma->vm_end == addr) &&
56109- !vma_growsup(vma->vm_next, addr);
56110-}
56111-
56112 extern unsigned long move_page_tables(struct vm_area_struct *vma,
56113 unsigned long old_addr, struct vm_area_struct *new_vma,
56114 unsigned long new_addr, unsigned long len);
56115@@ -1169,6 +1148,15 @@ struct shrinker {
56116 extern void register_shrinker(struct shrinker *);
56117 extern void unregister_shrinker(struct shrinker *);
56118
56119+#ifdef CONFIG_MMU
56120+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
56121+#else
56122+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
56123+{
56124+ return __pgprot(0);
56125+}
56126+#endif
56127+
56128 int vma_wants_writenotify(struct vm_area_struct *vma);
56129
56130 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
56131@@ -1452,6 +1440,7 @@ out:
56132 }
56133
56134 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
56135+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
56136
56137 extern unsigned long do_brk(unsigned long, unsigned long);
56138
56139@@ -1510,6 +1499,10 @@ extern struct vm_area_struct * find_vma(
56140 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
56141 struct vm_area_struct **pprev);
56142
56143+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
56144+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
56145+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
56146+
56147 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
56148 NULL if none. Assume start_addr < end_addr. */
56149 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
56150@@ -1526,15 +1519,6 @@ static inline unsigned long vma_pages(st
56151 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
56152 }
56153
56154-#ifdef CONFIG_MMU
56155-pgprot_t vm_get_page_prot(unsigned long vm_flags);
56156-#else
56157-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
56158-{
56159- return __pgprot(0);
56160-}
56161-#endif
56162-
56163 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
56164 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
56165 unsigned long pfn, unsigned long size, pgprot_t);
56166@@ -1647,7 +1631,7 @@ extern int unpoison_memory(unsigned long
56167 extern int sysctl_memory_failure_early_kill;
56168 extern int sysctl_memory_failure_recovery;
56169 extern void shake_page(struct page *p, int access);
56170-extern atomic_long_t mce_bad_pages;
56171+extern atomic_long_unchecked_t mce_bad_pages;
56172 extern int soft_offline_page(struct page *page, int flags);
56173
56174 extern void dump_page(struct page *page);
56175@@ -1661,5 +1645,11 @@ extern void copy_user_huge_page(struct p
56176 unsigned int pages_per_huge_page);
56177 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
56178
56179+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56180+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
56181+#else
56182+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
56183+#endif
56184+
56185 #endif /* __KERNEL__ */
56186 #endif /* _LINUX_MM_H */
56187diff -urNp linux-3.0.4/include/linux/mm_types.h linux-3.0.4/include/linux/mm_types.h
56188--- linux-3.0.4/include/linux/mm_types.h 2011-07-21 22:17:23.000000000 -0400
56189+++ linux-3.0.4/include/linux/mm_types.h 2011-08-23 21:47:56.000000000 -0400
56190@@ -184,6 +184,8 @@ struct vm_area_struct {
56191 #ifdef CONFIG_NUMA
56192 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
56193 #endif
56194+
56195+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
56196 };
56197
56198 struct core_thread {
56199@@ -316,6 +318,24 @@ struct mm_struct {
56200 #ifdef CONFIG_CPUMASK_OFFSTACK
56201 struct cpumask cpumask_allocation;
56202 #endif
56203+
56204+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56205+ unsigned long pax_flags;
56206+#endif
56207+
56208+#ifdef CONFIG_PAX_DLRESOLVE
56209+ unsigned long call_dl_resolve;
56210+#endif
56211+
56212+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56213+ unsigned long call_syscall;
56214+#endif
56215+
56216+#ifdef CONFIG_PAX_ASLR
56217+ unsigned long delta_mmap; /* randomized offset */
56218+ unsigned long delta_stack; /* randomized offset */
56219+#endif
56220+
56221 };
56222
56223 static inline void mm_init_cpumask(struct mm_struct *mm)
56224diff -urNp linux-3.0.4/include/linux/mmu_notifier.h linux-3.0.4/include/linux/mmu_notifier.h
56225--- linux-3.0.4/include/linux/mmu_notifier.h 2011-07-21 22:17:23.000000000 -0400
56226+++ linux-3.0.4/include/linux/mmu_notifier.h 2011-08-23 21:47:56.000000000 -0400
56227@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
56228 */
56229 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
56230 ({ \
56231- pte_t __pte; \
56232+ pte_t ___pte; \
56233 struct vm_area_struct *___vma = __vma; \
56234 unsigned long ___address = __address; \
56235- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
56236+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
56237 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
56238- __pte; \
56239+ ___pte; \
56240 })
56241
56242 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
56243diff -urNp linux-3.0.4/include/linux/mmzone.h linux-3.0.4/include/linux/mmzone.h
56244--- linux-3.0.4/include/linux/mmzone.h 2011-07-21 22:17:23.000000000 -0400
56245+++ linux-3.0.4/include/linux/mmzone.h 2011-08-23 21:47:56.000000000 -0400
56246@@ -350,7 +350,7 @@ struct zone {
56247 unsigned long flags; /* zone flags, see below */
56248
56249 /* Zone statistics */
56250- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
56251+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
56252
56253 /*
56254 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
56255diff -urNp linux-3.0.4/include/linux/mod_devicetable.h linux-3.0.4/include/linux/mod_devicetable.h
56256--- linux-3.0.4/include/linux/mod_devicetable.h 2011-07-21 22:17:23.000000000 -0400
56257+++ linux-3.0.4/include/linux/mod_devicetable.h 2011-08-23 21:47:56.000000000 -0400
56258@@ -12,7 +12,7 @@
56259 typedef unsigned long kernel_ulong_t;
56260 #endif
56261
56262-#define PCI_ANY_ID (~0)
56263+#define PCI_ANY_ID ((__u16)~0)
56264
56265 struct pci_device_id {
56266 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
56267@@ -131,7 +131,7 @@ struct usb_device_id {
56268 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
56269 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
56270
56271-#define HID_ANY_ID (~0)
56272+#define HID_ANY_ID (~0U)
56273
56274 struct hid_device_id {
56275 __u16 bus;
56276diff -urNp linux-3.0.4/include/linux/module.h linux-3.0.4/include/linux/module.h
56277--- linux-3.0.4/include/linux/module.h 2011-07-21 22:17:23.000000000 -0400
56278+++ linux-3.0.4/include/linux/module.h 2011-08-23 21:47:56.000000000 -0400
56279@@ -16,6 +16,7 @@
56280 #include <linux/kobject.h>
56281 #include <linux/moduleparam.h>
56282 #include <linux/tracepoint.h>
56283+#include <linux/fs.h>
56284
56285 #include <linux/percpu.h>
56286 #include <asm/module.h>
56287@@ -325,19 +326,16 @@ struct module
56288 int (*init)(void);
56289
56290 /* If this is non-NULL, vfree after init() returns */
56291- void *module_init;
56292+ void *module_init_rx, *module_init_rw;
56293
56294 /* Here is the actual code + data, vfree'd on unload. */
56295- void *module_core;
56296+ void *module_core_rx, *module_core_rw;
56297
56298 /* Here are the sizes of the init and core sections */
56299- unsigned int init_size, core_size;
56300+ unsigned int init_size_rw, core_size_rw;
56301
56302 /* The size of the executable code in each section. */
56303- unsigned int init_text_size, core_text_size;
56304-
56305- /* Size of RO sections of the module (text+rodata) */
56306- unsigned int init_ro_size, core_ro_size;
56307+ unsigned int init_size_rx, core_size_rx;
56308
56309 /* Arch-specific module values */
56310 struct mod_arch_specific arch;
56311@@ -393,6 +391,10 @@ struct module
56312 #ifdef CONFIG_EVENT_TRACING
56313 struct ftrace_event_call **trace_events;
56314 unsigned int num_trace_events;
56315+ struct file_operations trace_id;
56316+ struct file_operations trace_enable;
56317+ struct file_operations trace_format;
56318+ struct file_operations trace_filter;
56319 #endif
56320 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
56321 unsigned int num_ftrace_callsites;
56322@@ -443,16 +445,46 @@ bool is_module_address(unsigned long add
56323 bool is_module_percpu_address(unsigned long addr);
56324 bool is_module_text_address(unsigned long addr);
56325
56326+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
56327+{
56328+
56329+#ifdef CONFIG_PAX_KERNEXEC
56330+ if (ktla_ktva(addr) >= (unsigned long)start &&
56331+ ktla_ktva(addr) < (unsigned long)start + size)
56332+ return 1;
56333+#endif
56334+
56335+ return ((void *)addr >= start && (void *)addr < start + size);
56336+}
56337+
56338+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
56339+{
56340+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
56341+}
56342+
56343+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
56344+{
56345+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
56346+}
56347+
56348+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
56349+{
56350+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
56351+}
56352+
56353+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
56354+{
56355+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
56356+}
56357+
56358 static inline int within_module_core(unsigned long addr, struct module *mod)
56359 {
56360- return (unsigned long)mod->module_core <= addr &&
56361- addr < (unsigned long)mod->module_core + mod->core_size;
56362+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
56363 }
56364
56365 static inline int within_module_init(unsigned long addr, struct module *mod)
56366 {
56367- return (unsigned long)mod->module_init <= addr &&
56368- addr < (unsigned long)mod->module_init + mod->init_size;
56369+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
56370 }
56371
56372 /* Search for module by name: must hold module_mutex. */
56373diff -urNp linux-3.0.4/include/linux/moduleloader.h linux-3.0.4/include/linux/moduleloader.h
56374--- linux-3.0.4/include/linux/moduleloader.h 2011-07-21 22:17:23.000000000 -0400
56375+++ linux-3.0.4/include/linux/moduleloader.h 2011-08-23 21:47:56.000000000 -0400
56376@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
56377 sections. Returns NULL on failure. */
56378 void *module_alloc(unsigned long size);
56379
56380+#ifdef CONFIG_PAX_KERNEXEC
56381+void *module_alloc_exec(unsigned long size);
56382+#else
56383+#define module_alloc_exec(x) module_alloc(x)
56384+#endif
56385+
56386 /* Free memory returned from module_alloc. */
56387 void module_free(struct module *mod, void *module_region);
56388
56389+#ifdef CONFIG_PAX_KERNEXEC
56390+void module_free_exec(struct module *mod, void *module_region);
56391+#else
56392+#define module_free_exec(x, y) module_free((x), (y))
56393+#endif
56394+
56395 /* Apply the given relocation to the (simplified) ELF. Return -error
56396 or 0. */
56397 int apply_relocate(Elf_Shdr *sechdrs,
56398diff -urNp linux-3.0.4/include/linux/moduleparam.h linux-3.0.4/include/linux/moduleparam.h
56399--- linux-3.0.4/include/linux/moduleparam.h 2011-07-21 22:17:23.000000000 -0400
56400+++ linux-3.0.4/include/linux/moduleparam.h 2011-08-23 21:47:56.000000000 -0400
56401@@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
56402 * @len is usually just sizeof(string).
56403 */
56404 #define module_param_string(name, string, len, perm) \
56405- static const struct kparam_string __param_string_##name \
56406+ static const struct kparam_string __param_string_##name __used \
56407 = { len, string }; \
56408 __module_param_call(MODULE_PARAM_PREFIX, name, \
56409 &param_ops_string, \
56410@@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
56411 * module_param_named() for why this might be necessary.
56412 */
56413 #define module_param_array_named(name, array, type, nump, perm) \
56414- static const struct kparam_array __param_arr_##name \
56415+ static const struct kparam_array __param_arr_##name __used \
56416 = { .max = ARRAY_SIZE(array), .num = nump, \
56417 .ops = &param_ops_##type, \
56418 .elemsize = sizeof(array[0]), .elem = array }; \
56419diff -urNp linux-3.0.4/include/linux/namei.h linux-3.0.4/include/linux/namei.h
56420--- linux-3.0.4/include/linux/namei.h 2011-07-21 22:17:23.000000000 -0400
56421+++ linux-3.0.4/include/linux/namei.h 2011-08-23 21:47:56.000000000 -0400
56422@@ -24,7 +24,7 @@ struct nameidata {
56423 unsigned seq;
56424 int last_type;
56425 unsigned depth;
56426- char *saved_names[MAX_NESTED_LINKS + 1];
56427+ const char *saved_names[MAX_NESTED_LINKS + 1];
56428
56429 /* Intent data */
56430 union {
56431@@ -91,12 +91,12 @@ extern int follow_up(struct path *);
56432 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
56433 extern void unlock_rename(struct dentry *, struct dentry *);
56434
56435-static inline void nd_set_link(struct nameidata *nd, char *path)
56436+static inline void nd_set_link(struct nameidata *nd, const char *path)
56437 {
56438 nd->saved_names[nd->depth] = path;
56439 }
56440
56441-static inline char *nd_get_link(struct nameidata *nd)
56442+static inline const char *nd_get_link(const struct nameidata *nd)
56443 {
56444 return nd->saved_names[nd->depth];
56445 }
56446diff -urNp linux-3.0.4/include/linux/netdevice.h linux-3.0.4/include/linux/netdevice.h
56447--- linux-3.0.4/include/linux/netdevice.h 2011-08-23 21:44:40.000000000 -0400
56448+++ linux-3.0.4/include/linux/netdevice.h 2011-08-23 21:47:56.000000000 -0400
56449@@ -979,6 +979,7 @@ struct net_device_ops {
56450 int (*ndo_set_features)(struct net_device *dev,
56451 u32 features);
56452 };
56453+typedef struct net_device_ops __no_const net_device_ops_no_const;
56454
56455 /*
56456 * The DEVICE structure.
56457diff -urNp linux-3.0.4/include/linux/netfilter/xt_gradm.h linux-3.0.4/include/linux/netfilter/xt_gradm.h
56458--- linux-3.0.4/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
56459+++ linux-3.0.4/include/linux/netfilter/xt_gradm.h 2011-08-23 21:48:14.000000000 -0400
56460@@ -0,0 +1,9 @@
56461+#ifndef _LINUX_NETFILTER_XT_GRADM_H
56462+#define _LINUX_NETFILTER_XT_GRADM_H 1
56463+
56464+struct xt_gradm_mtinfo {
56465+ __u16 flags;
56466+ __u16 invflags;
56467+};
56468+
56469+#endif
56470diff -urNp linux-3.0.4/include/linux/of_pdt.h linux-3.0.4/include/linux/of_pdt.h
56471--- linux-3.0.4/include/linux/of_pdt.h 2011-07-21 22:17:23.000000000 -0400
56472+++ linux-3.0.4/include/linux/of_pdt.h 2011-08-30 06:20:11.000000000 -0400
56473@@ -32,7 +32,7 @@ struct of_pdt_ops {
56474
56475 /* return 0 on success; fill in 'len' with number of bytes in path */
56476 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
56477-};
56478+} __no_const;
56479
56480 extern void *prom_early_alloc(unsigned long size);
56481
56482diff -urNp linux-3.0.4/include/linux/oprofile.h linux-3.0.4/include/linux/oprofile.h
56483--- linux-3.0.4/include/linux/oprofile.h 2011-07-21 22:17:23.000000000 -0400
56484+++ linux-3.0.4/include/linux/oprofile.h 2011-08-23 21:47:56.000000000 -0400
56485@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
56486 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
56487 char const * name, ulong * val);
56488
56489-/** Create a file for read-only access to an atomic_t. */
56490+/** Create a file for read-only access to an atomic_unchecked_t. */
56491 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
56492- char const * name, atomic_t * val);
56493+ char const * name, atomic_unchecked_t * val);
56494
56495 /** create a directory */
56496 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
56497diff -urNp linux-3.0.4/include/linux/padata.h linux-3.0.4/include/linux/padata.h
56498--- linux-3.0.4/include/linux/padata.h 2011-07-21 22:17:23.000000000 -0400
56499+++ linux-3.0.4/include/linux/padata.h 2011-08-23 21:47:56.000000000 -0400
56500@@ -129,7 +129,7 @@ struct parallel_data {
56501 struct padata_instance *pinst;
56502 struct padata_parallel_queue __percpu *pqueue;
56503 struct padata_serial_queue __percpu *squeue;
56504- atomic_t seq_nr;
56505+ atomic_unchecked_t seq_nr;
56506 atomic_t reorder_objects;
56507 atomic_t refcnt;
56508 unsigned int max_seq_nr;
56509diff -urNp linux-3.0.4/include/linux/perf_event.h linux-3.0.4/include/linux/perf_event.h
56510--- linux-3.0.4/include/linux/perf_event.h 2011-07-21 22:17:23.000000000 -0400
56511+++ linux-3.0.4/include/linux/perf_event.h 2011-08-23 21:47:56.000000000 -0400
56512@@ -761,8 +761,8 @@ struct perf_event {
56513
56514 enum perf_event_active_state state;
56515 unsigned int attach_state;
56516- local64_t count;
56517- atomic64_t child_count;
56518+ local64_t count; /* PaX: fix it one day */
56519+ atomic64_unchecked_t child_count;
56520
56521 /*
56522 * These are the total time in nanoseconds that the event
56523@@ -813,8 +813,8 @@ struct perf_event {
56524 * These accumulate total time (in nanoseconds) that children
56525 * events have been enabled and running, respectively.
56526 */
56527- atomic64_t child_total_time_enabled;
56528- atomic64_t child_total_time_running;
56529+ atomic64_unchecked_t child_total_time_enabled;
56530+ atomic64_unchecked_t child_total_time_running;
56531
56532 /*
56533 * Protect attach/detach and child_list:
56534diff -urNp linux-3.0.4/include/linux/pipe_fs_i.h linux-3.0.4/include/linux/pipe_fs_i.h
56535--- linux-3.0.4/include/linux/pipe_fs_i.h 2011-07-21 22:17:23.000000000 -0400
56536+++ linux-3.0.4/include/linux/pipe_fs_i.h 2011-08-23 21:47:56.000000000 -0400
56537@@ -46,9 +46,9 @@ struct pipe_buffer {
56538 struct pipe_inode_info {
56539 wait_queue_head_t wait;
56540 unsigned int nrbufs, curbuf, buffers;
56541- unsigned int readers;
56542- unsigned int writers;
56543- unsigned int waiting_writers;
56544+ atomic_t readers;
56545+ atomic_t writers;
56546+ atomic_t waiting_writers;
56547 unsigned int r_counter;
56548 unsigned int w_counter;
56549 struct page *tmp_page;
56550diff -urNp linux-3.0.4/include/linux/pm_runtime.h linux-3.0.4/include/linux/pm_runtime.h
56551--- linux-3.0.4/include/linux/pm_runtime.h 2011-07-21 22:17:23.000000000 -0400
56552+++ linux-3.0.4/include/linux/pm_runtime.h 2011-08-23 21:47:56.000000000 -0400
56553@@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
56554
56555 static inline void pm_runtime_mark_last_busy(struct device *dev)
56556 {
56557- ACCESS_ONCE(dev->power.last_busy) = jiffies;
56558+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
56559 }
56560
56561 #else /* !CONFIG_PM_RUNTIME */
56562diff -urNp linux-3.0.4/include/linux/poison.h linux-3.0.4/include/linux/poison.h
56563--- linux-3.0.4/include/linux/poison.h 2011-07-21 22:17:23.000000000 -0400
56564+++ linux-3.0.4/include/linux/poison.h 2011-08-23 21:47:56.000000000 -0400
56565@@ -19,8 +19,8 @@
56566 * under normal circumstances, used to verify that nobody uses
56567 * non-initialized list entries.
56568 */
56569-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
56570-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
56571+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
56572+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
56573
56574 /********** include/linux/timer.h **********/
56575 /*
56576diff -urNp linux-3.0.4/include/linux/preempt.h linux-3.0.4/include/linux/preempt.h
56577--- linux-3.0.4/include/linux/preempt.h 2011-07-21 22:17:23.000000000 -0400
56578+++ linux-3.0.4/include/linux/preempt.h 2011-08-23 21:47:56.000000000 -0400
56579@@ -115,7 +115,7 @@ struct preempt_ops {
56580 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
56581 void (*sched_out)(struct preempt_notifier *notifier,
56582 struct task_struct *next);
56583-};
56584+} __no_const;
56585
56586 /**
56587 * preempt_notifier - key for installing preemption notifiers
56588diff -urNp linux-3.0.4/include/linux/proc_fs.h linux-3.0.4/include/linux/proc_fs.h
56589--- linux-3.0.4/include/linux/proc_fs.h 2011-07-21 22:17:23.000000000 -0400
56590+++ linux-3.0.4/include/linux/proc_fs.h 2011-08-23 21:48:14.000000000 -0400
56591@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
56592 return proc_create_data(name, mode, parent, proc_fops, NULL);
56593 }
56594
56595+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
56596+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
56597+{
56598+#ifdef CONFIG_GRKERNSEC_PROC_USER
56599+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
56600+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56601+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
56602+#else
56603+ return proc_create_data(name, mode, parent, proc_fops, NULL);
56604+#endif
56605+}
56606+
56607+
56608 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
56609 mode_t mode, struct proc_dir_entry *base,
56610 read_proc_t *read_proc, void * data)
56611@@ -258,7 +271,7 @@ union proc_op {
56612 int (*proc_show)(struct seq_file *m,
56613 struct pid_namespace *ns, struct pid *pid,
56614 struct task_struct *task);
56615-};
56616+} __no_const;
56617
56618 struct ctl_table_header;
56619 struct ctl_table;
56620diff -urNp linux-3.0.4/include/linux/ptrace.h linux-3.0.4/include/linux/ptrace.h
56621--- linux-3.0.4/include/linux/ptrace.h 2011-07-21 22:17:23.000000000 -0400
56622+++ linux-3.0.4/include/linux/ptrace.h 2011-08-23 21:48:14.000000000 -0400
56623@@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
56624 extern void exit_ptrace(struct task_struct *tracer);
56625 #define PTRACE_MODE_READ 1
56626 #define PTRACE_MODE_ATTACH 2
56627-/* Returns 0 on success, -errno on denial. */
56628-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
56629 /* Returns true on success, false on denial. */
56630 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
56631+/* Returns true on success, false on denial. */
56632+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
56633
56634 static inline int ptrace_reparented(struct task_struct *child)
56635 {
56636diff -urNp linux-3.0.4/include/linux/random.h linux-3.0.4/include/linux/random.h
56637--- linux-3.0.4/include/linux/random.h 2011-08-23 21:44:40.000000000 -0400
56638+++ linux-3.0.4/include/linux/random.h 2011-08-23 21:47:56.000000000 -0400
56639@@ -69,12 +69,17 @@ void srandom32(u32 seed);
56640
56641 u32 prandom32(struct rnd_state *);
56642
56643+static inline unsigned long pax_get_random_long(void)
56644+{
56645+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
56646+}
56647+
56648 /*
56649 * Handle minimum values for seeds
56650 */
56651 static inline u32 __seed(u32 x, u32 m)
56652 {
56653- return (x < m) ? x + m : x;
56654+ return (x <= m) ? x + m + 1 : x;
56655 }
56656
56657 /**
56658diff -urNp linux-3.0.4/include/linux/reboot.h linux-3.0.4/include/linux/reboot.h
56659--- linux-3.0.4/include/linux/reboot.h 2011-07-21 22:17:23.000000000 -0400
56660+++ linux-3.0.4/include/linux/reboot.h 2011-08-23 21:47:56.000000000 -0400
56661@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
56662 * Architecture-specific implementations of sys_reboot commands.
56663 */
56664
56665-extern void machine_restart(char *cmd);
56666-extern void machine_halt(void);
56667-extern void machine_power_off(void);
56668+extern void machine_restart(char *cmd) __noreturn;
56669+extern void machine_halt(void) __noreturn;
56670+extern void machine_power_off(void) __noreturn;
56671
56672 extern void machine_shutdown(void);
56673 struct pt_regs;
56674@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
56675 */
56676
56677 extern void kernel_restart_prepare(char *cmd);
56678-extern void kernel_restart(char *cmd);
56679-extern void kernel_halt(void);
56680-extern void kernel_power_off(void);
56681+extern void kernel_restart(char *cmd) __noreturn;
56682+extern void kernel_halt(void) __noreturn;
56683+extern void kernel_power_off(void) __noreturn;
56684
56685 extern int C_A_D; /* for sysctl */
56686 void ctrl_alt_del(void);
56687@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
56688 * Emergency restart, callable from an interrupt handler.
56689 */
56690
56691-extern void emergency_restart(void);
56692+extern void emergency_restart(void) __noreturn;
56693 #include <asm/emergency-restart.h>
56694
56695 #endif
56696diff -urNp linux-3.0.4/include/linux/reiserfs_fs.h linux-3.0.4/include/linux/reiserfs_fs.h
56697--- linux-3.0.4/include/linux/reiserfs_fs.h 2011-07-21 22:17:23.000000000 -0400
56698+++ linux-3.0.4/include/linux/reiserfs_fs.h 2011-08-23 21:47:56.000000000 -0400
56699@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
56700 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56701
56702 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56703-#define get_generation(s) atomic_read (&fs_generation(s))
56704+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56705 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56706 #define __fs_changed(gen,s) (gen != get_generation (s))
56707 #define fs_changed(gen,s) \
56708diff -urNp linux-3.0.4/include/linux/reiserfs_fs_sb.h linux-3.0.4/include/linux/reiserfs_fs_sb.h
56709--- linux-3.0.4/include/linux/reiserfs_fs_sb.h 2011-07-21 22:17:23.000000000 -0400
56710+++ linux-3.0.4/include/linux/reiserfs_fs_sb.h 2011-08-23 21:47:56.000000000 -0400
56711@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
56712 /* Comment? -Hans */
56713 wait_queue_head_t s_wait;
56714 /* To be obsoleted soon by per buffer seals.. -Hans */
56715- atomic_t s_generation_counter; // increased by one every time the
56716+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56717 // tree gets re-balanced
56718 unsigned long s_properties; /* File system properties. Currently holds
56719 on-disk FS format */
56720diff -urNp linux-3.0.4/include/linux/relay.h linux-3.0.4/include/linux/relay.h
56721--- linux-3.0.4/include/linux/relay.h 2011-07-21 22:17:23.000000000 -0400
56722+++ linux-3.0.4/include/linux/relay.h 2011-08-23 21:47:56.000000000 -0400
56723@@ -159,7 +159,7 @@ struct rchan_callbacks
56724 * The callback should return 0 if successful, negative if not.
56725 */
56726 int (*remove_buf_file)(struct dentry *dentry);
56727-};
56728+} __no_const;
56729
56730 /*
56731 * CONFIG_RELAY kernel API, kernel/relay.c
56732diff -urNp linux-3.0.4/include/linux/rfkill.h linux-3.0.4/include/linux/rfkill.h
56733--- linux-3.0.4/include/linux/rfkill.h 2011-07-21 22:17:23.000000000 -0400
56734+++ linux-3.0.4/include/linux/rfkill.h 2011-08-23 21:47:56.000000000 -0400
56735@@ -147,6 +147,7 @@ struct rfkill_ops {
56736 void (*query)(struct rfkill *rfkill, void *data);
56737 int (*set_block)(void *data, bool blocked);
56738 };
56739+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
56740
56741 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
56742 /**
56743diff -urNp linux-3.0.4/include/linux/rmap.h linux-3.0.4/include/linux/rmap.h
56744--- linux-3.0.4/include/linux/rmap.h 2011-07-21 22:17:23.000000000 -0400
56745+++ linux-3.0.4/include/linux/rmap.h 2011-08-23 21:47:56.000000000 -0400
56746@@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
56747 void anon_vma_init(void); /* create anon_vma_cachep */
56748 int anon_vma_prepare(struct vm_area_struct *);
56749 void unlink_anon_vmas(struct vm_area_struct *);
56750-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
56751-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
56752+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
56753+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
56754 void __anon_vma_link(struct vm_area_struct *);
56755
56756 static inline void anon_vma_merge(struct vm_area_struct *vma,
56757diff -urNp linux-3.0.4/include/linux/sched.h linux-3.0.4/include/linux/sched.h
56758--- linux-3.0.4/include/linux/sched.h 2011-07-21 22:17:23.000000000 -0400
56759+++ linux-3.0.4/include/linux/sched.h 2011-08-25 17:22:27.000000000 -0400
56760@@ -100,6 +100,7 @@ struct bio_list;
56761 struct fs_struct;
56762 struct perf_event_context;
56763 struct blk_plug;
56764+struct linux_binprm;
56765
56766 /*
56767 * List of flags we want to share for kernel threads,
56768@@ -380,10 +381,13 @@ struct user_namespace;
56769 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
56770
56771 extern int sysctl_max_map_count;
56772+extern unsigned long sysctl_heap_stack_gap;
56773
56774 #include <linux/aio.h>
56775
56776 #ifdef CONFIG_MMU
56777+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
56778+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
56779 extern void arch_pick_mmap_layout(struct mm_struct *mm);
56780 extern unsigned long
56781 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
56782@@ -629,6 +633,17 @@ struct signal_struct {
56783 #ifdef CONFIG_TASKSTATS
56784 struct taskstats *stats;
56785 #endif
56786+
56787+#ifdef CONFIG_GRKERNSEC
56788+ u32 curr_ip;
56789+ u32 saved_ip;
56790+ u32 gr_saddr;
56791+ u32 gr_daddr;
56792+ u16 gr_sport;
56793+ u16 gr_dport;
56794+ u8 used_accept:1;
56795+#endif
56796+
56797 #ifdef CONFIG_AUDIT
56798 unsigned audit_tty;
56799 struct tty_audit_buf *tty_audit_buf;
56800@@ -710,6 +725,11 @@ struct user_struct {
56801 struct key *session_keyring; /* UID's default session keyring */
56802 #endif
56803
56804+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56805+ unsigned int banned;
56806+ unsigned long ban_expires;
56807+#endif
56808+
56809 /* Hash table maintenance information */
56810 struct hlist_node uidhash_node;
56811 uid_t uid;
56812@@ -1340,8 +1360,8 @@ struct task_struct {
56813 struct list_head thread_group;
56814
56815 struct completion *vfork_done; /* for vfork() */
56816- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
56817- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
56818+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
56819+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
56820
56821 cputime_t utime, stime, utimescaled, stimescaled;
56822 cputime_t gtime;
56823@@ -1357,13 +1377,6 @@ struct task_struct {
56824 struct task_cputime cputime_expires;
56825 struct list_head cpu_timers[3];
56826
56827-/* process credentials */
56828- const struct cred __rcu *real_cred; /* objective and real subjective task
56829- * credentials (COW) */
56830- const struct cred __rcu *cred; /* effective (overridable) subjective task
56831- * credentials (COW) */
56832- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
56833-
56834 char comm[TASK_COMM_LEN]; /* executable name excluding path
56835 - access with [gs]et_task_comm (which lock
56836 it with task_lock())
56837@@ -1380,8 +1393,16 @@ struct task_struct {
56838 #endif
56839 /* CPU-specific state of this task */
56840 struct thread_struct thread;
56841+/* thread_info moved to task_struct */
56842+#ifdef CONFIG_X86
56843+ struct thread_info tinfo;
56844+#endif
56845 /* filesystem information */
56846 struct fs_struct *fs;
56847+
56848+ const struct cred __rcu *cred; /* effective (overridable) subjective task
56849+ * credentials (COW) */
56850+
56851 /* open file information */
56852 struct files_struct *files;
56853 /* namespaces */
56854@@ -1428,6 +1449,11 @@ struct task_struct {
56855 struct rt_mutex_waiter *pi_blocked_on;
56856 #endif
56857
56858+/* process credentials */
56859+ const struct cred __rcu *real_cred; /* objective and real subjective task
56860+ * credentials (COW) */
56861+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
56862+
56863 #ifdef CONFIG_DEBUG_MUTEXES
56864 /* mutex deadlock detection */
56865 struct mutex_waiter *blocked_on;
56866@@ -1538,6 +1564,21 @@ struct task_struct {
56867 unsigned long default_timer_slack_ns;
56868
56869 struct list_head *scm_work_list;
56870+
56871+#ifdef CONFIG_GRKERNSEC
56872+ /* grsecurity */
56873+ struct dentry *gr_chroot_dentry;
56874+ struct acl_subject_label *acl;
56875+ struct acl_role_label *role;
56876+ struct file *exec_file;
56877+ u16 acl_role_id;
56878+ /* is this the task that authenticated to the special role */
56879+ u8 acl_sp_role;
56880+ u8 is_writable;
56881+ u8 brute;
56882+ u8 gr_is_chrooted;
56883+#endif
56884+
56885 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
56886 /* Index of current stored address in ret_stack */
56887 int curr_ret_stack;
56888@@ -1572,6 +1613,57 @@ struct task_struct {
56889 #endif
56890 };
56891
56892+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
56893+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
56894+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
56895+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
56896+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
56897+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
56898+
56899+#ifdef CONFIG_PAX_SOFTMODE
56900+extern int pax_softmode;
56901+#endif
56902+
56903+extern int pax_check_flags(unsigned long *);
56904+
56905+/* if tsk != current then task_lock must be held on it */
56906+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56907+static inline unsigned long pax_get_flags(struct task_struct *tsk)
56908+{
56909+ if (likely(tsk->mm))
56910+ return tsk->mm->pax_flags;
56911+ else
56912+ return 0UL;
56913+}
56914+
56915+/* if tsk != current then task_lock must be held on it */
56916+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
56917+{
56918+ if (likely(tsk->mm)) {
56919+ tsk->mm->pax_flags = flags;
56920+ return 0;
56921+ }
56922+ return -EINVAL;
56923+}
56924+#endif
56925+
56926+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56927+extern void pax_set_initial_flags(struct linux_binprm *bprm);
56928+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56929+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
56930+#endif
56931+
56932+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
56933+extern void pax_report_insns(void *pc, void *sp);
56934+extern void pax_report_refcount_overflow(struct pt_regs *regs);
56935+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
56936+
56937+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56938+extern void pax_track_stack(void);
56939+#else
56940+static inline void pax_track_stack(void) {}
56941+#endif
56942+
56943 /* Future-safe accessor for struct task_struct's cpus_allowed. */
56944 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
56945
56946@@ -1768,6 +1860,7 @@ extern void thread_group_times(struct ta
56947 #define PF_DUMPCORE 0x00000200 /* dumped core */
56948 #define PF_SIGNALED 0x00000400 /* killed by a signal */
56949 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
56950+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
56951 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
56952 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
56953 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
56954@@ -2056,7 +2149,9 @@ void yield(void);
56955 extern struct exec_domain default_exec_domain;
56956
56957 union thread_union {
56958+#ifndef CONFIG_X86
56959 struct thread_info thread_info;
56960+#endif
56961 unsigned long stack[THREAD_SIZE/sizeof(long)];
56962 };
56963
56964@@ -2089,6 +2184,7 @@ extern struct pid_namespace init_pid_ns;
56965 */
56966
56967 extern struct task_struct *find_task_by_vpid(pid_t nr);
56968+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
56969 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
56970 struct pid_namespace *ns);
56971
56972@@ -2225,7 +2321,7 @@ extern void __cleanup_sighand(struct sig
56973 extern void exit_itimers(struct signal_struct *);
56974 extern void flush_itimer_signals(void);
56975
56976-extern NORET_TYPE void do_group_exit(int);
56977+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
56978
56979 extern void daemonize(const char *, ...);
56980 extern int allow_signal(int);
56981@@ -2393,13 +2489,17 @@ static inline unsigned long *end_of_stac
56982
56983 #endif
56984
56985-static inline int object_is_on_stack(void *obj)
56986+static inline int object_starts_on_stack(void *obj)
56987 {
56988- void *stack = task_stack_page(current);
56989+ const void *stack = task_stack_page(current);
56990
56991 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
56992 }
56993
56994+#ifdef CONFIG_PAX_USERCOPY
56995+extern int object_is_on_stack(const void *obj, unsigned long len);
56996+#endif
56997+
56998 extern void thread_info_cache_init(void);
56999
57000 #ifdef CONFIG_DEBUG_STACK_USAGE
57001diff -urNp linux-3.0.4/include/linux/screen_info.h linux-3.0.4/include/linux/screen_info.h
57002--- linux-3.0.4/include/linux/screen_info.h 2011-07-21 22:17:23.000000000 -0400
57003+++ linux-3.0.4/include/linux/screen_info.h 2011-08-23 21:47:56.000000000 -0400
57004@@ -43,7 +43,8 @@ struct screen_info {
57005 __u16 pages; /* 0x32 */
57006 __u16 vesa_attributes; /* 0x34 */
57007 __u32 capabilities; /* 0x36 */
57008- __u8 _reserved[6]; /* 0x3a */
57009+ __u16 vesapm_size; /* 0x3a */
57010+ __u8 _reserved[4]; /* 0x3c */
57011 } __attribute__((packed));
57012
57013 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
57014diff -urNp linux-3.0.4/include/linux/security.h linux-3.0.4/include/linux/security.h
57015--- linux-3.0.4/include/linux/security.h 2011-07-21 22:17:23.000000000 -0400
57016+++ linux-3.0.4/include/linux/security.h 2011-08-23 21:48:14.000000000 -0400
57017@@ -36,6 +36,7 @@
57018 #include <linux/key.h>
57019 #include <linux/xfrm.h>
57020 #include <linux/slab.h>
57021+#include <linux/grsecurity.h>
57022 #include <net/flow.h>
57023
57024 /* Maximum number of letters for an LSM name string */
57025diff -urNp linux-3.0.4/include/linux/seq_file.h linux-3.0.4/include/linux/seq_file.h
57026--- linux-3.0.4/include/linux/seq_file.h 2011-07-21 22:17:23.000000000 -0400
57027+++ linux-3.0.4/include/linux/seq_file.h 2011-08-23 21:47:56.000000000 -0400
57028@@ -32,6 +32,7 @@ struct seq_operations {
57029 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
57030 int (*show) (struct seq_file *m, void *v);
57031 };
57032+typedef struct seq_operations __no_const seq_operations_no_const;
57033
57034 #define SEQ_SKIP 1
57035
57036diff -urNp linux-3.0.4/include/linux/shmem_fs.h linux-3.0.4/include/linux/shmem_fs.h
57037--- linux-3.0.4/include/linux/shmem_fs.h 2011-07-21 22:17:23.000000000 -0400
57038+++ linux-3.0.4/include/linux/shmem_fs.h 2011-08-23 21:47:56.000000000 -0400
57039@@ -10,7 +10,7 @@
57040
57041 #define SHMEM_NR_DIRECT 16
57042
57043-#define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
57044+#define SHMEM_SYMLINK_INLINE_LEN 64
57045
57046 struct shmem_inode_info {
57047 spinlock_t lock;
57048diff -urNp linux-3.0.4/include/linux/shm.h linux-3.0.4/include/linux/shm.h
57049--- linux-3.0.4/include/linux/shm.h 2011-07-21 22:17:23.000000000 -0400
57050+++ linux-3.0.4/include/linux/shm.h 2011-08-23 21:48:14.000000000 -0400
57051@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
57052 pid_t shm_cprid;
57053 pid_t shm_lprid;
57054 struct user_struct *mlock_user;
57055+#ifdef CONFIG_GRKERNSEC
57056+ time_t shm_createtime;
57057+ pid_t shm_lapid;
57058+#endif
57059 };
57060
57061 /* shm_mode upper byte flags */
57062diff -urNp linux-3.0.4/include/linux/skbuff.h linux-3.0.4/include/linux/skbuff.h
57063--- linux-3.0.4/include/linux/skbuff.h 2011-07-21 22:17:23.000000000 -0400
57064+++ linux-3.0.4/include/linux/skbuff.h 2011-08-23 21:47:56.000000000 -0400
57065@@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
57066 */
57067 static inline int skb_queue_empty(const struct sk_buff_head *list)
57068 {
57069- return list->next == (struct sk_buff *)list;
57070+ return list->next == (const struct sk_buff *)list;
57071 }
57072
57073 /**
57074@@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
57075 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
57076 const struct sk_buff *skb)
57077 {
57078- return skb->next == (struct sk_buff *)list;
57079+ return skb->next == (const struct sk_buff *)list;
57080 }
57081
57082 /**
57083@@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
57084 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
57085 const struct sk_buff *skb)
57086 {
57087- return skb->prev == (struct sk_buff *)list;
57088+ return skb->prev == (const struct sk_buff *)list;
57089 }
57090
57091 /**
57092@@ -1440,7 +1440,7 @@ static inline int pskb_network_may_pull(
57093 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
57094 */
57095 #ifndef NET_SKB_PAD
57096-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
57097+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
57098 #endif
57099
57100 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
57101diff -urNp linux-3.0.4/include/linux/slab_def.h linux-3.0.4/include/linux/slab_def.h
57102--- linux-3.0.4/include/linux/slab_def.h 2011-07-21 22:17:23.000000000 -0400
57103+++ linux-3.0.4/include/linux/slab_def.h 2011-08-23 21:47:56.000000000 -0400
57104@@ -96,10 +96,10 @@ struct kmem_cache {
57105 unsigned long node_allocs;
57106 unsigned long node_frees;
57107 unsigned long node_overflow;
57108- atomic_t allochit;
57109- atomic_t allocmiss;
57110- atomic_t freehit;
57111- atomic_t freemiss;
57112+ atomic_unchecked_t allochit;
57113+ atomic_unchecked_t allocmiss;
57114+ atomic_unchecked_t freehit;
57115+ atomic_unchecked_t freemiss;
57116
57117 /*
57118 * If debugging is enabled, then the allocator can add additional
57119diff -urNp linux-3.0.4/include/linux/slab.h linux-3.0.4/include/linux/slab.h
57120--- linux-3.0.4/include/linux/slab.h 2011-07-21 22:17:23.000000000 -0400
57121+++ linux-3.0.4/include/linux/slab.h 2011-08-23 21:47:56.000000000 -0400
57122@@ -11,12 +11,20 @@
57123
57124 #include <linux/gfp.h>
57125 #include <linux/types.h>
57126+#include <linux/err.h>
57127
57128 /*
57129 * Flags to pass to kmem_cache_create().
57130 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
57131 */
57132 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
57133+
57134+#ifdef CONFIG_PAX_USERCOPY
57135+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
57136+#else
57137+#define SLAB_USERCOPY 0x00000000UL
57138+#endif
57139+
57140 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
57141 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
57142 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
57143@@ -87,10 +95,13 @@
57144 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
57145 * Both make kfree a no-op.
57146 */
57147-#define ZERO_SIZE_PTR ((void *)16)
57148+#define ZERO_SIZE_PTR \
57149+({ \
57150+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
57151+ (void *)(-MAX_ERRNO-1L); \
57152+})
57153
57154-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
57155- (unsigned long)ZERO_SIZE_PTR)
57156+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
57157
57158 /*
57159 * struct kmem_cache related prototypes
57160@@ -141,6 +152,7 @@ void * __must_check krealloc(const void
57161 void kfree(const void *);
57162 void kzfree(const void *);
57163 size_t ksize(const void *);
57164+void check_object_size(const void *ptr, unsigned long n, bool to);
57165
57166 /*
57167 * Allocator specific definitions. These are mainly used to establish optimized
57168@@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
57169
57170 void __init kmem_cache_init_late(void);
57171
57172+#define kmalloc(x, y) \
57173+({ \
57174+ void *___retval; \
57175+ intoverflow_t ___x = (intoverflow_t)x; \
57176+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
57177+ ___retval = NULL; \
57178+ else \
57179+ ___retval = kmalloc((size_t)___x, (y)); \
57180+ ___retval; \
57181+})
57182+
57183+#define kmalloc_node(x, y, z) \
57184+({ \
57185+ void *___retval; \
57186+ intoverflow_t ___x = (intoverflow_t)x; \
57187+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
57188+ ___retval = NULL; \
57189+ else \
57190+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
57191+ ___retval; \
57192+})
57193+
57194+#define kzalloc(x, y) \
57195+({ \
57196+ void *___retval; \
57197+ intoverflow_t ___x = (intoverflow_t)x; \
57198+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
57199+ ___retval = NULL; \
57200+ else \
57201+ ___retval = kzalloc((size_t)___x, (y)); \
57202+ ___retval; \
57203+})
57204+
57205+#define __krealloc(x, y, z) \
57206+({ \
57207+ void *___retval; \
57208+ intoverflow_t ___y = (intoverflow_t)y; \
57209+ if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
57210+ ___retval = NULL; \
57211+ else \
57212+ ___retval = __krealloc((x), (size_t)___y, (z)); \
57213+ ___retval; \
57214+})
57215+
57216+#define krealloc(x, y, z) \
57217+({ \
57218+ void *___retval; \
57219+ intoverflow_t ___y = (intoverflow_t)y; \
57220+ if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
57221+ ___retval = NULL; \
57222+ else \
57223+ ___retval = krealloc((x), (size_t)___y, (z)); \
57224+ ___retval; \
57225+})
57226+
57227 #endif /* _LINUX_SLAB_H */
57228diff -urNp linux-3.0.4/include/linux/slub_def.h linux-3.0.4/include/linux/slub_def.h
57229--- linux-3.0.4/include/linux/slub_def.h 2011-07-21 22:17:23.000000000 -0400
57230+++ linux-3.0.4/include/linux/slub_def.h 2011-08-23 21:47:56.000000000 -0400
57231@@ -82,7 +82,7 @@ struct kmem_cache {
57232 struct kmem_cache_order_objects max;
57233 struct kmem_cache_order_objects min;
57234 gfp_t allocflags; /* gfp flags to use on each alloc */
57235- int refcount; /* Refcount for slab cache destroy */
57236+ atomic_t refcount; /* Refcount for slab cache destroy */
57237 void (*ctor)(void *);
57238 int inuse; /* Offset to metadata */
57239 int align; /* Alignment */
57240@@ -218,7 +218,7 @@ static __always_inline struct kmem_cache
57241 }
57242
57243 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
57244-void *__kmalloc(size_t size, gfp_t flags);
57245+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
57246
57247 static __always_inline void *
57248 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
57249diff -urNp linux-3.0.4/include/linux/sonet.h linux-3.0.4/include/linux/sonet.h
57250--- linux-3.0.4/include/linux/sonet.h 2011-07-21 22:17:23.000000000 -0400
57251+++ linux-3.0.4/include/linux/sonet.h 2011-08-23 21:47:56.000000000 -0400
57252@@ -61,7 +61,7 @@ struct sonet_stats {
57253 #include <asm/atomic.h>
57254
57255 struct k_sonet_stats {
57256-#define __HANDLE_ITEM(i) atomic_t i
57257+#define __HANDLE_ITEM(i) atomic_unchecked_t i
57258 __SONET_ITEMS
57259 #undef __HANDLE_ITEM
57260 };
57261diff -urNp linux-3.0.4/include/linux/sunrpc/clnt.h linux-3.0.4/include/linux/sunrpc/clnt.h
57262--- linux-3.0.4/include/linux/sunrpc/clnt.h 2011-07-21 22:17:23.000000000 -0400
57263+++ linux-3.0.4/include/linux/sunrpc/clnt.h 2011-08-23 21:47:56.000000000 -0400
57264@@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
57265 {
57266 switch (sap->sa_family) {
57267 case AF_INET:
57268- return ntohs(((struct sockaddr_in *)sap)->sin_port);
57269+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
57270 case AF_INET6:
57271- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
57272+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
57273 }
57274 return 0;
57275 }
57276@@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
57277 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
57278 const struct sockaddr *src)
57279 {
57280- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
57281+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
57282 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
57283
57284 dsin->sin_family = ssin->sin_family;
57285@@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
57286 if (sa->sa_family != AF_INET6)
57287 return 0;
57288
57289- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
57290+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
57291 }
57292
57293 #endif /* __KERNEL__ */
57294diff -urNp linux-3.0.4/include/linux/sunrpc/svc_rdma.h linux-3.0.4/include/linux/sunrpc/svc_rdma.h
57295--- linux-3.0.4/include/linux/sunrpc/svc_rdma.h 2011-07-21 22:17:23.000000000 -0400
57296+++ linux-3.0.4/include/linux/sunrpc/svc_rdma.h 2011-08-23 21:47:56.000000000 -0400
57297@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
57298 extern unsigned int svcrdma_max_requests;
57299 extern unsigned int svcrdma_max_req_size;
57300
57301-extern atomic_t rdma_stat_recv;
57302-extern atomic_t rdma_stat_read;
57303-extern atomic_t rdma_stat_write;
57304-extern atomic_t rdma_stat_sq_starve;
57305-extern atomic_t rdma_stat_rq_starve;
57306-extern atomic_t rdma_stat_rq_poll;
57307-extern atomic_t rdma_stat_rq_prod;
57308-extern atomic_t rdma_stat_sq_poll;
57309-extern atomic_t rdma_stat_sq_prod;
57310+extern atomic_unchecked_t rdma_stat_recv;
57311+extern atomic_unchecked_t rdma_stat_read;
57312+extern atomic_unchecked_t rdma_stat_write;
57313+extern atomic_unchecked_t rdma_stat_sq_starve;
57314+extern atomic_unchecked_t rdma_stat_rq_starve;
57315+extern atomic_unchecked_t rdma_stat_rq_poll;
57316+extern atomic_unchecked_t rdma_stat_rq_prod;
57317+extern atomic_unchecked_t rdma_stat_sq_poll;
57318+extern atomic_unchecked_t rdma_stat_sq_prod;
57319
57320 #define RPCRDMA_VERSION 1
57321
57322diff -urNp linux-3.0.4/include/linux/sysctl.h linux-3.0.4/include/linux/sysctl.h
57323--- linux-3.0.4/include/linux/sysctl.h 2011-07-21 22:17:23.000000000 -0400
57324+++ linux-3.0.4/include/linux/sysctl.h 2011-08-23 21:48:14.000000000 -0400
57325@@ -155,7 +155,11 @@ enum
57326 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
57327 };
57328
57329-
57330+#ifdef CONFIG_PAX_SOFTMODE
57331+enum {
57332+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
57333+};
57334+#endif
57335
57336 /* CTL_VM names: */
57337 enum
57338@@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
57339
57340 extern int proc_dostring(struct ctl_table *, int,
57341 void __user *, size_t *, loff_t *);
57342+extern int proc_dostring_modpriv(struct ctl_table *, int,
57343+ void __user *, size_t *, loff_t *);
57344 extern int proc_dointvec(struct ctl_table *, int,
57345 void __user *, size_t *, loff_t *);
57346 extern int proc_dointvec_minmax(struct ctl_table *, int,
57347diff -urNp linux-3.0.4/include/linux/tty_ldisc.h linux-3.0.4/include/linux/tty_ldisc.h
57348--- linux-3.0.4/include/linux/tty_ldisc.h 2011-07-21 22:17:23.000000000 -0400
57349+++ linux-3.0.4/include/linux/tty_ldisc.h 2011-08-23 21:47:56.000000000 -0400
57350@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
57351
57352 struct module *owner;
57353
57354- int refcount;
57355+ atomic_t refcount;
57356 };
57357
57358 struct tty_ldisc {
57359diff -urNp linux-3.0.4/include/linux/types.h linux-3.0.4/include/linux/types.h
57360--- linux-3.0.4/include/linux/types.h 2011-07-21 22:17:23.000000000 -0400
57361+++ linux-3.0.4/include/linux/types.h 2011-08-23 21:47:56.000000000 -0400
57362@@ -213,10 +213,26 @@ typedef struct {
57363 int counter;
57364 } atomic_t;
57365
57366+#ifdef CONFIG_PAX_REFCOUNT
57367+typedef struct {
57368+ int counter;
57369+} atomic_unchecked_t;
57370+#else
57371+typedef atomic_t atomic_unchecked_t;
57372+#endif
57373+
57374 #ifdef CONFIG_64BIT
57375 typedef struct {
57376 long counter;
57377 } atomic64_t;
57378+
57379+#ifdef CONFIG_PAX_REFCOUNT
57380+typedef struct {
57381+ long counter;
57382+} atomic64_unchecked_t;
57383+#else
57384+typedef atomic64_t atomic64_unchecked_t;
57385+#endif
57386 #endif
57387
57388 struct list_head {
57389diff -urNp linux-3.0.4/include/linux/uaccess.h linux-3.0.4/include/linux/uaccess.h
57390--- linux-3.0.4/include/linux/uaccess.h 2011-07-21 22:17:23.000000000 -0400
57391+++ linux-3.0.4/include/linux/uaccess.h 2011-08-23 21:47:56.000000000 -0400
57392@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
57393 long ret; \
57394 mm_segment_t old_fs = get_fs(); \
57395 \
57396- set_fs(KERNEL_DS); \
57397 pagefault_disable(); \
57398+ set_fs(KERNEL_DS); \
57399 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
57400- pagefault_enable(); \
57401 set_fs(old_fs); \
57402+ pagefault_enable(); \
57403 ret; \
57404 })
57405
57406diff -urNp linux-3.0.4/include/linux/unaligned/access_ok.h linux-3.0.4/include/linux/unaligned/access_ok.h
57407--- linux-3.0.4/include/linux/unaligned/access_ok.h 2011-07-21 22:17:23.000000000 -0400
57408+++ linux-3.0.4/include/linux/unaligned/access_ok.h 2011-08-23 21:47:56.000000000 -0400
57409@@ -6,32 +6,32 @@
57410
57411 static inline u16 get_unaligned_le16(const void *p)
57412 {
57413- return le16_to_cpup((__le16 *)p);
57414+ return le16_to_cpup((const __le16 *)p);
57415 }
57416
57417 static inline u32 get_unaligned_le32(const void *p)
57418 {
57419- return le32_to_cpup((__le32 *)p);
57420+ return le32_to_cpup((const __le32 *)p);
57421 }
57422
57423 static inline u64 get_unaligned_le64(const void *p)
57424 {
57425- return le64_to_cpup((__le64 *)p);
57426+ return le64_to_cpup((const __le64 *)p);
57427 }
57428
57429 static inline u16 get_unaligned_be16(const void *p)
57430 {
57431- return be16_to_cpup((__be16 *)p);
57432+ return be16_to_cpup((const __be16 *)p);
57433 }
57434
57435 static inline u32 get_unaligned_be32(const void *p)
57436 {
57437- return be32_to_cpup((__be32 *)p);
57438+ return be32_to_cpup((const __be32 *)p);
57439 }
57440
57441 static inline u64 get_unaligned_be64(const void *p)
57442 {
57443- return be64_to_cpup((__be64 *)p);
57444+ return be64_to_cpup((const __be64 *)p);
57445 }
57446
57447 static inline void put_unaligned_le16(u16 val, void *p)
57448diff -urNp linux-3.0.4/include/linux/vmalloc.h linux-3.0.4/include/linux/vmalloc.h
57449--- linux-3.0.4/include/linux/vmalloc.h 2011-07-21 22:17:23.000000000 -0400
57450+++ linux-3.0.4/include/linux/vmalloc.h 2011-08-23 21:47:56.000000000 -0400
57451@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
57452 #define VM_MAP 0x00000004 /* vmap()ed pages */
57453 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
57454 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
57455+
57456+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
57457+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
57458+#endif
57459+
57460 /* bits [20..32] reserved for arch specific ioremap internals */
57461
57462 /*
57463@@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
57464 # endif
57465 #endif
57466
57467+#define vmalloc(x) \
57468+({ \
57469+ void *___retval; \
57470+ intoverflow_t ___x = (intoverflow_t)x; \
57471+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
57472+ ___retval = NULL; \
57473+ else \
57474+ ___retval = vmalloc((unsigned long)___x); \
57475+ ___retval; \
57476+})
57477+
57478+#define vzalloc(x) \
57479+({ \
57480+ void *___retval; \
57481+ intoverflow_t ___x = (intoverflow_t)x; \
57482+ if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
57483+ ___retval = NULL; \
57484+ else \
57485+ ___retval = vzalloc((unsigned long)___x); \
57486+ ___retval; \
57487+})
57488+
57489+#define __vmalloc(x, y, z) \
57490+({ \
57491+ void *___retval; \
57492+ intoverflow_t ___x = (intoverflow_t)x; \
57493+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
57494+ ___retval = NULL; \
57495+ else \
57496+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
57497+ ___retval; \
57498+})
57499+
57500+#define vmalloc_user(x) \
57501+({ \
57502+ void *___retval; \
57503+ intoverflow_t ___x = (intoverflow_t)x; \
57504+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
57505+ ___retval = NULL; \
57506+ else \
57507+ ___retval = vmalloc_user((unsigned long)___x); \
57508+ ___retval; \
57509+})
57510+
57511+#define vmalloc_exec(x) \
57512+({ \
57513+ void *___retval; \
57514+ intoverflow_t ___x = (intoverflow_t)x; \
57515+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
57516+ ___retval = NULL; \
57517+ else \
57518+ ___retval = vmalloc_exec((unsigned long)___x); \
57519+ ___retval; \
57520+})
57521+
57522+#define vmalloc_node(x, y) \
57523+({ \
57524+ void *___retval; \
57525+ intoverflow_t ___x = (intoverflow_t)x; \
57526+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
57527+ ___retval = NULL; \
57528+ else \
57529+ ___retval = vmalloc_node((unsigned long)___x, (y));\
57530+ ___retval; \
57531+})
57532+
57533+#define vzalloc_node(x, y) \
57534+({ \
57535+ void *___retval; \
57536+ intoverflow_t ___x = (intoverflow_t)x; \
57537+ if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
57538+ ___retval = NULL; \
57539+ else \
57540+ ___retval = vzalloc_node((unsigned long)___x, (y));\
57541+ ___retval; \
57542+})
57543+
57544+#define vmalloc_32(x) \
57545+({ \
57546+ void *___retval; \
57547+ intoverflow_t ___x = (intoverflow_t)x; \
57548+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
57549+ ___retval = NULL; \
57550+ else \
57551+ ___retval = vmalloc_32((unsigned long)___x); \
57552+ ___retval; \
57553+})
57554+
57555+#define vmalloc_32_user(x) \
57556+({ \
57557+void *___retval; \
57558+ intoverflow_t ___x = (intoverflow_t)x; \
57559+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
57560+ ___retval = NULL; \
57561+ else \
57562+ ___retval = vmalloc_32_user((unsigned long)___x);\
57563+ ___retval; \
57564+})
57565+
57566 #endif /* _LINUX_VMALLOC_H */
57567diff -urNp linux-3.0.4/include/linux/vmstat.h linux-3.0.4/include/linux/vmstat.h
57568--- linux-3.0.4/include/linux/vmstat.h 2011-07-21 22:17:23.000000000 -0400
57569+++ linux-3.0.4/include/linux/vmstat.h 2011-08-23 21:47:56.000000000 -0400
57570@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(in
57571 /*
57572 * Zone based page accounting with per cpu differentials.
57573 */
57574-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
57575+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
57576
57577 static inline void zone_page_state_add(long x, struct zone *zone,
57578 enum zone_stat_item item)
57579 {
57580- atomic_long_add(x, &zone->vm_stat[item]);
57581- atomic_long_add(x, &vm_stat[item]);
57582+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
57583+ atomic_long_add_unchecked(x, &vm_stat[item]);
57584 }
57585
57586 static inline unsigned long global_page_state(enum zone_stat_item item)
57587 {
57588- long x = atomic_long_read(&vm_stat[item]);
57589+ long x = atomic_long_read_unchecked(&vm_stat[item]);
57590 #ifdef CONFIG_SMP
57591 if (x < 0)
57592 x = 0;
57593@@ -109,7 +109,7 @@ static inline unsigned long global_page_
57594 static inline unsigned long zone_page_state(struct zone *zone,
57595 enum zone_stat_item item)
57596 {
57597- long x = atomic_long_read(&zone->vm_stat[item]);
57598+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
57599 #ifdef CONFIG_SMP
57600 if (x < 0)
57601 x = 0;
57602@@ -126,7 +126,7 @@ static inline unsigned long zone_page_st
57603 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
57604 enum zone_stat_item item)
57605 {
57606- long x = atomic_long_read(&zone->vm_stat[item]);
57607+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
57608
57609 #ifdef CONFIG_SMP
57610 int cpu;
57611@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state
57612
57613 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
57614 {
57615- atomic_long_inc(&zone->vm_stat[item]);
57616- atomic_long_inc(&vm_stat[item]);
57617+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
57618+ atomic_long_inc_unchecked(&vm_stat[item]);
57619 }
57620
57621 static inline void __inc_zone_page_state(struct page *page,
57622@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state
57623
57624 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
57625 {
57626- atomic_long_dec(&zone->vm_stat[item]);
57627- atomic_long_dec(&vm_stat[item]);
57628+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
57629+ atomic_long_dec_unchecked(&vm_stat[item]);
57630 }
57631
57632 static inline void __dec_zone_page_state(struct page *page,
57633diff -urNp linux-3.0.4/include/media/saa7146_vv.h linux-3.0.4/include/media/saa7146_vv.h
57634--- linux-3.0.4/include/media/saa7146_vv.h 2011-07-21 22:17:23.000000000 -0400
57635+++ linux-3.0.4/include/media/saa7146_vv.h 2011-08-24 18:26:09.000000000 -0400
57636@@ -163,7 +163,7 @@ struct saa7146_ext_vv
57637 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
57638
57639 /* the extension can override this */
57640- struct v4l2_ioctl_ops ops;
57641+ v4l2_ioctl_ops_no_const ops;
57642 /* pointer to the saa7146 core ops */
57643 const struct v4l2_ioctl_ops *core_ops;
57644
57645diff -urNp linux-3.0.4/include/media/v4l2-ioctl.h linux-3.0.4/include/media/v4l2-ioctl.h
57646--- linux-3.0.4/include/media/v4l2-ioctl.h 2011-07-21 22:17:23.000000000 -0400
57647+++ linux-3.0.4/include/media/v4l2-ioctl.h 2011-08-24 18:25:45.000000000 -0400
57648@@ -272,6 +272,7 @@ struct v4l2_ioctl_ops {
57649 long (*vidioc_default) (struct file *file, void *fh,
57650 bool valid_prio, int cmd, void *arg);
57651 };
57652+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
57653
57654
57655 /* v4l debugging and diagnostics */
57656diff -urNp linux-3.0.4/include/net/caif/cfctrl.h linux-3.0.4/include/net/caif/cfctrl.h
57657--- linux-3.0.4/include/net/caif/cfctrl.h 2011-07-21 22:17:23.000000000 -0400
57658+++ linux-3.0.4/include/net/caif/cfctrl.h 2011-08-23 21:47:56.000000000 -0400
57659@@ -52,7 +52,7 @@ struct cfctrl_rsp {
57660 void (*radioset_rsp)(void);
57661 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
57662 struct cflayer *client_layer);
57663-};
57664+} __no_const;
57665
57666 /* Link Setup Parameters for CAIF-Links. */
57667 struct cfctrl_link_param {
57668@@ -101,8 +101,8 @@ struct cfctrl_request_info {
57669 struct cfctrl {
57670 struct cfsrvl serv;
57671 struct cfctrl_rsp res;
57672- atomic_t req_seq_no;
57673- atomic_t rsp_seq_no;
57674+ atomic_unchecked_t req_seq_no;
57675+ atomic_unchecked_t rsp_seq_no;
57676 struct list_head list;
57677 /* Protects from simultaneous access to first_req list */
57678 spinlock_t info_list_lock;
57679diff -urNp linux-3.0.4/include/net/flow.h linux-3.0.4/include/net/flow.h
57680--- linux-3.0.4/include/net/flow.h 2011-07-21 22:17:23.000000000 -0400
57681+++ linux-3.0.4/include/net/flow.h 2011-08-23 21:47:56.000000000 -0400
57682@@ -188,6 +188,6 @@ extern struct flow_cache_object *flow_ca
57683 u8 dir, flow_resolve_t resolver, void *ctx);
57684
57685 extern void flow_cache_flush(void);
57686-extern atomic_t flow_cache_genid;
57687+extern atomic_unchecked_t flow_cache_genid;
57688
57689 #endif
57690diff -urNp linux-3.0.4/include/net/inetpeer.h linux-3.0.4/include/net/inetpeer.h
57691--- linux-3.0.4/include/net/inetpeer.h 2011-07-21 22:17:23.000000000 -0400
57692+++ linux-3.0.4/include/net/inetpeer.h 2011-08-23 21:47:56.000000000 -0400
57693@@ -43,8 +43,8 @@ struct inet_peer {
57694 */
57695 union {
57696 struct {
57697- atomic_t rid; /* Frag reception counter */
57698- atomic_t ip_id_count; /* IP ID for the next packet */
57699+ atomic_unchecked_t rid; /* Frag reception counter */
57700+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
57701 __u32 tcp_ts;
57702 __u32 tcp_ts_stamp;
57703 u32 metrics[RTAX_MAX];
57704@@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
57705 {
57706 more++;
57707 inet_peer_refcheck(p);
57708- return atomic_add_return(more, &p->ip_id_count) - more;
57709+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
57710 }
57711
57712 #endif /* _NET_INETPEER_H */
57713diff -urNp linux-3.0.4/include/net/ip_fib.h linux-3.0.4/include/net/ip_fib.h
57714--- linux-3.0.4/include/net/ip_fib.h 2011-07-21 22:17:23.000000000 -0400
57715+++ linux-3.0.4/include/net/ip_fib.h 2011-08-23 21:47:56.000000000 -0400
57716@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
57717
57718 #define FIB_RES_SADDR(net, res) \
57719 ((FIB_RES_NH(res).nh_saddr_genid == \
57720- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
57721+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
57722 FIB_RES_NH(res).nh_saddr : \
57723 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
57724 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
57725diff -urNp linux-3.0.4/include/net/ip_vs.h linux-3.0.4/include/net/ip_vs.h
57726--- linux-3.0.4/include/net/ip_vs.h 2011-07-21 22:17:23.000000000 -0400
57727+++ linux-3.0.4/include/net/ip_vs.h 2011-08-23 21:47:56.000000000 -0400
57728@@ -509,7 +509,7 @@ struct ip_vs_conn {
57729 struct ip_vs_conn *control; /* Master control connection */
57730 atomic_t n_control; /* Number of controlled ones */
57731 struct ip_vs_dest *dest; /* real server */
57732- atomic_t in_pkts; /* incoming packet counter */
57733+ atomic_unchecked_t in_pkts; /* incoming packet counter */
57734
57735 /* packet transmitter for different forwarding methods. If it
57736 mangles the packet, it must return NF_DROP or better NF_STOLEN,
57737@@ -647,7 +647,7 @@ struct ip_vs_dest {
57738 __be16 port; /* port number of the server */
57739 union nf_inet_addr addr; /* IP address of the server */
57740 volatile unsigned flags; /* dest status flags */
57741- atomic_t conn_flags; /* flags to copy to conn */
57742+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
57743 atomic_t weight; /* server weight */
57744
57745 atomic_t refcnt; /* reference counter */
57746diff -urNp linux-3.0.4/include/net/irda/ircomm_core.h linux-3.0.4/include/net/irda/ircomm_core.h
57747--- linux-3.0.4/include/net/irda/ircomm_core.h 2011-07-21 22:17:23.000000000 -0400
57748+++ linux-3.0.4/include/net/irda/ircomm_core.h 2011-08-23 21:47:56.000000000 -0400
57749@@ -51,7 +51,7 @@ typedef struct {
57750 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
57751 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
57752 struct ircomm_info *);
57753-} call_t;
57754+} __no_const call_t;
57755
57756 struct ircomm_cb {
57757 irda_queue_t queue;
57758diff -urNp linux-3.0.4/include/net/irda/ircomm_tty.h linux-3.0.4/include/net/irda/ircomm_tty.h
57759--- linux-3.0.4/include/net/irda/ircomm_tty.h 2011-07-21 22:17:23.000000000 -0400
57760+++ linux-3.0.4/include/net/irda/ircomm_tty.h 2011-08-23 21:47:56.000000000 -0400
57761@@ -35,6 +35,7 @@
57762 #include <linux/termios.h>
57763 #include <linux/timer.h>
57764 #include <linux/tty.h> /* struct tty_struct */
57765+#include <asm/local.h>
57766
57767 #include <net/irda/irias_object.h>
57768 #include <net/irda/ircomm_core.h>
57769@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
57770 unsigned short close_delay;
57771 unsigned short closing_wait; /* time to wait before closing */
57772
57773- int open_count;
57774- int blocked_open; /* # of blocked opens */
57775+ local_t open_count;
57776+ local_t blocked_open; /* # of blocked opens */
57777
57778 /* Protect concurent access to :
57779 * o self->open_count
57780diff -urNp linux-3.0.4/include/net/iucv/af_iucv.h linux-3.0.4/include/net/iucv/af_iucv.h
57781--- linux-3.0.4/include/net/iucv/af_iucv.h 2011-07-21 22:17:23.000000000 -0400
57782+++ linux-3.0.4/include/net/iucv/af_iucv.h 2011-08-23 21:47:56.000000000 -0400
57783@@ -87,7 +87,7 @@ struct iucv_sock {
57784 struct iucv_sock_list {
57785 struct hlist_head head;
57786 rwlock_t lock;
57787- atomic_t autobind_name;
57788+ atomic_unchecked_t autobind_name;
57789 };
57790
57791 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
57792diff -urNp linux-3.0.4/include/net/lapb.h linux-3.0.4/include/net/lapb.h
57793--- linux-3.0.4/include/net/lapb.h 2011-07-21 22:17:23.000000000 -0400
57794+++ linux-3.0.4/include/net/lapb.h 2011-08-23 21:47:56.000000000 -0400
57795@@ -95,7 +95,7 @@ struct lapb_cb {
57796 struct sk_buff_head write_queue;
57797 struct sk_buff_head ack_queue;
57798 unsigned char window;
57799- struct lapb_register_struct callbacks;
57800+ struct lapb_register_struct *callbacks;
57801
57802 /* FRMR control information */
57803 struct lapb_frame frmr_data;
57804diff -urNp linux-3.0.4/include/net/neighbour.h linux-3.0.4/include/net/neighbour.h
57805--- linux-3.0.4/include/net/neighbour.h 2011-07-21 22:17:23.000000000 -0400
57806+++ linux-3.0.4/include/net/neighbour.h 2011-08-31 18:39:25.000000000 -0400
57807@@ -124,7 +124,7 @@ struct neigh_ops {
57808 int (*connected_output)(struct sk_buff*);
57809 int (*hh_output)(struct sk_buff*);
57810 int (*queue_xmit)(struct sk_buff*);
57811-};
57812+} __do_const;
57813
57814 struct pneigh_entry {
57815 struct pneigh_entry *next;
57816diff -urNp linux-3.0.4/include/net/netlink.h linux-3.0.4/include/net/netlink.h
57817--- linux-3.0.4/include/net/netlink.h 2011-07-21 22:17:23.000000000 -0400
57818+++ linux-3.0.4/include/net/netlink.h 2011-08-23 21:47:56.000000000 -0400
57819@@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
57820 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
57821 {
57822 if (mark)
57823- skb_trim(skb, (unsigned char *) mark - skb->data);
57824+ skb_trim(skb, (const unsigned char *) mark - skb->data);
57825 }
57826
57827 /**
57828diff -urNp linux-3.0.4/include/net/netns/ipv4.h linux-3.0.4/include/net/netns/ipv4.h
57829--- linux-3.0.4/include/net/netns/ipv4.h 2011-07-21 22:17:23.000000000 -0400
57830+++ linux-3.0.4/include/net/netns/ipv4.h 2011-08-23 21:47:56.000000000 -0400
57831@@ -56,8 +56,8 @@ struct netns_ipv4 {
57832
57833 unsigned int sysctl_ping_group_range[2];
57834
57835- atomic_t rt_genid;
57836- atomic_t dev_addr_genid;
57837+ atomic_unchecked_t rt_genid;
57838+ atomic_unchecked_t dev_addr_genid;
57839
57840 #ifdef CONFIG_IP_MROUTE
57841 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
57842diff -urNp linux-3.0.4/include/net/sctp/sctp.h linux-3.0.4/include/net/sctp/sctp.h
57843--- linux-3.0.4/include/net/sctp/sctp.h 2011-07-21 22:17:23.000000000 -0400
57844+++ linux-3.0.4/include/net/sctp/sctp.h 2011-08-23 21:47:56.000000000 -0400
57845@@ -315,9 +315,9 @@ do { \
57846
57847 #else /* SCTP_DEBUG */
57848
57849-#define SCTP_DEBUG_PRINTK(whatever...)
57850-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
57851-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
57852+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
57853+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
57854+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
57855 #define SCTP_ENABLE_DEBUG
57856 #define SCTP_DISABLE_DEBUG
57857 #define SCTP_ASSERT(expr, str, func)
57858diff -urNp linux-3.0.4/include/net/sock.h linux-3.0.4/include/net/sock.h
57859--- linux-3.0.4/include/net/sock.h 2011-07-21 22:17:23.000000000 -0400
57860+++ linux-3.0.4/include/net/sock.h 2011-08-23 21:47:56.000000000 -0400
57861@@ -277,7 +277,7 @@ struct sock {
57862 #ifdef CONFIG_RPS
57863 __u32 sk_rxhash;
57864 #endif
57865- atomic_t sk_drops;
57866+ atomic_unchecked_t sk_drops;
57867 int sk_rcvbuf;
57868
57869 struct sk_filter __rcu *sk_filter;
57870@@ -1390,7 +1390,7 @@ static inline void sk_nocaps_add(struct
57871 }
57872
57873 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
57874- char __user *from, char *to,
57875+ char __user *from, unsigned char *to,
57876 int copy, int offset)
57877 {
57878 if (skb->ip_summed == CHECKSUM_NONE) {
57879diff -urNp linux-3.0.4/include/net/tcp.h linux-3.0.4/include/net/tcp.h
57880--- linux-3.0.4/include/net/tcp.h 2011-07-21 22:17:23.000000000 -0400
57881+++ linux-3.0.4/include/net/tcp.h 2011-08-23 21:47:56.000000000 -0400
57882@@ -1374,8 +1374,8 @@ enum tcp_seq_states {
57883 struct tcp_seq_afinfo {
57884 char *name;
57885 sa_family_t family;
57886- struct file_operations seq_fops;
57887- struct seq_operations seq_ops;
57888+ file_operations_no_const seq_fops;
57889+ seq_operations_no_const seq_ops;
57890 };
57891
57892 struct tcp_iter_state {
57893diff -urNp linux-3.0.4/include/net/udp.h linux-3.0.4/include/net/udp.h
57894--- linux-3.0.4/include/net/udp.h 2011-07-21 22:17:23.000000000 -0400
57895+++ linux-3.0.4/include/net/udp.h 2011-08-23 21:47:56.000000000 -0400
57896@@ -234,8 +234,8 @@ struct udp_seq_afinfo {
57897 char *name;
57898 sa_family_t family;
57899 struct udp_table *udp_table;
57900- struct file_operations seq_fops;
57901- struct seq_operations seq_ops;
57902+ file_operations_no_const seq_fops;
57903+ seq_operations_no_const seq_ops;
57904 };
57905
57906 struct udp_iter_state {
57907diff -urNp linux-3.0.4/include/net/xfrm.h linux-3.0.4/include/net/xfrm.h
57908--- linux-3.0.4/include/net/xfrm.h 2011-07-21 22:17:23.000000000 -0400
57909+++ linux-3.0.4/include/net/xfrm.h 2011-08-23 21:47:56.000000000 -0400
57910@@ -505,7 +505,7 @@ struct xfrm_policy {
57911 struct timer_list timer;
57912
57913 struct flow_cache_object flo;
57914- atomic_t genid;
57915+ atomic_unchecked_t genid;
57916 u32 priority;
57917 u32 index;
57918 struct xfrm_mark mark;
57919diff -urNp linux-3.0.4/include/rdma/iw_cm.h linux-3.0.4/include/rdma/iw_cm.h
57920--- linux-3.0.4/include/rdma/iw_cm.h 2011-07-21 22:17:23.000000000 -0400
57921+++ linux-3.0.4/include/rdma/iw_cm.h 2011-08-23 21:47:56.000000000 -0400
57922@@ -120,7 +120,7 @@ struct iw_cm_verbs {
57923 int backlog);
57924
57925 int (*destroy_listen)(struct iw_cm_id *cm_id);
57926-};
57927+} __no_const;
57928
57929 /**
57930 * iw_create_cm_id - Create an IW CM identifier.
57931diff -urNp linux-3.0.4/include/scsi/libfc.h linux-3.0.4/include/scsi/libfc.h
57932--- linux-3.0.4/include/scsi/libfc.h 2011-07-21 22:17:23.000000000 -0400
57933+++ linux-3.0.4/include/scsi/libfc.h 2011-08-23 21:47:56.000000000 -0400
57934@@ -750,6 +750,7 @@ struct libfc_function_template {
57935 */
57936 void (*disc_stop_final) (struct fc_lport *);
57937 };
57938+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
57939
57940 /**
57941 * struct fc_disc - Discovery context
57942@@ -853,7 +854,7 @@ struct fc_lport {
57943 struct fc_vport *vport;
57944
57945 /* Operational Information */
57946- struct libfc_function_template tt;
57947+ libfc_function_template_no_const tt;
57948 u8 link_up;
57949 u8 qfull;
57950 enum fc_lport_state state;
57951diff -urNp linux-3.0.4/include/scsi/scsi_device.h linux-3.0.4/include/scsi/scsi_device.h
57952--- linux-3.0.4/include/scsi/scsi_device.h 2011-07-21 22:17:23.000000000 -0400
57953+++ linux-3.0.4/include/scsi/scsi_device.h 2011-08-23 21:47:56.000000000 -0400
57954@@ -161,9 +161,9 @@ struct scsi_device {
57955 unsigned int max_device_blocked; /* what device_blocked counts down from */
57956 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
57957
57958- atomic_t iorequest_cnt;
57959- atomic_t iodone_cnt;
57960- atomic_t ioerr_cnt;
57961+ atomic_unchecked_t iorequest_cnt;
57962+ atomic_unchecked_t iodone_cnt;
57963+ atomic_unchecked_t ioerr_cnt;
57964
57965 struct device sdev_gendev,
57966 sdev_dev;
57967diff -urNp linux-3.0.4/include/scsi/scsi_transport_fc.h linux-3.0.4/include/scsi/scsi_transport_fc.h
57968--- linux-3.0.4/include/scsi/scsi_transport_fc.h 2011-07-21 22:17:23.000000000 -0400
57969+++ linux-3.0.4/include/scsi/scsi_transport_fc.h 2011-08-26 19:49:56.000000000 -0400
57970@@ -711,7 +711,7 @@ struct fc_function_template {
57971 unsigned long show_host_system_hostname:1;
57972
57973 unsigned long disable_target_scan:1;
57974-};
57975+} __do_const;
57976
57977
57978 /**
57979diff -urNp linux-3.0.4/include/sound/ak4xxx-adda.h linux-3.0.4/include/sound/ak4xxx-adda.h
57980--- linux-3.0.4/include/sound/ak4xxx-adda.h 2011-07-21 22:17:23.000000000 -0400
57981+++ linux-3.0.4/include/sound/ak4xxx-adda.h 2011-08-23 21:47:56.000000000 -0400
57982@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
57983 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
57984 unsigned char val);
57985 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
57986-};
57987+} __no_const;
57988
57989 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
57990
57991diff -urNp linux-3.0.4/include/sound/hwdep.h linux-3.0.4/include/sound/hwdep.h
57992--- linux-3.0.4/include/sound/hwdep.h 2011-07-21 22:17:23.000000000 -0400
57993+++ linux-3.0.4/include/sound/hwdep.h 2011-08-23 21:47:56.000000000 -0400
57994@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
57995 struct snd_hwdep_dsp_status *status);
57996 int (*dsp_load)(struct snd_hwdep *hw,
57997 struct snd_hwdep_dsp_image *image);
57998-};
57999+} __no_const;
58000
58001 struct snd_hwdep {
58002 struct snd_card *card;
58003diff -urNp linux-3.0.4/include/sound/info.h linux-3.0.4/include/sound/info.h
58004--- linux-3.0.4/include/sound/info.h 2011-07-21 22:17:23.000000000 -0400
58005+++ linux-3.0.4/include/sound/info.h 2011-08-23 21:47:56.000000000 -0400
58006@@ -44,7 +44,7 @@ struct snd_info_entry_text {
58007 struct snd_info_buffer *buffer);
58008 void (*write)(struct snd_info_entry *entry,
58009 struct snd_info_buffer *buffer);
58010-};
58011+} __no_const;
58012
58013 struct snd_info_entry_ops {
58014 int (*open)(struct snd_info_entry *entry,
58015diff -urNp linux-3.0.4/include/sound/pcm.h linux-3.0.4/include/sound/pcm.h
58016--- linux-3.0.4/include/sound/pcm.h 2011-07-21 22:17:23.000000000 -0400
58017+++ linux-3.0.4/include/sound/pcm.h 2011-08-23 21:47:56.000000000 -0400
58018@@ -81,6 +81,7 @@ struct snd_pcm_ops {
58019 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
58020 int (*ack)(struct snd_pcm_substream *substream);
58021 };
58022+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
58023
58024 /*
58025 *
58026diff -urNp linux-3.0.4/include/sound/sb16_csp.h linux-3.0.4/include/sound/sb16_csp.h
58027--- linux-3.0.4/include/sound/sb16_csp.h 2011-07-21 22:17:23.000000000 -0400
58028+++ linux-3.0.4/include/sound/sb16_csp.h 2011-08-23 21:47:56.000000000 -0400
58029@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
58030 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
58031 int (*csp_stop) (struct snd_sb_csp * p);
58032 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
58033-};
58034+} __no_const;
58035
58036 /*
58037 * CSP private data
58038diff -urNp linux-3.0.4/include/sound/soc.h linux-3.0.4/include/sound/soc.h
58039--- linux-3.0.4/include/sound/soc.h 2011-07-21 22:17:23.000000000 -0400
58040+++ linux-3.0.4/include/sound/soc.h 2011-08-26 19:49:56.000000000 -0400
58041@@ -636,7 +636,7 @@ struct snd_soc_platform_driver {
58042
58043 /* platform stream ops */
58044 struct snd_pcm_ops *ops;
58045-};
58046+} __do_const;
58047
58048 struct snd_soc_platform {
58049 const char *name;
58050diff -urNp linux-3.0.4/include/sound/ymfpci.h linux-3.0.4/include/sound/ymfpci.h
58051--- linux-3.0.4/include/sound/ymfpci.h 2011-07-21 22:17:23.000000000 -0400
58052+++ linux-3.0.4/include/sound/ymfpci.h 2011-08-23 21:47:56.000000000 -0400
58053@@ -358,7 +358,7 @@ struct snd_ymfpci {
58054 spinlock_t reg_lock;
58055 spinlock_t voice_lock;
58056 wait_queue_head_t interrupt_sleep;
58057- atomic_t interrupt_sleep_count;
58058+ atomic_unchecked_t interrupt_sleep_count;
58059 struct snd_info_entry *proc_entry;
58060 const struct firmware *dsp_microcode;
58061 const struct firmware *controller_microcode;
58062diff -urNp linux-3.0.4/include/target/target_core_base.h linux-3.0.4/include/target/target_core_base.h
58063--- linux-3.0.4/include/target/target_core_base.h 2011-07-21 22:17:23.000000000 -0400
58064+++ linux-3.0.4/include/target/target_core_base.h 2011-08-23 21:47:56.000000000 -0400
58065@@ -364,7 +364,7 @@ struct t10_reservation_ops {
58066 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
58067 int (*t10_pr_register)(struct se_cmd *);
58068 int (*t10_pr_clear)(struct se_cmd *);
58069-};
58070+} __no_const;
58071
58072 struct t10_reservation_template {
58073 /* Reservation effects all target ports */
58074@@ -432,8 +432,8 @@ struct se_transport_task {
58075 atomic_t t_task_cdbs_left;
58076 atomic_t t_task_cdbs_ex_left;
58077 atomic_t t_task_cdbs_timeout_left;
58078- atomic_t t_task_cdbs_sent;
58079- atomic_t t_transport_aborted;
58080+ atomic_unchecked_t t_task_cdbs_sent;
58081+ atomic_unchecked_t t_transport_aborted;
58082 atomic_t t_transport_active;
58083 atomic_t t_transport_complete;
58084 atomic_t t_transport_queue_active;
58085@@ -774,7 +774,7 @@ struct se_device {
58086 atomic_t active_cmds;
58087 atomic_t simple_cmds;
58088 atomic_t depth_left;
58089- atomic_t dev_ordered_id;
58090+ atomic_unchecked_t dev_ordered_id;
58091 atomic_t dev_tur_active;
58092 atomic_t execute_tasks;
58093 atomic_t dev_status_thr_count;
58094diff -urNp linux-3.0.4/include/trace/events/irq.h linux-3.0.4/include/trace/events/irq.h
58095--- linux-3.0.4/include/trace/events/irq.h 2011-07-21 22:17:23.000000000 -0400
58096+++ linux-3.0.4/include/trace/events/irq.h 2011-08-23 21:47:56.000000000 -0400
58097@@ -36,7 +36,7 @@ struct softirq_action;
58098 */
58099 TRACE_EVENT(irq_handler_entry,
58100
58101- TP_PROTO(int irq, struct irqaction *action),
58102+ TP_PROTO(int irq, const struct irqaction *action),
58103
58104 TP_ARGS(irq, action),
58105
58106@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
58107 */
58108 TRACE_EVENT(irq_handler_exit,
58109
58110- TP_PROTO(int irq, struct irqaction *action, int ret),
58111+ TP_PROTO(int irq, const struct irqaction *action, int ret),
58112
58113 TP_ARGS(irq, action, ret),
58114
58115diff -urNp linux-3.0.4/include/video/udlfb.h linux-3.0.4/include/video/udlfb.h
58116--- linux-3.0.4/include/video/udlfb.h 2011-07-21 22:17:23.000000000 -0400
58117+++ linux-3.0.4/include/video/udlfb.h 2011-08-23 21:47:56.000000000 -0400
58118@@ -51,10 +51,10 @@ struct dlfb_data {
58119 int base8;
58120 u32 pseudo_palette[256];
58121 /* blit-only rendering path metrics, exposed through sysfs */
58122- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
58123- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
58124- atomic_t bytes_sent; /* to usb, after compression including overhead */
58125- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
58126+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
58127+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
58128+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
58129+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
58130 };
58131
58132 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
58133diff -urNp linux-3.0.4/include/video/uvesafb.h linux-3.0.4/include/video/uvesafb.h
58134--- linux-3.0.4/include/video/uvesafb.h 2011-07-21 22:17:23.000000000 -0400
58135+++ linux-3.0.4/include/video/uvesafb.h 2011-08-23 21:47:56.000000000 -0400
58136@@ -177,6 +177,7 @@ struct uvesafb_par {
58137 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
58138 u8 pmi_setpal; /* PMI for palette changes */
58139 u16 *pmi_base; /* protected mode interface location */
58140+ u8 *pmi_code; /* protected mode code location */
58141 void *pmi_start;
58142 void *pmi_pal;
58143 u8 *vbe_state_orig; /*
58144diff -urNp linux-3.0.4/init/do_mounts.c linux-3.0.4/init/do_mounts.c
58145--- linux-3.0.4/init/do_mounts.c 2011-07-21 22:17:23.000000000 -0400
58146+++ linux-3.0.4/init/do_mounts.c 2011-08-23 21:47:56.000000000 -0400
58147@@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
58148
58149 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
58150 {
58151- int err = sys_mount(name, "/root", fs, flags, data);
58152+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
58153 if (err)
58154 return err;
58155
58156@@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
58157 va_start(args, fmt);
58158 vsprintf(buf, fmt, args);
58159 va_end(args);
58160- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
58161+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
58162 if (fd >= 0) {
58163 sys_ioctl(fd, FDEJECT, 0);
58164 sys_close(fd);
58165 }
58166 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
58167- fd = sys_open("/dev/console", O_RDWR, 0);
58168+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
58169 if (fd >= 0) {
58170 sys_ioctl(fd, TCGETS, (long)&termios);
58171 termios.c_lflag &= ~ICANON;
58172 sys_ioctl(fd, TCSETSF, (long)&termios);
58173- sys_read(fd, &c, 1);
58174+ sys_read(fd, (char __user *)&c, 1);
58175 termios.c_lflag |= ICANON;
58176 sys_ioctl(fd, TCSETSF, (long)&termios);
58177 sys_close(fd);
58178@@ -488,6 +488,6 @@ void __init prepare_namespace(void)
58179 mount_root();
58180 out:
58181 devtmpfs_mount("dev");
58182- sys_mount(".", "/", NULL, MS_MOVE, NULL);
58183+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
58184 sys_chroot((const char __user __force *)".");
58185 }
58186diff -urNp linux-3.0.4/init/do_mounts.h linux-3.0.4/init/do_mounts.h
58187--- linux-3.0.4/init/do_mounts.h 2011-07-21 22:17:23.000000000 -0400
58188+++ linux-3.0.4/init/do_mounts.h 2011-08-23 21:47:56.000000000 -0400
58189@@ -15,15 +15,15 @@ extern int root_mountflags;
58190
58191 static inline int create_dev(char *name, dev_t dev)
58192 {
58193- sys_unlink(name);
58194- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
58195+ sys_unlink((__force char __user *)name);
58196+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
58197 }
58198
58199 #if BITS_PER_LONG == 32
58200 static inline u32 bstat(char *name)
58201 {
58202 struct stat64 stat;
58203- if (sys_stat64(name, &stat) != 0)
58204+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
58205 return 0;
58206 if (!S_ISBLK(stat.st_mode))
58207 return 0;
58208diff -urNp linux-3.0.4/init/do_mounts_initrd.c linux-3.0.4/init/do_mounts_initrd.c
58209--- linux-3.0.4/init/do_mounts_initrd.c 2011-07-21 22:17:23.000000000 -0400
58210+++ linux-3.0.4/init/do_mounts_initrd.c 2011-08-23 21:47:56.000000000 -0400
58211@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
58212 create_dev("/dev/root.old", Root_RAM0);
58213 /* mount initrd on rootfs' /root */
58214 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
58215- sys_mkdir("/old", 0700);
58216- root_fd = sys_open("/", 0, 0);
58217- old_fd = sys_open("/old", 0, 0);
58218+ sys_mkdir((__force const char __user *)"/old", 0700);
58219+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
58220+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
58221 /* move initrd over / and chdir/chroot in initrd root */
58222- sys_chdir("/root");
58223- sys_mount(".", "/", NULL, MS_MOVE, NULL);
58224- sys_chroot(".");
58225+ sys_chdir((__force const char __user *)"/root");
58226+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
58227+ sys_chroot((__force const char __user *)".");
58228
58229 /*
58230 * In case that a resume from disk is carried out by linuxrc or one of
58231@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
58232
58233 /* move initrd to rootfs' /old */
58234 sys_fchdir(old_fd);
58235- sys_mount("/", ".", NULL, MS_MOVE, NULL);
58236+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
58237 /* switch root and cwd back to / of rootfs */
58238 sys_fchdir(root_fd);
58239- sys_chroot(".");
58240+ sys_chroot((__force const char __user *)".");
58241 sys_close(old_fd);
58242 sys_close(root_fd);
58243
58244 if (new_decode_dev(real_root_dev) == Root_RAM0) {
58245- sys_chdir("/old");
58246+ sys_chdir((__force const char __user *)"/old");
58247 return;
58248 }
58249
58250@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
58251 mount_root();
58252
58253 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
58254- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
58255+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
58256 if (!error)
58257 printk("okay\n");
58258 else {
58259- int fd = sys_open("/dev/root.old", O_RDWR, 0);
58260+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
58261 if (error == -ENOENT)
58262 printk("/initrd does not exist. Ignored.\n");
58263 else
58264 printk("failed\n");
58265 printk(KERN_NOTICE "Unmounting old root\n");
58266- sys_umount("/old", MNT_DETACH);
58267+ sys_umount((__force char __user *)"/old", MNT_DETACH);
58268 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
58269 if (fd < 0) {
58270 error = fd;
58271@@ -116,11 +116,11 @@ int __init initrd_load(void)
58272 * mounted in the normal path.
58273 */
58274 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
58275- sys_unlink("/initrd.image");
58276+ sys_unlink((__force const char __user *)"/initrd.image");
58277 handle_initrd();
58278 return 1;
58279 }
58280 }
58281- sys_unlink("/initrd.image");
58282+ sys_unlink((__force const char __user *)"/initrd.image");
58283 return 0;
58284 }
58285diff -urNp linux-3.0.4/init/do_mounts_md.c linux-3.0.4/init/do_mounts_md.c
58286--- linux-3.0.4/init/do_mounts_md.c 2011-07-21 22:17:23.000000000 -0400
58287+++ linux-3.0.4/init/do_mounts_md.c 2011-08-23 21:47:56.000000000 -0400
58288@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
58289 partitioned ? "_d" : "", minor,
58290 md_setup_args[ent].device_names);
58291
58292- fd = sys_open(name, 0, 0);
58293+ fd = sys_open((__force char __user *)name, 0, 0);
58294 if (fd < 0) {
58295 printk(KERN_ERR "md: open failed - cannot start "
58296 "array %s\n", name);
58297@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
58298 * array without it
58299 */
58300 sys_close(fd);
58301- fd = sys_open(name, 0, 0);
58302+ fd = sys_open((__force char __user *)name, 0, 0);
58303 sys_ioctl(fd, BLKRRPART, 0);
58304 }
58305 sys_close(fd);
58306diff -urNp linux-3.0.4/init/initramfs.c linux-3.0.4/init/initramfs.c
58307--- linux-3.0.4/init/initramfs.c 2011-07-21 22:17:23.000000000 -0400
58308+++ linux-3.0.4/init/initramfs.c 2011-08-23 21:47:56.000000000 -0400
58309@@ -74,7 +74,7 @@ static void __init free_hash(void)
58310 }
58311 }
58312
58313-static long __init do_utime(char __user *filename, time_t mtime)
58314+static long __init do_utime(__force char __user *filename, time_t mtime)
58315 {
58316 struct timespec t[2];
58317
58318@@ -109,7 +109,7 @@ static void __init dir_utime(void)
58319 struct dir_entry *de, *tmp;
58320 list_for_each_entry_safe(de, tmp, &dir_list, list) {
58321 list_del(&de->list);
58322- do_utime(de->name, de->mtime);
58323+ do_utime((__force char __user *)de->name, de->mtime);
58324 kfree(de->name);
58325 kfree(de);
58326 }
58327@@ -271,7 +271,7 @@ static int __init maybe_link(void)
58328 if (nlink >= 2) {
58329 char *old = find_link(major, minor, ino, mode, collected);
58330 if (old)
58331- return (sys_link(old, collected) < 0) ? -1 : 1;
58332+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
58333 }
58334 return 0;
58335 }
58336@@ -280,11 +280,11 @@ static void __init clean_path(char *path
58337 {
58338 struct stat st;
58339
58340- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
58341+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
58342 if (S_ISDIR(st.st_mode))
58343- sys_rmdir(path);
58344+ sys_rmdir((__force char __user *)path);
58345 else
58346- sys_unlink(path);
58347+ sys_unlink((__force char __user *)path);
58348 }
58349 }
58350
58351@@ -305,7 +305,7 @@ static int __init do_name(void)
58352 int openflags = O_WRONLY|O_CREAT;
58353 if (ml != 1)
58354 openflags |= O_TRUNC;
58355- wfd = sys_open(collected, openflags, mode);
58356+ wfd = sys_open((__force char __user *)collected, openflags, mode);
58357
58358 if (wfd >= 0) {
58359 sys_fchown(wfd, uid, gid);
58360@@ -317,17 +317,17 @@ static int __init do_name(void)
58361 }
58362 }
58363 } else if (S_ISDIR(mode)) {
58364- sys_mkdir(collected, mode);
58365- sys_chown(collected, uid, gid);
58366- sys_chmod(collected, mode);
58367+ sys_mkdir((__force char __user *)collected, mode);
58368+ sys_chown((__force char __user *)collected, uid, gid);
58369+ sys_chmod((__force char __user *)collected, mode);
58370 dir_add(collected, mtime);
58371 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
58372 S_ISFIFO(mode) || S_ISSOCK(mode)) {
58373 if (maybe_link() == 0) {
58374- sys_mknod(collected, mode, rdev);
58375- sys_chown(collected, uid, gid);
58376- sys_chmod(collected, mode);
58377- do_utime(collected, mtime);
58378+ sys_mknod((__force char __user *)collected, mode, rdev);
58379+ sys_chown((__force char __user *)collected, uid, gid);
58380+ sys_chmod((__force char __user *)collected, mode);
58381+ do_utime((__force char __user *)collected, mtime);
58382 }
58383 }
58384 return 0;
58385@@ -336,15 +336,15 @@ static int __init do_name(void)
58386 static int __init do_copy(void)
58387 {
58388 if (count >= body_len) {
58389- sys_write(wfd, victim, body_len);
58390+ sys_write(wfd, (__force char __user *)victim, body_len);
58391 sys_close(wfd);
58392- do_utime(vcollected, mtime);
58393+ do_utime((__force char __user *)vcollected, mtime);
58394 kfree(vcollected);
58395 eat(body_len);
58396 state = SkipIt;
58397 return 0;
58398 } else {
58399- sys_write(wfd, victim, count);
58400+ sys_write(wfd, (__force char __user *)victim, count);
58401 body_len -= count;
58402 eat(count);
58403 return 1;
58404@@ -355,9 +355,9 @@ static int __init do_symlink(void)
58405 {
58406 collected[N_ALIGN(name_len) + body_len] = '\0';
58407 clean_path(collected, 0);
58408- sys_symlink(collected + N_ALIGN(name_len), collected);
58409- sys_lchown(collected, uid, gid);
58410- do_utime(collected, mtime);
58411+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
58412+ sys_lchown((__force char __user *)collected, uid, gid);
58413+ do_utime((__force char __user *)collected, mtime);
58414 state = SkipIt;
58415 next_state = Reset;
58416 return 0;
58417diff -urNp linux-3.0.4/init/Kconfig linux-3.0.4/init/Kconfig
58418--- linux-3.0.4/init/Kconfig 2011-07-21 22:17:23.000000000 -0400
58419+++ linux-3.0.4/init/Kconfig 2011-08-23 21:47:56.000000000 -0400
58420@@ -1195,7 +1195,7 @@ config SLUB_DEBUG
58421
58422 config COMPAT_BRK
58423 bool "Disable heap randomization"
58424- default y
58425+ default n
58426 help
58427 Randomizing heap placement makes heap exploits harder, but it
58428 also breaks ancient binaries (including anything libc5 based).
58429diff -urNp linux-3.0.4/init/main.c linux-3.0.4/init/main.c
58430--- linux-3.0.4/init/main.c 2011-07-21 22:17:23.000000000 -0400
58431+++ linux-3.0.4/init/main.c 2011-08-23 21:48:14.000000000 -0400
58432@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
58433 extern void tc_init(void);
58434 #endif
58435
58436+extern void grsecurity_init(void);
58437+
58438 /*
58439 * Debug helper: via this flag we know that we are in 'early bootup code'
58440 * where only the boot processor is running with IRQ disabled. This means
58441@@ -149,6 +151,49 @@ static int __init set_reset_devices(char
58442
58443 __setup("reset_devices", set_reset_devices);
58444
58445+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
58446+extern char pax_enter_kernel_user[];
58447+extern char pax_exit_kernel_user[];
58448+extern pgdval_t clone_pgd_mask;
58449+#endif
58450+
58451+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
58452+static int __init setup_pax_nouderef(char *str)
58453+{
58454+#ifdef CONFIG_X86_32
58455+ unsigned int cpu;
58456+ struct desc_struct *gdt;
58457+
58458+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
58459+ gdt = get_cpu_gdt_table(cpu);
58460+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
58461+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
58462+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
58463+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
58464+ }
58465+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
58466+#else
58467+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
58468+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
58469+ clone_pgd_mask = ~(pgdval_t)0UL;
58470+#endif
58471+
58472+ return 0;
58473+}
58474+early_param("pax_nouderef", setup_pax_nouderef);
58475+#endif
58476+
58477+#ifdef CONFIG_PAX_SOFTMODE
58478+int pax_softmode;
58479+
58480+static int __init setup_pax_softmode(char *str)
58481+{
58482+ get_option(&str, &pax_softmode);
58483+ return 1;
58484+}
58485+__setup("pax_softmode=", setup_pax_softmode);
58486+#endif
58487+
58488 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
58489 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
58490 static const char *panic_later, *panic_param;
58491@@ -667,6 +712,7 @@ int __init_or_module do_one_initcall(ini
58492 {
58493 int count = preempt_count();
58494 int ret;
58495+ const char *msg1 = "", *msg2 = "";
58496
58497 if (initcall_debug)
58498 ret = do_one_initcall_debug(fn);
58499@@ -679,15 +725,15 @@ int __init_or_module do_one_initcall(ini
58500 sprintf(msgbuf, "error code %d ", ret);
58501
58502 if (preempt_count() != count) {
58503- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
58504+ msg1 = " preemption imbalance";
58505 preempt_count() = count;
58506 }
58507 if (irqs_disabled()) {
58508- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
58509+ msg2 = " disabled interrupts";
58510 local_irq_enable();
58511 }
58512- if (msgbuf[0]) {
58513- printk("initcall %pF returned with %s\n", fn, msgbuf);
58514+ if (msgbuf[0] || *msg1 || *msg2) {
58515+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
58516 }
58517
58518 return ret;
58519@@ -805,7 +851,7 @@ static int __init kernel_init(void * unu
58520 do_basic_setup();
58521
58522 /* Open the /dev/console on the rootfs, this should never fail */
58523- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
58524+ if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
58525 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
58526
58527 (void) sys_dup(0);
58528@@ -818,11 +864,13 @@ static int __init kernel_init(void * unu
58529 if (!ramdisk_execute_command)
58530 ramdisk_execute_command = "/init";
58531
58532- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
58533+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
58534 ramdisk_execute_command = NULL;
58535 prepare_namespace();
58536 }
58537
58538+ grsecurity_init();
58539+
58540 /*
58541 * Ok, we have completed the initial bootup, and
58542 * we're essentially up and running. Get rid of the
58543diff -urNp linux-3.0.4/ipc/mqueue.c linux-3.0.4/ipc/mqueue.c
58544--- linux-3.0.4/ipc/mqueue.c 2011-07-21 22:17:23.000000000 -0400
58545+++ linux-3.0.4/ipc/mqueue.c 2011-08-23 21:48:14.000000000 -0400
58546@@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
58547 mq_bytes = (mq_msg_tblsz +
58548 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
58549
58550+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
58551 spin_lock(&mq_lock);
58552 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
58553 u->mq_bytes + mq_bytes >
58554diff -urNp linux-3.0.4/ipc/msg.c linux-3.0.4/ipc/msg.c
58555--- linux-3.0.4/ipc/msg.c 2011-07-21 22:17:23.000000000 -0400
58556+++ linux-3.0.4/ipc/msg.c 2011-08-23 21:47:56.000000000 -0400
58557@@ -309,18 +309,19 @@ static inline int msg_security(struct ke
58558 return security_msg_queue_associate(msq, msgflg);
58559 }
58560
58561+static struct ipc_ops msg_ops = {
58562+ .getnew = newque,
58563+ .associate = msg_security,
58564+ .more_checks = NULL
58565+};
58566+
58567 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
58568 {
58569 struct ipc_namespace *ns;
58570- struct ipc_ops msg_ops;
58571 struct ipc_params msg_params;
58572
58573 ns = current->nsproxy->ipc_ns;
58574
58575- msg_ops.getnew = newque;
58576- msg_ops.associate = msg_security;
58577- msg_ops.more_checks = NULL;
58578-
58579 msg_params.key = key;
58580 msg_params.flg = msgflg;
58581
58582diff -urNp linux-3.0.4/ipc/sem.c linux-3.0.4/ipc/sem.c
58583--- linux-3.0.4/ipc/sem.c 2011-08-23 21:44:40.000000000 -0400
58584+++ linux-3.0.4/ipc/sem.c 2011-08-23 21:48:14.000000000 -0400
58585@@ -318,10 +318,15 @@ static inline int sem_more_checks(struct
58586 return 0;
58587 }
58588
58589+static struct ipc_ops sem_ops = {
58590+ .getnew = newary,
58591+ .associate = sem_security,
58592+ .more_checks = sem_more_checks
58593+};
58594+
58595 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
58596 {
58597 struct ipc_namespace *ns;
58598- struct ipc_ops sem_ops;
58599 struct ipc_params sem_params;
58600
58601 ns = current->nsproxy->ipc_ns;
58602@@ -329,10 +334,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int,
58603 if (nsems < 0 || nsems > ns->sc_semmsl)
58604 return -EINVAL;
58605
58606- sem_ops.getnew = newary;
58607- sem_ops.associate = sem_security;
58608- sem_ops.more_checks = sem_more_checks;
58609-
58610 sem_params.key = key;
58611 sem_params.flg = semflg;
58612 sem_params.u.nsems = nsems;
58613@@ -854,6 +855,8 @@ static int semctl_main(struct ipc_namesp
58614 int nsems;
58615 struct list_head tasks;
58616
58617+ pax_track_stack();
58618+
58619 sma = sem_lock_check(ns, semid);
58620 if (IS_ERR(sma))
58621 return PTR_ERR(sma);
58622@@ -1301,6 +1304,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
58623 struct ipc_namespace *ns;
58624 struct list_head tasks;
58625
58626+ pax_track_stack();
58627+
58628 ns = current->nsproxy->ipc_ns;
58629
58630 if (nsops < 1 || semid < 0)
58631diff -urNp linux-3.0.4/ipc/shm.c linux-3.0.4/ipc/shm.c
58632--- linux-3.0.4/ipc/shm.c 2011-07-21 22:17:23.000000000 -0400
58633+++ linux-3.0.4/ipc/shm.c 2011-08-23 21:48:14.000000000 -0400
58634@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
58635 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
58636 #endif
58637
58638+#ifdef CONFIG_GRKERNSEC
58639+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58640+ const time_t shm_createtime, const uid_t cuid,
58641+ const int shmid);
58642+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58643+ const time_t shm_createtime);
58644+#endif
58645+
58646 void shm_init_ns(struct ipc_namespace *ns)
58647 {
58648 ns->shm_ctlmax = SHMMAX;
58649@@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
58650 shp->shm_lprid = 0;
58651 shp->shm_atim = shp->shm_dtim = 0;
58652 shp->shm_ctim = get_seconds();
58653+#ifdef CONFIG_GRKERNSEC
58654+ {
58655+ struct timespec timeval;
58656+ do_posix_clock_monotonic_gettime(&timeval);
58657+
58658+ shp->shm_createtime = timeval.tv_sec;
58659+ }
58660+#endif
58661 shp->shm_segsz = size;
58662 shp->shm_nattch = 0;
58663 shp->shm_file = file;
58664@@ -451,18 +467,19 @@ static inline int shm_more_checks(struct
58665 return 0;
58666 }
58667
58668+static struct ipc_ops shm_ops = {
58669+ .getnew = newseg,
58670+ .associate = shm_security,
58671+ .more_checks = shm_more_checks
58672+};
58673+
58674 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
58675 {
58676 struct ipc_namespace *ns;
58677- struct ipc_ops shm_ops;
58678 struct ipc_params shm_params;
58679
58680 ns = current->nsproxy->ipc_ns;
58681
58682- shm_ops.getnew = newseg;
58683- shm_ops.associate = shm_security;
58684- shm_ops.more_checks = shm_more_checks;
58685-
58686 shm_params.key = key;
58687 shm_params.flg = shmflg;
58688 shm_params.u.size = size;
58689@@ -762,8 +779,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
58690 case SHM_LOCK:
58691 case SHM_UNLOCK:
58692 {
58693- struct file *uninitialized_var(shm_file);
58694-
58695 lru_add_drain_all(); /* drain pagevecs to lru lists */
58696
58697 shp = shm_lock_check(ns, shmid);
58698@@ -896,9 +911,21 @@ long do_shmat(int shmid, char __user *sh
58699 if (err)
58700 goto out_unlock;
58701
58702+#ifdef CONFIG_GRKERNSEC
58703+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
58704+ shp->shm_perm.cuid, shmid) ||
58705+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
58706+ err = -EACCES;
58707+ goto out_unlock;
58708+ }
58709+#endif
58710+
58711 path = shp->shm_file->f_path;
58712 path_get(&path);
58713 shp->shm_nattch++;
58714+#ifdef CONFIG_GRKERNSEC
58715+ shp->shm_lapid = current->pid;
58716+#endif
58717 size = i_size_read(path.dentry->d_inode);
58718 shm_unlock(shp);
58719
58720diff -urNp linux-3.0.4/kernel/acct.c linux-3.0.4/kernel/acct.c
58721--- linux-3.0.4/kernel/acct.c 2011-07-21 22:17:23.000000000 -0400
58722+++ linux-3.0.4/kernel/acct.c 2011-08-23 21:47:56.000000000 -0400
58723@@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
58724 */
58725 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
58726 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
58727- file->f_op->write(file, (char *)&ac,
58728+ file->f_op->write(file, (__force char __user *)&ac,
58729 sizeof(acct_t), &file->f_pos);
58730 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
58731 set_fs(fs);
58732diff -urNp linux-3.0.4/kernel/audit.c linux-3.0.4/kernel/audit.c
58733--- linux-3.0.4/kernel/audit.c 2011-07-21 22:17:23.000000000 -0400
58734+++ linux-3.0.4/kernel/audit.c 2011-08-23 21:47:56.000000000 -0400
58735@@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
58736 3) suppressed due to audit_rate_limit
58737 4) suppressed due to audit_backlog_limit
58738 */
58739-static atomic_t audit_lost = ATOMIC_INIT(0);
58740+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
58741
58742 /* The netlink socket. */
58743 static struct sock *audit_sock;
58744@@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
58745 unsigned long now;
58746 int print;
58747
58748- atomic_inc(&audit_lost);
58749+ atomic_inc_unchecked(&audit_lost);
58750
58751 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
58752
58753@@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
58754 printk(KERN_WARNING
58755 "audit: audit_lost=%d audit_rate_limit=%d "
58756 "audit_backlog_limit=%d\n",
58757- atomic_read(&audit_lost),
58758+ atomic_read_unchecked(&audit_lost),
58759 audit_rate_limit,
58760 audit_backlog_limit);
58761 audit_panic(message);
58762@@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
58763 status_set.pid = audit_pid;
58764 status_set.rate_limit = audit_rate_limit;
58765 status_set.backlog_limit = audit_backlog_limit;
58766- status_set.lost = atomic_read(&audit_lost);
58767+ status_set.lost = atomic_read_unchecked(&audit_lost);
58768 status_set.backlog = skb_queue_len(&audit_skb_queue);
58769 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
58770 &status_set, sizeof(status_set));
58771diff -urNp linux-3.0.4/kernel/auditsc.c linux-3.0.4/kernel/auditsc.c
58772--- linux-3.0.4/kernel/auditsc.c 2011-07-21 22:17:23.000000000 -0400
58773+++ linux-3.0.4/kernel/auditsc.c 2011-08-23 21:47:56.000000000 -0400
58774@@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_conte
58775 }
58776
58777 /* global counter which is incremented every time something logs in */
58778-static atomic_t session_id = ATOMIC_INIT(0);
58779+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
58780
58781 /**
58782 * audit_set_loginuid - set a task's audit_context loginuid
58783@@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT
58784 */
58785 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
58786 {
58787- unsigned int sessionid = atomic_inc_return(&session_id);
58788+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
58789 struct audit_context *context = task->audit_context;
58790
58791 if (context && context->in_syscall) {
58792diff -urNp linux-3.0.4/kernel/capability.c linux-3.0.4/kernel/capability.c
58793--- linux-3.0.4/kernel/capability.c 2011-07-21 22:17:23.000000000 -0400
58794+++ linux-3.0.4/kernel/capability.c 2011-08-23 21:48:14.000000000 -0400
58795@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
58796 * before modification is attempted and the application
58797 * fails.
58798 */
58799+ if (tocopy > ARRAY_SIZE(kdata))
58800+ return -EFAULT;
58801+
58802 if (copy_to_user(dataptr, kdata, tocopy
58803 * sizeof(struct __user_cap_data_struct))) {
58804 return -EFAULT;
58805@@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *n
58806 BUG();
58807 }
58808
58809- if (security_capable(ns, current_cred(), cap) == 0) {
58810+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
58811 current->flags |= PF_SUPERPRIV;
58812 return true;
58813 }
58814@@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *n
58815 }
58816 EXPORT_SYMBOL(ns_capable);
58817
58818+bool ns_capable_nolog(struct user_namespace *ns, int cap)
58819+{
58820+ if (unlikely(!cap_valid(cap))) {
58821+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
58822+ BUG();
58823+ }
58824+
58825+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
58826+ current->flags |= PF_SUPERPRIV;
58827+ return true;
58828+ }
58829+ return false;
58830+}
58831+EXPORT_SYMBOL(ns_capable_nolog);
58832+
58833+bool capable_nolog(int cap)
58834+{
58835+ return ns_capable_nolog(&init_user_ns, cap);
58836+}
58837+EXPORT_SYMBOL(capable_nolog);
58838+
58839 /**
58840 * task_ns_capable - Determine whether current task has a superior
58841 * capability targeted at a specific task's user namespace.
58842@@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct
58843 }
58844 EXPORT_SYMBOL(task_ns_capable);
58845
58846+bool task_ns_capable_nolog(struct task_struct *t, int cap)
58847+{
58848+ return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
58849+}
58850+EXPORT_SYMBOL(task_ns_capable_nolog);
58851+
58852 /**
58853 * nsown_capable - Check superior capability to one's own user_ns
58854 * @cap: The capability in question
58855diff -urNp linux-3.0.4/kernel/cgroup.c linux-3.0.4/kernel/cgroup.c
58856--- linux-3.0.4/kernel/cgroup.c 2011-07-21 22:17:23.000000000 -0400
58857+++ linux-3.0.4/kernel/cgroup.c 2011-08-23 21:48:14.000000000 -0400
58858@@ -593,6 +593,8 @@ static struct css_set *find_css_set(
58859 struct hlist_head *hhead;
58860 struct cg_cgroup_link *link;
58861
58862+ pax_track_stack();
58863+
58864 /* First see if we already have a cgroup group that matches
58865 * the desired set */
58866 read_lock(&css_set_lock);
58867diff -urNp linux-3.0.4/kernel/compat.c linux-3.0.4/kernel/compat.c
58868--- linux-3.0.4/kernel/compat.c 2011-07-21 22:17:23.000000000 -0400
58869+++ linux-3.0.4/kernel/compat.c 2011-08-23 21:48:14.000000000 -0400
58870@@ -13,6 +13,7 @@
58871
58872 #include <linux/linkage.h>
58873 #include <linux/compat.h>
58874+#include <linux/module.h>
58875 #include <linux/errno.h>
58876 #include <linux/time.h>
58877 #include <linux/signal.h>
58878diff -urNp linux-3.0.4/kernel/configs.c linux-3.0.4/kernel/configs.c
58879--- linux-3.0.4/kernel/configs.c 2011-07-21 22:17:23.000000000 -0400
58880+++ linux-3.0.4/kernel/configs.c 2011-08-23 21:48:14.000000000 -0400
58881@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
58882 struct proc_dir_entry *entry;
58883
58884 /* create the current config file */
58885+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
58886+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
58887+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
58888+ &ikconfig_file_ops);
58889+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58890+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
58891+ &ikconfig_file_ops);
58892+#endif
58893+#else
58894 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
58895 &ikconfig_file_ops);
58896+#endif
58897+
58898 if (!entry)
58899 return -ENOMEM;
58900
58901diff -urNp linux-3.0.4/kernel/cred.c linux-3.0.4/kernel/cred.c
58902--- linux-3.0.4/kernel/cred.c 2011-07-21 22:17:23.000000000 -0400
58903+++ linux-3.0.4/kernel/cred.c 2011-08-25 17:23:03.000000000 -0400
58904@@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
58905 */
58906 void __put_cred(struct cred *cred)
58907 {
58908+ pax_track_stack();
58909+
58910 kdebug("__put_cred(%p{%d,%d})", cred,
58911 atomic_read(&cred->usage),
58912 read_cred_subscribers(cred));
58913@@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
58914 {
58915 struct cred *cred;
58916
58917+ pax_track_stack();
58918+
58919 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
58920 atomic_read(&tsk->cred->usage),
58921 read_cred_subscribers(tsk->cred));
58922@@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
58923 {
58924 const struct cred *cred;
58925
58926+ pax_track_stack();
58927+
58928 rcu_read_lock();
58929
58930 do {
58931@@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
58932 {
58933 struct cred *new;
58934
58935+ pax_track_stack();
58936+
58937 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
58938 if (!new)
58939 return NULL;
58940@@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
58941 const struct cred *old;
58942 struct cred *new;
58943
58944+ pax_track_stack();
58945+
58946 validate_process_creds();
58947
58948 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
58949@@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
58950 struct thread_group_cred *tgcred = NULL;
58951 struct cred *new;
58952
58953+ pax_track_stack();
58954+
58955 #ifdef CONFIG_KEYS
58956 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
58957 if (!tgcred)
58958@@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
58959 struct cred *new;
58960 int ret;
58961
58962+ pax_track_stack();
58963+
58964 if (
58965 #ifdef CONFIG_KEYS
58966 !p->cred->thread_keyring &&
58967@@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
58968 struct task_struct *task = current;
58969 const struct cred *old = task->real_cred;
58970
58971+ pax_track_stack();
58972+
58973 kdebug("commit_creds(%p{%d,%d})", new,
58974 atomic_read(&new->usage),
58975 read_cred_subscribers(new));
58976@@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
58977
58978 get_cred(new); /* we will require a ref for the subj creds too */
58979
58980+ gr_set_role_label(task, new->uid, new->gid);
58981+
58982 /* dumpability changes */
58983 if (old->euid != new->euid ||
58984 old->egid != new->egid ||
58985@@ -508,10 +526,8 @@ int commit_creds(struct cred *new)
58986 key_fsgid_changed(task);
58987
58988 /* do it
58989- * - What if a process setreuid()'s and this brings the
58990- * new uid over his NPROC rlimit? We can check this now
58991- * cheaply with the new uid cache, so if it matters
58992- * we should be checking for it. -DaveM
58993+ * RLIMIT_NPROC limits on user->processes have already been checked
58994+ * in set_user().
58995 */
58996 alter_cred_subscribers(new, 2);
58997 if (new->user != old->user)
58998@@ -551,6 +567,8 @@ EXPORT_SYMBOL(commit_creds);
58999 */
59000 void abort_creds(struct cred *new)
59001 {
59002+ pax_track_stack();
59003+
59004 kdebug("abort_creds(%p{%d,%d})", new,
59005 atomic_read(&new->usage),
59006 read_cred_subscribers(new));
59007@@ -574,6 +592,8 @@ const struct cred *override_creds(const
59008 {
59009 const struct cred *old = current->cred;
59010
59011+ pax_track_stack();
59012+
59013 kdebug("override_creds(%p{%d,%d})", new,
59014 atomic_read(&new->usage),
59015 read_cred_subscribers(new));
59016@@ -603,6 +623,8 @@ void revert_creds(const struct cred *old
59017 {
59018 const struct cred *override = current->cred;
59019
59020+ pax_track_stack();
59021+
59022 kdebug("revert_creds(%p{%d,%d})", old,
59023 atomic_read(&old->usage),
59024 read_cred_subscribers(old));
59025@@ -649,6 +671,8 @@ struct cred *prepare_kernel_cred(struct
59026 const struct cred *old;
59027 struct cred *new;
59028
59029+ pax_track_stack();
59030+
59031 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
59032 if (!new)
59033 return NULL;
59034@@ -703,6 +727,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
59035 */
59036 int set_security_override(struct cred *new, u32 secid)
59037 {
59038+ pax_track_stack();
59039+
59040 return security_kernel_act_as(new, secid);
59041 }
59042 EXPORT_SYMBOL(set_security_override);
59043@@ -722,6 +748,8 @@ int set_security_override_from_ctx(struc
59044 u32 secid;
59045 int ret;
59046
59047+ pax_track_stack();
59048+
59049 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
59050 if (ret < 0)
59051 return ret;
59052diff -urNp linux-3.0.4/kernel/debug/debug_core.c linux-3.0.4/kernel/debug/debug_core.c
59053--- linux-3.0.4/kernel/debug/debug_core.c 2011-07-21 22:17:23.000000000 -0400
59054+++ linux-3.0.4/kernel/debug/debug_core.c 2011-08-23 21:47:56.000000000 -0400
59055@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
59056 */
59057 static atomic_t masters_in_kgdb;
59058 static atomic_t slaves_in_kgdb;
59059-static atomic_t kgdb_break_tasklet_var;
59060+static atomic_unchecked_t kgdb_break_tasklet_var;
59061 atomic_t kgdb_setting_breakpoint;
59062
59063 struct task_struct *kgdb_usethread;
59064@@ -129,7 +129,7 @@ int kgdb_single_step;
59065 static pid_t kgdb_sstep_pid;
59066
59067 /* to keep track of the CPU which is doing the single stepping*/
59068-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
59069+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
59070
59071 /*
59072 * If you are debugging a problem where roundup (the collection of
59073@@ -542,7 +542,7 @@ return_normal:
59074 * kernel will only try for the value of sstep_tries before
59075 * giving up and continuing on.
59076 */
59077- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
59078+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
59079 (kgdb_info[cpu].task &&
59080 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
59081 atomic_set(&kgdb_active, -1);
59082@@ -636,8 +636,8 @@ cpu_master_loop:
59083 }
59084
59085 kgdb_restore:
59086- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
59087- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
59088+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
59089+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
59090 if (kgdb_info[sstep_cpu].task)
59091 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
59092 else
59093@@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
59094 static void kgdb_tasklet_bpt(unsigned long ing)
59095 {
59096 kgdb_breakpoint();
59097- atomic_set(&kgdb_break_tasklet_var, 0);
59098+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
59099 }
59100
59101 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
59102
59103 void kgdb_schedule_breakpoint(void)
59104 {
59105- if (atomic_read(&kgdb_break_tasklet_var) ||
59106+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
59107 atomic_read(&kgdb_active) != -1 ||
59108 atomic_read(&kgdb_setting_breakpoint))
59109 return;
59110- atomic_inc(&kgdb_break_tasklet_var);
59111+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
59112 tasklet_schedule(&kgdb_tasklet_breakpoint);
59113 }
59114 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
59115diff -urNp linux-3.0.4/kernel/debug/kdb/kdb_main.c linux-3.0.4/kernel/debug/kdb/kdb_main.c
59116--- linux-3.0.4/kernel/debug/kdb/kdb_main.c 2011-07-21 22:17:23.000000000 -0400
59117+++ linux-3.0.4/kernel/debug/kdb/kdb_main.c 2011-08-23 21:47:56.000000000 -0400
59118@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
59119 list_for_each_entry(mod, kdb_modules, list) {
59120
59121 kdb_printf("%-20s%8u 0x%p ", mod->name,
59122- mod->core_size, (void *)mod);
59123+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
59124 #ifdef CONFIG_MODULE_UNLOAD
59125 kdb_printf("%4d ", module_refcount(mod));
59126 #endif
59127@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
59128 kdb_printf(" (Loading)");
59129 else
59130 kdb_printf(" (Live)");
59131- kdb_printf(" 0x%p", mod->module_core);
59132+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
59133
59134 #ifdef CONFIG_MODULE_UNLOAD
59135 {
59136diff -urNp linux-3.0.4/kernel/events/core.c linux-3.0.4/kernel/events/core.c
59137--- linux-3.0.4/kernel/events/core.c 2011-08-23 21:44:40.000000000 -0400
59138+++ linux-3.0.4/kernel/events/core.c 2011-08-23 21:47:56.000000000 -0400
59139@@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
59140 return 0;
59141 }
59142
59143-static atomic64_t perf_event_id;
59144+static atomic64_unchecked_t perf_event_id;
59145
59146 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
59147 enum event_type_t event_type);
59148@@ -2488,7 +2488,7 @@ static void __perf_event_read(void *info
59149
59150 static inline u64 perf_event_count(struct perf_event *event)
59151 {
59152- return local64_read(&event->count) + atomic64_read(&event->child_count);
59153+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
59154 }
59155
59156 static u64 perf_event_read(struct perf_event *event)
59157@@ -3023,9 +3023,9 @@ u64 perf_event_read_value(struct perf_ev
59158 mutex_lock(&event->child_mutex);
59159 total += perf_event_read(event);
59160 *enabled += event->total_time_enabled +
59161- atomic64_read(&event->child_total_time_enabled);
59162+ atomic64_read_unchecked(&event->child_total_time_enabled);
59163 *running += event->total_time_running +
59164- atomic64_read(&event->child_total_time_running);
59165+ atomic64_read_unchecked(&event->child_total_time_running);
59166
59167 list_for_each_entry(child, &event->child_list, child_list) {
59168 total += perf_event_read(child);
59169@@ -3388,10 +3388,10 @@ void perf_event_update_userpage(struct p
59170 userpg->offset -= local64_read(&event->hw.prev_count);
59171
59172 userpg->time_enabled = event->total_time_enabled +
59173- atomic64_read(&event->child_total_time_enabled);
59174+ atomic64_read_unchecked(&event->child_total_time_enabled);
59175
59176 userpg->time_running = event->total_time_running +
59177- atomic64_read(&event->child_total_time_running);
59178+ atomic64_read_unchecked(&event->child_total_time_running);
59179
59180 barrier();
59181 ++userpg->lock;
59182@@ -4188,11 +4188,11 @@ static void perf_output_read_one(struct
59183 values[n++] = perf_event_count(event);
59184 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
59185 values[n++] = enabled +
59186- atomic64_read(&event->child_total_time_enabled);
59187+ atomic64_read_unchecked(&event->child_total_time_enabled);
59188 }
59189 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
59190 values[n++] = running +
59191- atomic64_read(&event->child_total_time_running);
59192+ atomic64_read_unchecked(&event->child_total_time_running);
59193 }
59194 if (read_format & PERF_FORMAT_ID)
59195 values[n++] = primary_event_id(event);
59196@@ -6190,7 +6190,7 @@ perf_event_alloc(struct perf_event_attr
59197 event->parent = parent_event;
59198
59199 event->ns = get_pid_ns(current->nsproxy->pid_ns);
59200- event->id = atomic64_inc_return(&perf_event_id);
59201+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
59202
59203 event->state = PERF_EVENT_STATE_INACTIVE;
59204
59205@@ -6713,10 +6713,10 @@ static void sync_child_event(struct perf
59206 /*
59207 * Add back the child's count to the parent's count:
59208 */
59209- atomic64_add(child_val, &parent_event->child_count);
59210- atomic64_add(child_event->total_time_enabled,
59211+ atomic64_add_unchecked(child_val, &parent_event->child_count);
59212+ atomic64_add_unchecked(child_event->total_time_enabled,
59213 &parent_event->child_total_time_enabled);
59214- atomic64_add(child_event->total_time_running,
59215+ atomic64_add_unchecked(child_event->total_time_running,
59216 &parent_event->child_total_time_running);
59217
59218 /*
59219diff -urNp linux-3.0.4/kernel/exit.c linux-3.0.4/kernel/exit.c
59220--- linux-3.0.4/kernel/exit.c 2011-07-21 22:17:23.000000000 -0400
59221+++ linux-3.0.4/kernel/exit.c 2011-08-23 21:48:14.000000000 -0400
59222@@ -57,6 +57,10 @@
59223 #include <asm/pgtable.h>
59224 #include <asm/mmu_context.h>
59225
59226+#ifdef CONFIG_GRKERNSEC
59227+extern rwlock_t grsec_exec_file_lock;
59228+#endif
59229+
59230 static void exit_mm(struct task_struct * tsk);
59231
59232 static void __unhash_process(struct task_struct *p, bool group_dead)
59233@@ -169,6 +173,10 @@ void release_task(struct task_struct * p
59234 struct task_struct *leader;
59235 int zap_leader;
59236 repeat:
59237+#ifdef CONFIG_NET
59238+ gr_del_task_from_ip_table(p);
59239+#endif
59240+
59241 tracehook_prepare_release_task(p);
59242 /* don't need to get the RCU readlock here - the process is dead and
59243 * can't be modifying its own credentials. But shut RCU-lockdep up */
59244@@ -338,11 +346,22 @@ static void reparent_to_kthreadd(void)
59245 {
59246 write_lock_irq(&tasklist_lock);
59247
59248+#ifdef CONFIG_GRKERNSEC
59249+ write_lock(&grsec_exec_file_lock);
59250+ if (current->exec_file) {
59251+ fput(current->exec_file);
59252+ current->exec_file = NULL;
59253+ }
59254+ write_unlock(&grsec_exec_file_lock);
59255+#endif
59256+
59257 ptrace_unlink(current);
59258 /* Reparent to init */
59259 current->real_parent = current->parent = kthreadd_task;
59260 list_move_tail(&current->sibling, &current->real_parent->children);
59261
59262+ gr_set_kernel_label(current);
59263+
59264 /* Set the exit signal to SIGCHLD so we signal init on exit */
59265 current->exit_signal = SIGCHLD;
59266
59267@@ -394,7 +413,7 @@ int allow_signal(int sig)
59268 * know it'll be handled, so that they don't get converted to
59269 * SIGKILL or just silently dropped.
59270 */
59271- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
59272+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
59273 recalc_sigpending();
59274 spin_unlock_irq(&current->sighand->siglock);
59275 return 0;
59276@@ -430,6 +449,17 @@ void daemonize(const char *name, ...)
59277 vsnprintf(current->comm, sizeof(current->comm), name, args);
59278 va_end(args);
59279
59280+#ifdef CONFIG_GRKERNSEC
59281+ write_lock(&grsec_exec_file_lock);
59282+ if (current->exec_file) {
59283+ fput(current->exec_file);
59284+ current->exec_file = NULL;
59285+ }
59286+ write_unlock(&grsec_exec_file_lock);
59287+#endif
59288+
59289+ gr_set_kernel_label(current);
59290+
59291 /*
59292 * If we were started as result of loading a module, close all of the
59293 * user space pages. We don't need them, and if we didn't close them
59294@@ -904,15 +934,8 @@ NORET_TYPE void do_exit(long code)
59295 struct task_struct *tsk = current;
59296 int group_dead;
59297
59298- profile_task_exit(tsk);
59299-
59300- WARN_ON(atomic_read(&tsk->fs_excl));
59301- WARN_ON(blk_needs_flush_plug(tsk));
59302-
59303 if (unlikely(in_interrupt()))
59304 panic("Aiee, killing interrupt handler!");
59305- if (unlikely(!tsk->pid))
59306- panic("Attempted to kill the idle task!");
59307
59308 /*
59309 * If do_exit is called because this processes oopsed, it's possible
59310@@ -923,6 +946,14 @@ NORET_TYPE void do_exit(long code)
59311 */
59312 set_fs(USER_DS);
59313
59314+ profile_task_exit(tsk);
59315+
59316+ WARN_ON(atomic_read(&tsk->fs_excl));
59317+ WARN_ON(blk_needs_flush_plug(tsk));
59318+
59319+ if (unlikely(!tsk->pid))
59320+ panic("Attempted to kill the idle task!");
59321+
59322 tracehook_report_exit(&code);
59323
59324 validate_creds_for_do_exit(tsk);
59325@@ -983,6 +1014,9 @@ NORET_TYPE void do_exit(long code)
59326 tsk->exit_code = code;
59327 taskstats_exit(tsk, group_dead);
59328
59329+ gr_acl_handle_psacct(tsk, code);
59330+ gr_acl_handle_exit();
59331+
59332 exit_mm(tsk);
59333
59334 if (group_dead)
59335diff -urNp linux-3.0.4/kernel/fork.c linux-3.0.4/kernel/fork.c
59336--- linux-3.0.4/kernel/fork.c 2011-07-21 22:17:23.000000000 -0400
59337+++ linux-3.0.4/kernel/fork.c 2011-08-25 17:23:36.000000000 -0400
59338@@ -286,7 +286,7 @@ static struct task_struct *dup_task_stru
59339 *stackend = STACK_END_MAGIC; /* for overflow detection */
59340
59341 #ifdef CONFIG_CC_STACKPROTECTOR
59342- tsk->stack_canary = get_random_int();
59343+ tsk->stack_canary = pax_get_random_long();
59344 #endif
59345
59346 /* One for us, one for whoever does the "release_task()" (usually parent) */
59347@@ -308,13 +308,77 @@ out:
59348 }
59349
59350 #ifdef CONFIG_MMU
59351+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
59352+{
59353+ struct vm_area_struct *tmp;
59354+ unsigned long charge;
59355+ struct mempolicy *pol;
59356+ struct file *file;
59357+
59358+ charge = 0;
59359+ if (mpnt->vm_flags & VM_ACCOUNT) {
59360+ unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
59361+ if (security_vm_enough_memory(len))
59362+ goto fail_nomem;
59363+ charge = len;
59364+ }
59365+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
59366+ if (!tmp)
59367+ goto fail_nomem;
59368+ *tmp = *mpnt;
59369+ tmp->vm_mm = mm;
59370+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
59371+ pol = mpol_dup(vma_policy(mpnt));
59372+ if (IS_ERR(pol))
59373+ goto fail_nomem_policy;
59374+ vma_set_policy(tmp, pol);
59375+ if (anon_vma_fork(tmp, mpnt))
59376+ goto fail_nomem_anon_vma_fork;
59377+ tmp->vm_flags &= ~VM_LOCKED;
59378+ tmp->vm_next = tmp->vm_prev = NULL;
59379+ tmp->vm_mirror = NULL;
59380+ file = tmp->vm_file;
59381+ if (file) {
59382+ struct inode *inode = file->f_path.dentry->d_inode;
59383+ struct address_space *mapping = file->f_mapping;
59384+
59385+ get_file(file);
59386+ if (tmp->vm_flags & VM_DENYWRITE)
59387+ atomic_dec(&inode->i_writecount);
59388+ mutex_lock(&mapping->i_mmap_mutex);
59389+ if (tmp->vm_flags & VM_SHARED)
59390+ mapping->i_mmap_writable++;
59391+ flush_dcache_mmap_lock(mapping);
59392+ /* insert tmp into the share list, just after mpnt */
59393+ vma_prio_tree_add(tmp, mpnt);
59394+ flush_dcache_mmap_unlock(mapping);
59395+ mutex_unlock(&mapping->i_mmap_mutex);
59396+ }
59397+
59398+ /*
59399+ * Clear hugetlb-related page reserves for children. This only
59400+ * affects MAP_PRIVATE mappings. Faults generated by the child
59401+ * are not guaranteed to succeed, even if read-only
59402+ */
59403+ if (is_vm_hugetlb_page(tmp))
59404+ reset_vma_resv_huge_pages(tmp);
59405+
59406+ return tmp;
59407+
59408+fail_nomem_anon_vma_fork:
59409+ mpol_put(pol);
59410+fail_nomem_policy:
59411+ kmem_cache_free(vm_area_cachep, tmp);
59412+fail_nomem:
59413+ vm_unacct_memory(charge);
59414+ return NULL;
59415+}
59416+
59417 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
59418 {
59419 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
59420 struct rb_node **rb_link, *rb_parent;
59421 int retval;
59422- unsigned long charge;
59423- struct mempolicy *pol;
59424
59425 down_write(&oldmm->mmap_sem);
59426 flush_cache_dup_mm(oldmm);
59427@@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm
59428 mm->locked_vm = 0;
59429 mm->mmap = NULL;
59430 mm->mmap_cache = NULL;
59431- mm->free_area_cache = oldmm->mmap_base;
59432- mm->cached_hole_size = ~0UL;
59433+ mm->free_area_cache = oldmm->free_area_cache;
59434+ mm->cached_hole_size = oldmm->cached_hole_size;
59435 mm->map_count = 0;
59436 cpumask_clear(mm_cpumask(mm));
59437 mm->mm_rb = RB_ROOT;
59438@@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm
59439
59440 prev = NULL;
59441 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
59442- struct file *file;
59443-
59444 if (mpnt->vm_flags & VM_DONTCOPY) {
59445 long pages = vma_pages(mpnt);
59446 mm->total_vm -= pages;
59447@@ -352,55 +414,13 @@ static int dup_mmap(struct mm_struct *mm
59448 -pages);
59449 continue;
59450 }
59451- charge = 0;
59452- if (mpnt->vm_flags & VM_ACCOUNT) {
59453- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
59454- if (security_vm_enough_memory(len))
59455- goto fail_nomem;
59456- charge = len;
59457- }
59458- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
59459- if (!tmp)
59460- goto fail_nomem;
59461- *tmp = *mpnt;
59462- INIT_LIST_HEAD(&tmp->anon_vma_chain);
59463- pol = mpol_dup(vma_policy(mpnt));
59464- retval = PTR_ERR(pol);
59465- if (IS_ERR(pol))
59466- goto fail_nomem_policy;
59467- vma_set_policy(tmp, pol);
59468- tmp->vm_mm = mm;
59469- if (anon_vma_fork(tmp, mpnt))
59470- goto fail_nomem_anon_vma_fork;
59471- tmp->vm_flags &= ~VM_LOCKED;
59472- tmp->vm_next = tmp->vm_prev = NULL;
59473- file = tmp->vm_file;
59474- if (file) {
59475- struct inode *inode = file->f_path.dentry->d_inode;
59476- struct address_space *mapping = file->f_mapping;
59477-
59478- get_file(file);
59479- if (tmp->vm_flags & VM_DENYWRITE)
59480- atomic_dec(&inode->i_writecount);
59481- mutex_lock(&mapping->i_mmap_mutex);
59482- if (tmp->vm_flags & VM_SHARED)
59483- mapping->i_mmap_writable++;
59484- flush_dcache_mmap_lock(mapping);
59485- /* insert tmp into the share list, just after mpnt */
59486- vma_prio_tree_add(tmp, mpnt);
59487- flush_dcache_mmap_unlock(mapping);
59488- mutex_unlock(&mapping->i_mmap_mutex);
59489+ tmp = dup_vma(mm, mpnt);
59490+ if (!tmp) {
59491+ retval = -ENOMEM;
59492+ goto out;
59493 }
59494
59495 /*
59496- * Clear hugetlb-related page reserves for children. This only
59497- * affects MAP_PRIVATE mappings. Faults generated by the child
59498- * are not guaranteed to succeed, even if read-only
59499- */
59500- if (is_vm_hugetlb_page(tmp))
59501- reset_vma_resv_huge_pages(tmp);
59502-
59503- /*
59504 * Link in the new vma and copy the page table entries.
59505 */
59506 *pprev = tmp;
59507@@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm
59508 if (retval)
59509 goto out;
59510 }
59511+
59512+#ifdef CONFIG_PAX_SEGMEXEC
59513+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
59514+ struct vm_area_struct *mpnt_m;
59515+
59516+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
59517+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
59518+
59519+ if (!mpnt->vm_mirror)
59520+ continue;
59521+
59522+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
59523+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
59524+ mpnt->vm_mirror = mpnt_m;
59525+ } else {
59526+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
59527+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
59528+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
59529+ mpnt->vm_mirror->vm_mirror = mpnt;
59530+ }
59531+ }
59532+ BUG_ON(mpnt_m);
59533+ }
59534+#endif
59535+
59536 /* a new mm has just been created */
59537 arch_dup_mmap(oldmm, mm);
59538 retval = 0;
59539@@ -429,14 +474,6 @@ out:
59540 flush_tlb_mm(oldmm);
59541 up_write(&oldmm->mmap_sem);
59542 return retval;
59543-fail_nomem_anon_vma_fork:
59544- mpol_put(pol);
59545-fail_nomem_policy:
59546- kmem_cache_free(vm_area_cachep, tmp);
59547-fail_nomem:
59548- retval = -ENOMEM;
59549- vm_unacct_memory(charge);
59550- goto out;
59551 }
59552
59553 static inline int mm_alloc_pgd(struct mm_struct * mm)
59554@@ -836,13 +873,14 @@ static int copy_fs(unsigned long clone_f
59555 spin_unlock(&fs->lock);
59556 return -EAGAIN;
59557 }
59558- fs->users++;
59559+ atomic_inc(&fs->users);
59560 spin_unlock(&fs->lock);
59561 return 0;
59562 }
59563 tsk->fs = copy_fs_struct(fs);
59564 if (!tsk->fs)
59565 return -ENOMEM;
59566+ gr_set_chroot_entries(tsk, &tsk->fs->root);
59567 return 0;
59568 }
59569
59570@@ -1104,12 +1142,16 @@ static struct task_struct *copy_process(
59571 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
59572 #endif
59573 retval = -EAGAIN;
59574+
59575+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
59576+
59577 if (atomic_read(&p->real_cred->user->processes) >=
59578 task_rlimit(p, RLIMIT_NPROC)) {
59579- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
59580- p->real_cred->user != INIT_USER)
59581+ if (p->real_cred->user != INIT_USER &&
59582+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
59583 goto bad_fork_free;
59584 }
59585+ current->flags &= ~PF_NPROC_EXCEEDED;
59586
59587 retval = copy_creds(p, clone_flags);
59588 if (retval < 0)
59589@@ -1250,6 +1292,8 @@ static struct task_struct *copy_process(
59590 if (clone_flags & CLONE_THREAD)
59591 p->tgid = current->tgid;
59592
59593+ gr_copy_label(p);
59594+
59595 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
59596 /*
59597 * Clear TID on mm_release()?
59598@@ -1414,6 +1458,8 @@ bad_fork_cleanup_count:
59599 bad_fork_free:
59600 free_task(p);
59601 fork_out:
59602+ gr_log_forkfail(retval);
59603+
59604 return ERR_PTR(retval);
59605 }
59606
59607@@ -1502,6 +1548,8 @@ long do_fork(unsigned long clone_flags,
59608 if (clone_flags & CLONE_PARENT_SETTID)
59609 put_user(nr, parent_tidptr);
59610
59611+ gr_handle_brute_check();
59612+
59613 if (clone_flags & CLONE_VFORK) {
59614 p->vfork_done = &vfork;
59615 init_completion(&vfork);
59616@@ -1610,7 +1658,7 @@ static int unshare_fs(unsigned long unsh
59617 return 0;
59618
59619 /* don't need lock here; in the worst case we'll do useless copy */
59620- if (fs->users == 1)
59621+ if (atomic_read(&fs->users) == 1)
59622 return 0;
59623
59624 *new_fsp = copy_fs_struct(fs);
59625@@ -1697,7 +1745,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
59626 fs = current->fs;
59627 spin_lock(&fs->lock);
59628 current->fs = new_fs;
59629- if (--fs->users)
59630+ gr_set_chroot_entries(current, &current->fs->root);
59631+ if (atomic_dec_return(&fs->users))
59632 new_fs = NULL;
59633 else
59634 new_fs = fs;
59635diff -urNp linux-3.0.4/kernel/futex.c linux-3.0.4/kernel/futex.c
59636--- linux-3.0.4/kernel/futex.c 2011-08-23 21:44:40.000000000 -0400
59637+++ linux-3.0.4/kernel/futex.c 2011-08-23 21:48:14.000000000 -0400
59638@@ -54,6 +54,7 @@
59639 #include <linux/mount.h>
59640 #include <linux/pagemap.h>
59641 #include <linux/syscalls.h>
59642+#include <linux/ptrace.h>
59643 #include <linux/signal.h>
59644 #include <linux/module.h>
59645 #include <linux/magic.h>
59646@@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fsh
59647 struct page *page, *page_head;
59648 int err, ro = 0;
59649
59650+#ifdef CONFIG_PAX_SEGMEXEC
59651+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
59652+ return -EFAULT;
59653+#endif
59654+
59655 /*
59656 * The futex address must be "naturally" aligned.
59657 */
59658@@ -1863,6 +1869,8 @@ static int futex_wait(u32 __user *uaddr,
59659 struct futex_q q = futex_q_init;
59660 int ret;
59661
59662+ pax_track_stack();
59663+
59664 if (!bitset)
59665 return -EINVAL;
59666 q.bitset = bitset;
59667@@ -2259,6 +2267,8 @@ static int futex_wait_requeue_pi(u32 __u
59668 struct futex_q q = futex_q_init;
59669 int res, ret;
59670
59671+ pax_track_stack();
59672+
59673 if (!bitset)
59674 return -EINVAL;
59675
59676@@ -2431,7 +2441,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59677 {
59678 struct robust_list_head __user *head;
59679 unsigned long ret;
59680+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
59681 const struct cred *cred = current_cred(), *pcred;
59682+#endif
59683
59684 if (!futex_cmpxchg_enabled)
59685 return -ENOSYS;
59686@@ -2447,6 +2459,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59687 if (!p)
59688 goto err_unlock;
59689 ret = -EPERM;
59690+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59691+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
59692+ goto err_unlock;
59693+#else
59694 pcred = __task_cred(p);
59695 /* If victim is in different user_ns, then uids are not
59696 comparable, so we must have CAP_SYS_PTRACE */
59697@@ -2461,6 +2477,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59698 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
59699 goto err_unlock;
59700 ok:
59701+#endif
59702 head = p->robust_list;
59703 rcu_read_unlock();
59704 }
59705@@ -2712,6 +2729,7 @@ static int __init futex_init(void)
59706 {
59707 u32 curval;
59708 int i;
59709+ mm_segment_t oldfs;
59710
59711 /*
59712 * This will fail and we want it. Some arch implementations do
59713@@ -2723,8 +2741,11 @@ static int __init futex_init(void)
59714 * implementation, the non-functional ones will return
59715 * -ENOSYS.
59716 */
59717+ oldfs = get_fs();
59718+ set_fs(USER_DS);
59719 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
59720 futex_cmpxchg_enabled = 1;
59721+ set_fs(oldfs);
59722
59723 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
59724 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
59725diff -urNp linux-3.0.4/kernel/futex_compat.c linux-3.0.4/kernel/futex_compat.c
59726--- linux-3.0.4/kernel/futex_compat.c 2011-07-21 22:17:23.000000000 -0400
59727+++ linux-3.0.4/kernel/futex_compat.c 2011-08-23 21:48:14.000000000 -0400
59728@@ -10,6 +10,7 @@
59729 #include <linux/compat.h>
59730 #include <linux/nsproxy.h>
59731 #include <linux/futex.h>
59732+#include <linux/ptrace.h>
59733
59734 #include <asm/uaccess.h>
59735
59736@@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
59737 {
59738 struct compat_robust_list_head __user *head;
59739 unsigned long ret;
59740- const struct cred *cred = current_cred(), *pcred;
59741+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
59742+ const struct cred *cred = current_cred();
59743+ const struct cred *pcred;
59744+#endif
59745
59746 if (!futex_cmpxchg_enabled)
59747 return -ENOSYS;
59748@@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
59749 if (!p)
59750 goto err_unlock;
59751 ret = -EPERM;
59752+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59753+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
59754+ goto err_unlock;
59755+#else
59756 pcred = __task_cred(p);
59757 /* If victim is in different user_ns, then uids are not
59758 comparable, so we must have CAP_SYS_PTRACE */
59759@@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
59760 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
59761 goto err_unlock;
59762 ok:
59763+#endif
59764 head = p->compat_robust_list;
59765 rcu_read_unlock();
59766 }
59767diff -urNp linux-3.0.4/kernel/gcov/base.c linux-3.0.4/kernel/gcov/base.c
59768--- linux-3.0.4/kernel/gcov/base.c 2011-07-21 22:17:23.000000000 -0400
59769+++ linux-3.0.4/kernel/gcov/base.c 2011-08-23 21:47:56.000000000 -0400
59770@@ -102,11 +102,6 @@ void gcov_enable_events(void)
59771 }
59772
59773 #ifdef CONFIG_MODULES
59774-static inline int within(void *addr, void *start, unsigned long size)
59775-{
59776- return ((addr >= start) && (addr < start + size));
59777-}
59778-
59779 /* Update list and generate events when modules are unloaded. */
59780 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
59781 void *data)
59782@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
59783 prev = NULL;
59784 /* Remove entries located in module from linked list. */
59785 for (info = gcov_info_head; info; info = info->next) {
59786- if (within(info, mod->module_core, mod->core_size)) {
59787+ if (within_module_core_rw((unsigned long)info, mod)) {
59788 if (prev)
59789 prev->next = info->next;
59790 else
59791diff -urNp linux-3.0.4/kernel/hrtimer.c linux-3.0.4/kernel/hrtimer.c
59792--- linux-3.0.4/kernel/hrtimer.c 2011-07-21 22:17:23.000000000 -0400
59793+++ linux-3.0.4/kernel/hrtimer.c 2011-08-23 21:47:56.000000000 -0400
59794@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
59795 local_irq_restore(flags);
59796 }
59797
59798-static void run_hrtimer_softirq(struct softirq_action *h)
59799+static void run_hrtimer_softirq(void)
59800 {
59801 hrtimer_peek_ahead_timers();
59802 }
59803diff -urNp linux-3.0.4/kernel/jump_label.c linux-3.0.4/kernel/jump_label.c
59804--- linux-3.0.4/kernel/jump_label.c 2011-07-21 22:17:23.000000000 -0400
59805+++ linux-3.0.4/kernel/jump_label.c 2011-08-23 21:47:56.000000000 -0400
59806@@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entr
59807
59808 size = (((unsigned long)stop - (unsigned long)start)
59809 / sizeof(struct jump_entry));
59810+ pax_open_kernel();
59811 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
59812+ pax_close_kernel();
59813 }
59814
59815 static void jump_label_update(struct jump_label_key *key, int enable);
59816@@ -297,10 +299,12 @@ static void jump_label_invalidate_module
59817 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
59818 struct jump_entry *iter;
59819
59820+ pax_open_kernel();
59821 for (iter = iter_start; iter < iter_stop; iter++) {
59822 if (within_module_init(iter->code, mod))
59823 iter->code = 0;
59824 }
59825+ pax_close_kernel();
59826 }
59827
59828 static int
59829diff -urNp linux-3.0.4/kernel/kallsyms.c linux-3.0.4/kernel/kallsyms.c
59830--- linux-3.0.4/kernel/kallsyms.c 2011-07-21 22:17:23.000000000 -0400
59831+++ linux-3.0.4/kernel/kallsyms.c 2011-08-23 21:48:14.000000000 -0400
59832@@ -11,6 +11,9 @@
59833 * Changed the compression method from stem compression to "table lookup"
59834 * compression (see scripts/kallsyms.c for a more complete description)
59835 */
59836+#ifdef CONFIG_GRKERNSEC_HIDESYM
59837+#define __INCLUDED_BY_HIDESYM 1
59838+#endif
59839 #include <linux/kallsyms.h>
59840 #include <linux/module.h>
59841 #include <linux/init.h>
59842@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
59843
59844 static inline int is_kernel_inittext(unsigned long addr)
59845 {
59846+ if (system_state != SYSTEM_BOOTING)
59847+ return 0;
59848+
59849 if (addr >= (unsigned long)_sinittext
59850 && addr <= (unsigned long)_einittext)
59851 return 1;
59852 return 0;
59853 }
59854
59855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59856+#ifdef CONFIG_MODULES
59857+static inline int is_module_text(unsigned long addr)
59858+{
59859+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
59860+ return 1;
59861+
59862+ addr = ktla_ktva(addr);
59863+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
59864+}
59865+#else
59866+static inline int is_module_text(unsigned long addr)
59867+{
59868+ return 0;
59869+}
59870+#endif
59871+#endif
59872+
59873 static inline int is_kernel_text(unsigned long addr)
59874 {
59875 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
59876@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
59877
59878 static inline int is_kernel(unsigned long addr)
59879 {
59880+
59881+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59882+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
59883+ return 1;
59884+
59885+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
59886+#else
59887 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
59888+#endif
59889+
59890 return 1;
59891 return in_gate_area_no_mm(addr);
59892 }
59893
59894 static int is_ksym_addr(unsigned long addr)
59895 {
59896+
59897+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59898+ if (is_module_text(addr))
59899+ return 0;
59900+#endif
59901+
59902 if (all_var)
59903 return is_kernel(addr);
59904
59905@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
59906
59907 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
59908 {
59909- iter->name[0] = '\0';
59910 iter->nameoff = get_symbol_offset(new_pos);
59911 iter->pos = new_pos;
59912 }
59913@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
59914 {
59915 struct kallsym_iter *iter = m->private;
59916
59917+#ifdef CONFIG_GRKERNSEC_HIDESYM
59918+ if (current_uid())
59919+ return 0;
59920+#endif
59921+
59922 /* Some debugging symbols have no name. Ignore them. */
59923 if (!iter->name[0])
59924 return 0;
59925@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
59926 struct kallsym_iter *iter;
59927 int ret;
59928
59929- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
59930+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
59931 if (!iter)
59932 return -ENOMEM;
59933 reset_iter(iter, 0);
59934diff -urNp linux-3.0.4/kernel/kmod.c linux-3.0.4/kernel/kmod.c
59935--- linux-3.0.4/kernel/kmod.c 2011-07-21 22:17:23.000000000 -0400
59936+++ linux-3.0.4/kernel/kmod.c 2011-08-23 21:48:14.000000000 -0400
59937@@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
59938 * If module auto-loading support is disabled then this function
59939 * becomes a no-operation.
59940 */
59941-int __request_module(bool wait, const char *fmt, ...)
59942+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
59943 {
59944- va_list args;
59945 char module_name[MODULE_NAME_LEN];
59946 unsigned int max_modprobes;
59947 int ret;
59948- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
59949+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
59950 static char *envp[] = { "HOME=/",
59951 "TERM=linux",
59952 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
59953@@ -88,9 +87,7 @@ int __request_module(bool wait, const ch
59954 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
59955 static int kmod_loop_msg;
59956
59957- va_start(args, fmt);
59958- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
59959- va_end(args);
59960+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
59961 if (ret >= MODULE_NAME_LEN)
59962 return -ENAMETOOLONG;
59963
59964@@ -98,6 +95,20 @@ int __request_module(bool wait, const ch
59965 if (ret)
59966 return ret;
59967
59968+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59969+ if (!current_uid()) {
59970+ /* hack to workaround consolekit/udisks stupidity */
59971+ read_lock(&tasklist_lock);
59972+ if (!strcmp(current->comm, "mount") &&
59973+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
59974+ read_unlock(&tasklist_lock);
59975+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
59976+ return -EPERM;
59977+ }
59978+ read_unlock(&tasklist_lock);
59979+ }
59980+#endif
59981+
59982 /* If modprobe needs a service that is in a module, we get a recursive
59983 * loop. Limit the number of running kmod threads to max_threads/2 or
59984 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
59985@@ -131,6 +142,47 @@ int __request_module(bool wait, const ch
59986 atomic_dec(&kmod_concurrent);
59987 return ret;
59988 }
59989+
59990+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
59991+{
59992+ va_list args;
59993+ int ret;
59994+
59995+ va_start(args, fmt);
59996+ ret = ____request_module(wait, module_param, fmt, args);
59997+ va_end(args);
59998+
59999+ return ret;
60000+}
60001+
60002+int __request_module(bool wait, const char *fmt, ...)
60003+{
60004+ va_list args;
60005+ int ret;
60006+
60007+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60008+ if (current_uid()) {
60009+ char module_param[MODULE_NAME_LEN];
60010+
60011+ memset(module_param, 0, sizeof(module_param));
60012+
60013+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
60014+
60015+ va_start(args, fmt);
60016+ ret = ____request_module(wait, module_param, fmt, args);
60017+ va_end(args);
60018+
60019+ return ret;
60020+ }
60021+#endif
60022+
60023+ va_start(args, fmt);
60024+ ret = ____request_module(wait, NULL, fmt, args);
60025+ va_end(args);
60026+
60027+ return ret;
60028+}
60029+
60030 EXPORT_SYMBOL(__request_module);
60031 #endif /* CONFIG_MODULES */
60032
60033diff -urNp linux-3.0.4/kernel/kprobes.c linux-3.0.4/kernel/kprobes.c
60034--- linux-3.0.4/kernel/kprobes.c 2011-07-21 22:17:23.000000000 -0400
60035+++ linux-3.0.4/kernel/kprobes.c 2011-08-23 21:47:56.000000000 -0400
60036@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
60037 * kernel image and loaded module images reside. This is required
60038 * so x86_64 can correctly handle the %rip-relative fixups.
60039 */
60040- kip->insns = module_alloc(PAGE_SIZE);
60041+ kip->insns = module_alloc_exec(PAGE_SIZE);
60042 if (!kip->insns) {
60043 kfree(kip);
60044 return NULL;
60045@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
60046 */
60047 if (!list_is_singular(&kip->list)) {
60048 list_del(&kip->list);
60049- module_free(NULL, kip->insns);
60050+ module_free_exec(NULL, kip->insns);
60051 kfree(kip);
60052 }
60053 return 1;
60054@@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
60055 {
60056 int i, err = 0;
60057 unsigned long offset = 0, size = 0;
60058- char *modname, namebuf[128];
60059+ char *modname, namebuf[KSYM_NAME_LEN];
60060 const char *symbol_name;
60061 void *addr;
60062 struct kprobe_blackpoint *kb;
60063@@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
60064 const char *sym = NULL;
60065 unsigned int i = *(loff_t *) v;
60066 unsigned long offset = 0;
60067- char *modname, namebuf[128];
60068+ char *modname, namebuf[KSYM_NAME_LEN];
60069
60070 head = &kprobe_table[i];
60071 preempt_disable();
60072diff -urNp linux-3.0.4/kernel/lockdep.c linux-3.0.4/kernel/lockdep.c
60073--- linux-3.0.4/kernel/lockdep.c 2011-07-21 22:17:23.000000000 -0400
60074+++ linux-3.0.4/kernel/lockdep.c 2011-08-23 21:47:56.000000000 -0400
60075@@ -583,6 +583,10 @@ static int static_obj(void *obj)
60076 end = (unsigned long) &_end,
60077 addr = (unsigned long) obj;
60078
60079+#ifdef CONFIG_PAX_KERNEXEC
60080+ start = ktla_ktva(start);
60081+#endif
60082+
60083 /*
60084 * static variable?
60085 */
60086@@ -718,6 +722,7 @@ register_lock_class(struct lockdep_map *
60087 if (!static_obj(lock->key)) {
60088 debug_locks_off();
60089 printk("INFO: trying to register non-static key.\n");
60090+ printk("lock:%pS key:%pS.\n", lock, lock->key);
60091 printk("the code is fine but needs lockdep annotation.\n");
60092 printk("turning off the locking correctness validator.\n");
60093 dump_stack();
60094@@ -2936,7 +2941,7 @@ static int __lock_acquire(struct lockdep
60095 if (!class)
60096 return 0;
60097 }
60098- atomic_inc((atomic_t *)&class->ops);
60099+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
60100 if (very_verbose(class)) {
60101 printk("\nacquire class [%p] %s", class->key, class->name);
60102 if (class->name_version > 1)
60103diff -urNp linux-3.0.4/kernel/lockdep_proc.c linux-3.0.4/kernel/lockdep_proc.c
60104--- linux-3.0.4/kernel/lockdep_proc.c 2011-07-21 22:17:23.000000000 -0400
60105+++ linux-3.0.4/kernel/lockdep_proc.c 2011-08-23 21:47:56.000000000 -0400
60106@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
60107
60108 static void print_name(struct seq_file *m, struct lock_class *class)
60109 {
60110- char str[128];
60111+ char str[KSYM_NAME_LEN];
60112 const char *name = class->name;
60113
60114 if (!name) {
60115diff -urNp linux-3.0.4/kernel/module.c linux-3.0.4/kernel/module.c
60116--- linux-3.0.4/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
60117+++ linux-3.0.4/kernel/module.c 2011-08-23 21:48:14.000000000 -0400
60118@@ -58,6 +58,7 @@
60119 #include <linux/jump_label.h>
60120 #include <linux/pfn.h>
60121 #include <linux/bsearch.h>
60122+#include <linux/grsecurity.h>
60123
60124 #define CREATE_TRACE_POINTS
60125 #include <trace/events/module.h>
60126@@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
60127
60128 /* Bounds of module allocation, for speeding __module_address.
60129 * Protected by module_mutex. */
60130-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
60131+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
60132+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
60133
60134 int register_module_notifier(struct notifier_block * nb)
60135 {
60136@@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(cons
60137 return true;
60138
60139 list_for_each_entry_rcu(mod, &modules, list) {
60140- struct symsearch arr[] = {
60141+ struct symsearch modarr[] = {
60142 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
60143 NOT_GPL_ONLY, false },
60144 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
60145@@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(cons
60146 #endif
60147 };
60148
60149- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
60150+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
60151 return true;
60152 }
60153 return false;
60154@@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(
60155 static int percpu_modalloc(struct module *mod,
60156 unsigned long size, unsigned long align)
60157 {
60158- if (align > PAGE_SIZE) {
60159+ if (align-1 >= PAGE_SIZE) {
60160 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
60161 mod->name, align, PAGE_SIZE);
60162 align = PAGE_SIZE;
60163@@ -1166,7 +1168,7 @@ resolve_symbol_wait(struct module *mod,
60164 */
60165 #ifdef CONFIG_SYSFS
60166
60167-#ifdef CONFIG_KALLSYMS
60168+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60169 static inline bool sect_empty(const Elf_Shdr *sect)
60170 {
60171 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
60172@@ -1632,21 +1634,21 @@ static void set_section_ro_nx(void *base
60173
60174 static void unset_module_core_ro_nx(struct module *mod)
60175 {
60176- set_page_attributes(mod->module_core + mod->core_text_size,
60177- mod->module_core + mod->core_size,
60178+ set_page_attributes(mod->module_core_rw,
60179+ mod->module_core_rw + mod->core_size_rw,
60180 set_memory_x);
60181- set_page_attributes(mod->module_core,
60182- mod->module_core + mod->core_ro_size,
60183+ set_page_attributes(mod->module_core_rx,
60184+ mod->module_core_rx + mod->core_size_rx,
60185 set_memory_rw);
60186 }
60187
60188 static void unset_module_init_ro_nx(struct module *mod)
60189 {
60190- set_page_attributes(mod->module_init + mod->init_text_size,
60191- mod->module_init + mod->init_size,
60192+ set_page_attributes(mod->module_init_rw,
60193+ mod->module_init_rw + mod->init_size_rw,
60194 set_memory_x);
60195- set_page_attributes(mod->module_init,
60196- mod->module_init + mod->init_ro_size,
60197+ set_page_attributes(mod->module_init_rx,
60198+ mod->module_init_rx + mod->init_size_rx,
60199 set_memory_rw);
60200 }
60201
60202@@ -1657,14 +1659,14 @@ void set_all_modules_text_rw(void)
60203
60204 mutex_lock(&module_mutex);
60205 list_for_each_entry_rcu(mod, &modules, list) {
60206- if ((mod->module_core) && (mod->core_text_size)) {
60207- set_page_attributes(mod->module_core,
60208- mod->module_core + mod->core_text_size,
60209+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
60210+ set_page_attributes(mod->module_core_rx,
60211+ mod->module_core_rx + mod->core_size_rx,
60212 set_memory_rw);
60213 }
60214- if ((mod->module_init) && (mod->init_text_size)) {
60215- set_page_attributes(mod->module_init,
60216- mod->module_init + mod->init_text_size,
60217+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
60218+ set_page_attributes(mod->module_init_rx,
60219+ mod->module_init_rx + mod->init_size_rx,
60220 set_memory_rw);
60221 }
60222 }
60223@@ -1678,14 +1680,14 @@ void set_all_modules_text_ro(void)
60224
60225 mutex_lock(&module_mutex);
60226 list_for_each_entry_rcu(mod, &modules, list) {
60227- if ((mod->module_core) && (mod->core_text_size)) {
60228- set_page_attributes(mod->module_core,
60229- mod->module_core + mod->core_text_size,
60230+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
60231+ set_page_attributes(mod->module_core_rx,
60232+ mod->module_core_rx + mod->core_size_rx,
60233 set_memory_ro);
60234 }
60235- if ((mod->module_init) && (mod->init_text_size)) {
60236- set_page_attributes(mod->module_init,
60237- mod->module_init + mod->init_text_size,
60238+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
60239+ set_page_attributes(mod->module_init_rx,
60240+ mod->module_init_rx + mod->init_size_rx,
60241 set_memory_ro);
60242 }
60243 }
60244@@ -1722,16 +1724,19 @@ static void free_module(struct module *m
60245
60246 /* This may be NULL, but that's OK */
60247 unset_module_init_ro_nx(mod);
60248- module_free(mod, mod->module_init);
60249+ module_free(mod, mod->module_init_rw);
60250+ module_free_exec(mod, mod->module_init_rx);
60251 kfree(mod->args);
60252 percpu_modfree(mod);
60253
60254 /* Free lock-classes: */
60255- lockdep_free_key_range(mod->module_core, mod->core_size);
60256+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
60257+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
60258
60259 /* Finally, free the core (containing the module structure) */
60260 unset_module_core_ro_nx(mod);
60261- module_free(mod, mod->module_core);
60262+ module_free_exec(mod, mod->module_core_rx);
60263+ module_free(mod, mod->module_core_rw);
60264
60265 #ifdef CONFIG_MPU
60266 update_protections(current->mm);
60267@@ -1800,10 +1805,31 @@ static int simplify_symbols(struct modul
60268 unsigned int i;
60269 int ret = 0;
60270 const struct kernel_symbol *ksym;
60271+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60272+ int is_fs_load = 0;
60273+ int register_filesystem_found = 0;
60274+ char *p;
60275+
60276+ p = strstr(mod->args, "grsec_modharden_fs");
60277+ if (p) {
60278+ char *endptr = p + strlen("grsec_modharden_fs");
60279+ /* copy \0 as well */
60280+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
60281+ is_fs_load = 1;
60282+ }
60283+#endif
60284
60285 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
60286 const char *name = info->strtab + sym[i].st_name;
60287
60288+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60289+ /* it's a real shame this will never get ripped and copied
60290+ upstream! ;(
60291+ */
60292+ if (is_fs_load && !strcmp(name, "register_filesystem"))
60293+ register_filesystem_found = 1;
60294+#endif
60295+
60296 switch (sym[i].st_shndx) {
60297 case SHN_COMMON:
60298 /* We compiled with -fno-common. These are not
60299@@ -1824,7 +1850,9 @@ static int simplify_symbols(struct modul
60300 ksym = resolve_symbol_wait(mod, info, name);
60301 /* Ok if resolved. */
60302 if (ksym && !IS_ERR(ksym)) {
60303+ pax_open_kernel();
60304 sym[i].st_value = ksym->value;
60305+ pax_close_kernel();
60306 break;
60307 }
60308
60309@@ -1843,11 +1871,20 @@ static int simplify_symbols(struct modul
60310 secbase = (unsigned long)mod_percpu(mod);
60311 else
60312 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
60313+ pax_open_kernel();
60314 sym[i].st_value += secbase;
60315+ pax_close_kernel();
60316 break;
60317 }
60318 }
60319
60320+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60321+ if (is_fs_load && !register_filesystem_found) {
60322+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
60323+ ret = -EPERM;
60324+ }
60325+#endif
60326+
60327 return ret;
60328 }
60329
60330@@ -1931,22 +1968,12 @@ static void layout_sections(struct modul
60331 || s->sh_entsize != ~0UL
60332 || strstarts(sname, ".init"))
60333 continue;
60334- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
60335+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
60336+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
60337+ else
60338+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
60339 DEBUGP("\t%s\n", name);
60340 }
60341- switch (m) {
60342- case 0: /* executable */
60343- mod->core_size = debug_align(mod->core_size);
60344- mod->core_text_size = mod->core_size;
60345- break;
60346- case 1: /* RO: text and ro-data */
60347- mod->core_size = debug_align(mod->core_size);
60348- mod->core_ro_size = mod->core_size;
60349- break;
60350- case 3: /* whole core */
60351- mod->core_size = debug_align(mod->core_size);
60352- break;
60353- }
60354 }
60355
60356 DEBUGP("Init section allocation order:\n");
60357@@ -1960,23 +1987,13 @@ static void layout_sections(struct modul
60358 || s->sh_entsize != ~0UL
60359 || !strstarts(sname, ".init"))
60360 continue;
60361- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
60362- | INIT_OFFSET_MASK);
60363+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
60364+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
60365+ else
60366+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
60367+ s->sh_entsize |= INIT_OFFSET_MASK;
60368 DEBUGP("\t%s\n", sname);
60369 }
60370- switch (m) {
60371- case 0: /* executable */
60372- mod->init_size = debug_align(mod->init_size);
60373- mod->init_text_size = mod->init_size;
60374- break;
60375- case 1: /* RO: text and ro-data */
60376- mod->init_size = debug_align(mod->init_size);
60377- mod->init_ro_size = mod->init_size;
60378- break;
60379- case 3: /* whole init */
60380- mod->init_size = debug_align(mod->init_size);
60381- break;
60382- }
60383 }
60384 }
60385
60386@@ -2141,7 +2158,7 @@ static void layout_symtab(struct module
60387
60388 /* Put symbol section at end of init part of module. */
60389 symsect->sh_flags |= SHF_ALLOC;
60390- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
60391+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
60392 info->index.sym) | INIT_OFFSET_MASK;
60393 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
60394
60395@@ -2158,19 +2175,19 @@ static void layout_symtab(struct module
60396 }
60397
60398 /* Append room for core symbols at end of core part. */
60399- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
60400- mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
60401+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
60402+ mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
60403
60404 /* Put string table section at end of init part of module. */
60405 strsect->sh_flags |= SHF_ALLOC;
60406- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
60407+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
60408 info->index.str) | INIT_OFFSET_MASK;
60409 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
60410
60411 /* Append room for core symbols' strings at end of core part. */
60412- info->stroffs = mod->core_size;
60413+ info->stroffs = mod->core_size_rx;
60414 __set_bit(0, info->strmap);
60415- mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
60416+ mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
60417 }
60418
60419 static void add_kallsyms(struct module *mod, const struct load_info *info)
60420@@ -2186,11 +2203,13 @@ static void add_kallsyms(struct module *
60421 /* Make sure we get permanent strtab: don't use info->strtab. */
60422 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
60423
60424+ pax_open_kernel();
60425+
60426 /* Set types up while we still have access to sections. */
60427 for (i = 0; i < mod->num_symtab; i++)
60428 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
60429
60430- mod->core_symtab = dst = mod->module_core + info->symoffs;
60431+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
60432 src = mod->symtab;
60433 *dst = *src;
60434 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
60435@@ -2203,10 +2222,12 @@ static void add_kallsyms(struct module *
60436 }
60437 mod->core_num_syms = ndst;
60438
60439- mod->core_strtab = s = mod->module_core + info->stroffs;
60440+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
60441 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
60442 if (test_bit(i, info->strmap))
60443 *++s = mod->strtab[i];
60444+
60445+ pax_close_kernel();
60446 }
60447 #else
60448 static inline void layout_symtab(struct module *mod, struct load_info *info)
60449@@ -2235,17 +2256,33 @@ static void dynamic_debug_remove(struct
60450 ddebug_remove_module(debug->modname);
60451 }
60452
60453-static void *module_alloc_update_bounds(unsigned long size)
60454+static void *module_alloc_update_bounds_rw(unsigned long size)
60455 {
60456 void *ret = module_alloc(size);
60457
60458 if (ret) {
60459 mutex_lock(&module_mutex);
60460 /* Update module bounds. */
60461- if ((unsigned long)ret < module_addr_min)
60462- module_addr_min = (unsigned long)ret;
60463- if ((unsigned long)ret + size > module_addr_max)
60464- module_addr_max = (unsigned long)ret + size;
60465+ if ((unsigned long)ret < module_addr_min_rw)
60466+ module_addr_min_rw = (unsigned long)ret;
60467+ if ((unsigned long)ret + size > module_addr_max_rw)
60468+ module_addr_max_rw = (unsigned long)ret + size;
60469+ mutex_unlock(&module_mutex);
60470+ }
60471+ return ret;
60472+}
60473+
60474+static void *module_alloc_update_bounds_rx(unsigned long size)
60475+{
60476+ void *ret = module_alloc_exec(size);
60477+
60478+ if (ret) {
60479+ mutex_lock(&module_mutex);
60480+ /* Update module bounds. */
60481+ if ((unsigned long)ret < module_addr_min_rx)
60482+ module_addr_min_rx = (unsigned long)ret;
60483+ if ((unsigned long)ret + size > module_addr_max_rx)
60484+ module_addr_max_rx = (unsigned long)ret + size;
60485 mutex_unlock(&module_mutex);
60486 }
60487 return ret;
60488@@ -2538,7 +2575,7 @@ static int move_module(struct module *mo
60489 void *ptr;
60490
60491 /* Do the allocs. */
60492- ptr = module_alloc_update_bounds(mod->core_size);
60493+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
60494 /*
60495 * The pointer to this block is stored in the module structure
60496 * which is inside the block. Just mark it as not being a
60497@@ -2548,23 +2585,50 @@ static int move_module(struct module *mo
60498 if (!ptr)
60499 return -ENOMEM;
60500
60501- memset(ptr, 0, mod->core_size);
60502- mod->module_core = ptr;
60503+ memset(ptr, 0, mod->core_size_rw);
60504+ mod->module_core_rw = ptr;
60505
60506- ptr = module_alloc_update_bounds(mod->init_size);
60507+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
60508 /*
60509 * The pointer to this block is stored in the module structure
60510 * which is inside the block. This block doesn't need to be
60511 * scanned as it contains data and code that will be freed
60512 * after the module is initialized.
60513 */
60514- kmemleak_ignore(ptr);
60515- if (!ptr && mod->init_size) {
60516- module_free(mod, mod->module_core);
60517+ kmemleak_not_leak(ptr);
60518+ if (!ptr && mod->init_size_rw) {
60519+ module_free(mod, mod->module_core_rw);
60520 return -ENOMEM;
60521 }
60522- memset(ptr, 0, mod->init_size);
60523- mod->module_init = ptr;
60524+ memset(ptr, 0, mod->init_size_rw);
60525+ mod->module_init_rw = ptr;
60526+
60527+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
60528+ kmemleak_not_leak(ptr);
60529+ if (!ptr) {
60530+ module_free(mod, mod->module_init_rw);
60531+ module_free(mod, mod->module_core_rw);
60532+ return -ENOMEM;
60533+ }
60534+
60535+ pax_open_kernel();
60536+ memset(ptr, 0, mod->core_size_rx);
60537+ pax_close_kernel();
60538+ mod->module_core_rx = ptr;
60539+
60540+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
60541+ kmemleak_not_leak(ptr);
60542+ if (!ptr && mod->init_size_rx) {
60543+ module_free_exec(mod, mod->module_core_rx);
60544+ module_free(mod, mod->module_init_rw);
60545+ module_free(mod, mod->module_core_rw);
60546+ return -ENOMEM;
60547+ }
60548+
60549+ pax_open_kernel();
60550+ memset(ptr, 0, mod->init_size_rx);
60551+ pax_close_kernel();
60552+ mod->module_init_rx = ptr;
60553
60554 /* Transfer each section which specifies SHF_ALLOC */
60555 DEBUGP("final section addresses:\n");
60556@@ -2575,16 +2639,45 @@ static int move_module(struct module *mo
60557 if (!(shdr->sh_flags & SHF_ALLOC))
60558 continue;
60559
60560- if (shdr->sh_entsize & INIT_OFFSET_MASK)
60561- dest = mod->module_init
60562- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
60563- else
60564- dest = mod->module_core + shdr->sh_entsize;
60565+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
60566+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
60567+ dest = mod->module_init_rw
60568+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
60569+ else
60570+ dest = mod->module_init_rx
60571+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
60572+ } else {
60573+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
60574+ dest = mod->module_core_rw + shdr->sh_entsize;
60575+ else
60576+ dest = mod->module_core_rx + shdr->sh_entsize;
60577+ }
60578+
60579+ if (shdr->sh_type != SHT_NOBITS) {
60580+
60581+#ifdef CONFIG_PAX_KERNEXEC
60582+#ifdef CONFIG_X86_64
60583+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
60584+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
60585+#endif
60586+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
60587+ pax_open_kernel();
60588+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
60589+ pax_close_kernel();
60590+ } else
60591+#endif
60592
60593- if (shdr->sh_type != SHT_NOBITS)
60594 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
60595+ }
60596 /* Update sh_addr to point to copy in image. */
60597- shdr->sh_addr = (unsigned long)dest;
60598+
60599+#ifdef CONFIG_PAX_KERNEXEC
60600+ if (shdr->sh_flags & SHF_EXECINSTR)
60601+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
60602+ else
60603+#endif
60604+
60605+ shdr->sh_addr = (unsigned long)dest;
60606 DEBUGP("\t0x%lx %s\n",
60607 shdr->sh_addr, info->secstrings + shdr->sh_name);
60608 }
60609@@ -2635,12 +2728,12 @@ static void flush_module_icache(const st
60610 * Do it before processing of module parameters, so the module
60611 * can provide parameter accessor functions of its own.
60612 */
60613- if (mod->module_init)
60614- flush_icache_range((unsigned long)mod->module_init,
60615- (unsigned long)mod->module_init
60616- + mod->init_size);
60617- flush_icache_range((unsigned long)mod->module_core,
60618- (unsigned long)mod->module_core + mod->core_size);
60619+ if (mod->module_init_rx)
60620+ flush_icache_range((unsigned long)mod->module_init_rx,
60621+ (unsigned long)mod->module_init_rx
60622+ + mod->init_size_rx);
60623+ flush_icache_range((unsigned long)mod->module_core_rx,
60624+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
60625
60626 set_fs(old_fs);
60627 }
60628@@ -2712,8 +2805,10 @@ static void module_deallocate(struct mod
60629 {
60630 kfree(info->strmap);
60631 percpu_modfree(mod);
60632- module_free(mod, mod->module_init);
60633- module_free(mod, mod->module_core);
60634+ module_free_exec(mod, mod->module_init_rx);
60635+ module_free_exec(mod, mod->module_core_rx);
60636+ module_free(mod, mod->module_init_rw);
60637+ module_free(mod, mod->module_core_rw);
60638 }
60639
60640 static int post_relocation(struct module *mod, const struct load_info *info)
60641@@ -2770,9 +2865,38 @@ static struct module *load_module(void _
60642 if (err)
60643 goto free_unload;
60644
60645+ /* Now copy in args */
60646+ mod->args = strndup_user(uargs, ~0UL >> 1);
60647+ if (IS_ERR(mod->args)) {
60648+ err = PTR_ERR(mod->args);
60649+ goto free_unload;
60650+ }
60651+
60652 /* Set up MODINFO_ATTR fields */
60653 setup_modinfo(mod, &info);
60654
60655+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60656+ {
60657+ char *p, *p2;
60658+
60659+ if (strstr(mod->args, "grsec_modharden_netdev")) {
60660+ 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);
60661+ err = -EPERM;
60662+ goto free_modinfo;
60663+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
60664+ p += strlen("grsec_modharden_normal");
60665+ p2 = strstr(p, "_");
60666+ if (p2) {
60667+ *p2 = '\0';
60668+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
60669+ *p2 = '_';
60670+ }
60671+ err = -EPERM;
60672+ goto free_modinfo;
60673+ }
60674+ }
60675+#endif
60676+
60677 /* Fix up syms, so that st_value is a pointer to location. */
60678 err = simplify_symbols(mod, &info);
60679 if (err < 0)
60680@@ -2788,13 +2912,6 @@ static struct module *load_module(void _
60681
60682 flush_module_icache(mod);
60683
60684- /* Now copy in args */
60685- mod->args = strndup_user(uargs, ~0UL >> 1);
60686- if (IS_ERR(mod->args)) {
60687- err = PTR_ERR(mod->args);
60688- goto free_arch_cleanup;
60689- }
60690-
60691 /* Mark state as coming so strong_try_module_get() ignores us. */
60692 mod->state = MODULE_STATE_COMING;
60693
60694@@ -2854,11 +2971,10 @@ static struct module *load_module(void _
60695 unlock:
60696 mutex_unlock(&module_mutex);
60697 synchronize_sched();
60698- kfree(mod->args);
60699- free_arch_cleanup:
60700 module_arch_cleanup(mod);
60701 free_modinfo:
60702 free_modinfo(mod);
60703+ kfree(mod->args);
60704 free_unload:
60705 module_unload_free(mod);
60706 free_module:
60707@@ -2899,16 +3015,16 @@ SYSCALL_DEFINE3(init_module, void __user
60708 MODULE_STATE_COMING, mod);
60709
60710 /* Set RO and NX regions for core */
60711- set_section_ro_nx(mod->module_core,
60712- mod->core_text_size,
60713- mod->core_ro_size,
60714- mod->core_size);
60715+ set_section_ro_nx(mod->module_core_rx,
60716+ mod->core_size_rx,
60717+ mod->core_size_rx,
60718+ mod->core_size_rx);
60719
60720 /* Set RO and NX regions for init */
60721- set_section_ro_nx(mod->module_init,
60722- mod->init_text_size,
60723- mod->init_ro_size,
60724- mod->init_size);
60725+ set_section_ro_nx(mod->module_init_rx,
60726+ mod->init_size_rx,
60727+ mod->init_size_rx,
60728+ mod->init_size_rx);
60729
60730 do_mod_ctors(mod);
60731 /* Start the module */
60732@@ -2954,11 +3070,12 @@ SYSCALL_DEFINE3(init_module, void __user
60733 mod->strtab = mod->core_strtab;
60734 #endif
60735 unset_module_init_ro_nx(mod);
60736- module_free(mod, mod->module_init);
60737- mod->module_init = NULL;
60738- mod->init_size = 0;
60739- mod->init_ro_size = 0;
60740- mod->init_text_size = 0;
60741+ module_free(mod, mod->module_init_rw);
60742+ module_free_exec(mod, mod->module_init_rx);
60743+ mod->module_init_rw = NULL;
60744+ mod->module_init_rx = NULL;
60745+ mod->init_size_rw = 0;
60746+ mod->init_size_rx = 0;
60747 mutex_unlock(&module_mutex);
60748
60749 return 0;
60750@@ -2989,10 +3106,16 @@ static const char *get_ksymbol(struct mo
60751 unsigned long nextval;
60752
60753 /* At worse, next value is at end of module */
60754- if (within_module_init(addr, mod))
60755- nextval = (unsigned long)mod->module_init+mod->init_text_size;
60756+ if (within_module_init_rx(addr, mod))
60757+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
60758+ else if (within_module_init_rw(addr, mod))
60759+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
60760+ else if (within_module_core_rx(addr, mod))
60761+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
60762+ else if (within_module_core_rw(addr, mod))
60763+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
60764 else
60765- nextval = (unsigned long)mod->module_core+mod->core_text_size;
60766+ return NULL;
60767
60768 /* Scan for closest preceding symbol, and next symbol. (ELF
60769 starts real symbols at 1). */
60770@@ -3238,7 +3361,7 @@ static int m_show(struct seq_file *m, vo
60771 char buf[8];
60772
60773 seq_printf(m, "%s %u",
60774- mod->name, mod->init_size + mod->core_size);
60775+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
60776 print_unload_info(m, mod);
60777
60778 /* Informative for users. */
60779@@ -3247,7 +3370,7 @@ static int m_show(struct seq_file *m, vo
60780 mod->state == MODULE_STATE_COMING ? "Loading":
60781 "Live");
60782 /* Used by oprofile and other similar tools. */
60783- seq_printf(m, " 0x%pK", mod->module_core);
60784+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
60785
60786 /* Taints info */
60787 if (mod->taints)
60788@@ -3283,7 +3406,17 @@ static const struct file_operations proc
60789
60790 static int __init proc_modules_init(void)
60791 {
60792+#ifndef CONFIG_GRKERNSEC_HIDESYM
60793+#ifdef CONFIG_GRKERNSEC_PROC_USER
60794+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
60795+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60796+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
60797+#else
60798 proc_create("modules", 0, NULL, &proc_modules_operations);
60799+#endif
60800+#else
60801+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
60802+#endif
60803 return 0;
60804 }
60805 module_init(proc_modules_init);
60806@@ -3342,12 +3475,12 @@ struct module *__module_address(unsigned
60807 {
60808 struct module *mod;
60809
60810- if (addr < module_addr_min || addr > module_addr_max)
60811+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
60812+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
60813 return NULL;
60814
60815 list_for_each_entry_rcu(mod, &modules, list)
60816- if (within_module_core(addr, mod)
60817- || within_module_init(addr, mod))
60818+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
60819 return mod;
60820 return NULL;
60821 }
60822@@ -3381,11 +3514,20 @@ bool is_module_text_address(unsigned lon
60823 */
60824 struct module *__module_text_address(unsigned long addr)
60825 {
60826- struct module *mod = __module_address(addr);
60827+ struct module *mod;
60828+
60829+#ifdef CONFIG_X86_32
60830+ addr = ktla_ktva(addr);
60831+#endif
60832+
60833+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
60834+ return NULL;
60835+
60836+ mod = __module_address(addr);
60837+
60838 if (mod) {
60839 /* Make sure it's within the text section. */
60840- if (!within(addr, mod->module_init, mod->init_text_size)
60841- && !within(addr, mod->module_core, mod->core_text_size))
60842+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
60843 mod = NULL;
60844 }
60845 return mod;
60846diff -urNp linux-3.0.4/kernel/mutex.c linux-3.0.4/kernel/mutex.c
60847--- linux-3.0.4/kernel/mutex.c 2011-07-21 22:17:23.000000000 -0400
60848+++ linux-3.0.4/kernel/mutex.c 2011-08-23 21:47:56.000000000 -0400
60849@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock,
60850 spin_lock_mutex(&lock->wait_lock, flags);
60851
60852 debug_mutex_lock_common(lock, &waiter);
60853- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
60854+ debug_mutex_add_waiter(lock, &waiter, task);
60855
60856 /* add waiting tasks to the end of the waitqueue (FIFO): */
60857 list_add_tail(&waiter.list, &lock->wait_list);
60858@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock,
60859 * TASK_UNINTERRUPTIBLE case.)
60860 */
60861 if (unlikely(signal_pending_state(state, task))) {
60862- mutex_remove_waiter(lock, &waiter,
60863- task_thread_info(task));
60864+ mutex_remove_waiter(lock, &waiter, task);
60865 mutex_release(&lock->dep_map, 1, ip);
60866 spin_unlock_mutex(&lock->wait_lock, flags);
60867
60868@@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock,
60869 done:
60870 lock_acquired(&lock->dep_map, ip);
60871 /* got the lock - rejoice! */
60872- mutex_remove_waiter(lock, &waiter, current_thread_info());
60873+ mutex_remove_waiter(lock, &waiter, task);
60874 mutex_set_owner(lock);
60875
60876 /* set it to 0 if there are no waiters left: */
60877diff -urNp linux-3.0.4/kernel/mutex-debug.c linux-3.0.4/kernel/mutex-debug.c
60878--- linux-3.0.4/kernel/mutex-debug.c 2011-07-21 22:17:23.000000000 -0400
60879+++ linux-3.0.4/kernel/mutex-debug.c 2011-08-23 21:47:56.000000000 -0400
60880@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
60881 }
60882
60883 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60884- struct thread_info *ti)
60885+ struct task_struct *task)
60886 {
60887 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
60888
60889 /* Mark the current thread as blocked on the lock: */
60890- ti->task->blocked_on = waiter;
60891+ task->blocked_on = waiter;
60892 }
60893
60894 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60895- struct thread_info *ti)
60896+ struct task_struct *task)
60897 {
60898 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
60899- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
60900- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
60901- ti->task->blocked_on = NULL;
60902+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
60903+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
60904+ task->blocked_on = NULL;
60905
60906 list_del_init(&waiter->list);
60907 waiter->task = NULL;
60908diff -urNp linux-3.0.4/kernel/mutex-debug.h linux-3.0.4/kernel/mutex-debug.h
60909--- linux-3.0.4/kernel/mutex-debug.h 2011-07-21 22:17:23.000000000 -0400
60910+++ linux-3.0.4/kernel/mutex-debug.h 2011-08-23 21:47:56.000000000 -0400
60911@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(stru
60912 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
60913 extern void debug_mutex_add_waiter(struct mutex *lock,
60914 struct mutex_waiter *waiter,
60915- struct thread_info *ti);
60916+ struct task_struct *task);
60917 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60918- struct thread_info *ti);
60919+ struct task_struct *task);
60920 extern void debug_mutex_unlock(struct mutex *lock);
60921 extern void debug_mutex_init(struct mutex *lock, const char *name,
60922 struct lock_class_key *key);
60923diff -urNp linux-3.0.4/kernel/padata.c linux-3.0.4/kernel/padata.c
60924--- linux-3.0.4/kernel/padata.c 2011-07-21 22:17:23.000000000 -0400
60925+++ linux-3.0.4/kernel/padata.c 2011-08-23 21:47:56.000000000 -0400
60926@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
60927 padata->pd = pd;
60928 padata->cb_cpu = cb_cpu;
60929
60930- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
60931- atomic_set(&pd->seq_nr, -1);
60932+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
60933+ atomic_set_unchecked(&pd->seq_nr, -1);
60934
60935- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
60936+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
60937
60938 target_cpu = padata_cpu_hash(padata);
60939 queue = per_cpu_ptr(pd->pqueue, target_cpu);
60940@@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
60941 padata_init_pqueues(pd);
60942 padata_init_squeues(pd);
60943 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
60944- atomic_set(&pd->seq_nr, -1);
60945+ atomic_set_unchecked(&pd->seq_nr, -1);
60946 atomic_set(&pd->reorder_objects, 0);
60947 atomic_set(&pd->refcnt, 0);
60948 pd->pinst = pinst;
60949diff -urNp linux-3.0.4/kernel/panic.c linux-3.0.4/kernel/panic.c
60950--- linux-3.0.4/kernel/panic.c 2011-07-21 22:17:23.000000000 -0400
60951+++ linux-3.0.4/kernel/panic.c 2011-08-23 21:48:14.000000000 -0400
60952@@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
60953 const char *board;
60954
60955 printk(KERN_WARNING "------------[ cut here ]------------\n");
60956- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
60957+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
60958 board = dmi_get_system_info(DMI_PRODUCT_NAME);
60959 if (board)
60960 printk(KERN_WARNING "Hardware name: %s\n", board);
60961@@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
60962 */
60963 void __stack_chk_fail(void)
60964 {
60965- panic("stack-protector: Kernel stack is corrupted in: %p\n",
60966+ dump_stack();
60967+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
60968 __builtin_return_address(0));
60969 }
60970 EXPORT_SYMBOL(__stack_chk_fail);
60971diff -urNp linux-3.0.4/kernel/pid.c linux-3.0.4/kernel/pid.c
60972--- linux-3.0.4/kernel/pid.c 2011-07-21 22:17:23.000000000 -0400
60973+++ linux-3.0.4/kernel/pid.c 2011-08-23 21:48:14.000000000 -0400
60974@@ -33,6 +33,7 @@
60975 #include <linux/rculist.h>
60976 #include <linux/bootmem.h>
60977 #include <linux/hash.h>
60978+#include <linux/security.h>
60979 #include <linux/pid_namespace.h>
60980 #include <linux/init_task.h>
60981 #include <linux/syscalls.h>
60982@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
60983
60984 int pid_max = PID_MAX_DEFAULT;
60985
60986-#define RESERVED_PIDS 300
60987+#define RESERVED_PIDS 500
60988
60989 int pid_max_min = RESERVED_PIDS + 1;
60990 int pid_max_max = PID_MAX_LIMIT;
60991@@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
60992 */
60993 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
60994 {
60995+ struct task_struct *task;
60996+
60997 rcu_lockdep_assert(rcu_read_lock_held());
60998- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
60999+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
61000+
61001+ if (gr_pid_is_chrooted(task))
61002+ return NULL;
61003+
61004+ return task;
61005 }
61006
61007 struct task_struct *find_task_by_vpid(pid_t vnr)
61008@@ -428,6 +436,12 @@ struct task_struct *find_task_by_vpid(pi
61009 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
61010 }
61011
61012+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
61013+{
61014+ rcu_lockdep_assert(rcu_read_lock_held());
61015+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
61016+}
61017+
61018 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
61019 {
61020 struct pid *pid;
61021diff -urNp linux-3.0.4/kernel/posix-cpu-timers.c linux-3.0.4/kernel/posix-cpu-timers.c
61022--- linux-3.0.4/kernel/posix-cpu-timers.c 2011-07-21 22:17:23.000000000 -0400
61023+++ linux-3.0.4/kernel/posix-cpu-timers.c 2011-08-23 21:48:14.000000000 -0400
61024@@ -6,6 +6,7 @@
61025 #include <linux/posix-timers.h>
61026 #include <linux/errno.h>
61027 #include <linux/math64.h>
61028+#include <linux/security.h>
61029 #include <asm/uaccess.h>
61030 #include <linux/kernel_stat.h>
61031 #include <trace/events/timer.h>
61032@@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
61033
61034 static __init int init_posix_cpu_timers(void)
61035 {
61036- struct k_clock process = {
61037+ static struct k_clock process = {
61038 .clock_getres = process_cpu_clock_getres,
61039 .clock_get = process_cpu_clock_get,
61040 .timer_create = process_cpu_timer_create,
61041 .nsleep = process_cpu_nsleep,
61042 .nsleep_restart = process_cpu_nsleep_restart,
61043 };
61044- struct k_clock thread = {
61045+ static struct k_clock thread = {
61046 .clock_getres = thread_cpu_clock_getres,
61047 .clock_get = thread_cpu_clock_get,
61048 .timer_create = thread_cpu_timer_create,
61049diff -urNp linux-3.0.4/kernel/posix-timers.c linux-3.0.4/kernel/posix-timers.c
61050--- linux-3.0.4/kernel/posix-timers.c 2011-07-21 22:17:23.000000000 -0400
61051+++ linux-3.0.4/kernel/posix-timers.c 2011-08-23 21:48:14.000000000 -0400
61052@@ -43,6 +43,7 @@
61053 #include <linux/idr.h>
61054 #include <linux/posix-clock.h>
61055 #include <linux/posix-timers.h>
61056+#include <linux/grsecurity.h>
61057 #include <linux/syscalls.h>
61058 #include <linux/wait.h>
61059 #include <linux/workqueue.h>
61060@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
61061 * which we beg off on and pass to do_sys_settimeofday().
61062 */
61063
61064-static struct k_clock posix_clocks[MAX_CLOCKS];
61065+static struct k_clock *posix_clocks[MAX_CLOCKS];
61066
61067 /*
61068 * These ones are defined below.
61069@@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
61070 */
61071 static __init int init_posix_timers(void)
61072 {
61073- struct k_clock clock_realtime = {
61074+ static struct k_clock clock_realtime = {
61075 .clock_getres = hrtimer_get_res,
61076 .clock_get = posix_clock_realtime_get,
61077 .clock_set = posix_clock_realtime_set,
61078@@ -239,7 +240,7 @@ static __init int init_posix_timers(void
61079 .timer_get = common_timer_get,
61080 .timer_del = common_timer_del,
61081 };
61082- struct k_clock clock_monotonic = {
61083+ static struct k_clock clock_monotonic = {
61084 .clock_getres = hrtimer_get_res,
61085 .clock_get = posix_ktime_get_ts,
61086 .nsleep = common_nsleep,
61087@@ -249,19 +250,19 @@ static __init int init_posix_timers(void
61088 .timer_get = common_timer_get,
61089 .timer_del = common_timer_del,
61090 };
61091- struct k_clock clock_monotonic_raw = {
61092+ static struct k_clock clock_monotonic_raw = {
61093 .clock_getres = hrtimer_get_res,
61094 .clock_get = posix_get_monotonic_raw,
61095 };
61096- struct k_clock clock_realtime_coarse = {
61097+ static struct k_clock clock_realtime_coarse = {
61098 .clock_getres = posix_get_coarse_res,
61099 .clock_get = posix_get_realtime_coarse,
61100 };
61101- struct k_clock clock_monotonic_coarse = {
61102+ static struct k_clock clock_monotonic_coarse = {
61103 .clock_getres = posix_get_coarse_res,
61104 .clock_get = posix_get_monotonic_coarse,
61105 };
61106- struct k_clock clock_boottime = {
61107+ static struct k_clock clock_boottime = {
61108 .clock_getres = hrtimer_get_res,
61109 .clock_get = posix_get_boottime,
61110 .nsleep = common_nsleep,
61111@@ -272,6 +273,8 @@ static __init int init_posix_timers(void
61112 .timer_del = common_timer_del,
61113 };
61114
61115+ pax_track_stack();
61116+
61117 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
61118 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
61119 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
61120@@ -473,7 +476,7 @@ void posix_timers_register_clock(const c
61121 return;
61122 }
61123
61124- posix_clocks[clock_id] = *new_clock;
61125+ posix_clocks[clock_id] = new_clock;
61126 }
61127 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
61128
61129@@ -519,9 +522,9 @@ static struct k_clock *clockid_to_kclock
61130 return (id & CLOCKFD_MASK) == CLOCKFD ?
61131 &clock_posix_dynamic : &clock_posix_cpu;
61132
61133- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
61134+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
61135 return NULL;
61136- return &posix_clocks[id];
61137+ return posix_clocks[id];
61138 }
61139
61140 static int common_timer_create(struct k_itimer *new_timer)
61141@@ -959,6 +962,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
61142 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
61143 return -EFAULT;
61144
61145+ /* only the CLOCK_REALTIME clock can be set, all other clocks
61146+ have their clock_set fptr set to a nosettime dummy function
61147+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
61148+ call common_clock_set, which calls do_sys_settimeofday, which
61149+ we hook
61150+ */
61151+
61152 return kc->clock_set(which_clock, &new_tp);
61153 }
61154
61155diff -urNp linux-3.0.4/kernel/power/poweroff.c linux-3.0.4/kernel/power/poweroff.c
61156--- linux-3.0.4/kernel/power/poweroff.c 2011-07-21 22:17:23.000000000 -0400
61157+++ linux-3.0.4/kernel/power/poweroff.c 2011-08-23 21:47:56.000000000 -0400
61158@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
61159 .enable_mask = SYSRQ_ENABLE_BOOT,
61160 };
61161
61162-static int pm_sysrq_init(void)
61163+static int __init pm_sysrq_init(void)
61164 {
61165 register_sysrq_key('o', &sysrq_poweroff_op);
61166 return 0;
61167diff -urNp linux-3.0.4/kernel/power/process.c linux-3.0.4/kernel/power/process.c
61168--- linux-3.0.4/kernel/power/process.c 2011-07-21 22:17:23.000000000 -0400
61169+++ linux-3.0.4/kernel/power/process.c 2011-08-23 21:47:56.000000000 -0400
61170@@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
61171 u64 elapsed_csecs64;
61172 unsigned int elapsed_csecs;
61173 bool wakeup = false;
61174+ bool timedout = false;
61175
61176 do_gettimeofday(&start);
61177
61178@@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
61179
61180 while (true) {
61181 todo = 0;
61182+ if (time_after(jiffies, end_time))
61183+ timedout = true;
61184 read_lock(&tasklist_lock);
61185 do_each_thread(g, p) {
61186 if (frozen(p) || !freezable(p))
61187@@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
61188 * try_to_stop() after schedule() in ptrace/signal
61189 * stop sees TIF_FREEZE.
61190 */
61191- if (!task_is_stopped_or_traced(p) &&
61192- !freezer_should_skip(p))
61193+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
61194 todo++;
61195+ if (timedout) {
61196+ printk(KERN_ERR "Task refusing to freeze:\n");
61197+ sched_show_task(p);
61198+ }
61199+ }
61200 } while_each_thread(g, p);
61201 read_unlock(&tasklist_lock);
61202
61203@@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
61204 todo += wq_busy;
61205 }
61206
61207- if (!todo || time_after(jiffies, end_time))
61208+ if (!todo || timedout)
61209 break;
61210
61211 if (pm_wakeup_pending()) {
61212diff -urNp linux-3.0.4/kernel/printk.c linux-3.0.4/kernel/printk.c
61213--- linux-3.0.4/kernel/printk.c 2011-07-21 22:17:23.000000000 -0400
61214+++ linux-3.0.4/kernel/printk.c 2011-08-23 21:48:14.000000000 -0400
61215@@ -313,12 +313,17 @@ static int check_syslog_permissions(int
61216 if (from_file && type != SYSLOG_ACTION_OPEN)
61217 return 0;
61218
61219+#ifdef CONFIG_GRKERNSEC_DMESG
61220+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
61221+ return -EPERM;
61222+#endif
61223+
61224 if (syslog_action_restricted(type)) {
61225 if (capable(CAP_SYSLOG))
61226 return 0;
61227 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
61228 if (capable(CAP_SYS_ADMIN)) {
61229- WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
61230+ printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
61231 "but no CAP_SYSLOG (deprecated).\n");
61232 return 0;
61233 }
61234diff -urNp linux-3.0.4/kernel/profile.c linux-3.0.4/kernel/profile.c
61235--- linux-3.0.4/kernel/profile.c 2011-07-21 22:17:23.000000000 -0400
61236+++ linux-3.0.4/kernel/profile.c 2011-08-23 21:47:56.000000000 -0400
61237@@ -39,7 +39,7 @@ struct profile_hit {
61238 /* Oprofile timer tick hook */
61239 static int (*timer_hook)(struct pt_regs *) __read_mostly;
61240
61241-static atomic_t *prof_buffer;
61242+static atomic_unchecked_t *prof_buffer;
61243 static unsigned long prof_len, prof_shift;
61244
61245 int prof_on __read_mostly;
61246@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
61247 hits[i].pc = 0;
61248 continue;
61249 }
61250- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
61251+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
61252 hits[i].hits = hits[i].pc = 0;
61253 }
61254 }
61255@@ -342,9 +342,9 @@ static void do_profile_hits(int type, vo
61256 * Add the current hit(s) and flush the write-queue out
61257 * to the global buffer:
61258 */
61259- atomic_add(nr_hits, &prof_buffer[pc]);
61260+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
61261 for (i = 0; i < NR_PROFILE_HIT; ++i) {
61262- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
61263+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
61264 hits[i].pc = hits[i].hits = 0;
61265 }
61266 out:
61267@@ -419,7 +419,7 @@ static void do_profile_hits(int type, vo
61268 {
61269 unsigned long pc;
61270 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
61271- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
61272+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
61273 }
61274 #endif /* !CONFIG_SMP */
61275
61276@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
61277 return -EFAULT;
61278 buf++; p++; count--; read++;
61279 }
61280- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
61281+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
61282 if (copy_to_user(buf, (void *)pnt, count))
61283 return -EFAULT;
61284 read += count;
61285@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
61286 }
61287 #endif
61288 profile_discard_flip_buffers();
61289- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
61290+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
61291 return count;
61292 }
61293
61294diff -urNp linux-3.0.4/kernel/ptrace.c linux-3.0.4/kernel/ptrace.c
61295--- linux-3.0.4/kernel/ptrace.c 2011-07-21 22:17:23.000000000 -0400
61296+++ linux-3.0.4/kernel/ptrace.c 2011-08-23 21:48:14.000000000 -0400
61297@@ -132,7 +132,8 @@ int ptrace_check_attach(struct task_stru
61298 return ret;
61299 }
61300
61301-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
61302+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
61303+ unsigned int log)
61304 {
61305 const struct cred *cred = current_cred(), *tcred;
61306
61307@@ -158,7 +159,8 @@ int __ptrace_may_access(struct task_stru
61308 cred->gid == tcred->sgid &&
61309 cred->gid == tcred->gid))
61310 goto ok;
61311- if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
61312+ if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
61313+ (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
61314 goto ok;
61315 rcu_read_unlock();
61316 return -EPERM;
61317@@ -167,7 +169,9 @@ ok:
61318 smp_rmb();
61319 if (task->mm)
61320 dumpable = get_dumpable(task->mm);
61321- if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
61322+ if (!dumpable &&
61323+ ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
61324+ (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
61325 return -EPERM;
61326
61327 return security_ptrace_access_check(task, mode);
61328@@ -177,7 +181,16 @@ bool ptrace_may_access(struct task_struc
61329 {
61330 int err;
61331 task_lock(task);
61332- err = __ptrace_may_access(task, mode);
61333+ err = __ptrace_may_access(task, mode, 0);
61334+ task_unlock(task);
61335+ return !err;
61336+}
61337+
61338+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
61339+{
61340+ int err;
61341+ task_lock(task);
61342+ err = __ptrace_may_access(task, mode, 1);
61343 task_unlock(task);
61344 return !err;
61345 }
61346@@ -205,7 +218,7 @@ static int ptrace_attach(struct task_str
61347 goto out;
61348
61349 task_lock(task);
61350- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
61351+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
61352 task_unlock(task);
61353 if (retval)
61354 goto unlock_creds;
61355@@ -218,7 +231,7 @@ static int ptrace_attach(struct task_str
61356 goto unlock_tasklist;
61357
61358 task->ptrace = PT_PTRACED;
61359- if (task_ns_capable(task, CAP_SYS_PTRACE))
61360+ if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
61361 task->ptrace |= PT_PTRACE_CAP;
61362
61363 __ptrace_link(task, current);
61364@@ -406,6 +419,8 @@ int ptrace_readdata(struct task_struct *
61365 {
61366 int copied = 0;
61367
61368+ pax_track_stack();
61369+
61370 while (len > 0) {
61371 char buf[128];
61372 int this_len, retval;
61373@@ -417,7 +432,7 @@ int ptrace_readdata(struct task_struct *
61374 break;
61375 return -EIO;
61376 }
61377- if (copy_to_user(dst, buf, retval))
61378+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
61379 return -EFAULT;
61380 copied += retval;
61381 src += retval;
61382@@ -431,6 +446,8 @@ int ptrace_writedata(struct task_struct
61383 {
61384 int copied = 0;
61385
61386+ pax_track_stack();
61387+
61388 while (len > 0) {
61389 char buf[128];
61390 int this_len, retval;
61391@@ -613,9 +630,11 @@ int ptrace_request(struct task_struct *c
61392 {
61393 int ret = -EIO;
61394 siginfo_t siginfo;
61395- void __user *datavp = (void __user *) data;
61396+ void __user *datavp = (__force void __user *) data;
61397 unsigned long __user *datalp = datavp;
61398
61399+ pax_track_stack();
61400+
61401 switch (request) {
61402 case PTRACE_PEEKTEXT:
61403 case PTRACE_PEEKDATA:
61404@@ -761,14 +780,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
61405 goto out;
61406 }
61407
61408+ if (gr_handle_ptrace(child, request)) {
61409+ ret = -EPERM;
61410+ goto out_put_task_struct;
61411+ }
61412+
61413 if (request == PTRACE_ATTACH) {
61414 ret = ptrace_attach(child);
61415 /*
61416 * Some architectures need to do book-keeping after
61417 * a ptrace attach.
61418 */
61419- if (!ret)
61420+ if (!ret) {
61421 arch_ptrace_attach(child);
61422+ gr_audit_ptrace(child);
61423+ }
61424 goto out_put_task_struct;
61425 }
61426
61427@@ -793,7 +819,7 @@ int generic_ptrace_peekdata(struct task_
61428 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
61429 if (copied != sizeof(tmp))
61430 return -EIO;
61431- return put_user(tmp, (unsigned long __user *)data);
61432+ return put_user(tmp, (__force unsigned long __user *)data);
61433 }
61434
61435 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
61436@@ -816,6 +842,8 @@ int compat_ptrace_request(struct task_st
61437 siginfo_t siginfo;
61438 int ret;
61439
61440+ pax_track_stack();
61441+
61442 switch (request) {
61443 case PTRACE_PEEKTEXT:
61444 case PTRACE_PEEKDATA:
61445@@ -903,14 +931,21 @@ asmlinkage long compat_sys_ptrace(compat
61446 goto out;
61447 }
61448
61449+ if (gr_handle_ptrace(child, request)) {
61450+ ret = -EPERM;
61451+ goto out_put_task_struct;
61452+ }
61453+
61454 if (request == PTRACE_ATTACH) {
61455 ret = ptrace_attach(child);
61456 /*
61457 * Some architectures need to do book-keeping after
61458 * a ptrace attach.
61459 */
61460- if (!ret)
61461+ if (!ret) {
61462 arch_ptrace_attach(child);
61463+ gr_audit_ptrace(child);
61464+ }
61465 goto out_put_task_struct;
61466 }
61467
61468diff -urNp linux-3.0.4/kernel/rcutorture.c linux-3.0.4/kernel/rcutorture.c
61469--- linux-3.0.4/kernel/rcutorture.c 2011-07-21 22:17:23.000000000 -0400
61470+++ linux-3.0.4/kernel/rcutorture.c 2011-08-23 21:47:56.000000000 -0400
61471@@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
61472 { 0 };
61473 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
61474 { 0 };
61475-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
61476-static atomic_t n_rcu_torture_alloc;
61477-static atomic_t n_rcu_torture_alloc_fail;
61478-static atomic_t n_rcu_torture_free;
61479-static atomic_t n_rcu_torture_mberror;
61480-static atomic_t n_rcu_torture_error;
61481+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
61482+static atomic_unchecked_t n_rcu_torture_alloc;
61483+static atomic_unchecked_t n_rcu_torture_alloc_fail;
61484+static atomic_unchecked_t n_rcu_torture_free;
61485+static atomic_unchecked_t n_rcu_torture_mberror;
61486+static atomic_unchecked_t n_rcu_torture_error;
61487 static long n_rcu_torture_boost_ktrerror;
61488 static long n_rcu_torture_boost_rterror;
61489 static long n_rcu_torture_boost_failure;
61490@@ -223,11 +223,11 @@ rcu_torture_alloc(void)
61491
61492 spin_lock_bh(&rcu_torture_lock);
61493 if (list_empty(&rcu_torture_freelist)) {
61494- atomic_inc(&n_rcu_torture_alloc_fail);
61495+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
61496 spin_unlock_bh(&rcu_torture_lock);
61497 return NULL;
61498 }
61499- atomic_inc(&n_rcu_torture_alloc);
61500+ atomic_inc_unchecked(&n_rcu_torture_alloc);
61501 p = rcu_torture_freelist.next;
61502 list_del_init(p);
61503 spin_unlock_bh(&rcu_torture_lock);
61504@@ -240,7 +240,7 @@ rcu_torture_alloc(void)
61505 static void
61506 rcu_torture_free(struct rcu_torture *p)
61507 {
61508- atomic_inc(&n_rcu_torture_free);
61509+ atomic_inc_unchecked(&n_rcu_torture_free);
61510 spin_lock_bh(&rcu_torture_lock);
61511 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
61512 spin_unlock_bh(&rcu_torture_lock);
61513@@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
61514 i = rp->rtort_pipe_count;
61515 if (i > RCU_TORTURE_PIPE_LEN)
61516 i = RCU_TORTURE_PIPE_LEN;
61517- atomic_inc(&rcu_torture_wcount[i]);
61518+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61519 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
61520 rp->rtort_mbtest = 0;
61521 rcu_torture_free(rp);
61522@@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_fr
61523 i = rp->rtort_pipe_count;
61524 if (i > RCU_TORTURE_PIPE_LEN)
61525 i = RCU_TORTURE_PIPE_LEN;
61526- atomic_inc(&rcu_torture_wcount[i]);
61527+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61528 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
61529 rp->rtort_mbtest = 0;
61530 list_del(&rp->rtort_free);
61531@@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
61532 i = old_rp->rtort_pipe_count;
61533 if (i > RCU_TORTURE_PIPE_LEN)
61534 i = RCU_TORTURE_PIPE_LEN;
61535- atomic_inc(&rcu_torture_wcount[i]);
61536+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61537 old_rp->rtort_pipe_count++;
61538 cur_ops->deferred_free(old_rp);
61539 }
61540@@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
61541 return;
61542 }
61543 if (p->rtort_mbtest == 0)
61544- atomic_inc(&n_rcu_torture_mberror);
61545+ atomic_inc_unchecked(&n_rcu_torture_mberror);
61546 spin_lock(&rand_lock);
61547 cur_ops->read_delay(&rand);
61548 n_rcu_torture_timers++;
61549@@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
61550 continue;
61551 }
61552 if (p->rtort_mbtest == 0)
61553- atomic_inc(&n_rcu_torture_mberror);
61554+ atomic_inc_unchecked(&n_rcu_torture_mberror);
61555 cur_ops->read_delay(&rand);
61556 preempt_disable();
61557 pipe_count = p->rtort_pipe_count;
61558@@ -1072,16 +1072,16 @@ rcu_torture_printk(char *page)
61559 rcu_torture_current,
61560 rcu_torture_current_version,
61561 list_empty(&rcu_torture_freelist),
61562- atomic_read(&n_rcu_torture_alloc),
61563- atomic_read(&n_rcu_torture_alloc_fail),
61564- atomic_read(&n_rcu_torture_free),
61565- atomic_read(&n_rcu_torture_mberror),
61566+ atomic_read_unchecked(&n_rcu_torture_alloc),
61567+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
61568+ atomic_read_unchecked(&n_rcu_torture_free),
61569+ atomic_read_unchecked(&n_rcu_torture_mberror),
61570 n_rcu_torture_boost_ktrerror,
61571 n_rcu_torture_boost_rterror,
61572 n_rcu_torture_boost_failure,
61573 n_rcu_torture_boosts,
61574 n_rcu_torture_timers);
61575- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
61576+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
61577 n_rcu_torture_boost_ktrerror != 0 ||
61578 n_rcu_torture_boost_rterror != 0 ||
61579 n_rcu_torture_boost_failure != 0)
61580@@ -1089,7 +1089,7 @@ rcu_torture_printk(char *page)
61581 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
61582 if (i > 1) {
61583 cnt += sprintf(&page[cnt], "!!! ");
61584- atomic_inc(&n_rcu_torture_error);
61585+ atomic_inc_unchecked(&n_rcu_torture_error);
61586 WARN_ON_ONCE(1);
61587 }
61588 cnt += sprintf(&page[cnt], "Reader Pipe: ");
61589@@ -1103,7 +1103,7 @@ rcu_torture_printk(char *page)
61590 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
61591 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
61592 cnt += sprintf(&page[cnt], " %d",
61593- atomic_read(&rcu_torture_wcount[i]));
61594+ atomic_read_unchecked(&rcu_torture_wcount[i]));
61595 }
61596 cnt += sprintf(&page[cnt], "\n");
61597 if (cur_ops->stats)
61598@@ -1412,7 +1412,7 @@ rcu_torture_cleanup(void)
61599
61600 if (cur_ops->cleanup)
61601 cur_ops->cleanup();
61602- if (atomic_read(&n_rcu_torture_error))
61603+ if (atomic_read_unchecked(&n_rcu_torture_error))
61604 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
61605 else
61606 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
61607@@ -1476,17 +1476,17 @@ rcu_torture_init(void)
61608
61609 rcu_torture_current = NULL;
61610 rcu_torture_current_version = 0;
61611- atomic_set(&n_rcu_torture_alloc, 0);
61612- atomic_set(&n_rcu_torture_alloc_fail, 0);
61613- atomic_set(&n_rcu_torture_free, 0);
61614- atomic_set(&n_rcu_torture_mberror, 0);
61615- atomic_set(&n_rcu_torture_error, 0);
61616+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
61617+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
61618+ atomic_set_unchecked(&n_rcu_torture_free, 0);
61619+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
61620+ atomic_set_unchecked(&n_rcu_torture_error, 0);
61621 n_rcu_torture_boost_ktrerror = 0;
61622 n_rcu_torture_boost_rterror = 0;
61623 n_rcu_torture_boost_failure = 0;
61624 n_rcu_torture_boosts = 0;
61625 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
61626- atomic_set(&rcu_torture_wcount[i], 0);
61627+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
61628 for_each_possible_cpu(cpu) {
61629 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
61630 per_cpu(rcu_torture_count, cpu)[i] = 0;
61631diff -urNp linux-3.0.4/kernel/rcutree.c linux-3.0.4/kernel/rcutree.c
61632--- linux-3.0.4/kernel/rcutree.c 2011-07-21 22:17:23.000000000 -0400
61633+++ linux-3.0.4/kernel/rcutree.c 2011-08-23 21:47:56.000000000 -0400
61634@@ -1470,7 +1470,7 @@ __rcu_process_callbacks(struct rcu_state
61635 /*
61636 * Do softirq processing for the current CPU.
61637 */
61638-static void rcu_process_callbacks(struct softirq_action *unused)
61639+static void rcu_process_callbacks(void)
61640 {
61641 __rcu_process_callbacks(&rcu_sched_state,
61642 &__get_cpu_var(rcu_sched_data));
61643diff -urNp linux-3.0.4/kernel/rcutree_plugin.h linux-3.0.4/kernel/rcutree_plugin.h
61644--- linux-3.0.4/kernel/rcutree_plugin.h 2011-07-21 22:17:23.000000000 -0400
61645+++ linux-3.0.4/kernel/rcutree_plugin.h 2011-08-23 21:47:56.000000000 -0400
61646@@ -822,7 +822,7 @@ void synchronize_rcu_expedited(void)
61647
61648 /* Clean up and exit. */
61649 smp_mb(); /* ensure expedited GP seen before counter increment. */
61650- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
61651+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
61652 unlock_mb_ret:
61653 mutex_unlock(&sync_rcu_preempt_exp_mutex);
61654 mb_ret:
61655@@ -1774,8 +1774,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
61656
61657 #else /* #ifndef CONFIG_SMP */
61658
61659-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
61660-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
61661+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
61662+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
61663
61664 static int synchronize_sched_expedited_cpu_stop(void *data)
61665 {
61666@@ -1830,7 +1830,7 @@ void synchronize_sched_expedited(void)
61667 int firstsnap, s, snap, trycount = 0;
61668
61669 /* Note that atomic_inc_return() implies full memory barrier. */
61670- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
61671+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
61672 get_online_cpus();
61673
61674 /*
61675@@ -1851,7 +1851,7 @@ void synchronize_sched_expedited(void)
61676 }
61677
61678 /* Check to see if someone else did our work for us. */
61679- s = atomic_read(&sync_sched_expedited_done);
61680+ s = atomic_read_unchecked(&sync_sched_expedited_done);
61681 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
61682 smp_mb(); /* ensure test happens before caller kfree */
61683 return;
61684@@ -1866,7 +1866,7 @@ void synchronize_sched_expedited(void)
61685 * grace period works for us.
61686 */
61687 get_online_cpus();
61688- snap = atomic_read(&sync_sched_expedited_started) - 1;
61689+ snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
61690 smp_mb(); /* ensure read is before try_stop_cpus(). */
61691 }
61692
61693@@ -1877,12 +1877,12 @@ void synchronize_sched_expedited(void)
61694 * than we did beat us to the punch.
61695 */
61696 do {
61697- s = atomic_read(&sync_sched_expedited_done);
61698+ s = atomic_read_unchecked(&sync_sched_expedited_done);
61699 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
61700 smp_mb(); /* ensure test happens before caller kfree */
61701 break;
61702 }
61703- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
61704+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
61705
61706 put_online_cpus();
61707 }
61708diff -urNp linux-3.0.4/kernel/relay.c linux-3.0.4/kernel/relay.c
61709--- linux-3.0.4/kernel/relay.c 2011-07-21 22:17:23.000000000 -0400
61710+++ linux-3.0.4/kernel/relay.c 2011-08-23 21:48:14.000000000 -0400
61711@@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
61712 };
61713 ssize_t ret;
61714
61715+ pax_track_stack();
61716+
61717 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
61718 return 0;
61719 if (splice_grow_spd(pipe, &spd))
61720diff -urNp linux-3.0.4/kernel/resource.c linux-3.0.4/kernel/resource.c
61721--- linux-3.0.4/kernel/resource.c 2011-07-21 22:17:23.000000000 -0400
61722+++ linux-3.0.4/kernel/resource.c 2011-08-23 21:48:14.000000000 -0400
61723@@ -141,8 +141,18 @@ static const struct file_operations proc
61724
61725 static int __init ioresources_init(void)
61726 {
61727+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61728+#ifdef CONFIG_GRKERNSEC_PROC_USER
61729+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
61730+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
61731+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61732+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
61733+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
61734+#endif
61735+#else
61736 proc_create("ioports", 0, NULL, &proc_ioports_operations);
61737 proc_create("iomem", 0, NULL, &proc_iomem_operations);
61738+#endif
61739 return 0;
61740 }
61741 __initcall(ioresources_init);
61742diff -urNp linux-3.0.4/kernel/rtmutex-tester.c linux-3.0.4/kernel/rtmutex-tester.c
61743--- linux-3.0.4/kernel/rtmutex-tester.c 2011-07-21 22:17:23.000000000 -0400
61744+++ linux-3.0.4/kernel/rtmutex-tester.c 2011-08-23 21:47:56.000000000 -0400
61745@@ -20,7 +20,7 @@
61746 #define MAX_RT_TEST_MUTEXES 8
61747
61748 static spinlock_t rttest_lock;
61749-static atomic_t rttest_event;
61750+static atomic_unchecked_t rttest_event;
61751
61752 struct test_thread_data {
61753 int opcode;
61754@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
61755
61756 case RTTEST_LOCKCONT:
61757 td->mutexes[td->opdata] = 1;
61758- td->event = atomic_add_return(1, &rttest_event);
61759+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61760 return 0;
61761
61762 case RTTEST_RESET:
61763@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
61764 return 0;
61765
61766 case RTTEST_RESETEVENT:
61767- atomic_set(&rttest_event, 0);
61768+ atomic_set_unchecked(&rttest_event, 0);
61769 return 0;
61770
61771 default:
61772@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
61773 return ret;
61774
61775 td->mutexes[id] = 1;
61776- td->event = atomic_add_return(1, &rttest_event);
61777+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61778 rt_mutex_lock(&mutexes[id]);
61779- td->event = atomic_add_return(1, &rttest_event);
61780+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61781 td->mutexes[id] = 4;
61782 return 0;
61783
61784@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
61785 return ret;
61786
61787 td->mutexes[id] = 1;
61788- td->event = atomic_add_return(1, &rttest_event);
61789+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61790 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
61791- td->event = atomic_add_return(1, &rttest_event);
61792+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61793 td->mutexes[id] = ret ? 0 : 4;
61794 return ret ? -EINTR : 0;
61795
61796@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
61797 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
61798 return ret;
61799
61800- td->event = atomic_add_return(1, &rttest_event);
61801+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61802 rt_mutex_unlock(&mutexes[id]);
61803- td->event = atomic_add_return(1, &rttest_event);
61804+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61805 td->mutexes[id] = 0;
61806 return 0;
61807
61808@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
61809 break;
61810
61811 td->mutexes[dat] = 2;
61812- td->event = atomic_add_return(1, &rttest_event);
61813+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61814 break;
61815
61816 default:
61817@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
61818 return;
61819
61820 td->mutexes[dat] = 3;
61821- td->event = atomic_add_return(1, &rttest_event);
61822+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61823 break;
61824
61825 case RTTEST_LOCKNOWAIT:
61826@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
61827 return;
61828
61829 td->mutexes[dat] = 1;
61830- td->event = atomic_add_return(1, &rttest_event);
61831+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61832 return;
61833
61834 default:
61835diff -urNp linux-3.0.4/kernel/sched_autogroup.c linux-3.0.4/kernel/sched_autogroup.c
61836--- linux-3.0.4/kernel/sched_autogroup.c 2011-07-21 22:17:23.000000000 -0400
61837+++ linux-3.0.4/kernel/sched_autogroup.c 2011-08-23 21:47:56.000000000 -0400
61838@@ -7,7 +7,7 @@
61839
61840 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
61841 static struct autogroup autogroup_default;
61842-static atomic_t autogroup_seq_nr;
61843+static atomic_unchecked_t autogroup_seq_nr;
61844
61845 static void __init autogroup_init(struct task_struct *init_task)
61846 {
61847@@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
61848
61849 kref_init(&ag->kref);
61850 init_rwsem(&ag->lock);
61851- ag->id = atomic_inc_return(&autogroup_seq_nr);
61852+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
61853 ag->tg = tg;
61854 #ifdef CONFIG_RT_GROUP_SCHED
61855 /*
61856diff -urNp linux-3.0.4/kernel/sched.c linux-3.0.4/kernel/sched.c
61857--- linux-3.0.4/kernel/sched.c 2011-07-21 22:17:23.000000000 -0400
61858+++ linux-3.0.4/kernel/sched.c 2011-08-23 21:48:14.000000000 -0400
61859@@ -4251,6 +4251,8 @@ asmlinkage void __sched schedule(void)
61860 struct rq *rq;
61861 int cpu;
61862
61863+ pax_track_stack();
61864+
61865 need_resched:
61866 preempt_disable();
61867 cpu = smp_processor_id();
61868@@ -4934,6 +4936,8 @@ int can_nice(const struct task_struct *p
61869 /* convert nice value [19,-20] to rlimit style value [1,40] */
61870 int nice_rlim = 20 - nice;
61871
61872+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
61873+
61874 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
61875 capable(CAP_SYS_NICE));
61876 }
61877@@ -4967,7 +4971,8 @@ SYSCALL_DEFINE1(nice, int, increment)
61878 if (nice > 19)
61879 nice = 19;
61880
61881- if (increment < 0 && !can_nice(current, nice))
61882+ if (increment < 0 && (!can_nice(current, nice) ||
61883+ gr_handle_chroot_nice()))
61884 return -EPERM;
61885
61886 retval = security_task_setnice(current, nice);
61887@@ -5111,6 +5116,7 @@ recheck:
61888 unsigned long rlim_rtprio =
61889 task_rlimit(p, RLIMIT_RTPRIO);
61890
61891+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
61892 /* can't set/change the rt policy */
61893 if (policy != p->policy && !rlim_rtprio)
61894 return -EPERM;
61895diff -urNp linux-3.0.4/kernel/sched_fair.c linux-3.0.4/kernel/sched_fair.c
61896--- linux-3.0.4/kernel/sched_fair.c 2011-07-21 22:17:23.000000000 -0400
61897+++ linux-3.0.4/kernel/sched_fair.c 2011-08-23 21:47:56.000000000 -0400
61898@@ -4050,7 +4050,7 @@ static void nohz_idle_balance(int this_c
61899 * run_rebalance_domains is triggered when needed from the scheduler tick.
61900 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
61901 */
61902-static void run_rebalance_domains(struct softirq_action *h)
61903+static void run_rebalance_domains(void)
61904 {
61905 int this_cpu = smp_processor_id();
61906 struct rq *this_rq = cpu_rq(this_cpu);
61907diff -urNp linux-3.0.4/kernel/signal.c linux-3.0.4/kernel/signal.c
61908--- linux-3.0.4/kernel/signal.c 2011-07-21 22:17:23.000000000 -0400
61909+++ linux-3.0.4/kernel/signal.c 2011-08-23 21:48:14.000000000 -0400
61910@@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
61911
61912 int print_fatal_signals __read_mostly;
61913
61914-static void __user *sig_handler(struct task_struct *t, int sig)
61915+static __sighandler_t sig_handler(struct task_struct *t, int sig)
61916 {
61917 return t->sighand->action[sig - 1].sa.sa_handler;
61918 }
61919
61920-static int sig_handler_ignored(void __user *handler, int sig)
61921+static int sig_handler_ignored(__sighandler_t handler, int sig)
61922 {
61923 /* Is it explicitly or implicitly ignored? */
61924 return handler == SIG_IGN ||
61925@@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
61926 static int sig_task_ignored(struct task_struct *t, int sig,
61927 int from_ancestor_ns)
61928 {
61929- void __user *handler;
61930+ __sighandler_t handler;
61931
61932 handler = sig_handler(t, sig);
61933
61934@@ -320,6 +320,9 @@ __sigqueue_alloc(int sig, struct task_st
61935 atomic_inc(&user->sigpending);
61936 rcu_read_unlock();
61937
61938+ if (!override_rlimit)
61939+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
61940+
61941 if (override_rlimit ||
61942 atomic_read(&user->sigpending) <=
61943 task_rlimit(t, RLIMIT_SIGPENDING)) {
61944@@ -444,7 +447,7 @@ flush_signal_handlers(struct task_struct
61945
61946 int unhandled_signal(struct task_struct *tsk, int sig)
61947 {
61948- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
61949+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
61950 if (is_global_init(tsk))
61951 return 1;
61952 if (handler != SIG_IGN && handler != SIG_DFL)
61953@@ -770,6 +773,13 @@ static int check_kill_permission(int sig
61954 }
61955 }
61956
61957+ /* allow glibc communication via tgkill to other threads in our
61958+ thread group */
61959+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
61960+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
61961+ && gr_handle_signal(t, sig))
61962+ return -EPERM;
61963+
61964 return security_task_kill(t, info, sig, 0);
61965 }
61966
61967@@ -1092,7 +1102,7 @@ __group_send_sig_info(int sig, struct si
61968 return send_signal(sig, info, p, 1);
61969 }
61970
61971-static int
61972+int
61973 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
61974 {
61975 return send_signal(sig, info, t, 0);
61976@@ -1129,6 +1139,7 @@ force_sig_info(int sig, struct siginfo *
61977 unsigned long int flags;
61978 int ret, blocked, ignored;
61979 struct k_sigaction *action;
61980+ int is_unhandled = 0;
61981
61982 spin_lock_irqsave(&t->sighand->siglock, flags);
61983 action = &t->sighand->action[sig-1];
61984@@ -1143,9 +1154,18 @@ force_sig_info(int sig, struct siginfo *
61985 }
61986 if (action->sa.sa_handler == SIG_DFL)
61987 t->signal->flags &= ~SIGNAL_UNKILLABLE;
61988+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
61989+ is_unhandled = 1;
61990 ret = specific_send_sig_info(sig, info, t);
61991 spin_unlock_irqrestore(&t->sighand->siglock, flags);
61992
61993+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
61994+ normal operation */
61995+ if (is_unhandled) {
61996+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
61997+ gr_handle_crash(t, sig);
61998+ }
61999+
62000 return ret;
62001 }
62002
62003@@ -1212,8 +1232,11 @@ int group_send_sig_info(int sig, struct
62004 ret = check_kill_permission(sig, info, p);
62005 rcu_read_unlock();
62006
62007- if (!ret && sig)
62008+ if (!ret && sig) {
62009 ret = do_send_sig_info(sig, info, p, true);
62010+ if (!ret)
62011+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
62012+ }
62013
62014 return ret;
62015 }
62016@@ -1839,6 +1862,8 @@ void ptrace_notify(int exit_code)
62017 {
62018 siginfo_t info;
62019
62020+ pax_track_stack();
62021+
62022 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
62023
62024 memset(&info, 0, sizeof info);
62025@@ -2639,7 +2664,15 @@ do_send_specific(pid_t tgid, pid_t pid,
62026 int error = -ESRCH;
62027
62028 rcu_read_lock();
62029- p = find_task_by_vpid(pid);
62030+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62031+ /* allow glibc communication via tgkill to other threads in our
62032+ thread group */
62033+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
62034+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
62035+ p = find_task_by_vpid_unrestricted(pid);
62036+ else
62037+#endif
62038+ p = find_task_by_vpid(pid);
62039 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
62040 error = check_kill_permission(sig, info, p);
62041 /*
62042diff -urNp linux-3.0.4/kernel/smp.c linux-3.0.4/kernel/smp.c
62043--- linux-3.0.4/kernel/smp.c 2011-07-21 22:17:23.000000000 -0400
62044+++ linux-3.0.4/kernel/smp.c 2011-08-23 21:47:56.000000000 -0400
62045@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t fu
62046 }
62047 EXPORT_SYMBOL(smp_call_function);
62048
62049-void ipi_call_lock(void)
62050+void ipi_call_lock(void) __acquires(call_function.lock)
62051 {
62052 raw_spin_lock(&call_function.lock);
62053 }
62054
62055-void ipi_call_unlock(void)
62056+void ipi_call_unlock(void) __releases(call_function.lock)
62057 {
62058 raw_spin_unlock(&call_function.lock);
62059 }
62060
62061-void ipi_call_lock_irq(void)
62062+void ipi_call_lock_irq(void) __acquires(call_function.lock)
62063 {
62064 raw_spin_lock_irq(&call_function.lock);
62065 }
62066
62067-void ipi_call_unlock_irq(void)
62068+void ipi_call_unlock_irq(void) __releases(call_function.lock)
62069 {
62070 raw_spin_unlock_irq(&call_function.lock);
62071 }
62072diff -urNp linux-3.0.4/kernel/softirq.c linux-3.0.4/kernel/softirq.c
62073--- linux-3.0.4/kernel/softirq.c 2011-07-21 22:17:23.000000000 -0400
62074+++ linux-3.0.4/kernel/softirq.c 2011-08-23 21:47:56.000000000 -0400
62075@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
62076
62077 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
62078
62079-char *softirq_to_name[NR_SOFTIRQS] = {
62080+const char * const softirq_to_name[NR_SOFTIRQS] = {
62081 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
62082 "TASKLET", "SCHED", "HRTIMER", "RCU"
62083 };
62084@@ -235,7 +235,7 @@ restart:
62085 kstat_incr_softirqs_this_cpu(vec_nr);
62086
62087 trace_softirq_entry(vec_nr);
62088- h->action(h);
62089+ h->action();
62090 trace_softirq_exit(vec_nr);
62091 if (unlikely(prev_count != preempt_count())) {
62092 printk(KERN_ERR "huh, entered softirq %u %s %p"
62093@@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
62094 local_irq_restore(flags);
62095 }
62096
62097-void open_softirq(int nr, void (*action)(struct softirq_action *))
62098+void open_softirq(int nr, void (*action)(void))
62099 {
62100- softirq_vec[nr].action = action;
62101+ pax_open_kernel();
62102+ *(void **)&softirq_vec[nr].action = action;
62103+ pax_close_kernel();
62104 }
62105
62106 /*
62107@@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct
62108
62109 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
62110
62111-static void tasklet_action(struct softirq_action *a)
62112+static void tasklet_action(void)
62113 {
62114 struct tasklet_struct *list;
62115
62116@@ -476,7 +478,7 @@ static void tasklet_action(struct softir
62117 }
62118 }
62119
62120-static void tasklet_hi_action(struct softirq_action *a)
62121+static void tasklet_hi_action(void)
62122 {
62123 struct tasklet_struct *list;
62124
62125diff -urNp linux-3.0.4/kernel/sys.c linux-3.0.4/kernel/sys.c
62126--- linux-3.0.4/kernel/sys.c 2011-08-29 23:26:14.000000000 -0400
62127+++ linux-3.0.4/kernel/sys.c 2011-08-29 23:26:27.000000000 -0400
62128@@ -158,6 +158,12 @@ static int set_one_prio(struct task_stru
62129 error = -EACCES;
62130 goto out;
62131 }
62132+
62133+ if (gr_handle_chroot_setpriority(p, niceval)) {
62134+ error = -EACCES;
62135+ goto out;
62136+ }
62137+
62138 no_nice = security_task_setnice(p, niceval);
62139 if (no_nice) {
62140 error = no_nice;
62141@@ -541,6 +547,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
62142 goto error;
62143 }
62144
62145+ if (gr_check_group_change(new->gid, new->egid, -1))
62146+ goto error;
62147+
62148 if (rgid != (gid_t) -1 ||
62149 (egid != (gid_t) -1 && egid != old->gid))
62150 new->sgid = new->egid;
62151@@ -570,6 +579,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
62152 old = current_cred();
62153
62154 retval = -EPERM;
62155+
62156+ if (gr_check_group_change(gid, gid, gid))
62157+ goto error;
62158+
62159 if (nsown_capable(CAP_SETGID))
62160 new->gid = new->egid = new->sgid = new->fsgid = gid;
62161 else if (gid == old->gid || gid == old->sgid)
62162@@ -595,11 +608,18 @@ static int set_user(struct cred *new)
62163 if (!new_user)
62164 return -EAGAIN;
62165
62166+ /*
62167+ * We don't fail in case of NPROC limit excess here because too many
62168+ * poorly written programs don't check set*uid() return code, assuming
62169+ * it never fails if called by root. We may still enforce NPROC limit
62170+ * for programs doing set*uid()+execve() by harmlessly deferring the
62171+ * failure to the execve() stage.
62172+ */
62173 if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) &&
62174- new_user != INIT_USER) {
62175- free_uid(new_user);
62176- return -EAGAIN;
62177- }
62178+ new_user != INIT_USER)
62179+ current->flags |= PF_NPROC_EXCEEDED;
62180+ else
62181+ current->flags &= ~PF_NPROC_EXCEEDED;
62182
62183 free_uid(new->user);
62184 new->user = new_user;
62185@@ -650,6 +670,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
62186 goto error;
62187 }
62188
62189+ if (gr_check_user_change(new->uid, new->euid, -1))
62190+ goto error;
62191+
62192 if (new->uid != old->uid) {
62193 retval = set_user(new);
62194 if (retval < 0)
62195@@ -694,6 +717,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
62196 old = current_cred();
62197
62198 retval = -EPERM;
62199+
62200+ if (gr_check_crash_uid(uid))
62201+ goto error;
62202+ if (gr_check_user_change(uid, uid, uid))
62203+ goto error;
62204+
62205 if (nsown_capable(CAP_SETUID)) {
62206 new->suid = new->uid = uid;
62207 if (uid != old->uid) {
62208@@ -748,6 +777,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
62209 goto error;
62210 }
62211
62212+ if (gr_check_user_change(ruid, euid, -1))
62213+ goto error;
62214+
62215 if (ruid != (uid_t) -1) {
62216 new->uid = ruid;
62217 if (ruid != old->uid) {
62218@@ -812,6 +844,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
62219 goto error;
62220 }
62221
62222+ if (gr_check_group_change(rgid, egid, -1))
62223+ goto error;
62224+
62225 if (rgid != (gid_t) -1)
62226 new->gid = rgid;
62227 if (egid != (gid_t) -1)
62228@@ -858,6 +893,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
62229 old = current_cred();
62230 old_fsuid = old->fsuid;
62231
62232+ if (gr_check_user_change(-1, -1, uid))
62233+ goto error;
62234+
62235 if (uid == old->uid || uid == old->euid ||
62236 uid == old->suid || uid == old->fsuid ||
62237 nsown_capable(CAP_SETUID)) {
62238@@ -868,6 +906,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
62239 }
62240 }
62241
62242+error:
62243 abort_creds(new);
62244 return old_fsuid;
62245
62246@@ -894,12 +933,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
62247 if (gid == old->gid || gid == old->egid ||
62248 gid == old->sgid || gid == old->fsgid ||
62249 nsown_capable(CAP_SETGID)) {
62250+ if (gr_check_group_change(-1, -1, gid))
62251+ goto error;
62252+
62253 if (gid != old_fsgid) {
62254 new->fsgid = gid;
62255 goto change_okay;
62256 }
62257 }
62258
62259+error:
62260 abort_creds(new);
62261 return old_fsgid;
62262
62263@@ -1680,7 +1723,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
62264 error = get_dumpable(me->mm);
62265 break;
62266 case PR_SET_DUMPABLE:
62267- if (arg2 < 0 || arg2 > 1) {
62268+ if (arg2 > 1) {
62269 error = -EINVAL;
62270 break;
62271 }
62272diff -urNp linux-3.0.4/kernel/sysctl.c linux-3.0.4/kernel/sysctl.c
62273--- linux-3.0.4/kernel/sysctl.c 2011-07-21 22:17:23.000000000 -0400
62274+++ linux-3.0.4/kernel/sysctl.c 2011-08-23 21:48:14.000000000 -0400
62275@@ -85,6 +85,13 @@
62276
62277
62278 #if defined(CONFIG_SYSCTL)
62279+#include <linux/grsecurity.h>
62280+#include <linux/grinternal.h>
62281+
62282+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
62283+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62284+ const int op);
62285+extern int gr_handle_chroot_sysctl(const int op);
62286
62287 /* External variables not in a header file. */
62288 extern int sysctl_overcommit_memory;
62289@@ -197,6 +204,7 @@ static int sysrq_sysctl_handler(ctl_tabl
62290 }
62291
62292 #endif
62293+extern struct ctl_table grsecurity_table[];
62294
62295 static struct ctl_table root_table[];
62296 static struct ctl_table_root sysctl_table_root;
62297@@ -226,6 +234,20 @@ extern struct ctl_table epoll_table[];
62298 int sysctl_legacy_va_layout;
62299 #endif
62300
62301+#ifdef CONFIG_PAX_SOFTMODE
62302+static ctl_table pax_table[] = {
62303+ {
62304+ .procname = "softmode",
62305+ .data = &pax_softmode,
62306+ .maxlen = sizeof(unsigned int),
62307+ .mode = 0600,
62308+ .proc_handler = &proc_dointvec,
62309+ },
62310+
62311+ { }
62312+};
62313+#endif
62314+
62315 /* The default sysctl tables: */
62316
62317 static struct ctl_table root_table[] = {
62318@@ -272,6 +294,22 @@ static int max_extfrag_threshold = 1000;
62319 #endif
62320
62321 static struct ctl_table kern_table[] = {
62322+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62323+ {
62324+ .procname = "grsecurity",
62325+ .mode = 0500,
62326+ .child = grsecurity_table,
62327+ },
62328+#endif
62329+
62330+#ifdef CONFIG_PAX_SOFTMODE
62331+ {
62332+ .procname = "pax",
62333+ .mode = 0500,
62334+ .child = pax_table,
62335+ },
62336+#endif
62337+
62338 {
62339 .procname = "sched_child_runs_first",
62340 .data = &sysctl_sched_child_runs_first,
62341@@ -546,7 +584,7 @@ static struct ctl_table kern_table[] = {
62342 .data = &modprobe_path,
62343 .maxlen = KMOD_PATH_LEN,
62344 .mode = 0644,
62345- .proc_handler = proc_dostring,
62346+ .proc_handler = proc_dostring_modpriv,
62347 },
62348 {
62349 .procname = "modules_disabled",
62350@@ -713,16 +751,20 @@ static struct ctl_table kern_table[] = {
62351 .extra1 = &zero,
62352 .extra2 = &one,
62353 },
62354+#endif
62355 {
62356 .procname = "kptr_restrict",
62357 .data = &kptr_restrict,
62358 .maxlen = sizeof(int),
62359 .mode = 0644,
62360 .proc_handler = proc_dmesg_restrict,
62361+#ifdef CONFIG_GRKERNSEC_HIDESYM
62362+ .extra1 = &two,
62363+#else
62364 .extra1 = &zero,
62365+#endif
62366 .extra2 = &two,
62367 },
62368-#endif
62369 {
62370 .procname = "ngroups_max",
62371 .data = &ngroups_max,
62372@@ -1205,6 +1247,13 @@ static struct ctl_table vm_table[] = {
62373 .proc_handler = proc_dointvec_minmax,
62374 .extra1 = &zero,
62375 },
62376+ {
62377+ .procname = "heap_stack_gap",
62378+ .data = &sysctl_heap_stack_gap,
62379+ .maxlen = sizeof(sysctl_heap_stack_gap),
62380+ .mode = 0644,
62381+ .proc_handler = proc_doulongvec_minmax,
62382+ },
62383 #else
62384 {
62385 .procname = "nr_trim_pages",
62386@@ -1714,6 +1763,17 @@ static int test_perm(int mode, int op)
62387 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
62388 {
62389 int mode;
62390+ int error;
62391+
62392+ if (table->parent != NULL && table->parent->procname != NULL &&
62393+ table->procname != NULL &&
62394+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
62395+ return -EACCES;
62396+ if (gr_handle_chroot_sysctl(op))
62397+ return -EACCES;
62398+ error = gr_handle_sysctl(table, op);
62399+ if (error)
62400+ return error;
62401
62402 if (root->permissions)
62403 mode = root->permissions(root, current->nsproxy, table);
62404@@ -2118,6 +2178,16 @@ int proc_dostring(struct ctl_table *tabl
62405 buffer, lenp, ppos);
62406 }
62407
62408+int proc_dostring_modpriv(struct ctl_table *table, int write,
62409+ void __user *buffer, size_t *lenp, loff_t *ppos)
62410+{
62411+ if (write && !capable(CAP_SYS_MODULE))
62412+ return -EPERM;
62413+
62414+ return _proc_do_string(table->data, table->maxlen, write,
62415+ buffer, lenp, ppos);
62416+}
62417+
62418 static size_t proc_skip_spaces(char **buf)
62419 {
62420 size_t ret;
62421@@ -2223,6 +2293,8 @@ static int proc_put_long(void __user **b
62422 len = strlen(tmp);
62423 if (len > *size)
62424 len = *size;
62425+ if (len > sizeof(tmp))
62426+ len = sizeof(tmp);
62427 if (copy_to_user(*buf, tmp, len))
62428 return -EFAULT;
62429 *size -= len;
62430@@ -2539,8 +2611,11 @@ static int __do_proc_doulongvec_minmax(v
62431 *i = val;
62432 } else {
62433 val = convdiv * (*i) / convmul;
62434- if (!first)
62435+ if (!first) {
62436 err = proc_put_char(&buffer, &left, '\t');
62437+ if (err)
62438+ break;
62439+ }
62440 err = proc_put_long(&buffer, &left, val, false);
62441 if (err)
62442 break;
62443@@ -2935,6 +3010,12 @@ int proc_dostring(struct ctl_table *tabl
62444 return -ENOSYS;
62445 }
62446
62447+int proc_dostring_modpriv(struct ctl_table *table, int write,
62448+ void __user *buffer, size_t *lenp, loff_t *ppos)
62449+{
62450+ return -ENOSYS;
62451+}
62452+
62453 int proc_dointvec(struct ctl_table *table, int write,
62454 void __user *buffer, size_t *lenp, loff_t *ppos)
62455 {
62456@@ -2991,6 +3072,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
62457 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
62458 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
62459 EXPORT_SYMBOL(proc_dostring);
62460+EXPORT_SYMBOL(proc_dostring_modpriv);
62461 EXPORT_SYMBOL(proc_doulongvec_minmax);
62462 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
62463 EXPORT_SYMBOL(register_sysctl_table);
62464diff -urNp linux-3.0.4/kernel/sysctl_check.c linux-3.0.4/kernel/sysctl_check.c
62465--- linux-3.0.4/kernel/sysctl_check.c 2011-07-21 22:17:23.000000000 -0400
62466+++ linux-3.0.4/kernel/sysctl_check.c 2011-08-23 21:48:14.000000000 -0400
62467@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
62468 set_fail(&fail, table, "Directory with extra2");
62469 } else {
62470 if ((table->proc_handler == proc_dostring) ||
62471+ (table->proc_handler == proc_dostring_modpriv) ||
62472 (table->proc_handler == proc_dointvec) ||
62473 (table->proc_handler == proc_dointvec_minmax) ||
62474 (table->proc_handler == proc_dointvec_jiffies) ||
62475diff -urNp linux-3.0.4/kernel/taskstats.c linux-3.0.4/kernel/taskstats.c
62476--- linux-3.0.4/kernel/taskstats.c 2011-07-21 22:17:23.000000000 -0400
62477+++ linux-3.0.4/kernel/taskstats.c 2011-08-23 21:48:14.000000000 -0400
62478@@ -27,9 +27,12 @@
62479 #include <linux/cgroup.h>
62480 #include <linux/fs.h>
62481 #include <linux/file.h>
62482+#include <linux/grsecurity.h>
62483 #include <net/genetlink.h>
62484 #include <asm/atomic.h>
62485
62486+extern int gr_is_taskstats_denied(int pid);
62487+
62488 /*
62489 * Maximum length of a cpumask that can be specified in
62490 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
62491@@ -558,6 +561,9 @@ err:
62492
62493 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
62494 {
62495+ if (gr_is_taskstats_denied(current->pid))
62496+ return -EACCES;
62497+
62498 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
62499 return cmd_attr_register_cpumask(info);
62500 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
62501diff -urNp linux-3.0.4/kernel/time/alarmtimer.c linux-3.0.4/kernel/time/alarmtimer.c
62502--- linux-3.0.4/kernel/time/alarmtimer.c 2011-07-21 22:17:23.000000000 -0400
62503+++ linux-3.0.4/kernel/time/alarmtimer.c 2011-08-23 21:47:56.000000000 -0400
62504@@ -685,7 +685,7 @@ static int __init alarmtimer_init(void)
62505 {
62506 int error = 0;
62507 int i;
62508- struct k_clock alarm_clock = {
62509+ static struct k_clock alarm_clock = {
62510 .clock_getres = alarm_clock_getres,
62511 .clock_get = alarm_clock_get,
62512 .timer_create = alarm_timer_create,
62513diff -urNp linux-3.0.4/kernel/time/tick-broadcast.c linux-3.0.4/kernel/time/tick-broadcast.c
62514--- linux-3.0.4/kernel/time/tick-broadcast.c 2011-07-21 22:17:23.000000000 -0400
62515+++ linux-3.0.4/kernel/time/tick-broadcast.c 2011-08-23 21:47:56.000000000 -0400
62516@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
62517 * then clear the broadcast bit.
62518 */
62519 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
62520- int cpu = smp_processor_id();
62521+ cpu = smp_processor_id();
62522
62523 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
62524 tick_broadcast_clear_oneshot(cpu);
62525diff -urNp linux-3.0.4/kernel/time/timekeeping.c linux-3.0.4/kernel/time/timekeeping.c
62526--- linux-3.0.4/kernel/time/timekeeping.c 2011-07-21 22:17:23.000000000 -0400
62527+++ linux-3.0.4/kernel/time/timekeeping.c 2011-08-23 21:48:14.000000000 -0400
62528@@ -14,6 +14,7 @@
62529 #include <linux/init.h>
62530 #include <linux/mm.h>
62531 #include <linux/sched.h>
62532+#include <linux/grsecurity.h>
62533 #include <linux/syscore_ops.h>
62534 #include <linux/clocksource.h>
62535 #include <linux/jiffies.h>
62536@@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
62537 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
62538 return -EINVAL;
62539
62540+ gr_log_timechange();
62541+
62542 write_seqlock_irqsave(&xtime_lock, flags);
62543
62544 timekeeping_forward_now();
62545diff -urNp linux-3.0.4/kernel/time/timer_list.c linux-3.0.4/kernel/time/timer_list.c
62546--- linux-3.0.4/kernel/time/timer_list.c 2011-07-21 22:17:23.000000000 -0400
62547+++ linux-3.0.4/kernel/time/timer_list.c 2011-08-23 21:48:14.000000000 -0400
62548@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
62549
62550 static void print_name_offset(struct seq_file *m, void *sym)
62551 {
62552+#ifdef CONFIG_GRKERNSEC_HIDESYM
62553+ SEQ_printf(m, "<%p>", NULL);
62554+#else
62555 char symname[KSYM_NAME_LEN];
62556
62557 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
62558 SEQ_printf(m, "<%pK>", sym);
62559 else
62560 SEQ_printf(m, "%s", symname);
62561+#endif
62562 }
62563
62564 static void
62565@@ -112,7 +116,11 @@ next_one:
62566 static void
62567 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
62568 {
62569+#ifdef CONFIG_GRKERNSEC_HIDESYM
62570+ SEQ_printf(m, " .base: %p\n", NULL);
62571+#else
62572 SEQ_printf(m, " .base: %pK\n", base);
62573+#endif
62574 SEQ_printf(m, " .index: %d\n",
62575 base->index);
62576 SEQ_printf(m, " .resolution: %Lu nsecs\n",
62577@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
62578 {
62579 struct proc_dir_entry *pe;
62580
62581+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62582+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
62583+#else
62584 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
62585+#endif
62586 if (!pe)
62587 return -ENOMEM;
62588 return 0;
62589diff -urNp linux-3.0.4/kernel/time/timer_stats.c linux-3.0.4/kernel/time/timer_stats.c
62590--- linux-3.0.4/kernel/time/timer_stats.c 2011-07-21 22:17:23.000000000 -0400
62591+++ linux-3.0.4/kernel/time/timer_stats.c 2011-08-23 21:48:14.000000000 -0400
62592@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
62593 static unsigned long nr_entries;
62594 static struct entry entries[MAX_ENTRIES];
62595
62596-static atomic_t overflow_count;
62597+static atomic_unchecked_t overflow_count;
62598
62599 /*
62600 * The entries are in a hash-table, for fast lookup:
62601@@ -140,7 +140,7 @@ static void reset_entries(void)
62602 nr_entries = 0;
62603 memset(entries, 0, sizeof(entries));
62604 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
62605- atomic_set(&overflow_count, 0);
62606+ atomic_set_unchecked(&overflow_count, 0);
62607 }
62608
62609 static struct entry *alloc_entry(void)
62610@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
62611 if (likely(entry))
62612 entry->count++;
62613 else
62614- atomic_inc(&overflow_count);
62615+ atomic_inc_unchecked(&overflow_count);
62616
62617 out_unlock:
62618 raw_spin_unlock_irqrestore(lock, flags);
62619@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
62620
62621 static void print_name_offset(struct seq_file *m, unsigned long addr)
62622 {
62623+#ifdef CONFIG_GRKERNSEC_HIDESYM
62624+ seq_printf(m, "<%p>", NULL);
62625+#else
62626 char symname[KSYM_NAME_LEN];
62627
62628 if (lookup_symbol_name(addr, symname) < 0)
62629 seq_printf(m, "<%p>", (void *)addr);
62630 else
62631 seq_printf(m, "%s", symname);
62632+#endif
62633 }
62634
62635 static int tstats_show(struct seq_file *m, void *v)
62636@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
62637
62638 seq_puts(m, "Timer Stats Version: v0.2\n");
62639 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
62640- if (atomic_read(&overflow_count))
62641+ if (atomic_read_unchecked(&overflow_count))
62642 seq_printf(m, "Overflow: %d entries\n",
62643- atomic_read(&overflow_count));
62644+ atomic_read_unchecked(&overflow_count));
62645
62646 for (i = 0; i < nr_entries; i++) {
62647 entry = entries + i;
62648@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
62649 {
62650 struct proc_dir_entry *pe;
62651
62652+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62653+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
62654+#else
62655 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
62656+#endif
62657 if (!pe)
62658 return -ENOMEM;
62659 return 0;
62660diff -urNp linux-3.0.4/kernel/time.c linux-3.0.4/kernel/time.c
62661--- linux-3.0.4/kernel/time.c 2011-07-21 22:17:23.000000000 -0400
62662+++ linux-3.0.4/kernel/time.c 2011-08-23 21:48:14.000000000 -0400
62663@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
62664 return error;
62665
62666 if (tz) {
62667+ /* we log in do_settimeofday called below, so don't log twice
62668+ */
62669+ if (!tv)
62670+ gr_log_timechange();
62671+
62672 /* SMP safe, global irq locking makes it work. */
62673 sys_tz = *tz;
62674 update_vsyscall_tz();
62675diff -urNp linux-3.0.4/kernel/timer.c linux-3.0.4/kernel/timer.c
62676--- linux-3.0.4/kernel/timer.c 2011-07-21 22:17:23.000000000 -0400
62677+++ linux-3.0.4/kernel/timer.c 2011-08-23 21:47:56.000000000 -0400
62678@@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
62679 /*
62680 * This function runs timers and the timer-tq in bottom half context.
62681 */
62682-static void run_timer_softirq(struct softirq_action *h)
62683+static void run_timer_softirq(void)
62684 {
62685 struct tvec_base *base = __this_cpu_read(tvec_bases);
62686
62687diff -urNp linux-3.0.4/kernel/trace/blktrace.c linux-3.0.4/kernel/trace/blktrace.c
62688--- linux-3.0.4/kernel/trace/blktrace.c 2011-07-21 22:17:23.000000000 -0400
62689+++ linux-3.0.4/kernel/trace/blktrace.c 2011-08-23 21:47:56.000000000 -0400
62690@@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
62691 struct blk_trace *bt = filp->private_data;
62692 char buf[16];
62693
62694- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
62695+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
62696
62697 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
62698 }
62699@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
62700 return 1;
62701
62702 bt = buf->chan->private_data;
62703- atomic_inc(&bt->dropped);
62704+ atomic_inc_unchecked(&bt->dropped);
62705 return 0;
62706 }
62707
62708@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
62709
62710 bt->dir = dir;
62711 bt->dev = dev;
62712- atomic_set(&bt->dropped, 0);
62713+ atomic_set_unchecked(&bt->dropped, 0);
62714
62715 ret = -EIO;
62716 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
62717diff -urNp linux-3.0.4/kernel/trace/ftrace.c linux-3.0.4/kernel/trace/ftrace.c
62718--- linux-3.0.4/kernel/trace/ftrace.c 2011-07-21 22:17:23.000000000 -0400
62719+++ linux-3.0.4/kernel/trace/ftrace.c 2011-08-23 21:47:56.000000000 -0400
62720@@ -1566,12 +1566,17 @@ ftrace_code_disable(struct module *mod,
62721 if (unlikely(ftrace_disabled))
62722 return 0;
62723
62724+ ret = ftrace_arch_code_modify_prepare();
62725+ FTRACE_WARN_ON(ret);
62726+ if (ret)
62727+ return 0;
62728+
62729 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
62730+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
62731 if (ret) {
62732 ftrace_bug(ret, ip);
62733- return 0;
62734 }
62735- return 1;
62736+ return ret ? 0 : 1;
62737 }
62738
62739 /*
62740@@ -2550,7 +2555,7 @@ static void ftrace_free_entry_rcu(struct
62741
62742 int
62743 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62744- void *data)
62745+ void *data)
62746 {
62747 struct ftrace_func_probe *entry;
62748 struct ftrace_page *pg;
62749diff -urNp linux-3.0.4/kernel/trace/trace.c linux-3.0.4/kernel/trace/trace.c
62750--- linux-3.0.4/kernel/trace/trace.c 2011-07-21 22:17:23.000000000 -0400
62751+++ linux-3.0.4/kernel/trace/trace.c 2011-08-23 21:48:14.000000000 -0400
62752@@ -3339,6 +3339,8 @@ static ssize_t tracing_splice_read_pipe(
62753 size_t rem;
62754 unsigned int i;
62755
62756+ pax_track_stack();
62757+
62758 if (splice_grow_spd(pipe, &spd))
62759 return -ENOMEM;
62760
62761@@ -3822,6 +3824,8 @@ tracing_buffers_splice_read(struct file
62762 int entries, size, i;
62763 size_t ret;
62764
62765+ pax_track_stack();
62766+
62767 if (splice_grow_spd(pipe, &spd))
62768 return -ENOMEM;
62769
62770@@ -3990,10 +3994,9 @@ static const struct file_operations trac
62771 };
62772 #endif
62773
62774-static struct dentry *d_tracer;
62775-
62776 struct dentry *tracing_init_dentry(void)
62777 {
62778+ static struct dentry *d_tracer;
62779 static int once;
62780
62781 if (d_tracer)
62782@@ -4013,10 +4016,9 @@ struct dentry *tracing_init_dentry(void)
62783 return d_tracer;
62784 }
62785
62786-static struct dentry *d_percpu;
62787-
62788 struct dentry *tracing_dentry_percpu(void)
62789 {
62790+ static struct dentry *d_percpu;
62791 static int once;
62792 struct dentry *d_tracer;
62793
62794diff -urNp linux-3.0.4/kernel/trace/trace_events.c linux-3.0.4/kernel/trace/trace_events.c
62795--- linux-3.0.4/kernel/trace/trace_events.c 2011-08-23 21:44:40.000000000 -0400
62796+++ linux-3.0.4/kernel/trace/trace_events.c 2011-08-23 21:47:56.000000000 -0400
62797@@ -1318,10 +1318,6 @@ static LIST_HEAD(ftrace_module_file_list
62798 struct ftrace_module_file_ops {
62799 struct list_head list;
62800 struct module *mod;
62801- struct file_operations id;
62802- struct file_operations enable;
62803- struct file_operations format;
62804- struct file_operations filter;
62805 };
62806
62807 static struct ftrace_module_file_ops *
62808@@ -1342,17 +1338,12 @@ trace_create_file_ops(struct module *mod
62809
62810 file_ops->mod = mod;
62811
62812- file_ops->id = ftrace_event_id_fops;
62813- file_ops->id.owner = mod;
62814-
62815- file_ops->enable = ftrace_enable_fops;
62816- file_ops->enable.owner = mod;
62817-
62818- file_ops->filter = ftrace_event_filter_fops;
62819- file_ops->filter.owner = mod;
62820-
62821- file_ops->format = ftrace_event_format_fops;
62822- file_ops->format.owner = mod;
62823+ pax_open_kernel();
62824+ *(void **)&mod->trace_id.owner = mod;
62825+ *(void **)&mod->trace_enable.owner = mod;
62826+ *(void **)&mod->trace_filter.owner = mod;
62827+ *(void **)&mod->trace_format.owner = mod;
62828+ pax_close_kernel();
62829
62830 list_add(&file_ops->list, &ftrace_module_file_list);
62831
62832@@ -1376,8 +1367,8 @@ static void trace_module_add_events(stru
62833
62834 for_each_event(call, start, end) {
62835 __trace_add_event_call(*call, mod,
62836- &file_ops->id, &file_ops->enable,
62837- &file_ops->filter, &file_ops->format);
62838+ &mod->trace_id, &mod->trace_enable,
62839+ &mod->trace_filter, &mod->trace_format);
62840 }
62841 }
62842
62843diff -urNp linux-3.0.4/kernel/trace/trace_mmiotrace.c linux-3.0.4/kernel/trace/trace_mmiotrace.c
62844--- linux-3.0.4/kernel/trace/trace_mmiotrace.c 2011-07-21 22:17:23.000000000 -0400
62845+++ linux-3.0.4/kernel/trace/trace_mmiotrace.c 2011-08-23 21:47:56.000000000 -0400
62846@@ -24,7 +24,7 @@ struct header_iter {
62847 static struct trace_array *mmio_trace_array;
62848 static bool overrun_detected;
62849 static unsigned long prev_overruns;
62850-static atomic_t dropped_count;
62851+static atomic_unchecked_t dropped_count;
62852
62853 static void mmio_reset_data(struct trace_array *tr)
62854 {
62855@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
62856
62857 static unsigned long count_overruns(struct trace_iterator *iter)
62858 {
62859- unsigned long cnt = atomic_xchg(&dropped_count, 0);
62860+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
62861 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
62862
62863 if (over > prev_overruns)
62864@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
62865 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
62866 sizeof(*entry), 0, pc);
62867 if (!event) {
62868- atomic_inc(&dropped_count);
62869+ atomic_inc_unchecked(&dropped_count);
62870 return;
62871 }
62872 entry = ring_buffer_event_data(event);
62873@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
62874 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
62875 sizeof(*entry), 0, pc);
62876 if (!event) {
62877- atomic_inc(&dropped_count);
62878+ atomic_inc_unchecked(&dropped_count);
62879 return;
62880 }
62881 entry = ring_buffer_event_data(event);
62882diff -urNp linux-3.0.4/kernel/trace/trace_output.c linux-3.0.4/kernel/trace/trace_output.c
62883--- linux-3.0.4/kernel/trace/trace_output.c 2011-07-21 22:17:23.000000000 -0400
62884+++ linux-3.0.4/kernel/trace/trace_output.c 2011-08-23 21:47:56.000000000 -0400
62885@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
62886
62887 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
62888 if (!IS_ERR(p)) {
62889- p = mangle_path(s->buffer + s->len, p, "\n");
62890+ p = mangle_path(s->buffer + s->len, p, "\n\\");
62891 if (p) {
62892 s->len = p - s->buffer;
62893 return 1;
62894diff -urNp linux-3.0.4/kernel/trace/trace_stack.c linux-3.0.4/kernel/trace/trace_stack.c
62895--- linux-3.0.4/kernel/trace/trace_stack.c 2011-07-21 22:17:23.000000000 -0400
62896+++ linux-3.0.4/kernel/trace/trace_stack.c 2011-08-23 21:47:56.000000000 -0400
62897@@ -50,7 +50,7 @@ static inline void check_stack(void)
62898 return;
62899
62900 /* we do not handle interrupt stacks yet */
62901- if (!object_is_on_stack(&this_size))
62902+ if (!object_starts_on_stack(&this_size))
62903 return;
62904
62905 local_irq_save(flags);
62906diff -urNp linux-3.0.4/kernel/trace/trace_workqueue.c linux-3.0.4/kernel/trace/trace_workqueue.c
62907--- linux-3.0.4/kernel/trace/trace_workqueue.c 2011-07-21 22:17:23.000000000 -0400
62908+++ linux-3.0.4/kernel/trace/trace_workqueue.c 2011-08-23 21:47:56.000000000 -0400
62909@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
62910 int cpu;
62911 pid_t pid;
62912 /* Can be inserted from interrupt or user context, need to be atomic */
62913- atomic_t inserted;
62914+ atomic_unchecked_t inserted;
62915 /*
62916 * Don't need to be atomic, works are serialized in a single workqueue thread
62917 * on a single CPU.
62918@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
62919 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
62920 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
62921 if (node->pid == wq_thread->pid) {
62922- atomic_inc(&node->inserted);
62923+ atomic_inc_unchecked(&node->inserted);
62924 goto found;
62925 }
62926 }
62927@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
62928 tsk = get_pid_task(pid, PIDTYPE_PID);
62929 if (tsk) {
62930 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
62931- atomic_read(&cws->inserted), cws->executed,
62932+ atomic_read_unchecked(&cws->inserted), cws->executed,
62933 tsk->comm);
62934 put_task_struct(tsk);
62935 }
62936diff -urNp linux-3.0.4/lib/bug.c linux-3.0.4/lib/bug.c
62937--- linux-3.0.4/lib/bug.c 2011-07-21 22:17:23.000000000 -0400
62938+++ linux-3.0.4/lib/bug.c 2011-08-23 21:47:56.000000000 -0400
62939@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
62940 return BUG_TRAP_TYPE_NONE;
62941
62942 bug = find_bug(bugaddr);
62943+ if (!bug)
62944+ return BUG_TRAP_TYPE_NONE;
62945
62946 file = NULL;
62947 line = 0;
62948diff -urNp linux-3.0.4/lib/debugobjects.c linux-3.0.4/lib/debugobjects.c
62949--- linux-3.0.4/lib/debugobjects.c 2011-07-21 22:17:23.000000000 -0400
62950+++ linux-3.0.4/lib/debugobjects.c 2011-08-23 21:47:56.000000000 -0400
62951@@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
62952 if (limit > 4)
62953 return;
62954
62955- is_on_stack = object_is_on_stack(addr);
62956+ is_on_stack = object_starts_on_stack(addr);
62957 if (is_on_stack == onstack)
62958 return;
62959
62960diff -urNp linux-3.0.4/lib/dma-debug.c linux-3.0.4/lib/dma-debug.c
62961--- linux-3.0.4/lib/dma-debug.c 2011-07-21 22:17:23.000000000 -0400
62962+++ linux-3.0.4/lib/dma-debug.c 2011-08-23 21:47:56.000000000 -0400
62963@@ -870,7 +870,7 @@ out:
62964
62965 static void check_for_stack(struct device *dev, void *addr)
62966 {
62967- if (object_is_on_stack(addr))
62968+ if (object_starts_on_stack(addr))
62969 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
62970 "stack [addr=%p]\n", addr);
62971 }
62972diff -urNp linux-3.0.4/lib/extable.c linux-3.0.4/lib/extable.c
62973--- linux-3.0.4/lib/extable.c 2011-07-21 22:17:23.000000000 -0400
62974+++ linux-3.0.4/lib/extable.c 2011-08-23 21:47:56.000000000 -0400
62975@@ -13,6 +13,7 @@
62976 #include <linux/init.h>
62977 #include <linux/sort.h>
62978 #include <asm/uaccess.h>
62979+#include <asm/pgtable.h>
62980
62981 #ifndef ARCH_HAS_SORT_EXTABLE
62982 /*
62983@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const v
62984 void sort_extable(struct exception_table_entry *start,
62985 struct exception_table_entry *finish)
62986 {
62987+ pax_open_kernel();
62988 sort(start, finish - start, sizeof(struct exception_table_entry),
62989 cmp_ex, NULL);
62990+ pax_close_kernel();
62991 }
62992
62993 #ifdef CONFIG_MODULES
62994diff -urNp linux-3.0.4/lib/inflate.c linux-3.0.4/lib/inflate.c
62995--- linux-3.0.4/lib/inflate.c 2011-07-21 22:17:23.000000000 -0400
62996+++ linux-3.0.4/lib/inflate.c 2011-08-23 21:47:56.000000000 -0400
62997@@ -269,7 +269,7 @@ static void free(void *where)
62998 malloc_ptr = free_mem_ptr;
62999 }
63000 #else
63001-#define malloc(a) kmalloc(a, GFP_KERNEL)
63002+#define malloc(a) kmalloc((a), GFP_KERNEL)
63003 #define free(a) kfree(a)
63004 #endif
63005
63006diff -urNp linux-3.0.4/lib/Kconfig.debug linux-3.0.4/lib/Kconfig.debug
63007--- linux-3.0.4/lib/Kconfig.debug 2011-07-21 22:17:23.000000000 -0400
63008+++ linux-3.0.4/lib/Kconfig.debug 2011-08-23 21:48:14.000000000 -0400
63009@@ -1088,6 +1088,7 @@ config LATENCYTOP
63010 depends on DEBUG_KERNEL
63011 depends on STACKTRACE_SUPPORT
63012 depends on PROC_FS
63013+ depends on !GRKERNSEC_HIDESYM
63014 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
63015 select KALLSYMS
63016 select KALLSYMS_ALL
63017diff -urNp linux-3.0.4/lib/kref.c linux-3.0.4/lib/kref.c
63018--- linux-3.0.4/lib/kref.c 2011-07-21 22:17:23.000000000 -0400
63019+++ linux-3.0.4/lib/kref.c 2011-08-23 21:47:56.000000000 -0400
63020@@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
63021 */
63022 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
63023 {
63024- WARN_ON(release == NULL);
63025+ BUG_ON(release == NULL);
63026 WARN_ON(release == (void (*)(struct kref *))kfree);
63027
63028 if (atomic_dec_and_test(&kref->refcount)) {
63029diff -urNp linux-3.0.4/lib/radix-tree.c linux-3.0.4/lib/radix-tree.c
63030--- linux-3.0.4/lib/radix-tree.c 2011-07-21 22:17:23.000000000 -0400
63031+++ linux-3.0.4/lib/radix-tree.c 2011-08-23 21:47:56.000000000 -0400
63032@@ -80,7 +80,7 @@ struct radix_tree_preload {
63033 int nr;
63034 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
63035 };
63036-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
63037+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
63038
63039 static inline void *ptr_to_indirect(void *ptr)
63040 {
63041diff -urNp linux-3.0.4/lib/vsprintf.c linux-3.0.4/lib/vsprintf.c
63042--- linux-3.0.4/lib/vsprintf.c 2011-07-21 22:17:23.000000000 -0400
63043+++ linux-3.0.4/lib/vsprintf.c 2011-08-23 21:48:14.000000000 -0400
63044@@ -16,6 +16,9 @@
63045 * - scnprintf and vscnprintf
63046 */
63047
63048+#ifdef CONFIG_GRKERNSEC_HIDESYM
63049+#define __INCLUDED_BY_HIDESYM 1
63050+#endif
63051 #include <stdarg.h>
63052 #include <linux/module.h>
63053 #include <linux/types.h>
63054@@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
63055 char sym[KSYM_SYMBOL_LEN];
63056 if (ext == 'B')
63057 sprint_backtrace(sym, value);
63058- else if (ext != 'f' && ext != 's')
63059+ else if (ext != 'f' && ext != 's' && ext != 'a')
63060 sprint_symbol(sym, value);
63061 else
63062 kallsyms_lookup(value, NULL, NULL, NULL, sym);
63063@@ -799,7 +802,11 @@ char *uuid_string(char *buf, char *end,
63064 return string(buf, end, uuid, spec);
63065 }
63066
63067+#ifdef CONFIG_GRKERNSEC_HIDESYM
63068+int kptr_restrict __read_mostly = 2;
63069+#else
63070 int kptr_restrict __read_mostly;
63071+#endif
63072
63073 /*
63074 * Show a '%p' thing. A kernel extension is that the '%p' is followed
63075@@ -813,6 +820,8 @@ int kptr_restrict __read_mostly;
63076 * - 'S' For symbolic direct pointers with offset
63077 * - 's' For symbolic direct pointers without offset
63078 * - 'B' For backtraced symbolic direct pointers with offset
63079+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
63080+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
63081 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
63082 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
63083 * - 'M' For a 6-byte MAC address, it prints the address in the
63084@@ -857,12 +866,12 @@ char *pointer(const char *fmt, char *buf
63085 {
63086 if (!ptr && *fmt != 'K') {
63087 /*
63088- * Print (null) with the same width as a pointer so it makes
63089+ * Print (nil) with the same width as a pointer so it makes
63090 * tabular output look nice.
63091 */
63092 if (spec.field_width == -1)
63093 spec.field_width = 2 * sizeof(void *);
63094- return string(buf, end, "(null)", spec);
63095+ return string(buf, end, "(nil)", spec);
63096 }
63097
63098 switch (*fmt) {
63099@@ -872,6 +881,13 @@ char *pointer(const char *fmt, char *buf
63100 /* Fallthrough */
63101 case 'S':
63102 case 's':
63103+#ifdef CONFIG_GRKERNSEC_HIDESYM
63104+ break;
63105+#else
63106+ return symbol_string(buf, end, ptr, spec, *fmt);
63107+#endif
63108+ case 'A':
63109+ case 'a':
63110 case 'B':
63111 return symbol_string(buf, end, ptr, spec, *fmt);
63112 case 'R':
63113@@ -1631,11 +1647,11 @@ int bstr_printf(char *buf, size_t size,
63114 typeof(type) value; \
63115 if (sizeof(type) == 8) { \
63116 args = PTR_ALIGN(args, sizeof(u32)); \
63117- *(u32 *)&value = *(u32 *)args; \
63118- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
63119+ *(u32 *)&value = *(const u32 *)args; \
63120+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
63121 } else { \
63122 args = PTR_ALIGN(args, sizeof(type)); \
63123- value = *(typeof(type) *)args; \
63124+ value = *(const typeof(type) *)args; \
63125 } \
63126 args += sizeof(type); \
63127 value; \
63128@@ -1698,7 +1714,7 @@ int bstr_printf(char *buf, size_t size,
63129 case FORMAT_TYPE_STR: {
63130 const char *str_arg = args;
63131 args += strlen(str_arg) + 1;
63132- str = string(str, end, (char *)str_arg, spec);
63133+ str = string(str, end, str_arg, spec);
63134 break;
63135 }
63136
63137diff -urNp linux-3.0.4/localversion-grsec linux-3.0.4/localversion-grsec
63138--- linux-3.0.4/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
63139+++ linux-3.0.4/localversion-grsec 2011-08-23 21:48:14.000000000 -0400
63140@@ -0,0 +1 @@
63141+-grsec
63142diff -urNp linux-3.0.4/Makefile linux-3.0.4/Makefile
63143--- linux-3.0.4/Makefile 2011-08-29 23:26:13.000000000 -0400
63144+++ linux-3.0.4/Makefile 2011-09-01 17:26:49.000000000 -0400
63145@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
63146
63147 HOSTCC = gcc
63148 HOSTCXX = g++
63149-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
63150-HOSTCXXFLAGS = -O2
63151+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
63152+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
63153+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
63154
63155 # Decide whether to build built-in, modular, or both.
63156 # Normally, just do built-in.
63157@@ -365,10 +366,12 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
63158 KBUILD_CPPFLAGS := -D__KERNEL__
63159
63160 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
63161+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
63162 -fno-strict-aliasing -fno-common \
63163 -Werror-implicit-function-declaration \
63164 -Wno-format-security \
63165 -fno-delete-null-pointer-checks
63166+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
63167 KBUILD_AFLAGS_KERNEL :=
63168 KBUILD_CFLAGS_KERNEL :=
63169 KBUILD_AFLAGS := -D__ASSEMBLY__
63170@@ -408,6 +411,7 @@ export RCS_TAR_IGNORE := --exclude SCCS
63171
63172 # Basic helpers built in scripts/
63173 PHONY += scripts_basic
63174+scripts_basic: KBUILD_CFLAGS := $(filter-out $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN),$(KBUILD_CFLAGS))
63175 scripts_basic:
63176 $(Q)$(MAKE) $(build)=scripts/basic
63177 $(Q)rm -f .tmp_quiet_recordmcount
63178@@ -564,6 +568,24 @@ else
63179 KBUILD_CFLAGS += -O2
63180 endif
63181
63182+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh $(HOSTCC)), y)
63183+CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
63184+ifdef CONFIG_PAX_MEMORY_STACKLEAK
63185+STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -fplugin-arg-stackleak_plugin-track-lowest-sp=100
63186+endif
63187+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN
63188+gcc-plugins:
63189+ $(Q)$(MAKE) $(build)=tools/gcc
63190+else
63191+gcc-plugins:
63192+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
63193+ $(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.))
63194+else
63195+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
63196+endif
63197+ $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
63198+endif
63199+
63200 include $(srctree)/arch/$(SRCARCH)/Makefile
63201
63202 ifneq ($(CONFIG_FRAME_WARN),0)
63203@@ -708,7 +730,7 @@ export mod_strip_cmd
63204
63205
63206 ifeq ($(KBUILD_EXTMOD),)
63207-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
63208+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
63209
63210 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
63211 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
63212@@ -907,6 +929,8 @@ define rule_vmlinux-modpost
63213 endef
63214
63215 # vmlinux image - including updated kernel symbols
63216+$(vmlinux-all): KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63217+$(vmlinux-all): gcc-plugins
63218 vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE
63219 ifdef CONFIG_HEADERS_CHECK
63220 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
63221@@ -941,7 +965,8 @@ $(sort $(vmlinux-init) $(vmlinux-main))
63222 # Error messages still appears in the original language
63223
63224 PHONY += $(vmlinux-dirs)
63225-$(vmlinux-dirs): prepare scripts
63226+$(vmlinux-dirs): KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63227+$(vmlinux-dirs): gcc-plugins prepare scripts
63228 $(Q)$(MAKE) $(build)=$@
63229
63230 # Store (new) KERNELRELASE string in include/config/kernel.release
63231@@ -986,6 +1011,7 @@ prepare0: archprepare FORCE
63232 $(Q)$(MAKE) $(build)=. missing-syscalls
63233
63234 # All the preparing..
63235+prepare: KBUILD_CFLAGS := $(filter-out $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN),$(KBUILD_CFLAGS))
63236 prepare: prepare0
63237
63238 # Generate some files
63239@@ -1102,7 +1128,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modu
63240
63241 # Target to prepare building external modules
63242 PHONY += modules_prepare
63243-modules_prepare: prepare scripts
63244+modules_prepare: gcc-plugins prepare scripts
63245
63246 # Target to install modules
63247 PHONY += modules_install
63248@@ -1198,7 +1224,7 @@ distclean: mrproper
63249 @find $(srctree) $(RCS_FIND_IGNORE) \
63250 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
63251 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
63252- -o -name '.*.rej' -o -size 0 \
63253+ -o -name '.*.rej' -o -name '*.so' -o -size 0 \
63254 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
63255 -type f -print | xargs rm -f
63256
63257@@ -1359,6 +1385,7 @@ PHONY += $(module-dirs) modules
63258 $(module-dirs): crmodverdir $(objtree)/Module.symvers
63259 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
63260
63261+modules: KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63262 modules: $(module-dirs)
63263 @$(kecho) ' Building modules, stage 2.';
63264 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
63265@@ -1485,17 +1512,19 @@ else
63266 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
63267 endif
63268
63269-%.s: %.c prepare scripts FORCE
63270+%.s: KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63271+%.s: %.c gcc-plugins prepare scripts FORCE
63272 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63273 %.i: %.c prepare scripts FORCE
63274 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63275-%.o: %.c prepare scripts FORCE
63276+%.o: KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63277+%.o: %.c gcc-plugins prepare scripts FORCE
63278 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63279 %.lst: %.c prepare scripts FORCE
63280 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63281-%.s: %.S prepare scripts FORCE
63282+%.s: %.S gcc-plugins prepare scripts FORCE
63283 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63284-%.o: %.S prepare scripts FORCE
63285+%.o: %.S gcc-plugins prepare scripts FORCE
63286 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63287 %.symtypes: %.c prepare scripts FORCE
63288 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63289@@ -1505,11 +1534,13 @@ endif
63290 $(cmd_crmodverdir)
63291 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
63292 $(build)=$(build-dir)
63293-%/: prepare scripts FORCE
63294+%/: KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63295+%/: gcc-plugins prepare scripts FORCE
63296 $(cmd_crmodverdir)
63297 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
63298 $(build)=$(build-dir)
63299-%.ko: prepare scripts FORCE
63300+%.ko: KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
63301+%.ko: gcc-plugins prepare scripts FORCE
63302 $(cmd_crmodverdir)
63303 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
63304 $(build)=$(build-dir) $(@:.ko=.o)
63305diff -urNp linux-3.0.4/mm/filemap.c linux-3.0.4/mm/filemap.c
63306--- linux-3.0.4/mm/filemap.c 2011-07-21 22:17:23.000000000 -0400
63307+++ linux-3.0.4/mm/filemap.c 2011-08-23 21:48:14.000000000 -0400
63308@@ -1763,7 +1763,7 @@ int generic_file_mmap(struct file * file
63309 struct address_space *mapping = file->f_mapping;
63310
63311 if (!mapping->a_ops->readpage)
63312- return -ENOEXEC;
63313+ return -ENODEV;
63314 file_accessed(file);
63315 vma->vm_ops = &generic_file_vm_ops;
63316 vma->vm_flags |= VM_CAN_NONLINEAR;
63317@@ -2169,6 +2169,7 @@ inline int generic_write_checks(struct f
63318 *pos = i_size_read(inode);
63319
63320 if (limit != RLIM_INFINITY) {
63321+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
63322 if (*pos >= limit) {
63323 send_sig(SIGXFSZ, current, 0);
63324 return -EFBIG;
63325diff -urNp linux-3.0.4/mm/fremap.c linux-3.0.4/mm/fremap.c
63326--- linux-3.0.4/mm/fremap.c 2011-07-21 22:17:23.000000000 -0400
63327+++ linux-3.0.4/mm/fremap.c 2011-08-23 21:47:56.000000000 -0400
63328@@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
63329 retry:
63330 vma = find_vma(mm, start);
63331
63332+#ifdef CONFIG_PAX_SEGMEXEC
63333+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
63334+ goto out;
63335+#endif
63336+
63337 /*
63338 * Make sure the vma is shared, that it supports prefaulting,
63339 * and that the remapped range is valid and fully within
63340diff -urNp linux-3.0.4/mm/highmem.c linux-3.0.4/mm/highmem.c
63341--- linux-3.0.4/mm/highmem.c 2011-07-21 22:17:23.000000000 -0400
63342+++ linux-3.0.4/mm/highmem.c 2011-08-23 21:47:56.000000000 -0400
63343@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
63344 * So no dangers, even with speculative execution.
63345 */
63346 page = pte_page(pkmap_page_table[i]);
63347+ pax_open_kernel();
63348 pte_clear(&init_mm, (unsigned long)page_address(page),
63349 &pkmap_page_table[i]);
63350-
63351+ pax_close_kernel();
63352 set_page_address(page, NULL);
63353 need_flush = 1;
63354 }
63355@@ -186,9 +187,11 @@ start:
63356 }
63357 }
63358 vaddr = PKMAP_ADDR(last_pkmap_nr);
63359+
63360+ pax_open_kernel();
63361 set_pte_at(&init_mm, vaddr,
63362 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
63363-
63364+ pax_close_kernel();
63365 pkmap_count[last_pkmap_nr] = 1;
63366 set_page_address(page, (void *)vaddr);
63367
63368diff -urNp linux-3.0.4/mm/huge_memory.c linux-3.0.4/mm/huge_memory.c
63369--- linux-3.0.4/mm/huge_memory.c 2011-07-21 22:17:23.000000000 -0400
63370+++ linux-3.0.4/mm/huge_memory.c 2011-08-23 21:47:56.000000000 -0400
63371@@ -702,7 +702,7 @@ out:
63372 * run pte_offset_map on the pmd, if an huge pmd could
63373 * materialize from under us from a different thread.
63374 */
63375- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
63376+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
63377 return VM_FAULT_OOM;
63378 /* if an huge pmd materialized from under us just retry later */
63379 if (unlikely(pmd_trans_huge(*pmd)))
63380diff -urNp linux-3.0.4/mm/hugetlb.c linux-3.0.4/mm/hugetlb.c
63381--- linux-3.0.4/mm/hugetlb.c 2011-07-21 22:17:23.000000000 -0400
63382+++ linux-3.0.4/mm/hugetlb.c 2011-08-23 21:47:56.000000000 -0400
63383@@ -2339,6 +2339,27 @@ static int unmap_ref_private(struct mm_s
63384 return 1;
63385 }
63386
63387+#ifdef CONFIG_PAX_SEGMEXEC
63388+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
63389+{
63390+ struct mm_struct *mm = vma->vm_mm;
63391+ struct vm_area_struct *vma_m;
63392+ unsigned long address_m;
63393+ pte_t *ptep_m;
63394+
63395+ vma_m = pax_find_mirror_vma(vma);
63396+ if (!vma_m)
63397+ return;
63398+
63399+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63400+ address_m = address + SEGMEXEC_TASK_SIZE;
63401+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
63402+ get_page(page_m);
63403+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
63404+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
63405+}
63406+#endif
63407+
63408 /*
63409 * Hugetlb_cow() should be called with page lock of the original hugepage held.
63410 */
63411@@ -2440,6 +2461,11 @@ retry_avoidcopy:
63412 make_huge_pte(vma, new_page, 1));
63413 page_remove_rmap(old_page);
63414 hugepage_add_new_anon_rmap(new_page, vma, address);
63415+
63416+#ifdef CONFIG_PAX_SEGMEXEC
63417+ pax_mirror_huge_pte(vma, address, new_page);
63418+#endif
63419+
63420 /* Make the old page be freed below */
63421 new_page = old_page;
63422 mmu_notifier_invalidate_range_end(mm,
63423@@ -2591,6 +2617,10 @@ retry:
63424 && (vma->vm_flags & VM_SHARED)));
63425 set_huge_pte_at(mm, address, ptep, new_pte);
63426
63427+#ifdef CONFIG_PAX_SEGMEXEC
63428+ pax_mirror_huge_pte(vma, address, page);
63429+#endif
63430+
63431 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
63432 /* Optimization, do the COW without a second fault */
63433 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
63434@@ -2620,6 +2650,10 @@ int hugetlb_fault(struct mm_struct *mm,
63435 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
63436 struct hstate *h = hstate_vma(vma);
63437
63438+#ifdef CONFIG_PAX_SEGMEXEC
63439+ struct vm_area_struct *vma_m;
63440+#endif
63441+
63442 ptep = huge_pte_offset(mm, address);
63443 if (ptep) {
63444 entry = huge_ptep_get(ptep);
63445@@ -2631,6 +2665,26 @@ int hugetlb_fault(struct mm_struct *mm,
63446 VM_FAULT_SET_HINDEX(h - hstates);
63447 }
63448
63449+#ifdef CONFIG_PAX_SEGMEXEC
63450+ vma_m = pax_find_mirror_vma(vma);
63451+ if (vma_m) {
63452+ unsigned long address_m;
63453+
63454+ if (vma->vm_start > vma_m->vm_start) {
63455+ address_m = address;
63456+ address -= SEGMEXEC_TASK_SIZE;
63457+ vma = vma_m;
63458+ h = hstate_vma(vma);
63459+ } else
63460+ address_m = address + SEGMEXEC_TASK_SIZE;
63461+
63462+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
63463+ return VM_FAULT_OOM;
63464+ address_m &= HPAGE_MASK;
63465+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
63466+ }
63467+#endif
63468+
63469 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
63470 if (!ptep)
63471 return VM_FAULT_OOM;
63472diff -urNp linux-3.0.4/mm/internal.h linux-3.0.4/mm/internal.h
63473--- linux-3.0.4/mm/internal.h 2011-07-21 22:17:23.000000000 -0400
63474+++ linux-3.0.4/mm/internal.h 2011-08-23 21:47:56.000000000 -0400
63475@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page
63476 * in mm/page_alloc.c
63477 */
63478 extern void __free_pages_bootmem(struct page *page, unsigned int order);
63479+extern void free_compound_page(struct page *page);
63480 extern void prep_compound_page(struct page *page, unsigned long order);
63481 #ifdef CONFIG_MEMORY_FAILURE
63482 extern bool is_free_buddy_page(struct page *page);
63483diff -urNp linux-3.0.4/mm/Kconfig linux-3.0.4/mm/Kconfig
63484--- linux-3.0.4/mm/Kconfig 2011-07-21 22:17:23.000000000 -0400
63485+++ linux-3.0.4/mm/Kconfig 2011-08-23 21:48:14.000000000 -0400
63486@@ -240,7 +240,7 @@ config KSM
63487 config DEFAULT_MMAP_MIN_ADDR
63488 int "Low address space to protect from user allocation"
63489 depends on MMU
63490- default 4096
63491+ default 65536
63492 help
63493 This is the portion of low virtual memory which should be protected
63494 from userspace allocation. Keeping a user from writing to low pages
63495diff -urNp linux-3.0.4/mm/kmemleak.c linux-3.0.4/mm/kmemleak.c
63496--- linux-3.0.4/mm/kmemleak.c 2011-07-21 22:17:23.000000000 -0400
63497+++ linux-3.0.4/mm/kmemleak.c 2011-08-23 21:48:14.000000000 -0400
63498@@ -357,7 +357,7 @@ static void print_unreferenced(struct se
63499
63500 for (i = 0; i < object->trace_len; i++) {
63501 void *ptr = (void *)object->trace[i];
63502- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
63503+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
63504 }
63505 }
63506
63507diff -urNp linux-3.0.4/mm/madvise.c linux-3.0.4/mm/madvise.c
63508--- linux-3.0.4/mm/madvise.c 2011-07-21 22:17:23.000000000 -0400
63509+++ linux-3.0.4/mm/madvise.c 2011-08-23 21:47:56.000000000 -0400
63510@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
63511 pgoff_t pgoff;
63512 unsigned long new_flags = vma->vm_flags;
63513
63514+#ifdef CONFIG_PAX_SEGMEXEC
63515+ struct vm_area_struct *vma_m;
63516+#endif
63517+
63518 switch (behavior) {
63519 case MADV_NORMAL:
63520 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
63521@@ -110,6 +114,13 @@ success:
63522 /*
63523 * vm_flags is protected by the mmap_sem held in write mode.
63524 */
63525+
63526+#ifdef CONFIG_PAX_SEGMEXEC
63527+ vma_m = pax_find_mirror_vma(vma);
63528+ if (vma_m)
63529+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
63530+#endif
63531+
63532 vma->vm_flags = new_flags;
63533
63534 out:
63535@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
63536 struct vm_area_struct ** prev,
63537 unsigned long start, unsigned long end)
63538 {
63539+
63540+#ifdef CONFIG_PAX_SEGMEXEC
63541+ struct vm_area_struct *vma_m;
63542+#endif
63543+
63544 *prev = vma;
63545 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
63546 return -EINVAL;
63547@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
63548 zap_page_range(vma, start, end - start, &details);
63549 } else
63550 zap_page_range(vma, start, end - start, NULL);
63551+
63552+#ifdef CONFIG_PAX_SEGMEXEC
63553+ vma_m = pax_find_mirror_vma(vma);
63554+ if (vma_m) {
63555+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
63556+ struct zap_details details = {
63557+ .nonlinear_vma = vma_m,
63558+ .last_index = ULONG_MAX,
63559+ };
63560+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
63561+ } else
63562+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
63563+ }
63564+#endif
63565+
63566 return 0;
63567 }
63568
63569@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
63570 if (end < start)
63571 goto out;
63572
63573+#ifdef CONFIG_PAX_SEGMEXEC
63574+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
63575+ if (end > SEGMEXEC_TASK_SIZE)
63576+ goto out;
63577+ } else
63578+#endif
63579+
63580+ if (end > TASK_SIZE)
63581+ goto out;
63582+
63583 error = 0;
63584 if (end == start)
63585 goto out;
63586diff -urNp linux-3.0.4/mm/memory.c linux-3.0.4/mm/memory.c
63587--- linux-3.0.4/mm/memory.c 2011-08-23 21:44:40.000000000 -0400
63588+++ linux-3.0.4/mm/memory.c 2011-08-23 21:47:56.000000000 -0400
63589@@ -457,8 +457,12 @@ static inline void free_pmd_range(struct
63590 return;
63591
63592 pmd = pmd_offset(pud, start);
63593+
63594+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
63595 pud_clear(pud);
63596 pmd_free_tlb(tlb, pmd, start);
63597+#endif
63598+
63599 }
63600
63601 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
63602@@ -489,9 +493,12 @@ static inline void free_pud_range(struct
63603 if (end - 1 > ceiling - 1)
63604 return;
63605
63606+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
63607 pud = pud_offset(pgd, start);
63608 pgd_clear(pgd);
63609 pud_free_tlb(tlb, pud, start);
63610+#endif
63611+
63612 }
63613
63614 /*
63615@@ -1577,12 +1584,6 @@ no_page_table:
63616 return page;
63617 }
63618
63619-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
63620-{
63621- return stack_guard_page_start(vma, addr) ||
63622- stack_guard_page_end(vma, addr+PAGE_SIZE);
63623-}
63624-
63625 /**
63626 * __get_user_pages() - pin user pages in memory
63627 * @tsk: task_struct of target task
63628@@ -1655,10 +1656,10 @@ int __get_user_pages(struct task_struct
63629 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
63630 i = 0;
63631
63632- do {
63633+ while (nr_pages) {
63634 struct vm_area_struct *vma;
63635
63636- vma = find_extend_vma(mm, start);
63637+ vma = find_vma(mm, start);
63638 if (!vma && in_gate_area(mm, start)) {
63639 unsigned long pg = start & PAGE_MASK;
63640 pgd_t *pgd;
63641@@ -1706,7 +1707,7 @@ int __get_user_pages(struct task_struct
63642 goto next_page;
63643 }
63644
63645- if (!vma ||
63646+ if (!vma || start < vma->vm_start ||
63647 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
63648 !(vm_flags & vma->vm_flags))
63649 return i ? : -EFAULT;
63650@@ -1733,11 +1734,6 @@ int __get_user_pages(struct task_struct
63651 int ret;
63652 unsigned int fault_flags = 0;
63653
63654- /* For mlock, just skip the stack guard page. */
63655- if (foll_flags & FOLL_MLOCK) {
63656- if (stack_guard_page(vma, start))
63657- goto next_page;
63658- }
63659 if (foll_flags & FOLL_WRITE)
63660 fault_flags |= FAULT_FLAG_WRITE;
63661 if (nonblocking)
63662@@ -1811,7 +1807,7 @@ next_page:
63663 start += PAGE_SIZE;
63664 nr_pages--;
63665 } while (nr_pages && start < vma->vm_end);
63666- } while (nr_pages);
63667+ }
63668 return i;
63669 }
63670 EXPORT_SYMBOL(__get_user_pages);
63671@@ -2018,6 +2014,10 @@ static int insert_page(struct vm_area_st
63672 page_add_file_rmap(page);
63673 set_pte_at(mm, addr, pte, mk_pte(page, prot));
63674
63675+#ifdef CONFIG_PAX_SEGMEXEC
63676+ pax_mirror_file_pte(vma, addr, page, ptl);
63677+#endif
63678+
63679 retval = 0;
63680 pte_unmap_unlock(pte, ptl);
63681 return retval;
63682@@ -2052,10 +2052,22 @@ out:
63683 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
63684 struct page *page)
63685 {
63686+
63687+#ifdef CONFIG_PAX_SEGMEXEC
63688+ struct vm_area_struct *vma_m;
63689+#endif
63690+
63691 if (addr < vma->vm_start || addr >= vma->vm_end)
63692 return -EFAULT;
63693 if (!page_count(page))
63694 return -EINVAL;
63695+
63696+#ifdef CONFIG_PAX_SEGMEXEC
63697+ vma_m = pax_find_mirror_vma(vma);
63698+ if (vma_m)
63699+ vma_m->vm_flags |= VM_INSERTPAGE;
63700+#endif
63701+
63702 vma->vm_flags |= VM_INSERTPAGE;
63703 return insert_page(vma, addr, page, vma->vm_page_prot);
63704 }
63705@@ -2141,6 +2153,7 @@ int vm_insert_mixed(struct vm_area_struc
63706 unsigned long pfn)
63707 {
63708 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
63709+ BUG_ON(vma->vm_mirror);
63710
63711 if (addr < vma->vm_start || addr >= vma->vm_end)
63712 return -EFAULT;
63713@@ -2456,6 +2469,186 @@ static inline void cow_user_page(struct
63714 copy_user_highpage(dst, src, va, vma);
63715 }
63716
63717+#ifdef CONFIG_PAX_SEGMEXEC
63718+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
63719+{
63720+ struct mm_struct *mm = vma->vm_mm;
63721+ spinlock_t *ptl;
63722+ pte_t *pte, entry;
63723+
63724+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
63725+ entry = *pte;
63726+ if (!pte_present(entry)) {
63727+ if (!pte_none(entry)) {
63728+ BUG_ON(pte_file(entry));
63729+ free_swap_and_cache(pte_to_swp_entry(entry));
63730+ pte_clear_not_present_full(mm, address, pte, 0);
63731+ }
63732+ } else {
63733+ struct page *page;
63734+
63735+ flush_cache_page(vma, address, pte_pfn(entry));
63736+ entry = ptep_clear_flush(vma, address, pte);
63737+ BUG_ON(pte_dirty(entry));
63738+ page = vm_normal_page(vma, address, entry);
63739+ if (page) {
63740+ update_hiwater_rss(mm);
63741+ if (PageAnon(page))
63742+ dec_mm_counter_fast(mm, MM_ANONPAGES);
63743+ else
63744+ dec_mm_counter_fast(mm, MM_FILEPAGES);
63745+ page_remove_rmap(page);
63746+ page_cache_release(page);
63747+ }
63748+ }
63749+ pte_unmap_unlock(pte, ptl);
63750+}
63751+
63752+/* PaX: if vma is mirrored, synchronize the mirror's PTE
63753+ *
63754+ * the ptl of the lower mapped page is held on entry and is not released on exit
63755+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
63756+ */
63757+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
63758+{
63759+ struct mm_struct *mm = vma->vm_mm;
63760+ unsigned long address_m;
63761+ spinlock_t *ptl_m;
63762+ struct vm_area_struct *vma_m;
63763+ pmd_t *pmd_m;
63764+ pte_t *pte_m, entry_m;
63765+
63766+ BUG_ON(!page_m || !PageAnon(page_m));
63767+
63768+ vma_m = pax_find_mirror_vma(vma);
63769+ if (!vma_m)
63770+ return;
63771+
63772+ BUG_ON(!PageLocked(page_m));
63773+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63774+ address_m = address + SEGMEXEC_TASK_SIZE;
63775+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63776+ pte_m = pte_offset_map(pmd_m, address_m);
63777+ ptl_m = pte_lockptr(mm, pmd_m);
63778+ if (ptl != ptl_m) {
63779+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63780+ if (!pte_none(*pte_m))
63781+ goto out;
63782+ }
63783+
63784+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
63785+ page_cache_get(page_m);
63786+ page_add_anon_rmap(page_m, vma_m, address_m);
63787+ inc_mm_counter_fast(mm, MM_ANONPAGES);
63788+ set_pte_at(mm, address_m, pte_m, entry_m);
63789+ update_mmu_cache(vma_m, address_m, entry_m);
63790+out:
63791+ if (ptl != ptl_m)
63792+ spin_unlock(ptl_m);
63793+ pte_unmap(pte_m);
63794+ unlock_page(page_m);
63795+}
63796+
63797+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
63798+{
63799+ struct mm_struct *mm = vma->vm_mm;
63800+ unsigned long address_m;
63801+ spinlock_t *ptl_m;
63802+ struct vm_area_struct *vma_m;
63803+ pmd_t *pmd_m;
63804+ pte_t *pte_m, entry_m;
63805+
63806+ BUG_ON(!page_m || PageAnon(page_m));
63807+
63808+ vma_m = pax_find_mirror_vma(vma);
63809+ if (!vma_m)
63810+ return;
63811+
63812+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63813+ address_m = address + SEGMEXEC_TASK_SIZE;
63814+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63815+ pte_m = pte_offset_map(pmd_m, address_m);
63816+ ptl_m = pte_lockptr(mm, pmd_m);
63817+ if (ptl != ptl_m) {
63818+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63819+ if (!pte_none(*pte_m))
63820+ goto out;
63821+ }
63822+
63823+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
63824+ page_cache_get(page_m);
63825+ page_add_file_rmap(page_m);
63826+ inc_mm_counter_fast(mm, MM_FILEPAGES);
63827+ set_pte_at(mm, address_m, pte_m, entry_m);
63828+ update_mmu_cache(vma_m, address_m, entry_m);
63829+out:
63830+ if (ptl != ptl_m)
63831+ spin_unlock(ptl_m);
63832+ pte_unmap(pte_m);
63833+}
63834+
63835+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
63836+{
63837+ struct mm_struct *mm = vma->vm_mm;
63838+ unsigned long address_m;
63839+ spinlock_t *ptl_m;
63840+ struct vm_area_struct *vma_m;
63841+ pmd_t *pmd_m;
63842+ pte_t *pte_m, entry_m;
63843+
63844+ vma_m = pax_find_mirror_vma(vma);
63845+ if (!vma_m)
63846+ return;
63847+
63848+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63849+ address_m = address + SEGMEXEC_TASK_SIZE;
63850+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63851+ pte_m = pte_offset_map(pmd_m, address_m);
63852+ ptl_m = pte_lockptr(mm, pmd_m);
63853+ if (ptl != ptl_m) {
63854+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63855+ if (!pte_none(*pte_m))
63856+ goto out;
63857+ }
63858+
63859+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
63860+ set_pte_at(mm, address_m, pte_m, entry_m);
63861+out:
63862+ if (ptl != ptl_m)
63863+ spin_unlock(ptl_m);
63864+ pte_unmap(pte_m);
63865+}
63866+
63867+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
63868+{
63869+ struct page *page_m;
63870+ pte_t entry;
63871+
63872+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
63873+ goto out;
63874+
63875+ entry = *pte;
63876+ page_m = vm_normal_page(vma, address, entry);
63877+ if (!page_m)
63878+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
63879+ else if (PageAnon(page_m)) {
63880+ if (pax_find_mirror_vma(vma)) {
63881+ pte_unmap_unlock(pte, ptl);
63882+ lock_page(page_m);
63883+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
63884+ if (pte_same(entry, *pte))
63885+ pax_mirror_anon_pte(vma, address, page_m, ptl);
63886+ else
63887+ unlock_page(page_m);
63888+ }
63889+ } else
63890+ pax_mirror_file_pte(vma, address, page_m, ptl);
63891+
63892+out:
63893+ pte_unmap_unlock(pte, ptl);
63894+}
63895+#endif
63896+
63897 /*
63898 * This routine handles present pages, when users try to write
63899 * to a shared page. It is done by copying the page to a new address
63900@@ -2667,6 +2860,12 @@ gotten:
63901 */
63902 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
63903 if (likely(pte_same(*page_table, orig_pte))) {
63904+
63905+#ifdef CONFIG_PAX_SEGMEXEC
63906+ if (pax_find_mirror_vma(vma))
63907+ BUG_ON(!trylock_page(new_page));
63908+#endif
63909+
63910 if (old_page) {
63911 if (!PageAnon(old_page)) {
63912 dec_mm_counter_fast(mm, MM_FILEPAGES);
63913@@ -2718,6 +2917,10 @@ gotten:
63914 page_remove_rmap(old_page);
63915 }
63916
63917+#ifdef CONFIG_PAX_SEGMEXEC
63918+ pax_mirror_anon_pte(vma, address, new_page, ptl);
63919+#endif
63920+
63921 /* Free the old page.. */
63922 new_page = old_page;
63923 ret |= VM_FAULT_WRITE;
63924@@ -2997,6 +3200,11 @@ static int do_swap_page(struct mm_struct
63925 swap_free(entry);
63926 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
63927 try_to_free_swap(page);
63928+
63929+#ifdef CONFIG_PAX_SEGMEXEC
63930+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
63931+#endif
63932+
63933 unlock_page(page);
63934 if (swapcache) {
63935 /*
63936@@ -3020,6 +3228,11 @@ static int do_swap_page(struct mm_struct
63937
63938 /* No need to invalidate - it was non-present before */
63939 update_mmu_cache(vma, address, page_table);
63940+
63941+#ifdef CONFIG_PAX_SEGMEXEC
63942+ pax_mirror_anon_pte(vma, address, page, ptl);
63943+#endif
63944+
63945 unlock:
63946 pte_unmap_unlock(page_table, ptl);
63947 out:
63948@@ -3039,40 +3252,6 @@ out_release:
63949 }
63950
63951 /*
63952- * This is like a special single-page "expand_{down|up}wards()",
63953- * except we must first make sure that 'address{-|+}PAGE_SIZE'
63954- * doesn't hit another vma.
63955- */
63956-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
63957-{
63958- address &= PAGE_MASK;
63959- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
63960- struct vm_area_struct *prev = vma->vm_prev;
63961-
63962- /*
63963- * Is there a mapping abutting this one below?
63964- *
63965- * That's only ok if it's the same stack mapping
63966- * that has gotten split..
63967- */
63968- if (prev && prev->vm_end == address)
63969- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
63970-
63971- expand_downwards(vma, address - PAGE_SIZE);
63972- }
63973- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
63974- struct vm_area_struct *next = vma->vm_next;
63975-
63976- /* As VM_GROWSDOWN but s/below/above/ */
63977- if (next && next->vm_start == address + PAGE_SIZE)
63978- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
63979-
63980- expand_upwards(vma, address + PAGE_SIZE);
63981- }
63982- return 0;
63983-}
63984-
63985-/*
63986 * We enter with non-exclusive mmap_sem (to exclude vma changes,
63987 * but allow concurrent faults), and pte mapped but not yet locked.
63988 * We return with mmap_sem still held, but pte unmapped and unlocked.
63989@@ -3081,27 +3260,23 @@ static int do_anonymous_page(struct mm_s
63990 unsigned long address, pte_t *page_table, pmd_t *pmd,
63991 unsigned int flags)
63992 {
63993- struct page *page;
63994+ struct page *page = NULL;
63995 spinlock_t *ptl;
63996 pte_t entry;
63997
63998- pte_unmap(page_table);
63999-
64000- /* Check if we need to add a guard page to the stack */
64001- if (check_stack_guard_page(vma, address) < 0)
64002- return VM_FAULT_SIGBUS;
64003-
64004- /* Use the zero-page for reads */
64005 if (!(flags & FAULT_FLAG_WRITE)) {
64006 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
64007 vma->vm_page_prot));
64008- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
64009+ ptl = pte_lockptr(mm, pmd);
64010+ spin_lock(ptl);
64011 if (!pte_none(*page_table))
64012 goto unlock;
64013 goto setpte;
64014 }
64015
64016 /* Allocate our own private page. */
64017+ pte_unmap(page_table);
64018+
64019 if (unlikely(anon_vma_prepare(vma)))
64020 goto oom;
64021 page = alloc_zeroed_user_highpage_movable(vma, address);
64022@@ -3120,6 +3295,11 @@ static int do_anonymous_page(struct mm_s
64023 if (!pte_none(*page_table))
64024 goto release;
64025
64026+#ifdef CONFIG_PAX_SEGMEXEC
64027+ if (pax_find_mirror_vma(vma))
64028+ BUG_ON(!trylock_page(page));
64029+#endif
64030+
64031 inc_mm_counter_fast(mm, MM_ANONPAGES);
64032 page_add_new_anon_rmap(page, vma, address);
64033 setpte:
64034@@ -3127,6 +3307,12 @@ setpte:
64035
64036 /* No need to invalidate - it was non-present before */
64037 update_mmu_cache(vma, address, page_table);
64038+
64039+#ifdef CONFIG_PAX_SEGMEXEC
64040+ if (page)
64041+ pax_mirror_anon_pte(vma, address, page, ptl);
64042+#endif
64043+
64044 unlock:
64045 pte_unmap_unlock(page_table, ptl);
64046 return 0;
64047@@ -3264,6 +3450,12 @@ static int __do_fault(struct mm_struct *
64048 */
64049 /* Only go through if we didn't race with anybody else... */
64050 if (likely(pte_same(*page_table, orig_pte))) {
64051+
64052+#ifdef CONFIG_PAX_SEGMEXEC
64053+ if (anon && pax_find_mirror_vma(vma))
64054+ BUG_ON(!trylock_page(page));
64055+#endif
64056+
64057 flush_icache_page(vma, page);
64058 entry = mk_pte(page, vma->vm_page_prot);
64059 if (flags & FAULT_FLAG_WRITE)
64060@@ -3283,6 +3475,14 @@ static int __do_fault(struct mm_struct *
64061
64062 /* no need to invalidate: a not-present page won't be cached */
64063 update_mmu_cache(vma, address, page_table);
64064+
64065+#ifdef CONFIG_PAX_SEGMEXEC
64066+ if (anon)
64067+ pax_mirror_anon_pte(vma, address, page, ptl);
64068+ else
64069+ pax_mirror_file_pte(vma, address, page, ptl);
64070+#endif
64071+
64072 } else {
64073 if (charged)
64074 mem_cgroup_uncharge_page(page);
64075@@ -3430,6 +3630,12 @@ int handle_pte_fault(struct mm_struct *m
64076 if (flags & FAULT_FLAG_WRITE)
64077 flush_tlb_fix_spurious_fault(vma, address);
64078 }
64079+
64080+#ifdef CONFIG_PAX_SEGMEXEC
64081+ pax_mirror_pte(vma, address, pte, pmd, ptl);
64082+ return 0;
64083+#endif
64084+
64085 unlock:
64086 pte_unmap_unlock(pte, ptl);
64087 return 0;
64088@@ -3446,6 +3652,10 @@ int handle_mm_fault(struct mm_struct *mm
64089 pmd_t *pmd;
64090 pte_t *pte;
64091
64092+#ifdef CONFIG_PAX_SEGMEXEC
64093+ struct vm_area_struct *vma_m;
64094+#endif
64095+
64096 __set_current_state(TASK_RUNNING);
64097
64098 count_vm_event(PGFAULT);
64099@@ -3457,6 +3667,34 @@ int handle_mm_fault(struct mm_struct *mm
64100 if (unlikely(is_vm_hugetlb_page(vma)))
64101 return hugetlb_fault(mm, vma, address, flags);
64102
64103+#ifdef CONFIG_PAX_SEGMEXEC
64104+ vma_m = pax_find_mirror_vma(vma);
64105+ if (vma_m) {
64106+ unsigned long address_m;
64107+ pgd_t *pgd_m;
64108+ pud_t *pud_m;
64109+ pmd_t *pmd_m;
64110+
64111+ if (vma->vm_start > vma_m->vm_start) {
64112+ address_m = address;
64113+ address -= SEGMEXEC_TASK_SIZE;
64114+ vma = vma_m;
64115+ } else
64116+ address_m = address + SEGMEXEC_TASK_SIZE;
64117+
64118+ pgd_m = pgd_offset(mm, address_m);
64119+ pud_m = pud_alloc(mm, pgd_m, address_m);
64120+ if (!pud_m)
64121+ return VM_FAULT_OOM;
64122+ pmd_m = pmd_alloc(mm, pud_m, address_m);
64123+ if (!pmd_m)
64124+ return VM_FAULT_OOM;
64125+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
64126+ return VM_FAULT_OOM;
64127+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
64128+ }
64129+#endif
64130+
64131 pgd = pgd_offset(mm, address);
64132 pud = pud_alloc(mm, pgd, address);
64133 if (!pud)
64134@@ -3486,7 +3724,7 @@ int handle_mm_fault(struct mm_struct *mm
64135 * run pte_offset_map on the pmd, if an huge pmd could
64136 * materialize from under us from a different thread.
64137 */
64138- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
64139+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
64140 return VM_FAULT_OOM;
64141 /* if an huge pmd materialized from under us just retry later */
64142 if (unlikely(pmd_trans_huge(*pmd)))
64143@@ -3590,7 +3828,7 @@ static int __init gate_vma_init(void)
64144 gate_vma.vm_start = FIXADDR_USER_START;
64145 gate_vma.vm_end = FIXADDR_USER_END;
64146 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
64147- gate_vma.vm_page_prot = __P101;
64148+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
64149 /*
64150 * Make sure the vDSO gets into every core dump.
64151 * Dumping its contents makes post-mortem fully interpretable later
64152diff -urNp linux-3.0.4/mm/memory-failure.c linux-3.0.4/mm/memory-failure.c
64153--- linux-3.0.4/mm/memory-failure.c 2011-07-21 22:17:23.000000000 -0400
64154+++ linux-3.0.4/mm/memory-failure.c 2011-08-23 21:47:56.000000000 -0400
64155@@ -59,7 +59,7 @@ int sysctl_memory_failure_early_kill __r
64156
64157 int sysctl_memory_failure_recovery __read_mostly = 1;
64158
64159-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
64160+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
64161
64162 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
64163
64164@@ -1008,7 +1008,7 @@ int __memory_failure(unsigned long pfn,
64165 }
64166
64167 nr_pages = 1 << compound_trans_order(hpage);
64168- atomic_long_add(nr_pages, &mce_bad_pages);
64169+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
64170
64171 /*
64172 * We need/can do nothing about count=0 pages.
64173@@ -1038,7 +1038,7 @@ int __memory_failure(unsigned long pfn,
64174 if (!PageHWPoison(hpage)
64175 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
64176 || (p != hpage && TestSetPageHWPoison(hpage))) {
64177- atomic_long_sub(nr_pages, &mce_bad_pages);
64178+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64179 return 0;
64180 }
64181 set_page_hwpoison_huge_page(hpage);
64182@@ -1096,7 +1096,7 @@ int __memory_failure(unsigned long pfn,
64183 }
64184 if (hwpoison_filter(p)) {
64185 if (TestClearPageHWPoison(p))
64186- atomic_long_sub(nr_pages, &mce_bad_pages);
64187+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64188 unlock_page(hpage);
64189 put_page(hpage);
64190 return 0;
64191@@ -1222,7 +1222,7 @@ int unpoison_memory(unsigned long pfn)
64192 return 0;
64193 }
64194 if (TestClearPageHWPoison(p))
64195- atomic_long_sub(nr_pages, &mce_bad_pages);
64196+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64197 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
64198 return 0;
64199 }
64200@@ -1236,7 +1236,7 @@ int unpoison_memory(unsigned long pfn)
64201 */
64202 if (TestClearPageHWPoison(page)) {
64203 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
64204- atomic_long_sub(nr_pages, &mce_bad_pages);
64205+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64206 freeit = 1;
64207 if (PageHuge(page))
64208 clear_page_hwpoison_huge_page(page);
64209@@ -1349,7 +1349,7 @@ static int soft_offline_huge_page(struct
64210 }
64211 done:
64212 if (!PageHWPoison(hpage))
64213- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
64214+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
64215 set_page_hwpoison_huge_page(hpage);
64216 dequeue_hwpoisoned_huge_page(hpage);
64217 /* keep elevated page count for bad page */
64218@@ -1480,7 +1480,7 @@ int soft_offline_page(struct page *page,
64219 return ret;
64220
64221 done:
64222- atomic_long_add(1, &mce_bad_pages);
64223+ atomic_long_add_unchecked(1, &mce_bad_pages);
64224 SetPageHWPoison(page);
64225 /* keep elevated page count for bad page */
64226 return ret;
64227diff -urNp linux-3.0.4/mm/mempolicy.c linux-3.0.4/mm/mempolicy.c
64228--- linux-3.0.4/mm/mempolicy.c 2011-07-21 22:17:23.000000000 -0400
64229+++ linux-3.0.4/mm/mempolicy.c 2011-08-23 21:48:14.000000000 -0400
64230@@ -639,6 +639,10 @@ static int mbind_range(struct mm_struct
64231 unsigned long vmstart;
64232 unsigned long vmend;
64233
64234+#ifdef CONFIG_PAX_SEGMEXEC
64235+ struct vm_area_struct *vma_m;
64236+#endif
64237+
64238 vma = find_vma_prev(mm, start, &prev);
64239 if (!vma || vma->vm_start > start)
64240 return -EFAULT;
64241@@ -669,6 +673,16 @@ static int mbind_range(struct mm_struct
64242 err = policy_vma(vma, new_pol);
64243 if (err)
64244 goto out;
64245+
64246+#ifdef CONFIG_PAX_SEGMEXEC
64247+ vma_m = pax_find_mirror_vma(vma);
64248+ if (vma_m) {
64249+ err = policy_vma(vma_m, new_pol);
64250+ if (err)
64251+ goto out;
64252+ }
64253+#endif
64254+
64255 }
64256
64257 out:
64258@@ -1102,6 +1116,17 @@ static long do_mbind(unsigned long start
64259
64260 if (end < start)
64261 return -EINVAL;
64262+
64263+#ifdef CONFIG_PAX_SEGMEXEC
64264+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
64265+ if (end > SEGMEXEC_TASK_SIZE)
64266+ return -EINVAL;
64267+ } else
64268+#endif
64269+
64270+ if (end > TASK_SIZE)
64271+ return -EINVAL;
64272+
64273 if (end == start)
64274 return 0;
64275
64276@@ -1320,6 +1345,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
64277 if (!mm)
64278 goto out;
64279
64280+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64281+ if (mm != current->mm &&
64282+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
64283+ err = -EPERM;
64284+ goto out;
64285+ }
64286+#endif
64287+
64288 /*
64289 * Check if this process has the right to modify the specified
64290 * process. The right exists if the process has administrative
64291@@ -1329,8 +1362,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
64292 rcu_read_lock();
64293 tcred = __task_cred(task);
64294 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
64295- cred->uid != tcred->suid && cred->uid != tcred->uid &&
64296- !capable(CAP_SYS_NICE)) {
64297+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
64298 rcu_read_unlock();
64299 err = -EPERM;
64300 goto out;
64301diff -urNp linux-3.0.4/mm/migrate.c linux-3.0.4/mm/migrate.c
64302--- linux-3.0.4/mm/migrate.c 2011-07-21 22:17:23.000000000 -0400
64303+++ linux-3.0.4/mm/migrate.c 2011-08-23 21:48:14.000000000 -0400
64304@@ -1124,6 +1124,8 @@ static int do_pages_move(struct mm_struc
64305 unsigned long chunk_start;
64306 int err;
64307
64308+ pax_track_stack();
64309+
64310 task_nodes = cpuset_mems_allowed(task);
64311
64312 err = -ENOMEM;
64313@@ -1308,6 +1310,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
64314 if (!mm)
64315 return -EINVAL;
64316
64317+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64318+ if (mm != current->mm &&
64319+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
64320+ err = -EPERM;
64321+ goto out;
64322+ }
64323+#endif
64324+
64325 /*
64326 * Check if this process has the right to modify the specified
64327 * process. The right exists if the process has administrative
64328@@ -1317,8 +1327,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
64329 rcu_read_lock();
64330 tcred = __task_cred(task);
64331 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
64332- cred->uid != tcred->suid && cred->uid != tcred->uid &&
64333- !capable(CAP_SYS_NICE)) {
64334+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
64335 rcu_read_unlock();
64336 err = -EPERM;
64337 goto out;
64338diff -urNp linux-3.0.4/mm/mlock.c linux-3.0.4/mm/mlock.c
64339--- linux-3.0.4/mm/mlock.c 2011-07-21 22:17:23.000000000 -0400
64340+++ linux-3.0.4/mm/mlock.c 2011-08-23 21:48:14.000000000 -0400
64341@@ -13,6 +13,7 @@
64342 #include <linux/pagemap.h>
64343 #include <linux/mempolicy.h>
64344 #include <linux/syscalls.h>
64345+#include <linux/security.h>
64346 #include <linux/sched.h>
64347 #include <linux/module.h>
64348 #include <linux/rmap.h>
64349@@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
64350 return -EINVAL;
64351 if (end == start)
64352 return 0;
64353+ if (end > TASK_SIZE)
64354+ return -EINVAL;
64355+
64356 vma = find_vma_prev(current->mm, start, &prev);
64357 if (!vma || vma->vm_start > start)
64358 return -ENOMEM;
64359@@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
64360 for (nstart = start ; ; ) {
64361 vm_flags_t newflags;
64362
64363+#ifdef CONFIG_PAX_SEGMEXEC
64364+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
64365+ break;
64366+#endif
64367+
64368 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
64369
64370 newflags = vma->vm_flags | VM_LOCKED;
64371@@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
64372 lock_limit >>= PAGE_SHIFT;
64373
64374 /* check against resource limits */
64375+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
64376 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
64377 error = do_mlock(start, len, 1);
64378 up_write(&current->mm->mmap_sem);
64379@@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
64380 static int do_mlockall(int flags)
64381 {
64382 struct vm_area_struct * vma, * prev = NULL;
64383- unsigned int def_flags = 0;
64384
64385 if (flags & MCL_FUTURE)
64386- def_flags = VM_LOCKED;
64387- current->mm->def_flags = def_flags;
64388+ current->mm->def_flags |= VM_LOCKED;
64389+ else
64390+ current->mm->def_flags &= ~VM_LOCKED;
64391 if (flags == MCL_FUTURE)
64392 goto out;
64393
64394 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
64395 vm_flags_t newflags;
64396
64397+#ifdef CONFIG_PAX_SEGMEXEC
64398+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
64399+ break;
64400+#endif
64401+
64402+ BUG_ON(vma->vm_end > TASK_SIZE);
64403 newflags = vma->vm_flags | VM_LOCKED;
64404 if (!(flags & MCL_CURRENT))
64405 newflags &= ~VM_LOCKED;
64406@@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
64407 lock_limit >>= PAGE_SHIFT;
64408
64409 ret = -ENOMEM;
64410+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
64411 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
64412 capable(CAP_IPC_LOCK))
64413 ret = do_mlockall(flags);
64414diff -urNp linux-3.0.4/mm/mmap.c linux-3.0.4/mm/mmap.c
64415--- linux-3.0.4/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
64416+++ linux-3.0.4/mm/mmap.c 2011-08-23 21:48:14.000000000 -0400
64417@@ -46,6 +46,16 @@
64418 #define arch_rebalance_pgtables(addr, len) (addr)
64419 #endif
64420
64421+static inline void verify_mm_writelocked(struct mm_struct *mm)
64422+{
64423+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
64424+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
64425+ up_read(&mm->mmap_sem);
64426+ BUG();
64427+ }
64428+#endif
64429+}
64430+
64431 static void unmap_region(struct mm_struct *mm,
64432 struct vm_area_struct *vma, struct vm_area_struct *prev,
64433 unsigned long start, unsigned long end);
64434@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
64435 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
64436 *
64437 */
64438-pgprot_t protection_map[16] = {
64439+pgprot_t protection_map[16] __read_only = {
64440 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
64441 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
64442 };
64443
64444-pgprot_t vm_get_page_prot(unsigned long vm_flags)
64445+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64446 {
64447- return __pgprot(pgprot_val(protection_map[vm_flags &
64448+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
64449 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
64450 pgprot_val(arch_vm_get_page_prot(vm_flags)));
64451+
64452+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64453+ if (!(__supported_pte_mask & _PAGE_NX) &&
64454+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
64455+ (vm_flags & (VM_READ | VM_WRITE)))
64456+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
64457+#endif
64458+
64459+ return prot;
64460 }
64461 EXPORT_SYMBOL(vm_get_page_prot);
64462
64463 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
64464 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
64465 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
64466+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
64467 /*
64468 * Make sure vm_committed_as in one cacheline and not cacheline shared with
64469 * other variables. It can be updated by several CPUs frequently.
64470@@ -236,6 +256,7 @@ static struct vm_area_struct *remove_vma
64471 struct vm_area_struct *next = vma->vm_next;
64472
64473 might_sleep();
64474+ BUG_ON(vma->vm_mirror);
64475 if (vma->vm_ops && vma->vm_ops->close)
64476 vma->vm_ops->close(vma);
64477 if (vma->vm_file) {
64478@@ -280,6 +301,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
64479 * not page aligned -Ram Gupta
64480 */
64481 rlim = rlimit(RLIMIT_DATA);
64482+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
64483 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
64484 (mm->end_data - mm->start_data) > rlim)
64485 goto out;
64486@@ -697,6 +719,12 @@ static int
64487 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
64488 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
64489 {
64490+
64491+#ifdef CONFIG_PAX_SEGMEXEC
64492+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
64493+ return 0;
64494+#endif
64495+
64496 if (is_mergeable_vma(vma, file, vm_flags) &&
64497 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
64498 if (vma->vm_pgoff == vm_pgoff)
64499@@ -716,6 +744,12 @@ static int
64500 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
64501 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
64502 {
64503+
64504+#ifdef CONFIG_PAX_SEGMEXEC
64505+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
64506+ return 0;
64507+#endif
64508+
64509 if (is_mergeable_vma(vma, file, vm_flags) &&
64510 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
64511 pgoff_t vm_pglen;
64512@@ -758,13 +792,20 @@ can_vma_merge_after(struct vm_area_struc
64513 struct vm_area_struct *vma_merge(struct mm_struct *mm,
64514 struct vm_area_struct *prev, unsigned long addr,
64515 unsigned long end, unsigned long vm_flags,
64516- struct anon_vma *anon_vma, struct file *file,
64517+ struct anon_vma *anon_vma, struct file *file,
64518 pgoff_t pgoff, struct mempolicy *policy)
64519 {
64520 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
64521 struct vm_area_struct *area, *next;
64522 int err;
64523
64524+#ifdef CONFIG_PAX_SEGMEXEC
64525+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
64526+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
64527+
64528+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
64529+#endif
64530+
64531 /*
64532 * We later require that vma->vm_flags == vm_flags,
64533 * so this tests vma->vm_flags & VM_SPECIAL, too.
64534@@ -780,6 +821,15 @@ struct vm_area_struct *vma_merge(struct
64535 if (next && next->vm_end == end) /* cases 6, 7, 8 */
64536 next = next->vm_next;
64537
64538+#ifdef CONFIG_PAX_SEGMEXEC
64539+ if (prev)
64540+ prev_m = pax_find_mirror_vma(prev);
64541+ if (area)
64542+ area_m = pax_find_mirror_vma(area);
64543+ if (next)
64544+ next_m = pax_find_mirror_vma(next);
64545+#endif
64546+
64547 /*
64548 * Can it merge with the predecessor?
64549 */
64550@@ -799,9 +849,24 @@ struct vm_area_struct *vma_merge(struct
64551 /* cases 1, 6 */
64552 err = vma_adjust(prev, prev->vm_start,
64553 next->vm_end, prev->vm_pgoff, NULL);
64554- } else /* cases 2, 5, 7 */
64555+
64556+#ifdef CONFIG_PAX_SEGMEXEC
64557+ if (!err && prev_m)
64558+ err = vma_adjust(prev_m, prev_m->vm_start,
64559+ next_m->vm_end, prev_m->vm_pgoff, NULL);
64560+#endif
64561+
64562+ } else { /* cases 2, 5, 7 */
64563 err = vma_adjust(prev, prev->vm_start,
64564 end, prev->vm_pgoff, NULL);
64565+
64566+#ifdef CONFIG_PAX_SEGMEXEC
64567+ if (!err && prev_m)
64568+ err = vma_adjust(prev_m, prev_m->vm_start,
64569+ end_m, prev_m->vm_pgoff, NULL);
64570+#endif
64571+
64572+ }
64573 if (err)
64574 return NULL;
64575 khugepaged_enter_vma_merge(prev);
64576@@ -815,12 +880,27 @@ struct vm_area_struct *vma_merge(struct
64577 mpol_equal(policy, vma_policy(next)) &&
64578 can_vma_merge_before(next, vm_flags,
64579 anon_vma, file, pgoff+pglen)) {
64580- if (prev && addr < prev->vm_end) /* case 4 */
64581+ if (prev && addr < prev->vm_end) { /* case 4 */
64582 err = vma_adjust(prev, prev->vm_start,
64583 addr, prev->vm_pgoff, NULL);
64584- else /* cases 3, 8 */
64585+
64586+#ifdef CONFIG_PAX_SEGMEXEC
64587+ if (!err && prev_m)
64588+ err = vma_adjust(prev_m, prev_m->vm_start,
64589+ addr_m, prev_m->vm_pgoff, NULL);
64590+#endif
64591+
64592+ } else { /* cases 3, 8 */
64593 err = vma_adjust(area, addr, next->vm_end,
64594 next->vm_pgoff - pglen, NULL);
64595+
64596+#ifdef CONFIG_PAX_SEGMEXEC
64597+ if (!err && area_m)
64598+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
64599+ next_m->vm_pgoff - pglen, NULL);
64600+#endif
64601+
64602+ }
64603 if (err)
64604 return NULL;
64605 khugepaged_enter_vma_merge(area);
64606@@ -929,14 +1009,11 @@ none:
64607 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
64608 struct file *file, long pages)
64609 {
64610- const unsigned long stack_flags
64611- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
64612-
64613 if (file) {
64614 mm->shared_vm += pages;
64615 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
64616 mm->exec_vm += pages;
64617- } else if (flags & stack_flags)
64618+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
64619 mm->stack_vm += pages;
64620 if (flags & (VM_RESERVED|VM_IO))
64621 mm->reserved_vm += pages;
64622@@ -963,7 +1040,7 @@ unsigned long do_mmap_pgoff(struct file
64623 * (the exception is when the underlying filesystem is noexec
64624 * mounted, in which case we dont add PROT_EXEC.)
64625 */
64626- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
64627+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
64628 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
64629 prot |= PROT_EXEC;
64630
64631@@ -989,7 +1066,7 @@ unsigned long do_mmap_pgoff(struct file
64632 /* Obtain the address to map to. we verify (or select) it and ensure
64633 * that it represents a valid section of the address space.
64634 */
64635- addr = get_unmapped_area(file, addr, len, pgoff, flags);
64636+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
64637 if (addr & ~PAGE_MASK)
64638 return addr;
64639
64640@@ -1000,6 +1077,36 @@ unsigned long do_mmap_pgoff(struct file
64641 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
64642 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
64643
64644+#ifdef CONFIG_PAX_MPROTECT
64645+ if (mm->pax_flags & MF_PAX_MPROTECT) {
64646+#ifndef CONFIG_PAX_MPROTECT_COMPAT
64647+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
64648+ gr_log_rwxmmap(file);
64649+
64650+#ifdef CONFIG_PAX_EMUPLT
64651+ vm_flags &= ~VM_EXEC;
64652+#else
64653+ return -EPERM;
64654+#endif
64655+
64656+ }
64657+
64658+ if (!(vm_flags & VM_EXEC))
64659+ vm_flags &= ~VM_MAYEXEC;
64660+#else
64661+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
64662+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
64663+#endif
64664+ else
64665+ vm_flags &= ~VM_MAYWRITE;
64666+ }
64667+#endif
64668+
64669+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64670+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
64671+ vm_flags &= ~VM_PAGEEXEC;
64672+#endif
64673+
64674 if (flags & MAP_LOCKED)
64675 if (!can_do_mlock())
64676 return -EPERM;
64677@@ -1011,6 +1118,7 @@ unsigned long do_mmap_pgoff(struct file
64678 locked += mm->locked_vm;
64679 lock_limit = rlimit(RLIMIT_MEMLOCK);
64680 lock_limit >>= PAGE_SHIFT;
64681+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
64682 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
64683 return -EAGAIN;
64684 }
64685@@ -1081,6 +1189,9 @@ unsigned long do_mmap_pgoff(struct file
64686 if (error)
64687 return error;
64688
64689+ if (!gr_acl_handle_mmap(file, prot))
64690+ return -EACCES;
64691+
64692 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
64693 }
64694 EXPORT_SYMBOL(do_mmap_pgoff);
64695@@ -1161,7 +1272,7 @@ int vma_wants_writenotify(struct vm_area
64696 vm_flags_t vm_flags = vma->vm_flags;
64697
64698 /* If it was private or non-writable, the write bit is already clear */
64699- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
64700+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
64701 return 0;
64702
64703 /* The backer wishes to know when pages are first written to? */
64704@@ -1210,14 +1321,24 @@ unsigned long mmap_region(struct file *f
64705 unsigned long charged = 0;
64706 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
64707
64708+#ifdef CONFIG_PAX_SEGMEXEC
64709+ struct vm_area_struct *vma_m = NULL;
64710+#endif
64711+
64712+ /*
64713+ * mm->mmap_sem is required to protect against another thread
64714+ * changing the mappings in case we sleep.
64715+ */
64716+ verify_mm_writelocked(mm);
64717+
64718 /* Clear old maps */
64719 error = -ENOMEM;
64720-munmap_back:
64721 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
64722 if (vma && vma->vm_start < addr + len) {
64723 if (do_munmap(mm, addr, len))
64724 return -ENOMEM;
64725- goto munmap_back;
64726+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
64727+ BUG_ON(vma && vma->vm_start < addr + len);
64728 }
64729
64730 /* Check against address space limit. */
64731@@ -1266,6 +1387,16 @@ munmap_back:
64732 goto unacct_error;
64733 }
64734
64735+#ifdef CONFIG_PAX_SEGMEXEC
64736+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
64737+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
64738+ if (!vma_m) {
64739+ error = -ENOMEM;
64740+ goto free_vma;
64741+ }
64742+ }
64743+#endif
64744+
64745 vma->vm_mm = mm;
64746 vma->vm_start = addr;
64747 vma->vm_end = addr + len;
64748@@ -1289,6 +1420,19 @@ munmap_back:
64749 error = file->f_op->mmap(file, vma);
64750 if (error)
64751 goto unmap_and_free_vma;
64752+
64753+#ifdef CONFIG_PAX_SEGMEXEC
64754+ if (vma_m && (vm_flags & VM_EXECUTABLE))
64755+ added_exe_file_vma(mm);
64756+#endif
64757+
64758+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64759+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
64760+ vma->vm_flags |= VM_PAGEEXEC;
64761+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
64762+ }
64763+#endif
64764+
64765 if (vm_flags & VM_EXECUTABLE)
64766 added_exe_file_vma(mm);
64767
64768@@ -1324,6 +1468,11 @@ munmap_back:
64769 vma_link(mm, vma, prev, rb_link, rb_parent);
64770 file = vma->vm_file;
64771
64772+#ifdef CONFIG_PAX_SEGMEXEC
64773+ if (vma_m)
64774+ BUG_ON(pax_mirror_vma(vma_m, vma));
64775+#endif
64776+
64777 /* Once vma denies write, undo our temporary denial count */
64778 if (correct_wcount)
64779 atomic_inc(&inode->i_writecount);
64780@@ -1332,6 +1481,7 @@ out:
64781
64782 mm->total_vm += len >> PAGE_SHIFT;
64783 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
64784+ track_exec_limit(mm, addr, addr + len, vm_flags);
64785 if (vm_flags & VM_LOCKED) {
64786 if (!mlock_vma_pages_range(vma, addr, addr + len))
64787 mm->locked_vm += (len >> PAGE_SHIFT);
64788@@ -1349,6 +1499,12 @@ unmap_and_free_vma:
64789 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
64790 charged = 0;
64791 free_vma:
64792+
64793+#ifdef CONFIG_PAX_SEGMEXEC
64794+ if (vma_m)
64795+ kmem_cache_free(vm_area_cachep, vma_m);
64796+#endif
64797+
64798 kmem_cache_free(vm_area_cachep, vma);
64799 unacct_error:
64800 if (charged)
64801@@ -1356,6 +1512,44 @@ unacct_error:
64802 return error;
64803 }
64804
64805+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
64806+{
64807+ if (!vma) {
64808+#ifdef CONFIG_STACK_GROWSUP
64809+ if (addr > sysctl_heap_stack_gap)
64810+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
64811+ else
64812+ vma = find_vma(current->mm, 0);
64813+ if (vma && (vma->vm_flags & VM_GROWSUP))
64814+ return false;
64815+#endif
64816+ return true;
64817+ }
64818+
64819+ if (addr + len > vma->vm_start)
64820+ return false;
64821+
64822+ if (vma->vm_flags & VM_GROWSDOWN)
64823+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
64824+#ifdef CONFIG_STACK_GROWSUP
64825+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
64826+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
64827+#endif
64828+
64829+ return true;
64830+}
64831+
64832+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
64833+{
64834+ if (vma->vm_start < len)
64835+ return -ENOMEM;
64836+ if (!(vma->vm_flags & VM_GROWSDOWN))
64837+ return vma->vm_start - len;
64838+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
64839+ return vma->vm_start - len - sysctl_heap_stack_gap;
64840+ return -ENOMEM;
64841+}
64842+
64843 /* Get an address range which is currently unmapped.
64844 * For shmat() with addr=0.
64845 *
64846@@ -1382,18 +1576,23 @@ arch_get_unmapped_area(struct file *filp
64847 if (flags & MAP_FIXED)
64848 return addr;
64849
64850+#ifdef CONFIG_PAX_RANDMMAP
64851+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64852+#endif
64853+
64854 if (addr) {
64855 addr = PAGE_ALIGN(addr);
64856- vma = find_vma(mm, addr);
64857- if (TASK_SIZE - len >= addr &&
64858- (!vma || addr + len <= vma->vm_start))
64859- return addr;
64860+ if (TASK_SIZE - len >= addr) {
64861+ vma = find_vma(mm, addr);
64862+ if (check_heap_stack_gap(vma, addr, len))
64863+ return addr;
64864+ }
64865 }
64866 if (len > mm->cached_hole_size) {
64867- start_addr = addr = mm->free_area_cache;
64868+ start_addr = addr = mm->free_area_cache;
64869 } else {
64870- start_addr = addr = TASK_UNMAPPED_BASE;
64871- mm->cached_hole_size = 0;
64872+ start_addr = addr = mm->mmap_base;
64873+ mm->cached_hole_size = 0;
64874 }
64875
64876 full_search:
64877@@ -1404,34 +1603,40 @@ full_search:
64878 * Start a new search - just in case we missed
64879 * some holes.
64880 */
64881- if (start_addr != TASK_UNMAPPED_BASE) {
64882- addr = TASK_UNMAPPED_BASE;
64883- start_addr = addr;
64884+ if (start_addr != mm->mmap_base) {
64885+ start_addr = addr = mm->mmap_base;
64886 mm->cached_hole_size = 0;
64887 goto full_search;
64888 }
64889 return -ENOMEM;
64890 }
64891- if (!vma || addr + len <= vma->vm_start) {
64892- /*
64893- * Remember the place where we stopped the search:
64894- */
64895- mm->free_area_cache = addr + len;
64896- return addr;
64897- }
64898+ if (check_heap_stack_gap(vma, addr, len))
64899+ break;
64900 if (addr + mm->cached_hole_size < vma->vm_start)
64901 mm->cached_hole_size = vma->vm_start - addr;
64902 addr = vma->vm_end;
64903 }
64904+
64905+ /*
64906+ * Remember the place where we stopped the search:
64907+ */
64908+ mm->free_area_cache = addr + len;
64909+ return addr;
64910 }
64911 #endif
64912
64913 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
64914 {
64915+
64916+#ifdef CONFIG_PAX_SEGMEXEC
64917+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
64918+ return;
64919+#endif
64920+
64921 /*
64922 * Is this a new hole at the lowest possible address?
64923 */
64924- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
64925+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
64926 mm->free_area_cache = addr;
64927 mm->cached_hole_size = ~0UL;
64928 }
64929@@ -1449,7 +1654,7 @@ arch_get_unmapped_area_topdown(struct fi
64930 {
64931 struct vm_area_struct *vma;
64932 struct mm_struct *mm = current->mm;
64933- unsigned long addr = addr0;
64934+ unsigned long base = mm->mmap_base, addr = addr0;
64935
64936 /* requested length too big for entire address space */
64937 if (len > TASK_SIZE)
64938@@ -1458,13 +1663,18 @@ arch_get_unmapped_area_topdown(struct fi
64939 if (flags & MAP_FIXED)
64940 return addr;
64941
64942+#ifdef CONFIG_PAX_RANDMMAP
64943+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64944+#endif
64945+
64946 /* requesting a specific address */
64947 if (addr) {
64948 addr = PAGE_ALIGN(addr);
64949- vma = find_vma(mm, addr);
64950- if (TASK_SIZE - len >= addr &&
64951- (!vma || addr + len <= vma->vm_start))
64952- return addr;
64953+ if (TASK_SIZE - len >= addr) {
64954+ vma = find_vma(mm, addr);
64955+ if (check_heap_stack_gap(vma, addr, len))
64956+ return addr;
64957+ }
64958 }
64959
64960 /* check if free_area_cache is useful for us */
64961@@ -1479,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct fi
64962 /* make sure it can fit in the remaining address space */
64963 if (addr > len) {
64964 vma = find_vma(mm, addr-len);
64965- if (!vma || addr <= vma->vm_start)
64966+ if (check_heap_stack_gap(vma, addr - len, len))
64967 /* remember the address as a hint for next time */
64968 return (mm->free_area_cache = addr-len);
64969 }
64970@@ -1496,7 +1706,7 @@ arch_get_unmapped_area_topdown(struct fi
64971 * return with success:
64972 */
64973 vma = find_vma(mm, addr);
64974- if (!vma || addr+len <= vma->vm_start)
64975+ if (check_heap_stack_gap(vma, addr, len))
64976 /* remember the address as a hint for next time */
64977 return (mm->free_area_cache = addr);
64978
64979@@ -1505,8 +1715,8 @@ arch_get_unmapped_area_topdown(struct fi
64980 mm->cached_hole_size = vma->vm_start - addr;
64981
64982 /* try just below the current vma->vm_start */
64983- addr = vma->vm_start-len;
64984- } while (len < vma->vm_start);
64985+ addr = skip_heap_stack_gap(vma, len);
64986+ } while (!IS_ERR_VALUE(addr));
64987
64988 bottomup:
64989 /*
64990@@ -1515,13 +1725,21 @@ bottomup:
64991 * can happen with large stack limits and large mmap()
64992 * allocations.
64993 */
64994+ mm->mmap_base = TASK_UNMAPPED_BASE;
64995+
64996+#ifdef CONFIG_PAX_RANDMMAP
64997+ if (mm->pax_flags & MF_PAX_RANDMMAP)
64998+ mm->mmap_base += mm->delta_mmap;
64999+#endif
65000+
65001+ mm->free_area_cache = mm->mmap_base;
65002 mm->cached_hole_size = ~0UL;
65003- mm->free_area_cache = TASK_UNMAPPED_BASE;
65004 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
65005 /*
65006 * Restore the topdown base:
65007 */
65008- mm->free_area_cache = mm->mmap_base;
65009+ mm->mmap_base = base;
65010+ mm->free_area_cache = base;
65011 mm->cached_hole_size = ~0UL;
65012
65013 return addr;
65014@@ -1530,6 +1748,12 @@ bottomup:
65015
65016 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
65017 {
65018+
65019+#ifdef CONFIG_PAX_SEGMEXEC
65020+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
65021+ return;
65022+#endif
65023+
65024 /*
65025 * Is this a new hole at the highest possible address?
65026 */
65027@@ -1537,8 +1761,10 @@ void arch_unmap_area_topdown(struct mm_s
65028 mm->free_area_cache = addr;
65029
65030 /* dont allow allocations above current base */
65031- if (mm->free_area_cache > mm->mmap_base)
65032+ if (mm->free_area_cache > mm->mmap_base) {
65033 mm->free_area_cache = mm->mmap_base;
65034+ mm->cached_hole_size = ~0UL;
65035+ }
65036 }
65037
65038 unsigned long
65039@@ -1646,6 +1872,28 @@ out:
65040 return prev ? prev->vm_next : vma;
65041 }
65042
65043+#ifdef CONFIG_PAX_SEGMEXEC
65044+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
65045+{
65046+ struct vm_area_struct *vma_m;
65047+
65048+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
65049+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
65050+ BUG_ON(vma->vm_mirror);
65051+ return NULL;
65052+ }
65053+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
65054+ vma_m = vma->vm_mirror;
65055+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
65056+ BUG_ON(vma->vm_file != vma_m->vm_file);
65057+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
65058+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
65059+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
65060+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
65061+ return vma_m;
65062+}
65063+#endif
65064+
65065 /*
65066 * Verify that the stack growth is acceptable and
65067 * update accounting. This is shared with both the
65068@@ -1662,6 +1910,7 @@ static int acct_stack_growth(struct vm_a
65069 return -ENOMEM;
65070
65071 /* Stack limit test */
65072+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
65073 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
65074 return -ENOMEM;
65075
65076@@ -1672,6 +1921,7 @@ static int acct_stack_growth(struct vm_a
65077 locked = mm->locked_vm + grow;
65078 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
65079 limit >>= PAGE_SHIFT;
65080+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
65081 if (locked > limit && !capable(CAP_IPC_LOCK))
65082 return -ENOMEM;
65083 }
65084@@ -1702,37 +1952,48 @@ static int acct_stack_growth(struct vm_a
65085 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
65086 * vma is the last one with address > vma->vm_end. Have to extend vma.
65087 */
65088+#ifndef CONFIG_IA64
65089+static
65090+#endif
65091 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
65092 {
65093 int error;
65094+ bool locknext;
65095
65096 if (!(vma->vm_flags & VM_GROWSUP))
65097 return -EFAULT;
65098
65099+ /* Also guard against wrapping around to address 0. */
65100+ if (address < PAGE_ALIGN(address+1))
65101+ address = PAGE_ALIGN(address+1);
65102+ else
65103+ return -ENOMEM;
65104+
65105 /*
65106 * We must make sure the anon_vma is allocated
65107 * so that the anon_vma locking is not a noop.
65108 */
65109 if (unlikely(anon_vma_prepare(vma)))
65110 return -ENOMEM;
65111+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
65112+ if (locknext && anon_vma_prepare(vma->vm_next))
65113+ return -ENOMEM;
65114 vma_lock_anon_vma(vma);
65115+ if (locknext)
65116+ vma_lock_anon_vma(vma->vm_next);
65117
65118 /*
65119 * vma->vm_start/vm_end cannot change under us because the caller
65120 * is required to hold the mmap_sem in read mode. We need the
65121- * anon_vma lock to serialize against concurrent expand_stacks.
65122- * Also guard against wrapping around to address 0.
65123+ * anon_vma locks to serialize against concurrent expand_stacks
65124+ * and expand_upwards.
65125 */
65126- if (address < PAGE_ALIGN(address+4))
65127- address = PAGE_ALIGN(address+4);
65128- else {
65129- vma_unlock_anon_vma(vma);
65130- return -ENOMEM;
65131- }
65132 error = 0;
65133
65134 /* Somebody else might have raced and expanded it already */
65135- if (address > vma->vm_end) {
65136+ 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)
65137+ error = -ENOMEM;
65138+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
65139 unsigned long size, grow;
65140
65141 size = address - vma->vm_start;
65142@@ -1747,6 +2008,8 @@ int expand_upwards(struct vm_area_struct
65143 }
65144 }
65145 }
65146+ if (locknext)
65147+ vma_unlock_anon_vma(vma->vm_next);
65148 vma_unlock_anon_vma(vma);
65149 khugepaged_enter_vma_merge(vma);
65150 return error;
65151@@ -1760,6 +2023,8 @@ int expand_downwards(struct vm_area_stru
65152 unsigned long address)
65153 {
65154 int error;
65155+ bool lockprev = false;
65156+ struct vm_area_struct *prev;
65157
65158 /*
65159 * We must make sure the anon_vma is allocated
65160@@ -1773,6 +2038,15 @@ int expand_downwards(struct vm_area_stru
65161 if (error)
65162 return error;
65163
65164+ prev = vma->vm_prev;
65165+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
65166+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
65167+#endif
65168+ if (lockprev && anon_vma_prepare(prev))
65169+ return -ENOMEM;
65170+ if (lockprev)
65171+ vma_lock_anon_vma(prev);
65172+
65173 vma_lock_anon_vma(vma);
65174
65175 /*
65176@@ -1782,9 +2056,17 @@ int expand_downwards(struct vm_area_stru
65177 */
65178
65179 /* Somebody else might have raced and expanded it already */
65180- if (address < vma->vm_start) {
65181+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
65182+ error = -ENOMEM;
65183+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
65184 unsigned long size, grow;
65185
65186+#ifdef CONFIG_PAX_SEGMEXEC
65187+ struct vm_area_struct *vma_m;
65188+
65189+ vma_m = pax_find_mirror_vma(vma);
65190+#endif
65191+
65192 size = vma->vm_end - address;
65193 grow = (vma->vm_start - address) >> PAGE_SHIFT;
65194
65195@@ -1794,11 +2076,22 @@ int expand_downwards(struct vm_area_stru
65196 if (!error) {
65197 vma->vm_start = address;
65198 vma->vm_pgoff -= grow;
65199+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
65200+
65201+#ifdef CONFIG_PAX_SEGMEXEC
65202+ if (vma_m) {
65203+ vma_m->vm_start -= grow << PAGE_SHIFT;
65204+ vma_m->vm_pgoff -= grow;
65205+ }
65206+#endif
65207+
65208 perf_event_mmap(vma);
65209 }
65210 }
65211 }
65212 vma_unlock_anon_vma(vma);
65213+ if (lockprev)
65214+ vma_unlock_anon_vma(prev);
65215 khugepaged_enter_vma_merge(vma);
65216 return error;
65217 }
65218@@ -1868,6 +2161,13 @@ static void remove_vma_list(struct mm_st
65219 do {
65220 long nrpages = vma_pages(vma);
65221
65222+#ifdef CONFIG_PAX_SEGMEXEC
65223+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
65224+ vma = remove_vma(vma);
65225+ continue;
65226+ }
65227+#endif
65228+
65229 mm->total_vm -= nrpages;
65230 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
65231 vma = remove_vma(vma);
65232@@ -1913,6 +2213,16 @@ detach_vmas_to_be_unmapped(struct mm_str
65233 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
65234 vma->vm_prev = NULL;
65235 do {
65236+
65237+#ifdef CONFIG_PAX_SEGMEXEC
65238+ if (vma->vm_mirror) {
65239+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
65240+ vma->vm_mirror->vm_mirror = NULL;
65241+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
65242+ vma->vm_mirror = NULL;
65243+ }
65244+#endif
65245+
65246 rb_erase(&vma->vm_rb, &mm->mm_rb);
65247 mm->map_count--;
65248 tail_vma = vma;
65249@@ -1941,14 +2251,33 @@ static int __split_vma(struct mm_struct
65250 struct vm_area_struct *new;
65251 int err = -ENOMEM;
65252
65253+#ifdef CONFIG_PAX_SEGMEXEC
65254+ struct vm_area_struct *vma_m, *new_m = NULL;
65255+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
65256+#endif
65257+
65258 if (is_vm_hugetlb_page(vma) && (addr &
65259 ~(huge_page_mask(hstate_vma(vma)))))
65260 return -EINVAL;
65261
65262+#ifdef CONFIG_PAX_SEGMEXEC
65263+ vma_m = pax_find_mirror_vma(vma);
65264+#endif
65265+
65266 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65267 if (!new)
65268 goto out_err;
65269
65270+#ifdef CONFIG_PAX_SEGMEXEC
65271+ if (vma_m) {
65272+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65273+ if (!new_m) {
65274+ kmem_cache_free(vm_area_cachep, new);
65275+ goto out_err;
65276+ }
65277+ }
65278+#endif
65279+
65280 /* most fields are the same, copy all, and then fixup */
65281 *new = *vma;
65282
65283@@ -1961,6 +2290,22 @@ static int __split_vma(struct mm_struct
65284 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
65285 }
65286
65287+#ifdef CONFIG_PAX_SEGMEXEC
65288+ if (vma_m) {
65289+ *new_m = *vma_m;
65290+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
65291+ new_m->vm_mirror = new;
65292+ new->vm_mirror = new_m;
65293+
65294+ if (new_below)
65295+ new_m->vm_end = addr_m;
65296+ else {
65297+ new_m->vm_start = addr_m;
65298+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
65299+ }
65300+ }
65301+#endif
65302+
65303 pol = mpol_dup(vma_policy(vma));
65304 if (IS_ERR(pol)) {
65305 err = PTR_ERR(pol);
65306@@ -1986,6 +2331,42 @@ static int __split_vma(struct mm_struct
65307 else
65308 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
65309
65310+#ifdef CONFIG_PAX_SEGMEXEC
65311+ if (!err && vma_m) {
65312+ if (anon_vma_clone(new_m, vma_m))
65313+ goto out_free_mpol;
65314+
65315+ mpol_get(pol);
65316+ vma_set_policy(new_m, pol);
65317+
65318+ if (new_m->vm_file) {
65319+ get_file(new_m->vm_file);
65320+ if (vma_m->vm_flags & VM_EXECUTABLE)
65321+ added_exe_file_vma(mm);
65322+ }
65323+
65324+ if (new_m->vm_ops && new_m->vm_ops->open)
65325+ new_m->vm_ops->open(new_m);
65326+
65327+ if (new_below)
65328+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
65329+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
65330+ else
65331+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
65332+
65333+ if (err) {
65334+ if (new_m->vm_ops && new_m->vm_ops->close)
65335+ new_m->vm_ops->close(new_m);
65336+ if (new_m->vm_file) {
65337+ if (vma_m->vm_flags & VM_EXECUTABLE)
65338+ removed_exe_file_vma(mm);
65339+ fput(new_m->vm_file);
65340+ }
65341+ mpol_put(pol);
65342+ }
65343+ }
65344+#endif
65345+
65346 /* Success. */
65347 if (!err)
65348 return 0;
65349@@ -1998,10 +2379,18 @@ static int __split_vma(struct mm_struct
65350 removed_exe_file_vma(mm);
65351 fput(new->vm_file);
65352 }
65353- unlink_anon_vmas(new);
65354 out_free_mpol:
65355 mpol_put(pol);
65356 out_free_vma:
65357+
65358+#ifdef CONFIG_PAX_SEGMEXEC
65359+ if (new_m) {
65360+ unlink_anon_vmas(new_m);
65361+ kmem_cache_free(vm_area_cachep, new_m);
65362+ }
65363+#endif
65364+
65365+ unlink_anon_vmas(new);
65366 kmem_cache_free(vm_area_cachep, new);
65367 out_err:
65368 return err;
65369@@ -2014,6 +2403,15 @@ static int __split_vma(struct mm_struct
65370 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
65371 unsigned long addr, int new_below)
65372 {
65373+
65374+#ifdef CONFIG_PAX_SEGMEXEC
65375+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
65376+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
65377+ if (mm->map_count >= sysctl_max_map_count-1)
65378+ return -ENOMEM;
65379+ } else
65380+#endif
65381+
65382 if (mm->map_count >= sysctl_max_map_count)
65383 return -ENOMEM;
65384
65385@@ -2025,11 +2423,30 @@ int split_vma(struct mm_struct *mm, stru
65386 * work. This now handles partial unmappings.
65387 * Jeremy Fitzhardinge <jeremy@goop.org>
65388 */
65389+#ifdef CONFIG_PAX_SEGMEXEC
65390 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65391 {
65392+ int ret = __do_munmap(mm, start, len);
65393+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
65394+ return ret;
65395+
65396+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
65397+}
65398+
65399+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65400+#else
65401+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65402+#endif
65403+{
65404 unsigned long end;
65405 struct vm_area_struct *vma, *prev, *last;
65406
65407+ /*
65408+ * mm->mmap_sem is required to protect against another thread
65409+ * changing the mappings in case we sleep.
65410+ */
65411+ verify_mm_writelocked(mm);
65412+
65413 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
65414 return -EINVAL;
65415
65416@@ -2104,6 +2521,8 @@ int do_munmap(struct mm_struct *mm, unsi
65417 /* Fix up all other VM information */
65418 remove_vma_list(mm, vma);
65419
65420+ track_exec_limit(mm, start, end, 0UL);
65421+
65422 return 0;
65423 }
65424
65425@@ -2116,22 +2535,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
65426
65427 profile_munmap(addr);
65428
65429+#ifdef CONFIG_PAX_SEGMEXEC
65430+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
65431+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
65432+ return -EINVAL;
65433+#endif
65434+
65435 down_write(&mm->mmap_sem);
65436 ret = do_munmap(mm, addr, len);
65437 up_write(&mm->mmap_sem);
65438 return ret;
65439 }
65440
65441-static inline void verify_mm_writelocked(struct mm_struct *mm)
65442-{
65443-#ifdef CONFIG_DEBUG_VM
65444- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
65445- WARN_ON(1);
65446- up_read(&mm->mmap_sem);
65447- }
65448-#endif
65449-}
65450-
65451 /*
65452 * this is really a simplified "do_mmap". it only handles
65453 * anonymous maps. eventually we may be able to do some
65454@@ -2145,6 +2560,7 @@ unsigned long do_brk(unsigned long addr,
65455 struct rb_node ** rb_link, * rb_parent;
65456 pgoff_t pgoff = addr >> PAGE_SHIFT;
65457 int error;
65458+ unsigned long charged;
65459
65460 len = PAGE_ALIGN(len);
65461 if (!len)
65462@@ -2156,16 +2572,30 @@ unsigned long do_brk(unsigned long addr,
65463
65464 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
65465
65466+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
65467+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
65468+ flags &= ~VM_EXEC;
65469+
65470+#ifdef CONFIG_PAX_MPROTECT
65471+ if (mm->pax_flags & MF_PAX_MPROTECT)
65472+ flags &= ~VM_MAYEXEC;
65473+#endif
65474+
65475+ }
65476+#endif
65477+
65478 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
65479 if (error & ~PAGE_MASK)
65480 return error;
65481
65482+ charged = len >> PAGE_SHIFT;
65483+
65484 /*
65485 * mlock MCL_FUTURE?
65486 */
65487 if (mm->def_flags & VM_LOCKED) {
65488 unsigned long locked, lock_limit;
65489- locked = len >> PAGE_SHIFT;
65490+ locked = charged;
65491 locked += mm->locked_vm;
65492 lock_limit = rlimit(RLIMIT_MEMLOCK);
65493 lock_limit >>= PAGE_SHIFT;
65494@@ -2182,22 +2612,22 @@ unsigned long do_brk(unsigned long addr,
65495 /*
65496 * Clear old maps. this also does some error checking for us
65497 */
65498- munmap_back:
65499 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
65500 if (vma && vma->vm_start < addr + len) {
65501 if (do_munmap(mm, addr, len))
65502 return -ENOMEM;
65503- goto munmap_back;
65504+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
65505+ BUG_ON(vma && vma->vm_start < addr + len);
65506 }
65507
65508 /* Check against address space limits *after* clearing old maps... */
65509- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
65510+ if (!may_expand_vm(mm, charged))
65511 return -ENOMEM;
65512
65513 if (mm->map_count > sysctl_max_map_count)
65514 return -ENOMEM;
65515
65516- if (security_vm_enough_memory(len >> PAGE_SHIFT))
65517+ if (security_vm_enough_memory(charged))
65518 return -ENOMEM;
65519
65520 /* Can we just expand an old private anonymous mapping? */
65521@@ -2211,7 +2641,7 @@ unsigned long do_brk(unsigned long addr,
65522 */
65523 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65524 if (!vma) {
65525- vm_unacct_memory(len >> PAGE_SHIFT);
65526+ vm_unacct_memory(charged);
65527 return -ENOMEM;
65528 }
65529
65530@@ -2225,11 +2655,12 @@ unsigned long do_brk(unsigned long addr,
65531 vma_link(mm, vma, prev, rb_link, rb_parent);
65532 out:
65533 perf_event_mmap(vma);
65534- mm->total_vm += len >> PAGE_SHIFT;
65535+ mm->total_vm += charged;
65536 if (flags & VM_LOCKED) {
65537 if (!mlock_vma_pages_range(vma, addr, addr + len))
65538- mm->locked_vm += (len >> PAGE_SHIFT);
65539+ mm->locked_vm += charged;
65540 }
65541+ track_exec_limit(mm, addr, addr + len, flags);
65542 return addr;
65543 }
65544
65545@@ -2276,8 +2707,10 @@ void exit_mmap(struct mm_struct *mm)
65546 * Walk the list again, actually closing and freeing it,
65547 * with preemption enabled, without holding any MM locks.
65548 */
65549- while (vma)
65550+ while (vma) {
65551+ vma->vm_mirror = NULL;
65552 vma = remove_vma(vma);
65553+ }
65554
65555 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
65556 }
65557@@ -2291,6 +2724,13 @@ int insert_vm_struct(struct mm_struct *
65558 struct vm_area_struct * __vma, * prev;
65559 struct rb_node ** rb_link, * rb_parent;
65560
65561+#ifdef CONFIG_PAX_SEGMEXEC
65562+ struct vm_area_struct *vma_m = NULL;
65563+#endif
65564+
65565+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
65566+ return -EPERM;
65567+
65568 /*
65569 * The vm_pgoff of a purely anonymous vma should be irrelevant
65570 * until its first write fault, when page's anon_vma and index
65571@@ -2313,7 +2753,22 @@ int insert_vm_struct(struct mm_struct *
65572 if ((vma->vm_flags & VM_ACCOUNT) &&
65573 security_vm_enough_memory_mm(mm, vma_pages(vma)))
65574 return -ENOMEM;
65575+
65576+#ifdef CONFIG_PAX_SEGMEXEC
65577+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
65578+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65579+ if (!vma_m)
65580+ return -ENOMEM;
65581+ }
65582+#endif
65583+
65584 vma_link(mm, vma, prev, rb_link, rb_parent);
65585+
65586+#ifdef CONFIG_PAX_SEGMEXEC
65587+ if (vma_m)
65588+ BUG_ON(pax_mirror_vma(vma_m, vma));
65589+#endif
65590+
65591 return 0;
65592 }
65593
65594@@ -2331,6 +2786,8 @@ struct vm_area_struct *copy_vma(struct v
65595 struct rb_node **rb_link, *rb_parent;
65596 struct mempolicy *pol;
65597
65598+ BUG_ON(vma->vm_mirror);
65599+
65600 /*
65601 * If anonymous vma has not yet been faulted, update new pgoff
65602 * to match new location, to increase its chance of merging.
65603@@ -2381,6 +2838,39 @@ struct vm_area_struct *copy_vma(struct v
65604 return NULL;
65605 }
65606
65607+#ifdef CONFIG_PAX_SEGMEXEC
65608+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
65609+{
65610+ struct vm_area_struct *prev_m;
65611+ struct rb_node **rb_link_m, *rb_parent_m;
65612+ struct mempolicy *pol_m;
65613+
65614+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
65615+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
65616+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
65617+ *vma_m = *vma;
65618+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
65619+ if (anon_vma_clone(vma_m, vma))
65620+ return -ENOMEM;
65621+ pol_m = vma_policy(vma_m);
65622+ mpol_get(pol_m);
65623+ vma_set_policy(vma_m, pol_m);
65624+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
65625+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
65626+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
65627+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
65628+ if (vma_m->vm_file)
65629+ get_file(vma_m->vm_file);
65630+ if (vma_m->vm_ops && vma_m->vm_ops->open)
65631+ vma_m->vm_ops->open(vma_m);
65632+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
65633+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
65634+ vma_m->vm_mirror = vma;
65635+ vma->vm_mirror = vma_m;
65636+ return 0;
65637+}
65638+#endif
65639+
65640 /*
65641 * Return true if the calling process may expand its vm space by the passed
65642 * number of pages
65643@@ -2391,7 +2881,7 @@ int may_expand_vm(struct mm_struct *mm,
65644 unsigned long lim;
65645
65646 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
65647-
65648+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
65649 if (cur + npages > lim)
65650 return 0;
65651 return 1;
65652@@ -2462,6 +2952,22 @@ int install_special_mapping(struct mm_st
65653 vma->vm_start = addr;
65654 vma->vm_end = addr + len;
65655
65656+#ifdef CONFIG_PAX_MPROTECT
65657+ if (mm->pax_flags & MF_PAX_MPROTECT) {
65658+#ifndef CONFIG_PAX_MPROTECT_COMPAT
65659+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
65660+ return -EPERM;
65661+ if (!(vm_flags & VM_EXEC))
65662+ vm_flags &= ~VM_MAYEXEC;
65663+#else
65664+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
65665+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
65666+#endif
65667+ else
65668+ vm_flags &= ~VM_MAYWRITE;
65669+ }
65670+#endif
65671+
65672 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
65673 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
65674
65675diff -urNp linux-3.0.4/mm/mprotect.c linux-3.0.4/mm/mprotect.c
65676--- linux-3.0.4/mm/mprotect.c 2011-07-21 22:17:23.000000000 -0400
65677+++ linux-3.0.4/mm/mprotect.c 2011-08-23 21:48:14.000000000 -0400
65678@@ -23,10 +23,16 @@
65679 #include <linux/mmu_notifier.h>
65680 #include <linux/migrate.h>
65681 #include <linux/perf_event.h>
65682+
65683+#ifdef CONFIG_PAX_MPROTECT
65684+#include <linux/elf.h>
65685+#endif
65686+
65687 #include <asm/uaccess.h>
65688 #include <asm/pgtable.h>
65689 #include <asm/cacheflush.h>
65690 #include <asm/tlbflush.h>
65691+#include <asm/mmu_context.h>
65692
65693 #ifndef pgprot_modify
65694 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
65695@@ -141,6 +147,48 @@ static void change_protection(struct vm_
65696 flush_tlb_range(vma, start, end);
65697 }
65698
65699+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65700+/* called while holding the mmap semaphor for writing except stack expansion */
65701+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
65702+{
65703+ unsigned long oldlimit, newlimit = 0UL;
65704+
65705+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
65706+ return;
65707+
65708+ spin_lock(&mm->page_table_lock);
65709+ oldlimit = mm->context.user_cs_limit;
65710+ if ((prot & VM_EXEC) && oldlimit < end)
65711+ /* USER_CS limit moved up */
65712+ newlimit = end;
65713+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
65714+ /* USER_CS limit moved down */
65715+ newlimit = start;
65716+
65717+ if (newlimit) {
65718+ mm->context.user_cs_limit = newlimit;
65719+
65720+#ifdef CONFIG_SMP
65721+ wmb();
65722+ cpus_clear(mm->context.cpu_user_cs_mask);
65723+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
65724+#endif
65725+
65726+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
65727+ }
65728+ spin_unlock(&mm->page_table_lock);
65729+ if (newlimit == end) {
65730+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
65731+
65732+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
65733+ if (is_vm_hugetlb_page(vma))
65734+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
65735+ else
65736+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
65737+ }
65738+}
65739+#endif
65740+
65741 int
65742 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
65743 unsigned long start, unsigned long end, unsigned long newflags)
65744@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
65745 int error;
65746 int dirty_accountable = 0;
65747
65748+#ifdef CONFIG_PAX_SEGMEXEC
65749+ struct vm_area_struct *vma_m = NULL;
65750+ unsigned long start_m, end_m;
65751+
65752+ start_m = start + SEGMEXEC_TASK_SIZE;
65753+ end_m = end + SEGMEXEC_TASK_SIZE;
65754+#endif
65755+
65756 if (newflags == oldflags) {
65757 *pprev = vma;
65758 return 0;
65759 }
65760
65761+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
65762+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
65763+
65764+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
65765+ return -ENOMEM;
65766+
65767+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
65768+ return -ENOMEM;
65769+ }
65770+
65771 /*
65772 * If we make a private mapping writable we increase our commit;
65773 * but (without finer accounting) cannot reduce our commit if we
65774@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
65775 }
65776 }
65777
65778+#ifdef CONFIG_PAX_SEGMEXEC
65779+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
65780+ if (start != vma->vm_start) {
65781+ error = split_vma(mm, vma, start, 1);
65782+ if (error)
65783+ goto fail;
65784+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
65785+ *pprev = (*pprev)->vm_next;
65786+ }
65787+
65788+ if (end != vma->vm_end) {
65789+ error = split_vma(mm, vma, end, 0);
65790+ if (error)
65791+ goto fail;
65792+ }
65793+
65794+ if (pax_find_mirror_vma(vma)) {
65795+ error = __do_munmap(mm, start_m, end_m - start_m);
65796+ if (error)
65797+ goto fail;
65798+ } else {
65799+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65800+ if (!vma_m) {
65801+ error = -ENOMEM;
65802+ goto fail;
65803+ }
65804+ vma->vm_flags = newflags;
65805+ error = pax_mirror_vma(vma_m, vma);
65806+ if (error) {
65807+ vma->vm_flags = oldflags;
65808+ goto fail;
65809+ }
65810+ }
65811+ }
65812+#endif
65813+
65814 /*
65815 * First try to merge with previous and/or next vma.
65816 */
65817@@ -204,9 +306,21 @@ success:
65818 * vm_flags and vm_page_prot are protected by the mmap_sem
65819 * held in write mode.
65820 */
65821+
65822+#ifdef CONFIG_PAX_SEGMEXEC
65823+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
65824+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
65825+#endif
65826+
65827 vma->vm_flags = newflags;
65828+
65829+#ifdef CONFIG_PAX_MPROTECT
65830+ if (mm->binfmt && mm->binfmt->handle_mprotect)
65831+ mm->binfmt->handle_mprotect(vma, newflags);
65832+#endif
65833+
65834 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
65835- vm_get_page_prot(newflags));
65836+ vm_get_page_prot(vma->vm_flags));
65837
65838 if (vma_wants_writenotify(vma)) {
65839 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
65840@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65841 end = start + len;
65842 if (end <= start)
65843 return -ENOMEM;
65844+
65845+#ifdef CONFIG_PAX_SEGMEXEC
65846+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
65847+ if (end > SEGMEXEC_TASK_SIZE)
65848+ return -EINVAL;
65849+ } else
65850+#endif
65851+
65852+ if (end > TASK_SIZE)
65853+ return -EINVAL;
65854+
65855 if (!arch_validate_prot(prot))
65856 return -EINVAL;
65857
65858@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65859 /*
65860 * Does the application expect PROT_READ to imply PROT_EXEC:
65861 */
65862- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
65863+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
65864 prot |= PROT_EXEC;
65865
65866 vm_flags = calc_vm_prot_bits(prot);
65867@@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65868 if (start > vma->vm_start)
65869 prev = vma;
65870
65871+#ifdef CONFIG_PAX_MPROTECT
65872+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
65873+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
65874+#endif
65875+
65876 for (nstart = start ; ; ) {
65877 unsigned long newflags;
65878
65879@@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65880
65881 /* newflags >> 4 shift VM_MAY% in place of VM_% */
65882 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
65883+ if (prot & (PROT_WRITE | PROT_EXEC))
65884+ gr_log_rwxmprotect(vma->vm_file);
65885+
65886+ error = -EACCES;
65887+ goto out;
65888+ }
65889+
65890+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
65891 error = -EACCES;
65892 goto out;
65893 }
65894@@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65895 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
65896 if (error)
65897 goto out;
65898+
65899+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
65900+
65901 nstart = tmp;
65902
65903 if (nstart < prev->vm_end)
65904diff -urNp linux-3.0.4/mm/mremap.c linux-3.0.4/mm/mremap.c
65905--- linux-3.0.4/mm/mremap.c 2011-07-21 22:17:23.000000000 -0400
65906+++ linux-3.0.4/mm/mremap.c 2011-08-23 21:47:56.000000000 -0400
65907@@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_str
65908 continue;
65909 pte = ptep_clear_flush(vma, old_addr, old_pte);
65910 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
65911+
65912+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65913+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
65914+ pte = pte_exprotect(pte);
65915+#endif
65916+
65917 set_pte_at(mm, new_addr, new_pte, pte);
65918 }
65919
65920@@ -272,6 +278,11 @@ static struct vm_area_struct *vma_to_res
65921 if (is_vm_hugetlb_page(vma))
65922 goto Einval;
65923
65924+#ifdef CONFIG_PAX_SEGMEXEC
65925+ if (pax_find_mirror_vma(vma))
65926+ goto Einval;
65927+#endif
65928+
65929 /* We can't remap across vm area boundaries */
65930 if (old_len > vma->vm_end - addr)
65931 goto Efault;
65932@@ -328,20 +339,25 @@ static unsigned long mremap_to(unsigned
65933 unsigned long ret = -EINVAL;
65934 unsigned long charged = 0;
65935 unsigned long map_flags;
65936+ unsigned long pax_task_size = TASK_SIZE;
65937
65938 if (new_addr & ~PAGE_MASK)
65939 goto out;
65940
65941- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
65942+#ifdef CONFIG_PAX_SEGMEXEC
65943+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
65944+ pax_task_size = SEGMEXEC_TASK_SIZE;
65945+#endif
65946+
65947+ pax_task_size -= PAGE_SIZE;
65948+
65949+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
65950 goto out;
65951
65952 /* Check if the location we're moving into overlaps the
65953 * old location at all, and fail if it does.
65954 */
65955- if ((new_addr <= addr) && (new_addr+new_len) > addr)
65956- goto out;
65957-
65958- if ((addr <= new_addr) && (addr+old_len) > new_addr)
65959+ if (addr + old_len > new_addr && new_addr + new_len > addr)
65960 goto out;
65961
65962 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
65963@@ -413,6 +429,7 @@ unsigned long do_mremap(unsigned long ad
65964 struct vm_area_struct *vma;
65965 unsigned long ret = -EINVAL;
65966 unsigned long charged = 0;
65967+ unsigned long pax_task_size = TASK_SIZE;
65968
65969 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
65970 goto out;
65971@@ -431,6 +448,17 @@ unsigned long do_mremap(unsigned long ad
65972 if (!new_len)
65973 goto out;
65974
65975+#ifdef CONFIG_PAX_SEGMEXEC
65976+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
65977+ pax_task_size = SEGMEXEC_TASK_SIZE;
65978+#endif
65979+
65980+ pax_task_size -= PAGE_SIZE;
65981+
65982+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
65983+ old_len > pax_task_size || addr > pax_task_size-old_len)
65984+ goto out;
65985+
65986 if (flags & MREMAP_FIXED) {
65987 if (flags & MREMAP_MAYMOVE)
65988 ret = mremap_to(addr, old_len, new_addr, new_len);
65989@@ -480,6 +508,7 @@ unsigned long do_mremap(unsigned long ad
65990 addr + new_len);
65991 }
65992 ret = addr;
65993+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
65994 goto out;
65995 }
65996 }
65997@@ -506,7 +535,13 @@ unsigned long do_mremap(unsigned long ad
65998 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
65999 if (ret)
66000 goto out;
66001+
66002+ map_flags = vma->vm_flags;
66003 ret = move_vma(vma, addr, old_len, new_len, new_addr);
66004+ if (!(ret & ~PAGE_MASK)) {
66005+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
66006+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
66007+ }
66008 }
66009 out:
66010 if (ret & ~PAGE_MASK)
66011diff -urNp linux-3.0.4/mm/nobootmem.c linux-3.0.4/mm/nobootmem.c
66012--- linux-3.0.4/mm/nobootmem.c 2011-07-21 22:17:23.000000000 -0400
66013+++ linux-3.0.4/mm/nobootmem.c 2011-08-23 21:47:56.000000000 -0400
66014@@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
66015 unsigned long __init free_all_memory_core_early(int nodeid)
66016 {
66017 int i;
66018- u64 start, end;
66019+ u64 start, end, startrange, endrange;
66020 unsigned long count = 0;
66021- struct range *range = NULL;
66022+ struct range *range = NULL, rangerange = { 0, 0 };
66023 int nr_range;
66024
66025 nr_range = get_free_all_memory_range(&range, nodeid);
66026+ startrange = __pa(range) >> PAGE_SHIFT;
66027+ endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
66028
66029 for (i = 0; i < nr_range; i++) {
66030 start = range[i].start;
66031 end = range[i].end;
66032+ if (start <= endrange && startrange < end) {
66033+ BUG_ON(rangerange.start | rangerange.end);
66034+ rangerange = range[i];
66035+ continue;
66036+ }
66037 count += end - start;
66038 __free_pages_memory(start, end);
66039 }
66040+ start = rangerange.start;
66041+ end = rangerange.end;
66042+ count += end - start;
66043+ __free_pages_memory(start, end);
66044
66045 return count;
66046 }
66047diff -urNp linux-3.0.4/mm/nommu.c linux-3.0.4/mm/nommu.c
66048--- linux-3.0.4/mm/nommu.c 2011-07-21 22:17:23.000000000 -0400
66049+++ linux-3.0.4/mm/nommu.c 2011-08-23 21:47:56.000000000 -0400
66050@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
66051 int sysctl_overcommit_ratio = 50; /* default is 50% */
66052 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
66053 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
66054-int heap_stack_gap = 0;
66055
66056 atomic_long_t mmap_pages_allocated;
66057
66058@@ -826,15 +825,6 @@ struct vm_area_struct *find_vma(struct m
66059 EXPORT_SYMBOL(find_vma);
66060
66061 /*
66062- * find a VMA
66063- * - we don't extend stack VMAs under NOMMU conditions
66064- */
66065-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
66066-{
66067- return find_vma(mm, addr);
66068-}
66069-
66070-/*
66071 * expand a stack to a given address
66072 * - not supported under NOMMU conditions
66073 */
66074@@ -1554,6 +1544,7 @@ int split_vma(struct mm_struct *mm, stru
66075
66076 /* most fields are the same, copy all, and then fixup */
66077 *new = *vma;
66078+ INIT_LIST_HEAD(&new->anon_vma_chain);
66079 *region = *vma->vm_region;
66080 new->vm_region = region;
66081
66082diff -urNp linux-3.0.4/mm/page_alloc.c linux-3.0.4/mm/page_alloc.c
66083--- linux-3.0.4/mm/page_alloc.c 2011-07-21 22:17:23.000000000 -0400
66084+++ linux-3.0.4/mm/page_alloc.c 2011-08-23 21:48:14.000000000 -0400
66085@@ -340,7 +340,7 @@ out:
66086 * This usage means that zero-order pages may not be compound.
66087 */
66088
66089-static void free_compound_page(struct page *page)
66090+void free_compound_page(struct page *page)
66091 {
66092 __free_pages_ok(page, compound_order(page));
66093 }
66094@@ -653,6 +653,10 @@ static bool free_pages_prepare(struct pa
66095 int i;
66096 int bad = 0;
66097
66098+#ifdef CONFIG_PAX_MEMORY_SANITIZE
66099+ unsigned long index = 1UL << order;
66100+#endif
66101+
66102 trace_mm_page_free_direct(page, order);
66103 kmemcheck_free_shadow(page, order);
66104
66105@@ -668,6 +672,12 @@ static bool free_pages_prepare(struct pa
66106 debug_check_no_obj_freed(page_address(page),
66107 PAGE_SIZE << order);
66108 }
66109+
66110+#ifdef CONFIG_PAX_MEMORY_SANITIZE
66111+ for (; index; --index)
66112+ sanitize_highpage(page + index - 1);
66113+#endif
66114+
66115 arch_free_page(page, order);
66116 kernel_map_pages(page, 1 << order, 0);
66117
66118@@ -783,8 +793,10 @@ static int prep_new_page(struct page *pa
66119 arch_alloc_page(page, order);
66120 kernel_map_pages(page, 1 << order, 1);
66121
66122+#ifndef CONFIG_PAX_MEMORY_SANITIZE
66123 if (gfp_flags & __GFP_ZERO)
66124 prep_zero_page(page, order, gfp_flags);
66125+#endif
66126
66127 if (order && (gfp_flags & __GFP_COMP))
66128 prep_compound_page(page, order);
66129@@ -2525,6 +2537,8 @@ void show_free_areas(unsigned int filter
66130 int cpu;
66131 struct zone *zone;
66132
66133+ pax_track_stack();
66134+
66135 for_each_populated_zone(zone) {
66136 if (skip_free_areas_node(filter, zone_to_nid(zone)))
66137 continue;
66138diff -urNp linux-3.0.4/mm/percpu.c linux-3.0.4/mm/percpu.c
66139--- linux-3.0.4/mm/percpu.c 2011-07-21 22:17:23.000000000 -0400
66140+++ linux-3.0.4/mm/percpu.c 2011-08-23 21:47:56.000000000 -0400
66141@@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
66142 static unsigned int pcpu_last_unit_cpu __read_mostly;
66143
66144 /* the address of the first chunk which starts with the kernel static area */
66145-void *pcpu_base_addr __read_mostly;
66146+void *pcpu_base_addr __read_only;
66147 EXPORT_SYMBOL_GPL(pcpu_base_addr);
66148
66149 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
66150diff -urNp linux-3.0.4/mm/rmap.c linux-3.0.4/mm/rmap.c
66151--- linux-3.0.4/mm/rmap.c 2011-07-21 22:17:23.000000000 -0400
66152+++ linux-3.0.4/mm/rmap.c 2011-08-23 21:47:56.000000000 -0400
66153@@ -153,6 +153,10 @@ int anon_vma_prepare(struct vm_area_stru
66154 struct anon_vma *anon_vma = vma->anon_vma;
66155 struct anon_vma_chain *avc;
66156
66157+#ifdef CONFIG_PAX_SEGMEXEC
66158+ struct anon_vma_chain *avc_m = NULL;
66159+#endif
66160+
66161 might_sleep();
66162 if (unlikely(!anon_vma)) {
66163 struct mm_struct *mm = vma->vm_mm;
66164@@ -162,6 +166,12 @@ int anon_vma_prepare(struct vm_area_stru
66165 if (!avc)
66166 goto out_enomem;
66167
66168+#ifdef CONFIG_PAX_SEGMEXEC
66169+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
66170+ if (!avc_m)
66171+ goto out_enomem_free_avc;
66172+#endif
66173+
66174 anon_vma = find_mergeable_anon_vma(vma);
66175 allocated = NULL;
66176 if (!anon_vma) {
66177@@ -175,6 +185,21 @@ int anon_vma_prepare(struct vm_area_stru
66178 /* page_table_lock to protect against threads */
66179 spin_lock(&mm->page_table_lock);
66180 if (likely(!vma->anon_vma)) {
66181+
66182+#ifdef CONFIG_PAX_SEGMEXEC
66183+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
66184+
66185+ if (vma_m) {
66186+ BUG_ON(vma_m->anon_vma);
66187+ vma_m->anon_vma = anon_vma;
66188+ avc_m->anon_vma = anon_vma;
66189+ avc_m->vma = vma;
66190+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
66191+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
66192+ avc_m = NULL;
66193+ }
66194+#endif
66195+
66196 vma->anon_vma = anon_vma;
66197 avc->anon_vma = anon_vma;
66198 avc->vma = vma;
66199@@ -188,12 +213,24 @@ int anon_vma_prepare(struct vm_area_stru
66200
66201 if (unlikely(allocated))
66202 put_anon_vma(allocated);
66203+
66204+#ifdef CONFIG_PAX_SEGMEXEC
66205+ if (unlikely(avc_m))
66206+ anon_vma_chain_free(avc_m);
66207+#endif
66208+
66209 if (unlikely(avc))
66210 anon_vma_chain_free(avc);
66211 }
66212 return 0;
66213
66214 out_enomem_free_avc:
66215+
66216+#ifdef CONFIG_PAX_SEGMEXEC
66217+ if (avc_m)
66218+ anon_vma_chain_free(avc_m);
66219+#endif
66220+
66221 anon_vma_chain_free(avc);
66222 out_enomem:
66223 return -ENOMEM;
66224@@ -244,7 +281,7 @@ static void anon_vma_chain_link(struct v
66225 * Attach the anon_vmas from src to dst.
66226 * Returns 0 on success, -ENOMEM on failure.
66227 */
66228-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
66229+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
66230 {
66231 struct anon_vma_chain *avc, *pavc;
66232 struct anon_vma *root = NULL;
66233@@ -277,7 +314,7 @@ int anon_vma_clone(struct vm_area_struct
66234 * the corresponding VMA in the parent process is attached to.
66235 * Returns 0 on success, non-zero on failure.
66236 */
66237-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
66238+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
66239 {
66240 struct anon_vma_chain *avc;
66241 struct anon_vma *anon_vma;
66242diff -urNp linux-3.0.4/mm/shmem.c linux-3.0.4/mm/shmem.c
66243--- linux-3.0.4/mm/shmem.c 2011-07-21 22:17:23.000000000 -0400
66244+++ linux-3.0.4/mm/shmem.c 2011-08-23 21:48:14.000000000 -0400
66245@@ -31,7 +31,7 @@
66246 #include <linux/percpu_counter.h>
66247 #include <linux/swap.h>
66248
66249-static struct vfsmount *shm_mnt;
66250+struct vfsmount *shm_mnt;
66251
66252 #ifdef CONFIG_SHMEM
66253 /*
66254@@ -1101,6 +1101,8 @@ static int shmem_writepage(struct page *
66255 goto unlock;
66256 }
66257 entry = shmem_swp_entry(info, index, NULL);
66258+ if (!entry)
66259+ goto unlock;
66260 if (entry->val) {
66261 /*
66262 * The more uptodate page coming down from a stacked
66263@@ -1172,6 +1174,8 @@ static struct page *shmem_swapin(swp_ent
66264 struct vm_area_struct pvma;
66265 struct page *page;
66266
66267+ pax_track_stack();
66268+
66269 spol = mpol_cond_copy(&mpol,
66270 mpol_shared_policy_lookup(&info->policy, idx));
66271
66272@@ -2568,8 +2572,7 @@ int shmem_fill_super(struct super_block
66273 int err = -ENOMEM;
66274
66275 /* Round up to L1_CACHE_BYTES to resist false sharing */
66276- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
66277- L1_CACHE_BYTES), GFP_KERNEL);
66278+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
66279 if (!sbinfo)
66280 return -ENOMEM;
66281
66282diff -urNp linux-3.0.4/mm/slab.c linux-3.0.4/mm/slab.c
66283--- linux-3.0.4/mm/slab.c 2011-07-21 22:17:23.000000000 -0400
66284+++ linux-3.0.4/mm/slab.c 2011-08-23 21:48:14.000000000 -0400
66285@@ -151,7 +151,7 @@
66286
66287 /* Legal flag mask for kmem_cache_create(). */
66288 #if DEBUG
66289-# define CREATE_MASK (SLAB_RED_ZONE | \
66290+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
66291 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
66292 SLAB_CACHE_DMA | \
66293 SLAB_STORE_USER | \
66294@@ -159,7 +159,7 @@
66295 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
66296 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
66297 #else
66298-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
66299+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
66300 SLAB_CACHE_DMA | \
66301 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
66302 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
66303@@ -288,7 +288,7 @@ struct kmem_list3 {
66304 * Need this for bootstrapping a per node allocator.
66305 */
66306 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
66307-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
66308+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
66309 #define CACHE_CACHE 0
66310 #define SIZE_AC MAX_NUMNODES
66311 #define SIZE_L3 (2 * MAX_NUMNODES)
66312@@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_
66313 if ((x)->max_freeable < i) \
66314 (x)->max_freeable = i; \
66315 } while (0)
66316-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
66317-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
66318-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
66319-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
66320+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
66321+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
66322+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
66323+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
66324 #else
66325 #define STATS_INC_ACTIVE(x) do { } while (0)
66326 #define STATS_DEC_ACTIVE(x) do { } while (0)
66327@@ -538,7 +538,7 @@ static inline void *index_to_obj(struct
66328 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
66329 */
66330 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
66331- const struct slab *slab, void *obj)
66332+ const struct slab *slab, const void *obj)
66333 {
66334 u32 offset = (obj - slab->s_mem);
66335 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
66336@@ -564,7 +564,7 @@ struct cache_names {
66337 static struct cache_names __initdata cache_names[] = {
66338 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
66339 #include <linux/kmalloc_sizes.h>
66340- {NULL,}
66341+ {NULL}
66342 #undef CACHE
66343 };
66344
66345@@ -1530,7 +1530,7 @@ void __init kmem_cache_init(void)
66346 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
66347 sizes[INDEX_AC].cs_size,
66348 ARCH_KMALLOC_MINALIGN,
66349- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
66350+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
66351 NULL);
66352
66353 if (INDEX_AC != INDEX_L3) {
66354@@ -1538,7 +1538,7 @@ void __init kmem_cache_init(void)
66355 kmem_cache_create(names[INDEX_L3].name,
66356 sizes[INDEX_L3].cs_size,
66357 ARCH_KMALLOC_MINALIGN,
66358- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
66359+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
66360 NULL);
66361 }
66362
66363@@ -1556,7 +1556,7 @@ void __init kmem_cache_init(void)
66364 sizes->cs_cachep = kmem_cache_create(names->name,
66365 sizes->cs_size,
66366 ARCH_KMALLOC_MINALIGN,
66367- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
66368+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
66369 NULL);
66370 }
66371 #ifdef CONFIG_ZONE_DMA
66372@@ -4272,10 +4272,10 @@ static int s_show(struct seq_file *m, vo
66373 }
66374 /* cpu stats */
66375 {
66376- unsigned long allochit = atomic_read(&cachep->allochit);
66377- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
66378- unsigned long freehit = atomic_read(&cachep->freehit);
66379- unsigned long freemiss = atomic_read(&cachep->freemiss);
66380+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
66381+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
66382+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
66383+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
66384
66385 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
66386 allochit, allocmiss, freehit, freemiss);
66387@@ -4532,15 +4532,66 @@ static const struct file_operations proc
66388
66389 static int __init slab_proc_init(void)
66390 {
66391- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
66392+ mode_t gr_mode = S_IRUGO;
66393+
66394+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66395+ gr_mode = S_IRUSR;
66396+#endif
66397+
66398+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
66399 #ifdef CONFIG_DEBUG_SLAB_LEAK
66400- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
66401+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
66402 #endif
66403 return 0;
66404 }
66405 module_init(slab_proc_init);
66406 #endif
66407
66408+void check_object_size(const void *ptr, unsigned long n, bool to)
66409+{
66410+
66411+#ifdef CONFIG_PAX_USERCOPY
66412+ struct page *page;
66413+ struct kmem_cache *cachep = NULL;
66414+ struct slab *slabp;
66415+ unsigned int objnr;
66416+ unsigned long offset;
66417+
66418+ if (!n)
66419+ return;
66420+
66421+ if (ZERO_OR_NULL_PTR(ptr))
66422+ goto report;
66423+
66424+ if (!virt_addr_valid(ptr))
66425+ return;
66426+
66427+ page = virt_to_head_page(ptr);
66428+
66429+ if (!PageSlab(page)) {
66430+ if (object_is_on_stack(ptr, n) == -1)
66431+ goto report;
66432+ return;
66433+ }
66434+
66435+ cachep = page_get_cache(page);
66436+ if (!(cachep->flags & SLAB_USERCOPY))
66437+ goto report;
66438+
66439+ slabp = page_get_slab(page);
66440+ objnr = obj_to_index(cachep, slabp, ptr);
66441+ BUG_ON(objnr >= cachep->num);
66442+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
66443+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
66444+ return;
66445+
66446+report:
66447+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
66448+#endif
66449+
66450+}
66451+EXPORT_SYMBOL(check_object_size);
66452+
66453 /**
66454 * ksize - get the actual amount of memory allocated for a given object
66455 * @objp: Pointer to the object
66456diff -urNp linux-3.0.4/mm/slob.c linux-3.0.4/mm/slob.c
66457--- linux-3.0.4/mm/slob.c 2011-07-21 22:17:23.000000000 -0400
66458+++ linux-3.0.4/mm/slob.c 2011-08-23 21:47:56.000000000 -0400
66459@@ -29,7 +29,7 @@
66460 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
66461 * alloc_pages() directly, allocating compound pages so the page order
66462 * does not have to be separately tracked, and also stores the exact
66463- * allocation size in page->private so that it can be used to accurately
66464+ * allocation size in slob_page->size so that it can be used to accurately
66465 * provide ksize(). These objects are detected in kfree() because slob_page()
66466 * is false for them.
66467 *
66468@@ -58,6 +58,7 @@
66469 */
66470
66471 #include <linux/kernel.h>
66472+#include <linux/sched.h>
66473 #include <linux/slab.h>
66474 #include <linux/mm.h>
66475 #include <linux/swap.h> /* struct reclaim_state */
66476@@ -102,7 +103,8 @@ struct slob_page {
66477 unsigned long flags; /* mandatory */
66478 atomic_t _count; /* mandatory */
66479 slobidx_t units; /* free units left in page */
66480- unsigned long pad[2];
66481+ unsigned long pad[1];
66482+ unsigned long size; /* size when >=PAGE_SIZE */
66483 slob_t *free; /* first free slob_t in page */
66484 struct list_head list; /* linked list of free pages */
66485 };
66486@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
66487 */
66488 static inline int is_slob_page(struct slob_page *sp)
66489 {
66490- return PageSlab((struct page *)sp);
66491+ return PageSlab((struct page *)sp) && !sp->size;
66492 }
66493
66494 static inline void set_slob_page(struct slob_page *sp)
66495@@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
66496
66497 static inline struct slob_page *slob_page(const void *addr)
66498 {
66499- return (struct slob_page *)virt_to_page(addr);
66500+ return (struct slob_page *)virt_to_head_page(addr);
66501 }
66502
66503 /*
66504@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
66505 /*
66506 * Return the size of a slob block.
66507 */
66508-static slobidx_t slob_units(slob_t *s)
66509+static slobidx_t slob_units(const slob_t *s)
66510 {
66511 if (s->units > 0)
66512 return s->units;
66513@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
66514 /*
66515 * Return the next free slob block pointer after this one.
66516 */
66517-static slob_t *slob_next(slob_t *s)
66518+static slob_t *slob_next(const slob_t *s)
66519 {
66520 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
66521 slobidx_t next;
66522@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
66523 /*
66524 * Returns true if s is the last free block in its page.
66525 */
66526-static int slob_last(slob_t *s)
66527+static int slob_last(const slob_t *s)
66528 {
66529 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
66530 }
66531@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
66532 if (!page)
66533 return NULL;
66534
66535+ set_slob_page(page);
66536 return page_address(page);
66537 }
66538
66539@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
66540 if (!b)
66541 return NULL;
66542 sp = slob_page(b);
66543- set_slob_page(sp);
66544
66545 spin_lock_irqsave(&slob_lock, flags);
66546 sp->units = SLOB_UNITS(PAGE_SIZE);
66547 sp->free = b;
66548+ sp->size = 0;
66549 INIT_LIST_HEAD(&sp->list);
66550 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
66551 set_slob_page_free(sp, slob_list);
66552@@ -476,10 +479,9 @@ out:
66553 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
66554 */
66555
66556-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
66557+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
66558 {
66559- unsigned int *m;
66560- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66561+ slob_t *m;
66562 void *ret;
66563
66564 lockdep_trace_alloc(gfp);
66565@@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
66566
66567 if (!m)
66568 return NULL;
66569- *m = size;
66570+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
66571+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
66572+ m[0].units = size;
66573+ m[1].units = align;
66574 ret = (void *)m + align;
66575
66576 trace_kmalloc_node(_RET_IP_, ret,
66577@@ -504,16 +509,25 @@ void *__kmalloc_node(size_t size, gfp_t
66578 gfp |= __GFP_COMP;
66579 ret = slob_new_pages(gfp, order, node);
66580 if (ret) {
66581- struct page *page;
66582- page = virt_to_page(ret);
66583- page->private = size;
66584+ struct slob_page *sp;
66585+ sp = slob_page(ret);
66586+ sp->size = size;
66587 }
66588
66589 trace_kmalloc_node(_RET_IP_, ret,
66590 size, PAGE_SIZE << order, gfp, node);
66591 }
66592
66593- kmemleak_alloc(ret, size, 1, gfp);
66594+ return ret;
66595+}
66596+
66597+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
66598+{
66599+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66600+ void *ret = __kmalloc_node_align(size, gfp, node, align);
66601+
66602+ if (!ZERO_OR_NULL_PTR(ret))
66603+ kmemleak_alloc(ret, size, 1, gfp);
66604 return ret;
66605 }
66606 EXPORT_SYMBOL(__kmalloc_node);
66607@@ -531,13 +545,88 @@ void kfree(const void *block)
66608 sp = slob_page(block);
66609 if (is_slob_page(sp)) {
66610 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66611- unsigned int *m = (unsigned int *)(block - align);
66612- slob_free(m, *m + align);
66613- } else
66614+ slob_t *m = (slob_t *)(block - align);
66615+ slob_free(m, m[0].units + align);
66616+ } else {
66617+ clear_slob_page(sp);
66618+ free_slob_page(sp);
66619+ sp->size = 0;
66620 put_page(&sp->page);
66621+ }
66622 }
66623 EXPORT_SYMBOL(kfree);
66624
66625+void check_object_size(const void *ptr, unsigned long n, bool to)
66626+{
66627+
66628+#ifdef CONFIG_PAX_USERCOPY
66629+ struct slob_page *sp;
66630+ const slob_t *free;
66631+ const void *base;
66632+ unsigned long flags;
66633+
66634+ if (!n)
66635+ return;
66636+
66637+ if (ZERO_OR_NULL_PTR(ptr))
66638+ goto report;
66639+
66640+ if (!virt_addr_valid(ptr))
66641+ return;
66642+
66643+ sp = slob_page(ptr);
66644+ if (!PageSlab((struct page*)sp)) {
66645+ if (object_is_on_stack(ptr, n) == -1)
66646+ goto report;
66647+ return;
66648+ }
66649+
66650+ if (sp->size) {
66651+ base = page_address(&sp->page);
66652+ if (base <= ptr && n <= sp->size - (ptr - base))
66653+ return;
66654+ goto report;
66655+ }
66656+
66657+ /* some tricky double walking to find the chunk */
66658+ spin_lock_irqsave(&slob_lock, flags);
66659+ base = (void *)((unsigned long)ptr & PAGE_MASK);
66660+ free = sp->free;
66661+
66662+ while (!slob_last(free) && (void *)free <= ptr) {
66663+ base = free + slob_units(free);
66664+ free = slob_next(free);
66665+ }
66666+
66667+ while (base < (void *)free) {
66668+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
66669+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
66670+ int offset;
66671+
66672+ if (ptr < base + align)
66673+ break;
66674+
66675+ offset = ptr - base - align;
66676+ if (offset >= m) {
66677+ base += size;
66678+ continue;
66679+ }
66680+
66681+ if (n > m - offset)
66682+ break;
66683+
66684+ spin_unlock_irqrestore(&slob_lock, flags);
66685+ return;
66686+ }
66687+
66688+ spin_unlock_irqrestore(&slob_lock, flags);
66689+report:
66690+ pax_report_usercopy(ptr, n, to, NULL);
66691+#endif
66692+
66693+}
66694+EXPORT_SYMBOL(check_object_size);
66695+
66696 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
66697 size_t ksize(const void *block)
66698 {
66699@@ -550,10 +639,10 @@ size_t ksize(const void *block)
66700 sp = slob_page(block);
66701 if (is_slob_page(sp)) {
66702 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66703- unsigned int *m = (unsigned int *)(block - align);
66704- return SLOB_UNITS(*m) * SLOB_UNIT;
66705+ slob_t *m = (slob_t *)(block - align);
66706+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
66707 } else
66708- return sp->page.private;
66709+ return sp->size;
66710 }
66711 EXPORT_SYMBOL(ksize);
66712
66713@@ -569,8 +658,13 @@ struct kmem_cache *kmem_cache_create(con
66714 {
66715 struct kmem_cache *c;
66716
66717+#ifdef CONFIG_PAX_USERCOPY
66718+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
66719+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
66720+#else
66721 c = slob_alloc(sizeof(struct kmem_cache),
66722 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
66723+#endif
66724
66725 if (c) {
66726 c->name = name;
66727@@ -608,17 +702,25 @@ void *kmem_cache_alloc_node(struct kmem_
66728 {
66729 void *b;
66730
66731+#ifdef CONFIG_PAX_USERCOPY
66732+ b = __kmalloc_node_align(c->size, flags, node, c->align);
66733+#else
66734 if (c->size < PAGE_SIZE) {
66735 b = slob_alloc(c->size, flags, c->align, node);
66736 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
66737 SLOB_UNITS(c->size) * SLOB_UNIT,
66738 flags, node);
66739 } else {
66740+ struct slob_page *sp;
66741+
66742 b = slob_new_pages(flags, get_order(c->size), node);
66743+ sp = slob_page(b);
66744+ sp->size = c->size;
66745 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
66746 PAGE_SIZE << get_order(c->size),
66747 flags, node);
66748 }
66749+#endif
66750
66751 if (c->ctor)
66752 c->ctor(b);
66753@@ -630,10 +732,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
66754
66755 static void __kmem_cache_free(void *b, int size)
66756 {
66757- if (size < PAGE_SIZE)
66758+ struct slob_page *sp = slob_page(b);
66759+
66760+ if (is_slob_page(sp))
66761 slob_free(b, size);
66762- else
66763+ else {
66764+ clear_slob_page(sp);
66765+ free_slob_page(sp);
66766+ sp->size = 0;
66767 slob_free_pages(b, get_order(size));
66768+ }
66769 }
66770
66771 static void kmem_rcu_free(struct rcu_head *head)
66772@@ -646,17 +754,31 @@ static void kmem_rcu_free(struct rcu_hea
66773
66774 void kmem_cache_free(struct kmem_cache *c, void *b)
66775 {
66776+ int size = c->size;
66777+
66778+#ifdef CONFIG_PAX_USERCOPY
66779+ if (size + c->align < PAGE_SIZE) {
66780+ size += c->align;
66781+ b -= c->align;
66782+ }
66783+#endif
66784+
66785 kmemleak_free_recursive(b, c->flags);
66786 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
66787 struct slob_rcu *slob_rcu;
66788- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
66789- slob_rcu->size = c->size;
66790+ slob_rcu = b + (size - sizeof(struct slob_rcu));
66791+ slob_rcu->size = size;
66792 call_rcu(&slob_rcu->head, kmem_rcu_free);
66793 } else {
66794- __kmem_cache_free(b, c->size);
66795+ __kmem_cache_free(b, size);
66796 }
66797
66798+#ifdef CONFIG_PAX_USERCOPY
66799+ trace_kfree(_RET_IP_, b);
66800+#else
66801 trace_kmem_cache_free(_RET_IP_, b);
66802+#endif
66803+
66804 }
66805 EXPORT_SYMBOL(kmem_cache_free);
66806
66807diff -urNp linux-3.0.4/mm/slub.c linux-3.0.4/mm/slub.c
66808--- linux-3.0.4/mm/slub.c 2011-07-21 22:17:23.000000000 -0400
66809+++ linux-3.0.4/mm/slub.c 2011-08-23 21:48:14.000000000 -0400
66810@@ -442,7 +442,7 @@ static void print_track(const char *s, s
66811 if (!t->addr)
66812 return;
66813
66814- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
66815+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
66816 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
66817 }
66818
66819@@ -2137,6 +2137,8 @@ void kmem_cache_free(struct kmem_cache *
66820
66821 page = virt_to_head_page(x);
66822
66823+ BUG_ON(!PageSlab(page));
66824+
66825 slab_free(s, page, x, _RET_IP_);
66826
66827 trace_kmem_cache_free(_RET_IP_, x);
66828@@ -2170,7 +2172,7 @@ static int slub_min_objects;
66829 * Merge control. If this is set then no merging of slab caches will occur.
66830 * (Could be removed. This was introduced to pacify the merge skeptics.)
66831 */
66832-static int slub_nomerge;
66833+static int slub_nomerge = 1;
66834
66835 /*
66836 * Calculate the order of allocation given an slab object size.
66837@@ -2594,7 +2596,7 @@ static int kmem_cache_open(struct kmem_c
66838 * list to avoid pounding the page allocator excessively.
66839 */
66840 set_min_partial(s, ilog2(s->size));
66841- s->refcount = 1;
66842+ atomic_set(&s->refcount, 1);
66843 #ifdef CONFIG_NUMA
66844 s->remote_node_defrag_ratio = 1000;
66845 #endif
66846@@ -2699,8 +2701,7 @@ static inline int kmem_cache_close(struc
66847 void kmem_cache_destroy(struct kmem_cache *s)
66848 {
66849 down_write(&slub_lock);
66850- s->refcount--;
66851- if (!s->refcount) {
66852+ if (atomic_dec_and_test(&s->refcount)) {
66853 list_del(&s->list);
66854 if (kmem_cache_close(s)) {
66855 printk(KERN_ERR "SLUB %s: %s called for cache that "
66856@@ -2910,6 +2911,46 @@ void *__kmalloc_node(size_t size, gfp_t
66857 EXPORT_SYMBOL(__kmalloc_node);
66858 #endif
66859
66860+void check_object_size(const void *ptr, unsigned long n, bool to)
66861+{
66862+
66863+#ifdef CONFIG_PAX_USERCOPY
66864+ struct page *page;
66865+ struct kmem_cache *s = NULL;
66866+ unsigned long offset;
66867+
66868+ if (!n)
66869+ return;
66870+
66871+ if (ZERO_OR_NULL_PTR(ptr))
66872+ goto report;
66873+
66874+ if (!virt_addr_valid(ptr))
66875+ return;
66876+
66877+ page = virt_to_head_page(ptr);
66878+
66879+ if (!PageSlab(page)) {
66880+ if (object_is_on_stack(ptr, n) == -1)
66881+ goto report;
66882+ return;
66883+ }
66884+
66885+ s = page->slab;
66886+ if (!(s->flags & SLAB_USERCOPY))
66887+ goto report;
66888+
66889+ offset = (ptr - page_address(page)) % s->size;
66890+ if (offset <= s->objsize && n <= s->objsize - offset)
66891+ return;
66892+
66893+report:
66894+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
66895+#endif
66896+
66897+}
66898+EXPORT_SYMBOL(check_object_size);
66899+
66900 size_t ksize(const void *object)
66901 {
66902 struct page *page;
66903@@ -3154,7 +3195,7 @@ static void __init kmem_cache_bootstrap_
66904 int node;
66905
66906 list_add(&s->list, &slab_caches);
66907- s->refcount = -1;
66908+ atomic_set(&s->refcount, -1);
66909
66910 for_each_node_state(node, N_NORMAL_MEMORY) {
66911 struct kmem_cache_node *n = get_node(s, node);
66912@@ -3271,17 +3312,17 @@ void __init kmem_cache_init(void)
66913
66914 /* Caches that are not of the two-to-the-power-of size */
66915 if (KMALLOC_MIN_SIZE <= 32) {
66916- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
66917+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
66918 caches++;
66919 }
66920
66921 if (KMALLOC_MIN_SIZE <= 64) {
66922- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
66923+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
66924 caches++;
66925 }
66926
66927 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
66928- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
66929+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
66930 caches++;
66931 }
66932
66933@@ -3349,7 +3390,7 @@ static int slab_unmergeable(struct kmem_
66934 /*
66935 * We may have set a slab to be unmergeable during bootstrap.
66936 */
66937- if (s->refcount < 0)
66938+ if (atomic_read(&s->refcount) < 0)
66939 return 1;
66940
66941 return 0;
66942@@ -3408,7 +3449,7 @@ struct kmem_cache *kmem_cache_create(con
66943 down_write(&slub_lock);
66944 s = find_mergeable(size, align, flags, name, ctor);
66945 if (s) {
66946- s->refcount++;
66947+ atomic_inc(&s->refcount);
66948 /*
66949 * Adjust the object sizes so that we clear
66950 * the complete object on kzalloc.
66951@@ -3417,7 +3458,7 @@ struct kmem_cache *kmem_cache_create(con
66952 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
66953
66954 if (sysfs_slab_alias(s, name)) {
66955- s->refcount--;
66956+ atomic_dec(&s->refcount);
66957 goto err;
66958 }
66959 up_write(&slub_lock);
66960@@ -4150,7 +4191,7 @@ SLAB_ATTR_RO(ctor);
66961
66962 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
66963 {
66964- return sprintf(buf, "%d\n", s->refcount - 1);
66965+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
66966 }
66967 SLAB_ATTR_RO(aliases);
66968
66969@@ -4894,7 +4935,13 @@ static const struct file_operations proc
66970
66971 static int __init slab_proc_init(void)
66972 {
66973- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
66974+ mode_t gr_mode = S_IRUGO;
66975+
66976+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66977+ gr_mode = S_IRUSR;
66978+#endif
66979+
66980+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
66981 return 0;
66982 }
66983 module_init(slab_proc_init);
66984diff -urNp linux-3.0.4/mm/swap.c linux-3.0.4/mm/swap.c
66985--- linux-3.0.4/mm/swap.c 2011-07-21 22:17:23.000000000 -0400
66986+++ linux-3.0.4/mm/swap.c 2011-08-23 21:47:56.000000000 -0400
66987@@ -31,6 +31,7 @@
66988 #include <linux/backing-dev.h>
66989 #include <linux/memcontrol.h>
66990 #include <linux/gfp.h>
66991+#include <linux/hugetlb.h>
66992
66993 #include "internal.h"
66994
66995@@ -71,6 +72,8 @@ static void __put_compound_page(struct p
66996
66997 __page_cache_release(page);
66998 dtor = get_compound_page_dtor(page);
66999+ if (!PageHuge(page))
67000+ BUG_ON(dtor != free_compound_page);
67001 (*dtor)(page);
67002 }
67003
67004diff -urNp linux-3.0.4/mm/swapfile.c linux-3.0.4/mm/swapfile.c
67005--- linux-3.0.4/mm/swapfile.c 2011-07-21 22:17:23.000000000 -0400
67006+++ linux-3.0.4/mm/swapfile.c 2011-08-23 21:47:56.000000000 -0400
67007@@ -62,7 +62,7 @@ static DEFINE_MUTEX(swapon_mutex);
67008
67009 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
67010 /* Activity counter to indicate that a swapon or swapoff has occurred */
67011-static atomic_t proc_poll_event = ATOMIC_INIT(0);
67012+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
67013
67014 static inline unsigned char swap_count(unsigned char ent)
67015 {
67016@@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
67017 }
67018 filp_close(swap_file, NULL);
67019 err = 0;
67020- atomic_inc(&proc_poll_event);
67021+ atomic_inc_unchecked(&proc_poll_event);
67022 wake_up_interruptible(&proc_poll_wait);
67023
67024 out_dput:
67025@@ -1692,8 +1692,8 @@ static unsigned swaps_poll(struct file *
67026
67027 poll_wait(file, &proc_poll_wait, wait);
67028
67029- if (s->event != atomic_read(&proc_poll_event)) {
67030- s->event = atomic_read(&proc_poll_event);
67031+ if (s->event != atomic_read_unchecked(&proc_poll_event)) {
67032+ s->event = atomic_read_unchecked(&proc_poll_event);
67033 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
67034 }
67035
67036@@ -1799,7 +1799,7 @@ static int swaps_open(struct inode *inod
67037 }
67038
67039 s->seq.private = s;
67040- s->event = atomic_read(&proc_poll_event);
67041+ s->event = atomic_read_unchecked(&proc_poll_event);
67042 return ret;
67043 }
67044
67045@@ -2133,7 +2133,7 @@ SYSCALL_DEFINE2(swapon, const char __use
67046 (p->flags & SWP_DISCARDABLE) ? "D" : "");
67047
67048 mutex_unlock(&swapon_mutex);
67049- atomic_inc(&proc_poll_event);
67050+ atomic_inc_unchecked(&proc_poll_event);
67051 wake_up_interruptible(&proc_poll_wait);
67052
67053 if (S_ISREG(inode->i_mode))
67054diff -urNp linux-3.0.4/mm/util.c linux-3.0.4/mm/util.c
67055--- linux-3.0.4/mm/util.c 2011-07-21 22:17:23.000000000 -0400
67056+++ linux-3.0.4/mm/util.c 2011-08-23 21:47:56.000000000 -0400
67057@@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
67058 * allocated buffer. Use this if you don't want to free the buffer immediately
67059 * like, for example, with RCU.
67060 */
67061+#undef __krealloc
67062 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
67063 {
67064 void *ret;
67065@@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
67066 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
67067 * %NULL pointer, the object pointed to is freed.
67068 */
67069+#undef krealloc
67070 void *krealloc(const void *p, size_t new_size, gfp_t flags)
67071 {
67072 void *ret;
67073@@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *m
67074 void arch_pick_mmap_layout(struct mm_struct *mm)
67075 {
67076 mm->mmap_base = TASK_UNMAPPED_BASE;
67077+
67078+#ifdef CONFIG_PAX_RANDMMAP
67079+ if (mm->pax_flags & MF_PAX_RANDMMAP)
67080+ mm->mmap_base += mm->delta_mmap;
67081+#endif
67082+
67083 mm->get_unmapped_area = arch_get_unmapped_area;
67084 mm->unmap_area = arch_unmap_area;
67085 }
67086diff -urNp linux-3.0.4/mm/vmalloc.c linux-3.0.4/mm/vmalloc.c
67087--- linux-3.0.4/mm/vmalloc.c 2011-08-23 21:44:40.000000000 -0400
67088+++ linux-3.0.4/mm/vmalloc.c 2011-08-23 21:47:56.000000000 -0400
67089@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
67090
67091 pte = pte_offset_kernel(pmd, addr);
67092 do {
67093- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
67094- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
67095+
67096+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67097+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
67098+ BUG_ON(!pte_exec(*pte));
67099+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
67100+ continue;
67101+ }
67102+#endif
67103+
67104+ {
67105+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
67106+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
67107+ }
67108 } while (pte++, addr += PAGE_SIZE, addr != end);
67109 }
67110
67111@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
67112 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
67113 {
67114 pte_t *pte;
67115+ int ret = -ENOMEM;
67116
67117 /*
67118 * nr is a running index into the array which helps higher level
67119@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
67120 pte = pte_alloc_kernel(pmd, addr);
67121 if (!pte)
67122 return -ENOMEM;
67123+
67124+ pax_open_kernel();
67125 do {
67126 struct page *page = pages[*nr];
67127
67128- if (WARN_ON(!pte_none(*pte)))
67129- return -EBUSY;
67130- if (WARN_ON(!page))
67131- return -ENOMEM;
67132+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67133+ if (pgprot_val(prot) & _PAGE_NX)
67134+#endif
67135+
67136+ if (WARN_ON(!pte_none(*pte))) {
67137+ ret = -EBUSY;
67138+ goto out;
67139+ }
67140+ if (WARN_ON(!page)) {
67141+ ret = -ENOMEM;
67142+ goto out;
67143+ }
67144 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
67145 (*nr)++;
67146 } while (pte++, addr += PAGE_SIZE, addr != end);
67147- return 0;
67148+ ret = 0;
67149+out:
67150+ pax_close_kernel();
67151+ return ret;
67152 }
67153
67154 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
67155@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
67156 * and fall back on vmalloc() if that fails. Others
67157 * just put it in the vmalloc space.
67158 */
67159-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
67160+#ifdef CONFIG_MODULES
67161+#ifdef MODULES_VADDR
67162 unsigned long addr = (unsigned long)x;
67163 if (addr >= MODULES_VADDR && addr < MODULES_END)
67164 return 1;
67165 #endif
67166+
67167+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67168+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
67169+ return 1;
67170+#endif
67171+
67172+#endif
67173+
67174 return is_vmalloc_addr(x);
67175 }
67176
67177@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
67178
67179 if (!pgd_none(*pgd)) {
67180 pud_t *pud = pud_offset(pgd, addr);
67181+#ifdef CONFIG_X86
67182+ if (!pud_large(*pud))
67183+#endif
67184 if (!pud_none(*pud)) {
67185 pmd_t *pmd = pmd_offset(pud, addr);
67186+#ifdef CONFIG_X86
67187+ if (!pmd_large(*pmd))
67188+#endif
67189 if (!pmd_none(*pmd)) {
67190 pte_t *ptep, pte;
67191
67192@@ -1297,6 +1337,16 @@ static struct vm_struct *__get_vm_area_n
67193 struct vm_struct *area;
67194
67195 BUG_ON(in_interrupt());
67196+
67197+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67198+ if (flags & VM_KERNEXEC) {
67199+ if (start != VMALLOC_START || end != VMALLOC_END)
67200+ return NULL;
67201+ start = (unsigned long)MODULES_EXEC_VADDR;
67202+ end = (unsigned long)MODULES_EXEC_END;
67203+ }
67204+#endif
67205+
67206 if (flags & VM_IOREMAP) {
67207 int bit = fls(size);
67208
67209@@ -1515,6 +1565,11 @@ void *vmap(struct page **pages, unsigned
67210 if (count > totalram_pages)
67211 return NULL;
67212
67213+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67214+ if (!(pgprot_val(prot) & _PAGE_NX))
67215+ flags |= VM_KERNEXEC;
67216+#endif
67217+
67218 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
67219 __builtin_return_address(0));
67220 if (!area)
67221@@ -1616,6 +1671,13 @@ void *__vmalloc_node_range(unsigned long
67222 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
67223 return NULL;
67224
67225+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67226+ if (!(pgprot_val(prot) & _PAGE_NX))
67227+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
67228+ node, gfp_mask, caller);
67229+ else
67230+#endif
67231+
67232 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
67233 gfp_mask, caller);
67234
67235@@ -1655,6 +1717,7 @@ static void *__vmalloc_node(unsigned lon
67236 gfp_mask, prot, node, caller);
67237 }
67238
67239+#undef __vmalloc
67240 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
67241 {
67242 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
67243@@ -1678,6 +1741,7 @@ static inline void *__vmalloc_node_flags
67244 * For tight control over page level allocator and protection flags
67245 * use __vmalloc() instead.
67246 */
67247+#undef vmalloc
67248 void *vmalloc(unsigned long size)
67249 {
67250 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
67251@@ -1694,6 +1758,7 @@ EXPORT_SYMBOL(vmalloc);
67252 * For tight control over page level allocator and protection flags
67253 * use __vmalloc() instead.
67254 */
67255+#undef vzalloc
67256 void *vzalloc(unsigned long size)
67257 {
67258 return __vmalloc_node_flags(size, -1,
67259@@ -1708,6 +1773,7 @@ EXPORT_SYMBOL(vzalloc);
67260 * The resulting memory area is zeroed so it can be mapped to userspace
67261 * without leaking data.
67262 */
67263+#undef vmalloc_user
67264 void *vmalloc_user(unsigned long size)
67265 {
67266 struct vm_struct *area;
67267@@ -1735,6 +1801,7 @@ EXPORT_SYMBOL(vmalloc_user);
67268 * For tight control over page level allocator and protection flags
67269 * use __vmalloc() instead.
67270 */
67271+#undef vmalloc_node
67272 void *vmalloc_node(unsigned long size, int node)
67273 {
67274 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
67275@@ -1754,6 +1821,7 @@ EXPORT_SYMBOL(vmalloc_node);
67276 * For tight control over page level allocator and protection flags
67277 * use __vmalloc_node() instead.
67278 */
67279+#undef vzalloc_node
67280 void *vzalloc_node(unsigned long size, int node)
67281 {
67282 return __vmalloc_node_flags(size, node,
67283@@ -1776,10 +1844,10 @@ EXPORT_SYMBOL(vzalloc_node);
67284 * For tight control over page level allocator and protection flags
67285 * use __vmalloc() instead.
67286 */
67287-
67288+#undef vmalloc_exec
67289 void *vmalloc_exec(unsigned long size)
67290 {
67291- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
67292+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
67293 -1, __builtin_return_address(0));
67294 }
67295
67296@@ -1798,6 +1866,7 @@ void *vmalloc_exec(unsigned long size)
67297 * Allocate enough 32bit PA addressable pages to cover @size from the
67298 * page level allocator and map them into contiguous kernel virtual space.
67299 */
67300+#undef vmalloc_32
67301 void *vmalloc_32(unsigned long size)
67302 {
67303 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
67304@@ -1812,6 +1881,7 @@ EXPORT_SYMBOL(vmalloc_32);
67305 * The resulting memory area is 32bit addressable and zeroed so it can be
67306 * mapped to userspace without leaking data.
67307 */
67308+#undef vmalloc_32_user
67309 void *vmalloc_32_user(unsigned long size)
67310 {
67311 struct vm_struct *area;
67312@@ -2074,6 +2144,8 @@ int remap_vmalloc_range(struct vm_area_s
67313 unsigned long uaddr = vma->vm_start;
67314 unsigned long usize = vma->vm_end - vma->vm_start;
67315
67316+ BUG_ON(vma->vm_mirror);
67317+
67318 if ((PAGE_SIZE-1) & (unsigned long)addr)
67319 return -EINVAL;
67320
67321diff -urNp linux-3.0.4/mm/vmstat.c linux-3.0.4/mm/vmstat.c
67322--- linux-3.0.4/mm/vmstat.c 2011-07-21 22:17:23.000000000 -0400
67323+++ linux-3.0.4/mm/vmstat.c 2011-08-23 21:48:14.000000000 -0400
67324@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
67325 *
67326 * vm_stat contains the global counters
67327 */
67328-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67329+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67330 EXPORT_SYMBOL(vm_stat);
67331
67332 #ifdef CONFIG_SMP
67333@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
67334 v = p->vm_stat_diff[i];
67335 p->vm_stat_diff[i] = 0;
67336 local_irq_restore(flags);
67337- atomic_long_add(v, &zone->vm_stat[i]);
67338+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
67339 global_diff[i] += v;
67340 #ifdef CONFIG_NUMA
67341 /* 3 seconds idle till flush */
67342@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
67343
67344 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
67345 if (global_diff[i])
67346- atomic_long_add(global_diff[i], &vm_stat[i]);
67347+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
67348 }
67349
67350 #endif
67351@@ -1207,10 +1207,20 @@ static int __init setup_vmstat(void)
67352 start_cpu_timer(cpu);
67353 #endif
67354 #ifdef CONFIG_PROC_FS
67355- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
67356- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
67357- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
67358- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
67359+ {
67360+ mode_t gr_mode = S_IRUGO;
67361+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67362+ gr_mode = S_IRUSR;
67363+#endif
67364+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
67365+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
67366+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67367+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
67368+#else
67369+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
67370+#endif
67371+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
67372+ }
67373 #endif
67374 return 0;
67375 }
67376diff -urNp linux-3.0.4/net/8021q/vlan.c linux-3.0.4/net/8021q/vlan.c
67377--- linux-3.0.4/net/8021q/vlan.c 2011-07-21 22:17:23.000000000 -0400
67378+++ linux-3.0.4/net/8021q/vlan.c 2011-08-23 21:47:56.000000000 -0400
67379@@ -591,8 +591,7 @@ static int vlan_ioctl_handler(struct net
67380 err = -EPERM;
67381 if (!capable(CAP_NET_ADMIN))
67382 break;
67383- if ((args.u.name_type >= 0) &&
67384- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
67385+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
67386 struct vlan_net *vn;
67387
67388 vn = net_generic(net, vlan_net_id);
67389diff -urNp linux-3.0.4/net/atm/atm_misc.c linux-3.0.4/net/atm/atm_misc.c
67390--- linux-3.0.4/net/atm/atm_misc.c 2011-07-21 22:17:23.000000000 -0400
67391+++ linux-3.0.4/net/atm/atm_misc.c 2011-08-23 21:47:56.000000000 -0400
67392@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
67393 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
67394 return 1;
67395 atm_return(vcc, truesize);
67396- atomic_inc(&vcc->stats->rx_drop);
67397+ atomic_inc_unchecked(&vcc->stats->rx_drop);
67398 return 0;
67399 }
67400 EXPORT_SYMBOL(atm_charge);
67401@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
67402 }
67403 }
67404 atm_return(vcc, guess);
67405- atomic_inc(&vcc->stats->rx_drop);
67406+ atomic_inc_unchecked(&vcc->stats->rx_drop);
67407 return NULL;
67408 }
67409 EXPORT_SYMBOL(atm_alloc_charge);
67410@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
67411
67412 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
67413 {
67414-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
67415+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
67416 __SONET_ITEMS
67417 #undef __HANDLE_ITEM
67418 }
67419@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
67420
67421 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
67422 {
67423-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
67424+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
67425 __SONET_ITEMS
67426 #undef __HANDLE_ITEM
67427 }
67428diff -urNp linux-3.0.4/net/atm/lec.h linux-3.0.4/net/atm/lec.h
67429--- linux-3.0.4/net/atm/lec.h 2011-07-21 22:17:23.000000000 -0400
67430+++ linux-3.0.4/net/atm/lec.h 2011-08-23 21:47:56.000000000 -0400
67431@@ -48,7 +48,7 @@ struct lane2_ops {
67432 const u8 *tlvs, u32 sizeoftlvs);
67433 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
67434 const u8 *tlvs, u32 sizeoftlvs);
67435-};
67436+} __no_const;
67437
67438 /*
67439 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
67440diff -urNp linux-3.0.4/net/atm/mpc.h linux-3.0.4/net/atm/mpc.h
67441--- linux-3.0.4/net/atm/mpc.h 2011-07-21 22:17:23.000000000 -0400
67442+++ linux-3.0.4/net/atm/mpc.h 2011-08-23 21:47:56.000000000 -0400
67443@@ -33,7 +33,7 @@ struct mpoa_client {
67444 struct mpc_parameters parameters; /* parameters for this client */
67445
67446 const struct net_device_ops *old_ops;
67447- struct net_device_ops new_ops;
67448+ net_device_ops_no_const new_ops;
67449 };
67450
67451
67452diff -urNp linux-3.0.4/net/atm/mpoa_caches.c linux-3.0.4/net/atm/mpoa_caches.c
67453--- linux-3.0.4/net/atm/mpoa_caches.c 2011-07-21 22:17:23.000000000 -0400
67454+++ linux-3.0.4/net/atm/mpoa_caches.c 2011-08-23 21:48:14.000000000 -0400
67455@@ -255,6 +255,8 @@ static void check_resolving_entries(stru
67456 struct timeval now;
67457 struct k_message msg;
67458
67459+ pax_track_stack();
67460+
67461 do_gettimeofday(&now);
67462
67463 read_lock_bh(&client->ingress_lock);
67464diff -urNp linux-3.0.4/net/atm/proc.c linux-3.0.4/net/atm/proc.c
67465--- linux-3.0.4/net/atm/proc.c 2011-07-21 22:17:23.000000000 -0400
67466+++ linux-3.0.4/net/atm/proc.c 2011-08-23 21:47:56.000000000 -0400
67467@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
67468 const struct k_atm_aal_stats *stats)
67469 {
67470 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
67471- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
67472- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
67473- atomic_read(&stats->rx_drop));
67474+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
67475+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
67476+ atomic_read_unchecked(&stats->rx_drop));
67477 }
67478
67479 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
67480diff -urNp linux-3.0.4/net/atm/resources.c linux-3.0.4/net/atm/resources.c
67481--- linux-3.0.4/net/atm/resources.c 2011-07-21 22:17:23.000000000 -0400
67482+++ linux-3.0.4/net/atm/resources.c 2011-08-23 21:47:56.000000000 -0400
67483@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
67484 static void copy_aal_stats(struct k_atm_aal_stats *from,
67485 struct atm_aal_stats *to)
67486 {
67487-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
67488+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
67489 __AAL_STAT_ITEMS
67490 #undef __HANDLE_ITEM
67491 }
67492@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
67493 static void subtract_aal_stats(struct k_atm_aal_stats *from,
67494 struct atm_aal_stats *to)
67495 {
67496-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
67497+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
67498 __AAL_STAT_ITEMS
67499 #undef __HANDLE_ITEM
67500 }
67501diff -urNp linux-3.0.4/net/batman-adv/hard-interface.c linux-3.0.4/net/batman-adv/hard-interface.c
67502--- linux-3.0.4/net/batman-adv/hard-interface.c 2011-07-21 22:17:23.000000000 -0400
67503+++ linux-3.0.4/net/batman-adv/hard-interface.c 2011-08-23 21:47:56.000000000 -0400
67504@@ -351,8 +351,8 @@ int hardif_enable_interface(struct hard_
67505 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
67506 dev_add_pack(&hard_iface->batman_adv_ptype);
67507
67508- atomic_set(&hard_iface->seqno, 1);
67509- atomic_set(&hard_iface->frag_seqno, 1);
67510+ atomic_set_unchecked(&hard_iface->seqno, 1);
67511+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
67512 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
67513 hard_iface->net_dev->name);
67514
67515diff -urNp linux-3.0.4/net/batman-adv/routing.c linux-3.0.4/net/batman-adv/routing.c
67516--- linux-3.0.4/net/batman-adv/routing.c 2011-07-21 22:17:23.000000000 -0400
67517+++ linux-3.0.4/net/batman-adv/routing.c 2011-08-23 21:47:56.000000000 -0400
67518@@ -627,7 +627,7 @@ void receive_bat_packet(struct ethhdr *e
67519 return;
67520
67521 /* could be changed by schedule_own_packet() */
67522- if_incoming_seqno = atomic_read(&if_incoming->seqno);
67523+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
67524
67525 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
67526
67527diff -urNp linux-3.0.4/net/batman-adv/send.c linux-3.0.4/net/batman-adv/send.c
67528--- linux-3.0.4/net/batman-adv/send.c 2011-07-21 22:17:23.000000000 -0400
67529+++ linux-3.0.4/net/batman-adv/send.c 2011-08-23 21:47:56.000000000 -0400
67530@@ -279,7 +279,7 @@ void schedule_own_packet(struct hard_ifa
67531
67532 /* change sequence number to network order */
67533 batman_packet->seqno =
67534- htonl((uint32_t)atomic_read(&hard_iface->seqno));
67535+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
67536
67537 if (vis_server == VIS_TYPE_SERVER_SYNC)
67538 batman_packet->flags |= VIS_SERVER;
67539@@ -293,7 +293,7 @@ void schedule_own_packet(struct hard_ifa
67540 else
67541 batman_packet->gw_flags = 0;
67542
67543- atomic_inc(&hard_iface->seqno);
67544+ atomic_inc_unchecked(&hard_iface->seqno);
67545
67546 slide_own_bcast_window(hard_iface);
67547 send_time = own_send_time(bat_priv);
67548diff -urNp linux-3.0.4/net/batman-adv/soft-interface.c linux-3.0.4/net/batman-adv/soft-interface.c
67549--- linux-3.0.4/net/batman-adv/soft-interface.c 2011-07-21 22:17:23.000000000 -0400
67550+++ linux-3.0.4/net/batman-adv/soft-interface.c 2011-08-23 21:47:56.000000000 -0400
67551@@ -628,7 +628,7 @@ int interface_tx(struct sk_buff *skb, st
67552
67553 /* set broadcast sequence number */
67554 bcast_packet->seqno =
67555- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
67556+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
67557
67558 add_bcast_packet_to_list(bat_priv, skb);
67559
67560@@ -830,7 +830,7 @@ struct net_device *softif_create(char *n
67561 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
67562
67563 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
67564- atomic_set(&bat_priv->bcast_seqno, 1);
67565+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
67566 atomic_set(&bat_priv->tt_local_changed, 0);
67567
67568 bat_priv->primary_if = NULL;
67569diff -urNp linux-3.0.4/net/batman-adv/types.h linux-3.0.4/net/batman-adv/types.h
67570--- linux-3.0.4/net/batman-adv/types.h 2011-07-21 22:17:23.000000000 -0400
67571+++ linux-3.0.4/net/batman-adv/types.h 2011-08-23 21:47:56.000000000 -0400
67572@@ -38,8 +38,8 @@ struct hard_iface {
67573 int16_t if_num;
67574 char if_status;
67575 struct net_device *net_dev;
67576- atomic_t seqno;
67577- atomic_t frag_seqno;
67578+ atomic_unchecked_t seqno;
67579+ atomic_unchecked_t frag_seqno;
67580 unsigned char *packet_buff;
67581 int packet_len;
67582 struct kobject *hardif_obj;
67583@@ -142,7 +142,7 @@ struct bat_priv {
67584 atomic_t orig_interval; /* uint */
67585 atomic_t hop_penalty; /* uint */
67586 atomic_t log_level; /* uint */
67587- atomic_t bcast_seqno;
67588+ atomic_unchecked_t bcast_seqno;
67589 atomic_t bcast_queue_left;
67590 atomic_t batman_queue_left;
67591 char num_ifaces;
67592diff -urNp linux-3.0.4/net/batman-adv/unicast.c linux-3.0.4/net/batman-adv/unicast.c
67593--- linux-3.0.4/net/batman-adv/unicast.c 2011-07-21 22:17:23.000000000 -0400
67594+++ linux-3.0.4/net/batman-adv/unicast.c 2011-08-23 21:47:56.000000000 -0400
67595@@ -265,7 +265,7 @@ int frag_send_skb(struct sk_buff *skb, s
67596 frag1->flags = UNI_FRAG_HEAD | large_tail;
67597 frag2->flags = large_tail;
67598
67599- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
67600+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
67601 frag1->seqno = htons(seqno - 1);
67602 frag2->seqno = htons(seqno);
67603
67604diff -urNp linux-3.0.4/net/bridge/br_multicast.c linux-3.0.4/net/bridge/br_multicast.c
67605--- linux-3.0.4/net/bridge/br_multicast.c 2011-07-21 22:17:23.000000000 -0400
67606+++ linux-3.0.4/net/bridge/br_multicast.c 2011-08-23 21:47:56.000000000 -0400
67607@@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct
67608 nexthdr = ip6h->nexthdr;
67609 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
67610
67611- if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
67612+ if (nexthdr != IPPROTO_ICMPV6)
67613 return 0;
67614
67615 /* Okay, we found ICMPv6 header */
67616diff -urNp linux-3.0.4/net/bridge/netfilter/ebtables.c linux-3.0.4/net/bridge/netfilter/ebtables.c
67617--- linux-3.0.4/net/bridge/netfilter/ebtables.c 2011-07-21 22:17:23.000000000 -0400
67618+++ linux-3.0.4/net/bridge/netfilter/ebtables.c 2011-08-23 21:48:14.000000000 -0400
67619@@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
67620 tmp.valid_hooks = t->table->valid_hooks;
67621 }
67622 mutex_unlock(&ebt_mutex);
67623- if (copy_to_user(user, &tmp, *len) != 0){
67624+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
67625 BUGPRINT("c2u Didn't work\n");
67626 ret = -EFAULT;
67627 break;
67628@@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
67629 int ret;
67630 void __user *pos;
67631
67632+ pax_track_stack();
67633+
67634 memset(&tinfo, 0, sizeof(tinfo));
67635
67636 if (cmd == EBT_SO_GET_ENTRIES) {
67637diff -urNp linux-3.0.4/net/caif/caif_socket.c linux-3.0.4/net/caif/caif_socket.c
67638--- linux-3.0.4/net/caif/caif_socket.c 2011-07-21 22:17:23.000000000 -0400
67639+++ linux-3.0.4/net/caif/caif_socket.c 2011-08-23 21:47:56.000000000 -0400
67640@@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
67641 #ifdef CONFIG_DEBUG_FS
67642 struct debug_fs_counter {
67643 atomic_t caif_nr_socks;
67644- atomic_t caif_sock_create;
67645- atomic_t num_connect_req;
67646- atomic_t num_connect_resp;
67647- atomic_t num_connect_fail_resp;
67648- atomic_t num_disconnect;
67649- atomic_t num_remote_shutdown_ind;
67650- atomic_t num_tx_flow_off_ind;
67651- atomic_t num_tx_flow_on_ind;
67652- atomic_t num_rx_flow_off;
67653- atomic_t num_rx_flow_on;
67654+ atomic_unchecked_t caif_sock_create;
67655+ atomic_unchecked_t num_connect_req;
67656+ atomic_unchecked_t num_connect_resp;
67657+ atomic_unchecked_t num_connect_fail_resp;
67658+ atomic_unchecked_t num_disconnect;
67659+ atomic_unchecked_t num_remote_shutdown_ind;
67660+ atomic_unchecked_t num_tx_flow_off_ind;
67661+ atomic_unchecked_t num_tx_flow_on_ind;
67662+ atomic_unchecked_t num_rx_flow_off;
67663+ atomic_unchecked_t num_rx_flow_on;
67664 };
67665 static struct debug_fs_counter cnt;
67666 #define dbfs_atomic_inc(v) atomic_inc_return(v)
67667+#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
67668 #define dbfs_atomic_dec(v) atomic_dec_return(v)
67669 #else
67670 #define dbfs_atomic_inc(v) 0
67671@@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct soc
67672 atomic_read(&cf_sk->sk.sk_rmem_alloc),
67673 sk_rcvbuf_lowwater(cf_sk));
67674 set_rx_flow_off(cf_sk);
67675- dbfs_atomic_inc(&cnt.num_rx_flow_off);
67676+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
67677 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
67678 }
67679
67680@@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct soc
67681 set_rx_flow_off(cf_sk);
67682 if (net_ratelimit())
67683 pr_debug("sending flow OFF due to rmem_schedule\n");
67684- dbfs_atomic_inc(&cnt.num_rx_flow_off);
67685+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
67686 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
67687 }
67688 skb->dev = NULL;
67689@@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer
67690 switch (flow) {
67691 case CAIF_CTRLCMD_FLOW_ON_IND:
67692 /* OK from modem to start sending again */
67693- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
67694+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
67695 set_tx_flow_on(cf_sk);
67696 cf_sk->sk.sk_state_change(&cf_sk->sk);
67697 break;
67698
67699 case CAIF_CTRLCMD_FLOW_OFF_IND:
67700 /* Modem asks us to shut up */
67701- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
67702+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
67703 set_tx_flow_off(cf_sk);
67704 cf_sk->sk.sk_state_change(&cf_sk->sk);
67705 break;
67706@@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer
67707 /* We're now connected */
67708 caif_client_register_refcnt(&cf_sk->layer,
67709 cfsk_hold, cfsk_put);
67710- dbfs_atomic_inc(&cnt.num_connect_resp);
67711+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
67712 cf_sk->sk.sk_state = CAIF_CONNECTED;
67713 set_tx_flow_on(cf_sk);
67714 cf_sk->sk.sk_state_change(&cf_sk->sk);
67715@@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer
67716
67717 case CAIF_CTRLCMD_INIT_FAIL_RSP:
67718 /* Connect request failed */
67719- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
67720+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
67721 cf_sk->sk.sk_err = ECONNREFUSED;
67722 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
67723 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
67724@@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer
67725
67726 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
67727 /* Modem has closed this connection, or device is down. */
67728- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
67729+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
67730 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
67731 cf_sk->sk.sk_err = ECONNRESET;
67732 set_rx_flow_on(cf_sk);
67733@@ -297,7 +298,7 @@ static void caif_check_flow_release(stru
67734 return;
67735
67736 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
67737- dbfs_atomic_inc(&cnt.num_rx_flow_on);
67738+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
67739 set_rx_flow_on(cf_sk);
67740 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
67741 }
67742@@ -854,7 +855,7 @@ static int caif_connect(struct socket *s
67743 /*ifindex = id of the interface.*/
67744 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
67745
67746- dbfs_atomic_inc(&cnt.num_connect_req);
67747+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
67748 cf_sk->layer.receive = caif_sktrecv_cb;
67749
67750 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
67751@@ -943,7 +944,7 @@ static int caif_release(struct socket *s
67752 spin_unlock_bh(&sk->sk_receive_queue.lock);
67753 sock->sk = NULL;
67754
67755- dbfs_atomic_inc(&cnt.num_disconnect);
67756+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
67757
67758 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
67759 if (cf_sk->debugfs_socket_dir != NULL)
67760@@ -1122,7 +1123,7 @@ static int caif_create(struct net *net,
67761 cf_sk->conn_req.protocol = protocol;
67762 /* Increase the number of sockets created. */
67763 dbfs_atomic_inc(&cnt.caif_nr_socks);
67764- num = dbfs_atomic_inc(&cnt.caif_sock_create);
67765+ num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
67766 #ifdef CONFIG_DEBUG_FS
67767 if (!IS_ERR(debugfsdir)) {
67768
67769diff -urNp linux-3.0.4/net/caif/cfctrl.c linux-3.0.4/net/caif/cfctrl.c
67770--- linux-3.0.4/net/caif/cfctrl.c 2011-07-21 22:17:23.000000000 -0400
67771+++ linux-3.0.4/net/caif/cfctrl.c 2011-08-23 21:48:14.000000000 -0400
67772@@ -9,6 +9,7 @@
67773 #include <linux/stddef.h>
67774 #include <linux/spinlock.h>
67775 #include <linux/slab.h>
67776+#include <linux/sched.h>
67777 #include <net/caif/caif_layer.h>
67778 #include <net/caif/cfpkt.h>
67779 #include <net/caif/cfctrl.h>
67780@@ -45,8 +46,8 @@ struct cflayer *cfctrl_create(void)
67781 dev_info.id = 0xff;
67782 memset(this, 0, sizeof(*this));
67783 cfsrvl_init(&this->serv, 0, &dev_info, false);
67784- atomic_set(&this->req_seq_no, 1);
67785- atomic_set(&this->rsp_seq_no, 1);
67786+ atomic_set_unchecked(&this->req_seq_no, 1);
67787+ atomic_set_unchecked(&this->rsp_seq_no, 1);
67788 this->serv.layer.receive = cfctrl_recv;
67789 sprintf(this->serv.layer.name, "ctrl");
67790 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
67791@@ -132,8 +133,8 @@ static void cfctrl_insert_req(struct cfc
67792 struct cfctrl_request_info *req)
67793 {
67794 spin_lock_bh(&ctrl->info_list_lock);
67795- atomic_inc(&ctrl->req_seq_no);
67796- req->sequence_no = atomic_read(&ctrl->req_seq_no);
67797+ atomic_inc_unchecked(&ctrl->req_seq_no);
67798+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
67799 list_add_tail(&req->list, &ctrl->list);
67800 spin_unlock_bh(&ctrl->info_list_lock);
67801 }
67802@@ -151,7 +152,7 @@ static struct cfctrl_request_info *cfctr
67803 if (p != first)
67804 pr_warn("Requests are not received in order\n");
67805
67806- atomic_set(&ctrl->rsp_seq_no,
67807+ atomic_set_unchecked(&ctrl->rsp_seq_no,
67808 p->sequence_no);
67809 list_del(&p->list);
67810 goto out;
67811@@ -364,6 +365,7 @@ static int cfctrl_recv(struct cflayer *l
67812 struct cfctrl *cfctrl = container_obj(layer);
67813 struct cfctrl_request_info rsp, *req;
67814
67815+ pax_track_stack();
67816
67817 cfpkt_extr_head(pkt, &cmdrsp, 1);
67818 cmd = cmdrsp & CFCTRL_CMD_MASK;
67819diff -urNp linux-3.0.4/net/core/datagram.c linux-3.0.4/net/core/datagram.c
67820--- linux-3.0.4/net/core/datagram.c 2011-07-21 22:17:23.000000000 -0400
67821+++ linux-3.0.4/net/core/datagram.c 2011-08-23 21:47:56.000000000 -0400
67822@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
67823 }
67824
67825 kfree_skb(skb);
67826- atomic_inc(&sk->sk_drops);
67827+ atomic_inc_unchecked(&sk->sk_drops);
67828 sk_mem_reclaim_partial(sk);
67829
67830 return err;
67831diff -urNp linux-3.0.4/net/core/dev.c linux-3.0.4/net/core/dev.c
67832--- linux-3.0.4/net/core/dev.c 2011-07-21 22:17:23.000000000 -0400
67833+++ linux-3.0.4/net/core/dev.c 2011-08-23 21:48:14.000000000 -0400
67834@@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
67835 if (no_module && capable(CAP_NET_ADMIN))
67836 no_module = request_module("netdev-%s", name);
67837 if (no_module && capable(CAP_SYS_MODULE)) {
67838+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67839+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
67840+#else
67841 if (!request_module("%s", name))
67842 pr_err("Loading kernel module for a network device "
67843 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
67844 "instead\n", name);
67845+#endif
67846 }
67847 }
67848 EXPORT_SYMBOL(dev_load);
67849@@ -1959,7 +1963,7 @@ static int illegal_highdma(struct net_de
67850
67851 struct dev_gso_cb {
67852 void (*destructor)(struct sk_buff *skb);
67853-};
67854+} __no_const;
67855
67856 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
67857
67858@@ -2912,7 +2916,7 @@ int netif_rx_ni(struct sk_buff *skb)
67859 }
67860 EXPORT_SYMBOL(netif_rx_ni);
67861
67862-static void net_tx_action(struct softirq_action *h)
67863+static void net_tx_action(void)
67864 {
67865 struct softnet_data *sd = &__get_cpu_var(softnet_data);
67866
67867@@ -3761,7 +3765,7 @@ void netif_napi_del(struct napi_struct *
67868 }
67869 EXPORT_SYMBOL(netif_napi_del);
67870
67871-static void net_rx_action(struct softirq_action *h)
67872+static void net_rx_action(void)
67873 {
67874 struct softnet_data *sd = &__get_cpu_var(softnet_data);
67875 unsigned long time_limit = jiffies + 2;
67876diff -urNp linux-3.0.4/net/core/flow.c linux-3.0.4/net/core/flow.c
67877--- linux-3.0.4/net/core/flow.c 2011-07-21 22:17:23.000000000 -0400
67878+++ linux-3.0.4/net/core/flow.c 2011-08-23 21:47:56.000000000 -0400
67879@@ -60,7 +60,7 @@ struct flow_cache {
67880 struct timer_list rnd_timer;
67881 };
67882
67883-atomic_t flow_cache_genid = ATOMIC_INIT(0);
67884+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
67885 EXPORT_SYMBOL(flow_cache_genid);
67886 static struct flow_cache flow_cache_global;
67887 static struct kmem_cache *flow_cachep __read_mostly;
67888@@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
67889
67890 static int flow_entry_valid(struct flow_cache_entry *fle)
67891 {
67892- if (atomic_read(&flow_cache_genid) != fle->genid)
67893+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
67894 return 0;
67895 if (fle->object && !fle->object->ops->check(fle->object))
67896 return 0;
67897@@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
67898 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
67899 fcp->hash_count++;
67900 }
67901- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
67902+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
67903 flo = fle->object;
67904 if (!flo)
67905 goto ret_object;
67906@@ -274,7 +274,7 @@ nocache:
67907 }
67908 flo = resolver(net, key, family, dir, flo, ctx);
67909 if (fle) {
67910- fle->genid = atomic_read(&flow_cache_genid);
67911+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
67912 if (!IS_ERR(flo))
67913 fle->object = flo;
67914 else
67915diff -urNp linux-3.0.4/net/core/rtnetlink.c linux-3.0.4/net/core/rtnetlink.c
67916--- linux-3.0.4/net/core/rtnetlink.c 2011-07-21 22:17:23.000000000 -0400
67917+++ linux-3.0.4/net/core/rtnetlink.c 2011-08-23 21:47:56.000000000 -0400
67918@@ -56,7 +56,7 @@
67919 struct rtnl_link {
67920 rtnl_doit_func doit;
67921 rtnl_dumpit_func dumpit;
67922-};
67923+} __no_const;
67924
67925 static DEFINE_MUTEX(rtnl_mutex);
67926
67927diff -urNp linux-3.0.4/net/core/skbuff.c linux-3.0.4/net/core/skbuff.c
67928--- linux-3.0.4/net/core/skbuff.c 2011-07-21 22:17:23.000000000 -0400
67929+++ linux-3.0.4/net/core/skbuff.c 2011-08-23 21:48:14.000000000 -0400
67930@@ -1543,6 +1543,8 @@ int skb_splice_bits(struct sk_buff *skb,
67931 struct sock *sk = skb->sk;
67932 int ret = 0;
67933
67934+ pax_track_stack();
67935+
67936 if (splice_grow_spd(pipe, &spd))
67937 return -ENOMEM;
67938
67939diff -urNp linux-3.0.4/net/core/sock.c linux-3.0.4/net/core/sock.c
67940--- linux-3.0.4/net/core/sock.c 2011-07-21 22:17:23.000000000 -0400
67941+++ linux-3.0.4/net/core/sock.c 2011-08-23 21:48:14.000000000 -0400
67942@@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
67943 */
67944 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
67945 (unsigned)sk->sk_rcvbuf) {
67946- atomic_inc(&sk->sk_drops);
67947+ atomic_inc_unchecked(&sk->sk_drops);
67948 return -ENOMEM;
67949 }
67950
67951@@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
67952 return err;
67953
67954 if (!sk_rmem_schedule(sk, skb->truesize)) {
67955- atomic_inc(&sk->sk_drops);
67956+ atomic_inc_unchecked(&sk->sk_drops);
67957 return -ENOBUFS;
67958 }
67959
67960@@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
67961 skb_dst_force(skb);
67962
67963 spin_lock_irqsave(&list->lock, flags);
67964- skb->dropcount = atomic_read(&sk->sk_drops);
67965+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
67966 __skb_queue_tail(list, skb);
67967 spin_unlock_irqrestore(&list->lock, flags);
67968
67969@@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
67970 skb->dev = NULL;
67971
67972 if (sk_rcvqueues_full(sk, skb)) {
67973- atomic_inc(&sk->sk_drops);
67974+ atomic_inc_unchecked(&sk->sk_drops);
67975 goto discard_and_relse;
67976 }
67977 if (nested)
67978@@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
67979 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
67980 } else if (sk_add_backlog(sk, skb)) {
67981 bh_unlock_sock(sk);
67982- atomic_inc(&sk->sk_drops);
67983+ atomic_inc_unchecked(&sk->sk_drops);
67984 goto discard_and_relse;
67985 }
67986
67987@@ -921,7 +921,7 @@ int sock_getsockopt(struct socket *sock,
67988 if (len > sizeof(peercred))
67989 len = sizeof(peercred);
67990 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
67991- if (copy_to_user(optval, &peercred, len))
67992+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
67993 return -EFAULT;
67994 goto lenout;
67995 }
67996@@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
67997 return -ENOTCONN;
67998 if (lv < len)
67999 return -EINVAL;
68000- if (copy_to_user(optval, address, len))
68001+ if (len > sizeof(address) || copy_to_user(optval, address, len))
68002 return -EFAULT;
68003 goto lenout;
68004 }
68005@@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
68006
68007 if (len > lv)
68008 len = lv;
68009- if (copy_to_user(optval, &v, len))
68010+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
68011 return -EFAULT;
68012 lenout:
68013 if (put_user(len, optlen))
68014@@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
68015 */
68016 smp_wmb();
68017 atomic_set(&sk->sk_refcnt, 1);
68018- atomic_set(&sk->sk_drops, 0);
68019+ atomic_set_unchecked(&sk->sk_drops, 0);
68020 }
68021 EXPORT_SYMBOL(sock_init_data);
68022
68023diff -urNp linux-3.0.4/net/decnet/sysctl_net_decnet.c linux-3.0.4/net/decnet/sysctl_net_decnet.c
68024--- linux-3.0.4/net/decnet/sysctl_net_decnet.c 2011-07-21 22:17:23.000000000 -0400
68025+++ linux-3.0.4/net/decnet/sysctl_net_decnet.c 2011-08-23 21:47:56.000000000 -0400
68026@@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
68027
68028 if (len > *lenp) len = *lenp;
68029
68030- if (copy_to_user(buffer, addr, len))
68031+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
68032 return -EFAULT;
68033
68034 *lenp = len;
68035@@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
68036
68037 if (len > *lenp) len = *lenp;
68038
68039- if (copy_to_user(buffer, devname, len))
68040+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
68041 return -EFAULT;
68042
68043 *lenp = len;
68044diff -urNp linux-3.0.4/net/econet/Kconfig linux-3.0.4/net/econet/Kconfig
68045--- linux-3.0.4/net/econet/Kconfig 2011-07-21 22:17:23.000000000 -0400
68046+++ linux-3.0.4/net/econet/Kconfig 2011-08-23 21:48:14.000000000 -0400
68047@@ -4,7 +4,7 @@
68048
68049 config ECONET
68050 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
68051- depends on EXPERIMENTAL && INET
68052+ depends on EXPERIMENTAL && INET && BROKEN
68053 ---help---
68054 Econet is a fairly old and slow networking protocol mainly used by
68055 Acorn computers to access file and print servers. It uses native
68056diff -urNp linux-3.0.4/net/ipv4/fib_frontend.c linux-3.0.4/net/ipv4/fib_frontend.c
68057--- linux-3.0.4/net/ipv4/fib_frontend.c 2011-07-21 22:17:23.000000000 -0400
68058+++ linux-3.0.4/net/ipv4/fib_frontend.c 2011-08-23 21:47:56.000000000 -0400
68059@@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct not
68060 #ifdef CONFIG_IP_ROUTE_MULTIPATH
68061 fib_sync_up(dev);
68062 #endif
68063- atomic_inc(&net->ipv4.dev_addr_genid);
68064+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
68065 rt_cache_flush(dev_net(dev), -1);
68066 break;
68067 case NETDEV_DOWN:
68068 fib_del_ifaddr(ifa, NULL);
68069- atomic_inc(&net->ipv4.dev_addr_genid);
68070+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
68071 if (ifa->ifa_dev->ifa_list == NULL) {
68072 /* Last address was deleted from this interface.
68073 * Disable IP.
68074@@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notif
68075 #ifdef CONFIG_IP_ROUTE_MULTIPATH
68076 fib_sync_up(dev);
68077 #endif
68078- atomic_inc(&net->ipv4.dev_addr_genid);
68079+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
68080 rt_cache_flush(dev_net(dev), -1);
68081 break;
68082 case NETDEV_DOWN:
68083diff -urNp linux-3.0.4/net/ipv4/fib_semantics.c linux-3.0.4/net/ipv4/fib_semantics.c
68084--- linux-3.0.4/net/ipv4/fib_semantics.c 2011-07-21 22:17:23.000000000 -0400
68085+++ linux-3.0.4/net/ipv4/fib_semantics.c 2011-08-23 21:47:56.000000000 -0400
68086@@ -691,7 +691,7 @@ __be32 fib_info_update_nh_saddr(struct n
68087 nh->nh_saddr = inet_select_addr(nh->nh_dev,
68088 nh->nh_gw,
68089 nh->nh_parent->fib_scope);
68090- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
68091+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
68092
68093 return nh->nh_saddr;
68094 }
68095diff -urNp linux-3.0.4/net/ipv4/inet_diag.c linux-3.0.4/net/ipv4/inet_diag.c
68096--- linux-3.0.4/net/ipv4/inet_diag.c 2011-07-21 22:17:23.000000000 -0400
68097+++ linux-3.0.4/net/ipv4/inet_diag.c 2011-08-23 21:48:14.000000000 -0400
68098@@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
68099 r->idiag_retrans = 0;
68100
68101 r->id.idiag_if = sk->sk_bound_dev_if;
68102+
68103+#ifdef CONFIG_GRKERNSEC_HIDESYM
68104+ r->id.idiag_cookie[0] = 0;
68105+ r->id.idiag_cookie[1] = 0;
68106+#else
68107 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
68108 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
68109+#endif
68110
68111 r->id.idiag_sport = inet->inet_sport;
68112 r->id.idiag_dport = inet->inet_dport;
68113@@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
68114 r->idiag_family = tw->tw_family;
68115 r->idiag_retrans = 0;
68116 r->id.idiag_if = tw->tw_bound_dev_if;
68117+
68118+#ifdef CONFIG_GRKERNSEC_HIDESYM
68119+ r->id.idiag_cookie[0] = 0;
68120+ r->id.idiag_cookie[1] = 0;
68121+#else
68122 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
68123 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
68124+#endif
68125+
68126 r->id.idiag_sport = tw->tw_sport;
68127 r->id.idiag_dport = tw->tw_dport;
68128 r->id.idiag_src[0] = tw->tw_rcv_saddr;
68129@@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
68130 if (sk == NULL)
68131 goto unlock;
68132
68133+#ifndef CONFIG_GRKERNSEC_HIDESYM
68134 err = -ESTALE;
68135 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
68136 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
68137 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
68138 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
68139 goto out;
68140+#endif
68141
68142 err = -ENOMEM;
68143 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
68144@@ -580,8 +595,14 @@ static int inet_diag_fill_req(struct sk_
68145 r->idiag_retrans = req->retrans;
68146
68147 r->id.idiag_if = sk->sk_bound_dev_if;
68148+
68149+#ifdef CONFIG_GRKERNSEC_HIDESYM
68150+ r->id.idiag_cookie[0] = 0;
68151+ r->id.idiag_cookie[1] = 0;
68152+#else
68153 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
68154 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
68155+#endif
68156
68157 tmo = req->expires - jiffies;
68158 if (tmo < 0)
68159diff -urNp linux-3.0.4/net/ipv4/inet_hashtables.c linux-3.0.4/net/ipv4/inet_hashtables.c
68160--- linux-3.0.4/net/ipv4/inet_hashtables.c 2011-08-23 21:44:40.000000000 -0400
68161+++ linux-3.0.4/net/ipv4/inet_hashtables.c 2011-08-23 21:55:24.000000000 -0400
68162@@ -18,12 +18,15 @@
68163 #include <linux/sched.h>
68164 #include <linux/slab.h>
68165 #include <linux/wait.h>
68166+#include <linux/security.h>
68167
68168 #include <net/inet_connection_sock.h>
68169 #include <net/inet_hashtables.h>
68170 #include <net/secure_seq.h>
68171 #include <net/ip.h>
68172
68173+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
68174+
68175 /*
68176 * Allocate and initialize a new local port bind bucket.
68177 * The bindhash mutex for snum's hash chain must be held here.
68178@@ -530,6 +533,8 @@ ok:
68179 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
68180 spin_unlock(&head->lock);
68181
68182+ gr_update_task_in_ip_table(current, inet_sk(sk));
68183+
68184 if (tw) {
68185 inet_twsk_deschedule(tw, death_row);
68186 while (twrefcnt) {
68187diff -urNp linux-3.0.4/net/ipv4/inetpeer.c linux-3.0.4/net/ipv4/inetpeer.c
68188--- linux-3.0.4/net/ipv4/inetpeer.c 2011-08-23 21:44:40.000000000 -0400
68189+++ linux-3.0.4/net/ipv4/inetpeer.c 2011-08-23 21:48:14.000000000 -0400
68190@@ -481,6 +481,8 @@ struct inet_peer *inet_getpeer(struct in
68191 unsigned int sequence;
68192 int invalidated, newrefcnt = 0;
68193
68194+ pax_track_stack();
68195+
68196 /* Look up for the address quickly, lockless.
68197 * Because of a concurrent writer, we might not find an existing entry.
68198 */
68199@@ -517,8 +519,8 @@ found: /* The existing node has been fo
68200 if (p) {
68201 p->daddr = *daddr;
68202 atomic_set(&p->refcnt, 1);
68203- atomic_set(&p->rid, 0);
68204- atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
68205+ atomic_set_unchecked(&p->rid, 0);
68206+ atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
68207 p->tcp_ts_stamp = 0;
68208 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
68209 p->rate_tokens = 0;
68210diff -urNp linux-3.0.4/net/ipv4/ip_fragment.c linux-3.0.4/net/ipv4/ip_fragment.c
68211--- linux-3.0.4/net/ipv4/ip_fragment.c 2011-07-21 22:17:23.000000000 -0400
68212+++ linux-3.0.4/net/ipv4/ip_fragment.c 2011-08-23 21:47:56.000000000 -0400
68213@@ -315,7 +315,7 @@ static inline int ip_frag_too_far(struct
68214 return 0;
68215
68216 start = qp->rid;
68217- end = atomic_inc_return(&peer->rid);
68218+ end = atomic_inc_return_unchecked(&peer->rid);
68219 qp->rid = end;
68220
68221 rc = qp->q.fragments && (end - start) > max;
68222diff -urNp linux-3.0.4/net/ipv4/ip_sockglue.c linux-3.0.4/net/ipv4/ip_sockglue.c
68223--- linux-3.0.4/net/ipv4/ip_sockglue.c 2011-07-21 22:17:23.000000000 -0400
68224+++ linux-3.0.4/net/ipv4/ip_sockglue.c 2011-08-23 21:48:14.000000000 -0400
68225@@ -1073,6 +1073,8 @@ static int do_ip_getsockopt(struct sock
68226 int val;
68227 int len;
68228
68229+ pax_track_stack();
68230+
68231 if (level != SOL_IP)
68232 return -EOPNOTSUPP;
68233
68234@@ -1110,7 +1112,8 @@ static int do_ip_getsockopt(struct sock
68235 len = min_t(unsigned int, len, opt->optlen);
68236 if (put_user(len, optlen))
68237 return -EFAULT;
68238- if (copy_to_user(optval, opt->__data, len))
68239+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
68240+ copy_to_user(optval, opt->__data, len))
68241 return -EFAULT;
68242 return 0;
68243 }
68244diff -urNp linux-3.0.4/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-3.0.4/net/ipv4/netfilter/nf_nat_snmp_basic.c
68245--- linux-3.0.4/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-07-21 22:17:23.000000000 -0400
68246+++ linux-3.0.4/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-08-23 21:47:56.000000000 -0400
68247@@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
68248
68249 *len = 0;
68250
68251- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
68252+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
68253 if (*octets == NULL) {
68254 if (net_ratelimit())
68255 pr_notice("OOM in bsalg (%d)\n", __LINE__);
68256diff -urNp linux-3.0.4/net/ipv4/ping.c linux-3.0.4/net/ipv4/ping.c
68257--- linux-3.0.4/net/ipv4/ping.c 2011-07-21 22:17:23.000000000 -0400
68258+++ linux-3.0.4/net/ipv4/ping.c 2011-08-23 21:47:56.000000000 -0400
68259@@ -837,7 +837,7 @@ static void ping_format_sock(struct sock
68260 sk_rmem_alloc_get(sp),
68261 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
68262 atomic_read(&sp->sk_refcnt), sp,
68263- atomic_read(&sp->sk_drops), len);
68264+ atomic_read_unchecked(&sp->sk_drops), len);
68265 }
68266
68267 static int ping_seq_show(struct seq_file *seq, void *v)
68268diff -urNp linux-3.0.4/net/ipv4/raw.c linux-3.0.4/net/ipv4/raw.c
68269--- linux-3.0.4/net/ipv4/raw.c 2011-07-21 22:17:23.000000000 -0400
68270+++ linux-3.0.4/net/ipv4/raw.c 2011-08-23 21:48:14.000000000 -0400
68271@@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
68272 int raw_rcv(struct sock *sk, struct sk_buff *skb)
68273 {
68274 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
68275- atomic_inc(&sk->sk_drops);
68276+ atomic_inc_unchecked(&sk->sk_drops);
68277 kfree_skb(skb);
68278 return NET_RX_DROP;
68279 }
68280@@ -736,16 +736,20 @@ static int raw_init(struct sock *sk)
68281
68282 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
68283 {
68284+ struct icmp_filter filter;
68285+
68286 if (optlen > sizeof(struct icmp_filter))
68287 optlen = sizeof(struct icmp_filter);
68288- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
68289+ if (copy_from_user(&filter, optval, optlen))
68290 return -EFAULT;
68291+ raw_sk(sk)->filter = filter;
68292 return 0;
68293 }
68294
68295 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
68296 {
68297 int len, ret = -EFAULT;
68298+ struct icmp_filter filter;
68299
68300 if (get_user(len, optlen))
68301 goto out;
68302@@ -755,8 +759,9 @@ static int raw_geticmpfilter(struct sock
68303 if (len > sizeof(struct icmp_filter))
68304 len = sizeof(struct icmp_filter);
68305 ret = -EFAULT;
68306- if (put_user(len, optlen) ||
68307- copy_to_user(optval, &raw_sk(sk)->filter, len))
68308+ filter = raw_sk(sk)->filter;
68309+ if (put_user(len, optlen) || len > sizeof filter ||
68310+ copy_to_user(optval, &filter, len))
68311 goto out;
68312 ret = 0;
68313 out: return ret;
68314@@ -984,7 +989,13 @@ static void raw_sock_seq_show(struct seq
68315 sk_wmem_alloc_get(sp),
68316 sk_rmem_alloc_get(sp),
68317 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
68318- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
68319+ atomic_read(&sp->sk_refcnt),
68320+#ifdef CONFIG_GRKERNSEC_HIDESYM
68321+ NULL,
68322+#else
68323+ sp,
68324+#endif
68325+ atomic_read_unchecked(&sp->sk_drops));
68326 }
68327
68328 static int raw_seq_show(struct seq_file *seq, void *v)
68329diff -urNp linux-3.0.4/net/ipv4/route.c linux-3.0.4/net/ipv4/route.c
68330--- linux-3.0.4/net/ipv4/route.c 2011-08-23 21:44:40.000000000 -0400
68331+++ linux-3.0.4/net/ipv4/route.c 2011-08-23 21:47:56.000000000 -0400
68332@@ -304,7 +304,7 @@ static inline unsigned int rt_hash(__be3
68333
68334 static inline int rt_genid(struct net *net)
68335 {
68336- return atomic_read(&net->ipv4.rt_genid);
68337+ return atomic_read_unchecked(&net->ipv4.rt_genid);
68338 }
68339
68340 #ifdef CONFIG_PROC_FS
68341@@ -833,7 +833,7 @@ static void rt_cache_invalidate(struct n
68342 unsigned char shuffle;
68343
68344 get_random_bytes(&shuffle, sizeof(shuffle));
68345- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
68346+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
68347 }
68348
68349 /*
68350@@ -2834,7 +2834,7 @@ static int rt_fill_info(struct net *net,
68351 error = rt->dst.error;
68352 if (peer) {
68353 inet_peer_refcheck(rt->peer);
68354- id = atomic_read(&peer->ip_id_count) & 0xffff;
68355+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
68356 if (peer->tcp_ts_stamp) {
68357 ts = peer->tcp_ts;
68358 tsage = get_seconds() - peer->tcp_ts_stamp;
68359diff -urNp linux-3.0.4/net/ipv4/tcp.c linux-3.0.4/net/ipv4/tcp.c
68360--- linux-3.0.4/net/ipv4/tcp.c 2011-07-21 22:17:23.000000000 -0400
68361+++ linux-3.0.4/net/ipv4/tcp.c 2011-08-23 21:48:14.000000000 -0400
68362@@ -2122,6 +2122,8 @@ static int do_tcp_setsockopt(struct sock
68363 int val;
68364 int err = 0;
68365
68366+ pax_track_stack();
68367+
68368 /* These are data/string values, all the others are ints */
68369 switch (optname) {
68370 case TCP_CONGESTION: {
68371@@ -2501,6 +2503,8 @@ static int do_tcp_getsockopt(struct sock
68372 struct tcp_sock *tp = tcp_sk(sk);
68373 int val, len;
68374
68375+ pax_track_stack();
68376+
68377 if (get_user(len, optlen))
68378 return -EFAULT;
68379
68380diff -urNp linux-3.0.4/net/ipv4/tcp_ipv4.c linux-3.0.4/net/ipv4/tcp_ipv4.c
68381--- linux-3.0.4/net/ipv4/tcp_ipv4.c 2011-08-23 21:44:40.000000000 -0400
68382+++ linux-3.0.4/net/ipv4/tcp_ipv4.c 2011-08-23 21:48:14.000000000 -0400
68383@@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
68384 int sysctl_tcp_low_latency __read_mostly;
68385 EXPORT_SYMBOL(sysctl_tcp_low_latency);
68386
68387+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68388+extern int grsec_enable_blackhole;
68389+#endif
68390
68391 #ifdef CONFIG_TCP_MD5SIG
68392 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
68393@@ -1607,6 +1610,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
68394 return 0;
68395
68396 reset:
68397+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68398+ if (!grsec_enable_blackhole)
68399+#endif
68400 tcp_v4_send_reset(rsk, skb);
68401 discard:
68402 kfree_skb(skb);
68403@@ -1669,12 +1675,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
68404 TCP_SKB_CB(skb)->sacked = 0;
68405
68406 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
68407- if (!sk)
68408+ if (!sk) {
68409+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68410+ ret = 1;
68411+#endif
68412 goto no_tcp_socket;
68413-
68414+ }
68415 process:
68416- if (sk->sk_state == TCP_TIME_WAIT)
68417+ if (sk->sk_state == TCP_TIME_WAIT) {
68418+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68419+ ret = 2;
68420+#endif
68421 goto do_time_wait;
68422+ }
68423
68424 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
68425 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
68426@@ -1724,6 +1737,10 @@ no_tcp_socket:
68427 bad_packet:
68428 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
68429 } else {
68430+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68431+ if (!grsec_enable_blackhole || (ret == 1 &&
68432+ (skb->dev->flags & IFF_LOOPBACK)))
68433+#endif
68434 tcp_v4_send_reset(NULL, skb);
68435 }
68436
68437@@ -2388,7 +2405,11 @@ static void get_openreq4(struct sock *sk
68438 0, /* non standard timer */
68439 0, /* open_requests have no inode */
68440 atomic_read(&sk->sk_refcnt),
68441+#ifdef CONFIG_GRKERNSEC_HIDESYM
68442+ NULL,
68443+#else
68444 req,
68445+#endif
68446 len);
68447 }
68448
68449@@ -2438,7 +2459,12 @@ static void get_tcp4_sock(struct sock *s
68450 sock_i_uid(sk),
68451 icsk->icsk_probes_out,
68452 sock_i_ino(sk),
68453- atomic_read(&sk->sk_refcnt), sk,
68454+ atomic_read(&sk->sk_refcnt),
68455+#ifdef CONFIG_GRKERNSEC_HIDESYM
68456+ NULL,
68457+#else
68458+ sk,
68459+#endif
68460 jiffies_to_clock_t(icsk->icsk_rto),
68461 jiffies_to_clock_t(icsk->icsk_ack.ato),
68462 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
68463@@ -2466,7 +2492,13 @@ static void get_timewait4_sock(struct in
68464 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
68465 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
68466 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
68467- atomic_read(&tw->tw_refcnt), tw, len);
68468+ atomic_read(&tw->tw_refcnt),
68469+#ifdef CONFIG_GRKERNSEC_HIDESYM
68470+ NULL,
68471+#else
68472+ tw,
68473+#endif
68474+ len);
68475 }
68476
68477 #define TMPSZ 150
68478diff -urNp linux-3.0.4/net/ipv4/tcp_minisocks.c linux-3.0.4/net/ipv4/tcp_minisocks.c
68479--- linux-3.0.4/net/ipv4/tcp_minisocks.c 2011-07-21 22:17:23.000000000 -0400
68480+++ linux-3.0.4/net/ipv4/tcp_minisocks.c 2011-08-23 21:48:14.000000000 -0400
68481@@ -27,6 +27,10 @@
68482 #include <net/inet_common.h>
68483 #include <net/xfrm.h>
68484
68485+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68486+extern int grsec_enable_blackhole;
68487+#endif
68488+
68489 int sysctl_tcp_syncookies __read_mostly = 1;
68490 EXPORT_SYMBOL(sysctl_tcp_syncookies);
68491
68492@@ -745,6 +749,10 @@ listen_overflow:
68493
68494 embryonic_reset:
68495 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
68496+
68497+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68498+ if (!grsec_enable_blackhole)
68499+#endif
68500 if (!(flg & TCP_FLAG_RST))
68501 req->rsk_ops->send_reset(sk, skb);
68502
68503diff -urNp linux-3.0.4/net/ipv4/tcp_output.c linux-3.0.4/net/ipv4/tcp_output.c
68504--- linux-3.0.4/net/ipv4/tcp_output.c 2011-07-21 22:17:23.000000000 -0400
68505+++ linux-3.0.4/net/ipv4/tcp_output.c 2011-08-23 21:48:14.000000000 -0400
68506@@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
68507 int mss;
68508 int s_data_desired = 0;
68509
68510+ pax_track_stack();
68511+
68512 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
68513 s_data_desired = cvp->s_data_desired;
68514 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
68515diff -urNp linux-3.0.4/net/ipv4/tcp_probe.c linux-3.0.4/net/ipv4/tcp_probe.c
68516--- linux-3.0.4/net/ipv4/tcp_probe.c 2011-07-21 22:17:23.000000000 -0400
68517+++ linux-3.0.4/net/ipv4/tcp_probe.c 2011-08-23 21:47:56.000000000 -0400
68518@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
68519 if (cnt + width >= len)
68520 break;
68521
68522- if (copy_to_user(buf + cnt, tbuf, width))
68523+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
68524 return -EFAULT;
68525 cnt += width;
68526 }
68527diff -urNp linux-3.0.4/net/ipv4/tcp_timer.c linux-3.0.4/net/ipv4/tcp_timer.c
68528--- linux-3.0.4/net/ipv4/tcp_timer.c 2011-07-21 22:17:23.000000000 -0400
68529+++ linux-3.0.4/net/ipv4/tcp_timer.c 2011-08-23 21:48:14.000000000 -0400
68530@@ -22,6 +22,10 @@
68531 #include <linux/gfp.h>
68532 #include <net/tcp.h>
68533
68534+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68535+extern int grsec_lastack_retries;
68536+#endif
68537+
68538 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
68539 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
68540 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
68541@@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
68542 }
68543 }
68544
68545+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68546+ if ((sk->sk_state == TCP_LAST_ACK) &&
68547+ (grsec_lastack_retries > 0) &&
68548+ (grsec_lastack_retries < retry_until))
68549+ retry_until = grsec_lastack_retries;
68550+#endif
68551+
68552 if (retransmits_timed_out(sk, retry_until,
68553 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
68554 /* Has it gone just too far? */
68555diff -urNp linux-3.0.4/net/ipv4/udp.c linux-3.0.4/net/ipv4/udp.c
68556--- linux-3.0.4/net/ipv4/udp.c 2011-07-21 22:17:23.000000000 -0400
68557+++ linux-3.0.4/net/ipv4/udp.c 2011-08-23 21:48:14.000000000 -0400
68558@@ -86,6 +86,7 @@
68559 #include <linux/types.h>
68560 #include <linux/fcntl.h>
68561 #include <linux/module.h>
68562+#include <linux/security.h>
68563 #include <linux/socket.h>
68564 #include <linux/sockios.h>
68565 #include <linux/igmp.h>
68566@@ -107,6 +108,10 @@
68567 #include <net/xfrm.h>
68568 #include "udp_impl.h"
68569
68570+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68571+extern int grsec_enable_blackhole;
68572+#endif
68573+
68574 struct udp_table udp_table __read_mostly;
68575 EXPORT_SYMBOL(udp_table);
68576
68577@@ -564,6 +569,9 @@ found:
68578 return s;
68579 }
68580
68581+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
68582+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
68583+
68584 /*
68585 * This routine is called by the ICMP module when it gets some
68586 * sort of error condition. If err < 0 then the socket should
68587@@ -855,9 +863,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
68588 dport = usin->sin_port;
68589 if (dport == 0)
68590 return -EINVAL;
68591+
68592+ err = gr_search_udp_sendmsg(sk, usin);
68593+ if (err)
68594+ return err;
68595 } else {
68596 if (sk->sk_state != TCP_ESTABLISHED)
68597 return -EDESTADDRREQ;
68598+
68599+ err = gr_search_udp_sendmsg(sk, NULL);
68600+ if (err)
68601+ return err;
68602+
68603 daddr = inet->inet_daddr;
68604 dport = inet->inet_dport;
68605 /* Open fast path for connected socket.
68606@@ -1098,7 +1115,7 @@ static unsigned int first_packet_length(
68607 udp_lib_checksum_complete(skb)) {
68608 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
68609 IS_UDPLITE(sk));
68610- atomic_inc(&sk->sk_drops);
68611+ atomic_inc_unchecked(&sk->sk_drops);
68612 __skb_unlink(skb, rcvq);
68613 __skb_queue_tail(&list_kill, skb);
68614 }
68615@@ -1184,6 +1201,10 @@ try_again:
68616 if (!skb)
68617 goto out;
68618
68619+ err = gr_search_udp_recvmsg(sk, skb);
68620+ if (err)
68621+ goto out_free;
68622+
68623 ulen = skb->len - sizeof(struct udphdr);
68624 if (len > ulen)
68625 len = ulen;
68626@@ -1483,7 +1504,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
68627
68628 drop:
68629 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
68630- atomic_inc(&sk->sk_drops);
68631+ atomic_inc_unchecked(&sk->sk_drops);
68632 kfree_skb(skb);
68633 return -1;
68634 }
68635@@ -1502,7 +1523,7 @@ static void flush_stack(struct sock **st
68636 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
68637
68638 if (!skb1) {
68639- atomic_inc(&sk->sk_drops);
68640+ atomic_inc_unchecked(&sk->sk_drops);
68641 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
68642 IS_UDPLITE(sk));
68643 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
68644@@ -1671,6 +1692,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
68645 goto csum_error;
68646
68647 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
68648+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68649+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
68650+#endif
68651 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
68652
68653 /*
68654@@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock
68655 sk_wmem_alloc_get(sp),
68656 sk_rmem_alloc_get(sp),
68657 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
68658- atomic_read(&sp->sk_refcnt), sp,
68659- atomic_read(&sp->sk_drops), len);
68660+ atomic_read(&sp->sk_refcnt),
68661+#ifdef CONFIG_GRKERNSEC_HIDESYM
68662+ NULL,
68663+#else
68664+ sp,
68665+#endif
68666+ atomic_read_unchecked(&sp->sk_drops), len);
68667 }
68668
68669 int udp4_seq_show(struct seq_file *seq, void *v)
68670diff -urNp linux-3.0.4/net/ipv6/inet6_connection_sock.c linux-3.0.4/net/ipv6/inet6_connection_sock.c
68671--- linux-3.0.4/net/ipv6/inet6_connection_sock.c 2011-07-21 22:17:23.000000000 -0400
68672+++ linux-3.0.4/net/ipv6/inet6_connection_sock.c 2011-08-23 21:47:56.000000000 -0400
68673@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
68674 #ifdef CONFIG_XFRM
68675 {
68676 struct rt6_info *rt = (struct rt6_info *)dst;
68677- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
68678+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
68679 }
68680 #endif
68681 }
68682@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
68683 #ifdef CONFIG_XFRM
68684 if (dst) {
68685 struct rt6_info *rt = (struct rt6_info *)dst;
68686- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
68687+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
68688 __sk_dst_reset(sk);
68689 dst = NULL;
68690 }
68691diff -urNp linux-3.0.4/net/ipv6/ipv6_sockglue.c linux-3.0.4/net/ipv6/ipv6_sockglue.c
68692--- linux-3.0.4/net/ipv6/ipv6_sockglue.c 2011-07-21 22:17:23.000000000 -0400
68693+++ linux-3.0.4/net/ipv6/ipv6_sockglue.c 2011-08-23 21:48:14.000000000 -0400
68694@@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
68695 int val, valbool;
68696 int retv = -ENOPROTOOPT;
68697
68698+ pax_track_stack();
68699+
68700 if (optval == NULL)
68701 val=0;
68702 else {
68703@@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
68704 int len;
68705 int val;
68706
68707+ pax_track_stack();
68708+
68709 if (ip6_mroute_opt(optname))
68710 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
68711
68712diff -urNp linux-3.0.4/net/ipv6/raw.c linux-3.0.4/net/ipv6/raw.c
68713--- linux-3.0.4/net/ipv6/raw.c 2011-07-21 22:17:23.000000000 -0400
68714+++ linux-3.0.4/net/ipv6/raw.c 2011-08-23 21:48:14.000000000 -0400
68715@@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
68716 {
68717 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
68718 skb_checksum_complete(skb)) {
68719- atomic_inc(&sk->sk_drops);
68720+ atomic_inc_unchecked(&sk->sk_drops);
68721 kfree_skb(skb);
68722 return NET_RX_DROP;
68723 }
68724@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
68725 struct raw6_sock *rp = raw6_sk(sk);
68726
68727 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
68728- atomic_inc(&sk->sk_drops);
68729+ atomic_inc_unchecked(&sk->sk_drops);
68730 kfree_skb(skb);
68731 return NET_RX_DROP;
68732 }
68733@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
68734
68735 if (inet->hdrincl) {
68736 if (skb_checksum_complete(skb)) {
68737- atomic_inc(&sk->sk_drops);
68738+ atomic_inc_unchecked(&sk->sk_drops);
68739 kfree_skb(skb);
68740 return NET_RX_DROP;
68741 }
68742@@ -601,7 +601,7 @@ out:
68743 return err;
68744 }
68745
68746-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
68747+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
68748 struct flowi6 *fl6, struct dst_entry **dstp,
68749 unsigned int flags)
68750 {
68751@@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
68752 u16 proto;
68753 int err;
68754
68755+ pax_track_stack();
68756+
68757 /* Rough check on arithmetic overflow,
68758 better check is made in ip6_append_data().
68759 */
68760@@ -909,12 +911,15 @@ do_confirm:
68761 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
68762 char __user *optval, int optlen)
68763 {
68764+ struct icmp6_filter filter;
68765+
68766 switch (optname) {
68767 case ICMPV6_FILTER:
68768 if (optlen > sizeof(struct icmp6_filter))
68769 optlen = sizeof(struct icmp6_filter);
68770- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
68771+ if (copy_from_user(&filter, optval, optlen))
68772 return -EFAULT;
68773+ raw6_sk(sk)->filter = filter;
68774 return 0;
68775 default:
68776 return -ENOPROTOOPT;
68777@@ -927,6 +932,7 @@ static int rawv6_geticmpfilter(struct so
68778 char __user *optval, int __user *optlen)
68779 {
68780 int len;
68781+ struct icmp6_filter filter;
68782
68783 switch (optname) {
68784 case ICMPV6_FILTER:
68785@@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
68786 len = sizeof(struct icmp6_filter);
68787 if (put_user(len, optlen))
68788 return -EFAULT;
68789- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
68790+ filter = raw6_sk(sk)->filter;
68791+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
68792 return -EFAULT;
68793 return 0;
68794 default:
68795@@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
68796 0, 0L, 0,
68797 sock_i_uid(sp), 0,
68798 sock_i_ino(sp),
68799- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
68800+ atomic_read(&sp->sk_refcnt),
68801+#ifdef CONFIG_GRKERNSEC_HIDESYM
68802+ NULL,
68803+#else
68804+ sp,
68805+#endif
68806+ atomic_read_unchecked(&sp->sk_drops));
68807 }
68808
68809 static int raw6_seq_show(struct seq_file *seq, void *v)
68810diff -urNp linux-3.0.4/net/ipv6/tcp_ipv6.c linux-3.0.4/net/ipv6/tcp_ipv6.c
68811--- linux-3.0.4/net/ipv6/tcp_ipv6.c 2011-08-23 21:44:40.000000000 -0400
68812+++ linux-3.0.4/net/ipv6/tcp_ipv6.c 2011-08-23 21:48:14.000000000 -0400
68813@@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
68814 }
68815 #endif
68816
68817+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68818+extern int grsec_enable_blackhole;
68819+#endif
68820+
68821 static void tcp_v6_hash(struct sock *sk)
68822 {
68823 if (sk->sk_state != TCP_CLOSE) {
68824@@ -1662,6 +1666,9 @@ static int tcp_v6_do_rcv(struct sock *sk
68825 return 0;
68826
68827 reset:
68828+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68829+ if (!grsec_enable_blackhole)
68830+#endif
68831 tcp_v6_send_reset(sk, skb);
68832 discard:
68833 if (opt_skb)
68834@@ -1741,12 +1748,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
68835 TCP_SKB_CB(skb)->sacked = 0;
68836
68837 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
68838- if (!sk)
68839+ if (!sk) {
68840+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68841+ ret = 1;
68842+#endif
68843 goto no_tcp_socket;
68844+ }
68845
68846 process:
68847- if (sk->sk_state == TCP_TIME_WAIT)
68848+ if (sk->sk_state == TCP_TIME_WAIT) {
68849+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68850+ ret = 2;
68851+#endif
68852 goto do_time_wait;
68853+ }
68854
68855 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
68856 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
68857@@ -1794,6 +1809,10 @@ no_tcp_socket:
68858 bad_packet:
68859 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
68860 } else {
68861+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68862+ if (!grsec_enable_blackhole || (ret == 1 &&
68863+ (skb->dev->flags & IFF_LOOPBACK)))
68864+#endif
68865 tcp_v6_send_reset(NULL, skb);
68866 }
68867
68868@@ -2054,7 +2073,13 @@ static void get_openreq6(struct seq_file
68869 uid,
68870 0, /* non standard timer */
68871 0, /* open_requests have no inode */
68872- 0, req);
68873+ 0,
68874+#ifdef CONFIG_GRKERNSEC_HIDESYM
68875+ NULL
68876+#else
68877+ req
68878+#endif
68879+ );
68880 }
68881
68882 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
68883@@ -2104,7 +2129,12 @@ static void get_tcp6_sock(struct seq_fil
68884 sock_i_uid(sp),
68885 icsk->icsk_probes_out,
68886 sock_i_ino(sp),
68887- atomic_read(&sp->sk_refcnt), sp,
68888+ atomic_read(&sp->sk_refcnt),
68889+#ifdef CONFIG_GRKERNSEC_HIDESYM
68890+ NULL,
68891+#else
68892+ sp,
68893+#endif
68894 jiffies_to_clock_t(icsk->icsk_rto),
68895 jiffies_to_clock_t(icsk->icsk_ack.ato),
68896 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
68897@@ -2139,7 +2169,13 @@ static void get_timewait6_sock(struct se
68898 dest->s6_addr32[2], dest->s6_addr32[3], destp,
68899 tw->tw_substate, 0, 0,
68900 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
68901- atomic_read(&tw->tw_refcnt), tw);
68902+ atomic_read(&tw->tw_refcnt),
68903+#ifdef CONFIG_GRKERNSEC_HIDESYM
68904+ NULL
68905+#else
68906+ tw
68907+#endif
68908+ );
68909 }
68910
68911 static int tcp6_seq_show(struct seq_file *seq, void *v)
68912diff -urNp linux-3.0.4/net/ipv6/udp.c linux-3.0.4/net/ipv6/udp.c
68913--- linux-3.0.4/net/ipv6/udp.c 2011-08-23 21:44:40.000000000 -0400
68914+++ linux-3.0.4/net/ipv6/udp.c 2011-08-23 21:48:14.000000000 -0400
68915@@ -50,6 +50,10 @@
68916 #include <linux/seq_file.h>
68917 #include "udp_impl.h"
68918
68919+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68920+extern int grsec_enable_blackhole;
68921+#endif
68922+
68923 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
68924 {
68925 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
68926@@ -548,7 +552,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
68927
68928 return 0;
68929 drop:
68930- atomic_inc(&sk->sk_drops);
68931+ atomic_inc_unchecked(&sk->sk_drops);
68932 drop_no_sk_drops_inc:
68933 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
68934 kfree_skb(skb);
68935@@ -624,7 +628,7 @@ static void flush_stack(struct sock **st
68936 continue;
68937 }
68938 drop:
68939- atomic_inc(&sk->sk_drops);
68940+ atomic_inc_unchecked(&sk->sk_drops);
68941 UDP6_INC_STATS_BH(sock_net(sk),
68942 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
68943 UDP6_INC_STATS_BH(sock_net(sk),
68944@@ -779,6 +783,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
68945 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
68946 proto == IPPROTO_UDPLITE);
68947
68948+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68949+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
68950+#endif
68951 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
68952
68953 kfree_skb(skb);
68954@@ -795,7 +802,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
68955 if (!sock_owned_by_user(sk))
68956 udpv6_queue_rcv_skb(sk, skb);
68957 else if (sk_add_backlog(sk, skb)) {
68958- atomic_inc(&sk->sk_drops);
68959+ atomic_inc_unchecked(&sk->sk_drops);
68960 bh_unlock_sock(sk);
68961 sock_put(sk);
68962 goto discard;
68963@@ -1406,8 +1413,13 @@ static void udp6_sock_seq_show(struct se
68964 0, 0L, 0,
68965 sock_i_uid(sp), 0,
68966 sock_i_ino(sp),
68967- atomic_read(&sp->sk_refcnt), sp,
68968- atomic_read(&sp->sk_drops));
68969+ atomic_read(&sp->sk_refcnt),
68970+#ifdef CONFIG_GRKERNSEC_HIDESYM
68971+ NULL,
68972+#else
68973+ sp,
68974+#endif
68975+ atomic_read_unchecked(&sp->sk_drops));
68976 }
68977
68978 int udp6_seq_show(struct seq_file *seq, void *v)
68979diff -urNp linux-3.0.4/net/irda/ircomm/ircomm_tty.c linux-3.0.4/net/irda/ircomm/ircomm_tty.c
68980--- linux-3.0.4/net/irda/ircomm/ircomm_tty.c 2011-07-21 22:17:23.000000000 -0400
68981+++ linux-3.0.4/net/irda/ircomm/ircomm_tty.c 2011-08-23 21:47:56.000000000 -0400
68982@@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(st
68983 add_wait_queue(&self->open_wait, &wait);
68984
68985 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
68986- __FILE__,__LINE__, tty->driver->name, self->open_count );
68987+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
68988
68989 /* As far as I can see, we protect open_count - Jean II */
68990 spin_lock_irqsave(&self->spinlock, flags);
68991 if (!tty_hung_up_p(filp)) {
68992 extra_count = 1;
68993- self->open_count--;
68994+ local_dec(&self->open_count);
68995 }
68996 spin_unlock_irqrestore(&self->spinlock, flags);
68997- self->blocked_open++;
68998+ local_inc(&self->blocked_open);
68999
69000 while (1) {
69001 if (tty->termios->c_cflag & CBAUD) {
69002@@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(st
69003 }
69004
69005 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
69006- __FILE__,__LINE__, tty->driver->name, self->open_count );
69007+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
69008
69009 schedule();
69010 }
69011@@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(st
69012 if (extra_count) {
69013 /* ++ is not atomic, so this should be protected - Jean II */
69014 spin_lock_irqsave(&self->spinlock, flags);
69015- self->open_count++;
69016+ local_inc(&self->open_count);
69017 spin_unlock_irqrestore(&self->spinlock, flags);
69018 }
69019- self->blocked_open--;
69020+ local_dec(&self->blocked_open);
69021
69022 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
69023- __FILE__,__LINE__, tty->driver->name, self->open_count);
69024+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
69025
69026 if (!retval)
69027 self->flags |= ASYNC_NORMAL_ACTIVE;
69028@@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_st
69029 }
69030 /* ++ is not atomic, so this should be protected - Jean II */
69031 spin_lock_irqsave(&self->spinlock, flags);
69032- self->open_count++;
69033+ local_inc(&self->open_count);
69034
69035 tty->driver_data = self;
69036 self->tty = tty;
69037 spin_unlock_irqrestore(&self->spinlock, flags);
69038
69039 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
69040- self->line, self->open_count);
69041+ self->line, local_read(&self->open_count));
69042
69043 /* Not really used by us, but lets do it anyway */
69044 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
69045@@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_
69046 return;
69047 }
69048
69049- if ((tty->count == 1) && (self->open_count != 1)) {
69050+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
69051 /*
69052 * Uh, oh. tty->count is 1, which means that the tty
69053 * structure will be freed. state->count should always
69054@@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_
69055 */
69056 IRDA_DEBUG(0, "%s(), bad serial port count; "
69057 "tty->count is 1, state->count is %d\n", __func__ ,
69058- self->open_count);
69059- self->open_count = 1;
69060+ local_read(&self->open_count));
69061+ local_set(&self->open_count, 1);
69062 }
69063
69064- if (--self->open_count < 0) {
69065+ if (local_dec_return(&self->open_count) < 0) {
69066 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
69067- __func__, self->line, self->open_count);
69068- self->open_count = 0;
69069+ __func__, self->line, local_read(&self->open_count));
69070+ local_set(&self->open_count, 0);
69071 }
69072- if (self->open_count) {
69073+ if (local_read(&self->open_count)) {
69074 spin_unlock_irqrestore(&self->spinlock, flags);
69075
69076 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
69077@@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_
69078 tty->closing = 0;
69079 self->tty = NULL;
69080
69081- if (self->blocked_open) {
69082+ if (local_read(&self->blocked_open)) {
69083 if (self->close_delay)
69084 schedule_timeout_interruptible(self->close_delay);
69085 wake_up_interruptible(&self->open_wait);
69086@@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty
69087 spin_lock_irqsave(&self->spinlock, flags);
69088 self->flags &= ~ASYNC_NORMAL_ACTIVE;
69089 self->tty = NULL;
69090- self->open_count = 0;
69091+ local_set(&self->open_count, 0);
69092 spin_unlock_irqrestore(&self->spinlock, flags);
69093
69094 wake_up_interruptible(&self->open_wait);
69095@@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct
69096 seq_putc(m, '\n');
69097
69098 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
69099- seq_printf(m, "Open count: %d\n", self->open_count);
69100+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
69101 seq_printf(m, "Max data size: %d\n", self->max_data_size);
69102 seq_printf(m, "Max header size: %d\n", self->max_header_size);
69103
69104diff -urNp linux-3.0.4/net/iucv/af_iucv.c linux-3.0.4/net/iucv/af_iucv.c
69105--- linux-3.0.4/net/iucv/af_iucv.c 2011-07-21 22:17:23.000000000 -0400
69106+++ linux-3.0.4/net/iucv/af_iucv.c 2011-08-23 21:47:56.000000000 -0400
69107@@ -648,10 +648,10 @@ static int iucv_sock_autobind(struct soc
69108
69109 write_lock_bh(&iucv_sk_list.lock);
69110
69111- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
69112+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
69113 while (__iucv_get_sock_by_name(name)) {
69114 sprintf(name, "%08x",
69115- atomic_inc_return(&iucv_sk_list.autobind_name));
69116+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
69117 }
69118
69119 write_unlock_bh(&iucv_sk_list.lock);
69120diff -urNp linux-3.0.4/net/key/af_key.c linux-3.0.4/net/key/af_key.c
69121--- linux-3.0.4/net/key/af_key.c 2011-07-21 22:17:23.000000000 -0400
69122+++ linux-3.0.4/net/key/af_key.c 2011-08-23 21:48:14.000000000 -0400
69123@@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
69124 struct xfrm_migrate m[XFRM_MAX_DEPTH];
69125 struct xfrm_kmaddress k;
69126
69127+ pax_track_stack();
69128+
69129 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
69130 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
69131 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
69132@@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
69133 static u32 get_acqseq(void)
69134 {
69135 u32 res;
69136- static atomic_t acqseq;
69137+ static atomic_unchecked_t acqseq;
69138
69139 do {
69140- res = atomic_inc_return(&acqseq);
69141+ res = atomic_inc_return_unchecked(&acqseq);
69142 } while (!res);
69143 return res;
69144 }
69145diff -urNp linux-3.0.4/net/lapb/lapb_iface.c linux-3.0.4/net/lapb/lapb_iface.c
69146--- linux-3.0.4/net/lapb/lapb_iface.c 2011-07-21 22:17:23.000000000 -0400
69147+++ linux-3.0.4/net/lapb/lapb_iface.c 2011-08-23 21:47:56.000000000 -0400
69148@@ -158,7 +158,7 @@ int lapb_register(struct net_device *dev
69149 goto out;
69150
69151 lapb->dev = dev;
69152- lapb->callbacks = *callbacks;
69153+ lapb->callbacks = callbacks;
69154
69155 __lapb_insert_cb(lapb);
69156
69157@@ -380,32 +380,32 @@ int lapb_data_received(struct net_device
69158
69159 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
69160 {
69161- if (lapb->callbacks.connect_confirmation)
69162- lapb->callbacks.connect_confirmation(lapb->dev, reason);
69163+ if (lapb->callbacks->connect_confirmation)
69164+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
69165 }
69166
69167 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
69168 {
69169- if (lapb->callbacks.connect_indication)
69170- lapb->callbacks.connect_indication(lapb->dev, reason);
69171+ if (lapb->callbacks->connect_indication)
69172+ lapb->callbacks->connect_indication(lapb->dev, reason);
69173 }
69174
69175 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
69176 {
69177- if (lapb->callbacks.disconnect_confirmation)
69178- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
69179+ if (lapb->callbacks->disconnect_confirmation)
69180+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
69181 }
69182
69183 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
69184 {
69185- if (lapb->callbacks.disconnect_indication)
69186- lapb->callbacks.disconnect_indication(lapb->dev, reason);
69187+ if (lapb->callbacks->disconnect_indication)
69188+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
69189 }
69190
69191 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
69192 {
69193- if (lapb->callbacks.data_indication)
69194- return lapb->callbacks.data_indication(lapb->dev, skb);
69195+ if (lapb->callbacks->data_indication)
69196+ return lapb->callbacks->data_indication(lapb->dev, skb);
69197
69198 kfree_skb(skb);
69199 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
69200@@ -415,8 +415,8 @@ int lapb_data_transmit(struct lapb_cb *l
69201 {
69202 int used = 0;
69203
69204- if (lapb->callbacks.data_transmit) {
69205- lapb->callbacks.data_transmit(lapb->dev, skb);
69206+ if (lapb->callbacks->data_transmit) {
69207+ lapb->callbacks->data_transmit(lapb->dev, skb);
69208 used = 1;
69209 }
69210
69211diff -urNp linux-3.0.4/net/mac80211/debugfs_sta.c linux-3.0.4/net/mac80211/debugfs_sta.c
69212--- linux-3.0.4/net/mac80211/debugfs_sta.c 2011-07-21 22:17:23.000000000 -0400
69213+++ linux-3.0.4/net/mac80211/debugfs_sta.c 2011-08-23 21:48:14.000000000 -0400
69214@@ -140,6 +140,8 @@ static ssize_t sta_agg_status_read(struc
69215 struct tid_ampdu_rx *tid_rx;
69216 struct tid_ampdu_tx *tid_tx;
69217
69218+ pax_track_stack();
69219+
69220 rcu_read_lock();
69221
69222 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
69223@@ -240,6 +242,8 @@ static ssize_t sta_ht_capa_read(struct f
69224 struct sta_info *sta = file->private_data;
69225 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
69226
69227+ pax_track_stack();
69228+
69229 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
69230 htc->ht_supported ? "" : "not ");
69231 if (htc->ht_supported) {
69232diff -urNp linux-3.0.4/net/mac80211/ieee80211_i.h linux-3.0.4/net/mac80211/ieee80211_i.h
69233--- linux-3.0.4/net/mac80211/ieee80211_i.h 2011-07-21 22:17:23.000000000 -0400
69234+++ linux-3.0.4/net/mac80211/ieee80211_i.h 2011-08-23 21:47:56.000000000 -0400
69235@@ -27,6 +27,7 @@
69236 #include <net/ieee80211_radiotap.h>
69237 #include <net/cfg80211.h>
69238 #include <net/mac80211.h>
69239+#include <asm/local.h>
69240 #include "key.h"
69241 #include "sta_info.h"
69242
69243@@ -721,7 +722,7 @@ struct ieee80211_local {
69244 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
69245 spinlock_t queue_stop_reason_lock;
69246
69247- int open_count;
69248+ local_t open_count;
69249 int monitors, cooked_mntrs;
69250 /* number of interfaces with corresponding FIF_ flags */
69251 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
69252diff -urNp linux-3.0.4/net/mac80211/iface.c linux-3.0.4/net/mac80211/iface.c
69253--- linux-3.0.4/net/mac80211/iface.c 2011-08-23 21:44:40.000000000 -0400
69254+++ linux-3.0.4/net/mac80211/iface.c 2011-08-23 21:47:56.000000000 -0400
69255@@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
69256 break;
69257 }
69258
69259- if (local->open_count == 0) {
69260+ if (local_read(&local->open_count) == 0) {
69261 res = drv_start(local);
69262 if (res)
69263 goto err_del_bss;
69264@@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
69265 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
69266
69267 if (!is_valid_ether_addr(dev->dev_addr)) {
69268- if (!local->open_count)
69269+ if (!local_read(&local->open_count))
69270 drv_stop(local);
69271 return -EADDRNOTAVAIL;
69272 }
69273@@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
69274 mutex_unlock(&local->mtx);
69275
69276 if (coming_up)
69277- local->open_count++;
69278+ local_inc(&local->open_count);
69279
69280 if (hw_reconf_flags) {
69281 ieee80211_hw_config(local, hw_reconf_flags);
69282@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
69283 err_del_interface:
69284 drv_remove_interface(local, &sdata->vif);
69285 err_stop:
69286- if (!local->open_count)
69287+ if (!local_read(&local->open_count))
69288 drv_stop(local);
69289 err_del_bss:
69290 sdata->bss = NULL;
69291@@ -475,7 +475,7 @@ static void ieee80211_do_stop(struct iee
69292 }
69293
69294 if (going_down)
69295- local->open_count--;
69296+ local_dec(&local->open_count);
69297
69298 switch (sdata->vif.type) {
69299 case NL80211_IFTYPE_AP_VLAN:
69300@@ -534,7 +534,7 @@ static void ieee80211_do_stop(struct iee
69301
69302 ieee80211_recalc_ps(local, -1);
69303
69304- if (local->open_count == 0) {
69305+ if (local_read(&local->open_count) == 0) {
69306 if (local->ops->napi_poll)
69307 napi_disable(&local->napi);
69308 ieee80211_clear_tx_pending(local);
69309diff -urNp linux-3.0.4/net/mac80211/main.c linux-3.0.4/net/mac80211/main.c
69310--- linux-3.0.4/net/mac80211/main.c 2011-07-21 22:17:23.000000000 -0400
69311+++ linux-3.0.4/net/mac80211/main.c 2011-08-23 21:47:56.000000000 -0400
69312@@ -209,7 +209,7 @@ int ieee80211_hw_config(struct ieee80211
69313 local->hw.conf.power_level = power;
69314 }
69315
69316- if (changed && local->open_count) {
69317+ if (changed && local_read(&local->open_count)) {
69318 ret = drv_config(local, changed);
69319 /*
69320 * Goal:
69321diff -urNp linux-3.0.4/net/mac80211/mlme.c linux-3.0.4/net/mac80211/mlme.c
69322--- linux-3.0.4/net/mac80211/mlme.c 2011-08-23 21:44:40.000000000 -0400
69323+++ linux-3.0.4/net/mac80211/mlme.c 2011-08-23 21:48:14.000000000 -0400
69324@@ -1444,6 +1444,8 @@ static bool ieee80211_assoc_success(stru
69325 bool have_higher_than_11mbit = false;
69326 u16 ap_ht_cap_flags;
69327
69328+ pax_track_stack();
69329+
69330 /* AssocResp and ReassocResp have identical structure */
69331
69332 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
69333diff -urNp linux-3.0.4/net/mac80211/pm.c linux-3.0.4/net/mac80211/pm.c
69334--- linux-3.0.4/net/mac80211/pm.c 2011-07-21 22:17:23.000000000 -0400
69335+++ linux-3.0.4/net/mac80211/pm.c 2011-08-23 21:47:56.000000000 -0400
69336@@ -47,7 +47,7 @@ int __ieee80211_suspend(struct ieee80211
69337 cancel_work_sync(&local->dynamic_ps_enable_work);
69338 del_timer_sync(&local->dynamic_ps_timer);
69339
69340- local->wowlan = wowlan && local->open_count;
69341+ local->wowlan = wowlan && local_read(&local->open_count);
69342 if (local->wowlan) {
69343 int err = drv_suspend(local, wowlan);
69344 if (err) {
69345@@ -111,7 +111,7 @@ int __ieee80211_suspend(struct ieee80211
69346 }
69347
69348 /* stop hardware - this must stop RX */
69349- if (local->open_count)
69350+ if (local_read(&local->open_count))
69351 ieee80211_stop_device(local);
69352
69353 suspend:
69354diff -urNp linux-3.0.4/net/mac80211/rate.c linux-3.0.4/net/mac80211/rate.c
69355--- linux-3.0.4/net/mac80211/rate.c 2011-07-21 22:17:23.000000000 -0400
69356+++ linux-3.0.4/net/mac80211/rate.c 2011-08-23 21:47:56.000000000 -0400
69357@@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
69358
69359 ASSERT_RTNL();
69360
69361- if (local->open_count)
69362+ if (local_read(&local->open_count))
69363 return -EBUSY;
69364
69365 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
69366diff -urNp linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c
69367--- linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c 2011-07-21 22:17:23.000000000 -0400
69368+++ linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c 2011-08-23 21:47:56.000000000 -0400
69369@@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
69370
69371 spin_unlock_irqrestore(&events->lock, status);
69372
69373- if (copy_to_user(buf, pb, p))
69374+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
69375 return -EFAULT;
69376
69377 return p;
69378diff -urNp linux-3.0.4/net/mac80211/util.c linux-3.0.4/net/mac80211/util.c
69379--- linux-3.0.4/net/mac80211/util.c 2011-07-21 22:17:23.000000000 -0400
69380+++ linux-3.0.4/net/mac80211/util.c 2011-08-23 21:47:56.000000000 -0400
69381@@ -1147,7 +1147,7 @@ int ieee80211_reconfig(struct ieee80211_
69382 #endif
69383
69384 /* restart hardware */
69385- if (local->open_count) {
69386+ if (local_read(&local->open_count)) {
69387 /*
69388 * Upon resume hardware can sometimes be goofy due to
69389 * various platform / driver / bus issues, so restarting
69390diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c
69391--- linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c 2011-07-21 22:17:23.000000000 -0400
69392+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c 2011-08-23 21:47:56.000000000 -0400
69393@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
69394 /* Increase the refcnt counter of the dest */
69395 atomic_inc(&dest->refcnt);
69396
69397- conn_flags = atomic_read(&dest->conn_flags);
69398+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
69399 if (cp->protocol != IPPROTO_UDP)
69400 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
69401 /* Bind with the destination and its corresponding transmitter */
69402@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
69403 atomic_set(&cp->refcnt, 1);
69404
69405 atomic_set(&cp->n_control, 0);
69406- atomic_set(&cp->in_pkts, 0);
69407+ atomic_set_unchecked(&cp->in_pkts, 0);
69408
69409 atomic_inc(&ipvs->conn_count);
69410 if (flags & IP_VS_CONN_F_NO_CPORT)
69411@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip
69412
69413 /* Don't drop the entry if its number of incoming packets is not
69414 located in [0, 8] */
69415- i = atomic_read(&cp->in_pkts);
69416+ i = atomic_read_unchecked(&cp->in_pkts);
69417 if (i > 8 || i < 0) return 0;
69418
69419 if (!todrop_rate[i]) return 0;
69420diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c
69421--- linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c 2011-07-21 22:17:23.000000000 -0400
69422+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c 2011-08-23 21:47:56.000000000 -0400
69423@@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
69424 ret = cp->packet_xmit(skb, cp, pd->pp);
69425 /* do not touch skb anymore */
69426
69427- atomic_inc(&cp->in_pkts);
69428+ atomic_inc_unchecked(&cp->in_pkts);
69429 ip_vs_conn_put(cp);
69430 return ret;
69431 }
69432@@ -1613,7 +1613,7 @@ ip_vs_in(unsigned int hooknum, struct sk
69433 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
69434 pkts = sysctl_sync_threshold(ipvs);
69435 else
69436- pkts = atomic_add_return(1, &cp->in_pkts);
69437+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
69438
69439 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
69440 cp->protocol == IPPROTO_SCTP) {
69441diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c
69442--- linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c 2011-08-23 21:44:40.000000000 -0400
69443+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c 2011-08-23 21:48:14.000000000 -0400
69444@@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
69445 ip_vs_rs_hash(ipvs, dest);
69446 write_unlock_bh(&ipvs->rs_lock);
69447 }
69448- atomic_set(&dest->conn_flags, conn_flags);
69449+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
69450
69451 /* bind the service */
69452 if (!dest->svc) {
69453@@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
69454 " %-7s %-6d %-10d %-10d\n",
69455 &dest->addr.in6,
69456 ntohs(dest->port),
69457- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
69458+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
69459 atomic_read(&dest->weight),
69460 atomic_read(&dest->activeconns),
69461 atomic_read(&dest->inactconns));
69462@@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
69463 "%-7s %-6d %-10d %-10d\n",
69464 ntohl(dest->addr.ip),
69465 ntohs(dest->port),
69466- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
69467+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
69468 atomic_read(&dest->weight),
69469 atomic_read(&dest->activeconns),
69470 atomic_read(&dest->inactconns));
69471@@ -2284,6 +2284,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
69472 struct ip_vs_dest_user *udest_compat;
69473 struct ip_vs_dest_user_kern udest;
69474
69475+ pax_track_stack();
69476+
69477 if (!capable(CAP_NET_ADMIN))
69478 return -EPERM;
69479
69480@@ -2498,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net
69481
69482 entry.addr = dest->addr.ip;
69483 entry.port = dest->port;
69484- entry.conn_flags = atomic_read(&dest->conn_flags);
69485+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
69486 entry.weight = atomic_read(&dest->weight);
69487 entry.u_threshold = dest->u_threshold;
69488 entry.l_threshold = dest->l_threshold;
69489@@ -3026,7 +3028,7 @@ static int ip_vs_genl_fill_dest(struct s
69490 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
69491
69492 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
69493- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
69494+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
69495 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
69496 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
69497 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
69498diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c
69499--- linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c 2011-07-21 22:17:23.000000000 -0400
69500+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c 2011-08-23 21:47:56.000000000 -0400
69501@@ -648,7 +648,7 @@ control:
69502 * i.e only increment in_pkts for Templates.
69503 */
69504 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
69505- int pkts = atomic_add_return(1, &cp->in_pkts);
69506+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
69507
69508 if (pkts % sysctl_sync_period(ipvs) != 1)
69509 return;
69510@@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
69511
69512 if (opt)
69513 memcpy(&cp->in_seq, opt, sizeof(*opt));
69514- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
69515+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
69516 cp->state = state;
69517 cp->old_state = cp->state;
69518 /*
69519diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c
69520--- linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c 2011-07-21 22:17:23.000000000 -0400
69521+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c 2011-08-23 21:47:56.000000000 -0400
69522@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
69523 else
69524 rc = NF_ACCEPT;
69525 /* do not touch skb anymore */
69526- atomic_inc(&cp->in_pkts);
69527+ atomic_inc_unchecked(&cp->in_pkts);
69528 goto out;
69529 }
69530
69531@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
69532 else
69533 rc = NF_ACCEPT;
69534 /* do not touch skb anymore */
69535- atomic_inc(&cp->in_pkts);
69536+ atomic_inc_unchecked(&cp->in_pkts);
69537 goto out;
69538 }
69539
69540diff -urNp linux-3.0.4/net/netfilter/Kconfig linux-3.0.4/net/netfilter/Kconfig
69541--- linux-3.0.4/net/netfilter/Kconfig 2011-07-21 22:17:23.000000000 -0400
69542+++ linux-3.0.4/net/netfilter/Kconfig 2011-08-23 21:48:14.000000000 -0400
69543@@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
69544
69545 To compile it as a module, choose M here. If unsure, say N.
69546
69547+config NETFILTER_XT_MATCH_GRADM
69548+ tristate '"gradm" match support'
69549+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
69550+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
69551+ ---help---
69552+ The gradm match allows to match on grsecurity RBAC being enabled.
69553+ It is useful when iptables rules are applied early on bootup to
69554+ prevent connections to the machine (except from a trusted host)
69555+ while the RBAC system is disabled.
69556+
69557 config NETFILTER_XT_MATCH_HASHLIMIT
69558 tristate '"hashlimit" match support'
69559 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
69560diff -urNp linux-3.0.4/net/netfilter/Makefile linux-3.0.4/net/netfilter/Makefile
69561--- linux-3.0.4/net/netfilter/Makefile 2011-07-21 22:17:23.000000000 -0400
69562+++ linux-3.0.4/net/netfilter/Makefile 2011-08-23 21:48:14.000000000 -0400
69563@@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
69564 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
69565 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
69566 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
69567+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
69568 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
69569 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
69570 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
69571diff -urNp linux-3.0.4/net/netfilter/nfnetlink_log.c linux-3.0.4/net/netfilter/nfnetlink_log.c
69572--- linux-3.0.4/net/netfilter/nfnetlink_log.c 2011-07-21 22:17:23.000000000 -0400
69573+++ linux-3.0.4/net/netfilter/nfnetlink_log.c 2011-08-23 21:47:56.000000000 -0400
69574@@ -70,7 +70,7 @@ struct nfulnl_instance {
69575 };
69576
69577 static DEFINE_SPINLOCK(instances_lock);
69578-static atomic_t global_seq;
69579+static atomic_unchecked_t global_seq;
69580
69581 #define INSTANCE_BUCKETS 16
69582 static struct hlist_head instance_table[INSTANCE_BUCKETS];
69583@@ -505,7 +505,7 @@ __build_packet_message(struct nfulnl_ins
69584 /* global sequence number */
69585 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
69586 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
69587- htonl(atomic_inc_return(&global_seq)));
69588+ htonl(atomic_inc_return_unchecked(&global_seq)));
69589
69590 if (data_len) {
69591 struct nlattr *nla;
69592diff -urNp linux-3.0.4/net/netfilter/nfnetlink_queue.c linux-3.0.4/net/netfilter/nfnetlink_queue.c
69593--- linux-3.0.4/net/netfilter/nfnetlink_queue.c 2011-07-21 22:17:23.000000000 -0400
69594+++ linux-3.0.4/net/netfilter/nfnetlink_queue.c 2011-08-23 21:47:56.000000000 -0400
69595@@ -58,7 +58,7 @@ struct nfqnl_instance {
69596 */
69597 spinlock_t lock;
69598 unsigned int queue_total;
69599- atomic_t id_sequence; /* 'sequence' of pkt ids */
69600+ atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
69601 struct list_head queue_list; /* packets in queue */
69602 };
69603
69604@@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
69605 nfmsg->version = NFNETLINK_V0;
69606 nfmsg->res_id = htons(queue->queue_num);
69607
69608- entry->id = atomic_inc_return(&queue->id_sequence);
69609+ entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
69610 pmsg.packet_id = htonl(entry->id);
69611 pmsg.hw_protocol = entskb->protocol;
69612 pmsg.hook = entry->hook;
69613@@ -870,7 +870,7 @@ static int seq_show(struct seq_file *s,
69614 inst->peer_pid, inst->queue_total,
69615 inst->copy_mode, inst->copy_range,
69616 inst->queue_dropped, inst->queue_user_dropped,
69617- atomic_read(&inst->id_sequence), 1);
69618+ atomic_read_unchecked(&inst->id_sequence), 1);
69619 }
69620
69621 static const struct seq_operations nfqnl_seq_ops = {
69622diff -urNp linux-3.0.4/net/netfilter/xt_gradm.c linux-3.0.4/net/netfilter/xt_gradm.c
69623--- linux-3.0.4/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
69624+++ linux-3.0.4/net/netfilter/xt_gradm.c 2011-08-23 21:48:14.000000000 -0400
69625@@ -0,0 +1,51 @@
69626+/*
69627+ * gradm match for netfilter
69628