]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-3.0.4-201109150655.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-3.0.4-201109150655.patch
CommitLineData
e4221604
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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:26.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-09-02 18:11:26.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-09-02 18:11:21.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-09-02 18:11:26.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-09-02 18:11:26.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-09-02 18:11:26.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:26.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:21.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-09-02 18:11:26.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-09-02 18:11:21.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-09-14 09:16:46.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,13 @@ 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 set_fs_root(current->fs, &path);
41983+
41984+ gr_handle_chroot_chdir(&path);
41985+
41986 error = 0;
41987 dput_and_out:
41988 path_put(&path);
41989@@ -466,12 +488,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
41990 err = mnt_want_write_file(file);
41991 if (err)
41992 goto out_putf;
41993+
41994 mutex_lock(&inode->i_mutex);
41995+
41996+ if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
41997+ err = -EACCES;
41998+ goto out_unlock;
41999+ }
42000+
42001 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
42002 if (err)
42003 goto out_unlock;
42004 if (mode == (mode_t) -1)
42005 mode = inode->i_mode;
42006+
42007+ if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
42008+ err = -EACCES;
42009+ goto out_unlock;
42010+ }
42011+
42012 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
42013 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
42014 err = notify_change(dentry, &newattrs);
42015@@ -499,12 +534,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
42016 error = mnt_want_write(path.mnt);
42017 if (error)
42018 goto dput_and_out;
42019+
42020 mutex_lock(&inode->i_mutex);
42021+
42022+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
42023+ error = -EACCES;
42024+ goto out_unlock;
42025+ }
42026+
42027 error = security_path_chmod(path.dentry, path.mnt, mode);
42028 if (error)
42029 goto out_unlock;
42030 if (mode == (mode_t) -1)
42031 mode = inode->i_mode;
42032+
42033+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
42034+ error = -EACCES;
42035+ goto out_unlock;
42036+ }
42037+
42038 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
42039 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
42040 error = notify_change(path.dentry, &newattrs);
42041@@ -528,6 +576,9 @@ static int chown_common(struct path *pat
42042 int error;
42043 struct iattr newattrs;
42044
42045+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
42046+ return -EACCES;
42047+
42048 newattrs.ia_valid = ATTR_CTIME;
42049 if (user != (uid_t) -1) {
42050 newattrs.ia_valid |= ATTR_UID;
42051@@ -998,7 +1049,10 @@ long do_sys_open(int dfd, const char __u
42052 if (!IS_ERR(tmp)) {
42053 fd = get_unused_fd_flags(flags);
42054 if (fd >= 0) {
42055- struct file *f = do_filp_open(dfd, tmp, &op, lookup);
42056+ struct file *f;
42057+ /* don't allow to be set by userland */
42058+ flags &= ~FMODE_GREXEC;
42059+ f = do_filp_open(dfd, tmp, &op, lookup);
42060 if (IS_ERR(f)) {
42061 put_unused_fd(fd);
42062 fd = PTR_ERR(f);
42063diff -urNp linux-3.0.4/fs/partitions/ldm.c linux-3.0.4/fs/partitions/ldm.c
42064--- linux-3.0.4/fs/partitions/ldm.c 2011-07-21 22:17:23.000000000 -0400
42065+++ linux-3.0.4/fs/partitions/ldm.c 2011-08-23 21:48:14.000000000 -0400
42066@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
42067 ldm_error ("A VBLK claims to have %d parts.", num);
42068 return false;
42069 }
42070+
42071 if (rec >= num) {
42072 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
42073 return false;
42074@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
42075 goto found;
42076 }
42077
42078- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
42079+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
42080 if (!f) {
42081 ldm_crit ("Out of memory.");
42082 return false;
42083diff -urNp linux-3.0.4/fs/pipe.c linux-3.0.4/fs/pipe.c
42084--- linux-3.0.4/fs/pipe.c 2011-07-21 22:17:23.000000000 -0400
42085+++ linux-3.0.4/fs/pipe.c 2011-08-23 21:48:14.000000000 -0400
42086@@ -420,9 +420,9 @@ redo:
42087 }
42088 if (bufs) /* More to do? */
42089 continue;
42090- if (!pipe->writers)
42091+ if (!atomic_read(&pipe->writers))
42092 break;
42093- if (!pipe->waiting_writers) {
42094+ if (!atomic_read(&pipe->waiting_writers)) {
42095 /* syscall merging: Usually we must not sleep
42096 * if O_NONBLOCK is set, or if we got some data.
42097 * But if a writer sleeps in kernel space, then
42098@@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
42099 mutex_lock(&inode->i_mutex);
42100 pipe = inode->i_pipe;
42101
42102- if (!pipe->readers) {
42103+ if (!atomic_read(&pipe->readers)) {
42104 send_sig(SIGPIPE, current, 0);
42105 ret = -EPIPE;
42106 goto out;
42107@@ -530,7 +530,7 @@ redo1:
42108 for (;;) {
42109 int bufs;
42110
42111- if (!pipe->readers) {
42112+ if (!atomic_read(&pipe->readers)) {
42113 send_sig(SIGPIPE, current, 0);
42114 if (!ret)
42115 ret = -EPIPE;
42116@@ -616,9 +616,9 @@ redo2:
42117 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
42118 do_wakeup = 0;
42119 }
42120- pipe->waiting_writers++;
42121+ atomic_inc(&pipe->waiting_writers);
42122 pipe_wait(pipe);
42123- pipe->waiting_writers--;
42124+ atomic_dec(&pipe->waiting_writers);
42125 }
42126 out:
42127 mutex_unlock(&inode->i_mutex);
42128@@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
42129 mask = 0;
42130 if (filp->f_mode & FMODE_READ) {
42131 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
42132- if (!pipe->writers && filp->f_version != pipe->w_counter)
42133+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
42134 mask |= POLLHUP;
42135 }
42136
42137@@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
42138 * Most Unices do not set POLLERR for FIFOs but on Linux they
42139 * behave exactly like pipes for poll().
42140 */
42141- if (!pipe->readers)
42142+ if (!atomic_read(&pipe->readers))
42143 mask |= POLLERR;
42144 }
42145
42146@@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
42147
42148 mutex_lock(&inode->i_mutex);
42149 pipe = inode->i_pipe;
42150- pipe->readers -= decr;
42151- pipe->writers -= decw;
42152+ atomic_sub(decr, &pipe->readers);
42153+ atomic_sub(decw, &pipe->writers);
42154
42155- if (!pipe->readers && !pipe->writers) {
42156+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
42157 free_pipe_info(inode);
42158 } else {
42159 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
42160@@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
42161
42162 if (inode->i_pipe) {
42163 ret = 0;
42164- inode->i_pipe->readers++;
42165+ atomic_inc(&inode->i_pipe->readers);
42166 }
42167
42168 mutex_unlock(&inode->i_mutex);
42169@@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
42170
42171 if (inode->i_pipe) {
42172 ret = 0;
42173- inode->i_pipe->writers++;
42174+ atomic_inc(&inode->i_pipe->writers);
42175 }
42176
42177 mutex_unlock(&inode->i_mutex);
42178@@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
42179 if (inode->i_pipe) {
42180 ret = 0;
42181 if (filp->f_mode & FMODE_READ)
42182- inode->i_pipe->readers++;
42183+ atomic_inc(&inode->i_pipe->readers);
42184 if (filp->f_mode & FMODE_WRITE)
42185- inode->i_pipe->writers++;
42186+ atomic_inc(&inode->i_pipe->writers);
42187 }
42188
42189 mutex_unlock(&inode->i_mutex);
42190@@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
42191 inode->i_pipe = NULL;
42192 }
42193
42194-static struct vfsmount *pipe_mnt __read_mostly;
42195+struct vfsmount *pipe_mnt __read_mostly;
42196
42197 /*
42198 * pipefs_dname() is called from d_path().
42199@@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
42200 goto fail_iput;
42201 inode->i_pipe = pipe;
42202
42203- pipe->readers = pipe->writers = 1;
42204+ atomic_set(&pipe->readers, 1);
42205+ atomic_set(&pipe->writers, 1);
42206 inode->i_fop = &rdwr_pipefifo_fops;
42207
42208 /*
42209diff -urNp linux-3.0.4/fs/proc/array.c linux-3.0.4/fs/proc/array.c
42210--- linux-3.0.4/fs/proc/array.c 2011-07-21 22:17:23.000000000 -0400
42211+++ linux-3.0.4/fs/proc/array.c 2011-08-23 21:48:14.000000000 -0400
42212@@ -60,6 +60,7 @@
42213 #include <linux/tty.h>
42214 #include <linux/string.h>
42215 #include <linux/mman.h>
42216+#include <linux/grsecurity.h>
42217 #include <linux/proc_fs.h>
42218 #include <linux/ioport.h>
42219 #include <linux/uaccess.h>
42220@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
42221 seq_putc(m, '\n');
42222 }
42223
42224+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42225+static inline void task_pax(struct seq_file *m, struct task_struct *p)
42226+{
42227+ if (p->mm)
42228+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
42229+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
42230+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
42231+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
42232+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
42233+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
42234+ else
42235+ seq_printf(m, "PaX:\t-----\n");
42236+}
42237+#endif
42238+
42239 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
42240 struct pid *pid, struct task_struct *task)
42241 {
42242@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
42243 task_cpus_allowed(m, task);
42244 cpuset_task_status_allowed(m, task);
42245 task_context_switch_counts(m, task);
42246+
42247+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42248+ task_pax(m, task);
42249+#endif
42250+
42251+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
42252+ task_grsec_rbac(m, task);
42253+#endif
42254+
42255 return 0;
42256 }
42257
42258+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42259+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
42260+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
42261+ _mm->pax_flags & MF_PAX_SEGMEXEC))
42262+#endif
42263+
42264 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
42265 struct pid *pid, struct task_struct *task, int whole)
42266 {
42267@@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
42268 cputime_t cutime, cstime, utime, stime;
42269 cputime_t cgtime, gtime;
42270 unsigned long rsslim = 0;
42271- char tcomm[sizeof(task->comm)];
42272+ char tcomm[sizeof(task->comm)] = { 0 };
42273 unsigned long flags;
42274
42275+ pax_track_stack();
42276+
42277 state = *get_task_state(task);
42278 vsize = eip = esp = 0;
42279 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
42280@@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
42281 gtime = task->gtime;
42282 }
42283
42284+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42285+ if (PAX_RAND_FLAGS(mm)) {
42286+ eip = 0;
42287+ esp = 0;
42288+ wchan = 0;
42289+ }
42290+#endif
42291+#ifdef CONFIG_GRKERNSEC_HIDESYM
42292+ wchan = 0;
42293+ eip =0;
42294+ esp =0;
42295+#endif
42296+
42297 /* scale priority and nice values from timeslices to -20..20 */
42298 /* to make it look like a "normal" Unix priority/nice value */
42299 priority = task_prio(task);
42300@@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
42301 vsize,
42302 mm ? get_mm_rss(mm) : 0,
42303 rsslim,
42304+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42305+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
42306+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
42307+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
42308+#else
42309 mm ? (permitted ? mm->start_code : 1) : 0,
42310 mm ? (permitted ? mm->end_code : 1) : 0,
42311 (permitted && mm) ? mm->start_stack : 0,
42312+#endif
42313 esp,
42314 eip,
42315 /* The signal information here is obsolete.
42316@@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
42317
42318 return 0;
42319 }
42320+
42321+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42322+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
42323+{
42324+ u32 curr_ip = 0;
42325+ unsigned long flags;
42326+
42327+ if (lock_task_sighand(task, &flags)) {
42328+ curr_ip = task->signal->curr_ip;
42329+ unlock_task_sighand(task, &flags);
42330+ }
42331+
42332+ return sprintf(buffer, "%pI4\n", &curr_ip);
42333+}
42334+#endif
42335diff -urNp linux-3.0.4/fs/proc/base.c linux-3.0.4/fs/proc/base.c
42336--- linux-3.0.4/fs/proc/base.c 2011-09-02 18:11:21.000000000 -0400
42337+++ linux-3.0.4/fs/proc/base.c 2011-09-13 14:50:28.000000000 -0400
42338@@ -107,6 +107,22 @@ struct pid_entry {
42339 union proc_op op;
42340 };
42341
42342+struct getdents_callback {
42343+ struct linux_dirent __user * current_dir;
42344+ struct linux_dirent __user * previous;
42345+ struct file * file;
42346+ int count;
42347+ int error;
42348+};
42349+
42350+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
42351+ loff_t offset, u64 ino, unsigned int d_type)
42352+{
42353+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
42354+ buf->error = -EINVAL;
42355+ return 0;
42356+}
42357+
42358 #define NOD(NAME, MODE, IOP, FOP, OP) { \
42359 .name = (NAME), \
42360 .len = sizeof(NAME) - 1, \
42361@@ -209,6 +225,9 @@ static struct mm_struct *__check_mem_per
42362 if (task == current)
42363 return mm;
42364
42365+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
42366+ return ERR_PTR(-EPERM);
42367+
42368 /*
42369 * If current is actively ptrace'ing, and would also be
42370 * permitted to freshly attach with ptrace now, permit it.
42371@@ -282,6 +301,9 @@ static int proc_pid_cmdline(struct task_
42372 if (!mm->arg_end)
42373 goto out_mm; /* Shh! No looking before we're done */
42374
42375+ if (gr_acl_handle_procpidmem(task))
42376+ goto out_mm;
42377+
42378 len = mm->arg_end - mm->arg_start;
42379
42380 if (len > PAGE_SIZE)
42381@@ -309,12 +331,28 @@ out:
42382 return res;
42383 }
42384
42385+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42386+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
42387+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
42388+ _mm->pax_flags & MF_PAX_SEGMEXEC))
42389+#endif
42390+
42391 static int proc_pid_auxv(struct task_struct *task, char *buffer)
42392 {
42393 struct mm_struct *mm = mm_for_maps(task);
42394 int res = PTR_ERR(mm);
42395 if (mm && !IS_ERR(mm)) {
42396 unsigned int nwords = 0;
42397+
42398+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42399+ /* allow if we're currently ptracing this task */
42400+ if (PAX_RAND_FLAGS(mm) &&
42401+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
42402+ mmput(mm);
42403+ return 0;
42404+ }
42405+#endif
42406+
42407 do {
42408 nwords += 2;
42409 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
42410@@ -328,7 +366,7 @@ static int proc_pid_auxv(struct task_str
42411 }
42412
42413
42414-#ifdef CONFIG_KALLSYMS
42415+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42416 /*
42417 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
42418 * Returns the resolved symbol. If that fails, simply return the address.
42419@@ -367,7 +405,7 @@ static void unlock_trace(struct task_str
42420 mutex_unlock(&task->signal->cred_guard_mutex);
42421 }
42422
42423-#ifdef CONFIG_STACKTRACE
42424+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42425
42426 #define MAX_STACK_TRACE_DEPTH 64
42427
42428@@ -558,7 +596,7 @@ static int proc_pid_limits(struct task_s
42429 return count;
42430 }
42431
42432-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42433+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42434 static int proc_pid_syscall(struct task_struct *task, char *buffer)
42435 {
42436 long nr;
42437@@ -587,7 +625,7 @@ static int proc_pid_syscall(struct task_
42438 /************************************************************************/
42439
42440 /* permission checks */
42441-static int proc_fd_access_allowed(struct inode *inode)
42442+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
42443 {
42444 struct task_struct *task;
42445 int allowed = 0;
42446@@ -597,7 +635,10 @@ static int proc_fd_access_allowed(struct
42447 */
42448 task = get_proc_task(inode);
42449 if (task) {
42450- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
42451+ if (log)
42452+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
42453+ else
42454+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
42455 put_task_struct(task);
42456 }
42457 return allowed;
42458@@ -978,6 +1019,9 @@ static ssize_t environ_read(struct file
42459 if (!task)
42460 goto out_no_task;
42461
42462+ if (gr_acl_handle_procpidmem(task))
42463+ goto out;
42464+
42465 ret = -ENOMEM;
42466 page = (char *)__get_free_page(GFP_TEMPORARY);
42467 if (!page)
42468@@ -1614,7 +1658,7 @@ static void *proc_pid_follow_link(struct
42469 path_put(&nd->path);
42470
42471 /* Are we allowed to snoop on the tasks file descriptors? */
42472- if (!proc_fd_access_allowed(inode))
42473+ if (!proc_fd_access_allowed(inode,0))
42474 goto out;
42475
42476 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
42477@@ -1653,8 +1697,18 @@ static int proc_pid_readlink(struct dent
42478 struct path path;
42479
42480 /* Are we allowed to snoop on the tasks file descriptors? */
42481- if (!proc_fd_access_allowed(inode))
42482- goto out;
42483+ /* logging this is needed for learning on chromium to work properly,
42484+ but we don't want to flood the logs from 'ps' which does a readlink
42485+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
42486+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
42487+ */
42488+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
42489+ if (!proc_fd_access_allowed(inode,0))
42490+ goto out;
42491+ } else {
42492+ if (!proc_fd_access_allowed(inode,1))
42493+ goto out;
42494+ }
42495
42496 error = PROC_I(inode)->op.proc_get_link(inode, &path);
42497 if (error)
42498@@ -1719,7 +1773,11 @@ struct inode *proc_pid_make_inode(struct
42499 rcu_read_lock();
42500 cred = __task_cred(task);
42501 inode->i_uid = cred->euid;
42502+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42503+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42504+#else
42505 inode->i_gid = cred->egid;
42506+#endif
42507 rcu_read_unlock();
42508 }
42509 security_task_to_inode(task, inode);
42510@@ -1737,6 +1795,9 @@ int pid_getattr(struct vfsmount *mnt, st
42511 struct inode *inode = dentry->d_inode;
42512 struct task_struct *task;
42513 const struct cred *cred;
42514+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42515+ const struct cred *tmpcred = current_cred();
42516+#endif
42517
42518 generic_fillattr(inode, stat);
42519
42520@@ -1744,13 +1805,41 @@ int pid_getattr(struct vfsmount *mnt, st
42521 stat->uid = 0;
42522 stat->gid = 0;
42523 task = pid_task(proc_pid(inode), PIDTYPE_PID);
42524+
42525+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
42526+ rcu_read_unlock();
42527+ return -ENOENT;
42528+ }
42529+
42530 if (task) {
42531+ cred = __task_cred(task);
42532+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42533+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
42534+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42535+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
42536+#endif
42537+ ) {
42538+#endif
42539 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
42540+#ifdef CONFIG_GRKERNSEC_PROC_USER
42541+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
42542+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42543+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
42544+#endif
42545 task_dumpable(task)) {
42546- cred = __task_cred(task);
42547 stat->uid = cred->euid;
42548+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42549+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
42550+#else
42551 stat->gid = cred->egid;
42552+#endif
42553 }
42554+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42555+ } else {
42556+ rcu_read_unlock();
42557+ return -ENOENT;
42558+ }
42559+#endif
42560 }
42561 rcu_read_unlock();
42562 return 0;
42563@@ -1787,11 +1876,20 @@ int pid_revalidate(struct dentry *dentry
42564
42565 if (task) {
42566 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
42567+#ifdef CONFIG_GRKERNSEC_PROC_USER
42568+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
42569+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42570+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
42571+#endif
42572 task_dumpable(task)) {
42573 rcu_read_lock();
42574 cred = __task_cred(task);
42575 inode->i_uid = cred->euid;
42576+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42577+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42578+#else
42579 inode->i_gid = cred->egid;
42580+#endif
42581 rcu_read_unlock();
42582 } else {
42583 inode->i_uid = 0;
42584@@ -1909,7 +2007,8 @@ static int proc_fd_info(struct inode *in
42585 int fd = proc_fd(inode);
42586
42587 if (task) {
42588- files = get_files_struct(task);
42589+ if (!gr_acl_handle_procpidmem(task))
42590+ files = get_files_struct(task);
42591 put_task_struct(task);
42592 }
42593 if (files) {
42594@@ -2169,11 +2268,21 @@ static const struct file_operations proc
42595 */
42596 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
42597 {
42598+ struct task_struct *task;
42599 int rv = generic_permission(inode, mask, flags, NULL);
42600- if (rv == 0)
42601- return 0;
42602+
42603 if (task_pid(current) == proc_pid(inode))
42604 rv = 0;
42605+
42606+ task = get_proc_task(inode);
42607+ if (task == NULL)
42608+ return rv;
42609+
42610+ if (gr_acl_handle_procpidmem(task))
42611+ rv = -EACCES;
42612+
42613+ put_task_struct(task);
42614+
42615 return rv;
42616 }
42617
42618@@ -2283,6 +2392,9 @@ static struct dentry *proc_pident_lookup
42619 if (!task)
42620 goto out_no_task;
42621
42622+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42623+ goto out;
42624+
42625 /*
42626 * Yes, it does not scale. And it should not. Don't add
42627 * new entries into /proc/<tgid>/ without very good reasons.
42628@@ -2327,6 +2439,9 @@ static int proc_pident_readdir(struct fi
42629 if (!task)
42630 goto out_no_task;
42631
42632+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42633+ goto out;
42634+
42635 ret = 0;
42636 i = filp->f_pos;
42637 switch (i) {
42638@@ -2597,7 +2712,7 @@ static void *proc_self_follow_link(struc
42639 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
42640 void *cookie)
42641 {
42642- char *s = nd_get_link(nd);
42643+ const char *s = nd_get_link(nd);
42644 if (!IS_ERR(s))
42645 __putname(s);
42646 }
42647@@ -2795,7 +2910,7 @@ static const struct pid_entry tgid_base_
42648 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
42649 #endif
42650 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
42651-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42652+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42653 INF("syscall", S_IRUGO, proc_pid_syscall),
42654 #endif
42655 INF("cmdline", S_IRUGO, proc_pid_cmdline),
42656@@ -2820,10 +2935,10 @@ static const struct pid_entry tgid_base_
42657 #ifdef CONFIG_SECURITY
42658 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
42659 #endif
42660-#ifdef CONFIG_KALLSYMS
42661+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42662 INF("wchan", S_IRUGO, proc_pid_wchan),
42663 #endif
42664-#ifdef CONFIG_STACKTRACE
42665+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42666 ONE("stack", S_IRUGO, proc_pid_stack),
42667 #endif
42668 #ifdef CONFIG_SCHEDSTATS
42669@@ -2857,6 +2972,9 @@ static const struct pid_entry tgid_base_
42670 #ifdef CONFIG_HARDWALL
42671 INF("hardwall", S_IRUGO, proc_pid_hardwall),
42672 #endif
42673+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42674+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
42675+#endif
42676 };
42677
42678 static int proc_tgid_base_readdir(struct file * filp,
42679@@ -2982,7 +3100,14 @@ static struct dentry *proc_pid_instantia
42680 if (!inode)
42681 goto out;
42682
42683+#ifdef CONFIG_GRKERNSEC_PROC_USER
42684+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
42685+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42686+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42687+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
42688+#else
42689 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
42690+#endif
42691 inode->i_op = &proc_tgid_base_inode_operations;
42692 inode->i_fop = &proc_tgid_base_operations;
42693 inode->i_flags|=S_IMMUTABLE;
42694@@ -3024,7 +3149,11 @@ struct dentry *proc_pid_lookup(struct in
42695 if (!task)
42696 goto out;
42697
42698+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42699+ goto out_put_task;
42700+
42701 result = proc_pid_instantiate(dir, dentry, task, NULL);
42702+out_put_task:
42703 put_task_struct(task);
42704 out:
42705 return result;
42706@@ -3089,6 +3218,11 @@ int proc_pid_readdir(struct file * filp,
42707 {
42708 unsigned int nr;
42709 struct task_struct *reaper;
42710+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42711+ const struct cred *tmpcred = current_cred();
42712+ const struct cred *itercred;
42713+#endif
42714+ filldir_t __filldir = filldir;
42715 struct tgid_iter iter;
42716 struct pid_namespace *ns;
42717
42718@@ -3112,8 +3246,27 @@ int proc_pid_readdir(struct file * filp,
42719 for (iter = next_tgid(ns, iter);
42720 iter.task;
42721 iter.tgid += 1, iter = next_tgid(ns, iter)) {
42722+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42723+ rcu_read_lock();
42724+ itercred = __task_cred(iter.task);
42725+#endif
42726+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
42727+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42728+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
42729+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42730+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
42731+#endif
42732+ )
42733+#endif
42734+ )
42735+ __filldir = &gr_fake_filldir;
42736+ else
42737+ __filldir = filldir;
42738+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42739+ rcu_read_unlock();
42740+#endif
42741 filp->f_pos = iter.tgid + TGID_OFFSET;
42742- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
42743+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
42744 put_task_struct(iter.task);
42745 goto out;
42746 }
42747@@ -3141,7 +3294,7 @@ static const struct pid_entry tid_base_s
42748 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
42749 #endif
42750 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
42751-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42752+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42753 INF("syscall", S_IRUGO, proc_pid_syscall),
42754 #endif
42755 INF("cmdline", S_IRUGO, proc_pid_cmdline),
42756@@ -3165,10 +3318,10 @@ static const struct pid_entry tid_base_s
42757 #ifdef CONFIG_SECURITY
42758 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
42759 #endif
42760-#ifdef CONFIG_KALLSYMS
42761+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42762 INF("wchan", S_IRUGO, proc_pid_wchan),
42763 #endif
42764-#ifdef CONFIG_STACKTRACE
42765+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42766 ONE("stack", S_IRUGO, proc_pid_stack),
42767 #endif
42768 #ifdef CONFIG_SCHEDSTATS
42769diff -urNp linux-3.0.4/fs/proc/cmdline.c linux-3.0.4/fs/proc/cmdline.c
42770--- linux-3.0.4/fs/proc/cmdline.c 2011-07-21 22:17:23.000000000 -0400
42771+++ linux-3.0.4/fs/proc/cmdline.c 2011-08-23 21:48:14.000000000 -0400
42772@@ -23,7 +23,11 @@ static const struct file_operations cmdl
42773
42774 static int __init proc_cmdline_init(void)
42775 {
42776+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42777+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
42778+#else
42779 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
42780+#endif
42781 return 0;
42782 }
42783 module_init(proc_cmdline_init);
42784diff -urNp linux-3.0.4/fs/proc/devices.c linux-3.0.4/fs/proc/devices.c
42785--- linux-3.0.4/fs/proc/devices.c 2011-07-21 22:17:23.000000000 -0400
42786+++ linux-3.0.4/fs/proc/devices.c 2011-08-23 21:48:14.000000000 -0400
42787@@ -64,7 +64,11 @@ static const struct file_operations proc
42788
42789 static int __init proc_devices_init(void)
42790 {
42791+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42792+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
42793+#else
42794 proc_create("devices", 0, NULL, &proc_devinfo_operations);
42795+#endif
42796 return 0;
42797 }
42798 module_init(proc_devices_init);
42799diff -urNp linux-3.0.4/fs/proc/inode.c linux-3.0.4/fs/proc/inode.c
42800--- linux-3.0.4/fs/proc/inode.c 2011-07-21 22:17:23.000000000 -0400
42801+++ linux-3.0.4/fs/proc/inode.c 2011-08-23 21:48:14.000000000 -0400
42802@@ -440,7 +440,11 @@ struct inode *proc_get_inode(struct supe
42803 if (de->mode) {
42804 inode->i_mode = de->mode;
42805 inode->i_uid = de->uid;
42806+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42807+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42808+#else
42809 inode->i_gid = de->gid;
42810+#endif
42811 }
42812 if (de->size)
42813 inode->i_size = de->size;
42814diff -urNp linux-3.0.4/fs/proc/internal.h linux-3.0.4/fs/proc/internal.h
42815--- linux-3.0.4/fs/proc/internal.h 2011-07-21 22:17:23.000000000 -0400
42816+++ linux-3.0.4/fs/proc/internal.h 2011-08-23 21:48:14.000000000 -0400
42817@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
42818 struct pid *pid, struct task_struct *task);
42819 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
42820 struct pid *pid, struct task_struct *task);
42821+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42822+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
42823+#endif
42824 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
42825
42826 extern const struct file_operations proc_maps_operations;
42827diff -urNp linux-3.0.4/fs/proc/Kconfig linux-3.0.4/fs/proc/Kconfig
42828--- linux-3.0.4/fs/proc/Kconfig 2011-07-21 22:17:23.000000000 -0400
42829+++ linux-3.0.4/fs/proc/Kconfig 2011-08-23 21:48:14.000000000 -0400
42830@@ -30,12 +30,12 @@ config PROC_FS
42831
42832 config PROC_KCORE
42833 bool "/proc/kcore support" if !ARM
42834- depends on PROC_FS && MMU
42835+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
42836
42837 config PROC_VMCORE
42838 bool "/proc/vmcore support"
42839- depends on PROC_FS && CRASH_DUMP
42840- default y
42841+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
42842+ default n
42843 help
42844 Exports the dump image of crashed kernel in ELF format.
42845
42846@@ -59,8 +59,8 @@ config PROC_SYSCTL
42847 limited in memory.
42848
42849 config PROC_PAGE_MONITOR
42850- default y
42851- depends on PROC_FS && MMU
42852+ default n
42853+ depends on PROC_FS && MMU && !GRKERNSEC
42854 bool "Enable /proc page monitoring" if EXPERT
42855 help
42856 Various /proc files exist to monitor process memory utilization:
42857diff -urNp linux-3.0.4/fs/proc/kcore.c linux-3.0.4/fs/proc/kcore.c
42858--- linux-3.0.4/fs/proc/kcore.c 2011-07-21 22:17:23.000000000 -0400
42859+++ linux-3.0.4/fs/proc/kcore.c 2011-08-23 21:48:14.000000000 -0400
42860@@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
42861 off_t offset = 0;
42862 struct kcore_list *m;
42863
42864+ pax_track_stack();
42865+
42866 /* setup ELF header */
42867 elf = (struct elfhdr *) bufp;
42868 bufp += sizeof(struct elfhdr);
42869@@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
42870 * the addresses in the elf_phdr on our list.
42871 */
42872 start = kc_offset_to_vaddr(*fpos - elf_buflen);
42873- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
42874+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
42875+ if (tsz > buflen)
42876 tsz = buflen;
42877-
42878+
42879 while (buflen) {
42880 struct kcore_list *m;
42881
42882@@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
42883 kfree(elf_buf);
42884 } else {
42885 if (kern_addr_valid(start)) {
42886- unsigned long n;
42887+ char *elf_buf;
42888+ mm_segment_t oldfs;
42889
42890- n = copy_to_user(buffer, (char *)start, tsz);
42891- /*
42892- * We cannot distingush between fault on source
42893- * and fault on destination. When this happens
42894- * we clear too and hope it will trigger the
42895- * EFAULT again.
42896- */
42897- if (n) {
42898- if (clear_user(buffer + tsz - n,
42899- n))
42900+ elf_buf = kmalloc(tsz, GFP_KERNEL);
42901+ if (!elf_buf)
42902+ return -ENOMEM;
42903+ oldfs = get_fs();
42904+ set_fs(KERNEL_DS);
42905+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
42906+ set_fs(oldfs);
42907+ if (copy_to_user(buffer, elf_buf, tsz)) {
42908+ kfree(elf_buf);
42909 return -EFAULT;
42910+ }
42911 }
42912+ set_fs(oldfs);
42913+ kfree(elf_buf);
42914 } else {
42915 if (clear_user(buffer, tsz))
42916 return -EFAULT;
42917@@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
42918
42919 static int open_kcore(struct inode *inode, struct file *filp)
42920 {
42921+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
42922+ return -EPERM;
42923+#endif
42924 if (!capable(CAP_SYS_RAWIO))
42925 return -EPERM;
42926 if (kcore_need_update)
42927diff -urNp linux-3.0.4/fs/proc/meminfo.c linux-3.0.4/fs/proc/meminfo.c
42928--- linux-3.0.4/fs/proc/meminfo.c 2011-07-21 22:17:23.000000000 -0400
42929+++ linux-3.0.4/fs/proc/meminfo.c 2011-08-23 21:48:14.000000000 -0400
42930@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
42931 unsigned long pages[NR_LRU_LISTS];
42932 int lru;
42933
42934+ pax_track_stack();
42935+
42936 /*
42937 * display in kilobytes.
42938 */
42939@@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
42940 vmi.used >> 10,
42941 vmi.largest_chunk >> 10
42942 #ifdef CONFIG_MEMORY_FAILURE
42943- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
42944+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
42945 #endif
42946 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
42947 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
42948diff -urNp linux-3.0.4/fs/proc/nommu.c linux-3.0.4/fs/proc/nommu.c
42949--- linux-3.0.4/fs/proc/nommu.c 2011-07-21 22:17:23.000000000 -0400
42950+++ linux-3.0.4/fs/proc/nommu.c 2011-08-23 21:47:56.000000000 -0400
42951@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
42952 if (len < 1)
42953 len = 1;
42954 seq_printf(m, "%*c", len, ' ');
42955- seq_path(m, &file->f_path, "");
42956+ seq_path(m, &file->f_path, "\n\\");
42957 }
42958
42959 seq_putc(m, '\n');
42960diff -urNp linux-3.0.4/fs/proc/proc_net.c linux-3.0.4/fs/proc/proc_net.c
42961--- linux-3.0.4/fs/proc/proc_net.c 2011-07-21 22:17:23.000000000 -0400
42962+++ linux-3.0.4/fs/proc/proc_net.c 2011-08-23 21:48:14.000000000 -0400
42963@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
42964 struct task_struct *task;
42965 struct nsproxy *ns;
42966 struct net *net = NULL;
42967+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42968+ const struct cred *cred = current_cred();
42969+#endif
42970+
42971+#ifdef CONFIG_GRKERNSEC_PROC_USER
42972+ if (cred->fsuid)
42973+ return net;
42974+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42975+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
42976+ return net;
42977+#endif
42978
42979 rcu_read_lock();
42980 task = pid_task(proc_pid(dir), PIDTYPE_PID);
42981diff -urNp linux-3.0.4/fs/proc/proc_sysctl.c linux-3.0.4/fs/proc/proc_sysctl.c
42982--- linux-3.0.4/fs/proc/proc_sysctl.c 2011-07-21 22:17:23.000000000 -0400
42983+++ linux-3.0.4/fs/proc/proc_sysctl.c 2011-08-23 21:48:14.000000000 -0400
42984@@ -8,6 +8,8 @@
42985 #include <linux/namei.h>
42986 #include "internal.h"
42987
42988+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
42989+
42990 static const struct dentry_operations proc_sys_dentry_operations;
42991 static const struct file_operations proc_sys_file_operations;
42992 static const struct inode_operations proc_sys_inode_operations;
42993@@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
42994 if (!p)
42995 goto out;
42996
42997+ if (gr_handle_sysctl(p, MAY_EXEC))
42998+ goto out;
42999+
43000 err = ERR_PTR(-ENOMEM);
43001 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
43002 if (h)
43003@@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
43004 if (*pos < file->f_pos)
43005 continue;
43006
43007+ if (gr_handle_sysctl(table, 0))
43008+ continue;
43009+
43010 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
43011 if (res)
43012 return res;
43013@@ -355,6 +363,9 @@ static int proc_sys_getattr(struct vfsmo
43014 if (IS_ERR(head))
43015 return PTR_ERR(head);
43016
43017+ if (table && gr_handle_sysctl(table, MAY_EXEC))
43018+ return -ENOENT;
43019+
43020 generic_fillattr(inode, stat);
43021 if (table)
43022 stat->mode = (stat->mode & S_IFMT) | table->mode;
43023diff -urNp linux-3.0.4/fs/proc/root.c linux-3.0.4/fs/proc/root.c
43024--- linux-3.0.4/fs/proc/root.c 2011-07-21 22:17:23.000000000 -0400
43025+++ linux-3.0.4/fs/proc/root.c 2011-08-23 21:48:14.000000000 -0400
43026@@ -123,7 +123,15 @@ void __init proc_root_init(void)
43027 #ifdef CONFIG_PROC_DEVICETREE
43028 proc_device_tree_init();
43029 #endif
43030+#ifdef CONFIG_GRKERNSEC_PROC_ADD
43031+#ifdef CONFIG_GRKERNSEC_PROC_USER
43032+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
43033+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
43034+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
43035+#endif
43036+#else
43037 proc_mkdir("bus", NULL);
43038+#endif
43039 proc_sys_init();
43040 }
43041
43042diff -urNp linux-3.0.4/fs/proc/task_mmu.c linux-3.0.4/fs/proc/task_mmu.c
43043--- linux-3.0.4/fs/proc/task_mmu.c 2011-07-21 22:17:23.000000000 -0400
43044+++ linux-3.0.4/fs/proc/task_mmu.c 2011-08-23 21:48:14.000000000 -0400
43045@@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
43046 "VmExe:\t%8lu kB\n"
43047 "VmLib:\t%8lu kB\n"
43048 "VmPTE:\t%8lu kB\n"
43049- "VmSwap:\t%8lu kB\n",
43050- hiwater_vm << (PAGE_SHIFT-10),
43051+ "VmSwap:\t%8lu kB\n"
43052+
43053+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43054+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
43055+#endif
43056+
43057+ ,hiwater_vm << (PAGE_SHIFT-10),
43058 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
43059 mm->locked_vm << (PAGE_SHIFT-10),
43060 hiwater_rss << (PAGE_SHIFT-10),
43061@@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
43062 data << (PAGE_SHIFT-10),
43063 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
43064 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
43065- swap << (PAGE_SHIFT-10));
43066+ swap << (PAGE_SHIFT-10)
43067+
43068+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43069+ , mm->context.user_cs_base, mm->context.user_cs_limit
43070+#endif
43071+
43072+ );
43073 }
43074
43075 unsigned long task_vsize(struct mm_struct *mm)
43076@@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
43077 return ret;
43078 }
43079
43080+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43081+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
43082+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
43083+ _mm->pax_flags & MF_PAX_SEGMEXEC))
43084+#endif
43085+
43086 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
43087 {
43088 struct mm_struct *mm = vma->vm_mm;
43089@@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
43090 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
43091 }
43092
43093- /* We don't show the stack guard page in /proc/maps */
43094+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43095+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
43096+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
43097+#else
43098 start = vma->vm_start;
43099- if (stack_guard_page_start(vma, start))
43100- start += PAGE_SIZE;
43101 end = vma->vm_end;
43102- if (stack_guard_page_end(vma, end))
43103- end -= PAGE_SIZE;
43104+#endif
43105
43106 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
43107 start,
43108@@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
43109 flags & VM_WRITE ? 'w' : '-',
43110 flags & VM_EXEC ? 'x' : '-',
43111 flags & VM_MAYSHARE ? 's' : 'p',
43112+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43113+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
43114+#else
43115 pgoff,
43116+#endif
43117 MAJOR(dev), MINOR(dev), ino, &len);
43118
43119 /*
43120@@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
43121 */
43122 if (file) {
43123 pad_len_spaces(m, len);
43124- seq_path(m, &file->f_path, "\n");
43125+ seq_path(m, &file->f_path, "\n\\");
43126 } else {
43127 const char *name = arch_vma_name(vma);
43128 if (!name) {
43129@@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
43130 if (vma->vm_start <= mm->brk &&
43131 vma->vm_end >= mm->start_brk) {
43132 name = "[heap]";
43133- } else if (vma->vm_start <= mm->start_stack &&
43134- vma->vm_end >= mm->start_stack) {
43135+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
43136+ (vma->vm_start <= mm->start_stack &&
43137+ vma->vm_end >= mm->start_stack)) {
43138 name = "[stack]";
43139 }
43140 } else {
43141@@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
43142 };
43143
43144 memset(&mss, 0, sizeof mss);
43145- mss.vma = vma;
43146- /* mmap_sem is held in m_start */
43147- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
43148- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
43149-
43150+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43151+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
43152+#endif
43153+ mss.vma = vma;
43154+ /* mmap_sem is held in m_start */
43155+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
43156+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
43157+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43158+ }
43159+#endif
43160 show_map_vma(m, vma);
43161
43162 seq_printf(m,
43163@@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
43164 "KernelPageSize: %8lu kB\n"
43165 "MMUPageSize: %8lu kB\n"
43166 "Locked: %8lu kB\n",
43167+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43168+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
43169+#else
43170 (vma->vm_end - vma->vm_start) >> 10,
43171+#endif
43172 mss.resident >> 10,
43173 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
43174 mss.shared_clean >> 10,
43175@@ -1001,7 +1032,7 @@ static int show_numa_map(struct seq_file
43176
43177 if (file) {
43178 seq_printf(m, " file=");
43179- seq_path(m, &file->f_path, "\n\t= ");
43180+ seq_path(m, &file->f_path, "\n\t\\= ");
43181 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
43182 seq_printf(m, " heap");
43183 } else if (vma->vm_start <= mm->start_stack &&
43184diff -urNp linux-3.0.4/fs/proc/task_nommu.c linux-3.0.4/fs/proc/task_nommu.c
43185--- linux-3.0.4/fs/proc/task_nommu.c 2011-07-21 22:17:23.000000000 -0400
43186+++ linux-3.0.4/fs/proc/task_nommu.c 2011-08-23 21:47:56.000000000 -0400
43187@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
43188 else
43189 bytes += kobjsize(mm);
43190
43191- if (current->fs && current->fs->users > 1)
43192+ if (current->fs && atomic_read(&current->fs->users) > 1)
43193 sbytes += kobjsize(current->fs);
43194 else
43195 bytes += kobjsize(current->fs);
43196@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
43197
43198 if (file) {
43199 pad_len_spaces(m, len);
43200- seq_path(m, &file->f_path, "");
43201+ seq_path(m, &file->f_path, "\n\\");
43202 } else if (mm) {
43203 if (vma->vm_start <= mm->start_stack &&
43204 vma->vm_end >= mm->start_stack) {
43205diff -urNp linux-3.0.4/fs/quota/netlink.c linux-3.0.4/fs/quota/netlink.c
43206--- linux-3.0.4/fs/quota/netlink.c 2011-07-21 22:17:23.000000000 -0400
43207+++ linux-3.0.4/fs/quota/netlink.c 2011-08-23 21:47:56.000000000 -0400
43208@@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
43209 void quota_send_warning(short type, unsigned int id, dev_t dev,
43210 const char warntype)
43211 {
43212- static atomic_t seq;
43213+ static atomic_unchecked_t seq;
43214 struct sk_buff *skb;
43215 void *msg_head;
43216 int ret;
43217@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
43218 "VFS: Not enough memory to send quota warning.\n");
43219 return;
43220 }
43221- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
43222+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
43223 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
43224 if (!msg_head) {
43225 printk(KERN_ERR
43226diff -urNp linux-3.0.4/fs/readdir.c linux-3.0.4/fs/readdir.c
43227--- linux-3.0.4/fs/readdir.c 2011-07-21 22:17:23.000000000 -0400
43228+++ linux-3.0.4/fs/readdir.c 2011-08-23 21:48:14.000000000 -0400
43229@@ -17,6 +17,7 @@
43230 #include <linux/security.h>
43231 #include <linux/syscalls.h>
43232 #include <linux/unistd.h>
43233+#include <linux/namei.h>
43234
43235 #include <asm/uaccess.h>
43236
43237@@ -67,6 +68,7 @@ struct old_linux_dirent {
43238
43239 struct readdir_callback {
43240 struct old_linux_dirent __user * dirent;
43241+ struct file * file;
43242 int result;
43243 };
43244
43245@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
43246 buf->result = -EOVERFLOW;
43247 return -EOVERFLOW;
43248 }
43249+
43250+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43251+ return 0;
43252+
43253 buf->result++;
43254 dirent = buf->dirent;
43255 if (!access_ok(VERIFY_WRITE, dirent,
43256@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
43257
43258 buf.result = 0;
43259 buf.dirent = dirent;
43260+ buf.file = file;
43261
43262 error = vfs_readdir(file, fillonedir, &buf);
43263 if (buf.result)
43264@@ -142,6 +149,7 @@ struct linux_dirent {
43265 struct getdents_callback {
43266 struct linux_dirent __user * current_dir;
43267 struct linux_dirent __user * previous;
43268+ struct file * file;
43269 int count;
43270 int error;
43271 };
43272@@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
43273 buf->error = -EOVERFLOW;
43274 return -EOVERFLOW;
43275 }
43276+
43277+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43278+ return 0;
43279+
43280 dirent = buf->previous;
43281 if (dirent) {
43282 if (__put_user(offset, &dirent->d_off))
43283@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
43284 buf.previous = NULL;
43285 buf.count = count;
43286 buf.error = 0;
43287+ buf.file = file;
43288
43289 error = vfs_readdir(file, filldir, &buf);
43290 if (error >= 0)
43291@@ -229,6 +242,7 @@ out:
43292 struct getdents_callback64 {
43293 struct linux_dirent64 __user * current_dir;
43294 struct linux_dirent64 __user * previous;
43295+ struct file *file;
43296 int count;
43297 int error;
43298 };
43299@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
43300 buf->error = -EINVAL; /* only used if we fail.. */
43301 if (reclen > buf->count)
43302 return -EINVAL;
43303+
43304+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43305+ return 0;
43306+
43307 dirent = buf->previous;
43308 if (dirent) {
43309 if (__put_user(offset, &dirent->d_off))
43310@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
43311
43312 buf.current_dir = dirent;
43313 buf.previous = NULL;
43314+ buf.file = file;
43315 buf.count = count;
43316 buf.error = 0;
43317
43318diff -urNp linux-3.0.4/fs/reiserfs/dir.c linux-3.0.4/fs/reiserfs/dir.c
43319--- linux-3.0.4/fs/reiserfs/dir.c 2011-07-21 22:17:23.000000000 -0400
43320+++ linux-3.0.4/fs/reiserfs/dir.c 2011-08-23 21:48:14.000000000 -0400
43321@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
43322 struct reiserfs_dir_entry de;
43323 int ret = 0;
43324
43325+ pax_track_stack();
43326+
43327 reiserfs_write_lock(inode->i_sb);
43328
43329 reiserfs_check_lock_depth(inode->i_sb, "readdir");
43330diff -urNp linux-3.0.4/fs/reiserfs/do_balan.c linux-3.0.4/fs/reiserfs/do_balan.c
43331--- linux-3.0.4/fs/reiserfs/do_balan.c 2011-07-21 22:17:23.000000000 -0400
43332+++ linux-3.0.4/fs/reiserfs/do_balan.c 2011-08-23 21:47:56.000000000 -0400
43333@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
43334 return;
43335 }
43336
43337- atomic_inc(&(fs_generation(tb->tb_sb)));
43338+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
43339 do_balance_starts(tb);
43340
43341 /* balance leaf returns 0 except if combining L R and S into
43342diff -urNp linux-3.0.4/fs/reiserfs/journal.c linux-3.0.4/fs/reiserfs/journal.c
43343--- linux-3.0.4/fs/reiserfs/journal.c 2011-07-21 22:17:23.000000000 -0400
43344+++ linux-3.0.4/fs/reiserfs/journal.c 2011-08-23 21:48:14.000000000 -0400
43345@@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
43346 struct buffer_head *bh;
43347 int i, j;
43348
43349+ pax_track_stack();
43350+
43351 bh = __getblk(dev, block, bufsize);
43352 if (buffer_uptodate(bh))
43353 return (bh);
43354diff -urNp linux-3.0.4/fs/reiserfs/namei.c linux-3.0.4/fs/reiserfs/namei.c
43355--- linux-3.0.4/fs/reiserfs/namei.c 2011-07-21 22:17:23.000000000 -0400
43356+++ linux-3.0.4/fs/reiserfs/namei.c 2011-08-23 21:48:14.000000000 -0400
43357@@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
43358 unsigned long savelink = 1;
43359 struct timespec ctime;
43360
43361+ pax_track_stack();
43362+
43363 /* three balancings: (1) old name removal, (2) new name insertion
43364 and (3) maybe "save" link insertion
43365 stat data updates: (1) old directory,
43366diff -urNp linux-3.0.4/fs/reiserfs/procfs.c linux-3.0.4/fs/reiserfs/procfs.c
43367--- linux-3.0.4/fs/reiserfs/procfs.c 2011-07-21 22:17:23.000000000 -0400
43368+++ linux-3.0.4/fs/reiserfs/procfs.c 2011-08-23 21:48:14.000000000 -0400
43369@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
43370 "SMALL_TAILS " : "NO_TAILS ",
43371 replay_only(sb) ? "REPLAY_ONLY " : "",
43372 convert_reiserfs(sb) ? "CONV " : "",
43373- atomic_read(&r->s_generation_counter),
43374+ atomic_read_unchecked(&r->s_generation_counter),
43375 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
43376 SF(s_do_balance), SF(s_unneeded_left_neighbor),
43377 SF(s_good_search_by_key_reada), SF(s_bmaps),
43378@@ -299,6 +299,8 @@ static int show_journal(struct seq_file
43379 struct journal_params *jp = &rs->s_v1.s_journal;
43380 char b[BDEVNAME_SIZE];
43381
43382+ pax_track_stack();
43383+
43384 seq_printf(m, /* on-disk fields */
43385 "jp_journal_1st_block: \t%i\n"
43386 "jp_journal_dev: \t%s[%x]\n"
43387diff -urNp linux-3.0.4/fs/reiserfs/stree.c linux-3.0.4/fs/reiserfs/stree.c
43388--- linux-3.0.4/fs/reiserfs/stree.c 2011-07-21 22:17:23.000000000 -0400
43389+++ linux-3.0.4/fs/reiserfs/stree.c 2011-08-23 21:48:14.000000000 -0400
43390@@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
43391 int iter = 0;
43392 #endif
43393
43394+ pax_track_stack();
43395+
43396 BUG_ON(!th->t_trans_id);
43397
43398 init_tb_struct(th, &s_del_balance, sb, path,
43399@@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
43400 int retval;
43401 int quota_cut_bytes = 0;
43402
43403+ pax_track_stack();
43404+
43405 BUG_ON(!th->t_trans_id);
43406
43407 le_key2cpu_key(&cpu_key, key);
43408@@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
43409 int quota_cut_bytes;
43410 loff_t tail_pos = 0;
43411
43412+ pax_track_stack();
43413+
43414 BUG_ON(!th->t_trans_id);
43415
43416 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
43417@@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
43418 int retval;
43419 int fs_gen;
43420
43421+ pax_track_stack();
43422+
43423 BUG_ON(!th->t_trans_id);
43424
43425 fs_gen = get_generation(inode->i_sb);
43426@@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
43427 int fs_gen = 0;
43428 int quota_bytes = 0;
43429
43430+ pax_track_stack();
43431+
43432 BUG_ON(!th->t_trans_id);
43433
43434 if (inode) { /* Do we count quotas for item? */
43435diff -urNp linux-3.0.4/fs/reiserfs/super.c linux-3.0.4/fs/reiserfs/super.c
43436--- linux-3.0.4/fs/reiserfs/super.c 2011-07-21 22:17:23.000000000 -0400
43437+++ linux-3.0.4/fs/reiserfs/super.c 2011-08-23 21:48:14.000000000 -0400
43438@@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
43439 {.option_name = NULL}
43440 };
43441
43442+ pax_track_stack();
43443+
43444 *blocks = 0;
43445 if (!options || !*options)
43446 /* use default configuration: create tails, journaling on, no
43447diff -urNp linux-3.0.4/fs/select.c linux-3.0.4/fs/select.c
43448--- linux-3.0.4/fs/select.c 2011-07-21 22:17:23.000000000 -0400
43449+++ linux-3.0.4/fs/select.c 2011-08-23 21:48:14.000000000 -0400
43450@@ -20,6 +20,7 @@
43451 #include <linux/module.h>
43452 #include <linux/slab.h>
43453 #include <linux/poll.h>
43454+#include <linux/security.h>
43455 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
43456 #include <linux/file.h>
43457 #include <linux/fdtable.h>
43458@@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
43459 int retval, i, timed_out = 0;
43460 unsigned long slack = 0;
43461
43462+ pax_track_stack();
43463+
43464 rcu_read_lock();
43465 retval = max_select_fd(n, fds);
43466 rcu_read_unlock();
43467@@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
43468 /* Allocate small arguments on the stack to save memory and be faster */
43469 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
43470
43471+ pax_track_stack();
43472+
43473 ret = -EINVAL;
43474 if (n < 0)
43475 goto out_nofds;
43476@@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
43477 struct poll_list *walk = head;
43478 unsigned long todo = nfds;
43479
43480+ pax_track_stack();
43481+
43482+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
43483 if (nfds > rlimit(RLIMIT_NOFILE))
43484 return -EINVAL;
43485
43486diff -urNp linux-3.0.4/fs/seq_file.c linux-3.0.4/fs/seq_file.c
43487--- linux-3.0.4/fs/seq_file.c 2011-07-21 22:17:23.000000000 -0400
43488+++ linux-3.0.4/fs/seq_file.c 2011-08-23 21:47:56.000000000 -0400
43489@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
43490 return 0;
43491 }
43492 if (!m->buf) {
43493- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
43494+ m->size = PAGE_SIZE;
43495+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
43496 if (!m->buf)
43497 return -ENOMEM;
43498 }
43499@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
43500 Eoverflow:
43501 m->op->stop(m, p);
43502 kfree(m->buf);
43503- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
43504+ m->size <<= 1;
43505+ m->buf = kmalloc(m->size, GFP_KERNEL);
43506 return !m->buf ? -ENOMEM : -EAGAIN;
43507 }
43508
43509@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
43510 m->version = file->f_version;
43511 /* grab buffer if we didn't have one */
43512 if (!m->buf) {
43513- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
43514+ m->size = PAGE_SIZE;
43515+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
43516 if (!m->buf)
43517 goto Enomem;
43518 }
43519@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
43520 goto Fill;
43521 m->op->stop(m, p);
43522 kfree(m->buf);
43523- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
43524+ m->size <<= 1;
43525+ m->buf = kmalloc(m->size, GFP_KERNEL);
43526 if (!m->buf)
43527 goto Enomem;
43528 m->count = 0;
43529@@ -549,7 +553,7 @@ static void single_stop(struct seq_file
43530 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
43531 void *data)
43532 {
43533- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
43534+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
43535 int res = -ENOMEM;
43536
43537 if (op) {
43538diff -urNp linux-3.0.4/fs/splice.c linux-3.0.4/fs/splice.c
43539--- linux-3.0.4/fs/splice.c 2011-07-21 22:17:23.000000000 -0400
43540+++ linux-3.0.4/fs/splice.c 2011-08-23 21:48:14.000000000 -0400
43541@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode
43542 pipe_lock(pipe);
43543
43544 for (;;) {
43545- if (!pipe->readers) {
43546+ if (!atomic_read(&pipe->readers)) {
43547 send_sig(SIGPIPE, current, 0);
43548 if (!ret)
43549 ret = -EPIPE;
43550@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode
43551 do_wakeup = 0;
43552 }
43553
43554- pipe->waiting_writers++;
43555+ atomic_inc(&pipe->waiting_writers);
43556 pipe_wait(pipe);
43557- pipe->waiting_writers--;
43558+ atomic_dec(&pipe->waiting_writers);
43559 }
43560
43561 pipe_unlock(pipe);
43562@@ -320,6 +320,8 @@ __generic_file_splice_read(struct file *
43563 .spd_release = spd_release_page,
43564 };
43565
43566+ pax_track_stack();
43567+
43568 if (splice_grow_spd(pipe, &spd))
43569 return -ENOMEM;
43570
43571@@ -560,7 +562,7 @@ static ssize_t kernel_readv(struct file
43572 old_fs = get_fs();
43573 set_fs(get_ds());
43574 /* The cast to a user pointer is valid due to the set_fs() */
43575- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
43576+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
43577 set_fs(old_fs);
43578
43579 return res;
43580@@ -575,7 +577,7 @@ static ssize_t kernel_write(struct file
43581 old_fs = get_fs();
43582 set_fs(get_ds());
43583 /* The cast to a user pointer is valid due to the set_fs() */
43584- res = vfs_write(file, (const char __user *)buf, count, &pos);
43585+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
43586 set_fs(old_fs);
43587
43588 return res;
43589@@ -603,6 +605,8 @@ ssize_t default_file_splice_read(struct
43590 .spd_release = spd_release_page,
43591 };
43592
43593+ pax_track_stack();
43594+
43595 if (splice_grow_spd(pipe, &spd))
43596 return -ENOMEM;
43597
43598@@ -626,7 +630,7 @@ ssize_t default_file_splice_read(struct
43599 goto err;
43600
43601 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
43602- vec[i].iov_base = (void __user *) page_address(page);
43603+ vec[i].iov_base = (__force void __user *) page_address(page);
43604 vec[i].iov_len = this_len;
43605 spd.pages[i] = page;
43606 spd.nr_pages++;
43607@@ -846,10 +850,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
43608 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
43609 {
43610 while (!pipe->nrbufs) {
43611- if (!pipe->writers)
43612+ if (!atomic_read(&pipe->writers))
43613 return 0;
43614
43615- if (!pipe->waiting_writers && sd->num_spliced)
43616+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
43617 return 0;
43618
43619 if (sd->flags & SPLICE_F_NONBLOCK)
43620@@ -1182,7 +1186,7 @@ ssize_t splice_direct_to_actor(struct fi
43621 * out of the pipe right after the splice_to_pipe(). So set
43622 * PIPE_READERS appropriately.
43623 */
43624- pipe->readers = 1;
43625+ atomic_set(&pipe->readers, 1);
43626
43627 current->splice_pipe = pipe;
43628 }
43629@@ -1619,6 +1623,8 @@ static long vmsplice_to_pipe(struct file
43630 };
43631 long ret;
43632
43633+ pax_track_stack();
43634+
43635 pipe = get_pipe_info(file);
43636 if (!pipe)
43637 return -EBADF;
43638@@ -1734,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_
43639 ret = -ERESTARTSYS;
43640 break;
43641 }
43642- if (!pipe->writers)
43643+ if (!atomic_read(&pipe->writers))
43644 break;
43645- if (!pipe->waiting_writers) {
43646+ if (!atomic_read(&pipe->waiting_writers)) {
43647 if (flags & SPLICE_F_NONBLOCK) {
43648 ret = -EAGAIN;
43649 break;
43650@@ -1768,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_
43651 pipe_lock(pipe);
43652
43653 while (pipe->nrbufs >= pipe->buffers) {
43654- if (!pipe->readers) {
43655+ if (!atomic_read(&pipe->readers)) {
43656 send_sig(SIGPIPE, current, 0);
43657 ret = -EPIPE;
43658 break;
43659@@ -1781,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_
43660 ret = -ERESTARTSYS;
43661 break;
43662 }
43663- pipe->waiting_writers++;
43664+ atomic_inc(&pipe->waiting_writers);
43665 pipe_wait(pipe);
43666- pipe->waiting_writers--;
43667+ atomic_dec(&pipe->waiting_writers);
43668 }
43669
43670 pipe_unlock(pipe);
43671@@ -1819,14 +1825,14 @@ retry:
43672 pipe_double_lock(ipipe, opipe);
43673
43674 do {
43675- if (!opipe->readers) {
43676+ if (!atomic_read(&opipe->readers)) {
43677 send_sig(SIGPIPE, current, 0);
43678 if (!ret)
43679 ret = -EPIPE;
43680 break;
43681 }
43682
43683- if (!ipipe->nrbufs && !ipipe->writers)
43684+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
43685 break;
43686
43687 /*
43688@@ -1923,7 +1929,7 @@ static int link_pipe(struct pipe_inode_i
43689 pipe_double_lock(ipipe, opipe);
43690
43691 do {
43692- if (!opipe->readers) {
43693+ if (!atomic_read(&opipe->readers)) {
43694 send_sig(SIGPIPE, current, 0);
43695 if (!ret)
43696 ret = -EPIPE;
43697@@ -1968,7 +1974,7 @@ static int link_pipe(struct pipe_inode_i
43698 * return EAGAIN if we have the potential of some data in the
43699 * future, otherwise just return 0
43700 */
43701- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
43702+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
43703 ret = -EAGAIN;
43704
43705 pipe_unlock(ipipe);
43706diff -urNp linux-3.0.4/fs/sysfs/file.c linux-3.0.4/fs/sysfs/file.c
43707--- linux-3.0.4/fs/sysfs/file.c 2011-07-21 22:17:23.000000000 -0400
43708+++ linux-3.0.4/fs/sysfs/file.c 2011-08-23 21:47:56.000000000 -0400
43709@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
43710
43711 struct sysfs_open_dirent {
43712 atomic_t refcnt;
43713- atomic_t event;
43714+ atomic_unchecked_t event;
43715 wait_queue_head_t poll;
43716 struct list_head buffers; /* goes through sysfs_buffer.list */
43717 };
43718@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentr
43719 if (!sysfs_get_active(attr_sd))
43720 return -ENODEV;
43721
43722- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
43723+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
43724 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
43725
43726 sysfs_put_active(attr_sd);
43727@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct
43728 return -ENOMEM;
43729
43730 atomic_set(&new_od->refcnt, 0);
43731- atomic_set(&new_od->event, 1);
43732+ atomic_set_unchecked(&new_od->event, 1);
43733 init_waitqueue_head(&new_od->poll);
43734 INIT_LIST_HEAD(&new_od->buffers);
43735 goto retry;
43736@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct fi
43737
43738 sysfs_put_active(attr_sd);
43739
43740- if (buffer->event != atomic_read(&od->event))
43741+ if (buffer->event != atomic_read_unchecked(&od->event))
43742 goto trigger;
43743
43744 return DEFAULT_POLLMASK;
43745@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_di
43746
43747 od = sd->s_attr.open;
43748 if (od) {
43749- atomic_inc(&od->event);
43750+ atomic_inc_unchecked(&od->event);
43751 wake_up_interruptible(&od->poll);
43752 }
43753
43754diff -urNp linux-3.0.4/fs/sysfs/mount.c linux-3.0.4/fs/sysfs/mount.c
43755--- linux-3.0.4/fs/sysfs/mount.c 2011-07-21 22:17:23.000000000 -0400
43756+++ linux-3.0.4/fs/sysfs/mount.c 2011-08-23 21:48:14.000000000 -0400
43757@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
43758 .s_name = "",
43759 .s_count = ATOMIC_INIT(1),
43760 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
43761+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43762+ .s_mode = S_IFDIR | S_IRWXU,
43763+#else
43764 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43765+#endif
43766 .s_ino = 1,
43767 };
43768
43769diff -urNp linux-3.0.4/fs/sysfs/symlink.c linux-3.0.4/fs/sysfs/symlink.c
43770--- linux-3.0.4/fs/sysfs/symlink.c 2011-07-21 22:17:23.000000000 -0400
43771+++ linux-3.0.4/fs/sysfs/symlink.c 2011-08-23 21:47:56.000000000 -0400
43772@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
43773
43774 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
43775 {
43776- char *page = nd_get_link(nd);
43777+ const char *page = nd_get_link(nd);
43778 if (!IS_ERR(page))
43779 free_page((unsigned long)page);
43780 }
43781diff -urNp linux-3.0.4/fs/udf/inode.c linux-3.0.4/fs/udf/inode.c
43782--- linux-3.0.4/fs/udf/inode.c 2011-07-21 22:17:23.000000000 -0400
43783+++ linux-3.0.4/fs/udf/inode.c 2011-08-23 21:48:14.000000000 -0400
43784@@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
43785 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
43786 int lastblock = 0;
43787
43788+ pax_track_stack();
43789+
43790 prev_epos.offset = udf_file_entry_alloc_offset(inode);
43791 prev_epos.block = iinfo->i_location;
43792 prev_epos.bh = NULL;
43793diff -urNp linux-3.0.4/fs/udf/misc.c linux-3.0.4/fs/udf/misc.c
43794--- linux-3.0.4/fs/udf/misc.c 2011-07-21 22:17:23.000000000 -0400
43795+++ linux-3.0.4/fs/udf/misc.c 2011-08-23 21:47:56.000000000 -0400
43796@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
43797
43798 u8 udf_tag_checksum(const struct tag *t)
43799 {
43800- u8 *data = (u8 *)t;
43801+ const u8 *data = (const u8 *)t;
43802 u8 checksum = 0;
43803 int i;
43804 for (i = 0; i < sizeof(struct tag); ++i)
43805diff -urNp linux-3.0.4/fs/utimes.c linux-3.0.4/fs/utimes.c
43806--- linux-3.0.4/fs/utimes.c 2011-07-21 22:17:23.000000000 -0400
43807+++ linux-3.0.4/fs/utimes.c 2011-08-23 21:48:14.000000000 -0400
43808@@ -1,6 +1,7 @@
43809 #include <linux/compiler.h>
43810 #include <linux/file.h>
43811 #include <linux/fs.h>
43812+#include <linux/security.h>
43813 #include <linux/linkage.h>
43814 #include <linux/mount.h>
43815 #include <linux/namei.h>
43816@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
43817 goto mnt_drop_write_and_out;
43818 }
43819 }
43820+
43821+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
43822+ error = -EACCES;
43823+ goto mnt_drop_write_and_out;
43824+ }
43825+
43826 mutex_lock(&inode->i_mutex);
43827 error = notify_change(path->dentry, &newattrs);
43828 mutex_unlock(&inode->i_mutex);
43829diff -urNp linux-3.0.4/fs/xattr_acl.c linux-3.0.4/fs/xattr_acl.c
43830--- linux-3.0.4/fs/xattr_acl.c 2011-07-21 22:17:23.000000000 -0400
43831+++ linux-3.0.4/fs/xattr_acl.c 2011-08-23 21:47:56.000000000 -0400
43832@@ -17,8 +17,8 @@
43833 struct posix_acl *
43834 posix_acl_from_xattr(const void *value, size_t size)
43835 {
43836- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
43837- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
43838+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
43839+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
43840 int count;
43841 struct posix_acl *acl;
43842 struct posix_acl_entry *acl_e;
43843diff -urNp linux-3.0.4/fs/xattr.c linux-3.0.4/fs/xattr.c
43844--- linux-3.0.4/fs/xattr.c 2011-07-21 22:17:23.000000000 -0400
43845+++ linux-3.0.4/fs/xattr.c 2011-08-23 21:48:14.000000000 -0400
43846@@ -254,7 +254,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
43847 * Extended attribute SET operations
43848 */
43849 static long
43850-setxattr(struct dentry *d, const char __user *name, const void __user *value,
43851+setxattr(struct path *path, const char __user *name, const void __user *value,
43852 size_t size, int flags)
43853 {
43854 int error;
43855@@ -278,7 +278,13 @@ setxattr(struct dentry *d, const char __
43856 return PTR_ERR(kvalue);
43857 }
43858
43859- error = vfs_setxattr(d, kname, kvalue, size, flags);
43860+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
43861+ error = -EACCES;
43862+ goto out;
43863+ }
43864+
43865+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
43866+out:
43867 kfree(kvalue);
43868 return error;
43869 }
43870@@ -295,7 +301,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
43871 return error;
43872 error = mnt_want_write(path.mnt);
43873 if (!error) {
43874- error = setxattr(path.dentry, name, value, size, flags);
43875+ error = setxattr(&path, name, value, size, flags);
43876 mnt_drop_write(path.mnt);
43877 }
43878 path_put(&path);
43879@@ -314,7 +320,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
43880 return error;
43881 error = mnt_want_write(path.mnt);
43882 if (!error) {
43883- error = setxattr(path.dentry, name, value, size, flags);
43884+ error = setxattr(&path, name, value, size, flags);
43885 mnt_drop_write(path.mnt);
43886 }
43887 path_put(&path);
43888@@ -325,17 +331,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
43889 const void __user *,value, size_t, size, int, flags)
43890 {
43891 struct file *f;
43892- struct dentry *dentry;
43893 int error = -EBADF;
43894
43895 f = fget(fd);
43896 if (!f)
43897 return error;
43898- dentry = f->f_path.dentry;
43899- audit_inode(NULL, dentry);
43900+ audit_inode(NULL, f->f_path.dentry);
43901 error = mnt_want_write_file(f);
43902 if (!error) {
43903- error = setxattr(dentry, name, value, size, flags);
43904+ error = setxattr(&f->f_path, name, value, size, flags);
43905 mnt_drop_write(f->f_path.mnt);
43906 }
43907 fput(f);
43908diff -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
43909--- linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-07-21 22:17:23.000000000 -0400
43910+++ linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-08-23 21:48:14.000000000 -0400
43911@@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
43912 xfs_fsop_geom_t fsgeo;
43913 int error;
43914
43915+ memset(&fsgeo, 0, sizeof(fsgeo));
43916 error = xfs_fs_geometry(mp, &fsgeo, 3);
43917 if (error)
43918 return -error;
43919diff -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
43920--- linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c 2011-07-21 22:17:23.000000000 -0400
43921+++ linux-3.0.4/fs/xfs/linux-2.6/xfs_ioctl.c 2011-08-23 21:47:56.000000000 -0400
43922@@ -128,7 +128,7 @@ xfs_find_handle(
43923 }
43924
43925 error = -EFAULT;
43926- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
43927+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
43928 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
43929 goto out_put;
43930
43931diff -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
43932--- linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c 2011-07-21 22:17:23.000000000 -0400
43933+++ linux-3.0.4/fs/xfs/linux-2.6/xfs_iops.c 2011-08-23 21:47:56.000000000 -0400
43934@@ -437,7 +437,7 @@ xfs_vn_put_link(
43935 struct nameidata *nd,
43936 void *p)
43937 {
43938- char *s = nd_get_link(nd);
43939+ const char *s = nd_get_link(nd);
43940
43941 if (!IS_ERR(s))
43942 kfree(s);
43943diff -urNp linux-3.0.4/fs/xfs/xfs_bmap.c linux-3.0.4/fs/xfs/xfs_bmap.c
43944--- linux-3.0.4/fs/xfs/xfs_bmap.c 2011-07-21 22:17:23.000000000 -0400
43945+++ linux-3.0.4/fs/xfs/xfs_bmap.c 2011-08-23 21:47:56.000000000 -0400
43946@@ -253,7 +253,7 @@ xfs_bmap_validate_ret(
43947 int nmap,
43948 int ret_nmap);
43949 #else
43950-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
43951+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
43952 #endif /* DEBUG */
43953
43954 STATIC int
43955diff -urNp linux-3.0.4/fs/xfs/xfs_dir2_sf.c linux-3.0.4/fs/xfs/xfs_dir2_sf.c
43956--- linux-3.0.4/fs/xfs/xfs_dir2_sf.c 2011-07-21 22:17:23.000000000 -0400
43957+++ linux-3.0.4/fs/xfs/xfs_dir2_sf.c 2011-08-23 21:47:56.000000000 -0400
43958@@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
43959 }
43960
43961 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
43962- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
43963+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
43964+ char name[sfep->namelen];
43965+ memcpy(name, sfep->name, sfep->namelen);
43966+ if (filldir(dirent, name, sfep->namelen,
43967+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
43968+ *offset = off & 0x7fffffff;
43969+ return 0;
43970+ }
43971+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
43972 off & 0x7fffffff, ino, DT_UNKNOWN)) {
43973 *offset = off & 0x7fffffff;
43974 return 0;
43975diff -urNp linux-3.0.4/grsecurity/gracl_alloc.c linux-3.0.4/grsecurity/gracl_alloc.c
43976--- linux-3.0.4/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
43977+++ linux-3.0.4/grsecurity/gracl_alloc.c 2011-08-23 21:48:14.000000000 -0400
43978@@ -0,0 +1,105 @@
43979+#include <linux/kernel.h>
43980+#include <linux/mm.h>
43981+#include <linux/slab.h>
43982+#include <linux/vmalloc.h>
43983+#include <linux/gracl.h>
43984+#include <linux/grsecurity.h>
43985+
43986+static unsigned long alloc_stack_next = 1;
43987+static unsigned long alloc_stack_size = 1;
43988+static void **alloc_stack;
43989+
43990+static __inline__ int
43991+alloc_pop(void)
43992+{
43993+ if (alloc_stack_next == 1)
43994+ return 0;
43995+
43996+ kfree(alloc_stack[alloc_stack_next - 2]);
43997+
43998+ alloc_stack_next--;
43999+
44000+ return 1;
44001+}
44002+
44003+static __inline__ int
44004+alloc_push(void *buf)
44005+{
44006+ if (alloc_stack_next >= alloc_stack_size)
44007+ return 1;
44008+
44009+ alloc_stack[alloc_stack_next - 1] = buf;
44010+
44011+ alloc_stack_next++;
44012+
44013+ return 0;
44014+}
44015+
44016+void *
44017+acl_alloc(unsigned long len)
44018+{
44019+ void *ret = NULL;
44020+
44021+ if (!len || len > PAGE_SIZE)
44022+ goto out;
44023+
44024+ ret = kmalloc(len, GFP_KERNEL);
44025+
44026+ if (ret) {
44027+ if (alloc_push(ret)) {
44028+ kfree(ret);
44029+ ret = NULL;
44030+ }
44031+ }
44032+
44033+out:
44034+ return ret;
44035+}
44036+
44037+void *
44038+acl_alloc_num(unsigned long num, unsigned long len)
44039+{
44040+ if (!len || (num > (PAGE_SIZE / len)))
44041+ return NULL;
44042+
44043+ return acl_alloc(num * len);
44044+}
44045+
44046+void
44047+acl_free_all(void)
44048+{
44049+ if (gr_acl_is_enabled() || !alloc_stack)
44050+ return;
44051+
44052+ while (alloc_pop()) ;
44053+
44054+ if (alloc_stack) {
44055+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
44056+ kfree(alloc_stack);
44057+ else
44058+ vfree(alloc_stack);
44059+ }
44060+
44061+ alloc_stack = NULL;
44062+ alloc_stack_size = 1;
44063+ alloc_stack_next = 1;
44064+
44065+ return;
44066+}
44067+
44068+int
44069+acl_alloc_stack_init(unsigned long size)
44070+{
44071+ if ((size * sizeof (void *)) <= PAGE_SIZE)
44072+ alloc_stack =
44073+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
44074+ else
44075+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
44076+
44077+ alloc_stack_size = size;
44078+
44079+ if (!alloc_stack)
44080+ return 0;
44081+ else
44082+ return 1;
44083+}
44084diff -urNp linux-3.0.4/grsecurity/gracl.c linux-3.0.4/grsecurity/gracl.c
44085--- linux-3.0.4/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
44086+++ linux-3.0.4/grsecurity/gracl.c 2011-08-23 21:48:14.000000000 -0400
44087@@ -0,0 +1,4106 @@
44088+#include <linux/kernel.h>
44089+#include <linux/module.h>
44090+#include <linux/sched.h>
44091+#include <linux/mm.h>
44092+#include <linux/file.h>
44093+#include <linux/fs.h>
44094+#include <linux/namei.h>
44095+#include <linux/mount.h>
44096+#include <linux/tty.h>
44097+#include <linux/proc_fs.h>
44098+#include <linux/lglock.h>
44099+#include <linux/slab.h>
44100+#include <linux/vmalloc.h>
44101+#include <linux/types.h>
44102+#include <linux/sysctl.h>
44103+#include <linux/netdevice.h>
44104+#include <linux/ptrace.h>
44105+#include <linux/gracl.h>
44106+#include <linux/gralloc.h>
44107+#include <linux/grsecurity.h>
44108+#include <linux/grinternal.h>
44109+#include <linux/pid_namespace.h>
44110+#include <linux/fdtable.h>
44111+#include <linux/percpu.h>
44112+
44113+#include <asm/uaccess.h>
44114+#include <asm/errno.h>
44115+#include <asm/mman.h>
44116+
44117+static struct acl_role_db acl_role_set;
44118+static struct name_db name_set;
44119+static struct inodev_db inodev_set;
44120+
44121+/* for keeping track of userspace pointers used for subjects, so we
44122+ can share references in the kernel as well
44123+*/
44124+
44125+static struct path real_root;
44126+
44127+static struct acl_subj_map_db subj_map_set;
44128+
44129+static struct acl_role_label *default_role;
44130+
44131+static struct acl_role_label *role_list;
44132+
44133+static u16 acl_sp_role_value;
44134+
44135+extern char *gr_shared_page[4];
44136+static DEFINE_MUTEX(gr_dev_mutex);
44137+DEFINE_RWLOCK(gr_inode_lock);
44138+
44139+struct gr_arg *gr_usermode;
44140+
44141+static unsigned int gr_status __read_only = GR_STATUS_INIT;
44142+
44143+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
44144+extern void gr_clear_learn_entries(void);
44145+
44146+#ifdef CONFIG_GRKERNSEC_RESLOG
44147+extern void gr_log_resource(const struct task_struct *task,
44148+ const int res, const unsigned long wanted, const int gt);
44149+#endif
44150+
44151+unsigned char *gr_system_salt;
44152+unsigned char *gr_system_sum;
44153+
44154+static struct sprole_pw **acl_special_roles = NULL;
44155+static __u16 num_sprole_pws = 0;
44156+
44157+static struct acl_role_label *kernel_role = NULL;
44158+
44159+static unsigned int gr_auth_attempts = 0;
44160+static unsigned long gr_auth_expires = 0UL;
44161+
44162+#ifdef CONFIG_NET
44163+extern struct vfsmount *sock_mnt;
44164+#endif
44165+
44166+extern struct vfsmount *pipe_mnt;
44167+extern struct vfsmount *shm_mnt;
44168+#ifdef CONFIG_HUGETLBFS
44169+extern struct vfsmount *hugetlbfs_vfsmount;
44170+#endif
44171+
44172+static struct acl_object_label *fakefs_obj_rw;
44173+static struct acl_object_label *fakefs_obj_rwx;
44174+
44175+extern int gr_init_uidset(void);
44176+extern void gr_free_uidset(void);
44177+extern void gr_remove_uid(uid_t uid);
44178+extern int gr_find_uid(uid_t uid);
44179+
44180+DECLARE_BRLOCK(vfsmount_lock);
44181+
44182+__inline__ int
44183+gr_acl_is_enabled(void)
44184+{
44185+ return (gr_status & GR_READY);
44186+}
44187+
44188+#ifdef CONFIG_BTRFS_FS
44189+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
44190+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
44191+#endif
44192+
44193+static inline dev_t __get_dev(const struct dentry *dentry)
44194+{
44195+#ifdef CONFIG_BTRFS_FS
44196+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
44197+ return get_btrfs_dev_from_inode(dentry->d_inode);
44198+ else
44199+#endif
44200+ return dentry->d_inode->i_sb->s_dev;
44201+}
44202+
44203+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
44204+{
44205+ return __get_dev(dentry);
44206+}
44207+
44208+static char gr_task_roletype_to_char(struct task_struct *task)
44209+{
44210+ switch (task->role->roletype &
44211+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
44212+ GR_ROLE_SPECIAL)) {
44213+ case GR_ROLE_DEFAULT:
44214+ return 'D';
44215+ case GR_ROLE_USER:
44216+ return 'U';
44217+ case GR_ROLE_GROUP:
44218+ return 'G';
44219+ case GR_ROLE_SPECIAL:
44220+ return 'S';
44221+ }
44222+
44223+ return 'X';
44224+}
44225+
44226+char gr_roletype_to_char(void)
44227+{
44228+ return gr_task_roletype_to_char(current);
44229+}
44230+
44231+__inline__ int
44232+gr_acl_tpe_check(void)
44233+{
44234+ if (unlikely(!(gr_status & GR_READY)))
44235+ return 0;
44236+ if (current->role->roletype & GR_ROLE_TPE)
44237+ return 1;
44238+ else
44239+ return 0;
44240+}
44241+
44242+int
44243+gr_handle_rawio(const struct inode *inode)
44244+{
44245+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
44246+ if (inode && S_ISBLK(inode->i_mode) &&
44247+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
44248+ !capable(CAP_SYS_RAWIO))
44249+ return 1;
44250+#endif
44251+ return 0;
44252+}
44253+
44254+static int
44255+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
44256+{
44257+ if (likely(lena != lenb))
44258+ return 0;
44259+
44260+ return !memcmp(a, b, lena);
44261+}
44262+
44263+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
44264+{
44265+ *buflen -= namelen;
44266+ if (*buflen < 0)
44267+ return -ENAMETOOLONG;
44268+ *buffer -= namelen;
44269+ memcpy(*buffer, str, namelen);
44270+ return 0;
44271+}
44272+
44273+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
44274+{
44275+ return prepend(buffer, buflen, name->name, name->len);
44276+}
44277+
44278+static int prepend_path(const struct path *path, struct path *root,
44279+ char **buffer, int *buflen)
44280+{
44281+ struct dentry *dentry = path->dentry;
44282+ struct vfsmount *vfsmnt = path->mnt;
44283+ bool slash = false;
44284+ int error = 0;
44285+
44286+ while (dentry != root->dentry || vfsmnt != root->mnt) {
44287+ struct dentry * parent;
44288+
44289+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
44290+ /* Global root? */
44291+ if (vfsmnt->mnt_parent == vfsmnt) {
44292+ goto out;
44293+ }
44294+ dentry = vfsmnt->mnt_mountpoint;
44295+ vfsmnt = vfsmnt->mnt_parent;
44296+ continue;
44297+ }
44298+ parent = dentry->d_parent;
44299+ prefetch(parent);
44300+ spin_lock(&dentry->d_lock);
44301+ error = prepend_name(buffer, buflen, &dentry->d_name);
44302+ spin_unlock(&dentry->d_lock);
44303+ if (!error)
44304+ error = prepend(buffer, buflen, "/", 1);
44305+ if (error)
44306+ break;
44307+
44308+ slash = true;
44309+ dentry = parent;
44310+ }
44311+
44312+out:
44313+ if (!error && !slash)
44314+ error = prepend(buffer, buflen, "/", 1);
44315+
44316+ return error;
44317+}
44318+
44319+/* this must be called with vfsmount_lock and rename_lock held */
44320+
44321+static char *__our_d_path(const struct path *path, struct path *root,
44322+ char *buf, int buflen)
44323+{
44324+ char *res = buf + buflen;
44325+ int error;
44326+
44327+ prepend(&res, &buflen, "\0", 1);
44328+ error = prepend_path(path, root, &res, &buflen);
44329+ if (error)
44330+ return ERR_PTR(error);
44331+
44332+ return res;
44333+}
44334+
44335+static char *
44336+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
44337+{
44338+ char *retval;
44339+
44340+ retval = __our_d_path(path, root, buf, buflen);
44341+ if (unlikely(IS_ERR(retval)))
44342+ retval = strcpy(buf, "<path too long>");
44343+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
44344+ retval[1] = '\0';
44345+
44346+ return retval;
44347+}
44348+
44349+static char *
44350+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
44351+ char *buf, int buflen)
44352+{
44353+ struct path path;
44354+ char *res;
44355+
44356+ path.dentry = (struct dentry *)dentry;
44357+ path.mnt = (struct vfsmount *)vfsmnt;
44358+
44359+ /* we can use real_root.dentry, real_root.mnt, because this is only called
44360+ by the RBAC system */
44361+ res = gen_full_path(&path, &real_root, buf, buflen);
44362+
44363+ return res;
44364+}
44365+
44366+static char *
44367+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
44368+ char *buf, int buflen)
44369+{
44370+ char *res;
44371+ struct path path;
44372+ struct path root;
44373+ struct task_struct *reaper = &init_task;
44374+
44375+ path.dentry = (struct dentry *)dentry;
44376+ path.mnt = (struct vfsmount *)vfsmnt;
44377+
44378+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
44379+ get_fs_root(reaper->fs, &root);
44380+
44381+ write_seqlock(&rename_lock);
44382+ br_read_lock(vfsmount_lock);
44383+ res = gen_full_path(&path, &root, buf, buflen);
44384+ br_read_unlock(vfsmount_lock);
44385+ write_sequnlock(&rename_lock);
44386+
44387+ path_put(&root);
44388+ return res;
44389+}
44390+
44391+static char *
44392+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
44393+{
44394+ char *ret;
44395+ write_seqlock(&rename_lock);
44396+ br_read_lock(vfsmount_lock);
44397+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
44398+ PAGE_SIZE);
44399+ br_read_unlock(vfsmount_lock);
44400+ write_sequnlock(&rename_lock);
44401+ return ret;
44402+}
44403+
44404+char *
44405+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
44406+{
44407+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
44408+ PAGE_SIZE);
44409+}
44410+
44411+char *
44412+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
44413+{
44414+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
44415+ PAGE_SIZE);
44416+}
44417+
44418+char *
44419+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
44420+{
44421+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
44422+ PAGE_SIZE);
44423+}
44424+
44425+char *
44426+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
44427+{
44428+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
44429+ PAGE_SIZE);
44430+}
44431+
44432+char *
44433+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
44434+{
44435+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
44436+ PAGE_SIZE);
44437+}
44438+
44439+__inline__ __u32
44440+to_gr_audit(const __u32 reqmode)
44441+{
44442+ /* masks off auditable permission flags, then shifts them to create
44443+ auditing flags, and adds the special case of append auditing if
44444+ we're requesting write */
44445+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
44446+}
44447+
44448+struct acl_subject_label *
44449+lookup_subject_map(const struct acl_subject_label *userp)
44450+{
44451+ unsigned int index = shash(userp, subj_map_set.s_size);
44452+ struct subject_map *match;
44453+
44454+ match = subj_map_set.s_hash[index];
44455+
44456+ while (match && match->user != userp)
44457+ match = match->next;
44458+
44459+ if (match != NULL)
44460+ return match->kernel;
44461+ else
44462+ return NULL;
44463+}
44464+
44465+static void
44466+insert_subj_map_entry(struct subject_map *subjmap)
44467+{
44468+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
44469+ struct subject_map **curr;
44470+
44471+ subjmap->prev = NULL;
44472+
44473+ curr = &subj_map_set.s_hash[index];
44474+ if (*curr != NULL)
44475+ (*curr)->prev = subjmap;
44476+
44477+ subjmap->next = *curr;
44478+ *curr = subjmap;
44479+
44480+ return;
44481+}
44482+
44483+static struct acl_role_label *
44484+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
44485+ const gid_t gid)
44486+{
44487+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
44488+ struct acl_role_label *match;
44489+ struct role_allowed_ip *ipp;
44490+ unsigned int x;
44491+ u32 curr_ip = task->signal->curr_ip;
44492+
44493+ task->signal->saved_ip = curr_ip;
44494+
44495+ match = acl_role_set.r_hash[index];
44496+
44497+ while (match) {
44498+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
44499+ for (x = 0; x < match->domain_child_num; x++) {
44500+ if (match->domain_children[x] == uid)
44501+ goto found;
44502+ }
44503+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
44504+ break;
44505+ match = match->next;
44506+ }
44507+found:
44508+ if (match == NULL) {
44509+ try_group:
44510+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
44511+ match = acl_role_set.r_hash[index];
44512+
44513+ while (match) {
44514+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
44515+ for (x = 0; x < match->domain_child_num; x++) {
44516+ if (match->domain_children[x] == gid)
44517+ goto found2;
44518+ }
44519+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
44520+ break;
44521+ match = match->next;
44522+ }
44523+found2:
44524+ if (match == NULL)
44525+ match = default_role;
44526+ if (match->allowed_ips == NULL)
44527+ return match;
44528+ else {
44529+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
44530+ if (likely
44531+ ((ntohl(curr_ip) & ipp->netmask) ==
44532+ (ntohl(ipp->addr) & ipp->netmask)))
44533+ return match;
44534+ }
44535+ match = default_role;
44536+ }
44537+ } else if (match->allowed_ips == NULL) {
44538+ return match;
44539+ } else {
44540+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
44541+ if (likely
44542+ ((ntohl(curr_ip) & ipp->netmask) ==
44543+ (ntohl(ipp->addr) & ipp->netmask)))
44544+ return match;
44545+ }
44546+ goto try_group;
44547+ }
44548+
44549+ return match;
44550+}
44551+
44552+struct acl_subject_label *
44553+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
44554+ const struct acl_role_label *role)
44555+{
44556+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
44557+ struct acl_subject_label *match;
44558+
44559+ match = role->subj_hash[index];
44560+
44561+ while (match && (match->inode != ino || match->device != dev ||
44562+ (match->mode & GR_DELETED))) {
44563+ match = match->next;
44564+ }
44565+
44566+ if (match && !(match->mode & GR_DELETED))
44567+ return match;
44568+ else
44569+ return NULL;
44570+}
44571+
44572+struct acl_subject_label *
44573+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
44574+ const struct acl_role_label *role)
44575+{
44576+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
44577+ struct acl_subject_label *match;
44578+
44579+ match = role->subj_hash[index];
44580+
44581+ while (match && (match->inode != ino || match->device != dev ||
44582+ !(match->mode & GR_DELETED))) {
44583+ match = match->next;
44584+ }
44585+
44586+ if (match && (match->mode & GR_DELETED))
44587+ return match;
44588+ else
44589+ return NULL;
44590+}
44591+
44592+static struct acl_object_label *
44593+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
44594+ const struct acl_subject_label *subj)
44595+{
44596+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
44597+ struct acl_object_label *match;
44598+
44599+ match = subj->obj_hash[index];
44600+
44601+ while (match && (match->inode != ino || match->device != dev ||
44602+ (match->mode & GR_DELETED))) {
44603+ match = match->next;
44604+ }
44605+
44606+ if (match && !(match->mode & GR_DELETED))
44607+ return match;
44608+ else
44609+ return NULL;
44610+}
44611+
44612+static struct acl_object_label *
44613+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
44614+ const struct acl_subject_label *subj)
44615+{
44616+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
44617+ struct acl_object_label *match;
44618+
44619+ match = subj->obj_hash[index];
44620+
44621+ while (match && (match->inode != ino || match->device != dev ||
44622+ !(match->mode & GR_DELETED))) {
44623+ match = match->next;
44624+ }
44625+
44626+ if (match && (match->mode & GR_DELETED))
44627+ return match;
44628+
44629+ match = subj->obj_hash[index];
44630+
44631+ while (match && (match->inode != ino || match->device != dev ||
44632+ (match->mode & GR_DELETED))) {
44633+ match = match->next;
44634+ }
44635+
44636+ if (match && !(match->mode & GR_DELETED))
44637+ return match;
44638+ else
44639+ return NULL;
44640+}
44641+
44642+static struct name_entry *
44643+lookup_name_entry(const char *name)
44644+{
44645+ unsigned int len = strlen(name);
44646+ unsigned int key = full_name_hash(name, len);
44647+ unsigned int index = key % name_set.n_size;
44648+ struct name_entry *match;
44649+
44650+ match = name_set.n_hash[index];
44651+
44652+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
44653+ match = match->next;
44654+
44655+ return match;
44656+}
44657+
44658+static struct name_entry *
44659+lookup_name_entry_create(const char *name)
44660+{
44661+ unsigned int len = strlen(name);
44662+ unsigned int key = full_name_hash(name, len);
44663+ unsigned int index = key % name_set.n_size;
44664+ struct name_entry *match;
44665+
44666+ match = name_set.n_hash[index];
44667+
44668+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
44669+ !match->deleted))
44670+ match = match->next;
44671+
44672+ if (match && match->deleted)
44673+ return match;
44674+
44675+ match = name_set.n_hash[index];
44676+
44677+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
44678+ match->deleted))
44679+ match = match->next;
44680+
44681+ if (match && !match->deleted)
44682+ return match;
44683+ else
44684+ return NULL;
44685+}
44686+
44687+static struct inodev_entry *
44688+lookup_inodev_entry(const ino_t ino, const dev_t dev)
44689+{
44690+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
44691+ struct inodev_entry *match;
44692+
44693+ match = inodev_set.i_hash[index];
44694+
44695+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
44696+ match = match->next;
44697+
44698+ return match;
44699+}
44700+
44701+static void
44702+insert_inodev_entry(struct inodev_entry *entry)
44703+{
44704+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
44705+ inodev_set.i_size);
44706+ struct inodev_entry **curr;
44707+
44708+ entry->prev = NULL;
44709+
44710+ curr = &inodev_set.i_hash[index];
44711+ if (*curr != NULL)
44712+ (*curr)->prev = entry;
44713+
44714+ entry->next = *curr;
44715+ *curr = entry;
44716+
44717+ return;
44718+}
44719+
44720+static void
44721+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
44722+{
44723+ unsigned int index =
44724+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
44725+ struct acl_role_label **curr;
44726+ struct acl_role_label *tmp;
44727+
44728+ curr = &acl_role_set.r_hash[index];
44729+
44730+ /* if role was already inserted due to domains and already has
44731+ a role in the same bucket as it attached, then we need to
44732+ combine these two buckets
44733+ */
44734+ if (role->next) {
44735+ tmp = role->next;
44736+ while (tmp->next)
44737+ tmp = tmp->next;
44738+ tmp->next = *curr;
44739+ } else
44740+ role->next = *curr;
44741+ *curr = role;
44742+
44743+ return;
44744+}
44745+
44746+static void
44747+insert_acl_role_label(struct acl_role_label *role)
44748+{
44749+ int i;
44750+
44751+ if (role_list == NULL) {
44752+ role_list = role;
44753+ role->prev = NULL;
44754+ } else {
44755+ role->prev = role_list;
44756+ role_list = role;
44757+ }
44758+
44759+ /* used for hash chains */
44760+ role->next = NULL;
44761+
44762+ if (role->roletype & GR_ROLE_DOMAIN) {
44763+ for (i = 0; i < role->domain_child_num; i++)
44764+ __insert_acl_role_label(role, role->domain_children[i]);
44765+ } else
44766+ __insert_acl_role_label(role, role->uidgid);
44767+}
44768+
44769+static int
44770+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
44771+{
44772+ struct name_entry **curr, *nentry;
44773+ struct inodev_entry *ientry;
44774+ unsigned int len = strlen(name);
44775+ unsigned int key = full_name_hash(name, len);
44776+ unsigned int index = key % name_set.n_size;
44777+
44778+ curr = &name_set.n_hash[index];
44779+
44780+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
44781+ curr = &((*curr)->next);
44782+
44783+ if (*curr != NULL)
44784+ return 1;
44785+
44786+ nentry = acl_alloc(sizeof (struct name_entry));
44787+ if (nentry == NULL)
44788+ return 0;
44789+ ientry = acl_alloc(sizeof (struct inodev_entry));
44790+ if (ientry == NULL)
44791+ return 0;
44792+ ientry->nentry = nentry;
44793+
44794+ nentry->key = key;
44795+ nentry->name = name;
44796+ nentry->inode = inode;
44797+ nentry->device = device;
44798+ nentry->len = len;
44799+ nentry->deleted = deleted;
44800+
44801+ nentry->prev = NULL;
44802+ curr = &name_set.n_hash[index];
44803+ if (*curr != NULL)
44804+ (*curr)->prev = nentry;
44805+ nentry->next = *curr;
44806+ *curr = nentry;
44807+
44808+ /* insert us into the table searchable by inode/dev */
44809+ insert_inodev_entry(ientry);
44810+
44811+ return 1;
44812+}
44813+
44814+static void
44815+insert_acl_obj_label(struct acl_object_label *obj,
44816+ struct acl_subject_label *subj)
44817+{
44818+ unsigned int index =
44819+ fhash(obj->inode, obj->device, subj->obj_hash_size);
44820+ struct acl_object_label **curr;
44821+
44822+
44823+ obj->prev = NULL;
44824+
44825+ curr = &subj->obj_hash[index];
44826+ if (*curr != NULL)
44827+ (*curr)->prev = obj;
44828+
44829+ obj->next = *curr;
44830+ *curr = obj;
44831+
44832+ return;
44833+}
44834+
44835+static void
44836+insert_acl_subj_label(struct acl_subject_label *obj,
44837+ struct acl_role_label *role)
44838+{
44839+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
44840+ struct acl_subject_label **curr;
44841+
44842+ obj->prev = NULL;
44843+
44844+ curr = &role->subj_hash[index];
44845+ if (*curr != NULL)
44846+ (*curr)->prev = obj;
44847+
44848+ obj->next = *curr;
44849+ *curr = obj;
44850+
44851+ return;
44852+}
44853+
44854+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
44855+
44856+static void *
44857+create_table(__u32 * len, int elementsize)
44858+{
44859+ unsigned int table_sizes[] = {
44860+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
44861+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
44862+ 4194301, 8388593, 16777213, 33554393, 67108859
44863+ };
44864+ void *newtable = NULL;
44865+ unsigned int pwr = 0;
44866+
44867+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
44868+ table_sizes[pwr] <= *len)
44869+ pwr++;
44870+
44871+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
44872+ return newtable;
44873+
44874+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
44875+ newtable =
44876+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
44877+ else
44878+ newtable = vmalloc(table_sizes[pwr] * elementsize);
44879+
44880+ *len = table_sizes[pwr];
44881+
44882+ return newtable;
44883+}
44884+
44885+static int
44886+init_variables(const struct gr_arg *arg)
44887+{
44888+ struct task_struct *reaper = &init_task;
44889+ unsigned int stacksize;
44890+
44891+ subj_map_set.s_size = arg->role_db.num_subjects;
44892+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
44893+ name_set.n_size = arg->role_db.num_objects;
44894+ inodev_set.i_size = arg->role_db.num_objects;
44895+
44896+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
44897+ !name_set.n_size || !inodev_set.i_size)
44898+ return 1;
44899+
44900+ if (!gr_init_uidset())
44901+ return 1;
44902+
44903+ /* set up the stack that holds allocation info */
44904+
44905+ stacksize = arg->role_db.num_pointers + 5;
44906+
44907+ if (!acl_alloc_stack_init(stacksize))
44908+ return 1;
44909+
44910+ /* grab reference for the real root dentry and vfsmount */
44911+ get_fs_root(reaper->fs, &real_root);
44912+
44913+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
44914+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
44915+#endif
44916+
44917+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
44918+ if (fakefs_obj_rw == NULL)
44919+ return 1;
44920+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
44921+
44922+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
44923+ if (fakefs_obj_rwx == NULL)
44924+ return 1;
44925+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
44926+
44927+ subj_map_set.s_hash =
44928+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
44929+ acl_role_set.r_hash =
44930+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
44931+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
44932+ inodev_set.i_hash =
44933+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
44934+
44935+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
44936+ !name_set.n_hash || !inodev_set.i_hash)
44937+ return 1;
44938+
44939+ memset(subj_map_set.s_hash, 0,
44940+ sizeof(struct subject_map *) * subj_map_set.s_size);
44941+ memset(acl_role_set.r_hash, 0,
44942+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
44943+ memset(name_set.n_hash, 0,
44944+ sizeof (struct name_entry *) * name_set.n_size);
44945+ memset(inodev_set.i_hash, 0,
44946+ sizeof (struct inodev_entry *) * inodev_set.i_size);
44947+
44948+ return 0;
44949+}
44950+
44951+/* free information not needed after startup
44952+ currently contains user->kernel pointer mappings for subjects
44953+*/
44954+
44955+static void
44956+free_init_variables(void)
44957+{
44958+ __u32 i;
44959+
44960+ if (subj_map_set.s_hash) {
44961+ for (i = 0; i < subj_map_set.s_size; i++) {
44962+ if (subj_map_set.s_hash[i]) {
44963+ kfree(subj_map_set.s_hash[i]);
44964+ subj_map_set.s_hash[i] = NULL;
44965+ }
44966+ }
44967+
44968+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
44969+ PAGE_SIZE)
44970+ kfree(subj_map_set.s_hash);
44971+ else
44972+ vfree(subj_map_set.s_hash);
44973+ }
44974+
44975+ return;
44976+}
44977+
44978+static void
44979+free_variables(void)
44980+{
44981+ struct acl_subject_label *s;
44982+ struct acl_role_label *r;
44983+ struct task_struct *task, *task2;
44984+ unsigned int x;
44985+
44986+ gr_clear_learn_entries();
44987+
44988+ read_lock(&tasklist_lock);
44989+ do_each_thread(task2, task) {
44990+ task->acl_sp_role = 0;
44991+ task->acl_role_id = 0;
44992+ task->acl = NULL;
44993+ task->role = NULL;
44994+ } while_each_thread(task2, task);
44995+ read_unlock(&tasklist_lock);
44996+
44997+ /* release the reference to the real root dentry and vfsmount */
44998+ path_put(&real_root);
44999+
45000+ /* free all object hash tables */
45001+
45002+ FOR_EACH_ROLE_START(r)
45003+ if (r->subj_hash == NULL)
45004+ goto next_role;
45005+ FOR_EACH_SUBJECT_START(r, s, x)
45006+ if (s->obj_hash == NULL)
45007+ break;
45008+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
45009+ kfree(s->obj_hash);
45010+ else
45011+ vfree(s->obj_hash);
45012+ FOR_EACH_SUBJECT_END(s, x)
45013+ FOR_EACH_NESTED_SUBJECT_START(r, s)
45014+ if (s->obj_hash == NULL)
45015+ break;
45016+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
45017+ kfree(s->obj_hash);
45018+ else
45019+ vfree(s->obj_hash);
45020+ FOR_EACH_NESTED_SUBJECT_END(s)
45021+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
45022+ kfree(r->subj_hash);
45023+ else
45024+ vfree(r->subj_hash);
45025+ r->subj_hash = NULL;
45026+next_role:
45027+ FOR_EACH_ROLE_END(r)
45028+
45029+ acl_free_all();
45030+
45031+ if (acl_role_set.r_hash) {
45032+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
45033+ PAGE_SIZE)
45034+ kfree(acl_role_set.r_hash);
45035+ else
45036+ vfree(acl_role_set.r_hash);
45037+ }
45038+ if (name_set.n_hash) {
45039+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
45040+ PAGE_SIZE)
45041+ kfree(name_set.n_hash);
45042+ else
45043+ vfree(name_set.n_hash);
45044+ }
45045+
45046+ if (inodev_set.i_hash) {
45047+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
45048+ PAGE_SIZE)
45049+ kfree(inodev_set.i_hash);
45050+ else
45051+ vfree(inodev_set.i_hash);
45052+ }
45053+
45054+ gr_free_uidset();
45055+
45056+ memset(&name_set, 0, sizeof (struct name_db));
45057+ memset(&inodev_set, 0, sizeof (struct inodev_db));
45058+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
45059+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
45060+
45061+ default_role = NULL;
45062+ role_list = NULL;
45063+
45064+ return;
45065+}
45066+
45067+static __u32
45068+count_user_objs(struct acl_object_label *userp)
45069+{
45070+ struct acl_object_label o_tmp;
45071+ __u32 num = 0;
45072+
45073+ while (userp) {
45074+ if (copy_from_user(&o_tmp, userp,
45075+ sizeof (struct acl_object_label)))
45076+ break;
45077+
45078+ userp = o_tmp.prev;
45079+ num++;
45080+ }
45081+
45082+ return num;
45083+}
45084+
45085+static struct acl_subject_label *
45086+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
45087+
45088+static int
45089+copy_user_glob(struct acl_object_label *obj)
45090+{
45091+ struct acl_object_label *g_tmp, **guser;
45092+ unsigned int len;
45093+ char *tmp;
45094+
45095+ if (obj->globbed == NULL)
45096+ return 0;
45097+
45098+ guser = &obj->globbed;
45099+ while (*guser) {
45100+ g_tmp = (struct acl_object_label *)
45101+ acl_alloc(sizeof (struct acl_object_label));
45102+ if (g_tmp == NULL)
45103+ return -ENOMEM;
45104+
45105+ if (copy_from_user(g_tmp, *guser,
45106+ sizeof (struct acl_object_label)))
45107+ return -EFAULT;
45108+
45109+ len = strnlen_user(g_tmp->filename, PATH_MAX);
45110+
45111+ if (!len || len >= PATH_MAX)
45112+ return -EINVAL;
45113+
45114+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45115+ return -ENOMEM;
45116+
45117+ if (copy_from_user(tmp, g_tmp->filename, len))
45118+ return -EFAULT;
45119+ tmp[len-1] = '\0';
45120+ g_tmp->filename = tmp;
45121+
45122+ *guser = g_tmp;
45123+ guser = &(g_tmp->next);
45124+ }
45125+
45126+ return 0;
45127+}
45128+
45129+static int
45130+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
45131+ struct acl_role_label *role)
45132+{
45133+ struct acl_object_label *o_tmp;
45134+ unsigned int len;
45135+ int ret;
45136+ char *tmp;
45137+
45138+ while (userp) {
45139+ if ((o_tmp = (struct acl_object_label *)
45140+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
45141+ return -ENOMEM;
45142+
45143+ if (copy_from_user(o_tmp, userp,
45144+ sizeof (struct acl_object_label)))
45145+ return -EFAULT;
45146+
45147+ userp = o_tmp->prev;
45148+
45149+ len = strnlen_user(o_tmp->filename, PATH_MAX);
45150+
45151+ if (!len || len >= PATH_MAX)
45152+ return -EINVAL;
45153+
45154+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45155+ return -ENOMEM;
45156+
45157+ if (copy_from_user(tmp, o_tmp->filename, len))
45158+ return -EFAULT;
45159+ tmp[len-1] = '\0';
45160+ o_tmp->filename = tmp;
45161+
45162+ insert_acl_obj_label(o_tmp, subj);
45163+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
45164+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
45165+ return -ENOMEM;
45166+
45167+ ret = copy_user_glob(o_tmp);
45168+ if (ret)
45169+ return ret;
45170+
45171+ if (o_tmp->nested) {
45172+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
45173+ if (IS_ERR(o_tmp->nested))
45174+ return PTR_ERR(o_tmp->nested);
45175+
45176+ /* insert into nested subject list */
45177+ o_tmp->nested->next = role->hash->first;
45178+ role->hash->first = o_tmp->nested;
45179+ }
45180+ }
45181+
45182+ return 0;
45183+}
45184+
45185+static __u32
45186+count_user_subjs(struct acl_subject_label *userp)
45187+{
45188+ struct acl_subject_label s_tmp;
45189+ __u32 num = 0;
45190+
45191+ while (userp) {
45192+ if (copy_from_user(&s_tmp, userp,
45193+ sizeof (struct acl_subject_label)))
45194+ break;
45195+
45196+ userp = s_tmp.prev;
45197+ /* do not count nested subjects against this count, since
45198+ they are not included in the hash table, but are
45199+ attached to objects. We have already counted
45200+ the subjects in userspace for the allocation
45201+ stack
45202+ */
45203+ if (!(s_tmp.mode & GR_NESTED))
45204+ num++;
45205+ }
45206+
45207+ return num;
45208+}
45209+
45210+static int
45211+copy_user_allowedips(struct acl_role_label *rolep)
45212+{
45213+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
45214+
45215+ ruserip = rolep->allowed_ips;
45216+
45217+ while (ruserip) {
45218+ rlast = rtmp;
45219+
45220+ if ((rtmp = (struct role_allowed_ip *)
45221+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
45222+ return -ENOMEM;
45223+
45224+ if (copy_from_user(rtmp, ruserip,
45225+ sizeof (struct role_allowed_ip)))
45226+ return -EFAULT;
45227+
45228+ ruserip = rtmp->prev;
45229+
45230+ if (!rlast) {
45231+ rtmp->prev = NULL;
45232+ rolep->allowed_ips = rtmp;
45233+ } else {
45234+ rlast->next = rtmp;
45235+ rtmp->prev = rlast;
45236+ }
45237+
45238+ if (!ruserip)
45239+ rtmp->next = NULL;
45240+ }
45241+
45242+ return 0;
45243+}
45244+
45245+static int
45246+copy_user_transitions(struct acl_role_label *rolep)
45247+{
45248+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
45249+
45250+ unsigned int len;
45251+ char *tmp;
45252+
45253+ rusertp = rolep->transitions;
45254+
45255+ while (rusertp) {
45256+ rlast = rtmp;
45257+
45258+ if ((rtmp = (struct role_transition *)
45259+ acl_alloc(sizeof (struct role_transition))) == NULL)
45260+ return -ENOMEM;
45261+
45262+ if (copy_from_user(rtmp, rusertp,
45263+ sizeof (struct role_transition)))
45264+ return -EFAULT;
45265+
45266+ rusertp = rtmp->prev;
45267+
45268+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
45269+
45270+ if (!len || len >= GR_SPROLE_LEN)
45271+ return -EINVAL;
45272+
45273+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45274+ return -ENOMEM;
45275+
45276+ if (copy_from_user(tmp, rtmp->rolename, len))
45277+ return -EFAULT;
45278+ tmp[len-1] = '\0';
45279+ rtmp->rolename = tmp;
45280+
45281+ if (!rlast) {
45282+ rtmp->prev = NULL;
45283+ rolep->transitions = rtmp;
45284+ } else {
45285+ rlast->next = rtmp;
45286+ rtmp->prev = rlast;
45287+ }
45288+
45289+ if (!rusertp)
45290+ rtmp->next = NULL;
45291+ }
45292+
45293+ return 0;
45294+}
45295+
45296+static struct acl_subject_label *
45297+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
45298+{
45299+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
45300+ unsigned int len;
45301+ char *tmp;
45302+ __u32 num_objs;
45303+ struct acl_ip_label **i_tmp, *i_utmp2;
45304+ struct gr_hash_struct ghash;
45305+ struct subject_map *subjmap;
45306+ unsigned int i_num;
45307+ int err;
45308+
45309+ s_tmp = lookup_subject_map(userp);
45310+
45311+ /* we've already copied this subject into the kernel, just return
45312+ the reference to it, and don't copy it over again
45313+ */
45314+ if (s_tmp)
45315+ return(s_tmp);
45316+
45317+ if ((s_tmp = (struct acl_subject_label *)
45318+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
45319+ return ERR_PTR(-ENOMEM);
45320+
45321+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
45322+ if (subjmap == NULL)
45323+ return ERR_PTR(-ENOMEM);
45324+
45325+ subjmap->user = userp;
45326+ subjmap->kernel = s_tmp;
45327+ insert_subj_map_entry(subjmap);
45328+
45329+ if (copy_from_user(s_tmp, userp,
45330+ sizeof (struct acl_subject_label)))
45331+ return ERR_PTR(-EFAULT);
45332+
45333+ len = strnlen_user(s_tmp->filename, PATH_MAX);
45334+
45335+ if (!len || len >= PATH_MAX)
45336+ return ERR_PTR(-EINVAL);
45337+
45338+ if ((tmp = (char *) acl_alloc(len)) == NULL)
45339+ return ERR_PTR(-ENOMEM);
45340+
45341+ if (copy_from_user(tmp, s_tmp->filename, len))
45342+ return ERR_PTR(-EFAULT);
45343+ tmp[len-1] = '\0';
45344+ s_tmp->filename = tmp;
45345+
45346+ if (!strcmp(s_tmp->filename, "/"))
45347+ role->root_label = s_tmp;
45348+
45349+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
45350+ return ERR_PTR(-EFAULT);
45351+
45352+ /* copy user and group transition tables */
45353+
45354+ if (s_tmp->user_trans_num) {
45355+ uid_t *uidlist;
45356+
45357+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
45358+ if (uidlist == NULL)
45359+ return ERR_PTR(-ENOMEM);
45360+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
45361+ return ERR_PTR(-EFAULT);
45362+
45363+ s_tmp->user_transitions = uidlist;
45364+ }
45365+
45366+ if (s_tmp->group_trans_num) {
45367+ gid_t *gidlist;
45368+
45369+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
45370+ if (gidlist == NULL)
45371+ return ERR_PTR(-ENOMEM);
45372+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
45373+ return ERR_PTR(-EFAULT);
45374+
45375+ s_tmp->group_transitions = gidlist;
45376+ }
45377+
45378+ /* set up object hash table */
45379+ num_objs = count_user_objs(ghash.first);
45380+
45381+ s_tmp->obj_hash_size = num_objs;
45382+ s_tmp->obj_hash =
45383+ (struct acl_object_label **)
45384+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
45385+
45386+ if (!s_tmp->obj_hash)
45387+ return ERR_PTR(-ENOMEM);
45388+
45389+ memset(s_tmp->obj_hash, 0,
45390+ s_tmp->obj_hash_size *
45391+ sizeof (struct acl_object_label *));
45392+
45393+ /* add in objects */
45394+ err = copy_user_objs(ghash.first, s_tmp, role);
45395+
45396+ if (err)
45397+ return ERR_PTR(err);
45398+
45399+ /* set pointer for parent subject */
45400+ if (s_tmp->parent_subject) {
45401+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
45402+
45403+ if (IS_ERR(s_tmp2))
45404+ return s_tmp2;
45405+
45406+ s_tmp->parent_subject = s_tmp2;
45407+ }
45408+
45409+ /* add in ip acls */
45410+
45411+ if (!s_tmp->ip_num) {
45412+ s_tmp->ips = NULL;
45413+ goto insert;
45414+ }
45415+
45416+ i_tmp =
45417+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
45418+ sizeof (struct acl_ip_label *));
45419+
45420+ if (!i_tmp)
45421+ return ERR_PTR(-ENOMEM);
45422+
45423+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
45424+ *(i_tmp + i_num) =
45425+ (struct acl_ip_label *)
45426+ acl_alloc(sizeof (struct acl_ip_label));
45427+ if (!*(i_tmp + i_num))
45428+ return ERR_PTR(-ENOMEM);
45429+
45430+ if (copy_from_user
45431+ (&i_utmp2, s_tmp->ips + i_num,
45432+ sizeof (struct acl_ip_label *)))
45433+ return ERR_PTR(-EFAULT);
45434+
45435+ if (copy_from_user
45436+ (*(i_tmp + i_num), i_utmp2,
45437+ sizeof (struct acl_ip_label)))
45438+ return ERR_PTR(-EFAULT);
45439+
45440+ if ((*(i_tmp + i_num))->iface == NULL)
45441+ continue;
45442+
45443+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
45444+ if (!len || len >= IFNAMSIZ)
45445+ return ERR_PTR(-EINVAL);
45446+ tmp = acl_alloc(len);
45447+ if (tmp == NULL)
45448+ return ERR_PTR(-ENOMEM);
45449+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
45450+ return ERR_PTR(-EFAULT);
45451+ (*(i_tmp + i_num))->iface = tmp;
45452+ }
45453+
45454+ s_tmp->ips = i_tmp;
45455+
45456+insert:
45457+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
45458+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
45459+ return ERR_PTR(-ENOMEM);
45460+
45461+ return s_tmp;
45462+}
45463+
45464+static int
45465+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
45466+{
45467+ struct acl_subject_label s_pre;
45468+ struct acl_subject_label * ret;
45469+ int err;
45470+
45471+ while (userp) {
45472+ if (copy_from_user(&s_pre, userp,
45473+ sizeof (struct acl_subject_label)))
45474+ return -EFAULT;
45475+
45476+ /* do not add nested subjects here, add
45477+ while parsing objects
45478+ */
45479+
45480+ if (s_pre.mode & GR_NESTED) {
45481+ userp = s_pre.prev;
45482+ continue;
45483+ }
45484+
45485+ ret = do_copy_user_subj(userp, role);
45486+
45487+ err = PTR_ERR(ret);
45488+ if (IS_ERR(ret))
45489+ return err;
45490+
45491+ insert_acl_subj_label(ret, role);
45492+
45493+ userp = s_pre.prev;
45494+ }
45495+
45496+ return 0;
45497+}
45498+
45499+static int
45500+copy_user_acl(struct gr_arg *arg)
45501+{
45502+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
45503+ struct sprole_pw *sptmp;
45504+ struct gr_hash_struct *ghash;
45505+ uid_t *domainlist;
45506+ unsigned int r_num;
45507+ unsigned int len;
45508+ char *tmp;
45509+ int err = 0;
45510+ __u16 i;
45511+ __u32 num_subjs;
45512+
45513+ /* we need a default and kernel role */
45514+ if (arg->role_db.num_roles < 2)
45515+ return -EINVAL;
45516+
45517+ /* copy special role authentication info from userspace */
45518+
45519+ num_sprole_pws = arg->num_sprole_pws;
45520+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
45521+
45522+ if (!acl_special_roles) {
45523+ err = -ENOMEM;
45524+ goto cleanup;
45525+ }
45526+
45527+ for (i = 0; i < num_sprole_pws; i++) {
45528+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
45529+ if (!sptmp) {
45530+ err = -ENOMEM;
45531+ goto cleanup;
45532+ }
45533+ if (copy_from_user(sptmp, arg->sprole_pws + i,
45534+ sizeof (struct sprole_pw))) {
45535+ err = -EFAULT;
45536+ goto cleanup;
45537+ }
45538+
45539+ len =
45540+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
45541+
45542+ if (!len || len >= GR_SPROLE_LEN) {
45543+ err = -EINVAL;
45544+ goto cleanup;
45545+ }
45546+
45547+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
45548+ err = -ENOMEM;
45549+ goto cleanup;
45550+ }
45551+
45552+ if (copy_from_user(tmp, sptmp->rolename, len)) {
45553+ err = -EFAULT;
45554+ goto cleanup;
45555+ }
45556+ tmp[len-1] = '\0';
45557+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
45558+ printk(KERN_ALERT "Copying special role %s\n", tmp);
45559+#endif
45560+ sptmp->rolename = tmp;
45561+ acl_special_roles[i] = sptmp;
45562+ }
45563+
45564+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
45565+
45566+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
45567+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
45568+
45569+ if (!r_tmp) {
45570+ err = -ENOMEM;
45571+ goto cleanup;
45572+ }
45573+
45574+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
45575+ sizeof (struct acl_role_label *))) {
45576+ err = -EFAULT;
45577+ goto cleanup;
45578+ }
45579+
45580+ if (copy_from_user(r_tmp, r_utmp2,
45581+ sizeof (struct acl_role_label))) {
45582+ err = -EFAULT;
45583+ goto cleanup;
45584+ }
45585+
45586+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
45587+
45588+ if (!len || len >= PATH_MAX) {
45589+ err = -EINVAL;
45590+ goto cleanup;
45591+ }
45592+
45593+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
45594+ err = -ENOMEM;
45595+ goto cleanup;
45596+ }
45597+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
45598+ err = -EFAULT;
45599+ goto cleanup;
45600+ }
45601+ tmp[len-1] = '\0';
45602+ r_tmp->rolename = tmp;
45603+
45604+ if (!strcmp(r_tmp->rolename, "default")
45605+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
45606+ default_role = r_tmp;
45607+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
45608+ kernel_role = r_tmp;
45609+ }
45610+
45611+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
45612+ err = -ENOMEM;
45613+ goto cleanup;
45614+ }
45615+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
45616+ err = -EFAULT;
45617+ goto cleanup;
45618+ }
45619+
45620+ r_tmp->hash = ghash;
45621+
45622+ num_subjs = count_user_subjs(r_tmp->hash->first);
45623+
45624+ r_tmp->subj_hash_size = num_subjs;
45625+ r_tmp->subj_hash =
45626+ (struct acl_subject_label **)
45627+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
45628+
45629+ if (!r_tmp->subj_hash) {
45630+ err = -ENOMEM;
45631+ goto cleanup;
45632+ }
45633+
45634+ err = copy_user_allowedips(r_tmp);
45635+ if (err)
45636+ goto cleanup;
45637+
45638+ /* copy domain info */
45639+ if (r_tmp->domain_children != NULL) {
45640+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
45641+ if (domainlist == NULL) {
45642+ err = -ENOMEM;
45643+ goto cleanup;
45644+ }
45645+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
45646+ err = -EFAULT;
45647+ goto cleanup;
45648+ }
45649+ r_tmp->domain_children = domainlist;
45650+ }
45651+
45652+ err = copy_user_transitions(r_tmp);
45653+ if (err)
45654+ goto cleanup;
45655+
45656+ memset(r_tmp->subj_hash, 0,
45657+ r_tmp->subj_hash_size *
45658+ sizeof (struct acl_subject_label *));
45659+
45660+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
45661+
45662+ if (err)
45663+ goto cleanup;
45664+
45665+ /* set nested subject list to null */
45666+ r_tmp->hash->first = NULL;
45667+
45668+ insert_acl_role_label(r_tmp);
45669+ }
45670+
45671+ goto return_err;
45672+ cleanup:
45673+ free_variables();
45674+ return_err:
45675+ return err;
45676+
45677+}
45678+
45679+static int
45680+gracl_init(struct gr_arg *args)
45681+{
45682+ int error = 0;
45683+
45684+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
45685+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
45686+
45687+ if (init_variables(args)) {
45688+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
45689+ error = -ENOMEM;
45690+ free_variables();
45691+ goto out;
45692+ }
45693+
45694+ error = copy_user_acl(args);
45695+ free_init_variables();
45696+ if (error) {
45697+ free_variables();
45698+ goto out;
45699+ }
45700+
45701+ if ((error = gr_set_acls(0))) {
45702+ free_variables();
45703+ goto out;
45704+ }
45705+
45706+ pax_open_kernel();
45707+ gr_status |= GR_READY;
45708+ pax_close_kernel();
45709+
45710+ out:
45711+ return error;
45712+}
45713+
45714+/* derived from glibc fnmatch() 0: match, 1: no match*/
45715+
45716+static int
45717+glob_match(const char *p, const char *n)
45718+{
45719+ char c;
45720+
45721+ while ((c = *p++) != '\0') {
45722+ switch (c) {
45723+ case '?':
45724+ if (*n == '\0')
45725+ return 1;
45726+ else if (*n == '/')
45727+ return 1;
45728+ break;
45729+ case '\\':
45730+ if (*n != c)
45731+ return 1;
45732+ break;
45733+ case '*':
45734+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
45735+ if (*n == '/')
45736+ return 1;
45737+ else if (c == '?') {
45738+ if (*n == '\0')
45739+ return 1;
45740+ else
45741+ ++n;
45742+ }
45743+ }
45744+ if (c == '\0') {
45745+ return 0;
45746+ } else {
45747+ const char *endp;
45748+
45749+ if ((endp = strchr(n, '/')) == NULL)
45750+ endp = n + strlen(n);
45751+
45752+ if (c == '[') {
45753+ for (--p; n < endp; ++n)
45754+ if (!glob_match(p, n))
45755+ return 0;
45756+ } else if (c == '/') {
45757+ while (*n != '\0' && *n != '/')
45758+ ++n;
45759+ if (*n == '/' && !glob_match(p, n + 1))
45760+ return 0;
45761+ } else {
45762+ for (--p; n < endp; ++n)
45763+ if (*n == c && !glob_match(p, n))
45764+ return 0;
45765+ }
45766+
45767+ return 1;
45768+ }
45769+ case '[':
45770+ {
45771+ int not;
45772+ char cold;
45773+
45774+ if (*n == '\0' || *n == '/')
45775+ return 1;
45776+
45777+ not = (*p == '!' || *p == '^');
45778+ if (not)
45779+ ++p;
45780+
45781+ c = *p++;
45782+ for (;;) {
45783+ unsigned char fn = (unsigned char)*n;
45784+
45785+ if (c == '\0')
45786+ return 1;
45787+ else {
45788+ if (c == fn)
45789+ goto matched;
45790+ cold = c;
45791+ c = *p++;
45792+
45793+ if (c == '-' && *p != ']') {
45794+ unsigned char cend = *p++;
45795+
45796+ if (cend == '\0')
45797+ return 1;
45798+
45799+ if (cold <= fn && fn <= cend)
45800+ goto matched;
45801+
45802+ c = *p++;
45803+ }
45804+ }
45805+
45806+ if (c == ']')
45807+ break;
45808+ }
45809+ if (!not)
45810+ return 1;
45811+ break;
45812+ matched:
45813+ while (c != ']') {
45814+ if (c == '\0')
45815+ return 1;
45816+
45817+ c = *p++;
45818+ }
45819+ if (not)
45820+ return 1;
45821+ }
45822+ break;
45823+ default:
45824+ if (c != *n)
45825+ return 1;
45826+ }
45827+
45828+ ++n;
45829+ }
45830+
45831+ if (*n == '\0')
45832+ return 0;
45833+
45834+ if (*n == '/')
45835+ return 0;
45836+
45837+ return 1;
45838+}
45839+
45840+static struct acl_object_label *
45841+chk_glob_label(struct acl_object_label *globbed,
45842+ struct dentry *dentry, struct vfsmount *mnt, char **path)
45843+{
45844+ struct acl_object_label *tmp;
45845+
45846+ if (*path == NULL)
45847+ *path = gr_to_filename_nolock(dentry, mnt);
45848+
45849+ tmp = globbed;
45850+
45851+ while (tmp) {
45852+ if (!glob_match(tmp->filename, *path))
45853+ return tmp;
45854+ tmp = tmp->next;
45855+ }
45856+
45857+ return NULL;
45858+}
45859+
45860+static struct acl_object_label *
45861+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
45862+ const ino_t curr_ino, const dev_t curr_dev,
45863+ const struct acl_subject_label *subj, char **path, const int checkglob)
45864+{
45865+ struct acl_subject_label *tmpsubj;
45866+ struct acl_object_label *retval;
45867+ struct acl_object_label *retval2;
45868+
45869+ tmpsubj = (struct acl_subject_label *) subj;
45870+ read_lock(&gr_inode_lock);
45871+ do {
45872+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
45873+ if (retval) {
45874+ if (checkglob && retval->globbed) {
45875+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
45876+ (struct vfsmount *)orig_mnt, path);
45877+ if (retval2)
45878+ retval = retval2;
45879+ }
45880+ break;
45881+ }
45882+ } while ((tmpsubj = tmpsubj->parent_subject));
45883+ read_unlock(&gr_inode_lock);
45884+
45885+ return retval;
45886+}
45887+
45888+static __inline__ struct acl_object_label *
45889+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
45890+ struct dentry *curr_dentry,
45891+ const struct acl_subject_label *subj, char **path, const int checkglob)
45892+{
45893+ int newglob = checkglob;
45894+ ino_t inode;
45895+ dev_t device;
45896+
45897+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
45898+ as we don't want a / * rule to match instead of the / object
45899+ don't do this for create lookups that call this function though, since they're looking up
45900+ on the parent and thus need globbing checks on all paths
45901+ */
45902+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
45903+ newglob = GR_NO_GLOB;
45904+
45905+ spin_lock(&curr_dentry->d_lock);
45906+ inode = curr_dentry->d_inode->i_ino;
45907+ device = __get_dev(curr_dentry);
45908+ spin_unlock(&curr_dentry->d_lock);
45909+
45910+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
45911+}
45912+
45913+static struct acl_object_label *
45914+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45915+ const struct acl_subject_label *subj, char *path, const int checkglob)
45916+{
45917+ struct dentry *dentry = (struct dentry *) l_dentry;
45918+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
45919+ struct acl_object_label *retval;
45920+ struct dentry *parent;
45921+
45922+ write_seqlock(&rename_lock);
45923+ br_read_lock(vfsmount_lock);
45924+
45925+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
45926+#ifdef CONFIG_NET
45927+ mnt == sock_mnt ||
45928+#endif
45929+#ifdef CONFIG_HUGETLBFS
45930+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
45931+#endif
45932+ /* ignore Eric Biederman */
45933+ IS_PRIVATE(l_dentry->d_inode))) {
45934+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
45935+ goto out;
45936+ }
45937+
45938+ for (;;) {
45939+ if (dentry == real_root.dentry && mnt == real_root.mnt)
45940+ break;
45941+
45942+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
45943+ if (mnt->mnt_parent == mnt)
45944+ break;
45945+
45946+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45947+ if (retval != NULL)
45948+ goto out;
45949+
45950+ dentry = mnt->mnt_mountpoint;
45951+ mnt = mnt->mnt_parent;
45952+ continue;
45953+ }
45954+
45955+ parent = dentry->d_parent;
45956+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45957+ if (retval != NULL)
45958+ goto out;
45959+
45960+ dentry = parent;
45961+ }
45962+
45963+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45964+
45965+ /* real_root is pinned so we don't have to hold a reference */
45966+ if (retval == NULL)
45967+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
45968+out:
45969+ br_read_unlock(vfsmount_lock);
45970+ write_sequnlock(&rename_lock);
45971+
45972+ BUG_ON(retval == NULL);
45973+
45974+ return retval;
45975+}
45976+
45977+static __inline__ struct acl_object_label *
45978+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45979+ const struct acl_subject_label *subj)
45980+{
45981+ char *path = NULL;
45982+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
45983+}
45984+
45985+static __inline__ struct acl_object_label *
45986+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45987+ const struct acl_subject_label *subj)
45988+{
45989+ char *path = NULL;
45990+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
45991+}
45992+
45993+static __inline__ struct acl_object_label *
45994+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45995+ const struct acl_subject_label *subj, char *path)
45996+{
45997+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
45998+}
45999+
46000+static struct acl_subject_label *
46001+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
46002+ const struct acl_role_label *role)
46003+{
46004+ struct dentry *dentry = (struct dentry *) l_dentry;
46005+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
46006+ struct acl_subject_label *retval;
46007+ struct dentry *parent;
46008+
46009+ write_seqlock(&rename_lock);
46010+ br_read_lock(vfsmount_lock);
46011+
46012+ for (;;) {
46013+ if (dentry == real_root.dentry && mnt == real_root.mnt)
46014+ break;
46015+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
46016+ if (mnt->mnt_parent == mnt)
46017+ break;
46018+
46019+ spin_lock(&dentry->d_lock);
46020+ read_lock(&gr_inode_lock);
46021+ retval =
46022+ lookup_acl_subj_label(dentry->d_inode->i_ino,
46023+ __get_dev(dentry), role);
46024+ read_unlock(&gr_inode_lock);
46025+ spin_unlock(&dentry->d_lock);
46026+ if (retval != NULL)
46027+ goto out;
46028+
46029+ dentry = mnt->mnt_mountpoint;
46030+ mnt = mnt->mnt_parent;
46031+ continue;
46032+ }
46033+
46034+ spin_lock(&dentry->d_lock);
46035+ read_lock(&gr_inode_lock);
46036+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
46037+ __get_dev(dentry), role);
46038+ read_unlock(&gr_inode_lock);
46039+ parent = dentry->d_parent;
46040+ spin_unlock(&dentry->d_lock);
46041+
46042+ if (retval != NULL)
46043+ goto out;
46044+
46045+ dentry = parent;
46046+ }
46047+
46048+ spin_lock(&dentry->d_lock);
46049+ read_lock(&gr_inode_lock);
46050+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
46051+ __get_dev(dentry), role);
46052+ read_unlock(&gr_inode_lock);
46053+ spin_unlock(&dentry->d_lock);
46054+
46055+ if (unlikely(retval == NULL)) {
46056+ /* real_root is pinned, we don't need to hold a reference */
46057+ read_lock(&gr_inode_lock);
46058+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
46059+ __get_dev(real_root.dentry), role);
46060+ read_unlock(&gr_inode_lock);
46061+ }
46062+out:
46063+ br_read_unlock(vfsmount_lock);
46064+ write_sequnlock(&rename_lock);
46065+
46066+ BUG_ON(retval == NULL);
46067+
46068+ return retval;
46069+}
46070+
46071+static void
46072+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
46073+{
46074+ struct task_struct *task = current;
46075+ const struct cred *cred = current_cred();
46076+
46077+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
46078+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
46079+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
46080+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
46081+
46082+ return;
46083+}
46084+
46085+static void
46086+gr_log_learn_sysctl(const char *path, const __u32 mode)
46087+{
46088+ struct task_struct *task = current;
46089+ const struct cred *cred = current_cred();
46090+
46091+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
46092+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
46093+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
46094+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
46095+
46096+ return;
46097+}
46098+
46099+static void
46100+gr_log_learn_id_change(const char type, const unsigned int real,
46101+ const unsigned int effective, const unsigned int fs)
46102+{
46103+ struct task_struct *task = current;
46104+ const struct cred *cred = current_cred();
46105+
46106+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
46107+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
46108+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
46109+ type, real, effective, fs, &task->signal->saved_ip);
46110+
46111+ return;
46112+}
46113+
46114+__u32
46115+gr_check_link(const struct dentry * new_dentry,
46116+ const struct dentry * parent_dentry,
46117+ const struct vfsmount * parent_mnt,
46118+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
46119+{
46120+ struct acl_object_label *obj;
46121+ __u32 oldmode, newmode;
46122+ __u32 needmode;
46123+
46124+ if (unlikely(!(gr_status & GR_READY)))
46125+ return (GR_CREATE | GR_LINK);
46126+
46127+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
46128+ oldmode = obj->mode;
46129+
46130+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
46131+ oldmode |= (GR_CREATE | GR_LINK);
46132+
46133+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
46134+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
46135+ needmode |= GR_SETID | GR_AUDIT_SETID;
46136+
46137+ newmode =
46138+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
46139+ oldmode | needmode);
46140+
46141+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
46142+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
46143+ GR_INHERIT | GR_AUDIT_INHERIT);
46144+
46145+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
46146+ goto bad;
46147+
46148+ if ((oldmode & needmode) != needmode)
46149+ goto bad;
46150+
46151+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
46152+ if ((newmode & needmode) != needmode)
46153+ goto bad;
46154+
46155+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
46156+ return newmode;
46157+bad:
46158+ needmode = oldmode;
46159+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
46160+ needmode |= GR_SETID;
46161+
46162+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
46163+ gr_log_learn(old_dentry, old_mnt, needmode);
46164+ return (GR_CREATE | GR_LINK);
46165+ } else if (newmode & GR_SUPPRESS)
46166+ return GR_SUPPRESS;
46167+ else
46168+ return 0;
46169+}
46170+
46171+__u32
46172+gr_search_file(const struct dentry * dentry, const __u32 mode,
46173+ const struct vfsmount * mnt)
46174+{
46175+ __u32 retval = mode;
46176+ struct acl_subject_label *curracl;
46177+ struct acl_object_label *currobj;
46178+
46179+ if (unlikely(!(gr_status & GR_READY)))
46180+ return (mode & ~GR_AUDITS);
46181+
46182+ curracl = current->acl;
46183+
46184+ currobj = chk_obj_label(dentry, mnt, curracl);
46185+ retval = currobj->mode & mode;
46186+
46187+ /* if we're opening a specified transfer file for writing
46188+ (e.g. /dev/initctl), then transfer our role to init
46189+ */
46190+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
46191+ current->role->roletype & GR_ROLE_PERSIST)) {
46192+ struct task_struct *task = init_pid_ns.child_reaper;
46193+
46194+ if (task->role != current->role) {
46195+ task->acl_sp_role = 0;
46196+ task->acl_role_id = current->acl_role_id;
46197+ task->role = current->role;
46198+ rcu_read_lock();
46199+ read_lock(&grsec_exec_file_lock);
46200+ gr_apply_subject_to_task(task);
46201+ read_unlock(&grsec_exec_file_lock);
46202+ rcu_read_unlock();
46203+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
46204+ }
46205+ }
46206+
46207+ if (unlikely
46208+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
46209+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
46210+ __u32 new_mode = mode;
46211+
46212+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
46213+
46214+ retval = new_mode;
46215+
46216+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
46217+ new_mode |= GR_INHERIT;
46218+
46219+ if (!(mode & GR_NOLEARN))
46220+ gr_log_learn(dentry, mnt, new_mode);
46221+ }
46222+
46223+ return retval;
46224+}
46225+
46226+__u32
46227+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
46228+ const struct vfsmount * mnt, const __u32 mode)
46229+{
46230+ struct name_entry *match;
46231+ struct acl_object_label *matchpo;
46232+ struct acl_subject_label *curracl;
46233+ char *path;
46234+ __u32 retval;
46235+
46236+ if (unlikely(!(gr_status & GR_READY)))
46237+ return (mode & ~GR_AUDITS);
46238+
46239+ preempt_disable();
46240+ path = gr_to_filename_rbac(new_dentry, mnt);
46241+ match = lookup_name_entry_create(path);
46242+
46243+ if (!match)
46244+ goto check_parent;
46245+
46246+ curracl = current->acl;
46247+
46248+ read_lock(&gr_inode_lock);
46249+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
46250+ read_unlock(&gr_inode_lock);
46251+
46252+ if (matchpo) {
46253+ if ((matchpo->mode & mode) !=
46254+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
46255+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
46256+ __u32 new_mode = mode;
46257+
46258+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
46259+
46260+ gr_log_learn(new_dentry, mnt, new_mode);
46261+
46262+ preempt_enable();
46263+ return new_mode;
46264+ }
46265+ preempt_enable();
46266+ return (matchpo->mode & mode);
46267+ }
46268+
46269+ check_parent:
46270+ curracl = current->acl;
46271+
46272+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
46273+ retval = matchpo->mode & mode;
46274+
46275+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
46276+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
46277+ __u32 new_mode = mode;
46278+
46279+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
46280+
46281+ gr_log_learn(new_dentry, mnt, new_mode);
46282+ preempt_enable();
46283+ return new_mode;
46284+ }
46285+
46286+ preempt_enable();
46287+ return retval;
46288+}
46289+
46290+int
46291+gr_check_hidden_task(const struct task_struct *task)
46292+{
46293+ if (unlikely(!(gr_status & GR_READY)))
46294+ return 0;
46295+
46296+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
46297+ return 1;
46298+
46299+ return 0;
46300+}
46301+
46302+int
46303+gr_check_protected_task(const struct task_struct *task)
46304+{
46305+ if (unlikely(!(gr_status & GR_READY) || !task))
46306+ return 0;
46307+
46308+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
46309+ task->acl != current->acl)
46310+ return 1;
46311+
46312+ return 0;
46313+}
46314+
46315+int
46316+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
46317+{
46318+ struct task_struct *p;
46319+ int ret = 0;
46320+
46321+ if (unlikely(!(gr_status & GR_READY) || !pid))
46322+ return ret;
46323+
46324+ read_lock(&tasklist_lock);
46325+ do_each_pid_task(pid, type, p) {
46326+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
46327+ p->acl != current->acl) {
46328+ ret = 1;
46329+ goto out;
46330+ }
46331+ } while_each_pid_task(pid, type, p);
46332+out:
46333+ read_unlock(&tasklist_lock);
46334+
46335+ return ret;
46336+}
46337+
46338+void
46339+gr_copy_label(struct task_struct *tsk)
46340+{
46341+ tsk->signal->used_accept = 0;
46342+ tsk->acl_sp_role = 0;
46343+ tsk->acl_role_id = current->acl_role_id;
46344+ tsk->acl = current->acl;
46345+ tsk->role = current->role;
46346+ tsk->signal->curr_ip = current->signal->curr_ip;
46347+ tsk->signal->saved_ip = current->signal->saved_ip;
46348+ if (current->exec_file)
46349+ get_file(current->exec_file);
46350+ tsk->exec_file = current->exec_file;
46351+ tsk->is_writable = current->is_writable;
46352+ if (unlikely(current->signal->used_accept)) {
46353+ current->signal->curr_ip = 0;
46354+ current->signal->saved_ip = 0;
46355+ }
46356+
46357+ return;
46358+}
46359+
46360+static void
46361+gr_set_proc_res(struct task_struct *task)
46362+{
46363+ struct acl_subject_label *proc;
46364+ unsigned short i;
46365+
46366+ proc = task->acl;
46367+
46368+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
46369+ return;
46370+
46371+ for (i = 0; i < RLIM_NLIMITS; i++) {
46372+ if (!(proc->resmask & (1 << i)))
46373+ continue;
46374+
46375+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
46376+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
46377+ }
46378+
46379+ return;
46380+}
46381+
46382+extern int __gr_process_user_ban(struct user_struct *user);
46383+
46384+int
46385+gr_check_user_change(int real, int effective, int fs)
46386+{
46387+ unsigned int i;
46388+ __u16 num;
46389+ uid_t *uidlist;
46390+ int curuid;
46391+ int realok = 0;
46392+ int effectiveok = 0;
46393+ int fsok = 0;
46394+
46395+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
46396+ struct user_struct *user;
46397+
46398+ if (real == -1)
46399+ goto skipit;
46400+
46401+ user = find_user(real);
46402+ if (user == NULL)
46403+ goto skipit;
46404+
46405+ if (__gr_process_user_ban(user)) {
46406+ /* for find_user */
46407+ free_uid(user);
46408+ return 1;
46409+ }
46410+
46411+ /* for find_user */
46412+ free_uid(user);
46413+
46414+skipit:
46415+#endif
46416+
46417+ if (unlikely(!(gr_status & GR_READY)))
46418+ return 0;
46419+
46420+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
46421+ gr_log_learn_id_change('u', real, effective, fs);
46422+
46423+ num = current->acl->user_trans_num;
46424+ uidlist = current->acl->user_transitions;
46425+
46426+ if (uidlist == NULL)
46427+ return 0;
46428+
46429+ if (real == -1)
46430+ realok = 1;
46431+ if (effective == -1)
46432+ effectiveok = 1;
46433+ if (fs == -1)
46434+ fsok = 1;
46435+
46436+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
46437+ for (i = 0; i < num; i++) {
46438+ curuid = (int)uidlist[i];
46439+ if (real == curuid)
46440+ realok = 1;
46441+ if (effective == curuid)
46442+ effectiveok = 1;
46443+ if (fs == curuid)
46444+ fsok = 1;
46445+ }
46446+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
46447+ for (i = 0; i < num; i++) {
46448+ curuid = (int)uidlist[i];
46449+ if (real == curuid)
46450+ break;
46451+ if (effective == curuid)
46452+ break;
46453+ if (fs == curuid)
46454+ break;
46455+ }
46456+ /* not in deny list */
46457+ if (i == num) {
46458+ realok = 1;
46459+ effectiveok = 1;
46460+ fsok = 1;
46461+ }
46462+ }
46463+
46464+ if (realok && effectiveok && fsok)
46465+ return 0;
46466+ else {
46467+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
46468+ return 1;
46469+ }
46470+}
46471+
46472+int
46473+gr_check_group_change(int real, int effective, int fs)
46474+{
46475+ unsigned int i;
46476+ __u16 num;
46477+ gid_t *gidlist;
46478+ int curgid;
46479+ int realok = 0;
46480+ int effectiveok = 0;
46481+ int fsok = 0;
46482+
46483+ if (unlikely(!(gr_status & GR_READY)))
46484+ return 0;
46485+
46486+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
46487+ gr_log_learn_id_change('g', real, effective, fs);
46488+
46489+ num = current->acl->group_trans_num;
46490+ gidlist = current->acl->group_transitions;
46491+
46492+ if (gidlist == NULL)
46493+ return 0;
46494+
46495+ if (real == -1)
46496+ realok = 1;
46497+ if (effective == -1)
46498+ effectiveok = 1;
46499+ if (fs == -1)
46500+ fsok = 1;
46501+
46502+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
46503+ for (i = 0; i < num; i++) {
46504+ curgid = (int)gidlist[i];
46505+ if (real == curgid)
46506+ realok = 1;
46507+ if (effective == curgid)
46508+ effectiveok = 1;
46509+ if (fs == curgid)
46510+ fsok = 1;
46511+ }
46512+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
46513+ for (i = 0; i < num; i++) {
46514+ curgid = (int)gidlist[i];
46515+ if (real == curgid)
46516+ break;
46517+ if (effective == curgid)
46518+ break;
46519+ if (fs == curgid)
46520+ break;
46521+ }
46522+ /* not in deny list */
46523+ if (i == num) {
46524+ realok = 1;
46525+ effectiveok = 1;
46526+ fsok = 1;
46527+ }
46528+ }
46529+
46530+ if (realok && effectiveok && fsok)
46531+ return 0;
46532+ else {
46533+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
46534+ return 1;
46535+ }
46536+}
46537+
46538+void
46539+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
46540+{
46541+ struct acl_role_label *role = task->role;
46542+ struct acl_subject_label *subj = NULL;
46543+ struct acl_object_label *obj;
46544+ struct file *filp;
46545+
46546+ if (unlikely(!(gr_status & GR_READY)))
46547+ return;
46548+
46549+ filp = task->exec_file;
46550+
46551+ /* kernel process, we'll give them the kernel role */
46552+ if (unlikely(!filp)) {
46553+ task->role = kernel_role;
46554+ task->acl = kernel_role->root_label;
46555+ return;
46556+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
46557+ role = lookup_acl_role_label(task, uid, gid);
46558+
46559+ /* perform subject lookup in possibly new role
46560+ we can use this result below in the case where role == task->role
46561+ */
46562+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
46563+
46564+ /* if we changed uid/gid, but result in the same role
46565+ and are using inheritance, don't lose the inherited subject
46566+ if current subject is other than what normal lookup
46567+ would result in, we arrived via inheritance, don't
46568+ lose subject
46569+ */
46570+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
46571+ (subj == task->acl)))
46572+ task->acl = subj;
46573+
46574+ task->role = role;
46575+
46576+ task->is_writable = 0;
46577+
46578+ /* ignore additional mmap checks for processes that are writable
46579+ by the default ACL */
46580+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
46581+ if (unlikely(obj->mode & GR_WRITE))
46582+ task->is_writable = 1;
46583+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
46584+ if (unlikely(obj->mode & GR_WRITE))
46585+ task->is_writable = 1;
46586+
46587+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46588+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46589+#endif
46590+
46591+ gr_set_proc_res(task);
46592+
46593+ return;
46594+}
46595+
46596+int
46597+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
46598+ const int unsafe_share)
46599+{
46600+ struct task_struct *task = current;
46601+ struct acl_subject_label *newacl;
46602+ struct acl_object_label *obj;
46603+ __u32 retmode;
46604+
46605+ if (unlikely(!(gr_status & GR_READY)))
46606+ return 0;
46607+
46608+ newacl = chk_subj_label(dentry, mnt, task->role);
46609+
46610+ task_lock(task);
46611+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
46612+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
46613+ !(task->role->roletype & GR_ROLE_GOD) &&
46614+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
46615+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
46616+ task_unlock(task);
46617+ if (unsafe_share)
46618+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
46619+ else
46620+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
46621+ return -EACCES;
46622+ }
46623+ task_unlock(task);
46624+
46625+ obj = chk_obj_label(dentry, mnt, task->acl);
46626+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
46627+
46628+ if (!(task->acl->mode & GR_INHERITLEARN) &&
46629+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
46630+ if (obj->nested)
46631+ task->acl = obj->nested;
46632+ else
46633+ task->acl = newacl;
46634+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
46635+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
46636+
46637+ task->is_writable = 0;
46638+
46639+ /* ignore additional mmap checks for processes that are writable
46640+ by the default ACL */
46641+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
46642+ if (unlikely(obj->mode & GR_WRITE))
46643+ task->is_writable = 1;
46644+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
46645+ if (unlikely(obj->mode & GR_WRITE))
46646+ task->is_writable = 1;
46647+
46648+ gr_set_proc_res(task);
46649+
46650+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46651+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46652+#endif
46653+ return 0;
46654+}
46655+
46656+/* always called with valid inodev ptr */
46657+static void
46658+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
46659+{
46660+ struct acl_object_label *matchpo;
46661+ struct acl_subject_label *matchps;
46662+ struct acl_subject_label *subj;
46663+ struct acl_role_label *role;
46664+ unsigned int x;
46665+
46666+ FOR_EACH_ROLE_START(role)
46667+ FOR_EACH_SUBJECT_START(role, subj, x)
46668+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
46669+ matchpo->mode |= GR_DELETED;
46670+ FOR_EACH_SUBJECT_END(subj,x)
46671+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
46672+ if (subj->inode == ino && subj->device == dev)
46673+ subj->mode |= GR_DELETED;
46674+ FOR_EACH_NESTED_SUBJECT_END(subj)
46675+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
46676+ matchps->mode |= GR_DELETED;
46677+ FOR_EACH_ROLE_END(role)
46678+
46679+ inodev->nentry->deleted = 1;
46680+
46681+ return;
46682+}
46683+
46684+void
46685+gr_handle_delete(const ino_t ino, const dev_t dev)
46686+{
46687+ struct inodev_entry *inodev;
46688+
46689+ if (unlikely(!(gr_status & GR_READY)))
46690+ return;
46691+
46692+ write_lock(&gr_inode_lock);
46693+ inodev = lookup_inodev_entry(ino, dev);
46694+ if (inodev != NULL)
46695+ do_handle_delete(inodev, ino, dev);
46696+ write_unlock(&gr_inode_lock);
46697+
46698+ return;
46699+}
46700+
46701+static void
46702+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
46703+ const ino_t newinode, const dev_t newdevice,
46704+ struct acl_subject_label *subj)
46705+{
46706+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
46707+ struct acl_object_label *match;
46708+
46709+ match = subj->obj_hash[index];
46710+
46711+ while (match && (match->inode != oldinode ||
46712+ match->device != olddevice ||
46713+ !(match->mode & GR_DELETED)))
46714+ match = match->next;
46715+
46716+ if (match && (match->inode == oldinode)
46717+ && (match->device == olddevice)
46718+ && (match->mode & GR_DELETED)) {
46719+ if (match->prev == NULL) {
46720+ subj->obj_hash[index] = match->next;
46721+ if (match->next != NULL)
46722+ match->next->prev = NULL;
46723+ } else {
46724+ match->prev->next = match->next;
46725+ if (match->next != NULL)
46726+ match->next->prev = match->prev;
46727+ }
46728+ match->prev = NULL;
46729+ match->next = NULL;
46730+ match->inode = newinode;
46731+ match->device = newdevice;
46732+ match->mode &= ~GR_DELETED;
46733+
46734+ insert_acl_obj_label(match, subj);
46735+ }
46736+
46737+ return;
46738+}
46739+
46740+static void
46741+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
46742+ const ino_t newinode, const dev_t newdevice,
46743+ struct acl_role_label *role)
46744+{
46745+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
46746+ struct acl_subject_label *match;
46747+
46748+ match = role->subj_hash[index];
46749+
46750+ while (match && (match->inode != oldinode ||
46751+ match->device != olddevice ||
46752+ !(match->mode & GR_DELETED)))
46753+ match = match->next;
46754+
46755+ if (match && (match->inode == oldinode)
46756+ && (match->device == olddevice)
46757+ && (match->mode & GR_DELETED)) {
46758+ if (match->prev == NULL) {
46759+ role->subj_hash[index] = match->next;
46760+ if (match->next != NULL)
46761+ match->next->prev = NULL;
46762+ } else {
46763+ match->prev->next = match->next;
46764+ if (match->next != NULL)
46765+ match->next->prev = match->prev;
46766+ }
46767+ match->prev = NULL;
46768+ match->next = NULL;
46769+ match->inode = newinode;
46770+ match->device = newdevice;
46771+ match->mode &= ~GR_DELETED;
46772+
46773+ insert_acl_subj_label(match, role);
46774+ }
46775+
46776+ return;
46777+}
46778+
46779+static void
46780+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
46781+ const ino_t newinode, const dev_t newdevice)
46782+{
46783+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
46784+ struct inodev_entry *match;
46785+
46786+ match = inodev_set.i_hash[index];
46787+
46788+ while (match && (match->nentry->inode != oldinode ||
46789+ match->nentry->device != olddevice || !match->nentry->deleted))
46790+ match = match->next;
46791+
46792+ if (match && (match->nentry->inode == oldinode)
46793+ && (match->nentry->device == olddevice) &&
46794+ match->nentry->deleted) {
46795+ if (match->prev == NULL) {
46796+ inodev_set.i_hash[index] = match->next;
46797+ if (match->next != NULL)
46798+ match->next->prev = NULL;
46799+ } else {
46800+ match->prev->next = match->next;
46801+ if (match->next != NULL)
46802+ match->next->prev = match->prev;
46803+ }
46804+ match->prev = NULL;
46805+ match->next = NULL;
46806+ match->nentry->inode = newinode;
46807+ match->nentry->device = newdevice;
46808+ match->nentry->deleted = 0;
46809+
46810+ insert_inodev_entry(match);
46811+ }
46812+
46813+ return;
46814+}
46815+
46816+static void
46817+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
46818+ const struct vfsmount *mnt)
46819+{
46820+ struct acl_subject_label *subj;
46821+ struct acl_role_label *role;
46822+ unsigned int x;
46823+ ino_t ino = dentry->d_inode->i_ino;
46824+ dev_t dev = __get_dev(dentry);
46825+
46826+ FOR_EACH_ROLE_START(role)
46827+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
46828+
46829+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
46830+ if ((subj->inode == ino) && (subj->device == dev)) {
46831+ subj->inode = ino;
46832+ subj->device = dev;
46833+ }
46834+ FOR_EACH_NESTED_SUBJECT_END(subj)
46835+ FOR_EACH_SUBJECT_START(role, subj, x)
46836+ update_acl_obj_label(matchn->inode, matchn->device,
46837+ ino, dev, subj);
46838+ FOR_EACH_SUBJECT_END(subj,x)
46839+ FOR_EACH_ROLE_END(role)
46840+
46841+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
46842+
46843+ return;
46844+}
46845+
46846+void
46847+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
46848+{
46849+ struct name_entry *matchn;
46850+
46851+ if (unlikely(!(gr_status & GR_READY)))
46852+ return;
46853+
46854+ preempt_disable();
46855+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
46856+
46857+ if (unlikely((unsigned long)matchn)) {
46858+ write_lock(&gr_inode_lock);
46859+ do_handle_create(matchn, dentry, mnt);
46860+ write_unlock(&gr_inode_lock);
46861+ }
46862+ preempt_enable();
46863+
46864+ return;
46865+}
46866+
46867+void
46868+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
46869+ struct dentry *old_dentry,
46870+ struct dentry *new_dentry,
46871+ struct vfsmount *mnt, const __u8 replace)
46872+{
46873+ struct name_entry *matchn;
46874+ struct inodev_entry *inodev;
46875+ ino_t old_ino = old_dentry->d_inode->i_ino;
46876+ dev_t old_dev = __get_dev(old_dentry);
46877+
46878+ /* vfs_rename swaps the name and parent link for old_dentry and
46879+ new_dentry
46880+ at this point, old_dentry has the new name, parent link, and inode
46881+ for the renamed file
46882+ if a file is being replaced by a rename, new_dentry has the inode
46883+ and name for the replaced file
46884+ */
46885+
46886+ if (unlikely(!(gr_status & GR_READY)))
46887+ return;
46888+
46889+ preempt_disable();
46890+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
46891+
46892+ /* we wouldn't have to check d_inode if it weren't for
46893+ NFS silly-renaming
46894+ */
46895+
46896+ write_lock(&gr_inode_lock);
46897+ if (unlikely(replace && new_dentry->d_inode)) {
46898+ ino_t new_ino = new_dentry->d_inode->i_ino;
46899+ dev_t new_dev = __get_dev(new_dentry);
46900+
46901+ inodev = lookup_inodev_entry(new_ino, new_dev);
46902+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
46903+ do_handle_delete(inodev, new_ino, new_dev);
46904+ }
46905+
46906+ inodev = lookup_inodev_entry(old_ino, old_dev);
46907+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
46908+ do_handle_delete(inodev, old_ino, old_dev);
46909+
46910+ if (unlikely((unsigned long)matchn))
46911+ do_handle_create(matchn, old_dentry, mnt);
46912+
46913+ write_unlock(&gr_inode_lock);
46914+ preempt_enable();
46915+
46916+ return;
46917+}
46918+
46919+static int
46920+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
46921+ unsigned char **sum)
46922+{
46923+ struct acl_role_label *r;
46924+ struct role_allowed_ip *ipp;
46925+ struct role_transition *trans;
46926+ unsigned int i;
46927+ int found = 0;
46928+ u32 curr_ip = current->signal->curr_ip;
46929+
46930+ current->signal->saved_ip = curr_ip;
46931+
46932+ /* check transition table */
46933+
46934+ for (trans = current->role->transitions; trans; trans = trans->next) {
46935+ if (!strcmp(rolename, trans->rolename)) {
46936+ found = 1;
46937+ break;
46938+ }
46939+ }
46940+
46941+ if (!found)
46942+ return 0;
46943+
46944+ /* handle special roles that do not require authentication
46945+ and check ip */
46946+
46947+ FOR_EACH_ROLE_START(r)
46948+ if (!strcmp(rolename, r->rolename) &&
46949+ (r->roletype & GR_ROLE_SPECIAL)) {
46950+ found = 0;
46951+ if (r->allowed_ips != NULL) {
46952+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
46953+ if ((ntohl(curr_ip) & ipp->netmask) ==
46954+ (ntohl(ipp->addr) & ipp->netmask))
46955+ found = 1;
46956+ }
46957+ } else
46958+ found = 2;
46959+ if (!found)
46960+ return 0;
46961+
46962+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
46963+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
46964+ *salt = NULL;
46965+ *sum = NULL;
46966+ return 1;
46967+ }
46968+ }
46969+ FOR_EACH_ROLE_END(r)
46970+
46971+ for (i = 0; i < num_sprole_pws; i++) {
46972+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
46973+ *salt = acl_special_roles[i]->salt;
46974+ *sum = acl_special_roles[i]->sum;
46975+ return 1;
46976+ }
46977+ }
46978+
46979+ return 0;
46980+}
46981+
46982+static void
46983+assign_special_role(char *rolename)
46984+{
46985+ struct acl_object_label *obj;
46986+ struct acl_role_label *r;
46987+ struct acl_role_label *assigned = NULL;
46988+ struct task_struct *tsk;
46989+ struct file *filp;
46990+
46991+ FOR_EACH_ROLE_START(r)
46992+ if (!strcmp(rolename, r->rolename) &&
46993+ (r->roletype & GR_ROLE_SPECIAL)) {
46994+ assigned = r;
46995+ break;
46996+ }
46997+ FOR_EACH_ROLE_END(r)
46998+
46999+ if (!assigned)
47000+ return;
47001+
47002+ read_lock(&tasklist_lock);
47003+ read_lock(&grsec_exec_file_lock);
47004+
47005+ tsk = current->real_parent;
47006+ if (tsk == NULL)
47007+ goto out_unlock;
47008+
47009+ filp = tsk->exec_file;
47010+ if (filp == NULL)
47011+ goto out_unlock;
47012+
47013+ tsk->is_writable = 0;
47014+
47015+ tsk->acl_sp_role = 1;
47016+ tsk->acl_role_id = ++acl_sp_role_value;
47017+ tsk->role = assigned;
47018+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
47019+
47020+ /* ignore additional mmap checks for processes that are writable
47021+ by the default ACL */
47022+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47023+ if (unlikely(obj->mode & GR_WRITE))
47024+ tsk->is_writable = 1;
47025+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
47026+ if (unlikely(obj->mode & GR_WRITE))
47027+ tsk->is_writable = 1;
47028+
47029+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
47030+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
47031+#endif
47032+
47033+out_unlock:
47034+ read_unlock(&grsec_exec_file_lock);
47035+ read_unlock(&tasklist_lock);
47036+ return;
47037+}
47038+
47039+int gr_check_secure_terminal(struct task_struct *task)
47040+{
47041+ struct task_struct *p, *p2, *p3;
47042+ struct files_struct *files;
47043+ struct fdtable *fdt;
47044+ struct file *our_file = NULL, *file;
47045+ int i;
47046+
47047+ if (task->signal->tty == NULL)
47048+ return 1;
47049+
47050+ files = get_files_struct(task);
47051+ if (files != NULL) {
47052+ rcu_read_lock();
47053+ fdt = files_fdtable(files);
47054+ for (i=0; i < fdt->max_fds; i++) {
47055+ file = fcheck_files(files, i);
47056+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
47057+ get_file(file);
47058+ our_file = file;
47059+ }
47060+ }
47061+ rcu_read_unlock();
47062+ put_files_struct(files);
47063+ }
47064+
47065+ if (our_file == NULL)
47066+ return 1;
47067+
47068+ read_lock(&tasklist_lock);
47069+ do_each_thread(p2, p) {
47070+ files = get_files_struct(p);
47071+ if (files == NULL ||
47072+ (p->signal && p->signal->tty == task->signal->tty)) {
47073+ if (files != NULL)
47074+ put_files_struct(files);
47075+ continue;
47076+ }
47077+ rcu_read_lock();
47078+ fdt = files_fdtable(files);
47079+ for (i=0; i < fdt->max_fds; i++) {
47080+ file = fcheck_files(files, i);
47081+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
47082+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
47083+ p3 = task;
47084+ while (p3->pid > 0) {
47085+ if (p3 == p)
47086+ break;
47087+ p3 = p3->real_parent;
47088+ }
47089+ if (p3 == p)
47090+ break;
47091+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
47092+ gr_handle_alertkill(p);
47093+ rcu_read_unlock();
47094+ put_files_struct(files);
47095+ read_unlock(&tasklist_lock);
47096+ fput(our_file);
47097+ return 0;
47098+ }
47099+ }
47100+ rcu_read_unlock();
47101+ put_files_struct(files);
47102+ } while_each_thread(p2, p);
47103+ read_unlock(&tasklist_lock);
47104+
47105+ fput(our_file);
47106+ return 1;
47107+}
47108+
47109+ssize_t
47110+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
47111+{
47112+ struct gr_arg_wrapper uwrap;
47113+ unsigned char *sprole_salt = NULL;
47114+ unsigned char *sprole_sum = NULL;
47115+ int error = sizeof (struct gr_arg_wrapper);
47116+ int error2 = 0;
47117+
47118+ mutex_lock(&gr_dev_mutex);
47119+
47120+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
47121+ error = -EPERM;
47122+ goto out;
47123+ }
47124+
47125+ if (count != sizeof (struct gr_arg_wrapper)) {
47126+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
47127+ error = -EINVAL;
47128+ goto out;
47129+ }
47130+
47131+
47132+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
47133+ gr_auth_expires = 0;
47134+ gr_auth_attempts = 0;
47135+ }
47136+
47137+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
47138+ error = -EFAULT;
47139+ goto out;
47140+ }
47141+
47142+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
47143+ error = -EINVAL;
47144+ goto out;
47145+ }
47146+
47147+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
47148+ error = -EFAULT;
47149+ goto out;
47150+ }
47151+
47152+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
47153+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
47154+ time_after(gr_auth_expires, get_seconds())) {
47155+ error = -EBUSY;
47156+ goto out;
47157+ }
47158+
47159+ /* if non-root trying to do anything other than use a special role,
47160+ do not attempt authentication, do not count towards authentication
47161+ locking
47162+ */
47163+
47164+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
47165+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
47166+ current_uid()) {
47167+ error = -EPERM;
47168+ goto out;
47169+ }
47170+
47171+ /* ensure pw and special role name are null terminated */
47172+
47173+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
47174+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
47175+
47176+ /* Okay.
47177+ * We have our enough of the argument structure..(we have yet
47178+ * to copy_from_user the tables themselves) . Copy the tables
47179+ * only if we need them, i.e. for loading operations. */
47180+
47181+ switch (gr_usermode->mode) {
47182+ case GR_STATUS:
47183+ if (gr_status & GR_READY) {
47184+ error = 1;
47185+ if (!gr_check_secure_terminal(current))
47186+ error = 3;
47187+ } else
47188+ error = 2;
47189+ goto out;
47190+ case GR_SHUTDOWN:
47191+ if ((gr_status & GR_READY)
47192+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
47193+ pax_open_kernel();
47194+ gr_status &= ~GR_READY;
47195+ pax_close_kernel();
47196+
47197+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
47198+ free_variables();
47199+ memset(gr_usermode, 0, sizeof (struct gr_arg));
47200+ memset(gr_system_salt, 0, GR_SALT_LEN);
47201+ memset(gr_system_sum, 0, GR_SHA_LEN);
47202+ } else if (gr_status & GR_READY) {
47203+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
47204+ error = -EPERM;
47205+ } else {
47206+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
47207+ error = -EAGAIN;
47208+ }
47209+ break;
47210+ case GR_ENABLE:
47211+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
47212+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
47213+ else {
47214+ if (gr_status & GR_READY)
47215+ error = -EAGAIN;
47216+ else
47217+ error = error2;
47218+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
47219+ }
47220+ break;
47221+ case GR_RELOAD:
47222+ if (!(gr_status & GR_READY)) {
47223+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
47224+ error = -EAGAIN;
47225+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
47226+ preempt_disable();
47227+
47228+ pax_open_kernel();
47229+ gr_status &= ~GR_READY;
47230+ pax_close_kernel();
47231+
47232+ free_variables();
47233+ if (!(error2 = gracl_init(gr_usermode))) {
47234+ preempt_enable();
47235+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
47236+ } else {
47237+ preempt_enable();
47238+ error = error2;
47239+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
47240+ }
47241+ } else {
47242+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
47243+ error = -EPERM;
47244+ }
47245+ break;
47246+ case GR_SEGVMOD:
47247+ if (unlikely(!(gr_status & GR_READY))) {
47248+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
47249+ error = -EAGAIN;
47250+ break;
47251+ }
47252+
47253+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
47254+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
47255+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
47256+ struct acl_subject_label *segvacl;
47257+ segvacl =
47258+ lookup_acl_subj_label(gr_usermode->segv_inode,
47259+ gr_usermode->segv_device,
47260+ current->role);
47261+ if (segvacl) {
47262+ segvacl->crashes = 0;
47263+ segvacl->expires = 0;
47264+ }
47265+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
47266+ gr_remove_uid(gr_usermode->segv_uid);
47267+ }
47268+ } else {
47269+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
47270+ error = -EPERM;
47271+ }
47272+ break;
47273+ case GR_SPROLE:
47274+ case GR_SPROLEPAM:
47275+ if (unlikely(!(gr_status & GR_READY))) {
47276+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
47277+ error = -EAGAIN;
47278+ break;
47279+ }
47280+
47281+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
47282+ current->role->expires = 0;
47283+ current->role->auth_attempts = 0;
47284+ }
47285+
47286+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
47287+ time_after(current->role->expires, get_seconds())) {
47288+ error = -EBUSY;
47289+ goto out;
47290+ }
47291+
47292+ if (lookup_special_role_auth
47293+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
47294+ && ((!sprole_salt && !sprole_sum)
47295+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
47296+ char *p = "";
47297+ assign_special_role(gr_usermode->sp_role);
47298+ read_lock(&tasklist_lock);
47299+ if (current->real_parent)
47300+ p = current->real_parent->role->rolename;
47301+ read_unlock(&tasklist_lock);
47302+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
47303+ p, acl_sp_role_value);
47304+ } else {
47305+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
47306+ error = -EPERM;
47307+ if(!(current->role->auth_attempts++))
47308+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
47309+
47310+ goto out;
47311+ }
47312+ break;
47313+ case GR_UNSPROLE:
47314+ if (unlikely(!(gr_status & GR_READY))) {
47315+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
47316+ error = -EAGAIN;
47317+ break;
47318+ }
47319+
47320+ if (current->role->roletype & GR_ROLE_SPECIAL) {
47321+ char *p = "";
47322+ int i = 0;
47323+
47324+ read_lock(&tasklist_lock);
47325+ if (current->real_parent) {
47326+ p = current->real_parent->role->rolename;
47327+ i = current->real_parent->acl_role_id;
47328+ }
47329+ read_unlock(&tasklist_lock);
47330+
47331+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
47332+ gr_set_acls(1);
47333+ } else {
47334+ error = -EPERM;
47335+ goto out;
47336+ }
47337+ break;
47338+ default:
47339+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
47340+ error = -EINVAL;
47341+ break;
47342+ }
47343+
47344+ if (error != -EPERM)
47345+ goto out;
47346+
47347+ if(!(gr_auth_attempts++))
47348+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
47349+
47350+ out:
47351+ mutex_unlock(&gr_dev_mutex);
47352+ return error;
47353+}
47354+
47355+/* must be called with
47356+ rcu_read_lock();
47357+ read_lock(&tasklist_lock);
47358+ read_lock(&grsec_exec_file_lock);
47359+*/
47360+int gr_apply_subject_to_task(struct task_struct *task)
47361+{
47362+ struct acl_object_label *obj;
47363+ char *tmpname;
47364+ struct acl_subject_label *tmpsubj;
47365+ struct file *filp;
47366+ struct name_entry *nmatch;
47367+
47368+ filp = task->exec_file;
47369+ if (filp == NULL)
47370+ return 0;
47371+
47372+ /* the following is to apply the correct subject
47373+ on binaries running when the RBAC system
47374+ is enabled, when the binaries have been
47375+ replaced or deleted since their execution
47376+ -----
47377+ when the RBAC system starts, the inode/dev
47378+ from exec_file will be one the RBAC system
47379+ is unaware of. It only knows the inode/dev
47380+ of the present file on disk, or the absence
47381+ of it.
47382+ */
47383+ preempt_disable();
47384+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
47385+
47386+ nmatch = lookup_name_entry(tmpname);
47387+ preempt_enable();
47388+ tmpsubj = NULL;
47389+ if (nmatch) {
47390+ if (nmatch->deleted)
47391+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
47392+ else
47393+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
47394+ if (tmpsubj != NULL)
47395+ task->acl = tmpsubj;
47396+ }
47397+ if (tmpsubj == NULL)
47398+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
47399+ task->role);
47400+ if (task->acl) {
47401+ task->is_writable = 0;
47402+ /* ignore additional mmap checks for processes that are writable
47403+ by the default ACL */
47404+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47405+ if (unlikely(obj->mode & GR_WRITE))
47406+ task->is_writable = 1;
47407+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
47408+ if (unlikely(obj->mode & GR_WRITE))
47409+ task->is_writable = 1;
47410+
47411+ gr_set_proc_res(task);
47412+
47413+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
47414+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
47415+#endif
47416+ } else {
47417+ return 1;
47418+ }
47419+
47420+ return 0;
47421+}
47422+
47423+int
47424+gr_set_acls(const int type)
47425+{
47426+ struct task_struct *task, *task2;
47427+ struct acl_role_label *role = current->role;
47428+ __u16 acl_role_id = current->acl_role_id;
47429+ const struct cred *cred;
47430+ int ret;
47431+
47432+ rcu_read_lock();
47433+ read_lock(&tasklist_lock);
47434+ read_lock(&grsec_exec_file_lock);
47435+ do_each_thread(task2, task) {
47436+ /* check to see if we're called from the exit handler,
47437+ if so, only replace ACLs that have inherited the admin
47438+ ACL */
47439+
47440+ if (type && (task->role != role ||
47441+ task->acl_role_id != acl_role_id))
47442+ continue;
47443+
47444+ task->acl_role_id = 0;
47445+ task->acl_sp_role = 0;
47446+
47447+ if (task->exec_file) {
47448+ cred = __task_cred(task);
47449+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
47450+ ret = gr_apply_subject_to_task(task);
47451+ if (ret) {
47452+ read_unlock(&grsec_exec_file_lock);
47453+ read_unlock(&tasklist_lock);
47454+ rcu_read_unlock();
47455+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
47456+ return ret;
47457+ }
47458+ } else {
47459+ // it's a kernel process
47460+ task->role = kernel_role;
47461+ task->acl = kernel_role->root_label;
47462+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
47463+ task->acl->mode &= ~GR_PROCFIND;
47464+#endif
47465+ }
47466+ } while_each_thread(task2, task);
47467+ read_unlock(&grsec_exec_file_lock);
47468+ read_unlock(&tasklist_lock);
47469+ rcu_read_unlock();
47470+
47471+ return 0;
47472+}
47473+
47474+void
47475+gr_learn_resource(const struct task_struct *task,
47476+ const int res, const unsigned long wanted, const int gt)
47477+{
47478+ struct acl_subject_label *acl;
47479+ const struct cred *cred;
47480+
47481+ if (unlikely((gr_status & GR_READY) &&
47482+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
47483+ goto skip_reslog;
47484+
47485+#ifdef CONFIG_GRKERNSEC_RESLOG
47486+ gr_log_resource(task, res, wanted, gt);
47487+#endif
47488+ skip_reslog:
47489+
47490+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
47491+ return;
47492+
47493+ acl = task->acl;
47494+
47495+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
47496+ !(acl->resmask & (1 << (unsigned short) res))))
47497+ return;
47498+
47499+ if (wanted >= acl->res[res].rlim_cur) {
47500+ unsigned long res_add;
47501+
47502+ res_add = wanted;
47503+ switch (res) {
47504+ case RLIMIT_CPU:
47505+ res_add += GR_RLIM_CPU_BUMP;
47506+ break;
47507+ case RLIMIT_FSIZE:
47508+ res_add += GR_RLIM_FSIZE_BUMP;
47509+ break;
47510+ case RLIMIT_DATA:
47511+ res_add += GR_RLIM_DATA_BUMP;
47512+ break;
47513+ case RLIMIT_STACK:
47514+ res_add += GR_RLIM_STACK_BUMP;
47515+ break;
47516+ case RLIMIT_CORE:
47517+ res_add += GR_RLIM_CORE_BUMP;
47518+ break;
47519+ case RLIMIT_RSS:
47520+ res_add += GR_RLIM_RSS_BUMP;
47521+ break;
47522+ case RLIMIT_NPROC:
47523+ res_add += GR_RLIM_NPROC_BUMP;
47524+ break;
47525+ case RLIMIT_NOFILE:
47526+ res_add += GR_RLIM_NOFILE_BUMP;
47527+ break;
47528+ case RLIMIT_MEMLOCK:
47529+ res_add += GR_RLIM_MEMLOCK_BUMP;
47530+ break;
47531+ case RLIMIT_AS:
47532+ res_add += GR_RLIM_AS_BUMP;
47533+ break;
47534+ case RLIMIT_LOCKS:
47535+ res_add += GR_RLIM_LOCKS_BUMP;
47536+ break;
47537+ case RLIMIT_SIGPENDING:
47538+ res_add += GR_RLIM_SIGPENDING_BUMP;
47539+ break;
47540+ case RLIMIT_MSGQUEUE:
47541+ res_add += GR_RLIM_MSGQUEUE_BUMP;
47542+ break;
47543+ case RLIMIT_NICE:
47544+ res_add += GR_RLIM_NICE_BUMP;
47545+ break;
47546+ case RLIMIT_RTPRIO:
47547+ res_add += GR_RLIM_RTPRIO_BUMP;
47548+ break;
47549+ case RLIMIT_RTTIME:
47550+ res_add += GR_RLIM_RTTIME_BUMP;
47551+ break;
47552+ }
47553+
47554+ acl->res[res].rlim_cur = res_add;
47555+
47556+ if (wanted > acl->res[res].rlim_max)
47557+ acl->res[res].rlim_max = res_add;
47558+
47559+ /* only log the subject filename, since resource logging is supported for
47560+ single-subject learning only */
47561+ rcu_read_lock();
47562+ cred = __task_cred(task);
47563+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
47564+ task->role->roletype, cred->uid, cred->gid, acl->filename,
47565+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
47566+ "", (unsigned long) res, &task->signal->saved_ip);
47567+ rcu_read_unlock();
47568+ }
47569+
47570+ return;
47571+}
47572+
47573+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
47574+void
47575+pax_set_initial_flags(struct linux_binprm *bprm)
47576+{
47577+ struct task_struct *task = current;
47578+ struct acl_subject_label *proc;
47579+ unsigned long flags;
47580+
47581+ if (unlikely(!(gr_status & GR_READY)))
47582+ return;
47583+
47584+ flags = pax_get_flags(task);
47585+
47586+ proc = task->acl;
47587+
47588+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
47589+ flags &= ~MF_PAX_PAGEEXEC;
47590+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
47591+ flags &= ~MF_PAX_SEGMEXEC;
47592+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
47593+ flags &= ~MF_PAX_RANDMMAP;
47594+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
47595+ flags &= ~MF_PAX_EMUTRAMP;
47596+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
47597+ flags &= ~MF_PAX_MPROTECT;
47598+
47599+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
47600+ flags |= MF_PAX_PAGEEXEC;
47601+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
47602+ flags |= MF_PAX_SEGMEXEC;
47603+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
47604+ flags |= MF_PAX_RANDMMAP;
47605+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
47606+ flags |= MF_PAX_EMUTRAMP;
47607+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
47608+ flags |= MF_PAX_MPROTECT;
47609+
47610+ pax_set_flags(task, flags);
47611+
47612+ return;
47613+}
47614+#endif
47615+
47616+#ifdef CONFIG_SYSCTL
47617+/* Eric Biederman likes breaking userland ABI and every inode-based security
47618+ system to save 35kb of memory */
47619+
47620+/* we modify the passed in filename, but adjust it back before returning */
47621+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
47622+{
47623+ struct name_entry *nmatch;
47624+ char *p, *lastp = NULL;
47625+ struct acl_object_label *obj = NULL, *tmp;
47626+ struct acl_subject_label *tmpsubj;
47627+ char c = '\0';
47628+
47629+ read_lock(&gr_inode_lock);
47630+
47631+ p = name + len - 1;
47632+ do {
47633+ nmatch = lookup_name_entry(name);
47634+ if (lastp != NULL)
47635+ *lastp = c;
47636+
47637+ if (nmatch == NULL)
47638+ goto next_component;
47639+ tmpsubj = current->acl;
47640+ do {
47641+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
47642+ if (obj != NULL) {
47643+ tmp = obj->globbed;
47644+ while (tmp) {
47645+ if (!glob_match(tmp->filename, name)) {
47646+ obj = tmp;
47647+ goto found_obj;
47648+ }
47649+ tmp = tmp->next;
47650+ }
47651+ goto found_obj;
47652+ }
47653+ } while ((tmpsubj = tmpsubj->parent_subject));
47654+next_component:
47655+ /* end case */
47656+ if (p == name)
47657+ break;
47658+
47659+ while (*p != '/')
47660+ p--;
47661+ if (p == name)
47662+ lastp = p + 1;
47663+ else {
47664+ lastp = p;
47665+ p--;
47666+ }
47667+ c = *lastp;
47668+ *lastp = '\0';
47669+ } while (1);
47670+found_obj:
47671+ read_unlock(&gr_inode_lock);
47672+ /* obj returned will always be non-null */
47673+ return obj;
47674+}
47675+
47676+/* returns 0 when allowing, non-zero on error
47677+ op of 0 is used for readdir, so we don't log the names of hidden files
47678+*/
47679+__u32
47680+gr_handle_sysctl(const struct ctl_table *table, const int op)
47681+{
47682+ struct ctl_table *tmp;
47683+ const char *proc_sys = "/proc/sys";
47684+ char *path;
47685+ struct acl_object_label *obj;
47686+ unsigned short len = 0, pos = 0, depth = 0, i;
47687+ __u32 err = 0;
47688+ __u32 mode = 0;
47689+
47690+ if (unlikely(!(gr_status & GR_READY)))
47691+ return 0;
47692+
47693+ /* for now, ignore operations on non-sysctl entries if it's not a
47694+ readdir*/
47695+ if (table->child != NULL && op != 0)
47696+ return 0;
47697+
47698+ mode |= GR_FIND;
47699+ /* it's only a read if it's an entry, read on dirs is for readdir */
47700+ if (op & MAY_READ)
47701+ mode |= GR_READ;
47702+ if (op & MAY_WRITE)
47703+ mode |= GR_WRITE;
47704+
47705+ preempt_disable();
47706+
47707+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
47708+
47709+ /* it's only a read/write if it's an actual entry, not a dir
47710+ (which are opened for readdir)
47711+ */
47712+
47713+ /* convert the requested sysctl entry into a pathname */
47714+
47715+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
47716+ len += strlen(tmp->procname);
47717+ len++;
47718+ depth++;
47719+ }
47720+
47721+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
47722+ /* deny */
47723+ goto out;
47724+ }
47725+
47726+ memset(path, 0, PAGE_SIZE);
47727+
47728+ memcpy(path, proc_sys, strlen(proc_sys));
47729+
47730+ pos += strlen(proc_sys);
47731+
47732+ for (; depth > 0; depth--) {
47733+ path[pos] = '/';
47734+ pos++;
47735+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
47736+ if (depth == i) {
47737+ memcpy(path + pos, tmp->procname,
47738+ strlen(tmp->procname));
47739+ pos += strlen(tmp->procname);
47740+ }
47741+ i++;
47742+ }
47743+ }
47744+
47745+ obj = gr_lookup_by_name(path, pos);
47746+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
47747+
47748+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
47749+ ((err & mode) != mode))) {
47750+ __u32 new_mode = mode;
47751+
47752+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
47753+
47754+ err = 0;
47755+ gr_log_learn_sysctl(path, new_mode);
47756+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
47757+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
47758+ err = -ENOENT;
47759+ } else if (!(err & GR_FIND)) {
47760+ err = -ENOENT;
47761+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
47762+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
47763+ path, (mode & GR_READ) ? " reading" : "",
47764+ (mode & GR_WRITE) ? " writing" : "");
47765+ err = -EACCES;
47766+ } else if ((err & mode) != mode) {
47767+ err = -EACCES;
47768+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
47769+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
47770+ path, (mode & GR_READ) ? " reading" : "",
47771+ (mode & GR_WRITE) ? " writing" : "");
47772+ err = 0;
47773+ } else
47774+ err = 0;
47775+
47776+ out:
47777+ preempt_enable();
47778+
47779+ return err;
47780+}
47781+#endif
47782+
47783+int
47784+gr_handle_proc_ptrace(struct task_struct *task)
47785+{
47786+ struct file *filp;
47787+ struct task_struct *tmp = task;
47788+ struct task_struct *curtemp = current;
47789+ __u32 retmode;
47790+
47791+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
47792+ if (unlikely(!(gr_status & GR_READY)))
47793+ return 0;
47794+#endif
47795+
47796+ read_lock(&tasklist_lock);
47797+ read_lock(&grsec_exec_file_lock);
47798+ filp = task->exec_file;
47799+
47800+ while (tmp->pid > 0) {
47801+ if (tmp == curtemp)
47802+ break;
47803+ tmp = tmp->real_parent;
47804+ }
47805+
47806+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
47807+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
47808+ read_unlock(&grsec_exec_file_lock);
47809+ read_unlock(&tasklist_lock);
47810+ return 1;
47811+ }
47812+
47813+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
47814+ if (!(gr_status & GR_READY)) {
47815+ read_unlock(&grsec_exec_file_lock);
47816+ read_unlock(&tasklist_lock);
47817+ return 0;
47818+ }
47819+#endif
47820+
47821+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
47822+ read_unlock(&grsec_exec_file_lock);
47823+ read_unlock(&tasklist_lock);
47824+
47825+ if (retmode & GR_NOPTRACE)
47826+ return 1;
47827+
47828+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
47829+ && (current->acl != task->acl || (current->acl != current->role->root_label
47830+ && current->pid != task->pid)))
47831+ return 1;
47832+
47833+ return 0;
47834+}
47835+
47836+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
47837+{
47838+ if (unlikely(!(gr_status & GR_READY)))
47839+ return;
47840+
47841+ if (!(current->role->roletype & GR_ROLE_GOD))
47842+ return;
47843+
47844+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
47845+ p->role->rolename, gr_task_roletype_to_char(p),
47846+ p->acl->filename);
47847+}
47848+
47849+int
47850+gr_handle_ptrace(struct task_struct *task, const long request)
47851+{
47852+ struct task_struct *tmp = task;
47853+ struct task_struct *curtemp = current;
47854+ __u32 retmode;
47855+
47856+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
47857+ if (unlikely(!(gr_status & GR_READY)))
47858+ return 0;
47859+#endif
47860+
47861+ read_lock(&tasklist_lock);
47862+ while (tmp->pid > 0) {
47863+ if (tmp == curtemp)
47864+ break;
47865+ tmp = tmp->real_parent;
47866+ }
47867+
47868+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
47869+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
47870+ read_unlock(&tasklist_lock);
47871+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47872+ return 1;
47873+ }
47874+ read_unlock(&tasklist_lock);
47875+
47876+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
47877+ if (!(gr_status & GR_READY))
47878+ return 0;
47879+#endif
47880+
47881+ read_lock(&grsec_exec_file_lock);
47882+ if (unlikely(!task->exec_file)) {
47883+ read_unlock(&grsec_exec_file_lock);
47884+ return 0;
47885+ }
47886+
47887+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
47888+ read_unlock(&grsec_exec_file_lock);
47889+
47890+ if (retmode & GR_NOPTRACE) {
47891+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47892+ return 1;
47893+ }
47894+
47895+ if (retmode & GR_PTRACERD) {
47896+ switch (request) {
47897+ case PTRACE_POKETEXT:
47898+ case PTRACE_POKEDATA:
47899+ case PTRACE_POKEUSR:
47900+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
47901+ case PTRACE_SETREGS:
47902+ case PTRACE_SETFPREGS:
47903+#endif
47904+#ifdef CONFIG_X86
47905+ case PTRACE_SETFPXREGS:
47906+#endif
47907+#ifdef CONFIG_ALTIVEC
47908+ case PTRACE_SETVRREGS:
47909+#endif
47910+ return 1;
47911+ default:
47912+ return 0;
47913+ }
47914+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
47915+ !(current->role->roletype & GR_ROLE_GOD) &&
47916+ (current->acl != task->acl)) {
47917+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47918+ return 1;
47919+ }
47920+
47921+ return 0;
47922+}
47923+
47924+static int is_writable_mmap(const struct file *filp)
47925+{
47926+ struct task_struct *task = current;
47927+ struct acl_object_label *obj, *obj2;
47928+
47929+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
47930+ !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))) {
47931+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47932+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
47933+ task->role->root_label);
47934+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
47935+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
47936+ return 1;
47937+ }
47938+ }
47939+ return 0;
47940+}
47941+
47942+int
47943+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
47944+{
47945+ __u32 mode;
47946+
47947+ if (unlikely(!file || !(prot & PROT_EXEC)))
47948+ return 1;
47949+
47950+ if (is_writable_mmap(file))
47951+ return 0;
47952+
47953+ mode =
47954+ gr_search_file(file->f_path.dentry,
47955+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
47956+ file->f_path.mnt);
47957+
47958+ if (!gr_tpe_allow(file))
47959+ return 0;
47960+
47961+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
47962+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47963+ return 0;
47964+ } else if (unlikely(!(mode & GR_EXEC))) {
47965+ return 0;
47966+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
47967+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47968+ return 1;
47969+ }
47970+
47971+ return 1;
47972+}
47973+
47974+int
47975+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
47976+{
47977+ __u32 mode;
47978+
47979+ if (unlikely(!file || !(prot & PROT_EXEC)))
47980+ return 1;
47981+
47982+ if (is_writable_mmap(file))
47983+ return 0;
47984+
47985+ mode =
47986+ gr_search_file(file->f_path.dentry,
47987+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
47988+ file->f_path.mnt);
47989+
47990+ if (!gr_tpe_allow(file))
47991+ return 0;
47992+
47993+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
47994+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47995+ return 0;
47996+ } else if (unlikely(!(mode & GR_EXEC))) {
47997+ return 0;
47998+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
47999+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
48000+ return 1;
48001+ }
48002+
48003+ return 1;
48004+}
48005+
48006+void
48007+gr_acl_handle_psacct(struct task_struct *task, const long code)
48008+{
48009+ unsigned long runtime;
48010+ unsigned long cputime;
48011+ unsigned int wday, cday;
48012+ __u8 whr, chr;
48013+ __u8 wmin, cmin;
48014+ __u8 wsec, csec;
48015+ struct timespec timeval;
48016+
48017+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
48018+ !(task->acl->mode & GR_PROCACCT)))
48019+ return;
48020+
48021+ do_posix_clock_monotonic_gettime(&timeval);
48022+ runtime = timeval.tv_sec - task->start_time.tv_sec;
48023+ wday = runtime / (3600 * 24);
48024+ runtime -= wday * (3600 * 24);
48025+ whr = runtime / 3600;
48026+ runtime -= whr * 3600;
48027+ wmin = runtime / 60;
48028+ runtime -= wmin * 60;
48029+ wsec = runtime;
48030+
48031+ cputime = (task->utime + task->stime) / HZ;
48032+ cday = cputime / (3600 * 24);
48033+ cputime -= cday * (3600 * 24);
48034+ chr = cputime / 3600;
48035+ cputime -= chr * 3600;
48036+ cmin = cputime / 60;
48037+ cputime -= cmin * 60;
48038+ csec = cputime;
48039+
48040+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
48041+
48042+ return;
48043+}
48044+
48045+void gr_set_kernel_label(struct task_struct *task)
48046+{
48047+ if (gr_status & GR_READY) {
48048+ task->role = kernel_role;
48049+ task->acl = kernel_role->root_label;
48050+ }
48051+ return;
48052+}
48053+
48054+#ifdef CONFIG_TASKSTATS
48055+int gr_is_taskstats_denied(int pid)
48056+{
48057+ struct task_struct *task;
48058+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48059+ const struct cred *cred;
48060+#endif
48061+ int ret = 0;
48062+
48063+ /* restrict taskstats viewing to un-chrooted root users
48064+ who have the 'view' subject flag if the RBAC system is enabled
48065+ */
48066+
48067+ rcu_read_lock();
48068+ read_lock(&tasklist_lock);
48069+ task = find_task_by_vpid(pid);
48070+ if (task) {
48071+#ifdef CONFIG_GRKERNSEC_CHROOT
48072+ if (proc_is_chrooted(task))
48073+ ret = -EACCES;
48074+#endif
48075+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48076+ cred = __task_cred(task);
48077+#ifdef CONFIG_GRKERNSEC_PROC_USER
48078+ if (cred->uid != 0)
48079+ ret = -EACCES;
48080+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48081+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
48082+ ret = -EACCES;
48083+#endif
48084+#endif
48085+ if (gr_status & GR_READY) {
48086+ if (!(task->acl->mode & GR_VIEW))
48087+ ret = -EACCES;
48088+ }
48089+ } else
48090+ ret = -ENOENT;
48091+
48092+ read_unlock(&tasklist_lock);
48093+ rcu_read_unlock();
48094+
48095+ return ret;
48096+}
48097+#endif
48098+
48099+/* AUXV entries are filled via a descendant of search_binary_handler
48100+ after we've already applied the subject for the target
48101+*/
48102+int gr_acl_enable_at_secure(void)
48103+{
48104+ if (unlikely(!(gr_status & GR_READY)))
48105+ return 0;
48106+
48107+ if (current->acl->mode & GR_ATSECURE)
48108+ return 1;
48109+
48110+ return 0;
48111+}
48112+
48113+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
48114+{
48115+ struct task_struct *task = current;
48116+ struct dentry *dentry = file->f_path.dentry;
48117+ struct vfsmount *mnt = file->f_path.mnt;
48118+ struct acl_object_label *obj, *tmp;
48119+ struct acl_subject_label *subj;
48120+ unsigned int bufsize;
48121+ int is_not_root;
48122+ char *path;
48123+ dev_t dev = __get_dev(dentry);
48124+
48125+ if (unlikely(!(gr_status & GR_READY)))
48126+ return 1;
48127+
48128+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
48129+ return 1;
48130+
48131+ /* ignore Eric Biederman */
48132+ if (IS_PRIVATE(dentry->d_inode))
48133+ return 1;
48134+
48135+ subj = task->acl;
48136+ do {
48137+ obj = lookup_acl_obj_label(ino, dev, subj);
48138+ if (obj != NULL)
48139+ return (obj->mode & GR_FIND) ? 1 : 0;
48140+ } while ((subj = subj->parent_subject));
48141+
48142+ /* this is purely an optimization since we're looking for an object
48143+ for the directory we're doing a readdir on
48144+ if it's possible for any globbed object to match the entry we're
48145+ filling into the directory, then the object we find here will be
48146+ an anchor point with attached globbed objects
48147+ */
48148+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
48149+ if (obj->globbed == NULL)
48150+ return (obj->mode & GR_FIND) ? 1 : 0;
48151+
48152+ is_not_root = ((obj->filename[0] == '/') &&
48153+ (obj->filename[1] == '\0')) ? 0 : 1;
48154+ bufsize = PAGE_SIZE - namelen - is_not_root;
48155+
48156+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
48157+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
48158+ return 1;
48159+
48160+ preempt_disable();
48161+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
48162+ bufsize);
48163+
48164+ bufsize = strlen(path);
48165+
48166+ /* if base is "/", don't append an additional slash */
48167+ if (is_not_root)
48168+ *(path + bufsize) = '/';
48169+ memcpy(path + bufsize + is_not_root, name, namelen);
48170+ *(path + bufsize + namelen + is_not_root) = '\0';
48171+
48172+ tmp = obj->globbed;
48173+ while (tmp) {
48174+ if (!glob_match(tmp->filename, path)) {
48175+ preempt_enable();
48176+ return (tmp->mode & GR_FIND) ? 1 : 0;
48177+ }
48178+ tmp = tmp->next;
48179+ }
48180+ preempt_enable();
48181+ return (obj->mode & GR_FIND) ? 1 : 0;
48182+}
48183+
48184+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
48185+EXPORT_SYMBOL(gr_acl_is_enabled);
48186+#endif
48187+EXPORT_SYMBOL(gr_learn_resource);
48188+EXPORT_SYMBOL(gr_set_kernel_label);
48189+#ifdef CONFIG_SECURITY
48190+EXPORT_SYMBOL(gr_check_user_change);
48191+EXPORT_SYMBOL(gr_check_group_change);
48192+#endif
48193+
48194diff -urNp linux-3.0.4/grsecurity/gracl_cap.c linux-3.0.4/grsecurity/gracl_cap.c
48195--- linux-3.0.4/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
48196+++ linux-3.0.4/grsecurity/gracl_cap.c 2011-09-14 09:21:24.000000000 -0400
48197@@ -0,0 +1,101 @@
48198+#include <linux/kernel.h>
48199+#include <linux/module.h>
48200+#include <linux/sched.h>
48201+#include <linux/gracl.h>
48202+#include <linux/grsecurity.h>
48203+#include <linux/grinternal.h>
48204+
48205+extern const char *captab_log[];
48206+extern int captab_log_entries;
48207+
48208+int
48209+gr_acl_is_capable(const int cap)
48210+{
48211+ struct task_struct *task = current;
48212+ const struct cred *cred = current_cred();
48213+ struct acl_subject_label *curracl;
48214+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
48215+ kernel_cap_t cap_audit = __cap_empty_set;
48216+
48217+ if (!gr_acl_is_enabled())
48218+ return 1;
48219+
48220+ curracl = task->acl;
48221+
48222+ cap_drop = curracl->cap_lower;
48223+ cap_mask = curracl->cap_mask;
48224+ cap_audit = curracl->cap_invert_audit;
48225+
48226+ while ((curracl = curracl->parent_subject)) {
48227+ /* if the cap isn't specified in the current computed mask but is specified in the
48228+ current level subject, and is lowered in the current level subject, then add
48229+ it to the set of dropped capabilities
48230+ otherwise, add the current level subject's mask to the current computed mask
48231+ */
48232+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
48233+ cap_raise(cap_mask, cap);
48234+ if (cap_raised(curracl->cap_lower, cap))
48235+ cap_raise(cap_drop, cap);
48236+ if (cap_raised(curracl->cap_invert_audit, cap))
48237+ cap_raise(cap_audit, cap);
48238+ }
48239+ }
48240+
48241+ if (!cap_raised(cap_drop, cap)) {
48242+ if (cap_raised(cap_audit, cap))
48243+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
48244+ return 1;
48245+ }
48246+
48247+ curracl = task->acl;
48248+
48249+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
48250+ && cap_raised(cred->cap_effective, cap)) {
48251+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
48252+ task->role->roletype, cred->uid,
48253+ cred->gid, task->exec_file ?
48254+ gr_to_filename(task->exec_file->f_path.dentry,
48255+ task->exec_file->f_path.mnt) : curracl->filename,
48256+ curracl->filename, 0UL,
48257+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
48258+ return 1;
48259+ }
48260+
48261+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
48262+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
48263+ return 0;
48264+}
48265+
48266+int
48267+gr_acl_is_capable_nolog(const int cap)
48268+{
48269+ struct acl_subject_label *curracl;
48270+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
48271+
48272+ if (!gr_acl_is_enabled())
48273+ return 1;
48274+
48275+ curracl = current->acl;
48276+
48277+ cap_drop = curracl->cap_lower;
48278+ cap_mask = curracl->cap_mask;
48279+
48280+ while ((curracl = curracl->parent_subject)) {
48281+ /* if the cap isn't specified in the current computed mask but is specified in the
48282+ current level subject, and is lowered in the current level subject, then add
48283+ it to the set of dropped capabilities
48284+ otherwise, add the current level subject's mask to the current computed mask
48285+ */
48286+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
48287+ cap_raise(cap_mask, cap);
48288+ if (cap_raised(curracl->cap_lower, cap))
48289+ cap_raise(cap_drop, cap);
48290+ }
48291+ }
48292+
48293+ if (!cap_raised(cap_drop, cap))
48294+ return 1;
48295+
48296+ return 0;
48297+}
48298+
48299diff -urNp linux-3.0.4/grsecurity/gracl_fs.c linux-3.0.4/grsecurity/gracl_fs.c
48300--- linux-3.0.4/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
48301+++ linux-3.0.4/grsecurity/gracl_fs.c 2011-08-23 21:48:14.000000000 -0400
48302@@ -0,0 +1,431 @@
48303+#include <linux/kernel.h>
48304+#include <linux/sched.h>
48305+#include <linux/types.h>
48306+#include <linux/fs.h>
48307+#include <linux/file.h>
48308+#include <linux/stat.h>
48309+#include <linux/grsecurity.h>
48310+#include <linux/grinternal.h>
48311+#include <linux/gracl.h>
48312+
48313+__u32
48314+gr_acl_handle_hidden_file(const struct dentry * dentry,
48315+ const struct vfsmount * mnt)
48316+{
48317+ __u32 mode;
48318+
48319+ if (unlikely(!dentry->d_inode))
48320+ return GR_FIND;
48321+
48322+ mode =
48323+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
48324+
48325+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
48326+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
48327+ return mode;
48328+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
48329+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
48330+ return 0;
48331+ } else if (unlikely(!(mode & GR_FIND)))
48332+ return 0;
48333+
48334+ return GR_FIND;
48335+}
48336+
48337+__u32
48338+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
48339+ const int fmode)
48340+{
48341+ __u32 reqmode = GR_FIND;
48342+ __u32 mode;
48343+
48344+ if (unlikely(!dentry->d_inode))
48345+ return reqmode;
48346+
48347+ if (unlikely(fmode & O_APPEND))
48348+ reqmode |= GR_APPEND;
48349+ else if (unlikely(fmode & FMODE_WRITE))
48350+ reqmode |= GR_WRITE;
48351+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
48352+ reqmode |= GR_READ;
48353+ if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
48354+ reqmode &= ~GR_READ;
48355+ mode =
48356+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
48357+ mnt);
48358+
48359+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
48360+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
48361+ reqmode & GR_READ ? " reading" : "",
48362+ reqmode & GR_WRITE ? " writing" : reqmode &
48363+ GR_APPEND ? " appending" : "");
48364+ return reqmode;
48365+ } else
48366+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
48367+ {
48368+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
48369+ reqmode & GR_READ ? " reading" : "",
48370+ reqmode & GR_WRITE ? " writing" : reqmode &
48371+ GR_APPEND ? " appending" : "");
48372+ return 0;
48373+ } else if (unlikely((mode & reqmode) != reqmode))
48374+ return 0;
48375+
48376+ return reqmode;
48377+}
48378+
48379+__u32
48380+gr_acl_handle_creat(const struct dentry * dentry,
48381+ const struct dentry * p_dentry,
48382+ const struct vfsmount * p_mnt, const int fmode,
48383+ const int imode)
48384+{
48385+ __u32 reqmode = GR_WRITE | GR_CREATE;
48386+ __u32 mode;
48387+
48388+ if (unlikely(fmode & O_APPEND))
48389+ reqmode |= GR_APPEND;
48390+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
48391+ reqmode |= GR_READ;
48392+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
48393+ reqmode |= GR_SETID;
48394+
48395+ mode =
48396+ gr_check_create(dentry, p_dentry, p_mnt,
48397+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
48398+
48399+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
48400+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
48401+ reqmode & GR_READ ? " reading" : "",
48402+ reqmode & GR_WRITE ? " writing" : reqmode &
48403+ GR_APPEND ? " appending" : "");
48404+ return reqmode;
48405+ } else
48406+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
48407+ {
48408+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
48409+ reqmode & GR_READ ? " reading" : "",
48410+ reqmode & GR_WRITE ? " writing" : reqmode &
48411+ GR_APPEND ? " appending" : "");
48412+ return 0;
48413+ } else if (unlikely((mode & reqmode) != reqmode))
48414+ return 0;
48415+
48416+ return reqmode;
48417+}
48418+
48419+__u32
48420+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
48421+ const int fmode)
48422+{
48423+ __u32 mode, reqmode = GR_FIND;
48424+
48425+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
48426+ reqmode |= GR_EXEC;
48427+ if (fmode & S_IWOTH)
48428+ reqmode |= GR_WRITE;
48429+ if (fmode & S_IROTH)
48430+ reqmode |= GR_READ;
48431+
48432+ mode =
48433+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
48434+ mnt);
48435+
48436+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
48437+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
48438+ reqmode & GR_READ ? " reading" : "",
48439+ reqmode & GR_WRITE ? " writing" : "",
48440+ reqmode & GR_EXEC ? " executing" : "");
48441+ return reqmode;
48442+ } else
48443+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
48444+ {
48445+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
48446+ reqmode & GR_READ ? " reading" : "",
48447+ reqmode & GR_WRITE ? " writing" : "",
48448+ reqmode & GR_EXEC ? " executing" : "");
48449+ return 0;
48450+ } else if (unlikely((mode & reqmode) != reqmode))
48451+ return 0;
48452+
48453+ return reqmode;
48454+}
48455+
48456+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
48457+{
48458+ __u32 mode;
48459+
48460+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
48461+
48462+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
48463+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
48464+ return mode;
48465+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
48466+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
48467+ return 0;
48468+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
48469+ return 0;
48470+
48471+ return (reqmode);
48472+}
48473+
48474+__u32
48475+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
48476+{
48477+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
48478+}
48479+
48480+__u32
48481+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
48482+{
48483+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
48484+}
48485+
48486+__u32
48487+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
48488+{
48489+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
48490+}
48491+
48492+__u32
48493+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
48494+{
48495+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
48496+}
48497+
48498+__u32
48499+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
48500+ mode_t mode)
48501+{
48502+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
48503+ return 1;
48504+
48505+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
48506+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
48507+ GR_FCHMOD_ACL_MSG);
48508+ } else {
48509+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
48510+ }
48511+}
48512+
48513+__u32
48514+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
48515+ mode_t mode)
48516+{
48517+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
48518+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
48519+ GR_CHMOD_ACL_MSG);
48520+ } else {
48521+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
48522+ }
48523+}
48524+
48525+__u32
48526+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
48527+{
48528+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
48529+}
48530+
48531+__u32
48532+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
48533+{
48534+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
48535+}
48536+
48537+__u32
48538+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
48539+{
48540+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
48541+}
48542+
48543+__u32
48544+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
48545+{
48546+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
48547+ GR_UNIXCONNECT_ACL_MSG);
48548+}
48549+
48550+/* hardlinks require at minimum create permission,
48551+ any additional privilege required is based on the
48552+ privilege of the file being linked to
48553+*/
48554+__u32
48555+gr_acl_handle_link(const struct dentry * new_dentry,
48556+ const struct dentry * parent_dentry,
48557+ const struct vfsmount * parent_mnt,
48558+ const struct dentry * old_dentry,
48559+ const struct vfsmount * old_mnt, const char *to)
48560+{
48561+ __u32 mode;
48562+ __u32 needmode = GR_CREATE | GR_LINK;
48563+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
48564+
48565+ mode =
48566+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
48567+ old_mnt);
48568+
48569+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
48570+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
48571+ return mode;
48572+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
48573+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
48574+ return 0;
48575+ } else if (unlikely((mode & needmode) != needmode))
48576+ return 0;
48577+
48578+ return 1;
48579+}
48580+
48581+__u32
48582+gr_acl_handle_symlink(const struct dentry * new_dentry,
48583+ const struct dentry * parent_dentry,
48584+ const struct vfsmount * parent_mnt, const char *from)
48585+{
48586+ __u32 needmode = GR_WRITE | GR_CREATE;
48587+ __u32 mode;
48588+
48589+ mode =
48590+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
48591+ GR_CREATE | GR_AUDIT_CREATE |
48592+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
48593+
48594+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
48595+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
48596+ return mode;
48597+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
48598+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
48599+ return 0;
48600+ } else if (unlikely((mode & needmode) != needmode))
48601+ return 0;
48602+
48603+ return (GR_WRITE | GR_CREATE);
48604+}
48605+
48606+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)
48607+{
48608+ __u32 mode;
48609+
48610+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
48611+
48612+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
48613+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
48614+ return mode;
48615+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
48616+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
48617+ return 0;
48618+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
48619+ return 0;
48620+
48621+ return (reqmode);
48622+}
48623+
48624+__u32
48625+gr_acl_handle_mknod(const struct dentry * new_dentry,
48626+ const struct dentry * parent_dentry,
48627+ const struct vfsmount * parent_mnt,
48628+ const int mode)
48629+{
48630+ __u32 reqmode = GR_WRITE | GR_CREATE;
48631+ if (unlikely(mode & (S_ISUID | S_ISGID)))
48632+ reqmode |= GR_SETID;
48633+
48634+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
48635+ reqmode, GR_MKNOD_ACL_MSG);
48636+}
48637+
48638+__u32
48639+gr_acl_handle_mkdir(const struct dentry *new_dentry,
48640+ const struct dentry *parent_dentry,
48641+ const struct vfsmount *parent_mnt)
48642+{
48643+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
48644+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
48645+}
48646+
48647+#define RENAME_CHECK_SUCCESS(old, new) \
48648+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
48649+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
48650+
48651+int
48652+gr_acl_handle_rename(struct dentry *new_dentry,
48653+ struct dentry *parent_dentry,
48654+ const struct vfsmount *parent_mnt,
48655+ struct dentry *old_dentry,
48656+ struct inode *old_parent_inode,
48657+ struct vfsmount *old_mnt, const char *newname)
48658+{
48659+ __u32 comp1, comp2;
48660+ int error = 0;
48661+
48662+ if (unlikely(!gr_acl_is_enabled()))
48663+ return 0;
48664+
48665+ if (!new_dentry->d_inode) {
48666+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
48667+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
48668+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
48669+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
48670+ GR_DELETE | GR_AUDIT_DELETE |
48671+ GR_AUDIT_READ | GR_AUDIT_WRITE |
48672+ GR_SUPPRESS, old_mnt);
48673+ } else {
48674+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
48675+ GR_CREATE | GR_DELETE |
48676+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
48677+ GR_AUDIT_READ | GR_AUDIT_WRITE |
48678+ GR_SUPPRESS, parent_mnt);
48679+ comp2 =
48680+ gr_search_file(old_dentry,
48681+ GR_READ | GR_WRITE | GR_AUDIT_READ |
48682+ GR_DELETE | GR_AUDIT_DELETE |
48683+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
48684+ }
48685+
48686+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
48687+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
48688+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
48689+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
48690+ && !(comp2 & GR_SUPPRESS)) {
48691+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
48692+ error = -EACCES;
48693+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
48694+ error = -EACCES;
48695+
48696+ return error;
48697+}
48698+
48699+void
48700+gr_acl_handle_exit(void)
48701+{
48702+ u16 id;
48703+ char *rolename;
48704+ struct file *exec_file;
48705+
48706+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
48707+ !(current->role->roletype & GR_ROLE_PERSIST))) {
48708+ id = current->acl_role_id;
48709+ rolename = current->role->rolename;
48710+ gr_set_acls(1);
48711+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
48712+ }
48713+
48714+ write_lock(&grsec_exec_file_lock);
48715+ exec_file = current->exec_file;
48716+ current->exec_file = NULL;
48717+ write_unlock(&grsec_exec_file_lock);
48718+
48719+ if (exec_file)
48720+ fput(exec_file);
48721+}
48722+
48723+int
48724+gr_acl_handle_procpidmem(const struct task_struct *task)
48725+{
48726+ if (unlikely(!gr_acl_is_enabled()))
48727+ return 0;
48728+
48729+ if (task != current && task->acl->mode & GR_PROTPROCFD)
48730+ return -EACCES;
48731+
48732+ return 0;
48733+}
48734diff -urNp linux-3.0.4/grsecurity/gracl_ip.c linux-3.0.4/grsecurity/gracl_ip.c
48735--- linux-3.0.4/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
48736+++ linux-3.0.4/grsecurity/gracl_ip.c 2011-08-23 21:48:14.000000000 -0400
48737@@ -0,0 +1,381 @@
48738+#include <linux/kernel.h>
48739+#include <asm/uaccess.h>
48740+#include <asm/errno.h>
48741+#include <net/sock.h>
48742+#include <linux/file.h>
48743+#include <linux/fs.h>
48744+#include <linux/net.h>
48745+#include <linux/in.h>
48746+#include <linux/skbuff.h>
48747+#include <linux/ip.h>
48748+#include <linux/udp.h>
48749+#include <linux/types.h>
48750+#include <linux/sched.h>
48751+#include <linux/netdevice.h>
48752+#include <linux/inetdevice.h>
48753+#include <linux/gracl.h>
48754+#include <linux/grsecurity.h>
48755+#include <linux/grinternal.h>
48756+
48757+#define GR_BIND 0x01
48758+#define GR_CONNECT 0x02
48759+#define GR_INVERT 0x04
48760+#define GR_BINDOVERRIDE 0x08
48761+#define GR_CONNECTOVERRIDE 0x10
48762+#define GR_SOCK_FAMILY 0x20
48763+
48764+static const char * gr_protocols[IPPROTO_MAX] = {
48765+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
48766+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
48767+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
48768+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
48769+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
48770+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
48771+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
48772+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
48773+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
48774+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
48775+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
48776+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
48777+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
48778+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
48779+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
48780+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
48781+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
48782+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
48783+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
48784+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
48785+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
48786+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
48787+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
48788+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
48789+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
48790+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
48791+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
48792+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
48793+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
48794+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
48795+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
48796+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
48797+ };
48798+
48799+static const char * gr_socktypes[SOCK_MAX] = {
48800+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
48801+ "unknown:7", "unknown:8", "unknown:9", "packet"
48802+ };
48803+
48804+static const char * gr_sockfamilies[AF_MAX+1] = {
48805+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
48806+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
48807+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
48808+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
48809+ };
48810+
48811+const char *
48812+gr_proto_to_name(unsigned char proto)
48813+{
48814+ return gr_protocols[proto];
48815+}
48816+
48817+const char *
48818+gr_socktype_to_name(unsigned char type)
48819+{
48820+ return gr_socktypes[type];
48821+}
48822+
48823+const char *
48824+gr_sockfamily_to_name(unsigned char family)
48825+{
48826+ return gr_sockfamilies[family];
48827+}
48828+
48829+int
48830+gr_search_socket(const int domain, const int type, const int protocol)
48831+{
48832+ struct acl_subject_label *curr;
48833+ const struct cred *cred = current_cred();
48834+
48835+ if (unlikely(!gr_acl_is_enabled()))
48836+ goto exit;
48837+
48838+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
48839+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
48840+ goto exit; // let the kernel handle it
48841+
48842+ curr = current->acl;
48843+
48844+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
48845+ /* the family is allowed, if this is PF_INET allow it only if
48846+ the extra sock type/protocol checks pass */
48847+ if (domain == PF_INET)
48848+ goto inet_check;
48849+ goto exit;
48850+ } else {
48851+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48852+ __u32 fakeip = 0;
48853+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48854+ current->role->roletype, cred->uid,
48855+ cred->gid, current->exec_file ?
48856+ gr_to_filename(current->exec_file->f_path.dentry,
48857+ current->exec_file->f_path.mnt) :
48858+ curr->filename, curr->filename,
48859+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
48860+ &current->signal->saved_ip);
48861+ goto exit;
48862+ }
48863+ goto exit_fail;
48864+ }
48865+
48866+inet_check:
48867+ /* the rest of this checking is for IPv4 only */
48868+ if (!curr->ips)
48869+ goto exit;
48870+
48871+ if ((curr->ip_type & (1 << type)) &&
48872+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
48873+ goto exit;
48874+
48875+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48876+ /* we don't place acls on raw sockets , and sometimes
48877+ dgram/ip sockets are opened for ioctl and not
48878+ bind/connect, so we'll fake a bind learn log */
48879+ if (type == SOCK_RAW || type == SOCK_PACKET) {
48880+ __u32 fakeip = 0;
48881+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48882+ current->role->roletype, cred->uid,
48883+ cred->gid, current->exec_file ?
48884+ gr_to_filename(current->exec_file->f_path.dentry,
48885+ current->exec_file->f_path.mnt) :
48886+ curr->filename, curr->filename,
48887+ &fakeip, 0, type,
48888+ protocol, GR_CONNECT, &current->signal->saved_ip);
48889+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
48890+ __u32 fakeip = 0;
48891+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48892+ current->role->roletype, cred->uid,
48893+ cred->gid, current->exec_file ?
48894+ gr_to_filename(current->exec_file->f_path.dentry,
48895+ current->exec_file->f_path.mnt) :
48896+ curr->filename, curr->filename,
48897+ &fakeip, 0, type,
48898+ protocol, GR_BIND, &current->signal->saved_ip);
48899+ }
48900+ /* we'll log when they use connect or bind */
48901+ goto exit;
48902+ }
48903+
48904+exit_fail:
48905+ if (domain == PF_INET)
48906+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
48907+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
48908+ else
48909+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
48910+ gr_socktype_to_name(type), protocol);
48911+
48912+ return 0;
48913+exit:
48914+ return 1;
48915+}
48916+
48917+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)
48918+{
48919+ if ((ip->mode & mode) &&
48920+ (ip_port >= ip->low) &&
48921+ (ip_port <= ip->high) &&
48922+ ((ntohl(ip_addr) & our_netmask) ==
48923+ (ntohl(our_addr) & our_netmask))
48924+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
48925+ && (ip->type & (1 << type))) {
48926+ if (ip->mode & GR_INVERT)
48927+ return 2; // specifically denied
48928+ else
48929+ return 1; // allowed
48930+ }
48931+
48932+ return 0; // not specifically allowed, may continue parsing
48933+}
48934+
48935+static int
48936+gr_search_connectbind(const int full_mode, struct sock *sk,
48937+ struct sockaddr_in *addr, const int type)
48938+{
48939+ char iface[IFNAMSIZ] = {0};
48940+ struct acl_subject_label *curr;
48941+ struct acl_ip_label *ip;
48942+ struct inet_sock *isk;
48943+ struct net_device *dev;
48944+ struct in_device *idev;
48945+ unsigned long i;
48946+ int ret;
48947+ int mode = full_mode & (GR_BIND | GR_CONNECT);
48948+ __u32 ip_addr = 0;
48949+ __u32 our_addr;
48950+ __u32 our_netmask;
48951+ char *p;
48952+ __u16 ip_port = 0;
48953+ const struct cred *cred = current_cred();
48954+
48955+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
48956+ return 0;
48957+
48958+ curr = current->acl;
48959+ isk = inet_sk(sk);
48960+
48961+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
48962+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
48963+ addr->sin_addr.s_addr = curr->inaddr_any_override;
48964+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
48965+ struct sockaddr_in saddr;
48966+ int err;
48967+
48968+ saddr.sin_family = AF_INET;
48969+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
48970+ saddr.sin_port = isk->inet_sport;
48971+
48972+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
48973+ if (err)
48974+ return err;
48975+
48976+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
48977+ if (err)
48978+ return err;
48979+ }
48980+
48981+ if (!curr->ips)
48982+ return 0;
48983+
48984+ ip_addr = addr->sin_addr.s_addr;
48985+ ip_port = ntohs(addr->sin_port);
48986+
48987+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48988+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48989+ current->role->roletype, cred->uid,
48990+ cred->gid, current->exec_file ?
48991+ gr_to_filename(current->exec_file->f_path.dentry,
48992+ current->exec_file->f_path.mnt) :
48993+ curr->filename, curr->filename,
48994+ &ip_addr, ip_port, type,
48995+ sk->sk_protocol, mode, &current->signal->saved_ip);
48996+ return 0;
48997+ }
48998+
48999+ for (i = 0; i < curr->ip_num; i++) {
49000+ ip = *(curr->ips + i);
49001+ if (ip->iface != NULL) {
49002+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
49003+ p = strchr(iface, ':');
49004+ if (p != NULL)
49005+ *p = '\0';
49006+ dev = dev_get_by_name(sock_net(sk), iface);
49007+ if (dev == NULL)
49008+ continue;
49009+ idev = in_dev_get(dev);
49010+ if (idev == NULL) {
49011+ dev_put(dev);
49012+ continue;
49013+ }
49014+ rcu_read_lock();
49015+ for_ifa(idev) {
49016+ if (!strcmp(ip->iface, ifa->ifa_label)) {
49017+ our_addr = ifa->ifa_address;
49018+ our_netmask = 0xffffffff;
49019+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
49020+ if (ret == 1) {
49021+ rcu_read_unlock();
49022+ in_dev_put(idev);
49023+ dev_put(dev);
49024+ return 0;
49025+ } else if (ret == 2) {
49026+ rcu_read_unlock();
49027+ in_dev_put(idev);
49028+ dev_put(dev);
49029+ goto denied;
49030+ }
49031+ }
49032+ } endfor_ifa(idev);
49033+ rcu_read_unlock();
49034+ in_dev_put(idev);
49035+ dev_put(dev);
49036+ } else {
49037+ our_addr = ip->addr;
49038+ our_netmask = ip->netmask;
49039+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
49040+ if (ret == 1)
49041+ return 0;
49042+ else if (ret == 2)
49043+ goto denied;
49044+ }
49045+ }
49046+
49047+denied:
49048+ if (mode == GR_BIND)
49049+ 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));
49050+ else if (mode == GR_CONNECT)
49051+ 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));
49052+
49053+ return -EACCES;
49054+}
49055+
49056+int
49057+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
49058+{
49059+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
49060+}
49061+
49062+int
49063+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
49064+{
49065+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
49066+}
49067+
49068+int gr_search_listen(struct socket *sock)
49069+{
49070+ struct sock *sk = sock->sk;
49071+ struct sockaddr_in addr;
49072+
49073+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
49074+ addr.sin_port = inet_sk(sk)->inet_sport;
49075+
49076+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
49077+}
49078+
49079+int gr_search_accept(struct socket *sock)
49080+{
49081+ struct sock *sk = sock->sk;
49082+ struct sockaddr_in addr;
49083+
49084+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
49085+ addr.sin_port = inet_sk(sk)->inet_sport;
49086+
49087+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
49088+}
49089+
49090+int
49091+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
49092+{
49093+ if (addr)
49094+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
49095+ else {
49096+ struct sockaddr_in sin;
49097+ const struct inet_sock *inet = inet_sk(sk);
49098+
49099+ sin.sin_addr.s_addr = inet->inet_daddr;
49100+ sin.sin_port = inet->inet_dport;
49101+
49102+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
49103+ }
49104+}
49105+
49106+int
49107+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
49108+{
49109+ struct sockaddr_in sin;
49110+
49111+ if (unlikely(skb->len < sizeof (struct udphdr)))
49112+ return 0; // skip this packet
49113+
49114+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
49115+ sin.sin_port = udp_hdr(skb)->source;
49116+
49117+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
49118+}
49119diff -urNp linux-3.0.4/grsecurity/gracl_learn.c linux-3.0.4/grsecurity/gracl_learn.c
49120--- linux-3.0.4/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
49121+++ linux-3.0.4/grsecurity/gracl_learn.c 2011-08-23 21:48:14.000000000 -0400
49122@@ -0,0 +1,207 @@
49123+#include <linux/kernel.h>
49124+#include <linux/mm.h>
49125+#include <linux/sched.h>
49126+#include <linux/poll.h>
49127+#include <linux/string.h>
49128+#include <linux/file.h>
49129+#include <linux/types.h>
49130+#include <linux/vmalloc.h>
49131+#include <linux/grinternal.h>
49132+
49133+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
49134+ size_t count, loff_t *ppos);
49135+extern int gr_acl_is_enabled(void);
49136+
49137+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
49138+static int gr_learn_attached;
49139+
49140+/* use a 512k buffer */
49141+#define LEARN_BUFFER_SIZE (512 * 1024)
49142+
49143+static DEFINE_SPINLOCK(gr_learn_lock);
49144+static DEFINE_MUTEX(gr_learn_user_mutex);
49145+
49146+/* we need to maintain two buffers, so that the kernel context of grlearn
49147+ uses a semaphore around the userspace copying, and the other kernel contexts
49148+ use a spinlock when copying into the buffer, since they cannot sleep
49149+*/
49150+static char *learn_buffer;
49151+static char *learn_buffer_user;
49152+static int learn_buffer_len;
49153+static int learn_buffer_user_len;
49154+
49155+static ssize_t
49156+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
49157+{
49158+ DECLARE_WAITQUEUE(wait, current);
49159+ ssize_t retval = 0;
49160+
49161+ add_wait_queue(&learn_wait, &wait);
49162+ set_current_state(TASK_INTERRUPTIBLE);
49163+ do {
49164+ mutex_lock(&gr_learn_user_mutex);
49165+ spin_lock(&gr_learn_lock);
49166+ if (learn_buffer_len)
49167+ break;
49168+ spin_unlock(&gr_learn_lock);
49169+ mutex_unlock(&gr_learn_user_mutex);
49170+ if (file->f_flags & O_NONBLOCK) {
49171+ retval = -EAGAIN;
49172+ goto out;
49173+ }
49174+ if (signal_pending(current)) {
49175+ retval = -ERESTARTSYS;
49176+ goto out;
49177+ }
49178+
49179+ schedule();
49180+ } while (1);
49181+
49182+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
49183+ learn_buffer_user_len = learn_buffer_len;
49184+ retval = learn_buffer_len;
49185+ learn_buffer_len = 0;
49186+
49187+ spin_unlock(&gr_learn_lock);
49188+
49189+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
49190+ retval = -EFAULT;
49191+
49192+ mutex_unlock(&gr_learn_user_mutex);
49193+out:
49194+ set_current_state(TASK_RUNNING);
49195+ remove_wait_queue(&learn_wait, &wait);
49196+ return retval;
49197+}
49198+
49199+static unsigned int
49200+poll_learn(struct file * file, poll_table * wait)
49201+{
49202+ poll_wait(file, &learn_wait, wait);
49203+
49204+ if (learn_buffer_len)
49205+ return (POLLIN | POLLRDNORM);
49206+
49207+ return 0;
49208+}
49209+
49210+void
49211+gr_clear_learn_entries(void)
49212+{
49213+ char *tmp;
49214+
49215+ mutex_lock(&gr_learn_user_mutex);
49216+ spin_lock(&gr_learn_lock);
49217+ tmp = learn_buffer;
49218+ learn_buffer = NULL;
49219+ spin_unlock(&gr_learn_lock);
49220+ if (tmp)
49221+ vfree(tmp);
49222+ if (learn_buffer_user != NULL) {
49223+ vfree(learn_buffer_user);
49224+ learn_buffer_user = NULL;
49225+ }
49226+ learn_buffer_len = 0;
49227+ mutex_unlock(&gr_learn_user_mutex);
49228+
49229+ return;
49230+}
49231+
49232+void
49233+gr_add_learn_entry(const char *fmt, ...)
49234+{
49235+ va_list args;
49236+ unsigned int len;
49237+
49238+ if (!gr_learn_attached)
49239+ return;
49240+
49241+ spin_lock(&gr_learn_lock);
49242+
49243+ /* leave a gap at the end so we know when it's "full" but don't have to
49244+ compute the exact length of the string we're trying to append
49245+ */
49246+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
49247+ spin_unlock(&gr_learn_lock);
49248+ wake_up_interruptible(&learn_wait);
49249+ return;
49250+ }
49251+ if (learn_buffer == NULL) {
49252+ spin_unlock(&gr_learn_lock);
49253+ return;
49254+ }
49255+
49256+ va_start(args, fmt);
49257+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
49258+ va_end(args);
49259+
49260+ learn_buffer_len += len + 1;
49261+
49262+ spin_unlock(&gr_learn_lock);
49263+ wake_up_interruptible(&learn_wait);
49264+
49265+ return;
49266+}
49267+
49268+static int
49269+open_learn(struct inode *inode, struct file *file)
49270+{
49271+ if (file->f_mode & FMODE_READ && gr_learn_attached)
49272+ return -EBUSY;
49273+ if (file->f_mode & FMODE_READ) {
49274+ int retval = 0;
49275+ mutex_lock(&gr_learn_user_mutex);
49276+ if (learn_buffer == NULL)
49277+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
49278+ if (learn_buffer_user == NULL)
49279+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
49280+ if (learn_buffer == NULL) {
49281+ retval = -ENOMEM;
49282+ goto out_error;
49283+ }
49284+ if (learn_buffer_user == NULL) {
49285+ retval = -ENOMEM;
49286+ goto out_error;
49287+ }
49288+ learn_buffer_len = 0;
49289+ learn_buffer_user_len = 0;
49290+ gr_learn_attached = 1;
49291+out_error:
49292+ mutex_unlock(&gr_learn_user_mutex);
49293+ return retval;
49294+ }
49295+ return 0;
49296+}
49297+
49298+static int
49299+close_learn(struct inode *inode, struct file *file)
49300+{
49301+ if (file->f_mode & FMODE_READ) {
49302+ char *tmp = NULL;
49303+ mutex_lock(&gr_learn_user_mutex);
49304+ spin_lock(&gr_learn_lock);
49305+ tmp = learn_buffer;
49306+ learn_buffer = NULL;
49307+ spin_unlock(&gr_learn_lock);
49308+ if (tmp)
49309+ vfree(tmp);
49310+ if (learn_buffer_user != NULL) {
49311+ vfree(learn_buffer_user);
49312+ learn_buffer_user = NULL;
49313+ }
49314+ learn_buffer_len = 0;
49315+ learn_buffer_user_len = 0;
49316+ gr_learn_attached = 0;
49317+ mutex_unlock(&gr_learn_user_mutex);
49318+ }
49319+
49320+ return 0;
49321+}
49322+
49323+const struct file_operations grsec_fops = {
49324+ .read = read_learn,
49325+ .write = write_grsec_handler,
49326+ .open = open_learn,
49327+ .release = close_learn,
49328+ .poll = poll_learn,
49329+};
49330diff -urNp linux-3.0.4/grsecurity/gracl_res.c linux-3.0.4/grsecurity/gracl_res.c
49331--- linux-3.0.4/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
49332+++ linux-3.0.4/grsecurity/gracl_res.c 2011-08-23 21:48:14.000000000 -0400
49333@@ -0,0 +1,68 @@
49334+#include <linux/kernel.h>
49335+#include <linux/sched.h>
49336+#include <linux/gracl.h>
49337+#include <linux/grinternal.h>
49338+
49339+static const char *restab_log[] = {
49340+ [RLIMIT_CPU] = "RLIMIT_CPU",
49341+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
49342+ [RLIMIT_DATA] = "RLIMIT_DATA",
49343+ [RLIMIT_STACK] = "RLIMIT_STACK",
49344+ [RLIMIT_CORE] = "RLIMIT_CORE",
49345+ [RLIMIT_RSS] = "RLIMIT_RSS",
49346+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
49347+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
49348+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
49349+ [RLIMIT_AS] = "RLIMIT_AS",
49350+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
49351+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
49352+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
49353+ [RLIMIT_NICE] = "RLIMIT_NICE",
49354+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
49355+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
49356+ [GR_CRASH_RES] = "RLIMIT_CRASH"
49357+};
49358+
49359+void
49360+gr_log_resource(const struct task_struct *task,
49361+ const int res, const unsigned long wanted, const int gt)
49362+{
49363+ const struct cred *cred;
49364+ unsigned long rlim;
49365+
49366+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
49367+ return;
49368+
49369+ // not yet supported resource
49370+ if (unlikely(!restab_log[res]))
49371+ return;
49372+
49373+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
49374+ rlim = task_rlimit_max(task, res);
49375+ else
49376+ rlim = task_rlimit(task, res);
49377+
49378+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
49379+ return;
49380+
49381+ rcu_read_lock();
49382+ cred = __task_cred(task);
49383+
49384+ if (res == RLIMIT_NPROC &&
49385+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
49386+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
49387+ goto out_rcu_unlock;
49388+ else if (res == RLIMIT_MEMLOCK &&
49389+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
49390+ goto out_rcu_unlock;
49391+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
49392+ goto out_rcu_unlock;
49393+ rcu_read_unlock();
49394+
49395+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
49396+
49397+ return;
49398+out_rcu_unlock:
49399+ rcu_read_unlock();
49400+ return;
49401+}
49402diff -urNp linux-3.0.4/grsecurity/gracl_segv.c linux-3.0.4/grsecurity/gracl_segv.c
49403--- linux-3.0.4/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
49404+++ linux-3.0.4/grsecurity/gracl_segv.c 2011-08-23 21:48:14.000000000 -0400
49405@@ -0,0 +1,299 @@
49406+#include <linux/kernel.h>
49407+#include <linux/mm.h>
49408+#include <asm/uaccess.h>
49409+#include <asm/errno.h>
49410+#include <asm/mman.h>
49411+#include <net/sock.h>
49412+#include <linux/file.h>
49413+#include <linux/fs.h>
49414+#include <linux/net.h>
49415+#include <linux/in.h>
49416+#include <linux/slab.h>
49417+#include <linux/types.h>
49418+#include <linux/sched.h>
49419+#include <linux/timer.h>
49420+#include <linux/gracl.h>
49421+#include <linux/grsecurity.h>
49422+#include <linux/grinternal.h>
49423+
49424+static struct crash_uid *uid_set;
49425+static unsigned short uid_used;
49426+static DEFINE_SPINLOCK(gr_uid_lock);
49427+extern rwlock_t gr_inode_lock;
49428+extern struct acl_subject_label *
49429+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
49430+ struct acl_role_label *role);
49431+
49432+#ifdef CONFIG_BTRFS_FS
49433+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
49434+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
49435+#endif
49436+
49437+static inline dev_t __get_dev(const struct dentry *dentry)
49438+{
49439+#ifdef CONFIG_BTRFS_FS
49440+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
49441+ return get_btrfs_dev_from_inode(dentry->d_inode);
49442+ else
49443+#endif
49444+ return dentry->d_inode->i_sb->s_dev;
49445+}
49446+
49447+int
49448+gr_init_uidset(void)
49449+{
49450+ uid_set =
49451+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
49452+ uid_used = 0;
49453+
49454+ return uid_set ? 1 : 0;
49455+}
49456+
49457+void
49458+gr_free_uidset(void)
49459+{
49460+ if (uid_set)
49461+ kfree(uid_set);
49462+
49463+ return;
49464+}
49465+
49466+int
49467+gr_find_uid(const uid_t uid)
49468+{
49469+ struct crash_uid *tmp = uid_set;
49470+ uid_t buid;
49471+ int low = 0, high = uid_used - 1, mid;
49472+
49473+ while (high >= low) {
49474+ mid = (low + high) >> 1;
49475+ buid = tmp[mid].uid;
49476+ if (buid == uid)
49477+ return mid;
49478+ if (buid > uid)
49479+ high = mid - 1;
49480+ if (buid < uid)
49481+ low = mid + 1;
49482+ }
49483+
49484+ return -1;
49485+}
49486+
49487+static __inline__ void
49488+gr_insertsort(void)
49489+{
49490+ unsigned short i, j;
49491+ struct crash_uid index;
49492+
49493+ for (i = 1; i < uid_used; i++) {
49494+ index = uid_set[i];
49495+ j = i;
49496+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
49497+ uid_set[j] = uid_set[j - 1];
49498+ j--;
49499+ }
49500+ uid_set[j] = index;
49501+ }
49502+
49503+ return;
49504+}
49505+
49506+static __inline__ void
49507+gr_insert_uid(const uid_t uid, const unsigned long expires)
49508+{
49509+ int loc;
49510+
49511+ if (uid_used == GR_UIDTABLE_MAX)
49512+ return;
49513+
49514+ loc = gr_find_uid(uid);
49515+
49516+ if (loc >= 0) {
49517+ uid_set[loc].expires = expires;
49518+ return;
49519+ }
49520+
49521+ uid_set[uid_used].uid = uid;
49522+ uid_set[uid_used].expires = expires;
49523+ uid_used++;
49524+
49525+ gr_insertsort();
49526+
49527+ return;
49528+}
49529+
49530+void
49531+gr_remove_uid(const unsigned short loc)
49532+{
49533+ unsigned short i;
49534+
49535+ for (i = loc + 1; i < uid_used; i++)
49536+ uid_set[i - 1] = uid_set[i];
49537+
49538+ uid_used--;
49539+
49540+ return;
49541+}
49542+
49543+int
49544+gr_check_crash_uid(const uid_t uid)
49545+{
49546+ int loc;
49547+ int ret = 0;
49548+
49549+ if (unlikely(!gr_acl_is_enabled()))
49550+ return 0;
49551+
49552+ spin_lock(&gr_uid_lock);
49553+ loc = gr_find_uid(uid);
49554+
49555+ if (loc < 0)
49556+ goto out_unlock;
49557+
49558+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
49559+ gr_remove_uid(loc);
49560+ else
49561+ ret = 1;
49562+
49563+out_unlock:
49564+ spin_unlock(&gr_uid_lock);
49565+ return ret;
49566+}
49567+
49568+static __inline__ int
49569+proc_is_setxid(const struct cred *cred)
49570+{
49571+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
49572+ cred->uid != cred->fsuid)
49573+ return 1;
49574+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
49575+ cred->gid != cred->fsgid)
49576+ return 1;
49577+
49578+ return 0;
49579+}
49580+
49581+extern int gr_fake_force_sig(int sig, struct task_struct *t);
49582+
49583+void
49584+gr_handle_crash(struct task_struct *task, const int sig)
49585+{
49586+ struct acl_subject_label *curr;
49587+ struct acl_subject_label *curr2;
49588+ struct task_struct *tsk, *tsk2;
49589+ const struct cred *cred;
49590+ const struct cred *cred2;
49591+
49592+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
49593+ return;
49594+
49595+ if (unlikely(!gr_acl_is_enabled()))
49596+ return;
49597+
49598+ curr = task->acl;
49599+
49600+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
49601+ return;
49602+
49603+ if (time_before_eq(curr->expires, get_seconds())) {
49604+ curr->expires = 0;
49605+ curr->crashes = 0;
49606+ }
49607+
49608+ curr->crashes++;
49609+
49610+ if (!curr->expires)
49611+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
49612+
49613+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
49614+ time_after(curr->expires, get_seconds())) {
49615+ rcu_read_lock();
49616+ cred = __task_cred(task);
49617+ if (cred->uid && proc_is_setxid(cred)) {
49618+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
49619+ spin_lock(&gr_uid_lock);
49620+ gr_insert_uid(cred->uid, curr->expires);
49621+ spin_unlock(&gr_uid_lock);
49622+ curr->expires = 0;
49623+ curr->crashes = 0;
49624+ read_lock(&tasklist_lock);
49625+ do_each_thread(tsk2, tsk) {
49626+ cred2 = __task_cred(tsk);
49627+ if (tsk != task && cred2->uid == cred->uid)
49628+ gr_fake_force_sig(SIGKILL, tsk);
49629+ } while_each_thread(tsk2, tsk);
49630+ read_unlock(&tasklist_lock);
49631+ } else {
49632+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
49633+ read_lock(&tasklist_lock);
49634+ do_each_thread(tsk2, tsk) {
49635+ if (likely(tsk != task)) {
49636+ curr2 = tsk->acl;
49637+
49638+ if (curr2->device == curr->device &&
49639+ curr2->inode == curr->inode)
49640+ gr_fake_force_sig(SIGKILL, tsk);
49641+ }
49642+ } while_each_thread(tsk2, tsk);
49643+ read_unlock(&tasklist_lock);
49644+ }
49645+ rcu_read_unlock();
49646+ }
49647+
49648+ return;
49649+}
49650+
49651+int
49652+gr_check_crash_exec(const struct file *filp)
49653+{
49654+ struct acl_subject_label *curr;
49655+
49656+ if (unlikely(!gr_acl_is_enabled()))
49657+ return 0;
49658+
49659+ read_lock(&gr_inode_lock);
49660+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
49661+ __get_dev(filp->f_path.dentry),
49662+ current->role);
49663+ read_unlock(&gr_inode_lock);
49664+
49665+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
49666+ (!curr->crashes && !curr->expires))
49667+ return 0;
49668+
49669+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
49670+ time_after(curr->expires, get_seconds()))
49671+ return 1;
49672+ else if (time_before_eq(curr->expires, get_seconds())) {
49673+ curr->crashes = 0;
49674+ curr->expires = 0;
49675+ }
49676+
49677+ return 0;
49678+}
49679+
49680+void
49681+gr_handle_alertkill(struct task_struct *task)
49682+{
49683+ struct acl_subject_label *curracl;
49684+ __u32 curr_ip;
49685+ struct task_struct *p, *p2;
49686+
49687+ if (unlikely(!gr_acl_is_enabled()))
49688+ return;
49689+
49690+ curracl = task->acl;
49691+ curr_ip = task->signal->curr_ip;
49692+
49693+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
49694+ read_lock(&tasklist_lock);
49695+ do_each_thread(p2, p) {
49696+ if (p->signal->curr_ip == curr_ip)
49697+ gr_fake_force_sig(SIGKILL, p);
49698+ } while_each_thread(p2, p);
49699+ read_unlock(&tasklist_lock);
49700+ } else if (curracl->mode & GR_KILLPROC)
49701+ gr_fake_force_sig(SIGKILL, task);
49702+
49703+ return;
49704+}
49705diff -urNp linux-3.0.4/grsecurity/gracl_shm.c linux-3.0.4/grsecurity/gracl_shm.c
49706--- linux-3.0.4/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
49707+++ linux-3.0.4/grsecurity/gracl_shm.c 2011-08-23 21:48:14.000000000 -0400
49708@@ -0,0 +1,40 @@
49709+#include <linux/kernel.h>
49710+#include <linux/mm.h>
49711+#include <linux/sched.h>
49712+#include <linux/file.h>
49713+#include <linux/ipc.h>
49714+#include <linux/gracl.h>
49715+#include <linux/grsecurity.h>
49716+#include <linux/grinternal.h>
49717+
49718+int
49719+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
49720+ const time_t shm_createtime, const uid_t cuid, const int shmid)
49721+{
49722+ struct task_struct *task;
49723+
49724+ if (!gr_acl_is_enabled())
49725+ return 1;
49726+
49727+ rcu_read_lock();
49728+ read_lock(&tasklist_lock);
49729+
49730+ task = find_task_by_vpid(shm_cprid);
49731+
49732+ if (unlikely(!task))
49733+ task = find_task_by_vpid(shm_lapid);
49734+
49735+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
49736+ (task->pid == shm_lapid)) &&
49737+ (task->acl->mode & GR_PROTSHM) &&
49738+ (task->acl != current->acl))) {
49739+ read_unlock(&tasklist_lock);
49740+ rcu_read_unlock();
49741+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
49742+ return 0;
49743+ }
49744+ read_unlock(&tasklist_lock);
49745+ rcu_read_unlock();
49746+
49747+ return 1;
49748+}
49749diff -urNp linux-3.0.4/grsecurity/grsec_chdir.c linux-3.0.4/grsecurity/grsec_chdir.c
49750--- linux-3.0.4/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
49751+++ linux-3.0.4/grsecurity/grsec_chdir.c 2011-08-23 21:48:14.000000000 -0400
49752@@ -0,0 +1,19 @@
49753+#include <linux/kernel.h>
49754+#include <linux/sched.h>
49755+#include <linux/fs.h>
49756+#include <linux/file.h>
49757+#include <linux/grsecurity.h>
49758+#include <linux/grinternal.h>
49759+
49760+void
49761+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
49762+{
49763+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
49764+ if ((grsec_enable_chdir && grsec_enable_group &&
49765+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
49766+ !grsec_enable_group)) {
49767+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
49768+ }
49769+#endif
49770+ return;
49771+}
49772diff -urNp linux-3.0.4/grsecurity/grsec_chroot.c linux-3.0.4/grsecurity/grsec_chroot.c
49773--- linux-3.0.4/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
49774+++ linux-3.0.4/grsecurity/grsec_chroot.c 2011-09-15 06:47:48.000000000 -0400
49775@@ -0,0 +1,351 @@
49776+#include <linux/kernel.h>
49777+#include <linux/module.h>
49778+#include <linux/sched.h>
49779+#include <linux/file.h>
49780+#include <linux/fs.h>
49781+#include <linux/mount.h>
49782+#include <linux/types.h>
49783+#include <linux/pid_namespace.h>
49784+#include <linux/grsecurity.h>
49785+#include <linux/grinternal.h>
49786+
49787+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
49788+{
49789+#ifdef CONFIG_GRKERNSEC
49790+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
49791+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
49792+ task->gr_is_chrooted = 1;
49793+ else
49794+ task->gr_is_chrooted = 0;
49795+
49796+ task->gr_chroot_dentry = path->dentry;
49797+#endif
49798+ return;
49799+}
49800+
49801+void gr_clear_chroot_entries(struct task_struct *task)
49802+{
49803+#ifdef CONFIG_GRKERNSEC
49804+ task->gr_is_chrooted = 0;
49805+ task->gr_chroot_dentry = NULL;
49806+#endif
49807+ return;
49808+}
49809+
49810+int
49811+gr_handle_chroot_unix(const pid_t pid)
49812+{
49813+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
49814+ struct task_struct *p;
49815+
49816+ if (unlikely(!grsec_enable_chroot_unix))
49817+ return 1;
49818+
49819+ if (likely(!proc_is_chrooted(current)))
49820+ return 1;
49821+
49822+ rcu_read_lock();
49823+ read_lock(&tasklist_lock);
49824+ p = find_task_by_vpid_unrestricted(pid);
49825+ if (unlikely(p && !have_same_root(current, p))) {
49826+ read_unlock(&tasklist_lock);
49827+ rcu_read_unlock();
49828+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
49829+ return 0;
49830+ }
49831+ read_unlock(&tasklist_lock);
49832+ rcu_read_unlock();
49833+#endif
49834+ return 1;
49835+}
49836+
49837+int
49838+gr_handle_chroot_nice(void)
49839+{
49840+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
49841+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
49842+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
49843+ return -EPERM;
49844+ }
49845+#endif
49846+ return 0;
49847+}
49848+
49849+int
49850+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
49851+{
49852+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
49853+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
49854+ && proc_is_chrooted(current)) {
49855+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
49856+ return -EACCES;
49857+ }
49858+#endif
49859+ return 0;
49860+}
49861+
49862+int
49863+gr_handle_chroot_rawio(const struct inode *inode)
49864+{
49865+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49866+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
49867+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
49868+ return 1;
49869+#endif
49870+ return 0;
49871+}
49872+
49873+int
49874+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
49875+{
49876+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
49877+ struct task_struct *p;
49878+ int ret = 0;
49879+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
49880+ return ret;
49881+
49882+ read_lock(&tasklist_lock);
49883+ do_each_pid_task(pid, type, p) {
49884+ if (!have_same_root(current, p)) {
49885+ ret = 1;
49886+ goto out;
49887+ }
49888+ } while_each_pid_task(pid, type, p);
49889+out:
49890+ read_unlock(&tasklist_lock);
49891+ return ret;
49892+#endif
49893+ return 0;
49894+}
49895+
49896+int
49897+gr_pid_is_chrooted(struct task_struct *p)
49898+{
49899+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
49900+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
49901+ return 0;
49902+
49903+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
49904+ !have_same_root(current, p)) {
49905+ return 1;
49906+ }
49907+#endif
49908+ return 0;
49909+}
49910+
49911+EXPORT_SYMBOL(gr_pid_is_chrooted);
49912+
49913+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
49914+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
49915+{
49916+ struct path path, currentroot;
49917+ int ret = 0;
49918+
49919+ path.dentry = (struct dentry *)u_dentry;
49920+ path.mnt = (struct vfsmount *)u_mnt;
49921+ get_fs_root(current->fs, &currentroot);
49922+ if (path_is_under(&path, &currentroot))
49923+ ret = 1;
49924+ path_put(&currentroot);
49925+
49926+ return ret;
49927+}
49928+#endif
49929+
49930+int
49931+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
49932+{
49933+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
49934+ if (!grsec_enable_chroot_fchdir)
49935+ return 1;
49936+
49937+ if (!proc_is_chrooted(current))
49938+ return 1;
49939+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
49940+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
49941+ return 0;
49942+ }
49943+#endif
49944+ return 1;
49945+}
49946+
49947+int
49948+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
49949+ const time_t shm_createtime)
49950+{
49951+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
49952+ struct task_struct *p;
49953+ time_t starttime;
49954+
49955+ if (unlikely(!grsec_enable_chroot_shmat))
49956+ return 1;
49957+
49958+ if (likely(!proc_is_chrooted(current)))
49959+ return 1;
49960+
49961+ rcu_read_lock();
49962+ read_lock(&tasklist_lock);
49963+
49964+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
49965+ starttime = p->start_time.tv_sec;
49966+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
49967+ if (have_same_root(current, p)) {
49968+ goto allow;
49969+ } else {
49970+ read_unlock(&tasklist_lock);
49971+ rcu_read_unlock();
49972+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
49973+ return 0;
49974+ }
49975+ }
49976+ /* creator exited, pid reuse, fall through to next check */
49977+ }
49978+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
49979+ if (unlikely(!have_same_root(current, p))) {
49980+ read_unlock(&tasklist_lock);
49981+ rcu_read_unlock();
49982+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
49983+ return 0;
49984+ }
49985+ }
49986+
49987+allow:
49988+ read_unlock(&tasklist_lock);
49989+ rcu_read_unlock();
49990+#endif
49991+ return 1;
49992+}
49993+
49994+void
49995+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
49996+{
49997+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
49998+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
49999+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
50000+#endif
50001+ return;
50002+}
50003+
50004+int
50005+gr_handle_chroot_mknod(const struct dentry *dentry,
50006+ const struct vfsmount *mnt, const int mode)
50007+{
50008+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
50009+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
50010+ proc_is_chrooted(current)) {
50011+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
50012+ return -EPERM;
50013+ }
50014+#endif
50015+ return 0;
50016+}
50017+
50018+int
50019+gr_handle_chroot_mount(const struct dentry *dentry,
50020+ const struct vfsmount *mnt, const char *dev_name)
50021+{
50022+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
50023+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
50024+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
50025+ return -EPERM;
50026+ }
50027+#endif
50028+ return 0;
50029+}
50030+
50031+int
50032+gr_handle_chroot_pivot(void)
50033+{
50034+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
50035+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
50036+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
50037+ return -EPERM;
50038+ }
50039+#endif
50040+ return 0;
50041+}
50042+
50043+int
50044+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
50045+{
50046+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
50047+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
50048+ !gr_is_outside_chroot(dentry, mnt)) {
50049+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
50050+ return -EPERM;
50051+ }
50052+#endif
50053+ return 0;
50054+}
50055+
50056+extern const char *captab_log[];
50057+extern int captab_log_entries;
50058+
50059+int
50060+gr_chroot_is_capable(const int cap)
50061+{
50062+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50063+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
50064+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
50065+ if (cap_raised(chroot_caps, cap)) {
50066+ const struct cred *creds = current_cred();
50067+ if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
50068+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
50069+ }
50070+ return 0;
50071+ }
50072+ }
50073+#endif
50074+ return 1;
50075+}
50076+
50077+int
50078+gr_chroot_is_capable_nolog(const int cap)
50079+{
50080+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50081+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
50082+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
50083+ if (cap_raised(chroot_caps, cap)) {
50084+ return 0;
50085+ }
50086+ }
50087+#endif
50088+ return 1;
50089+}
50090+
50091+int
50092+gr_handle_chroot_sysctl(const int op)
50093+{
50094+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
50095+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
50096+ proc_is_chrooted(current))
50097+ return -EACCES;
50098+#endif
50099+ return 0;
50100+}
50101+
50102+void
50103+gr_handle_chroot_chdir(struct path *path)
50104+{
50105+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
50106+ if (grsec_enable_chroot_chdir)
50107+ set_fs_pwd(current->fs, path);
50108+#endif
50109+ return;
50110+}
50111+
50112+int
50113+gr_handle_chroot_chmod(const struct dentry *dentry,
50114+ const struct vfsmount *mnt, const int mode)
50115+{
50116+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
50117+ /* allow chmod +s on directories, but not files */
50118+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
50119+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
50120+ proc_is_chrooted(current)) {
50121+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
50122+ return -EPERM;
50123+ }
50124+#endif
50125+ return 0;
50126+}
50127diff -urNp linux-3.0.4/grsecurity/grsec_disabled.c linux-3.0.4/grsecurity/grsec_disabled.c
50128--- linux-3.0.4/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
50129+++ linux-3.0.4/grsecurity/grsec_disabled.c 2011-08-23 21:48:14.000000000 -0400
50130@@ -0,0 +1,447 @@
50131+#include <linux/kernel.h>
50132+#include <linux/module.h>
50133+#include <linux/sched.h>
50134+#include <linux/file.h>
50135+#include <linux/fs.h>
50136+#include <linux/kdev_t.h>
50137+#include <linux/net.h>
50138+#include <linux/in.h>
50139+#include <linux/ip.h>
50140+#include <linux/skbuff.h>
50141+#include <linux/sysctl.h>
50142+
50143+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50144+void
50145+pax_set_initial_flags(struct linux_binprm *bprm)
50146+{
50147+ return;
50148+}
50149+#endif
50150+
50151+#ifdef CONFIG_SYSCTL
50152+__u32
50153+gr_handle_sysctl(const struct ctl_table * table, const int op)
50154+{
50155+ return 0;
50156+}
50157+#endif
50158+
50159+#ifdef CONFIG_TASKSTATS
50160+int gr_is_taskstats_denied(int pid)
50161+{
50162+ return 0;
50163+}
50164+#endif
50165+
50166+int
50167+gr_acl_is_enabled(void)
50168+{
50169+ return 0;
50170+}
50171+
50172+int
50173+gr_handle_rawio(const struct inode *inode)
50174+{
50175+ return 0;
50176+}
50177+
50178+void
50179+gr_acl_handle_psacct(struct task_struct *task, const long code)
50180+{
50181+ return;
50182+}
50183+
50184+int
50185+gr_handle_ptrace(struct task_struct *task, const long request)
50186+{
50187+ return 0;
50188+}
50189+
50190+int
50191+gr_handle_proc_ptrace(struct task_struct *task)
50192+{
50193+ return 0;
50194+}
50195+
50196+void
50197+gr_learn_resource(const struct task_struct *task,
50198+ const int res, const unsigned long wanted, const int gt)
50199+{
50200+ return;
50201+}
50202+
50203+int
50204+gr_set_acls(const int type)
50205+{
50206+ return 0;
50207+}
50208+
50209+int
50210+gr_check_hidden_task(const struct task_struct *tsk)
50211+{
50212+ return 0;
50213+}
50214+
50215+int
50216+gr_check_protected_task(const struct task_struct *task)
50217+{
50218+ return 0;
50219+}
50220+
50221+int
50222+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
50223+{
50224+ return 0;
50225+}
50226+
50227+void
50228+gr_copy_label(struct task_struct *tsk)
50229+{
50230+ return;
50231+}
50232+
50233+void
50234+gr_set_pax_flags(struct task_struct *task)
50235+{
50236+ return;
50237+}
50238+
50239+int
50240+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
50241+ const int unsafe_share)
50242+{
50243+ return 0;
50244+}
50245+
50246+void
50247+gr_handle_delete(const ino_t ino, const dev_t dev)
50248+{
50249+ return;
50250+}
50251+
50252+void
50253+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
50254+{
50255+ return;
50256+}
50257+
50258+void
50259+gr_handle_crash(struct task_struct *task, const int sig)
50260+{
50261+ return;
50262+}
50263+
50264+int
50265+gr_check_crash_exec(const struct file *filp)
50266+{
50267+ return 0;
50268+}
50269+
50270+int
50271+gr_check_crash_uid(const uid_t uid)
50272+{
50273+ return 0;
50274+}
50275+
50276+void
50277+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
50278+ struct dentry *old_dentry,
50279+ struct dentry *new_dentry,
50280+ struct vfsmount *mnt, const __u8 replace)
50281+{
50282+ return;
50283+}
50284+
50285+int
50286+gr_search_socket(const int family, const int type, const int protocol)
50287+{
50288+ return 1;
50289+}
50290+
50291+int
50292+gr_search_connectbind(const int mode, const struct socket *sock,
50293+ const struct sockaddr_in *addr)
50294+{
50295+ return 0;
50296+}
50297+
50298+int
50299+gr_is_capable(const int cap)
50300+{
50301+ return 1;
50302+}
50303+
50304+int
50305+gr_is_capable_nolog(const int cap)
50306+{
50307+ return 1;
50308+}
50309+
50310+void
50311+gr_handle_alertkill(struct task_struct *task)
50312+{
50313+ return;
50314+}
50315+
50316+__u32
50317+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
50318+{
50319+ return 1;
50320+}
50321+
50322+__u32
50323+gr_acl_handle_hidden_file(const struct dentry * dentry,
50324+ const struct vfsmount * mnt)
50325+{
50326+ return 1;
50327+}
50328+
50329+__u32
50330+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
50331+ const int fmode)
50332+{
50333+ return 1;
50334+}
50335+
50336+__u32
50337+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
50338+{
50339+ return 1;
50340+}
50341+
50342+__u32
50343+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
50344+{
50345+ return 1;
50346+}
50347+
50348+int
50349+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
50350+ unsigned int *vm_flags)
50351+{
50352+ return 1;
50353+}
50354+
50355+__u32
50356+gr_acl_handle_truncate(const struct dentry * dentry,
50357+ const struct vfsmount * mnt)
50358+{
50359+ return 1;
50360+}
50361+
50362+__u32
50363+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
50364+{
50365+ return 1;
50366+}
50367+
50368+__u32
50369+gr_acl_handle_access(const struct dentry * dentry,
50370+ const struct vfsmount * mnt, const int fmode)
50371+{
50372+ return 1;
50373+}
50374+
50375+__u32
50376+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
50377+ mode_t mode)
50378+{
50379+ return 1;
50380+}
50381+
50382+__u32
50383+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
50384+ mode_t mode)
50385+{
50386+ return 1;
50387+}
50388+
50389+__u32
50390+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
50391+{
50392+ return 1;
50393+}
50394+
50395+__u32
50396+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
50397+{
50398+ return 1;
50399+}
50400+
50401+void
50402+grsecurity_init(void)
50403+{
50404+ return;
50405+}
50406+
50407+__u32
50408+gr_acl_handle_mknod(const struct dentry * new_dentry,
50409+ const struct dentry * parent_dentry,
50410+ const struct vfsmount * parent_mnt,
50411+ const int mode)
50412+{
50413+ return 1;
50414+}
50415+
50416+__u32
50417+gr_acl_handle_mkdir(const struct dentry * new_dentry,
50418+ const struct dentry * parent_dentry,
50419+ const struct vfsmount * parent_mnt)
50420+{
50421+ return 1;
50422+}
50423+
50424+__u32
50425+gr_acl_handle_symlink(const struct dentry * new_dentry,
50426+ const struct dentry * parent_dentry,
50427+ const struct vfsmount * parent_mnt, const char *from)
50428+{
50429+ return 1;
50430+}
50431+
50432+__u32
50433+gr_acl_handle_link(const struct dentry * new_dentry,
50434+ const struct dentry * parent_dentry,
50435+ const struct vfsmount * parent_mnt,
50436+ const struct dentry * old_dentry,
50437+ const struct vfsmount * old_mnt, const char *to)
50438+{
50439+ return 1;
50440+}
50441+
50442+int
50443+gr_acl_handle_rename(const struct dentry *new_dentry,
50444+ const struct dentry *parent_dentry,
50445+ const struct vfsmount *parent_mnt,
50446+ const struct dentry *old_dentry,
50447+ const struct inode *old_parent_inode,
50448+ const struct vfsmount *old_mnt, const char *newname)
50449+{
50450+ return 0;
50451+}
50452+
50453+int
50454+gr_acl_handle_filldir(const struct file *file, const char *name,
50455+ const int namelen, const ino_t ino)
50456+{
50457+ return 1;
50458+}
50459+
50460+int
50461+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
50462+ const time_t shm_createtime, const uid_t cuid, const int shmid)
50463+{
50464+ return 1;
50465+}
50466+
50467+int
50468+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
50469+{
50470+ return 0;
50471+}
50472+
50473+int
50474+gr_search_accept(const struct socket *sock)
50475+{
50476+ return 0;
50477+}
50478+
50479+int
50480+gr_search_listen(const struct socket *sock)
50481+{
50482+ return 0;
50483+}
50484+
50485+int
50486+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
50487+{
50488+ return 0;
50489+}
50490+
50491+__u32
50492+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
50493+{
50494+ return 1;
50495+}
50496+
50497+__u32
50498+gr_acl_handle_creat(const struct dentry * dentry,
50499+ const struct dentry * p_dentry,
50500+ const struct vfsmount * p_mnt, const int fmode,
50501+ const int imode)
50502+{
50503+ return 1;
50504+}
50505+
50506+void
50507+gr_acl_handle_exit(void)
50508+{
50509+ return;
50510+}
50511+
50512+int
50513+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
50514+{
50515+ return 1;
50516+}
50517+
50518+void
50519+gr_set_role_label(const uid_t uid, const gid_t gid)
50520+{
50521+ return;
50522+}
50523+
50524+int
50525+gr_acl_handle_procpidmem(const struct task_struct *task)
50526+{
50527+ return 0;
50528+}
50529+
50530+int
50531+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
50532+{
50533+ return 0;
50534+}
50535+
50536+int
50537+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
50538+{
50539+ return 0;
50540+}
50541+
50542+void
50543+gr_set_kernel_label(struct task_struct *task)
50544+{
50545+ return;
50546+}
50547+
50548+int
50549+gr_check_user_change(int real, int effective, int fs)
50550+{
50551+ return 0;
50552+}
50553+
50554+int
50555+gr_check_group_change(int real, int effective, int fs)
50556+{
50557+ return 0;
50558+}
50559+
50560+int gr_acl_enable_at_secure(void)
50561+{
50562+ return 0;
50563+}
50564+
50565+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50566+{
50567+ return dentry->d_inode->i_sb->s_dev;
50568+}
50569+
50570+EXPORT_SYMBOL(gr_is_capable);
50571+EXPORT_SYMBOL(gr_is_capable_nolog);
50572+EXPORT_SYMBOL(gr_learn_resource);
50573+EXPORT_SYMBOL(gr_set_kernel_label);
50574+#ifdef CONFIG_SECURITY
50575+EXPORT_SYMBOL(gr_check_user_change);
50576+EXPORT_SYMBOL(gr_check_group_change);
50577+#endif
50578diff -urNp linux-3.0.4/grsecurity/grsec_exec.c linux-3.0.4/grsecurity/grsec_exec.c
50579--- linux-3.0.4/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
50580+++ linux-3.0.4/grsecurity/grsec_exec.c 2011-09-14 09:20:28.000000000 -0400
50581@@ -0,0 +1,145 @@
50582+#include <linux/kernel.h>
50583+#include <linux/sched.h>
50584+#include <linux/file.h>
50585+#include <linux/binfmts.h>
50586+#include <linux/fs.h>
50587+#include <linux/types.h>
50588+#include <linux/grdefs.h>
50589+#include <linux/grsecurity.h>
50590+#include <linux/grinternal.h>
50591+#include <linux/capability.h>
50592+#include <linux/module.h>
50593+
50594+#include <asm/uaccess.h>
50595+
50596+#ifdef CONFIG_GRKERNSEC_EXECLOG
50597+static char gr_exec_arg_buf[132];
50598+static DEFINE_MUTEX(gr_exec_arg_mutex);
50599+#endif
50600+
50601+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
50602+
50603+void
50604+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
50605+{
50606+#ifdef CONFIG_GRKERNSEC_EXECLOG
50607+ char *grarg = gr_exec_arg_buf;
50608+ unsigned int i, x, execlen = 0;
50609+ char c;
50610+
50611+ if (!((grsec_enable_execlog && grsec_enable_group &&
50612+ in_group_p(grsec_audit_gid))
50613+ || (grsec_enable_execlog && !grsec_enable_group)))
50614+ return;
50615+
50616+ mutex_lock(&gr_exec_arg_mutex);
50617+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
50618+
50619+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
50620+ const char __user *p;
50621+ unsigned int len;
50622+
50623+ p = get_user_arg_ptr(argv, i);
50624+ if (IS_ERR(p))
50625+ goto log;
50626+
50627+ len = strnlen_user(p, 128 - execlen);
50628+ if (len > 128 - execlen)
50629+ len = 128 - execlen;
50630+ else if (len > 0)
50631+ len--;
50632+ if (copy_from_user(grarg + execlen, p, len))
50633+ goto log;
50634+
50635+ /* rewrite unprintable characters */
50636+ for (x = 0; x < len; x++) {
50637+ c = *(grarg + execlen + x);
50638+ if (c < 32 || c > 126)
50639+ *(grarg + execlen + x) = ' ';
50640+ }
50641+
50642+ execlen += len;
50643+ *(grarg + execlen) = ' ';
50644+ *(grarg + execlen + 1) = '\0';
50645+ execlen++;
50646+ }
50647+
50648+ log:
50649+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
50650+ bprm->file->f_path.mnt, grarg);
50651+ mutex_unlock(&gr_exec_arg_mutex);
50652+#endif
50653+ return;
50654+}
50655+
50656+#ifdef CONFIG_GRKERNSEC
50657+extern int gr_acl_is_capable(const int cap);
50658+extern int gr_acl_is_capable_nolog(const int cap);
50659+extern int gr_chroot_is_capable(const int cap);
50660+extern int gr_chroot_is_capable_nolog(const int cap);
50661+#endif
50662+
50663+const char *captab_log[] = {
50664+ "CAP_CHOWN",
50665+ "CAP_DAC_OVERRIDE",
50666+ "CAP_DAC_READ_SEARCH",
50667+ "CAP_FOWNER",
50668+ "CAP_FSETID",
50669+ "CAP_KILL",
50670+ "CAP_SETGID",
50671+ "CAP_SETUID",
50672+ "CAP_SETPCAP",
50673+ "CAP_LINUX_IMMUTABLE",
50674+ "CAP_NET_BIND_SERVICE",
50675+ "CAP_NET_BROADCAST",
50676+ "CAP_NET_ADMIN",
50677+ "CAP_NET_RAW",
50678+ "CAP_IPC_LOCK",
50679+ "CAP_IPC_OWNER",
50680+ "CAP_SYS_MODULE",
50681+ "CAP_SYS_RAWIO",
50682+ "CAP_SYS_CHROOT",
50683+ "CAP_SYS_PTRACE",
50684+ "CAP_SYS_PACCT",
50685+ "CAP_SYS_ADMIN",
50686+ "CAP_SYS_BOOT",
50687+ "CAP_SYS_NICE",
50688+ "CAP_SYS_RESOURCE",
50689+ "CAP_SYS_TIME",
50690+ "CAP_SYS_TTY_CONFIG",
50691+ "CAP_MKNOD",
50692+ "CAP_LEASE",
50693+ "CAP_AUDIT_WRITE",
50694+ "CAP_AUDIT_CONTROL",
50695+ "CAP_SETFCAP",
50696+ "CAP_MAC_OVERRIDE",
50697+ "CAP_MAC_ADMIN",
50698+ "CAP_SYSLOG"
50699+};
50700+
50701+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
50702+
50703+int gr_is_capable(const int cap)
50704+{
50705+#ifdef CONFIG_GRKERNSEC
50706+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
50707+ return 1;
50708+ return 0;
50709+#else
50710+ return 1;
50711+#endif
50712+}
50713+
50714+int gr_is_capable_nolog(const int cap)
50715+{
50716+#ifdef CONFIG_GRKERNSEC
50717+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
50718+ return 1;
50719+ return 0;
50720+#else
50721+ return 1;
50722+#endif
50723+}
50724+
50725+EXPORT_SYMBOL(gr_is_capable);
50726+EXPORT_SYMBOL(gr_is_capable_nolog);
50727diff -urNp linux-3.0.4/grsecurity/grsec_fifo.c linux-3.0.4/grsecurity/grsec_fifo.c
50728--- linux-3.0.4/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
50729+++ linux-3.0.4/grsecurity/grsec_fifo.c 2011-08-23 21:48:14.000000000 -0400
50730@@ -0,0 +1,24 @@
50731+#include <linux/kernel.h>
50732+#include <linux/sched.h>
50733+#include <linux/fs.h>
50734+#include <linux/file.h>
50735+#include <linux/grinternal.h>
50736+
50737+int
50738+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
50739+ const struct dentry *dir, const int flag, const int acc_mode)
50740+{
50741+#ifdef CONFIG_GRKERNSEC_FIFO
50742+ const struct cred *cred = current_cred();
50743+
50744+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
50745+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
50746+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
50747+ (cred->fsuid != dentry->d_inode->i_uid)) {
50748+ if (!inode_permission(dentry->d_inode, acc_mode))
50749+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
50750+ return -EACCES;
50751+ }
50752+#endif
50753+ return 0;
50754+}
50755diff -urNp linux-3.0.4/grsecurity/grsec_fork.c linux-3.0.4/grsecurity/grsec_fork.c
50756--- linux-3.0.4/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
50757+++ linux-3.0.4/grsecurity/grsec_fork.c 2011-08-23 21:48:14.000000000 -0400
50758@@ -0,0 +1,23 @@
50759+#include <linux/kernel.h>
50760+#include <linux/sched.h>
50761+#include <linux/grsecurity.h>
50762+#include <linux/grinternal.h>
50763+#include <linux/errno.h>
50764+
50765+void
50766+gr_log_forkfail(const int retval)
50767+{
50768+#ifdef CONFIG_GRKERNSEC_FORKFAIL
50769+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
50770+ switch (retval) {
50771+ case -EAGAIN:
50772+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
50773+ break;
50774+ case -ENOMEM:
50775+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
50776+ break;
50777+ }
50778+ }
50779+#endif
50780+ return;
50781+}
50782diff -urNp linux-3.0.4/grsecurity/grsec_init.c linux-3.0.4/grsecurity/grsec_init.c
50783--- linux-3.0.4/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
50784+++ linux-3.0.4/grsecurity/grsec_init.c 2011-08-25 17:25:12.000000000 -0400
50785@@ -0,0 +1,269 @@
50786+#include <linux/kernel.h>
50787+#include <linux/sched.h>
50788+#include <linux/mm.h>
50789+#include <linux/gracl.h>
50790+#include <linux/slab.h>
50791+#include <linux/vmalloc.h>
50792+#include <linux/percpu.h>
50793+#include <linux/module.h>
50794+
50795+int grsec_enable_brute;
50796+int grsec_enable_link;
50797+int grsec_enable_dmesg;
50798+int grsec_enable_harden_ptrace;
50799+int grsec_enable_fifo;
50800+int grsec_enable_execlog;
50801+int grsec_enable_signal;
50802+int grsec_enable_forkfail;
50803+int grsec_enable_audit_ptrace;
50804+int grsec_enable_time;
50805+int grsec_enable_audit_textrel;
50806+int grsec_enable_group;
50807+int grsec_audit_gid;
50808+int grsec_enable_chdir;
50809+int grsec_enable_mount;
50810+int grsec_enable_rofs;
50811+int grsec_enable_chroot_findtask;
50812+int grsec_enable_chroot_mount;
50813+int grsec_enable_chroot_shmat;
50814+int grsec_enable_chroot_fchdir;
50815+int grsec_enable_chroot_double;
50816+int grsec_enable_chroot_pivot;
50817+int grsec_enable_chroot_chdir;
50818+int grsec_enable_chroot_chmod;
50819+int grsec_enable_chroot_mknod;
50820+int grsec_enable_chroot_nice;
50821+int grsec_enable_chroot_execlog;
50822+int grsec_enable_chroot_caps;
50823+int grsec_enable_chroot_sysctl;
50824+int grsec_enable_chroot_unix;
50825+int grsec_enable_tpe;
50826+int grsec_tpe_gid;
50827+int grsec_enable_blackhole;
50828+#ifdef CONFIG_IPV6_MODULE
50829+EXPORT_SYMBOL(grsec_enable_blackhole);
50830+#endif
50831+int grsec_lastack_retries;
50832+int grsec_enable_tpe_all;
50833+int grsec_enable_tpe_invert;
50834+int grsec_enable_socket_all;
50835+int grsec_socket_all_gid;
50836+int grsec_enable_socket_client;
50837+int grsec_socket_client_gid;
50838+int grsec_enable_socket_server;
50839+int grsec_socket_server_gid;
50840+int grsec_resource_logging;
50841+int grsec_disable_privio;
50842+int grsec_enable_log_rwxmaps;
50843+int grsec_lock;
50844+
50845+DEFINE_SPINLOCK(grsec_alert_lock);
50846+unsigned long grsec_alert_wtime = 0;
50847+unsigned long grsec_alert_fyet = 0;
50848+
50849+DEFINE_SPINLOCK(grsec_audit_lock);
50850+
50851+DEFINE_RWLOCK(grsec_exec_file_lock);
50852+
50853+char *gr_shared_page[4];
50854+
50855+char *gr_alert_log_fmt;
50856+char *gr_audit_log_fmt;
50857+char *gr_alert_log_buf;
50858+char *gr_audit_log_buf;
50859+
50860+extern struct gr_arg *gr_usermode;
50861+extern unsigned char *gr_system_salt;
50862+extern unsigned char *gr_system_sum;
50863+
50864+void __init
50865+grsecurity_init(void)
50866+{
50867+ int j;
50868+ /* create the per-cpu shared pages */
50869+
50870+#ifdef CONFIG_X86
50871+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
50872+#endif
50873+
50874+ for (j = 0; j < 4; j++) {
50875+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
50876+ if (gr_shared_page[j] == NULL) {
50877+ panic("Unable to allocate grsecurity shared page");
50878+ return;
50879+ }
50880+ }
50881+
50882+ /* allocate log buffers */
50883+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
50884+ if (!gr_alert_log_fmt) {
50885+ panic("Unable to allocate grsecurity alert log format buffer");
50886+ return;
50887+ }
50888+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
50889+ if (!gr_audit_log_fmt) {
50890+ panic("Unable to allocate grsecurity audit log format buffer");
50891+ return;
50892+ }
50893+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
50894+ if (!gr_alert_log_buf) {
50895+ panic("Unable to allocate grsecurity alert log buffer");
50896+ return;
50897+ }
50898+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
50899+ if (!gr_audit_log_buf) {
50900+ panic("Unable to allocate grsecurity audit log buffer");
50901+ return;
50902+ }
50903+
50904+ /* allocate memory for authentication structure */
50905+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
50906+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
50907+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
50908+
50909+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
50910+ panic("Unable to allocate grsecurity authentication structure");
50911+ return;
50912+ }
50913+
50914+
50915+#ifdef CONFIG_GRKERNSEC_IO
50916+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
50917+ grsec_disable_privio = 1;
50918+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
50919+ grsec_disable_privio = 1;
50920+#else
50921+ grsec_disable_privio = 0;
50922+#endif
50923+#endif
50924+
50925+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
50926+ /* for backward compatibility, tpe_invert always defaults to on if
50927+ enabled in the kernel
50928+ */
50929+ grsec_enable_tpe_invert = 1;
50930+#endif
50931+
50932+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
50933+#ifndef CONFIG_GRKERNSEC_SYSCTL
50934+ grsec_lock = 1;
50935+#endif
50936+
50937+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
50938+ grsec_enable_audit_textrel = 1;
50939+#endif
50940+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
50941+ grsec_enable_log_rwxmaps = 1;
50942+#endif
50943+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
50944+ grsec_enable_group = 1;
50945+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
50946+#endif
50947+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
50948+ grsec_enable_chdir = 1;
50949+#endif
50950+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
50951+ grsec_enable_harden_ptrace = 1;
50952+#endif
50953+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
50954+ grsec_enable_mount = 1;
50955+#endif
50956+#ifdef CONFIG_GRKERNSEC_LINK
50957+ grsec_enable_link = 1;
50958+#endif
50959+#ifdef CONFIG_GRKERNSEC_BRUTE
50960+ grsec_enable_brute = 1;
50961+#endif
50962+#ifdef CONFIG_GRKERNSEC_DMESG
50963+ grsec_enable_dmesg = 1;
50964+#endif
50965+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
50966+ grsec_enable_blackhole = 1;
50967+ grsec_lastack_retries = 4;
50968+#endif
50969+#ifdef CONFIG_GRKERNSEC_FIFO
50970+ grsec_enable_fifo = 1;
50971+#endif
50972+#ifdef CONFIG_GRKERNSEC_EXECLOG
50973+ grsec_enable_execlog = 1;
50974+#endif
50975+#ifdef CONFIG_GRKERNSEC_SIGNAL
50976+ grsec_enable_signal = 1;
50977+#endif
50978+#ifdef CONFIG_GRKERNSEC_FORKFAIL
50979+ grsec_enable_forkfail = 1;
50980+#endif
50981+#ifdef CONFIG_GRKERNSEC_TIME
50982+ grsec_enable_time = 1;
50983+#endif
50984+#ifdef CONFIG_GRKERNSEC_RESLOG
50985+ grsec_resource_logging = 1;
50986+#endif
50987+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
50988+ grsec_enable_chroot_findtask = 1;
50989+#endif
50990+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
50991+ grsec_enable_chroot_unix = 1;
50992+#endif
50993+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
50994+ grsec_enable_chroot_mount = 1;
50995+#endif
50996+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
50997+ grsec_enable_chroot_fchdir = 1;
50998+#endif
50999+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
51000+ grsec_enable_chroot_shmat = 1;
51001+#endif
51002+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
51003+ grsec_enable_audit_ptrace = 1;
51004+#endif
51005+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
51006+ grsec_enable_chroot_double = 1;
51007+#endif
51008+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
51009+ grsec_enable_chroot_pivot = 1;
51010+#endif
51011+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
51012+ grsec_enable_chroot_chdir = 1;
51013+#endif
51014+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
51015+ grsec_enable_chroot_chmod = 1;
51016+#endif
51017+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
51018+ grsec_enable_chroot_mknod = 1;
51019+#endif
51020+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
51021+ grsec_enable_chroot_nice = 1;
51022+#endif
51023+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
51024+ grsec_enable_chroot_execlog = 1;
51025+#endif
51026+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51027+ grsec_enable_chroot_caps = 1;
51028+#endif
51029+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
51030+ grsec_enable_chroot_sysctl = 1;
51031+#endif
51032+#ifdef CONFIG_GRKERNSEC_TPE
51033+ grsec_enable_tpe = 1;
51034+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
51035+#ifdef CONFIG_GRKERNSEC_TPE_ALL
51036+ grsec_enable_tpe_all = 1;
51037+#endif
51038+#endif
51039+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
51040+ grsec_enable_socket_all = 1;
51041+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
51042+#endif
51043+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
51044+ grsec_enable_socket_client = 1;
51045+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
51046+#endif
51047+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51048+ grsec_enable_socket_server = 1;
51049+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
51050+#endif
51051+#endif
51052+
51053+ return;
51054+}
51055diff -urNp linux-3.0.4/grsecurity/grsec_link.c linux-3.0.4/grsecurity/grsec_link.c
51056--- linux-3.0.4/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
51057+++ linux-3.0.4/grsecurity/grsec_link.c 2011-08-23 21:48:14.000000000 -0400
51058@@ -0,0 +1,43 @@
51059+#include <linux/kernel.h>
51060+#include <linux/sched.h>
51061+#include <linux/fs.h>
51062+#include <linux/file.h>
51063+#include <linux/grinternal.h>
51064+
51065+int
51066+gr_handle_follow_link(const struct inode *parent,
51067+ const struct inode *inode,
51068+ const struct dentry *dentry, const struct vfsmount *mnt)
51069+{
51070+#ifdef CONFIG_GRKERNSEC_LINK
51071+ const struct cred *cred = current_cred();
51072+
51073+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
51074+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
51075+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
51076+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
51077+ return -EACCES;
51078+ }
51079+#endif
51080+ return 0;
51081+}
51082+
51083+int
51084+gr_handle_hardlink(const struct dentry *dentry,
51085+ const struct vfsmount *mnt,
51086+ struct inode *inode, const int mode, const char *to)
51087+{
51088+#ifdef CONFIG_GRKERNSEC_LINK
51089+ const struct cred *cred = current_cred();
51090+
51091+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
51092+ (!S_ISREG(mode) || (mode & S_ISUID) ||
51093+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
51094+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
51095+ !capable(CAP_FOWNER) && cred->uid) {
51096+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
51097+ return -EPERM;
51098+ }
51099+#endif
51100+ return 0;
51101+}
51102diff -urNp linux-3.0.4/grsecurity/grsec_log.c linux-3.0.4/grsecurity/grsec_log.c
51103--- linux-3.0.4/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
51104+++ linux-3.0.4/grsecurity/grsec_log.c 2011-09-14 23:17:55.000000000 -0400
51105@@ -0,0 +1,313 @@
51106+#include <linux/kernel.h>
51107+#include <linux/sched.h>
51108+#include <linux/file.h>
51109+#include <linux/tty.h>
51110+#include <linux/fs.h>
51111+#include <linux/grinternal.h>
51112+
51113+#ifdef CONFIG_TREE_PREEMPT_RCU
51114+#define DISABLE_PREEMPT() preempt_disable()
51115+#define ENABLE_PREEMPT() preempt_enable()
51116+#else
51117+#define DISABLE_PREEMPT()
51118+#define ENABLE_PREEMPT()
51119+#endif
51120+
51121+#define BEGIN_LOCKS(x) \
51122+ DISABLE_PREEMPT(); \
51123+ rcu_read_lock(); \
51124+ read_lock(&tasklist_lock); \
51125+ read_lock(&grsec_exec_file_lock); \
51126+ if (x != GR_DO_AUDIT) \
51127+ spin_lock(&grsec_alert_lock); \
51128+ else \
51129+ spin_lock(&grsec_audit_lock)
51130+
51131+#define END_LOCKS(x) \
51132+ if (x != GR_DO_AUDIT) \
51133+ spin_unlock(&grsec_alert_lock); \
51134+ else \
51135+ spin_unlock(&grsec_audit_lock); \
51136+ read_unlock(&grsec_exec_file_lock); \
51137+ read_unlock(&tasklist_lock); \
51138+ rcu_read_unlock(); \
51139+ ENABLE_PREEMPT(); \
51140+ if (x == GR_DONT_AUDIT) \
51141+ gr_handle_alertkill(current)
51142+
51143+enum {
51144+ FLOODING,
51145+ NO_FLOODING
51146+};
51147+
51148+extern char *gr_alert_log_fmt;
51149+extern char *gr_audit_log_fmt;
51150+extern char *gr_alert_log_buf;
51151+extern char *gr_audit_log_buf;
51152+
51153+static int gr_log_start(int audit)
51154+{
51155+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
51156+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
51157+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51158+ unsigned long curr_secs = get_seconds();
51159+
51160+ if (audit == GR_DO_AUDIT)
51161+ goto set_fmt;
51162+
51163+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
51164+ grsec_alert_wtime = curr_secs;
51165+ grsec_alert_fyet = 0;
51166+ } else if (time_before(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
51167+ if (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST) {
51168+ grsec_alert_fyet++;
51169+ } else if (grsec_alert_fyet && grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
51170+ grsec_alert_wtime = curr_secs;
51171+ grsec_alert_fyet++;
51172+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
51173+ return FLOODING;
51174+ }
51175+ } else return FLOODING;
51176+
51177+set_fmt:
51178+ memset(buf, 0, PAGE_SIZE);
51179+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
51180+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
51181+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
51182+ } else if (current->signal->curr_ip) {
51183+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
51184+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
51185+ } else if (gr_acl_is_enabled()) {
51186+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
51187+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
51188+ } else {
51189+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
51190+ strcpy(buf, fmt);
51191+ }
51192+
51193+ return NO_FLOODING;
51194+}
51195+
51196+static void gr_log_middle(int audit, const char *msg, va_list ap)
51197+ __attribute__ ((format (printf, 2, 0)));
51198+
51199+static void gr_log_middle(int audit, const char *msg, va_list ap)
51200+{
51201+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51202+ unsigned int len = strlen(buf);
51203+
51204+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
51205+
51206+ return;
51207+}
51208+
51209+static void gr_log_middle_varargs(int audit, const char *msg, ...)
51210+ __attribute__ ((format (printf, 2, 3)));
51211+
51212+static void gr_log_middle_varargs(int audit, const char *msg, ...)
51213+{
51214+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51215+ unsigned int len = strlen(buf);
51216+ va_list ap;
51217+
51218+ va_start(ap, msg);
51219+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
51220+ va_end(ap);
51221+
51222+ return;
51223+}
51224+
51225+static void gr_log_end(int audit)
51226+{
51227+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
51228+ unsigned int len = strlen(buf);
51229+
51230+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
51231+ printk("%s\n", buf);
51232+
51233+ return;
51234+}
51235+
51236+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
51237+{
51238+ int logtype;
51239+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
51240+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
51241+ void *voidptr = NULL;
51242+ int num1 = 0, num2 = 0;
51243+ unsigned long ulong1 = 0, ulong2 = 0;
51244+ struct dentry *dentry = NULL;
51245+ struct vfsmount *mnt = NULL;
51246+ struct file *file = NULL;
51247+ struct task_struct *task = NULL;
51248+ const struct cred *cred, *pcred;
51249+ va_list ap;
51250+
51251+ BEGIN_LOCKS(audit);
51252+ logtype = gr_log_start(audit);
51253+ if (logtype == FLOODING) {
51254+ END_LOCKS(audit);
51255+ return;
51256+ }
51257+ va_start(ap, argtypes);
51258+ switch (argtypes) {
51259+ case GR_TTYSNIFF:
51260+ task = va_arg(ap, struct task_struct *);
51261+ 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);
51262+ break;
51263+ case GR_SYSCTL_HIDDEN:
51264+ str1 = va_arg(ap, char *);
51265+ gr_log_middle_varargs(audit, msg, result, str1);
51266+ break;
51267+ case GR_RBAC:
51268+ dentry = va_arg(ap, struct dentry *);
51269+ mnt = va_arg(ap, struct vfsmount *);
51270+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
51271+ break;
51272+ case GR_RBAC_STR:
51273+ dentry = va_arg(ap, struct dentry *);
51274+ mnt = va_arg(ap, struct vfsmount *);
51275+ str1 = va_arg(ap, char *);
51276+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
51277+ break;
51278+ case GR_STR_RBAC:
51279+ str1 = va_arg(ap, char *);
51280+ dentry = va_arg(ap, struct dentry *);
51281+ mnt = va_arg(ap, struct vfsmount *);
51282+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
51283+ break;
51284+ case GR_RBAC_MODE2:
51285+ dentry = va_arg(ap, struct dentry *);
51286+ mnt = va_arg(ap, struct vfsmount *);
51287+ str1 = va_arg(ap, char *);
51288+ str2 = va_arg(ap, char *);
51289+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
51290+ break;
51291+ case GR_RBAC_MODE3:
51292+ dentry = va_arg(ap, struct dentry *);
51293+ mnt = va_arg(ap, struct vfsmount *);
51294+ str1 = va_arg(ap, char *);
51295+ str2 = va_arg(ap, char *);
51296+ str3 = va_arg(ap, char *);
51297+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
51298+ break;
51299+ case GR_FILENAME:
51300+ dentry = va_arg(ap, struct dentry *);
51301+ mnt = va_arg(ap, struct vfsmount *);
51302+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
51303+ break;
51304+ case GR_STR_FILENAME:
51305+ str1 = va_arg(ap, char *);
51306+ dentry = va_arg(ap, struct dentry *);
51307+ mnt = va_arg(ap, struct vfsmount *);
51308+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
51309+ break;
51310+ case GR_FILENAME_STR:
51311+ dentry = va_arg(ap, struct dentry *);
51312+ mnt = va_arg(ap, struct vfsmount *);
51313+ str1 = va_arg(ap, char *);
51314+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
51315+ break;
51316+ case GR_FILENAME_TWO_INT:
51317+ dentry = va_arg(ap, struct dentry *);
51318+ mnt = va_arg(ap, struct vfsmount *);
51319+ num1 = va_arg(ap, int);
51320+ num2 = va_arg(ap, int);
51321+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
51322+ break;
51323+ case GR_FILENAME_TWO_INT_STR:
51324+ dentry = va_arg(ap, struct dentry *);
51325+ mnt = va_arg(ap, struct vfsmount *);
51326+ num1 = va_arg(ap, int);
51327+ num2 = va_arg(ap, int);
51328+ str1 = va_arg(ap, char *);
51329+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
51330+ break;
51331+ case GR_TEXTREL:
51332+ file = va_arg(ap, struct file *);
51333+ ulong1 = va_arg(ap, unsigned long);
51334+ ulong2 = va_arg(ap, unsigned long);
51335+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
51336+ break;
51337+ case GR_PTRACE:
51338+ task = va_arg(ap, struct task_struct *);
51339+ 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);
51340+ break;
51341+ case GR_RESOURCE:
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+ str1 = va_arg(ap, char *);
51347+ ulong2 = va_arg(ap, unsigned long);
51348+ 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);
51349+ break;
51350+ case GR_CAP:
51351+ task = va_arg(ap, struct task_struct *);
51352+ cred = __task_cred(task);
51353+ pcred = __task_cred(task->real_parent);
51354+ str1 = va_arg(ap, char *);
51355+ 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);
51356+ break;
51357+ case GR_SIG:
51358+ str1 = va_arg(ap, char *);
51359+ voidptr = va_arg(ap, void *);
51360+ gr_log_middle_varargs(audit, msg, str1, voidptr);
51361+ break;
51362+ case GR_SIG2:
51363+ task = va_arg(ap, struct task_struct *);
51364+ cred = __task_cred(task);
51365+ pcred = __task_cred(task->real_parent);
51366+ num1 = va_arg(ap, int);
51367+ 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);
51368+ break;
51369+ case GR_CRASH1:
51370+ task = va_arg(ap, struct task_struct *);
51371+ cred = __task_cred(task);
51372+ pcred = __task_cred(task->real_parent);
51373+ ulong1 = va_arg(ap, unsigned long);
51374+ 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);
51375+ break;
51376+ case GR_CRASH2:
51377+ task = va_arg(ap, struct task_struct *);
51378+ cred = __task_cred(task);
51379+ pcred = __task_cred(task->real_parent);
51380+ ulong1 = va_arg(ap, unsigned long);
51381+ 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);
51382+ break;
51383+ case GR_RWXMAP:
51384+ file = va_arg(ap, struct file *);
51385+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
51386+ break;
51387+ case GR_PSACCT:
51388+ {
51389+ unsigned int wday, cday;
51390+ __u8 whr, chr;
51391+ __u8 wmin, cmin;
51392+ __u8 wsec, csec;
51393+ char cur_tty[64] = { 0 };
51394+ char parent_tty[64] = { 0 };
51395+
51396+ task = va_arg(ap, struct task_struct *);
51397+ wday = va_arg(ap, unsigned int);
51398+ cday = va_arg(ap, unsigned int);
51399+ whr = va_arg(ap, int);
51400+ chr = va_arg(ap, int);
51401+ wmin = va_arg(ap, int);
51402+ cmin = va_arg(ap, int);
51403+ wsec = va_arg(ap, int);
51404+ csec = va_arg(ap, int);
51405+ ulong1 = va_arg(ap, unsigned long);
51406+ cred = __task_cred(task);
51407+ pcred = __task_cred(task->real_parent);
51408+
51409+ 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);
51410+ }
51411+ break;
51412+ default:
51413+ gr_log_middle(audit, msg, ap);
51414+ }
51415+ va_end(ap);
51416+ gr_log_end(audit);
51417+ END_LOCKS(audit);
51418+}
51419diff -urNp linux-3.0.4/grsecurity/grsec_mem.c linux-3.0.4/grsecurity/grsec_mem.c
51420--- linux-3.0.4/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
51421+++ linux-3.0.4/grsecurity/grsec_mem.c 2011-08-23 21:48:14.000000000 -0400
51422@@ -0,0 +1,33 @@
51423+#include <linux/kernel.h>
51424+#include <linux/sched.h>
51425+#include <linux/mm.h>
51426+#include <linux/mman.h>
51427+#include <linux/grinternal.h>
51428+
51429+void
51430+gr_handle_ioperm(void)
51431+{
51432+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
51433+ return;
51434+}
51435+
51436+void
51437+gr_handle_iopl(void)
51438+{
51439+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
51440+ return;
51441+}
51442+
51443+void
51444+gr_handle_mem_readwrite(u64 from, u64 to)
51445+{
51446+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
51447+ return;
51448+}
51449+
51450+void
51451+gr_handle_vm86(void)
51452+{
51453+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
51454+ return;
51455+}
51456diff -urNp linux-3.0.4/grsecurity/grsec_mount.c linux-3.0.4/grsecurity/grsec_mount.c
51457--- linux-3.0.4/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
51458+++ linux-3.0.4/grsecurity/grsec_mount.c 2011-08-23 21:48:14.000000000 -0400
51459@@ -0,0 +1,62 @@
51460+#include <linux/kernel.h>
51461+#include <linux/sched.h>
51462+#include <linux/mount.h>
51463+#include <linux/grsecurity.h>
51464+#include <linux/grinternal.h>
51465+
51466+void
51467+gr_log_remount(const char *devname, const int retval)
51468+{
51469+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51470+ if (grsec_enable_mount && (retval >= 0))
51471+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
51472+#endif
51473+ return;
51474+}
51475+
51476+void
51477+gr_log_unmount(const char *devname, const int retval)
51478+{
51479+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51480+ if (grsec_enable_mount && (retval >= 0))
51481+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
51482+#endif
51483+ return;
51484+}
51485+
51486+void
51487+gr_log_mount(const char *from, const char *to, const int retval)
51488+{
51489+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51490+ if (grsec_enable_mount && (retval >= 0))
51491+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
51492+#endif
51493+ return;
51494+}
51495+
51496+int
51497+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
51498+{
51499+#ifdef CONFIG_GRKERNSEC_ROFS
51500+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
51501+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
51502+ return -EPERM;
51503+ } else
51504+ return 0;
51505+#endif
51506+ return 0;
51507+}
51508+
51509+int
51510+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
51511+{
51512+#ifdef CONFIG_GRKERNSEC_ROFS
51513+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
51514+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
51515+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
51516+ return -EPERM;
51517+ } else
51518+ return 0;
51519+#endif
51520+ return 0;
51521+}
51522diff -urNp linux-3.0.4/grsecurity/grsec_pax.c linux-3.0.4/grsecurity/grsec_pax.c
51523--- linux-3.0.4/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
51524+++ linux-3.0.4/grsecurity/grsec_pax.c 2011-08-23 21:48:14.000000000 -0400
51525@@ -0,0 +1,36 @@
51526+#include <linux/kernel.h>
51527+#include <linux/sched.h>
51528+#include <linux/mm.h>
51529+#include <linux/file.h>
51530+#include <linux/grinternal.h>
51531+#include <linux/grsecurity.h>
51532+
51533+void
51534+gr_log_textrel(struct vm_area_struct * vma)
51535+{
51536+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
51537+ if (grsec_enable_audit_textrel)
51538+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
51539+#endif
51540+ return;
51541+}
51542+
51543+void
51544+gr_log_rwxmmap(struct file *file)
51545+{
51546+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51547+ if (grsec_enable_log_rwxmaps)
51548+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
51549+#endif
51550+ return;
51551+}
51552+
51553+void
51554+gr_log_rwxmprotect(struct file *file)
51555+{
51556+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51557+ if (grsec_enable_log_rwxmaps)
51558+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
51559+#endif
51560+ return;
51561+}
51562diff -urNp linux-3.0.4/grsecurity/grsec_ptrace.c linux-3.0.4/grsecurity/grsec_ptrace.c
51563--- linux-3.0.4/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
51564+++ linux-3.0.4/grsecurity/grsec_ptrace.c 2011-08-23 21:48:14.000000000 -0400
51565@@ -0,0 +1,14 @@
51566+#include <linux/kernel.h>
51567+#include <linux/sched.h>
51568+#include <linux/grinternal.h>
51569+#include <linux/grsecurity.h>
51570+
51571+void
51572+gr_audit_ptrace(struct task_struct *task)
51573+{
51574+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
51575+ if (grsec_enable_audit_ptrace)
51576+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
51577+#endif
51578+ return;
51579+}
51580diff -urNp linux-3.0.4/grsecurity/grsec_sig.c linux-3.0.4/grsecurity/grsec_sig.c
51581--- linux-3.0.4/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
51582+++ linux-3.0.4/grsecurity/grsec_sig.c 2011-08-23 21:48:14.000000000 -0400
51583@@ -0,0 +1,206 @@
51584+#include <linux/kernel.h>
51585+#include <linux/sched.h>
51586+#include <linux/delay.h>
51587+#include <linux/grsecurity.h>
51588+#include <linux/grinternal.h>
51589+#include <linux/hardirq.h>
51590+
51591+char *signames[] = {
51592+ [SIGSEGV] = "Segmentation fault",
51593+ [SIGILL] = "Illegal instruction",
51594+ [SIGABRT] = "Abort",
51595+ [SIGBUS] = "Invalid alignment/Bus error"
51596+};
51597+
51598+void
51599+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
51600+{
51601+#ifdef CONFIG_GRKERNSEC_SIGNAL
51602+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
51603+ (sig == SIGABRT) || (sig == SIGBUS))) {
51604+ if (t->pid == current->pid) {
51605+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
51606+ } else {
51607+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
51608+ }
51609+ }
51610+#endif
51611+ return;
51612+}
51613+
51614+int
51615+gr_handle_signal(const struct task_struct *p, const int sig)
51616+{
51617+#ifdef CONFIG_GRKERNSEC
51618+ if (current->pid > 1 && gr_check_protected_task(p)) {
51619+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
51620+ return -EPERM;
51621+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
51622+ return -EPERM;
51623+ }
51624+#endif
51625+ return 0;
51626+}
51627+
51628+#ifdef CONFIG_GRKERNSEC
51629+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
51630+
51631+int gr_fake_force_sig(int sig, struct task_struct *t)
51632+{
51633+ unsigned long int flags;
51634+ int ret, blocked, ignored;
51635+ struct k_sigaction *action;
51636+
51637+ spin_lock_irqsave(&t->sighand->siglock, flags);
51638+ action = &t->sighand->action[sig-1];
51639+ ignored = action->sa.sa_handler == SIG_IGN;
51640+ blocked = sigismember(&t->blocked, sig);
51641+ if (blocked || ignored) {
51642+ action->sa.sa_handler = SIG_DFL;
51643+ if (blocked) {
51644+ sigdelset(&t->blocked, sig);
51645+ recalc_sigpending_and_wake(t);
51646+ }
51647+ }
51648+ if (action->sa.sa_handler == SIG_DFL)
51649+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
51650+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
51651+
51652+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
51653+
51654+ return ret;
51655+}
51656+#endif
51657+
51658+#ifdef CONFIG_GRKERNSEC_BRUTE
51659+#define GR_USER_BAN_TIME (15 * 60)
51660+
51661+static int __get_dumpable(unsigned long mm_flags)
51662+{
51663+ int ret;
51664+
51665+ ret = mm_flags & MMF_DUMPABLE_MASK;
51666+ return (ret >= 2) ? 2 : ret;
51667+}
51668+#endif
51669+
51670+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
51671+{
51672+#ifdef CONFIG_GRKERNSEC_BRUTE
51673+ uid_t uid = 0;
51674+
51675+ if (!grsec_enable_brute)
51676+ return;
51677+
51678+ rcu_read_lock();
51679+ read_lock(&tasklist_lock);
51680+ read_lock(&grsec_exec_file_lock);
51681+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
51682+ p->real_parent->brute = 1;
51683+ else {
51684+ const struct cred *cred = __task_cred(p), *cred2;
51685+ struct task_struct *tsk, *tsk2;
51686+
51687+ if (!__get_dumpable(mm_flags) && cred->uid) {
51688+ struct user_struct *user;
51689+
51690+ uid = cred->uid;
51691+
51692+ /* this is put upon execution past expiration */
51693+ user = find_user(uid);
51694+ if (user == NULL)
51695+ goto unlock;
51696+ user->banned = 1;
51697+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
51698+ if (user->ban_expires == ~0UL)
51699+ user->ban_expires--;
51700+
51701+ do_each_thread(tsk2, tsk) {
51702+ cred2 = __task_cred(tsk);
51703+ if (tsk != p && cred2->uid == uid)
51704+ gr_fake_force_sig(SIGKILL, tsk);
51705+ } while_each_thread(tsk2, tsk);
51706+ }
51707+ }
51708+unlock:
51709+ read_unlock(&grsec_exec_file_lock);
51710+ read_unlock(&tasklist_lock);
51711+ rcu_read_unlock();
51712+
51713+ if (uid)
51714+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
51715+
51716+#endif
51717+ return;
51718+}
51719+
51720+void gr_handle_brute_check(void)
51721+{
51722+#ifdef CONFIG_GRKERNSEC_BRUTE
51723+ if (current->brute)
51724+ msleep(30 * 1000);
51725+#endif
51726+ return;
51727+}
51728+
51729+void gr_handle_kernel_exploit(void)
51730+{
51731+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
51732+ const struct cred *cred;
51733+ struct task_struct *tsk, *tsk2;
51734+ struct user_struct *user;
51735+ uid_t uid;
51736+
51737+ if (in_irq() || in_serving_softirq() || in_nmi())
51738+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
51739+
51740+ uid = current_uid();
51741+
51742+ if (uid == 0)
51743+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
51744+ else {
51745+ /* kill all the processes of this user, hold a reference
51746+ to their creds struct, and prevent them from creating
51747+ another process until system reset
51748+ */
51749+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
51750+ /* we intentionally leak this ref */
51751+ user = get_uid(current->cred->user);
51752+ if (user) {
51753+ user->banned = 1;
51754+ user->ban_expires = ~0UL;
51755+ }
51756+
51757+ read_lock(&tasklist_lock);
51758+ do_each_thread(tsk2, tsk) {
51759+ cred = __task_cred(tsk);
51760+ if (cred->uid == uid)
51761+ gr_fake_force_sig(SIGKILL, tsk);
51762+ } while_each_thread(tsk2, tsk);
51763+ read_unlock(&tasklist_lock);
51764+ }
51765+#endif
51766+}
51767+
51768+int __gr_process_user_ban(struct user_struct *user)
51769+{
51770+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51771+ if (unlikely(user->banned)) {
51772+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
51773+ user->banned = 0;
51774+ user->ban_expires = 0;
51775+ free_uid(user);
51776+ } else
51777+ return -EPERM;
51778+ }
51779+#endif
51780+ return 0;
51781+}
51782+
51783+int gr_process_user_ban(void)
51784+{
51785+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51786+ return __gr_process_user_ban(current->cred->user);
51787+#endif
51788+ return 0;
51789+}
51790diff -urNp linux-3.0.4/grsecurity/grsec_sock.c linux-3.0.4/grsecurity/grsec_sock.c
51791--- linux-3.0.4/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
51792+++ linux-3.0.4/grsecurity/grsec_sock.c 2011-08-23 21:48:14.000000000 -0400
51793@@ -0,0 +1,244 @@
51794+#include <linux/kernel.h>
51795+#include <linux/module.h>
51796+#include <linux/sched.h>
51797+#include <linux/file.h>
51798+#include <linux/net.h>
51799+#include <linux/in.h>
51800+#include <linux/ip.h>
51801+#include <net/sock.h>
51802+#include <net/inet_sock.h>
51803+#include <linux/grsecurity.h>
51804+#include <linux/grinternal.h>
51805+#include <linux/gracl.h>
51806+
51807+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
51808+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
51809+
51810+EXPORT_SYMBOL(gr_search_udp_recvmsg);
51811+EXPORT_SYMBOL(gr_search_udp_sendmsg);
51812+
51813+#ifdef CONFIG_UNIX_MODULE
51814+EXPORT_SYMBOL(gr_acl_handle_unix);
51815+EXPORT_SYMBOL(gr_acl_handle_mknod);
51816+EXPORT_SYMBOL(gr_handle_chroot_unix);
51817+EXPORT_SYMBOL(gr_handle_create);
51818+#endif
51819+
51820+#ifdef CONFIG_GRKERNSEC
51821+#define gr_conn_table_size 32749
51822+struct conn_table_entry {
51823+ struct conn_table_entry *next;
51824+ struct signal_struct *sig;
51825+};
51826+
51827+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
51828+DEFINE_SPINLOCK(gr_conn_table_lock);
51829+
51830+extern const char * gr_socktype_to_name(unsigned char type);
51831+extern const char * gr_proto_to_name(unsigned char proto);
51832+extern const char * gr_sockfamily_to_name(unsigned char family);
51833+
51834+static __inline__ int
51835+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
51836+{
51837+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
51838+}
51839+
51840+static __inline__ int
51841+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
51842+ __u16 sport, __u16 dport)
51843+{
51844+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
51845+ sig->gr_sport == sport && sig->gr_dport == dport))
51846+ return 1;
51847+ else
51848+ return 0;
51849+}
51850+
51851+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
51852+{
51853+ struct conn_table_entry **match;
51854+ unsigned int index;
51855+
51856+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
51857+ sig->gr_sport, sig->gr_dport,
51858+ gr_conn_table_size);
51859+
51860+ newent->sig = sig;
51861+
51862+ match = &gr_conn_table[index];
51863+ newent->next = *match;
51864+ *match = newent;
51865+
51866+ return;
51867+}
51868+
51869+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
51870+{
51871+ struct conn_table_entry *match, *last = NULL;
51872+ unsigned int index;
51873+
51874+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
51875+ sig->gr_sport, sig->gr_dport,
51876+ gr_conn_table_size);
51877+
51878+ match = gr_conn_table[index];
51879+ while (match && !conn_match(match->sig,
51880+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
51881+ sig->gr_dport)) {
51882+ last = match;
51883+ match = match->next;
51884+ }
51885+
51886+ if (match) {
51887+ if (last)
51888+ last->next = match->next;
51889+ else
51890+ gr_conn_table[index] = NULL;
51891+ kfree(match);
51892+ }
51893+
51894+ return;
51895+}
51896+
51897+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
51898+ __u16 sport, __u16 dport)
51899+{
51900+ struct conn_table_entry *match;
51901+ unsigned int index;
51902+
51903+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
51904+
51905+ match = gr_conn_table[index];
51906+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
51907+ match = match->next;
51908+
51909+ if (match)
51910+ return match->sig;
51911+ else
51912+ return NULL;
51913+}
51914+
51915+#endif
51916+
51917+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
51918+{
51919+#ifdef CONFIG_GRKERNSEC
51920+ struct signal_struct *sig = task->signal;
51921+ struct conn_table_entry *newent;
51922+
51923+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
51924+ if (newent == NULL)
51925+ return;
51926+ /* no bh lock needed since we are called with bh disabled */
51927+ spin_lock(&gr_conn_table_lock);
51928+ gr_del_task_from_ip_table_nolock(sig);
51929+ sig->gr_saddr = inet->inet_rcv_saddr;
51930+ sig->gr_daddr = inet->inet_daddr;
51931+ sig->gr_sport = inet->inet_sport;
51932+ sig->gr_dport = inet->inet_dport;
51933+ gr_add_to_task_ip_table_nolock(sig, newent);
51934+ spin_unlock(&gr_conn_table_lock);
51935+#endif
51936+ return;
51937+}
51938+
51939+void gr_del_task_from_ip_table(struct task_struct *task)
51940+{
51941+#ifdef CONFIG_GRKERNSEC
51942+ spin_lock_bh(&gr_conn_table_lock);
51943+ gr_del_task_from_ip_table_nolock(task->signal);
51944+ spin_unlock_bh(&gr_conn_table_lock);
51945+#endif
51946+ return;
51947+}
51948+
51949+void
51950+gr_attach_curr_ip(const struct sock *sk)
51951+{
51952+#ifdef CONFIG_GRKERNSEC
51953+ struct signal_struct *p, *set;
51954+ const struct inet_sock *inet = inet_sk(sk);
51955+
51956+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
51957+ return;
51958+
51959+ set = current->signal;
51960+
51961+ spin_lock_bh(&gr_conn_table_lock);
51962+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
51963+ inet->inet_dport, inet->inet_sport);
51964+ if (unlikely(p != NULL)) {
51965+ set->curr_ip = p->curr_ip;
51966+ set->used_accept = 1;
51967+ gr_del_task_from_ip_table_nolock(p);
51968+ spin_unlock_bh(&gr_conn_table_lock);
51969+ return;
51970+ }
51971+ spin_unlock_bh(&gr_conn_table_lock);
51972+
51973+ set->curr_ip = inet->inet_daddr;
51974+ set->used_accept = 1;
51975+#endif
51976+ return;
51977+}
51978+
51979+int
51980+gr_handle_sock_all(const int family, const int type, const int protocol)
51981+{
51982+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
51983+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
51984+ (family != AF_UNIX)) {
51985+ if (family == AF_INET)
51986+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
51987+ else
51988+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
51989+ return -EACCES;
51990+ }
51991+#endif
51992+ return 0;
51993+}
51994+
51995+int
51996+gr_handle_sock_server(const struct sockaddr *sck)
51997+{
51998+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51999+ if (grsec_enable_socket_server &&
52000+ in_group_p(grsec_socket_server_gid) &&
52001+ sck && (sck->sa_family != AF_UNIX) &&
52002+ (sck->sa_family != AF_LOCAL)) {
52003+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
52004+ return -EACCES;
52005+ }
52006+#endif
52007+ return 0;
52008+}
52009+
52010+int
52011+gr_handle_sock_server_other(const struct sock *sck)
52012+{
52013+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
52014+ if (grsec_enable_socket_server &&
52015+ in_group_p(grsec_socket_server_gid) &&
52016+ sck && (sck->sk_family != AF_UNIX) &&
52017+ (sck->sk_family != AF_LOCAL)) {
52018+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
52019+ return -EACCES;
52020+ }
52021+#endif
52022+ return 0;
52023+}
52024+
52025+int
52026+gr_handle_sock_client(const struct sockaddr *sck)
52027+{
52028+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
52029+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
52030+ sck && (sck->sa_family != AF_UNIX) &&
52031+ (sck->sa_family != AF_LOCAL)) {
52032+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
52033+ return -EACCES;
52034+ }
52035+#endif
52036+ return 0;
52037+}
52038diff -urNp linux-3.0.4/grsecurity/grsec_sysctl.c linux-3.0.4/grsecurity/grsec_sysctl.c
52039--- linux-3.0.4/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
52040+++ linux-3.0.4/grsecurity/grsec_sysctl.c 2011-08-25 17:26:15.000000000 -0400
52041@@ -0,0 +1,433 @@
52042+#include <linux/kernel.h>
52043+#include <linux/sched.h>
52044+#include <linux/sysctl.h>
52045+#include <linux/grsecurity.h>
52046+#include <linux/grinternal.h>
52047+
52048+int
52049+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
52050+{
52051+#ifdef CONFIG_GRKERNSEC_SYSCTL
52052+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
52053+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
52054+ return -EACCES;
52055+ }
52056+#endif
52057+ return 0;
52058+}
52059+
52060+#ifdef CONFIG_GRKERNSEC_ROFS
52061+static int __maybe_unused one = 1;
52062+#endif
52063+
52064+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
52065+struct ctl_table grsecurity_table[] = {
52066+#ifdef CONFIG_GRKERNSEC_SYSCTL
52067+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
52068+#ifdef CONFIG_GRKERNSEC_IO
52069+ {
52070+ .procname = "disable_priv_io",
52071+ .data = &grsec_disable_privio,
52072+ .maxlen = sizeof(int),
52073+ .mode = 0600,
52074+ .proc_handler = &proc_dointvec,
52075+ },
52076+#endif
52077+#endif
52078+#ifdef CONFIG_GRKERNSEC_LINK
52079+ {
52080+ .procname = "linking_restrictions",
52081+ .data = &grsec_enable_link,
52082+ .maxlen = sizeof(int),
52083+ .mode = 0600,
52084+ .proc_handler = &proc_dointvec,
52085+ },
52086+#endif
52087+#ifdef CONFIG_GRKERNSEC_BRUTE
52088+ {
52089+ .procname = "deter_bruteforce",
52090+ .data = &grsec_enable_brute,
52091+ .maxlen = sizeof(int),
52092+ .mode = 0600,
52093+ .proc_handler = &proc_dointvec,
52094+ },
52095+#endif
52096+#ifdef CONFIG_GRKERNSEC_FIFO
52097+ {
52098+ .procname = "fifo_restrictions",
52099+ .data = &grsec_enable_fifo,
52100+ .maxlen = sizeof(int),
52101+ .mode = 0600,
52102+ .proc_handler = &proc_dointvec,
52103+ },
52104+#endif
52105+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
52106+ {
52107+ .procname = "ip_blackhole",
52108+ .data = &grsec_enable_blackhole,
52109+ .maxlen = sizeof(int),
52110+ .mode = 0600,
52111+ .proc_handler = &proc_dointvec,
52112+ },
52113+ {
52114+ .procname = "lastack_retries",
52115+ .data = &grsec_lastack_retries,
52116+ .maxlen = sizeof(int),
52117+ .mode = 0600,
52118+ .proc_handler = &proc_dointvec,
52119+ },
52120+#endif
52121+#ifdef CONFIG_GRKERNSEC_EXECLOG
52122+ {
52123+ .procname = "exec_logging",
52124+ .data = &grsec_enable_execlog,
52125+ .maxlen = sizeof(int),
52126+ .mode = 0600,
52127+ .proc_handler = &proc_dointvec,
52128+ },
52129+#endif
52130+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52131+ {
52132+ .procname = "rwxmap_logging",
52133+ .data = &grsec_enable_log_rwxmaps,
52134+ .maxlen = sizeof(int),
52135+ .mode = 0600,
52136+ .proc_handler = &proc_dointvec,
52137+ },
52138+#endif
52139+#ifdef CONFIG_GRKERNSEC_SIGNAL
52140+ {
52141+ .procname = "signal_logging",
52142+ .data = &grsec_enable_signal,
52143+ .maxlen = sizeof(int),
52144+ .mode = 0600,
52145+ .proc_handler = &proc_dointvec,
52146+ },
52147+#endif
52148+#ifdef CONFIG_GRKERNSEC_FORKFAIL
52149+ {
52150+ .procname = "forkfail_logging",
52151+ .data = &grsec_enable_forkfail,
52152+ .maxlen = sizeof(int),
52153+ .mode = 0600,
52154+ .proc_handler = &proc_dointvec,
52155+ },
52156+#endif
52157+#ifdef CONFIG_GRKERNSEC_TIME
52158+ {
52159+ .procname = "timechange_logging",
52160+ .data = &grsec_enable_time,
52161+ .maxlen = sizeof(int),
52162+ .mode = 0600,
52163+ .proc_handler = &proc_dointvec,
52164+ },
52165+#endif
52166+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
52167+ {
52168+ .procname = "chroot_deny_shmat",
52169+ .data = &grsec_enable_chroot_shmat,
52170+ .maxlen = sizeof(int),
52171+ .mode = 0600,
52172+ .proc_handler = &proc_dointvec,
52173+ },
52174+#endif
52175+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
52176+ {
52177+ .procname = "chroot_deny_unix",
52178+ .data = &grsec_enable_chroot_unix,
52179+ .maxlen = sizeof(int),
52180+ .mode = 0600,
52181+ .proc_handler = &proc_dointvec,
52182+ },
52183+#endif
52184+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
52185+ {
52186+ .procname = "chroot_deny_mount",
52187+ .data = &grsec_enable_chroot_mount,
52188+ .maxlen = sizeof(int),
52189+ .mode = 0600,
52190+ .proc_handler = &proc_dointvec,
52191+ },
52192+#endif
52193+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
52194+ {
52195+ .procname = "chroot_deny_fchdir",
52196+ .data = &grsec_enable_chroot_fchdir,
52197+ .maxlen = sizeof(int),
52198+ .mode = 0600,
52199+ .proc_handler = &proc_dointvec,
52200+ },
52201+#endif
52202+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
52203+ {
52204+ .procname = "chroot_deny_chroot",
52205+ .data = &grsec_enable_chroot_double,
52206+ .maxlen = sizeof(int),
52207+ .mode = 0600,
52208+ .proc_handler = &proc_dointvec,
52209+ },
52210+#endif
52211+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
52212+ {
52213+ .procname = "chroot_deny_pivot",
52214+ .data = &grsec_enable_chroot_pivot,
52215+ .maxlen = sizeof(int),
52216+ .mode = 0600,
52217+ .proc_handler = &proc_dointvec,
52218+ },
52219+#endif
52220+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
52221+ {
52222+ .procname = "chroot_enforce_chdir",
52223+ .data = &grsec_enable_chroot_chdir,
52224+ .maxlen = sizeof(int),
52225+ .mode = 0600,
52226+ .proc_handler = &proc_dointvec,
52227+ },
52228+#endif
52229+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
52230+ {
52231+ .procname = "chroot_deny_chmod",
52232+ .data = &grsec_enable_chroot_chmod,
52233+ .maxlen = sizeof(int),
52234+ .mode = 0600,
52235+ .proc_handler = &proc_dointvec,
52236+ },
52237+#endif
52238+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
52239+ {
52240+ .procname = "chroot_deny_mknod",
52241+ .data = &grsec_enable_chroot_mknod,
52242+ .maxlen = sizeof(int),
52243+ .mode = 0600,
52244+ .proc_handler = &proc_dointvec,
52245+ },
52246+#endif
52247+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
52248+ {
52249+ .procname = "chroot_restrict_nice",
52250+ .data = &grsec_enable_chroot_nice,
52251+ .maxlen = sizeof(int),
52252+ .mode = 0600,
52253+ .proc_handler = &proc_dointvec,
52254+ },
52255+#endif
52256+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
52257+ {
52258+ .procname = "chroot_execlog",
52259+ .data = &grsec_enable_chroot_execlog,
52260+ .maxlen = sizeof(int),
52261+ .mode = 0600,
52262+ .proc_handler = &proc_dointvec,
52263+ },
52264+#endif
52265+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52266+ {
52267+ .procname = "chroot_caps",
52268+ .data = &grsec_enable_chroot_caps,
52269+ .maxlen = sizeof(int),
52270+ .mode = 0600,
52271+ .proc_handler = &proc_dointvec,
52272+ },
52273+#endif
52274+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
52275+ {
52276+ .procname = "chroot_deny_sysctl",
52277+ .data = &grsec_enable_chroot_sysctl,
52278+ .maxlen = sizeof(int),
52279+ .mode = 0600,
52280+ .proc_handler = &proc_dointvec,
52281+ },
52282+#endif
52283+#ifdef CONFIG_GRKERNSEC_TPE
52284+ {
52285+ .procname = "tpe",
52286+ .data = &grsec_enable_tpe,
52287+ .maxlen = sizeof(int),
52288+ .mode = 0600,
52289+ .proc_handler = &proc_dointvec,
52290+ },
52291+ {
52292+ .procname = "tpe_gid",
52293+ .data = &grsec_tpe_gid,
52294+ .maxlen = sizeof(int),
52295+ .mode = 0600,
52296+ .proc_handler = &proc_dointvec,
52297+ },
52298+#endif
52299+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
52300+ {
52301+ .procname = "tpe_invert",
52302+ .data = &grsec_enable_tpe_invert,
52303+ .maxlen = sizeof(int),
52304+ .mode = 0600,
52305+ .proc_handler = &proc_dointvec,
52306+ },
52307+#endif
52308+#ifdef CONFIG_GRKERNSEC_TPE_ALL
52309+ {
52310+ .procname = "tpe_restrict_all",
52311+ .data = &grsec_enable_tpe_all,
52312+ .maxlen = sizeof(int),
52313+ .mode = 0600,
52314+ .proc_handler = &proc_dointvec,
52315+ },
52316+#endif
52317+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
52318+ {
52319+ .procname = "socket_all",
52320+ .data = &grsec_enable_socket_all,
52321+ .maxlen = sizeof(int),
52322+ .mode = 0600,
52323+ .proc_handler = &proc_dointvec,
52324+ },
52325+ {
52326+ .procname = "socket_all_gid",
52327+ .data = &grsec_socket_all_gid,
52328+ .maxlen = sizeof(int),
52329+ .mode = 0600,
52330+ .proc_handler = &proc_dointvec,
52331+ },
52332+#endif
52333+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
52334+ {
52335+ .procname = "socket_client",
52336+ .data = &grsec_enable_socket_client,
52337+ .maxlen = sizeof(int),
52338+ .mode = 0600,
52339+ .proc_handler = &proc_dointvec,
52340+ },
52341+ {
52342+ .procname = "socket_client_gid",
52343+ .data = &grsec_socket_client_gid,
52344+ .maxlen = sizeof(int),
52345+ .mode = 0600,
52346+ .proc_handler = &proc_dointvec,
52347+ },
52348+#endif
52349+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
52350+ {
52351+ .procname = "socket_server",
52352+ .data = &grsec_enable_socket_server,
52353+ .maxlen = sizeof(int),
52354+ .mode = 0600,
52355+ .proc_handler = &proc_dointvec,
52356+ },
52357+ {
52358+ .procname = "socket_server_gid",
52359+ .data = &grsec_socket_server_gid,
52360+ .maxlen = sizeof(int),
52361+ .mode = 0600,
52362+ .proc_handler = &proc_dointvec,
52363+ },
52364+#endif
52365+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
52366+ {
52367+ .procname = "audit_group",
52368+ .data = &grsec_enable_group,
52369+ .maxlen = sizeof(int),
52370+ .mode = 0600,
52371+ .proc_handler = &proc_dointvec,
52372+ },
52373+ {
52374+ .procname = "audit_gid",
52375+ .data = &grsec_audit_gid,
52376+ .maxlen = sizeof(int),
52377+ .mode = 0600,
52378+ .proc_handler = &proc_dointvec,
52379+ },
52380+#endif
52381+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
52382+ {
52383+ .procname = "audit_chdir",
52384+ .data = &grsec_enable_chdir,
52385+ .maxlen = sizeof(int),
52386+ .mode = 0600,
52387+ .proc_handler = &proc_dointvec,
52388+ },
52389+#endif
52390+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
52391+ {
52392+ .procname = "audit_mount",
52393+ .data = &grsec_enable_mount,
52394+ .maxlen = sizeof(int),
52395+ .mode = 0600,
52396+ .proc_handler = &proc_dointvec,
52397+ },
52398+#endif
52399+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
52400+ {
52401+ .procname = "audit_textrel",
52402+ .data = &grsec_enable_audit_textrel,
52403+ .maxlen = sizeof(int),
52404+ .mode = 0600,
52405+ .proc_handler = &proc_dointvec,
52406+ },
52407+#endif
52408+#ifdef CONFIG_GRKERNSEC_DMESG
52409+ {
52410+ .procname = "dmesg",
52411+ .data = &grsec_enable_dmesg,
52412+ .maxlen = sizeof(int),
52413+ .mode = 0600,
52414+ .proc_handler = &proc_dointvec,
52415+ },
52416+#endif
52417+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
52418+ {
52419+ .procname = "chroot_findtask",
52420+ .data = &grsec_enable_chroot_findtask,
52421+ .maxlen = sizeof(int),
52422+ .mode = 0600,
52423+ .proc_handler = &proc_dointvec,
52424+ },
52425+#endif
52426+#ifdef CONFIG_GRKERNSEC_RESLOG
52427+ {
52428+ .procname = "resource_logging",
52429+ .data = &grsec_resource_logging,
52430+ .maxlen = sizeof(int),
52431+ .mode = 0600,
52432+ .proc_handler = &proc_dointvec,
52433+ },
52434+#endif
52435+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
52436+ {
52437+ .procname = "audit_ptrace",
52438+ .data = &grsec_enable_audit_ptrace,
52439+ .maxlen = sizeof(int),
52440+ .mode = 0600,
52441+ .proc_handler = &proc_dointvec,
52442+ },
52443+#endif
52444+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52445+ {
52446+ .procname = "harden_ptrace",
52447+ .data = &grsec_enable_harden_ptrace,
52448+ .maxlen = sizeof(int),
52449+ .mode = 0600,
52450+ .proc_handler = &proc_dointvec,
52451+ },
52452+#endif
52453+ {
52454+ .procname = "grsec_lock",
52455+ .data = &grsec_lock,
52456+ .maxlen = sizeof(int),
52457+ .mode = 0600,
52458+ .proc_handler = &proc_dointvec,
52459+ },
52460+#endif
52461+#ifdef CONFIG_GRKERNSEC_ROFS
52462+ {
52463+ .procname = "romount_protect",
52464+ .data = &grsec_enable_rofs,
52465+ .maxlen = sizeof(int),
52466+ .mode = 0600,
52467+ .proc_handler = &proc_dointvec_minmax,
52468+ .extra1 = &one,
52469+ .extra2 = &one,
52470+ },
52471+#endif
52472+ { }
52473+};
52474+#endif
52475diff -urNp linux-3.0.4/grsecurity/grsec_time.c linux-3.0.4/grsecurity/grsec_time.c
52476--- linux-3.0.4/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
52477+++ linux-3.0.4/grsecurity/grsec_time.c 2011-08-23 21:48:14.000000000 -0400
52478@@ -0,0 +1,16 @@
52479+#include <linux/kernel.h>
52480+#include <linux/sched.h>
52481+#include <linux/grinternal.h>
52482+#include <linux/module.h>
52483+
52484+void
52485+gr_log_timechange(void)
52486+{
52487+#ifdef CONFIG_GRKERNSEC_TIME
52488+ if (grsec_enable_time)
52489+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
52490+#endif
52491+ return;
52492+}
52493+
52494+EXPORT_SYMBOL(gr_log_timechange);
52495diff -urNp linux-3.0.4/grsecurity/grsec_tpe.c linux-3.0.4/grsecurity/grsec_tpe.c
52496--- linux-3.0.4/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
52497+++ linux-3.0.4/grsecurity/grsec_tpe.c 2011-08-23 21:48:14.000000000 -0400
52498@@ -0,0 +1,39 @@
52499+#include <linux/kernel.h>
52500+#include <linux/sched.h>
52501+#include <linux/file.h>
52502+#include <linux/fs.h>
52503+#include <linux/grinternal.h>
52504+
52505+extern int gr_acl_tpe_check(void);
52506+
52507+int
52508+gr_tpe_allow(const struct file *file)
52509+{
52510+#ifdef CONFIG_GRKERNSEC
52511+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
52512+ const struct cred *cred = current_cred();
52513+
52514+ if (cred->uid && ((grsec_enable_tpe &&
52515+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
52516+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
52517+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
52518+#else
52519+ in_group_p(grsec_tpe_gid)
52520+#endif
52521+ ) || gr_acl_tpe_check()) &&
52522+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
52523+ (inode->i_mode & S_IWOTH))))) {
52524+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
52525+ return 0;
52526+ }
52527+#ifdef CONFIG_GRKERNSEC_TPE_ALL
52528+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
52529+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
52530+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
52531+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
52532+ return 0;
52533+ }
52534+#endif
52535+#endif
52536+ return 1;
52537+}
52538diff -urNp linux-3.0.4/grsecurity/grsum.c linux-3.0.4/grsecurity/grsum.c
52539--- linux-3.0.4/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
52540+++ linux-3.0.4/grsecurity/grsum.c 2011-08-23 21:48:14.000000000 -0400
52541@@ -0,0 +1,61 @@
52542+#include <linux/err.h>
52543+#include <linux/kernel.h>
52544+#include <linux/sched.h>
52545+#include <linux/mm.h>
52546+#include <linux/scatterlist.h>
52547+#include <linux/crypto.h>
52548+#include <linux/gracl.h>
52549+
52550+
52551+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
52552+#error "crypto and sha256 must be built into the kernel"
52553+#endif
52554+
52555+int
52556+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
52557+{
52558+ char *p;
52559+ struct crypto_hash *tfm;
52560+ struct hash_desc desc;
52561+ struct scatterlist sg;
52562+ unsigned char temp_sum[GR_SHA_LEN];
52563+ volatile int retval = 0;
52564+ volatile int dummy = 0;
52565+ unsigned int i;
52566+
52567+ sg_init_table(&sg, 1);
52568+
52569+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
52570+ if (IS_ERR(tfm)) {
52571+ /* should never happen, since sha256 should be built in */
52572+ return 1;
52573+ }
52574+
52575+ desc.tfm = tfm;
52576+ desc.flags = 0;
52577+
52578+ crypto_hash_init(&desc);
52579+
52580+ p = salt;
52581+ sg_set_buf(&sg, p, GR_SALT_LEN);
52582+ crypto_hash_update(&desc, &sg, sg.length);
52583+
52584+ p = entry->pw;
52585+ sg_set_buf(&sg, p, strlen(p));
52586+
52587+ crypto_hash_update(&desc, &sg, sg.length);
52588+
52589+ crypto_hash_final(&desc, temp_sum);
52590+
52591+ memset(entry->pw, 0, GR_PW_LEN);
52592+
52593+ for (i = 0; i < GR_SHA_LEN; i++)
52594+ if (sum[i] != temp_sum[i])
52595+ retval = 1;
52596+ else
52597+ dummy = 1; // waste a cycle
52598+
52599+ crypto_free_hash(tfm);
52600+
52601+ return retval;
52602+}
52603diff -urNp linux-3.0.4/grsecurity/Kconfig linux-3.0.4/grsecurity/Kconfig
52604--- linux-3.0.4/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
52605+++ linux-3.0.4/grsecurity/Kconfig 2011-09-15 00:00:57.000000000 -0400
52606@@ -0,0 +1,1038 @@
52607+#
52608+# grecurity configuration
52609+#
52610+
52611+menu "Grsecurity"
52612+
52613+config GRKERNSEC
52614+ bool "Grsecurity"
52615+ select CRYPTO
52616+ select CRYPTO_SHA256
52617+ help
52618+ If you say Y here, you will be able to configure many features
52619+ that will enhance the security of your system. It is highly
52620+ recommended that you say Y here and read through the help
52621+ for each option so that you fully understand the features and
52622+ can evaluate their usefulness for your machine.
52623+
52624+choice
52625+ prompt "Security Level"
52626+ depends on GRKERNSEC
52627+ default GRKERNSEC_CUSTOM
52628+
52629+config GRKERNSEC_LOW
52630+ bool "Low"
52631+ select GRKERNSEC_LINK
52632+ select GRKERNSEC_FIFO
52633+ select GRKERNSEC_RANDNET
52634+ select GRKERNSEC_DMESG
52635+ select GRKERNSEC_CHROOT
52636+ select GRKERNSEC_CHROOT_CHDIR
52637+
52638+ help
52639+ If you choose this option, several of the grsecurity options will
52640+ be enabled that will give you greater protection against a number
52641+ of attacks, while assuring that none of your software will have any
52642+ conflicts with the additional security measures. If you run a lot
52643+ of unusual software, or you are having problems with the higher
52644+ security levels, you should say Y here. With this option, the
52645+ following features are enabled:
52646+
52647+ - Linking restrictions
52648+ - FIFO restrictions
52649+ - Restricted dmesg
52650+ - Enforced chdir("/") on chroot
52651+ - Runtime module disabling
52652+
52653+config GRKERNSEC_MEDIUM
52654+ bool "Medium"
52655+ select PAX
52656+ select PAX_EI_PAX
52657+ select PAX_PT_PAX_FLAGS
52658+ select PAX_HAVE_ACL_FLAGS
52659+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
52660+ select GRKERNSEC_CHROOT
52661+ select GRKERNSEC_CHROOT_SYSCTL
52662+ select GRKERNSEC_LINK
52663+ select GRKERNSEC_FIFO
52664+ select GRKERNSEC_DMESG
52665+ select GRKERNSEC_RANDNET
52666+ select GRKERNSEC_FORKFAIL
52667+ select GRKERNSEC_TIME
52668+ select GRKERNSEC_SIGNAL
52669+ select GRKERNSEC_CHROOT
52670+ select GRKERNSEC_CHROOT_UNIX
52671+ select GRKERNSEC_CHROOT_MOUNT
52672+ select GRKERNSEC_CHROOT_PIVOT
52673+ select GRKERNSEC_CHROOT_DOUBLE
52674+ select GRKERNSEC_CHROOT_CHDIR
52675+ select GRKERNSEC_CHROOT_MKNOD
52676+ select GRKERNSEC_PROC
52677+ select GRKERNSEC_PROC_USERGROUP
52678+ select PAX_RANDUSTACK
52679+ select PAX_ASLR
52680+ select PAX_RANDMMAP
52681+ select PAX_REFCOUNT if (X86 || SPARC64)
52682+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
52683+
52684+ help
52685+ If you say Y here, several features in addition to those included
52686+ in the low additional security level will be enabled. These
52687+ features provide even more security to your system, though in rare
52688+ cases they may be incompatible with very old or poorly written
52689+ software. If you enable this option, make sure that your auth
52690+ service (identd) is running as gid 1001. With this option,
52691+ the following features (in addition to those provided in the
52692+ low additional security level) will be enabled:
52693+
52694+ - Failed fork logging
52695+ - Time change logging
52696+ - Signal logging
52697+ - Deny mounts in chroot
52698+ - Deny double chrooting
52699+ - Deny sysctl writes in chroot
52700+ - Deny mknod in chroot
52701+ - Deny access to abstract AF_UNIX sockets out of chroot
52702+ - Deny pivot_root in chroot
52703+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
52704+ - /proc restrictions with special GID set to 10 (usually wheel)
52705+ - Address Space Layout Randomization (ASLR)
52706+ - Prevent exploitation of most refcount overflows
52707+ - Bounds checking of copying between the kernel and userland
52708+
52709+config GRKERNSEC_HIGH
52710+ bool "High"
52711+ select GRKERNSEC_LINK
52712+ select GRKERNSEC_FIFO
52713+ select GRKERNSEC_DMESG
52714+ select GRKERNSEC_FORKFAIL
52715+ select GRKERNSEC_TIME
52716+ select GRKERNSEC_SIGNAL
52717+ select GRKERNSEC_CHROOT
52718+ select GRKERNSEC_CHROOT_SHMAT
52719+ select GRKERNSEC_CHROOT_UNIX
52720+ select GRKERNSEC_CHROOT_MOUNT
52721+ select GRKERNSEC_CHROOT_FCHDIR
52722+ select GRKERNSEC_CHROOT_PIVOT
52723+ select GRKERNSEC_CHROOT_DOUBLE
52724+ select GRKERNSEC_CHROOT_CHDIR
52725+ select GRKERNSEC_CHROOT_MKNOD
52726+ select GRKERNSEC_CHROOT_CAPS
52727+ select GRKERNSEC_CHROOT_SYSCTL
52728+ select GRKERNSEC_CHROOT_FINDTASK
52729+ select GRKERNSEC_SYSFS_RESTRICT
52730+ select GRKERNSEC_PROC
52731+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
52732+ select GRKERNSEC_HIDESYM
52733+ select GRKERNSEC_BRUTE
52734+ select GRKERNSEC_PROC_USERGROUP
52735+ select GRKERNSEC_KMEM
52736+ select GRKERNSEC_RESLOG
52737+ select GRKERNSEC_RANDNET
52738+ select GRKERNSEC_PROC_ADD
52739+ select GRKERNSEC_CHROOT_CHMOD
52740+ select GRKERNSEC_CHROOT_NICE
52741+ select GRKERNSEC_AUDIT_MOUNT
52742+ select GRKERNSEC_MODHARDEN if (MODULES)
52743+ select GRKERNSEC_HARDEN_PTRACE
52744+ select GRKERNSEC_VM86 if (X86_32)
52745+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
52746+ select PAX
52747+ select PAX_RANDUSTACK
52748+ select PAX_ASLR
52749+ select PAX_RANDMMAP
52750+ select PAX_NOEXEC
52751+ select PAX_MPROTECT
52752+ select PAX_EI_PAX
52753+ select PAX_PT_PAX_FLAGS
52754+ select PAX_HAVE_ACL_FLAGS
52755+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
52756+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
52757+ select PAX_RANDKSTACK if (X86_TSC && X86)
52758+ select PAX_SEGMEXEC if (X86_32)
52759+ select PAX_PAGEEXEC
52760+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
52761+ select PAX_EMUTRAMP if (PARISC)
52762+ select PAX_EMUSIGRT if (PARISC)
52763+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
52764+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
52765+ select PAX_REFCOUNT if (X86 || SPARC64)
52766+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
52767+ help
52768+ If you say Y here, many of the features of grsecurity will be
52769+ enabled, which will protect you against many kinds of attacks
52770+ against your system. The heightened security comes at a cost
52771+ of an increased chance of incompatibilities with rare software
52772+ on your machine. Since this security level enables PaX, you should
52773+ view <http://pax.grsecurity.net> and read about the PaX
52774+ project. While you are there, download chpax and run it on
52775+ binaries that cause problems with PaX. Also remember that
52776+ since the /proc restrictions are enabled, you must run your
52777+ identd as gid 1001. This security level enables the following
52778+ features in addition to those listed in the low and medium
52779+ security levels:
52780+
52781+ - Additional /proc restrictions
52782+ - Chmod restrictions in chroot
52783+ - No signals, ptrace, or viewing of processes outside of chroot
52784+ - Capability restrictions in chroot
52785+ - Deny fchdir out of chroot
52786+ - Priority restrictions in chroot
52787+ - Segmentation-based implementation of PaX
52788+ - Mprotect restrictions
52789+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
52790+ - Kernel stack randomization
52791+ - Mount/unmount/remount logging
52792+ - Kernel symbol hiding
52793+ - Prevention of memory exhaustion-based exploits
52794+ - Hardening of module auto-loading
52795+ - Ptrace restrictions
52796+ - Restricted vm86 mode
52797+ - Restricted sysfs/debugfs
52798+ - Active kernel exploit response
52799+
52800+config GRKERNSEC_CUSTOM
52801+ bool "Custom"
52802+ help
52803+ If you say Y here, you will be able to configure every grsecurity
52804+ option, which allows you to enable many more features that aren't
52805+ covered in the basic security levels. These additional features
52806+ include TPE, socket restrictions, and the sysctl system for
52807+ grsecurity. It is advised that you read through the help for
52808+ each option to determine its usefulness in your situation.
52809+
52810+endchoice
52811+
52812+menu "Address Space Protection"
52813+depends on GRKERNSEC
52814+
52815+config GRKERNSEC_KMEM
52816+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
52817+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52818+ help
52819+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52820+ be written to via mmap or otherwise to modify the running kernel.
52821+ /dev/port will also not be allowed to be opened. If you have module
52822+ support disabled, enabling this will close up four ways that are
52823+ currently used to insert malicious code into the running kernel.
52824+ Even with all these features enabled, we still highly recommend that
52825+ you use the RBAC system, as it is still possible for an attacker to
52826+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52827+ If you are not using XFree86, you may be able to stop this additional
52828+ case by enabling the 'Disable privileged I/O' option. Though nothing
52829+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52830+ but only to video memory, which is the only writing we allow in this
52831+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52832+ not be allowed to mprotect it with PROT_WRITE later.
52833+ It is highly recommended that you say Y here if you meet all the
52834+ conditions above.
52835+
52836+config GRKERNSEC_VM86
52837+ bool "Restrict VM86 mode"
52838+ depends on X86_32
52839+
52840+ help
52841+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52842+ make use of a special execution mode on 32bit x86 processors called
52843+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52844+ video cards and will still work with this option enabled. The purpose
52845+ of the option is to prevent exploitation of emulation errors in
52846+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52847+ Nearly all users should be able to enable this option.
52848+
52849+config GRKERNSEC_IO
52850+ bool "Disable privileged I/O"
52851+ depends on X86
52852+ select RTC_CLASS
52853+ select RTC_INTF_DEV
52854+ select RTC_DRV_CMOS
52855+
52856+ help
52857+ If you say Y here, all ioperm and iopl calls will return an error.
52858+ Ioperm and iopl can be used to modify the running kernel.
52859+ Unfortunately, some programs need this access to operate properly,
52860+ the most notable of which are XFree86 and hwclock. hwclock can be
52861+ remedied by having RTC support in the kernel, so real-time
52862+ clock support is enabled if this option is enabled, to ensure
52863+ that hwclock operates correctly. XFree86 still will not
52864+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52865+ IF YOU USE XFree86. If you use XFree86 and you still want to
52866+ protect your kernel against modification, use the RBAC system.
52867+
52868+config GRKERNSEC_PROC_MEMMAP
52869+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
52870+ default y if (PAX_NOEXEC || PAX_ASLR)
52871+ depends on PAX_NOEXEC || PAX_ASLR
52872+ help
52873+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52874+ give no information about the addresses of its mappings if
52875+ PaX features that rely on random addresses are enabled on the task.
52876+ If you use PaX it is greatly recommended that you say Y here as it
52877+ closes up a hole that makes the full ASLR useless for suid
52878+ binaries.
52879+
52880+config GRKERNSEC_BRUTE
52881+ bool "Deter exploit bruteforcing"
52882+ help
52883+ If you say Y here, attempts to bruteforce exploits against forking
52884+ daemons such as apache or sshd, as well as against suid/sgid binaries
52885+ will be deterred. When a child of a forking daemon is killed by PaX
52886+ or crashes due to an illegal instruction or other suspicious signal,
52887+ the parent process will be delayed 30 seconds upon every subsequent
52888+ fork until the administrator is able to assess the situation and
52889+ restart the daemon.
52890+ In the suid/sgid case, the attempt is logged, the user has all their
52891+ processes terminated, and they are prevented from executing any further
52892+ processes for 15 minutes.
52893+ It is recommended that you also enable signal logging in the auditing
52894+ section so that logs are generated when a process triggers a suspicious
52895+ signal.
52896+ If the sysctl option is enabled, a sysctl option with name
52897+ "deter_bruteforce" is created.
52898+
52899+
52900+config GRKERNSEC_MODHARDEN
52901+ bool "Harden module auto-loading"
52902+ depends on MODULES
52903+ help
52904+ If you say Y here, module auto-loading in response to use of some
52905+ feature implemented by an unloaded module will be restricted to
52906+ root users. Enabling this option helps defend against attacks
52907+ by unprivileged users who abuse the auto-loading behavior to
52908+ cause a vulnerable module to load that is then exploited.
52909+
52910+ If this option prevents a legitimate use of auto-loading for a
52911+ non-root user, the administrator can execute modprobe manually
52912+ with the exact name of the module mentioned in the alert log.
52913+ Alternatively, the administrator can add the module to the list
52914+ of modules loaded at boot by modifying init scripts.
52915+
52916+ Modification of init scripts will most likely be needed on
52917+ Ubuntu servers with encrypted home directory support enabled,
52918+ as the first non-root user logging in will cause the ecb(aes),
52919+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52920+
52921+config GRKERNSEC_HIDESYM
52922+ bool "Hide kernel symbols"
52923+ help
52924+ If you say Y here, getting information on loaded modules, and
52925+ displaying all kernel symbols through a syscall will be restricted
52926+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52927+ /proc/kallsyms will be restricted to the root user. The RBAC
52928+ system can hide that entry even from root.
52929+
52930+ This option also prevents leaking of kernel addresses through
52931+ several /proc entries.
52932+
52933+ Note that this option is only effective provided the following
52934+ conditions are met:
52935+ 1) The kernel using grsecurity is not precompiled by some distribution
52936+ 2) You have also enabled GRKERNSEC_DMESG
52937+ 3) You are using the RBAC system and hiding other files such as your
52938+ kernel image and System.map. Alternatively, enabling this option
52939+ causes the permissions on /boot, /lib/modules, and the kernel
52940+ source directory to change at compile time to prevent
52941+ reading by non-root users.
52942+ If the above conditions are met, this option will aid in providing a
52943+ useful protection against local kernel exploitation of overflows
52944+ and arbitrary read/write vulnerabilities.
52945+
52946+config GRKERNSEC_KERN_LOCKOUT
52947+ bool "Active kernel exploit response"
52948+ depends on X86 || ARM || PPC || SPARC
52949+ help
52950+ If you say Y here, when a PaX alert is triggered due to suspicious
52951+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52952+ or an OOPs occurs due to bad memory accesses, instead of just
52953+ terminating the offending process (and potentially allowing
52954+ a subsequent exploit from the same user), we will take one of two
52955+ actions:
52956+ If the user was root, we will panic the system
52957+ If the user was non-root, we will log the attempt, terminate
52958+ all processes owned by the user, then prevent them from creating
52959+ any new processes until the system is restarted
52960+ This deters repeated kernel exploitation/bruteforcing attempts
52961+ and is useful for later forensics.
52962+
52963+endmenu
52964+menu "Role Based Access Control Options"
52965+depends on GRKERNSEC
52966+
52967+config GRKERNSEC_RBAC_DEBUG
52968+ bool
52969+
52970+config GRKERNSEC_NO_RBAC
52971+ bool "Disable RBAC system"
52972+ help
52973+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52974+ preventing the RBAC system from being enabled. You should only say Y
52975+ here if you have no intention of using the RBAC system, so as to prevent
52976+ an attacker with root access from misusing the RBAC system to hide files
52977+ and processes when loadable module support and /dev/[k]mem have been
52978+ locked down.
52979+
52980+config GRKERNSEC_ACL_HIDEKERN
52981+ bool "Hide kernel processes"
52982+ help
52983+ If you say Y here, all kernel threads will be hidden to all
52984+ processes but those whose subject has the "view hidden processes"
52985+ flag.
52986+
52987+config GRKERNSEC_ACL_MAXTRIES
52988+ int "Maximum tries before password lockout"
52989+ default 3
52990+ help
52991+ This option enforces the maximum number of times a user can attempt
52992+ to authorize themselves with the grsecurity RBAC system before being
52993+ denied the ability to attempt authorization again for a specified time.
52994+ The lower the number, the harder it will be to brute-force a password.
52995+
52996+config GRKERNSEC_ACL_TIMEOUT
52997+ int "Time to wait after max password tries, in seconds"
52998+ default 30
52999+ help
53000+ This option specifies the time the user must wait after attempting to
53001+ authorize to the RBAC system with the maximum number of invalid
53002+ passwords. The higher the number, the harder it will be to brute-force
53003+ a password.
53004+
53005+endmenu
53006+menu "Filesystem Protections"
53007+depends on GRKERNSEC
53008+
53009+config GRKERNSEC_PROC
53010+ bool "Proc restrictions"
53011+ help
53012+ If you say Y here, the permissions of the /proc filesystem
53013+ will be altered to enhance system security and privacy. You MUST
53014+ choose either a user only restriction or a user and group restriction.
53015+ Depending upon the option you choose, you can either restrict users to
53016+ see only the processes they themselves run, or choose a group that can
53017+ view all processes and files normally restricted to root if you choose
53018+ the "restrict to user only" option. NOTE: If you're running identd as
53019+ a non-root user, you will have to run it as the group you specify here.
53020+
53021+config GRKERNSEC_PROC_USER
53022+ bool "Restrict /proc to user only"
53023+ depends on GRKERNSEC_PROC
53024+ help
53025+ If you say Y here, non-root users will only be able to view their own
53026+ processes, and restricts them from viewing network-related information,
53027+ and viewing kernel symbol and module information.
53028+
53029+config GRKERNSEC_PROC_USERGROUP
53030+ bool "Allow special group"
53031+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53032+ help
53033+ If you say Y here, you will be able to select a group that will be
53034+ able to view all processes and network-related information. If you've
53035+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53036+ remain hidden. This option is useful if you want to run identd as
53037+ a non-root user.
53038+
53039+config GRKERNSEC_PROC_GID
53040+ int "GID for special group"
53041+ depends on GRKERNSEC_PROC_USERGROUP
53042+ default 1001
53043+
53044+config GRKERNSEC_PROC_ADD
53045+ bool "Additional restrictions"
53046+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53047+ help
53048+ If you say Y here, additional restrictions will be placed on
53049+ /proc that keep normal users from viewing device information and
53050+ slabinfo information that could be useful for exploits.
53051+
53052+config GRKERNSEC_LINK
53053+ bool "Linking restrictions"
53054+ help
53055+ If you say Y here, /tmp race exploits will be prevented, since users
53056+ will no longer be able to follow symlinks owned by other users in
53057+ world-writable +t directories (e.g. /tmp), unless the owner of the
53058+ symlink is the owner of the directory. users will also not be
53059+ able to hardlink to files they do not own. If the sysctl option is
53060+ enabled, a sysctl option with name "linking_restrictions" is created.
53061+
53062+config GRKERNSEC_FIFO
53063+ bool "FIFO restrictions"
53064+ help
53065+ If you say Y here, users will not be able to write to FIFOs they don't
53066+ own in world-writable +t directories (e.g. /tmp), unless the owner of
53067+ the FIFO is the same owner of the directory it's held in. If the sysctl
53068+ option is enabled, a sysctl option with name "fifo_restrictions" is
53069+ created.
53070+
53071+config GRKERNSEC_SYSFS_RESTRICT
53072+ bool "Sysfs/debugfs restriction"
53073+ depends on SYSFS
53074+ help
53075+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53076+ any filesystem normally mounted under it (e.g. debugfs) will only
53077+ be accessible by root. These filesystems generally provide access
53078+ to hardware and debug information that isn't appropriate for unprivileged
53079+ users of the system. Sysfs and debugfs have also become a large source
53080+ of new vulnerabilities, ranging from infoleaks to local compromise.
53081+ There has been very little oversight with an eye toward security involved
53082+ in adding new exporters of information to these filesystems, so their
53083+ use is discouraged.
53084+ This option is equivalent to a chmod 0700 of the mount paths.
53085+
53086+config GRKERNSEC_ROFS
53087+ bool "Runtime read-only mount protection"
53088+ help
53089+ If you say Y here, a sysctl option with name "romount_protect" will
53090+ be created. By setting this option to 1 at runtime, filesystems
53091+ will be protected in the following ways:
53092+ * No new writable mounts will be allowed
53093+ * Existing read-only mounts won't be able to be remounted read/write
53094+ * Write operations will be denied on all block devices
53095+ This option acts independently of grsec_lock: once it is set to 1,
53096+ it cannot be turned off. Therefore, please be mindful of the resulting
53097+ behavior if this option is enabled in an init script on a read-only
53098+ filesystem. This feature is mainly intended for secure embedded systems.
53099+
53100+config GRKERNSEC_CHROOT
53101+ bool "Chroot jail restrictions"
53102+ help
53103+ If you say Y here, you will be able to choose several options that will
53104+ make breaking out of a chrooted jail much more difficult. If you
53105+ encounter no software incompatibilities with the following options, it
53106+ is recommended that you enable each one.
53107+
53108+config GRKERNSEC_CHROOT_MOUNT
53109+ bool "Deny mounts"
53110+ depends on GRKERNSEC_CHROOT
53111+ help
53112+ If you say Y here, processes inside a chroot will not be able to
53113+ mount or remount filesystems. If the sysctl option is enabled, a
53114+ sysctl option with name "chroot_deny_mount" is created.
53115+
53116+config GRKERNSEC_CHROOT_DOUBLE
53117+ bool "Deny double-chroots"
53118+ depends on GRKERNSEC_CHROOT
53119+ help
53120+ If you say Y here, processes inside a chroot will not be able to chroot
53121+ again outside the chroot. This is a widely used method of breaking
53122+ out of a chroot jail and should not be allowed. If the sysctl
53123+ option is enabled, a sysctl option with name
53124+ "chroot_deny_chroot" is created.
53125+
53126+config GRKERNSEC_CHROOT_PIVOT
53127+ bool "Deny pivot_root in chroot"
53128+ depends on GRKERNSEC_CHROOT
53129+ help
53130+ If you say Y here, processes inside a chroot will not be able to use
53131+ a function called pivot_root() that was introduced in Linux 2.3.41. It
53132+ works similar to chroot in that it changes the root filesystem. This
53133+ function could be misused in a chrooted process to attempt to break out
53134+ of the chroot, and therefore should not be allowed. If the sysctl
53135+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
53136+ created.
53137+
53138+config GRKERNSEC_CHROOT_CHDIR
53139+ bool "Enforce chdir(\"/\") on all chroots"
53140+ depends on GRKERNSEC_CHROOT
53141+ help
53142+ If you say Y here, the current working directory of all newly-chrooted
53143+ applications will be set to the the root directory of the chroot.
53144+ The man page on chroot(2) states:
53145+ Note that this call does not change the current working
53146+ directory, so that `.' can be outside the tree rooted at
53147+ `/'. In particular, the super-user can escape from a
53148+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53149+
53150+ It is recommended that you say Y here, since it's not known to break
53151+ any software. If the sysctl option is enabled, a sysctl option with
53152+ name "chroot_enforce_chdir" is created.
53153+
53154+config GRKERNSEC_CHROOT_CHMOD
53155+ bool "Deny (f)chmod +s"
53156+ depends on GRKERNSEC_CHROOT
53157+ help
53158+ If you say Y here, processes inside a chroot will not be able to chmod
53159+ or fchmod files to make them have suid or sgid bits. This protects
53160+ against another published method of breaking a chroot. If the sysctl
53161+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53162+ created.
53163+
53164+config GRKERNSEC_CHROOT_FCHDIR
53165+ bool "Deny fchdir out of chroot"
53166+ depends on GRKERNSEC_CHROOT
53167+ help
53168+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53169+ to a file descriptor of the chrooting process that points to a directory
53170+ outside the filesystem will be stopped. If the sysctl option
53171+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53172+
53173+config GRKERNSEC_CHROOT_MKNOD
53174+ bool "Deny mknod"
53175+ depends on GRKERNSEC_CHROOT
53176+ help
53177+ If you say Y here, processes inside a chroot will not be allowed to
53178+ mknod. The problem with using mknod inside a chroot is that it
53179+ would allow an attacker to create a device entry that is the same
53180+ as one on the physical root of your system, which could range from
53181+ anything from the console device to a device for your harddrive (which
53182+ they could then use to wipe the drive or steal data). It is recommended
53183+ that you say Y here, unless you run into software incompatibilities.
53184+ If the sysctl option is enabled, a sysctl option with name
53185+ "chroot_deny_mknod" is created.
53186+
53187+config GRKERNSEC_CHROOT_SHMAT
53188+ bool "Deny shmat() out of chroot"
53189+ depends on GRKERNSEC_CHROOT
53190+ help
53191+ If you say Y here, processes inside a chroot will not be able to attach
53192+ to shared memory segments that were created outside of the chroot jail.
53193+ It is recommended that you say Y here. If the sysctl option is enabled,
53194+ a sysctl option with name "chroot_deny_shmat" is created.
53195+
53196+config GRKERNSEC_CHROOT_UNIX
53197+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53198+ depends on GRKERNSEC_CHROOT
53199+ help
53200+ If you say Y here, processes inside a chroot will not be able to
53201+ connect to abstract (meaning not belonging to a filesystem) Unix
53202+ domain sockets that were bound outside of a chroot. It is recommended
53203+ that you say Y here. If the sysctl option is enabled, a sysctl option
53204+ with name "chroot_deny_unix" is created.
53205+
53206+config GRKERNSEC_CHROOT_FINDTASK
53207+ bool "Protect outside processes"
53208+ depends on GRKERNSEC_CHROOT
53209+ help
53210+ If you say Y here, processes inside a chroot will not be able to
53211+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53212+ getsid, or view any process outside of the chroot. If the sysctl
53213+ option is enabled, a sysctl option with name "chroot_findtask" is
53214+ created.
53215+
53216+config GRKERNSEC_CHROOT_NICE
53217+ bool "Restrict priority changes"
53218+ depends on GRKERNSEC_CHROOT
53219+ help
53220+ If you say Y here, processes inside a chroot will not be able to raise
53221+ the priority of processes in the chroot, or alter the priority of
53222+ processes outside the chroot. This provides more security than simply
53223+ removing CAP_SYS_NICE from the process' capability set. If the
53224+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53225+ is created.
53226+
53227+config GRKERNSEC_CHROOT_SYSCTL
53228+ bool "Deny sysctl writes"
53229+ depends on GRKERNSEC_CHROOT
53230+ help
53231+ If you say Y here, an attacker in a chroot will not be able to
53232+ write to sysctl entries, either by sysctl(2) or through a /proc
53233+ interface. It is strongly recommended that you say Y here. If the
53234+ sysctl option is enabled, a sysctl option with name
53235+ "chroot_deny_sysctl" is created.
53236+
53237+config GRKERNSEC_CHROOT_CAPS
53238+ bool "Capability restrictions"
53239+ depends on GRKERNSEC_CHROOT
53240+ help
53241+ If you say Y here, the capabilities on all processes within a
53242+ chroot jail will be lowered to stop module insertion, raw i/o,
53243+ system and net admin tasks, rebooting the system, modifying immutable
53244+ files, modifying IPC owned by another, and changing the system time.
53245+ This is left an option because it can break some apps. Disable this
53246+ if your chrooted apps are having problems performing those kinds of
53247+ tasks. If the sysctl option is enabled, a sysctl option with
53248+ name "chroot_caps" is created.
53249+
53250+endmenu
53251+menu "Kernel Auditing"
53252+depends on GRKERNSEC
53253+
53254+config GRKERNSEC_AUDIT_GROUP
53255+ bool "Single group for auditing"
53256+ help
53257+ If you say Y here, the exec, chdir, and (un)mount logging features
53258+ will only operate on a group you specify. This option is recommended
53259+ if you only want to watch certain users instead of having a large
53260+ amount of logs from the entire system. If the sysctl option is enabled,
53261+ a sysctl option with name "audit_group" is created.
53262+
53263+config GRKERNSEC_AUDIT_GID
53264+ int "GID for auditing"
53265+ depends on GRKERNSEC_AUDIT_GROUP
53266+ default 1007
53267+
53268+config GRKERNSEC_EXECLOG
53269+ bool "Exec logging"
53270+ help
53271+ If you say Y here, all execve() calls will be logged (since the
53272+ other exec*() calls are frontends to execve(), all execution
53273+ will be logged). Useful for shell-servers that like to keep track
53274+ of their users. If the sysctl option is enabled, a sysctl option with
53275+ name "exec_logging" is created.
53276+ WARNING: This option when enabled will produce a LOT of logs, especially
53277+ on an active system.
53278+
53279+config GRKERNSEC_RESLOG
53280+ bool "Resource logging"
53281+ help
53282+ If you say Y here, all attempts to overstep resource limits will
53283+ be logged with the resource name, the requested size, and the current
53284+ limit. It is highly recommended that you say Y here. If the sysctl
53285+ option is enabled, a sysctl option with name "resource_logging" is
53286+ created. If the RBAC system is enabled, the sysctl value is ignored.
53287+
53288+config GRKERNSEC_CHROOT_EXECLOG
53289+ bool "Log execs within chroot"
53290+ help
53291+ If you say Y here, all executions inside a chroot jail will be logged
53292+ to syslog. This can cause a large amount of logs if certain
53293+ applications (eg. djb's daemontools) are installed on the system, and
53294+ is therefore left as an option. If the sysctl option is enabled, a
53295+ sysctl option with name "chroot_execlog" is created.
53296+
53297+config GRKERNSEC_AUDIT_PTRACE
53298+ bool "Ptrace logging"
53299+ help
53300+ If you say Y here, all attempts to attach to a process via ptrace
53301+ will be logged. If the sysctl option is enabled, a sysctl option
53302+ with name "audit_ptrace" is created.
53303+
53304+config GRKERNSEC_AUDIT_CHDIR
53305+ bool "Chdir logging"
53306+ help
53307+ If you say Y here, all chdir() calls will be logged. If the sysctl
53308+ option is enabled, a sysctl option with name "audit_chdir" is created.
53309+
53310+config GRKERNSEC_AUDIT_MOUNT
53311+ bool "(Un)Mount logging"
53312+ help
53313+ If you say Y here, all mounts and unmounts will be logged. If the
53314+ sysctl option is enabled, a sysctl option with name "audit_mount" is
53315+ created.
53316+
53317+config GRKERNSEC_SIGNAL
53318+ bool "Signal logging"
53319+ help
53320+ If you say Y here, certain important signals will be logged, such as
53321+ SIGSEGV, which will as a result inform you of when a error in a program
53322+ occurred, which in some cases could mean a possible exploit attempt.
53323+ If the sysctl option is enabled, a sysctl option with name
53324+ "signal_logging" is created.
53325+
53326+config GRKERNSEC_FORKFAIL
53327+ bool "Fork failure logging"
53328+ help
53329+ If you say Y here, all failed fork() attempts will be logged.
53330+ This could suggest a fork bomb, or someone attempting to overstep
53331+ their process limit. If the sysctl option is enabled, a sysctl option
53332+ with name "forkfail_logging" is created.
53333+
53334+config GRKERNSEC_TIME
53335+ bool "Time change logging"
53336+ help
53337+ If you say Y here, any changes of the system clock will be logged.
53338+ If the sysctl option is enabled, a sysctl option with name
53339+ "timechange_logging" is created.
53340+
53341+config GRKERNSEC_PROC_IPADDR
53342+ bool "/proc/<pid>/ipaddr support"
53343+ help
53344+ If you say Y here, a new entry will be added to each /proc/<pid>
53345+ directory that contains the IP address of the person using the task.
53346+ The IP is carried across local TCP and AF_UNIX stream sockets.
53347+ This information can be useful for IDS/IPSes to perform remote response
53348+ to a local attack. The entry is readable by only the owner of the
53349+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53350+ the RBAC system), and thus does not create privacy concerns.
53351+
53352+config GRKERNSEC_RWXMAP_LOG
53353+ bool 'Denied RWX mmap/mprotect logging'
53354+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53355+ help
53356+ If you say Y here, calls to mmap() and mprotect() with explicit
53357+ usage of PROT_WRITE and PROT_EXEC together will be logged when
53358+ denied by the PAX_MPROTECT feature. If the sysctl option is
53359+ enabled, a sysctl option with name "rwxmap_logging" is created.
53360+
53361+config GRKERNSEC_AUDIT_TEXTREL
53362+ bool 'ELF text relocations logging (READ HELP)'
53363+ depends on PAX_MPROTECT
53364+ help
53365+ If you say Y here, text relocations will be logged with the filename
53366+ of the offending library or binary. The purpose of the feature is
53367+ to help Linux distribution developers get rid of libraries and
53368+ binaries that need text relocations which hinder the future progress
53369+ of PaX. Only Linux distribution developers should say Y here, and
53370+ never on a production machine, as this option creates an information
53371+ leak that could aid an attacker in defeating the randomization of
53372+ a single memory region. If the sysctl option is enabled, a sysctl
53373+ option with name "audit_textrel" is created.
53374+
53375+endmenu
53376+
53377+menu "Executable Protections"
53378+depends on GRKERNSEC
53379+
53380+config GRKERNSEC_DMESG
53381+ bool "Dmesg(8) restriction"
53382+ help
53383+ If you say Y here, non-root users will not be able to use dmesg(8)
53384+ to view up to the last 4kb of messages in the kernel's log buffer.
53385+ The kernel's log buffer often contains kernel addresses and other
53386+ identifying information useful to an attacker in fingerprinting a
53387+ system for a targeted exploit.
53388+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
53389+ created.
53390+
53391+config GRKERNSEC_HARDEN_PTRACE
53392+ bool "Deter ptrace-based process snooping"
53393+ help
53394+ If you say Y here, TTY sniffers and other malicious monitoring
53395+ programs implemented through ptrace will be defeated. If you
53396+ have been using the RBAC system, this option has already been
53397+ enabled for several years for all users, with the ability to make
53398+ fine-grained exceptions.
53399+
53400+ This option only affects the ability of non-root users to ptrace
53401+ processes that are not a descendent of the ptracing process.
53402+ This means that strace ./binary and gdb ./binary will still work,
53403+ but attaching to arbitrary processes will not. If the sysctl
53404+ option is enabled, a sysctl option with name "harden_ptrace" is
53405+ created.
53406+
53407+config GRKERNSEC_TPE
53408+ bool "Trusted Path Execution (TPE)"
53409+ help
53410+ If you say Y here, you will be able to choose a gid to add to the
53411+ supplementary groups of users you want to mark as "untrusted."
53412+ These users will not be able to execute any files that are not in
53413+ root-owned directories writable only by root. If the sysctl option
53414+ is enabled, a sysctl option with name "tpe" is created.
53415+
53416+config GRKERNSEC_TPE_ALL
53417+ bool "Partially restrict all non-root users"
53418+ depends on GRKERNSEC_TPE
53419+ help
53420+ If you say Y here, all non-root users will be covered under
53421+ a weaker TPE restriction. This is separate from, and in addition to,
53422+ the main TPE options that you have selected elsewhere. Thus, if a
53423+ "trusted" GID is chosen, this restriction applies to even that GID.
53424+ Under this restriction, all non-root users will only be allowed to
53425+ execute files in directories they own that are not group or
53426+ world-writable, or in directories owned by root and writable only by
53427+ root. If the sysctl option is enabled, a sysctl option with name
53428+ "tpe_restrict_all" is created.
53429+
53430+config GRKERNSEC_TPE_INVERT
53431+ bool "Invert GID option"
53432+ depends on GRKERNSEC_TPE
53433+ help
53434+ If you say Y here, the group you specify in the TPE configuration will
53435+ decide what group TPE restrictions will be *disabled* for. This
53436+ option is useful if you want TPE restrictions to be applied to most
53437+ users on the system. If the sysctl option is enabled, a sysctl option
53438+ with name "tpe_invert" is created. Unlike other sysctl options, this
53439+ entry will default to on for backward-compatibility.
53440+
53441+config GRKERNSEC_TPE_GID
53442+ int "GID for untrusted users"
53443+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53444+ default 1005
53445+ help
53446+ Setting this GID determines what group TPE restrictions will be
53447+ *enabled* for. If the sysctl option is enabled, a sysctl option
53448+ with name "tpe_gid" is created.
53449+
53450+config GRKERNSEC_TPE_GID
53451+ int "GID for trusted users"
53452+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53453+ default 1005
53454+ help
53455+ Setting this GID determines what group TPE restrictions will be
53456+ *disabled* for. If the sysctl option is enabled, a sysctl option
53457+ with name "tpe_gid" is created.
53458+
53459+endmenu
53460+menu "Network Protections"
53461+depends on GRKERNSEC
53462+
53463+config GRKERNSEC_RANDNET
53464+ bool "Larger entropy pools"
53465+ help
53466+ If you say Y here, the entropy pools used for many features of Linux
53467+ and grsecurity will be doubled in size. Since several grsecurity
53468+ features use additional randomness, it is recommended that you say Y
53469+ here. Saying Y here has a similar effect as modifying
53470+ /proc/sys/kernel/random/poolsize.
53471+
53472+config GRKERNSEC_BLACKHOLE
53473+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53474+ depends on NET
53475+ help
53476+ If you say Y here, neither TCP resets nor ICMP
53477+ destination-unreachable packets will be sent in response to packets
53478+ sent to ports for which no associated listening process exists.
53479+ This feature supports both IPV4 and IPV6 and exempts the
53480+ loopback interface from blackholing. Enabling this feature
53481+ makes a host more resilient to DoS attacks and reduces network
53482+ visibility against scanners.
53483+
53484+ The blackhole feature as-implemented is equivalent to the FreeBSD
53485+ blackhole feature, as it prevents RST responses to all packets, not
53486+ just SYNs. Under most application behavior this causes no
53487+ problems, but applications (like haproxy) may not close certain
53488+ connections in a way that cleanly terminates them on the remote
53489+ end, leaving the remote host in LAST_ACK state. Because of this
53490+ side-effect and to prevent intentional LAST_ACK DoSes, this
53491+ feature also adds automatic mitigation against such attacks.
53492+ The mitigation drastically reduces the amount of time a socket
53493+ can spend in LAST_ACK state. If you're using haproxy and not
53494+ all servers it connects to have this option enabled, consider
53495+ disabling this feature on the haproxy host.
53496+
53497+ If the sysctl option is enabled, two sysctl options with names
53498+ "ip_blackhole" and "lastack_retries" will be created.
53499+ While "ip_blackhole" takes the standard zero/non-zero on/off
53500+ toggle, "lastack_retries" uses the same kinds of values as
53501+ "tcp_retries1" and "tcp_retries2". The default value of 4
53502+ prevents a socket from lasting more than 45 seconds in LAST_ACK
53503+ state.
53504+
53505+config GRKERNSEC_SOCKET
53506+ bool "Socket restrictions"
53507+ depends on NET
53508+ help
53509+ If you say Y here, you will be able to choose from several options.
53510+ If you assign a GID on your system and add it to the supplementary
53511+ groups of users you want to restrict socket access to, this patch
53512+ will perform up to three things, based on the option(s) you choose.
53513+
53514+config GRKERNSEC_SOCKET_ALL
53515+ bool "Deny any sockets to group"
53516+ depends on GRKERNSEC_SOCKET
53517+ help
53518+ If you say Y here, you will be able to choose a GID of whose users will
53519+ be unable to connect to other hosts from your machine or run server
53520+ applications from your machine. If the sysctl option is enabled, a
53521+ sysctl option with name "socket_all" is created.
53522+
53523+config GRKERNSEC_SOCKET_ALL_GID
53524+ int "GID to deny all sockets for"
53525+ depends on GRKERNSEC_SOCKET_ALL
53526+ default 1004
53527+ help
53528+ Here you can choose the GID to disable socket access for. Remember to
53529+ add the users you want socket access disabled for to the GID
53530+ specified here. If the sysctl option is enabled, a sysctl option
53531+ with name "socket_all_gid" is created.
53532+
53533+config GRKERNSEC_SOCKET_CLIENT
53534+ bool "Deny client sockets to group"
53535+ depends on GRKERNSEC_SOCKET
53536+ help
53537+ If you say Y here, you will be able to choose a GID of whose users will
53538+ be unable to connect to other hosts from your machine, but will be
53539+ able to run servers. If this option is enabled, all users in the group
53540+ you specify will have to use passive mode when initiating ftp transfers
53541+ from the shell on your machine. If the sysctl option is enabled, a
53542+ sysctl option with name "socket_client" is created.
53543+
53544+config GRKERNSEC_SOCKET_CLIENT_GID
53545+ int "GID to deny client sockets for"
53546+ depends on GRKERNSEC_SOCKET_CLIENT
53547+ default 1003
53548+ help
53549+ Here you can choose the GID to disable client socket access for.
53550+ Remember to add the users you want client socket access disabled for to
53551+ the GID specified here. If the sysctl option is enabled, a sysctl
53552+ option with name "socket_client_gid" is created.
53553+
53554+config GRKERNSEC_SOCKET_SERVER
53555+ bool "Deny server sockets to group"
53556+ depends on GRKERNSEC_SOCKET
53557+ help
53558+ If you say Y here, you will be able to choose a GID of whose users will
53559+ be unable to run server applications from your machine. If the sysctl
53560+ option is enabled, a sysctl option with name "socket_server" is created.
53561+
53562+config GRKERNSEC_SOCKET_SERVER_GID
53563+ int "GID to deny server sockets for"
53564+ depends on GRKERNSEC_SOCKET_SERVER
53565+ default 1002
53566+ help
53567+ Here you can choose the GID to disable server socket access for.
53568+ Remember to add the users you want server socket access disabled for to
53569+ the GID specified here. If the sysctl option is enabled, a sysctl
53570+ option with name "socket_server_gid" is created.
53571+
53572+endmenu
53573+menu "Sysctl support"
53574+depends on GRKERNSEC && SYSCTL
53575+
53576+config GRKERNSEC_SYSCTL
53577+ bool "Sysctl support"
53578+ help
53579+ If you say Y here, you will be able to change the options that
53580+ grsecurity runs with at bootup, without having to recompile your
53581+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53582+ to enable (1) or disable (0) various features. All the sysctl entries
53583+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53584+ All features enabled in the kernel configuration are disabled at boot
53585+ if you do not say Y to the "Turn on features by default" option.
53586+ All options should be set at startup, and the grsec_lock entry should
53587+ be set to a non-zero value after all the options are set.
53588+ *THIS IS EXTREMELY IMPORTANT*
53589+
53590+config GRKERNSEC_SYSCTL_DISTRO
53591+ bool "Extra sysctl support for distro makers (READ HELP)"
53592+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53593+ help
53594+ If you say Y here, additional sysctl options will be created
53595+ for features that affect processes running as root. Therefore,
53596+ it is critical when using this option that the grsec_lock entry be
53597+ enabled after boot. Only distros with prebuilt kernel packages
53598+ with this option enabled that can ensure grsec_lock is enabled
53599+ after boot should use this option.
53600+ *Failure to set grsec_lock after boot makes all grsec features
53601+ this option covers useless*
53602+
53603+ Currently this option creates the following sysctl entries:
53604+ "Disable Privileged I/O": "disable_priv_io"
53605+
53606+config GRKERNSEC_SYSCTL_ON
53607+ bool "Turn on features by default"
53608+ depends on GRKERNSEC_SYSCTL
53609+ help
53610+ If you say Y here, instead of having all features enabled in the
53611+ kernel configuration disabled at boot time, the features will be
53612+ enabled at boot time. It is recommended you say Y here unless
53613+ there is some reason you would want all sysctl-tunable features to
53614+ be disabled by default. As mentioned elsewhere, it is important
53615+ to enable the grsec_lock entry once you have finished modifying
53616+ the sysctl entries.
53617+
53618+endmenu
53619+menu "Logging Options"
53620+depends on GRKERNSEC
53621+
53622+config GRKERNSEC_FLOODTIME
53623+ int "Seconds in between log messages (minimum)"
53624+ default 10
53625+ help
53626+ This option allows you to enforce the number of seconds between
53627+ grsecurity log messages. The default should be suitable for most
53628+ people, however, if you choose to change it, choose a value small enough
53629+ to allow informative logs to be produced, but large enough to
53630+ prevent flooding.
53631+
53632+config GRKERNSEC_FLOODBURST
53633+ int "Number of messages in a burst (maximum)"
53634+ default 6
53635+ help
53636+ This option allows you to choose the maximum number of messages allowed
53637+ within the flood time interval you chose in a separate option. The
53638+ default should be suitable for most people, however if you find that
53639+ many of your logs are being interpreted as flooding, you may want to
53640+ raise this value.
53641+
53642+endmenu
53643+
53644+endmenu
53645diff -urNp linux-3.0.4/grsecurity/Makefile linux-3.0.4/grsecurity/Makefile
53646--- linux-3.0.4/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
53647+++ linux-3.0.4/grsecurity/Makefile 2011-09-14 23:29:56.000000000 -0400
53648@@ -0,0 +1,35 @@
53649+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53650+# during 2001-2009 it has been completely redesigned by Brad Spengler
53651+# into an RBAC system
53652+#
53653+# All code in this directory and various hooks inserted throughout the kernel
53654+# are copyright Brad Spengler - Open Source Security, Inc., and released
53655+# under the GPL v2 or higher
53656+
53657+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53658+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
53659+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53660+
53661+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53662+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53663+ gracl_learn.o grsec_log.o
53664+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53665+
53666+ifdef CONFIG_NET
53667+obj-y += grsec_sock.o
53668+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53669+endif
53670+
53671+ifndef CONFIG_GRKERNSEC
53672+obj-y += grsec_disabled.o
53673+endif
53674+
53675+ifdef CONFIG_GRKERNSEC_HIDESYM
53676+extra-y := grsec_hidesym.o
53677+$(obj)/grsec_hidesym.o:
53678+ @-chmod -f 500 /boot
53679+ @-chmod -f 500 /lib/modules
53680+ @-chmod -f 500 /lib64/modules
53681+ @-chmod -f 700 .
53682+ @echo ' grsec: protected kernel image paths'
53683+endif
53684diff -urNp linux-3.0.4/include/acpi/acpi_bus.h linux-3.0.4/include/acpi/acpi_bus.h
53685--- linux-3.0.4/include/acpi/acpi_bus.h 2011-07-21 22:17:23.000000000 -0400
53686+++ linux-3.0.4/include/acpi/acpi_bus.h 2011-08-23 21:47:56.000000000 -0400
53687@@ -107,7 +107,7 @@ struct acpi_device_ops {
53688 acpi_op_bind bind;
53689 acpi_op_unbind unbind;
53690 acpi_op_notify notify;
53691-};
53692+} __no_const;
53693
53694 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
53695
53696diff -urNp linux-3.0.4/include/asm-generic/atomic-long.h linux-3.0.4/include/asm-generic/atomic-long.h
53697--- linux-3.0.4/include/asm-generic/atomic-long.h 2011-07-21 22:17:23.000000000 -0400
53698+++ linux-3.0.4/include/asm-generic/atomic-long.h 2011-08-23 21:47:56.000000000 -0400
53699@@ -22,6 +22,12 @@
53700
53701 typedef atomic64_t atomic_long_t;
53702
53703+#ifdef CONFIG_PAX_REFCOUNT
53704+typedef atomic64_unchecked_t atomic_long_unchecked_t;
53705+#else
53706+typedef atomic64_t atomic_long_unchecked_t;
53707+#endif
53708+
53709 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
53710
53711 static inline long atomic_long_read(atomic_long_t *l)
53712@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
53713 return (long)atomic64_read(v);
53714 }
53715
53716+#ifdef CONFIG_PAX_REFCOUNT
53717+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
53718+{
53719+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53720+
53721+ return (long)atomic64_read_unchecked(v);
53722+}
53723+#endif
53724+
53725 static inline void atomic_long_set(atomic_long_t *l, long i)
53726 {
53727 atomic64_t *v = (atomic64_t *)l;
53728@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
53729 atomic64_set(v, i);
53730 }
53731
53732+#ifdef CONFIG_PAX_REFCOUNT
53733+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
53734+{
53735+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53736+
53737+ atomic64_set_unchecked(v, i);
53738+}
53739+#endif
53740+
53741 static inline void atomic_long_inc(atomic_long_t *l)
53742 {
53743 atomic64_t *v = (atomic64_t *)l;
53744@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
53745 atomic64_inc(v);
53746 }
53747
53748+#ifdef CONFIG_PAX_REFCOUNT
53749+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
53750+{
53751+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53752+
53753+ atomic64_inc_unchecked(v);
53754+}
53755+#endif
53756+
53757 static inline void atomic_long_dec(atomic_long_t *l)
53758 {
53759 atomic64_t *v = (atomic64_t *)l;
53760@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
53761 atomic64_dec(v);
53762 }
53763
53764+#ifdef CONFIG_PAX_REFCOUNT
53765+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
53766+{
53767+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53768+
53769+ atomic64_dec_unchecked(v);
53770+}
53771+#endif
53772+
53773 static inline void atomic_long_add(long i, atomic_long_t *l)
53774 {
53775 atomic64_t *v = (atomic64_t *)l;
53776@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
53777 atomic64_add(i, v);
53778 }
53779
53780+#ifdef CONFIG_PAX_REFCOUNT
53781+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
53782+{
53783+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53784+
53785+ atomic64_add_unchecked(i, v);
53786+}
53787+#endif
53788+
53789 static inline void atomic_long_sub(long i, atomic_long_t *l)
53790 {
53791 atomic64_t *v = (atomic64_t *)l;
53792@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
53793 atomic64_sub(i, v);
53794 }
53795
53796+#ifdef CONFIG_PAX_REFCOUNT
53797+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
53798+{
53799+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53800+
53801+ atomic64_sub_unchecked(i, v);
53802+}
53803+#endif
53804+
53805 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
53806 {
53807 atomic64_t *v = (atomic64_t *)l;
53808@@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
53809 return (long)atomic64_inc_return(v);
53810 }
53811
53812+#ifdef CONFIG_PAX_REFCOUNT
53813+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
53814+{
53815+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53816+
53817+ return (long)atomic64_inc_return_unchecked(v);
53818+}
53819+#endif
53820+
53821 static inline long atomic_long_dec_return(atomic_long_t *l)
53822 {
53823 atomic64_t *v = (atomic64_t *)l;
53824@@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
53825
53826 typedef atomic_t atomic_long_t;
53827
53828+#ifdef CONFIG_PAX_REFCOUNT
53829+typedef atomic_unchecked_t atomic_long_unchecked_t;
53830+#else
53831+typedef atomic_t atomic_long_unchecked_t;
53832+#endif
53833+
53834 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
53835 static inline long atomic_long_read(atomic_long_t *l)
53836 {
53837@@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
53838 return (long)atomic_read(v);
53839 }
53840
53841+#ifdef CONFIG_PAX_REFCOUNT
53842+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
53843+{
53844+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53845+
53846+ return (long)atomic_read_unchecked(v);
53847+}
53848+#endif
53849+
53850 static inline void atomic_long_set(atomic_long_t *l, long i)
53851 {
53852 atomic_t *v = (atomic_t *)l;
53853@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
53854 atomic_set(v, i);
53855 }
53856
53857+#ifdef CONFIG_PAX_REFCOUNT
53858+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
53859+{
53860+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53861+
53862+ atomic_set_unchecked(v, i);
53863+}
53864+#endif
53865+
53866 static inline void atomic_long_inc(atomic_long_t *l)
53867 {
53868 atomic_t *v = (atomic_t *)l;
53869@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
53870 atomic_inc(v);
53871 }
53872
53873+#ifdef CONFIG_PAX_REFCOUNT
53874+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
53875+{
53876+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53877+
53878+ atomic_inc_unchecked(v);
53879+}
53880+#endif
53881+
53882 static inline void atomic_long_dec(atomic_long_t *l)
53883 {
53884 atomic_t *v = (atomic_t *)l;
53885@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
53886 atomic_dec(v);
53887 }
53888
53889+#ifdef CONFIG_PAX_REFCOUNT
53890+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
53891+{
53892+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53893+
53894+ atomic_dec_unchecked(v);
53895+}
53896+#endif
53897+
53898 static inline void atomic_long_add(long i, atomic_long_t *l)
53899 {
53900 atomic_t *v = (atomic_t *)l;
53901@@ -176,6 +287,15 @@ static inline void atomic_long_add(long
53902 atomic_add(i, v);
53903 }
53904
53905+#ifdef CONFIG_PAX_REFCOUNT
53906+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
53907+{
53908+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53909+
53910+ atomic_add_unchecked(i, v);
53911+}
53912+#endif
53913+
53914 static inline void atomic_long_sub(long i, atomic_long_t *l)
53915 {
53916 atomic_t *v = (atomic_t *)l;
53917@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
53918 atomic_sub(i, v);
53919 }
53920
53921+#ifdef CONFIG_PAX_REFCOUNT
53922+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
53923+{
53924+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53925+
53926+ atomic_sub_unchecked(i, v);
53927+}
53928+#endif
53929+
53930 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
53931 {
53932 atomic_t *v = (atomic_t *)l;
53933@@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
53934 return (long)atomic_inc_return(v);
53935 }
53936
53937+#ifdef CONFIG_PAX_REFCOUNT
53938+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
53939+{
53940+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53941+
53942+ return (long)atomic_inc_return_unchecked(v);
53943+}
53944+#endif
53945+
53946 static inline long atomic_long_dec_return(atomic_long_t *l)
53947 {
53948 atomic_t *v = (atomic_t *)l;
53949@@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
53950
53951 #endif /* BITS_PER_LONG == 64 */
53952
53953+#ifdef CONFIG_PAX_REFCOUNT
53954+static inline void pax_refcount_needs_these_functions(void)
53955+{
53956+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
53957+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
53958+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
53959+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
53960+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
53961+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
53962+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
53963+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
53964+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
53965+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
53966+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
53967+
53968+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
53969+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
53970+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
53971+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
53972+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
53973+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
53974+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
53975+}
53976+#else
53977+#define atomic_read_unchecked(v) atomic_read(v)
53978+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
53979+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
53980+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
53981+#define atomic_inc_unchecked(v) atomic_inc(v)
53982+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
53983+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
53984+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
53985+#define atomic_dec_unchecked(v) atomic_dec(v)
53986+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
53987+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
53988+
53989+#define atomic_long_read_unchecked(v) atomic_long_read(v)
53990+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
53991+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
53992+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
53993+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
53994+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
53995+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
53996+#endif
53997+
53998 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
53999diff -urNp linux-3.0.4/include/asm-generic/cache.h linux-3.0.4/include/asm-generic/cache.h
54000--- linux-3.0.4/include/asm-generic/cache.h 2011-07-21 22:17:23.000000000 -0400
54001+++ linux-3.0.4/include/asm-generic/cache.h 2011-08-23 21:47:56.000000000 -0400
54002@@ -6,7 +6,7 @@
54003 * cache lines need to provide their own cache.h.
54004 */
54005
54006-#define L1_CACHE_SHIFT 5
54007-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
54008+#define L1_CACHE_SHIFT 5UL
54009+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
54010
54011 #endif /* __ASM_GENERIC_CACHE_H */
54012diff -urNp linux-3.0.4/include/asm-generic/int-l64.h linux-3.0.4/include/asm-generic/int-l64.h
54013--- linux-3.0.4/include/asm-generic/int-l64.h 2011-07-21 22:17:23.000000000 -0400
54014+++ linux-3.0.4/include/asm-generic/int-l64.h 2011-08-23 21:47:56.000000000 -0400
54015@@ -46,6 +46,8 @@ typedef unsigned int u32;
54016 typedef signed long s64;
54017 typedef unsigned long u64;
54018
54019+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
54020+
54021 #define S8_C(x) x
54022 #define U8_C(x) x ## U
54023 #define S16_C(x) x
54024diff -urNp linux-3.0.4/include/asm-generic/int-ll64.h linux-3.0.4/include/asm-generic/int-ll64.h
54025--- linux-3.0.4/include/asm-generic/int-ll64.h 2011-07-21 22:17:23.000000000 -0400
54026+++ linux-3.0.4/include/asm-generic/int-ll64.h 2011-08-23 21:47:56.000000000 -0400
54027@@ -51,6 +51,8 @@ typedef unsigned int u32;
54028 typedef signed long long s64;
54029 typedef unsigned long long u64;
54030
54031+typedef unsigned long long intoverflow_t;
54032+
54033 #define S8_C(x) x
54034 #define U8_C(x) x ## U
54035 #define S16_C(x) x
54036diff -urNp linux-3.0.4/include/asm-generic/kmap_types.h linux-3.0.4/include/asm-generic/kmap_types.h
54037--- linux-3.0.4/include/asm-generic/kmap_types.h 2011-07-21 22:17:23.000000000 -0400
54038+++ linux-3.0.4/include/asm-generic/kmap_types.h 2011-08-23 21:47:56.000000000 -0400
54039@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
54040 KMAP_D(17) KM_NMI,
54041 KMAP_D(18) KM_NMI_PTE,
54042 KMAP_D(19) KM_KDB,
54043+KMAP_D(20) KM_CLEARPAGE,
54044 /*
54045 * Remember to update debug_kmap_atomic() when adding new kmap types!
54046 */
54047-KMAP_D(20) KM_TYPE_NR
54048+KMAP_D(21) KM_TYPE_NR
54049 };
54050
54051 #undef KMAP_D
54052diff -urNp linux-3.0.4/include/asm-generic/pgtable.h linux-3.0.4/include/asm-generic/pgtable.h
54053--- linux-3.0.4/include/asm-generic/pgtable.h 2011-07-21 22:17:23.000000000 -0400
54054+++ linux-3.0.4/include/asm-generic/pgtable.h 2011-08-23 21:47:56.000000000 -0400
54055@@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
54056 #endif /* __HAVE_ARCH_PMD_WRITE */
54057 #endif
54058
54059+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
54060+static inline unsigned long pax_open_kernel(void) { return 0; }
54061+#endif
54062+
54063+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
54064+static inline unsigned long pax_close_kernel(void) { return 0; }
54065+#endif
54066+
54067 #endif /* !__ASSEMBLY__ */
54068
54069 #endif /* _ASM_GENERIC_PGTABLE_H */
54070diff -urNp linux-3.0.4/include/asm-generic/pgtable-nopmd.h linux-3.0.4/include/asm-generic/pgtable-nopmd.h
54071--- linux-3.0.4/include/asm-generic/pgtable-nopmd.h 2011-07-21 22:17:23.000000000 -0400
54072+++ linux-3.0.4/include/asm-generic/pgtable-nopmd.h 2011-08-23 21:47:56.000000000 -0400
54073@@ -1,14 +1,19 @@
54074 #ifndef _PGTABLE_NOPMD_H
54075 #define _PGTABLE_NOPMD_H
54076
54077-#ifndef __ASSEMBLY__
54078-
54079 #include <asm-generic/pgtable-nopud.h>
54080
54081-struct mm_struct;
54082-
54083 #define __PAGETABLE_PMD_FOLDED
54084
54085+#define PMD_SHIFT PUD_SHIFT
54086+#define PTRS_PER_PMD 1
54087+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
54088+#define PMD_MASK (~(PMD_SIZE-1))
54089+
54090+#ifndef __ASSEMBLY__
54091+
54092+struct mm_struct;
54093+
54094 /*
54095 * Having the pmd type consist of a pud gets the size right, and allows
54096 * us to conceptually access the pud entry that this pmd is folded into
54097@@ -16,11 +21,6 @@ struct mm_struct;
54098 */
54099 typedef struct { pud_t pud; } pmd_t;
54100
54101-#define PMD_SHIFT PUD_SHIFT
54102-#define PTRS_PER_PMD 1
54103-#define PMD_SIZE (1UL << PMD_SHIFT)
54104-#define PMD_MASK (~(PMD_SIZE-1))
54105-
54106 /*
54107 * The "pud_xxx()" functions here are trivial for a folded two-level
54108 * setup: the pmd is never bad, and a pmd always exists (as it's folded
54109diff -urNp linux-3.0.4/include/asm-generic/pgtable-nopud.h linux-3.0.4/include/asm-generic/pgtable-nopud.h
54110--- linux-3.0.4/include/asm-generic/pgtable-nopud.h 2011-07-21 22:17:23.000000000 -0400
54111+++ linux-3.0.4/include/asm-generic/pgtable-nopud.h 2011-08-23 21:47:56.000000000 -0400
54112@@ -1,10 +1,15 @@
54113 #ifndef _PGTABLE_NOPUD_H
54114 #define _PGTABLE_NOPUD_H
54115
54116-#ifndef __ASSEMBLY__
54117-
54118 #define __PAGETABLE_PUD_FOLDED
54119
54120+#define PUD_SHIFT PGDIR_SHIFT
54121+#define PTRS_PER_PUD 1
54122+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
54123+#define PUD_MASK (~(PUD_SIZE-1))
54124+
54125+#ifndef __ASSEMBLY__
54126+
54127 /*
54128 * Having the pud type consist of a pgd gets the size right, and allows
54129 * us to conceptually access the pgd entry that this pud is folded into
54130@@ -12,11 +17,6 @@
54131 */
54132 typedef struct { pgd_t pgd; } pud_t;
54133
54134-#define PUD_SHIFT PGDIR_SHIFT
54135-#define PTRS_PER_PUD 1
54136-#define PUD_SIZE (1UL << PUD_SHIFT)
54137-#define PUD_MASK (~(PUD_SIZE-1))
54138-
54139 /*
54140 * The "pgd_xxx()" functions here are trivial for a folded two-level
54141 * setup: the pud is never bad, and a pud always exists (as it's folded
54142diff -urNp linux-3.0.4/include/asm-generic/vmlinux.lds.h linux-3.0.4/include/asm-generic/vmlinux.lds.h
54143--- linux-3.0.4/include/asm-generic/vmlinux.lds.h 2011-07-21 22:17:23.000000000 -0400
54144+++ linux-3.0.4/include/asm-generic/vmlinux.lds.h 2011-08-23 21:47:56.000000000 -0400
54145@@ -217,6 +217,7 @@
54146 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
54147 VMLINUX_SYMBOL(__start_rodata) = .; \
54148 *(.rodata) *(.rodata.*) \
54149+ *(.data..read_only) \
54150 *(__vermagic) /* Kernel version magic */ \
54151 . = ALIGN(8); \
54152 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
54153@@ -723,17 +724,18 @@
54154 * section in the linker script will go there too. @phdr should have
54155 * a leading colon.
54156 *
54157- * Note that this macros defines __per_cpu_load as an absolute symbol.
54158+ * Note that this macros defines per_cpu_load as an absolute symbol.
54159 * If there is no need to put the percpu section at a predetermined
54160 * address, use PERCPU_SECTION.
54161 */
54162 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
54163- VMLINUX_SYMBOL(__per_cpu_load) = .; \
54164- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
54165+ per_cpu_load = .; \
54166+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
54167 - LOAD_OFFSET) { \
54168+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
54169 PERCPU_INPUT(cacheline) \
54170 } phdr \
54171- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
54172+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
54173
54174 /**
54175 * PERCPU_SECTION - define output section for percpu area, simple version
54176diff -urNp linux-3.0.4/include/drm/drm_crtc_helper.h linux-3.0.4/include/drm/drm_crtc_helper.h
54177--- linux-3.0.4/include/drm/drm_crtc_helper.h 2011-07-21 22:17:23.000000000 -0400
54178+++ linux-3.0.4/include/drm/drm_crtc_helper.h 2011-08-23 21:47:56.000000000 -0400
54179@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
54180
54181 /* disable crtc when not in use - more explicit than dpms off */
54182 void (*disable)(struct drm_crtc *crtc);
54183-};
54184+} __no_const;
54185
54186 struct drm_encoder_helper_funcs {
54187 void (*dpms)(struct drm_encoder *encoder, int mode);
54188@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
54189 struct drm_connector *connector);
54190 /* disable encoder when not in use - more explicit than dpms off */
54191 void (*disable)(struct drm_encoder *encoder);
54192-};
54193+} __no_const;
54194
54195 struct drm_connector_helper_funcs {
54196 int (*get_modes)(struct drm_connector *connector);
54197diff -urNp linux-3.0.4/include/drm/drmP.h linux-3.0.4/include/drm/drmP.h
54198--- linux-3.0.4/include/drm/drmP.h 2011-07-21 22:17:23.000000000 -0400
54199+++ linux-3.0.4/include/drm/drmP.h 2011-08-23 21:47:56.000000000 -0400
54200@@ -73,6 +73,7 @@
54201 #include <linux/workqueue.h>
54202 #include <linux/poll.h>
54203 #include <asm/pgalloc.h>
54204+#include <asm/local.h>
54205 #include "drm.h"
54206
54207 #include <linux/idr.h>
54208@@ -1033,7 +1034,7 @@ struct drm_device {
54209
54210 /** \name Usage Counters */
54211 /*@{ */
54212- int open_count; /**< Outstanding files open */
54213+ local_t open_count; /**< Outstanding files open */
54214 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
54215 atomic_t vma_count; /**< Outstanding vma areas open */
54216 int buf_use; /**< Buffers in use -- cannot alloc */
54217@@ -1044,7 +1045,7 @@ struct drm_device {
54218 /*@{ */
54219 unsigned long counters;
54220 enum drm_stat_type types[15];
54221- atomic_t counts[15];
54222+ atomic_unchecked_t counts[15];
54223 /*@} */
54224
54225 struct list_head filelist;
54226diff -urNp linux-3.0.4/include/drm/ttm/ttm_memory.h linux-3.0.4/include/drm/ttm/ttm_memory.h
54227--- linux-3.0.4/include/drm/ttm/ttm_memory.h 2011-07-21 22:17:23.000000000 -0400
54228+++ linux-3.0.4/include/drm/ttm/ttm_memory.h 2011-08-23 21:47:56.000000000 -0400
54229@@ -47,7 +47,7 @@
54230
54231 struct ttm_mem_shrink {
54232 int (*do_shrink) (struct ttm_mem_shrink *);
54233-};
54234+} __no_const;
54235
54236 /**
54237 * struct ttm_mem_global - Global memory accounting structure.
54238diff -urNp linux-3.0.4/include/linux/a.out.h linux-3.0.4/include/linux/a.out.h
54239--- linux-3.0.4/include/linux/a.out.h 2011-07-21 22:17:23.000000000 -0400
54240+++ linux-3.0.4/include/linux/a.out.h 2011-08-23 21:47:56.000000000 -0400
54241@@ -39,6 +39,14 @@ enum machine_type {
54242 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
54243 };
54244
54245+/* Constants for the N_FLAGS field */
54246+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
54247+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
54248+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
54249+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
54250+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
54251+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
54252+
54253 #if !defined (N_MAGIC)
54254 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
54255 #endif
54256diff -urNp linux-3.0.4/include/linux/atmdev.h linux-3.0.4/include/linux/atmdev.h
54257--- linux-3.0.4/include/linux/atmdev.h 2011-07-21 22:17:23.000000000 -0400
54258+++ linux-3.0.4/include/linux/atmdev.h 2011-08-23 21:47:56.000000000 -0400
54259@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
54260 #endif
54261
54262 struct k_atm_aal_stats {
54263-#define __HANDLE_ITEM(i) atomic_t i
54264+#define __HANDLE_ITEM(i) atomic_unchecked_t i
54265 __AAL_STAT_ITEMS
54266 #undef __HANDLE_ITEM
54267 };
54268diff -urNp linux-3.0.4/include/linux/binfmts.h linux-3.0.4/include/linux/binfmts.h
54269--- linux-3.0.4/include/linux/binfmts.h 2011-07-21 22:17:23.000000000 -0400
54270+++ linux-3.0.4/include/linux/binfmts.h 2011-08-23 21:47:56.000000000 -0400
54271@@ -88,6 +88,7 @@ struct linux_binfmt {
54272 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
54273 int (*load_shlib)(struct file *);
54274 int (*core_dump)(struct coredump_params *cprm);
54275+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
54276 unsigned long min_coredump; /* minimal dump size */
54277 };
54278
54279diff -urNp linux-3.0.4/include/linux/blkdev.h linux-3.0.4/include/linux/blkdev.h
54280--- linux-3.0.4/include/linux/blkdev.h 2011-07-21 22:17:23.000000000 -0400
54281+++ linux-3.0.4/include/linux/blkdev.h 2011-08-26 19:49:56.000000000 -0400
54282@@ -1308,7 +1308,7 @@ struct block_device_operations {
54283 /* this callback is with swap_lock and sometimes page table lock held */
54284 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
54285 struct module *owner;
54286-};
54287+} __do_const;
54288
54289 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
54290 unsigned long);
54291diff -urNp linux-3.0.4/include/linux/blktrace_api.h linux-3.0.4/include/linux/blktrace_api.h
54292--- linux-3.0.4/include/linux/blktrace_api.h 2011-07-21 22:17:23.000000000 -0400
54293+++ linux-3.0.4/include/linux/blktrace_api.h 2011-08-23 21:47:56.000000000 -0400
54294@@ -161,7 +161,7 @@ struct blk_trace {
54295 struct dentry *dir;
54296 struct dentry *dropped_file;
54297 struct dentry *msg_file;
54298- atomic_t dropped;
54299+ atomic_unchecked_t dropped;
54300 };
54301
54302 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
54303diff -urNp linux-3.0.4/include/linux/byteorder/little_endian.h linux-3.0.4/include/linux/byteorder/little_endian.h
54304--- linux-3.0.4/include/linux/byteorder/little_endian.h 2011-07-21 22:17:23.000000000 -0400
54305+++ linux-3.0.4/include/linux/byteorder/little_endian.h 2011-08-23 21:47:56.000000000 -0400
54306@@ -42,51 +42,51 @@
54307
54308 static inline __le64 __cpu_to_le64p(const __u64 *p)
54309 {
54310- return (__force __le64)*p;
54311+ return (__force const __le64)*p;
54312 }
54313 static inline __u64 __le64_to_cpup(const __le64 *p)
54314 {
54315- return (__force __u64)*p;
54316+ return (__force const __u64)*p;
54317 }
54318 static inline __le32 __cpu_to_le32p(const __u32 *p)
54319 {
54320- return (__force __le32)*p;
54321+ return (__force const __le32)*p;
54322 }
54323 static inline __u32 __le32_to_cpup(const __le32 *p)
54324 {
54325- return (__force __u32)*p;
54326+ return (__force const __u32)*p;
54327 }
54328 static inline __le16 __cpu_to_le16p(const __u16 *p)
54329 {
54330- return (__force __le16)*p;
54331+ return (__force const __le16)*p;
54332 }
54333 static inline __u16 __le16_to_cpup(const __le16 *p)
54334 {
54335- return (__force __u16)*p;
54336+ return (__force const __u16)*p;
54337 }
54338 static inline __be64 __cpu_to_be64p(const __u64 *p)
54339 {
54340- return (__force __be64)__swab64p(p);
54341+ return (__force const __be64)__swab64p(p);
54342 }
54343 static inline __u64 __be64_to_cpup(const __be64 *p)
54344 {
54345- return __swab64p((__u64 *)p);
54346+ return __swab64p((const __u64 *)p);
54347 }
54348 static inline __be32 __cpu_to_be32p(const __u32 *p)
54349 {
54350- return (__force __be32)__swab32p(p);
54351+ return (__force const __be32)__swab32p(p);
54352 }
54353 static inline __u32 __be32_to_cpup(const __be32 *p)
54354 {
54355- return __swab32p((__u32 *)p);
54356+ return __swab32p((const __u32 *)p);
54357 }
54358 static inline __be16 __cpu_to_be16p(const __u16 *p)
54359 {
54360- return (__force __be16)__swab16p(p);
54361+ return (__force const __be16)__swab16p(p);
54362 }
54363 static inline __u16 __be16_to_cpup(const __be16 *p)
54364 {
54365- return __swab16p((__u16 *)p);
54366+ return __swab16p((const __u16 *)p);
54367 }
54368 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
54369 #define __le64_to_cpus(x) do { (void)(x); } while (0)
54370diff -urNp linux-3.0.4/include/linux/cache.h linux-3.0.4/include/linux/cache.h
54371--- linux-3.0.4/include/linux/cache.h 2011-07-21 22:17:23.000000000 -0400
54372+++ linux-3.0.4/include/linux/cache.h 2011-08-23 21:47:56.000000000 -0400
54373@@ -16,6 +16,10 @@
54374 #define __read_mostly
54375 #endif
54376
54377+#ifndef __read_only
54378+#define __read_only __read_mostly
54379+#endif
54380+
54381 #ifndef ____cacheline_aligned
54382 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
54383 #endif
54384diff -urNp linux-3.0.4/include/linux/capability.h linux-3.0.4/include/linux/capability.h
54385--- linux-3.0.4/include/linux/capability.h 2011-07-21 22:17:23.000000000 -0400
54386+++ linux-3.0.4/include/linux/capability.h 2011-08-23 21:48:14.000000000 -0400
54387@@ -547,6 +547,9 @@ extern bool capable(int cap);
54388 extern bool ns_capable(struct user_namespace *ns, int cap);
54389 extern bool task_ns_capable(struct task_struct *t, int cap);
54390 extern bool nsown_capable(int cap);
54391+extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
54392+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
54393+extern bool capable_nolog(int cap);
54394
54395 /* audit system wants to get cap info from files as well */
54396 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
54397diff -urNp linux-3.0.4/include/linux/cleancache.h linux-3.0.4/include/linux/cleancache.h
54398--- linux-3.0.4/include/linux/cleancache.h 2011-07-21 22:17:23.000000000 -0400
54399+++ linux-3.0.4/include/linux/cleancache.h 2011-08-23 21:47:56.000000000 -0400
54400@@ -31,7 +31,7 @@ struct cleancache_ops {
54401 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
54402 void (*flush_inode)(int, struct cleancache_filekey);
54403 void (*flush_fs)(int);
54404-};
54405+} __no_const;
54406
54407 extern struct cleancache_ops
54408 cleancache_register_ops(struct cleancache_ops *ops);
54409diff -urNp linux-3.0.4/include/linux/compiler-gcc4.h linux-3.0.4/include/linux/compiler-gcc4.h
54410--- linux-3.0.4/include/linux/compiler-gcc4.h 2011-07-21 22:17:23.000000000 -0400
54411+++ linux-3.0.4/include/linux/compiler-gcc4.h 2011-08-26 19:49:56.000000000 -0400
54412@@ -31,6 +31,12 @@
54413
54414
54415 #if __GNUC_MINOR__ >= 5
54416+
54417+#ifdef CONSTIFY_PLUGIN
54418+#define __no_const __attribute__((no_const))
54419+#define __do_const __attribute__((do_const))
54420+#endif
54421+
54422 /*
54423 * Mark a position in code as unreachable. This can be used to
54424 * suppress control flow warnings after asm blocks that transfer
54425@@ -46,6 +52,11 @@
54426 #define __noclone __attribute__((__noclone__))
54427
54428 #endif
54429+
54430+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
54431+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
54432+#define __bos0(ptr) __bos((ptr), 0)
54433+#define __bos1(ptr) __bos((ptr), 1)
54434 #endif
54435
54436 #if __GNUC_MINOR__ > 0
54437diff -urNp linux-3.0.4/include/linux/compiler.h linux-3.0.4/include/linux/compiler.h
54438--- linux-3.0.4/include/linux/compiler.h 2011-07-21 22:17:23.000000000 -0400
54439+++ linux-3.0.4/include/linux/compiler.h 2011-08-26 19:49:56.000000000 -0400
54440@@ -264,6 +264,14 @@ void ftrace_likely_update(struct ftrace_
54441 # define __attribute_const__ /* unimplemented */
54442 #endif
54443
54444+#ifndef __no_const
54445+# define __no_const
54446+#endif
54447+
54448+#ifndef __do_const
54449+# define __do_const
54450+#endif
54451+
54452 /*
54453 * Tell gcc if a function is cold. The compiler will assume any path
54454 * directly leading to the call is unlikely.
54455@@ -273,6 +281,22 @@ void ftrace_likely_update(struct ftrace_
54456 #define __cold
54457 #endif
54458
54459+#ifndef __alloc_size
54460+#define __alloc_size(...)
54461+#endif
54462+
54463+#ifndef __bos
54464+#define __bos(ptr, arg)
54465+#endif
54466+
54467+#ifndef __bos0
54468+#define __bos0(ptr)
54469+#endif
54470+
54471+#ifndef __bos1
54472+#define __bos1(ptr)
54473+#endif
54474+
54475 /* Simple shorthand for a section definition */
54476 #ifndef __section
54477 # define __section(S) __attribute__ ((__section__(#S)))
54478@@ -306,6 +330,7 @@ void ftrace_likely_update(struct ftrace_
54479 * use is to mediate communication between process-level code and irq/NMI
54480 * handlers, all running on the same CPU.
54481 */
54482-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
54483+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
54484+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
54485
54486 #endif /* __LINUX_COMPILER_H */
54487diff -urNp linux-3.0.4/include/linux/cpuset.h linux-3.0.4/include/linux/cpuset.h
54488--- linux-3.0.4/include/linux/cpuset.h 2011-07-21 22:17:23.000000000 -0400
54489+++ linux-3.0.4/include/linux/cpuset.h 2011-08-23 21:47:56.000000000 -0400
54490@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
54491 * nodemask.
54492 */
54493 smp_mb();
54494- --ACCESS_ONCE(current->mems_allowed_change_disable);
54495+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
54496 }
54497
54498 static inline void set_mems_allowed(nodemask_t nodemask)
54499diff -urNp linux-3.0.4/include/linux/crypto.h linux-3.0.4/include/linux/crypto.h
54500--- linux-3.0.4/include/linux/crypto.h 2011-07-21 22:17:23.000000000 -0400
54501+++ linux-3.0.4/include/linux/crypto.h 2011-08-23 21:47:56.000000000 -0400
54502@@ -361,7 +361,7 @@ struct cipher_tfm {
54503 const u8 *key, unsigned int keylen);
54504 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
54505 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
54506-};
54507+} __no_const;
54508
54509 struct hash_tfm {
54510 int (*init)(struct hash_desc *desc);
54511@@ -382,13 +382,13 @@ struct compress_tfm {
54512 int (*cot_decompress)(struct crypto_tfm *tfm,
54513 const u8 *src, unsigned int slen,
54514 u8 *dst, unsigned int *dlen);
54515-};
54516+} __no_const;
54517
54518 struct rng_tfm {
54519 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
54520 unsigned int dlen);
54521 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
54522-};
54523+} __no_const;
54524
54525 #define crt_ablkcipher crt_u.ablkcipher
54526 #define crt_aead crt_u.aead
54527diff -urNp linux-3.0.4/include/linux/decompress/mm.h linux-3.0.4/include/linux/decompress/mm.h
54528--- linux-3.0.4/include/linux/decompress/mm.h 2011-07-21 22:17:23.000000000 -0400
54529+++ linux-3.0.4/include/linux/decompress/mm.h 2011-08-23 21:47:56.000000000 -0400
54530@@ -77,7 +77,7 @@ static void free(void *where)
54531 * warnings when not needed (indeed large_malloc / large_free are not
54532 * needed by inflate */
54533
54534-#define malloc(a) kmalloc(a, GFP_KERNEL)
54535+#define malloc(a) kmalloc((a), GFP_KERNEL)
54536 #define free(a) kfree(a)
54537
54538 #define large_malloc(a) vmalloc(a)
54539diff -urNp linux-3.0.4/include/linux/dma-mapping.h linux-3.0.4/include/linux/dma-mapping.h
54540--- linux-3.0.4/include/linux/dma-mapping.h 2011-07-21 22:17:23.000000000 -0400
54541+++ linux-3.0.4/include/linux/dma-mapping.h 2011-08-26 19:49:56.000000000 -0400
54542@@ -50,7 +50,7 @@ struct dma_map_ops {
54543 int (*dma_supported)(struct device *dev, u64 mask);
54544 int (*set_dma_mask)(struct device *dev, u64 mask);
54545 int is_phys;
54546-};
54547+} __do_const;
54548
54549 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
54550
54551diff -urNp linux-3.0.4/include/linux/efi.h linux-3.0.4/include/linux/efi.h
54552--- linux-3.0.4/include/linux/efi.h 2011-07-21 22:17:23.000000000 -0400
54553+++ linux-3.0.4/include/linux/efi.h 2011-08-23 21:47:56.000000000 -0400
54554@@ -410,7 +410,7 @@ struct efivar_operations {
54555 efi_get_variable_t *get_variable;
54556 efi_get_next_variable_t *get_next_variable;
54557 efi_set_variable_t *set_variable;
54558-};
54559+} __no_const;
54560
54561 struct efivars {
54562 /*
54563diff -urNp linux-3.0.4/include/linux/elf.h linux-3.0.4/include/linux/elf.h
54564--- linux-3.0.4/include/linux/elf.h 2011-07-21 22:17:23.000000000 -0400
54565+++ linux-3.0.4/include/linux/elf.h 2011-08-23 21:47:56.000000000 -0400
54566@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
54567 #define PT_GNU_EH_FRAME 0x6474e550
54568
54569 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
54570+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
54571+
54572+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
54573+
54574+/* Constants for the e_flags field */
54575+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
54576+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
54577+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
54578+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
54579+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
54580+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
54581
54582 /*
54583 * Extended Numbering
54584@@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
54585 #define DT_DEBUG 21
54586 #define DT_TEXTREL 22
54587 #define DT_JMPREL 23
54588+#define DT_FLAGS 30
54589+ #define DF_TEXTREL 0x00000004
54590 #define DT_ENCODING 32
54591 #define OLD_DT_LOOS 0x60000000
54592 #define DT_LOOS 0x6000000d
54593@@ -252,6 +265,19 @@ typedef struct elf64_hdr {
54594 #define PF_W 0x2
54595 #define PF_X 0x1
54596
54597+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
54598+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
54599+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
54600+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
54601+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
54602+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
54603+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
54604+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
54605+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
54606+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
54607+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
54608+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
54609+
54610 typedef struct elf32_phdr{
54611 Elf32_Word p_type;
54612 Elf32_Off p_offset;
54613@@ -344,6 +370,8 @@ typedef struct elf64_shdr {
54614 #define EI_OSABI 7
54615 #define EI_PAD 8
54616
54617+#define EI_PAX 14
54618+
54619 #define ELFMAG0 0x7f /* EI_MAG */
54620 #define ELFMAG1 'E'
54621 #define ELFMAG2 'L'
54622@@ -422,6 +450,7 @@ extern Elf32_Dyn _DYNAMIC [];
54623 #define elf_note elf32_note
54624 #define elf_addr_t Elf32_Off
54625 #define Elf_Half Elf32_Half
54626+#define elf_dyn Elf32_Dyn
54627
54628 #else
54629
54630@@ -432,6 +461,7 @@ extern Elf64_Dyn _DYNAMIC [];
54631 #define elf_note elf64_note
54632 #define elf_addr_t Elf64_Off
54633 #define Elf_Half Elf64_Half
54634+#define elf_dyn Elf64_Dyn
54635
54636 #endif
54637
54638diff -urNp linux-3.0.4/include/linux/firewire.h linux-3.0.4/include/linux/firewire.h
54639--- linux-3.0.4/include/linux/firewire.h 2011-07-21 22:17:23.000000000 -0400
54640+++ linux-3.0.4/include/linux/firewire.h 2011-08-23 21:47:56.000000000 -0400
54641@@ -428,7 +428,7 @@ struct fw_iso_context {
54642 union {
54643 fw_iso_callback_t sc;
54644 fw_iso_mc_callback_t mc;
54645- } callback;
54646+ } __no_const callback;
54647 void *callback_data;
54648 };
54649
54650diff -urNp linux-3.0.4/include/linux/fscache-cache.h linux-3.0.4/include/linux/fscache-cache.h
54651--- linux-3.0.4/include/linux/fscache-cache.h 2011-07-21 22:17:23.000000000 -0400
54652+++ linux-3.0.4/include/linux/fscache-cache.h 2011-08-23 21:47:56.000000000 -0400
54653@@ -102,7 +102,7 @@ struct fscache_operation {
54654 fscache_operation_release_t release;
54655 };
54656
54657-extern atomic_t fscache_op_debug_id;
54658+extern atomic_unchecked_t fscache_op_debug_id;
54659 extern void fscache_op_work_func(struct work_struct *work);
54660
54661 extern void fscache_enqueue_operation(struct fscache_operation *);
54662@@ -122,7 +122,7 @@ static inline void fscache_operation_ini
54663 {
54664 INIT_WORK(&op->work, fscache_op_work_func);
54665 atomic_set(&op->usage, 1);
54666- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
54667+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
54668 op->processor = processor;
54669 op->release = release;
54670 INIT_LIST_HEAD(&op->pend_link);
54671diff -urNp linux-3.0.4/include/linux/fs.h linux-3.0.4/include/linux/fs.h
54672--- linux-3.0.4/include/linux/fs.h 2011-07-21 22:17:23.000000000 -0400
54673+++ linux-3.0.4/include/linux/fs.h 2011-08-26 19:49:56.000000000 -0400
54674@@ -109,6 +109,11 @@ struct inodes_stat_t {
54675 /* File was opened by fanotify and shouldn't generate fanotify events */
54676 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
54677
54678+/* Hack for grsec so as not to require read permission simply to execute
54679+ * a binary
54680+ */
54681+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
54682+
54683 /*
54684 * The below are the various read and write types that we support. Some of
54685 * them include behavioral modifiers that send information down to the
54686@@ -1571,7 +1576,8 @@ struct file_operations {
54687 int (*setlease)(struct file *, long, struct file_lock **);
54688 long (*fallocate)(struct file *file, int mode, loff_t offset,
54689 loff_t len);
54690-};
54691+} __do_const;
54692+typedef struct file_operations __no_const file_operations_no_const;
54693
54694 #define IPERM_FLAG_RCU 0x0001
54695
54696diff -urNp linux-3.0.4/include/linux/fsnotify.h linux-3.0.4/include/linux/fsnotify.h
54697--- linux-3.0.4/include/linux/fsnotify.h 2011-07-21 22:17:23.000000000 -0400
54698+++ linux-3.0.4/include/linux/fsnotify.h 2011-08-24 18:10:29.000000000 -0400
54699@@ -314,7 +314,7 @@ static inline void fsnotify_change(struc
54700 */
54701 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
54702 {
54703- return kstrdup(name, GFP_KERNEL);
54704+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
54705 }
54706
54707 /*
54708diff -urNp linux-3.0.4/include/linux/fs_struct.h linux-3.0.4/include/linux/fs_struct.h
54709--- linux-3.0.4/include/linux/fs_struct.h 2011-07-21 22:17:23.000000000 -0400
54710+++ linux-3.0.4/include/linux/fs_struct.h 2011-08-23 21:47:56.000000000 -0400
54711@@ -6,7 +6,7 @@
54712 #include <linux/seqlock.h>
54713
54714 struct fs_struct {
54715- int users;
54716+ atomic_t users;
54717 spinlock_t lock;
54718 seqcount_t seq;
54719 int umask;
54720diff -urNp linux-3.0.4/include/linux/ftrace_event.h linux-3.0.4/include/linux/ftrace_event.h
54721--- linux-3.0.4/include/linux/ftrace_event.h 2011-07-21 22:17:23.000000000 -0400
54722+++ linux-3.0.4/include/linux/ftrace_event.h 2011-08-23 21:47:56.000000000 -0400
54723@@ -96,7 +96,7 @@ struct trace_event_functions {
54724 trace_print_func raw;
54725 trace_print_func hex;
54726 trace_print_func binary;
54727-};
54728+} __no_const;
54729
54730 struct trace_event {
54731 struct hlist_node node;
54732@@ -247,7 +247,7 @@ extern int trace_define_field(struct ftr
54733 extern int trace_add_event_call(struct ftrace_event_call *call);
54734 extern void trace_remove_event_call(struct ftrace_event_call *call);
54735
54736-#define is_signed_type(type) (((type)(-1)) < 0)
54737+#define is_signed_type(type) (((type)(-1)) < (type)1)
54738
54739 int trace_set_clr_event(const char *system, const char *event, int set);
54740
54741diff -urNp linux-3.0.4/include/linux/genhd.h linux-3.0.4/include/linux/genhd.h
54742--- linux-3.0.4/include/linux/genhd.h 2011-07-21 22:17:23.000000000 -0400
54743+++ linux-3.0.4/include/linux/genhd.h 2011-08-23 21:47:56.000000000 -0400
54744@@ -184,7 +184,7 @@ struct gendisk {
54745 struct kobject *slave_dir;
54746
54747 struct timer_rand_state *random;
54748- atomic_t sync_io; /* RAID */
54749+ atomic_unchecked_t sync_io; /* RAID */
54750 struct disk_events *ev;
54751 #ifdef CONFIG_BLK_DEV_INTEGRITY
54752 struct blk_integrity *integrity;
54753diff -urNp linux-3.0.4/include/linux/gracl.h linux-3.0.4/include/linux/gracl.h
54754--- linux-3.0.4/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
54755+++ linux-3.0.4/include/linux/gracl.h 2011-08-23 21:48:14.000000000 -0400
54756@@ -0,0 +1,317 @@
54757+#ifndef GR_ACL_H
54758+#define GR_ACL_H
54759+
54760+#include <linux/grdefs.h>
54761+#include <linux/resource.h>
54762+#include <linux/capability.h>
54763+#include <linux/dcache.h>
54764+#include <asm/resource.h>
54765+
54766+/* Major status information */
54767+
54768+#define GR_VERSION "grsecurity 2.2.2"
54769+#define GRSECURITY_VERSION 0x2202
54770+
54771+enum {
54772+ GR_SHUTDOWN = 0,
54773+ GR_ENABLE = 1,
54774+ GR_SPROLE = 2,
54775+ GR_RELOAD = 3,
54776+ GR_SEGVMOD = 4,
54777+ GR_STATUS = 5,
54778+ GR_UNSPROLE = 6,
54779+ GR_PASSSET = 7,
54780+ GR_SPROLEPAM = 8,
54781+};
54782+
54783+/* Password setup definitions
54784+ * kernel/grhash.c */
54785+enum {
54786+ GR_PW_LEN = 128,
54787+ GR_SALT_LEN = 16,
54788+ GR_SHA_LEN = 32,
54789+};
54790+
54791+enum {
54792+ GR_SPROLE_LEN = 64,
54793+};
54794+
54795+enum {
54796+ GR_NO_GLOB = 0,
54797+ GR_REG_GLOB,
54798+ GR_CREATE_GLOB
54799+};
54800+
54801+#define GR_NLIMITS 32
54802+
54803+/* Begin Data Structures */
54804+
54805+struct sprole_pw {
54806+ unsigned char *rolename;
54807+ unsigned char salt[GR_SALT_LEN];
54808+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
54809+};
54810+
54811+struct name_entry {
54812+ __u32 key;
54813+ ino_t inode;
54814+ dev_t device;
54815+ char *name;
54816+ __u16 len;
54817+ __u8 deleted;
54818+ struct name_entry *prev;
54819+ struct name_entry *next;
54820+};
54821+
54822+struct inodev_entry {
54823+ struct name_entry *nentry;
54824+ struct inodev_entry *prev;
54825+ struct inodev_entry *next;
54826+};
54827+
54828+struct acl_role_db {
54829+ struct acl_role_label **r_hash;
54830+ __u32 r_size;
54831+};
54832+
54833+struct inodev_db {
54834+ struct inodev_entry **i_hash;
54835+ __u32 i_size;
54836+};
54837+
54838+struct name_db {
54839+ struct name_entry **n_hash;
54840+ __u32 n_size;
54841+};
54842+
54843+struct crash_uid {
54844+ uid_t uid;
54845+ unsigned long expires;
54846+};
54847+
54848+struct gr_hash_struct {
54849+ void **table;
54850+ void **nametable;
54851+ void *first;
54852+ __u32 table_size;
54853+ __u32 used_size;
54854+ int type;
54855+};
54856+
54857+/* Userspace Grsecurity ACL data structures */
54858+
54859+struct acl_subject_label {
54860+ char *filename;
54861+ ino_t inode;
54862+ dev_t device;
54863+ __u32 mode;
54864+ kernel_cap_t cap_mask;
54865+ kernel_cap_t cap_lower;
54866+ kernel_cap_t cap_invert_audit;
54867+
54868+ struct rlimit res[GR_NLIMITS];
54869+ __u32 resmask;
54870+
54871+ __u8 user_trans_type;
54872+ __u8 group_trans_type;
54873+ uid_t *user_transitions;
54874+ gid_t *group_transitions;
54875+ __u16 user_trans_num;
54876+ __u16 group_trans_num;
54877+
54878+ __u32 sock_families[2];
54879+ __u32 ip_proto[8];
54880+ __u32 ip_type;
54881+ struct acl_ip_label **ips;
54882+ __u32 ip_num;
54883+ __u32 inaddr_any_override;
54884+
54885+ __u32 crashes;
54886+ unsigned long expires;
54887+
54888+ struct acl_subject_label *parent_subject;
54889+ struct gr_hash_struct *hash;
54890+ struct acl_subject_label *prev;
54891+ struct acl_subject_label *next;
54892+
54893+ struct acl_object_label **obj_hash;
54894+ __u32 obj_hash_size;
54895+ __u16 pax_flags;
54896+};
54897+
54898+struct role_allowed_ip {
54899+ __u32 addr;
54900+ __u32 netmask;
54901+
54902+ struct role_allowed_ip *prev;
54903+ struct role_allowed_ip *next;
54904+};
54905+
54906+struct role_transition {
54907+ char *rolename;
54908+
54909+ struct role_transition *prev;
54910+ struct role_transition *next;
54911+};
54912+
54913+struct acl_role_label {
54914+ char *rolename;
54915+ uid_t uidgid;
54916+ __u16 roletype;
54917+
54918+ __u16 auth_attempts;
54919+ unsigned long expires;
54920+
54921+ struct acl_subject_label *root_label;
54922+ struct gr_hash_struct *hash;
54923+
54924+ struct acl_role_label *prev;
54925+ struct acl_role_label *next;
54926+
54927+ struct role_transition *transitions;
54928+ struct role_allowed_ip *allowed_ips;
54929+ uid_t *domain_children;
54930+ __u16 domain_child_num;
54931+
54932+ struct acl_subject_label **subj_hash;
54933+ __u32 subj_hash_size;
54934+};
54935+
54936+struct user_acl_role_db {
54937+ struct acl_role_label **r_table;
54938+ __u32 num_pointers; /* Number of allocations to track */
54939+ __u32 num_roles; /* Number of roles */
54940+ __u32 num_domain_children; /* Number of domain children */
54941+ __u32 num_subjects; /* Number of subjects */
54942+ __u32 num_objects; /* Number of objects */
54943+};
54944+
54945+struct acl_object_label {
54946+ char *filename;
54947+ ino_t inode;
54948+ dev_t device;
54949+ __u32 mode;
54950+
54951+ struct acl_subject_label *nested;
54952+ struct acl_object_label *globbed;
54953+
54954+ /* next two structures not used */
54955+
54956+ struct acl_object_label *prev;
54957+ struct acl_object_label *next;
54958+};
54959+
54960+struct acl_ip_label {
54961+ char *iface;
54962+ __u32 addr;
54963+ __u32 netmask;
54964+ __u16 low, high;
54965+ __u8 mode;
54966+ __u32 type;
54967+ __u32 proto[8];
54968+
54969+ /* next two structures not used */
54970+
54971+ struct acl_ip_label *prev;
54972+ struct acl_ip_label *next;
54973+};
54974+
54975+struct gr_arg {
54976+ struct user_acl_role_db role_db;
54977+ unsigned char pw[GR_PW_LEN];
54978+ unsigned char salt[GR_SALT_LEN];
54979+ unsigned char sum[GR_SHA_LEN];
54980+ unsigned char sp_role[GR_SPROLE_LEN];
54981+ struct sprole_pw *sprole_pws;
54982+ dev_t segv_device;
54983+ ino_t segv_inode;
54984+ uid_t segv_uid;
54985+ __u16 num_sprole_pws;
54986+ __u16 mode;
54987+};
54988+
54989+struct gr_arg_wrapper {
54990+ struct gr_arg *arg;
54991+ __u32 version;
54992+ __u32 size;
54993+};
54994+
54995+struct subject_map {
54996+ struct acl_subject_label *user;
54997+ struct acl_subject_label *kernel;
54998+ struct subject_map *prev;
54999+ struct subject_map *next;
55000+};
55001+
55002+struct acl_subj_map_db {
55003+ struct subject_map **s_hash;
55004+ __u32 s_size;
55005+};
55006+
55007+/* End Data Structures Section */
55008+
55009+/* Hash functions generated by empirical testing by Brad Spengler
55010+ Makes good use of the low bits of the inode. Generally 0-1 times
55011+ in loop for successful match. 0-3 for unsuccessful match.
55012+ Shift/add algorithm with modulus of table size and an XOR*/
55013+
55014+static __inline__ unsigned int
55015+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
55016+{
55017+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
55018+}
55019+
55020+ static __inline__ unsigned int
55021+shash(const struct acl_subject_label *userp, const unsigned int sz)
55022+{
55023+ return ((const unsigned long)userp % sz);
55024+}
55025+
55026+static __inline__ unsigned int
55027+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
55028+{
55029+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
55030+}
55031+
55032+static __inline__ unsigned int
55033+nhash(const char *name, const __u16 len, const unsigned int sz)
55034+{
55035+ return full_name_hash((const unsigned char *)name, len) % sz;
55036+}
55037+
55038+#define FOR_EACH_ROLE_START(role) \
55039+ role = role_list; \
55040+ while (role) {
55041+
55042+#define FOR_EACH_ROLE_END(role) \
55043+ role = role->prev; \
55044+ }
55045+
55046+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
55047+ subj = NULL; \
55048+ iter = 0; \
55049+ while (iter < role->subj_hash_size) { \
55050+ if (subj == NULL) \
55051+ subj = role->subj_hash[iter]; \
55052+ if (subj == NULL) { \
55053+ iter++; \
55054+ continue; \
55055+ }
55056+
55057+#define FOR_EACH_SUBJECT_END(subj,iter) \
55058+ subj = subj->next; \
55059+ if (subj == NULL) \
55060+ iter++; \
55061+ }
55062+
55063+
55064+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
55065+ subj = role->hash->first; \
55066+ while (subj != NULL) {
55067+
55068+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
55069+ subj = subj->next; \
55070+ }
55071+
55072+#endif
55073+
55074diff -urNp linux-3.0.4/include/linux/gralloc.h linux-3.0.4/include/linux/gralloc.h
55075--- linux-3.0.4/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
55076+++ linux-3.0.4/include/linux/gralloc.h 2011-08-23 21:48:14.000000000 -0400
55077@@ -0,0 +1,9 @@
55078+#ifndef __GRALLOC_H
55079+#define __GRALLOC_H
55080+
55081+void acl_free_all(void);
55082+int acl_alloc_stack_init(unsigned long size);
55083+void *acl_alloc(unsigned long len);
55084+void *acl_alloc_num(unsigned long num, unsigned long len);
55085+
55086+#endif
55087diff -urNp linux-3.0.4/include/linux/grdefs.h linux-3.0.4/include/linux/grdefs.h
55088--- linux-3.0.4/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
55089+++ linux-3.0.4/include/linux/grdefs.h 2011-08-23 21:48:14.000000000 -0400
55090@@ -0,0 +1,140 @@
55091+#ifndef GRDEFS_H
55092+#define GRDEFS_H
55093+
55094+/* Begin grsecurity status declarations */
55095+
55096+enum {
55097+ GR_READY = 0x01,
55098+ GR_STATUS_INIT = 0x00 // disabled state
55099+};
55100+
55101+/* Begin ACL declarations */
55102+
55103+/* Role flags */
55104+
55105+enum {
55106+ GR_ROLE_USER = 0x0001,
55107+ GR_ROLE_GROUP = 0x0002,
55108+ GR_ROLE_DEFAULT = 0x0004,
55109+ GR_ROLE_SPECIAL = 0x0008,
55110+ GR_ROLE_AUTH = 0x0010,
55111+ GR_ROLE_NOPW = 0x0020,
55112+ GR_ROLE_GOD = 0x0040,
55113+ GR_ROLE_LEARN = 0x0080,
55114+ GR_ROLE_TPE = 0x0100,
55115+ GR_ROLE_DOMAIN = 0x0200,
55116+ GR_ROLE_PAM = 0x0400,
55117+ GR_ROLE_PERSIST = 0x0800
55118+};
55119+
55120+/* ACL Subject and Object mode flags */
55121+enum {
55122+ GR_DELETED = 0x80000000
55123+};
55124+
55125+/* ACL Object-only mode flags */
55126+enum {
55127+ GR_READ = 0x00000001,
55128+ GR_APPEND = 0x00000002,
55129+ GR_WRITE = 0x00000004,
55130+ GR_EXEC = 0x00000008,
55131+ GR_FIND = 0x00000010,
55132+ GR_INHERIT = 0x00000020,
55133+ GR_SETID = 0x00000040,
55134+ GR_CREATE = 0x00000080,
55135+ GR_DELETE = 0x00000100,
55136+ GR_LINK = 0x00000200,
55137+ GR_AUDIT_READ = 0x00000400,
55138+ GR_AUDIT_APPEND = 0x00000800,
55139+ GR_AUDIT_WRITE = 0x00001000,
55140+ GR_AUDIT_EXEC = 0x00002000,
55141+ GR_AUDIT_FIND = 0x00004000,
55142+ GR_AUDIT_INHERIT= 0x00008000,
55143+ GR_AUDIT_SETID = 0x00010000,
55144+ GR_AUDIT_CREATE = 0x00020000,
55145+ GR_AUDIT_DELETE = 0x00040000,
55146+ GR_AUDIT_LINK = 0x00080000,
55147+ GR_PTRACERD = 0x00100000,
55148+ GR_NOPTRACE = 0x00200000,
55149+ GR_SUPPRESS = 0x00400000,
55150+ GR_NOLEARN = 0x00800000,
55151+ GR_INIT_TRANSFER= 0x01000000
55152+};
55153+
55154+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
55155+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
55156+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
55157+
55158+/* ACL subject-only mode flags */
55159+enum {
55160+ GR_KILL = 0x00000001,
55161+ GR_VIEW = 0x00000002,
55162+ GR_PROTECTED = 0x00000004,
55163+ GR_LEARN = 0x00000008,
55164+ GR_OVERRIDE = 0x00000010,
55165+ /* just a placeholder, this mode is only used in userspace */
55166+ GR_DUMMY = 0x00000020,
55167+ GR_PROTSHM = 0x00000040,
55168+ GR_KILLPROC = 0x00000080,
55169+ GR_KILLIPPROC = 0x00000100,
55170+ /* just a placeholder, this mode is only used in userspace */
55171+ GR_NOTROJAN = 0x00000200,
55172+ GR_PROTPROCFD = 0x00000400,
55173+ GR_PROCACCT = 0x00000800,
55174+ GR_RELAXPTRACE = 0x00001000,
55175+ GR_NESTED = 0x00002000,
55176+ GR_INHERITLEARN = 0x00004000,
55177+ GR_PROCFIND = 0x00008000,
55178+ GR_POVERRIDE = 0x00010000,
55179+ GR_KERNELAUTH = 0x00020000,
55180+ GR_ATSECURE = 0x00040000,
55181+ GR_SHMEXEC = 0x00080000
55182+};
55183+
55184+enum {
55185+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
55186+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
55187+ GR_PAX_ENABLE_MPROTECT = 0x0004,
55188+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
55189+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
55190+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
55191+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
55192+ GR_PAX_DISABLE_MPROTECT = 0x0400,
55193+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
55194+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
55195+};
55196+
55197+enum {
55198+ GR_ID_USER = 0x01,
55199+ GR_ID_GROUP = 0x02,
55200+};
55201+
55202+enum {
55203+ GR_ID_ALLOW = 0x01,
55204+ GR_ID_DENY = 0x02,
55205+};
55206+
55207+#define GR_CRASH_RES 31
55208+#define GR_UIDTABLE_MAX 500
55209+
55210+/* begin resource learning section */
55211+enum {
55212+ GR_RLIM_CPU_BUMP = 60,
55213+ GR_RLIM_FSIZE_BUMP = 50000,
55214+ GR_RLIM_DATA_BUMP = 10000,
55215+ GR_RLIM_STACK_BUMP = 1000,
55216+ GR_RLIM_CORE_BUMP = 10000,
55217+ GR_RLIM_RSS_BUMP = 500000,
55218+ GR_RLIM_NPROC_BUMP = 1,
55219+ GR_RLIM_NOFILE_BUMP = 5,
55220+ GR_RLIM_MEMLOCK_BUMP = 50000,
55221+ GR_RLIM_AS_BUMP = 500000,
55222+ GR_RLIM_LOCKS_BUMP = 2,
55223+ GR_RLIM_SIGPENDING_BUMP = 5,
55224+ GR_RLIM_MSGQUEUE_BUMP = 10000,
55225+ GR_RLIM_NICE_BUMP = 1,
55226+ GR_RLIM_RTPRIO_BUMP = 1,
55227+ GR_RLIM_RTTIME_BUMP = 1000000
55228+};
55229+
55230+#endif
55231diff -urNp linux-3.0.4/include/linux/grinternal.h linux-3.0.4/include/linux/grinternal.h
55232--- linux-3.0.4/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
55233+++ linux-3.0.4/include/linux/grinternal.h 2011-08-23 21:48:14.000000000 -0400
55234@@ -0,0 +1,219 @@
55235+#ifndef __GRINTERNAL_H
55236+#define __GRINTERNAL_H
55237+
55238+#ifdef CONFIG_GRKERNSEC
55239+
55240+#include <linux/fs.h>
55241+#include <linux/mnt_namespace.h>
55242+#include <linux/nsproxy.h>
55243+#include <linux/gracl.h>
55244+#include <linux/grdefs.h>
55245+#include <linux/grmsg.h>
55246+
55247+void gr_add_learn_entry(const char *fmt, ...)
55248+ __attribute__ ((format (printf, 1, 2)));
55249+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
55250+ const struct vfsmount *mnt);
55251+__u32 gr_check_create(const struct dentry *new_dentry,
55252+ const struct dentry *parent,
55253+ const struct vfsmount *mnt, const __u32 mode);
55254+int gr_check_protected_task(const struct task_struct *task);
55255+__u32 to_gr_audit(const __u32 reqmode);
55256+int gr_set_acls(const int type);
55257+int gr_apply_subject_to_task(struct task_struct *task);
55258+int gr_acl_is_enabled(void);
55259+char gr_roletype_to_char(void);
55260+
55261+void gr_handle_alertkill(struct task_struct *task);
55262+char *gr_to_filename(const struct dentry *dentry,
55263+ const struct vfsmount *mnt);
55264+char *gr_to_filename1(const struct dentry *dentry,
55265+ const struct vfsmount *mnt);
55266+char *gr_to_filename2(const struct dentry *dentry,
55267+ const struct vfsmount *mnt);
55268+char *gr_to_filename3(const struct dentry *dentry,
55269+ const struct vfsmount *mnt);
55270+
55271+extern int grsec_enable_harden_ptrace;
55272+extern int grsec_enable_link;
55273+extern int grsec_enable_fifo;
55274+extern int grsec_enable_execve;
55275+extern int grsec_enable_shm;
55276+extern int grsec_enable_execlog;
55277+extern int grsec_enable_signal;
55278+extern int grsec_enable_audit_ptrace;
55279+extern int grsec_enable_forkfail;
55280+extern int grsec_enable_time;
55281+extern int grsec_enable_rofs;
55282+extern int grsec_enable_chroot_shmat;
55283+extern int grsec_enable_chroot_mount;
55284+extern int grsec_enable_chroot_double;
55285+extern int grsec_enable_chroot_pivot;
55286+extern int grsec_enable_chroot_chdir;
55287+extern int grsec_enable_chroot_chmod;
55288+extern int grsec_enable_chroot_mknod;
55289+extern int grsec_enable_chroot_fchdir;
55290+extern int grsec_enable_chroot_nice;
55291+extern int grsec_enable_chroot_execlog;
55292+extern int grsec_enable_chroot_caps;
55293+extern int grsec_enable_chroot_sysctl;
55294+extern int grsec_enable_chroot_unix;
55295+extern int grsec_enable_tpe;
55296+extern int grsec_tpe_gid;
55297+extern int grsec_enable_tpe_all;
55298+extern int grsec_enable_tpe_invert;
55299+extern int grsec_enable_socket_all;
55300+extern int grsec_socket_all_gid;
55301+extern int grsec_enable_socket_client;
55302+extern int grsec_socket_client_gid;
55303+extern int grsec_enable_socket_server;
55304+extern int grsec_socket_server_gid;
55305+extern int grsec_audit_gid;
55306+extern int grsec_enable_group;
55307+extern int grsec_enable_audit_textrel;
55308+extern int grsec_enable_log_rwxmaps;
55309+extern int grsec_enable_mount;
55310+extern int grsec_enable_chdir;
55311+extern int grsec_resource_logging;
55312+extern int grsec_enable_blackhole;
55313+extern int grsec_lastack_retries;
55314+extern int grsec_enable_brute;
55315+extern int grsec_lock;
55316+
55317+extern spinlock_t grsec_alert_lock;
55318+extern unsigned long grsec_alert_wtime;
55319+extern unsigned long grsec_alert_fyet;
55320+
55321+extern spinlock_t grsec_audit_lock;
55322+
55323+extern rwlock_t grsec_exec_file_lock;
55324+
55325+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
55326+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
55327+ (tsk)->exec_file->f_vfsmnt) : "/")
55328+
55329+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
55330+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
55331+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
55332+
55333+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
55334+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
55335+ (tsk)->exec_file->f_vfsmnt) : "/")
55336+
55337+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
55338+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
55339+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
55340+
55341+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
55342+
55343+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
55344+
55345+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
55346+ (task)->pid, (cred)->uid, \
55347+ (cred)->euid, (cred)->gid, (cred)->egid, \
55348+ gr_parent_task_fullpath(task), \
55349+ (task)->real_parent->comm, (task)->real_parent->pid, \
55350+ (pcred)->uid, (pcred)->euid, \
55351+ (pcred)->gid, (pcred)->egid
55352+
55353+#define GR_CHROOT_CAPS {{ \
55354+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
55355+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
55356+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
55357+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
55358+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
55359+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
55360+
55361+#define security_learn(normal_msg,args...) \
55362+({ \
55363+ read_lock(&grsec_exec_file_lock); \
55364+ gr_add_learn_entry(normal_msg "\n", ## args); \
55365+ read_unlock(&grsec_exec_file_lock); \
55366+})
55367+
55368+enum {
55369+ GR_DO_AUDIT,
55370+ GR_DONT_AUDIT,
55371+ /* used for non-audit messages that we shouldn't kill the task on */
55372+ GR_DONT_AUDIT_GOOD
55373+};
55374+
55375+enum {
55376+ GR_TTYSNIFF,
55377+ GR_RBAC,
55378+ GR_RBAC_STR,
55379+ GR_STR_RBAC,
55380+ GR_RBAC_MODE2,
55381+ GR_RBAC_MODE3,
55382+ GR_FILENAME,
55383+ GR_SYSCTL_HIDDEN,
55384+ GR_NOARGS,
55385+ GR_ONE_INT,
55386+ GR_ONE_INT_TWO_STR,
55387+ GR_ONE_STR,
55388+ GR_STR_INT,
55389+ GR_TWO_STR_INT,
55390+ GR_TWO_INT,
55391+ GR_TWO_U64,
55392+ GR_THREE_INT,
55393+ GR_FIVE_INT_TWO_STR,
55394+ GR_TWO_STR,
55395+ GR_THREE_STR,
55396+ GR_FOUR_STR,
55397+ GR_STR_FILENAME,
55398+ GR_FILENAME_STR,
55399+ GR_FILENAME_TWO_INT,
55400+ GR_FILENAME_TWO_INT_STR,
55401+ GR_TEXTREL,
55402+ GR_PTRACE,
55403+ GR_RESOURCE,
55404+ GR_CAP,
55405+ GR_SIG,
55406+ GR_SIG2,
55407+ GR_CRASH1,
55408+ GR_CRASH2,
55409+ GR_PSACCT,
55410+ GR_RWXMAP
55411+};
55412+
55413+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
55414+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
55415+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
55416+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
55417+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
55418+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
55419+#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)
55420+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
55421+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
55422+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
55423+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
55424+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
55425+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
55426+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
55427+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
55428+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
55429+#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)
55430+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
55431+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
55432+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
55433+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
55434+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
55435+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
55436+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
55437+#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)
55438+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
55439+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
55440+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
55441+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
55442+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
55443+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
55444+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
55445+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
55446+#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)
55447+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
55448+
55449+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
55450+
55451+#endif
55452+
55453+#endif
55454diff -urNp linux-3.0.4/include/linux/grmsg.h linux-3.0.4/include/linux/grmsg.h
55455--- linux-3.0.4/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
55456+++ linux-3.0.4/include/linux/grmsg.h 2011-09-14 09:16:54.000000000 -0400
55457@@ -0,0 +1,108 @@
55458+#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"
55459+#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"
55460+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
55461+#define GR_STOPMOD_MSG "denied modification of module state by "
55462+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
55463+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
55464+#define GR_IOPERM_MSG "denied use of ioperm() by "
55465+#define GR_IOPL_MSG "denied use of iopl() by "
55466+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
55467+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
55468+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
55469+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
55470+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
55471+#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"
55472+#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"
55473+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
55474+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
55475+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
55476+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
55477+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
55478+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
55479+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
55480+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
55481+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
55482+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
55483+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
55484+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
55485+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
55486+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
55487+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
55488+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
55489+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
55490+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
55491+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
55492+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
55493+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
55494+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
55495+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
55496+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
55497+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
55498+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
55499+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
55500+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
55501+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
55502+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
55503+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
55504+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
55505+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
55506+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
55507+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
55508+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
55509+#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"
55510+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
55511+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
55512+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
55513+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
55514+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
55515+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
55516+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
55517+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
55518+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
55519+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
55520+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
55521+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
55522+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
55523+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
55524+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
55525+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
55526+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
55527+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
55528+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
55529+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
55530+#define GR_FAILFORK_MSG "failed fork with errno %s by "
55531+#define GR_NICE_CHROOT_MSG "denied priority change by "
55532+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
55533+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
55534+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
55535+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
55536+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
55537+#define GR_TIME_MSG "time set by "
55538+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
55539+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
55540+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
55541+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
55542+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
55543+#define GR_BIND_MSG "denied bind() by "
55544+#define GR_CONNECT_MSG "denied connect() by "
55545+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
55546+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
55547+#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"
55548+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
55549+#define GR_CAP_ACL_MSG "use of %s denied for "
55550+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
55551+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
55552+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
55553+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
55554+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
55555+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
55556+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
55557+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
55558+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
55559+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
55560+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
55561+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
55562+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
55563+#define GR_VM86_MSG "denied use of vm86 by "
55564+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
55565+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
55566diff -urNp linux-3.0.4/include/linux/grsecurity.h linux-3.0.4/include/linux/grsecurity.h
55567--- linux-3.0.4/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
55568+++ linux-3.0.4/include/linux/grsecurity.h 2011-09-14 09:16:54.000000000 -0400
55569@@ -0,0 +1,226 @@
55570+#ifndef GR_SECURITY_H
55571+#define GR_SECURITY_H
55572+#include <linux/fs.h>
55573+#include <linux/fs_struct.h>
55574+#include <linux/binfmts.h>
55575+#include <linux/gracl.h>
55576+
55577+/* notify of brain-dead configs */
55578+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55579+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
55580+#endif
55581+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
55582+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
55583+#endif
55584+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
55585+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
55586+#endif
55587+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
55588+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
55589+#endif
55590+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
55591+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
55592+#endif
55593+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
55594+#error "CONFIG_PAX enabled, but no PaX options are enabled."
55595+#endif
55596+
55597+#include <linux/compat.h>
55598+
55599+struct user_arg_ptr {
55600+#ifdef CONFIG_COMPAT
55601+ bool is_compat;
55602+#endif
55603+ union {
55604+ const char __user *const __user *native;
55605+#ifdef CONFIG_COMPAT
55606+ compat_uptr_t __user *compat;
55607+#endif
55608+ } ptr;
55609+};
55610+
55611+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
55612+void gr_handle_brute_check(void);
55613+void gr_handle_kernel_exploit(void);
55614+int gr_process_user_ban(void);
55615+
55616+char gr_roletype_to_char(void);
55617+
55618+int gr_acl_enable_at_secure(void);
55619+
55620+int gr_check_user_change(int real, int effective, int fs);
55621+int gr_check_group_change(int real, int effective, int fs);
55622+
55623+void gr_del_task_from_ip_table(struct task_struct *p);
55624+
55625+int gr_pid_is_chrooted(struct task_struct *p);
55626+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
55627+int gr_handle_chroot_nice(void);
55628+int gr_handle_chroot_sysctl(const int op);
55629+int gr_handle_chroot_setpriority(struct task_struct *p,
55630+ const int niceval);
55631+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
55632+int gr_handle_chroot_chroot(const struct dentry *dentry,
55633+ const struct vfsmount *mnt);
55634+void gr_handle_chroot_chdir(struct path *path);
55635+int gr_handle_chroot_chmod(const struct dentry *dentry,
55636+ const struct vfsmount *mnt, const int mode);
55637+int gr_handle_chroot_mknod(const struct dentry *dentry,
55638+ const struct vfsmount *mnt, const int mode);
55639+int gr_handle_chroot_mount(const struct dentry *dentry,
55640+ const struct vfsmount *mnt,
55641+ const char *dev_name);
55642+int gr_handle_chroot_pivot(void);
55643+int gr_handle_chroot_unix(const pid_t pid);
55644+
55645+int gr_handle_rawio(const struct inode *inode);
55646+
55647+void gr_handle_ioperm(void);
55648+void gr_handle_iopl(void);
55649+
55650+int gr_tpe_allow(const struct file *file);
55651+
55652+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
55653+void gr_clear_chroot_entries(struct task_struct *task);
55654+
55655+void gr_log_forkfail(const int retval);
55656+void gr_log_timechange(void);
55657+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
55658+void gr_log_chdir(const struct dentry *dentry,
55659+ const struct vfsmount *mnt);
55660+void gr_log_chroot_exec(const struct dentry *dentry,
55661+ const struct vfsmount *mnt);
55662+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
55663+void gr_log_remount(const char *devname, const int retval);
55664+void gr_log_unmount(const char *devname, const int retval);
55665+void gr_log_mount(const char *from, const char *to, const int retval);
55666+void gr_log_textrel(struct vm_area_struct *vma);
55667+void gr_log_rwxmmap(struct file *file);
55668+void gr_log_rwxmprotect(struct file *file);
55669+
55670+int gr_handle_follow_link(const struct inode *parent,
55671+ const struct inode *inode,
55672+ const struct dentry *dentry,
55673+ const struct vfsmount *mnt);
55674+int gr_handle_fifo(const struct dentry *dentry,
55675+ const struct vfsmount *mnt,
55676+ const struct dentry *dir, const int flag,
55677+ const int acc_mode);
55678+int gr_handle_hardlink(const struct dentry *dentry,
55679+ const struct vfsmount *mnt,
55680+ struct inode *inode,
55681+ const int mode, const char *to);
55682+
55683+int gr_is_capable(const int cap);
55684+int gr_is_capable_nolog(const int cap);
55685+void gr_learn_resource(const struct task_struct *task, const int limit,
55686+ const unsigned long wanted, const int gt);
55687+void gr_copy_label(struct task_struct *tsk);
55688+void gr_handle_crash(struct task_struct *task, const int sig);
55689+int gr_handle_signal(const struct task_struct *p, const int sig);
55690+int gr_check_crash_uid(const uid_t uid);
55691+int gr_check_protected_task(const struct task_struct *task);
55692+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
55693+int gr_acl_handle_mmap(const struct file *file,
55694+ const unsigned long prot);
55695+int gr_acl_handle_mprotect(const struct file *file,
55696+ const unsigned long prot);
55697+int gr_check_hidden_task(const struct task_struct *tsk);
55698+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
55699+ const struct vfsmount *mnt);
55700+__u32 gr_acl_handle_utime(const struct dentry *dentry,
55701+ const struct vfsmount *mnt);
55702+__u32 gr_acl_handle_access(const struct dentry *dentry,
55703+ const struct vfsmount *mnt, const int fmode);
55704+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
55705+ const struct vfsmount *mnt, mode_t mode);
55706+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
55707+ const struct vfsmount *mnt, mode_t mode);
55708+__u32 gr_acl_handle_chown(const struct dentry *dentry,
55709+ const struct vfsmount *mnt);
55710+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
55711+ const struct vfsmount *mnt);
55712+int gr_handle_ptrace(struct task_struct *task, const long request);
55713+int gr_handle_proc_ptrace(struct task_struct *task);
55714+__u32 gr_acl_handle_execve(const struct dentry *dentry,
55715+ const struct vfsmount *mnt);
55716+int gr_check_crash_exec(const struct file *filp);
55717+int gr_acl_is_enabled(void);
55718+void gr_set_kernel_label(struct task_struct *task);
55719+void gr_set_role_label(struct task_struct *task, const uid_t uid,
55720+ const gid_t gid);
55721+int gr_set_proc_label(const struct dentry *dentry,
55722+ const struct vfsmount *mnt,
55723+ const int unsafe_share);
55724+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
55725+ const struct vfsmount *mnt);
55726+__u32 gr_acl_handle_open(const struct dentry *dentry,
55727+ const struct vfsmount *mnt, const int fmode);
55728+__u32 gr_acl_handle_creat(const struct dentry *dentry,
55729+ const struct dentry *p_dentry,
55730+ const struct vfsmount *p_mnt, const int fmode,
55731+ const int imode);
55732+void gr_handle_create(const struct dentry *dentry,
55733+ const struct vfsmount *mnt);
55734+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
55735+ const struct dentry *parent_dentry,
55736+ const struct vfsmount *parent_mnt,
55737+ const int mode);
55738+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
55739+ const struct dentry *parent_dentry,
55740+ const struct vfsmount *parent_mnt);
55741+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
55742+ const struct vfsmount *mnt);
55743+void gr_handle_delete(const ino_t ino, const dev_t dev);
55744+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
55745+ const struct vfsmount *mnt);
55746+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
55747+ const struct dentry *parent_dentry,
55748+ const struct vfsmount *parent_mnt,
55749+ const char *from);
55750+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
55751+ const struct dentry *parent_dentry,
55752+ const struct vfsmount *parent_mnt,
55753+ const struct dentry *old_dentry,
55754+ const struct vfsmount *old_mnt, const char *to);
55755+int gr_acl_handle_rename(struct dentry *new_dentry,
55756+ struct dentry *parent_dentry,
55757+ const struct vfsmount *parent_mnt,
55758+ struct dentry *old_dentry,
55759+ struct inode *old_parent_inode,
55760+ struct vfsmount *old_mnt, const char *newname);
55761+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55762+ struct dentry *old_dentry,
55763+ struct dentry *new_dentry,
55764+ struct vfsmount *mnt, const __u8 replace);
55765+__u32 gr_check_link(const struct dentry *new_dentry,
55766+ const struct dentry *parent_dentry,
55767+ const struct vfsmount *parent_mnt,
55768+ const struct dentry *old_dentry,
55769+ const struct vfsmount *old_mnt);
55770+int gr_acl_handle_filldir(const struct file *file, const char *name,
55771+ const unsigned int namelen, const ino_t ino);
55772+
55773+__u32 gr_acl_handle_unix(const struct dentry *dentry,
55774+ const struct vfsmount *mnt);
55775+void gr_acl_handle_exit(void);
55776+void gr_acl_handle_psacct(struct task_struct *task, const long code);
55777+int gr_acl_handle_procpidmem(const struct task_struct *task);
55778+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
55779+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
55780+void gr_audit_ptrace(struct task_struct *task);
55781+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
55782+
55783+#ifdef CONFIG_GRKERNSEC
55784+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
55785+void gr_handle_vm86(void);
55786+void gr_handle_mem_readwrite(u64 from, u64 to);
55787+
55788+extern int grsec_enable_dmesg;
55789+extern int grsec_disable_privio;
55790+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55791+extern int grsec_enable_chroot_findtask;
55792+#endif
55793+#endif
55794+
55795+#endif
55796diff -urNp linux-3.0.4/include/linux/grsock.h linux-3.0.4/include/linux/grsock.h
55797--- linux-3.0.4/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
55798+++ linux-3.0.4/include/linux/grsock.h 2011-08-23 21:48:14.000000000 -0400
55799@@ -0,0 +1,19 @@
55800+#ifndef __GRSOCK_H
55801+#define __GRSOCK_H
55802+
55803+extern void gr_attach_curr_ip(const struct sock *sk);
55804+extern int gr_handle_sock_all(const int family, const int type,
55805+ const int protocol);
55806+extern int gr_handle_sock_server(const struct sockaddr *sck);
55807+extern int gr_handle_sock_server_other(const struct sock *sck);
55808+extern int gr_handle_sock_client(const struct sockaddr *sck);
55809+extern int gr_search_connect(struct socket * sock,
55810+ struct sockaddr_in * addr);
55811+extern int gr_search_bind(struct socket * sock,
55812+ struct sockaddr_in * addr);
55813+extern int gr_search_listen(struct socket * sock);
55814+extern int gr_search_accept(struct socket * sock);
55815+extern int gr_search_socket(const int domain, const int type,
55816+ const int protocol);
55817+
55818+#endif
55819diff -urNp linux-3.0.4/include/linux/hid.h linux-3.0.4/include/linux/hid.h
55820--- linux-3.0.4/include/linux/hid.h 2011-07-21 22:17:23.000000000 -0400
55821+++ linux-3.0.4/include/linux/hid.h 2011-08-23 21:47:56.000000000 -0400
55822@@ -675,7 +675,7 @@ struct hid_ll_driver {
55823 unsigned int code, int value);
55824
55825 int (*parse)(struct hid_device *hdev);
55826-};
55827+} __no_const;
55828
55829 #define PM_HINT_FULLON 1<<5
55830 #define PM_HINT_NORMAL 1<<1
55831diff -urNp linux-3.0.4/include/linux/highmem.h linux-3.0.4/include/linux/highmem.h
55832--- linux-3.0.4/include/linux/highmem.h 2011-07-21 22:17:23.000000000 -0400
55833+++ linux-3.0.4/include/linux/highmem.h 2011-08-23 21:47:56.000000000 -0400
55834@@ -185,6 +185,18 @@ static inline void clear_highpage(struct
55835 kunmap_atomic(kaddr, KM_USER0);
55836 }
55837
55838+static inline void sanitize_highpage(struct page *page)
55839+{
55840+ void *kaddr;
55841+ unsigned long flags;
55842+
55843+ local_irq_save(flags);
55844+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
55845+ clear_page(kaddr);
55846+ kunmap_atomic(kaddr, KM_CLEARPAGE);
55847+ local_irq_restore(flags);
55848+}
55849+
55850 static inline void zero_user_segments(struct page *page,
55851 unsigned start1, unsigned end1,
55852 unsigned start2, unsigned end2)
55853diff -urNp linux-3.0.4/include/linux/i2c.h linux-3.0.4/include/linux/i2c.h
55854--- linux-3.0.4/include/linux/i2c.h 2011-07-21 22:17:23.000000000 -0400
55855+++ linux-3.0.4/include/linux/i2c.h 2011-08-23 21:47:56.000000000 -0400
55856@@ -346,6 +346,7 @@ struct i2c_algorithm {
55857 /* To determine what the adapter supports */
55858 u32 (*functionality) (struct i2c_adapter *);
55859 };
55860+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
55861
55862 /*
55863 * i2c_adapter is the structure used to identify a physical i2c bus along
55864diff -urNp linux-3.0.4/include/linux/i2o.h linux-3.0.4/include/linux/i2o.h
55865--- linux-3.0.4/include/linux/i2o.h 2011-07-21 22:17:23.000000000 -0400
55866+++ linux-3.0.4/include/linux/i2o.h 2011-08-23 21:47:56.000000000 -0400
55867@@ -564,7 +564,7 @@ struct i2o_controller {
55868 struct i2o_device *exec; /* Executive */
55869 #if BITS_PER_LONG == 64
55870 spinlock_t context_list_lock; /* lock for context_list */
55871- atomic_t context_list_counter; /* needed for unique contexts */
55872+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
55873 struct list_head context_list; /* list of context id's
55874 and pointers */
55875 #endif
55876diff -urNp linux-3.0.4/include/linux/init.h linux-3.0.4/include/linux/init.h
55877--- linux-3.0.4/include/linux/init.h 2011-07-21 22:17:23.000000000 -0400
55878+++ linux-3.0.4/include/linux/init.h 2011-08-23 21:47:56.000000000 -0400
55879@@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
55880
55881 /* Each module must use one module_init(). */
55882 #define module_init(initfn) \
55883- static inline initcall_t __inittest(void) \
55884+ static inline __used initcall_t __inittest(void) \
55885 { return initfn; } \
55886 int init_module(void) __attribute__((alias(#initfn)));
55887
55888 /* This is only required if you want to be unloadable. */
55889 #define module_exit(exitfn) \
55890- static inline exitcall_t __exittest(void) \
55891+ static inline __used exitcall_t __exittest(void) \
55892 { return exitfn; } \
55893 void cleanup_module(void) __attribute__((alias(#exitfn)));
55894
55895diff -urNp linux-3.0.4/include/linux/init_task.h linux-3.0.4/include/linux/init_task.h
55896--- linux-3.0.4/include/linux/init_task.h 2011-07-21 22:17:23.000000000 -0400
55897+++ linux-3.0.4/include/linux/init_task.h 2011-08-23 21:47:56.000000000 -0400
55898@@ -126,6 +126,12 @@ extern struct cred init_cred;
55899 # define INIT_PERF_EVENTS(tsk)
55900 #endif
55901
55902+#ifdef CONFIG_X86
55903+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
55904+#else
55905+#define INIT_TASK_THREAD_INFO
55906+#endif
55907+
55908 /*
55909 * INIT_TASK is used to set up the first task table, touch at
55910 * your own risk!. Base=0, limit=0x1fffff (=2MB)
55911@@ -164,6 +170,7 @@ extern struct cred init_cred;
55912 RCU_INIT_POINTER(.cred, &init_cred), \
55913 .comm = "swapper", \
55914 .thread = INIT_THREAD, \
55915+ INIT_TASK_THREAD_INFO \
55916 .fs = &init_fs, \
55917 .files = &init_files, \
55918 .signal = &init_signals, \
55919diff -urNp linux-3.0.4/include/linux/intel-iommu.h linux-3.0.4/include/linux/intel-iommu.h
55920--- linux-3.0.4/include/linux/intel-iommu.h 2011-07-21 22:17:23.000000000 -0400
55921+++ linux-3.0.4/include/linux/intel-iommu.h 2011-08-23 21:47:56.000000000 -0400
55922@@ -296,7 +296,7 @@ struct iommu_flush {
55923 u8 fm, u64 type);
55924 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
55925 unsigned int size_order, u64 type);
55926-};
55927+} __no_const;
55928
55929 enum {
55930 SR_DMAR_FECTL_REG,
55931diff -urNp linux-3.0.4/include/linux/interrupt.h linux-3.0.4/include/linux/interrupt.h
55932--- linux-3.0.4/include/linux/interrupt.h 2011-07-21 22:17:23.000000000 -0400
55933+++ linux-3.0.4/include/linux/interrupt.h 2011-08-23 21:47:56.000000000 -0400
55934@@ -422,7 +422,7 @@ enum
55935 /* map softirq index to softirq name. update 'softirq_to_name' in
55936 * kernel/softirq.c when adding a new softirq.
55937 */
55938-extern char *softirq_to_name[NR_SOFTIRQS];
55939+extern const char * const softirq_to_name[NR_SOFTIRQS];
55940
55941 /* softirq mask and active fields moved to irq_cpustat_t in
55942 * asm/hardirq.h to get better cache usage. KAO
55943@@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
55944
55945 struct softirq_action
55946 {
55947- void (*action)(struct softirq_action *);
55948+ void (*action)(void);
55949 };
55950
55951 asmlinkage void do_softirq(void);
55952 asmlinkage void __do_softirq(void);
55953-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
55954+extern void open_softirq(int nr, void (*action)(void));
55955 extern void softirq_init(void);
55956 static inline void __raise_softirq_irqoff(unsigned int nr)
55957 {
55958diff -urNp linux-3.0.4/include/linux/kallsyms.h linux-3.0.4/include/linux/kallsyms.h
55959--- linux-3.0.4/include/linux/kallsyms.h 2011-07-21 22:17:23.000000000 -0400
55960+++ linux-3.0.4/include/linux/kallsyms.h 2011-08-23 21:48:14.000000000 -0400
55961@@ -15,7 +15,8 @@
55962
55963 struct module;
55964
55965-#ifdef CONFIG_KALLSYMS
55966+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
55967+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55968 /* Lookup the address for a symbol. Returns 0 if not found. */
55969 unsigned long kallsyms_lookup_name(const char *name);
55970
55971@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
55972 /* Stupid that this does nothing, but I didn't create this mess. */
55973 #define __print_symbol(fmt, addr)
55974 #endif /*CONFIG_KALLSYMS*/
55975+#else /* when included by kallsyms.c, vsnprintf.c, or
55976+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
55977+extern void __print_symbol(const char *fmt, unsigned long address);
55978+extern int sprint_backtrace(char *buffer, unsigned long address);
55979+extern int sprint_symbol(char *buffer, unsigned long address);
55980+const char *kallsyms_lookup(unsigned long addr,
55981+ unsigned long *symbolsize,
55982+ unsigned long *offset,
55983+ char **modname, char *namebuf);
55984+#endif
55985
55986 /* This macro allows us to keep printk typechecking */
55987 static void __check_printsym_format(const char *fmt, ...)
55988diff -urNp linux-3.0.4/include/linux/kgdb.h linux-3.0.4/include/linux/kgdb.h
55989--- linux-3.0.4/include/linux/kgdb.h 2011-07-21 22:17:23.000000000 -0400
55990+++ linux-3.0.4/include/linux/kgdb.h 2011-08-26 19:49:56.000000000 -0400
55991@@ -53,7 +53,7 @@ extern int kgdb_connected;
55992 extern int kgdb_io_module_registered;
55993
55994 extern atomic_t kgdb_setting_breakpoint;
55995-extern atomic_t kgdb_cpu_doing_single_step;
55996+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
55997
55998 extern struct task_struct *kgdb_usethread;
55999 extern struct task_struct *kgdb_contthread;
56000@@ -251,7 +251,7 @@ struct kgdb_arch {
56001 void (*disable_hw_break)(struct pt_regs *regs);
56002 void (*remove_all_hw_break)(void);
56003 void (*correct_hw_break)(void);
56004-};
56005+} __do_const;
56006
56007 /**
56008 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
56009@@ -276,7 +276,7 @@ struct kgdb_io {
56010 void (*pre_exception) (void);
56011 void (*post_exception) (void);
56012 int is_console;
56013-};
56014+} __do_const;
56015
56016 extern struct kgdb_arch arch_kgdb_ops;
56017
56018diff -urNp linux-3.0.4/include/linux/kmod.h linux-3.0.4/include/linux/kmod.h
56019--- linux-3.0.4/include/linux/kmod.h 2011-07-21 22:17:23.000000000 -0400
56020+++ linux-3.0.4/include/linux/kmod.h 2011-08-23 21:48:14.000000000 -0400
56021@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysc
56022 * usually useless though. */
56023 extern int __request_module(bool wait, const char *name, ...) \
56024 __attribute__((format(printf, 2, 3)));
56025+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
56026+ __attribute__((format(printf, 3, 4)));
56027 #define request_module(mod...) __request_module(true, mod)
56028 #define request_module_nowait(mod...) __request_module(false, mod)
56029 #define try_then_request_module(x, mod...) \
56030diff -urNp linux-3.0.4/include/linux/kvm_host.h linux-3.0.4/include/linux/kvm_host.h
56031--- linux-3.0.4/include/linux/kvm_host.h 2011-07-21 22:17:23.000000000 -0400
56032+++ linux-3.0.4/include/linux/kvm_host.h 2011-08-23 21:47:56.000000000 -0400
56033@@ -307,7 +307,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
56034 void vcpu_load(struct kvm_vcpu *vcpu);
56035 void vcpu_put(struct kvm_vcpu *vcpu);
56036
56037-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
56038+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
56039 struct module *module);
56040 void kvm_exit(void);
56041
56042@@ -446,7 +446,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
56043 struct kvm_guest_debug *dbg);
56044 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
56045
56046-int kvm_arch_init(void *opaque);
56047+int kvm_arch_init(const void *opaque);
56048 void kvm_arch_exit(void);
56049
56050 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
56051diff -urNp linux-3.0.4/include/linux/libata.h linux-3.0.4/include/linux/libata.h
56052--- linux-3.0.4/include/linux/libata.h 2011-07-21 22:17:23.000000000 -0400
56053+++ linux-3.0.4/include/linux/libata.h 2011-08-26 19:49:56.000000000 -0400
56054@@ -899,7 +899,7 @@ struct ata_port_operations {
56055 * fields must be pointers.
56056 */
56057 const struct ata_port_operations *inherits;
56058-};
56059+} __do_const;
56060
56061 struct ata_port_info {
56062 unsigned long flags;
56063diff -urNp linux-3.0.4/include/linux/mca.h linux-3.0.4/include/linux/mca.h
56064--- linux-3.0.4/include/linux/mca.h 2011-07-21 22:17:23.000000000 -0400
56065+++ linux-3.0.4/include/linux/mca.h 2011-08-23 21:47:56.000000000 -0400
56066@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
56067 int region);
56068 void * (*mca_transform_memory)(struct mca_device *,
56069 void *memory);
56070-};
56071+} __no_const;
56072
56073 struct mca_bus {
56074 u64 default_dma_mask;
56075diff -urNp linux-3.0.4/include/linux/memory.h linux-3.0.4/include/linux/memory.h
56076--- linux-3.0.4/include/linux/memory.h 2011-07-21 22:17:23.000000000 -0400
56077+++ linux-3.0.4/include/linux/memory.h 2011-08-23 21:47:56.000000000 -0400
56078@@ -144,7 +144,7 @@ struct memory_accessor {
56079 size_t count);
56080 ssize_t (*write)(struct memory_accessor *, const char *buf,
56081 off_t offset, size_t count);
56082-};
56083+} __no_const;
56084
56085 /*
56086 * Kernel text modification mutex, used for code patching. Users of this lock
56087diff -urNp linux-3.0.4/include/linux/mfd/abx500.h linux-3.0.4/include/linux/mfd/abx500.h
56088--- linux-3.0.4/include/linux/mfd/abx500.h 2011-07-21 22:17:23.000000000 -0400
56089+++ linux-3.0.4/include/linux/mfd/abx500.h 2011-08-23 21:47:56.000000000 -0400
56090@@ -234,6 +234,7 @@ struct abx500_ops {
56091 int (*event_registers_startup_state_get) (struct device *, u8 *);
56092 int (*startup_irq_enabled) (struct device *, unsigned int);
56093 };
56094+typedef struct abx500_ops __no_const abx500_ops_no_const;
56095
56096 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
56097 void abx500_remove_ops(struct device *dev);
56098diff -urNp linux-3.0.4/include/linux/mm.h linux-3.0.4/include/linux/mm.h
56099--- linux-3.0.4/include/linux/mm.h 2011-09-02 18:11:21.000000000 -0400
56100+++ linux-3.0.4/include/linux/mm.h 2011-08-23 21:47:56.000000000 -0400
56101@@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
56102
56103 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
56104 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
56105+
56106+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
56107+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
56108+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
56109+#else
56110 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
56111+#endif
56112+
56113 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
56114 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
56115
56116@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
56117 int set_page_dirty_lock(struct page *page);
56118 int clear_page_dirty_for_io(struct page *page);
56119
56120-/* Is the vma a continuation of the stack vma above it? */
56121-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
56122-{
56123- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
56124-}
56125-
56126-static inline int stack_guard_page_start(struct vm_area_struct *vma,
56127- unsigned long addr)
56128-{
56129- return (vma->vm_flags & VM_GROWSDOWN) &&
56130- (vma->vm_start == addr) &&
56131- !vma_growsdown(vma->vm_prev, addr);
56132-}
56133-
56134-/* Is the vma a continuation of the stack vma below it? */
56135-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
56136-{
56137- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
56138-}
56139-
56140-static inline int stack_guard_page_end(struct vm_area_struct *vma,
56141- unsigned long addr)
56142-{
56143- return (vma->vm_flags & VM_GROWSUP) &&
56144- (vma->vm_end == addr) &&
56145- !vma_growsup(vma->vm_next, addr);
56146-}
56147-
56148 extern unsigned long move_page_tables(struct vm_area_struct *vma,
56149 unsigned long old_addr, struct vm_area_struct *new_vma,
56150 unsigned long new_addr, unsigned long len);
56151@@ -1169,6 +1148,15 @@ struct shrinker {
56152 extern void register_shrinker(struct shrinker *);
56153 extern void unregister_shrinker(struct shrinker *);
56154
56155+#ifdef CONFIG_MMU
56156+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
56157+#else
56158+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
56159+{
56160+ return __pgprot(0);
56161+}
56162+#endif
56163+
56164 int vma_wants_writenotify(struct vm_area_struct *vma);
56165
56166 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
56167@@ -1452,6 +1440,7 @@ out:
56168 }
56169
56170 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
56171+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
56172
56173 extern unsigned long do_brk(unsigned long, unsigned long);
56174
56175@@ -1510,6 +1499,10 @@ extern struct vm_area_struct * find_vma(
56176 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
56177 struct vm_area_struct **pprev);
56178
56179+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
56180+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
56181+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
56182+
56183 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
56184 NULL if none. Assume start_addr < end_addr. */
56185 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
56186@@ -1526,15 +1519,6 @@ static inline unsigned long vma_pages(st
56187 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
56188 }
56189
56190-#ifdef CONFIG_MMU
56191-pgprot_t vm_get_page_prot(unsigned long vm_flags);
56192-#else
56193-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
56194-{
56195- return __pgprot(0);
56196-}
56197-#endif
56198-
56199 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
56200 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
56201 unsigned long pfn, unsigned long size, pgprot_t);
56202@@ -1647,7 +1631,7 @@ extern int unpoison_memory(unsigned long
56203 extern int sysctl_memory_failure_early_kill;
56204 extern int sysctl_memory_failure_recovery;
56205 extern void shake_page(struct page *p, int access);
56206-extern atomic_long_t mce_bad_pages;
56207+extern atomic_long_unchecked_t mce_bad_pages;
56208 extern int soft_offline_page(struct page *page, int flags);
56209
56210 extern void dump_page(struct page *page);
56211@@ -1661,5 +1645,11 @@ extern void copy_user_huge_page(struct p
56212 unsigned int pages_per_huge_page);
56213 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
56214
56215+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56216+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
56217+#else
56218+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
56219+#endif
56220+
56221 #endif /* __KERNEL__ */
56222 #endif /* _LINUX_MM_H */
56223diff -urNp linux-3.0.4/include/linux/mm_types.h linux-3.0.4/include/linux/mm_types.h
56224--- linux-3.0.4/include/linux/mm_types.h 2011-07-21 22:17:23.000000000 -0400
56225+++ linux-3.0.4/include/linux/mm_types.h 2011-08-23 21:47:56.000000000 -0400
56226@@ -184,6 +184,8 @@ struct vm_area_struct {
56227 #ifdef CONFIG_NUMA
56228 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
56229 #endif
56230+
56231+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
56232 };
56233
56234 struct core_thread {
56235@@ -316,6 +318,24 @@ struct mm_struct {
56236 #ifdef CONFIG_CPUMASK_OFFSTACK
56237 struct cpumask cpumask_allocation;
56238 #endif
56239+
56240+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56241+ unsigned long pax_flags;
56242+#endif
56243+
56244+#ifdef CONFIG_PAX_DLRESOLVE
56245+ unsigned long call_dl_resolve;
56246+#endif
56247+
56248+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56249+ unsigned long call_syscall;
56250+#endif
56251+
56252+#ifdef CONFIG_PAX_ASLR
56253+ unsigned long delta_mmap; /* randomized offset */
56254+ unsigned long delta_stack; /* randomized offset */
56255+#endif
56256+
56257 };
56258
56259 static inline void mm_init_cpumask(struct mm_struct *mm)
56260diff -urNp linux-3.0.4/include/linux/mmu_notifier.h linux-3.0.4/include/linux/mmu_notifier.h
56261--- linux-3.0.4/include/linux/mmu_notifier.h 2011-07-21 22:17:23.000000000 -0400
56262+++ linux-3.0.4/include/linux/mmu_notifier.h 2011-08-23 21:47:56.000000000 -0400
56263@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
56264 */
56265 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
56266 ({ \
56267- pte_t __pte; \
56268+ pte_t ___pte; \
56269 struct vm_area_struct *___vma = __vma; \
56270 unsigned long ___address = __address; \
56271- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
56272+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
56273 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
56274- __pte; \
56275+ ___pte; \
56276 })
56277
56278 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
56279diff -urNp linux-3.0.4/include/linux/mmzone.h linux-3.0.4/include/linux/mmzone.h
56280--- linux-3.0.4/include/linux/mmzone.h 2011-07-21 22:17:23.000000000 -0400
56281+++ linux-3.0.4/include/linux/mmzone.h 2011-08-23 21:47:56.000000000 -0400
56282@@ -350,7 +350,7 @@ struct zone {
56283 unsigned long flags; /* zone flags, see below */
56284
56285 /* Zone statistics */
56286- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
56287+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
56288
56289 /*
56290 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
56291diff -urNp linux-3.0.4/include/linux/mod_devicetable.h linux-3.0.4/include/linux/mod_devicetable.h
56292--- linux-3.0.4/include/linux/mod_devicetable.h 2011-07-21 22:17:23.000000000 -0400
56293+++ linux-3.0.4/include/linux/mod_devicetable.h 2011-08-23 21:47:56.000000000 -0400
56294@@ -12,7 +12,7 @@
56295 typedef unsigned long kernel_ulong_t;
56296 #endif
56297
56298-#define PCI_ANY_ID (~0)
56299+#define PCI_ANY_ID ((__u16)~0)
56300
56301 struct pci_device_id {
56302 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
56303@@ -131,7 +131,7 @@ struct usb_device_id {
56304 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
56305 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
56306
56307-#define HID_ANY_ID (~0)
56308+#define HID_ANY_ID (~0U)
56309
56310 struct hid_device_id {
56311 __u16 bus;
56312diff -urNp linux-3.0.4/include/linux/module.h linux-3.0.4/include/linux/module.h
56313--- linux-3.0.4/include/linux/module.h 2011-07-21 22:17:23.000000000 -0400
56314+++ linux-3.0.4/include/linux/module.h 2011-08-23 21:47:56.000000000 -0400
56315@@ -16,6 +16,7 @@
56316 #include <linux/kobject.h>
56317 #include <linux/moduleparam.h>
56318 #include <linux/tracepoint.h>
56319+#include <linux/fs.h>
56320
56321 #include <linux/percpu.h>
56322 #include <asm/module.h>
56323@@ -325,19 +326,16 @@ struct module
56324 int (*init)(void);
56325
56326 /* If this is non-NULL, vfree after init() returns */
56327- void *module_init;
56328+ void *module_init_rx, *module_init_rw;
56329
56330 /* Here is the actual code + data, vfree'd on unload. */
56331- void *module_core;
56332+ void *module_core_rx, *module_core_rw;
56333
56334 /* Here are the sizes of the init and core sections */
56335- unsigned int init_size, core_size;
56336+ unsigned int init_size_rw, core_size_rw;
56337
56338 /* The size of the executable code in each section. */
56339- unsigned int init_text_size, core_text_size;
56340-
56341- /* Size of RO sections of the module (text+rodata) */
56342- unsigned int init_ro_size, core_ro_size;
56343+ unsigned int init_size_rx, core_size_rx;
56344
56345 /* Arch-specific module values */
56346 struct mod_arch_specific arch;
56347@@ -393,6 +391,10 @@ struct module
56348 #ifdef CONFIG_EVENT_TRACING
56349 struct ftrace_event_call **trace_events;
56350 unsigned int num_trace_events;
56351+ struct file_operations trace_id;
56352+ struct file_operations trace_enable;
56353+ struct file_operations trace_format;
56354+ struct file_operations trace_filter;
56355 #endif
56356 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
56357 unsigned int num_ftrace_callsites;
56358@@ -443,16 +445,46 @@ bool is_module_address(unsigned long add
56359 bool is_module_percpu_address(unsigned long addr);
56360 bool is_module_text_address(unsigned long addr);
56361
56362+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
56363+{
56364+
56365+#ifdef CONFIG_PAX_KERNEXEC
56366+ if (ktla_ktva(addr) >= (unsigned long)start &&
56367+ ktla_ktva(addr) < (unsigned long)start + size)
56368+ return 1;
56369+#endif
56370+
56371+ return ((void *)addr >= start && (void *)addr < start + size);
56372+}
56373+
56374+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
56375+{
56376+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
56377+}
56378+
56379+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
56380+{
56381+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
56382+}
56383+
56384+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
56385+{
56386+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
56387+}
56388+
56389+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
56390+{
56391+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
56392+}
56393+
56394 static inline int within_module_core(unsigned long addr, struct module *mod)
56395 {
56396- return (unsigned long)mod->module_core <= addr &&
56397- addr < (unsigned long)mod->module_core + mod->core_size;
56398+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
56399 }
56400
56401 static inline int within_module_init(unsigned long addr, struct module *mod)
56402 {
56403- return (unsigned long)mod->module_init <= addr &&
56404- addr < (unsigned long)mod->module_init + mod->init_size;
56405+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
56406 }
56407
56408 /* Search for module by name: must hold module_mutex. */
56409diff -urNp linux-3.0.4/include/linux/moduleloader.h linux-3.0.4/include/linux/moduleloader.h
56410--- linux-3.0.4/include/linux/moduleloader.h 2011-07-21 22:17:23.000000000 -0400
56411+++ linux-3.0.4/include/linux/moduleloader.h 2011-08-23 21:47:56.000000000 -0400
56412@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
56413 sections. Returns NULL on failure. */
56414 void *module_alloc(unsigned long size);
56415
56416+#ifdef CONFIG_PAX_KERNEXEC
56417+void *module_alloc_exec(unsigned long size);
56418+#else
56419+#define module_alloc_exec(x) module_alloc(x)
56420+#endif
56421+
56422 /* Free memory returned from module_alloc. */
56423 void module_free(struct module *mod, void *module_region);
56424
56425+#ifdef CONFIG_PAX_KERNEXEC
56426+void module_free_exec(struct module *mod, void *module_region);
56427+#else
56428+#define module_free_exec(x, y) module_free((x), (y))
56429+#endif
56430+
56431 /* Apply the given relocation to the (simplified) ELF. Return -error
56432 or 0. */
56433 int apply_relocate(Elf_Shdr *sechdrs,
56434diff -urNp linux-3.0.4/include/linux/moduleparam.h linux-3.0.4/include/linux/moduleparam.h
56435--- linux-3.0.4/include/linux/moduleparam.h 2011-07-21 22:17:23.000000000 -0400
56436+++ linux-3.0.4/include/linux/moduleparam.h 2011-08-23 21:47:56.000000000 -0400
56437@@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
56438 * @len is usually just sizeof(string).
56439 */
56440 #define module_param_string(name, string, len, perm) \
56441- static const struct kparam_string __param_string_##name \
56442+ static const struct kparam_string __param_string_##name __used \
56443 = { len, string }; \
56444 __module_param_call(MODULE_PARAM_PREFIX, name, \
56445 &param_ops_string, \
56446@@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
56447 * module_param_named() for why this might be necessary.
56448 */
56449 #define module_param_array_named(name, array, type, nump, perm) \
56450- static const struct kparam_array __param_arr_##name \
56451+ static const struct kparam_array __param_arr_##name __used \
56452 = { .max = ARRAY_SIZE(array), .num = nump, \
56453 .ops = &param_ops_##type, \
56454 .elemsize = sizeof(array[0]), .elem = array }; \
56455diff -urNp linux-3.0.4/include/linux/namei.h linux-3.0.4/include/linux/namei.h
56456--- linux-3.0.4/include/linux/namei.h 2011-07-21 22:17:23.000000000 -0400
56457+++ linux-3.0.4/include/linux/namei.h 2011-08-23 21:47:56.000000000 -0400
56458@@ -24,7 +24,7 @@ struct nameidata {
56459 unsigned seq;
56460 int last_type;
56461 unsigned depth;
56462- char *saved_names[MAX_NESTED_LINKS + 1];
56463+ const char *saved_names[MAX_NESTED_LINKS + 1];
56464
56465 /* Intent data */
56466 union {
56467@@ -91,12 +91,12 @@ extern int follow_up(struct path *);
56468 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
56469 extern void unlock_rename(struct dentry *, struct dentry *);
56470
56471-static inline void nd_set_link(struct nameidata *nd, char *path)
56472+static inline void nd_set_link(struct nameidata *nd, const char *path)
56473 {
56474 nd->saved_names[nd->depth] = path;
56475 }
56476
56477-static inline char *nd_get_link(struct nameidata *nd)
56478+static inline const char *nd_get_link(const struct nameidata *nd)
56479 {
56480 return nd->saved_names[nd->depth];
56481 }
56482diff -urNp linux-3.0.4/include/linux/netdevice.h linux-3.0.4/include/linux/netdevice.h
56483--- linux-3.0.4/include/linux/netdevice.h 2011-09-02 18:11:21.000000000 -0400
56484+++ linux-3.0.4/include/linux/netdevice.h 2011-08-23 21:47:56.000000000 -0400
56485@@ -979,6 +979,7 @@ struct net_device_ops {
56486 int (*ndo_set_features)(struct net_device *dev,
56487 u32 features);
56488 };
56489+typedef struct net_device_ops __no_const net_device_ops_no_const;
56490
56491 /*
56492 * The DEVICE structure.
56493diff -urNp linux-3.0.4/include/linux/netfilter/xt_gradm.h linux-3.0.4/include/linux/netfilter/xt_gradm.h
56494--- linux-3.0.4/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
56495+++ linux-3.0.4/include/linux/netfilter/xt_gradm.h 2011-08-23 21:48:14.000000000 -0400
56496@@ -0,0 +1,9 @@
56497+#ifndef _LINUX_NETFILTER_XT_GRADM_H
56498+#define _LINUX_NETFILTER_XT_GRADM_H 1
56499+
56500+struct xt_gradm_mtinfo {
56501+ __u16 flags;
56502+ __u16 invflags;
56503+};
56504+
56505+#endif
56506diff -urNp linux-3.0.4/include/linux/of_pdt.h linux-3.0.4/include/linux/of_pdt.h
56507--- linux-3.0.4/include/linux/of_pdt.h 2011-07-21 22:17:23.000000000 -0400
56508+++ linux-3.0.4/include/linux/of_pdt.h 2011-08-30 06:20:11.000000000 -0400
56509@@ -32,7 +32,7 @@ struct of_pdt_ops {
56510
56511 /* return 0 on success; fill in 'len' with number of bytes in path */
56512 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
56513-};
56514+} __no_const;
56515
56516 extern void *prom_early_alloc(unsigned long size);
56517
56518diff -urNp linux-3.0.4/include/linux/oprofile.h linux-3.0.4/include/linux/oprofile.h
56519--- linux-3.0.4/include/linux/oprofile.h 2011-07-21 22:17:23.000000000 -0400
56520+++ linux-3.0.4/include/linux/oprofile.h 2011-08-23 21:47:56.000000000 -0400
56521@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
56522 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
56523 char const * name, ulong * val);
56524
56525-/** Create a file for read-only access to an atomic_t. */
56526+/** Create a file for read-only access to an atomic_unchecked_t. */
56527 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
56528- char const * name, atomic_t * val);
56529+ char const * name, atomic_unchecked_t * val);
56530
56531 /** create a directory */
56532 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
56533diff -urNp linux-3.0.4/include/linux/padata.h linux-3.0.4/include/linux/padata.h
56534--- linux-3.0.4/include/linux/padata.h 2011-07-21 22:17:23.000000000 -0400
56535+++ linux-3.0.4/include/linux/padata.h 2011-08-23 21:47:56.000000000 -0400
56536@@ -129,7 +129,7 @@ struct parallel_data {
56537 struct padata_instance *pinst;
56538 struct padata_parallel_queue __percpu *pqueue;
56539 struct padata_serial_queue __percpu *squeue;
56540- atomic_t seq_nr;
56541+ atomic_unchecked_t seq_nr;
56542 atomic_t reorder_objects;
56543 atomic_t refcnt;
56544 unsigned int max_seq_nr;
56545diff -urNp linux-3.0.4/include/linux/perf_event.h linux-3.0.4/include/linux/perf_event.h
56546--- linux-3.0.4/include/linux/perf_event.h 2011-07-21 22:17:23.000000000 -0400
56547+++ linux-3.0.4/include/linux/perf_event.h 2011-08-23 21:47:56.000000000 -0400
56548@@ -761,8 +761,8 @@ struct perf_event {
56549
56550 enum perf_event_active_state state;
56551 unsigned int attach_state;
56552- local64_t count;
56553- atomic64_t child_count;
56554+ local64_t count; /* PaX: fix it one day */
56555+ atomic64_unchecked_t child_count;
56556
56557 /*
56558 * These are the total time in nanoseconds that the event
56559@@ -813,8 +813,8 @@ struct perf_event {
56560 * These accumulate total time (in nanoseconds) that children
56561 * events have been enabled and running, respectively.
56562 */
56563- atomic64_t child_total_time_enabled;
56564- atomic64_t child_total_time_running;
56565+ atomic64_unchecked_t child_total_time_enabled;
56566+ atomic64_unchecked_t child_total_time_running;
56567
56568 /*
56569 * Protect attach/detach and child_list:
56570diff -urNp linux-3.0.4/include/linux/pipe_fs_i.h linux-3.0.4/include/linux/pipe_fs_i.h
56571--- linux-3.0.4/include/linux/pipe_fs_i.h 2011-07-21 22:17:23.000000000 -0400
56572+++ linux-3.0.4/include/linux/pipe_fs_i.h 2011-08-23 21:47:56.000000000 -0400
56573@@ -46,9 +46,9 @@ struct pipe_buffer {
56574 struct pipe_inode_info {
56575 wait_queue_head_t wait;
56576 unsigned int nrbufs, curbuf, buffers;
56577- unsigned int readers;
56578- unsigned int writers;
56579- unsigned int waiting_writers;
56580+ atomic_t readers;
56581+ atomic_t writers;
56582+ atomic_t waiting_writers;
56583 unsigned int r_counter;
56584 unsigned int w_counter;
56585 struct page *tmp_page;
56586diff -urNp linux-3.0.4/include/linux/pm_runtime.h linux-3.0.4/include/linux/pm_runtime.h
56587--- linux-3.0.4/include/linux/pm_runtime.h 2011-07-21 22:17:23.000000000 -0400
56588+++ linux-3.0.4/include/linux/pm_runtime.h 2011-08-23 21:47:56.000000000 -0400
56589@@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
56590
56591 static inline void pm_runtime_mark_last_busy(struct device *dev)
56592 {
56593- ACCESS_ONCE(dev->power.last_busy) = jiffies;
56594+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
56595 }
56596
56597 #else /* !CONFIG_PM_RUNTIME */
56598diff -urNp linux-3.0.4/include/linux/poison.h linux-3.0.4/include/linux/poison.h
56599--- linux-3.0.4/include/linux/poison.h 2011-07-21 22:17:23.000000000 -0400
56600+++ linux-3.0.4/include/linux/poison.h 2011-08-23 21:47:56.000000000 -0400
56601@@ -19,8 +19,8 @@
56602 * under normal circumstances, used to verify that nobody uses
56603 * non-initialized list entries.
56604 */
56605-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
56606-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
56607+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
56608+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
56609
56610 /********** include/linux/timer.h **********/
56611 /*
56612diff -urNp linux-3.0.4/include/linux/preempt.h linux-3.0.4/include/linux/preempt.h
56613--- linux-3.0.4/include/linux/preempt.h 2011-07-21 22:17:23.000000000 -0400
56614+++ linux-3.0.4/include/linux/preempt.h 2011-08-23 21:47:56.000000000 -0400
56615@@ -115,7 +115,7 @@ struct preempt_ops {
56616 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
56617 void (*sched_out)(struct preempt_notifier *notifier,
56618 struct task_struct *next);
56619-};
56620+} __no_const;
56621
56622 /**
56623 * preempt_notifier - key for installing preemption notifiers
56624diff -urNp linux-3.0.4/include/linux/proc_fs.h linux-3.0.4/include/linux/proc_fs.h
56625--- linux-3.0.4/include/linux/proc_fs.h 2011-07-21 22:17:23.000000000 -0400
56626+++ linux-3.0.4/include/linux/proc_fs.h 2011-08-23 21:48:14.000000000 -0400
56627@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
56628 return proc_create_data(name, mode, parent, proc_fops, NULL);
56629 }
56630
56631+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
56632+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
56633+{
56634+#ifdef CONFIG_GRKERNSEC_PROC_USER
56635+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
56636+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56637+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
56638+#else
56639+ return proc_create_data(name, mode, parent, proc_fops, NULL);
56640+#endif
56641+}
56642+
56643+
56644 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
56645 mode_t mode, struct proc_dir_entry *base,
56646 read_proc_t *read_proc, void * data)
56647@@ -258,7 +271,7 @@ union proc_op {
56648 int (*proc_show)(struct seq_file *m,
56649 struct pid_namespace *ns, struct pid *pid,
56650 struct task_struct *task);
56651-};
56652+} __no_const;
56653
56654 struct ctl_table_header;
56655 struct ctl_table;
56656diff -urNp linux-3.0.4/include/linux/ptrace.h linux-3.0.4/include/linux/ptrace.h
56657--- linux-3.0.4/include/linux/ptrace.h 2011-07-21 22:17:23.000000000 -0400
56658+++ linux-3.0.4/include/linux/ptrace.h 2011-08-23 21:48:14.000000000 -0400
56659@@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
56660 extern void exit_ptrace(struct task_struct *tracer);
56661 #define PTRACE_MODE_READ 1
56662 #define PTRACE_MODE_ATTACH 2
56663-/* Returns 0 on success, -errno on denial. */
56664-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
56665 /* Returns true on success, false on denial. */
56666 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
56667+/* Returns true on success, false on denial. */
56668+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
56669
56670 static inline int ptrace_reparented(struct task_struct *child)
56671 {
56672diff -urNp linux-3.0.4/include/linux/random.h linux-3.0.4/include/linux/random.h
56673--- linux-3.0.4/include/linux/random.h 2011-09-02 18:11:21.000000000 -0400
56674+++ linux-3.0.4/include/linux/random.h 2011-08-23 21:47:56.000000000 -0400
56675@@ -69,12 +69,17 @@ void srandom32(u32 seed);
56676
56677 u32 prandom32(struct rnd_state *);
56678
56679+static inline unsigned long pax_get_random_long(void)
56680+{
56681+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
56682+}
56683+
56684 /*
56685 * Handle minimum values for seeds
56686 */
56687 static inline u32 __seed(u32 x, u32 m)
56688 {
56689- return (x < m) ? x + m : x;
56690+ return (x <= m) ? x + m + 1 : x;
56691 }
56692
56693 /**
56694diff -urNp linux-3.0.4/include/linux/reboot.h linux-3.0.4/include/linux/reboot.h
56695--- linux-3.0.4/include/linux/reboot.h 2011-07-21 22:17:23.000000000 -0400
56696+++ linux-3.0.4/include/linux/reboot.h 2011-08-23 21:47:56.000000000 -0400
56697@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
56698 * Architecture-specific implementations of sys_reboot commands.
56699 */
56700
56701-extern void machine_restart(char *cmd);
56702-extern void machine_halt(void);
56703-extern void machine_power_off(void);
56704+extern void machine_restart(char *cmd) __noreturn;
56705+extern void machine_halt(void) __noreturn;
56706+extern void machine_power_off(void) __noreturn;
56707
56708 extern void machine_shutdown(void);
56709 struct pt_regs;
56710@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
56711 */
56712
56713 extern void kernel_restart_prepare(char *cmd);
56714-extern void kernel_restart(char *cmd);
56715-extern void kernel_halt(void);
56716-extern void kernel_power_off(void);
56717+extern void kernel_restart(char *cmd) __noreturn;
56718+extern void kernel_halt(void) __noreturn;
56719+extern void kernel_power_off(void) __noreturn;
56720
56721 extern int C_A_D; /* for sysctl */
56722 void ctrl_alt_del(void);
56723@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
56724 * Emergency restart, callable from an interrupt handler.
56725 */
56726
56727-extern void emergency_restart(void);
56728+extern void emergency_restart(void) __noreturn;
56729 #include <asm/emergency-restart.h>
56730
56731 #endif
56732diff -urNp linux-3.0.4/include/linux/reiserfs_fs.h linux-3.0.4/include/linux/reiserfs_fs.h
56733--- linux-3.0.4/include/linux/reiserfs_fs.h 2011-07-21 22:17:23.000000000 -0400
56734+++ linux-3.0.4/include/linux/reiserfs_fs.h 2011-08-23 21:47:56.000000000 -0400
56735@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
56736 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56737
56738 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56739-#define get_generation(s) atomic_read (&fs_generation(s))
56740+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56741 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56742 #define __fs_changed(gen,s) (gen != get_generation (s))
56743 #define fs_changed(gen,s) \
56744diff -urNp linux-3.0.4/include/linux/reiserfs_fs_sb.h linux-3.0.4/include/linux/reiserfs_fs_sb.h
56745--- linux-3.0.4/include/linux/reiserfs_fs_sb.h 2011-07-21 22:17:23.000000000 -0400
56746+++ linux-3.0.4/include/linux/reiserfs_fs_sb.h 2011-08-23 21:47:56.000000000 -0400
56747@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
56748 /* Comment? -Hans */
56749 wait_queue_head_t s_wait;
56750 /* To be obsoleted soon by per buffer seals.. -Hans */
56751- atomic_t s_generation_counter; // increased by one every time the
56752+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56753 // tree gets re-balanced
56754 unsigned long s_properties; /* File system properties. Currently holds
56755 on-disk FS format */
56756diff -urNp linux-3.0.4/include/linux/relay.h linux-3.0.4/include/linux/relay.h
56757--- linux-3.0.4/include/linux/relay.h 2011-07-21 22:17:23.000000000 -0400
56758+++ linux-3.0.4/include/linux/relay.h 2011-08-23 21:47:56.000000000 -0400
56759@@ -159,7 +159,7 @@ struct rchan_callbacks
56760 * The callback should return 0 if successful, negative if not.
56761 */
56762 int (*remove_buf_file)(struct dentry *dentry);
56763-};
56764+} __no_const;
56765
56766 /*
56767 * CONFIG_RELAY kernel API, kernel/relay.c
56768diff -urNp linux-3.0.4/include/linux/rfkill.h linux-3.0.4/include/linux/rfkill.h
56769--- linux-3.0.4/include/linux/rfkill.h 2011-07-21 22:17:23.000000000 -0400
56770+++ linux-3.0.4/include/linux/rfkill.h 2011-08-23 21:47:56.000000000 -0400
56771@@ -147,6 +147,7 @@ struct rfkill_ops {
56772 void (*query)(struct rfkill *rfkill, void *data);
56773 int (*set_block)(void *data, bool blocked);
56774 };
56775+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
56776
56777 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
56778 /**
56779diff -urNp linux-3.0.4/include/linux/rmap.h linux-3.0.4/include/linux/rmap.h
56780--- linux-3.0.4/include/linux/rmap.h 2011-07-21 22:17:23.000000000 -0400
56781+++ linux-3.0.4/include/linux/rmap.h 2011-08-23 21:47:56.000000000 -0400
56782@@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
56783 void anon_vma_init(void); /* create anon_vma_cachep */
56784 int anon_vma_prepare(struct vm_area_struct *);
56785 void unlink_anon_vmas(struct vm_area_struct *);
56786-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
56787-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
56788+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
56789+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
56790 void __anon_vma_link(struct vm_area_struct *);
56791
56792 static inline void anon_vma_merge(struct vm_area_struct *vma,
56793diff -urNp linux-3.0.4/include/linux/sched.h linux-3.0.4/include/linux/sched.h
56794--- linux-3.0.4/include/linux/sched.h 2011-07-21 22:17:23.000000000 -0400
56795+++ linux-3.0.4/include/linux/sched.h 2011-08-25 17:22:27.000000000 -0400
56796@@ -100,6 +100,7 @@ struct bio_list;
56797 struct fs_struct;
56798 struct perf_event_context;
56799 struct blk_plug;
56800+struct linux_binprm;
56801
56802 /*
56803 * List of flags we want to share for kernel threads,
56804@@ -380,10 +381,13 @@ struct user_namespace;
56805 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
56806
56807 extern int sysctl_max_map_count;
56808+extern unsigned long sysctl_heap_stack_gap;
56809
56810 #include <linux/aio.h>
56811
56812 #ifdef CONFIG_MMU
56813+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
56814+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
56815 extern void arch_pick_mmap_layout(struct mm_struct *mm);
56816 extern unsigned long
56817 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
56818@@ -629,6 +633,17 @@ struct signal_struct {
56819 #ifdef CONFIG_TASKSTATS
56820 struct taskstats *stats;
56821 #endif
56822+
56823+#ifdef CONFIG_GRKERNSEC
56824+ u32 curr_ip;
56825+ u32 saved_ip;
56826+ u32 gr_saddr;
56827+ u32 gr_daddr;
56828+ u16 gr_sport;
56829+ u16 gr_dport;
56830+ u8 used_accept:1;
56831+#endif
56832+
56833 #ifdef CONFIG_AUDIT
56834 unsigned audit_tty;
56835 struct tty_audit_buf *tty_audit_buf;
56836@@ -710,6 +725,11 @@ struct user_struct {
56837 struct key *session_keyring; /* UID's default session keyring */
56838 #endif
56839
56840+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56841+ unsigned int banned;
56842+ unsigned long ban_expires;
56843+#endif
56844+
56845 /* Hash table maintenance information */
56846 struct hlist_node uidhash_node;
56847 uid_t uid;
56848@@ -1340,8 +1360,8 @@ struct task_struct {
56849 struct list_head thread_group;
56850
56851 struct completion *vfork_done; /* for vfork() */
56852- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
56853- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
56854+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
56855+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
56856
56857 cputime_t utime, stime, utimescaled, stimescaled;
56858 cputime_t gtime;
56859@@ -1357,13 +1377,6 @@ struct task_struct {
56860 struct task_cputime cputime_expires;
56861 struct list_head cpu_timers[3];
56862
56863-/* process credentials */
56864- const struct cred __rcu *real_cred; /* objective and real subjective task
56865- * credentials (COW) */
56866- const struct cred __rcu *cred; /* effective (overridable) subjective task
56867- * credentials (COW) */
56868- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
56869-
56870 char comm[TASK_COMM_LEN]; /* executable name excluding path
56871 - access with [gs]et_task_comm (which lock
56872 it with task_lock())
56873@@ -1380,8 +1393,16 @@ struct task_struct {
56874 #endif
56875 /* CPU-specific state of this task */
56876 struct thread_struct thread;
56877+/* thread_info moved to task_struct */
56878+#ifdef CONFIG_X86
56879+ struct thread_info tinfo;
56880+#endif
56881 /* filesystem information */
56882 struct fs_struct *fs;
56883+
56884+ const struct cred __rcu *cred; /* effective (overridable) subjective task
56885+ * credentials (COW) */
56886+
56887 /* open file information */
56888 struct files_struct *files;
56889 /* namespaces */
56890@@ -1428,6 +1449,11 @@ struct task_struct {
56891 struct rt_mutex_waiter *pi_blocked_on;
56892 #endif
56893
56894+/* process credentials */
56895+ const struct cred __rcu *real_cred; /* objective and real subjective task
56896+ * credentials (COW) */
56897+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
56898+
56899 #ifdef CONFIG_DEBUG_MUTEXES
56900 /* mutex deadlock detection */
56901 struct mutex_waiter *blocked_on;
56902@@ -1538,6 +1564,21 @@ struct task_struct {
56903 unsigned long default_timer_slack_ns;
56904
56905 struct list_head *scm_work_list;
56906+
56907+#ifdef CONFIG_GRKERNSEC
56908+ /* grsecurity */
56909+ struct dentry *gr_chroot_dentry;
56910+ struct acl_subject_label *acl;
56911+ struct acl_role_label *role;
56912+ struct file *exec_file;
56913+ u16 acl_role_id;
56914+ /* is this the task that authenticated to the special role */
56915+ u8 acl_sp_role;
56916+ u8 is_writable;
56917+ u8 brute;
56918+ u8 gr_is_chrooted;
56919+#endif
56920+
56921 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
56922 /* Index of current stored address in ret_stack */
56923 int curr_ret_stack;
56924@@ -1572,6 +1613,57 @@ struct task_struct {
56925 #endif
56926 };
56927
56928+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
56929+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
56930+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
56931+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
56932+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
56933+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
56934+
56935+#ifdef CONFIG_PAX_SOFTMODE
56936+extern int pax_softmode;
56937+#endif
56938+
56939+extern int pax_check_flags(unsigned long *);
56940+
56941+/* if tsk != current then task_lock must be held on it */
56942+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56943+static inline unsigned long pax_get_flags(struct task_struct *tsk)
56944+{
56945+ if (likely(tsk->mm))
56946+ return tsk->mm->pax_flags;
56947+ else
56948+ return 0UL;
56949+}
56950+
56951+/* if tsk != current then task_lock must be held on it */
56952+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
56953+{
56954+ if (likely(tsk->mm)) {
56955+ tsk->mm->pax_flags = flags;
56956+ return 0;
56957+ }
56958+ return -EINVAL;
56959+}
56960+#endif
56961+
56962+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56963+extern void pax_set_initial_flags(struct linux_binprm *bprm);
56964+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56965+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
56966+#endif
56967+
56968+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
56969+extern void pax_report_insns(void *pc, void *sp);
56970+extern void pax_report_refcount_overflow(struct pt_regs *regs);
56971+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
56972+
56973+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56974+extern void pax_track_stack(void);
56975+#else
56976+static inline void pax_track_stack(void) {}
56977+#endif
56978+
56979 /* Future-safe accessor for struct task_struct's cpus_allowed. */
56980 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
56981
56982@@ -1768,6 +1860,7 @@ extern void thread_group_times(struct ta
56983 #define PF_DUMPCORE 0x00000200 /* dumped core */
56984 #define PF_SIGNALED 0x00000400 /* killed by a signal */
56985 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
56986+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
56987 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
56988 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
56989 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
56990@@ -2056,7 +2149,9 @@ void yield(void);
56991 extern struct exec_domain default_exec_domain;
56992
56993 union thread_union {
56994+#ifndef CONFIG_X86
56995 struct thread_info thread_info;
56996+#endif
56997 unsigned long stack[THREAD_SIZE/sizeof(long)];
56998 };
56999
57000@@ -2089,6 +2184,7 @@ extern struct pid_namespace init_pid_ns;
57001 */
57002
57003 extern struct task_struct *find_task_by_vpid(pid_t nr);
57004+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
57005 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
57006 struct pid_namespace *ns);
57007
57008@@ -2225,7 +2321,7 @@ extern void __cleanup_sighand(struct sig
57009 extern void exit_itimers(struct signal_struct *);
57010 extern void flush_itimer_signals(void);
57011
57012-extern NORET_TYPE void do_group_exit(int);
57013+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
57014
57015 extern void daemonize(const char *, ...);
57016 extern int allow_signal(int);
57017@@ -2393,13 +2489,17 @@ static inline unsigned long *end_of_stac
57018
57019 #endif
57020
57021-static inline int object_is_on_stack(void *obj)
57022+static inline int object_starts_on_stack(void *obj)
57023 {
57024- void *stack = task_stack_page(current);
57025+ const void *stack = task_stack_page(current);
57026
57027 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
57028 }
57029
57030+#ifdef CONFIG_PAX_USERCOPY
57031+extern int object_is_on_stack(const void *obj, unsigned long len);
57032+#endif
57033+
57034 extern void thread_info_cache_init(void);
57035
57036 #ifdef CONFIG_DEBUG_STACK_USAGE
57037diff -urNp linux-3.0.4/include/linux/screen_info.h linux-3.0.4/include/linux/screen_info.h
57038--- linux-3.0.4/include/linux/screen_info.h 2011-07-21 22:17:23.000000000 -0400
57039+++ linux-3.0.4/include/linux/screen_info.h 2011-08-23 21:47:56.000000000 -0400
57040@@ -43,7 +43,8 @@ struct screen_info {
57041 __u16 pages; /* 0x32 */
57042 __u16 vesa_attributes; /* 0x34 */
57043 __u32 capabilities; /* 0x36 */
57044- __u8 _reserved[6]; /* 0x3a */
57045+ __u16 vesapm_size; /* 0x3a */
57046+ __u8 _reserved[4]; /* 0x3c */
57047 } __attribute__((packed));
57048
57049 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
57050diff -urNp linux-3.0.4/include/linux/security.h linux-3.0.4/include/linux/security.h
57051--- linux-3.0.4/include/linux/security.h 2011-07-21 22:17:23.000000000 -0400
57052+++ linux-3.0.4/include/linux/security.h 2011-08-23 21:48:14.000000000 -0400
57053@@ -36,6 +36,7 @@
57054 #include <linux/key.h>
57055 #include <linux/xfrm.h>
57056 #include <linux/slab.h>
57057+#include <linux/grsecurity.h>
57058 #include <net/flow.h>
57059
57060 /* Maximum number of letters for an LSM name string */
57061diff -urNp linux-3.0.4/include/linux/seq_file.h linux-3.0.4/include/linux/seq_file.h
57062--- linux-3.0.4/include/linux/seq_file.h 2011-07-21 22:17:23.000000000 -0400
57063+++ linux-3.0.4/include/linux/seq_file.h 2011-08-23 21:47:56.000000000 -0400
57064@@ -32,6 +32,7 @@ struct seq_operations {
57065 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
57066 int (*show) (struct seq_file *m, void *v);
57067 };
57068+typedef struct seq_operations __no_const seq_operations_no_const;
57069
57070 #define SEQ_SKIP 1
57071
57072diff -urNp linux-3.0.4/include/linux/shmem_fs.h linux-3.0.4/include/linux/shmem_fs.h
57073--- linux-3.0.4/include/linux/shmem_fs.h 2011-07-21 22:17:23.000000000 -0400
57074+++ linux-3.0.4/include/linux/shmem_fs.h 2011-08-23 21:47:56.000000000 -0400
57075@@ -10,7 +10,7 @@
57076
57077 #define SHMEM_NR_DIRECT 16
57078
57079-#define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
57080+#define SHMEM_SYMLINK_INLINE_LEN 64
57081
57082 struct shmem_inode_info {
57083 spinlock_t lock;
57084diff -urNp linux-3.0.4/include/linux/shm.h linux-3.0.4/include/linux/shm.h
57085--- linux-3.0.4/include/linux/shm.h 2011-07-21 22:17:23.000000000 -0400
57086+++ linux-3.0.4/include/linux/shm.h 2011-08-23 21:48:14.000000000 -0400
57087@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
57088 pid_t shm_cprid;
57089 pid_t shm_lprid;
57090 struct user_struct *mlock_user;
57091+#ifdef CONFIG_GRKERNSEC
57092+ time_t shm_createtime;
57093+ pid_t shm_lapid;
57094+#endif
57095 };
57096
57097 /* shm_mode upper byte flags */
57098diff -urNp linux-3.0.4/include/linux/skbuff.h linux-3.0.4/include/linux/skbuff.h
57099--- linux-3.0.4/include/linux/skbuff.h 2011-07-21 22:17:23.000000000 -0400
57100+++ linux-3.0.4/include/linux/skbuff.h 2011-08-23 21:47:56.000000000 -0400
57101@@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
57102 */
57103 static inline int skb_queue_empty(const struct sk_buff_head *list)
57104 {
57105- return list->next == (struct sk_buff *)list;
57106+ return list->next == (const struct sk_buff *)list;
57107 }
57108
57109 /**
57110@@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
57111 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
57112 const struct sk_buff *skb)
57113 {
57114- return skb->next == (struct sk_buff *)list;
57115+ return skb->next == (const struct sk_buff *)list;
57116 }
57117
57118 /**
57119@@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
57120 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
57121 const struct sk_buff *skb)
57122 {
57123- return skb->prev == (struct sk_buff *)list;
57124+ return skb->prev == (const struct sk_buff *)list;
57125 }
57126
57127 /**
57128@@ -1440,7 +1440,7 @@ static inline int pskb_network_may_pull(
57129 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
57130 */
57131 #ifndef NET_SKB_PAD
57132-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
57133+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
57134 #endif
57135
57136 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
57137diff -urNp linux-3.0.4/include/linux/slab_def.h linux-3.0.4/include/linux/slab_def.h
57138--- linux-3.0.4/include/linux/slab_def.h 2011-07-21 22:17:23.000000000 -0400
57139+++ linux-3.0.4/include/linux/slab_def.h 2011-08-23 21:47:56.000000000 -0400
57140@@ -96,10 +96,10 @@ struct kmem_cache {
57141 unsigned long node_allocs;
57142 unsigned long node_frees;
57143 unsigned long node_overflow;
57144- atomic_t allochit;
57145- atomic_t allocmiss;
57146- atomic_t freehit;
57147- atomic_t freemiss;
57148+ atomic_unchecked_t allochit;
57149+ atomic_unchecked_t allocmiss;
57150+ atomic_unchecked_t freehit;
57151+ atomic_unchecked_t freemiss;
57152
57153 /*
57154 * If debugging is enabled, then the allocator can add additional
57155diff -urNp linux-3.0.4/include/linux/slab.h linux-3.0.4/include/linux/slab.h
57156--- linux-3.0.4/include/linux/slab.h 2011-07-21 22:17:23.000000000 -0400
57157+++ linux-3.0.4/include/linux/slab.h 2011-08-23 21:47:56.000000000 -0400
57158@@ -11,12 +11,20 @@
57159
57160 #include <linux/gfp.h>
57161 #include <linux/types.h>
57162+#include <linux/err.h>
57163
57164 /*
57165 * Flags to pass to kmem_cache_create().
57166 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
57167 */
57168 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
57169+
57170+#ifdef CONFIG_PAX_USERCOPY
57171+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
57172+#else
57173+#define SLAB_USERCOPY 0x00000000UL
57174+#endif
57175+
57176 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
57177 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
57178 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
57179@@ -87,10 +95,13 @@
57180 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
57181 * Both make kfree a no-op.
57182 */
57183-#define ZERO_SIZE_PTR ((void *)16)
57184+#define ZERO_SIZE_PTR \
57185+({ \
57186+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
57187+ (void *)(-MAX_ERRNO-1L); \
57188+})
57189
57190-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
57191- (unsigned long)ZERO_SIZE_PTR)
57192+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
57193
57194 /*
57195 * struct kmem_cache related prototypes
57196@@ -141,6 +152,7 @@ void * __must_check krealloc(const void
57197 void kfree(const void *);
57198 void kzfree(const void *);
57199 size_t ksize(const void *);
57200+void check_object_size(const void *ptr, unsigned long n, bool to);
57201
57202 /*
57203 * Allocator specific definitions. These are mainly used to establish optimized
57204@@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
57205
57206 void __init kmem_cache_init_late(void);
57207
57208+#define kmalloc(x, y) \
57209+({ \
57210+ void *___retval; \
57211+ intoverflow_t ___x = (intoverflow_t)x; \
57212+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
57213+ ___retval = NULL; \
57214+ else \
57215+ ___retval = kmalloc((size_t)___x, (y)); \
57216+ ___retval; \
57217+})
57218+
57219+#define kmalloc_node(x, y, z) \
57220+({ \
57221+ void *___retval; \
57222+ intoverflow_t ___x = (intoverflow_t)x; \
57223+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
57224+ ___retval = NULL; \
57225+ else \
57226+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
57227+ ___retval; \
57228+})
57229+
57230+#define kzalloc(x, y) \
57231+({ \
57232+ void *___retval; \
57233+ intoverflow_t ___x = (intoverflow_t)x; \
57234+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
57235+ ___retval = NULL; \
57236+ else \
57237+ ___retval = kzalloc((size_t)___x, (y)); \
57238+ ___retval; \
57239+})
57240+
57241+#define __krealloc(x, y, z) \
57242+({ \
57243+ void *___retval; \
57244+ intoverflow_t ___y = (intoverflow_t)y; \
57245+ if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
57246+ ___retval = NULL; \
57247+ else \
57248+ ___retval = __krealloc((x), (size_t)___y, (z)); \
57249+ ___retval; \
57250+})
57251+
57252+#define krealloc(x, y, z) \
57253+({ \
57254+ void *___retval; \
57255+ intoverflow_t ___y = (intoverflow_t)y; \
57256+ if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
57257+ ___retval = NULL; \
57258+ else \
57259+ ___retval = krealloc((x), (size_t)___y, (z)); \
57260+ ___retval; \
57261+})
57262+
57263 #endif /* _LINUX_SLAB_H */
57264diff -urNp linux-3.0.4/include/linux/slub_def.h linux-3.0.4/include/linux/slub_def.h
57265--- linux-3.0.4/include/linux/slub_def.h 2011-07-21 22:17:23.000000000 -0400
57266+++ linux-3.0.4/include/linux/slub_def.h 2011-08-23 21:47:56.000000000 -0400
57267@@ -82,7 +82,7 @@ struct kmem_cache {
57268 struct kmem_cache_order_objects max;
57269 struct kmem_cache_order_objects min;
57270 gfp_t allocflags; /* gfp flags to use on each alloc */
57271- int refcount; /* Refcount for slab cache destroy */
57272+ atomic_t refcount; /* Refcount for slab cache destroy */
57273 void (*ctor)(void *);
57274 int inuse; /* Offset to metadata */
57275 int align; /* Alignment */
57276@@ -218,7 +218,7 @@ static __always_inline struct kmem_cache
57277 }
57278
57279 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
57280-void *__kmalloc(size_t size, gfp_t flags);
57281+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
57282
57283 static __always_inline void *
57284 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
57285diff -urNp linux-3.0.4/include/linux/sonet.h linux-3.0.4/include/linux/sonet.h
57286--- linux-3.0.4/include/linux/sonet.h 2011-07-21 22:17:23.000000000 -0400
57287+++ linux-3.0.4/include/linux/sonet.h 2011-08-23 21:47:56.000000000 -0400
57288@@ -61,7 +61,7 @@ struct sonet_stats {
57289 #include <asm/atomic.h>
57290
57291 struct k_sonet_stats {
57292-#define __HANDLE_ITEM(i) atomic_t i
57293+#define __HANDLE_ITEM(i) atomic_unchecked_t i
57294 __SONET_ITEMS
57295 #undef __HANDLE_ITEM
57296 };
57297diff -urNp linux-3.0.4/include/linux/sunrpc/clnt.h linux-3.0.4/include/linux/sunrpc/clnt.h
57298--- linux-3.0.4/include/linux/sunrpc/clnt.h 2011-07-21 22:17:23.000000000 -0400
57299+++ linux-3.0.4/include/linux/sunrpc/clnt.h 2011-08-23 21:47:56.000000000 -0400
57300@@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
57301 {
57302 switch (sap->sa_family) {
57303 case AF_INET:
57304- return ntohs(((struct sockaddr_in *)sap)->sin_port);
57305+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
57306 case AF_INET6:
57307- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
57308+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
57309 }
57310 return 0;
57311 }
57312@@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
57313 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
57314 const struct sockaddr *src)
57315 {
57316- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
57317+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
57318 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
57319
57320 dsin->sin_family = ssin->sin_family;
57321@@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
57322 if (sa->sa_family != AF_INET6)
57323 return 0;
57324
57325- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
57326+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
57327 }
57328
57329 #endif /* __KERNEL__ */
57330diff -urNp linux-3.0.4/include/linux/sunrpc/svc_rdma.h linux-3.0.4/include/linux/sunrpc/svc_rdma.h
57331--- linux-3.0.4/include/linux/sunrpc/svc_rdma.h 2011-07-21 22:17:23.000000000 -0400
57332+++ linux-3.0.4/include/linux/sunrpc/svc_rdma.h 2011-08-23 21:47:56.000000000 -0400
57333@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
57334 extern unsigned int svcrdma_max_requests;
57335 extern unsigned int svcrdma_max_req_size;
57336
57337-extern atomic_t rdma_stat_recv;
57338-extern atomic_t rdma_stat_read;
57339-extern atomic_t rdma_stat_write;
57340-extern atomic_t rdma_stat_sq_starve;
57341-extern atomic_t rdma_stat_rq_starve;
57342-extern atomic_t rdma_stat_rq_poll;
57343-extern atomic_t rdma_stat_rq_prod;
57344-extern atomic_t rdma_stat_sq_poll;
57345-extern atomic_t rdma_stat_sq_prod;
57346+extern atomic_unchecked_t rdma_stat_recv;
57347+extern atomic_unchecked_t rdma_stat_read;
57348+extern atomic_unchecked_t rdma_stat_write;
57349+extern atomic_unchecked_t rdma_stat_sq_starve;
57350+extern atomic_unchecked_t rdma_stat_rq_starve;
57351+extern atomic_unchecked_t rdma_stat_rq_poll;
57352+extern atomic_unchecked_t rdma_stat_rq_prod;
57353+extern atomic_unchecked_t rdma_stat_sq_poll;
57354+extern atomic_unchecked_t rdma_stat_sq_prod;
57355
57356 #define RPCRDMA_VERSION 1
57357
57358diff -urNp linux-3.0.4/include/linux/sysctl.h linux-3.0.4/include/linux/sysctl.h
57359--- linux-3.0.4/include/linux/sysctl.h 2011-07-21 22:17:23.000000000 -0400
57360+++ linux-3.0.4/include/linux/sysctl.h 2011-08-23 21:48:14.000000000 -0400
57361@@ -155,7 +155,11 @@ enum
57362 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
57363 };
57364
57365-
57366+#ifdef CONFIG_PAX_SOFTMODE
57367+enum {
57368+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
57369+};
57370+#endif
57371
57372 /* CTL_VM names: */
57373 enum
57374@@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
57375
57376 extern int proc_dostring(struct ctl_table *, int,
57377 void __user *, size_t *, loff_t *);
57378+extern int proc_dostring_modpriv(struct ctl_table *, int,
57379+ void __user *, size_t *, loff_t *);
57380 extern int proc_dointvec(struct ctl_table *, int,
57381 void __user *, size_t *, loff_t *);
57382 extern int proc_dointvec_minmax(struct ctl_table *, int,
57383diff -urNp linux-3.0.4/include/linux/tty_ldisc.h linux-3.0.4/include/linux/tty_ldisc.h
57384--- linux-3.0.4/include/linux/tty_ldisc.h 2011-07-21 22:17:23.000000000 -0400
57385+++ linux-3.0.4/include/linux/tty_ldisc.h 2011-08-23 21:47:56.000000000 -0400
57386@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
57387
57388 struct module *owner;
57389
57390- int refcount;
57391+ atomic_t refcount;
57392 };
57393
57394 struct tty_ldisc {
57395diff -urNp linux-3.0.4/include/linux/types.h linux-3.0.4/include/linux/types.h
57396--- linux-3.0.4/include/linux/types.h 2011-07-21 22:17:23.000000000 -0400
57397+++ linux-3.0.4/include/linux/types.h 2011-08-23 21:47:56.000000000 -0400
57398@@ -213,10 +213,26 @@ typedef struct {
57399 int counter;
57400 } atomic_t;
57401
57402+#ifdef CONFIG_PAX_REFCOUNT
57403+typedef struct {
57404+ int counter;
57405+} atomic_unchecked_t;
57406+#else
57407+typedef atomic_t atomic_unchecked_t;
57408+#endif
57409+
57410 #ifdef CONFIG_64BIT
57411 typedef struct {
57412 long counter;
57413 } atomic64_t;
57414+
57415+#ifdef CONFIG_PAX_REFCOUNT
57416+typedef struct {
57417+ long counter;
57418+} atomic64_unchecked_t;
57419+#else
57420+typedef atomic64_t atomic64_unchecked_t;
57421+#endif
57422 #endif
57423
57424 struct list_head {
57425diff -urNp linux-3.0.4/include/linux/uaccess.h linux-3.0.4/include/linux/uaccess.h
57426--- linux-3.0.4/include/linux/uaccess.h 2011-07-21 22:17:23.000000000 -0400
57427+++ linux-3.0.4/include/linux/uaccess.h 2011-08-23 21:47:56.000000000 -0400
57428@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
57429 long ret; \
57430 mm_segment_t old_fs = get_fs(); \
57431 \
57432- set_fs(KERNEL_DS); \
57433 pagefault_disable(); \
57434+ set_fs(KERNEL_DS); \
57435 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
57436- pagefault_enable(); \
57437 set_fs(old_fs); \
57438+ pagefault_enable(); \
57439 ret; \
57440 })
57441
57442diff -urNp linux-3.0.4/include/linux/unaligned/access_ok.h linux-3.0.4/include/linux/unaligned/access_ok.h
57443--- linux-3.0.4/include/linux/unaligned/access_ok.h 2011-07-21 22:17:23.000000000 -0400
57444+++ linux-3.0.4/include/linux/unaligned/access_ok.h 2011-08-23 21:47:56.000000000 -0400
57445@@ -6,32 +6,32 @@
57446
57447 static inline u16 get_unaligned_le16(const void *p)
57448 {
57449- return le16_to_cpup((__le16 *)p);
57450+ return le16_to_cpup((const __le16 *)p);
57451 }
57452
57453 static inline u32 get_unaligned_le32(const void *p)
57454 {
57455- return le32_to_cpup((__le32 *)p);
57456+ return le32_to_cpup((const __le32 *)p);
57457 }
57458
57459 static inline u64 get_unaligned_le64(const void *p)
57460 {
57461- return le64_to_cpup((__le64 *)p);
57462+ return le64_to_cpup((const __le64 *)p);
57463 }
57464
57465 static inline u16 get_unaligned_be16(const void *p)
57466 {
57467- return be16_to_cpup((__be16 *)p);
57468+ return be16_to_cpup((const __be16 *)p);
57469 }
57470
57471 static inline u32 get_unaligned_be32(const void *p)
57472 {
57473- return be32_to_cpup((__be32 *)p);
57474+ return be32_to_cpup((const __be32 *)p);
57475 }
57476
57477 static inline u64 get_unaligned_be64(const void *p)
57478 {
57479- return be64_to_cpup((__be64 *)p);
57480+ return be64_to_cpup((const __be64 *)p);
57481 }
57482
57483 static inline void put_unaligned_le16(u16 val, void *p)
57484diff -urNp linux-3.0.4/include/linux/vmalloc.h linux-3.0.4/include/linux/vmalloc.h
57485--- linux-3.0.4/include/linux/vmalloc.h 2011-07-21 22:17:23.000000000 -0400
57486+++ linux-3.0.4/include/linux/vmalloc.h 2011-08-23 21:47:56.000000000 -0400
57487@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
57488 #define VM_MAP 0x00000004 /* vmap()ed pages */
57489 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
57490 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
57491+
57492+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
57493+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
57494+#endif
57495+
57496 /* bits [20..32] reserved for arch specific ioremap internals */
57497
57498 /*
57499@@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
57500 # endif
57501 #endif
57502
57503+#define vmalloc(x) \
57504+({ \
57505+ void *___retval; \
57506+ intoverflow_t ___x = (intoverflow_t)x; \
57507+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
57508+ ___retval = NULL; \
57509+ else \
57510+ ___retval = vmalloc((unsigned long)___x); \
57511+ ___retval; \
57512+})
57513+
57514+#define vzalloc(x) \
57515+({ \
57516+ void *___retval; \
57517+ intoverflow_t ___x = (intoverflow_t)x; \
57518+ if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
57519+ ___retval = NULL; \
57520+ else \
57521+ ___retval = vzalloc((unsigned long)___x); \
57522+ ___retval; \
57523+})
57524+
57525+#define __vmalloc(x, y, z) \
57526+({ \
57527+ void *___retval; \
57528+ intoverflow_t ___x = (intoverflow_t)x; \
57529+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
57530+ ___retval = NULL; \
57531+ else \
57532+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
57533+ ___retval; \
57534+})
57535+
57536+#define vmalloc_user(x) \
57537+({ \
57538+ void *___retval; \
57539+ intoverflow_t ___x = (intoverflow_t)x; \
57540+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
57541+ ___retval = NULL; \
57542+ else \
57543+ ___retval = vmalloc_user((unsigned long)___x); \
57544+ ___retval; \
57545+})
57546+
57547+#define vmalloc_exec(x) \
57548+({ \
57549+ void *___retval; \
57550+ intoverflow_t ___x = (intoverflow_t)x; \
57551+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
57552+ ___retval = NULL; \
57553+ else \
57554+ ___retval = vmalloc_exec((unsigned long)___x); \
57555+ ___retval; \
57556+})
57557+
57558+#define vmalloc_node(x, y) \
57559+({ \
57560+ void *___retval; \
57561+ intoverflow_t ___x = (intoverflow_t)x; \
57562+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
57563+ ___retval = NULL; \
57564+ else \
57565+ ___retval = vmalloc_node((unsigned long)___x, (y));\
57566+ ___retval; \
57567+})
57568+
57569+#define vzalloc_node(x, y) \
57570+({ \
57571+ void *___retval; \
57572+ intoverflow_t ___x = (intoverflow_t)x; \
57573+ if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
57574+ ___retval = NULL; \
57575+ else \
57576+ ___retval = vzalloc_node((unsigned long)___x, (y));\
57577+ ___retval; \
57578+})
57579+
57580+#define vmalloc_32(x) \
57581+({ \
57582+ void *___retval; \
57583+ intoverflow_t ___x = (intoverflow_t)x; \
57584+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
57585+ ___retval = NULL; \
57586+ else \
57587+ ___retval = vmalloc_32((unsigned long)___x); \
57588+ ___retval; \
57589+})
57590+
57591+#define vmalloc_32_user(x) \
57592+({ \
57593+void *___retval; \
57594+ intoverflow_t ___x = (intoverflow_t)x; \
57595+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
57596+ ___retval = NULL; \
57597+ else \
57598+ ___retval = vmalloc_32_user((unsigned long)___x);\
57599+ ___retval; \
57600+})
57601+
57602 #endif /* _LINUX_VMALLOC_H */
57603diff -urNp linux-3.0.4/include/linux/vmstat.h linux-3.0.4/include/linux/vmstat.h
57604--- linux-3.0.4/include/linux/vmstat.h 2011-07-21 22:17:23.000000000 -0400
57605+++ linux-3.0.4/include/linux/vmstat.h 2011-08-23 21:47:56.000000000 -0400
57606@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(in
57607 /*
57608 * Zone based page accounting with per cpu differentials.
57609 */
57610-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
57611+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
57612
57613 static inline void zone_page_state_add(long x, struct zone *zone,
57614 enum zone_stat_item item)
57615 {
57616- atomic_long_add(x, &zone->vm_stat[item]);
57617- atomic_long_add(x, &vm_stat[item]);
57618+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
57619+ atomic_long_add_unchecked(x, &vm_stat[item]);
57620 }
57621
57622 static inline unsigned long global_page_state(enum zone_stat_item item)
57623 {
57624- long x = atomic_long_read(&vm_stat[item]);
57625+ long x = atomic_long_read_unchecked(&vm_stat[item]);
57626 #ifdef CONFIG_SMP
57627 if (x < 0)
57628 x = 0;
57629@@ -109,7 +109,7 @@ static inline unsigned long global_page_
57630 static inline unsigned long zone_page_state(struct zone *zone,
57631 enum zone_stat_item item)
57632 {
57633- long x = atomic_long_read(&zone->vm_stat[item]);
57634+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
57635 #ifdef CONFIG_SMP
57636 if (x < 0)
57637 x = 0;
57638@@ -126,7 +126,7 @@ static inline unsigned long zone_page_st
57639 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
57640 enum zone_stat_item item)
57641 {
57642- long x = atomic_long_read(&zone->vm_stat[item]);
57643+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
57644
57645 #ifdef CONFIG_SMP
57646 int cpu;
57647@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state
57648
57649 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
57650 {
57651- atomic_long_inc(&zone->vm_stat[item]);
57652- atomic_long_inc(&vm_stat[item]);
57653+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
57654+ atomic_long_inc_unchecked(&vm_stat[item]);
57655 }
57656
57657 static inline void __inc_zone_page_state(struct page *page,
57658@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state
57659
57660 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
57661 {
57662- atomic_long_dec(&zone->vm_stat[item]);
57663- atomic_long_dec(&vm_stat[item]);
57664+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
57665+ atomic_long_dec_unchecked(&vm_stat[item]);
57666 }
57667
57668 static inline void __dec_zone_page_state(struct page *page,
57669diff -urNp linux-3.0.4/include/media/saa7146_vv.h linux-3.0.4/include/media/saa7146_vv.h
57670--- linux-3.0.4/include/media/saa7146_vv.h 2011-07-21 22:17:23.000000000 -0400
57671+++ linux-3.0.4/include/media/saa7146_vv.h 2011-08-24 18:26:09.000000000 -0400
57672@@ -163,7 +163,7 @@ struct saa7146_ext_vv
57673 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
57674
57675 /* the extension can override this */
57676- struct v4l2_ioctl_ops ops;
57677+ v4l2_ioctl_ops_no_const ops;
57678 /* pointer to the saa7146 core ops */
57679 const struct v4l2_ioctl_ops *core_ops;
57680
57681diff -urNp linux-3.0.4/include/media/v4l2-ioctl.h linux-3.0.4/include/media/v4l2-ioctl.h
57682--- linux-3.0.4/include/media/v4l2-ioctl.h 2011-07-21 22:17:23.000000000 -0400
57683+++ linux-3.0.4/include/media/v4l2-ioctl.h 2011-08-24 18:25:45.000000000 -0400
57684@@ -272,6 +272,7 @@ struct v4l2_ioctl_ops {
57685 long (*vidioc_default) (struct file *file, void *fh,
57686 bool valid_prio, int cmd, void *arg);
57687 };
57688+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
57689
57690
57691 /* v4l debugging and diagnostics */
57692diff -urNp linux-3.0.4/include/net/caif/cfctrl.h linux-3.0.4/include/net/caif/cfctrl.h
57693--- linux-3.0.4/include/net/caif/cfctrl.h 2011-07-21 22:17:23.000000000 -0400
57694+++ linux-3.0.4/include/net/caif/cfctrl.h 2011-08-23 21:47:56.000000000 -0400
57695@@ -52,7 +52,7 @@ struct cfctrl_rsp {
57696 void (*radioset_rsp)(void);
57697 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
57698 struct cflayer *client_layer);
57699-};
57700+} __no_const;
57701
57702 /* Link Setup Parameters for CAIF-Links. */
57703 struct cfctrl_link_param {
57704@@ -101,8 +101,8 @@ struct cfctrl_request_info {
57705 struct cfctrl {
57706 struct cfsrvl serv;
57707 struct cfctrl_rsp res;
57708- atomic_t req_seq_no;
57709- atomic_t rsp_seq_no;
57710+ atomic_unchecked_t req_seq_no;
57711+ atomic_unchecked_t rsp_seq_no;
57712 struct list_head list;
57713 /* Protects from simultaneous access to first_req list */
57714 spinlock_t info_list_lock;
57715diff -urNp linux-3.0.4/include/net/flow.h linux-3.0.4/include/net/flow.h
57716--- linux-3.0.4/include/net/flow.h 2011-07-21 22:17:23.000000000 -0400
57717+++ linux-3.0.4/include/net/flow.h 2011-08-23 21:47:56.000000000 -0400
57718@@ -188,6 +188,6 @@ extern struct flow_cache_object *flow_ca
57719 u8 dir, flow_resolve_t resolver, void *ctx);
57720
57721 extern void flow_cache_flush(void);
57722-extern atomic_t flow_cache_genid;
57723+extern atomic_unchecked_t flow_cache_genid;
57724
57725 #endif
57726diff -urNp linux-3.0.4/include/net/inetpeer.h linux-3.0.4/include/net/inetpeer.h
57727--- linux-3.0.4/include/net/inetpeer.h 2011-07-21 22:17:23.000000000 -0400
57728+++ linux-3.0.4/include/net/inetpeer.h 2011-08-23 21:47:56.000000000 -0400
57729@@ -43,8 +43,8 @@ struct inet_peer {
57730 */
57731 union {
57732 struct {
57733- atomic_t rid; /* Frag reception counter */
57734- atomic_t ip_id_count; /* IP ID for the next packet */
57735+ atomic_unchecked_t rid; /* Frag reception counter */
57736+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
57737 __u32 tcp_ts;
57738 __u32 tcp_ts_stamp;
57739 u32 metrics[RTAX_MAX];
57740@@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
57741 {
57742 more++;
57743 inet_peer_refcheck(p);
57744- return atomic_add_return(more, &p->ip_id_count) - more;
57745+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
57746 }
57747
57748 #endif /* _NET_INETPEER_H */
57749diff -urNp linux-3.0.4/include/net/ip_fib.h linux-3.0.4/include/net/ip_fib.h
57750--- linux-3.0.4/include/net/ip_fib.h 2011-07-21 22:17:23.000000000 -0400
57751+++ linux-3.0.4/include/net/ip_fib.h 2011-08-23 21:47:56.000000000 -0400
57752@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
57753
57754 #define FIB_RES_SADDR(net, res) \
57755 ((FIB_RES_NH(res).nh_saddr_genid == \
57756- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
57757+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
57758 FIB_RES_NH(res).nh_saddr : \
57759 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
57760 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
57761diff -urNp linux-3.0.4/include/net/ip_vs.h linux-3.0.4/include/net/ip_vs.h
57762--- linux-3.0.4/include/net/ip_vs.h 2011-07-21 22:17:23.000000000 -0400
57763+++ linux-3.0.4/include/net/ip_vs.h 2011-08-23 21:47:56.000000000 -0400
57764@@ -509,7 +509,7 @@ struct ip_vs_conn {
57765 struct ip_vs_conn *control; /* Master control connection */
57766 atomic_t n_control; /* Number of controlled ones */
57767 struct ip_vs_dest *dest; /* real server */
57768- atomic_t in_pkts; /* incoming packet counter */
57769+ atomic_unchecked_t in_pkts; /* incoming packet counter */
57770
57771 /* packet transmitter for different forwarding methods. If it
57772 mangles the packet, it must return NF_DROP or better NF_STOLEN,
57773@@ -647,7 +647,7 @@ struct ip_vs_dest {
57774 __be16 port; /* port number of the server */
57775 union nf_inet_addr addr; /* IP address of the server */
57776 volatile unsigned flags; /* dest status flags */
57777- atomic_t conn_flags; /* flags to copy to conn */
57778+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
57779 atomic_t weight; /* server weight */
57780
57781 atomic_t refcnt; /* reference counter */
57782diff -urNp linux-3.0.4/include/net/irda/ircomm_core.h linux-3.0.4/include/net/irda/ircomm_core.h
57783--- linux-3.0.4/include/net/irda/ircomm_core.h 2011-07-21 22:17:23.000000000 -0400
57784+++ linux-3.0.4/include/net/irda/ircomm_core.h 2011-08-23 21:47:56.000000000 -0400
57785@@ -51,7 +51,7 @@ typedef struct {
57786 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
57787 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
57788 struct ircomm_info *);
57789-} call_t;
57790+} __no_const call_t;
57791
57792 struct ircomm_cb {
57793 irda_queue_t queue;
57794diff -urNp linux-3.0.4/include/net/irda/ircomm_tty.h linux-3.0.4/include/net/irda/ircomm_tty.h
57795--- linux-3.0.4/include/net/irda/ircomm_tty.h 2011-07-21 22:17:23.000000000 -0400
57796+++ linux-3.0.4/include/net/irda/ircomm_tty.h 2011-08-23 21:47:56.000000000 -0400
57797@@ -35,6 +35,7 @@
57798 #include <linux/termios.h>
57799 #include <linux/timer.h>
57800 #include <linux/tty.h> /* struct tty_struct */
57801+#include <asm/local.h>
57802
57803 #include <net/irda/irias_object.h>
57804 #include <net/irda/ircomm_core.h>
57805@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
57806 unsigned short close_delay;
57807 unsigned short closing_wait; /* time to wait before closing */
57808
57809- int open_count;
57810- int blocked_open; /* # of blocked opens */
57811+ local_t open_count;
57812+ local_t blocked_open; /* # of blocked opens */
57813
57814 /* Protect concurent access to :
57815 * o self->open_count
57816diff -urNp linux-3.0.4/include/net/iucv/af_iucv.h linux-3.0.4/include/net/iucv/af_iucv.h
57817--- linux-3.0.4/include/net/iucv/af_iucv.h 2011-07-21 22:17:23.000000000 -0400
57818+++ linux-3.0.4/include/net/iucv/af_iucv.h 2011-08-23 21:47:56.000000000 -0400
57819@@ -87,7 +87,7 @@ struct iucv_sock {
57820 struct iucv_sock_list {
57821 struct hlist_head head;
57822 rwlock_t lock;
57823- atomic_t autobind_name;
57824+ atomic_unchecked_t autobind_name;
57825 };
57826
57827 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
57828diff -urNp linux-3.0.4/include/net/lapb.h linux-3.0.4/include/net/lapb.h
57829--- linux-3.0.4/include/net/lapb.h 2011-07-21 22:17:23.000000000 -0400
57830+++ linux-3.0.4/include/net/lapb.h 2011-08-23 21:47:56.000000000 -0400
57831@@ -95,7 +95,7 @@ struct lapb_cb {
57832 struct sk_buff_head write_queue;
57833 struct sk_buff_head ack_queue;
57834 unsigned char window;
57835- struct lapb_register_struct callbacks;
57836+ struct lapb_register_struct *callbacks;
57837
57838 /* FRMR control information */
57839 struct lapb_frame frmr_data;
57840diff -urNp linux-3.0.4/include/net/neighbour.h linux-3.0.4/include/net/neighbour.h
57841--- linux-3.0.4/include/net/neighbour.h 2011-07-21 22:17:23.000000000 -0400
57842+++ linux-3.0.4/include/net/neighbour.h 2011-08-31 18:39:25.000000000 -0400
57843@@ -124,7 +124,7 @@ struct neigh_ops {
57844 int (*connected_output)(struct sk_buff*);
57845 int (*hh_output)(struct sk_buff*);
57846 int (*queue_xmit)(struct sk_buff*);
57847-};
57848+} __do_const;
57849
57850 struct pneigh_entry {
57851 struct pneigh_entry *next;
57852diff -urNp linux-3.0.4/include/net/netlink.h linux-3.0.4/include/net/netlink.h
57853--- linux-3.0.4/include/net/netlink.h 2011-07-21 22:17:23.000000000 -0400
57854+++ linux-3.0.4/include/net/netlink.h 2011-08-23 21:47:56.000000000 -0400
57855@@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
57856 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
57857 {
57858 if (mark)
57859- skb_trim(skb, (unsigned char *) mark - skb->data);
57860+ skb_trim(skb, (const unsigned char *) mark - skb->data);
57861 }
57862
57863 /**
57864diff -urNp linux-3.0.4/include/net/netns/ipv4.h linux-3.0.4/include/net/netns/ipv4.h
57865--- linux-3.0.4/include/net/netns/ipv4.h 2011-07-21 22:17:23.000000000 -0400
57866+++ linux-3.0.4/include/net/netns/ipv4.h 2011-08-23 21:47:56.000000000 -0400
57867@@ -56,8 +56,8 @@ struct netns_ipv4 {
57868
57869 unsigned int sysctl_ping_group_range[2];
57870
57871- atomic_t rt_genid;
57872- atomic_t dev_addr_genid;
57873+ atomic_unchecked_t rt_genid;
57874+ atomic_unchecked_t dev_addr_genid;
57875
57876 #ifdef CONFIG_IP_MROUTE
57877 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
57878diff -urNp linux-3.0.4/include/net/sctp/sctp.h linux-3.0.4/include/net/sctp/sctp.h
57879--- linux-3.0.4/include/net/sctp/sctp.h 2011-07-21 22:17:23.000000000 -0400
57880+++ linux-3.0.4/include/net/sctp/sctp.h 2011-08-23 21:47:56.000000000 -0400
57881@@ -315,9 +315,9 @@ do { \
57882
57883 #else /* SCTP_DEBUG */
57884
57885-#define SCTP_DEBUG_PRINTK(whatever...)
57886-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
57887-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
57888+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
57889+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
57890+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
57891 #define SCTP_ENABLE_DEBUG
57892 #define SCTP_DISABLE_DEBUG
57893 #define SCTP_ASSERT(expr, str, func)
57894diff -urNp linux-3.0.4/include/net/sock.h linux-3.0.4/include/net/sock.h
57895--- linux-3.0.4/include/net/sock.h 2011-07-21 22:17:23.000000000 -0400
57896+++ linux-3.0.4/include/net/sock.h 2011-08-23 21:47:56.000000000 -0400
57897@@ -277,7 +277,7 @@ struct sock {
57898 #ifdef CONFIG_RPS
57899 __u32 sk_rxhash;
57900 #endif
57901- atomic_t sk_drops;
57902+ atomic_unchecked_t sk_drops;
57903 int sk_rcvbuf;
57904
57905 struct sk_filter __rcu *sk_filter;
57906@@ -1390,7 +1390,7 @@ static inline void sk_nocaps_add(struct
57907 }
57908
57909 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
57910- char __user *from, char *to,
57911+ char __user *from, unsigned char *to,
57912 int copy, int offset)
57913 {
57914 if (skb->ip_summed == CHECKSUM_NONE) {
57915diff -urNp linux-3.0.4/include/net/tcp.h linux-3.0.4/include/net/tcp.h
57916--- linux-3.0.4/include/net/tcp.h 2011-07-21 22:17:23.000000000 -0400
57917+++ linux-3.0.4/include/net/tcp.h 2011-08-23 21:47:56.000000000 -0400
57918@@ -1374,8 +1374,8 @@ enum tcp_seq_states {
57919 struct tcp_seq_afinfo {
57920 char *name;
57921 sa_family_t family;
57922- struct file_operations seq_fops;
57923- struct seq_operations seq_ops;
57924+ file_operations_no_const seq_fops;
57925+ seq_operations_no_const seq_ops;
57926 };
57927
57928 struct tcp_iter_state {
57929diff -urNp linux-3.0.4/include/net/udp.h linux-3.0.4/include/net/udp.h
57930--- linux-3.0.4/include/net/udp.h 2011-07-21 22:17:23.000000000 -0400
57931+++ linux-3.0.4/include/net/udp.h 2011-08-23 21:47:56.000000000 -0400
57932@@ -234,8 +234,8 @@ struct udp_seq_afinfo {
57933 char *name;
57934 sa_family_t family;
57935 struct udp_table *udp_table;
57936- struct file_operations seq_fops;
57937- struct seq_operations seq_ops;
57938+ file_operations_no_const seq_fops;
57939+ seq_operations_no_const seq_ops;
57940 };
57941
57942 struct udp_iter_state {
57943diff -urNp linux-3.0.4/include/net/xfrm.h linux-3.0.4/include/net/xfrm.h
57944--- linux-3.0.4/include/net/xfrm.h 2011-07-21 22:17:23.000000000 -0400
57945+++ linux-3.0.4/include/net/xfrm.h 2011-08-23 21:47:56.000000000 -0400
57946@@ -505,7 +505,7 @@ struct xfrm_policy {
57947 struct timer_list timer;
57948
57949 struct flow_cache_object flo;
57950- atomic_t genid;
57951+ atomic_unchecked_t genid;
57952 u32 priority;
57953 u32 index;
57954 struct xfrm_mark mark;
57955diff -urNp linux-3.0.4/include/rdma/iw_cm.h linux-3.0.4/include/rdma/iw_cm.h
57956--- linux-3.0.4/include/rdma/iw_cm.h 2011-07-21 22:17:23.000000000 -0400
57957+++ linux-3.0.4/include/rdma/iw_cm.h 2011-08-23 21:47:56.000000000 -0400
57958@@ -120,7 +120,7 @@ struct iw_cm_verbs {
57959 int backlog);
57960
57961 int (*destroy_listen)(struct iw_cm_id *cm_id);
57962-};
57963+} __no_const;
57964
57965 /**
57966 * iw_create_cm_id - Create an IW CM identifier.
57967diff -urNp linux-3.0.4/include/scsi/libfc.h linux-3.0.4/include/scsi/libfc.h
57968--- linux-3.0.4/include/scsi/libfc.h 2011-07-21 22:17:23.000000000 -0400
57969+++ linux-3.0.4/include/scsi/libfc.h 2011-08-23 21:47:56.000000000 -0400
57970@@ -750,6 +750,7 @@ struct libfc_function_template {
57971 */
57972 void (*disc_stop_final) (struct fc_lport *);
57973 };
57974+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
57975
57976 /**
57977 * struct fc_disc - Discovery context
57978@@ -853,7 +854,7 @@ struct fc_lport {
57979 struct fc_vport *vport;
57980
57981 /* Operational Information */
57982- struct libfc_function_template tt;
57983+ libfc_function_template_no_const tt;
57984 u8 link_up;
57985 u8 qfull;
57986 enum fc_lport_state state;
57987diff -urNp linux-3.0.4/include/scsi/scsi_device.h linux-3.0.4/include/scsi/scsi_device.h
57988--- linux-3.0.4/include/scsi/scsi_device.h 2011-07-21 22:17:23.000000000 -0400
57989+++ linux-3.0.4/include/scsi/scsi_device.h 2011-08-23 21:47:56.000000000 -0400
57990@@ -161,9 +161,9 @@ struct scsi_device {
57991 unsigned int max_device_blocked; /* what device_blocked counts down from */
57992 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
57993
57994- atomic_t iorequest_cnt;
57995- atomic_t iodone_cnt;
57996- atomic_t ioerr_cnt;
57997+ atomic_unchecked_t iorequest_cnt;
57998+ atomic_unchecked_t iodone_cnt;
57999+ atomic_unchecked_t ioerr_cnt;
58000
58001 struct device sdev_gendev,
58002 sdev_dev;
58003diff -urNp linux-3.0.4/include/scsi/scsi_transport_fc.h linux-3.0.4/include/scsi/scsi_transport_fc.h
58004--- linux-3.0.4/include/scsi/scsi_transport_fc.h 2011-07-21 22:17:23.000000000 -0400
58005+++ linux-3.0.4/include/scsi/scsi_transport_fc.h 2011-08-26 19:49:56.000000000 -0400
58006@@ -711,7 +711,7 @@ struct fc_function_template {
58007 unsigned long show_host_system_hostname:1;
58008
58009 unsigned long disable_target_scan:1;
58010-};
58011+} __do_const;
58012
58013
58014 /**
58015diff -urNp linux-3.0.4/include/sound/ak4xxx-adda.h linux-3.0.4/include/sound/ak4xxx-adda.h
58016--- linux-3.0.4/include/sound/ak4xxx-adda.h 2011-07-21 22:17:23.000000000 -0400
58017+++ linux-3.0.4/include/sound/ak4xxx-adda.h 2011-08-23 21:47:56.000000000 -0400
58018@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
58019 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
58020 unsigned char val);
58021 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
58022-};
58023+} __no_const;
58024
58025 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
58026
58027diff -urNp linux-3.0.4/include/sound/hwdep.h linux-3.0.4/include/sound/hwdep.h
58028--- linux-3.0.4/include/sound/hwdep.h 2011-07-21 22:17:23.000000000 -0400
58029+++ linux-3.0.4/include/sound/hwdep.h 2011-08-23 21:47:56.000000000 -0400
58030@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
58031 struct snd_hwdep_dsp_status *status);
58032 int (*dsp_load)(struct snd_hwdep *hw,
58033 struct snd_hwdep_dsp_image *image);
58034-};
58035+} __no_const;
58036
58037 struct snd_hwdep {
58038 struct snd_card *card;
58039diff -urNp linux-3.0.4/include/sound/info.h linux-3.0.4/include/sound/info.h
58040--- linux-3.0.4/include/sound/info.h 2011-07-21 22:17:23.000000000 -0400
58041+++ linux-3.0.4/include/sound/info.h 2011-08-23 21:47:56.000000000 -0400
58042@@ -44,7 +44,7 @@ struct snd_info_entry_text {
58043 struct snd_info_buffer *buffer);
58044 void (*write)(struct snd_info_entry *entry,
58045 struct snd_info_buffer *buffer);
58046-};
58047+} __no_const;
58048
58049 struct snd_info_entry_ops {
58050 int (*open)(struct snd_info_entry *entry,
58051diff -urNp linux-3.0.4/include/sound/pcm.h linux-3.0.4/include/sound/pcm.h
58052--- linux-3.0.4/include/sound/pcm.h 2011-07-21 22:17:23.000000000 -0400
58053+++ linux-3.0.4/include/sound/pcm.h 2011-08-23 21:47:56.000000000 -0400
58054@@ -81,6 +81,7 @@ struct snd_pcm_ops {
58055 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
58056 int (*ack)(struct snd_pcm_substream *substream);
58057 };
58058+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
58059
58060 /*
58061 *
58062diff -urNp linux-3.0.4/include/sound/sb16_csp.h linux-3.0.4/include/sound/sb16_csp.h
58063--- linux-3.0.4/include/sound/sb16_csp.h 2011-07-21 22:17:23.000000000 -0400
58064+++ linux-3.0.4/include/sound/sb16_csp.h 2011-08-23 21:47:56.000000000 -0400
58065@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
58066 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
58067 int (*csp_stop) (struct snd_sb_csp * p);
58068 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
58069-};
58070+} __no_const;
58071
58072 /*
58073 * CSP private data
58074diff -urNp linux-3.0.4/include/sound/soc.h linux-3.0.4/include/sound/soc.h
58075--- linux-3.0.4/include/sound/soc.h 2011-07-21 22:17:23.000000000 -0400
58076+++ linux-3.0.4/include/sound/soc.h 2011-08-26 19:49:56.000000000 -0400
58077@@ -636,7 +636,7 @@ struct snd_soc_platform_driver {
58078
58079 /* platform stream ops */
58080 struct snd_pcm_ops *ops;
58081-};
58082+} __do_const;
58083
58084 struct snd_soc_platform {
58085 const char *name;
58086diff -urNp linux-3.0.4/include/sound/ymfpci.h linux-3.0.4/include/sound/ymfpci.h
58087--- linux-3.0.4/include/sound/ymfpci.h 2011-07-21 22:17:23.000000000 -0400
58088+++ linux-3.0.4/include/sound/ymfpci.h 2011-08-23 21:47:56.000000000 -0400
58089@@ -358,7 +358,7 @@ struct snd_ymfpci {
58090 spinlock_t reg_lock;
58091 spinlock_t voice_lock;
58092 wait_queue_head_t interrupt_sleep;
58093- atomic_t interrupt_sleep_count;
58094+ atomic_unchecked_t interrupt_sleep_count;
58095 struct snd_info_entry *proc_entry;
58096 const struct firmware *dsp_microcode;
58097 const struct firmware *controller_microcode;
58098diff -urNp linux-3.0.4/include/target/target_core_base.h linux-3.0.4/include/target/target_core_base.h
58099--- linux-3.0.4/include/target/target_core_base.h 2011-07-21 22:17:23.000000000 -0400
58100+++ linux-3.0.4/include/target/target_core_base.h 2011-08-23 21:47:56.000000000 -0400
58101@@ -364,7 +364,7 @@ struct t10_reservation_ops {
58102 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
58103 int (*t10_pr_register)(struct se_cmd *);
58104 int (*t10_pr_clear)(struct se_cmd *);
58105-};
58106+} __no_const;
58107
58108 struct t10_reservation_template {
58109 /* Reservation effects all target ports */
58110@@ -432,8 +432,8 @@ struct se_transport_task {
58111 atomic_t t_task_cdbs_left;
58112 atomic_t t_task_cdbs_ex_left;
58113 atomic_t t_task_cdbs_timeout_left;
58114- atomic_t t_task_cdbs_sent;
58115- atomic_t t_transport_aborted;
58116+ atomic_unchecked_t t_task_cdbs_sent;
58117+ atomic_unchecked_t t_transport_aborted;
58118 atomic_t t_transport_active;
58119 atomic_t t_transport_complete;
58120 atomic_t t_transport_queue_active;
58121@@ -774,7 +774,7 @@ struct se_device {
58122 atomic_t active_cmds;
58123 atomic_t simple_cmds;
58124 atomic_t depth_left;
58125- atomic_t dev_ordered_id;
58126+ atomic_unchecked_t dev_ordered_id;
58127 atomic_t dev_tur_active;
58128 atomic_t execute_tasks;
58129 atomic_t dev_status_thr_count;
58130diff -urNp linux-3.0.4/include/trace/events/irq.h linux-3.0.4/include/trace/events/irq.h
58131--- linux-3.0.4/include/trace/events/irq.h 2011-07-21 22:17:23.000000000 -0400
58132+++ linux-3.0.4/include/trace/events/irq.h 2011-08-23 21:47:56.000000000 -0400
58133@@ -36,7 +36,7 @@ struct softirq_action;
58134 */
58135 TRACE_EVENT(irq_handler_entry,
58136
58137- TP_PROTO(int irq, struct irqaction *action),
58138+ TP_PROTO(int irq, const struct irqaction *action),
58139
58140 TP_ARGS(irq, action),
58141
58142@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
58143 */
58144 TRACE_EVENT(irq_handler_exit,
58145
58146- TP_PROTO(int irq, struct irqaction *action, int ret),
58147+ TP_PROTO(int irq, const struct irqaction *action, int ret),
58148
58149 TP_ARGS(irq, action, ret),
58150
58151diff -urNp linux-3.0.4/include/video/udlfb.h linux-3.0.4/include/video/udlfb.h
58152--- linux-3.0.4/include/video/udlfb.h 2011-07-21 22:17:23.000000000 -0400
58153+++ linux-3.0.4/include/video/udlfb.h 2011-08-23 21:47:56.000000000 -0400
58154@@ -51,10 +51,10 @@ struct dlfb_data {
58155 int base8;
58156 u32 pseudo_palette[256];
58157 /* blit-only rendering path metrics, exposed through sysfs */
58158- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
58159- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
58160- atomic_t bytes_sent; /* to usb, after compression including overhead */
58161- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
58162+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
58163+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
58164+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
58165+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
58166 };
58167
58168 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
58169diff -urNp linux-3.0.4/include/video/uvesafb.h linux-3.0.4/include/video/uvesafb.h
58170--- linux-3.0.4/include/video/uvesafb.h 2011-07-21 22:17:23.000000000 -0400
58171+++ linux-3.0.4/include/video/uvesafb.h 2011-08-23 21:47:56.000000000 -0400
58172@@ -177,6 +177,7 @@ struct uvesafb_par {
58173 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
58174 u8 pmi_setpal; /* PMI for palette changes */
58175 u16 *pmi_base; /* protected mode interface location */
58176+ u8 *pmi_code; /* protected mode code location */
58177 void *pmi_start;
58178 void *pmi_pal;
58179 u8 *vbe_state_orig; /*
58180diff -urNp linux-3.0.4/init/do_mounts.c linux-3.0.4/init/do_mounts.c
58181--- linux-3.0.4/init/do_mounts.c 2011-07-21 22:17:23.000000000 -0400
58182+++ linux-3.0.4/init/do_mounts.c 2011-08-23 21:47:56.000000000 -0400
58183@@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
58184
58185 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
58186 {
58187- int err = sys_mount(name, "/root", fs, flags, data);
58188+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
58189 if (err)
58190 return err;
58191
58192@@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
58193 va_start(args, fmt);
58194 vsprintf(buf, fmt, args);
58195 va_end(args);
58196- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
58197+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
58198 if (fd >= 0) {
58199 sys_ioctl(fd, FDEJECT, 0);
58200 sys_close(fd);
58201 }
58202 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
58203- fd = sys_open("/dev/console", O_RDWR, 0);
58204+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
58205 if (fd >= 0) {
58206 sys_ioctl(fd, TCGETS, (long)&termios);
58207 termios.c_lflag &= ~ICANON;
58208 sys_ioctl(fd, TCSETSF, (long)&termios);
58209- sys_read(fd, &c, 1);
58210+ sys_read(fd, (char __user *)&c, 1);
58211 termios.c_lflag |= ICANON;
58212 sys_ioctl(fd, TCSETSF, (long)&termios);
58213 sys_close(fd);
58214@@ -488,6 +488,6 @@ void __init prepare_namespace(void)
58215 mount_root();
58216 out:
58217 devtmpfs_mount("dev");
58218- sys_mount(".", "/", NULL, MS_MOVE, NULL);
58219+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
58220 sys_chroot((const char __user __force *)".");
58221 }
58222diff -urNp linux-3.0.4/init/do_mounts.h linux-3.0.4/init/do_mounts.h
58223--- linux-3.0.4/init/do_mounts.h 2011-07-21 22:17:23.000000000 -0400
58224+++ linux-3.0.4/init/do_mounts.h 2011-08-23 21:47:56.000000000 -0400
58225@@ -15,15 +15,15 @@ extern int root_mountflags;
58226
58227 static inline int create_dev(char *name, dev_t dev)
58228 {
58229- sys_unlink(name);
58230- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
58231+ sys_unlink((__force char __user *)name);
58232+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
58233 }
58234
58235 #if BITS_PER_LONG == 32
58236 static inline u32 bstat(char *name)
58237 {
58238 struct stat64 stat;
58239- if (sys_stat64(name, &stat) != 0)
58240+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
58241 return 0;
58242 if (!S_ISBLK(stat.st_mode))
58243 return 0;
58244diff -urNp linux-3.0.4/init/do_mounts_initrd.c linux-3.0.4/init/do_mounts_initrd.c
58245--- linux-3.0.4/init/do_mounts_initrd.c 2011-07-21 22:17:23.000000000 -0400
58246+++ linux-3.0.4/init/do_mounts_initrd.c 2011-08-23 21:47:56.000000000 -0400
58247@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
58248 create_dev("/dev/root.old", Root_RAM0);
58249 /* mount initrd on rootfs' /root */
58250 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
58251- sys_mkdir("/old", 0700);
58252- root_fd = sys_open("/", 0, 0);
58253- old_fd = sys_open("/old", 0, 0);
58254+ sys_mkdir((__force const char __user *)"/old", 0700);
58255+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
58256+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
58257 /* move initrd over / and chdir/chroot in initrd root */
58258- sys_chdir("/root");
58259- sys_mount(".", "/", NULL, MS_MOVE, NULL);
58260- sys_chroot(".");
58261+ sys_chdir((__force const char __user *)"/root");
58262+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
58263+ sys_chroot((__force const char __user *)".");
58264
58265 /*
58266 * In case that a resume from disk is carried out by linuxrc or one of
58267@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
58268
58269 /* move initrd to rootfs' /old */
58270 sys_fchdir(old_fd);
58271- sys_mount("/", ".", NULL, MS_MOVE, NULL);
58272+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
58273 /* switch root and cwd back to / of rootfs */
58274 sys_fchdir(root_fd);
58275- sys_chroot(".");
58276+ sys_chroot((__force const char __user *)".");
58277 sys_close(old_fd);
58278 sys_close(root_fd);
58279
58280 if (new_decode_dev(real_root_dev) == Root_RAM0) {
58281- sys_chdir("/old");
58282+ sys_chdir((__force const char __user *)"/old");
58283 return;
58284 }
58285
58286@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
58287 mount_root();
58288
58289 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
58290- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
58291+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
58292 if (!error)
58293 printk("okay\n");
58294 else {
58295- int fd = sys_open("/dev/root.old", O_RDWR, 0);
58296+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
58297 if (error == -ENOENT)
58298 printk("/initrd does not exist. Ignored.\n");
58299 else
58300 printk("failed\n");
58301 printk(KERN_NOTICE "Unmounting old root\n");
58302- sys_umount("/old", MNT_DETACH);
58303+ sys_umount((__force char __user *)"/old", MNT_DETACH);
58304 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
58305 if (fd < 0) {
58306 error = fd;
58307@@ -116,11 +116,11 @@ int __init initrd_load(void)
58308 * mounted in the normal path.
58309 */
58310 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
58311- sys_unlink("/initrd.image");
58312+ sys_unlink((__force const char __user *)"/initrd.image");
58313 handle_initrd();
58314 return 1;
58315 }
58316 }
58317- sys_unlink("/initrd.image");
58318+ sys_unlink((__force const char __user *)"/initrd.image");
58319 return 0;
58320 }
58321diff -urNp linux-3.0.4/init/do_mounts_md.c linux-3.0.4/init/do_mounts_md.c
58322--- linux-3.0.4/init/do_mounts_md.c 2011-07-21 22:17:23.000000000 -0400
58323+++ linux-3.0.4/init/do_mounts_md.c 2011-08-23 21:47:56.000000000 -0400
58324@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
58325 partitioned ? "_d" : "", minor,
58326 md_setup_args[ent].device_names);
58327
58328- fd = sys_open(name, 0, 0);
58329+ fd = sys_open((__force char __user *)name, 0, 0);
58330 if (fd < 0) {
58331 printk(KERN_ERR "md: open failed - cannot start "
58332 "array %s\n", name);
58333@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
58334 * array without it
58335 */
58336 sys_close(fd);
58337- fd = sys_open(name, 0, 0);
58338+ fd = sys_open((__force char __user *)name, 0, 0);
58339 sys_ioctl(fd, BLKRRPART, 0);
58340 }
58341 sys_close(fd);
58342diff -urNp linux-3.0.4/init/initramfs.c linux-3.0.4/init/initramfs.c
58343--- linux-3.0.4/init/initramfs.c 2011-07-21 22:17:23.000000000 -0400
58344+++ linux-3.0.4/init/initramfs.c 2011-08-23 21:47:56.000000000 -0400
58345@@ -74,7 +74,7 @@ static void __init free_hash(void)
58346 }
58347 }
58348
58349-static long __init do_utime(char __user *filename, time_t mtime)
58350+static long __init do_utime(__force char __user *filename, time_t mtime)
58351 {
58352 struct timespec t[2];
58353
58354@@ -109,7 +109,7 @@ static void __init dir_utime(void)
58355 struct dir_entry *de, *tmp;
58356 list_for_each_entry_safe(de, tmp, &dir_list, list) {
58357 list_del(&de->list);
58358- do_utime(de->name, de->mtime);
58359+ do_utime((__force char __user *)de->name, de->mtime);
58360 kfree(de->name);
58361 kfree(de);
58362 }
58363@@ -271,7 +271,7 @@ static int __init maybe_link(void)
58364 if (nlink >= 2) {
58365 char *old = find_link(major, minor, ino, mode, collected);
58366 if (old)
58367- return (sys_link(old, collected) < 0) ? -1 : 1;
58368+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
58369 }
58370 return 0;
58371 }
58372@@ -280,11 +280,11 @@ static void __init clean_path(char *path
58373 {
58374 struct stat st;
58375
58376- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
58377+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
58378 if (S_ISDIR(st.st_mode))
58379- sys_rmdir(path);
58380+ sys_rmdir((__force char __user *)path);
58381 else
58382- sys_unlink(path);
58383+ sys_unlink((__force char __user *)path);
58384 }
58385 }
58386
58387@@ -305,7 +305,7 @@ static int __init do_name(void)
58388 int openflags = O_WRONLY|O_CREAT;
58389 if (ml != 1)
58390 openflags |= O_TRUNC;
58391- wfd = sys_open(collected, openflags, mode);
58392+ wfd = sys_open((__force char __user *)collected, openflags, mode);
58393
58394 if (wfd >= 0) {
58395 sys_fchown(wfd, uid, gid);
58396@@ -317,17 +317,17 @@ static int __init do_name(void)
58397 }
58398 }
58399 } else if (S_ISDIR(mode)) {
58400- sys_mkdir(collected, mode);
58401- sys_chown(collected, uid, gid);
58402- sys_chmod(collected, mode);
58403+ sys_mkdir((__force char __user *)collected, mode);
58404+ sys_chown((__force char __user *)collected, uid, gid);
58405+ sys_chmod((__force char __user *)collected, mode);
58406 dir_add(collected, mtime);
58407 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
58408 S_ISFIFO(mode) || S_ISSOCK(mode)) {
58409 if (maybe_link() == 0) {
58410- sys_mknod(collected, mode, rdev);
58411- sys_chown(collected, uid, gid);
58412- sys_chmod(collected, mode);
58413- do_utime(collected, mtime);
58414+ sys_mknod((__force char __user *)collected, mode, rdev);
58415+ sys_chown((__force char __user *)collected, uid, gid);
58416+ sys_chmod((__force char __user *)collected, mode);
58417+ do_utime((__force char __user *)collected, mtime);
58418 }
58419 }
58420 return 0;
58421@@ -336,15 +336,15 @@ static int __init do_name(void)
58422 static int __init do_copy(void)
58423 {
58424 if (count >= body_len) {
58425- sys_write(wfd, victim, body_len);
58426+ sys_write(wfd, (__force char __user *)victim, body_len);
58427 sys_close(wfd);
58428- do_utime(vcollected, mtime);
58429+ do_utime((__force char __user *)vcollected, mtime);
58430 kfree(vcollected);
58431 eat(body_len);
58432 state = SkipIt;
58433 return 0;
58434 } else {
58435- sys_write(wfd, victim, count);
58436+ sys_write(wfd, (__force char __user *)victim, count);
58437 body_len -= count;
58438 eat(count);
58439 return 1;
58440@@ -355,9 +355,9 @@ static int __init do_symlink(void)
58441 {
58442 collected[N_ALIGN(name_len) + body_len] = '\0';
58443 clean_path(collected, 0);
58444- sys_symlink(collected + N_ALIGN(name_len), collected);
58445- sys_lchown(collected, uid, gid);
58446- do_utime(collected, mtime);
58447+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
58448+ sys_lchown((__force char __user *)collected, uid, gid);
58449+ do_utime((__force char __user *)collected, mtime);
58450 state = SkipIt;
58451 next_state = Reset;
58452 return 0;
58453diff -urNp linux-3.0.4/init/Kconfig linux-3.0.4/init/Kconfig
58454--- linux-3.0.4/init/Kconfig 2011-07-21 22:17:23.000000000 -0400
58455+++ linux-3.0.4/init/Kconfig 2011-08-23 21:47:56.000000000 -0400
58456@@ -1195,7 +1195,7 @@ config SLUB_DEBUG
58457
58458 config COMPAT_BRK
58459 bool "Disable heap randomization"
58460- default y
58461+ default n
58462 help
58463 Randomizing heap placement makes heap exploits harder, but it
58464 also breaks ancient binaries (including anything libc5 based).
58465diff -urNp linux-3.0.4/init/main.c linux-3.0.4/init/main.c
58466--- linux-3.0.4/init/main.c 2011-07-21 22:17:23.000000000 -0400
58467+++ linux-3.0.4/init/main.c 2011-08-23 21:48:14.000000000 -0400
58468@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
58469 extern void tc_init(void);
58470 #endif
58471
58472+extern void grsecurity_init(void);
58473+
58474 /*
58475 * Debug helper: via this flag we know that we are in 'early bootup code'
58476 * where only the boot processor is running with IRQ disabled. This means
58477@@ -149,6 +151,49 @@ static int __init set_reset_devices(char
58478
58479 __setup("reset_devices", set_reset_devices);
58480
58481+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
58482+extern char pax_enter_kernel_user[];
58483+extern char pax_exit_kernel_user[];
58484+extern pgdval_t clone_pgd_mask;
58485+#endif
58486+
58487+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
58488+static int __init setup_pax_nouderef(char *str)
58489+{
58490+#ifdef CONFIG_X86_32
58491+ unsigned int cpu;
58492+ struct desc_struct *gdt;
58493+
58494+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
58495+ gdt = get_cpu_gdt_table(cpu);
58496+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
58497+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
58498+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
58499+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
58500+ }
58501+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
58502+#else
58503+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
58504+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
58505+ clone_pgd_mask = ~(pgdval_t)0UL;
58506+#endif
58507+
58508+ return 0;
58509+}
58510+early_param("pax_nouderef", setup_pax_nouderef);
58511+#endif
58512+
58513+#ifdef CONFIG_PAX_SOFTMODE
58514+int pax_softmode;
58515+
58516+static int __init setup_pax_softmode(char *str)
58517+{
58518+ get_option(&str, &pax_softmode);
58519+ return 1;
58520+}
58521+__setup("pax_softmode=", setup_pax_softmode);
58522+#endif
58523+
58524 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
58525 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
58526 static const char *panic_later, *panic_param;
58527@@ -667,6 +712,7 @@ int __init_or_module do_one_initcall(ini
58528 {
58529 int count = preempt_count();
58530 int ret;
58531+ const char *msg1 = "", *msg2 = "";
58532
58533 if (initcall_debug)
58534 ret = do_one_initcall_debug(fn);
58535@@ -679,15 +725,15 @@ int __init_or_module do_one_initcall(ini
58536 sprintf(msgbuf, "error code %d ", ret);
58537
58538 if (preempt_count() != count) {
58539- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
58540+ msg1 = " preemption imbalance";
58541 preempt_count() = count;
58542 }
58543 if (irqs_disabled()) {
58544- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
58545+ msg2 = " disabled interrupts";
58546 local_irq_enable();
58547 }
58548- if (msgbuf[0]) {
58549- printk("initcall %pF returned with %s\n", fn, msgbuf);
58550+ if (msgbuf[0] || *msg1 || *msg2) {
58551+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
58552 }
58553
58554 return ret;
58555@@ -805,7 +851,7 @@ static int __init kernel_init(void * unu
58556 do_basic_setup();
58557
58558 /* Open the /dev/console on the rootfs, this should never fail */
58559- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
58560+ if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
58561 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
58562
58563 (void) sys_dup(0);
58564@@ -818,11 +864,13 @@ static int __init kernel_init(void * unu
58565 if (!ramdisk_execute_command)
58566 ramdisk_execute_command = "/init";
58567
58568- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
58569+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
58570 ramdisk_execute_command = NULL;
58571 prepare_namespace();
58572 }
58573
58574+ grsecurity_init();
58575+
58576 /*
58577 * Ok, we have completed the initial bootup, and
58578 * we're essentially up and running. Get rid of the
58579diff -urNp linux-3.0.4/ipc/mqueue.c linux-3.0.4/ipc/mqueue.c
58580--- linux-3.0.4/ipc/mqueue.c 2011-07-21 22:17:23.000000000 -0400
58581+++ linux-3.0.4/ipc/mqueue.c 2011-08-23 21:48:14.000000000 -0400
58582@@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
58583 mq_bytes = (mq_msg_tblsz +
58584 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
58585
58586+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
58587 spin_lock(&mq_lock);
58588 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
58589 u->mq_bytes + mq_bytes >
58590diff -urNp linux-3.0.4/ipc/msg.c linux-3.0.4/ipc/msg.c
58591--- linux-3.0.4/ipc/msg.c 2011-07-21 22:17:23.000000000 -0400
58592+++ linux-3.0.4/ipc/msg.c 2011-08-23 21:47:56.000000000 -0400
58593@@ -309,18 +309,19 @@ static inline int msg_security(struct ke
58594 return security_msg_queue_associate(msq, msgflg);
58595 }
58596
58597+static struct ipc_ops msg_ops = {
58598+ .getnew = newque,
58599+ .associate = msg_security,
58600+ .more_checks = NULL
58601+};
58602+
58603 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
58604 {
58605 struct ipc_namespace *ns;
58606- struct ipc_ops msg_ops;
58607 struct ipc_params msg_params;
58608
58609 ns = current->nsproxy->ipc_ns;
58610
58611- msg_ops.getnew = newque;
58612- msg_ops.associate = msg_security;
58613- msg_ops.more_checks = NULL;
58614-
58615 msg_params.key = key;
58616 msg_params.flg = msgflg;
58617
58618diff -urNp linux-3.0.4/ipc/sem.c linux-3.0.4/ipc/sem.c
58619--- linux-3.0.4/ipc/sem.c 2011-09-02 18:11:21.000000000 -0400
58620+++ linux-3.0.4/ipc/sem.c 2011-08-23 21:48:14.000000000 -0400
58621@@ -318,10 +318,15 @@ static inline int sem_more_checks(struct
58622 return 0;
58623 }
58624
58625+static struct ipc_ops sem_ops = {
58626+ .getnew = newary,
58627+ .associate = sem_security,
58628+ .more_checks = sem_more_checks
58629+};
58630+
58631 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
58632 {
58633 struct ipc_namespace *ns;
58634- struct ipc_ops sem_ops;
58635 struct ipc_params sem_params;
58636
58637 ns = current->nsproxy->ipc_ns;
58638@@ -329,10 +334,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int,
58639 if (nsems < 0 || nsems > ns->sc_semmsl)
58640 return -EINVAL;
58641
58642- sem_ops.getnew = newary;
58643- sem_ops.associate = sem_security;
58644- sem_ops.more_checks = sem_more_checks;
58645-
58646 sem_params.key = key;
58647 sem_params.flg = semflg;
58648 sem_params.u.nsems = nsems;
58649@@ -854,6 +855,8 @@ static int semctl_main(struct ipc_namesp
58650 int nsems;
58651 struct list_head tasks;
58652
58653+ pax_track_stack();
58654+
58655 sma = sem_lock_check(ns, semid);
58656 if (IS_ERR(sma))
58657 return PTR_ERR(sma);
58658@@ -1301,6 +1304,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
58659 struct ipc_namespace *ns;
58660 struct list_head tasks;
58661
58662+ pax_track_stack();
58663+
58664 ns = current->nsproxy->ipc_ns;
58665
58666 if (nsops < 1 || semid < 0)
58667diff -urNp linux-3.0.4/ipc/shm.c linux-3.0.4/ipc/shm.c
58668--- linux-3.0.4/ipc/shm.c 2011-07-21 22:17:23.000000000 -0400
58669+++ linux-3.0.4/ipc/shm.c 2011-08-23 21:48:14.000000000 -0400
58670@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
58671 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
58672 #endif
58673
58674+#ifdef CONFIG_GRKERNSEC
58675+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58676+ const time_t shm_createtime, const uid_t cuid,
58677+ const int shmid);
58678+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58679+ const time_t shm_createtime);
58680+#endif
58681+
58682 void shm_init_ns(struct ipc_namespace *ns)
58683 {
58684 ns->shm_ctlmax = SHMMAX;
58685@@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
58686 shp->shm_lprid = 0;
58687 shp->shm_atim = shp->shm_dtim = 0;
58688 shp->shm_ctim = get_seconds();
58689+#ifdef CONFIG_GRKERNSEC
58690+ {
58691+ struct timespec timeval;
58692+ do_posix_clock_monotonic_gettime(&timeval);
58693+
58694+ shp->shm_createtime = timeval.tv_sec;
58695+ }
58696+#endif
58697 shp->shm_segsz = size;
58698 shp->shm_nattch = 0;
58699 shp->shm_file = file;
58700@@ -451,18 +467,19 @@ static inline int shm_more_checks(struct
58701 return 0;
58702 }
58703
58704+static struct ipc_ops shm_ops = {
58705+ .getnew = newseg,
58706+ .associate = shm_security,
58707+ .more_checks = shm_more_checks
58708+};
58709+
58710 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
58711 {
58712 struct ipc_namespace *ns;
58713- struct ipc_ops shm_ops;
58714 struct ipc_params shm_params;
58715
58716 ns = current->nsproxy->ipc_ns;
58717
58718- shm_ops.getnew = newseg;
58719- shm_ops.associate = shm_security;
58720- shm_ops.more_checks = shm_more_checks;
58721-
58722 shm_params.key = key;
58723 shm_params.flg = shmflg;
58724 shm_params.u.size = size;
58725@@ -762,8 +779,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
58726 case SHM_LOCK:
58727 case SHM_UNLOCK:
58728 {
58729- struct file *uninitialized_var(shm_file);
58730-
58731 lru_add_drain_all(); /* drain pagevecs to lru lists */
58732
58733 shp = shm_lock_check(ns, shmid);
58734@@ -896,9 +911,21 @@ long do_shmat(int shmid, char __user *sh
58735 if (err)
58736 goto out_unlock;
58737
58738+#ifdef CONFIG_GRKERNSEC
58739+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
58740+ shp->shm_perm.cuid, shmid) ||
58741+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
58742+ err = -EACCES;
58743+ goto out_unlock;
58744+ }
58745+#endif
58746+
58747 path = shp->shm_file->f_path;
58748 path_get(&path);
58749 shp->shm_nattch++;
58750+#ifdef CONFIG_GRKERNSEC
58751+ shp->shm_lapid = current->pid;
58752+#endif
58753 size = i_size_read(path.dentry->d_inode);
58754 shm_unlock(shp);
58755
58756diff -urNp linux-3.0.4/kernel/acct.c linux-3.0.4/kernel/acct.c
58757--- linux-3.0.4/kernel/acct.c 2011-07-21 22:17:23.000000000 -0400
58758+++ linux-3.0.4/kernel/acct.c 2011-08-23 21:47:56.000000000 -0400
58759@@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
58760 */
58761 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
58762 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
58763- file->f_op->write(file, (char *)&ac,
58764+ file->f_op->write(file, (__force char __user *)&ac,
58765 sizeof(acct_t), &file->f_pos);
58766 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
58767 set_fs(fs);
58768diff -urNp linux-3.0.4/kernel/audit.c linux-3.0.4/kernel/audit.c
58769--- linux-3.0.4/kernel/audit.c 2011-07-21 22:17:23.000000000 -0400
58770+++ linux-3.0.4/kernel/audit.c 2011-08-23 21:47:56.000000000 -0400
58771@@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
58772 3) suppressed due to audit_rate_limit
58773 4) suppressed due to audit_backlog_limit
58774 */
58775-static atomic_t audit_lost = ATOMIC_INIT(0);
58776+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
58777
58778 /* The netlink socket. */
58779 static struct sock *audit_sock;
58780@@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
58781 unsigned long now;
58782 int print;
58783
58784- atomic_inc(&audit_lost);
58785+ atomic_inc_unchecked(&audit_lost);
58786
58787 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
58788
58789@@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
58790 printk(KERN_WARNING
58791 "audit: audit_lost=%d audit_rate_limit=%d "
58792 "audit_backlog_limit=%d\n",
58793- atomic_read(&audit_lost),
58794+ atomic_read_unchecked(&audit_lost),
58795 audit_rate_limit,
58796 audit_backlog_limit);
58797 audit_panic(message);
58798@@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
58799 status_set.pid = audit_pid;
58800 status_set.rate_limit = audit_rate_limit;
58801 status_set.backlog_limit = audit_backlog_limit;
58802- status_set.lost = atomic_read(&audit_lost);
58803+ status_set.lost = atomic_read_unchecked(&audit_lost);
58804 status_set.backlog = skb_queue_len(&audit_skb_queue);
58805 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
58806 &status_set, sizeof(status_set));
58807diff -urNp linux-3.0.4/kernel/auditsc.c linux-3.0.4/kernel/auditsc.c
58808--- linux-3.0.4/kernel/auditsc.c 2011-07-21 22:17:23.000000000 -0400
58809+++ linux-3.0.4/kernel/auditsc.c 2011-08-23 21:47:56.000000000 -0400
58810@@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_conte
58811 }
58812
58813 /* global counter which is incremented every time something logs in */
58814-static atomic_t session_id = ATOMIC_INIT(0);
58815+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
58816
58817 /**
58818 * audit_set_loginuid - set a task's audit_context loginuid
58819@@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT
58820 */
58821 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
58822 {
58823- unsigned int sessionid = atomic_inc_return(&session_id);
58824+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
58825 struct audit_context *context = task->audit_context;
58826
58827 if (context && context->in_syscall) {
58828diff -urNp linux-3.0.4/kernel/capability.c linux-3.0.4/kernel/capability.c
58829--- linux-3.0.4/kernel/capability.c 2011-07-21 22:17:23.000000000 -0400
58830+++ linux-3.0.4/kernel/capability.c 2011-08-23 21:48:14.000000000 -0400
58831@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
58832 * before modification is attempted and the application
58833 * fails.
58834 */
58835+ if (tocopy > ARRAY_SIZE(kdata))
58836+ return -EFAULT;
58837+
58838 if (copy_to_user(dataptr, kdata, tocopy
58839 * sizeof(struct __user_cap_data_struct))) {
58840 return -EFAULT;
58841@@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *n
58842 BUG();
58843 }
58844
58845- if (security_capable(ns, current_cred(), cap) == 0) {
58846+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
58847 current->flags |= PF_SUPERPRIV;
58848 return true;
58849 }
58850@@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *n
58851 }
58852 EXPORT_SYMBOL(ns_capable);
58853
58854+bool ns_capable_nolog(struct user_namespace *ns, int cap)
58855+{
58856+ if (unlikely(!cap_valid(cap))) {
58857+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
58858+ BUG();
58859+ }
58860+
58861+ if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
58862+ current->flags |= PF_SUPERPRIV;
58863+ return true;
58864+ }
58865+ return false;
58866+}
58867+EXPORT_SYMBOL(ns_capable_nolog);
58868+
58869+bool capable_nolog(int cap)
58870+{
58871+ return ns_capable_nolog(&init_user_ns, cap);
58872+}
58873+EXPORT_SYMBOL(capable_nolog);
58874+
58875 /**
58876 * task_ns_capable - Determine whether current task has a superior
58877 * capability targeted at a specific task's user namespace.
58878@@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct
58879 }
58880 EXPORT_SYMBOL(task_ns_capable);
58881
58882+bool task_ns_capable_nolog(struct task_struct *t, int cap)
58883+{
58884+ return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
58885+}
58886+EXPORT_SYMBOL(task_ns_capable_nolog);
58887+
58888 /**
58889 * nsown_capable - Check superior capability to one's own user_ns
58890 * @cap: The capability in question
58891diff -urNp linux-3.0.4/kernel/cgroup.c linux-3.0.4/kernel/cgroup.c
58892--- linux-3.0.4/kernel/cgroup.c 2011-07-21 22:17:23.000000000 -0400
58893+++ linux-3.0.4/kernel/cgroup.c 2011-08-23 21:48:14.000000000 -0400
58894@@ -593,6 +593,8 @@ static struct css_set *find_css_set(
58895 struct hlist_head *hhead;
58896 struct cg_cgroup_link *link;
58897
58898+ pax_track_stack();
58899+
58900 /* First see if we already have a cgroup group that matches
58901 * the desired set */
58902 read_lock(&css_set_lock);
58903diff -urNp linux-3.0.4/kernel/compat.c linux-3.0.4/kernel/compat.c
58904--- linux-3.0.4/kernel/compat.c 2011-07-21 22:17:23.000000000 -0400
58905+++ linux-3.0.4/kernel/compat.c 2011-08-23 21:48:14.000000000 -0400
58906@@ -13,6 +13,7 @@
58907
58908 #include <linux/linkage.h>
58909 #include <linux/compat.h>
58910+#include <linux/module.h>
58911 #include <linux/errno.h>
58912 #include <linux/time.h>
58913 #include <linux/signal.h>
58914diff -urNp linux-3.0.4/kernel/configs.c linux-3.0.4/kernel/configs.c
58915--- linux-3.0.4/kernel/configs.c 2011-07-21 22:17:23.000000000 -0400
58916+++ linux-3.0.4/kernel/configs.c 2011-08-23 21:48:14.000000000 -0400
58917@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
58918 struct proc_dir_entry *entry;
58919
58920 /* create the current config file */
58921+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
58922+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
58923+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
58924+ &ikconfig_file_ops);
58925+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58926+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
58927+ &ikconfig_file_ops);
58928+#endif
58929+#else
58930 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
58931 &ikconfig_file_ops);
58932+#endif
58933+
58934 if (!entry)
58935 return -ENOMEM;
58936
58937diff -urNp linux-3.0.4/kernel/cred.c linux-3.0.4/kernel/cred.c
58938--- linux-3.0.4/kernel/cred.c 2011-07-21 22:17:23.000000000 -0400
58939+++ linux-3.0.4/kernel/cred.c 2011-08-25 17:23:03.000000000 -0400
58940@@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
58941 */
58942 void __put_cred(struct cred *cred)
58943 {
58944+ pax_track_stack();
58945+
58946 kdebug("__put_cred(%p{%d,%d})", cred,
58947 atomic_read(&cred->usage),
58948 read_cred_subscribers(cred));
58949@@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
58950 {
58951 struct cred *cred;
58952
58953+ pax_track_stack();
58954+
58955 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
58956 atomic_read(&tsk->cred->usage),
58957 read_cred_subscribers(tsk->cred));
58958@@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
58959 {
58960 const struct cred *cred;
58961
58962+ pax_track_stack();
58963+
58964 rcu_read_lock();
58965
58966 do {
58967@@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
58968 {
58969 struct cred *new;
58970
58971+ pax_track_stack();
58972+
58973 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
58974 if (!new)
58975 return NULL;
58976@@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
58977 const struct cred *old;
58978 struct cred *new;
58979
58980+ pax_track_stack();
58981+
58982 validate_process_creds();
58983
58984 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
58985@@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
58986 struct thread_group_cred *tgcred = NULL;
58987 struct cred *new;
58988
58989+ pax_track_stack();
58990+
58991 #ifdef CONFIG_KEYS
58992 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
58993 if (!tgcred)
58994@@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
58995 struct cred *new;
58996 int ret;
58997
58998+ pax_track_stack();
58999+
59000 if (
59001 #ifdef CONFIG_KEYS
59002 !p->cred->thread_keyring &&
59003@@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
59004 struct task_struct *task = current;
59005 const struct cred *old = task->real_cred;
59006
59007+ pax_track_stack();
59008+
59009 kdebug("commit_creds(%p{%d,%d})", new,
59010 atomic_read(&new->usage),
59011 read_cred_subscribers(new));
59012@@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
59013
59014 get_cred(new); /* we will require a ref for the subj creds too */
59015
59016+ gr_set_role_label(task, new->uid, new->gid);
59017+
59018 /* dumpability changes */
59019 if (old->euid != new->euid ||
59020 old->egid != new->egid ||
59021@@ -508,10 +526,8 @@ int commit_creds(struct cred *new)
59022 key_fsgid_changed(task);
59023
59024 /* do it
59025- * - What if a process setreuid()'s and this brings the
59026- * new uid over his NPROC rlimit? We can check this now
59027- * cheaply with the new uid cache, so if it matters
59028- * we should be checking for it. -DaveM
59029+ * RLIMIT_NPROC limits on user->processes have already been checked
59030+ * in set_user().
59031 */
59032 alter_cred_subscribers(new, 2);
59033 if (new->user != old->user)
59034@@ -551,6 +567,8 @@ EXPORT_SYMBOL(commit_creds);
59035 */
59036 void abort_creds(struct cred *new)
59037 {
59038+ pax_track_stack();
59039+
59040 kdebug("abort_creds(%p{%d,%d})", new,
59041 atomic_read(&new->usage),
59042 read_cred_subscribers(new));
59043@@ -574,6 +592,8 @@ const struct cred *override_creds(const
59044 {
59045 const struct cred *old = current->cred;
59046
59047+ pax_track_stack();
59048+
59049 kdebug("override_creds(%p{%d,%d})", new,
59050 atomic_read(&new->usage),
59051 read_cred_subscribers(new));
59052@@ -603,6 +623,8 @@ void revert_creds(const struct cred *old
59053 {
59054 const struct cred *override = current->cred;
59055
59056+ pax_track_stack();
59057+
59058 kdebug("revert_creds(%p{%d,%d})", old,
59059 atomic_read(&old->usage),
59060 read_cred_subscribers(old));
59061@@ -649,6 +671,8 @@ struct cred *prepare_kernel_cred(struct
59062 const struct cred *old;
59063 struct cred *new;
59064
59065+ pax_track_stack();
59066+
59067 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
59068 if (!new)
59069 return NULL;
59070@@ -703,6 +727,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
59071 */
59072 int set_security_override(struct cred *new, u32 secid)
59073 {
59074+ pax_track_stack();
59075+
59076 return security_kernel_act_as(new, secid);
59077 }
59078 EXPORT_SYMBOL(set_security_override);
59079@@ -722,6 +748,8 @@ int set_security_override_from_ctx(struc
59080 u32 secid;
59081 int ret;
59082
59083+ pax_track_stack();
59084+
59085 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
59086 if (ret < 0)
59087 return ret;
59088diff -urNp linux-3.0.4/kernel/debug/debug_core.c linux-3.0.4/kernel/debug/debug_core.c
59089--- linux-3.0.4/kernel/debug/debug_core.c 2011-07-21 22:17:23.000000000 -0400
59090+++ linux-3.0.4/kernel/debug/debug_core.c 2011-08-23 21:47:56.000000000 -0400
59091@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
59092 */
59093 static atomic_t masters_in_kgdb;
59094 static atomic_t slaves_in_kgdb;
59095-static atomic_t kgdb_break_tasklet_var;
59096+static atomic_unchecked_t kgdb_break_tasklet_var;
59097 atomic_t kgdb_setting_breakpoint;
59098
59099 struct task_struct *kgdb_usethread;
59100@@ -129,7 +129,7 @@ int kgdb_single_step;
59101 static pid_t kgdb_sstep_pid;
59102
59103 /* to keep track of the CPU which is doing the single stepping*/
59104-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
59105+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
59106
59107 /*
59108 * If you are debugging a problem where roundup (the collection of
59109@@ -542,7 +542,7 @@ return_normal:
59110 * kernel will only try for the value of sstep_tries before
59111 * giving up and continuing on.
59112 */
59113- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
59114+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
59115 (kgdb_info[cpu].task &&
59116 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
59117 atomic_set(&kgdb_active, -1);
59118@@ -636,8 +636,8 @@ cpu_master_loop:
59119 }
59120
59121 kgdb_restore:
59122- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
59123- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
59124+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
59125+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
59126 if (kgdb_info[sstep_cpu].task)
59127 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
59128 else
59129@@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
59130 static void kgdb_tasklet_bpt(unsigned long ing)
59131 {
59132 kgdb_breakpoint();
59133- atomic_set(&kgdb_break_tasklet_var, 0);
59134+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
59135 }
59136
59137 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
59138
59139 void kgdb_schedule_breakpoint(void)
59140 {
59141- if (atomic_read(&kgdb_break_tasklet_var) ||
59142+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
59143 atomic_read(&kgdb_active) != -1 ||
59144 atomic_read(&kgdb_setting_breakpoint))
59145 return;
59146- atomic_inc(&kgdb_break_tasklet_var);
59147+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
59148 tasklet_schedule(&kgdb_tasklet_breakpoint);
59149 }
59150 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
59151diff -urNp linux-3.0.4/kernel/debug/kdb/kdb_main.c linux-3.0.4/kernel/debug/kdb/kdb_main.c
59152--- linux-3.0.4/kernel/debug/kdb/kdb_main.c 2011-07-21 22:17:23.000000000 -0400
59153+++ linux-3.0.4/kernel/debug/kdb/kdb_main.c 2011-08-23 21:47:56.000000000 -0400
59154@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
59155 list_for_each_entry(mod, kdb_modules, list) {
59156
59157 kdb_printf("%-20s%8u 0x%p ", mod->name,
59158- mod->core_size, (void *)mod);
59159+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
59160 #ifdef CONFIG_MODULE_UNLOAD
59161 kdb_printf("%4d ", module_refcount(mod));
59162 #endif
59163@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
59164 kdb_printf(" (Loading)");
59165 else
59166 kdb_printf(" (Live)");
59167- kdb_printf(" 0x%p", mod->module_core);
59168+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
59169
59170 #ifdef CONFIG_MODULE_UNLOAD
59171 {
59172diff -urNp linux-3.0.4/kernel/events/core.c linux-3.0.4/kernel/events/core.c
59173--- linux-3.0.4/kernel/events/core.c 2011-09-02 18:11:21.000000000 -0400
59174+++ linux-3.0.4/kernel/events/core.c 2011-09-14 09:08:05.000000000 -0400
59175@@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
59176 return 0;
59177 }
59178
59179-static atomic64_t perf_event_id;
59180+static atomic64_unchecked_t perf_event_id;
59181
59182 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
59183 enum event_type_t event_type);
59184@@ -2488,7 +2488,7 @@ static void __perf_event_read(void *info
59185
59186 static inline u64 perf_event_count(struct perf_event *event)
59187 {
59188- return local64_read(&event->count) + atomic64_read(&event->child_count);
59189+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
59190 }
59191
59192 static u64 perf_event_read(struct perf_event *event)
59193@@ -3023,9 +3023,9 @@ u64 perf_event_read_value(struct perf_ev
59194 mutex_lock(&event->child_mutex);
59195 total += perf_event_read(event);
59196 *enabled += event->total_time_enabled +
59197- atomic64_read(&event->child_total_time_enabled);
59198+ atomic64_read_unchecked(&event->child_total_time_enabled);
59199 *running += event->total_time_running +
59200- atomic64_read(&event->child_total_time_running);
59201+ atomic64_read_unchecked(&event->child_total_time_running);
59202
59203 list_for_each_entry(child, &event->child_list, child_list) {
59204 total += perf_event_read(child);
59205@@ -3388,10 +3388,10 @@ void perf_event_update_userpage(struct p
59206 userpg->offset -= local64_read(&event->hw.prev_count);
59207
59208 userpg->time_enabled = event->total_time_enabled +
59209- atomic64_read(&event->child_total_time_enabled);
59210+ atomic64_read_unchecked(&event->child_total_time_enabled);
59211
59212 userpg->time_running = event->total_time_running +
59213- atomic64_read(&event->child_total_time_running);
59214+ atomic64_read_unchecked(&event->child_total_time_running);
59215
59216 barrier();
59217 ++userpg->lock;
59218@@ -4188,11 +4188,11 @@ static void perf_output_read_one(struct
59219 values[n++] = perf_event_count(event);
59220 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
59221 values[n++] = enabled +
59222- atomic64_read(&event->child_total_time_enabled);
59223+ atomic64_read_unchecked(&event->child_total_time_enabled);
59224 }
59225 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
59226 values[n++] = running +
59227- atomic64_read(&event->child_total_time_running);
59228+ atomic64_read_unchecked(&event->child_total_time_running);
59229 }
59230 if (read_format & PERF_FORMAT_ID)
59231 values[n++] = primary_event_id(event);
59232@@ -4833,12 +4833,12 @@ static void perf_event_mmap_event(struct
59233 * need to add enough zero bytes after the string to handle
59234 * the 64bit alignment we do later.
59235 */
59236- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
59237+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
59238 if (!buf) {
59239 name = strncpy(tmp, "//enomem", sizeof(tmp));
59240 goto got_name;
59241 }
59242- name = d_path(&file->f_path, buf, PATH_MAX);
59243+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
59244 if (IS_ERR(name)) {
59245 name = strncpy(tmp, "//toolong", sizeof(tmp));
59246 goto got_name;
59247@@ -6190,7 +6190,7 @@ perf_event_alloc(struct perf_event_attr
59248 event->parent = parent_event;
59249
59250 event->ns = get_pid_ns(current->nsproxy->pid_ns);
59251- event->id = atomic64_inc_return(&perf_event_id);
59252+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
59253
59254 event->state = PERF_EVENT_STATE_INACTIVE;
59255
59256@@ -6713,10 +6713,10 @@ static void sync_child_event(struct perf
59257 /*
59258 * Add back the child's count to the parent's count:
59259 */
59260- atomic64_add(child_val, &parent_event->child_count);
59261- atomic64_add(child_event->total_time_enabled,
59262+ atomic64_add_unchecked(child_val, &parent_event->child_count);
59263+ atomic64_add_unchecked(child_event->total_time_enabled,
59264 &parent_event->child_total_time_enabled);
59265- atomic64_add(child_event->total_time_running,
59266+ atomic64_add_unchecked(child_event->total_time_running,
59267 &parent_event->child_total_time_running);
59268
59269 /*
59270diff -urNp linux-3.0.4/kernel/exit.c linux-3.0.4/kernel/exit.c
59271--- linux-3.0.4/kernel/exit.c 2011-07-21 22:17:23.000000000 -0400
59272+++ linux-3.0.4/kernel/exit.c 2011-08-23 21:48:14.000000000 -0400
59273@@ -57,6 +57,10 @@
59274 #include <asm/pgtable.h>
59275 #include <asm/mmu_context.h>
59276
59277+#ifdef CONFIG_GRKERNSEC
59278+extern rwlock_t grsec_exec_file_lock;
59279+#endif
59280+
59281 static void exit_mm(struct task_struct * tsk);
59282
59283 static void __unhash_process(struct task_struct *p, bool group_dead)
59284@@ -169,6 +173,10 @@ void release_task(struct task_struct * p
59285 struct task_struct *leader;
59286 int zap_leader;
59287 repeat:
59288+#ifdef CONFIG_NET
59289+ gr_del_task_from_ip_table(p);
59290+#endif
59291+
59292 tracehook_prepare_release_task(p);
59293 /* don't need to get the RCU readlock here - the process is dead and
59294 * can't be modifying its own credentials. But shut RCU-lockdep up */
59295@@ -338,11 +346,22 @@ static void reparent_to_kthreadd(void)
59296 {
59297 write_lock_irq(&tasklist_lock);
59298
59299+#ifdef CONFIG_GRKERNSEC
59300+ write_lock(&grsec_exec_file_lock);
59301+ if (current->exec_file) {
59302+ fput(current->exec_file);
59303+ current->exec_file = NULL;
59304+ }
59305+ write_unlock(&grsec_exec_file_lock);
59306+#endif
59307+
59308 ptrace_unlink(current);
59309 /* Reparent to init */
59310 current->real_parent = current->parent = kthreadd_task;
59311 list_move_tail(&current->sibling, &current->real_parent->children);
59312
59313+ gr_set_kernel_label(current);
59314+
59315 /* Set the exit signal to SIGCHLD so we signal init on exit */
59316 current->exit_signal = SIGCHLD;
59317
59318@@ -394,7 +413,7 @@ int allow_signal(int sig)
59319 * know it'll be handled, so that they don't get converted to
59320 * SIGKILL or just silently dropped.
59321 */
59322- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
59323+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
59324 recalc_sigpending();
59325 spin_unlock_irq(&current->sighand->siglock);
59326 return 0;
59327@@ -430,6 +449,17 @@ void daemonize(const char *name, ...)
59328 vsnprintf(current->comm, sizeof(current->comm), name, args);
59329 va_end(args);
59330
59331+#ifdef CONFIG_GRKERNSEC
59332+ write_lock(&grsec_exec_file_lock);
59333+ if (current->exec_file) {
59334+ fput(current->exec_file);
59335+ current->exec_file = NULL;
59336+ }
59337+ write_unlock(&grsec_exec_file_lock);
59338+#endif
59339+
59340+ gr_set_kernel_label(current);
59341+
59342 /*
59343 * If we were started as result of loading a module, close all of the
59344 * user space pages. We don't need them, and if we didn't close them
59345@@ -904,15 +934,8 @@ NORET_TYPE void do_exit(long code)
59346 struct task_struct *tsk = current;
59347 int group_dead;
59348
59349- profile_task_exit(tsk);
59350-
59351- WARN_ON(atomic_read(&tsk->fs_excl));
59352- WARN_ON(blk_needs_flush_plug(tsk));
59353-
59354 if (unlikely(in_interrupt()))
59355 panic("Aiee, killing interrupt handler!");
59356- if (unlikely(!tsk->pid))
59357- panic("Attempted to kill the idle task!");
59358
59359 /*
59360 * If do_exit is called because this processes oopsed, it's possible
59361@@ -923,6 +946,14 @@ NORET_TYPE void do_exit(long code)
59362 */
59363 set_fs(USER_DS);
59364
59365+ profile_task_exit(tsk);
59366+
59367+ WARN_ON(atomic_read(&tsk->fs_excl));
59368+ WARN_ON(blk_needs_flush_plug(tsk));
59369+
59370+ if (unlikely(!tsk->pid))
59371+ panic("Attempted to kill the idle task!");
59372+
59373 tracehook_report_exit(&code);
59374
59375 validate_creds_for_do_exit(tsk);
59376@@ -983,6 +1014,9 @@ NORET_TYPE void do_exit(long code)
59377 tsk->exit_code = code;
59378 taskstats_exit(tsk, group_dead);
59379
59380+ gr_acl_handle_psacct(tsk, code);
59381+ gr_acl_handle_exit();
59382+
59383 exit_mm(tsk);
59384
59385 if (group_dead)
59386diff -urNp linux-3.0.4/kernel/fork.c linux-3.0.4/kernel/fork.c
59387--- linux-3.0.4/kernel/fork.c 2011-07-21 22:17:23.000000000 -0400
59388+++ linux-3.0.4/kernel/fork.c 2011-08-25 17:23:36.000000000 -0400
59389@@ -286,7 +286,7 @@ static struct task_struct *dup_task_stru
59390 *stackend = STACK_END_MAGIC; /* for overflow detection */
59391
59392 #ifdef CONFIG_CC_STACKPROTECTOR
59393- tsk->stack_canary = get_random_int();
59394+ tsk->stack_canary = pax_get_random_long();
59395 #endif
59396
59397 /* One for us, one for whoever does the "release_task()" (usually parent) */
59398@@ -308,13 +308,77 @@ out:
59399 }
59400
59401 #ifdef CONFIG_MMU
59402+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
59403+{
59404+ struct vm_area_struct *tmp;
59405+ unsigned long charge;
59406+ struct mempolicy *pol;
59407+ struct file *file;
59408+
59409+ charge = 0;
59410+ if (mpnt->vm_flags & VM_ACCOUNT) {
59411+ unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
59412+ if (security_vm_enough_memory(len))
59413+ goto fail_nomem;
59414+ charge = len;
59415+ }
59416+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
59417+ if (!tmp)
59418+ goto fail_nomem;
59419+ *tmp = *mpnt;
59420+ tmp->vm_mm = mm;
59421+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
59422+ pol = mpol_dup(vma_policy(mpnt));
59423+ if (IS_ERR(pol))
59424+ goto fail_nomem_policy;
59425+ vma_set_policy(tmp, pol);
59426+ if (anon_vma_fork(tmp, mpnt))
59427+ goto fail_nomem_anon_vma_fork;
59428+ tmp->vm_flags &= ~VM_LOCKED;
59429+ tmp->vm_next = tmp->vm_prev = NULL;
59430+ tmp->vm_mirror = NULL;
59431+ file = tmp->vm_file;
59432+ if (file) {
59433+ struct inode *inode = file->f_path.dentry->d_inode;
59434+ struct address_space *mapping = file->f_mapping;
59435+
59436+ get_file(file);
59437+ if (tmp->vm_flags & VM_DENYWRITE)
59438+ atomic_dec(&inode->i_writecount);
59439+ mutex_lock(&mapping->i_mmap_mutex);
59440+ if (tmp->vm_flags & VM_SHARED)
59441+ mapping->i_mmap_writable++;
59442+ flush_dcache_mmap_lock(mapping);
59443+ /* insert tmp into the share list, just after mpnt */
59444+ vma_prio_tree_add(tmp, mpnt);
59445+ flush_dcache_mmap_unlock(mapping);
59446+ mutex_unlock(&mapping->i_mmap_mutex);
59447+ }
59448+
59449+ /*
59450+ * Clear hugetlb-related page reserves for children. This only
59451+ * affects MAP_PRIVATE mappings. Faults generated by the child
59452+ * are not guaranteed to succeed, even if read-only
59453+ */
59454+ if (is_vm_hugetlb_page(tmp))
59455+ reset_vma_resv_huge_pages(tmp);
59456+
59457+ return tmp;
59458+
59459+fail_nomem_anon_vma_fork:
59460+ mpol_put(pol);
59461+fail_nomem_policy:
59462+ kmem_cache_free(vm_area_cachep, tmp);
59463+fail_nomem:
59464+ vm_unacct_memory(charge);
59465+ return NULL;
59466+}
59467+
59468 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
59469 {
59470 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
59471 struct rb_node **rb_link, *rb_parent;
59472 int retval;
59473- unsigned long charge;
59474- struct mempolicy *pol;
59475
59476 down_write(&oldmm->mmap_sem);
59477 flush_cache_dup_mm(oldmm);
59478@@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm
59479 mm->locked_vm = 0;
59480 mm->mmap = NULL;
59481 mm->mmap_cache = NULL;
59482- mm->free_area_cache = oldmm->mmap_base;
59483- mm->cached_hole_size = ~0UL;
59484+ mm->free_area_cache = oldmm->free_area_cache;
59485+ mm->cached_hole_size = oldmm->cached_hole_size;
59486 mm->map_count = 0;
59487 cpumask_clear(mm_cpumask(mm));
59488 mm->mm_rb = RB_ROOT;
59489@@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm
59490
59491 prev = NULL;
59492 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
59493- struct file *file;
59494-
59495 if (mpnt->vm_flags & VM_DONTCOPY) {
59496 long pages = vma_pages(mpnt);
59497 mm->total_vm -= pages;
59498@@ -352,55 +414,13 @@ static int dup_mmap(struct mm_struct *mm
59499 -pages);
59500 continue;
59501 }
59502- charge = 0;
59503- if (mpnt->vm_flags & VM_ACCOUNT) {
59504- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
59505- if (security_vm_enough_memory(len))
59506- goto fail_nomem;
59507- charge = len;
59508- }
59509- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
59510- if (!tmp)
59511- goto fail_nomem;
59512- *tmp = *mpnt;
59513- INIT_LIST_HEAD(&tmp->anon_vma_chain);
59514- pol = mpol_dup(vma_policy(mpnt));
59515- retval = PTR_ERR(pol);
59516- if (IS_ERR(pol))
59517- goto fail_nomem_policy;
59518- vma_set_policy(tmp, pol);
59519- tmp->vm_mm = mm;
59520- if (anon_vma_fork(tmp, mpnt))
59521- goto fail_nomem_anon_vma_fork;
59522- tmp->vm_flags &= ~VM_LOCKED;
59523- tmp->vm_next = tmp->vm_prev = NULL;
59524- file = tmp->vm_file;
59525- if (file) {
59526- struct inode *inode = file->f_path.dentry->d_inode;
59527- struct address_space *mapping = file->f_mapping;
59528-
59529- get_file(file);
59530- if (tmp->vm_flags & VM_DENYWRITE)
59531- atomic_dec(&inode->i_writecount);
59532- mutex_lock(&mapping->i_mmap_mutex);
59533- if (tmp->vm_flags & VM_SHARED)
59534- mapping->i_mmap_writable++;
59535- flush_dcache_mmap_lock(mapping);
59536- /* insert tmp into the share list, just after mpnt */
59537- vma_prio_tree_add(tmp, mpnt);
59538- flush_dcache_mmap_unlock(mapping);
59539- mutex_unlock(&mapping->i_mmap_mutex);
59540+ tmp = dup_vma(mm, mpnt);
59541+ if (!tmp) {
59542+ retval = -ENOMEM;
59543+ goto out;
59544 }
59545
59546 /*
59547- * Clear hugetlb-related page reserves for children. This only
59548- * affects MAP_PRIVATE mappings. Faults generated by the child
59549- * are not guaranteed to succeed, even if read-only
59550- */
59551- if (is_vm_hugetlb_page(tmp))
59552- reset_vma_resv_huge_pages(tmp);
59553-
59554- /*
59555 * Link in the new vma and copy the page table entries.
59556 */
59557 *pprev = tmp;
59558@@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm
59559 if (retval)
59560 goto out;
59561 }
59562+
59563+#ifdef CONFIG_PAX_SEGMEXEC
59564+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
59565+ struct vm_area_struct *mpnt_m;
59566+
59567+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
59568+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
59569+
59570+ if (!mpnt->vm_mirror)
59571+ continue;
59572+
59573+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
59574+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
59575+ mpnt->vm_mirror = mpnt_m;
59576+ } else {
59577+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
59578+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
59579+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
59580+ mpnt->vm_mirror->vm_mirror = mpnt;
59581+ }
59582+ }
59583+ BUG_ON(mpnt_m);
59584+ }
59585+#endif
59586+
59587 /* a new mm has just been created */
59588 arch_dup_mmap(oldmm, mm);
59589 retval = 0;
59590@@ -429,14 +474,6 @@ out:
59591 flush_tlb_mm(oldmm);
59592 up_write(&oldmm->mmap_sem);
59593 return retval;
59594-fail_nomem_anon_vma_fork:
59595- mpol_put(pol);
59596-fail_nomem_policy:
59597- kmem_cache_free(vm_area_cachep, tmp);
59598-fail_nomem:
59599- retval = -ENOMEM;
59600- vm_unacct_memory(charge);
59601- goto out;
59602 }
59603
59604 static inline int mm_alloc_pgd(struct mm_struct * mm)
59605@@ -836,13 +873,14 @@ static int copy_fs(unsigned long clone_f
59606 spin_unlock(&fs->lock);
59607 return -EAGAIN;
59608 }
59609- fs->users++;
59610+ atomic_inc(&fs->users);
59611 spin_unlock(&fs->lock);
59612 return 0;
59613 }
59614 tsk->fs = copy_fs_struct(fs);
59615 if (!tsk->fs)
59616 return -ENOMEM;
59617+ gr_set_chroot_entries(tsk, &tsk->fs->root);
59618 return 0;
59619 }
59620
59621@@ -1104,12 +1142,16 @@ static struct task_struct *copy_process(
59622 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
59623 #endif
59624 retval = -EAGAIN;
59625+
59626+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
59627+
59628 if (atomic_read(&p->real_cred->user->processes) >=
59629 task_rlimit(p, RLIMIT_NPROC)) {
59630- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
59631- p->real_cred->user != INIT_USER)
59632+ if (p->real_cred->user != INIT_USER &&
59633+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
59634 goto bad_fork_free;
59635 }
59636+ current->flags &= ~PF_NPROC_EXCEEDED;
59637
59638 retval = copy_creds(p, clone_flags);
59639 if (retval < 0)
59640@@ -1250,6 +1292,8 @@ static struct task_struct *copy_process(
59641 if (clone_flags & CLONE_THREAD)
59642 p->tgid = current->tgid;
59643
59644+ gr_copy_label(p);
59645+
59646 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
59647 /*
59648 * Clear TID on mm_release()?
59649@@ -1414,6 +1458,8 @@ bad_fork_cleanup_count:
59650 bad_fork_free:
59651 free_task(p);
59652 fork_out:
59653+ gr_log_forkfail(retval);
59654+
59655 return ERR_PTR(retval);
59656 }
59657
59658@@ -1502,6 +1548,8 @@ long do_fork(unsigned long clone_flags,
59659 if (clone_flags & CLONE_PARENT_SETTID)
59660 put_user(nr, parent_tidptr);
59661
59662+ gr_handle_brute_check();
59663+
59664 if (clone_flags & CLONE_VFORK) {
59665 p->vfork_done = &vfork;
59666 init_completion(&vfork);
59667@@ -1610,7 +1658,7 @@ static int unshare_fs(unsigned long unsh
59668 return 0;
59669
59670 /* don't need lock here; in the worst case we'll do useless copy */
59671- if (fs->users == 1)
59672+ if (atomic_read(&fs->users) == 1)
59673 return 0;
59674
59675 *new_fsp = copy_fs_struct(fs);
59676@@ -1697,7 +1745,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
59677 fs = current->fs;
59678 spin_lock(&fs->lock);
59679 current->fs = new_fs;
59680- if (--fs->users)
59681+ gr_set_chroot_entries(current, &current->fs->root);
59682+ if (atomic_dec_return(&fs->users))
59683 new_fs = NULL;
59684 else
59685 new_fs = fs;
59686diff -urNp linux-3.0.4/kernel/futex.c linux-3.0.4/kernel/futex.c
59687--- linux-3.0.4/kernel/futex.c 2011-09-02 18:11:21.000000000 -0400
59688+++ linux-3.0.4/kernel/futex.c 2011-08-23 21:48:14.000000000 -0400
59689@@ -54,6 +54,7 @@
59690 #include <linux/mount.h>
59691 #include <linux/pagemap.h>
59692 #include <linux/syscalls.h>
59693+#include <linux/ptrace.h>
59694 #include <linux/signal.h>
59695 #include <linux/module.h>
59696 #include <linux/magic.h>
59697@@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fsh
59698 struct page *page, *page_head;
59699 int err, ro = 0;
59700
59701+#ifdef CONFIG_PAX_SEGMEXEC
59702+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
59703+ return -EFAULT;
59704+#endif
59705+
59706 /*
59707 * The futex address must be "naturally" aligned.
59708 */
59709@@ -1863,6 +1869,8 @@ static int futex_wait(u32 __user *uaddr,
59710 struct futex_q q = futex_q_init;
59711 int ret;
59712
59713+ pax_track_stack();
59714+
59715 if (!bitset)
59716 return -EINVAL;
59717 q.bitset = bitset;
59718@@ -2259,6 +2267,8 @@ static int futex_wait_requeue_pi(u32 __u
59719 struct futex_q q = futex_q_init;
59720 int res, ret;
59721
59722+ pax_track_stack();
59723+
59724 if (!bitset)
59725 return -EINVAL;
59726
59727@@ -2431,7 +2441,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59728 {
59729 struct robust_list_head __user *head;
59730 unsigned long ret;
59731+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
59732 const struct cred *cred = current_cred(), *pcred;
59733+#endif
59734
59735 if (!futex_cmpxchg_enabled)
59736 return -ENOSYS;
59737@@ -2447,6 +2459,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59738 if (!p)
59739 goto err_unlock;
59740 ret = -EPERM;
59741+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59742+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
59743+ goto err_unlock;
59744+#else
59745 pcred = __task_cred(p);
59746 /* If victim is in different user_ns, then uids are not
59747 comparable, so we must have CAP_SYS_PTRACE */
59748@@ -2461,6 +2477,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59749 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
59750 goto err_unlock;
59751 ok:
59752+#endif
59753 head = p->robust_list;
59754 rcu_read_unlock();
59755 }
59756@@ -2712,6 +2729,7 @@ static int __init futex_init(void)
59757 {
59758 u32 curval;
59759 int i;
59760+ mm_segment_t oldfs;
59761
59762 /*
59763 * This will fail and we want it. Some arch implementations do
59764@@ -2723,8 +2741,11 @@ static int __init futex_init(void)
59765 * implementation, the non-functional ones will return
59766 * -ENOSYS.
59767 */
59768+ oldfs = get_fs();
59769+ set_fs(USER_DS);
59770 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
59771 futex_cmpxchg_enabled = 1;
59772+ set_fs(oldfs);
59773
59774 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
59775 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
59776diff -urNp linux-3.0.4/kernel/futex_compat.c linux-3.0.4/kernel/futex_compat.c
59777--- linux-3.0.4/kernel/futex_compat.c 2011-07-21 22:17:23.000000000 -0400
59778+++ linux-3.0.4/kernel/futex_compat.c 2011-08-23 21:48:14.000000000 -0400
59779@@ -10,6 +10,7 @@
59780 #include <linux/compat.h>
59781 #include <linux/nsproxy.h>
59782 #include <linux/futex.h>
59783+#include <linux/ptrace.h>
59784
59785 #include <asm/uaccess.h>
59786
59787@@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
59788 {
59789 struct compat_robust_list_head __user *head;
59790 unsigned long ret;
59791- const struct cred *cred = current_cred(), *pcred;
59792+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
59793+ const struct cred *cred = current_cred();
59794+ const struct cred *pcred;
59795+#endif
59796
59797 if (!futex_cmpxchg_enabled)
59798 return -ENOSYS;
59799@@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
59800 if (!p)
59801 goto err_unlock;
59802 ret = -EPERM;
59803+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59804+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
59805+ goto err_unlock;
59806+#else
59807 pcred = __task_cred(p);
59808 /* If victim is in different user_ns, then uids are not
59809 comparable, so we must have CAP_SYS_PTRACE */
59810@@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
59811 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
59812 goto err_unlock;
59813 ok:
59814+#endif
59815 head = p->compat_robust_list;
59816 rcu_read_unlock();
59817 }
59818diff -urNp linux-3.0.4/kernel/gcov/base.c linux-3.0.4/kernel/gcov/base.c
59819--- linux-3.0.4/kernel/gcov/base.c 2011-07-21 22:17:23.000000000 -0400
59820+++ linux-3.0.4/kernel/gcov/base.c 2011-08-23 21:47:56.000000000 -0400
59821@@ -102,11 +102,6 @@ void gcov_enable_events(void)
59822 }
59823
59824 #ifdef CONFIG_MODULES
59825-static inline int within(void *addr, void *start, unsigned long size)
59826-{
59827- return ((addr >= start) && (addr < start + size));
59828-}
59829-
59830 /* Update list and generate events when modules are unloaded. */
59831 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
59832 void *data)
59833@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
59834 prev = NULL;
59835 /* Remove entries located in module from linked list. */
59836 for (info = gcov_info_head; info; info = info->next) {
59837- if (within(info, mod->module_core, mod->core_size)) {
59838+ if (within_module_core_rw((unsigned long)info, mod)) {
59839 if (prev)
59840 prev->next = info->next;
59841 else
59842diff -urNp linux-3.0.4/kernel/hrtimer.c linux-3.0.4/kernel/hrtimer.c
59843--- linux-3.0.4/kernel/hrtimer.c 2011-07-21 22:17:23.000000000 -0400
59844+++ linux-3.0.4/kernel/hrtimer.c 2011-08-23 21:47:56.000000000 -0400
59845@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
59846 local_irq_restore(flags);
59847 }
59848
59849-static void run_hrtimer_softirq(struct softirq_action *h)
59850+static void run_hrtimer_softirq(void)
59851 {
59852 hrtimer_peek_ahead_timers();
59853 }
59854diff -urNp linux-3.0.4/kernel/jump_label.c linux-3.0.4/kernel/jump_label.c
59855--- linux-3.0.4/kernel/jump_label.c 2011-07-21 22:17:23.000000000 -0400
59856+++ linux-3.0.4/kernel/jump_label.c 2011-08-23 21:47:56.000000000 -0400
59857@@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entr
59858
59859 size = (((unsigned long)stop - (unsigned long)start)
59860 / sizeof(struct jump_entry));
59861+ pax_open_kernel();
59862 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
59863+ pax_close_kernel();
59864 }
59865
59866 static void jump_label_update(struct jump_label_key *key, int enable);
59867@@ -297,10 +299,12 @@ static void jump_label_invalidate_module
59868 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
59869 struct jump_entry *iter;
59870
59871+ pax_open_kernel();
59872 for (iter = iter_start; iter < iter_stop; iter++) {
59873 if (within_module_init(iter->code, mod))
59874 iter->code = 0;
59875 }
59876+ pax_close_kernel();
59877 }
59878
59879 static int
59880diff -urNp linux-3.0.4/kernel/kallsyms.c linux-3.0.4/kernel/kallsyms.c
59881--- linux-3.0.4/kernel/kallsyms.c 2011-07-21 22:17:23.000000000 -0400
59882+++ linux-3.0.4/kernel/kallsyms.c 2011-08-23 21:48:14.000000000 -0400
59883@@ -11,6 +11,9 @@
59884 * Changed the compression method from stem compression to "table lookup"
59885 * compression (see scripts/kallsyms.c for a more complete description)
59886 */
59887+#ifdef CONFIG_GRKERNSEC_HIDESYM
59888+#define __INCLUDED_BY_HIDESYM 1
59889+#endif
59890 #include <linux/kallsyms.h>
59891 #include <linux/module.h>
59892 #include <linux/init.h>
59893@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
59894
59895 static inline int is_kernel_inittext(unsigned long addr)
59896 {
59897+ if (system_state != SYSTEM_BOOTING)
59898+ return 0;
59899+
59900 if (addr >= (unsigned long)_sinittext
59901 && addr <= (unsigned long)_einittext)
59902 return 1;
59903 return 0;
59904 }
59905
59906+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59907+#ifdef CONFIG_MODULES
59908+static inline int is_module_text(unsigned long addr)
59909+{
59910+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
59911+ return 1;
59912+
59913+ addr = ktla_ktva(addr);
59914+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
59915+}
59916+#else
59917+static inline int is_module_text(unsigned long addr)
59918+{
59919+ return 0;
59920+}
59921+#endif
59922+#endif
59923+
59924 static inline int is_kernel_text(unsigned long addr)
59925 {
59926 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
59927@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
59928
59929 static inline int is_kernel(unsigned long addr)
59930 {
59931+
59932+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59933+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
59934+ return 1;
59935+
59936+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
59937+#else
59938 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
59939+#endif
59940+
59941 return 1;
59942 return in_gate_area_no_mm(addr);
59943 }
59944
59945 static int is_ksym_addr(unsigned long addr)
59946 {
59947+
59948+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59949+ if (is_module_text(addr))
59950+ return 0;
59951+#endif
59952+
59953 if (all_var)
59954 return is_kernel(addr);
59955
59956@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
59957
59958 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
59959 {
59960- iter->name[0] = '\0';
59961 iter->nameoff = get_symbol_offset(new_pos);
59962 iter->pos = new_pos;
59963 }
59964@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
59965 {
59966 struct kallsym_iter *iter = m->private;
59967
59968+#ifdef CONFIG_GRKERNSEC_HIDESYM
59969+ if (current_uid())
59970+ return 0;
59971+#endif
59972+
59973 /* Some debugging symbols have no name. Ignore them. */
59974 if (!iter->name[0])
59975 return 0;
59976@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
59977 struct kallsym_iter *iter;
59978 int ret;
59979
59980- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
59981+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
59982 if (!iter)
59983 return -ENOMEM;
59984 reset_iter(iter, 0);
59985diff -urNp linux-3.0.4/kernel/kmod.c linux-3.0.4/kernel/kmod.c
59986--- linux-3.0.4/kernel/kmod.c 2011-07-21 22:17:23.000000000 -0400
59987+++ linux-3.0.4/kernel/kmod.c 2011-08-23 21:48:14.000000000 -0400
59988@@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
59989 * If module auto-loading support is disabled then this function
59990 * becomes a no-operation.
59991 */
59992-int __request_module(bool wait, const char *fmt, ...)
59993+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
59994 {
59995- va_list args;
59996 char module_name[MODULE_NAME_LEN];
59997 unsigned int max_modprobes;
59998 int ret;
59999- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
60000+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
60001 static char *envp[] = { "HOME=/",
60002 "TERM=linux",
60003 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
60004@@ -88,9 +87,7 @@ int __request_module(bool wait, const ch
60005 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
60006 static int kmod_loop_msg;
60007
60008- va_start(args, fmt);
60009- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
60010- va_end(args);
60011+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
60012 if (ret >= MODULE_NAME_LEN)
60013 return -ENAMETOOLONG;
60014
60015@@ -98,6 +95,20 @@ int __request_module(bool wait, const ch
60016 if (ret)
60017 return ret;
60018
60019+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60020+ if (!current_uid()) {
60021+ /* hack to workaround consolekit/udisks stupidity */
60022+ read_lock(&tasklist_lock);
60023+ if (!strcmp(current->comm, "mount") &&
60024+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
60025+ read_unlock(&tasklist_lock);
60026+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
60027+ return -EPERM;
60028+ }
60029+ read_unlock(&tasklist_lock);
60030+ }
60031+#endif
60032+
60033 /* If modprobe needs a service that is in a module, we get a recursive
60034 * loop. Limit the number of running kmod threads to max_threads/2 or
60035 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
60036@@ -131,6 +142,47 @@ int __request_module(bool wait, const ch
60037 atomic_dec(&kmod_concurrent);
60038 return ret;
60039 }
60040+
60041+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
60042+{
60043+ va_list args;
60044+ int ret;
60045+
60046+ va_start(args, fmt);
60047+ ret = ____request_module(wait, module_param, fmt, args);
60048+ va_end(args);
60049+
60050+ return ret;
60051+}
60052+
60053+int __request_module(bool wait, const char *fmt, ...)
60054+{
60055+ va_list args;
60056+ int ret;
60057+
60058+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60059+ if (current_uid()) {
60060+ char module_param[MODULE_NAME_LEN];
60061+
60062+ memset(module_param, 0, sizeof(module_param));
60063+
60064+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
60065+
60066+ va_start(args, fmt);
60067+ ret = ____request_module(wait, module_param, fmt, args);
60068+ va_end(args);
60069+
60070+ return ret;
60071+ }
60072+#endif
60073+
60074+ va_start(args, fmt);
60075+ ret = ____request_module(wait, NULL, fmt, args);
60076+ va_end(args);
60077+
60078+ return ret;
60079+}
60080+
60081 EXPORT_SYMBOL(__request_module);
60082 #endif /* CONFIG_MODULES */
60083
60084diff -urNp linux-3.0.4/kernel/kprobes.c linux-3.0.4/kernel/kprobes.c
60085--- linux-3.0.4/kernel/kprobes.c 2011-07-21 22:17:23.000000000 -0400
60086+++ linux-3.0.4/kernel/kprobes.c 2011-08-23 21:47:56.000000000 -0400
60087@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
60088 * kernel image and loaded module images reside. This is required
60089 * so x86_64 can correctly handle the %rip-relative fixups.
60090 */
60091- kip->insns = module_alloc(PAGE_SIZE);
60092+ kip->insns = module_alloc_exec(PAGE_SIZE);
60093 if (!kip->insns) {
60094 kfree(kip);
60095 return NULL;
60096@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
60097 */
60098 if (!list_is_singular(&kip->list)) {
60099 list_del(&kip->list);
60100- module_free(NULL, kip->insns);
60101+ module_free_exec(NULL, kip->insns);
60102 kfree(kip);
60103 }
60104 return 1;
60105@@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
60106 {
60107 int i, err = 0;
60108 unsigned long offset = 0, size = 0;
60109- char *modname, namebuf[128];
60110+ char *modname, namebuf[KSYM_NAME_LEN];
60111 const char *symbol_name;
60112 void *addr;
60113 struct kprobe_blackpoint *kb;
60114@@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
60115 const char *sym = NULL;
60116 unsigned int i = *(loff_t *) v;
60117 unsigned long offset = 0;
60118- char *modname, namebuf[128];
60119+ char *modname, namebuf[KSYM_NAME_LEN];
60120
60121 head = &kprobe_table[i];
60122 preempt_disable();
60123diff -urNp linux-3.0.4/kernel/lockdep.c linux-3.0.4/kernel/lockdep.c
60124--- linux-3.0.4/kernel/lockdep.c 2011-07-21 22:17:23.000000000 -0400
60125+++ linux-3.0.4/kernel/lockdep.c 2011-08-23 21:47:56.000000000 -0400
60126@@ -583,6 +583,10 @@ static int static_obj(void *obj)
60127 end = (unsigned long) &_end,
60128 addr = (unsigned long) obj;
60129
60130+#ifdef CONFIG_PAX_KERNEXEC
60131+ start = ktla_ktva(start);
60132+#endif
60133+
60134 /*
60135 * static variable?
60136 */
60137@@ -718,6 +722,7 @@ register_lock_class(struct lockdep_map *
60138 if (!static_obj(lock->key)) {
60139 debug_locks_off();
60140 printk("INFO: trying to register non-static key.\n");
60141+ printk("lock:%pS key:%pS.\n", lock, lock->key);
60142 printk("the code is fine but needs lockdep annotation.\n");
60143 printk("turning off the locking correctness validator.\n");
60144 dump_stack();
60145@@ -2936,7 +2941,7 @@ static int __lock_acquire(struct lockdep
60146 if (!class)
60147 return 0;
60148 }
60149- atomic_inc((atomic_t *)&class->ops);
60150+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
60151 if (very_verbose(class)) {
60152 printk("\nacquire class [%p] %s", class->key, class->name);
60153 if (class->name_version > 1)
60154diff -urNp linux-3.0.4/kernel/lockdep_proc.c linux-3.0.4/kernel/lockdep_proc.c
60155--- linux-3.0.4/kernel/lockdep_proc.c 2011-07-21 22:17:23.000000000 -0400
60156+++ linux-3.0.4/kernel/lockdep_proc.c 2011-08-23 21:47:56.000000000 -0400
60157@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
60158
60159 static void print_name(struct seq_file *m, struct lock_class *class)
60160 {
60161- char str[128];
60162+ char str[KSYM_NAME_LEN];
60163 const char *name = class->name;
60164
60165 if (!name) {
60166diff -urNp linux-3.0.4/kernel/module.c linux-3.0.4/kernel/module.c
60167--- linux-3.0.4/kernel/module.c 2011-07-21 22:17:23.000000000 -0400
60168+++ linux-3.0.4/kernel/module.c 2011-08-23 21:48:14.000000000 -0400
60169@@ -58,6 +58,7 @@
60170 #include <linux/jump_label.h>
60171 #include <linux/pfn.h>
60172 #include <linux/bsearch.h>
60173+#include <linux/grsecurity.h>
60174
60175 #define CREATE_TRACE_POINTS
60176 #include <trace/events/module.h>
60177@@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
60178
60179 /* Bounds of module allocation, for speeding __module_address.
60180 * Protected by module_mutex. */
60181-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
60182+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
60183+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
60184
60185 int register_module_notifier(struct notifier_block * nb)
60186 {
60187@@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(cons
60188 return true;
60189
60190 list_for_each_entry_rcu(mod, &modules, list) {
60191- struct symsearch arr[] = {
60192+ struct symsearch modarr[] = {
60193 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
60194 NOT_GPL_ONLY, false },
60195 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
60196@@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(cons
60197 #endif
60198 };
60199
60200- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
60201+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
60202 return true;
60203 }
60204 return false;
60205@@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(
60206 static int percpu_modalloc(struct module *mod,
60207 unsigned long size, unsigned long align)
60208 {
60209- if (align > PAGE_SIZE) {
60210+ if (align-1 >= PAGE_SIZE) {
60211 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
60212 mod->name, align, PAGE_SIZE);
60213 align = PAGE_SIZE;
60214@@ -1166,7 +1168,7 @@ resolve_symbol_wait(struct module *mod,
60215 */
60216 #ifdef CONFIG_SYSFS
60217
60218-#ifdef CONFIG_KALLSYMS
60219+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60220 static inline bool sect_empty(const Elf_Shdr *sect)
60221 {
60222 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
60223@@ -1632,21 +1634,21 @@ static void set_section_ro_nx(void *base
60224
60225 static void unset_module_core_ro_nx(struct module *mod)
60226 {
60227- set_page_attributes(mod->module_core + mod->core_text_size,
60228- mod->module_core + mod->core_size,
60229+ set_page_attributes(mod->module_core_rw,
60230+ mod->module_core_rw + mod->core_size_rw,
60231 set_memory_x);
60232- set_page_attributes(mod->module_core,
60233- mod->module_core + mod->core_ro_size,
60234+ set_page_attributes(mod->module_core_rx,
60235+ mod->module_core_rx + mod->core_size_rx,
60236 set_memory_rw);
60237 }
60238
60239 static void unset_module_init_ro_nx(struct module *mod)
60240 {
60241- set_page_attributes(mod->module_init + mod->init_text_size,
60242- mod->module_init + mod->init_size,
60243+ set_page_attributes(mod->module_init_rw,
60244+ mod->module_init_rw + mod->init_size_rw,
60245 set_memory_x);
60246- set_page_attributes(mod->module_init,
60247- mod->module_init + mod->init_ro_size,
60248+ set_page_attributes(mod->module_init_rx,
60249+ mod->module_init_rx + mod->init_size_rx,
60250 set_memory_rw);
60251 }
60252
60253@@ -1657,14 +1659,14 @@ void set_all_modules_text_rw(void)
60254
60255 mutex_lock(&module_mutex);
60256 list_for_each_entry_rcu(mod, &modules, list) {
60257- if ((mod->module_core) && (mod->core_text_size)) {
60258- set_page_attributes(mod->module_core,
60259- mod->module_core + mod->core_text_size,
60260+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
60261+ set_page_attributes(mod->module_core_rx,
60262+ mod->module_core_rx + mod->core_size_rx,
60263 set_memory_rw);
60264 }
60265- if ((mod->module_init) && (mod->init_text_size)) {
60266- set_page_attributes(mod->module_init,
60267- mod->module_init + mod->init_text_size,
60268+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
60269+ set_page_attributes(mod->module_init_rx,
60270+ mod->module_init_rx + mod->init_size_rx,
60271 set_memory_rw);
60272 }
60273 }
60274@@ -1678,14 +1680,14 @@ void set_all_modules_text_ro(void)
60275
60276 mutex_lock(&module_mutex);
60277 list_for_each_entry_rcu(mod, &modules, list) {
60278- if ((mod->module_core) && (mod->core_text_size)) {
60279- set_page_attributes(mod->module_core,
60280- mod->module_core + mod->core_text_size,
60281+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
60282+ set_page_attributes(mod->module_core_rx,
60283+ mod->module_core_rx + mod->core_size_rx,
60284 set_memory_ro);
60285 }
60286- if ((mod->module_init) && (mod->init_text_size)) {
60287- set_page_attributes(mod->module_init,
60288- mod->module_init + mod->init_text_size,
60289+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
60290+ set_page_attributes(mod->module_init_rx,
60291+ mod->module_init_rx + mod->init_size_rx,
60292 set_memory_ro);
60293 }
60294 }
60295@@ -1722,16 +1724,19 @@ static void free_module(struct module *m
60296
60297 /* This may be NULL, but that's OK */
60298 unset_module_init_ro_nx(mod);
60299- module_free(mod, mod->module_init);
60300+ module_free(mod, mod->module_init_rw);
60301+ module_free_exec(mod, mod->module_init_rx);
60302 kfree(mod->args);
60303 percpu_modfree(mod);
60304
60305 /* Free lock-classes: */
60306- lockdep_free_key_range(mod->module_core, mod->core_size);
60307+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
60308+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
60309
60310 /* Finally, free the core (containing the module structure) */
60311 unset_module_core_ro_nx(mod);
60312- module_free(mod, mod->module_core);
60313+ module_free_exec(mod, mod->module_core_rx);
60314+ module_free(mod, mod->module_core_rw);
60315
60316 #ifdef CONFIG_MPU
60317 update_protections(current->mm);
60318@@ -1800,10 +1805,31 @@ static int simplify_symbols(struct modul
60319 unsigned int i;
60320 int ret = 0;
60321 const struct kernel_symbol *ksym;
60322+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60323+ int is_fs_load = 0;
60324+ int register_filesystem_found = 0;
60325+ char *p;
60326+
60327+ p = strstr(mod->args, "grsec_modharden_fs");
60328+ if (p) {
60329+ char *endptr = p + strlen("grsec_modharden_fs");
60330+ /* copy \0 as well */
60331+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
60332+ is_fs_load = 1;
60333+ }
60334+#endif
60335
60336 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
60337 const char *name = info->strtab + sym[i].st_name;
60338
60339+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60340+ /* it's a real shame this will never get ripped and copied
60341+ upstream! ;(
60342+ */
60343+ if (is_fs_load && !strcmp(name, "register_filesystem"))
60344+ register_filesystem_found = 1;
60345+#endif
60346+
60347 switch (sym[i].st_shndx) {
60348 case SHN_COMMON:
60349 /* We compiled with -fno-common. These are not
60350@@ -1824,7 +1850,9 @@ static int simplify_symbols(struct modul
60351 ksym = resolve_symbol_wait(mod, info, name);
60352 /* Ok if resolved. */
60353 if (ksym && !IS_ERR(ksym)) {
60354+ pax_open_kernel();
60355 sym[i].st_value = ksym->value;
60356+ pax_close_kernel();
60357 break;
60358 }
60359
60360@@ -1843,11 +1871,20 @@ static int simplify_symbols(struct modul
60361 secbase = (unsigned long)mod_percpu(mod);
60362 else
60363 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
60364+ pax_open_kernel();
60365 sym[i].st_value += secbase;
60366+ pax_close_kernel();
60367 break;
60368 }
60369 }
60370
60371+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60372+ if (is_fs_load && !register_filesystem_found) {
60373+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
60374+ ret = -EPERM;
60375+ }
60376+#endif
60377+
60378 return ret;
60379 }
60380
60381@@ -1931,22 +1968,12 @@ static void layout_sections(struct modul
60382 || s->sh_entsize != ~0UL
60383 || strstarts(sname, ".init"))
60384 continue;
60385- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
60386+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
60387+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
60388+ else
60389+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
60390 DEBUGP("\t%s\n", name);
60391 }
60392- switch (m) {
60393- case 0: /* executable */
60394- mod->core_size = debug_align(mod->core_size);
60395- mod->core_text_size = mod->core_size;
60396- break;
60397- case 1: /* RO: text and ro-data */
60398- mod->core_size = debug_align(mod->core_size);
60399- mod->core_ro_size = mod->core_size;
60400- break;
60401- case 3: /* whole core */
60402- mod->core_size = debug_align(mod->core_size);
60403- break;
60404- }
60405 }
60406
60407 DEBUGP("Init section allocation order:\n");
60408@@ -1960,23 +1987,13 @@ static void layout_sections(struct modul
60409 || s->sh_entsize != ~0UL
60410 || !strstarts(sname, ".init"))
60411 continue;
60412- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
60413- | INIT_OFFSET_MASK);
60414+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
60415+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
60416+ else
60417+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
60418+ s->sh_entsize |= INIT_OFFSET_MASK;
60419 DEBUGP("\t%s\n", sname);
60420 }
60421- switch (m) {
60422- case 0: /* executable */
60423- mod->init_size = debug_align(mod->init_size);
60424- mod->init_text_size = mod->init_size;
60425- break;
60426- case 1: /* RO: text and ro-data */
60427- mod->init_size = debug_align(mod->init_size);
60428- mod->init_ro_size = mod->init_size;
60429- break;
60430- case 3: /* whole init */
60431- mod->init_size = debug_align(mod->init_size);
60432- break;
60433- }
60434 }
60435 }
60436
60437@@ -2141,7 +2158,7 @@ static void layout_symtab(struct module
60438
60439 /* Put symbol section at end of init part of module. */
60440 symsect->sh_flags |= SHF_ALLOC;
60441- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
60442+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
60443 info->index.sym) | INIT_OFFSET_MASK;
60444 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
60445
60446@@ -2158,19 +2175,19 @@ static void layout_symtab(struct module
60447 }
60448
60449 /* Append room for core symbols at end of core part. */
60450- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
60451- mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
60452+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
60453+ mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
60454
60455 /* Put string table section at end of init part of module. */
60456 strsect->sh_flags |= SHF_ALLOC;
60457- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
60458+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
60459 info->index.str) | INIT_OFFSET_MASK;
60460 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
60461
60462 /* Append room for core symbols' strings at end of core part. */
60463- info->stroffs = mod->core_size;
60464+ info->stroffs = mod->core_size_rx;
60465 __set_bit(0, info->strmap);
60466- mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
60467+ mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
60468 }
60469
60470 static void add_kallsyms(struct module *mod, const struct load_info *info)
60471@@ -2186,11 +2203,13 @@ static void add_kallsyms(struct module *
60472 /* Make sure we get permanent strtab: don't use info->strtab. */
60473 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
60474
60475+ pax_open_kernel();
60476+
60477 /* Set types up while we still have access to sections. */
60478 for (i = 0; i < mod->num_symtab; i++)
60479 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
60480
60481- mod->core_symtab = dst = mod->module_core + info->symoffs;
60482+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
60483 src = mod->symtab;
60484 *dst = *src;
60485 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
60486@@ -2203,10 +2222,12 @@ static void add_kallsyms(struct module *
60487 }
60488 mod->core_num_syms = ndst;
60489
60490- mod->core_strtab = s = mod->module_core + info->stroffs;
60491+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
60492 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
60493 if (test_bit(i, info->strmap))
60494 *++s = mod->strtab[i];
60495+
60496+ pax_close_kernel();
60497 }
60498 #else
60499 static inline void layout_symtab(struct module *mod, struct load_info *info)
60500@@ -2235,17 +2256,33 @@ static void dynamic_debug_remove(struct
60501 ddebug_remove_module(debug->modname);
60502 }
60503
60504-static void *module_alloc_update_bounds(unsigned long size)
60505+static void *module_alloc_update_bounds_rw(unsigned long size)
60506 {
60507 void *ret = module_alloc(size);
60508
60509 if (ret) {
60510 mutex_lock(&module_mutex);
60511 /* Update module bounds. */
60512- if ((unsigned long)ret < module_addr_min)
60513- module_addr_min = (unsigned long)ret;
60514- if ((unsigned long)ret + size > module_addr_max)
60515- module_addr_max = (unsigned long)ret + size;
60516+ if ((unsigned long)ret < module_addr_min_rw)
60517+ module_addr_min_rw = (unsigned long)ret;
60518+ if ((unsigned long)ret + size > module_addr_max_rw)
60519+ module_addr_max_rw = (unsigned long)ret + size;
60520+ mutex_unlock(&module_mutex);
60521+ }
60522+ return ret;
60523+}
60524+
60525+static void *module_alloc_update_bounds_rx(unsigned long size)
60526+{
60527+ void *ret = module_alloc_exec(size);
60528+
60529+ if (ret) {
60530+ mutex_lock(&module_mutex);
60531+ /* Update module bounds. */
60532+ if ((unsigned long)ret < module_addr_min_rx)
60533+ module_addr_min_rx = (unsigned long)ret;
60534+ if ((unsigned long)ret + size > module_addr_max_rx)
60535+ module_addr_max_rx = (unsigned long)ret + size;
60536 mutex_unlock(&module_mutex);
60537 }
60538 return ret;
60539@@ -2538,7 +2575,7 @@ static int move_module(struct module *mo
60540 void *ptr;
60541
60542 /* Do the allocs. */
60543- ptr = module_alloc_update_bounds(mod->core_size);
60544+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
60545 /*
60546 * The pointer to this block is stored in the module structure
60547 * which is inside the block. Just mark it as not being a
60548@@ -2548,23 +2585,50 @@ static int move_module(struct module *mo
60549 if (!ptr)
60550 return -ENOMEM;
60551
60552- memset(ptr, 0, mod->core_size);
60553- mod->module_core = ptr;
60554+ memset(ptr, 0, mod->core_size_rw);
60555+ mod->module_core_rw = ptr;
60556
60557- ptr = module_alloc_update_bounds(mod->init_size);
60558+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
60559 /*
60560 * The pointer to this block is stored in the module structure
60561 * which is inside the block. This block doesn't need to be
60562 * scanned as it contains data and code that will be freed
60563 * after the module is initialized.
60564 */
60565- kmemleak_ignore(ptr);
60566- if (!ptr && mod->init_size) {
60567- module_free(mod, mod->module_core);
60568+ kmemleak_not_leak(ptr);
60569+ if (!ptr && mod->init_size_rw) {
60570+ module_free(mod, mod->module_core_rw);
60571 return -ENOMEM;
60572 }
60573- memset(ptr, 0, mod->init_size);
60574- mod->module_init = ptr;
60575+ memset(ptr, 0, mod->init_size_rw);
60576+ mod->module_init_rw = ptr;
60577+
60578+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
60579+ kmemleak_not_leak(ptr);
60580+ if (!ptr) {
60581+ module_free(mod, mod->module_init_rw);
60582+ module_free(mod, mod->module_core_rw);
60583+ return -ENOMEM;
60584+ }
60585+
60586+ pax_open_kernel();
60587+ memset(ptr, 0, mod->core_size_rx);
60588+ pax_close_kernel();
60589+ mod->module_core_rx = ptr;
60590+
60591+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
60592+ kmemleak_not_leak(ptr);
60593+ if (!ptr && mod->init_size_rx) {
60594+ module_free_exec(mod, mod->module_core_rx);
60595+ module_free(mod, mod->module_init_rw);
60596+ module_free(mod, mod->module_core_rw);
60597+ return -ENOMEM;
60598+ }
60599+
60600+ pax_open_kernel();
60601+ memset(ptr, 0, mod->init_size_rx);
60602+ pax_close_kernel();
60603+ mod->module_init_rx = ptr;
60604
60605 /* Transfer each section which specifies SHF_ALLOC */
60606 DEBUGP("final section addresses:\n");
60607@@ -2575,16 +2639,45 @@ static int move_module(struct module *mo
60608 if (!(shdr->sh_flags & SHF_ALLOC))
60609 continue;
60610
60611- if (shdr->sh_entsize & INIT_OFFSET_MASK)
60612- dest = mod->module_init
60613- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
60614- else
60615- dest = mod->module_core + shdr->sh_entsize;
60616+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
60617+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
60618+ dest = mod->module_init_rw
60619+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
60620+ else
60621+ dest = mod->module_init_rx
60622+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
60623+ } else {
60624+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
60625+ dest = mod->module_core_rw + shdr->sh_entsize;
60626+ else
60627+ dest = mod->module_core_rx + shdr->sh_entsize;
60628+ }
60629+
60630+ if (shdr->sh_type != SHT_NOBITS) {
60631+
60632+#ifdef CONFIG_PAX_KERNEXEC
60633+#ifdef CONFIG_X86_64
60634+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
60635+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
60636+#endif
60637+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
60638+ pax_open_kernel();
60639+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
60640+ pax_close_kernel();
60641+ } else
60642+#endif
60643
60644- if (shdr->sh_type != SHT_NOBITS)
60645 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
60646+ }
60647 /* Update sh_addr to point to copy in image. */
60648- shdr->sh_addr = (unsigned long)dest;
60649+
60650+#ifdef CONFIG_PAX_KERNEXEC
60651+ if (shdr->sh_flags & SHF_EXECINSTR)
60652+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
60653+ else
60654+#endif
60655+
60656+ shdr->sh_addr = (unsigned long)dest;
60657 DEBUGP("\t0x%lx %s\n",
60658 shdr->sh_addr, info->secstrings + shdr->sh_name);
60659 }
60660@@ -2635,12 +2728,12 @@ static void flush_module_icache(const st
60661 * Do it before processing of module parameters, so the module
60662 * can provide parameter accessor functions of its own.
60663 */
60664- if (mod->module_init)
60665- flush_icache_range((unsigned long)mod->module_init,
60666- (unsigned long)mod->module_init
60667- + mod->init_size);
60668- flush_icache_range((unsigned long)mod->module_core,
60669- (unsigned long)mod->module_core + mod->core_size);
60670+ if (mod->module_init_rx)
60671+ flush_icache_range((unsigned long)mod->module_init_rx,
60672+ (unsigned long)mod->module_init_rx
60673+ + mod->init_size_rx);
60674+ flush_icache_range((unsigned long)mod->module_core_rx,
60675+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
60676
60677 set_fs(old_fs);
60678 }
60679@@ -2712,8 +2805,10 @@ static void module_deallocate(struct mod
60680 {
60681 kfree(info->strmap);
60682 percpu_modfree(mod);
60683- module_free(mod, mod->module_init);
60684- module_free(mod, mod->module_core);
60685+ module_free_exec(mod, mod->module_init_rx);
60686+ module_free_exec(mod, mod->module_core_rx);
60687+ module_free(mod, mod->module_init_rw);
60688+ module_free(mod, mod->module_core_rw);
60689 }
60690
60691 static int post_relocation(struct module *mod, const struct load_info *info)
60692@@ -2770,9 +2865,38 @@ static struct module *load_module(void _
60693 if (err)
60694 goto free_unload;
60695
60696+ /* Now copy in args */
60697+ mod->args = strndup_user(uargs, ~0UL >> 1);
60698+ if (IS_ERR(mod->args)) {
60699+ err = PTR_ERR(mod->args);
60700+ goto free_unload;
60701+ }
60702+
60703 /* Set up MODINFO_ATTR fields */
60704 setup_modinfo(mod, &info);
60705
60706+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60707+ {
60708+ char *p, *p2;
60709+
60710+ if (strstr(mod->args, "grsec_modharden_netdev")) {
60711+ 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);
60712+ err = -EPERM;
60713+ goto free_modinfo;
60714+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
60715+ p += strlen("grsec_modharden_normal");
60716+ p2 = strstr(p, "_");
60717+ if (p2) {
60718+ *p2 = '\0';
60719+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
60720+ *p2 = '_';
60721+ }
60722+ err = -EPERM;
60723+ goto free_modinfo;
60724+ }
60725+ }
60726+#endif
60727+
60728 /* Fix up syms, so that st_value is a pointer to location. */
60729 err = simplify_symbols(mod, &info);
60730 if (err < 0)
60731@@ -2788,13 +2912,6 @@ static struct module *load_module(void _
60732
60733 flush_module_icache(mod);
60734
60735- /* Now copy in args */
60736- mod->args = strndup_user(uargs, ~0UL >> 1);
60737- if (IS_ERR(mod->args)) {
60738- err = PTR_ERR(mod->args);
60739- goto free_arch_cleanup;
60740- }
60741-
60742 /* Mark state as coming so strong_try_module_get() ignores us. */
60743 mod->state = MODULE_STATE_COMING;
60744
60745@@ -2854,11 +2971,10 @@ static struct module *load_module(void _
60746 unlock:
60747 mutex_unlock(&module_mutex);
60748 synchronize_sched();
60749- kfree(mod->args);
60750- free_arch_cleanup:
60751 module_arch_cleanup(mod);
60752 free_modinfo:
60753 free_modinfo(mod);
60754+ kfree(mod->args);
60755 free_unload:
60756 module_unload_free(mod);
60757 free_module:
60758@@ -2899,16 +3015,16 @@ SYSCALL_DEFINE3(init_module, void __user
60759 MODULE_STATE_COMING, mod);
60760
60761 /* Set RO and NX regions for core */
60762- set_section_ro_nx(mod->module_core,
60763- mod->core_text_size,
60764- mod->core_ro_size,
60765- mod->core_size);
60766+ set_section_ro_nx(mod->module_core_rx,
60767+ mod->core_size_rx,
60768+ mod->core_size_rx,
60769+ mod->core_size_rx);
60770
60771 /* Set RO and NX regions for init */
60772- set_section_ro_nx(mod->module_init,
60773- mod->init_text_size,
60774- mod->init_ro_size,
60775- mod->init_size);
60776+ set_section_ro_nx(mod->module_init_rx,
60777+ mod->init_size_rx,
60778+ mod->init_size_rx,
60779+ mod->init_size_rx);
60780
60781 do_mod_ctors(mod);
60782 /* Start the module */
60783@@ -2954,11 +3070,12 @@ SYSCALL_DEFINE3(init_module, void __user
60784 mod->strtab = mod->core_strtab;
60785 #endif
60786 unset_module_init_ro_nx(mod);
60787- module_free(mod, mod->module_init);
60788- mod->module_init = NULL;
60789- mod->init_size = 0;
60790- mod->init_ro_size = 0;
60791- mod->init_text_size = 0;
60792+ module_free(mod, mod->module_init_rw);
60793+ module_free_exec(mod, mod->module_init_rx);
60794+ mod->module_init_rw = NULL;
60795+ mod->module_init_rx = NULL;
60796+ mod->init_size_rw = 0;
60797+ mod->init_size_rx = 0;
60798 mutex_unlock(&module_mutex);
60799
60800 return 0;
60801@@ -2989,10 +3106,16 @@ static const char *get_ksymbol(struct mo
60802 unsigned long nextval;
60803
60804 /* At worse, next value is at end of module */
60805- if (within_module_init(addr, mod))
60806- nextval = (unsigned long)mod->module_init+mod->init_text_size;
60807+ if (within_module_init_rx(addr, mod))
60808+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
60809+ else if (within_module_init_rw(addr, mod))
60810+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
60811+ else if (within_module_core_rx(addr, mod))
60812+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
60813+ else if (within_module_core_rw(addr, mod))
60814+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
60815 else
60816- nextval = (unsigned long)mod->module_core+mod->core_text_size;
60817+ return NULL;
60818
60819 /* Scan for closest preceding symbol, and next symbol. (ELF
60820 starts real symbols at 1). */
60821@@ -3238,7 +3361,7 @@ static int m_show(struct seq_file *m, vo
60822 char buf[8];
60823
60824 seq_printf(m, "%s %u",
60825- mod->name, mod->init_size + mod->core_size);
60826+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
60827 print_unload_info(m, mod);
60828
60829 /* Informative for users. */
60830@@ -3247,7 +3370,7 @@ static int m_show(struct seq_file *m, vo
60831 mod->state == MODULE_STATE_COMING ? "Loading":
60832 "Live");
60833 /* Used by oprofile and other similar tools. */
60834- seq_printf(m, " 0x%pK", mod->module_core);
60835+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
60836
60837 /* Taints info */
60838 if (mod->taints)
60839@@ -3283,7 +3406,17 @@ static const struct file_operations proc
60840
60841 static int __init proc_modules_init(void)
60842 {
60843+#ifndef CONFIG_GRKERNSEC_HIDESYM
60844+#ifdef CONFIG_GRKERNSEC_PROC_USER
60845+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
60846+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60847+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
60848+#else
60849 proc_create("modules", 0, NULL, &proc_modules_operations);
60850+#endif
60851+#else
60852+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
60853+#endif
60854 return 0;
60855 }
60856 module_init(proc_modules_init);
60857@@ -3342,12 +3475,12 @@ struct module *__module_address(unsigned
60858 {
60859 struct module *mod;
60860
60861- if (addr < module_addr_min || addr > module_addr_max)
60862+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
60863+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
60864 return NULL;
60865
60866 list_for_each_entry_rcu(mod, &modules, list)
60867- if (within_module_core(addr, mod)
60868- || within_module_init(addr, mod))
60869+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
60870 return mod;
60871 return NULL;
60872 }
60873@@ -3381,11 +3514,20 @@ bool is_module_text_address(unsigned lon
60874 */
60875 struct module *__module_text_address(unsigned long addr)
60876 {
60877- struct module *mod = __module_address(addr);
60878+ struct module *mod;
60879+
60880+#ifdef CONFIG_X86_32
60881+ addr = ktla_ktva(addr);
60882+#endif
60883+
60884+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
60885+ return NULL;
60886+
60887+ mod = __module_address(addr);
60888+
60889 if (mod) {
60890 /* Make sure it's within the text section. */
60891- if (!within(addr, mod->module_init, mod->init_text_size)
60892- && !within(addr, mod->module_core, mod->core_text_size))
60893+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
60894 mod = NULL;
60895 }
60896 return mod;
60897diff -urNp linux-3.0.4/kernel/mutex.c linux-3.0.4/kernel/mutex.c
60898--- linux-3.0.4/kernel/mutex.c 2011-07-21 22:17:23.000000000 -0400
60899+++ linux-3.0.4/kernel/mutex.c 2011-08-23 21:47:56.000000000 -0400
60900@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock,
60901 spin_lock_mutex(&lock->wait_lock, flags);
60902
60903 debug_mutex_lock_common(lock, &waiter);
60904- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
60905+ debug_mutex_add_waiter(lock, &waiter, task);
60906
60907 /* add waiting tasks to the end of the waitqueue (FIFO): */
60908 list_add_tail(&waiter.list, &lock->wait_list);
60909@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock,
60910 * TASK_UNINTERRUPTIBLE case.)
60911 */
60912 if (unlikely(signal_pending_state(state, task))) {
60913- mutex_remove_waiter(lock, &waiter,
60914- task_thread_info(task));
60915+ mutex_remove_waiter(lock, &waiter, task);
60916 mutex_release(&lock->dep_map, 1, ip);
60917 spin_unlock_mutex(&lock->wait_lock, flags);
60918
60919@@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock,
60920 done:
60921 lock_acquired(&lock->dep_map, ip);
60922 /* got the lock - rejoice! */
60923- mutex_remove_waiter(lock, &waiter, current_thread_info());
60924+ mutex_remove_waiter(lock, &waiter, task);
60925 mutex_set_owner(lock);
60926
60927 /* set it to 0 if there are no waiters left: */
60928diff -urNp linux-3.0.4/kernel/mutex-debug.c linux-3.0.4/kernel/mutex-debug.c
60929--- linux-3.0.4/kernel/mutex-debug.c 2011-07-21 22:17:23.000000000 -0400
60930+++ linux-3.0.4/kernel/mutex-debug.c 2011-08-23 21:47:56.000000000 -0400
60931@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
60932 }
60933
60934 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60935- struct thread_info *ti)
60936+ struct task_struct *task)
60937 {
60938 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
60939
60940 /* Mark the current thread as blocked on the lock: */
60941- ti->task->blocked_on = waiter;
60942+ task->blocked_on = waiter;
60943 }
60944
60945 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60946- struct thread_info *ti)
60947+ struct task_struct *task)
60948 {
60949 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
60950- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
60951- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
60952- ti->task->blocked_on = NULL;
60953+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
60954+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
60955+ task->blocked_on = NULL;
60956
60957 list_del_init(&waiter->list);
60958 waiter->task = NULL;
60959diff -urNp linux-3.0.4/kernel/mutex-debug.h linux-3.0.4/kernel/mutex-debug.h
60960--- linux-3.0.4/kernel/mutex-debug.h 2011-07-21 22:17:23.000000000 -0400
60961+++ linux-3.0.4/kernel/mutex-debug.h 2011-08-23 21:47:56.000000000 -0400
60962@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(stru
60963 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
60964 extern void debug_mutex_add_waiter(struct mutex *lock,
60965 struct mutex_waiter *waiter,
60966- struct thread_info *ti);
60967+ struct task_struct *task);
60968 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60969- struct thread_info *ti);
60970+ struct task_struct *task);
60971 extern void debug_mutex_unlock(struct mutex *lock);
60972 extern void debug_mutex_init(struct mutex *lock, const char *name,
60973 struct lock_class_key *key);
60974diff -urNp linux-3.0.4/kernel/padata.c linux-3.0.4/kernel/padata.c
60975--- linux-3.0.4/kernel/padata.c 2011-07-21 22:17:23.000000000 -0400
60976+++ linux-3.0.4/kernel/padata.c 2011-08-23 21:47:56.000000000 -0400
60977@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
60978 padata->pd = pd;
60979 padata->cb_cpu = cb_cpu;
60980
60981- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
60982- atomic_set(&pd->seq_nr, -1);
60983+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
60984+ atomic_set_unchecked(&pd->seq_nr, -1);
60985
60986- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
60987+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
60988
60989 target_cpu = padata_cpu_hash(padata);
60990 queue = per_cpu_ptr(pd->pqueue, target_cpu);
60991@@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
60992 padata_init_pqueues(pd);
60993 padata_init_squeues(pd);
60994 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
60995- atomic_set(&pd->seq_nr, -1);
60996+ atomic_set_unchecked(&pd->seq_nr, -1);
60997 atomic_set(&pd->reorder_objects, 0);
60998 atomic_set(&pd->refcnt, 0);
60999 pd->pinst = pinst;
61000diff -urNp linux-3.0.4/kernel/panic.c linux-3.0.4/kernel/panic.c
61001--- linux-3.0.4/kernel/panic.c 2011-07-21 22:17:23.000000000 -0400
61002+++ linux-3.0.4/kernel/panic.c 2011-08-23 21:48:14.000000000 -0400
61003@@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
61004 const char *board;
61005
61006 printk(KERN_WARNING "------------[ cut here ]------------\n");
61007- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
61008+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
61009 board = dmi_get_system_info(DMI_PRODUCT_NAME);
61010 if (board)
61011 printk(KERN_WARNING "Hardware name: %s\n", board);
61012@@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
61013 */
61014 void __stack_chk_fail(void)
61015 {
61016- panic("stack-protector: Kernel stack is corrupted in: %p\n",
61017+ dump_stack();
61018+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
61019 __builtin_return_address(0));
61020 }
61021 EXPORT_SYMBOL(__stack_chk_fail);
61022diff -urNp linux-3.0.4/kernel/pid.c linux-3.0.4/kernel/pid.c
61023--- linux-3.0.4/kernel/pid.c 2011-07-21 22:17:23.000000000 -0400
61024+++ linux-3.0.4/kernel/pid.c 2011-08-23 21:48:14.000000000 -0400
61025@@ -33,6 +33,7 @@
61026 #include <linux/rculist.h>
61027 #include <linux/bootmem.h>
61028 #include <linux/hash.h>
61029+#include <linux/security.h>
61030 #include <linux/pid_namespace.h>
61031 #include <linux/init_task.h>
61032 #include <linux/syscalls.h>
61033@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
61034
61035 int pid_max = PID_MAX_DEFAULT;
61036
61037-#define RESERVED_PIDS 300
61038+#define RESERVED_PIDS 500
61039
61040 int pid_max_min = RESERVED_PIDS + 1;
61041 int pid_max_max = PID_MAX_LIMIT;
61042@@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
61043 */
61044 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
61045 {
61046+ struct task_struct *task;
61047+
61048 rcu_lockdep_assert(rcu_read_lock_held());
61049- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
61050+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
61051+
61052+ if (gr_pid_is_chrooted(task))
61053+ return NULL;
61054+
61055+ return task;
61056 }
61057
61058 struct task_struct *find_task_by_vpid(pid_t vnr)
61059@@ -428,6 +436,12 @@ struct task_struct *find_task_by_vpid(pi
61060 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
61061 }
61062
61063+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
61064+{
61065+ rcu_lockdep_assert(rcu_read_lock_held());
61066+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
61067+}
61068+
61069 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
61070 {
61071 struct pid *pid;
61072diff -urNp linux-3.0.4/kernel/posix-cpu-timers.c linux-3.0.4/kernel/posix-cpu-timers.c
61073--- linux-3.0.4/kernel/posix-cpu-timers.c 2011-07-21 22:17:23.000000000 -0400
61074+++ linux-3.0.4/kernel/posix-cpu-timers.c 2011-08-23 21:48:14.000000000 -0400
61075@@ -6,6 +6,7 @@
61076 #include <linux/posix-timers.h>
61077 #include <linux/errno.h>
61078 #include <linux/math64.h>
61079+#include <linux/security.h>
61080 #include <asm/uaccess.h>
61081 #include <linux/kernel_stat.h>
61082 #include <trace/events/timer.h>
61083@@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
61084
61085 static __init int init_posix_cpu_timers(void)
61086 {
61087- struct k_clock process = {
61088+ static struct k_clock process = {
61089 .clock_getres = process_cpu_clock_getres,
61090 .clock_get = process_cpu_clock_get,
61091 .timer_create = process_cpu_timer_create,
61092 .nsleep = process_cpu_nsleep,
61093 .nsleep_restart = process_cpu_nsleep_restart,
61094 };
61095- struct k_clock thread = {
61096+ static struct k_clock thread = {
61097 .clock_getres = thread_cpu_clock_getres,
61098 .clock_get = thread_cpu_clock_get,
61099 .timer_create = thread_cpu_timer_create,
61100diff -urNp linux-3.0.4/kernel/posix-timers.c linux-3.0.4/kernel/posix-timers.c
61101--- linux-3.0.4/kernel/posix-timers.c 2011-07-21 22:17:23.000000000 -0400
61102+++ linux-3.0.4/kernel/posix-timers.c 2011-08-23 21:48:14.000000000 -0400
61103@@ -43,6 +43,7 @@
61104 #include <linux/idr.h>
61105 #include <linux/posix-clock.h>
61106 #include <linux/posix-timers.h>
61107+#include <linux/grsecurity.h>
61108 #include <linux/syscalls.h>
61109 #include <linux/wait.h>
61110 #include <linux/workqueue.h>
61111@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
61112 * which we beg off on and pass to do_sys_settimeofday().
61113 */
61114
61115-static struct k_clock posix_clocks[MAX_CLOCKS];
61116+static struct k_clock *posix_clocks[MAX_CLOCKS];
61117
61118 /*
61119 * These ones are defined below.
61120@@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
61121 */
61122 static __init int init_posix_timers(void)
61123 {
61124- struct k_clock clock_realtime = {
61125+ static struct k_clock clock_realtime = {
61126 .clock_getres = hrtimer_get_res,
61127 .clock_get = posix_clock_realtime_get,
61128 .clock_set = posix_clock_realtime_set,
61129@@ -239,7 +240,7 @@ static __init int init_posix_timers(void
61130 .timer_get = common_timer_get,
61131 .timer_del = common_timer_del,
61132 };
61133- struct k_clock clock_monotonic = {
61134+ static struct k_clock clock_monotonic = {
61135 .clock_getres = hrtimer_get_res,
61136 .clock_get = posix_ktime_get_ts,
61137 .nsleep = common_nsleep,
61138@@ -249,19 +250,19 @@ static __init int init_posix_timers(void
61139 .timer_get = common_timer_get,
61140 .timer_del = common_timer_del,
61141 };
61142- struct k_clock clock_monotonic_raw = {
61143+ static struct k_clock clock_monotonic_raw = {
61144 .clock_getres = hrtimer_get_res,
61145 .clock_get = posix_get_monotonic_raw,
61146 };
61147- struct k_clock clock_realtime_coarse = {
61148+ static struct k_clock clock_realtime_coarse = {
61149 .clock_getres = posix_get_coarse_res,
61150 .clock_get = posix_get_realtime_coarse,
61151 };
61152- struct k_clock clock_monotonic_coarse = {
61153+ static struct k_clock clock_monotonic_coarse = {
61154 .clock_getres = posix_get_coarse_res,
61155 .clock_get = posix_get_monotonic_coarse,
61156 };
61157- struct k_clock clock_boottime = {
61158+ static struct k_clock clock_boottime = {
61159 .clock_getres = hrtimer_get_res,
61160 .clock_get = posix_get_boottime,
61161 .nsleep = common_nsleep,
61162@@ -272,6 +273,8 @@ static __init int init_posix_timers(void
61163 .timer_del = common_timer_del,
61164 };
61165
61166+ pax_track_stack();
61167+
61168 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
61169 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
61170 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
61171@@ -473,7 +476,7 @@ void posix_timers_register_clock(const c
61172 return;
61173 }
61174
61175- posix_clocks[clock_id] = *new_clock;
61176+ posix_clocks[clock_id] = new_clock;
61177 }
61178 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
61179
61180@@ -519,9 +522,9 @@ static struct k_clock *clockid_to_kclock
61181 return (id & CLOCKFD_MASK) == CLOCKFD ?
61182 &clock_posix_dynamic : &clock_posix_cpu;
61183
61184- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
61185+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
61186 return NULL;
61187- return &posix_clocks[id];
61188+ return posix_clocks[id];
61189 }
61190
61191 static int common_timer_create(struct k_itimer *new_timer)
61192@@ -959,6 +962,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
61193 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
61194 return -EFAULT;
61195
61196+ /* only the CLOCK_REALTIME clock can be set, all other clocks
61197+ have their clock_set fptr set to a nosettime dummy function
61198+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
61199+ call common_clock_set, which calls do_sys_settimeofday, which
61200+ we hook
61201+ */
61202+
61203 return kc->clock_set(which_clock, &new_tp);
61204 }
61205
61206diff -urNp linux-3.0.4/kernel/power/poweroff.c linux-3.0.4/kernel/power/poweroff.c
61207--- linux-3.0.4/kernel/power/poweroff.c 2011-07-21 22:17:23.000000000 -0400
61208+++ linux-3.0.4/kernel/power/poweroff.c 2011-08-23 21:47:56.000000000 -0400
61209@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
61210 .enable_mask = SYSRQ_ENABLE_BOOT,
61211 };
61212
61213-static int pm_sysrq_init(void)
61214+static int __init pm_sysrq_init(void)
61215 {
61216 register_sysrq_key('o', &sysrq_poweroff_op);
61217 return 0;
61218diff -urNp linux-3.0.4/kernel/power/process.c linux-3.0.4/kernel/power/process.c
61219--- linux-3.0.4/kernel/power/process.c 2011-07-21 22:17:23.000000000 -0400
61220+++ linux-3.0.4/kernel/power/process.c 2011-08-23 21:47:56.000000000 -0400
61221@@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
61222 u64 elapsed_csecs64;
61223 unsigned int elapsed_csecs;
61224 bool wakeup = false;
61225+ bool timedout = false;
61226
61227 do_gettimeofday(&start);
61228
61229@@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
61230
61231 while (true) {
61232 todo = 0;
61233+ if (time_after(jiffies, end_time))
61234+ timedout = true;
61235 read_lock(&tasklist_lock);
61236 do_each_thread(g, p) {
61237 if (frozen(p) || !freezable(p))
61238@@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
61239 * try_to_stop() after schedule() in ptrace/signal
61240 * stop sees TIF_FREEZE.
61241 */
61242- if (!task_is_stopped_or_traced(p) &&
61243- !freezer_should_skip(p))
61244+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
61245 todo++;
61246+ if (timedout) {
61247+ printk(KERN_ERR "Task refusing to freeze:\n");
61248+ sched_show_task(p);
61249+ }
61250+ }
61251 } while_each_thread(g, p);
61252 read_unlock(&tasklist_lock);
61253
61254@@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
61255 todo += wq_busy;
61256 }
61257
61258- if (!todo || time_after(jiffies, end_time))
61259+ if (!todo || timedout)
61260 break;
61261
61262 if (pm_wakeup_pending()) {
61263diff -urNp linux-3.0.4/kernel/printk.c linux-3.0.4/kernel/printk.c
61264--- linux-3.0.4/kernel/printk.c 2011-07-21 22:17:23.000000000 -0400
61265+++ linux-3.0.4/kernel/printk.c 2011-08-23 21:48:14.000000000 -0400
61266@@ -313,12 +313,17 @@ static int check_syslog_permissions(int
61267 if (from_file && type != SYSLOG_ACTION_OPEN)
61268 return 0;
61269
61270+#ifdef CONFIG_GRKERNSEC_DMESG
61271+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
61272+ return -EPERM;
61273+#endif
61274+
61275 if (syslog_action_restricted(type)) {
61276 if (capable(CAP_SYSLOG))
61277 return 0;
61278 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
61279 if (capable(CAP_SYS_ADMIN)) {
61280- WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
61281+ printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
61282 "but no CAP_SYSLOG (deprecated).\n");
61283 return 0;
61284 }
61285diff -urNp linux-3.0.4/kernel/profile.c linux-3.0.4/kernel/profile.c
61286--- linux-3.0.4/kernel/profile.c 2011-07-21 22:17:23.000000000 -0400
61287+++ linux-3.0.4/kernel/profile.c 2011-08-23 21:47:56.000000000 -0400
61288@@ -39,7 +39,7 @@ struct profile_hit {
61289 /* Oprofile timer tick hook */
61290 static int (*timer_hook)(struct pt_regs *) __read_mostly;
61291
61292-static atomic_t *prof_buffer;
61293+static atomic_unchecked_t *prof_buffer;
61294 static unsigned long prof_len, prof_shift;
61295
61296 int prof_on __read_mostly;
61297@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
61298 hits[i].pc = 0;
61299 continue;
61300 }
61301- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
61302+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
61303 hits[i].hits = hits[i].pc = 0;
61304 }
61305 }
61306@@ -342,9 +342,9 @@ static void do_profile_hits(int type, vo
61307 * Add the current hit(s) and flush the write-queue out
61308 * to the global buffer:
61309 */
61310- atomic_add(nr_hits, &prof_buffer[pc]);
61311+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
61312 for (i = 0; i < NR_PROFILE_HIT; ++i) {
61313- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
61314+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
61315 hits[i].pc = hits[i].hits = 0;
61316 }
61317 out:
61318@@ -419,7 +419,7 @@ static void do_profile_hits(int type, vo
61319 {
61320 unsigned long pc;
61321 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
61322- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
61323+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
61324 }
61325 #endif /* !CONFIG_SMP */
61326
61327@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
61328 return -EFAULT;
61329 buf++; p++; count--; read++;
61330 }
61331- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
61332+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
61333 if (copy_to_user(buf, (void *)pnt, count))
61334 return -EFAULT;
61335 read += count;
61336@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
61337 }
61338 #endif
61339 profile_discard_flip_buffers();
61340- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
61341+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
61342 return count;
61343 }
61344
61345diff -urNp linux-3.0.4/kernel/ptrace.c linux-3.0.4/kernel/ptrace.c
61346--- linux-3.0.4/kernel/ptrace.c 2011-07-21 22:17:23.000000000 -0400
61347+++ linux-3.0.4/kernel/ptrace.c 2011-08-23 21:48:14.000000000 -0400
61348@@ -132,7 +132,8 @@ int ptrace_check_attach(struct task_stru
61349 return ret;
61350 }
61351
61352-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
61353+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
61354+ unsigned int log)
61355 {
61356 const struct cred *cred = current_cred(), *tcred;
61357
61358@@ -158,7 +159,8 @@ int __ptrace_may_access(struct task_stru
61359 cred->gid == tcred->sgid &&
61360 cred->gid == tcred->gid))
61361 goto ok;
61362- if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
61363+ if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
61364+ (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
61365 goto ok;
61366 rcu_read_unlock();
61367 return -EPERM;
61368@@ -167,7 +169,9 @@ ok:
61369 smp_rmb();
61370 if (task->mm)
61371 dumpable = get_dumpable(task->mm);
61372- if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
61373+ if (!dumpable &&
61374+ ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
61375+ (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
61376 return -EPERM;
61377
61378 return security_ptrace_access_check(task, mode);
61379@@ -177,7 +181,16 @@ bool ptrace_may_access(struct task_struc
61380 {
61381 int err;
61382 task_lock(task);
61383- err = __ptrace_may_access(task, mode);
61384+ err = __ptrace_may_access(task, mode, 0);
61385+ task_unlock(task);
61386+ return !err;
61387+}
61388+
61389+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
61390+{
61391+ int err;
61392+ task_lock(task);
61393+ err = __ptrace_may_access(task, mode, 1);
61394 task_unlock(task);
61395 return !err;
61396 }
61397@@ -205,7 +218,7 @@ static int ptrace_attach(struct task_str
61398 goto out;
61399
61400 task_lock(task);
61401- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
61402+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
61403 task_unlock(task);
61404 if (retval)
61405 goto unlock_creds;
61406@@ -218,7 +231,7 @@ static int ptrace_attach(struct task_str
61407 goto unlock_tasklist;
61408
61409 task->ptrace = PT_PTRACED;
61410- if (task_ns_capable(task, CAP_SYS_PTRACE))
61411+ if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
61412 task->ptrace |= PT_PTRACE_CAP;
61413
61414 __ptrace_link(task, current);
61415@@ -406,6 +419,8 @@ int ptrace_readdata(struct task_struct *
61416 {
61417 int copied = 0;
61418
61419+ pax_track_stack();
61420+
61421 while (len > 0) {
61422 char buf[128];
61423 int this_len, retval;
61424@@ -417,7 +432,7 @@ int ptrace_readdata(struct task_struct *
61425 break;
61426 return -EIO;
61427 }
61428- if (copy_to_user(dst, buf, retval))
61429+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
61430 return -EFAULT;
61431 copied += retval;
61432 src += retval;
61433@@ -431,6 +446,8 @@ int ptrace_writedata(struct task_struct
61434 {
61435 int copied = 0;
61436
61437+ pax_track_stack();
61438+
61439 while (len > 0) {
61440 char buf[128];
61441 int this_len, retval;
61442@@ -613,9 +630,11 @@ int ptrace_request(struct task_struct *c
61443 {
61444 int ret = -EIO;
61445 siginfo_t siginfo;
61446- void __user *datavp = (void __user *) data;
61447+ void __user *datavp = (__force void __user *) data;
61448 unsigned long __user *datalp = datavp;
61449
61450+ pax_track_stack();
61451+
61452 switch (request) {
61453 case PTRACE_PEEKTEXT:
61454 case PTRACE_PEEKDATA:
61455@@ -761,14 +780,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
61456 goto out;
61457 }
61458
61459+ if (gr_handle_ptrace(child, request)) {
61460+ ret = -EPERM;
61461+ goto out_put_task_struct;
61462+ }
61463+
61464 if (request == PTRACE_ATTACH) {
61465 ret = ptrace_attach(child);
61466 /*
61467 * Some architectures need to do book-keeping after
61468 * a ptrace attach.
61469 */
61470- if (!ret)
61471+ if (!ret) {
61472 arch_ptrace_attach(child);
61473+ gr_audit_ptrace(child);
61474+ }
61475 goto out_put_task_struct;
61476 }
61477
61478@@ -793,7 +819,7 @@ int generic_ptrace_peekdata(struct task_
61479 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
61480 if (copied != sizeof(tmp))
61481 return -EIO;
61482- return put_user(tmp, (unsigned long __user *)data);
61483+ return put_user(tmp, (__force unsigned long __user *)data);
61484 }
61485
61486 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
61487@@ -816,6 +842,8 @@ int compat_ptrace_request(struct task_st
61488 siginfo_t siginfo;
61489 int ret;
61490
61491+ pax_track_stack();
61492+
61493 switch (request) {
61494 case PTRACE_PEEKTEXT:
61495 case PTRACE_PEEKDATA:
61496@@ -903,14 +931,21 @@ asmlinkage long compat_sys_ptrace(compat
61497 goto out;
61498 }
61499
61500+ if (gr_handle_ptrace(child, request)) {
61501+ ret = -EPERM;
61502+ goto out_put_task_struct;
61503+ }
61504+
61505 if (request == PTRACE_ATTACH) {
61506 ret = ptrace_attach(child);
61507 /*
61508 * Some architectures need to do book-keeping after
61509 * a ptrace attach.
61510 */
61511- if (!ret)
61512+ if (!ret) {
61513 arch_ptrace_attach(child);
61514+ gr_audit_ptrace(child);
61515+ }
61516 goto out_put_task_struct;
61517 }
61518
61519diff -urNp linux-3.0.4/kernel/rcutorture.c linux-3.0.4/kernel/rcutorture.c
61520--- linux-3.0.4/kernel/rcutorture.c 2011-07-21 22:17:23.000000000 -0400
61521+++ linux-3.0.4/kernel/rcutorture.c 2011-08-23 21:47:56.000000000 -0400
61522@@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
61523 { 0 };
61524 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
61525 { 0 };
61526-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
61527-static atomic_t n_rcu_torture_alloc;
61528-static atomic_t n_rcu_torture_alloc_fail;
61529-static atomic_t n_rcu_torture_free;
61530-static atomic_t n_rcu_torture_mberror;
61531-static atomic_t n_rcu_torture_error;
61532+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
61533+static atomic_unchecked_t n_rcu_torture_alloc;
61534+static atomic_unchecked_t n_rcu_torture_alloc_fail;
61535+static atomic_unchecked_t n_rcu_torture_free;
61536+static atomic_unchecked_t n_rcu_torture_mberror;
61537+static atomic_unchecked_t n_rcu_torture_error;
61538 static long n_rcu_torture_boost_ktrerror;
61539 static long n_rcu_torture_boost_rterror;
61540 static long n_rcu_torture_boost_failure;
61541@@ -223,11 +223,11 @@ rcu_torture_alloc(void)
61542
61543 spin_lock_bh(&rcu_torture_lock);
61544 if (list_empty(&rcu_torture_freelist)) {
61545- atomic_inc(&n_rcu_torture_alloc_fail);
61546+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
61547 spin_unlock_bh(&rcu_torture_lock);
61548 return NULL;
61549 }
61550- atomic_inc(&n_rcu_torture_alloc);
61551+ atomic_inc_unchecked(&n_rcu_torture_alloc);
61552 p = rcu_torture_freelist.next;
61553 list_del_init(p);
61554 spin_unlock_bh(&rcu_torture_lock);
61555@@ -240,7 +240,7 @@ rcu_torture_alloc(void)
61556 static void
61557 rcu_torture_free(struct rcu_torture *p)
61558 {
61559- atomic_inc(&n_rcu_torture_free);
61560+ atomic_inc_unchecked(&n_rcu_torture_free);
61561 spin_lock_bh(&rcu_torture_lock);
61562 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
61563 spin_unlock_bh(&rcu_torture_lock);
61564@@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
61565 i = rp->rtort_pipe_count;
61566 if (i > RCU_TORTURE_PIPE_LEN)
61567 i = RCU_TORTURE_PIPE_LEN;
61568- atomic_inc(&rcu_torture_wcount[i]);
61569+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61570 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
61571 rp->rtort_mbtest = 0;
61572 rcu_torture_free(rp);
61573@@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_fr
61574 i = rp->rtort_pipe_count;
61575 if (i > RCU_TORTURE_PIPE_LEN)
61576 i = RCU_TORTURE_PIPE_LEN;
61577- atomic_inc(&rcu_torture_wcount[i]);
61578+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61579 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
61580 rp->rtort_mbtest = 0;
61581 list_del(&rp->rtort_free);
61582@@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
61583 i = old_rp->rtort_pipe_count;
61584 if (i > RCU_TORTURE_PIPE_LEN)
61585 i = RCU_TORTURE_PIPE_LEN;
61586- atomic_inc(&rcu_torture_wcount[i]);
61587+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61588 old_rp->rtort_pipe_count++;
61589 cur_ops->deferred_free(old_rp);
61590 }
61591@@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
61592 return;
61593 }
61594 if (p->rtort_mbtest == 0)
61595- atomic_inc(&n_rcu_torture_mberror);
61596+ atomic_inc_unchecked(&n_rcu_torture_mberror);
61597 spin_lock(&rand_lock);
61598 cur_ops->read_delay(&rand);
61599 n_rcu_torture_timers++;
61600@@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
61601 continue;
61602 }
61603 if (p->rtort_mbtest == 0)
61604- atomic_inc(&n_rcu_torture_mberror);
61605+ atomic_inc_unchecked(&n_rcu_torture_mberror);
61606 cur_ops->read_delay(&rand);
61607 preempt_disable();
61608 pipe_count = p->rtort_pipe_count;
61609@@ -1072,16 +1072,16 @@ rcu_torture_printk(char *page)
61610 rcu_torture_current,
61611 rcu_torture_current_version,
61612 list_empty(&rcu_torture_freelist),
61613- atomic_read(&n_rcu_torture_alloc),
61614- atomic_read(&n_rcu_torture_alloc_fail),
61615- atomic_read(&n_rcu_torture_free),
61616- atomic_read(&n_rcu_torture_mberror),
61617+ atomic_read_unchecked(&n_rcu_torture_alloc),
61618+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
61619+ atomic_read_unchecked(&n_rcu_torture_free),
61620+ atomic_read_unchecked(&n_rcu_torture_mberror),
61621 n_rcu_torture_boost_ktrerror,
61622 n_rcu_torture_boost_rterror,
61623 n_rcu_torture_boost_failure,
61624 n_rcu_torture_boosts,
61625 n_rcu_torture_timers);
61626- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
61627+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
61628 n_rcu_torture_boost_ktrerror != 0 ||
61629 n_rcu_torture_boost_rterror != 0 ||
61630 n_rcu_torture_boost_failure != 0)
61631@@ -1089,7 +1089,7 @@ rcu_torture_printk(char *page)
61632 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
61633 if (i > 1) {
61634 cnt += sprintf(&page[cnt], "!!! ");
61635- atomic_inc(&n_rcu_torture_error);
61636+ atomic_inc_unchecked(&n_rcu_torture_error);
61637 WARN_ON_ONCE(1);
61638 }
61639 cnt += sprintf(&page[cnt], "Reader Pipe: ");
61640@@ -1103,7 +1103,7 @@ rcu_torture_printk(char *page)
61641 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
61642 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
61643 cnt += sprintf(&page[cnt], " %d",
61644- atomic_read(&rcu_torture_wcount[i]));
61645+ atomic_read_unchecked(&rcu_torture_wcount[i]));
61646 }
61647 cnt += sprintf(&page[cnt], "\n");
61648 if (cur_ops->stats)
61649@@ -1412,7 +1412,7 @@ rcu_torture_cleanup(void)
61650
61651 if (cur_ops->cleanup)
61652 cur_ops->cleanup();
61653- if (atomic_read(&n_rcu_torture_error))
61654+ if (atomic_read_unchecked(&n_rcu_torture_error))
61655 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
61656 else
61657 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
61658@@ -1476,17 +1476,17 @@ rcu_torture_init(void)
61659
61660 rcu_torture_current = NULL;
61661 rcu_torture_current_version = 0;
61662- atomic_set(&n_rcu_torture_alloc, 0);
61663- atomic_set(&n_rcu_torture_alloc_fail, 0);
61664- atomic_set(&n_rcu_torture_free, 0);
61665- atomic_set(&n_rcu_torture_mberror, 0);
61666- atomic_set(&n_rcu_torture_error, 0);
61667+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
61668+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
61669+ atomic_set_unchecked(&n_rcu_torture_free, 0);
61670+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
61671+ atomic_set_unchecked(&n_rcu_torture_error, 0);
61672 n_rcu_torture_boost_ktrerror = 0;
61673 n_rcu_torture_boost_rterror = 0;
61674 n_rcu_torture_boost_failure = 0;
61675 n_rcu_torture_boosts = 0;
61676 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
61677- atomic_set(&rcu_torture_wcount[i], 0);
61678+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
61679 for_each_possible_cpu(cpu) {
61680 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
61681 per_cpu(rcu_torture_count, cpu)[i] = 0;
61682diff -urNp linux-3.0.4/kernel/rcutree.c linux-3.0.4/kernel/rcutree.c
61683--- linux-3.0.4/kernel/rcutree.c 2011-07-21 22:17:23.000000000 -0400
61684+++ linux-3.0.4/kernel/rcutree.c 2011-09-14 09:08:05.000000000 -0400
61685@@ -356,9 +356,9 @@ void rcu_enter_nohz(void)
61686 }
61687 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
61688 smp_mb__before_atomic_inc(); /* See above. */
61689- atomic_inc(&rdtp->dynticks);
61690+ atomic_inc_unchecked(&rdtp->dynticks);
61691 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
61692- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
61693+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
61694 local_irq_restore(flags);
61695
61696 /* If the interrupt queued a callback, get out of dyntick mode. */
61697@@ -387,10 +387,10 @@ void rcu_exit_nohz(void)
61698 return;
61699 }
61700 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
61701- atomic_inc(&rdtp->dynticks);
61702+ atomic_inc_unchecked(&rdtp->dynticks);
61703 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
61704 smp_mb__after_atomic_inc(); /* See above. */
61705- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
61706+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
61707 local_irq_restore(flags);
61708 }
61709
61710@@ -406,14 +406,14 @@ void rcu_nmi_enter(void)
61711 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
61712
61713 if (rdtp->dynticks_nmi_nesting == 0 &&
61714- (atomic_read(&rdtp->dynticks) & 0x1))
61715+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
61716 return;
61717 rdtp->dynticks_nmi_nesting++;
61718 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
61719- atomic_inc(&rdtp->dynticks);
61720+ atomic_inc_unchecked(&rdtp->dynticks);
61721 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
61722 smp_mb__after_atomic_inc(); /* See above. */
61723- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
61724+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
61725 }
61726
61727 /**
61728@@ -432,9 +432,9 @@ void rcu_nmi_exit(void)
61729 return;
61730 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
61731 smp_mb__before_atomic_inc(); /* See above. */
61732- atomic_inc(&rdtp->dynticks);
61733+ atomic_inc_unchecked(&rdtp->dynticks);
61734 smp_mb__after_atomic_inc(); /* Force delay to next write. */
61735- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
61736+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
61737 }
61738
61739 /**
61740@@ -469,7 +469,7 @@ void rcu_irq_exit(void)
61741 */
61742 static int dyntick_save_progress_counter(struct rcu_data *rdp)
61743 {
61744- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
61745+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
61746 return 0;
61747 }
61748
61749@@ -484,7 +484,7 @@ static int rcu_implicit_dynticks_qs(stru
61750 unsigned long curr;
61751 unsigned long snap;
61752
61753- curr = (unsigned long)atomic_add_return(0, &rdp->dynticks->dynticks);
61754+ curr = (unsigned long)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
61755 snap = (unsigned long)rdp->dynticks_snap;
61756
61757 /*
61758@@ -1470,7 +1470,7 @@ __rcu_process_callbacks(struct rcu_state
61759 /*
61760 * Do softirq processing for the current CPU.
61761 */
61762-static void rcu_process_callbacks(struct softirq_action *unused)
61763+static void rcu_process_callbacks(void)
61764 {
61765 __rcu_process_callbacks(&rcu_sched_state,
61766 &__get_cpu_var(rcu_sched_data));
61767diff -urNp linux-3.0.4/kernel/rcutree.h linux-3.0.4/kernel/rcutree.h
61768--- linux-3.0.4/kernel/rcutree.h 2011-07-21 22:17:23.000000000 -0400
61769+++ linux-3.0.4/kernel/rcutree.h 2011-09-14 09:08:05.000000000 -0400
61770@@ -86,7 +86,7 @@
61771 struct rcu_dynticks {
61772 int dynticks_nesting; /* Track irq/process nesting level. */
61773 int dynticks_nmi_nesting; /* Track NMI nesting level. */
61774- atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
61775+ atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
61776 };
61777
61778 /* RCU's kthread states for tracing. */
61779diff -urNp linux-3.0.4/kernel/rcutree_plugin.h linux-3.0.4/kernel/rcutree_plugin.h
61780--- linux-3.0.4/kernel/rcutree_plugin.h 2011-07-21 22:17:23.000000000 -0400
61781+++ linux-3.0.4/kernel/rcutree_plugin.h 2011-08-23 21:47:56.000000000 -0400
61782@@ -822,7 +822,7 @@ void synchronize_rcu_expedited(void)
61783
61784 /* Clean up and exit. */
61785 smp_mb(); /* ensure expedited GP seen before counter increment. */
61786- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
61787+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
61788 unlock_mb_ret:
61789 mutex_unlock(&sync_rcu_preempt_exp_mutex);
61790 mb_ret:
61791@@ -1774,8 +1774,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
61792
61793 #else /* #ifndef CONFIG_SMP */
61794
61795-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
61796-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
61797+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
61798+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
61799
61800 static int synchronize_sched_expedited_cpu_stop(void *data)
61801 {
61802@@ -1830,7 +1830,7 @@ void synchronize_sched_expedited(void)
61803 int firstsnap, s, snap, trycount = 0;
61804
61805 /* Note that atomic_inc_return() implies full memory barrier. */
61806- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
61807+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
61808 get_online_cpus();
61809
61810 /*
61811@@ -1851,7 +1851,7 @@ void synchronize_sched_expedited(void)
61812 }
61813
61814 /* Check to see if someone else did our work for us. */
61815- s = atomic_read(&sync_sched_expedited_done);
61816+ s = atomic_read_unchecked(&sync_sched_expedited_done);
61817 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
61818 smp_mb(); /* ensure test happens before caller kfree */
61819 return;
61820@@ -1866,7 +1866,7 @@ void synchronize_sched_expedited(void)
61821 * grace period works for us.
61822 */
61823 get_online_cpus();
61824- snap = atomic_read(&sync_sched_expedited_started) - 1;
61825+ snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
61826 smp_mb(); /* ensure read is before try_stop_cpus(). */
61827 }
61828
61829@@ -1877,12 +1877,12 @@ void synchronize_sched_expedited(void)
61830 * than we did beat us to the punch.
61831 */
61832 do {
61833- s = atomic_read(&sync_sched_expedited_done);
61834+ s = atomic_read_unchecked(&sync_sched_expedited_done);
61835 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
61836 smp_mb(); /* ensure test happens before caller kfree */
61837 break;
61838 }
61839- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
61840+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
61841
61842 put_online_cpus();
61843 }
61844diff -urNp linux-3.0.4/kernel/relay.c linux-3.0.4/kernel/relay.c
61845--- linux-3.0.4/kernel/relay.c 2011-07-21 22:17:23.000000000 -0400
61846+++ linux-3.0.4/kernel/relay.c 2011-08-23 21:48:14.000000000 -0400
61847@@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
61848 };
61849 ssize_t ret;
61850
61851+ pax_track_stack();
61852+
61853 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
61854 return 0;
61855 if (splice_grow_spd(pipe, &spd))
61856diff -urNp linux-3.0.4/kernel/resource.c linux-3.0.4/kernel/resource.c
61857--- linux-3.0.4/kernel/resource.c 2011-07-21 22:17:23.000000000 -0400
61858+++ linux-3.0.4/kernel/resource.c 2011-08-23 21:48:14.000000000 -0400
61859@@ -141,8 +141,18 @@ static const struct file_operations proc
61860
61861 static int __init ioresources_init(void)
61862 {
61863+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61864+#ifdef CONFIG_GRKERNSEC_PROC_USER
61865+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
61866+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
61867+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61868+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
61869+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
61870+#endif
61871+#else
61872 proc_create("ioports", 0, NULL, &proc_ioports_operations);
61873 proc_create("iomem", 0, NULL, &proc_iomem_operations);
61874+#endif
61875 return 0;
61876 }
61877 __initcall(ioresources_init);
61878diff -urNp linux-3.0.4/kernel/rtmutex-tester.c linux-3.0.4/kernel/rtmutex-tester.c
61879--- linux-3.0.4/kernel/rtmutex-tester.c 2011-07-21 22:17:23.000000000 -0400
61880+++ linux-3.0.4/kernel/rtmutex-tester.c 2011-08-23 21:47:56.000000000 -0400
61881@@ -20,7 +20,7 @@
61882 #define MAX_RT_TEST_MUTEXES 8
61883
61884 static spinlock_t rttest_lock;
61885-static atomic_t rttest_event;
61886+static atomic_unchecked_t rttest_event;
61887
61888 struct test_thread_data {
61889 int opcode;
61890@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
61891
61892 case RTTEST_LOCKCONT:
61893 td->mutexes[td->opdata] = 1;
61894- td->event = atomic_add_return(1, &rttest_event);
61895+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61896 return 0;
61897
61898 case RTTEST_RESET:
61899@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
61900 return 0;
61901
61902 case RTTEST_RESETEVENT:
61903- atomic_set(&rttest_event, 0);
61904+ atomic_set_unchecked(&rttest_event, 0);
61905 return 0;
61906
61907 default:
61908@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
61909 return ret;
61910
61911 td->mutexes[id] = 1;
61912- td->event = atomic_add_return(1, &rttest_event);
61913+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61914 rt_mutex_lock(&mutexes[id]);
61915- td->event = atomic_add_return(1, &rttest_event);
61916+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61917 td->mutexes[id] = 4;
61918 return 0;
61919
61920@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
61921 return ret;
61922
61923 td->mutexes[id] = 1;
61924- td->event = atomic_add_return(1, &rttest_event);
61925+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61926 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
61927- td->event = atomic_add_return(1, &rttest_event);
61928+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61929 td->mutexes[id] = ret ? 0 : 4;
61930 return ret ? -EINTR : 0;
61931
61932@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
61933 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
61934 return ret;
61935
61936- td->event = atomic_add_return(1, &rttest_event);
61937+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61938 rt_mutex_unlock(&mutexes[id]);
61939- td->event = atomic_add_return(1, &rttest_event);
61940+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61941 td->mutexes[id] = 0;
61942 return 0;
61943
61944@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
61945 break;
61946
61947 td->mutexes[dat] = 2;
61948- td->event = atomic_add_return(1, &rttest_event);
61949+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61950 break;
61951
61952 default:
61953@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
61954 return;
61955
61956 td->mutexes[dat] = 3;
61957- td->event = atomic_add_return(1, &rttest_event);
61958+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61959 break;
61960
61961 case RTTEST_LOCKNOWAIT:
61962@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
61963 return;
61964
61965 td->mutexes[dat] = 1;
61966- td->event = atomic_add_return(1, &rttest_event);
61967+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61968 return;
61969
61970 default:
61971diff -urNp linux-3.0.4/kernel/sched_autogroup.c linux-3.0.4/kernel/sched_autogroup.c
61972--- linux-3.0.4/kernel/sched_autogroup.c 2011-07-21 22:17:23.000000000 -0400
61973+++ linux-3.0.4/kernel/sched_autogroup.c 2011-08-23 21:47:56.000000000 -0400
61974@@ -7,7 +7,7 @@
61975
61976 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
61977 static struct autogroup autogroup_default;
61978-static atomic_t autogroup_seq_nr;
61979+static atomic_unchecked_t autogroup_seq_nr;
61980
61981 static void __init autogroup_init(struct task_struct *init_task)
61982 {
61983@@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
61984
61985 kref_init(&ag->kref);
61986 init_rwsem(&ag->lock);
61987- ag->id = atomic_inc_return(&autogroup_seq_nr);
61988+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
61989 ag->tg = tg;
61990 #ifdef CONFIG_RT_GROUP_SCHED
61991 /*
61992diff -urNp linux-3.0.4/kernel/sched.c linux-3.0.4/kernel/sched.c
61993--- linux-3.0.4/kernel/sched.c 2011-07-21 22:17:23.000000000 -0400
61994+++ linux-3.0.4/kernel/sched.c 2011-08-23 21:48:14.000000000 -0400
61995@@ -4251,6 +4251,8 @@ asmlinkage void __sched schedule(void)
61996 struct rq *rq;
61997 int cpu;
61998
61999+ pax_track_stack();
62000+
62001 need_resched:
62002 preempt_disable();
62003 cpu = smp_processor_id();
62004@@ -4934,6 +4936,8 @@ int can_nice(const struct task_struct *p
62005 /* convert nice value [19,-20] to rlimit style value [1,40] */
62006 int nice_rlim = 20 - nice;
62007
62008+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
62009+
62010 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
62011 capable(CAP_SYS_NICE));
62012 }
62013@@ -4967,7 +4971,8 @@ SYSCALL_DEFINE1(nice, int, increment)
62014 if (nice > 19)
62015 nice = 19;
62016
62017- if (increment < 0 && !can_nice(current, nice))
62018+ if (increment < 0 && (!can_nice(current, nice) ||
62019+ gr_handle_chroot_nice()))
62020 return -EPERM;
62021
62022 retval = security_task_setnice(current, nice);
62023@@ -5111,6 +5116,7 @@ recheck:
62024 unsigned long rlim_rtprio =
62025 task_rlimit(p, RLIMIT_RTPRIO);
62026
62027+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
62028 /* can't set/change the rt policy */
62029 if (policy != p->policy && !rlim_rtprio)
62030 return -EPERM;
62031diff -urNp linux-3.0.4/kernel/sched_fair.c linux-3.0.4/kernel/sched_fair.c
62032--- linux-3.0.4/kernel/sched_fair.c 2011-07-21 22:17:23.000000000 -0400
62033+++ linux-3.0.4/kernel/sched_fair.c 2011-08-23 21:47:56.000000000 -0400
62034@@ -4050,7 +4050,7 @@ static void nohz_idle_balance(int this_c
62035 * run_rebalance_domains is triggered when needed from the scheduler tick.
62036 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
62037 */
62038-static void run_rebalance_domains(struct softirq_action *h)
62039+static void run_rebalance_domains(void)
62040 {
62041 int this_cpu = smp_processor_id();
62042 struct rq *this_rq = cpu_rq(this_cpu);
62043diff -urNp linux-3.0.4/kernel/signal.c linux-3.0.4/kernel/signal.c
62044--- linux-3.0.4/kernel/signal.c 2011-07-21 22:17:23.000000000 -0400
62045+++ linux-3.0.4/kernel/signal.c 2011-08-23 21:48:14.000000000 -0400
62046@@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
62047
62048 int print_fatal_signals __read_mostly;
62049
62050-static void __user *sig_handler(struct task_struct *t, int sig)
62051+static __sighandler_t sig_handler(struct task_struct *t, int sig)
62052 {
62053 return t->sighand->action[sig - 1].sa.sa_handler;
62054 }
62055
62056-static int sig_handler_ignored(void __user *handler, int sig)
62057+static int sig_handler_ignored(__sighandler_t handler, int sig)
62058 {
62059 /* Is it explicitly or implicitly ignored? */
62060 return handler == SIG_IGN ||
62061@@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
62062 static int sig_task_ignored(struct task_struct *t, int sig,
62063 int from_ancestor_ns)
62064 {
62065- void __user *handler;
62066+ __sighandler_t handler;
62067
62068 handler = sig_handler(t, sig);
62069
62070@@ -320,6 +320,9 @@ __sigqueue_alloc(int sig, struct task_st
62071 atomic_inc(&user->sigpending);
62072 rcu_read_unlock();
62073
62074+ if (!override_rlimit)
62075+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
62076+
62077 if (override_rlimit ||
62078 atomic_read(&user->sigpending) <=
62079 task_rlimit(t, RLIMIT_SIGPENDING)) {
62080@@ -444,7 +447,7 @@ flush_signal_handlers(struct task_struct
62081
62082 int unhandled_signal(struct task_struct *tsk, int sig)
62083 {
62084- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
62085+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
62086 if (is_global_init(tsk))
62087 return 1;
62088 if (handler != SIG_IGN && handler != SIG_DFL)
62089@@ -770,6 +773,13 @@ static int check_kill_permission(int sig
62090 }
62091 }
62092
62093+ /* allow glibc communication via tgkill to other threads in our
62094+ thread group */
62095+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
62096+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
62097+ && gr_handle_signal(t, sig))
62098+ return -EPERM;
62099+
62100 return security_task_kill(t, info, sig, 0);
62101 }
62102
62103@@ -1092,7 +1102,7 @@ __group_send_sig_info(int sig, struct si
62104 return send_signal(sig, info, p, 1);
62105 }
62106
62107-static int
62108+int
62109 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
62110 {
62111 return send_signal(sig, info, t, 0);
62112@@ -1129,6 +1139,7 @@ force_sig_info(int sig, struct siginfo *
62113 unsigned long int flags;
62114 int ret, blocked, ignored;
62115 struct k_sigaction *action;
62116+ int is_unhandled = 0;
62117
62118 spin_lock_irqsave(&t->sighand->siglock, flags);
62119 action = &t->sighand->action[sig-1];
62120@@ -1143,9 +1154,18 @@ force_sig_info(int sig, struct siginfo *
62121 }
62122 if (action->sa.sa_handler == SIG_DFL)
62123 t->signal->flags &= ~SIGNAL_UNKILLABLE;
62124+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
62125+ is_unhandled = 1;
62126 ret = specific_send_sig_info(sig, info, t);
62127 spin_unlock_irqrestore(&t->sighand->siglock, flags);
62128
62129+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
62130+ normal operation */
62131+ if (is_unhandled) {
62132+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
62133+ gr_handle_crash(t, sig);
62134+ }
62135+
62136 return ret;
62137 }
62138
62139@@ -1212,8 +1232,11 @@ int group_send_sig_info(int sig, struct
62140 ret = check_kill_permission(sig, info, p);
62141 rcu_read_unlock();
62142
62143- if (!ret && sig)
62144+ if (!ret && sig) {
62145 ret = do_send_sig_info(sig, info, p, true);
62146+ if (!ret)
62147+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
62148+ }
62149
62150 return ret;
62151 }
62152@@ -1839,6 +1862,8 @@ void ptrace_notify(int exit_code)
62153 {
62154 siginfo_t info;
62155
62156+ pax_track_stack();
62157+
62158 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
62159
62160 memset(&info, 0, sizeof info);
62161@@ -2639,7 +2664,15 @@ do_send_specific(pid_t tgid, pid_t pid,
62162 int error = -ESRCH;
62163
62164 rcu_read_lock();
62165- p = find_task_by_vpid(pid);
62166+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62167+ /* allow glibc communication via tgkill to other threads in our
62168+ thread group */
62169+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
62170+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
62171+ p = find_task_by_vpid_unrestricted(pid);
62172+ else
62173+#endif
62174+ p = find_task_by_vpid(pid);
62175 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
62176 error = check_kill_permission(sig, info, p);
62177 /*
62178diff -urNp linux-3.0.4/kernel/smp.c linux-3.0.4/kernel/smp.c
62179--- linux-3.0.4/kernel/smp.c 2011-07-21 22:17:23.000000000 -0400
62180+++ linux-3.0.4/kernel/smp.c 2011-08-23 21:47:56.000000000 -0400
62181@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t fu
62182 }
62183 EXPORT_SYMBOL(smp_call_function);
62184
62185-void ipi_call_lock(void)
62186+void ipi_call_lock(void) __acquires(call_function.lock)
62187 {
62188 raw_spin_lock(&call_function.lock);
62189 }
62190
62191-void ipi_call_unlock(void)
62192+void ipi_call_unlock(void) __releases(call_function.lock)
62193 {
62194 raw_spin_unlock(&call_function.lock);
62195 }
62196
62197-void ipi_call_lock_irq(void)
62198+void ipi_call_lock_irq(void) __acquires(call_function.lock)
62199 {
62200 raw_spin_lock_irq(&call_function.lock);
62201 }
62202
62203-void ipi_call_unlock_irq(void)
62204+void ipi_call_unlock_irq(void) __releases(call_function.lock)
62205 {
62206 raw_spin_unlock_irq(&call_function.lock);
62207 }
62208diff -urNp linux-3.0.4/kernel/softirq.c linux-3.0.4/kernel/softirq.c
62209--- linux-3.0.4/kernel/softirq.c 2011-07-21 22:17:23.000000000 -0400
62210+++ linux-3.0.4/kernel/softirq.c 2011-08-23 21:47:56.000000000 -0400
62211@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
62212
62213 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
62214
62215-char *softirq_to_name[NR_SOFTIRQS] = {
62216+const char * const softirq_to_name[NR_SOFTIRQS] = {
62217 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
62218 "TASKLET", "SCHED", "HRTIMER", "RCU"
62219 };
62220@@ -235,7 +235,7 @@ restart:
62221 kstat_incr_softirqs_this_cpu(vec_nr);
62222
62223 trace_softirq_entry(vec_nr);
62224- h->action(h);
62225+ h->action();
62226 trace_softirq_exit(vec_nr);
62227 if (unlikely(prev_count != preempt_count())) {
62228 printk(KERN_ERR "huh, entered softirq %u %s %p"
62229@@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
62230 local_irq_restore(flags);
62231 }
62232
62233-void open_softirq(int nr, void (*action)(struct softirq_action *))
62234+void open_softirq(int nr, void (*action)(void))
62235 {
62236- softirq_vec[nr].action = action;
62237+ pax_open_kernel();
62238+ *(void **)&softirq_vec[nr].action = action;
62239+ pax_close_kernel();
62240 }
62241
62242 /*
62243@@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct
62244
62245 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
62246
62247-static void tasklet_action(struct softirq_action *a)
62248+static void tasklet_action(void)
62249 {
62250 struct tasklet_struct *list;
62251
62252@@ -476,7 +478,7 @@ static void tasklet_action(struct softir
62253 }
62254 }
62255
62256-static void tasklet_hi_action(struct softirq_action *a)
62257+static void tasklet_hi_action(void)
62258 {
62259 struct tasklet_struct *list;
62260
62261diff -urNp linux-3.0.4/kernel/sys.c linux-3.0.4/kernel/sys.c
62262--- linux-3.0.4/kernel/sys.c 2011-09-02 18:11:26.000000000 -0400
62263+++ linux-3.0.4/kernel/sys.c 2011-08-29 23:26:27.000000000 -0400
62264@@ -158,6 +158,12 @@ static int set_one_prio(struct task_stru
62265 error = -EACCES;
62266 goto out;
62267 }
62268+
62269+ if (gr_handle_chroot_setpriority(p, niceval)) {
62270+ error = -EACCES;
62271+ goto out;
62272+ }
62273+
62274 no_nice = security_task_setnice(p, niceval);
62275 if (no_nice) {
62276 error = no_nice;
62277@@ -541,6 +547,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
62278 goto error;
62279 }
62280
62281+ if (gr_check_group_change(new->gid, new->egid, -1))
62282+ goto error;
62283+
62284 if (rgid != (gid_t) -1 ||
62285 (egid != (gid_t) -1 && egid != old->gid))
62286 new->sgid = new->egid;
62287@@ -570,6 +579,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
62288 old = current_cred();
62289
62290 retval = -EPERM;
62291+
62292+ if (gr_check_group_change(gid, gid, gid))
62293+ goto error;
62294+
62295 if (nsown_capable(CAP_SETGID))
62296 new->gid = new->egid = new->sgid = new->fsgid = gid;
62297 else if (gid == old->gid || gid == old->sgid)
62298@@ -595,11 +608,18 @@ static int set_user(struct cred *new)
62299 if (!new_user)
62300 return -EAGAIN;
62301
62302+ /*
62303+ * We don't fail in case of NPROC limit excess here because too many
62304+ * poorly written programs don't check set*uid() return code, assuming
62305+ * it never fails if called by root. We may still enforce NPROC limit
62306+ * for programs doing set*uid()+execve() by harmlessly deferring the
62307+ * failure to the execve() stage.
62308+ */
62309 if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) &&
62310- new_user != INIT_USER) {
62311- free_uid(new_user);
62312- return -EAGAIN;
62313- }
62314+ new_user != INIT_USER)
62315+ current->flags |= PF_NPROC_EXCEEDED;
62316+ else
62317+ current->flags &= ~PF_NPROC_EXCEEDED;
62318
62319 free_uid(new->user);
62320 new->user = new_user;
62321@@ -650,6 +670,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
62322 goto error;
62323 }
62324
62325+ if (gr_check_user_change(new->uid, new->euid, -1))
62326+ goto error;
62327+
62328 if (new->uid != old->uid) {
62329 retval = set_user(new);
62330 if (retval < 0)
62331@@ -694,6 +717,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
62332 old = current_cred();
62333
62334 retval = -EPERM;
62335+
62336+ if (gr_check_crash_uid(uid))
62337+ goto error;
62338+ if (gr_check_user_change(uid, uid, uid))
62339+ goto error;
62340+
62341 if (nsown_capable(CAP_SETUID)) {
62342 new->suid = new->uid = uid;
62343 if (uid != old->uid) {
62344@@ -748,6 +777,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
62345 goto error;
62346 }
62347
62348+ if (gr_check_user_change(ruid, euid, -1))
62349+ goto error;
62350+
62351 if (ruid != (uid_t) -1) {
62352 new->uid = ruid;
62353 if (ruid != old->uid) {
62354@@ -812,6 +844,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
62355 goto error;
62356 }
62357
62358+ if (gr_check_group_change(rgid, egid, -1))
62359+ goto error;
62360+
62361 if (rgid != (gid_t) -1)
62362 new->gid = rgid;
62363 if (egid != (gid_t) -1)
62364@@ -858,6 +893,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
62365 old = current_cred();
62366 old_fsuid = old->fsuid;
62367
62368+ if (gr_check_user_change(-1, -1, uid))
62369+ goto error;
62370+
62371 if (uid == old->uid || uid == old->euid ||
62372 uid == old->suid || uid == old->fsuid ||
62373 nsown_capable(CAP_SETUID)) {
62374@@ -868,6 +906,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
62375 }
62376 }
62377
62378+error:
62379 abort_creds(new);
62380 return old_fsuid;
62381
62382@@ -894,12 +933,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
62383 if (gid == old->gid || gid == old->egid ||
62384 gid == old->sgid || gid == old->fsgid ||
62385 nsown_capable(CAP_SETGID)) {
62386+ if (gr_check_group_change(-1, -1, gid))
62387+ goto error;
62388+
62389 if (gid != old_fsgid) {
62390 new->fsgid = gid;
62391 goto change_okay;
62392 }
62393 }
62394
62395+error:
62396 abort_creds(new);
62397 return old_fsgid;
62398
62399@@ -1680,7 +1723,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
62400 error = get_dumpable(me->mm);
62401 break;
62402 case PR_SET_DUMPABLE:
62403- if (arg2 < 0 || arg2 > 1) {
62404+ if (arg2 > 1) {
62405 error = -EINVAL;
62406 break;
62407 }
62408diff -urNp linux-3.0.4/kernel/sysctl.c linux-3.0.4/kernel/sysctl.c
62409--- linux-3.0.4/kernel/sysctl.c 2011-07-21 22:17:23.000000000 -0400
62410+++ linux-3.0.4/kernel/sysctl.c 2011-08-23 21:48:14.000000000 -0400
62411@@ -85,6 +85,13 @@
62412
62413
62414 #if defined(CONFIG_SYSCTL)
62415+#include <linux/grsecurity.h>
62416+#include <linux/grinternal.h>
62417+
62418+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
62419+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62420+ const int op);
62421+extern int gr_handle_chroot_sysctl(const int op);
62422
62423 /* External variables not in a header file. */
62424 extern int sysctl_overcommit_memory;
62425@@ -197,6 +204,7 @@ static int sysrq_sysctl_handler(ctl_tabl
62426 }
62427
62428 #endif
62429+extern struct ctl_table grsecurity_table[];
62430
62431 static struct ctl_table root_table[];
62432 static struct ctl_table_root sysctl_table_root;
62433@@ -226,6 +234,20 @@ extern struct ctl_table epoll_table[];
62434 int sysctl_legacy_va_layout;
62435 #endif
62436
62437+#ifdef CONFIG_PAX_SOFTMODE
62438+static ctl_table pax_table[] = {
62439+ {
62440+ .procname = "softmode",
62441+ .data = &pax_softmode,
62442+ .maxlen = sizeof(unsigned int),
62443+ .mode = 0600,
62444+ .proc_handler = &proc_dointvec,
62445+ },
62446+
62447+ { }
62448+};
62449+#endif
62450+
62451 /* The default sysctl tables: */
62452
62453 static struct ctl_table root_table[] = {
62454@@ -272,6 +294,22 @@ static int max_extfrag_threshold = 1000;
62455 #endif
62456
62457 static struct ctl_table kern_table[] = {
62458+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62459+ {
62460+ .procname = "grsecurity",
62461+ .mode = 0500,
62462+ .child = grsecurity_table,
62463+ },
62464+#endif
62465+
62466+#ifdef CONFIG_PAX_SOFTMODE
62467+ {
62468+ .procname = "pax",
62469+ .mode = 0500,
62470+ .child = pax_table,
62471+ },
62472+#endif
62473+
62474 {
62475 .procname = "sched_child_runs_first",
62476 .data = &sysctl_sched_child_runs_first,
62477@@ -546,7 +584,7 @@ static struct ctl_table kern_table[] = {
62478 .data = &modprobe_path,
62479 .maxlen = KMOD_PATH_LEN,
62480 .mode = 0644,
62481- .proc_handler = proc_dostring,
62482+ .proc_handler = proc_dostring_modpriv,
62483 },
62484 {
62485 .procname = "modules_disabled",
62486@@ -713,16 +751,20 @@ static struct ctl_table kern_table[] = {
62487 .extra1 = &zero,
62488 .extra2 = &one,
62489 },
62490+#endif
62491 {
62492 .procname = "kptr_restrict",
62493 .data = &kptr_restrict,
62494 .maxlen = sizeof(int),
62495 .mode = 0644,
62496 .proc_handler = proc_dmesg_restrict,
62497+#ifdef CONFIG_GRKERNSEC_HIDESYM
62498+ .extra1 = &two,
62499+#else
62500 .extra1 = &zero,
62501+#endif
62502 .extra2 = &two,
62503 },
62504-#endif
62505 {
62506 .procname = "ngroups_max",
62507 .data = &ngroups_max,
62508@@ -1205,6 +1247,13 @@ static struct ctl_table vm_table[] = {
62509 .proc_handler = proc_dointvec_minmax,
62510 .extra1 = &zero,
62511 },
62512+ {
62513+ .procname = "heap_stack_gap",
62514+ .data = &sysctl_heap_stack_gap,
62515+ .maxlen = sizeof(sysctl_heap_stack_gap),
62516+ .mode = 0644,
62517+ .proc_handler = proc_doulongvec_minmax,
62518+ },
62519 #else
62520 {
62521 .procname = "nr_trim_pages",
62522@@ -1714,6 +1763,17 @@ static int test_perm(int mode, int op)
62523 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
62524 {
62525 int mode;
62526+ int error;
62527+
62528+ if (table->parent != NULL && table->parent->procname != NULL &&
62529+ table->procname != NULL &&
62530+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
62531+ return -EACCES;
62532+ if (gr_handle_chroot_sysctl(op))
62533+ return -EACCES;
62534+ error = gr_handle_sysctl(table, op);
62535+ if (error)
62536+ return error;
62537
62538 if (root->permissions)
62539 mode = root->permissions(root, current->nsproxy, table);
62540@@ -2118,6 +2178,16 @@ int proc_dostring(struct ctl_table *tabl
62541 buffer, lenp, ppos);
62542 }
62543
62544+int proc_dostring_modpriv(struct ctl_table *table, int write,
62545+ void __user *buffer, size_t *lenp, loff_t *ppos)
62546+{
62547+ if (write && !capable(CAP_SYS_MODULE))
62548+ return -EPERM;
62549+
62550+ return _proc_do_string(table->data, table->maxlen, write,
62551+ buffer, lenp, ppos);
62552+}
62553+
62554 static size_t proc_skip_spaces(char **buf)
62555 {
62556 size_t ret;
62557@@ -2223,6 +2293,8 @@ static int proc_put_long(void __user **b
62558 len = strlen(tmp);
62559 if (len > *size)
62560 len = *size;
62561+ if (len > sizeof(tmp))
62562+ len = sizeof(tmp);
62563 if (copy_to_user(*buf, tmp, len))
62564 return -EFAULT;
62565 *size -= len;
62566@@ -2539,8 +2611,11 @@ static int __do_proc_doulongvec_minmax(v
62567 *i = val;
62568 } else {
62569 val = convdiv * (*i) / convmul;
62570- if (!first)
62571+ if (!first) {
62572 err = proc_put_char(&buffer, &left, '\t');
62573+ if (err)
62574+ break;
62575+ }
62576 err = proc_put_long(&buffer, &left, val, false);
62577 if (err)
62578 break;
62579@@ -2935,6 +3010,12 @@ int proc_dostring(struct ctl_table *tabl
62580 return -ENOSYS;
62581 }
62582
62583+int proc_dostring_modpriv(struct ctl_table *table, int write,
62584+ void __user *buffer, size_t *lenp, loff_t *ppos)
62585+{
62586+ return -ENOSYS;
62587+}
62588+
62589 int proc_dointvec(struct ctl_table *table, int write,
62590 void __user *buffer, size_t *lenp, loff_t *ppos)
62591 {
62592@@ -2991,6 +3072,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
62593 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
62594 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
62595 EXPORT_SYMBOL(proc_dostring);
62596+EXPORT_SYMBOL(proc_dostring_modpriv);
62597 EXPORT_SYMBOL(proc_doulongvec_minmax);
62598 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
62599 EXPORT_SYMBOL(register_sysctl_table);
62600diff -urNp linux-3.0.4/kernel/sysctl_check.c linux-3.0.4/kernel/sysctl_check.c
62601--- linux-3.0.4/kernel/sysctl_check.c 2011-07-21 22:17:23.000000000 -0400
62602+++ linux-3.0.4/kernel/sysctl_check.c 2011-08-23 21:48:14.000000000 -0400
62603@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
62604 set_fail(&fail, table, "Directory with extra2");
62605 } else {
62606 if ((table->proc_handler == proc_dostring) ||
62607+ (table->proc_handler == proc_dostring_modpriv) ||
62608 (table->proc_handler == proc_dointvec) ||
62609 (table->proc_handler == proc_dointvec_minmax) ||
62610 (table->proc_handler == proc_dointvec_jiffies) ||
62611diff -urNp linux-3.0.4/kernel/taskstats.c linux-3.0.4/kernel/taskstats.c
62612--- linux-3.0.4/kernel/taskstats.c 2011-07-21 22:17:23.000000000 -0400
62613+++ linux-3.0.4/kernel/taskstats.c 2011-08-23 21:48:14.000000000 -0400
62614@@ -27,9 +27,12 @@
62615 #include <linux/cgroup.h>
62616 #include <linux/fs.h>
62617 #include <linux/file.h>
62618+#include <linux/grsecurity.h>
62619 #include <net/genetlink.h>
62620 #include <asm/atomic.h>
62621
62622+extern int gr_is_taskstats_denied(int pid);
62623+
62624 /*
62625 * Maximum length of a cpumask that can be specified in
62626 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
62627@@ -558,6 +561,9 @@ err:
62628
62629 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
62630 {
62631+ if (gr_is_taskstats_denied(current->pid))
62632+ return -EACCES;
62633+
62634 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
62635 return cmd_attr_register_cpumask(info);
62636 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
62637diff -urNp linux-3.0.4/kernel/time/alarmtimer.c linux-3.0.4/kernel/time/alarmtimer.c
62638--- linux-3.0.4/kernel/time/alarmtimer.c 2011-07-21 22:17:23.000000000 -0400
62639+++ linux-3.0.4/kernel/time/alarmtimer.c 2011-08-23 21:47:56.000000000 -0400
62640@@ -685,7 +685,7 @@ static int __init alarmtimer_init(void)
62641 {
62642 int error = 0;
62643 int i;
62644- struct k_clock alarm_clock = {
62645+ static struct k_clock alarm_clock = {
62646 .clock_getres = alarm_clock_getres,
62647 .clock_get = alarm_clock_get,
62648 .timer_create = alarm_timer_create,
62649diff -urNp linux-3.0.4/kernel/time/tick-broadcast.c linux-3.0.4/kernel/time/tick-broadcast.c
62650--- linux-3.0.4/kernel/time/tick-broadcast.c 2011-07-21 22:17:23.000000000 -0400
62651+++ linux-3.0.4/kernel/time/tick-broadcast.c 2011-08-23 21:47:56.000000000 -0400
62652@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
62653 * then clear the broadcast bit.
62654 */
62655 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
62656- int cpu = smp_processor_id();
62657+ cpu = smp_processor_id();
62658
62659 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
62660 tick_broadcast_clear_oneshot(cpu);
62661diff -urNp linux-3.0.4/kernel/time/timekeeping.c linux-3.0.4/kernel/time/timekeeping.c
62662--- linux-3.0.4/kernel/time/timekeeping.c 2011-07-21 22:17:23.000000000 -0400
62663+++ linux-3.0.4/kernel/time/timekeeping.c 2011-08-23 21:48:14.000000000 -0400
62664@@ -14,6 +14,7 @@
62665 #include <linux/init.h>
62666 #include <linux/mm.h>
62667 #include <linux/sched.h>
62668+#include <linux/grsecurity.h>
62669 #include <linux/syscore_ops.h>
62670 #include <linux/clocksource.h>
62671 #include <linux/jiffies.h>
62672@@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
62673 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
62674 return -EINVAL;
62675
62676+ gr_log_timechange();
62677+
62678 write_seqlock_irqsave(&xtime_lock, flags);
62679
62680 timekeeping_forward_now();
62681diff -urNp linux-3.0.4/kernel/time/timer_list.c linux-3.0.4/kernel/time/timer_list.c
62682--- linux-3.0.4/kernel/time/timer_list.c 2011-07-21 22:17:23.000000000 -0400
62683+++ linux-3.0.4/kernel/time/timer_list.c 2011-08-23 21:48:14.000000000 -0400
62684@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
62685
62686 static void print_name_offset(struct seq_file *m, void *sym)
62687 {
62688+#ifdef CONFIG_GRKERNSEC_HIDESYM
62689+ SEQ_printf(m, "<%p>", NULL);
62690+#else
62691 char symname[KSYM_NAME_LEN];
62692
62693 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
62694 SEQ_printf(m, "<%pK>", sym);
62695 else
62696 SEQ_printf(m, "%s", symname);
62697+#endif
62698 }
62699
62700 static void
62701@@ -112,7 +116,11 @@ next_one:
62702 static void
62703 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
62704 {
62705+#ifdef CONFIG_GRKERNSEC_HIDESYM
62706+ SEQ_printf(m, " .base: %p\n", NULL);
62707+#else
62708 SEQ_printf(m, " .base: %pK\n", base);
62709+#endif
62710 SEQ_printf(m, " .index: %d\n",
62711 base->index);
62712 SEQ_printf(m, " .resolution: %Lu nsecs\n",
62713@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
62714 {
62715 struct proc_dir_entry *pe;
62716
62717+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62718+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
62719+#else
62720 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
62721+#endif
62722 if (!pe)
62723 return -ENOMEM;
62724 return 0;
62725diff -urNp linux-3.0.4/kernel/time/timer_stats.c linux-3.0.4/kernel/time/timer_stats.c
62726--- linux-3.0.4/kernel/time/timer_stats.c 2011-07-21 22:17:23.000000000 -0400
62727+++ linux-3.0.4/kernel/time/timer_stats.c 2011-08-23 21:48:14.000000000 -0400
62728@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
62729 static unsigned long nr_entries;
62730 static struct entry entries[MAX_ENTRIES];
62731
62732-static atomic_t overflow_count;
62733+static atomic_unchecked_t overflow_count;
62734
62735 /*
62736 * The entries are in a hash-table, for fast lookup:
62737@@ -140,7 +140,7 @@ static void reset_entries(void)
62738 nr_entries = 0;
62739 memset(entries, 0, sizeof(entries));
62740 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
62741- atomic_set(&overflow_count, 0);
62742+ atomic_set_unchecked(&overflow_count, 0);
62743 }
62744
62745 static struct entry *alloc_entry(void)
62746@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
62747 if (likely(entry))
62748 entry->count++;
62749 else
62750- atomic_inc(&overflow_count);
62751+ atomic_inc_unchecked(&overflow_count);
62752
62753 out_unlock:
62754 raw_spin_unlock_irqrestore(lock, flags);
62755@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
62756
62757 static void print_name_offset(struct seq_file *m, unsigned long addr)
62758 {
62759+#ifdef CONFIG_GRKERNSEC_HIDESYM
62760+ seq_printf(m, "<%p>", NULL);
62761+#else
62762 char symname[KSYM_NAME_LEN];
62763
62764 if (lookup_symbol_name(addr, symname) < 0)
62765 seq_printf(m, "<%p>", (void *)addr);
62766 else
62767 seq_printf(m, "%s", symname);
62768+#endif
62769 }
62770
62771 static int tstats_show(struct seq_file *m, void *v)
62772@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
62773
62774 seq_puts(m, "Timer Stats Version: v0.2\n");
62775 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
62776- if (atomic_read(&overflow_count))
62777+ if (atomic_read_unchecked(&overflow_count))
62778 seq_printf(m, "Overflow: %d entries\n",
62779- atomic_read(&overflow_count));
62780+ atomic_read_unchecked(&overflow_count));
62781
62782 for (i = 0; i < nr_entries; i++) {
62783 entry = entries + i;
62784@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
62785 {
62786 struct proc_dir_entry *pe;
62787
62788+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62789+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
62790+#else
62791 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
62792+#endif
62793 if (!pe)
62794 return -ENOMEM;
62795 return 0;
62796diff -urNp linux-3.0.4/kernel/time.c linux-3.0.4/kernel/time.c
62797--- linux-3.0.4/kernel/time.c 2011-07-21 22:17:23.000000000 -0400
62798+++ linux-3.0.4/kernel/time.c 2011-08-23 21:48:14.000000000 -0400
62799@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
62800 return error;
62801
62802 if (tz) {
62803+ /* we log in do_settimeofday called below, so don't log twice
62804+ */
62805+ if (!tv)
62806+ gr_log_timechange();
62807+
62808 /* SMP safe, global irq locking makes it work. */
62809 sys_tz = *tz;
62810 update_vsyscall_tz();
62811diff -urNp linux-3.0.4/kernel/timer.c linux-3.0.4/kernel/timer.c
62812--- linux-3.0.4/kernel/timer.c 2011-07-21 22:17:23.000000000 -0400
62813+++ linux-3.0.4/kernel/timer.c 2011-08-23 21:47:56.000000000 -0400
62814@@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
62815 /*
62816 * This function runs timers and the timer-tq in bottom half context.
62817 */
62818-static void run_timer_softirq(struct softirq_action *h)
62819+static void run_timer_softirq(void)
62820 {
62821 struct tvec_base *base = __this_cpu_read(tvec_bases);
62822
62823diff -urNp linux-3.0.4/kernel/trace/blktrace.c linux-3.0.4/kernel/trace/blktrace.c
62824--- linux-3.0.4/kernel/trace/blktrace.c 2011-07-21 22:17:23.000000000 -0400
62825+++ linux-3.0.4/kernel/trace/blktrace.c 2011-08-23 21:47:56.000000000 -0400
62826@@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
62827 struct blk_trace *bt = filp->private_data;
62828 char buf[16];
62829
62830- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
62831+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
62832
62833 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
62834 }
62835@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
62836 return 1;
62837
62838 bt = buf->chan->private_data;
62839- atomic_inc(&bt->dropped);
62840+ atomic_inc_unchecked(&bt->dropped);
62841 return 0;
62842 }
62843
62844@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
62845
62846 bt->dir = dir;
62847 bt->dev = dev;
62848- atomic_set(&bt->dropped, 0);
62849+ atomic_set_unchecked(&bt->dropped, 0);
62850
62851 ret = -EIO;
62852 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
62853diff -urNp linux-3.0.4/kernel/trace/ftrace.c linux-3.0.4/kernel/trace/ftrace.c
62854--- linux-3.0.4/kernel/trace/ftrace.c 2011-07-21 22:17:23.000000000 -0400
62855+++ linux-3.0.4/kernel/trace/ftrace.c 2011-08-23 21:47:56.000000000 -0400
62856@@ -1566,12 +1566,17 @@ ftrace_code_disable(struct module *mod,
62857 if (unlikely(ftrace_disabled))
62858 return 0;
62859
62860+ ret = ftrace_arch_code_modify_prepare();
62861+ FTRACE_WARN_ON(ret);
62862+ if (ret)
62863+ return 0;
62864+
62865 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
62866+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
62867 if (ret) {
62868 ftrace_bug(ret, ip);
62869- return 0;
62870 }
62871- return 1;
62872+ return ret ? 0 : 1;
62873 }
62874
62875 /*
62876@@ -2550,7 +2555,7 @@ static void ftrace_free_entry_rcu(struct
62877
62878 int
62879 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62880- void *data)
62881+ void *data)
62882 {
62883 struct ftrace_func_probe *entry;
62884 struct ftrace_page *pg;
62885diff -urNp linux-3.0.4/kernel/trace/trace.c linux-3.0.4/kernel/trace/trace.c
62886--- linux-3.0.4/kernel/trace/trace.c 2011-07-21 22:17:23.000000000 -0400
62887+++ linux-3.0.4/kernel/trace/trace.c 2011-08-23 21:48:14.000000000 -0400
62888@@ -3339,6 +3339,8 @@ static ssize_t tracing_splice_read_pipe(
62889 size_t rem;
62890 unsigned int i;
62891
62892+ pax_track_stack();
62893+
62894 if (splice_grow_spd(pipe, &spd))
62895 return -ENOMEM;
62896
62897@@ -3822,6 +3824,8 @@ tracing_buffers_splice_read(struct file
62898 int entries, size, i;
62899 size_t ret;
62900
62901+ pax_track_stack();
62902+
62903 if (splice_grow_spd(pipe, &spd))
62904 return -ENOMEM;
62905
62906@@ -3990,10 +3994,9 @@ static const struct file_operations trac
62907 };
62908 #endif
62909
62910-static struct dentry *d_tracer;
62911-
62912 struct dentry *tracing_init_dentry(void)
62913 {
62914+ static struct dentry *d_tracer;
62915 static int once;
62916
62917 if (d_tracer)
62918@@ -4013,10 +4016,9 @@ struct dentry *tracing_init_dentry(void)
62919 return d_tracer;
62920 }
62921
62922-static struct dentry *d_percpu;
62923-
62924 struct dentry *tracing_dentry_percpu(void)
62925 {
62926+ static struct dentry *d_percpu;
62927 static int once;
62928 struct dentry *d_tracer;
62929
62930diff -urNp linux-3.0.4/kernel/trace/trace_events.c linux-3.0.4/kernel/trace/trace_events.c
62931--- linux-3.0.4/kernel/trace/trace_events.c 2011-09-02 18:11:21.000000000 -0400
62932+++ linux-3.0.4/kernel/trace/trace_events.c 2011-08-23 21:47:56.000000000 -0400
62933@@ -1318,10 +1318,6 @@ static LIST_HEAD(ftrace_module_file_list
62934 struct ftrace_module_file_ops {
62935 struct list_head list;
62936 struct module *mod;
62937- struct file_operations id;
62938- struct file_operations enable;
62939- struct file_operations format;
62940- struct file_operations filter;
62941 };
62942
62943 static struct ftrace_module_file_ops *
62944@@ -1342,17 +1338,12 @@ trace_create_file_ops(struct module *mod
62945
62946 file_ops->mod = mod;
62947
62948- file_ops->id = ftrace_event_id_fops;
62949- file_ops->id.owner = mod;
62950-
62951- file_ops->enable = ftrace_enable_fops;
62952- file_ops->enable.owner = mod;
62953-
62954- file_ops->filter = ftrace_event_filter_fops;
62955- file_ops->filter.owner = mod;
62956-
62957- file_ops->format = ftrace_event_format_fops;
62958- file_ops->format.owner = mod;
62959+ pax_open_kernel();
62960+ *(void **)&mod->trace_id.owner = mod;
62961+ *(void **)&mod->trace_enable.owner = mod;
62962+ *(void **)&mod->trace_filter.owner = mod;
62963+ *(void **)&mod->trace_format.owner = mod;
62964+ pax_close_kernel();
62965
62966 list_add(&file_ops->list, &ftrace_module_file_list);
62967
62968@@ -1376,8 +1367,8 @@ static void trace_module_add_events(stru
62969
62970 for_each_event(call, start, end) {
62971 __trace_add_event_call(*call, mod,
62972- &file_ops->id, &file_ops->enable,
62973- &file_ops->filter, &file_ops->format);
62974+ &mod->trace_id, &mod->trace_enable,
62975+ &mod->trace_filter, &mod->trace_format);
62976 }
62977 }
62978
62979diff -urNp linux-3.0.4/kernel/trace/trace_mmiotrace.c linux-3.0.4/kernel/trace/trace_mmiotrace.c
62980--- linux-3.0.4/kernel/trace/trace_mmiotrace.c 2011-07-21 22:17:23.000000000 -0400
62981+++ linux-3.0.4/kernel/trace/trace_mmiotrace.c 2011-08-23 21:47:56.000000000 -0400
62982@@ -24,7 +24,7 @@ struct header_iter {
62983 static struct trace_array *mmio_trace_array;
62984 static bool overrun_detected;
62985 static unsigned long prev_overruns;
62986-static atomic_t dropped_count;
62987+static atomic_unchecked_t dropped_count;
62988
62989 static void mmio_reset_data(struct trace_array *tr)
62990 {
62991@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
62992
62993 static unsigned long count_overruns(struct trace_iterator *iter)
62994 {
62995- unsigned long cnt = atomic_xchg(&dropped_count, 0);
62996+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
62997 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
62998
62999 if (over > prev_overruns)
63000@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
63001 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
63002 sizeof(*entry), 0, pc);
63003 if (!event) {
63004- atomic_inc(&dropped_count);
63005+ atomic_inc_unchecked(&dropped_count);
63006 return;
63007 }
63008 entry = ring_buffer_event_data(event);
63009@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
63010 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
63011 sizeof(*entry), 0, pc);
63012 if (!event) {
63013- atomic_inc(&dropped_count);
63014+ atomic_inc_unchecked(&dropped_count);
63015 return;
63016 }
63017 entry = ring_buffer_event_data(event);
63018diff -urNp linux-3.0.4/kernel/trace/trace_output.c linux-3.0.4/kernel/trace/trace_output.c
63019--- linux-3.0.4/kernel/trace/trace_output.c 2011-07-21 22:17:23.000000000 -0400
63020+++ linux-3.0.4/kernel/trace/trace_output.c 2011-08-23 21:47:56.000000000 -0400
63021@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
63022
63023 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
63024 if (!IS_ERR(p)) {
63025- p = mangle_path(s->buffer + s->len, p, "\n");
63026+ p = mangle_path(s->buffer + s->len, p, "\n\\");
63027 if (p) {
63028 s->len = p - s->buffer;
63029 return 1;
63030diff -urNp linux-3.0.4/kernel/trace/trace_stack.c linux-3.0.4/kernel/trace/trace_stack.c
63031--- linux-3.0.4/kernel/trace/trace_stack.c 2011-07-21 22:17:23.000000000 -0400
63032+++ linux-3.0.4/kernel/trace/trace_stack.c 2011-08-23 21:47:56.000000000 -0400
63033@@ -50,7 +50,7 @@ static inline void check_stack(void)
63034 return;
63035
63036 /* we do not handle interrupt stacks yet */
63037- if (!object_is_on_stack(&this_size))
63038+ if (!object_starts_on_stack(&this_size))
63039 return;
63040
63041 local_irq_save(flags);
63042diff -urNp linux-3.0.4/kernel/trace/trace_workqueue.c linux-3.0.4/kernel/trace/trace_workqueue.c
63043--- linux-3.0.4/kernel/trace/trace_workqueue.c 2011-07-21 22:17:23.000000000 -0400
63044+++ linux-3.0.4/kernel/trace/trace_workqueue.c 2011-08-23 21:47:56.000000000 -0400
63045@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
63046 int cpu;
63047 pid_t pid;
63048 /* Can be inserted from interrupt or user context, need to be atomic */
63049- atomic_t inserted;
63050+ atomic_unchecked_t inserted;
63051 /*
63052 * Don't need to be atomic, works are serialized in a single workqueue thread
63053 * on a single CPU.
63054@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
63055 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
63056 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
63057 if (node->pid == wq_thread->pid) {
63058- atomic_inc(&node->inserted);
63059+ atomic_inc_unchecked(&node->inserted);
63060 goto found;
63061 }
63062 }
63063@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
63064 tsk = get_pid_task(pid, PIDTYPE_PID);
63065 if (tsk) {
63066 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
63067- atomic_read(&cws->inserted), cws->executed,
63068+ atomic_read_unchecked(&cws->inserted), cws->executed,
63069 tsk->comm);
63070 put_task_struct(tsk);
63071 }
63072diff -urNp linux-3.0.4/lib/bug.c linux-3.0.4/lib/bug.c
63073--- linux-3.0.4/lib/bug.c 2011-07-21 22:17:23.000000000 -0400
63074+++ linux-3.0.4/lib/bug.c 2011-08-23 21:47:56.000000000 -0400
63075@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
63076 return BUG_TRAP_TYPE_NONE;
63077
63078 bug = find_bug(bugaddr);
63079+ if (!bug)
63080+ return BUG_TRAP_TYPE_NONE;
63081
63082 file = NULL;
63083 line = 0;
63084diff -urNp linux-3.0.4/lib/debugobjects.c linux-3.0.4/lib/debugobjects.c
63085--- linux-3.0.4/lib/debugobjects.c 2011-07-21 22:17:23.000000000 -0400
63086+++ linux-3.0.4/lib/debugobjects.c 2011-08-23 21:47:56.000000000 -0400
63087@@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
63088 if (limit > 4)
63089 return;
63090
63091- is_on_stack = object_is_on_stack(addr);
63092+ is_on_stack = object_starts_on_stack(addr);
63093 if (is_on_stack == onstack)
63094 return;
63095
63096diff -urNp linux-3.0.4/lib/dma-debug.c linux-3.0.4/lib/dma-debug.c
63097--- linux-3.0.4/lib/dma-debug.c 2011-07-21 22:17:23.000000000 -0400
63098+++ linux-3.0.4/lib/dma-debug.c 2011-08-23 21:47:56.000000000 -0400
63099@@ -870,7 +870,7 @@ out:
63100
63101 static void check_for_stack(struct device *dev, void *addr)
63102 {
63103- if (object_is_on_stack(addr))
63104+ if (object_starts_on_stack(addr))
63105 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
63106 "stack [addr=%p]\n", addr);
63107 }
63108diff -urNp linux-3.0.4/lib/extable.c linux-3.0.4/lib/extable.c
63109--- linux-3.0.4/lib/extable.c 2011-07-21 22:17:23.000000000 -0400
63110+++ linux-3.0.4/lib/extable.c 2011-08-23 21:47:56.000000000 -0400
63111@@ -13,6 +13,7 @@
63112 #include <linux/init.h>
63113 #include <linux/sort.h>
63114 #include <asm/uaccess.h>
63115+#include <asm/pgtable.h>
63116
63117 #ifndef ARCH_HAS_SORT_EXTABLE
63118 /*
63119@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const v
63120 void sort_extable(struct exception_table_entry *start,
63121 struct exception_table_entry *finish)
63122 {
63123+ pax_open_kernel();
63124 sort(start, finish - start, sizeof(struct exception_table_entry),
63125 cmp_ex, NULL);
63126+ pax_close_kernel();
63127 }
63128
63129 #ifdef CONFIG_MODULES
63130diff -urNp linux-3.0.4/lib/inflate.c linux-3.0.4/lib/inflate.c
63131--- linux-3.0.4/lib/inflate.c 2011-07-21 22:17:23.000000000 -0400
63132+++ linux-3.0.4/lib/inflate.c 2011-08-23 21:47:56.000000000 -0400
63133@@ -269,7 +269,7 @@ static void free(void *where)
63134 malloc_ptr = free_mem_ptr;
63135 }
63136 #else
63137-#define malloc(a) kmalloc(a, GFP_KERNEL)
63138+#define malloc(a) kmalloc((a), GFP_KERNEL)
63139 #define free(a) kfree(a)
63140 #endif
63141
63142diff -urNp linux-3.0.4/lib/Kconfig.debug linux-3.0.4/lib/Kconfig.debug
63143--- linux-3.0.4/lib/Kconfig.debug 2011-07-21 22:17:23.000000000 -0400
63144+++ linux-3.0.4/lib/Kconfig.debug 2011-08-23 21:48:14.000000000 -0400
63145@@ -1088,6 +1088,7 @@ config LATENCYTOP
63146 depends on DEBUG_KERNEL
63147 depends on STACKTRACE_SUPPORT
63148 depends on PROC_FS
63149+ depends on !GRKERNSEC_HIDESYM
63150 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
63151 select KALLSYMS
63152 select KALLSYMS_ALL
63153diff -urNp linux-3.0.4/lib/kref.c linux-3.0.4/lib/kref.c
63154--- linux-3.0.4/lib/kref.c 2011-07-21 22:17:23.000000000 -0400
63155+++ linux-3.0.4/lib/kref.c 2011-08-23 21:47:56.000000000 -0400
63156@@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
63157 */
63158 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
63159 {
63160- WARN_ON(release == NULL);
63161+ BUG_ON(release == NULL);
63162 WARN_ON(release == (void (*)(struct kref *))kfree);
63163
63164 if (atomic_dec_and_test(&kref->refcount)) {
63165diff -urNp linux-3.0.4/lib/radix-tree.c linux-3.0.4/lib/radix-tree.c
63166--- linux-3.0.4/lib/radix-tree.c 2011-07-21 22:17:23.000000000 -0400
63167+++ linux-3.0.4/lib/radix-tree.c 2011-08-23 21:47:56.000000000 -0400
63168@@ -80,7 +80,7 @@ struct radix_tree_preload {
63169 int nr;
63170 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
63171 };
63172-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
63173+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
63174
63175 static inline void *ptr_to_indirect(void *ptr)
63176 {
63177diff -urNp linux-3.0.4/lib/vsprintf.c linux-3.0.4/lib/vsprintf.c
63178--- linux-3.0.4/lib/vsprintf.c 2011-07-21 22:17:23.000000000 -0400
63179+++ linux-3.0.4/lib/vsprintf.c 2011-08-23 21:48:14.000000000 -0400
63180@@ -16,6 +16,9 @@
63181 * - scnprintf and vscnprintf
63182 */
63183
63184+#ifdef CONFIG_GRKERNSEC_HIDESYM
63185+#define __INCLUDED_BY_HIDESYM 1
63186+#endif
63187 #include <stdarg.h>
63188 #include <linux/module.h>
63189 #include <linux/types.h>
63190@@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
63191 char sym[KSYM_SYMBOL_LEN];
63192 if (ext == 'B')
63193 sprint_backtrace(sym, value);
63194- else if (ext != 'f' && ext != 's')
63195+ else if (ext != 'f' && ext != 's' && ext != 'a')
63196 sprint_symbol(sym, value);
63197 else
63198 kallsyms_lookup(value, NULL, NULL, NULL, sym);
63199@@ -799,7 +802,11 @@ char *uuid_string(char *buf, char *end,
63200 return string(buf, end, uuid, spec);
63201 }
63202
63203+#ifdef CONFIG_GRKERNSEC_HIDESYM
63204+int kptr_restrict __read_mostly = 2;
63205+#else
63206 int kptr_restrict __read_mostly;
63207+#endif
63208
63209 /*
63210 * Show a '%p' thing. A kernel extension is that the '%p' is followed
63211@@ -813,6 +820,8 @@ int kptr_restrict __read_mostly;
63212 * - 'S' For symbolic direct pointers with offset
63213 * - 's' For symbolic direct pointers without offset
63214 * - 'B' For backtraced symbolic direct pointers with offset
63215+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
63216+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
63217 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
63218 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
63219 * - 'M' For a 6-byte MAC address, it prints the address in the
63220@@ -857,12 +866,12 @@ char *pointer(const char *fmt, char *buf
63221 {
63222 if (!ptr && *fmt != 'K') {
63223 /*
63224- * Print (null) with the same width as a pointer so it makes
63225+ * Print (nil) with the same width as a pointer so it makes
63226 * tabular output look nice.
63227 */
63228 if (spec.field_width == -1)
63229 spec.field_width = 2 * sizeof(void *);
63230- return string(buf, end, "(null)", spec);
63231+ return string(buf, end, "(nil)", spec);
63232 }
63233
63234 switch (*fmt) {
63235@@ -872,6 +881,13 @@ char *pointer(const char *fmt, char *buf
63236 /* Fallthrough */
63237 case 'S':
63238 case 's':
63239+#ifdef CONFIG_GRKERNSEC_HIDESYM
63240+ break;
63241+#else
63242+ return symbol_string(buf, end, ptr, spec, *fmt);
63243+#endif
63244+ case 'A':
63245+ case 'a':
63246 case 'B':
63247 return symbol_string(buf, end, ptr, spec, *fmt);
63248 case 'R':
63249@@ -1631,11 +1647,11 @@ int bstr_printf(char *buf, size_t size,
63250 typeof(type) value; \
63251 if (sizeof(type) == 8) { \
63252 args = PTR_ALIGN(args, sizeof(u32)); \
63253- *(u32 *)&value = *(u32 *)args; \
63254- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
63255+ *(u32 *)&value = *(const u32 *)args; \
63256+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
63257 } else { \
63258 args = PTR_ALIGN(args, sizeof(type)); \
63259- value = *(typeof(type) *)args; \
63260+ value = *(const typeof(type) *)args; \
63261 } \
63262 args += sizeof(type); \
63263 value; \
63264@@ -1698,7 +1714,7 @@ int bstr_printf(char *buf, size_t size,
63265 case FORMAT_TYPE_STR: {
63266 const char *str_arg = args;
63267 args += strlen(str_arg) + 1;
63268- str = string(str, end, (char *)str_arg, spec);
63269+ str = string(str, end, str_arg, spec);
63270 break;
63271 }
63272
63273diff -urNp linux-3.0.4/localversion-grsec linux-3.0.4/localversion-grsec
63274--- linux-3.0.4/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
63275+++ linux-3.0.4/localversion-grsec 2011-08-23 21:48:14.000000000 -0400
63276@@ -0,0 +1 @@
63277+-grsec
63278diff -urNp linux-3.0.4/Makefile linux-3.0.4/Makefile
63279--- linux-3.0.4/Makefile 2011-09-02 18:11:26.000000000 -0400
63280+++ linux-3.0.4/Makefile 2011-09-14 11:16:43.000000000 -0400
63281@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
63282
63283 HOSTCC = gcc
63284 HOSTCXX = g++
63285-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
63286-HOSTCXXFLAGS = -O2
63287+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
63288+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
63289+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
63290
63291 # Decide whether to build built-in, modular, or both.
63292 # Normally, just do built-in.
63293@@ -365,10 +366,12 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
63294 KBUILD_CPPFLAGS := -D__KERNEL__
63295
63296 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
63297+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
63298 -fno-strict-aliasing -fno-common \
63299 -Werror-implicit-function-declaration \
63300 -Wno-format-security \
63301 -fno-delete-null-pointer-checks
63302+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
63303 KBUILD_AFLAGS_KERNEL :=
63304 KBUILD_CFLAGS_KERNEL :=
63305 KBUILD_AFLAGS := -D__ASSEMBLY__
63306@@ -407,8 +410,8 @@ export RCS_TAR_IGNORE := --exclude SCCS
63307 # Rules shared between *config targets and build targets
63308
63309 # Basic helpers built in scripts/
63310-PHONY += scripts_basic
63311-scripts_basic:
63312+PHONY += scripts_basic gcc-plugins
63313+scripts_basic: gcc-plugins
63314 $(Q)$(MAKE) $(build)=scripts/basic
63315 $(Q)rm -f .tmp_quiet_recordmcount
63316
63317@@ -564,6 +567,28 @@ else
63318 KBUILD_CFLAGS += -O2
63319 endif
63320
63321+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh $(HOSTCC) $(CC)), y)
63322+CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
63323+ifdef CONFIG_KALLOCSTAT_PLUGIN
63324+KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
63325+endif
63326+ifdef CONFIG_PAX_MEMORY_STACKLEAK
63327+STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -fplugin-arg-stackleak_plugin-track-lowest-sp=100
63328+endif
63329+GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN)
63330+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN
63331+gcc-plugins:
63332+ $(Q)$(MAKE) $(build)=tools/gcc
63333+else
63334+gcc-plugins:
63335+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
63336+ $(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.))
63337+else
63338+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
63339+endif
63340+ $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
63341+endif
63342+
63343 include $(srctree)/arch/$(SRCARCH)/Makefile
63344
63345 ifneq ($(CONFIG_FRAME_WARN),0)
63346@@ -708,7 +733,7 @@ export mod_strip_cmd
63347
63348
63349 ifeq ($(KBUILD_EXTMOD),)
63350-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
63351+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
63352
63353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
63354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
63355@@ -907,6 +932,8 @@ define rule_vmlinux-modpost
63356 endef
63357
63358 # vmlinux image - including updated kernel symbols
63359+$(vmlinux-all): KBUILD_CFLAGS += $(GCC_PLUGINS)
63360+$(vmlinux-all): gcc-plugins
63361 vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE
63362 ifdef CONFIG_HEADERS_CHECK
63363 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
63364@@ -941,7 +968,8 @@ $(sort $(vmlinux-init) $(vmlinux-main))
63365 # Error messages still appears in the original language
63366
63367 PHONY += $(vmlinux-dirs)
63368-$(vmlinux-dirs): prepare scripts
63369+$(vmlinux-dirs): KBUILD_CFLAGS += $(GCC_PLUGINS)
63370+$(vmlinux-dirs): gcc-plugins prepare scripts
63371 $(Q)$(MAKE) $(build)=$@
63372
63373 # Store (new) KERNELRELASE string in include/config/kernel.release
63374@@ -986,6 +1014,7 @@ prepare0: archprepare FORCE
63375 $(Q)$(MAKE) $(build)=. missing-syscalls
63376
63377 # All the preparing..
63378+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
63379 prepare: prepare0
63380
63381 # Generate some files
63382@@ -1102,7 +1131,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modu
63383
63384 # Target to prepare building external modules
63385 PHONY += modules_prepare
63386-modules_prepare: prepare scripts
63387+modules_prepare: gcc-plugins prepare scripts
63388
63389 # Target to install modules
63390 PHONY += modules_install
63391@@ -1198,7 +1227,7 @@ distclean: mrproper
63392 @find $(srctree) $(RCS_FIND_IGNORE) \
63393 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
63394 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
63395- -o -name '.*.rej' -o -size 0 \
63396+ -o -name '.*.rej' -o -name '*.so' -o -size 0 \
63397 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
63398 -type f -print | xargs rm -f
63399
63400@@ -1359,6 +1388,7 @@ PHONY += $(module-dirs) modules
63401 $(module-dirs): crmodverdir $(objtree)/Module.symvers
63402 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
63403
63404+modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
63405 modules: $(module-dirs)
63406 @$(kecho) ' Building modules, stage 2.';
63407 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
63408@@ -1485,17 +1515,19 @@ else
63409 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
63410 endif
63411
63412-%.s: %.c prepare scripts FORCE
63413+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
63414+%.s: %.c gcc-plugins prepare scripts FORCE
63415 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63416 %.i: %.c prepare scripts FORCE
63417 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63418-%.o: %.c prepare scripts FORCE
63419+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
63420+%.o: %.c gcc-plugins prepare scripts FORCE
63421 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63422 %.lst: %.c prepare scripts FORCE
63423 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63424-%.s: %.S prepare scripts FORCE
63425+%.s: %.S gcc-plugins prepare scripts FORCE
63426 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63427-%.o: %.S prepare scripts FORCE
63428+%.o: %.S gcc-plugins prepare scripts FORCE
63429 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63430 %.symtypes: %.c prepare scripts FORCE
63431 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
63432@@ -1505,11 +1537,13 @@ endif
63433 $(cmd_crmodverdir)
63434 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
63435 $(build)=$(build-dir)
63436-%/: prepare scripts FORCE
63437+%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
63438+%/: gcc-plugins prepare scripts FORCE
63439 $(cmd_crmodverdir)
63440 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
63441 $(build)=$(build-dir)
63442-%.ko: prepare scripts FORCE
63443+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
63444+%.ko: gcc-plugins prepare scripts FORCE
63445 $(cmd_crmodverdir)
63446 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
63447 $(build)=$(build-dir) $(@:.ko=.o)
63448diff -urNp linux-3.0.4/mm/filemap.c linux-3.0.4/mm/filemap.c
63449--- linux-3.0.4/mm/filemap.c 2011-07-21 22:17:23.000000000 -0400
63450+++ linux-3.0.4/mm/filemap.c 2011-08-23 21:48:14.000000000 -0400
63451@@ -1763,7 +1763,7 @@ int generic_file_mmap(struct file * file
63452 struct address_space *mapping = file->f_mapping;
63453
63454 if (!mapping->a_ops->readpage)
63455- return -ENOEXEC;
63456+ return -ENODEV;
63457 file_accessed(file);
63458 vma->vm_ops = &generic_file_vm_ops;
63459 vma->vm_flags |= VM_CAN_NONLINEAR;
63460@@ -2169,6 +2169,7 @@ inline int generic_write_checks(struct f
63461 *pos = i_size_read(inode);
63462
63463 if (limit != RLIM_INFINITY) {
63464+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
63465 if (*pos >= limit) {
63466 send_sig(SIGXFSZ, current, 0);
63467 return -EFBIG;
63468diff -urNp linux-3.0.4/mm/fremap.c linux-3.0.4/mm/fremap.c
63469--- linux-3.0.4/mm/fremap.c 2011-07-21 22:17:23.000000000 -0400
63470+++ linux-3.0.4/mm/fremap.c 2011-08-23 21:47:56.000000000 -0400
63471@@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
63472 retry:
63473 vma = find_vma(mm, start);
63474
63475+#ifdef CONFIG_PAX_SEGMEXEC
63476+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
63477+ goto out;
63478+#endif
63479+
63480 /*
63481 * Make sure the vma is shared, that it supports prefaulting,
63482 * and that the remapped range is valid and fully within
63483diff -urNp linux-3.0.4/mm/highmem.c linux-3.0.4/mm/highmem.c
63484--- linux-3.0.4/mm/highmem.c 2011-07-21 22:17:23.000000000 -0400
63485+++ linux-3.0.4/mm/highmem.c 2011-08-23 21:47:56.000000000 -0400
63486@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
63487 * So no dangers, even with speculative execution.
63488 */
63489 page = pte_page(pkmap_page_table[i]);
63490+ pax_open_kernel();
63491 pte_clear(&init_mm, (unsigned long)page_address(page),
63492 &pkmap_page_table[i]);
63493-
63494+ pax_close_kernel();
63495 set_page_address(page, NULL);
63496 need_flush = 1;
63497 }
63498@@ -186,9 +187,11 @@ start:
63499 }
63500 }
63501 vaddr = PKMAP_ADDR(last_pkmap_nr);
63502+
63503+ pax_open_kernel();
63504 set_pte_at(&init_mm, vaddr,
63505 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
63506-
63507+ pax_close_kernel();
63508 pkmap_count[last_pkmap_nr] = 1;
63509 set_page_address(page, (void *)vaddr);
63510
63511diff -urNp linux-3.0.4/mm/huge_memory.c linux-3.0.4/mm/huge_memory.c
63512--- linux-3.0.4/mm/huge_memory.c 2011-07-21 22:17:23.000000000 -0400
63513+++ linux-3.0.4/mm/huge_memory.c 2011-08-23 21:47:56.000000000 -0400
63514@@ -702,7 +702,7 @@ out:
63515 * run pte_offset_map on the pmd, if an huge pmd could
63516 * materialize from under us from a different thread.
63517 */
63518- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
63519+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
63520 return VM_FAULT_OOM;
63521 /* if an huge pmd materialized from under us just retry later */
63522 if (unlikely(pmd_trans_huge(*pmd)))
63523diff -urNp linux-3.0.4/mm/hugetlb.c linux-3.0.4/mm/hugetlb.c
63524--- linux-3.0.4/mm/hugetlb.c 2011-07-21 22:17:23.000000000 -0400
63525+++ linux-3.0.4/mm/hugetlb.c 2011-08-23 21:47:56.000000000 -0400
63526@@ -2339,6 +2339,27 @@ static int unmap_ref_private(struct mm_s
63527 return 1;
63528 }
63529
63530+#ifdef CONFIG_PAX_SEGMEXEC
63531+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
63532+{
63533+ struct mm_struct *mm = vma->vm_mm;
63534+ struct vm_area_struct *vma_m;
63535+ unsigned long address_m;
63536+ pte_t *ptep_m;
63537+
63538+ vma_m = pax_find_mirror_vma(vma);
63539+ if (!vma_m)
63540+ return;
63541+
63542+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63543+ address_m = address + SEGMEXEC_TASK_SIZE;
63544+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
63545+ get_page(page_m);
63546+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
63547+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
63548+}
63549+#endif
63550+
63551 /*
63552 * Hugetlb_cow() should be called with page lock of the original hugepage held.
63553 */
63554@@ -2440,6 +2461,11 @@ retry_avoidcopy:
63555 make_huge_pte(vma, new_page, 1));
63556 page_remove_rmap(old_page);
63557 hugepage_add_new_anon_rmap(new_page, vma, address);
63558+
63559+#ifdef CONFIG_PAX_SEGMEXEC
63560+ pax_mirror_huge_pte(vma, address, new_page);
63561+#endif
63562+
63563 /* Make the old page be freed below */
63564 new_page = old_page;
63565 mmu_notifier_invalidate_range_end(mm,
63566@@ -2591,6 +2617,10 @@ retry:
63567 && (vma->vm_flags & VM_SHARED)));
63568 set_huge_pte_at(mm, address, ptep, new_pte);
63569
63570+#ifdef CONFIG_PAX_SEGMEXEC
63571+ pax_mirror_huge_pte(vma, address, page);
63572+#endif
63573+
63574 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
63575 /* Optimization, do the COW without a second fault */
63576 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
63577@@ -2620,6 +2650,10 @@ int hugetlb_fault(struct mm_struct *mm,
63578 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
63579 struct hstate *h = hstate_vma(vma);
63580
63581+#ifdef CONFIG_PAX_SEGMEXEC
63582+ struct vm_area_struct *vma_m;
63583+#endif
63584+
63585 ptep = huge_pte_offset(mm, address);
63586 if (ptep) {
63587 entry = huge_ptep_get(ptep);
63588@@ -2631,6 +2665,26 @@ int hugetlb_fault(struct mm_struct *mm,
63589 VM_FAULT_SET_HINDEX(h - hstates);
63590 }
63591
63592+#ifdef CONFIG_PAX_SEGMEXEC
63593+ vma_m = pax_find_mirror_vma(vma);
63594+ if (vma_m) {
63595+ unsigned long address_m;
63596+
63597+ if (vma->vm_start > vma_m->vm_start) {
63598+ address_m = address;
63599+ address -= SEGMEXEC_TASK_SIZE;
63600+ vma = vma_m;
63601+ h = hstate_vma(vma);
63602+ } else
63603+ address_m = address + SEGMEXEC_TASK_SIZE;
63604+
63605+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
63606+ return VM_FAULT_OOM;
63607+ address_m &= HPAGE_MASK;
63608+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
63609+ }
63610+#endif
63611+
63612 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
63613 if (!ptep)
63614 return VM_FAULT_OOM;
63615diff -urNp linux-3.0.4/mm/internal.h linux-3.0.4/mm/internal.h
63616--- linux-3.0.4/mm/internal.h 2011-07-21 22:17:23.000000000 -0400
63617+++ linux-3.0.4/mm/internal.h 2011-08-23 21:47:56.000000000 -0400
63618@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page
63619 * in mm/page_alloc.c
63620 */
63621 extern void __free_pages_bootmem(struct page *page, unsigned int order);
63622+extern void free_compound_page(struct page *page);
63623 extern void prep_compound_page(struct page *page, unsigned long order);
63624 #ifdef CONFIG_MEMORY_FAILURE
63625 extern bool is_free_buddy_page(struct page *page);
63626diff -urNp linux-3.0.4/mm/Kconfig linux-3.0.4/mm/Kconfig
63627--- linux-3.0.4/mm/Kconfig 2011-07-21 22:17:23.000000000 -0400
63628+++ linux-3.0.4/mm/Kconfig 2011-08-23 21:48:14.000000000 -0400
63629@@ -240,7 +240,7 @@ config KSM
63630 config DEFAULT_MMAP_MIN_ADDR
63631 int "Low address space to protect from user allocation"
63632 depends on MMU
63633- default 4096
63634+ default 65536
63635 help
63636 This is the portion of low virtual memory which should be protected
63637 from userspace allocation. Keeping a user from writing to low pages
63638diff -urNp linux-3.0.4/mm/kmemleak.c linux-3.0.4/mm/kmemleak.c
63639--- linux-3.0.4/mm/kmemleak.c 2011-07-21 22:17:23.000000000 -0400
63640+++ linux-3.0.4/mm/kmemleak.c 2011-08-23 21:48:14.000000000 -0400
63641@@ -357,7 +357,7 @@ static void print_unreferenced(struct se
63642
63643 for (i = 0; i < object->trace_len; i++) {
63644 void *ptr = (void *)object->trace[i];
63645- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
63646+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
63647 }
63648 }
63649
63650diff -urNp linux-3.0.4/mm/madvise.c linux-3.0.4/mm/madvise.c
63651--- linux-3.0.4/mm/madvise.c 2011-07-21 22:17:23.000000000 -0400
63652+++ linux-3.0.4/mm/madvise.c 2011-08-23 21:47:56.000000000 -0400
63653@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
63654 pgoff_t pgoff;
63655 unsigned long new_flags = vma->vm_flags;
63656
63657+#ifdef CONFIG_PAX_SEGMEXEC
63658+ struct vm_area_struct *vma_m;
63659+#endif
63660+
63661 switch (behavior) {
63662 case MADV_NORMAL:
63663 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
63664@@ -110,6 +114,13 @@ success:
63665 /*
63666 * vm_flags is protected by the mmap_sem held in write mode.
63667 */
63668+
63669+#ifdef CONFIG_PAX_SEGMEXEC
63670+ vma_m = pax_find_mirror_vma(vma);
63671+ if (vma_m)
63672+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
63673+#endif
63674+
63675 vma->vm_flags = new_flags;
63676
63677 out:
63678@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
63679 struct vm_area_struct ** prev,
63680 unsigned long start, unsigned long end)
63681 {
63682+
63683+#ifdef CONFIG_PAX_SEGMEXEC
63684+ struct vm_area_struct *vma_m;
63685+#endif
63686+
63687 *prev = vma;
63688 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
63689 return -EINVAL;
63690@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
63691 zap_page_range(vma, start, end - start, &details);
63692 } else
63693 zap_page_range(vma, start, end - start, NULL);
63694+
63695+#ifdef CONFIG_PAX_SEGMEXEC
63696+ vma_m = pax_find_mirror_vma(vma);
63697+ if (vma_m) {
63698+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
63699+ struct zap_details details = {
63700+ .nonlinear_vma = vma_m,
63701+ .last_index = ULONG_MAX,
63702+ };
63703+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
63704+ } else
63705+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
63706+ }
63707+#endif
63708+
63709 return 0;
63710 }
63711
63712@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
63713 if (end < start)
63714 goto out;
63715
63716+#ifdef CONFIG_PAX_SEGMEXEC
63717+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
63718+ if (end > SEGMEXEC_TASK_SIZE)
63719+ goto out;
63720+ } else
63721+#endif
63722+
63723+ if (end > TASK_SIZE)
63724+ goto out;
63725+
63726 error = 0;
63727 if (end == start)
63728 goto out;
63729diff -urNp linux-3.0.4/mm/memory.c linux-3.0.4/mm/memory.c
63730--- linux-3.0.4/mm/memory.c 2011-09-02 18:11:21.000000000 -0400
63731+++ linux-3.0.4/mm/memory.c 2011-08-23 21:47:56.000000000 -0400
63732@@ -457,8 +457,12 @@ static inline void free_pmd_range(struct
63733 return;
63734
63735 pmd = pmd_offset(pud, start);
63736+
63737+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
63738 pud_clear(pud);
63739 pmd_free_tlb(tlb, pmd, start);
63740+#endif
63741+
63742 }
63743
63744 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
63745@@ -489,9 +493,12 @@ static inline void free_pud_range(struct
63746 if (end - 1 > ceiling - 1)
63747 return;
63748
63749+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
63750 pud = pud_offset(pgd, start);
63751 pgd_clear(pgd);
63752 pud_free_tlb(tlb, pud, start);
63753+#endif
63754+
63755 }
63756
63757 /*
63758@@ -1577,12 +1584,6 @@ no_page_table:
63759 return page;
63760 }
63761
63762-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
63763-{
63764- return stack_guard_page_start(vma, addr) ||
63765- stack_guard_page_end(vma, addr+PAGE_SIZE);
63766-}
63767-
63768 /**
63769 * __get_user_pages() - pin user pages in memory
63770 * @tsk: task_struct of target task
63771@@ -1655,10 +1656,10 @@ int __get_user_pages(struct task_struct
63772 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
63773 i = 0;
63774
63775- do {
63776+ while (nr_pages) {
63777 struct vm_area_struct *vma;
63778
63779- vma = find_extend_vma(mm, start);
63780+ vma = find_vma(mm, start);
63781 if (!vma && in_gate_area(mm, start)) {
63782 unsigned long pg = start & PAGE_MASK;
63783 pgd_t *pgd;
63784@@ -1706,7 +1707,7 @@ int __get_user_pages(struct task_struct
63785 goto next_page;
63786 }
63787
63788- if (!vma ||
63789+ if (!vma || start < vma->vm_start ||
63790 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
63791 !(vm_flags & vma->vm_flags))
63792 return i ? : -EFAULT;
63793@@ -1733,11 +1734,6 @@ int __get_user_pages(struct task_struct
63794 int ret;
63795 unsigned int fault_flags = 0;
63796
63797- /* For mlock, just skip the stack guard page. */
63798- if (foll_flags & FOLL_MLOCK) {
63799- if (stack_guard_page(vma, start))
63800- goto next_page;
63801- }
63802 if (foll_flags & FOLL_WRITE)
63803 fault_flags |= FAULT_FLAG_WRITE;
63804 if (nonblocking)
63805@@ -1811,7 +1807,7 @@ next_page:
63806 start += PAGE_SIZE;
63807 nr_pages--;
63808 } while (nr_pages && start < vma->vm_end);
63809- } while (nr_pages);
63810+ }
63811 return i;
63812 }
63813 EXPORT_SYMBOL(__get_user_pages);
63814@@ -2018,6 +2014,10 @@ static int insert_page(struct vm_area_st
63815 page_add_file_rmap(page);
63816 set_pte_at(mm, addr, pte, mk_pte(page, prot));
63817
63818+#ifdef CONFIG_PAX_SEGMEXEC
63819+ pax_mirror_file_pte(vma, addr, page, ptl);
63820+#endif
63821+
63822 retval = 0;
63823 pte_unmap_unlock(pte, ptl);
63824 return retval;
63825@@ -2052,10 +2052,22 @@ out:
63826 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
63827 struct page *page)
63828 {
63829+
63830+#ifdef CONFIG_PAX_SEGMEXEC
63831+ struct vm_area_struct *vma_m;
63832+#endif
63833+
63834 if (addr < vma->vm_start || addr >= vma->vm_end)
63835 return -EFAULT;
63836 if (!page_count(page))
63837 return -EINVAL;
63838+
63839+#ifdef CONFIG_PAX_SEGMEXEC
63840+ vma_m = pax_find_mirror_vma(vma);
63841+ if (vma_m)
63842+ vma_m->vm_flags |= VM_INSERTPAGE;
63843+#endif
63844+
63845 vma->vm_flags |= VM_INSERTPAGE;
63846 return insert_page(vma, addr, page, vma->vm_page_prot);
63847 }
63848@@ -2141,6 +2153,7 @@ int vm_insert_mixed(struct vm_area_struc
63849 unsigned long pfn)
63850 {
63851 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
63852+ BUG_ON(vma->vm_mirror);
63853
63854 if (addr < vma->vm_start || addr >= vma->vm_end)
63855 return -EFAULT;
63856@@ -2456,6 +2469,186 @@ static inline void cow_user_page(struct
63857 copy_user_highpage(dst, src, va, vma);
63858 }
63859
63860+#ifdef CONFIG_PAX_SEGMEXEC
63861+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
63862+{
63863+ struct mm_struct *mm = vma->vm_mm;
63864+ spinlock_t *ptl;
63865+ pte_t *pte, entry;
63866+
63867+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
63868+ entry = *pte;
63869+ if (!pte_present(entry)) {
63870+ if (!pte_none(entry)) {
63871+ BUG_ON(pte_file(entry));
63872+ free_swap_and_cache(pte_to_swp_entry(entry));
63873+ pte_clear_not_present_full(mm, address, pte, 0);
63874+ }
63875+ } else {
63876+ struct page *page;
63877+
63878+ flush_cache_page(vma, address, pte_pfn(entry));
63879+ entry = ptep_clear_flush(vma, address, pte);
63880+ BUG_ON(pte_dirty(entry));
63881+ page = vm_normal_page(vma, address, entry);
63882+ if (page) {
63883+ update_hiwater_rss(mm);
63884+ if (PageAnon(page))
63885+ dec_mm_counter_fast(mm, MM_ANONPAGES);
63886+ else
63887+ dec_mm_counter_fast(mm, MM_FILEPAGES);
63888+ page_remove_rmap(page);
63889+ page_cache_release(page);
63890+ }
63891+ }
63892+ pte_unmap_unlock(pte, ptl);
63893+}
63894+
63895+/* PaX: if vma is mirrored, synchronize the mirror's PTE
63896+ *
63897+ * the ptl of the lower mapped page is held on entry and is not released on exit
63898+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
63899+ */
63900+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
63901+{
63902+ struct mm_struct *mm = vma->vm_mm;
63903+ unsigned long address_m;
63904+ spinlock_t *ptl_m;
63905+ struct vm_area_struct *vma_m;
63906+ pmd_t *pmd_m;
63907+ pte_t *pte_m, entry_m;
63908+
63909+ BUG_ON(!page_m || !PageAnon(page_m));
63910+
63911+ vma_m = pax_find_mirror_vma(vma);
63912+ if (!vma_m)
63913+ return;
63914+
63915+ BUG_ON(!PageLocked(page_m));
63916+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63917+ address_m = address + SEGMEXEC_TASK_SIZE;
63918+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63919+ pte_m = pte_offset_map(pmd_m, address_m);
63920+ ptl_m = pte_lockptr(mm, pmd_m);
63921+ if (ptl != ptl_m) {
63922+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63923+ if (!pte_none(*pte_m))
63924+ goto out;
63925+ }
63926+
63927+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
63928+ page_cache_get(page_m);
63929+ page_add_anon_rmap(page_m, vma_m, address_m);
63930+ inc_mm_counter_fast(mm, MM_ANONPAGES);
63931+ set_pte_at(mm, address_m, pte_m, entry_m);
63932+ update_mmu_cache(vma_m, address_m, entry_m);
63933+out:
63934+ if (ptl != ptl_m)
63935+ spin_unlock(ptl_m);
63936+ pte_unmap(pte_m);
63937+ unlock_page(page_m);
63938+}
63939+
63940+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
63941+{
63942+ struct mm_struct *mm = vma->vm_mm;
63943+ unsigned long address_m;
63944+ spinlock_t *ptl_m;
63945+ struct vm_area_struct *vma_m;
63946+ pmd_t *pmd_m;
63947+ pte_t *pte_m, entry_m;
63948+
63949+ BUG_ON(!page_m || PageAnon(page_m));
63950+
63951+ vma_m = pax_find_mirror_vma(vma);
63952+ if (!vma_m)
63953+ return;
63954+
63955+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63956+ address_m = address + SEGMEXEC_TASK_SIZE;
63957+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63958+ pte_m = pte_offset_map(pmd_m, address_m);
63959+ ptl_m = pte_lockptr(mm, pmd_m);
63960+ if (ptl != ptl_m) {
63961+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63962+ if (!pte_none(*pte_m))
63963+ goto out;
63964+ }
63965+
63966+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
63967+ page_cache_get(page_m);
63968+ page_add_file_rmap(page_m);
63969+ inc_mm_counter_fast(mm, MM_FILEPAGES);
63970+ set_pte_at(mm, address_m, pte_m, entry_m);
63971+ update_mmu_cache(vma_m, address_m, entry_m);
63972+out:
63973+ if (ptl != ptl_m)
63974+ spin_unlock(ptl_m);
63975+ pte_unmap(pte_m);
63976+}
63977+
63978+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
63979+{
63980+ struct mm_struct *mm = vma->vm_mm;
63981+ unsigned long address_m;
63982+ spinlock_t *ptl_m;
63983+ struct vm_area_struct *vma_m;
63984+ pmd_t *pmd_m;
63985+ pte_t *pte_m, entry_m;
63986+
63987+ vma_m = pax_find_mirror_vma(vma);
63988+ if (!vma_m)
63989+ return;
63990+
63991+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63992+ address_m = address + SEGMEXEC_TASK_SIZE;
63993+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63994+ pte_m = pte_offset_map(pmd_m, address_m);
63995+ ptl_m = pte_lockptr(mm, pmd_m);
63996+ if (ptl != ptl_m) {
63997+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63998+ if (!pte_none(*pte_m))
63999+ goto out;
64000+ }
64001+
64002+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
64003+ set_pte_at(mm, address_m, pte_m, entry_m);
64004+out:
64005+ if (ptl != ptl_m)
64006+ spin_unlock(ptl_m);
64007+ pte_unmap(pte_m);
64008+}
64009+
64010+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
64011+{
64012+ struct page *page_m;
64013+ pte_t entry;
64014+
64015+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
64016+ goto out;
64017+
64018+ entry = *pte;
64019+ page_m = vm_normal_page(vma, address, entry);
64020+ if (!page_m)
64021+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
64022+ else if (PageAnon(page_m)) {
64023+ if (pax_find_mirror_vma(vma)) {
64024+ pte_unmap_unlock(pte, ptl);
64025+ lock_page(page_m);
64026+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
64027+ if (pte_same(entry, *pte))
64028+ pax_mirror_anon_pte(vma, address, page_m, ptl);
64029+ else
64030+ unlock_page(page_m);
64031+ }
64032+ } else
64033+ pax_mirror_file_pte(vma, address, page_m, ptl);
64034+
64035+out:
64036+ pte_unmap_unlock(pte, ptl);
64037+}
64038+#endif
64039+
64040 /*
64041 * This routine handles present pages, when users try to write
64042 * to a shared page. It is done by copying the page to a new address
64043@@ -2667,6 +2860,12 @@ gotten:
64044 */
64045 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
64046 if (likely(pte_same(*page_table, orig_pte))) {
64047+
64048+#ifdef CONFIG_PAX_SEGMEXEC
64049+ if (pax_find_mirror_vma(vma))
64050+ BUG_ON(!trylock_page(new_page));
64051+#endif
64052+
64053 if (old_page) {
64054 if (!PageAnon(old_page)) {
64055 dec_mm_counter_fast(mm, MM_FILEPAGES);
64056@@ -2718,6 +2917,10 @@ gotten:
64057 page_remove_rmap(old_page);
64058 }
64059
64060+#ifdef CONFIG_PAX_SEGMEXEC
64061+ pax_mirror_anon_pte(vma, address, new_page, ptl);
64062+#endif
64063+
64064 /* Free the old page.. */
64065 new_page = old_page;
64066 ret |= VM_FAULT_WRITE;
64067@@ -2997,6 +3200,11 @@ static int do_swap_page(struct mm_struct
64068 swap_free(entry);
64069 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
64070 try_to_free_swap(page);
64071+
64072+#ifdef CONFIG_PAX_SEGMEXEC
64073+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
64074+#endif
64075+
64076 unlock_page(page);
64077 if (swapcache) {
64078 /*
64079@@ -3020,6 +3228,11 @@ static int do_swap_page(struct mm_struct
64080
64081 /* No need to invalidate - it was non-present before */
64082 update_mmu_cache(vma, address, page_table);
64083+
64084+#ifdef CONFIG_PAX_SEGMEXEC
64085+ pax_mirror_anon_pte(vma, address, page, ptl);
64086+#endif
64087+
64088 unlock:
64089 pte_unmap_unlock(page_table, ptl);
64090 out:
64091@@ -3039,40 +3252,6 @@ out_release:
64092 }
64093
64094 /*
64095- * This is like a special single-page "expand_{down|up}wards()",
64096- * except we must first make sure that 'address{-|+}PAGE_SIZE'
64097- * doesn't hit another vma.
64098- */
64099-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
64100-{
64101- address &= PAGE_MASK;
64102- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
64103- struct vm_area_struct *prev = vma->vm_prev;
64104-
64105- /*
64106- * Is there a mapping abutting this one below?
64107- *
64108- * That's only ok if it's the same stack mapping
64109- * that has gotten split..
64110- */
64111- if (prev && prev->vm_end == address)
64112- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
64113-
64114- expand_downwards(vma, address - PAGE_SIZE);
64115- }
64116- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
64117- struct vm_area_struct *next = vma->vm_next;
64118-
64119- /* As VM_GROWSDOWN but s/below/above/ */
64120- if (next && next->vm_start == address + PAGE_SIZE)
64121- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
64122-
64123- expand_upwards(vma, address + PAGE_SIZE);
64124- }
64125- return 0;
64126-}
64127-
64128-/*
64129 * We enter with non-exclusive mmap_sem (to exclude vma changes,
64130 * but allow concurrent faults), and pte mapped but not yet locked.
64131 * We return with mmap_sem still held, but pte unmapped and unlocked.
64132@@ -3081,27 +3260,23 @@ static int do_anonymous_page(struct mm_s
64133 unsigned long address, pte_t *page_table, pmd_t *pmd,
64134 unsigned int flags)
64135 {
64136- struct page *page;
64137+ struct page *page = NULL;
64138 spinlock_t *ptl;
64139 pte_t entry;
64140
64141- pte_unmap(page_table);
64142-
64143- /* Check if we need to add a guard page to the stack */
64144- if (check_stack_guard_page(vma, address) < 0)
64145- return VM_FAULT_SIGBUS;
64146-
64147- /* Use the zero-page for reads */
64148 if (!(flags & FAULT_FLAG_WRITE)) {
64149 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
64150 vma->vm_page_prot));
64151- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
64152+ ptl = pte_lockptr(mm, pmd);
64153+ spin_lock(ptl);
64154 if (!pte_none(*page_table))
64155 goto unlock;
64156 goto setpte;
64157 }
64158
64159 /* Allocate our own private page. */
64160+ pte_unmap(page_table);
64161+
64162 if (unlikely(anon_vma_prepare(vma)))
64163 goto oom;
64164 page = alloc_zeroed_user_highpage_movable(vma, address);
64165@@ -3120,6 +3295,11 @@ static int do_anonymous_page(struct mm_s
64166 if (!pte_none(*page_table))
64167 goto release;
64168
64169+#ifdef CONFIG_PAX_SEGMEXEC
64170+ if (pax_find_mirror_vma(vma))
64171+ BUG_ON(!trylock_page(page));
64172+#endif
64173+
64174 inc_mm_counter_fast(mm, MM_ANONPAGES);
64175 page_add_new_anon_rmap(page, vma, address);
64176 setpte:
64177@@ -3127,6 +3307,12 @@ setpte:
64178
64179 /* No need to invalidate - it was non-present before */
64180 update_mmu_cache(vma, address, page_table);
64181+
64182+#ifdef CONFIG_PAX_SEGMEXEC
64183+ if (page)
64184+ pax_mirror_anon_pte(vma, address, page, ptl);
64185+#endif
64186+
64187 unlock:
64188 pte_unmap_unlock(page_table, ptl);
64189 return 0;
64190@@ -3264,6 +3450,12 @@ static int __do_fault(struct mm_struct *
64191 */
64192 /* Only go through if we didn't race with anybody else... */
64193 if (likely(pte_same(*page_table, orig_pte))) {
64194+
64195+#ifdef CONFIG_PAX_SEGMEXEC
64196+ if (anon && pax_find_mirror_vma(vma))
64197+ BUG_ON(!trylock_page(page));
64198+#endif
64199+
64200 flush_icache_page(vma, page);
64201 entry = mk_pte(page, vma->vm_page_prot);
64202 if (flags & FAULT_FLAG_WRITE)
64203@@ -3283,6 +3475,14 @@ static int __do_fault(struct mm_struct *
64204
64205 /* no need to invalidate: a not-present page won't be cached */
64206 update_mmu_cache(vma, address, page_table);
64207+
64208+#ifdef CONFIG_PAX_SEGMEXEC
64209+ if (anon)
64210+ pax_mirror_anon_pte(vma, address, page, ptl);
64211+ else
64212+ pax_mirror_file_pte(vma, address, page, ptl);
64213+#endif
64214+
64215 } else {
64216 if (charged)
64217 mem_cgroup_uncharge_page(page);
64218@@ -3430,6 +3630,12 @@ int handle_pte_fault(struct mm_struct *m
64219 if (flags & FAULT_FLAG_WRITE)
64220 flush_tlb_fix_spurious_fault(vma, address);
64221 }
64222+
64223+#ifdef CONFIG_PAX_SEGMEXEC
64224+ pax_mirror_pte(vma, address, pte, pmd, ptl);
64225+ return 0;
64226+#endif
64227+
64228 unlock:
64229 pte_unmap_unlock(pte, ptl);
64230 return 0;
64231@@ -3446,6 +3652,10 @@ int handle_mm_fault(struct mm_struct *mm
64232 pmd_t *pmd;
64233 pte_t *pte;
64234
64235+#ifdef CONFIG_PAX_SEGMEXEC
64236+ struct vm_area_struct *vma_m;
64237+#endif
64238+
64239 __set_current_state(TASK_RUNNING);
64240
64241 count_vm_event(PGFAULT);
64242@@ -3457,6 +3667,34 @@ int handle_mm_fault(struct mm_struct *mm
64243 if (unlikely(is_vm_hugetlb_page(vma)))
64244 return hugetlb_fault(mm, vma, address, flags);
64245
64246+#ifdef CONFIG_PAX_SEGMEXEC
64247+ vma_m = pax_find_mirror_vma(vma);
64248+ if (vma_m) {
64249+ unsigned long address_m;
64250+ pgd_t *pgd_m;
64251+ pud_t *pud_m;
64252+ pmd_t *pmd_m;
64253+
64254+ if (vma->vm_start > vma_m->vm_start) {
64255+ address_m = address;
64256+ address -= SEGMEXEC_TASK_SIZE;
64257+ vma = vma_m;
64258+ } else
64259+ address_m = address + SEGMEXEC_TASK_SIZE;
64260+
64261+ pgd_m = pgd_offset(mm, address_m);
64262+ pud_m = pud_alloc(mm, pgd_m, address_m);
64263+ if (!pud_m)
64264+ return VM_FAULT_OOM;
64265+ pmd_m = pmd_alloc(mm, pud_m, address_m);
64266+ if (!pmd_m)
64267+ return VM_FAULT_OOM;
64268+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
64269+ return VM_FAULT_OOM;
64270+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
64271+ }
64272+#endif
64273+
64274 pgd = pgd_offset(mm, address);
64275 pud = pud_alloc(mm, pgd, address);
64276 if (!pud)
64277@@ -3486,7 +3724,7 @@ int handle_mm_fault(struct mm_struct *mm
64278 * run pte_offset_map on the pmd, if an huge pmd could
64279 * materialize from under us from a different thread.
64280 */
64281- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
64282+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
64283 return VM_FAULT_OOM;
64284 /* if an huge pmd materialized from under us just retry later */
64285 if (unlikely(pmd_trans_huge(*pmd)))
64286@@ -3590,7 +3828,7 @@ static int __init gate_vma_init(void)
64287 gate_vma.vm_start = FIXADDR_USER_START;
64288 gate_vma.vm_end = FIXADDR_USER_END;
64289 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
64290- gate_vma.vm_page_prot = __P101;
64291+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
64292 /*
64293 * Make sure the vDSO gets into every core dump.
64294 * Dumping its contents makes post-mortem fully interpretable later
64295diff -urNp linux-3.0.4/mm/memory-failure.c linux-3.0.4/mm/memory-failure.c
64296--- linux-3.0.4/mm/memory-failure.c 2011-07-21 22:17:23.000000000 -0400
64297+++ linux-3.0.4/mm/memory-failure.c 2011-08-23 21:47:56.000000000 -0400
64298@@ -59,7 +59,7 @@ int sysctl_memory_failure_early_kill __r
64299
64300 int sysctl_memory_failure_recovery __read_mostly = 1;
64301
64302-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
64303+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
64304
64305 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
64306
64307@@ -1008,7 +1008,7 @@ int __memory_failure(unsigned long pfn,
64308 }
64309
64310 nr_pages = 1 << compound_trans_order(hpage);
64311- atomic_long_add(nr_pages, &mce_bad_pages);
64312+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
64313
64314 /*
64315 * We need/can do nothing about count=0 pages.
64316@@ -1038,7 +1038,7 @@ int __memory_failure(unsigned long pfn,
64317 if (!PageHWPoison(hpage)
64318 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
64319 || (p != hpage && TestSetPageHWPoison(hpage))) {
64320- atomic_long_sub(nr_pages, &mce_bad_pages);
64321+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64322 return 0;
64323 }
64324 set_page_hwpoison_huge_page(hpage);
64325@@ -1096,7 +1096,7 @@ int __memory_failure(unsigned long pfn,
64326 }
64327 if (hwpoison_filter(p)) {
64328 if (TestClearPageHWPoison(p))
64329- atomic_long_sub(nr_pages, &mce_bad_pages);
64330+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64331 unlock_page(hpage);
64332 put_page(hpage);
64333 return 0;
64334@@ -1222,7 +1222,7 @@ int unpoison_memory(unsigned long pfn)
64335 return 0;
64336 }
64337 if (TestClearPageHWPoison(p))
64338- atomic_long_sub(nr_pages, &mce_bad_pages);
64339+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64340 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
64341 return 0;
64342 }
64343@@ -1236,7 +1236,7 @@ int unpoison_memory(unsigned long pfn)
64344 */
64345 if (TestClearPageHWPoison(page)) {
64346 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
64347- atomic_long_sub(nr_pages, &mce_bad_pages);
64348+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
64349 freeit = 1;
64350 if (PageHuge(page))
64351 clear_page_hwpoison_huge_page(page);
64352@@ -1349,7 +1349,7 @@ static int soft_offline_huge_page(struct
64353 }
64354 done:
64355 if (!PageHWPoison(hpage))
64356- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
64357+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
64358 set_page_hwpoison_huge_page(hpage);
64359 dequeue_hwpoisoned_huge_page(hpage);
64360 /* keep elevated page count for bad page */
64361@@ -1480,7 +1480,7 @@ int soft_offline_page(struct page *page,
64362 return ret;
64363
64364 done:
64365- atomic_long_add(1, &mce_bad_pages);
64366+ atomic_long_add_unchecked(1, &mce_bad_pages);
64367 SetPageHWPoison(page);
64368 /* keep elevated page count for bad page */
64369 return ret;
64370diff -urNp linux-3.0.4/mm/mempolicy.c linux-3.0.4/mm/mempolicy.c
64371--- linux-3.0.4/mm/mempolicy.c 2011-07-21 22:17:23.000000000 -0400
64372+++ linux-3.0.4/mm/mempolicy.c 2011-08-23 21:48:14.000000000 -0400
64373@@ -639,6 +639,10 @@ static int mbind_range(struct mm_struct
64374 unsigned long vmstart;
64375 unsigned long vmend;
64376
64377+#ifdef CONFIG_PAX_SEGMEXEC
64378+ struct vm_area_struct *vma_m;
64379+#endif
64380+
64381 vma = find_vma_prev(mm, start, &prev);
64382 if (!vma || vma->vm_start > start)
64383 return -EFAULT;
64384@@ -669,6 +673,16 @@ static int mbind_range(struct mm_struct
64385 err = policy_vma(vma, new_pol);
64386 if (err)
64387 goto out;
64388+
64389+#ifdef CONFIG_PAX_SEGMEXEC
64390+ vma_m = pax_find_mirror_vma(vma);
64391+ if (vma_m) {
64392+ err = policy_vma(vma_m, new_pol);
64393+ if (err)
64394+ goto out;
64395+ }
64396+#endif
64397+
64398 }
64399
64400 out:
64401@@ -1102,6 +1116,17 @@ static long do_mbind(unsigned long start
64402
64403 if (end < start)
64404 return -EINVAL;
64405+
64406+#ifdef CONFIG_PAX_SEGMEXEC
64407+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
64408+ if (end > SEGMEXEC_TASK_SIZE)
64409+ return -EINVAL;
64410+ } else
64411+#endif
64412+
64413+ if (end > TASK_SIZE)
64414+ return -EINVAL;
64415+
64416 if (end == start)
64417 return 0;
64418
64419@@ -1320,6 +1345,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
64420 if (!mm)
64421 goto out;
64422
64423+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64424+ if (mm != current->mm &&
64425+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
64426+ err = -EPERM;
64427+ goto out;
64428+ }
64429+#endif
64430+
64431 /*
64432 * Check if this process has the right to modify the specified
64433 * process. The right exists if the process has administrative
64434@@ -1329,8 +1362,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
64435 rcu_read_lock();
64436 tcred = __task_cred(task);
64437 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
64438- cred->uid != tcred->suid && cred->uid != tcred->uid &&
64439- !capable(CAP_SYS_NICE)) {
64440+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
64441 rcu_read_unlock();
64442 err = -EPERM;
64443 goto out;
64444diff -urNp linux-3.0.4/mm/migrate.c linux-3.0.4/mm/migrate.c
64445--- linux-3.0.4/mm/migrate.c 2011-07-21 22:17:23.000000000 -0400
64446+++ linux-3.0.4/mm/migrate.c 2011-08-23 21:48:14.000000000 -0400
64447@@ -1124,6 +1124,8 @@ static int do_pages_move(struct mm_struc
64448 unsigned long chunk_start;
64449 int err;
64450
64451+ pax_track_stack();
64452+
64453 task_nodes = cpuset_mems_allowed(task);
64454
64455 err = -ENOMEM;
64456@@ -1308,6 +1310,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
64457 if (!mm)
64458 return -EINVAL;
64459
64460+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64461+ if (mm != current->mm &&
64462+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
64463+ err = -EPERM;
64464+ goto out;
64465+ }
64466+#endif
64467+
64468 /*
64469 * Check if this process has the right to modify the specified
64470 * process. The right exists if the process has administrative
64471@@ -1317,8 +1327,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
64472 rcu_read_lock();
64473 tcred = __task_cred(task);
64474 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
64475- cred->uid != tcred->suid && cred->uid != tcred->uid &&
64476- !capable(CAP_SYS_NICE)) {
64477+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
64478 rcu_read_unlock();
64479 err = -EPERM;
64480 goto out;
64481diff -urNp linux-3.0.4/mm/mlock.c linux-3.0.4/mm/mlock.c
64482--- linux-3.0.4/mm/mlock.c 2011-07-21 22:17:23.000000000 -0400
64483+++ linux-3.0.4/mm/mlock.c 2011-08-23 21:48:14.000000000 -0400
64484@@ -13,6 +13,7 @@
64485 #include <linux/pagemap.h>
64486 #include <linux/mempolicy.h>
64487 #include <linux/syscalls.h>
64488+#include <linux/security.h>
64489 #include <linux/sched.h>
64490 #include <linux/module.h>
64491 #include <linux/rmap.h>
64492@@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
64493 return -EINVAL;
64494 if (end == start)
64495 return 0;
64496+ if (end > TASK_SIZE)
64497+ return -EINVAL;
64498+
64499 vma = find_vma_prev(current->mm, start, &prev);
64500 if (!vma || vma->vm_start > start)
64501 return -ENOMEM;
64502@@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
64503 for (nstart = start ; ; ) {
64504 vm_flags_t newflags;
64505
64506+#ifdef CONFIG_PAX_SEGMEXEC
64507+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
64508+ break;
64509+#endif
64510+
64511 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
64512
64513 newflags = vma->vm_flags | VM_LOCKED;
64514@@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
64515 lock_limit >>= PAGE_SHIFT;
64516
64517 /* check against resource limits */
64518+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
64519 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
64520 error = do_mlock(start, len, 1);
64521 up_write(&current->mm->mmap_sem);
64522@@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
64523 static int do_mlockall(int flags)
64524 {
64525 struct vm_area_struct * vma, * prev = NULL;
64526- unsigned int def_flags = 0;
64527
64528 if (flags & MCL_FUTURE)
64529- def_flags = VM_LOCKED;
64530- current->mm->def_flags = def_flags;
64531+ current->mm->def_flags |= VM_LOCKED;
64532+ else
64533+ current->mm->def_flags &= ~VM_LOCKED;
64534 if (flags == MCL_FUTURE)
64535 goto out;
64536
64537 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
64538 vm_flags_t newflags;
64539
64540+#ifdef CONFIG_PAX_SEGMEXEC
64541+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
64542+ break;
64543+#endif
64544+
64545+ BUG_ON(vma->vm_end > TASK_SIZE);
64546 newflags = vma->vm_flags | VM_LOCKED;
64547 if (!(flags & MCL_CURRENT))
64548 newflags &= ~VM_LOCKED;
64549@@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
64550 lock_limit >>= PAGE_SHIFT;
64551
64552 ret = -ENOMEM;
64553+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
64554 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
64555 capable(CAP_IPC_LOCK))
64556 ret = do_mlockall(flags);
64557diff -urNp linux-3.0.4/mm/mmap.c linux-3.0.4/mm/mmap.c
64558--- linux-3.0.4/mm/mmap.c 2011-07-21 22:17:23.000000000 -0400
64559+++ linux-3.0.4/mm/mmap.c 2011-08-23 21:48:14.000000000 -0400
64560@@ -46,6 +46,16 @@
64561 #define arch_rebalance_pgtables(addr, len) (addr)
64562 #endif
64563
64564+static inline void verify_mm_writelocked(struct mm_struct *mm)
64565+{
64566+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
64567+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
64568+ up_read(&mm->mmap_sem);
64569+ BUG();
64570+ }
64571+#endif
64572+}
64573+
64574 static void unmap_region(struct mm_struct *mm,
64575 struct vm_area_struct *vma, struct vm_area_struct *prev,
64576 unsigned long start, unsigned long end);
64577@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
64578 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
64579 *
64580 */
64581-pgprot_t protection_map[16] = {
64582+pgprot_t protection_map[16] __read_only = {
64583 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
64584 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
64585 };
64586
64587-pgprot_t vm_get_page_prot(unsigned long vm_flags)
64588+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64589 {
64590- return __pgprot(pgprot_val(protection_map[vm_flags &
64591+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
64592 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
64593 pgprot_val(arch_vm_get_page_prot(vm_flags)));
64594+
64595+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64596+ if (!(__supported_pte_mask & _PAGE_NX) &&
64597+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
64598+ (vm_flags & (VM_READ | VM_WRITE)))
64599+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
64600+#endif
64601+
64602+ return prot;
64603 }
64604 EXPORT_SYMBOL(vm_get_page_prot);
64605
64606 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
64607 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
64608 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
64609+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
64610 /*
64611 * Make sure vm_committed_as in one cacheline and not cacheline shared with
64612 * other variables. It can be updated by several CPUs frequently.
64613@@ -236,6 +256,7 @@ static struct vm_area_struct *remove_vma
64614 struct vm_area_struct *next = vma->vm_next;
64615
64616 might_sleep();
64617+ BUG_ON(vma->vm_mirror);
64618 if (vma->vm_ops && vma->vm_ops->close)
64619 vma->vm_ops->close(vma);
64620 if (vma->vm_file) {
64621@@ -280,6 +301,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
64622 * not page aligned -Ram Gupta
64623 */
64624 rlim = rlimit(RLIMIT_DATA);
64625+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
64626 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
64627 (mm->end_data - mm->start_data) > rlim)
64628 goto out;
64629@@ -697,6 +719,12 @@ static int
64630 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
64631 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
64632 {
64633+
64634+#ifdef CONFIG_PAX_SEGMEXEC
64635+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
64636+ return 0;
64637+#endif
64638+
64639 if (is_mergeable_vma(vma, file, vm_flags) &&
64640 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
64641 if (vma->vm_pgoff == vm_pgoff)
64642@@ -716,6 +744,12 @@ static int
64643 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
64644 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
64645 {
64646+
64647+#ifdef CONFIG_PAX_SEGMEXEC
64648+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
64649+ return 0;
64650+#endif
64651+
64652 if (is_mergeable_vma(vma, file, vm_flags) &&
64653 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
64654 pgoff_t vm_pglen;
64655@@ -758,13 +792,20 @@ can_vma_merge_after(struct vm_area_struc
64656 struct vm_area_struct *vma_merge(struct mm_struct *mm,
64657 struct vm_area_struct *prev, unsigned long addr,
64658 unsigned long end, unsigned long vm_flags,
64659- struct anon_vma *anon_vma, struct file *file,
64660+ struct anon_vma *anon_vma, struct file *file,
64661 pgoff_t pgoff, struct mempolicy *policy)
64662 {
64663 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
64664 struct vm_area_struct *area, *next;
64665 int err;
64666
64667+#ifdef CONFIG_PAX_SEGMEXEC
64668+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
64669+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
64670+
64671+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
64672+#endif
64673+
64674 /*
64675 * We later require that vma->vm_flags == vm_flags,
64676 * so this tests vma->vm_flags & VM_SPECIAL, too.
64677@@ -780,6 +821,15 @@ struct vm_area_struct *vma_merge(struct
64678 if (next && next->vm_end == end) /* cases 6, 7, 8 */
64679 next = next->vm_next;
64680
64681+#ifdef CONFIG_PAX_SEGMEXEC
64682+ if (prev)
64683+ prev_m = pax_find_mirror_vma(prev);
64684+ if (area)
64685+ area_m = pax_find_mirror_vma(area);
64686+ if (next)
64687+ next_m = pax_find_mirror_vma(next);
64688+#endif
64689+
64690 /*
64691 * Can it merge with the predecessor?
64692 */
64693@@ -799,9 +849,24 @@ struct vm_area_struct *vma_merge(struct
64694 /* cases 1, 6 */
64695 err = vma_adjust(prev, prev->vm_start,
64696 next->vm_end, prev->vm_pgoff, NULL);
64697- } else /* cases 2, 5, 7 */
64698+
64699+#ifdef CONFIG_PAX_SEGMEXEC
64700+ if (!err && prev_m)
64701+ err = vma_adjust(prev_m, prev_m->vm_start,
64702+ next_m->vm_end, prev_m->vm_pgoff, NULL);
64703+#endif
64704+
64705+ } else { /* cases 2, 5, 7 */
64706 err = vma_adjust(prev, prev->vm_start,
64707 end, prev->vm_pgoff, NULL);
64708+
64709+#ifdef CONFIG_PAX_SEGMEXEC
64710+ if (!err && prev_m)
64711+ err = vma_adjust(prev_m, prev_m->vm_start,
64712+ end_m, prev_m->vm_pgoff, NULL);
64713+#endif
64714+
64715+ }
64716 if (err)
64717 return NULL;
64718 khugepaged_enter_vma_merge(prev);
64719@@ -815,12 +880,27 @@ struct vm_area_struct *vma_merge(struct
64720 mpol_equal(policy, vma_policy(next)) &&
64721 can_vma_merge_before(next, vm_flags,
64722 anon_vma, file, pgoff+pglen)) {
64723- if (prev && addr < prev->vm_end) /* case 4 */
64724+ if (prev && addr < prev->vm_end) { /* case 4 */
64725 err = vma_adjust(prev, prev->vm_start,
64726 addr, prev->vm_pgoff, NULL);
64727- else /* cases 3, 8 */
64728+
64729+#ifdef CONFIG_PAX_SEGMEXEC
64730+ if (!err && prev_m)
64731+ err = vma_adjust(prev_m, prev_m->vm_start,
64732+ addr_m, prev_m->vm_pgoff, NULL);
64733+#endif
64734+
64735+ } else { /* cases 3, 8 */
64736 err = vma_adjust(area, addr, next->vm_end,
64737 next->vm_pgoff - pglen, NULL);
64738+
64739+#ifdef CONFIG_PAX_SEGMEXEC
64740+ if (!err && area_m)
64741+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
64742+ next_m->vm_pgoff - pglen, NULL);
64743+#endif
64744+
64745+ }
64746 if (err)
64747 return NULL;
64748 khugepaged_enter_vma_merge(area);
64749@@ -929,14 +1009,11 @@ none:
64750 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
64751 struct file *file, long pages)
64752 {
64753- const unsigned long stack_flags
64754- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
64755-
64756 if (file) {
64757 mm->shared_vm += pages;
64758 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
64759 mm->exec_vm += pages;
64760- } else if (flags & stack_flags)
64761+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
64762 mm->stack_vm += pages;
64763 if (flags & (VM_RESERVED|VM_IO))
64764 mm->reserved_vm += pages;
64765@@ -963,7 +1040,7 @@ unsigned long do_mmap_pgoff(struct file
64766 * (the exception is when the underlying filesystem is noexec
64767 * mounted, in which case we dont add PROT_EXEC.)
64768 */
64769- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
64770+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
64771 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
64772 prot |= PROT_EXEC;
64773
64774@@ -989,7 +1066,7 @@ unsigned long do_mmap_pgoff(struct file
64775 /* Obtain the address to map to. we verify (or select) it and ensure
64776 * that it represents a valid section of the address space.
64777 */
64778- addr = get_unmapped_area(file, addr, len, pgoff, flags);
64779+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
64780 if (addr & ~PAGE_MASK)
64781 return addr;
64782
64783@@ -1000,6 +1077,36 @@ unsigned long do_mmap_pgoff(struct file
64784 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
64785 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
64786
64787+#ifdef CONFIG_PAX_MPROTECT
64788+ if (mm->pax_flags & MF_PAX_MPROTECT) {
64789+#ifndef CONFIG_PAX_MPROTECT_COMPAT
64790+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
64791+ gr_log_rwxmmap(file);
64792+
64793+#ifdef CONFIG_PAX_EMUPLT
64794+ vm_flags &= ~VM_EXEC;
64795+#else
64796+ return -EPERM;
64797+#endif
64798+
64799+ }
64800+
64801+ if (!(vm_flags & VM_EXEC))
64802+ vm_flags &= ~VM_MAYEXEC;
64803+#else
64804+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
64805+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
64806+#endif
64807+ else
64808+ vm_flags &= ~VM_MAYWRITE;
64809+ }
64810+#endif
64811+
64812+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64813+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
64814+ vm_flags &= ~VM_PAGEEXEC;
64815+#endif
64816+
64817 if (flags & MAP_LOCKED)
64818 if (!can_do_mlock())
64819 return -EPERM;
64820@@ -1011,6 +1118,7 @@ unsigned long do_mmap_pgoff(struct file
64821 locked += mm->locked_vm;
64822 lock_limit = rlimit(RLIMIT_MEMLOCK);
64823 lock_limit >>= PAGE_SHIFT;
64824+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
64825 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
64826 return -EAGAIN;
64827 }
64828@@ -1081,6 +1189,9 @@ unsigned long do_mmap_pgoff(struct file
64829 if (error)
64830 return error;
64831
64832+ if (!gr_acl_handle_mmap(file, prot))
64833+ return -EACCES;
64834+
64835 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
64836 }
64837 EXPORT_SYMBOL(do_mmap_pgoff);
64838@@ -1161,7 +1272,7 @@ int vma_wants_writenotify(struct vm_area
64839 vm_flags_t vm_flags = vma->vm_flags;
64840
64841 /* If it was private or non-writable, the write bit is already clear */
64842- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
64843+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
64844 return 0;
64845
64846 /* The backer wishes to know when pages are first written to? */
64847@@ -1210,14 +1321,24 @@ unsigned long mmap_region(struct file *f
64848 unsigned long charged = 0;
64849 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
64850
64851+#ifdef CONFIG_PAX_SEGMEXEC
64852+ struct vm_area_struct *vma_m = NULL;
64853+#endif
64854+
64855+ /*
64856+ * mm->mmap_sem is required to protect against another thread
64857+ * changing the mappings in case we sleep.
64858+ */
64859+ verify_mm_writelocked(mm);
64860+
64861 /* Clear old maps */
64862 error = -ENOMEM;
64863-munmap_back:
64864 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
64865 if (vma && vma->vm_start < addr + len) {
64866 if (do_munmap(mm, addr, len))
64867 return -ENOMEM;
64868- goto munmap_back;
64869+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
64870+ BUG_ON(vma && vma->vm_start < addr + len);
64871 }
64872
64873 /* Check against address space limit. */
64874@@ -1266,6 +1387,16 @@ munmap_back:
64875 goto unacct_error;
64876 }
64877
64878+#ifdef CONFIG_PAX_SEGMEXEC
64879+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
64880+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
64881+ if (!vma_m) {
64882+ error = -ENOMEM;
64883+ goto free_vma;
64884+ }
64885+ }
64886+#endif
64887+
64888 vma->vm_mm = mm;
64889 vma->vm_start = addr;
64890 vma->vm_end = addr + len;
64891@@ -1289,6 +1420,19 @@ munmap_back:
64892 error = file->f_op->mmap(file, vma);
64893 if (error)
64894 goto unmap_and_free_vma;
64895+
64896+#ifdef CONFIG_PAX_SEGMEXEC
64897+ if (vma_m && (vm_flags & VM_EXECUTABLE))
64898+ added_exe_file_vma(mm);
64899+#endif
64900+
64901+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64902+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
64903+ vma->vm_flags |= VM_PAGEEXEC;
64904+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
64905+ }
64906+#endif
64907+
64908 if (vm_flags & VM_EXECUTABLE)
64909 added_exe_file_vma(mm);
64910
64911@@ -1324,6 +1468,11 @@ munmap_back:
64912 vma_link(mm, vma, prev, rb_link, rb_parent);
64913 file = vma->vm_file;
64914
64915+#ifdef CONFIG_PAX_SEGMEXEC
64916+ if (vma_m)
64917+ BUG_ON(pax_mirror_vma(vma_m, vma));
64918+#endif
64919+
64920 /* Once vma denies write, undo our temporary denial count */
64921 if (correct_wcount)
64922 atomic_inc(&inode->i_writecount);
64923@@ -1332,6 +1481,7 @@ out:
64924
64925 mm->total_vm += len >> PAGE_SHIFT;
64926 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
64927+ track_exec_limit(mm, addr, addr + len, vm_flags);
64928 if (vm_flags & VM_LOCKED) {
64929 if (!mlock_vma_pages_range(vma, addr, addr + len))
64930 mm->locked_vm += (len >> PAGE_SHIFT);
64931@@ -1349,6 +1499,12 @@ unmap_and_free_vma:
64932 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
64933 charged = 0;
64934 free_vma:
64935+
64936+#ifdef CONFIG_PAX_SEGMEXEC
64937+ if (vma_m)
64938+ kmem_cache_free(vm_area_cachep, vma_m);
64939+#endif
64940+
64941 kmem_cache_free(vm_area_cachep, vma);
64942 unacct_error:
64943 if (charged)
64944@@ -1356,6 +1512,44 @@ unacct_error:
64945 return error;
64946 }
64947
64948+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
64949+{
64950+ if (!vma) {
64951+#ifdef CONFIG_STACK_GROWSUP
64952+ if (addr > sysctl_heap_stack_gap)
64953+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
64954+ else
64955+ vma = find_vma(current->mm, 0);
64956+ if (vma && (vma->vm_flags & VM_GROWSUP))
64957+ return false;
64958+#endif
64959+ return true;
64960+ }
64961+
64962+ if (addr + len > vma->vm_start)
64963+ return false;
64964+
64965+ if (vma->vm_flags & VM_GROWSDOWN)
64966+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
64967+#ifdef CONFIG_STACK_GROWSUP
64968+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
64969+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
64970+#endif
64971+
64972+ return true;
64973+}
64974+
64975+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
64976+{
64977+ if (vma->vm_start < len)
64978+ return -ENOMEM;
64979+ if (!(vma->vm_flags & VM_GROWSDOWN))
64980+ return vma->vm_start - len;
64981+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
64982+ return vma->vm_start - len - sysctl_heap_stack_gap;
64983+ return -ENOMEM;
64984+}
64985+
64986 /* Get an address range which is currently unmapped.
64987 * For shmat() with addr=0.
64988 *
64989@@ -1382,18 +1576,23 @@ arch_get_unmapped_area(struct file *filp
64990 if (flags & MAP_FIXED)
64991 return addr;
64992
64993+#ifdef CONFIG_PAX_RANDMMAP
64994+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64995+#endif
64996+
64997 if (addr) {
64998 addr = PAGE_ALIGN(addr);
64999- vma = find_vma(mm, addr);
65000- if (TASK_SIZE - len >= addr &&
65001- (!vma || addr + len <= vma->vm_start))
65002- return addr;
65003+ if (TASK_SIZE - len >= addr) {
65004+ vma = find_vma(mm, addr);
65005+ if (check_heap_stack_gap(vma, addr, len))
65006+ return addr;
65007+ }
65008 }
65009 if (len > mm->cached_hole_size) {
65010- start_addr = addr = mm->free_area_cache;
65011+ start_addr = addr = mm->free_area_cache;
65012 } else {
65013- start_addr = addr = TASK_UNMAPPED_BASE;
65014- mm->cached_hole_size = 0;
65015+ start_addr = addr = mm->mmap_base;
65016+ mm->cached_hole_size = 0;
65017 }
65018
65019 full_search:
65020@@ -1404,34 +1603,40 @@ full_search:
65021 * Start a new search - just in case we missed
65022 * some holes.
65023 */
65024- if (start_addr != TASK_UNMAPPED_BASE) {
65025- addr = TASK_UNMAPPED_BASE;
65026- start_addr = addr;
65027+ if (start_addr != mm->mmap_base) {
65028+ start_addr = addr = mm->mmap_base;
65029 mm->cached_hole_size = 0;
65030 goto full_search;
65031 }
65032 return -ENOMEM;
65033 }
65034- if (!vma || addr + len <= vma->vm_start) {
65035- /*
65036- * Remember the place where we stopped the search:
65037- */
65038- mm->free_area_cache = addr + len;
65039- return addr;
65040- }
65041+ if (check_heap_stack_gap(vma, addr, len))
65042+ break;
65043 if (addr + mm->cached_hole_size < vma->vm_start)
65044 mm->cached_hole_size = vma->vm_start - addr;
65045 addr = vma->vm_end;
65046 }
65047+
65048+ /*
65049+ * Remember the place where we stopped the search:
65050+ */
65051+ mm->free_area_cache = addr + len;
65052+ return addr;
65053 }
65054 #endif
65055
65056 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
65057 {
65058+
65059+#ifdef CONFIG_PAX_SEGMEXEC
65060+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
65061+ return;
65062+#endif
65063+
65064 /*
65065 * Is this a new hole at the lowest possible address?
65066 */
65067- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
65068+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
65069 mm->free_area_cache = addr;
65070 mm->cached_hole_size = ~0UL;
65071 }
65072@@ -1449,7 +1654,7 @@ arch_get_unmapped_area_topdown(struct fi
65073 {
65074 struct vm_area_struct *vma;
65075 struct mm_struct *mm = current->mm;
65076- unsigned long addr = addr0;
65077+ unsigned long base = mm->mmap_base, addr = addr0;
65078
65079 /* requested length too big for entire address space */
65080 if (len > TASK_SIZE)
65081@@ -1458,13 +1663,18 @@ arch_get_unmapped_area_topdown(struct fi
65082 if (flags & MAP_FIXED)
65083 return addr;
65084
65085+#ifdef CONFIG_PAX_RANDMMAP
65086+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
65087+#endif
65088+
65089 /* requesting a specific address */
65090 if (addr) {
65091 addr = PAGE_ALIGN(addr);
65092- vma = find_vma(mm, addr);
65093- if (TASK_SIZE - len >= addr &&
65094- (!vma || addr + len <= vma->vm_start))
65095- return addr;
65096+ if (TASK_SIZE - len >= addr) {
65097+ vma = find_vma(mm, addr);
65098+ if (check_heap_stack_gap(vma, addr, len))
65099+ return addr;
65100+ }
65101 }
65102
65103 /* check if free_area_cache is useful for us */
65104@@ -1479,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct fi
65105 /* make sure it can fit in the remaining address space */
65106 if (addr > len) {
65107 vma = find_vma(mm, addr-len);
65108- if (!vma || addr <= vma->vm_start)
65109+ if (check_heap_stack_gap(vma, addr - len, len))
65110 /* remember the address as a hint for next time */
65111 return (mm->free_area_cache = addr-len);
65112 }
65113@@ -1496,7 +1706,7 @@ arch_get_unmapped_area_topdown(struct fi
65114 * return with success:
65115 */
65116 vma = find_vma(mm, addr);
65117- if (!vma || addr+len <= vma->vm_start)
65118+ if (check_heap_stack_gap(vma, addr, len))
65119 /* remember the address as a hint for next time */
65120 return (mm->free_area_cache = addr);
65121
65122@@ -1505,8 +1715,8 @@ arch_get_unmapped_area_topdown(struct fi
65123 mm->cached_hole_size = vma->vm_start - addr;
65124
65125 /* try just below the current vma->vm_start */
65126- addr = vma->vm_start-len;
65127- } while (len < vma->vm_start);
65128+ addr = skip_heap_stack_gap(vma, len);
65129+ } while (!IS_ERR_VALUE(addr));
65130
65131 bottomup:
65132 /*
65133@@ -1515,13 +1725,21 @@ bottomup:
65134 * can happen with large stack limits and large mmap()
65135 * allocations.
65136 */
65137+ mm->mmap_base = TASK_UNMAPPED_BASE;
65138+
65139+#ifdef CONFIG_PAX_RANDMMAP
65140+ if (mm->pax_flags & MF_PAX_RANDMMAP)
65141+ mm->mmap_base += mm->delta_mmap;
65142+#endif
65143+
65144+ mm->free_area_cache = mm->mmap_base;
65145 mm->cached_hole_size = ~0UL;
65146- mm->free_area_cache = TASK_UNMAPPED_BASE;
65147 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
65148 /*
65149 * Restore the topdown base:
65150 */
65151- mm->free_area_cache = mm->mmap_base;
65152+ mm->mmap_base = base;
65153+ mm->free_area_cache = base;
65154 mm->cached_hole_size = ~0UL;
65155
65156 return addr;
65157@@ -1530,6 +1748,12 @@ bottomup:
65158
65159 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
65160 {
65161+
65162+#ifdef CONFIG_PAX_SEGMEXEC
65163+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
65164+ return;
65165+#endif
65166+
65167 /*
65168 * Is this a new hole at the highest possible address?
65169 */
65170@@ -1537,8 +1761,10 @@ void arch_unmap_area_topdown(struct mm_s
65171 mm->free_area_cache = addr;
65172
65173 /* dont allow allocations above current base */
65174- if (mm->free_area_cache > mm->mmap_base)
65175+ if (mm->free_area_cache > mm->mmap_base) {
65176 mm->free_area_cache = mm->mmap_base;
65177+ mm->cached_hole_size = ~0UL;
65178+ }
65179 }
65180
65181 unsigned long
65182@@ -1646,6 +1872,28 @@ out:
65183 return prev ? prev->vm_next : vma;
65184 }
65185
65186+#ifdef CONFIG_PAX_SEGMEXEC
65187+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
65188+{
65189+ struct vm_area_struct *vma_m;
65190+
65191+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
65192+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
65193+ BUG_ON(vma->vm_mirror);
65194+ return NULL;
65195+ }
65196+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
65197+ vma_m = vma->vm_mirror;
65198+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
65199+ BUG_ON(vma->vm_file != vma_m->vm_file);
65200+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
65201+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
65202+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
65203+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
65204+ return vma_m;
65205+}
65206+#endif
65207+
65208 /*
65209 * Verify that the stack growth is acceptable and
65210 * update accounting. This is shared with both the
65211@@ -1662,6 +1910,7 @@ static int acct_stack_growth(struct vm_a
65212 return -ENOMEM;
65213
65214 /* Stack limit test */
65215+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
65216 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
65217 return -ENOMEM;
65218
65219@@ -1672,6 +1921,7 @@ static int acct_stack_growth(struct vm_a
65220 locked = mm->locked_vm + grow;
65221 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
65222 limit >>= PAGE_SHIFT;
65223+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
65224 if (locked > limit && !capable(CAP_IPC_LOCK))
65225 return -ENOMEM;
65226 }
65227@@ -1702,37 +1952,48 @@ static int acct_stack_growth(struct vm_a
65228 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
65229 * vma is the last one with address > vma->vm_end. Have to extend vma.
65230 */
65231+#ifndef CONFIG_IA64
65232+static
65233+#endif
65234 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
65235 {
65236 int error;
65237+ bool locknext;
65238
65239 if (!(vma->vm_flags & VM_GROWSUP))
65240 return -EFAULT;
65241
65242+ /* Also guard against wrapping around to address 0. */
65243+ if (address < PAGE_ALIGN(address+1))
65244+ address = PAGE_ALIGN(address+1);
65245+ else
65246+ return -ENOMEM;
65247+
65248 /*
65249 * We must make sure the anon_vma is allocated
65250 * so that the anon_vma locking is not a noop.
65251 */
65252 if (unlikely(anon_vma_prepare(vma)))
65253 return -ENOMEM;
65254+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
65255+ if (locknext && anon_vma_prepare(vma->vm_next))
65256+ return -ENOMEM;
65257 vma_lock_anon_vma(vma);
65258+ if (locknext)
65259+ vma_lock_anon_vma(vma->vm_next);
65260
65261 /*
65262 * vma->vm_start/vm_end cannot change under us because the caller
65263 * is required to hold the mmap_sem in read mode. We need the
65264- * anon_vma lock to serialize against concurrent expand_stacks.
65265- * Also guard against wrapping around to address 0.
65266+ * anon_vma locks to serialize against concurrent expand_stacks
65267+ * and expand_upwards.
65268 */
65269- if (address < PAGE_ALIGN(address+4))
65270- address = PAGE_ALIGN(address+4);
65271- else {
65272- vma_unlock_anon_vma(vma);
65273- return -ENOMEM;
65274- }
65275 error = 0;
65276
65277 /* Somebody else might have raced and expanded it already */
65278- if (address > vma->vm_end) {
65279+ 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)
65280+ error = -ENOMEM;
65281+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
65282 unsigned long size, grow;
65283
65284 size = address - vma->vm_start;
65285@@ -1747,6 +2008,8 @@ int expand_upwards(struct vm_area_struct
65286 }
65287 }
65288 }
65289+ if (locknext)
65290+ vma_unlock_anon_vma(vma->vm_next);
65291 vma_unlock_anon_vma(vma);
65292 khugepaged_enter_vma_merge(vma);
65293 return error;
65294@@ -1760,6 +2023,8 @@ int expand_downwards(struct vm_area_stru
65295 unsigned long address)
65296 {
65297 int error;
65298+ bool lockprev = false;
65299+ struct vm_area_struct *prev;
65300
65301 /*
65302 * We must make sure the anon_vma is allocated
65303@@ -1773,6 +2038,15 @@ int expand_downwards(struct vm_area_stru
65304 if (error)
65305 return error;
65306
65307+ prev = vma->vm_prev;
65308+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
65309+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
65310+#endif
65311+ if (lockprev && anon_vma_prepare(prev))
65312+ return -ENOMEM;
65313+ if (lockprev)
65314+ vma_lock_anon_vma(prev);
65315+
65316 vma_lock_anon_vma(vma);
65317
65318 /*
65319@@ -1782,9 +2056,17 @@ int expand_downwards(struct vm_area_stru
65320 */
65321
65322 /* Somebody else might have raced and expanded it already */
65323- if (address < vma->vm_start) {
65324+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
65325+ error = -ENOMEM;
65326+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
65327 unsigned long size, grow;
65328
65329+#ifdef CONFIG_PAX_SEGMEXEC
65330+ struct vm_area_struct *vma_m;
65331+
65332+ vma_m = pax_find_mirror_vma(vma);
65333+#endif
65334+
65335 size = vma->vm_end - address;
65336 grow = (vma->vm_start - address) >> PAGE_SHIFT;
65337
65338@@ -1794,11 +2076,22 @@ int expand_downwards(struct vm_area_stru
65339 if (!error) {
65340 vma->vm_start = address;
65341 vma->vm_pgoff -= grow;
65342+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
65343+
65344+#ifdef CONFIG_PAX_SEGMEXEC
65345+ if (vma_m) {
65346+ vma_m->vm_start -= grow << PAGE_SHIFT;
65347+ vma_m->vm_pgoff -= grow;
65348+ }
65349+#endif
65350+
65351 perf_event_mmap(vma);
65352 }
65353 }
65354 }
65355 vma_unlock_anon_vma(vma);
65356+ if (lockprev)
65357+ vma_unlock_anon_vma(prev);
65358 khugepaged_enter_vma_merge(vma);
65359 return error;
65360 }
65361@@ -1868,6 +2161,13 @@ static void remove_vma_list(struct mm_st
65362 do {
65363 long nrpages = vma_pages(vma);
65364
65365+#ifdef CONFIG_PAX_SEGMEXEC
65366+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
65367+ vma = remove_vma(vma);
65368+ continue;
65369+ }
65370+#endif
65371+
65372 mm->total_vm -= nrpages;
65373 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
65374 vma = remove_vma(vma);
65375@@ -1913,6 +2213,16 @@ detach_vmas_to_be_unmapped(struct mm_str
65376 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
65377 vma->vm_prev = NULL;
65378 do {
65379+
65380+#ifdef CONFIG_PAX_SEGMEXEC
65381+ if (vma->vm_mirror) {
65382+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
65383+ vma->vm_mirror->vm_mirror = NULL;
65384+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
65385+ vma->vm_mirror = NULL;
65386+ }
65387+#endif
65388+
65389 rb_erase(&vma->vm_rb, &mm->mm_rb);
65390 mm->map_count--;
65391 tail_vma = vma;
65392@@ -1941,14 +2251,33 @@ static int __split_vma(struct mm_struct
65393 struct vm_area_struct *new;
65394 int err = -ENOMEM;
65395
65396+#ifdef CONFIG_PAX_SEGMEXEC
65397+ struct vm_area_struct *vma_m, *new_m = NULL;
65398+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
65399+#endif
65400+
65401 if (is_vm_hugetlb_page(vma) && (addr &
65402 ~(huge_page_mask(hstate_vma(vma)))))
65403 return -EINVAL;
65404
65405+#ifdef CONFIG_PAX_SEGMEXEC
65406+ vma_m = pax_find_mirror_vma(vma);
65407+#endif
65408+
65409 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65410 if (!new)
65411 goto out_err;
65412
65413+#ifdef CONFIG_PAX_SEGMEXEC
65414+ if (vma_m) {
65415+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65416+ if (!new_m) {
65417+ kmem_cache_free(vm_area_cachep, new);
65418+ goto out_err;
65419+ }
65420+ }
65421+#endif
65422+
65423 /* most fields are the same, copy all, and then fixup */
65424 *new = *vma;
65425
65426@@ -1961,6 +2290,22 @@ static int __split_vma(struct mm_struct
65427 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
65428 }
65429
65430+#ifdef CONFIG_PAX_SEGMEXEC
65431+ if (vma_m) {
65432+ *new_m = *vma_m;
65433+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
65434+ new_m->vm_mirror = new;
65435+ new->vm_mirror = new_m;
65436+
65437+ if (new_below)
65438+ new_m->vm_end = addr_m;
65439+ else {
65440+ new_m->vm_start = addr_m;
65441+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
65442+ }
65443+ }
65444+#endif
65445+
65446 pol = mpol_dup(vma_policy(vma));
65447 if (IS_ERR(pol)) {
65448 err = PTR_ERR(pol);
65449@@ -1986,6 +2331,42 @@ static int __split_vma(struct mm_struct
65450 else
65451 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
65452
65453+#ifdef CONFIG_PAX_SEGMEXEC
65454+ if (!err && vma_m) {
65455+ if (anon_vma_clone(new_m, vma_m))
65456+ goto out_free_mpol;
65457+
65458+ mpol_get(pol);
65459+ vma_set_policy(new_m, pol);
65460+
65461+ if (new_m->vm_file) {
65462+ get_file(new_m->vm_file);
65463+ if (vma_m->vm_flags & VM_EXECUTABLE)
65464+ added_exe_file_vma(mm);
65465+ }
65466+
65467+ if (new_m->vm_ops && new_m->vm_ops->open)
65468+ new_m->vm_ops->open(new_m);
65469+
65470+ if (new_below)
65471+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
65472+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
65473+ else
65474+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
65475+
65476+ if (err) {
65477+ if (new_m->vm_ops && new_m->vm_ops->close)
65478+ new_m->vm_ops->close(new_m);
65479+ if (new_m->vm_file) {
65480+ if (vma_m->vm_flags & VM_EXECUTABLE)
65481+ removed_exe_file_vma(mm);
65482+ fput(new_m->vm_file);
65483+ }
65484+ mpol_put(pol);
65485+ }
65486+ }
65487+#endif
65488+
65489 /* Success. */
65490 if (!err)
65491 return 0;
65492@@ -1998,10 +2379,18 @@ static int __split_vma(struct mm_struct
65493 removed_exe_file_vma(mm);
65494 fput(new->vm_file);
65495 }
65496- unlink_anon_vmas(new);
65497 out_free_mpol:
65498 mpol_put(pol);
65499 out_free_vma:
65500+
65501+#ifdef CONFIG_PAX_SEGMEXEC
65502+ if (new_m) {
65503+ unlink_anon_vmas(new_m);
65504+ kmem_cache_free(vm_area_cachep, new_m);
65505+ }
65506+#endif
65507+
65508+ unlink_anon_vmas(new);
65509 kmem_cache_free(vm_area_cachep, new);
65510 out_err:
65511 return err;
65512@@ -2014,6 +2403,15 @@ static int __split_vma(struct mm_struct
65513 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
65514 unsigned long addr, int new_below)
65515 {
65516+
65517+#ifdef CONFIG_PAX_SEGMEXEC
65518+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
65519+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
65520+ if (mm->map_count >= sysctl_max_map_count-1)
65521+ return -ENOMEM;
65522+ } else
65523+#endif
65524+
65525 if (mm->map_count >= sysctl_max_map_count)
65526 return -ENOMEM;
65527
65528@@ -2025,11 +2423,30 @@ int split_vma(struct mm_struct *mm, stru
65529 * work. This now handles partial unmappings.
65530 * Jeremy Fitzhardinge <jeremy@goop.org>
65531 */
65532+#ifdef CONFIG_PAX_SEGMEXEC
65533 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65534 {
65535+ int ret = __do_munmap(mm, start, len);
65536+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
65537+ return ret;
65538+
65539+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
65540+}
65541+
65542+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65543+#else
65544+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65545+#endif
65546+{
65547 unsigned long end;
65548 struct vm_area_struct *vma, *prev, *last;
65549
65550+ /*
65551+ * mm->mmap_sem is required to protect against another thread
65552+ * changing the mappings in case we sleep.
65553+ */
65554+ verify_mm_writelocked(mm);
65555+
65556 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
65557 return -EINVAL;
65558
65559@@ -2104,6 +2521,8 @@ int do_munmap(struct mm_struct *mm, unsi
65560 /* Fix up all other VM information */
65561 remove_vma_list(mm, vma);
65562
65563+ track_exec_limit(mm, start, end, 0UL);
65564+
65565 return 0;
65566 }
65567
65568@@ -2116,22 +2535,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
65569
65570 profile_munmap(addr);
65571
65572+#ifdef CONFIG_PAX_SEGMEXEC
65573+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
65574+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
65575+ return -EINVAL;
65576+#endif
65577+
65578 down_write(&mm->mmap_sem);
65579 ret = do_munmap(mm, addr, len);
65580 up_write(&mm->mmap_sem);
65581 return ret;
65582 }
65583
65584-static inline void verify_mm_writelocked(struct mm_struct *mm)
65585-{
65586-#ifdef CONFIG_DEBUG_VM
65587- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
65588- WARN_ON(1);
65589- up_read(&mm->mmap_sem);
65590- }
65591-#endif
65592-}
65593-
65594 /*
65595 * this is really a simplified "do_mmap". it only handles
65596 * anonymous maps. eventually we may be able to do some
65597@@ -2145,6 +2560,7 @@ unsigned long do_brk(unsigned long addr,
65598 struct rb_node ** rb_link, * rb_parent;
65599 pgoff_t pgoff = addr >> PAGE_SHIFT;
65600 int error;
65601+ unsigned long charged;
65602
65603 len = PAGE_ALIGN(len);
65604 if (!len)
65605@@ -2156,16 +2572,30 @@ unsigned long do_brk(unsigned long addr,
65606
65607 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
65608
65609+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
65610+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
65611+ flags &= ~VM_EXEC;
65612+
65613+#ifdef CONFIG_PAX_MPROTECT
65614+ if (mm->pax_flags & MF_PAX_MPROTECT)
65615+ flags &= ~VM_MAYEXEC;
65616+#endif
65617+
65618+ }
65619+#endif
65620+
65621 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
65622 if (error & ~PAGE_MASK)
65623 return error;
65624
65625+ charged = len >> PAGE_SHIFT;
65626+
65627 /*
65628 * mlock MCL_FUTURE?
65629 */
65630 if (mm->def_flags & VM_LOCKED) {
65631 unsigned long locked, lock_limit;
65632- locked = len >> PAGE_SHIFT;
65633+ locked = charged;
65634 locked += mm->locked_vm;
65635 lock_limit = rlimit(RLIMIT_MEMLOCK);
65636 lock_limit >>= PAGE_SHIFT;
65637@@ -2182,22 +2612,22 @@ unsigned long do_brk(unsigned long addr,
65638 /*
65639 * Clear old maps. this also does some error checking for us
65640 */
65641- munmap_back:
65642 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
65643 if (vma && vma->vm_start < addr + len) {
65644 if (do_munmap(mm, addr, len))
65645 return -ENOMEM;
65646- goto munmap_back;
65647+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
65648+ BUG_ON(vma && vma->vm_start < addr + len);
65649 }
65650
65651 /* Check against address space limits *after* clearing old maps... */
65652- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
65653+ if (!may_expand_vm(mm, charged))
65654 return -ENOMEM;
65655
65656 if (mm->map_count > sysctl_max_map_count)
65657 return -ENOMEM;
65658
65659- if (security_vm_enough_memory(len >> PAGE_SHIFT))
65660+ if (security_vm_enough_memory(charged))
65661 return -ENOMEM;
65662
65663 /* Can we just expand an old private anonymous mapping? */
65664@@ -2211,7 +2641,7 @@ unsigned long do_brk(unsigned long addr,
65665 */
65666 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65667 if (!vma) {
65668- vm_unacct_memory(len >> PAGE_SHIFT);
65669+ vm_unacct_memory(charged);
65670 return -ENOMEM;
65671 }
65672
65673@@ -2225,11 +2655,12 @@ unsigned long do_brk(unsigned long addr,
65674 vma_link(mm, vma, prev, rb_link, rb_parent);
65675 out:
65676 perf_event_mmap(vma);
65677- mm->total_vm += len >> PAGE_SHIFT;
65678+ mm->total_vm += charged;
65679 if (flags & VM_LOCKED) {
65680 if (!mlock_vma_pages_range(vma, addr, addr + len))
65681- mm->locked_vm += (len >> PAGE_SHIFT);
65682+ mm->locked_vm += charged;
65683 }
65684+ track_exec_limit(mm, addr, addr + len, flags);
65685 return addr;
65686 }
65687
65688@@ -2276,8 +2707,10 @@ void exit_mmap(struct mm_struct *mm)
65689 * Walk the list again, actually closing and freeing it,
65690 * with preemption enabled, without holding any MM locks.
65691 */
65692- while (vma)
65693+ while (vma) {
65694+ vma->vm_mirror = NULL;
65695 vma = remove_vma(vma);
65696+ }
65697
65698 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
65699 }
65700@@ -2291,6 +2724,13 @@ int insert_vm_struct(struct mm_struct *
65701 struct vm_area_struct * __vma, * prev;
65702 struct rb_node ** rb_link, * rb_parent;
65703
65704+#ifdef CONFIG_PAX_SEGMEXEC
65705+ struct vm_area_struct *vma_m = NULL;
65706+#endif
65707+
65708+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
65709+ return -EPERM;
65710+
65711 /*
65712 * The vm_pgoff of a purely anonymous vma should be irrelevant
65713 * until its first write fault, when page's anon_vma and index
65714@@ -2313,7 +2753,22 @@ int insert_vm_struct(struct mm_struct *
65715 if ((vma->vm_flags & VM_ACCOUNT) &&
65716 security_vm_enough_memory_mm(mm, vma_pages(vma)))
65717 return -ENOMEM;
65718+
65719+#ifdef CONFIG_PAX_SEGMEXEC
65720+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
65721+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65722+ if (!vma_m)
65723+ return -ENOMEM;
65724+ }
65725+#endif
65726+
65727 vma_link(mm, vma, prev, rb_link, rb_parent);
65728+
65729+#ifdef CONFIG_PAX_SEGMEXEC
65730+ if (vma_m)
65731+ BUG_ON(pax_mirror_vma(vma_m, vma));
65732+#endif
65733+
65734 return 0;
65735 }
65736
65737@@ -2331,6 +2786,8 @@ struct vm_area_struct *copy_vma(struct v
65738 struct rb_node **rb_link, *rb_parent;
65739 struct mempolicy *pol;
65740
65741+ BUG_ON(vma->vm_mirror);
65742+
65743 /*
65744 * If anonymous vma has not yet been faulted, update new pgoff
65745 * to match new location, to increase its chance of merging.
65746@@ -2381,6 +2838,39 @@ struct vm_area_struct *copy_vma(struct v
65747 return NULL;
65748 }
65749
65750+#ifdef CONFIG_PAX_SEGMEXEC
65751+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
65752+{
65753+ struct vm_area_struct *prev_m;
65754+ struct rb_node **rb_link_m, *rb_parent_m;
65755+ struct mempolicy *pol_m;
65756+
65757+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
65758+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
65759+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
65760+ *vma_m = *vma;
65761+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
65762+ if (anon_vma_clone(vma_m, vma))
65763+ return -ENOMEM;
65764+ pol_m = vma_policy(vma_m);
65765+ mpol_get(pol_m);
65766+ vma_set_policy(vma_m, pol_m);
65767+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
65768+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
65769+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
65770+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
65771+ if (vma_m->vm_file)
65772+ get_file(vma_m->vm_file);
65773+ if (vma_m->vm_ops && vma_m->vm_ops->open)
65774+ vma_m->vm_ops->open(vma_m);
65775+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
65776+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
65777+ vma_m->vm_mirror = vma;
65778+ vma->vm_mirror = vma_m;
65779+ return 0;
65780+}
65781+#endif
65782+
65783 /*
65784 * Return true if the calling process may expand its vm space by the passed
65785 * number of pages
65786@@ -2391,7 +2881,7 @@ int may_expand_vm(struct mm_struct *mm,
65787 unsigned long lim;
65788
65789 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
65790-
65791+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
65792 if (cur + npages > lim)
65793 return 0;
65794 return 1;
65795@@ -2462,6 +2952,22 @@ int install_special_mapping(struct mm_st
65796 vma->vm_start = addr;
65797 vma->vm_end = addr + len;
65798
65799+#ifdef CONFIG_PAX_MPROTECT
65800+ if (mm->pax_flags & MF_PAX_MPROTECT) {
65801+#ifndef CONFIG_PAX_MPROTECT_COMPAT
65802+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
65803+ return -EPERM;
65804+ if (!(vm_flags & VM_EXEC))
65805+ vm_flags &= ~VM_MAYEXEC;
65806+#else
65807+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
65808+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
65809+#endif
65810+ else
65811+ vm_flags &= ~VM_MAYWRITE;
65812+ }
65813+#endif
65814+
65815 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
65816 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
65817
65818diff -urNp linux-3.0.4/mm/mprotect.c linux-3.0.4/mm/mprotect.c
65819--- linux-3.0.4/mm/mprotect.c 2011-07-21 22:17:23.000000000 -0400
65820+++ linux-3.0.4/mm/mprotect.c 2011-08-23 21:48:14.000000000 -0400
65821@@ -23,10 +23,16 @@
65822 #include <linux/mmu_notifier.h>
65823 #include <linux/migrate.h>
65824 #include <linux/perf_event.h>
65825+
65826+#ifdef CONFIG_PAX_MPROTECT
65827+#include <linux/elf.h>
65828+#endif
65829+
65830 #include <asm/uaccess.h>
65831 #include <asm/pgtable.h>
65832 #include <asm/cacheflush.h>
65833 #include <asm/tlbflush.h>
65834+#include <asm/mmu_context.h>
65835
65836 #ifndef pgprot_modify
65837 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
65838@@ -141,6 +147,48 @@ static void change_protection(struct vm_
65839 flush_tlb_range(vma, start, end);
65840 }
65841
65842+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65843+/* called while holding the mmap semaphor for writing except stack expansion */
65844+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
65845+{
65846+ unsigned long oldlimit, newlimit = 0UL;
65847+
65848+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
65849+ return;
65850+
65851+ spin_lock(&mm->page_table_lock);
65852+ oldlimit = mm->context.user_cs_limit;
65853+ if ((prot & VM_EXEC) && oldlimit < end)
65854+ /* USER_CS limit moved up */
65855+ newlimit = end;
65856+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
65857+ /* USER_CS limit moved down */
65858+ newlimit = start;
65859+
65860+ if (newlimit) {
65861+ mm->context.user_cs_limit = newlimit;
65862+
65863+#ifdef CONFIG_SMP
65864+ wmb();
65865+ cpus_clear(mm->context.cpu_user_cs_mask);
65866+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
65867+#endif
65868+
65869+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
65870+ }
65871+ spin_unlock(&mm->page_table_lock);
65872+ if (newlimit == end) {
65873+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
65874+
65875+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
65876+ if (is_vm_hugetlb_page(vma))
65877+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
65878+ else
65879+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
65880+ }
65881+}
65882+#endif
65883+
65884 int
65885 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
65886 unsigned long start, unsigned long end, unsigned long newflags)
65887@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
65888 int error;
65889 int dirty_accountable = 0;
65890
65891+#ifdef CONFIG_PAX_SEGMEXEC
65892+ struct vm_area_struct *vma_m = NULL;
65893+ unsigned long start_m, end_m;
65894+
65895+ start_m = start + SEGMEXEC_TASK_SIZE;
65896+ end_m = end + SEGMEXEC_TASK_SIZE;
65897+#endif
65898+
65899 if (newflags == oldflags) {
65900 *pprev = vma;
65901 return 0;
65902 }
65903
65904+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
65905+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
65906+
65907+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
65908+ return -ENOMEM;
65909+
65910+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
65911+ return -ENOMEM;
65912+ }
65913+
65914 /*
65915 * If we make a private mapping writable we increase our commit;
65916 * but (without finer accounting) cannot reduce our commit if we
65917@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
65918 }
65919 }
65920
65921+#ifdef CONFIG_PAX_SEGMEXEC
65922+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
65923+ if (start != vma->vm_start) {
65924+ error = split_vma(mm, vma, start, 1);
65925+ if (error)
65926+ goto fail;
65927+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
65928+ *pprev = (*pprev)->vm_next;
65929+ }
65930+
65931+ if (end != vma->vm_end) {
65932+ error = split_vma(mm, vma, end, 0);
65933+ if (error)
65934+ goto fail;
65935+ }
65936+
65937+ if (pax_find_mirror_vma(vma)) {
65938+ error = __do_munmap(mm, start_m, end_m - start_m);
65939+ if (error)
65940+ goto fail;
65941+ } else {
65942+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65943+ if (!vma_m) {
65944+ error = -ENOMEM;
65945+ goto fail;
65946+ }
65947+ vma->vm_flags = newflags;
65948+ error = pax_mirror_vma(vma_m, vma);
65949+ if (error) {
65950+ vma->vm_flags = oldflags;
65951+ goto fail;
65952+ }
65953+ }
65954+ }
65955+#endif
65956+
65957 /*
65958 * First try to merge with previous and/or next vma.
65959 */
65960@@ -204,9 +306,21 @@ success:
65961 * vm_flags and vm_page_prot are protected by the mmap_sem
65962 * held in write mode.
65963 */
65964+
65965+#ifdef CONFIG_PAX_SEGMEXEC
65966+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
65967+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
65968+#endif
65969+
65970 vma->vm_flags = newflags;
65971+
65972+#ifdef CONFIG_PAX_MPROTECT
65973+ if (mm->binfmt && mm->binfmt->handle_mprotect)
65974+ mm->binfmt->handle_mprotect(vma, newflags);
65975+#endif
65976+
65977 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
65978- vm_get_page_prot(newflags));
65979+ vm_get_page_prot(vma->vm_flags));
65980
65981 if (vma_wants_writenotify(vma)) {
65982 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
65983@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65984 end = start + len;
65985 if (end <= start)
65986 return -ENOMEM;
65987+
65988+#ifdef CONFIG_PAX_SEGMEXEC
65989+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
65990+ if (end > SEGMEXEC_TASK_SIZE)
65991+ return -EINVAL;
65992+ } else
65993+#endif
65994+
65995+ if (end > TASK_SIZE)
65996+ return -EINVAL;
65997+
65998 if (!arch_validate_prot(prot))
65999 return -EINVAL;
66000
66001@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
66002 /*
66003 * Does the application expect PROT_READ to imply PROT_EXEC:
66004 */
66005- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
66006+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
66007 prot |= PROT_EXEC;
66008
66009 vm_flags = calc_vm_prot_bits(prot);
66010@@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
66011 if (start > vma->vm_start)
66012 prev = vma;
66013
66014+#ifdef CONFIG_PAX_MPROTECT
66015+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
66016+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
66017+#endif
66018+
66019 for (nstart = start ; ; ) {
66020 unsigned long newflags;
66021
66022@@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
66023
66024 /* newflags >> 4 shift VM_MAY% in place of VM_% */
66025 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
66026+ if (prot & (PROT_WRITE | PROT_EXEC))
66027+ gr_log_rwxmprotect(vma->vm_file);
66028+
66029+ error = -EACCES;
66030+ goto out;
66031+ }
66032+
66033+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
66034 error = -EACCES;
66035 goto out;
66036 }
66037@@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
66038 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
66039 if (error)
66040 goto out;
66041+
66042+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
66043+
66044 nstart = tmp;
66045
66046 if (nstart < prev->vm_end)
66047diff -urNp linux-3.0.4/mm/mremap.c linux-3.0.4/mm/mremap.c
66048--- linux-3.0.4/mm/mremap.c 2011-07-21 22:17:23.000000000 -0400
66049+++ linux-3.0.4/mm/mremap.c 2011-08-23 21:47:56.000000000 -0400
66050@@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_str
66051 continue;
66052 pte = ptep_clear_flush(vma, old_addr, old_pte);
66053 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
66054+
66055+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66056+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
66057+ pte = pte_exprotect(pte);
66058+#endif
66059+
66060 set_pte_at(mm, new_addr, new_pte, pte);
66061 }
66062
66063@@ -272,6 +278,11 @@ static struct vm_area_struct *vma_to_res
66064 if (is_vm_hugetlb_page(vma))
66065 goto Einval;
66066
66067+#ifdef CONFIG_PAX_SEGMEXEC
66068+ if (pax_find_mirror_vma(vma))
66069+ goto Einval;
66070+#endif
66071+
66072 /* We can't remap across vm area boundaries */
66073 if (old_len > vma->vm_end - addr)
66074 goto Efault;
66075@@ -328,20 +339,25 @@ static unsigned long mremap_to(unsigned
66076 unsigned long ret = -EINVAL;
66077 unsigned long charged = 0;
66078 unsigned long map_flags;
66079+ unsigned long pax_task_size = TASK_SIZE;
66080
66081 if (new_addr & ~PAGE_MASK)
66082 goto out;
66083
66084- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
66085+#ifdef CONFIG_PAX_SEGMEXEC
66086+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
66087+ pax_task_size = SEGMEXEC_TASK_SIZE;
66088+#endif
66089+
66090+ pax_task_size -= PAGE_SIZE;
66091+
66092+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
66093 goto out;
66094
66095 /* Check if the location we're moving into overlaps the
66096 * old location at all, and fail if it does.
66097 */
66098- if ((new_addr <= addr) && (new_addr+new_len) > addr)
66099- goto out;
66100-
66101- if ((addr <= new_addr) && (addr+old_len) > new_addr)
66102+ if (addr + old_len > new_addr && new_addr + new_len > addr)
66103 goto out;
66104
66105 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
66106@@ -413,6 +429,7 @@ unsigned long do_mremap(unsigned long ad
66107 struct vm_area_struct *vma;
66108 unsigned long ret = -EINVAL;
66109 unsigned long charged = 0;
66110+ unsigned long pax_task_size = TASK_SIZE;
66111
66112 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
66113 goto out;
66114@@ -431,6 +448,17 @@ unsigned long do_mremap(unsigned long ad
66115 if (!new_len)
66116 goto out;
66117
66118+#ifdef CONFIG_PAX_SEGMEXEC
66119+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
66120+ pax_task_size = SEGMEXEC_TASK_SIZE;
66121+#endif
66122+
66123+ pax_task_size -= PAGE_SIZE;
66124+
66125+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
66126+ old_len > pax_task_size || addr > pax_task_size-old_len)
66127+ goto out;
66128+
66129 if (flags & MREMAP_FIXED) {
66130 if (flags & MREMAP_MAYMOVE)
66131 ret = mremap_to(addr, old_len, new_addr, new_len);
66132@@ -480,6 +508,7 @@ unsigned long do_mremap(unsigned long ad
66133 addr + new_len);
66134 }
66135 ret = addr;
66136+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
66137 goto out;
66138 }
66139 }
66140@@ -506,7 +535,13 @@ unsigned long do_mremap(unsigned long ad
66141 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
66142 if (ret)
66143 goto out;
66144+
66145+ map_flags = vma->vm_flags;
66146 ret = move_vma(vma, addr, old_len, new_len, new_addr);
66147+ if (!(ret & ~PAGE_MASK)) {
66148+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
66149+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
66150+ }
66151 }
66152 out:
66153 if (ret & ~PAGE_MASK)
66154diff -urNp linux-3.0.4/mm/nobootmem.c linux-3.0.4/mm/nobootmem.c
66155--- linux-3.0.4/mm/nobootmem.c 2011-07-21 22:17:23.000000000 -0400
66156+++ linux-3.0.4/mm/nobootmem.c 2011-08-23 21:47:56.000000000 -0400
66157@@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
66158 unsigned long __init free_all_memory_core_early(int nodeid)
66159 {
66160 int i;
66161- u64 start, end;
66162+ u64 start, end, startrange, endrange;
66163 unsigned long count = 0;
66164- struct range *range = NULL;
66165+ struct range *range = NULL, rangerange = { 0, 0 };
66166 int nr_range;
66167
66168 nr_range = get_free_all_memory_range(&range, nodeid);
66169+ startrange = __pa(range) >> PAGE_SHIFT;
66170+ endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
66171
66172 for (i = 0; i < nr_range; i++) {
66173 start = range[i].start;
66174 end = range[i].end;
66175+ if (start <= endrange && startrange < end) {
66176+ BUG_ON(rangerange.start | rangerange.end);
66177+ rangerange = range[i];
66178+ continue;
66179+ }
66180 count += end - start;
66181 __free_pages_memory(start, end);
66182 }
66183+ start = rangerange.start;
66184+ end = rangerange.end;
66185+ count += end - start;
66186+ __free_pages_memory(start, end);
66187
66188 return count;
66189 }
66190diff -urNp linux-3.0.4/mm/nommu.c linux-3.0.4/mm/nommu.c
66191--- linux-3.0.4/mm/nommu.c 2011-07-21 22:17:23.000000000 -0400
66192+++ linux-3.0.4/mm/nommu.c 2011-08-23 21:47:56.000000000 -0400
66193@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
66194 int sysctl_overcommit_ratio = 50; /* default is 50% */
66195 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
66196 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
66197-int heap_stack_gap = 0;
66198
66199 atomic_long_t mmap_pages_allocated;
66200
66201@@ -826,15 +825,6 @@ struct vm_area_struct *find_vma(struct m
66202 EXPORT_SYMBOL(find_vma);
66203
66204 /*
66205- * find a VMA
66206- * - we don't extend stack VMAs under NOMMU conditions
66207- */
66208-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
66209-{
66210- return find_vma(mm, addr);
66211-}
66212-
66213-/*
66214 * expand a stack to a given address
66215 * - not supported under NOMMU conditions
66216 */
66217@@ -1554,6 +1544,7 @@ int split_vma(struct mm_struct *mm, stru
66218
66219 /* most fields are the same, copy all, and then fixup */
66220 *new = *vma;
66221+ INIT_LIST_HEAD(&new->anon_vma_chain);
66222 *region = *vma->vm_region;
66223 new->vm_region = region;
66224
66225diff -urNp linux-3.0.4/mm/page_alloc.c linux-3.0.4/mm/page_alloc.c
66226--- linux-3.0.4/mm/page_alloc.c 2011-07-21 22:17:23.000000000 -0400
66227+++ linux-3.0.4/mm/page_alloc.c 2011-08-23 21:48:14.000000000 -0400
66228@@ -340,7 +340,7 @@ out:
66229 * This usage means that zero-order pages may not be compound.
66230 */
66231
66232-static void free_compound_page(struct page *page)
66233+void free_compound_page(struct page *page)
66234 {
66235 __free_pages_ok(page, compound_order(page));
66236 }
66237@@ -653,6 +653,10 @@ static bool free_pages_prepare(struct pa
66238 int i;
66239 int bad = 0;
66240
66241+#ifdef CONFIG_PAX_MEMORY_SANITIZE
66242+ unsigned long index = 1UL << order;
66243+#endif
66244+
66245 trace_mm_page_free_direct(page, order);
66246 kmemcheck_free_shadow(page, order);
66247
66248@@ -668,6 +672,12 @@ static bool free_pages_prepare(struct pa
66249 debug_check_no_obj_freed(page_address(page),
66250 PAGE_SIZE << order);
66251 }
66252+
66253+#ifdef CONFIG_PAX_MEMORY_SANITIZE
66254+ for (; index; --index)
66255+ sanitize_highpage(page + index - 1);
66256+#endif
66257+
66258 arch_free_page(page, order);
66259 kernel_map_pages(page, 1 << order, 0);
66260
66261@@ -783,8 +793,10 @@ static int prep_new_page(struct page *pa
66262 arch_alloc_page(page, order);
66263 kernel_map_pages(page, 1 << order, 1);
66264
66265+#ifndef CONFIG_PAX_MEMORY_SANITIZE
66266 if (gfp_flags & __GFP_ZERO)
66267 prep_zero_page(page, order, gfp_flags);
66268+#endif
66269
66270 if (order && (gfp_flags & __GFP_COMP))
66271 prep_compound_page(page, order);
66272@@ -2525,6 +2537,8 @@ void show_free_areas(unsigned int filter
66273 int cpu;
66274 struct zone *zone;
66275
66276+ pax_track_stack();
66277+
66278 for_each_populated_zone(zone) {
66279 if (skip_free_areas_node(filter, zone_to_nid(zone)))
66280 continue;
66281diff -urNp linux-3.0.4/mm/percpu.c linux-3.0.4/mm/percpu.c
66282--- linux-3.0.4/mm/percpu.c 2011-07-21 22:17:23.000000000 -0400
66283+++ linux-3.0.4/mm/percpu.c 2011-08-23 21:47:56.000000000 -0400
66284@@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
66285 static unsigned int pcpu_last_unit_cpu __read_mostly;
66286
66287 /* the address of the first chunk which starts with the kernel static area */
66288-void *pcpu_base_addr __read_mostly;
66289+void *pcpu_base_addr __read_only;
66290 EXPORT_SYMBOL_GPL(pcpu_base_addr);
66291
66292 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
66293diff -urNp linux-3.0.4/mm/rmap.c linux-3.0.4/mm/rmap.c
66294--- linux-3.0.4/mm/rmap.c 2011-07-21 22:17:23.000000000 -0400
66295+++ linux-3.0.4/mm/rmap.c 2011-08-23 21:47:56.000000000 -0400
66296@@ -153,6 +153,10 @@ int anon_vma_prepare(struct vm_area_stru
66297 struct anon_vma *anon_vma = vma->anon_vma;
66298 struct anon_vma_chain *avc;
66299
66300+#ifdef CONFIG_PAX_SEGMEXEC
66301+ struct anon_vma_chain *avc_m = NULL;
66302+#endif
66303+
66304 might_sleep();
66305 if (unlikely(!anon_vma)) {
66306 struct mm_struct *mm = vma->vm_mm;
66307@@ -162,6 +166,12 @@ int anon_vma_prepare(struct vm_area_stru
66308 if (!avc)
66309 goto out_enomem;
66310
66311+#ifdef CONFIG_PAX_SEGMEXEC
66312+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
66313+ if (!avc_m)
66314+ goto out_enomem_free_avc;
66315+#endif
66316+
66317 anon_vma = find_mergeable_anon_vma(vma);
66318 allocated = NULL;
66319 if (!anon_vma) {
66320@@ -175,6 +185,21 @@ int anon_vma_prepare(struct vm_area_stru
66321 /* page_table_lock to protect against threads */
66322 spin_lock(&mm->page_table_lock);
66323 if (likely(!vma->anon_vma)) {
66324+
66325+#ifdef CONFIG_PAX_SEGMEXEC
66326+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
66327+
66328+ if (vma_m) {
66329+ BUG_ON(vma_m->anon_vma);
66330+ vma_m->anon_vma = anon_vma;
66331+ avc_m->anon_vma = anon_vma;
66332+ avc_m->vma = vma;
66333+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
66334+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
66335+ avc_m = NULL;
66336+ }
66337+#endif
66338+
66339 vma->anon_vma = anon_vma;
66340 avc->anon_vma = anon_vma;
66341 avc->vma = vma;
66342@@ -188,12 +213,24 @@ int anon_vma_prepare(struct vm_area_stru
66343
66344 if (unlikely(allocated))
66345 put_anon_vma(allocated);
66346+
66347+#ifdef CONFIG_PAX_SEGMEXEC
66348+ if (unlikely(avc_m))
66349+ anon_vma_chain_free(avc_m);
66350+#endif
66351+
66352 if (unlikely(avc))
66353 anon_vma_chain_free(avc);
66354 }
66355 return 0;
66356
66357 out_enomem_free_avc:
66358+
66359+#ifdef CONFIG_PAX_SEGMEXEC
66360+ if (avc_m)
66361+ anon_vma_chain_free(avc_m);
66362+#endif
66363+
66364 anon_vma_chain_free(avc);
66365 out_enomem:
66366 return -ENOMEM;
66367@@ -244,7 +281,7 @@ static void anon_vma_chain_link(struct v
66368 * Attach the anon_vmas from src to dst.
66369 * Returns 0 on success, -ENOMEM on failure.
66370 */
66371-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
66372+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
66373 {
66374 struct anon_vma_chain *avc, *pavc;
66375 struct anon_vma *root = NULL;
66376@@ -277,7 +314,7 @@ int anon_vma_clone(struct vm_area_struct
66377 * the corresponding VMA in the parent process is attached to.
66378 * Returns 0 on success, non-zero on failure.
66379 */
66380-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
66381+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
66382 {
66383 struct anon_vma_chain *avc;
66384 struct anon_vma *anon_vma;
66385diff -urNp linux-3.0.4/mm/shmem.c linux-3.0.4/mm/shmem.c
66386--- linux-3.0.4/mm/shmem.c 2011-07-21 22:17:23.000000000 -0400
66387+++ linux-3.0.4/mm/shmem.c 2011-08-23 21:48:14.000000000 -0400
66388@@ -31,7 +31,7 @@
66389 #include <linux/percpu_counter.h>
66390 #include <linux/swap.h>
66391
66392-static struct vfsmount *shm_mnt;
66393+struct vfsmount *shm_mnt;
66394
66395 #ifdef CONFIG_SHMEM
66396 /*
66397@@ -1101,6 +1101,8 @@ static int shmem_writepage(struct page *
66398 goto unlock;
66399 }
66400 entry = shmem_swp_entry(info, index, NULL);
66401+ if (!entry)
66402+ goto unlock;
66403 if (entry->val) {
66404 /*
66405 * The more uptodate page coming down from a stacked
66406@@ -1172,6 +1174,8 @@ static struct page *shmem_swapin(swp_ent
66407 struct vm_area_struct pvma;
66408 struct page *page;
66409
66410+ pax_track_stack();
66411+
66412 spol = mpol_cond_copy(&mpol,
66413 mpol_shared_policy_lookup(&info->policy, idx));
66414
66415@@ -2568,8 +2572,7 @@ int shmem_fill_super(struct super_block
66416 int err = -ENOMEM;
66417
66418 /* Round up to L1_CACHE_BYTES to resist false sharing */
66419- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
66420- L1_CACHE_BYTES), GFP_KERNEL);
66421+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
66422 if (!sbinfo)
66423 return -ENOMEM;
66424
66425diff -urNp linux-3.0.4/mm/slab.c linux-3.0.4/mm/slab.c
66426--- linux-3.0.4/mm/slab.c 2011-07-21 22:17:23.000000000 -0400
66427+++ linux-3.0.4/mm/slab.c 2011-08-23 21:48:14.000000000 -0400
66428@@ -151,7 +151,7 @@
66429
66430 /* Legal flag mask for kmem_cache_create(). */
66431 #if DEBUG
66432-# define CREATE_MASK (SLAB_RED_ZONE | \
66433+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
66434 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
66435 SLAB_CACHE_DMA | \
66436 SLAB_STORE_USER | \
66437@@ -159,7 +159,7 @@
66438 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
66439 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
66440 #else
66441-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
66442+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
66443 SLAB_CACHE_DMA | \
66444 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
66445 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
66446@@ -288,7 +288,7 @@ struct kmem_list3 {
66447 * Need this for bootstrapping a per node allocator.
66448 */
66449 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
66450-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
66451+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
66452 #define CACHE_CACHE 0
66453 #define SIZE_AC MAX_NUMNODES
66454 #define SIZE_L3 (2 * MAX_NUMNODES)
66455@@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_
66456 if ((x)->max_freeable < i) \
66457 (x)->max_freeable = i; \
66458 } while (0)
66459-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
66460-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
66461-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
66462-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
66463+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
66464+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
66465+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
66466+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
66467 #else
66468 #define STATS_INC_ACTIVE(x) do { } while (0)
66469 #define STATS_DEC_ACTIVE(x) do { } while (0)
66470@@ -538,7 +538,7 @@ static inline void *index_to_obj(struct
66471 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
66472 */
66473 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
66474- const struct slab *slab, void *obj)
66475+ const struct slab *slab, const void *obj)
66476 {
66477 u32 offset = (obj - slab->s_mem);
66478 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
66479@@ -564,7 +564,7 @@ struct cache_names {
66480 static struct cache_names __initdata cache_names[] = {
66481 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
66482 #include <linux/kmalloc_sizes.h>
66483- {NULL,}
66484+ {NULL}
66485 #undef CACHE
66486 };
66487
66488@@ -1530,7 +1530,7 @@ void __init kmem_cache_init(void)
66489 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
66490 sizes[INDEX_AC].cs_size,
66491 ARCH_KMALLOC_MINALIGN,
66492- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
66493+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
66494 NULL);
66495
66496 if (INDEX_AC != INDEX_L3) {
66497@@ -1538,7 +1538,7 @@ void __init kmem_cache_init(void)
66498 kmem_cache_create(names[INDEX_L3].name,
66499 sizes[INDEX_L3].cs_size,
66500 ARCH_KMALLOC_MINALIGN,
66501- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
66502+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
66503 NULL);
66504 }
66505
66506@@ -1556,7 +1556,7 @@ void __init kmem_cache_init(void)
66507 sizes->cs_cachep = kmem_cache_create(names->name,
66508 sizes->cs_size,
66509 ARCH_KMALLOC_MINALIGN,
66510- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
66511+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
66512 NULL);
66513 }
66514 #ifdef CONFIG_ZONE_DMA
66515@@ -4272,10 +4272,10 @@ static int s_show(struct seq_file *m, vo
66516 }
66517 /* cpu stats */
66518 {
66519- unsigned long allochit = atomic_read(&cachep->allochit);
66520- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
66521- unsigned long freehit = atomic_read(&cachep->freehit);
66522- unsigned long freemiss = atomic_read(&cachep->freemiss);
66523+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
66524+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
66525+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
66526+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
66527
66528 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
66529 allochit, allocmiss, freehit, freemiss);
66530@@ -4532,15 +4532,66 @@ static const struct file_operations proc
66531
66532 static int __init slab_proc_init(void)
66533 {
66534- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
66535+ mode_t gr_mode = S_IRUGO;
66536+
66537+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66538+ gr_mode = S_IRUSR;
66539+#endif
66540+
66541+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
66542 #ifdef CONFIG_DEBUG_SLAB_LEAK
66543- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
66544+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
66545 #endif
66546 return 0;
66547 }
66548 module_init(slab_proc_init);
66549 #endif
66550
66551+void check_object_size(const void *ptr, unsigned long n, bool to)
66552+{
66553+
66554+#ifdef CONFIG_PAX_USERCOPY
66555+ struct page *page;
66556+ struct kmem_cache *cachep = NULL;
66557+ struct slab *slabp;
66558+ unsigned int objnr;
66559+ unsigned long offset;
66560+
66561+ if (!n)
66562+ return;
66563+
66564+ if (ZERO_OR_NULL_PTR(ptr))
66565+ goto report;
66566+
66567+ if (!virt_addr_valid(ptr))
66568+ return;
66569+
66570+ page = virt_to_head_page(ptr);
66571+
66572+ if (!PageSlab(page)) {
66573+ if (object_is_on_stack(ptr, n) == -1)
66574+ goto report;
66575+ return;
66576+ }
66577+
66578+ cachep = page_get_cache(page);
66579+ if (!(cachep->flags & SLAB_USERCOPY))
66580+ goto report;
66581+
66582+ slabp = page_get_slab(page);
66583+ objnr = obj_to_index(cachep, slabp, ptr);
66584+ BUG_ON(objnr >= cachep->num);
66585+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
66586+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
66587+ return;
66588+
66589+report:
66590+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
66591+#endif
66592+
66593+}
66594+EXPORT_SYMBOL(check_object_size);
66595+
66596 /**
66597 * ksize - get the actual amount of memory allocated for a given object
66598 * @objp: Pointer to the object
66599diff -urNp linux-3.0.4/mm/slob.c linux-3.0.4/mm/slob.c
66600--- linux-3.0.4/mm/slob.c 2011-07-21 22:17:23.000000000 -0400
66601+++ linux-3.0.4/mm/slob.c 2011-08-23 21:47:56.000000000 -0400
66602@@ -29,7 +29,7 @@
66603 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
66604 * alloc_pages() directly, allocating compound pages so the page order
66605 * does not have to be separately tracked, and also stores the exact
66606- * allocation size in page->private so that it can be used to accurately
66607+ * allocation size in slob_page->size so that it can be used to accurately
66608 * provide ksize(). These objects are detected in kfree() because slob_page()
66609 * is false for them.
66610 *
66611@@ -58,6 +58,7 @@
66612 */
66613
66614 #include <linux/kernel.h>
66615+#include <linux/sched.h>
66616 #include <linux/slab.h>
66617 #include <linux/mm.h>
66618 #include <linux/swap.h> /* struct reclaim_state */
66619@@ -102,7 +103,8 @@ struct slob_page {
66620 unsigned long flags; /* mandatory */
66621 atomic_t _count; /* mandatory */
66622 slobidx_t units; /* free units left in page */
66623- unsigned long pad[2];
66624+ unsigned long pad[1];
66625+ unsigned long size; /* size when >=PAGE_SIZE */
66626 slob_t *free; /* first free slob_t in page */
66627 struct list_head list; /* linked list of free pages */
66628 };
66629@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
66630 */
66631 static inline int is_slob_page(struct slob_page *sp)
66632 {
66633- return PageSlab((struct page *)sp);
66634+ return PageSlab((struct page *)sp) && !sp->size;
66635 }
66636
66637 static inline void set_slob_page(struct slob_page *sp)
66638@@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
66639
66640 static inline struct slob_page *slob_page(const void *addr)
66641 {
66642- return (struct slob_page *)virt_to_page(addr);
66643+ return (struct slob_page *)virt_to_head_page(addr);
66644 }
66645
66646 /*
66647@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
66648 /*
66649 * Return the size of a slob block.
66650 */
66651-static slobidx_t slob_units(slob_t *s)
66652+static slobidx_t slob_units(const slob_t *s)
66653 {
66654 if (s->units > 0)
66655 return s->units;
66656@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
66657 /*
66658 * Return the next free slob block pointer after this one.
66659 */
66660-static slob_t *slob_next(slob_t *s)
66661+static slob_t *slob_next(const slob_t *s)
66662 {
66663 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
66664 slobidx_t next;
66665@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
66666 /*
66667 * Returns true if s is the last free block in its page.
66668 */
66669-static int slob_last(slob_t *s)
66670+static int slob_last(const slob_t *s)
66671 {
66672 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
66673 }
66674@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
66675 if (!page)
66676 return NULL;
66677
66678+ set_slob_page(page);
66679 return page_address(page);
66680 }
66681
66682@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
66683 if (!b)
66684 return NULL;
66685 sp = slob_page(b);
66686- set_slob_page(sp);
66687
66688 spin_lock_irqsave(&slob_lock, flags);
66689 sp->units = SLOB_UNITS(PAGE_SIZE);
66690 sp->free = b;
66691+ sp->size = 0;
66692 INIT_LIST_HEAD(&sp->list);
66693 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
66694 set_slob_page_free(sp, slob_list);
66695@@ -476,10 +479,9 @@ out:
66696 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
66697 */
66698
66699-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
66700+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
66701 {
66702- unsigned int *m;
66703- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66704+ slob_t *m;
66705 void *ret;
66706
66707 lockdep_trace_alloc(gfp);
66708@@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
66709
66710 if (!m)
66711 return NULL;
66712- *m = size;
66713+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
66714+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
66715+ m[0].units = size;
66716+ m[1].units = align;
66717 ret = (void *)m + align;
66718
66719 trace_kmalloc_node(_RET_IP_, ret,
66720@@ -504,16 +509,25 @@ void *__kmalloc_node(size_t size, gfp_t
66721 gfp |= __GFP_COMP;
66722 ret = slob_new_pages(gfp, order, node);
66723 if (ret) {
66724- struct page *page;
66725- page = virt_to_page(ret);
66726- page->private = size;
66727+ struct slob_page *sp;
66728+ sp = slob_page(ret);
66729+ sp->size = size;
66730 }
66731
66732 trace_kmalloc_node(_RET_IP_, ret,
66733 size, PAGE_SIZE << order, gfp, node);
66734 }
66735
66736- kmemleak_alloc(ret, size, 1, gfp);
66737+ return ret;
66738+}
66739+
66740+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
66741+{
66742+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66743+ void *ret = __kmalloc_node_align(size, gfp, node, align);
66744+
66745+ if (!ZERO_OR_NULL_PTR(ret))
66746+ kmemleak_alloc(ret, size, 1, gfp);
66747 return ret;
66748 }
66749 EXPORT_SYMBOL(__kmalloc_node);
66750@@ -531,13 +545,88 @@ void kfree(const void *block)
66751 sp = slob_page(block);
66752 if (is_slob_page(sp)) {
66753 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66754- unsigned int *m = (unsigned int *)(block - align);
66755- slob_free(m, *m + align);
66756- } else
66757+ slob_t *m = (slob_t *)(block - align);
66758+ slob_free(m, m[0].units + align);
66759+ } else {
66760+ clear_slob_page(sp);
66761+ free_slob_page(sp);
66762+ sp->size = 0;
66763 put_page(&sp->page);
66764+ }
66765 }
66766 EXPORT_SYMBOL(kfree);
66767
66768+void check_object_size(const void *ptr, unsigned long n, bool to)
66769+{
66770+
66771+#ifdef CONFIG_PAX_USERCOPY
66772+ struct slob_page *sp;
66773+ const slob_t *free;
66774+ const void *base;
66775+ unsigned long flags;
66776+
66777+ if (!n)
66778+ return;
66779+
66780+ if (ZERO_OR_NULL_PTR(ptr))
66781+ goto report;
66782+
66783+ if (!virt_addr_valid(ptr))
66784+ return;
66785+
66786+ sp = slob_page(ptr);
66787+ if (!PageSlab((struct page*)sp)) {
66788+ if (object_is_on_stack(ptr, n) == -1)
66789+ goto report;
66790+ return;
66791+ }
66792+
66793+ if (sp->size) {
66794+ base = page_address(&sp->page);
66795+ if (base <= ptr && n <= sp->size - (ptr - base))
66796+ return;
66797+ goto report;
66798+ }
66799+
66800+ /* some tricky double walking to find the chunk */
66801+ spin_lock_irqsave(&slob_lock, flags);
66802+ base = (void *)((unsigned long)ptr & PAGE_MASK);
66803+ free = sp->free;
66804+
66805+ while (!slob_last(free) && (void *)free <= ptr) {
66806+ base = free + slob_units(free);
66807+ free = slob_next(free);
66808+ }
66809+
66810+ while (base < (void *)free) {
66811+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
66812+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
66813+ int offset;
66814+
66815+ if (ptr < base + align)
66816+ break;
66817+
66818+ offset = ptr - base - align;
66819+ if (offset >= m) {
66820+ base += size;
66821+ continue;
66822+ }
66823+
66824+ if (n > m - offset)
66825+ break;
66826+
66827+ spin_unlock_irqrestore(&slob_lock, flags);
66828+ return;
66829+ }
66830+
66831+ spin_unlock_irqrestore(&slob_lock, flags);
66832+report:
66833+ pax_report_usercopy(ptr, n, to, NULL);
66834+#endif
66835+
66836+}
66837+EXPORT_SYMBOL(check_object_size);
66838+
66839 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
66840 size_t ksize(const void *block)
66841 {
66842@@ -550,10 +639,10 @@ size_t ksize(const void *block)
66843 sp = slob_page(block);
66844 if (is_slob_page(sp)) {
66845 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66846- unsigned int *m = (unsigned int *)(block - align);
66847- return SLOB_UNITS(*m) * SLOB_UNIT;
66848+ slob_t *m = (slob_t *)(block - align);
66849+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
66850 } else
66851- return sp->page.private;
66852+ return sp->size;
66853 }
66854 EXPORT_SYMBOL(ksize);
66855
66856@@ -569,8 +658,13 @@ struct kmem_cache *kmem_cache_create(con
66857 {
66858 struct kmem_cache *c;
66859
66860+#ifdef CONFIG_PAX_USERCOPY
66861+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
66862+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
66863+#else
66864 c = slob_alloc(sizeof(struct kmem_cache),
66865 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
66866+#endif
66867
66868 if (c) {
66869 c->name = name;
66870@@ -608,17 +702,25 @@ void *kmem_cache_alloc_node(struct kmem_
66871 {
66872 void *b;
66873
66874+#ifdef CONFIG_PAX_USERCOPY
66875+ b = __kmalloc_node_align(c->size, flags, node, c->align);
66876+#else
66877 if (c->size < PAGE_SIZE) {
66878 b = slob_alloc(c->size, flags, c->align, node);
66879 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
66880 SLOB_UNITS(c->size) * SLOB_UNIT,
66881 flags, node);
66882 } else {
66883+ struct slob_page *sp;
66884+
66885 b = slob_new_pages(flags, get_order(c->size), node);
66886+ sp = slob_page(b);
66887+ sp->size = c->size;
66888 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
66889 PAGE_SIZE << get_order(c->size),
66890 flags, node);
66891 }
66892+#endif
66893
66894 if (c->ctor)
66895 c->ctor(b);
66896@@ -630,10 +732,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
66897
66898 static void __kmem_cache_free(void *b, int size)
66899 {
66900- if (size < PAGE_SIZE)
66901+ struct slob_page *sp = slob_page(b);
66902+
66903+ if (is_slob_page(sp))
66904 slob_free(b, size);
66905- else
66906+ else {
66907+ clear_slob_page(sp);
66908+ free_slob_page(sp);
66909+ sp->size = 0;
66910 slob_free_pages(b, get_order(size));
66911+ }
66912 }
66913
66914 static void kmem_rcu_free(struct rcu_head *head)
66915@@ -646,17 +754,31 @@ static void kmem_rcu_free(struct rcu_hea
66916
66917 void kmem_cache_free(struct kmem_cache *c, void *b)
66918 {
66919+ int size = c->size;
66920+
66921+#ifdef CONFIG_PAX_USERCOPY
66922+ if (size + c->align < PAGE_SIZE) {
66923+ size += c->align;
66924+ b -= c->align;
66925+ }
66926+#endif
66927+
66928 kmemleak_free_recursive(b, c->flags);
66929 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
66930 struct slob_rcu *slob_rcu;
66931- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
66932- slob_rcu->size = c->size;
66933+ slob_rcu = b + (size - sizeof(struct slob_rcu));
66934+ slob_rcu->size = size;
66935 call_rcu(&slob_rcu->head, kmem_rcu_free);
66936 } else {
66937- __kmem_cache_free(b, c->size);
66938+ __kmem_cache_free(b, size);
66939 }
66940
66941+#ifdef CONFIG_PAX_USERCOPY
66942+ trace_kfree(_RET_IP_, b);
66943+#else
66944 trace_kmem_cache_free(_RET_IP_, b);
66945+#endif
66946+
66947 }
66948 EXPORT_SYMBOL(kmem_cache_free);
66949
66950diff -urNp linux-3.0.4/mm/slub.c linux-3.0.4/mm/slub.c
66951--- linux-3.0.4/mm/slub.c 2011-07-21 22:17:23.000000000 -0400
66952+++ linux-3.0.4/mm/slub.c 2011-08-23 21:48:14.000000000 -0400
66953@@ -442,7 +442,7 @@ static void print_track(const char *s, s
66954 if (!t->addr)
66955 return;
66956
66957- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
66958+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
66959 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
66960 }
66961
66962@@ -2137,6 +2137,8 @@ void kmem_cache_free(struct kmem_cache *
66963
66964 page = virt_to_head_page(x);
66965
66966+ BUG_ON(!PageSlab(page));
66967+
66968 slab_free(s, page, x, _RET_IP_);
66969
66970 trace_kmem_cache_free(_RET_IP_, x);
66971@@ -2170,7 +2172,7 @@ static int slub_min_objects;
66972 * Merge control. If this is set then no merging of slab caches will occur.
66973 * (Could be removed. This was introduced to pacify the merge skeptics.)
66974 */
66975-static int slub_nomerge;
66976+static int slub_nomerge = 1;
66977
66978 /*
66979 * Calculate the order of allocation given an slab object size.
66980@@ -2594,7 +2596,7 @@ static int kmem_cache_open(struct kmem_c
66981 * list to avoid pounding the page allocator excessively.
66982 */
66983 set_min_partial(s, ilog2(s->size));
66984- s->refcount = 1;
66985+ atomic_set(&s->refcount, 1);
66986 #ifdef CONFIG_NUMA
66987 s->remote_node_defrag_ratio = 1000;
66988 #endif
66989@@ -2699,8 +2701,7 @@ static inline int kmem_cache_close(struc
66990 void kmem_cache_destroy(struct kmem_cache *s)
66991 {
66992 down_write(&slub_lock);
66993- s->refcount--;
66994- if (!s->refcount) {
66995+ if (atomic_dec_and_test(&s->refcount)) {
66996 list_del(&s->list);
66997 if (kmem_cache_close(s)) {
66998 printk(KERN_ERR "SLUB %s: %s called for cache that "
66999@@ -2910,6 +2911,46 @@ void *__kmalloc_node(size_t size, gfp_t
67000 EXPORT_SYMBOL(__kmalloc_node);
67001 #endif
67002
67003+void check_object_size(const void *ptr, unsigned long n, bool to)
67004+{
67005+
67006+#ifdef CONFIG_PAX_USERCOPY
67007+ struct page *page;
67008+ struct kmem_cache *s = NULL;
67009+ unsigned long offset;
67010+
67011+ if (!n)
67012+ return;
67013+
67014+ if (ZERO_OR_NULL_PTR(ptr))
67015+ goto report;
67016+
67017+ if (!virt_addr_valid(ptr))
67018+ return;
67019+
67020+ page = virt_to_head_page(ptr);
67021+
67022+ if (!PageSlab(page)) {
67023+ if (object_is_on_stack(ptr, n) == -1)
67024+ goto report;
67025+ return;
67026+ }
67027+
67028+ s = page->slab;
67029+ if (!(s->flags & SLAB_USERCOPY))
67030+ goto report;
67031+
67032+ offset = (ptr - page_address(page)) % s->size;
67033+ if (offset <= s->objsize && n <= s->objsize - offset)
67034+ return;
67035+
67036+report:
67037+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
67038+#endif
67039+
67040+}
67041+EXPORT_SYMBOL(check_object_size);
67042+
67043 size_t ksize(const void *object)
67044 {
67045 struct page *page;
67046@@ -3154,7 +3195,7 @@ static void __init kmem_cache_bootstrap_
67047 int node;
67048
67049 list_add(&s->list, &slab_caches);
67050- s->refcount = -1;
67051+ atomic_set(&s->refcount, -1);
67052
67053 for_each_node_state(node, N_NORMAL_MEMORY) {
67054 struct kmem_cache_node *n = get_node(s, node);
67055@@ -3271,17 +3312,17 @@ void __init kmem_cache_init(void)
67056
67057 /* Caches that are not of the two-to-the-power-of size */
67058 if (KMALLOC_MIN_SIZE <= 32) {
67059- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
67060+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
67061 caches++;
67062 }
67063
67064 if (KMALLOC_MIN_SIZE <= 64) {
67065- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
67066+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
67067 caches++;
67068 }
67069
67070 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
67071- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
67072+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
67073 caches++;
67074 }
67075
67076@@ -3349,7 +3390,7 @@ static int slab_unmergeable(struct kmem_
67077 /*
67078 * We may have set a slab to be unmergeable during bootstrap.
67079 */
67080- if (s->refcount < 0)
67081+ if (atomic_read(&s->refcount) < 0)
67082 return 1;
67083
67084 return 0;
67085@@ -3408,7 +3449,7 @@ struct kmem_cache *kmem_cache_create(con
67086 down_write(&slub_lock);
67087 s = find_mergeable(size, align, flags, name, ctor);
67088 if (s) {
67089- s->refcount++;
67090+ atomic_inc(&s->refcount);
67091 /*
67092 * Adjust the object sizes so that we clear
67093 * the complete object on kzalloc.
67094@@ -3417,7 +3458,7 @@ struct kmem_cache *kmem_cache_create(con
67095 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
67096
67097 if (sysfs_slab_alias(s, name)) {
67098- s->refcount--;
67099+ atomic_dec(&s->refcount);
67100 goto err;
67101 }
67102 up_write(&slub_lock);
67103@@ -4150,7 +4191,7 @@ SLAB_ATTR_RO(ctor);
67104
67105 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
67106 {
67107- return sprintf(buf, "%d\n", s->refcount - 1);
67108+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
67109 }
67110 SLAB_ATTR_RO(aliases);
67111
67112@@ -4894,7 +4935,13 @@ static const struct file_operations proc
67113
67114 static int __init slab_proc_init(void)
67115 {
67116- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
67117+ mode_t gr_mode = S_IRUGO;
67118+
67119+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67120+ gr_mode = S_IRUSR;
67121+#endif
67122+
67123+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
67124 return 0;
67125 }
67126 module_init(slab_proc_init);
67127diff -urNp linux-3.0.4/mm/swap.c linux-3.0.4/mm/swap.c
67128--- linux-3.0.4/mm/swap.c 2011-07-21 22:17:23.000000000 -0400
67129+++ linux-3.0.4/mm/swap.c 2011-08-23 21:47:56.000000000 -0400
67130@@ -31,6 +31,7 @@
67131 #include <linux/backing-dev.h>
67132 #include <linux/memcontrol.h>
67133 #include <linux/gfp.h>
67134+#include <linux/hugetlb.h>
67135
67136 #include "internal.h"
67137
67138@@ -71,6 +72,8 @@ static void __put_compound_page(struct p
67139
67140 __page_cache_release(page);
67141 dtor = get_compound_page_dtor(page);
67142+ if (!PageHuge(page))
67143+ BUG_ON(dtor != free_compound_page);
67144 (*dtor)(page);
67145 }
67146
67147diff -urNp linux-3.0.4/mm/swapfile.c linux-3.0.4/mm/swapfile.c
67148--- linux-3.0.4/mm/swapfile.c 2011-07-21 22:17:23.000000000 -0400
67149+++ linux-3.0.4/mm/swapfile.c 2011-08-23 21:47:56.000000000 -0400
67150@@ -62,7 +62,7 @@ static DEFINE_MUTEX(swapon_mutex);
67151
67152 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
67153 /* Activity counter to indicate that a swapon or swapoff has occurred */
67154-static atomic_t proc_poll_event = ATOMIC_INIT(0);
67155+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
67156
67157 static inline unsigned char swap_count(unsigned char ent)
67158 {
67159@@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
67160 }
67161 filp_close(swap_file, NULL);
67162 err = 0;
67163- atomic_inc(&proc_poll_event);
67164+ atomic_inc_unchecked(&proc_poll_event);
67165 wake_up_interruptible(&proc_poll_wait);
67166
67167 out_dput:
67168@@ -1692,8 +1692,8 @@ static unsigned swaps_poll(struct file *
67169
67170 poll_wait(file, &proc_poll_wait, wait);
67171
67172- if (s->event != atomic_read(&proc_poll_event)) {
67173- s->event = atomic_read(&proc_poll_event);
67174+ if (s->event != atomic_read_unchecked(&proc_poll_event)) {
67175+ s->event = atomic_read_unchecked(&proc_poll_event);
67176 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
67177 }
67178
67179@@ -1799,7 +1799,7 @@ static int swaps_open(struct inode *inod
67180 }
67181
67182 s->seq.private = s;
67183- s->event = atomic_read(&proc_poll_event);
67184+ s->event = atomic_read_unchecked(&proc_poll_event);
67185 return ret;
67186 }
67187
67188@@ -2133,7 +2133,7 @@ SYSCALL_DEFINE2(swapon, const char __use
67189 (p->flags & SWP_DISCARDABLE) ? "D" : "");
67190
67191 mutex_unlock(&swapon_mutex);
67192- atomic_inc(&proc_poll_event);
67193+ atomic_inc_unchecked(&proc_poll_event);
67194 wake_up_interruptible(&proc_poll_wait);
67195
67196 if (S_ISREG(inode->i_mode))
67197diff -urNp linux-3.0.4/mm/util.c linux-3.0.4/mm/util.c
67198--- linux-3.0.4/mm/util.c 2011-07-21 22:17:23.000000000 -0400
67199+++ linux-3.0.4/mm/util.c 2011-08-23 21:47:56.000000000 -0400
67200@@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
67201 * allocated buffer. Use this if you don't want to free the buffer immediately
67202 * like, for example, with RCU.
67203 */
67204+#undef __krealloc
67205 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
67206 {
67207 void *ret;
67208@@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
67209 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
67210 * %NULL pointer, the object pointed to is freed.
67211 */
67212+#undef krealloc
67213 void *krealloc(const void *p, size_t new_size, gfp_t flags)
67214 {
67215 void *ret;
67216@@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *m
67217 void arch_pick_mmap_layout(struct mm_struct *mm)
67218 {
67219 mm->mmap_base = TASK_UNMAPPED_BASE;
67220+
67221+#ifdef CONFIG_PAX_RANDMMAP
67222+ if (mm->pax_flags & MF_PAX_RANDMMAP)
67223+ mm->mmap_base += mm->delta_mmap;
67224+#endif
67225+
67226 mm->get_unmapped_area = arch_get_unmapped_area;
67227 mm->unmap_area = arch_unmap_area;
67228 }
67229diff -urNp linux-3.0.4/mm/vmalloc.c linux-3.0.4/mm/vmalloc.c
67230--- linux-3.0.4/mm/vmalloc.c 2011-09-02 18:11:21.000000000 -0400
67231+++ linux-3.0.4/mm/vmalloc.c 2011-08-23 21:47:56.000000000 -0400
67232@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
67233
67234 pte = pte_offset_kernel(pmd, addr);
67235 do {
67236- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
67237- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
67238+
67239+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67240+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
67241+ BUG_ON(!pte_exec(*pte));
67242+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
67243+ continue;
67244+ }
67245+#endif
67246+
67247+ {
67248+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
67249+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
67250+ }
67251 } while (pte++, addr += PAGE_SIZE, addr != end);
67252 }
67253
67254@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
67255 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
67256 {
67257 pte_t *pte;
67258+ int ret = -ENOMEM;
67259
67260 /*
67261 * nr is a running index into the array which helps higher level
67262@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
67263 pte = pte_alloc_kernel(pmd, addr);
67264 if (!pte)
67265 return -ENOMEM;
67266+
67267+ pax_open_kernel();
67268 do {
67269 struct page *page = pages[*nr];
67270
67271- if (WARN_ON(!pte_none(*pte)))
67272- return -EBUSY;
67273- if (WARN_ON(!page))
67274- return -ENOMEM;
67275+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67276+ if (pgprot_val(prot) & _PAGE_NX)
67277+#endif
67278+
67279+ if (WARN_ON(!pte_none(*pte))) {
67280+ ret = -EBUSY;
67281+ goto out;
67282+ }
67283+ if (WARN_ON(!page)) {
67284+ ret = -ENOMEM;
67285+ goto out;
67286+ }
67287 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
67288 (*nr)++;
67289 } while (pte++, addr += PAGE_SIZE, addr != end);
67290- return 0;
67291+ ret = 0;
67292+out:
67293+ pax_close_kernel();
67294+ return ret;
67295 }
67296
67297 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
67298@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
67299 * and fall back on vmalloc() if that fails. Others
67300 * just put it in the vmalloc space.
67301 */
67302-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
67303+#ifdef CONFIG_MODULES
67304+#ifdef MODULES_VADDR
67305 unsigned long addr = (unsigned long)x;
67306 if (addr >= MODULES_VADDR && addr < MODULES_END)
67307 return 1;
67308 #endif
67309+
67310+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67311+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
67312+ return 1;
67313+#endif
67314+
67315+#endif
67316+
67317 return is_vmalloc_addr(x);
67318 }
67319
67320@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
67321
67322 if (!pgd_none(*pgd)) {
67323 pud_t *pud = pud_offset(pgd, addr);
67324+#ifdef CONFIG_X86
67325+ if (!pud_large(*pud))
67326+#endif
67327 if (!pud_none(*pud)) {
67328 pmd_t *pmd = pmd_offset(pud, addr);
67329+#ifdef CONFIG_X86
67330+ if (!pmd_large(*pmd))
67331+#endif
67332 if (!pmd_none(*pmd)) {
67333 pte_t *ptep, pte;
67334
67335@@ -1297,6 +1337,16 @@ static struct vm_struct *__get_vm_area_n
67336 struct vm_struct *area;
67337
67338 BUG_ON(in_interrupt());
67339+
67340+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67341+ if (flags & VM_KERNEXEC) {
67342+ if (start != VMALLOC_START || end != VMALLOC_END)
67343+ return NULL;
67344+ start = (unsigned long)MODULES_EXEC_VADDR;
67345+ end = (unsigned long)MODULES_EXEC_END;
67346+ }
67347+#endif
67348+
67349 if (flags & VM_IOREMAP) {
67350 int bit = fls(size);
67351
67352@@ -1515,6 +1565,11 @@ void *vmap(struct page **pages, unsigned
67353 if (count > totalram_pages)
67354 return NULL;
67355
67356+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67357+ if (!(pgprot_val(prot) & _PAGE_NX))
67358+ flags |= VM_KERNEXEC;
67359+#endif
67360+
67361 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
67362 __builtin_return_address(0));
67363 if (!area)
67364@@ -1616,6 +1671,13 @@ void *__vmalloc_node_range(unsigned long
67365 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
67366 return NULL;
67367
67368+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67369+ if (!(pgprot_val(prot) & _PAGE_NX))
67370+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
67371+ node, gfp_mask, caller);
67372+ else
67373+#endif
67374+
67375 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
67376 gfp_mask, caller);
67377
67378@@ -1655,6 +1717,7 @@ static void *__vmalloc_node(unsigned lon
67379 gfp_mask, prot, node, caller);
67380 }
67381
67382+#undef __vmalloc
67383 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
67384 {
67385 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
67386@@ -1678,6 +1741,7 @@ static inline void *__vmalloc_node_flags
67387 * For tight control over page level allocator and protection flags
67388 * use __vmalloc() instead.
67389 */
67390+#undef vmalloc
67391 void *vmalloc(unsigned long size)
67392 {
67393 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
67394@@ -1694,6 +1758,7 @@ EXPORT_SYMBOL(vmalloc);
67395 * For tight control over page level allocator and protection flags
67396 * use __vmalloc() instead.
67397 */
67398+#undef vzalloc
67399 void *vzalloc(unsigned long size)
67400 {
67401 return __vmalloc_node_flags(size, -1,
67402@@ -1708,6 +1773,7 @@ EXPORT_SYMBOL(vzalloc);
67403 * The resulting memory area is zeroed so it can be mapped to userspace
67404 * without leaking data.
67405 */
67406+#undef vmalloc_user
67407 void *vmalloc_user(unsigned long size)
67408 {
67409 struct vm_struct *area;
67410@@ -1735,6 +1801,7 @@ EXPORT_SYMBOL(vmalloc_user);
67411 * For tight control over page level allocator and protection flags
67412 * use __vmalloc() instead.
67413 */
67414+#undef vmalloc_node
67415 void *vmalloc_node(unsigned long size, int node)
67416 {
67417 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
67418@@ -1754,6 +1821,7 @@ EXPORT_SYMBOL(vmalloc_node);
67419 * For tight control over page level allocator and protection flags
67420 * use __vmalloc_node() instead.
67421 */
67422+#undef vzalloc_node
67423 void *vzalloc_node(unsigned long size, int node)
67424 {
67425 return __vmalloc_node_flags(size, node,
67426@@ -1776,10 +1844,10 @@ EXPORT_SYMBOL(vzalloc_node);
67427 * For tight control over page level allocator and protection flags
67428 * use __vmalloc() instead.
67429 */
67430-
67431+#undef vmalloc_exec
67432 void *vmalloc_exec(unsigned long size)
67433 {
67434- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
67435+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
67436 -1, __builtin_return_address(0));
67437 }
67438
67439@@ -1798,6 +1866,7 @@ void *vmalloc_exec(unsigned long size)
67440 * Allocate enough 32bit PA addressable pages to cover @size from the
67441 * page level allocator and map them into contiguous kernel virtual space.
67442 */
67443+#undef vmalloc_32
67444 void *vmalloc_32(unsigned long size)
67445 {
67446 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
67447@@ -1812,6 +1881,7 @@ EXPORT_SYMBOL(vmalloc_32);
67448 * The resulting memory area is 32bit addressable and zeroed so it can be
67449 * mapped to userspace without leaking data.
67450 */
67451+#undef vmalloc_32_user
67452 void *vmalloc_32_user(unsigned long size)
67453 {
67454 struct vm_struct *area;
67455@@ -2074,6 +2144,8 @@ int remap_vmalloc_range(struct vm_area_s
67456 unsigned long uaddr = vma->vm_start;
67457 unsigned long usize = vma->vm_end - vma->vm_start;
67458
67459+ BUG_ON(vma->vm_mirror);
67460+
67461 if ((PAGE_SIZE-1) & (unsigned long)addr)
67462 return -EINVAL;
67463
67464diff -urNp linux-3.0.4/mm/vmstat.c linux-3.0.4/mm/vmstat.c
67465--- linux-3.0.4/mm/vmstat.c 2011-07-21 22:17:23.000000000 -0400
67466+++ linux-3.0.4/mm/vmstat.c 2011-08-23 21:48:14.000000000 -0400
67467@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
67468 *
67469 * vm_stat contains the global counters
67470 */
67471-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67472+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67473 EXPORT_SYMBOL(vm_stat);
67474
67475 #ifdef CONFIG_SMP
67476@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
67477 v = p->vm_stat_diff[i];
67478 p->vm_stat_diff[i] = 0;
67479 local_irq_restore(flags);
67480- atomic_long_add(v, &zone->vm_stat[i]);
67481+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
67482 global_diff[i] += v;
67483 #ifdef CONFIG_NUMA
67484 /* 3 seconds idle till flush */
67485@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
67486
67487 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
67488 if (global_diff[i])
67489- atomic_long_add(global_diff[i], &vm_stat[i]);
67490+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
67491 }
67492
67493 #endif
67494@@ -1207,10 +1207,20 @@ static int __init setup_vmstat(void)
67495 start_cpu_timer(cpu);
67496 #endif
67497 #ifdef CONFIG_PROC_FS
67498- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
67499- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
67500- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
67501- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
67502+ {
67503+ mode_t gr_mode = S_IRUGO;
67504+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67505+ gr_mode = S_IRUSR;
67506+#endif
67507+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
67508+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
67509+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67510+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
67511+#else
67512+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
67513+#endif
67514+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
67515+ }
67516 #endif
67517 return 0;
67518 }
67519diff -urNp linux-3.0.4/net/8021q/vlan.c linux-3.0.4/net/8021q/vlan.c
67520--- linux-3.0.4/net/8021q/vlan.c 2011-07-21 22:17:23.000000000 -0400
67521+++ linux-3.0.4/net/8021q/vlan.c 2011-08-23 21:47:56.000000000 -0400
67522@@ -591,8 +591,7 @@ static int vlan_ioctl_handler(struct net
67523 err = -EPERM;
67524 if (!capable(CAP_NET_ADMIN))
67525 break;
67526- if ((args.u.name_type >= 0) &&
67527- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
67528+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
67529 struct vlan_net *vn;
67530
67531 vn = net_generic(net, vlan_net_id);
67532diff -urNp linux-3.0.4/net/atm/atm_misc.c linux-3.0.4/net/atm/atm_misc.c
67533--- linux-3.0.4/net/atm/atm_misc.c 2011-07-21 22:17:23.000000000 -0400
67534+++ linux-3.0.4/net/atm/atm_misc.c 2011-08-23 21:47:56.000000000 -0400
67535@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
67536 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
67537 return 1;
67538 atm_return(vcc, truesize);
67539- atomic_inc(&vcc->stats->rx_drop);
67540+ atomic_inc_unchecked(&vcc->stats->rx_drop);
67541 return 0;
67542 }
67543 EXPORT_SYMBOL(atm_charge);
67544@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
67545 }
67546 }
67547 atm_return(vcc, guess);
67548- atomic_inc(&vcc->stats->rx_drop);
67549+ atomic_inc_unchecked(&vcc->stats->rx_drop);
67550 return NULL;
67551 }
67552 EXPORT_SYMBOL(atm_alloc_charge);
67553@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
67554
67555 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
67556 {
67557-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
67558+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
67559 __SONET_ITEMS
67560 #undef __HANDLE_ITEM
67561 }
67562@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
67563
67564 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
67565 {
67566-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
67567+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
67568 __SONET_ITEMS
67569 #undef __HANDLE_ITEM
67570 }
67571diff -urNp linux-3.0.4/net/atm/lec.h linux-3.0.4/net/atm/lec.h
67572--- linux-3.0.4/net/atm/lec.h 2011-07-21 22:17:23.000000000 -0400
67573+++ linux-3.0.4/net/atm/lec.h 2011-08-23 21:47:56.000000000 -0400
67574@@ -48,7 +48,7 @@ struct lane2_ops {
67575 const u8 *tlvs, u32 sizeoftlvs);
67576 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
67577 const u8 *tlvs, u32 sizeoftlvs);
67578-};
67579+} __no_const;
67580
67581 /*
67582 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
67583diff -urNp linux-3.0.4/net/atm/mpc.h linux-3.0.4/net/atm/mpc.h
67584--- linux-3.0.4/net/atm/mpc.h 2011-07-21 22:17:23.000000000 -0400
67585+++ linux-3.0.4/net/atm/mpc.h 2011-08-23 21:47:56.000000000 -0400
67586@@ -33,7 +33,7 @@ struct mpoa_client {
67587 struct mpc_parameters parameters; /* parameters for this client */
67588
67589 const struct net_device_ops *old_ops;
67590- struct net_device_ops new_ops;
67591+ net_device_ops_no_const new_ops;
67592 };
67593
67594
67595diff -urNp linux-3.0.4/net/atm/mpoa_caches.c linux-3.0.4/net/atm/mpoa_caches.c
67596--- linux-3.0.4/net/atm/mpoa_caches.c 2011-07-21 22:17:23.000000000 -0400
67597+++ linux-3.0.4/net/atm/mpoa_caches.c 2011-08-23 21:48:14.000000000 -0400
67598@@ -255,6 +255,8 @@ static void check_resolving_entries(stru
67599 struct timeval now;
67600 struct k_message msg;
67601
67602+ pax_track_stack();
67603+
67604 do_gettimeofday(&now);
67605
67606 read_lock_bh(&client->ingress_lock);
67607diff -urNp linux-3.0.4/net/atm/proc.c linux-3.0.4/net/atm/proc.c
67608--- linux-3.0.4/net/atm/proc.c 2011-07-21 22:17:23.000000000 -0400
67609+++ linux-3.0.4/net/atm/proc.c 2011-08-23 21:47:56.000000000 -0400
67610@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
67611 const struct k_atm_aal_stats *stats)
67612 {
67613 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
67614- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
67615- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
67616- atomic_read(&stats->rx_drop));
67617+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
67618+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
67619+ atomic_read_unchecked(&stats->rx_drop));
67620 }
67621
67622 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
67623diff -urNp linux-3.0.4/net/atm/resources.c linux-3.0.4/net/atm/resources.c
67624--- linux-3.0.4/net/atm/resources.c 2011-07-21 22:17:23.000000000 -0400
67625+++ linux-3.0.4/net/atm/resources.c 2011-08-23 21:47:56.000000000 -0400
67626@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
67627 static void copy_aal_stats(struct k_atm_aal_stats *from,
67628 struct atm_aal_stats *to)
67629 {
67630-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
67631+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
67632 __AAL_STAT_ITEMS
67633 #undef __HANDLE_ITEM
67634 }
67635@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
67636 static void subtract_aal_stats(struct k_atm_aal_stats *from,
67637 struct atm_aal_stats *to)
67638 {
67639-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
67640+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
67641 __AAL_STAT_ITEMS
67642 #undef __HANDLE_ITEM
67643 }
67644diff -urNp linux-3.0.4/net/batman-adv/hard-interface.c linux-3.0.4/net/batman-adv/hard-interface.c
67645--- linux-3.0.4/net/batman-adv/hard-interface.c 2011-07-21 22:17:23.000000000 -0400
67646+++ linux-3.0.4/net/batman-adv/hard-interface.c 2011-08-23 21:47:56.000000000 -0400
67647@@ -351,8 +351,8 @@ int hardif_enable_interface(struct hard_
67648 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
67649 dev_add_pack(&hard_iface->batman_adv_ptype);
67650
67651- atomic_set(&hard_iface->seqno, 1);
67652- atomic_set(&hard_iface->frag_seqno, 1);
67653+ atomic_set_unchecked(&hard_iface->seqno, 1);
67654+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
67655 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
67656 hard_iface->net_dev->name);
67657
67658diff -urNp linux-3.0.4/net/batman-adv/routing.c linux-3.0.4/net/batman-adv/routing.c
67659--- linux-3.0.4/net/batman-adv/routing.c 2011-07-21 22:17:23.000000000 -0400
67660+++ linux-3.0.4/net/batman-adv/routing.c 2011-08-23 21:47:56.000000000 -0400
67661@@ -627,7 +627,7 @@ void receive_bat_packet(struct ethhdr *e
67662 return;
67663
67664 /* could be changed by schedule_own_packet() */
67665- if_incoming_seqno = atomic_read(&if_incoming->seqno);
67666+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
67667
67668 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
67669
67670diff -urNp linux-3.0.4/net/batman-adv/send.c linux-3.0.4/net/batman-adv/send.c
67671--- linux-3.0.4/net/batman-adv/send.c 2011-07-21 22:17:23.000000000 -0400
67672+++ linux-3.0.4/net/batman-adv/send.c 2011-08-23 21:47:56.000000000 -0400
67673@@ -279,7 +279,7 @@ void schedule_own_packet(struct hard_ifa
67674
67675 /* change sequence number to network order */
67676 batman_packet->seqno =
67677- htonl((uint32_t)atomic_read(&hard_iface->seqno));
67678+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
67679
67680 if (vis_server == VIS_TYPE_SERVER_SYNC)
67681 batman_packet->flags |= VIS_SERVER;
67682@@ -293,7 +293,7 @@ void schedule_own_packet(struct hard_ifa
67683 else
67684 batman_packet->gw_flags = 0;
67685
67686- atomic_inc(&hard_iface->seqno);
67687+ atomic_inc_unchecked(&hard_iface->seqno);
67688
67689 slide_own_bcast_window(hard_iface);
67690 send_time = own_send_time(bat_priv);
67691diff -urNp linux-3.0.4/net/batman-adv/soft-interface.c linux-3.0.4/net/batman-adv/soft-interface.c
67692--- linux-3.0.4/net/batman-adv/soft-interface.c 2011-07-21 22:17:23.000000000 -0400
67693+++ linux-3.0.4/net/batman-adv/soft-interface.c 2011-08-23 21:47:56.000000000 -0400
67694@@ -628,7 +628,7 @@ int interface_tx(struct sk_buff *skb, st
67695
67696 /* set broadcast sequence number */
67697 bcast_packet->seqno =
67698- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
67699+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
67700
67701 add_bcast_packet_to_list(bat_priv, skb);
67702
67703@@ -830,7 +830,7 @@ struct net_device *softif_create(char *n
67704 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
67705
67706 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
67707- atomic_set(&bat_priv->bcast_seqno, 1);
67708+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
67709 atomic_set(&bat_priv->tt_local_changed, 0);
67710
67711 bat_priv->primary_if = NULL;
67712diff -urNp linux-3.0.4/net/batman-adv/types.h linux-3.0.4/net/batman-adv/types.h
67713--- linux-3.0.4/net/batman-adv/types.h 2011-07-21 22:17:23.000000000 -0400
67714+++ linux-3.0.4/net/batman-adv/types.h 2011-08-23 21:47:56.000000000 -0400
67715@@ -38,8 +38,8 @@ struct hard_iface {
67716 int16_t if_num;
67717 char if_status;
67718 struct net_device *net_dev;
67719- atomic_t seqno;
67720- atomic_t frag_seqno;
67721+ atomic_unchecked_t seqno;
67722+ atomic_unchecked_t frag_seqno;
67723 unsigned char *packet_buff;
67724 int packet_len;
67725 struct kobject *hardif_obj;
67726@@ -142,7 +142,7 @@ struct bat_priv {
67727 atomic_t orig_interval; /* uint */
67728 atomic_t hop_penalty; /* uint */
67729 atomic_t log_level; /* uint */
67730- atomic_t bcast_seqno;
67731+ atomic_unchecked_t bcast_seqno;
67732 atomic_t bcast_queue_left;
67733 atomic_t batman_queue_left;
67734 char num_ifaces;
67735diff -urNp linux-3.0.4/net/batman-adv/unicast.c linux-3.0.4/net/batman-adv/unicast.c
67736--- linux-3.0.4/net/batman-adv/unicast.c 2011-07-21 22:17:23.000000000 -0400
67737+++ linux-3.0.4/net/batman-adv/unicast.c 2011-08-23 21:47:56.000000000 -0400
67738@@ -265,7 +265,7 @@ int frag_send_skb(struct sk_buff *skb, s
67739 frag1->flags = UNI_FRAG_HEAD | large_tail;
67740 frag2->flags = large_tail;
67741
67742- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
67743+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
67744 frag1->seqno = htons(seqno - 1);
67745 frag2->seqno = htons(seqno);
67746
67747diff -urNp linux-3.0.4/net/bridge/br_multicast.c linux-3.0.4/net/bridge/br_multicast.c
67748--- linux-3.0.4/net/bridge/br_multicast.c 2011-07-21 22:17:23.000000000 -0400
67749+++ linux-3.0.4/net/bridge/br_multicast.c 2011-08-23 21:47:56.000000000 -0400
67750@@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct
67751 nexthdr = ip6h->nexthdr;
67752 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
67753
67754- if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
67755+ if (nexthdr != IPPROTO_ICMPV6)
67756 return 0;
67757
67758 /* Okay, we found ICMPv6 header */
67759diff -urNp linux-3.0.4/net/bridge/netfilter/ebtables.c linux-3.0.4/net/bridge/netfilter/ebtables.c
67760--- linux-3.0.4/net/bridge/netfilter/ebtables.c 2011-07-21 22:17:23.000000000 -0400
67761+++ linux-3.0.4/net/bridge/netfilter/ebtables.c 2011-08-23 21:48:14.000000000 -0400
67762@@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
67763 tmp.valid_hooks = t->table->valid_hooks;
67764 }
67765 mutex_unlock(&ebt_mutex);
67766- if (copy_to_user(user, &tmp, *len) != 0){
67767+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
67768 BUGPRINT("c2u Didn't work\n");
67769 ret = -EFAULT;
67770 break;
67771@@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
67772 int ret;
67773 void __user *pos;
67774
67775+ pax_track_stack();
67776+
67777 memset(&tinfo, 0, sizeof(tinfo));
67778
67779 if (cmd == EBT_SO_GET_ENTRIES) {
67780diff -urNp linux-3.0.4/net/caif/caif_socket.c linux-3.0.4/net/caif/caif_socket.c
67781--- linux-3.0.4/net/caif/caif_socket.c 2011-07-21 22:17:23.000000000 -0400
67782+++ linux-3.0.4/net/caif/caif_socket.c 2011-08-23 21:47:56.000000000 -0400
67783@@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
67784 #ifdef CONFIG_DEBUG_FS
67785 struct debug_fs_counter {
67786 atomic_t caif_nr_socks;
67787- atomic_t caif_sock_create;
67788- atomic_t num_connect_req;
67789- atomic_t num_connect_resp;
67790- atomic_t num_connect_fail_resp;
67791- atomic_t num_disconnect;
67792- atomic_t num_remote_shutdown_ind;
67793- atomic_t num_tx_flow_off_ind;
67794- atomic_t num_tx_flow_on_ind;
67795- atomic_t num_rx_flow_off;
67796- atomic_t num_rx_flow_on;
67797+ atomic_unchecked_t caif_sock_create;
67798+ atomic_unchecked_t num_connect_req;
67799+ atomic_unchecked_t num_connect_resp;
67800+ atomic_unchecked_t num_connect_fail_resp;
67801+ atomic_unchecked_t num_disconnect;
67802+ atomic_unchecked_t num_remote_shutdown_ind;
67803+ atomic_unchecked_t num_tx_flow_off_ind;
67804+ atomic_unchecked_t num_tx_flow_on_ind;
67805+ atomic_unchecked_t num_rx_flow_off;
67806+ atomic_unchecked_t num_rx_flow_on;
67807 };
67808 static struct debug_fs_counter cnt;
67809 #define dbfs_atomic_inc(v) atomic_inc_return(v)
67810+#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
67811 #define dbfs_atomic_dec(v) atomic_dec_return(v)
67812 #else
67813 #define dbfs_atomic_inc(v) 0
67814@@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct soc
67815 atomic_read(&cf_sk->sk.sk_rmem_alloc),
67816 sk_rcvbuf_lowwater(cf_sk));
67817 set_rx_flow_off(cf_sk);
67818- dbfs_atomic_inc(&cnt.num_rx_flow_off);
67819+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
67820 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
67821 }
67822
67823@@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct soc
67824 set_rx_flow_off(cf_sk);
67825 if (net_ratelimit())
67826 pr_debug("sending flow OFF due to rmem_schedule\n");
67827- dbfs_atomic_inc(&cnt.num_rx_flow_off);
67828+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
67829 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
67830 }
67831 skb->dev = NULL;
67832@@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer
67833 switch (flow) {
67834 case CAIF_CTRLCMD_FLOW_ON_IND:
67835 /* OK from modem to start sending again */
67836- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
67837+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
67838 set_tx_flow_on(cf_sk);
67839 cf_sk->sk.sk_state_change(&cf_sk->sk);
67840 break;
67841
67842 case CAIF_CTRLCMD_FLOW_OFF_IND:
67843 /* Modem asks us to shut up */
67844- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
67845+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
67846 set_tx_flow_off(cf_sk);
67847 cf_sk->sk.sk_state_change(&cf_sk->sk);
67848 break;
67849@@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer
67850 /* We're now connected */
67851 caif_client_register_refcnt(&cf_sk->layer,
67852 cfsk_hold, cfsk_put);
67853- dbfs_atomic_inc(&cnt.num_connect_resp);
67854+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
67855 cf_sk->sk.sk_state = CAIF_CONNECTED;
67856 set_tx_flow_on(cf_sk);
67857 cf_sk->sk.sk_state_change(&cf_sk->sk);
67858@@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer
67859
67860 case CAIF_CTRLCMD_INIT_FAIL_RSP:
67861 /* Connect request failed */
67862- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
67863+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
67864 cf_sk->sk.sk_err = ECONNREFUSED;
67865 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
67866 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
67867@@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer
67868
67869 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
67870 /* Modem has closed this connection, or device is down. */
67871- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
67872+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
67873 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
67874 cf_sk->sk.sk_err = ECONNRESET;
67875 set_rx_flow_on(cf_sk);
67876@@ -297,7 +298,7 @@ static void caif_check_flow_release(stru
67877 return;
67878
67879 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
67880- dbfs_atomic_inc(&cnt.num_rx_flow_on);
67881+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
67882 set_rx_flow_on(cf_sk);
67883 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
67884 }
67885@@ -854,7 +855,7 @@ static int caif_connect(struct socket *s
67886 /*ifindex = id of the interface.*/
67887 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
67888
67889- dbfs_atomic_inc(&cnt.num_connect_req);
67890+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
67891 cf_sk->layer.receive = caif_sktrecv_cb;
67892
67893 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
67894@@ -943,7 +944,7 @@ static int caif_release(struct socket *s
67895 spin_unlock_bh(&sk->sk_receive_queue.lock);
67896 sock->sk = NULL;
67897
67898- dbfs_atomic_inc(&cnt.num_disconnect);
67899+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
67900
67901 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
67902 if (cf_sk->debugfs_socket_dir != NULL)
67903@@ -1122,7 +1123,7 @@ static int caif_create(struct net *net,
67904 cf_sk->conn_req.protocol = protocol;
67905 /* Increase the number of sockets created. */
67906 dbfs_atomic_inc(&cnt.caif_nr_socks);
67907- num = dbfs_atomic_inc(&cnt.caif_sock_create);
67908+ num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
67909 #ifdef CONFIG_DEBUG_FS
67910 if (!IS_ERR(debugfsdir)) {
67911
67912diff -urNp linux-3.0.4/net/caif/cfctrl.c linux-3.0.4/net/caif/cfctrl.c
67913--- linux-3.0.4/net/caif/cfctrl.c 2011-07-21 22:17:23.000000000 -0400
67914+++ linux-3.0.4/net/caif/cfctrl.c 2011-08-23 21:48:14.000000000 -0400
67915@@ -9,6 +9,7 @@
67916 #include <linux/stddef.h>
67917 #include <linux/spinlock.h>
67918 #include <linux/slab.h>
67919+#include <linux/sched.h>
67920 #include <net/caif/caif_layer.h>
67921 #include <net/caif/cfpkt.h>
67922 #include <net/caif/cfctrl.h>
67923@@ -45,8 +46,8 @@ struct cflayer *cfctrl_create(void)
67924 dev_info.id = 0xff;
67925 memset(this, 0, sizeof(*this));
67926 cfsrvl_init(&this->serv, 0, &dev_info, false);
67927- atomic_set(&this->req_seq_no, 1);
67928- atomic_set(&this->rsp_seq_no, 1);
67929+ atomic_set_unchecked(&this->req_seq_no, 1);
67930+ atomic_set_unchecked(&this->rsp_seq_no, 1);
67931 this->serv.layer.receive = cfctrl_recv;
67932 sprintf(this->serv.layer.name, "ctrl");
67933 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
67934@@ -132,8 +133,8 @@ static void cfctrl_insert_req(struct cfc
67935 struct cfctrl_request_info *req)
67936 {
67937 spin_lock_bh(&ctrl->info_list_lock);
67938- atomic_inc(&ctrl->req_seq_no);
67939- req->sequence_no = atomic_read(&ctrl->req_seq_no);
67940+ atomic_inc_unchecked(&ctrl->req_seq_no);
67941+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
67942 list_add_tail(&req->list, &ctrl->list);
67943 spin_unlock_bh(&ctrl->info_list_lock);
67944 }
67945@@ -151,7 +152,7 @@ static struct cfctrl_request_info *cfctr
67946 if (p != first)
67947 pr_warn("Requests are not received in order\n");
67948
67949- atomic_set(&ctrl->rsp_seq_no,
67950+ atomic_set_unchecked(&ctrl->rsp_seq_no,
67951 p->sequence_no);
67952 list_del(&p->list);
67953 goto out;
67954@@ -364,6 +365,7 @@ static int cfctrl_recv(struct cflayer *l
67955 struct cfctrl *cfctrl = container_obj(layer);
67956 struct cfctrl_request_info rsp, *req;
67957
67958+ pax_track_stack();
67959
67960 cfpkt_extr_head(pkt, &cmdrsp, 1);
67961 cmd = cmdrsp & CFCTRL_CMD_MASK;
67962diff -urNp linux-3.0.4/net/core/datagram.c linux-3.0.4/net/core/datagram.c
67963--- linux-3.0.4/net/core/datagram.c 2011-07-21 22:17:23.000000000 -0400
67964+++ linux-3.0.4/net/core/datagram.c 2011-08-23 21:47:56.000000000 -0400
67965@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
67966 }
67967
67968 kfree_skb(skb);
67969- atomic_inc(&sk->sk_drops);
67970+ atomic_inc_unchecked(&sk->sk_drops);
67971 sk_mem_reclaim_partial(sk);
67972
67973 return err;
67974diff -urNp linux-3.0.4/net/core/dev.c linux-3.0.4/net/core/dev.c
67975--- linux-3.0.4/net/core/dev.c 2011-07-21 22:17:23.000000000 -0400
67976+++ linux-3.0.4/net/core/dev.c 2011-08-23 21:48:14.000000000 -0400
67977@@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
67978 if (no_module && capable(CAP_NET_ADMIN))
67979 no_module = request_module("netdev-%s", name);
67980 if (no_module && capable(CAP_SYS_MODULE)) {
67981+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67982+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
67983+#else
67984 if (!request_module("%s", name))
67985 pr_err("Loading kernel module for a network device "
67986 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
67987 "instead\n", name);
67988+#endif
67989 }
67990 }
67991 EXPORT_SYMBOL(dev_load);
67992@@ -1959,7 +1963,7 @@ static int illegal_highdma(struct net_de
67993
67994 struct dev_gso_cb {
67995 void (*destructor)(struct sk_buff *skb);
67996-};
67997+} __no_const;
67998
67999 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
68000
68001@@ -2912,7 +2916,7 @@ int netif_rx_ni(struct sk_buff *skb)
68002 }
68003 EXPORT_SYMBOL(netif_rx_ni);
68004
68005-static void net_tx_action(struct softirq_action *h)
68006+static void net_tx_action(void)
68007 {
68008 struct softnet_data *sd = &__get_cpu_var(softnet_data);
68009
68010@@ -3761,7 +3765,7 @@ void netif_napi_del(struct napi_struct *
68011 }
68012 EXPORT_SYMBOL(netif_napi_del);
68013
68014-static void net_rx_action(struct softirq_action *h)
68015+static void net_rx_action(void)
68016 {
68017 struct softnet_data *sd = &__get_cpu_var(softnet_data);
68018 unsigned long time_limit = jiffies + 2;
68019diff -urNp linux-3.0.4/net/core/flow.c linux-3.0.4/net/core/flow.c
68020--- linux-3.0.4/net/core/flow.c 2011-07-21 22:17:23.000000000 -0400
68021+++ linux-3.0.4/net/core/flow.c 2011-08-23 21:47:56.000000000 -0400
68022@@ -60,7 +60,7 @@ struct flow_cache {
68023 struct timer_list rnd_timer;
68024 };
68025
68026-atomic_t flow_cache_genid = ATOMIC_INIT(0);
68027+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
68028 EXPORT_SYMBOL(flow_cache_genid);
68029 static struct flow_cache flow_cache_global;
68030 static struct kmem_cache *flow_cachep __read_mostly;
68031@@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
68032
68033 static int flow_entry_valid(struct flow_cache_entry *fle)
68034 {
68035- if (atomic_read(&flow_cache_genid) != fle->genid)
68036+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
68037 return 0;
68038 if (fle->object && !fle->object->ops->check(fle->object))
68039 return 0;
68040@@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
68041 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
68042 fcp->hash_count++;
68043 }
68044- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
68045+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
68046 flo = fle->object;
68047 if (!flo)
68048 goto ret_object;
68049@@ -274,7 +274,7 @@ nocache:
68050 }
68051 flo = resolver(net, key, family, dir, flo, ctx);
68052 if (fle) {
68053- fle->genid = atomic_read(&flow_cache_genid);
68054+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
68055 if (!IS_ERR(flo))
68056 fle->object = flo;
68057 else
68058diff -urNp linux-3.0.4/net/core/rtnetlink.c linux-3.0.4/net/core/rtnetlink.c
68059--- linux-3.0.4/net/core/rtnetlink.c 2011-07-21 22:17:23.000000000 -0400
68060+++ linux-3.0.4/net/core/rtnetlink.c 2011-08-23 21:47:56.000000000 -0400
68061@@ -56,7 +56,7 @@
68062 struct rtnl_link {
68063 rtnl_doit_func doit;
68064 rtnl_dumpit_func dumpit;
68065-};
68066+} __no_const;
68067
68068 static DEFINE_MUTEX(rtnl_mutex);
68069
68070diff -urNp linux-3.0.4/net/core/skbuff.c linux-3.0.4/net/core/skbuff.c
68071--- linux-3.0.4/net/core/skbuff.c 2011-07-21 22:17:23.000000000 -0400
68072+++ linux-3.0.4/net/core/skbuff.c 2011-08-23 21:48:14.000000000 -0400
68073@@ -1543,6 +1543,8 @@ int skb_splice_bits(struct sk_buff *skb,
68074 struct sock *sk = skb->sk;
68075 int ret = 0;
68076
68077+ pax_track_stack();
68078+
68079 if (splice_grow_spd(pipe, &spd))
68080 return -ENOMEM;
68081
68082diff -urNp linux-3.0.4/net/core/sock.c linux-3.0.4/net/core/sock.c
68083--- linux-3.0.4/net/core/sock.c 2011-07-21 22:17:23.000000000 -0400
68084+++ linux-3.0.4/net/core/sock.c 2011-08-23 21:48:14.000000000 -0400
68085@@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
68086 */
68087 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
68088 (unsigned)sk->sk_rcvbuf) {
68089- atomic_inc(&sk->sk_drops);
68090+ atomic_inc_unchecked(&sk->sk_drops);
68091 return -ENOMEM;
68092 }
68093
68094@@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
68095 return err;
68096
68097 if (!sk_rmem_schedule(sk, skb->truesize)) {
68098- atomic_inc(&sk->sk_drops);
68099+ atomic_inc_unchecked(&sk->sk_drops);
68100 return -ENOBUFS;
68101 }
68102
68103@@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
68104 skb_dst_force(skb);
68105
68106 spin_lock_irqsave(&list->lock, flags);
68107- skb->dropcount = atomic_read(&sk->sk_drops);
68108+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
68109 __skb_queue_tail(list, skb);
68110 spin_unlock_irqrestore(&list->lock, flags);
68111
68112@@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
68113 skb->dev = NULL;
68114
68115 if (sk_rcvqueues_full(sk, skb)) {
68116- atomic_inc(&sk->sk_drops);
68117+ atomic_inc_unchecked(&sk->sk_drops);
68118 goto discard_and_relse;
68119 }
68120 if (nested)
68121@@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
68122 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
68123 } else if (sk_add_backlog(sk, skb)) {
68124 bh_unlock_sock(sk);
68125- atomic_inc(&sk->sk_drops);
68126+ atomic_inc_unchecked(&sk->sk_drops);
68127 goto discard_and_relse;
68128 }
68129
68130@@ -921,7 +921,7 @@ int sock_getsockopt(struct socket *sock,
68131 if (len > sizeof(peercred))
68132 len = sizeof(peercred);
68133 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
68134- if (copy_to_user(optval, &peercred, len))
68135+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
68136 return -EFAULT;
68137 goto lenout;
68138 }
68139@@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
68140 return -ENOTCONN;
68141 if (lv < len)
68142 return -EINVAL;
68143- if (copy_to_user(optval, address, len))
68144+ if (len > sizeof(address) || copy_to_user(optval, address, len))
68145 return -EFAULT;
68146 goto lenout;
68147 }
68148@@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
68149
68150 if (len > lv)
68151 len = lv;
68152- if (copy_to_user(optval, &v, len))
68153+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
68154 return -EFAULT;
68155 lenout:
68156 if (put_user(len, optlen))
68157@@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
68158 */
68159 smp_wmb();
68160 atomic_set(&sk->sk_refcnt, 1);
68161- atomic_set(&sk->sk_drops, 0);
68162+ atomic_set_unchecked(&sk->sk_drops, 0);
68163 }
68164 EXPORT_SYMBOL(sock_init_data);
68165
68166diff -urNp linux-3.0.4/net/decnet/sysctl_net_decnet.c linux-3.0.4/net/decnet/sysctl_net_decnet.c
68167--- linux-3.0.4/net/decnet/sysctl_net_decnet.c 2011-07-21 22:17:23.000000000 -0400
68168+++ linux-3.0.4/net/decnet/sysctl_net_decnet.c 2011-08-23 21:47:56.000000000 -0400
68169@@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
68170
68171 if (len > *lenp) len = *lenp;
68172
68173- if (copy_to_user(buffer, addr, len))
68174+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
68175 return -EFAULT;
68176
68177 *lenp = len;
68178@@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
68179
68180 if (len > *lenp) len = *lenp;
68181
68182- if (copy_to_user(buffer, devname, len))
68183+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
68184 return -EFAULT;
68185
68186 *lenp = len;
68187diff -urNp linux-3.0.4/net/econet/Kconfig linux-3.0.4/net/econet/Kconfig
68188--- linux-3.0.4/net/econet/Kconfig 2011-07-21 22:17:23.000000000 -0400
68189+++ linux-3.0.4/net/econet/Kconfig 2011-08-23 21:48:14.000000000 -0400
68190@@ -4,7 +4,7 @@
68191
68192 config ECONET
68193 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
68194- depends on EXPERIMENTAL && INET
68195+ depends on EXPERIMENTAL && INET && BROKEN
68196 ---help---
68197 Econet is a fairly old and slow networking protocol mainly used by
68198 Acorn computers to access file and print servers. It uses native
68199diff -urNp linux-3.0.4/net/ipv4/fib_frontend.c linux-3.0.4/net/ipv4/fib_frontend.c
68200--- linux-3.0.4/net/ipv4/fib_frontend.c 2011-07-21 22:17:23.000000000 -0400
68201+++ linux-3.0.4/net/ipv4/fib_frontend.c 2011-08-23 21:47:56.000000000 -0400
68202@@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct not
68203 #ifdef CONFIG_IP_ROUTE_MULTIPATH
68204 fib_sync_up(dev);
68205 #endif
68206- atomic_inc(&net->ipv4.dev_addr_genid);
68207+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
68208 rt_cache_flush(dev_net(dev), -1);
68209 break;
68210 case NETDEV_DOWN:
68211 fib_del_ifaddr(ifa, NULL);
68212- atomic_inc(&net->ipv4.dev_addr_genid);
68213+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
68214 if (ifa->ifa_dev->ifa_list == NULL) {
68215 /* Last address was deleted from this interface.
68216 * Disable IP.
68217@@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notif
68218 #ifdef CONFIG_IP_ROUTE_MULTIPATH
68219 fib_sync_up(dev);
68220 #endif
68221- atomic_inc(&net->ipv4.dev_addr_genid);
68222+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
68223 rt_cache_flush(dev_net(dev), -1);
68224 break;
68225 case NETDEV_DOWN:
68226diff -urNp linux-3.0.4/net/ipv4/fib_semantics.c linux-3.0.4/net/ipv4/fib_semantics.c
68227--- linux-3.0.4/net/ipv4/fib_semantics.c 2011-07-21 22:17:23.000000000 -0400
68228+++ linux-3.0.4/net/ipv4/fib_semantics.c 2011-08-23 21:47:56.000000000 -0400
68229@@ -691,7 +691,7 @@ __be32 fib_info_update_nh_saddr(struct n
68230 nh->nh_saddr = inet_select_addr(nh->nh_dev,
68231 nh->nh_gw,
68232 nh->nh_parent->fib_scope);
68233- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
68234+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
68235
68236 return nh->nh_saddr;
68237 }
68238diff -urNp linux-3.0.4/net/ipv4/inet_diag.c linux-3.0.4/net/ipv4/inet_diag.c
68239--- linux-3.0.4/net/ipv4/inet_diag.c 2011-07-21 22:17:23.000000000 -0400
68240+++ linux-3.0.4/net/ipv4/inet_diag.c 2011-08-23 21:48:14.000000000 -0400
68241@@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
68242 r->idiag_retrans = 0;
68243
68244 r->id.idiag_if = sk->sk_bound_dev_if;
68245+
68246+#ifdef CONFIG_GRKERNSEC_HIDESYM
68247+ r->id.idiag_cookie[0] = 0;
68248+ r->id.idiag_cookie[1] = 0;
68249+#else
68250 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
68251 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
68252+#endif
68253
68254 r->id.idiag_sport = inet->inet_sport;
68255 r->id.idiag_dport = inet->inet_dport;
68256@@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
68257 r->idiag_family = tw->tw_family;
68258 r->idiag_retrans = 0;
68259 r->id.idiag_if = tw->tw_bound_dev_if;
68260+
68261+#ifdef CONFIG_GRKERNSEC_HIDESYM
68262+ r->id.idiag_cookie[0] = 0;
68263+ r->id.idiag_cookie[1] = 0;
68264+#else
68265 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
68266 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
68267+#endif
68268+
68269 r->id.idiag_sport = tw->tw_sport;
68270 r->id.idiag_dport = tw->tw_dport;
68271 r->id.idiag_src[0] = tw->tw_rcv_saddr;
68272@@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
68273 if (sk == NULL)
68274 goto unlock;
68275
68276+#ifndef CONFIG_GRKERNSEC_HIDESYM
68277 err = -ESTALE;
68278 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
68279 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
68280 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
68281 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
68282 goto out;
68283+#endif
68284
68285 err = -ENOMEM;
68286 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
68287@@ -580,8 +595,14 @@ static int inet_diag_fill_req(struct sk_
68288 r->idiag_retrans = req->retrans;
68289
68290 r->id.idiag_if = sk->sk_bound_dev_if;
68291+
68292+#ifdef CONFIG_GRKERNSEC_HIDESYM
68293+ r->id.idiag_cookie[0] = 0;
68294+ r->id.idiag_cookie[1] = 0;
68295+#else
68296 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
68297 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
68298+#endif
68299
68300 tmo = req->expires - jiffies;
68301 if (tmo < 0)
68302diff -urNp linux-3.0.4/net/ipv4/inet_hashtables.c linux-3.0.4/net/ipv4/inet_hashtables.c
68303--- linux-3.0.4/net/ipv4/inet_hashtables.c 2011-09-02 18:11:21.000000000 -0400
68304+++ linux-3.0.4/net/ipv4/inet_hashtables.c 2011-08-23 21:55:24.000000000 -0400
68305@@ -18,12 +18,15 @@
68306 #include <linux/sched.h>
68307 #include <linux/slab.h>
68308 #include <linux/wait.h>
68309+#include <linux/security.h>
68310
68311 #include <net/inet_connection_sock.h>
68312 #include <net/inet_hashtables.h>
68313 #include <net/secure_seq.h>
68314 #include <net/ip.h>
68315
68316+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
68317+
68318 /*
68319 * Allocate and initialize a new local port bind bucket.
68320 * The bindhash mutex for snum's hash chain must be held here.
68321@@ -530,6 +533,8 @@ ok:
68322 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
68323 spin_unlock(&head->lock);
68324
68325+ gr_update_task_in_ip_table(current, inet_sk(sk));
68326+
68327 if (tw) {
68328 inet_twsk_deschedule(tw, death_row);
68329 while (twrefcnt) {
68330diff -urNp linux-3.0.4/net/ipv4/inetpeer.c linux-3.0.4/net/ipv4/inetpeer.c
68331--- linux-3.0.4/net/ipv4/inetpeer.c 2011-09-02 18:11:21.000000000 -0400
68332+++ linux-3.0.4/net/ipv4/inetpeer.c 2011-08-23 21:48:14.000000000 -0400
68333@@ -481,6 +481,8 @@ struct inet_peer *inet_getpeer(struct in
68334 unsigned int sequence;
68335 int invalidated, newrefcnt = 0;
68336
68337+ pax_track_stack();
68338+
68339 /* Look up for the address quickly, lockless.
68340 * Because of a concurrent writer, we might not find an existing entry.
68341 */
68342@@ -517,8 +519,8 @@ found: /* The existing node has been fo
68343 if (p) {
68344 p->daddr = *daddr;
68345 atomic_set(&p->refcnt, 1);
68346- atomic_set(&p->rid, 0);
68347- atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
68348+ atomic_set_unchecked(&p->rid, 0);
68349+ atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
68350 p->tcp_ts_stamp = 0;
68351 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
68352 p->rate_tokens = 0;
68353diff -urNp linux-3.0.4/net/ipv4/ip_fragment.c linux-3.0.4/net/ipv4/ip_fragment.c
68354--- linux-3.0.4/net/ipv4/ip_fragment.c 2011-07-21 22:17:23.000000000 -0400
68355+++ linux-3.0.4/net/ipv4/ip_fragment.c 2011-08-23 21:47:56.000000000 -0400
68356@@ -315,7 +315,7 @@ static inline int ip_frag_too_far(struct
68357 return 0;
68358
68359 start = qp->rid;
68360- end = atomic_inc_return(&peer->rid);
68361+ end = atomic_inc_return_unchecked(&peer->rid);
68362 qp->rid = end;
68363
68364 rc = qp->q.fragments && (end - start) > max;
68365diff -urNp linux-3.0.4/net/ipv4/ip_sockglue.c linux-3.0.4/net/ipv4/ip_sockglue.c
68366--- linux-3.0.4/net/ipv4/ip_sockglue.c 2011-07-21 22:17:23.000000000 -0400
68367+++ linux-3.0.4/net/ipv4/ip_sockglue.c 2011-08-23 21:48:14.000000000 -0400
68368@@ -1073,6 +1073,8 @@ static int do_ip_getsockopt(struct sock
68369 int val;
68370 int len;
68371
68372+ pax_track_stack();
68373+
68374 if (level != SOL_IP)
68375 return -EOPNOTSUPP;
68376
68377@@ -1110,7 +1112,8 @@ static int do_ip_getsockopt(struct sock
68378 len = min_t(unsigned int, len, opt->optlen);
68379 if (put_user(len, optlen))
68380 return -EFAULT;
68381- if (copy_to_user(optval, opt->__data, len))
68382+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
68383+ copy_to_user(optval, opt->__data, len))
68384 return -EFAULT;
68385 return 0;
68386 }
68387diff -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
68388--- linux-3.0.4/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-07-21 22:17:23.000000000 -0400
68389+++ linux-3.0.4/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-08-23 21:47:56.000000000 -0400
68390@@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
68391
68392 *len = 0;
68393
68394- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
68395+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
68396 if (*octets == NULL) {
68397 if (net_ratelimit())
68398 pr_notice("OOM in bsalg (%d)\n", __LINE__);
68399diff -urNp linux-3.0.4/net/ipv4/ping.c linux-3.0.4/net/ipv4/ping.c
68400--- linux-3.0.4/net/ipv4/ping.c 2011-07-21 22:17:23.000000000 -0400
68401+++ linux-3.0.4/net/ipv4/ping.c 2011-08-23 21:47:56.000000000 -0400
68402@@ -837,7 +837,7 @@ static void ping_format_sock(struct sock
68403 sk_rmem_alloc_get(sp),
68404 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
68405 atomic_read(&sp->sk_refcnt), sp,
68406- atomic_read(&sp->sk_drops), len);
68407+ atomic_read_unchecked(&sp->sk_drops), len);
68408 }
68409
68410 static int ping_seq_show(struct seq_file *seq, void *v)
68411diff -urNp linux-3.0.4/net/ipv4/raw.c linux-3.0.4/net/ipv4/raw.c
68412--- linux-3.0.4/net/ipv4/raw.c 2011-07-21 22:17:23.000000000 -0400
68413+++ linux-3.0.4/net/ipv4/raw.c 2011-08-23 21:48:14.000000000 -0400
68414@@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
68415 int raw_rcv(struct sock *sk, struct sk_buff *skb)
68416 {
68417 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
68418- atomic_inc(&sk->sk_drops);
68419+ atomic_inc_unchecked(&sk->sk_drops);
68420 kfree_skb(skb);
68421 return NET_RX_DROP;
68422 }
68423@@ -736,16 +736,20 @@ static int raw_init(struct sock *sk)
68424
68425 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
68426 {
68427+ struct icmp_filter filter;
68428+
68429 if (optlen > sizeof(struct icmp_filter))
68430 optlen = sizeof(struct icmp_filter);
68431- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
68432+ if (copy_from_user(&filter, optval, optlen))
68433 return -EFAULT;
68434+ raw_sk(sk)->filter = filter;
68435 return 0;
68436 }
68437
68438 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
68439 {
68440 int len, ret = -EFAULT;
68441+ struct icmp_filter filter;
68442
68443 if (get_user(len, optlen))
68444 goto out;
68445@@ -755,8 +759,9 @@ static int raw_geticmpfilter(struct sock
68446 if (len > sizeof(struct icmp_filter))
68447 len = sizeof(struct icmp_filter);
68448 ret = -EFAULT;
68449- if (put_user(len, optlen) ||
68450- copy_to_user(optval, &raw_sk(sk)->filter, len))
68451+ filter = raw_sk(sk)->filter;
68452+ if (put_user(len, optlen) || len > sizeof filter ||
68453+ copy_to_user(optval, &filter, len))
68454 goto out;
68455 ret = 0;
68456 out: return ret;
68457@@ -984,7 +989,13 @@ static void raw_sock_seq_show(struct seq
68458 sk_wmem_alloc_get(sp),
68459 sk_rmem_alloc_get(sp),
68460 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
68461- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
68462+ atomic_read(&sp->sk_refcnt),
68463+#ifdef CONFIG_GRKERNSEC_HIDESYM
68464+ NULL,
68465+#else
68466+ sp,
68467+#endif
68468+ atomic_read_unchecked(&sp->sk_drops));
68469 }
68470
68471 static int raw_seq_show(struct seq_file *seq, void *v)
68472diff -urNp linux-3.0.4/net/ipv4/route.c linux-3.0.4/net/ipv4/route.c
68473--- linux-3.0.4/net/ipv4/route.c 2011-09-02 18:11:21.000000000 -0400
68474+++ linux-3.0.4/net/ipv4/route.c 2011-08-23 21:47:56.000000000 -0400
68475@@ -304,7 +304,7 @@ static inline unsigned int rt_hash(__be3
68476
68477 static inline int rt_genid(struct net *net)
68478 {
68479- return atomic_read(&net->ipv4.rt_genid);
68480+ return atomic_read_unchecked(&net->ipv4.rt_genid);
68481 }
68482
68483 #ifdef CONFIG_PROC_FS
68484@@ -833,7 +833,7 @@ static void rt_cache_invalidate(struct n
68485 unsigned char shuffle;
68486
68487 get_random_bytes(&shuffle, sizeof(shuffle));
68488- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
68489+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
68490 }
68491
68492 /*
68493@@ -2834,7 +2834,7 @@ static int rt_fill_info(struct net *net,
68494 error = rt->dst.error;
68495 if (peer) {
68496 inet_peer_refcheck(rt->peer);
68497- id = atomic_read(&peer->ip_id_count) & 0xffff;
68498+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
68499 if (peer->tcp_ts_stamp) {
68500 ts = peer->tcp_ts;
68501 tsage = get_seconds() - peer->tcp_ts_stamp;
68502diff -urNp linux-3.0.4/net/ipv4/tcp.c linux-3.0.4/net/ipv4/tcp.c
68503--- linux-3.0.4/net/ipv4/tcp.c 2011-07-21 22:17:23.000000000 -0400
68504+++ linux-3.0.4/net/ipv4/tcp.c 2011-08-23 21:48:14.000000000 -0400
68505@@ -2122,6 +2122,8 @@ static int do_tcp_setsockopt(struct sock
68506 int val;
68507 int err = 0;
68508
68509+ pax_track_stack();
68510+
68511 /* These are data/string values, all the others are ints */
68512 switch (optname) {
68513 case TCP_CONGESTION: {
68514@@ -2501,6 +2503,8 @@ static int do_tcp_getsockopt(struct sock
68515 struct tcp_sock *tp = tcp_sk(sk);
68516 int val, len;
68517
68518+ pax_track_stack();
68519+
68520 if (get_user(len, optlen))
68521 return -EFAULT;
68522
68523diff -urNp linux-3.0.4/net/ipv4/tcp_ipv4.c linux-3.0.4/net/ipv4/tcp_ipv4.c
68524--- linux-3.0.4/net/ipv4/tcp_ipv4.c 2011-09-02 18:11:21.000000000 -0400
68525+++ linux-3.0.4/net/ipv4/tcp_ipv4.c 2011-08-23 21:48:14.000000000 -0400
68526@@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
68527 int sysctl_tcp_low_latency __read_mostly;
68528 EXPORT_SYMBOL(sysctl_tcp_low_latency);
68529
68530+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68531+extern int grsec_enable_blackhole;
68532+#endif
68533
68534 #ifdef CONFIG_TCP_MD5SIG
68535 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
68536@@ -1607,6 +1610,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
68537 return 0;
68538
68539 reset:
68540+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68541+ if (!grsec_enable_blackhole)
68542+#endif
68543 tcp_v4_send_reset(rsk, skb);
68544 discard:
68545 kfree_skb(skb);
68546@@ -1669,12 +1675,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
68547 TCP_SKB_CB(skb)->sacked = 0;
68548
68549 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
68550- if (!sk)
68551+ if (!sk) {
68552+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68553+ ret = 1;
68554+#endif
68555 goto no_tcp_socket;
68556-
68557+ }
68558 process:
68559- if (sk->sk_state == TCP_TIME_WAIT)
68560+ if (sk->sk_state == TCP_TIME_WAIT) {
68561+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68562+ ret = 2;
68563+#endif
68564 goto do_time_wait;
68565+ }
68566
68567 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
68568 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
68569@@ -1724,6 +1737,10 @@ no_tcp_socket:
68570 bad_packet:
68571 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
68572 } else {
68573+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68574+ if (!grsec_enable_blackhole || (ret == 1 &&
68575+ (skb->dev->flags & IFF_LOOPBACK)))
68576+#endif
68577 tcp_v4_send_reset(NULL, skb);
68578 }
68579
68580@@ -2388,7 +2405,11 @@ static void get_openreq4(struct sock *sk
68581 0, /* non standard timer */
68582 0, /* open_requests have no inode */
68583 atomic_read(&sk->sk_refcnt),
68584+#ifdef CONFIG_GRKERNSEC_HIDESYM
68585+ NULL,
68586+#else
68587 req,
68588+#endif
68589 len);
68590 }
68591
68592@@ -2438,7 +2459,12 @@ static void get_tcp4_sock(struct sock *s
68593 sock_i_uid(sk),
68594 icsk->icsk_probes_out,
68595 sock_i_ino(sk),
68596- atomic_read(&sk->sk_refcnt), sk,
68597+ atomic_read(&sk->sk_refcnt),
68598+#ifdef CONFIG_GRKERNSEC_HIDESYM
68599+ NULL,
68600+#else
68601+ sk,
68602+#endif
68603 jiffies_to_clock_t(icsk->icsk_rto),
68604 jiffies_to_clock_t(icsk->icsk_ack.ato),
68605 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
68606@@ -2466,7 +2492,13 @@ static void get_timewait4_sock(struct in
68607 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
68608 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
68609 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
68610- atomic_read(&tw->tw_refcnt), tw, len);
68611+ atomic_read(&tw->tw_refcnt),
68612+#ifdef CONFIG_GRKERNSEC_HIDESYM
68613+ NULL,
68614+#else
68615+ tw,
68616+#endif
68617+ len);
68618 }
68619
68620 #define TMPSZ 150
68621diff -urNp linux-3.0.4/net/ipv4/tcp_minisocks.c linux-3.0.4/net/ipv4/tcp_minisocks.c
68622--- linux-3.0.4/net/ipv4/tcp_minisocks.c 2011-07-21 22:17:23.000000000 -0400
68623+++ linux-3.0.4/net/ipv4/tcp_minisocks.c 2011-08-23 21:48:14.000000000 -0400
68624@@ -27,6 +27,10 @@
68625 #include <net/inet_common.h>
68626 #include <net/xfrm.h>
68627
68628+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68629+extern int grsec_enable_blackhole;
68630+#endif
68631+
68632 int sysctl_tcp_syncookies __read_mostly = 1;
68633 EXPORT_SYMBOL(sysctl_tcp_syncookies);
68634
68635@@ -745,6 +749,10 @@ listen_overflow:
68636
68637 embryonic_reset:
68638 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
68639+
68640+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68641+ if (!grsec_enable_blackhole)
68642+#endif
68643 if (!(flg & TCP_FLAG_RST))
68644 req->rsk_ops->send_reset(sk, skb);
68645
68646diff -urNp linux-3.0.4/net/ipv4/tcp_output.c linux-3.0.4/net/ipv4/tcp_output.c
68647--- linux-3.0.4/net/ipv4/tcp_output.c 2011-07-21 22:17:23.000000000 -0400
68648+++ linux-3.0.4/net/ipv4/tcp_output.c 2011-08-23 21:48:14.000000000 -0400
68649@@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
68650 int mss;
68651 int s_data_desired = 0;
68652
68653+ pax_track_stack();
68654+
68655 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
68656 s_data_desired = cvp->s_data_desired;
68657 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
68658diff -urNp linux-3.0.4/net/ipv4/tcp_probe.c linux-3.0.4/net/ipv4/tcp_probe.c
68659--- linux-3.0.4/net/ipv4/tcp_probe.c 2011-07-21 22:17:23.000000000 -0400
68660+++ linux-3.0.4/net/ipv4/tcp_probe.c 2011-08-23 21:47:56.000000000 -0400
68661@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
68662 if (cnt + width >= len)
68663 break;
68664
68665- if (copy_to_user(buf + cnt, tbuf, width))
68666+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
68667 return -EFAULT;
68668 cnt += width;
68669 }
68670diff -urNp linux-3.0.4/net/ipv4/tcp_timer.c linux-3.0.4/net/ipv4/tcp_timer.c
68671--- linux-3.0.4/net/ipv4/tcp_timer.c 2011-07-21 22:17:23.000000000 -0400
68672+++ linux-3.0.4/net/ipv4/tcp_timer.c 2011-08-23 21:48:14.000000000 -0400
68673@@ -22,6 +22,10 @@
68674 #include <linux/gfp.h>
68675 #include <net/tcp.h>
68676
68677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68678+extern int grsec_lastack_retries;
68679+#endif
68680+
68681 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
68682 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
68683 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
68684@@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
68685 }
68686 }
68687
68688+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68689+ if ((sk->sk_state == TCP_LAST_ACK) &&
68690+ (grsec_lastack_retries > 0) &&
68691+ (grsec_lastack_retries < retry_until))
68692+ retry_until = grsec_lastack_retries;
68693+#endif
68694+
68695 if (retransmits_timed_out(sk, retry_until,
68696 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
68697 /* Has it gone just too far? */
68698diff -urNp linux-3.0.4/net/ipv4/udp.c linux-3.0.4/net/ipv4/udp.c
68699--- linux-3.0.4/net/ipv4/udp.c 2011-07-21 22:17:23.000000000 -0400
68700+++ linux-3.0.4/net/ipv4/udp.c 2011-08-23 21:48:14.000000000 -0400
68701@@ -86,6 +86,7 @@
68702 #include <linux/types.h>
68703 #include <linux/fcntl.h>
68704 #include <linux/module.h>
68705+#include <linux/security.h>
68706 #include <linux/socket.h>
68707 #include <linux/sockios.h>
68708 #include <linux/igmp.h>
68709@@ -107,6 +108,10 @@
68710 #include <net/xfrm.h>
68711 #include "udp_impl.h"
68712
68713+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68714+extern int grsec_enable_blackhole;
68715+#endif
68716+
68717 struct udp_table udp_table __read_mostly;
68718 EXPORT_SYMBOL(udp_table);
68719
68720@@ -564,6 +569,9 @@ found:
68721 return s;
68722 }
68723
68724+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
68725+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
68726+
68727 /*
68728 * This routine is called by the ICMP module when it gets some
68729 * sort of error condition. If err < 0 then the socket should
68730@@ -855,9 +863,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
68731 dport = usin->sin_port;
68732 if (dport == 0)
68733 return -EINVAL;
68734+
68735+ err = gr_search_udp_sendmsg(sk, usin);
68736+ if (err)
68737+ return err;
68738 } else {
68739 if (sk->sk_state != TCP_ESTABLISHED)
68740 return -EDESTADDRREQ;
68741+
68742+ err = gr_search_udp_sendmsg(sk, NULL);
68743+ if (err)
68744+ return err;
68745+
68746 daddr = inet->inet_daddr;
68747 dport = inet->inet_dport;
68748 /* Open fast path for connected socket.
68749@@ -1098,7 +1115,7 @@ static unsigned int first_packet_length(
68750 udp_lib_checksum_complete(skb)) {
68751 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
68752 IS_UDPLITE(sk));
68753- atomic_inc(&sk->sk_drops);
68754+ atomic_inc_unchecked(&sk->sk_drops);
68755 __skb_unlink(skb, rcvq);
68756 __skb_queue_tail(&list_kill, skb);
68757 }
68758@@ -1184,6 +1201,10 @@ try_again:
68759 if (!skb)
68760 goto out;
68761
68762+ err = gr_search_udp_recvmsg(sk, skb);
68763+ if (err)
68764+ goto out_free;
68765+
68766 ulen = skb->len - sizeof(struct udphdr);
68767 if (len > ulen)
68768 len = ulen;
68769@@ -1483,7 +1504,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
68770
68771 drop:
68772 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
68773- atomic_inc(&sk->sk_drops);
68774+ atomic_inc_unchecked(&sk->sk_drops);
68775 kfree_skb(skb);
68776 return -1;
68777 }
68778@@ -1502,7 +1523,7 @@ static void flush_stack(struct sock **st
68779 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
68780
68781 if (!skb1) {
68782- atomic_inc(&sk->sk_drops);
68783+ atomic_inc_unchecked(&sk->sk_drops);
68784 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
68785 IS_UDPLITE(sk));
68786 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
68787@@ -1671,6 +1692,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
68788 goto csum_error;
68789
68790 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
68791+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68792+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
68793+#endif
68794 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
68795
68796 /*
68797@@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock
68798 sk_wmem_alloc_get(sp),
68799 sk_rmem_alloc_get(sp),
68800 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
68801- atomic_read(&sp->sk_refcnt), sp,
68802- atomic_read(&sp->sk_drops), len);
68803+ atomic_read(&sp->sk_refcnt),
68804+#ifdef CONFIG_GRKERNSEC_HIDESYM
68805+ NULL,
68806+#else
68807+ sp,
68808+#endif
68809+ atomic_read_unchecked(&sp->sk_drops), len);
68810 }
68811
68812 int udp4_seq_show(struct seq_file *seq, void *v)
68813diff -urNp linux-3.0.4/net/ipv6/inet6_connection_sock.c linux-3.0.4/net/ipv6/inet6_connection_sock.c
68814--- linux-3.0.4/net/ipv6/inet6_connection_sock.c 2011-07-21 22:17:23.000000000 -0400
68815+++ linux-3.0.4/net/ipv6/inet6_connection_sock.c 2011-08-23 21:47:56.000000000 -0400
68816@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
68817 #ifdef CONFIG_XFRM
68818 {
68819 struct rt6_info *rt = (struct rt6_info *)dst;
68820- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
68821+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
68822 }
68823 #endif
68824 }
68825@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
68826 #ifdef CONFIG_XFRM
68827 if (dst) {
68828 struct rt6_info *rt = (struct rt6_info *)dst;
68829- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
68830+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
68831 __sk_dst_reset(sk);
68832 dst = NULL;
68833 }
68834diff -urNp linux-3.0.4/net/ipv6/ipv6_sockglue.c linux-3.0.4/net/ipv6/ipv6_sockglue.c
68835--- linux-3.0.4/net/ipv6/ipv6_sockglue.c 2011-07-21 22:17:23.000000000 -0400
68836+++ linux-3.0.4/net/ipv6/ipv6_sockglue.c 2011-08-23 21:48:14.000000000 -0400
68837@@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
68838 int val, valbool;
68839 int retv = -ENOPROTOOPT;
68840
68841+ pax_track_stack();
68842+
68843 if (optval == NULL)
68844 val=0;
68845 else {
68846@@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
68847 int len;
68848 int val;
68849
68850+ pax_track_stack();
68851+
68852 if (ip6_mroute_opt(optname))
68853 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
68854
68855diff -urNp linux-3.0.4/net/ipv6/raw.c linux-3.0.4/net/ipv6/raw.c
68856--- linux-3.0.4/net/ipv6/raw.c 2011-07-21 22:17:23.000000000 -0400
68857+++ linux-3.0.4/net/ipv6/raw.c 2011-08-23 21:48:14.000000000 -0400
68858@@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
68859 {
68860 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
68861 skb_checksum_complete(skb)) {
68862- atomic_inc(&sk->sk_drops);
68863+ atomic_inc_unchecked(&sk->sk_drops);
68864 kfree_skb(skb);
68865 return NET_RX_DROP;
68866 }
68867@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
68868 struct raw6_sock *rp = raw6_sk(sk);
68869
68870 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
68871- atomic_inc(&sk->sk_drops);
68872+ atomic_inc_unchecked(&sk->sk_drops);
68873 kfree_skb(skb);
68874 return NET_RX_DROP;
68875 }
68876@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
68877
68878 if (inet->hdrincl) {
68879 if (skb_checksum_complete(skb)) {
68880- atomic_inc(&sk->sk_drops);
68881+ atomic_inc_unchecked(&sk->sk_drops);
68882 kfree_skb(skb);
68883 return NET_RX_DROP;
68884 }
68885@@ -601,7 +601,7 @@ out:
68886 return err;
68887 }
68888
68889-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
68890+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
68891 struct flowi6 *fl6, struct dst_entry **dstp,
68892 unsigned int flags)
68893 {
68894@@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
68895 u16 proto;
68896 int err;
68897
68898+ pax_track_stack();
68899+
68900 /* Rough check on arithmetic overflow,
68901 better check is made in ip6_append_data().
68902 */
68903@@ -909,12 +911,15 @@ do_confirm:
68904 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
68905 char __user *optval, int optlen)
68906 {
68907+ struct icmp6_filter filter;
68908+
68909 switch (optname) {
68910 case ICMPV6_FILTER:
68911 if (optlen > sizeof(struct icmp6_filter))
68912 optlen = sizeof(struct icmp6_filter);
68913- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
68914+ if (copy_from_user(&filter, optval, optlen))
68915 return -EFAULT;
68916+ raw6_sk(sk)->filter = filter;
68917 return 0;
68918 default:
68919 return -ENOPROTOOPT;
68920@@ -927,6 +932,7 @@ static int rawv6_geticmpfilter(struct so
68921 char __user *optval, int __user *optlen)
68922 {
68923 int len;
68924+ struct icmp6_filter filter;
68925
68926 switch (optname) {
68927 case ICMPV6_FILTER:
68928@@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
68929 len = sizeof(struct icmp6_filter);
68930 if (put_user(len, optlen))
68931 return -EFAULT;
68932- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
68933+ filter = raw6_sk(sk)->filter;
68934+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
68935 return -EFAULT;
68936 return 0;
68937 default:
68938@@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
68939 0, 0L, 0,
68940 sock_i_uid(sp), 0,
68941 sock_i_ino(sp),
68942- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
68943+ atomic_read(&sp->sk_refcnt),
68944+#ifdef CONFIG_GRKERNSEC_HIDESYM
68945+ NULL,
68946+#else
68947+ sp,
68948+#endif
68949+ atomic_read_unchecked(&sp->sk_drops));
68950 }
68951
68952 static int raw6_seq_show(struct seq_file *seq, void *v)
68953diff -urNp linux-3.0.4/net/ipv6/tcp_ipv6.c linux-3.0.4/net/ipv6/tcp_ipv6.c
68954--- linux-3.0.4/net/ipv6/tcp_ipv6.c 2011-09-02 18:11:21.000000000 -0400
68955+++ linux-3.0.4/net/ipv6/tcp_ipv6.c 2011-08-23 21:48:14.000000000 -0400
68956@@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
68957 }
68958 #endif
68959
68960+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68961+extern int grsec_enable_blackhole;
68962+#endif
68963+
68964 static void tcp_v6_hash(struct sock *sk)
68965 {
68966 if (sk->sk_state != TCP_CLOSE) {
68967@@ -1662,6 +1666,9 @@ static int tcp_v6_do_rcv(struct sock *sk
68968 return 0;
68969
68970 reset:
68971+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68972+ if (!grsec_enable_blackhole)
68973+#endif
68974 tcp_v6_send_reset(sk, skb);
68975 discard:
68976 if (opt_skb)
68977@@ -1741,12 +1748,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
68978 TCP_SKB_CB(skb)->sacked = 0;
68979
68980 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
68981- if (!sk)
68982+ if (!sk) {
68983+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68984+ ret = 1;
68985+#endif
68986 goto no_tcp_socket;
68987+ }
68988
68989 process:
68990- if (sk->sk_state == TCP_TIME_WAIT)
68991+ if (sk->sk_state == TCP_TIME_WAIT) {
68992+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68993+ ret = 2;
68994+#endif
68995 goto do_time_wait;
68996+ }
68997
68998 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
68999 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
69000@@ -1794,6 +1809,10 @@ no_tcp_socket:
69001 bad_packet:
69002 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
69003 } else {
69004+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69005+ if (!grsec_enable_blackhole || (ret == 1 &&
69006+ (skb->dev->flags & IFF_LOOPBACK)))
69007+#endif
69008 tcp_v6_send_reset(NULL, skb);
69009 }
69010
69011@@ -2054,7 +2073,13 @@ static void get_openreq6(struct seq_file
69012 uid,
69013 0, /* non standard timer */
69014 0, /* open_requests have no inode */
69015- 0, req);
69016+ 0,
69017+#ifdef CONFIG_GRKERNSEC_HIDESYM
69018+ NULL
69019+#else
69020+ req
69021+#endif
69022+ );
69023 }
69024
69025 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
69026@@ -2104,7 +2129,12 @@ static void get_tcp6_sock(struct seq_fil
69027 sock_i_uid(sp),
69028 icsk->icsk_probes_out,
69029 sock_i_ino(sp),
69030- atomic_read(&sp->sk_refcnt), sp,
69031+ atomic_read(&sp->sk_refcnt),
69032+#ifdef CONFIG_GRKERNSEC_HIDESYM
69033+ NULL,
69034+#else
69035+ sp,
69036+#endif
69037 jiffies_to_clock_t(icsk->icsk_rto),
69038 jiffies_to_clock_t(icsk->icsk_ack.ato),
69039 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
69040@@ -2139,7 +2169,13 @@ static void get_timewait6_sock(struct se
69041 dest->s6_addr32[2], dest->s6_addr32[3], destp,
69042 tw->tw_substate, 0, 0,
69043 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
69044- atomic_read(&tw->tw_refcnt), tw);
69045+ atomic_read(&tw->tw_refcnt),
69046+#ifdef CONFIG_GRKERNSEC_HIDESYM
69047+ NULL
69048+#else
69049+ tw
69050+#endif
69051+ );
69052 }
69053
69054 static int tcp6_seq_show(struct seq_file *seq, void *v)
69055diff -urNp linux-3.0.4/net/ipv6/udp.c linux-3.0.4/net/ipv6/udp.c
69056--- linux-3.0.4/net/ipv6/udp.c 2011-09-02 18:11:21.000000000 -0400
69057+++ linux-3.0.4/net/ipv6/udp.c 2011-08-23 21:48:14.000000000 -0400
69058@@ -50,6 +50,10 @@
69059 #include <linux/seq_file.h>
69060 #include "udp_impl.h"
69061
69062+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69063+extern int grsec_enable_blackhole;
69064+#endif
69065+
69066 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
69067 {
69068 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
69069@@ -548,7 +552,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
69070
69071 return 0;
69072 drop:
69073- atomic_inc(&sk->sk_drops);
69074+ atomic_inc_unchecked(&sk->sk_drops);
69075 drop_no_sk_drops_inc:
69076 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
69077 kfree_skb(skb);
69078@@ -624,7 +628,7 @@ static void flush_stack(struct sock **st
69079 continue;
69080 }
69081 drop:
69082- atomic_inc(&sk->sk_drops);
69083+ atomic_inc_unchecked(&sk->sk_drops);
69084 UDP6_INC_STATS_BH(sock_net(sk),
69085 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
69086 UDP6_INC_STATS_BH(sock_net(sk),
69087@@ -779,6 +783,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
69088 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
69089 proto == IPPROTO_UDPLITE);
69090
69091+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69092+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
69093+#endif
69094 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
69095
69096 kfree_skb(skb);
69097@@ -795,7 +802,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
69098 if (!sock_owned_by_user(sk))
69099 udpv6_queue_rcv_skb(sk, skb);
69100 else if (sk_add_backlog(sk, skb)) {
69101- atomic_inc(&sk->sk_drops);
69102+ atomic_inc_unchecked(&sk->sk_drops);
69103 bh_unlock_sock(sk);
69104 sock_put(sk);
69105 goto discard;
69106@@ -1406,8 +1413,13 @@ static void udp6_sock_seq_show(struct se
69107 0, 0L, 0,
69108 sock_i_uid(sp), 0,
69109 sock_i_ino(sp),
69110- atomic_read(&sp->sk_refcnt), sp,
69111- atomic_read(&sp->sk_drops));
69112+ atomic_read(&sp->sk_refcnt),
69113+#ifdef CONFIG_GRKERNSEC_HIDESYM
69114+ NULL,
69115+#else
69116+ sp,
69117+#endif
69118+ atomic_read_unchecked(&sp->sk_drops));
69119 }
69120
69121 int udp6_seq_show(struct seq_file *seq, void *v)
69122diff -urNp linux-3.0.4/net/irda/ircomm/ircomm_tty.c linux-3.0.4/net/irda/ircomm/ircomm_tty.c
69123--- linux-3.0.4/net/irda/ircomm/ircomm_tty.c 2011-07-21 22:17:23.000000000 -0400
69124+++ linux-3.0.4/net/irda/ircomm/ircomm_tty.c 2011-08-23 21:47:56.000000000 -0400
69125@@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(st
69126 add_wait_queue(&self->open_wait, &wait);
69127
69128 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
69129- __FILE__,__LINE__, tty->driver->name, self->open_count );
69130+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
69131
69132 /* As far as I can see, we protect open_count - Jean II */
69133 spin_lock_irqsave(&self->spinlock, flags);
69134 if (!tty_hung_up_p(filp)) {
69135 extra_count = 1;
69136- self->open_count--;
69137+ local_dec(&self->open_count);
69138 }
69139 spin_unlock_irqrestore(&self->spinlock, flags);
69140- self->blocked_open++;
69141+ local_inc(&self->blocked_open);
69142
69143 while (1) {
69144 if (tty->termios->c_cflag & CBAUD) {
69145@@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(st
69146 }
69147
69148 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
69149- __FILE__,__LINE__, tty->driver->name, self->open_count );
69150+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
69151
69152 schedule();
69153 }
69154@@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(st
69155 if (extra_count) {
69156 /* ++ is not atomic, so this should be protected - Jean II */
69157 spin_lock_irqsave(&self->spinlock, flags);
69158- self->open_count++;
69159+ local_inc(&self->open_count);
69160 spin_unlock_irqrestore(&self->spinlock, flags);
69161 }
69162- self->blocked_open--;
69163+ local_dec(&self->blocked_open);
69164
69165 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
69166- __FILE__,__LINE__, tty->driver->name, self->open_count);
69167+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
69168
69169 if (!retval)
69170 self->flags |= ASYNC_NORMAL_ACTIVE;
69171@@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_st
69172 }
69173 /* ++ is not atomic, so this should be protected - Jean II */
69174 spin_lock_irqsave(&self->spinlock, flags);
69175- self->open_count++;
69176+ local_inc(&self->open_count);
69177
69178 tty->driver_data = self;
69179 self->tty = tty;
69180 spin_unlock_irqrestore(&self->spinlock, flags);
69181
69182 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
69183- self->line, self->open_count);
69184+ self->line, local_read(&self->open_count));
69185
69186 /* Not really used by us, but lets do it anyway */
69187 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
69188@@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_
69189 return;
69190 }
69191
69192- if ((tty->count == 1) && (self->open_count != 1)) {
69193+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
69194 /*
69195 * Uh, oh. tty->count is 1, which means that the tty
69196 * structure will be freed. state->count should always
69197@@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_
69198 */
69199 IRDA_DEBUG(0, "%s(), bad serial port count; "
69200 "tty->count is 1, state->count is %d\n", __func__ ,
69201- self->open_count);
69202- self->open_count = 1;
69203+ local_read(&self->open_count));
69204+ local_set(&self->open_count, 1);
69205 }
69206
69207- if (--self->open_count < 0) {
69208+ if (local_dec_return(&self->open_count) < 0) {
69209 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
69210- __func__, self->line, self->open_count);
69211- self->open_count = 0;
69212+ __func__, self->line, local_read(&self->open_count));
69213+ local_set(&self->open_count, 0);
69214 }
69215- if (self->open_count) {
69216+ if (local_read(&self->open_count)) {
69217 spin_unlock_irqrestore(&self->spinlock, flags);
69218
69219 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
69220@@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_
69221 tty->closing = 0;
69222 self->tty = NULL;
69223
69224- if (self->blocked_open) {
69225+ if (local_read(&self->blocked_open)) {
69226 if (self->close_delay)
69227 schedule_timeout_interruptible(self->close_delay);
69228 wake_up_interruptible(&self->open_wait);
69229@@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty
69230 spin_lock_irqsave(&self->spinlock, flags);
69231 self->flags &= ~ASYNC_NORMAL_ACTIVE;
69232 self->tty = NULL;
69233- self->open_count = 0;
69234+ local_set(&self->open_count, 0);
69235 spin_unlock_irqrestore(&self->spinlock, flags);
69236
69237 wake_up_interruptible(&self->open_wait);
69238@@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct
69239 seq_putc(m, '\n');
69240
69241 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
69242- seq_printf(m, "Open count: %d\n", self->open_count);
69243+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
69244 seq_printf(m, "Max data size: %d\n", self->max_data_size);
69245 seq_printf(m, "Max header size: %d\n", self->max_header_size);
69246
69247diff -urNp linux-3.0.4/net/iucv/af_iucv.c linux-3.0.4/net/iucv/af_iucv.c
69248--- linux-3.0.4/net/iucv/af_iucv.c 2011-07-21 22:17:23.000000000 -0400
69249+++ linux-3.0.4/net/iucv/af_iucv.c 2011-08-23 21:47:56.000000000 -0400
69250@@ -648,10 +648,10 @@ static int iucv_sock_autobind(struct soc
69251
69252 write_lock_bh(&iucv_sk_list.lock);
69253
69254- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
69255+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
69256 while (__iucv_get_sock_by_name(name)) {
69257 sprintf(name, "%08x",
69258- atomic_inc_return(&iucv_sk_list.autobind_name));
69259+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
69260 }
69261
69262 write_unlock_bh(&iucv_sk_list.lock);
69263diff -urNp linux-3.0.4/net/key/af_key.c linux-3.0.4/net/key/af_key.c
69264--- linux-3.0.4/net/key/af_key.c 2011-07-21 22:17:23.000000000 -0400
69265+++ linux-3.0.4/net/key/af_key.c 2011-08-23 21:48:14.000000000 -0400
69266@@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
69267 struct xfrm_migrate m[XFRM_MAX_DEPTH];
69268 struct xfrm_kmaddress k;
69269
69270+ pax_track_stack();
69271+
69272 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
69273 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
69274 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
69275@@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
69276 static u32 get_acqseq(void)
69277 {
69278 u32 res;
69279- static atomic_t acqseq;
69280+ static atomic_unchecked_t acqseq;
69281
69282 do {
69283- res = atomic_inc_return(&acqseq);
69284+ res = atomic_inc_return_unchecked(&acqseq);
69285 } while (!res);
69286 return res;
69287 }
69288diff -urNp linux-3.0.4/net/lapb/lapb_iface.c linux-3.0.4/net/lapb/lapb_iface.c
69289--- linux-3.0.4/net/lapb/lapb_iface.c 2011-07-21 22:17:23.000000000 -0400
69290+++ linux-3.0.4/net/lapb/lapb_iface.c 2011-08-23 21:47:56.000000000 -0400
69291@@ -158,7 +158,7 @@ int lapb_register(struct net_device *dev
69292 goto out;
69293
69294 lapb->dev = dev;
69295- lapb->callbacks = *callbacks;
69296+ lapb->callbacks = callbacks;
69297
69298 __lapb_insert_cb(lapb);
69299
69300@@ -380,32 +380,32 @@ int lapb_data_received(struct net_device
69301
69302 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
69303 {
69304- if (lapb->callbacks.connect_confirmation)
69305- lapb->callbacks.connect_confirmation(lapb->dev, reason);
69306+ if (lapb->callbacks->connect_confirmation)
69307+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
69308 }
69309
69310 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
69311 {
69312- if (lapb->callbacks.connect_indication)
69313- lapb->callbacks.connect_indication(lapb->dev, reason);
69314+ if (lapb->callbacks->connect_indication)
69315+ lapb->callbacks->connect_indication(lapb->dev, reason);
69316 }
69317
69318 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
69319 {
69320- if (lapb->callbacks.disconnect_confirmation)
69321- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
69322+ if (lapb->callbacks->disconnect_confirmation)
69323+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
69324 }
69325
69326 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
69327 {
69328- if (lapb->callbacks.disconnect_indication)
69329- lapb->callbacks.disconnect_indication(lapb->dev, reason);
69330+ if (lapb->callbacks->disconnect_indication)
69331+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
69332 }
69333
69334 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
69335 {
69336- if (lapb->callbacks.data_indication)
69337- return lapb->callbacks.data_indication(lapb->dev, skb);
69338+ if (lapb->callbacks->data_indication)
69339+ return lapb->callbacks->data_indication(lapb->dev, skb);
69340
69341 kfree_skb(skb);
69342 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
69343@@ -415,8 +415,8 @@ int lapb_data_transmit(struct lapb_cb *l
69344 {
69345 int used = 0;
69346
69347- if (lapb->callbacks.data_transmit) {
69348- lapb->callbacks.data_transmit(lapb->dev, skb);
69349+ if (lapb->callbacks->data_transmit) {
69350+ lapb->callbacks->data_transmit(lapb->dev, skb);
69351 used = 1;
69352 }
69353
69354diff -urNp linux-3.0.4/net/mac80211/debugfs_sta.c linux-3.0.4/net/mac80211/debugfs_sta.c
69355--- linux-3.0.4/net/mac80211/debugfs_sta.c 2011-07-21 22:17:23.000000000 -0400
69356+++ linux-3.0.4/net/mac80211/debugfs_sta.c 2011-08-23 21:48:14.000000000 -0400
69357@@ -140,6 +140,8 @@ static ssize_t sta_agg_status_read(struc
69358 struct tid_ampdu_rx *tid_rx;
69359 struct tid_ampdu_tx *tid_tx;
69360
69361+ pax_track_stack();
69362+
69363 rcu_read_lock();
69364
69365 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
69366@@ -240,6 +242,8 @@ static ssize_t sta_ht_capa_read(struct f
69367 struct sta_info *sta = file->private_data;
69368 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
69369
69370+ pax_track_stack();
69371+
69372 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
69373 htc->ht_supported ? "" : "not ");
69374 if (htc->ht_supported) {
69375diff -urNp linux-3.0.4/net/mac80211/ieee80211_i.h linux-3.0.4/net/mac80211/ieee80211_i.h
69376--- linux-3.0.4/net/mac80211/ieee80211_i.h 2011-07-21 22:17:23.000000000 -0400
69377+++ linux-3.0.4/net/mac80211/ieee80211_i.h 2011-08-23 21:47:56.000000000 -0400
69378@@ -27,6 +27,7 @@
69379 #include <net/ieee80211_radiotap.h>
69380 #include <net/cfg80211.h>
69381 #include <net/mac80211.h>
69382+#include <asm/local.h>
69383 #include "key.h"
69384 #include "sta_info.h"
69385
69386@@ -721,7 +722,7 @@ struct ieee80211_local {
69387 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
69388 spinlock_t queue_stop_reason_lock;
69389
69390- int open_count;
69391+ local_t open_count;
69392 int monitors, cooked_mntrs;
69393 /* number of interfaces with corresponding FIF_ flags */
69394 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
69395diff -urNp linux-3.0.4/net/mac80211/iface.c linux-3.0.4/net/mac80211/iface.c
69396--- linux-3.0.4/net/mac80211/iface.c 2011-09-02 18:11:21.000000000 -0400
69397+++ linux-3.0.4/net/mac80211/iface.c 2011-08-23 21:47:56.000000000 -0400
69398@@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
69399 break;
69400 }
69401
69402- if (local->open_count == 0) {
69403+ if (local_read(&local->open_count) == 0) {
69404 res = drv_start(local);
69405 if (res)
69406 goto err_del_bss;
69407@@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
69408 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
69409
69410 if (!is_valid_ether_addr(dev->dev_addr)) {
69411- if (!local->open_count)
69412+ if (!local_read(&local->open_count))
69413 drv_stop(local);
69414 return -EADDRNOTAVAIL;
69415 }
69416@@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
69417 mutex_unlock(&local->mtx);
69418
69419 if (coming_up)
69420- local->open_count++;
69421+ local_inc(&local->open_count);
69422
69423 if (hw_reconf_flags) {
69424 ieee80211_hw_config(local, hw_reconf_flags);
69425@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
69426 err_del_interface:
69427 drv_remove_interface(local, &sdata->vif);
69428 err_stop:
69429- if (!local->open_count)
69430+ if (!local_read(&local->open_count))
69431 drv_stop(local);
69432 err_del_bss:
69433 sdata->bss = NULL;
69434@@ -475,7 +475,7 @@ static void ieee80211_do_stop(struct iee
69435 }
69436
69437 if (going_down)
69438- local->open_count--;
69439+ local_dec(&local->open_count);
69440
69441 switch (sdata->vif.type) {
69442 case NL80211_IFTYPE_AP_VLAN:
69443@@ -534,7 +534,7 @@ static void ieee80211_do_stop(struct iee
69444
69445 ieee80211_recalc_ps(local, -1);
69446
69447- if (local->open_count == 0) {
69448+ if (local_read(&local->open_count) == 0) {
69449 if (local->ops->napi_poll)
69450 napi_disable(&local->napi);
69451 ieee80211_clear_tx_pending(local);
69452diff -urNp linux-3.0.4/net/mac80211/main.c linux-3.0.4/net/mac80211/main.c
69453--- linux-3.0.4/net/mac80211/main.c 2011-07-21 22:17:23.000000000 -0400
69454+++ linux-3.0.4/net/mac80211/main.c 2011-08-23 21:47:56.000000000 -0400
69455@@ -209,7 +209,7 @@ int ieee80211_hw_config(struct ieee80211
69456 local->hw.conf.power_level = power;
69457 }
69458
69459- if (changed && local->open_count) {
69460+ if (changed && local_read(&local->open_count)) {
69461 ret = drv_config(local, changed);
69462 /*
69463 * Goal:
69464diff -urNp linux-3.0.4/net/mac80211/mlme.c linux-3.0.4/net/mac80211/mlme.c
69465--- linux-3.0.4/net/mac80211/mlme.c 2011-09-02 18:11:21.000000000 -0400
69466+++ linux-3.0.4/net/mac80211/mlme.c 2011-08-23 21:48:14.000000000 -0400
69467@@ -1444,6 +1444,8 @@ static bool ieee80211_assoc_success(stru
69468 bool have_higher_than_11mbit = false;
69469 u16 ap_ht_cap_flags;
69470
69471+ pax_track_stack();
69472+
69473 /* AssocResp and ReassocResp have identical structure */
69474
69475 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
69476diff -urNp linux-3.0.4/net/mac80211/pm.c linux-3.0.4/net/mac80211/pm.c
69477--- linux-3.0.4/net/mac80211/pm.c 2011-07-21 22:17:23.000000000 -0400
69478+++ linux-3.0.4/net/mac80211/pm.c 2011-08-23 21:47:56.000000000 -0400
69479@@ -47,7 +47,7 @@ int __ieee80211_suspend(struct ieee80211
69480 cancel_work_sync(&local->dynamic_ps_enable_work);
69481 del_timer_sync(&local->dynamic_ps_timer);
69482
69483- local->wowlan = wowlan && local->open_count;
69484+ local->wowlan = wowlan && local_read(&local->open_count);
69485 if (local->wowlan) {
69486 int err = drv_suspend(local, wowlan);
69487 if (err) {
69488@@ -111,7 +111,7 @@ int __ieee80211_suspend(struct ieee80211
69489 }
69490
69491 /* stop hardware - this must stop RX */
69492- if (local->open_count)
69493+ if (local_read(&local->open_count))
69494 ieee80211_stop_device(local);
69495
69496 suspend:
69497diff -urNp linux-3.0.4/net/mac80211/rate.c linux-3.0.4/net/mac80211/rate.c
69498--- linux-3.0.4/net/mac80211/rate.c 2011-07-21 22:17:23.000000000 -0400
69499+++ linux-3.0.4/net/mac80211/rate.c 2011-08-23 21:47:56.000000000 -0400
69500@@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
69501
69502 ASSERT_RTNL();
69503
69504- if (local->open_count)
69505+ if (local_read(&local->open_count))
69506 return -EBUSY;
69507
69508 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
69509diff -urNp linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c
69510--- linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c 2011-07-21 22:17:23.000000000 -0400
69511+++ linux-3.0.4/net/mac80211/rc80211_pid_debugfs.c 2011-08-23 21:47:56.000000000 -0400
69512@@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
69513
69514 spin_unlock_irqrestore(&events->lock, status);
69515
69516- if (copy_to_user(buf, pb, p))
69517+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
69518 return -EFAULT;
69519
69520 return p;
69521diff -urNp linux-3.0.4/net/mac80211/util.c linux-3.0.4/net/mac80211/util.c
69522--- linux-3.0.4/net/mac80211/util.c 2011-07-21 22:17:23.000000000 -0400
69523+++ linux-3.0.4/net/mac80211/util.c 2011-08-23 21:47:56.000000000 -0400
69524@@ -1147,7 +1147,7 @@ int ieee80211_reconfig(struct ieee80211_
69525 #endif
69526
69527 /* restart hardware */
69528- if (local->open_count) {
69529+ if (local_read(&local->open_count)) {
69530 /*
69531 * Upon resume hardware can sometimes be goofy due to
69532 * various platform / driver / bus issues, so restarting
69533diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c
69534--- linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c 2011-07-21 22:17:23.000000000 -0400
69535+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_conn.c 2011-08-23 21:47:56.000000000 -0400
69536@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
69537 /* Increase the refcnt counter of the dest */
69538 atomic_inc(&dest->refcnt);
69539
69540- conn_flags = atomic_read(&dest->conn_flags);
69541+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
69542 if (cp->protocol != IPPROTO_UDP)
69543 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
69544 /* Bind with the destination and its corresponding transmitter */
69545@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
69546 atomic_set(&cp->refcnt, 1);
69547
69548 atomic_set(&cp->n_control, 0);
69549- atomic_set(&cp->in_pkts, 0);
69550+ atomic_set_unchecked(&cp->in_pkts, 0);
69551
69552 atomic_inc(&ipvs->conn_count);
69553 if (flags & IP_VS_CONN_F_NO_CPORT)
69554@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip
69555
69556 /* Don't drop the entry if its number of incoming packets is not
69557 located in [0, 8] */
69558- i = atomic_read(&cp->in_pkts);
69559+ i = atomic_read_unchecked(&cp->in_pkts);
69560 if (i > 8 || i < 0) return 0;
69561
69562 if (!todrop_rate[i]) return 0;
69563diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c
69564--- linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c 2011-07-21 22:17:23.000000000 -0400
69565+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_core.c 2011-08-23 21:47:56.000000000 -0400
69566@@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
69567 ret = cp->packet_xmit(skb, cp, pd->pp);
69568 /* do not touch skb anymore */
69569
69570- atomic_inc(&cp->in_pkts);
69571+ atomic_inc_unchecked(&cp->in_pkts);
69572 ip_vs_conn_put(cp);
69573 return ret;
69574 }
69575@@ -1613,7 +1613,7 @@ ip_vs_in(unsigned int hooknum, struct sk
69576 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
69577 pkts = sysctl_sync_threshold(ipvs);
69578 else
69579- pkts = atomic_add_return(1, &cp->in_pkts);
69580+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
69581
69582 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
69583 cp->protocol == IPPROTO_SCTP) {
69584diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c
69585--- linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c 2011-09-02 18:11:21.000000000 -0400
69586+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_ctl.c 2011-08-23 21:48:14.000000000 -0400
69587@@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
69588 ip_vs_rs_hash(ipvs, dest);
69589 write_unlock_bh(&ipvs->rs_lock);
69590 }
69591- atomic_set(&dest->conn_flags, conn_flags);
69592+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
69593
69594 /* bind the service */
69595 if (!dest->svc) {
69596@@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
69597 " %-7s %-6d %-10d %-10d\n",
69598 &dest->addr.in6,
69599 ntohs(dest->port),
69600- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
69601+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
69602 atomic_read(&dest->weight),
69603 atomic_read(&dest->activeconns),
69604 atomic_read(&dest->inactconns));
69605@@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
69606 "%-7s %-6d %-10d %-10d\n",
69607 ntohl(dest->addr.ip),
69608 ntohs(dest->port),
69609- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
69610+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
69611 atomic_read(&dest->weight),
69612 atomic_read(&dest->activeconns),
69613 atomic_read(&dest->inactconns));
69614@@ -2284,6 +2284,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
69615 struct ip_vs_dest_user *udest_compat;
69616 struct ip_vs_dest_user_kern udest;
69617
69618+ pax_track_stack();
69619+
69620 if (!capable(CAP_NET_ADMIN))
69621 return -EPERM;
69622
69623@@ -2498,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net
69624
69625 entry.addr = dest->addr.ip;
69626 entry.port = dest->port;
69627- entry.conn_flags = atomic_read(&dest->conn_flags);
69628+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
69629 entry.weight = atomic_read(&dest->weight);
69630 entry.u_threshold = dest->u_threshold;
69631 entry.l_threshold = dest->l_threshold;
69632@@ -3026,7 +3028,7 @@ static int ip_vs_genl_fill_dest(struct s
69633 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
69634
69635 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
69636- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
69637+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
69638 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
69639 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
69640 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
69641diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c
69642--- linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c 2011-07-21 22:17:23.000000000 -0400
69643+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_sync.c 2011-08-23 21:47:56.000000000 -0400
69644@@ -648,7 +648,7 @@ control:
69645 * i.e only increment in_pkts for Templates.
69646 */
69647 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
69648- int pkts = atomic_add_return(1, &cp->in_pkts);
69649+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
69650
69651 if (pkts % sysctl_sync_period(ipvs) != 1)
69652 return;
69653@@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
69654
69655 if (opt)
69656 memcpy(&cp->in_seq, opt, sizeof(*opt));
69657- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
69658+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
69659 cp->state = state;
69660 cp->old_state = cp->state;
69661 /*
69662diff -urNp linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c
69663--- linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c 2011-07-21 22:17:23.000000000 -0400
69664+++ linux-3.0.4/net/netfilter/ipvs/ip_vs_xmit.c 2011-08-23 21:47:56.000000000 -0400
69665@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
69666 else
69667 rc = NF_ACCEPT;
69668 /* do not touch skb anymore */
69669- atomic_inc(&cp->in_pkts);
69670+ atomic_inc_unchecked(&cp->in_pkts);
69671 goto out;
69672 }
69673
69674@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
69675 else
69676 rc = NF_ACCEPT;
69677 /* do not touch skb anymore */
69678- atomic_inc(&cp->in_pkts);
69679+ atomic_inc_unchecked(&cp->in_pkts);
69680 goto out;
69681 }
69682
69683diff -urNp linux-3.0.4/net/netfilter/Kconfig linux-3.0.4/net/netfilter/Kconfig
69684--- linux-3.0.4/net/netfilter/Kconfig 2011-07-21 22:17:23.000000000 -0400
69685+++ linux-3.0.4/net/netfilter/Kconfig 2011-08-23 21:48:14.000000000 -0400
69686@@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
69687
69688 To compile it as a module, choose M here. If unsure, say N.
69689
69690+config NETFILTER_XT_MATCH_GRADM
69691+ tristate '"gradm" match support'
69692+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
69693+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
69694+ ---help---
69695+ The gradm match allows to match on grsecurity RBAC being enabled.
69696+ It is useful when iptables rules are applied early on bootup to
69697+ prevent connections to the machine (except from a trusted host)
69698+ while the RBAC system is disabled.
69699+
69700 config NETFILTER_XT_MATCH_HASHLIMIT
69701 tristate '"hashlimit" match support'
69702 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
69703diff -urNp linux-3.0.4/net/netfilter/Makefile linux-3.0.4/net/netfilter/Makefile
69704--- linux-3.0.4/net/netfilter/Makefile 2011-07-21 22:17:23.000000000 -0400
69705+++ linux-3.0.4/net/netfilter/Makefile 2011-08-23 21:48:14.000000000 -0400
69706@@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
69707 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
69708 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
69709 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
69710+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
69711 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
69712 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
69713 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
69714diff -urNp linux-3.0.4/net/netfilter/nfnetlink_log.c linux-3.0.4/net/netfilter/nfnetlink_log.c
69715--- linux-3.0.4/net/netfilter/nfnetlink_log.c 2011-07-21 22:17:23.000000000 -0400
69716+++ linux-3.0.4/net/netfilter/nfnetlink_log.c 2011-08-23 21:47:56.000000000 -0400
69717@@ -70,7 +70,7 @@ struct nfulnl_instance {
69718 };
69719
69720 static DEFINE_SPINLOCK(instances_lock);
69721-static atomic_t global_seq;
69722+static atomic_unchecked_t global_seq;
69723
69724 #define INSTANCE_BUCKETS 16
69725 static struct hlist_head instance_table[INSTANCE_BUCKETS];
69726@@ -505,7 +505,7 @@ __build_packet_message(struct nfulnl_ins
69727 /* global sequence number */
69728 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
69729 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
69730- htonl(atomic_inc_return(&global_seq)));
69731+ htonl(atomic_inc_return_unchecked(&global_seq)));
69732
69733 if (data_len) {
69734 struct nlattr *nla;
69735diff -urNp linux-3.0.4/net/netfilter/nfnetlink_queue.c linux-3.0.4/net/netfilter/nfnetlink_queue.c
69736--- linux-3.0.4/net/netfilter/nfnetlink_queue.c 2011-07-21 22:17:23.000000000 -0400
69737+++ linux-3.0.4/net/netfilter/nfnetlink_queue.c 2011-08-23 21:47:56.000000000 -0400
69738@@ -58,7 +58,7 @@ struct nfqnl_instance {
69739 */
69740 spinlock_t lock;
69741 unsigned int queue_total;
69742- atomic_t id_sequence; /* 'sequence' of pkt ids */
69743+ atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
69744 struct list_head queue_list; /* packets in queue */
69745 };
69746
69747@@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
69748 nfmsg->version = NFNETLINK_V0;
69749 nfmsg->res_id = htons(queue->queue_num);
69750
69751- entry->id = atomic_inc_return(&queue->id_sequence);
69752+ entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
69753 pmsg.packet_id = htonl(entry->id);
69754 pmsg.hw_protocol = entskb->protocol;
69755 pmsg.hook = entry->hook;
69756@@ -870,7 +870,7 @@ static int seq_show(struct seq_file *s,
69757 inst->peer_pid, inst->queue_total,
69758 inst->copy_mode, inst->copy_range,
69759 inst->queue_dropped, inst->queue_user_dropped,
69760- atomic_read(&inst->id_sequence), 1);
69761+ atomic_read_unchecked(&inst->id_sequence), 1);
69762 }
69763
69764 static const struct seq_operations nfqnl_seq_ops = {
69765diff -urNp linux-3.0.4/net/netfilter/xt_gradm.c linux-3.0.4/net/netfilter/xt_gradm.c
69766--- linux-3.0.4/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
69767+++ linux-3.0.4/net/netfilter/xt_gradm.c 2011-08-23 21:48:14.000000000 -0400
69768@@ -0,0 +1,51 @@
69769+/*
69770+ * gradm match for netfilter
69771