]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.43-201108071438.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.43-201108071438.patch
CommitLineData
1aed85a4
PK
1diff -urNp linux-2.6.32.43/arch/alpha/include/asm/elf.h linux-2.6.32.43/arch/alpha/include/asm/elf.h
2--- linux-2.6.32.43/arch/alpha/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
3+++ linux-2.6.32.43/arch/alpha/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
4@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
5
6 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
7
8+#ifdef CONFIG_PAX_ASLR
9+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
10+
11+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
12+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
13+#endif
14+
15 /* $0 is set by ld.so to a pointer to a function which might be
16 registered using atexit. This provides a mean for the dynamic
17 linker to call DT_FINI functions for shared libraries that have
18diff -urNp linux-2.6.32.43/arch/alpha/include/asm/pgtable.h linux-2.6.32.43/arch/alpha/include/asm/pgtable.h
19--- linux-2.6.32.43/arch/alpha/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
20+++ linux-2.6.32.43/arch/alpha/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
21@@ -101,6 +101,17 @@ struct vm_area_struct;
22 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
23 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
24 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
25+
26+#ifdef CONFIG_PAX_PAGEEXEC
27+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
28+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
29+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
30+#else
31+# define PAGE_SHARED_NOEXEC PAGE_SHARED
32+# define PAGE_COPY_NOEXEC PAGE_COPY
33+# define PAGE_READONLY_NOEXEC PAGE_READONLY
34+#endif
35+
36 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
37
38 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
39diff -urNp linux-2.6.32.43/arch/alpha/kernel/module.c linux-2.6.32.43/arch/alpha/kernel/module.c
40--- linux-2.6.32.43/arch/alpha/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
41+++ linux-2.6.32.43/arch/alpha/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
42@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
43
44 /* The small sections were sorted to the end of the segment.
45 The following should definitely cover them. */
46- gp = (u64)me->module_core + me->core_size - 0x8000;
47+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
48 got = sechdrs[me->arch.gotsecindex].sh_addr;
49
50 for (i = 0; i < n; i++) {
51diff -urNp linux-2.6.32.43/arch/alpha/kernel/osf_sys.c linux-2.6.32.43/arch/alpha/kernel/osf_sys.c
52--- linux-2.6.32.43/arch/alpha/kernel/osf_sys.c 2011-03-27 14:31:47.000000000 -0400
53+++ linux-2.6.32.43/arch/alpha/kernel/osf_sys.c 2011-06-13 17:19:47.000000000 -0400
54@@ -431,7 +431,7 @@ SYSCALL_DEFINE2(osf_getdomainname, char
55 return -EFAULT;
56
57 len = namelen;
58- if (namelen > 32)
59+ if (len > 32)
60 len = 32;
61
62 down_read(&uts_sem);
63@@ -618,7 +618,7 @@ SYSCALL_DEFINE3(osf_sysinfo, int, comman
64 down_read(&uts_sem);
65 res = sysinfo_table[offset];
66 len = strlen(res)+1;
67- if (len > count)
68+ if ((unsigned long)len > (unsigned long)count)
69 len = count;
70 if (copy_to_user(buf, res, len))
71 err = -EFAULT;
72@@ -673,7 +673,7 @@ SYSCALL_DEFINE5(osf_getsysinfo, unsigned
73 return 1;
74
75 case GSI_GET_HWRPB:
76- if (nbytes < sizeof(*hwrpb))
77+ if (nbytes > sizeof(*hwrpb))
78 return -EINVAL;
79 if (copy_to_user(buffer, hwrpb, nbytes) != 0)
80 return -EFAULT;
81@@ -1035,6 +1035,7 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, i
82 {
83 struct rusage r;
84 long ret, err;
85+ unsigned int status = 0;
86 mm_segment_t old_fs;
87
88 if (!ur)
89@@ -1043,13 +1044,15 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, i
90 old_fs = get_fs();
91
92 set_fs (KERNEL_DS);
93- ret = sys_wait4(pid, ustatus, options, (struct rusage __user *) &r);
94+ ret = sys_wait4(pid, (unsigned int __user *) &status, options,
95+ (struct rusage __user *) &r);
96 set_fs (old_fs);
97
98 if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
99 return -EFAULT;
100
101 err = 0;
102+ err |= put_user(status, ustatus);
103 err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
104 err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
105 err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
106@@ -1169,7 +1172,7 @@ arch_get_unmapped_area_1(unsigned long a
107 /* At this point: (!vma || addr < vma->vm_end). */
108 if (limit - len < addr)
109 return -ENOMEM;
110- if (!vma || addr + len <= vma->vm_start)
111+ if (check_heap_stack_gap(vma, addr, len))
112 return addr;
113 addr = vma->vm_end;
114 vma = vma->vm_next;
115@@ -1205,6 +1208,10 @@ arch_get_unmapped_area(struct file *filp
116 merely specific addresses, but regions of memory -- perhaps
117 this feature should be incorporated into all ports? */
118
119+#ifdef CONFIG_PAX_RANDMMAP
120+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
121+#endif
122+
123 if (addr) {
124 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
125 if (addr != (unsigned long) -ENOMEM)
126@@ -1212,8 +1219,8 @@ arch_get_unmapped_area(struct file *filp
127 }
128
129 /* Next, try allocating at TASK_UNMAPPED_BASE. */
130- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
131- len, limit);
132+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
133+
134 if (addr != (unsigned long) -ENOMEM)
135 return addr;
136
137diff -urNp linux-2.6.32.43/arch/alpha/mm/fault.c linux-2.6.32.43/arch/alpha/mm/fault.c
138--- linux-2.6.32.43/arch/alpha/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
139+++ linux-2.6.32.43/arch/alpha/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
140@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
141 __reload_thread(pcb);
142 }
143
144+#ifdef CONFIG_PAX_PAGEEXEC
145+/*
146+ * PaX: decide what to do with offenders (regs->pc = fault address)
147+ *
148+ * returns 1 when task should be killed
149+ * 2 when patched PLT trampoline was detected
150+ * 3 when unpatched PLT trampoline was detected
151+ */
152+static int pax_handle_fetch_fault(struct pt_regs *regs)
153+{
154+
155+#ifdef CONFIG_PAX_EMUPLT
156+ int err;
157+
158+ do { /* PaX: patched PLT emulation #1 */
159+ unsigned int ldah, ldq, jmp;
160+
161+ err = get_user(ldah, (unsigned int *)regs->pc);
162+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
163+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
164+
165+ if (err)
166+ break;
167+
168+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
169+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
170+ jmp == 0x6BFB0000U)
171+ {
172+ unsigned long r27, addr;
173+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
174+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
175+
176+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
177+ err = get_user(r27, (unsigned long *)addr);
178+ if (err)
179+ break;
180+
181+ regs->r27 = r27;
182+ regs->pc = r27;
183+ return 2;
184+ }
185+ } while (0);
186+
187+ do { /* PaX: patched PLT emulation #2 */
188+ unsigned int ldah, lda, br;
189+
190+ err = get_user(ldah, (unsigned int *)regs->pc);
191+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
192+ err |= get_user(br, (unsigned int *)(regs->pc+8));
193+
194+ if (err)
195+ break;
196+
197+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
198+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
199+ (br & 0xFFE00000U) == 0xC3E00000U)
200+ {
201+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
202+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
203+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
204+
205+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
206+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
207+ return 2;
208+ }
209+ } while (0);
210+
211+ do { /* PaX: unpatched PLT emulation */
212+ unsigned int br;
213+
214+ err = get_user(br, (unsigned int *)regs->pc);
215+
216+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
217+ unsigned int br2, ldq, nop, jmp;
218+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
219+
220+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
221+ err = get_user(br2, (unsigned int *)addr);
222+ err |= get_user(ldq, (unsigned int *)(addr+4));
223+ err |= get_user(nop, (unsigned int *)(addr+8));
224+ err |= get_user(jmp, (unsigned int *)(addr+12));
225+ err |= get_user(resolver, (unsigned long *)(addr+16));
226+
227+ if (err)
228+ break;
229+
230+ if (br2 == 0xC3600000U &&
231+ ldq == 0xA77B000CU &&
232+ nop == 0x47FF041FU &&
233+ jmp == 0x6B7B0000U)
234+ {
235+ regs->r28 = regs->pc+4;
236+ regs->r27 = addr+16;
237+ regs->pc = resolver;
238+ return 3;
239+ }
240+ }
241+ } while (0);
242+#endif
243+
244+ return 1;
245+}
246+
247+void pax_report_insns(void *pc, void *sp)
248+{
249+ unsigned long i;
250+
251+ printk(KERN_ERR "PAX: bytes at PC: ");
252+ for (i = 0; i < 5; i++) {
253+ unsigned int c;
254+ if (get_user(c, (unsigned int *)pc+i))
255+ printk(KERN_CONT "???????? ");
256+ else
257+ printk(KERN_CONT "%08x ", c);
258+ }
259+ printk("\n");
260+}
261+#endif
262
263 /*
264 * This routine handles page faults. It determines the address,
265@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
266 good_area:
267 si_code = SEGV_ACCERR;
268 if (cause < 0) {
269- if (!(vma->vm_flags & VM_EXEC))
270+ if (!(vma->vm_flags & VM_EXEC)) {
271+
272+#ifdef CONFIG_PAX_PAGEEXEC
273+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
274+ goto bad_area;
275+
276+ up_read(&mm->mmap_sem);
277+ switch (pax_handle_fetch_fault(regs)) {
278+
279+#ifdef CONFIG_PAX_EMUPLT
280+ case 2:
281+ case 3:
282+ return;
283+#endif
284+
285+ }
286+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
287+ do_group_exit(SIGKILL);
288+#else
289 goto bad_area;
290+#endif
291+
292+ }
293 } else if (!cause) {
294 /* Allow reads even for write-only mappings */
295 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
296diff -urNp linux-2.6.32.43/arch/arm/include/asm/elf.h linux-2.6.32.43/arch/arm/include/asm/elf.h
297--- linux-2.6.32.43/arch/arm/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
298+++ linux-2.6.32.43/arch/arm/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
299@@ -109,7 +109,14 @@ int dump_task_regs(struct task_struct *t
300 the loader. We need to make sure that it is out of the way of the program
301 that it will "exec", and that there is sufficient room for the brk. */
302
303-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
304+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
305+
306+#ifdef CONFIG_PAX_ASLR
307+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
308+
309+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
310+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
311+#endif
312
313 /* When the program starts, a1 contains a pointer to a function to be
314 registered with atexit, as per the SVR4 ABI. A value of 0 means we
315diff -urNp linux-2.6.32.43/arch/arm/include/asm/kmap_types.h linux-2.6.32.43/arch/arm/include/asm/kmap_types.h
316--- linux-2.6.32.43/arch/arm/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
317+++ linux-2.6.32.43/arch/arm/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
318@@ -19,6 +19,7 @@ enum km_type {
319 KM_SOFTIRQ0,
320 KM_SOFTIRQ1,
321 KM_L2_CACHE,
322+ KM_CLEARPAGE,
323 KM_TYPE_NR
324 };
325
326diff -urNp linux-2.6.32.43/arch/arm/include/asm/uaccess.h linux-2.6.32.43/arch/arm/include/asm/uaccess.h
327--- linux-2.6.32.43/arch/arm/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
328+++ linux-2.6.32.43/arch/arm/include/asm/uaccess.h 2011-06-29 21:02:24.000000000 -0400
329@@ -22,6 +22,8 @@
330 #define VERIFY_READ 0
331 #define VERIFY_WRITE 1
332
333+extern void check_object_size(const void *ptr, unsigned long n, bool to);
334+
335 /*
336 * The exception table consists of pairs of addresses: the first is the
337 * address of an instruction that is allowed to fault, and the second is
338@@ -387,8 +389,23 @@ do { \
339
340
341 #ifdef CONFIG_MMU
342-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
343-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
344+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
345+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
346+
347+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
348+{
349+ if (!__builtin_constant_p(n))
350+ check_object_size(to, n, false);
351+ return ___copy_from_user(to, from, n);
352+}
353+
354+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
355+{
356+ if (!__builtin_constant_p(n))
357+ check_object_size(from, n, true);
358+ return ___copy_to_user(to, from, n);
359+}
360+
361 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
362 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
363 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
364@@ -403,6 +420,9 @@ extern unsigned long __must_check __strn
365
366 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
367 {
368+ if ((long)n < 0)
369+ return n;
370+
371 if (access_ok(VERIFY_READ, from, n))
372 n = __copy_from_user(to, from, n);
373 else /* security hole - plug it */
374@@ -412,6 +432,9 @@ static inline unsigned long __must_check
375
376 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
377 {
378+ if ((long)n < 0)
379+ return n;
380+
381 if (access_ok(VERIFY_WRITE, to, n))
382 n = __copy_to_user(to, from, n);
383 return n;
384diff -urNp linux-2.6.32.43/arch/arm/kernel/armksyms.c linux-2.6.32.43/arch/arm/kernel/armksyms.c
385--- linux-2.6.32.43/arch/arm/kernel/armksyms.c 2011-03-27 14:31:47.000000000 -0400
386+++ linux-2.6.32.43/arch/arm/kernel/armksyms.c 2011-07-06 19:51:50.000000000 -0400
387@@ -118,8 +118,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
388 #ifdef CONFIG_MMU
389 EXPORT_SYMBOL(copy_page);
390
391-EXPORT_SYMBOL(__copy_from_user);
392-EXPORT_SYMBOL(__copy_to_user);
393+EXPORT_SYMBOL(___copy_from_user);
394+EXPORT_SYMBOL(___copy_to_user);
395 EXPORT_SYMBOL(__clear_user);
396
397 EXPORT_SYMBOL(__get_user_1);
398diff -urNp linux-2.6.32.43/arch/arm/kernel/kgdb.c linux-2.6.32.43/arch/arm/kernel/kgdb.c
399--- linux-2.6.32.43/arch/arm/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
400+++ linux-2.6.32.43/arch/arm/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
401@@ -190,7 +190,7 @@ void kgdb_arch_exit(void)
402 * and we handle the normal undef case within the do_undefinstr
403 * handler.
404 */
405-struct kgdb_arch arch_kgdb_ops = {
406+const struct kgdb_arch arch_kgdb_ops = {
407 #ifndef __ARMEB__
408 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
409 #else /* ! __ARMEB__ */
410diff -urNp linux-2.6.32.43/arch/arm/kernel/traps.c linux-2.6.32.43/arch/arm/kernel/traps.c
411--- linux-2.6.32.43/arch/arm/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
412+++ linux-2.6.32.43/arch/arm/kernel/traps.c 2011-06-13 21:31:18.000000000 -0400
413@@ -247,6 +247,8 @@ static void __die(const char *str, int e
414
415 DEFINE_SPINLOCK(die_lock);
416
417+extern void gr_handle_kernel_exploit(void);
418+
419 /*
420 * This function is protected against re-entrancy.
421 */
422@@ -271,6 +273,8 @@ NORET_TYPE void die(const char *str, str
423 if (panic_on_oops)
424 panic("Fatal exception");
425
426+ gr_handle_kernel_exploit();
427+
428 do_exit(SIGSEGV);
429 }
430
431diff -urNp linux-2.6.32.43/arch/arm/lib/copy_from_user.S linux-2.6.32.43/arch/arm/lib/copy_from_user.S
432--- linux-2.6.32.43/arch/arm/lib/copy_from_user.S 2011-03-27 14:31:47.000000000 -0400
433+++ linux-2.6.32.43/arch/arm/lib/copy_from_user.S 2011-06-29 20:48:38.000000000 -0400
434@@ -16,7 +16,7 @@
435 /*
436 * Prototype:
437 *
438- * size_t __copy_from_user(void *to, const void *from, size_t n)
439+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
440 *
441 * Purpose:
442 *
443@@ -84,11 +84,11 @@
444
445 .text
446
447-ENTRY(__copy_from_user)
448+ENTRY(___copy_from_user)
449
450 #include "copy_template.S"
451
452-ENDPROC(__copy_from_user)
453+ENDPROC(___copy_from_user)
454
455 .section .fixup,"ax"
456 .align 0
457diff -urNp linux-2.6.32.43/arch/arm/lib/copy_to_user.S linux-2.6.32.43/arch/arm/lib/copy_to_user.S
458--- linux-2.6.32.43/arch/arm/lib/copy_to_user.S 2011-03-27 14:31:47.000000000 -0400
459+++ linux-2.6.32.43/arch/arm/lib/copy_to_user.S 2011-06-29 20:46:49.000000000 -0400
460@@ -16,7 +16,7 @@
461 /*
462 * Prototype:
463 *
464- * size_t __copy_to_user(void *to, const void *from, size_t n)
465+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
466 *
467 * Purpose:
468 *
469@@ -88,11 +88,11 @@
470 .text
471
472 ENTRY(__copy_to_user_std)
473-WEAK(__copy_to_user)
474+WEAK(___copy_to_user)
475
476 #include "copy_template.S"
477
478-ENDPROC(__copy_to_user)
479+ENDPROC(___copy_to_user)
480
481 .section .fixup,"ax"
482 .align 0
483diff -urNp linux-2.6.32.43/arch/arm/lib/uaccess.S linux-2.6.32.43/arch/arm/lib/uaccess.S
484--- linux-2.6.32.43/arch/arm/lib/uaccess.S 2011-03-27 14:31:47.000000000 -0400
485+++ linux-2.6.32.43/arch/arm/lib/uaccess.S 2011-06-29 20:48:53.000000000 -0400
486@@ -19,7 +19,7 @@
487
488 #define PAGE_SHIFT 12
489
490-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
491+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
492 * Purpose : copy a block to user memory from kernel memory
493 * Params : to - user memory
494 * : from - kernel memory
495@@ -39,7 +39,7 @@ USER( strgtbt r3, [r0], #1) @ May fau
496 sub r2, r2, ip
497 b .Lc2u_dest_aligned
498
499-ENTRY(__copy_to_user)
500+ENTRY(___copy_to_user)
501 stmfd sp!, {r2, r4 - r7, lr}
502 cmp r2, #4
503 blt .Lc2u_not_enough
504@@ -277,14 +277,14 @@ USER( strgebt r3, [r0], #1) @ May fau
505 ldrgtb r3, [r1], #0
506 USER( strgtbt r3, [r0], #1) @ May fault
507 b .Lc2u_finished
508-ENDPROC(__copy_to_user)
509+ENDPROC(___copy_to_user)
510
511 .section .fixup,"ax"
512 .align 0
513 9001: ldmfd sp!, {r0, r4 - r7, pc}
514 .previous
515
516-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
517+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
518 * Purpose : copy a block from user memory to kernel memory
519 * Params : to - kernel memory
520 * : from - user memory
521@@ -303,7 +303,7 @@ USER( ldrgtbt r3, [r1], #1) @ May fau
522 sub r2, r2, ip
523 b .Lcfu_dest_aligned
524
525-ENTRY(__copy_from_user)
526+ENTRY(___copy_from_user)
527 stmfd sp!, {r0, r2, r4 - r7, lr}
528 cmp r2, #4
529 blt .Lcfu_not_enough
530@@ -543,7 +543,7 @@ USER( ldrgebt r3, [r1], #1) @ May fau
531 USER( ldrgtbt r3, [r1], #1) @ May fault
532 strgtb r3, [r0], #1
533 b .Lcfu_finished
534-ENDPROC(__copy_from_user)
535+ENDPROC(___copy_from_user)
536
537 .section .fixup,"ax"
538 .align 0
539diff -urNp linux-2.6.32.43/arch/arm/lib/uaccess_with_memcpy.c linux-2.6.32.43/arch/arm/lib/uaccess_with_memcpy.c
540--- linux-2.6.32.43/arch/arm/lib/uaccess_with_memcpy.c 2011-03-27 14:31:47.000000000 -0400
541+++ linux-2.6.32.43/arch/arm/lib/uaccess_with_memcpy.c 2011-06-29 20:44:35.000000000 -0400
542@@ -97,7 +97,7 @@ out:
543 }
544
545 unsigned long
546-__copy_to_user(void __user *to, const void *from, unsigned long n)
547+___copy_to_user(void __user *to, const void *from, unsigned long n)
548 {
549 /*
550 * This test is stubbed out of the main function above to keep
551diff -urNp linux-2.6.32.43/arch/arm/mach-at91/pm.c linux-2.6.32.43/arch/arm/mach-at91/pm.c
552--- linux-2.6.32.43/arch/arm/mach-at91/pm.c 2011-03-27 14:31:47.000000000 -0400
553+++ linux-2.6.32.43/arch/arm/mach-at91/pm.c 2011-04-17 15:56:45.000000000 -0400
554@@ -348,7 +348,7 @@ static void at91_pm_end(void)
555 }
556
557
558-static struct platform_suspend_ops at91_pm_ops ={
559+static const struct platform_suspend_ops at91_pm_ops ={
560 .valid = at91_pm_valid_state,
561 .begin = at91_pm_begin,
562 .enter = at91_pm_enter,
563diff -urNp linux-2.6.32.43/arch/arm/mach-omap1/pm.c linux-2.6.32.43/arch/arm/mach-omap1/pm.c
564--- linux-2.6.32.43/arch/arm/mach-omap1/pm.c 2011-03-27 14:31:47.000000000 -0400
565+++ linux-2.6.32.43/arch/arm/mach-omap1/pm.c 2011-04-17 15:56:45.000000000 -0400
566@@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq
567
568
569
570-static struct platform_suspend_ops omap_pm_ops ={
571+static const struct platform_suspend_ops omap_pm_ops ={
572 .prepare = omap_pm_prepare,
573 .enter = omap_pm_enter,
574 .finish = omap_pm_finish,
575diff -urNp linux-2.6.32.43/arch/arm/mach-omap2/pm24xx.c linux-2.6.32.43/arch/arm/mach-omap2/pm24xx.c
576--- linux-2.6.32.43/arch/arm/mach-omap2/pm24xx.c 2011-03-27 14:31:47.000000000 -0400
577+++ linux-2.6.32.43/arch/arm/mach-omap2/pm24xx.c 2011-04-17 15:56:45.000000000 -0400
578@@ -326,7 +326,7 @@ static void omap2_pm_finish(void)
579 enable_hlt();
580 }
581
582-static struct platform_suspend_ops omap_pm_ops = {
583+static const struct platform_suspend_ops omap_pm_ops = {
584 .prepare = omap2_pm_prepare,
585 .enter = omap2_pm_enter,
586 .finish = omap2_pm_finish,
587diff -urNp linux-2.6.32.43/arch/arm/mach-omap2/pm34xx.c linux-2.6.32.43/arch/arm/mach-omap2/pm34xx.c
588--- linux-2.6.32.43/arch/arm/mach-omap2/pm34xx.c 2011-03-27 14:31:47.000000000 -0400
589+++ linux-2.6.32.43/arch/arm/mach-omap2/pm34xx.c 2011-04-17 15:56:45.000000000 -0400
590@@ -401,7 +401,7 @@ static void omap3_pm_end(void)
591 return;
592 }
593
594-static struct platform_suspend_ops omap_pm_ops = {
595+static const struct platform_suspend_ops omap_pm_ops = {
596 .begin = omap3_pm_begin,
597 .end = omap3_pm_end,
598 .prepare = omap3_pm_prepare,
599diff -urNp linux-2.6.32.43/arch/arm/mach-pnx4008/pm.c linux-2.6.32.43/arch/arm/mach-pnx4008/pm.c
600--- linux-2.6.32.43/arch/arm/mach-pnx4008/pm.c 2011-03-27 14:31:47.000000000 -0400
601+++ linux-2.6.32.43/arch/arm/mach-pnx4008/pm.c 2011-04-17 15:56:45.000000000 -0400
602@@ -116,7 +116,7 @@ static int pnx4008_pm_valid(suspend_stat
603 (state == PM_SUSPEND_MEM);
604 }
605
606-static struct platform_suspend_ops pnx4008_pm_ops = {
607+static const struct platform_suspend_ops pnx4008_pm_ops = {
608 .enter = pnx4008_pm_enter,
609 .valid = pnx4008_pm_valid,
610 };
611diff -urNp linux-2.6.32.43/arch/arm/mach-pxa/pm.c linux-2.6.32.43/arch/arm/mach-pxa/pm.c
612--- linux-2.6.32.43/arch/arm/mach-pxa/pm.c 2011-03-27 14:31:47.000000000 -0400
613+++ linux-2.6.32.43/arch/arm/mach-pxa/pm.c 2011-04-17 15:56:45.000000000 -0400
614@@ -95,7 +95,7 @@ void pxa_pm_finish(void)
615 pxa_cpu_pm_fns->finish();
616 }
617
618-static struct platform_suspend_ops pxa_pm_ops = {
619+static const struct platform_suspend_ops pxa_pm_ops = {
620 .valid = pxa_pm_valid,
621 .enter = pxa_pm_enter,
622 .prepare = pxa_pm_prepare,
623diff -urNp linux-2.6.32.43/arch/arm/mach-pxa/sharpsl_pm.c linux-2.6.32.43/arch/arm/mach-pxa/sharpsl_pm.c
624--- linux-2.6.32.43/arch/arm/mach-pxa/sharpsl_pm.c 2011-03-27 14:31:47.000000000 -0400
625+++ linux-2.6.32.43/arch/arm/mach-pxa/sharpsl_pm.c 2011-04-17 15:56:45.000000000 -0400
626@@ -891,7 +891,7 @@ static void sharpsl_apm_get_power_status
627 }
628
629 #ifdef CONFIG_PM
630-static struct platform_suspend_ops sharpsl_pm_ops = {
631+static const struct platform_suspend_ops sharpsl_pm_ops = {
632 .prepare = pxa_pm_prepare,
633 .finish = pxa_pm_finish,
634 .enter = corgi_pxa_pm_enter,
635diff -urNp linux-2.6.32.43/arch/arm/mach-sa1100/pm.c linux-2.6.32.43/arch/arm/mach-sa1100/pm.c
636--- linux-2.6.32.43/arch/arm/mach-sa1100/pm.c 2011-03-27 14:31:47.000000000 -0400
637+++ linux-2.6.32.43/arch/arm/mach-sa1100/pm.c 2011-04-17 15:56:45.000000000 -0400
638@@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
639 return virt_to_phys(sp);
640 }
641
642-static struct platform_suspend_ops sa11x0_pm_ops = {
643+static const struct platform_suspend_ops sa11x0_pm_ops = {
644 .enter = sa11x0_pm_enter,
645 .valid = suspend_valid_only_mem,
646 };
647diff -urNp linux-2.6.32.43/arch/arm/mm/fault.c linux-2.6.32.43/arch/arm/mm/fault.c
648--- linux-2.6.32.43/arch/arm/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
649+++ linux-2.6.32.43/arch/arm/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
650@@ -166,6 +166,13 @@ __do_user_fault(struct task_struct *tsk,
651 }
652 #endif
653
654+#ifdef CONFIG_PAX_PAGEEXEC
655+ if (fsr & FSR_LNX_PF) {
656+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
657+ do_group_exit(SIGKILL);
658+ }
659+#endif
660+
661 tsk->thread.address = addr;
662 tsk->thread.error_code = fsr;
663 tsk->thread.trap_no = 14;
664@@ -357,6 +364,33 @@ do_page_fault(unsigned long addr, unsign
665 }
666 #endif /* CONFIG_MMU */
667
668+#ifdef CONFIG_PAX_PAGEEXEC
669+void pax_report_insns(void *pc, void *sp)
670+{
671+ long i;
672+
673+ printk(KERN_ERR "PAX: bytes at PC: ");
674+ for (i = 0; i < 20; i++) {
675+ unsigned char c;
676+ if (get_user(c, (__force unsigned char __user *)pc+i))
677+ printk(KERN_CONT "?? ");
678+ else
679+ printk(KERN_CONT "%02x ", c);
680+ }
681+ printk("\n");
682+
683+ printk(KERN_ERR "PAX: bytes at SP-4: ");
684+ for (i = -1; i < 20; i++) {
685+ unsigned long c;
686+ if (get_user(c, (__force unsigned long __user *)sp+i))
687+ printk(KERN_CONT "???????? ");
688+ else
689+ printk(KERN_CONT "%08lx ", c);
690+ }
691+ printk("\n");
692+}
693+#endif
694+
695 /*
696 * First Level Translation Fault Handler
697 *
698diff -urNp linux-2.6.32.43/arch/arm/mm/mmap.c linux-2.6.32.43/arch/arm/mm/mmap.c
699--- linux-2.6.32.43/arch/arm/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
700+++ linux-2.6.32.43/arch/arm/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
701@@ -63,6 +63,10 @@ arch_get_unmapped_area(struct file *filp
702 if (len > TASK_SIZE)
703 return -ENOMEM;
704
705+#ifdef CONFIG_PAX_RANDMMAP
706+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
707+#endif
708+
709 if (addr) {
710 if (do_align)
711 addr = COLOUR_ALIGN(addr, pgoff);
712@@ -70,15 +74,14 @@ arch_get_unmapped_area(struct file *filp
713 addr = PAGE_ALIGN(addr);
714
715 vma = find_vma(mm, addr);
716- if (TASK_SIZE - len >= addr &&
717- (!vma || addr + len <= vma->vm_start))
718+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
719 return addr;
720 }
721 if (len > mm->cached_hole_size) {
722- start_addr = addr = mm->free_area_cache;
723+ start_addr = addr = mm->free_area_cache;
724 } else {
725- start_addr = addr = TASK_UNMAPPED_BASE;
726- mm->cached_hole_size = 0;
727+ start_addr = addr = mm->mmap_base;
728+ mm->cached_hole_size = 0;
729 }
730
731 full_search:
732@@ -94,14 +97,14 @@ full_search:
733 * Start a new search - just in case we missed
734 * some holes.
735 */
736- if (start_addr != TASK_UNMAPPED_BASE) {
737- start_addr = addr = TASK_UNMAPPED_BASE;
738+ if (start_addr != mm->mmap_base) {
739+ start_addr = addr = mm->mmap_base;
740 mm->cached_hole_size = 0;
741 goto full_search;
742 }
743 return -ENOMEM;
744 }
745- if (!vma || addr + len <= vma->vm_start) {
746+ if (check_heap_stack_gap(vma, addr, len)) {
747 /*
748 * Remember the place where we stopped the search:
749 */
750diff -urNp linux-2.6.32.43/arch/arm/plat-s3c/pm.c linux-2.6.32.43/arch/arm/plat-s3c/pm.c
751--- linux-2.6.32.43/arch/arm/plat-s3c/pm.c 2011-03-27 14:31:47.000000000 -0400
752+++ linux-2.6.32.43/arch/arm/plat-s3c/pm.c 2011-04-17 15:56:45.000000000 -0400
753@@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
754 s3c_pm_check_cleanup();
755 }
756
757-static struct platform_suspend_ops s3c_pm_ops = {
758+static const struct platform_suspend_ops s3c_pm_ops = {
759 .enter = s3c_pm_enter,
760 .prepare = s3c_pm_prepare,
761 .finish = s3c_pm_finish,
762diff -urNp linux-2.6.32.43/arch/avr32/include/asm/elf.h linux-2.6.32.43/arch/avr32/include/asm/elf.h
763--- linux-2.6.32.43/arch/avr32/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
764+++ linux-2.6.32.43/arch/avr32/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
765@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
766 the loader. We need to make sure that it is out of the way of the program
767 that it will "exec", and that there is sufficient room for the brk. */
768
769-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
770+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
771
772+#ifdef CONFIG_PAX_ASLR
773+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
774+
775+#define PAX_DELTA_MMAP_LEN 15
776+#define PAX_DELTA_STACK_LEN 15
777+#endif
778
779 /* This yields a mask that user programs can use to figure out what
780 instruction set this CPU supports. This could be done in user space,
781diff -urNp linux-2.6.32.43/arch/avr32/include/asm/kmap_types.h linux-2.6.32.43/arch/avr32/include/asm/kmap_types.h
782--- linux-2.6.32.43/arch/avr32/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
783+++ linux-2.6.32.43/arch/avr32/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
784@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
785 D(11) KM_IRQ1,
786 D(12) KM_SOFTIRQ0,
787 D(13) KM_SOFTIRQ1,
788-D(14) KM_TYPE_NR
789+D(14) KM_CLEARPAGE,
790+D(15) KM_TYPE_NR
791 };
792
793 #undef D
794diff -urNp linux-2.6.32.43/arch/avr32/mach-at32ap/pm.c linux-2.6.32.43/arch/avr32/mach-at32ap/pm.c
795--- linux-2.6.32.43/arch/avr32/mach-at32ap/pm.c 2011-03-27 14:31:47.000000000 -0400
796+++ linux-2.6.32.43/arch/avr32/mach-at32ap/pm.c 2011-04-17 15:56:45.000000000 -0400
797@@ -176,7 +176,7 @@ out:
798 return 0;
799 }
800
801-static struct platform_suspend_ops avr32_pm_ops = {
802+static const struct platform_suspend_ops avr32_pm_ops = {
803 .valid = avr32_pm_valid_state,
804 .enter = avr32_pm_enter,
805 };
806diff -urNp linux-2.6.32.43/arch/avr32/mm/fault.c linux-2.6.32.43/arch/avr32/mm/fault.c
807--- linux-2.6.32.43/arch/avr32/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
808+++ linux-2.6.32.43/arch/avr32/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
809@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
810
811 int exception_trace = 1;
812
813+#ifdef CONFIG_PAX_PAGEEXEC
814+void pax_report_insns(void *pc, void *sp)
815+{
816+ unsigned long i;
817+
818+ printk(KERN_ERR "PAX: bytes at PC: ");
819+ for (i = 0; i < 20; i++) {
820+ unsigned char c;
821+ if (get_user(c, (unsigned char *)pc+i))
822+ printk(KERN_CONT "???????? ");
823+ else
824+ printk(KERN_CONT "%02x ", c);
825+ }
826+ printk("\n");
827+}
828+#endif
829+
830 /*
831 * This routine handles page faults. It determines the address and the
832 * problem, and then passes it off to one of the appropriate routines.
833@@ -157,6 +174,16 @@ bad_area:
834 up_read(&mm->mmap_sem);
835
836 if (user_mode(regs)) {
837+
838+#ifdef CONFIG_PAX_PAGEEXEC
839+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
840+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
841+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
842+ do_group_exit(SIGKILL);
843+ }
844+ }
845+#endif
846+
847 if (exception_trace && printk_ratelimit())
848 printk("%s%s[%d]: segfault at %08lx pc %08lx "
849 "sp %08lx ecr %lu\n",
850diff -urNp linux-2.6.32.43/arch/blackfin/kernel/kgdb.c linux-2.6.32.43/arch/blackfin/kernel/kgdb.c
851--- linux-2.6.32.43/arch/blackfin/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
852+++ linux-2.6.32.43/arch/blackfin/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
853@@ -428,7 +428,7 @@ int kgdb_arch_handle_exception(int vecto
854 return -1; /* this means that we do not want to exit from the handler */
855 }
856
857-struct kgdb_arch arch_kgdb_ops = {
858+const struct kgdb_arch arch_kgdb_ops = {
859 .gdb_bpt_instr = {0xa1},
860 #ifdef CONFIG_SMP
861 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
862diff -urNp linux-2.6.32.43/arch/blackfin/mach-common/pm.c linux-2.6.32.43/arch/blackfin/mach-common/pm.c
863--- linux-2.6.32.43/arch/blackfin/mach-common/pm.c 2011-03-27 14:31:47.000000000 -0400
864+++ linux-2.6.32.43/arch/blackfin/mach-common/pm.c 2011-04-17 15:56:45.000000000 -0400
865@@ -255,7 +255,7 @@ static int bfin_pm_enter(suspend_state_t
866 return 0;
867 }
868
869-struct platform_suspend_ops bfin_pm_ops = {
870+const struct platform_suspend_ops bfin_pm_ops = {
871 .enter = bfin_pm_enter,
872 .valid = bfin_pm_valid,
873 };
874diff -urNp linux-2.6.32.43/arch/frv/include/asm/kmap_types.h linux-2.6.32.43/arch/frv/include/asm/kmap_types.h
875--- linux-2.6.32.43/arch/frv/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
876+++ linux-2.6.32.43/arch/frv/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
877@@ -23,6 +23,7 @@ enum km_type {
878 KM_IRQ1,
879 KM_SOFTIRQ0,
880 KM_SOFTIRQ1,
881+ KM_CLEARPAGE,
882 KM_TYPE_NR
883 };
884
885diff -urNp linux-2.6.32.43/arch/frv/mm/elf-fdpic.c linux-2.6.32.43/arch/frv/mm/elf-fdpic.c
886--- linux-2.6.32.43/arch/frv/mm/elf-fdpic.c 2011-03-27 14:31:47.000000000 -0400
887+++ linux-2.6.32.43/arch/frv/mm/elf-fdpic.c 2011-04-17 15:56:45.000000000 -0400
888@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
889 if (addr) {
890 addr = PAGE_ALIGN(addr);
891 vma = find_vma(current->mm, addr);
892- if (TASK_SIZE - len >= addr &&
893- (!vma || addr + len <= vma->vm_start))
894+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
895 goto success;
896 }
897
898@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
899 for (; vma; vma = vma->vm_next) {
900 if (addr > limit)
901 break;
902- if (addr + len <= vma->vm_start)
903+ if (check_heap_stack_gap(vma, addr, len))
904 goto success;
905 addr = vma->vm_end;
906 }
907@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
908 for (; vma; vma = vma->vm_next) {
909 if (addr > limit)
910 break;
911- if (addr + len <= vma->vm_start)
912+ if (check_heap_stack_gap(vma, addr, len))
913 goto success;
914 addr = vma->vm_end;
915 }
916diff -urNp linux-2.6.32.43/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.32.43/arch/ia64/hp/common/hwsw_iommu.c
917--- linux-2.6.32.43/arch/ia64/hp/common/hwsw_iommu.c 2011-03-27 14:31:47.000000000 -0400
918+++ linux-2.6.32.43/arch/ia64/hp/common/hwsw_iommu.c 2011-04-17 15:56:45.000000000 -0400
919@@ -17,7 +17,7 @@
920 #include <linux/swiotlb.h>
921 #include <asm/machvec.h>
922
923-extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
924+extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
925
926 /* swiotlb declarations & definitions: */
927 extern int swiotlb_late_init_with_default_size (size_t size);
928@@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
929 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
930 }
931
932-struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
933+const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
934 {
935 if (use_swiotlb(dev))
936 return &swiotlb_dma_ops;
937diff -urNp linux-2.6.32.43/arch/ia64/hp/common/sba_iommu.c linux-2.6.32.43/arch/ia64/hp/common/sba_iommu.c
938--- linux-2.6.32.43/arch/ia64/hp/common/sba_iommu.c 2011-03-27 14:31:47.000000000 -0400
939+++ linux-2.6.32.43/arch/ia64/hp/common/sba_iommu.c 2011-04-17 15:56:45.000000000 -0400
940@@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
941 },
942 };
943
944-extern struct dma_map_ops swiotlb_dma_ops;
945+extern const struct dma_map_ops swiotlb_dma_ops;
946
947 static int __init
948 sba_init(void)
949@@ -2211,7 +2211,7 @@ sba_page_override(char *str)
950
951 __setup("sbapagesize=",sba_page_override);
952
953-struct dma_map_ops sba_dma_ops = {
954+const struct dma_map_ops sba_dma_ops = {
955 .alloc_coherent = sba_alloc_coherent,
956 .free_coherent = sba_free_coherent,
957 .map_page = sba_map_page,
958diff -urNp linux-2.6.32.43/arch/ia64/ia32/binfmt_elf32.c linux-2.6.32.43/arch/ia64/ia32/binfmt_elf32.c
959--- linux-2.6.32.43/arch/ia64/ia32/binfmt_elf32.c 2011-03-27 14:31:47.000000000 -0400
960+++ linux-2.6.32.43/arch/ia64/ia32/binfmt_elf32.c 2011-04-17 15:56:45.000000000 -0400
961@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
962
963 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
964
965+#ifdef CONFIG_PAX_ASLR
966+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
967+
968+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
969+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
970+#endif
971+
972 /* Ugly but avoids duplication */
973 #include "../../../fs/binfmt_elf.c"
974
975diff -urNp linux-2.6.32.43/arch/ia64/ia32/ia32priv.h linux-2.6.32.43/arch/ia64/ia32/ia32priv.h
976--- linux-2.6.32.43/arch/ia64/ia32/ia32priv.h 2011-03-27 14:31:47.000000000 -0400
977+++ linux-2.6.32.43/arch/ia64/ia32/ia32priv.h 2011-04-17 15:56:45.000000000 -0400
978@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
979 #define ELF_DATA ELFDATA2LSB
980 #define ELF_ARCH EM_386
981
982-#define IA32_STACK_TOP IA32_PAGE_OFFSET
983+#ifdef CONFIG_PAX_RANDUSTACK
984+#define __IA32_DELTA_STACK (current->mm->delta_stack)
985+#else
986+#define __IA32_DELTA_STACK 0UL
987+#endif
988+
989+#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
990+
991 #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
992 #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
993
994diff -urNp linux-2.6.32.43/arch/ia64/include/asm/dma-mapping.h linux-2.6.32.43/arch/ia64/include/asm/dma-mapping.h
995--- linux-2.6.32.43/arch/ia64/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
996+++ linux-2.6.32.43/arch/ia64/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
997@@ -12,7 +12,7 @@
998
999 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
1000
1001-extern struct dma_map_ops *dma_ops;
1002+extern const struct dma_map_ops *dma_ops;
1003 extern struct ia64_machine_vector ia64_mv;
1004 extern void set_iommu_machvec(void);
1005
1006@@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct d
1007 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1008 dma_addr_t *daddr, gfp_t gfp)
1009 {
1010- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1011+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1012 void *caddr;
1013
1014 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1015@@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(s
1016 static inline void dma_free_coherent(struct device *dev, size_t size,
1017 void *caddr, dma_addr_t daddr)
1018 {
1019- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1020+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1021 debug_dma_free_coherent(dev, size, caddr, daddr);
1022 ops->free_coherent(dev, size, caddr, daddr);
1023 }
1024@@ -49,13 +49,13 @@ static inline void dma_free_coherent(str
1025
1026 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1027 {
1028- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1029+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1030 return ops->mapping_error(dev, daddr);
1031 }
1032
1033 static inline int dma_supported(struct device *dev, u64 mask)
1034 {
1035- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1036+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1037 return ops->dma_supported(dev, mask);
1038 }
1039
1040diff -urNp linux-2.6.32.43/arch/ia64/include/asm/elf.h linux-2.6.32.43/arch/ia64/include/asm/elf.h
1041--- linux-2.6.32.43/arch/ia64/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1042+++ linux-2.6.32.43/arch/ia64/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1043@@ -43,6 +43,13 @@
1044 */
1045 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1046
1047+#ifdef CONFIG_PAX_ASLR
1048+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1049+
1050+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1051+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1052+#endif
1053+
1054 #define PT_IA_64_UNWIND 0x70000001
1055
1056 /* IA-64 relocations: */
1057diff -urNp linux-2.6.32.43/arch/ia64/include/asm/machvec.h linux-2.6.32.43/arch/ia64/include/asm/machvec.h
1058--- linux-2.6.32.43/arch/ia64/include/asm/machvec.h 2011-03-27 14:31:47.000000000 -0400
1059+++ linux-2.6.32.43/arch/ia64/include/asm/machvec.h 2011-04-17 15:56:45.000000000 -0400
1060@@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1061 /* DMA-mapping interface: */
1062 typedef void ia64_mv_dma_init (void);
1063 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1064-typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1065+typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1066
1067 /*
1068 * WARNING: The legacy I/O space is _architected_. Platforms are
1069@@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1070 # endif /* CONFIG_IA64_GENERIC */
1071
1072 extern void swiotlb_dma_init(void);
1073-extern struct dma_map_ops *dma_get_ops(struct device *);
1074+extern const struct dma_map_ops *dma_get_ops(struct device *);
1075
1076 /*
1077 * Define default versions so we can extend machvec for new platforms without having
1078diff -urNp linux-2.6.32.43/arch/ia64/include/asm/pgtable.h linux-2.6.32.43/arch/ia64/include/asm/pgtable.h
1079--- linux-2.6.32.43/arch/ia64/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1080+++ linux-2.6.32.43/arch/ia64/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1081@@ -12,7 +12,7 @@
1082 * David Mosberger-Tang <davidm@hpl.hp.com>
1083 */
1084
1085-
1086+#include <linux/const.h>
1087 #include <asm/mman.h>
1088 #include <asm/page.h>
1089 #include <asm/processor.h>
1090@@ -143,6 +143,17 @@
1091 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1092 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1093 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1094+
1095+#ifdef CONFIG_PAX_PAGEEXEC
1096+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1097+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1098+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1099+#else
1100+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1101+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1102+# define PAGE_COPY_NOEXEC PAGE_COPY
1103+#endif
1104+
1105 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1106 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1107 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1108diff -urNp linux-2.6.32.43/arch/ia64/include/asm/spinlock.h linux-2.6.32.43/arch/ia64/include/asm/spinlock.h
1109--- linux-2.6.32.43/arch/ia64/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
1110+++ linux-2.6.32.43/arch/ia64/include/asm/spinlock.h 2011-04-17 15:56:45.000000000 -0400
1111@@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1112 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1113
1114 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1115- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1116+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1117 }
1118
1119 static __always_inline void __ticket_spin_unlock_wait(raw_spinlock_t *lock)
1120diff -urNp linux-2.6.32.43/arch/ia64/include/asm/uaccess.h linux-2.6.32.43/arch/ia64/include/asm/uaccess.h
1121--- linux-2.6.32.43/arch/ia64/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
1122+++ linux-2.6.32.43/arch/ia64/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
1123@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1124 const void *__cu_from = (from); \
1125 long __cu_len = (n); \
1126 \
1127- if (__access_ok(__cu_to, __cu_len, get_fs())) \
1128+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1129 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1130 __cu_len; \
1131 })
1132@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1133 long __cu_len = (n); \
1134 \
1135 __chk_user_ptr(__cu_from); \
1136- if (__access_ok(__cu_from, __cu_len, get_fs())) \
1137+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1138 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1139 __cu_len; \
1140 })
1141diff -urNp linux-2.6.32.43/arch/ia64/kernel/dma-mapping.c linux-2.6.32.43/arch/ia64/kernel/dma-mapping.c
1142--- linux-2.6.32.43/arch/ia64/kernel/dma-mapping.c 2011-03-27 14:31:47.000000000 -0400
1143+++ linux-2.6.32.43/arch/ia64/kernel/dma-mapping.c 2011-04-17 15:56:45.000000000 -0400
1144@@ -3,7 +3,7 @@
1145 /* Set this to 1 if there is a HW IOMMU in the system */
1146 int iommu_detected __read_mostly;
1147
1148-struct dma_map_ops *dma_ops;
1149+const struct dma_map_ops *dma_ops;
1150 EXPORT_SYMBOL(dma_ops);
1151
1152 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1153@@ -16,7 +16,7 @@ static int __init dma_init(void)
1154 }
1155 fs_initcall(dma_init);
1156
1157-struct dma_map_ops *dma_get_ops(struct device *dev)
1158+const struct dma_map_ops *dma_get_ops(struct device *dev)
1159 {
1160 return dma_ops;
1161 }
1162diff -urNp linux-2.6.32.43/arch/ia64/kernel/module.c linux-2.6.32.43/arch/ia64/kernel/module.c
1163--- linux-2.6.32.43/arch/ia64/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
1164+++ linux-2.6.32.43/arch/ia64/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
1165@@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1166 void
1167 module_free (struct module *mod, void *module_region)
1168 {
1169- if (mod && mod->arch.init_unw_table &&
1170- module_region == mod->module_init) {
1171+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1172 unw_remove_unwind_table(mod->arch.init_unw_table);
1173 mod->arch.init_unw_table = NULL;
1174 }
1175@@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1176 }
1177
1178 static inline int
1179+in_init_rx (const struct module *mod, uint64_t addr)
1180+{
1181+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1182+}
1183+
1184+static inline int
1185+in_init_rw (const struct module *mod, uint64_t addr)
1186+{
1187+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1188+}
1189+
1190+static inline int
1191 in_init (const struct module *mod, uint64_t addr)
1192 {
1193- return addr - (uint64_t) mod->module_init < mod->init_size;
1194+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1195+}
1196+
1197+static inline int
1198+in_core_rx (const struct module *mod, uint64_t addr)
1199+{
1200+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1201+}
1202+
1203+static inline int
1204+in_core_rw (const struct module *mod, uint64_t addr)
1205+{
1206+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1207 }
1208
1209 static inline int
1210 in_core (const struct module *mod, uint64_t addr)
1211 {
1212- return addr - (uint64_t) mod->module_core < mod->core_size;
1213+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1214 }
1215
1216 static inline int
1217@@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1218 break;
1219
1220 case RV_BDREL:
1221- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1222+ if (in_init_rx(mod, val))
1223+ val -= (uint64_t) mod->module_init_rx;
1224+ else if (in_init_rw(mod, val))
1225+ val -= (uint64_t) mod->module_init_rw;
1226+ else if (in_core_rx(mod, val))
1227+ val -= (uint64_t) mod->module_core_rx;
1228+ else if (in_core_rw(mod, val))
1229+ val -= (uint64_t) mod->module_core_rw;
1230 break;
1231
1232 case RV_LTV:
1233@@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1234 * addresses have been selected...
1235 */
1236 uint64_t gp;
1237- if (mod->core_size > MAX_LTOFF)
1238+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1239 /*
1240 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1241 * at the end of the module.
1242 */
1243- gp = mod->core_size - MAX_LTOFF / 2;
1244+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1245 else
1246- gp = mod->core_size / 2;
1247- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1248+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1249+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1250 mod->arch.gp = gp;
1251 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1252 }
1253diff -urNp linux-2.6.32.43/arch/ia64/kernel/pci-dma.c linux-2.6.32.43/arch/ia64/kernel/pci-dma.c
1254--- linux-2.6.32.43/arch/ia64/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
1255+++ linux-2.6.32.43/arch/ia64/kernel/pci-dma.c 2011-04-17 15:56:45.000000000 -0400
1256@@ -43,7 +43,7 @@ struct device fallback_dev = {
1257 .dma_mask = &fallback_dev.coherent_dma_mask,
1258 };
1259
1260-extern struct dma_map_ops intel_dma_ops;
1261+extern const struct dma_map_ops intel_dma_ops;
1262
1263 static int __init pci_iommu_init(void)
1264 {
1265@@ -96,15 +96,34 @@ int iommu_dma_supported(struct device *d
1266 }
1267 EXPORT_SYMBOL(iommu_dma_supported);
1268
1269+extern void *intel_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags);
1270+extern void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
1271+extern int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1272+extern void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1273+extern dma_addr_t intel_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1274+extern void intel_unmap_page(struct device *dev, dma_addr_t dev_addr, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
1275+extern int intel_mapping_error(struct device *dev, dma_addr_t dma_addr);
1276+
1277+static const struct dma_map_ops intel_iommu_dma_ops = {
1278+ /* from drivers/pci/intel-iommu.c:intel_dma_ops */
1279+ .alloc_coherent = intel_alloc_coherent,
1280+ .free_coherent = intel_free_coherent,
1281+ .map_sg = intel_map_sg,
1282+ .unmap_sg = intel_unmap_sg,
1283+ .map_page = intel_map_page,
1284+ .unmap_page = intel_unmap_page,
1285+ .mapping_error = intel_mapping_error,
1286+
1287+ .sync_single_for_cpu = machvec_dma_sync_single,
1288+ .sync_sg_for_cpu = machvec_dma_sync_sg,
1289+ .sync_single_for_device = machvec_dma_sync_single,
1290+ .sync_sg_for_device = machvec_dma_sync_sg,
1291+ .dma_supported = iommu_dma_supported,
1292+};
1293+
1294 void __init pci_iommu_alloc(void)
1295 {
1296- dma_ops = &intel_dma_ops;
1297-
1298- dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
1299- dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
1300- dma_ops->sync_single_for_device = machvec_dma_sync_single;
1301- dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
1302- dma_ops->dma_supported = iommu_dma_supported;
1303+ dma_ops = &intel_iommu_dma_ops;
1304
1305 /*
1306 * The order of these functions is important for
1307diff -urNp linux-2.6.32.43/arch/ia64/kernel/pci-swiotlb.c linux-2.6.32.43/arch/ia64/kernel/pci-swiotlb.c
1308--- linux-2.6.32.43/arch/ia64/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
1309+++ linux-2.6.32.43/arch/ia64/kernel/pci-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
1310@@ -21,7 +21,7 @@ static void *ia64_swiotlb_alloc_coherent
1311 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1312 }
1313
1314-struct dma_map_ops swiotlb_dma_ops = {
1315+const struct dma_map_ops swiotlb_dma_ops = {
1316 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1317 .free_coherent = swiotlb_free_coherent,
1318 .map_page = swiotlb_map_page,
1319diff -urNp linux-2.6.32.43/arch/ia64/kernel/sys_ia64.c linux-2.6.32.43/arch/ia64/kernel/sys_ia64.c
1320--- linux-2.6.32.43/arch/ia64/kernel/sys_ia64.c 2011-03-27 14:31:47.000000000 -0400
1321+++ linux-2.6.32.43/arch/ia64/kernel/sys_ia64.c 2011-04-17 15:56:45.000000000 -0400
1322@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1323 if (REGION_NUMBER(addr) == RGN_HPAGE)
1324 addr = 0;
1325 #endif
1326+
1327+#ifdef CONFIG_PAX_RANDMMAP
1328+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1329+ addr = mm->free_area_cache;
1330+ else
1331+#endif
1332+
1333 if (!addr)
1334 addr = mm->free_area_cache;
1335
1336@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1337 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1338 /* At this point: (!vma || addr < vma->vm_end). */
1339 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1340- if (start_addr != TASK_UNMAPPED_BASE) {
1341+ if (start_addr != mm->mmap_base) {
1342 /* Start a new search --- just in case we missed some holes. */
1343- addr = TASK_UNMAPPED_BASE;
1344+ addr = mm->mmap_base;
1345 goto full_search;
1346 }
1347 return -ENOMEM;
1348 }
1349- if (!vma || addr + len <= vma->vm_start) {
1350+ if (check_heap_stack_gap(vma, addr, len)) {
1351 /* Remember the address where we stopped this search: */
1352 mm->free_area_cache = addr + len;
1353 return addr;
1354diff -urNp linux-2.6.32.43/arch/ia64/kernel/topology.c linux-2.6.32.43/arch/ia64/kernel/topology.c
1355--- linux-2.6.32.43/arch/ia64/kernel/topology.c 2011-03-27 14:31:47.000000000 -0400
1356+++ linux-2.6.32.43/arch/ia64/kernel/topology.c 2011-04-17 15:56:45.000000000 -0400
1357@@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject
1358 return ret;
1359 }
1360
1361-static struct sysfs_ops cache_sysfs_ops = {
1362+static const struct sysfs_ops cache_sysfs_ops = {
1363 .show = cache_show
1364 };
1365
1366diff -urNp linux-2.6.32.43/arch/ia64/kernel/vmlinux.lds.S linux-2.6.32.43/arch/ia64/kernel/vmlinux.lds.S
1367--- linux-2.6.32.43/arch/ia64/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
1368+++ linux-2.6.32.43/arch/ia64/kernel/vmlinux.lds.S 2011-04-17 15:56:45.000000000 -0400
1369@@ -190,7 +190,7 @@ SECTIONS
1370 /* Per-cpu data: */
1371 . = ALIGN(PERCPU_PAGE_SIZE);
1372 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1373- __phys_per_cpu_start = __per_cpu_load;
1374+ __phys_per_cpu_start = per_cpu_load;
1375 . = __phys_per_cpu_start + PERCPU_PAGE_SIZE; /* ensure percpu data fits
1376 * into percpu page size
1377 */
1378diff -urNp linux-2.6.32.43/arch/ia64/mm/fault.c linux-2.6.32.43/arch/ia64/mm/fault.c
1379--- linux-2.6.32.43/arch/ia64/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1380+++ linux-2.6.32.43/arch/ia64/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1381@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1382 return pte_present(pte);
1383 }
1384
1385+#ifdef CONFIG_PAX_PAGEEXEC
1386+void pax_report_insns(void *pc, void *sp)
1387+{
1388+ unsigned long i;
1389+
1390+ printk(KERN_ERR "PAX: bytes at PC: ");
1391+ for (i = 0; i < 8; i++) {
1392+ unsigned int c;
1393+ if (get_user(c, (unsigned int *)pc+i))
1394+ printk(KERN_CONT "???????? ");
1395+ else
1396+ printk(KERN_CONT "%08x ", c);
1397+ }
1398+ printk("\n");
1399+}
1400+#endif
1401+
1402 void __kprobes
1403 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1404 {
1405@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1406 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1407 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1408
1409- if ((vma->vm_flags & mask) != mask)
1410+ if ((vma->vm_flags & mask) != mask) {
1411+
1412+#ifdef CONFIG_PAX_PAGEEXEC
1413+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1414+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1415+ goto bad_area;
1416+
1417+ up_read(&mm->mmap_sem);
1418+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1419+ do_group_exit(SIGKILL);
1420+ }
1421+#endif
1422+
1423 goto bad_area;
1424
1425+ }
1426+
1427 survive:
1428 /*
1429 * If for any reason at all we couldn't handle the fault, make
1430diff -urNp linux-2.6.32.43/arch/ia64/mm/hugetlbpage.c linux-2.6.32.43/arch/ia64/mm/hugetlbpage.c
1431--- linux-2.6.32.43/arch/ia64/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
1432+++ linux-2.6.32.43/arch/ia64/mm/hugetlbpage.c 2011-04-17 15:56:45.000000000 -0400
1433@@ -172,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(
1434 /* At this point: (!vmm || addr < vmm->vm_end). */
1435 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1436 return -ENOMEM;
1437- if (!vmm || (addr + len) <= vmm->vm_start)
1438+ if (check_heap_stack_gap(vmm, addr, len))
1439 return addr;
1440 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1441 }
1442diff -urNp linux-2.6.32.43/arch/ia64/mm/init.c linux-2.6.32.43/arch/ia64/mm/init.c
1443--- linux-2.6.32.43/arch/ia64/mm/init.c 2011-03-27 14:31:47.000000000 -0400
1444+++ linux-2.6.32.43/arch/ia64/mm/init.c 2011-04-17 15:56:45.000000000 -0400
1445@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1446 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1447 vma->vm_end = vma->vm_start + PAGE_SIZE;
1448 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1449+
1450+#ifdef CONFIG_PAX_PAGEEXEC
1451+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1452+ vma->vm_flags &= ~VM_EXEC;
1453+
1454+#ifdef CONFIG_PAX_MPROTECT
1455+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
1456+ vma->vm_flags &= ~VM_MAYEXEC;
1457+#endif
1458+
1459+ }
1460+#endif
1461+
1462 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1463 down_write(&current->mm->mmap_sem);
1464 if (insert_vm_struct(current->mm, vma)) {
1465diff -urNp linux-2.6.32.43/arch/ia64/sn/pci/pci_dma.c linux-2.6.32.43/arch/ia64/sn/pci/pci_dma.c
1466--- linux-2.6.32.43/arch/ia64/sn/pci/pci_dma.c 2011-03-27 14:31:47.000000000 -0400
1467+++ linux-2.6.32.43/arch/ia64/sn/pci/pci_dma.c 2011-04-17 15:56:45.000000000 -0400
1468@@ -464,7 +464,7 @@ int sn_pci_legacy_write(struct pci_bus *
1469 return ret;
1470 }
1471
1472-static struct dma_map_ops sn_dma_ops = {
1473+static const struct dma_map_ops sn_dma_ops = {
1474 .alloc_coherent = sn_dma_alloc_coherent,
1475 .free_coherent = sn_dma_free_coherent,
1476 .map_page = sn_dma_map_page,
1477diff -urNp linux-2.6.32.43/arch/m32r/lib/usercopy.c linux-2.6.32.43/arch/m32r/lib/usercopy.c
1478--- linux-2.6.32.43/arch/m32r/lib/usercopy.c 2011-03-27 14:31:47.000000000 -0400
1479+++ linux-2.6.32.43/arch/m32r/lib/usercopy.c 2011-04-17 15:56:45.000000000 -0400
1480@@ -14,6 +14,9 @@
1481 unsigned long
1482 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1483 {
1484+ if ((long)n < 0)
1485+ return n;
1486+
1487 prefetch(from);
1488 if (access_ok(VERIFY_WRITE, to, n))
1489 __copy_user(to,from,n);
1490@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1491 unsigned long
1492 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1493 {
1494+ if ((long)n < 0)
1495+ return n;
1496+
1497 prefetchw(to);
1498 if (access_ok(VERIFY_READ, from, n))
1499 __copy_user_zeroing(to,from,n);
1500diff -urNp linux-2.6.32.43/arch/mips/alchemy/devboards/pm.c linux-2.6.32.43/arch/mips/alchemy/devboards/pm.c
1501--- linux-2.6.32.43/arch/mips/alchemy/devboards/pm.c 2011-03-27 14:31:47.000000000 -0400
1502+++ linux-2.6.32.43/arch/mips/alchemy/devboards/pm.c 2011-04-17 15:56:45.000000000 -0400
1503@@ -78,7 +78,7 @@ static void db1x_pm_end(void)
1504
1505 }
1506
1507-static struct platform_suspend_ops db1x_pm_ops = {
1508+static const struct platform_suspend_ops db1x_pm_ops = {
1509 .valid = suspend_valid_only_mem,
1510 .begin = db1x_pm_begin,
1511 .enter = db1x_pm_enter,
1512diff -urNp linux-2.6.32.43/arch/mips/include/asm/elf.h linux-2.6.32.43/arch/mips/include/asm/elf.h
1513--- linux-2.6.32.43/arch/mips/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1514+++ linux-2.6.32.43/arch/mips/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1515@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
1516 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1517 #endif
1518
1519+#ifdef CONFIG_PAX_ASLR
1520+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1521+
1522+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1523+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1524+#endif
1525+
1526 #endif /* _ASM_ELF_H */
1527diff -urNp linux-2.6.32.43/arch/mips/include/asm/page.h linux-2.6.32.43/arch/mips/include/asm/page.h
1528--- linux-2.6.32.43/arch/mips/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
1529+++ linux-2.6.32.43/arch/mips/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
1530@@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
1531 #ifdef CONFIG_CPU_MIPS32
1532 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1533 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1534- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1535+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1536 #else
1537 typedef struct { unsigned long long pte; } pte_t;
1538 #define pte_val(x) ((x).pte)
1539diff -urNp linux-2.6.32.43/arch/mips/include/asm/system.h linux-2.6.32.43/arch/mips/include/asm/system.h
1540--- linux-2.6.32.43/arch/mips/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
1541+++ linux-2.6.32.43/arch/mips/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
1542@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1543 */
1544 #define __ARCH_WANT_UNLOCKED_CTXSW
1545
1546-extern unsigned long arch_align_stack(unsigned long sp);
1547+#define arch_align_stack(x) ((x) & ~0xfUL)
1548
1549 #endif /* _ASM_SYSTEM_H */
1550diff -urNp linux-2.6.32.43/arch/mips/kernel/binfmt_elfn32.c linux-2.6.32.43/arch/mips/kernel/binfmt_elfn32.c
1551--- linux-2.6.32.43/arch/mips/kernel/binfmt_elfn32.c 2011-03-27 14:31:47.000000000 -0400
1552+++ linux-2.6.32.43/arch/mips/kernel/binfmt_elfn32.c 2011-04-17 15:56:45.000000000 -0400
1553@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1554 #undef ELF_ET_DYN_BASE
1555 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1556
1557+#ifdef CONFIG_PAX_ASLR
1558+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1559+
1560+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1561+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1562+#endif
1563+
1564 #include <asm/processor.h>
1565 #include <linux/module.h>
1566 #include <linux/elfcore.h>
1567diff -urNp linux-2.6.32.43/arch/mips/kernel/binfmt_elfo32.c linux-2.6.32.43/arch/mips/kernel/binfmt_elfo32.c
1568--- linux-2.6.32.43/arch/mips/kernel/binfmt_elfo32.c 2011-03-27 14:31:47.000000000 -0400
1569+++ linux-2.6.32.43/arch/mips/kernel/binfmt_elfo32.c 2011-04-17 15:56:45.000000000 -0400
1570@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1571 #undef ELF_ET_DYN_BASE
1572 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1573
1574+#ifdef CONFIG_PAX_ASLR
1575+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1576+
1577+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1578+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1579+#endif
1580+
1581 #include <asm/processor.h>
1582
1583 /*
1584diff -urNp linux-2.6.32.43/arch/mips/kernel/kgdb.c linux-2.6.32.43/arch/mips/kernel/kgdb.c
1585--- linux-2.6.32.43/arch/mips/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
1586+++ linux-2.6.32.43/arch/mips/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
1587@@ -245,6 +245,7 @@ int kgdb_arch_handle_exception(int vecto
1588 return -1;
1589 }
1590
1591+/* cannot be const */
1592 struct kgdb_arch arch_kgdb_ops;
1593
1594 /*
1595diff -urNp linux-2.6.32.43/arch/mips/kernel/process.c linux-2.6.32.43/arch/mips/kernel/process.c
1596--- linux-2.6.32.43/arch/mips/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
1597+++ linux-2.6.32.43/arch/mips/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
1598@@ -470,15 +470,3 @@ unsigned long get_wchan(struct task_stru
1599 out:
1600 return pc;
1601 }
1602-
1603-/*
1604- * Don't forget that the stack pointer must be aligned on a 8 bytes
1605- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1606- */
1607-unsigned long arch_align_stack(unsigned long sp)
1608-{
1609- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1610- sp -= get_random_int() & ~PAGE_MASK;
1611-
1612- return sp & ALMASK;
1613-}
1614diff -urNp linux-2.6.32.43/arch/mips/kernel/syscall.c linux-2.6.32.43/arch/mips/kernel/syscall.c
1615--- linux-2.6.32.43/arch/mips/kernel/syscall.c 2011-03-27 14:31:47.000000000 -0400
1616+++ linux-2.6.32.43/arch/mips/kernel/syscall.c 2011-04-17 15:56:45.000000000 -0400
1617@@ -102,17 +102,21 @@ unsigned long arch_get_unmapped_area(str
1618 do_color_align = 0;
1619 if (filp || (flags & MAP_SHARED))
1620 do_color_align = 1;
1621+
1622+#ifdef CONFIG_PAX_RANDMMAP
1623+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1624+#endif
1625+
1626 if (addr) {
1627 if (do_color_align)
1628 addr = COLOUR_ALIGN(addr, pgoff);
1629 else
1630 addr = PAGE_ALIGN(addr);
1631 vmm = find_vma(current->mm, addr);
1632- if (task_size - len >= addr &&
1633- (!vmm || addr + len <= vmm->vm_start))
1634+ if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
1635 return addr;
1636 }
1637- addr = TASK_UNMAPPED_BASE;
1638+ addr = current->mm->mmap_base;
1639 if (do_color_align)
1640 addr = COLOUR_ALIGN(addr, pgoff);
1641 else
1642@@ -122,7 +126,7 @@ unsigned long arch_get_unmapped_area(str
1643 /* At this point: (!vmm || addr < vmm->vm_end). */
1644 if (task_size - len < addr)
1645 return -ENOMEM;
1646- if (!vmm || addr + len <= vmm->vm_start)
1647+ if (check_heap_stack_gap(vmm, addr, len))
1648 return addr;
1649 addr = vmm->vm_end;
1650 if (do_color_align)
1651diff -urNp linux-2.6.32.43/arch/mips/mm/fault.c linux-2.6.32.43/arch/mips/mm/fault.c
1652--- linux-2.6.32.43/arch/mips/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1653+++ linux-2.6.32.43/arch/mips/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1654@@ -26,6 +26,23 @@
1655 #include <asm/ptrace.h>
1656 #include <asm/highmem.h> /* For VMALLOC_END */
1657
1658+#ifdef CONFIG_PAX_PAGEEXEC
1659+void pax_report_insns(void *pc, void *sp)
1660+{
1661+ unsigned long i;
1662+
1663+ printk(KERN_ERR "PAX: bytes at PC: ");
1664+ for (i = 0; i < 5; i++) {
1665+ unsigned int c;
1666+ if (get_user(c, (unsigned int *)pc+i))
1667+ printk(KERN_CONT "???????? ");
1668+ else
1669+ printk(KERN_CONT "%08x ", c);
1670+ }
1671+ printk("\n");
1672+}
1673+#endif
1674+
1675 /*
1676 * This routine handles page faults. It determines the address,
1677 * and the problem, and then passes it off to one of the appropriate
1678diff -urNp linux-2.6.32.43/arch/parisc/include/asm/elf.h linux-2.6.32.43/arch/parisc/include/asm/elf.h
1679--- linux-2.6.32.43/arch/parisc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1680+++ linux-2.6.32.43/arch/parisc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1681@@ -343,6 +343,13 @@ struct pt_regs; /* forward declaration..
1682
1683 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1684
1685+#ifdef CONFIG_PAX_ASLR
1686+#define PAX_ELF_ET_DYN_BASE 0x10000UL
1687+
1688+#define PAX_DELTA_MMAP_LEN 16
1689+#define PAX_DELTA_STACK_LEN 16
1690+#endif
1691+
1692 /* This yields a mask that user programs can use to figure out what
1693 instruction set this CPU supports. This could be done in user space,
1694 but it's not easy, and we've already done it here. */
1695diff -urNp linux-2.6.32.43/arch/parisc/include/asm/pgtable.h linux-2.6.32.43/arch/parisc/include/asm/pgtable.h
1696--- linux-2.6.32.43/arch/parisc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1697+++ linux-2.6.32.43/arch/parisc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1698@@ -207,6 +207,17 @@
1699 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1700 #define PAGE_COPY PAGE_EXECREAD
1701 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1702+
1703+#ifdef CONFIG_PAX_PAGEEXEC
1704+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1705+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1706+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1707+#else
1708+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1709+# define PAGE_COPY_NOEXEC PAGE_COPY
1710+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1711+#endif
1712+
1713 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1714 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
1715 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
1716diff -urNp linux-2.6.32.43/arch/parisc/kernel/module.c linux-2.6.32.43/arch/parisc/kernel/module.c
1717--- linux-2.6.32.43/arch/parisc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
1718+++ linux-2.6.32.43/arch/parisc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
1719@@ -95,16 +95,38 @@
1720
1721 /* three functions to determine where in the module core
1722 * or init pieces the location is */
1723+static inline int in_init_rx(struct module *me, void *loc)
1724+{
1725+ return (loc >= me->module_init_rx &&
1726+ loc < (me->module_init_rx + me->init_size_rx));
1727+}
1728+
1729+static inline int in_init_rw(struct module *me, void *loc)
1730+{
1731+ return (loc >= me->module_init_rw &&
1732+ loc < (me->module_init_rw + me->init_size_rw));
1733+}
1734+
1735 static inline int in_init(struct module *me, void *loc)
1736 {
1737- return (loc >= me->module_init &&
1738- loc <= (me->module_init + me->init_size));
1739+ return in_init_rx(me, loc) || in_init_rw(me, loc);
1740+}
1741+
1742+static inline int in_core_rx(struct module *me, void *loc)
1743+{
1744+ return (loc >= me->module_core_rx &&
1745+ loc < (me->module_core_rx + me->core_size_rx));
1746+}
1747+
1748+static inline int in_core_rw(struct module *me, void *loc)
1749+{
1750+ return (loc >= me->module_core_rw &&
1751+ loc < (me->module_core_rw + me->core_size_rw));
1752 }
1753
1754 static inline int in_core(struct module *me, void *loc)
1755 {
1756- return (loc >= me->module_core &&
1757- loc <= (me->module_core + me->core_size));
1758+ return in_core_rx(me, loc) || in_core_rw(me, loc);
1759 }
1760
1761 static inline int in_local(struct module *me, void *loc)
1762@@ -364,13 +386,13 @@ int module_frob_arch_sections(CONST Elf_
1763 }
1764
1765 /* align things a bit */
1766- me->core_size = ALIGN(me->core_size, 16);
1767- me->arch.got_offset = me->core_size;
1768- me->core_size += gots * sizeof(struct got_entry);
1769-
1770- me->core_size = ALIGN(me->core_size, 16);
1771- me->arch.fdesc_offset = me->core_size;
1772- me->core_size += fdescs * sizeof(Elf_Fdesc);
1773+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1774+ me->arch.got_offset = me->core_size_rw;
1775+ me->core_size_rw += gots * sizeof(struct got_entry);
1776+
1777+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1778+ me->arch.fdesc_offset = me->core_size_rw;
1779+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1780
1781 me->arch.got_max = gots;
1782 me->arch.fdesc_max = fdescs;
1783@@ -388,7 +410,7 @@ static Elf64_Word get_got(struct module
1784
1785 BUG_ON(value == 0);
1786
1787- got = me->module_core + me->arch.got_offset;
1788+ got = me->module_core_rw + me->arch.got_offset;
1789 for (i = 0; got[i].addr; i++)
1790 if (got[i].addr == value)
1791 goto out;
1792@@ -406,7 +428,7 @@ static Elf64_Word get_got(struct module
1793 #ifdef CONFIG_64BIT
1794 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1795 {
1796- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1797+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1798
1799 if (!value) {
1800 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1801@@ -424,7 +446,7 @@ static Elf_Addr get_fdesc(struct module
1802
1803 /* Create new one */
1804 fdesc->addr = value;
1805- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1806+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1807 return (Elf_Addr)fdesc;
1808 }
1809 #endif /* CONFIG_64BIT */
1810@@ -848,7 +870,7 @@ register_unwind_table(struct module *me,
1811
1812 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1813 end = table + sechdrs[me->arch.unwind_section].sh_size;
1814- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1815+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1816
1817 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1818 me->arch.unwind_section, table, end, gp);
1819diff -urNp linux-2.6.32.43/arch/parisc/kernel/sys_parisc.c linux-2.6.32.43/arch/parisc/kernel/sys_parisc.c
1820--- linux-2.6.32.43/arch/parisc/kernel/sys_parisc.c 2011-03-27 14:31:47.000000000 -0400
1821+++ linux-2.6.32.43/arch/parisc/kernel/sys_parisc.c 2011-04-17 15:56:45.000000000 -0400
1822@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
1823 /* At this point: (!vma || addr < vma->vm_end). */
1824 if (TASK_SIZE - len < addr)
1825 return -ENOMEM;
1826- if (!vma || addr + len <= vma->vm_start)
1827+ if (check_heap_stack_gap(vma, addr, len))
1828 return addr;
1829 addr = vma->vm_end;
1830 }
1831@@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
1832 /* At this point: (!vma || addr < vma->vm_end). */
1833 if (TASK_SIZE - len < addr)
1834 return -ENOMEM;
1835- if (!vma || addr + len <= vma->vm_start)
1836+ if (check_heap_stack_gap(vma, addr, len))
1837 return addr;
1838 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1839 if (addr < vma->vm_end) /* handle wraparound */
1840@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1841 if (flags & MAP_FIXED)
1842 return addr;
1843 if (!addr)
1844- addr = TASK_UNMAPPED_BASE;
1845+ addr = current->mm->mmap_base;
1846
1847 if (filp) {
1848 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1849diff -urNp linux-2.6.32.43/arch/parisc/kernel/traps.c linux-2.6.32.43/arch/parisc/kernel/traps.c
1850--- linux-2.6.32.43/arch/parisc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
1851+++ linux-2.6.32.43/arch/parisc/kernel/traps.c 2011-04-17 15:56:45.000000000 -0400
1852@@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
1853
1854 down_read(&current->mm->mmap_sem);
1855 vma = find_vma(current->mm,regs->iaoq[0]);
1856- if (vma && (regs->iaoq[0] >= vma->vm_start)
1857- && (vma->vm_flags & VM_EXEC)) {
1858-
1859+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1860 fault_address = regs->iaoq[0];
1861 fault_space = regs->iasq[0];
1862
1863diff -urNp linux-2.6.32.43/arch/parisc/mm/fault.c linux-2.6.32.43/arch/parisc/mm/fault.c
1864--- linux-2.6.32.43/arch/parisc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1865+++ linux-2.6.32.43/arch/parisc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1866@@ -15,6 +15,7 @@
1867 #include <linux/sched.h>
1868 #include <linux/interrupt.h>
1869 #include <linux/module.h>
1870+#include <linux/unistd.h>
1871
1872 #include <asm/uaccess.h>
1873 #include <asm/traps.h>
1874@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1875 static unsigned long
1876 parisc_acctyp(unsigned long code, unsigned int inst)
1877 {
1878- if (code == 6 || code == 16)
1879+ if (code == 6 || code == 7 || code == 16)
1880 return VM_EXEC;
1881
1882 switch (inst & 0xf0000000) {
1883@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
1884 }
1885 #endif
1886
1887+#ifdef CONFIG_PAX_PAGEEXEC
1888+/*
1889+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1890+ *
1891+ * returns 1 when task should be killed
1892+ * 2 when rt_sigreturn trampoline was detected
1893+ * 3 when unpatched PLT trampoline was detected
1894+ */
1895+static int pax_handle_fetch_fault(struct pt_regs *regs)
1896+{
1897+
1898+#ifdef CONFIG_PAX_EMUPLT
1899+ int err;
1900+
1901+ do { /* PaX: unpatched PLT emulation */
1902+ unsigned int bl, depwi;
1903+
1904+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1905+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1906+
1907+ if (err)
1908+ break;
1909+
1910+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1911+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1912+
1913+ err = get_user(ldw, (unsigned int *)addr);
1914+ err |= get_user(bv, (unsigned int *)(addr+4));
1915+ err |= get_user(ldw2, (unsigned int *)(addr+8));
1916+
1917+ if (err)
1918+ break;
1919+
1920+ if (ldw == 0x0E801096U &&
1921+ bv == 0xEAC0C000U &&
1922+ ldw2 == 0x0E881095U)
1923+ {
1924+ unsigned int resolver, map;
1925+
1926+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1927+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1928+ if (err)
1929+ break;
1930+
1931+ regs->gr[20] = instruction_pointer(regs)+8;
1932+ regs->gr[21] = map;
1933+ regs->gr[22] = resolver;
1934+ regs->iaoq[0] = resolver | 3UL;
1935+ regs->iaoq[1] = regs->iaoq[0] + 4;
1936+ return 3;
1937+ }
1938+ }
1939+ } while (0);
1940+#endif
1941+
1942+#ifdef CONFIG_PAX_EMUTRAMP
1943+
1944+#ifndef CONFIG_PAX_EMUSIGRT
1945+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1946+ return 1;
1947+#endif
1948+
1949+ do { /* PaX: rt_sigreturn emulation */
1950+ unsigned int ldi1, ldi2, bel, nop;
1951+
1952+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1953+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1954+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1955+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1956+
1957+ if (err)
1958+ break;
1959+
1960+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1961+ ldi2 == 0x3414015AU &&
1962+ bel == 0xE4008200U &&
1963+ nop == 0x08000240U)
1964+ {
1965+ regs->gr[25] = (ldi1 & 2) >> 1;
1966+ regs->gr[20] = __NR_rt_sigreturn;
1967+ regs->gr[31] = regs->iaoq[1] + 16;
1968+ regs->sr[0] = regs->iasq[1];
1969+ regs->iaoq[0] = 0x100UL;
1970+ regs->iaoq[1] = regs->iaoq[0] + 4;
1971+ regs->iasq[0] = regs->sr[2];
1972+ regs->iasq[1] = regs->sr[2];
1973+ return 2;
1974+ }
1975+ } while (0);
1976+#endif
1977+
1978+ return 1;
1979+}
1980+
1981+void pax_report_insns(void *pc, void *sp)
1982+{
1983+ unsigned long i;
1984+
1985+ printk(KERN_ERR "PAX: bytes at PC: ");
1986+ for (i = 0; i < 5; i++) {
1987+ unsigned int c;
1988+ if (get_user(c, (unsigned int *)pc+i))
1989+ printk(KERN_CONT "???????? ");
1990+ else
1991+ printk(KERN_CONT "%08x ", c);
1992+ }
1993+ printk("\n");
1994+}
1995+#endif
1996+
1997 int fixup_exception(struct pt_regs *regs)
1998 {
1999 const struct exception_table_entry *fix;
2000@@ -192,8 +303,33 @@ good_area:
2001
2002 acc_type = parisc_acctyp(code,regs->iir);
2003
2004- if ((vma->vm_flags & acc_type) != acc_type)
2005+ if ((vma->vm_flags & acc_type) != acc_type) {
2006+
2007+#ifdef CONFIG_PAX_PAGEEXEC
2008+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2009+ (address & ~3UL) == instruction_pointer(regs))
2010+ {
2011+ up_read(&mm->mmap_sem);
2012+ switch (pax_handle_fetch_fault(regs)) {
2013+
2014+#ifdef CONFIG_PAX_EMUPLT
2015+ case 3:
2016+ return;
2017+#endif
2018+
2019+#ifdef CONFIG_PAX_EMUTRAMP
2020+ case 2:
2021+ return;
2022+#endif
2023+
2024+ }
2025+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2026+ do_group_exit(SIGKILL);
2027+ }
2028+#endif
2029+
2030 goto bad_area;
2031+ }
2032
2033 /*
2034 * If for any reason at all we couldn't handle the fault, make
2035diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/device.h linux-2.6.32.43/arch/powerpc/include/asm/device.h
2036--- linux-2.6.32.43/arch/powerpc/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
2037+++ linux-2.6.32.43/arch/powerpc/include/asm/device.h 2011-04-17 15:56:45.000000000 -0400
2038@@ -14,7 +14,7 @@ struct dev_archdata {
2039 struct device_node *of_node;
2040
2041 /* DMA operations on that device */
2042- struct dma_map_ops *dma_ops;
2043+ const struct dma_map_ops *dma_ops;
2044
2045 /*
2046 * When an iommu is in use, dma_data is used as a ptr to the base of the
2047diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/dma-mapping.h linux-2.6.32.43/arch/powerpc/include/asm/dma-mapping.h
2048--- linux-2.6.32.43/arch/powerpc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
2049+++ linux-2.6.32.43/arch/powerpc/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
2050@@ -69,9 +69,9 @@ static inline unsigned long device_to_ma
2051 #ifdef CONFIG_PPC64
2052 extern struct dma_map_ops dma_iommu_ops;
2053 #endif
2054-extern struct dma_map_ops dma_direct_ops;
2055+extern const struct dma_map_ops dma_direct_ops;
2056
2057-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2058+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2059 {
2060 /* We don't handle the NULL dev case for ISA for now. We could
2061 * do it via an out of line call but it is not needed for now. The
2062@@ -84,7 +84,7 @@ static inline struct dma_map_ops *get_dm
2063 return dev->archdata.dma_ops;
2064 }
2065
2066-static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
2067+static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
2068 {
2069 dev->archdata.dma_ops = ops;
2070 }
2071@@ -118,7 +118,7 @@ static inline void set_dma_offset(struct
2072
2073 static inline int dma_supported(struct device *dev, u64 mask)
2074 {
2075- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2076+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2077
2078 if (unlikely(dma_ops == NULL))
2079 return 0;
2080@@ -132,7 +132,7 @@ static inline int dma_supported(struct d
2081
2082 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2083 {
2084- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2085+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2086
2087 if (unlikely(dma_ops == NULL))
2088 return -EIO;
2089@@ -147,7 +147,7 @@ static inline int dma_set_mask(struct de
2090 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2091 dma_addr_t *dma_handle, gfp_t flag)
2092 {
2093- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2094+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2095 void *cpu_addr;
2096
2097 BUG_ON(!dma_ops);
2098@@ -162,7 +162,7 @@ static inline void *dma_alloc_coherent(s
2099 static inline void dma_free_coherent(struct device *dev, size_t size,
2100 void *cpu_addr, dma_addr_t dma_handle)
2101 {
2102- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2103+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2104
2105 BUG_ON(!dma_ops);
2106
2107@@ -173,7 +173,7 @@ static inline void dma_free_coherent(str
2108
2109 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2110 {
2111- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2112+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2113
2114 if (dma_ops->mapping_error)
2115 return dma_ops->mapping_error(dev, dma_addr);
2116diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/elf.h linux-2.6.32.43/arch/powerpc/include/asm/elf.h
2117--- linux-2.6.32.43/arch/powerpc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
2118+++ linux-2.6.32.43/arch/powerpc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
2119@@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
2120 the loader. We need to make sure that it is out of the way of the program
2121 that it will "exec", and that there is sufficient room for the brk. */
2122
2123-extern unsigned long randomize_et_dyn(unsigned long base);
2124-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2125+#define ELF_ET_DYN_BASE (0x20000000)
2126+
2127+#ifdef CONFIG_PAX_ASLR
2128+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2129+
2130+#ifdef __powerpc64__
2131+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2132+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2133+#else
2134+#define PAX_DELTA_MMAP_LEN 15
2135+#define PAX_DELTA_STACK_LEN 15
2136+#endif
2137+#endif
2138
2139 /*
2140 * Our registers are always unsigned longs, whether we're a 32 bit
2141@@ -275,9 +286,6 @@ extern int arch_setup_additional_pages(s
2142 (0x7ff >> (PAGE_SHIFT - 12)) : \
2143 (0x3ffff >> (PAGE_SHIFT - 12)))
2144
2145-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2146-#define arch_randomize_brk arch_randomize_brk
2147-
2148 #endif /* __KERNEL__ */
2149
2150 /*
2151diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/iommu.h linux-2.6.32.43/arch/powerpc/include/asm/iommu.h
2152--- linux-2.6.32.43/arch/powerpc/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
2153+++ linux-2.6.32.43/arch/powerpc/include/asm/iommu.h 2011-04-17 15:56:45.000000000 -0400
2154@@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
2155 extern void iommu_init_early_dart(void);
2156 extern void iommu_init_early_pasemi(void);
2157
2158+/* dma-iommu.c */
2159+extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2160+
2161 #ifdef CONFIG_PCI
2162 extern void pci_iommu_init(void);
2163 extern void pci_direct_iommu_init(void);
2164diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/kmap_types.h linux-2.6.32.43/arch/powerpc/include/asm/kmap_types.h
2165--- linux-2.6.32.43/arch/powerpc/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
2166+++ linux-2.6.32.43/arch/powerpc/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
2167@@ -26,6 +26,7 @@ enum km_type {
2168 KM_SOFTIRQ1,
2169 KM_PPC_SYNC_PAGE,
2170 KM_PPC_SYNC_ICACHE,
2171+ KM_CLEARPAGE,
2172 KM_TYPE_NR
2173 };
2174
2175diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/page_64.h linux-2.6.32.43/arch/powerpc/include/asm/page_64.h
2176--- linux-2.6.32.43/arch/powerpc/include/asm/page_64.h 2011-03-27 14:31:47.000000000 -0400
2177+++ linux-2.6.32.43/arch/powerpc/include/asm/page_64.h 2011-04-17 15:56:45.000000000 -0400
2178@@ -180,15 +180,18 @@ do { \
2179 * stack by default, so in the absense of a PT_GNU_STACK program header
2180 * we turn execute permission off.
2181 */
2182-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2183- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2184+#define VM_STACK_DEFAULT_FLAGS32 \
2185+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2186+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2187
2188 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2189 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2190
2191+#ifndef CONFIG_PAX_PAGEEXEC
2192 #define VM_STACK_DEFAULT_FLAGS \
2193 (test_thread_flag(TIF_32BIT) ? \
2194 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2195+#endif
2196
2197 #include <asm-generic/getorder.h>
2198
2199diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/page.h linux-2.6.32.43/arch/powerpc/include/asm/page.h
2200--- linux-2.6.32.43/arch/powerpc/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
2201+++ linux-2.6.32.43/arch/powerpc/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
2202@@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
2203 * and needs to be executable. This means the whole heap ends
2204 * up being executable.
2205 */
2206-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2207- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2208+#define VM_DATA_DEFAULT_FLAGS32 \
2209+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2210+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2211
2212 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2213 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2214@@ -145,6 +146,9 @@ extern phys_addr_t kernstart_addr;
2215 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2216 #endif
2217
2218+#define ktla_ktva(addr) (addr)
2219+#define ktva_ktla(addr) (addr)
2220+
2221 #ifndef __ASSEMBLY__
2222
2223 #undef STRICT_MM_TYPECHECKS
2224diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/pci.h linux-2.6.32.43/arch/powerpc/include/asm/pci.h
2225--- linux-2.6.32.43/arch/powerpc/include/asm/pci.h 2011-03-27 14:31:47.000000000 -0400
2226+++ linux-2.6.32.43/arch/powerpc/include/asm/pci.h 2011-04-17 15:56:45.000000000 -0400
2227@@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
2228 }
2229
2230 #ifdef CONFIG_PCI
2231-extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
2232-extern struct dma_map_ops *get_pci_dma_ops(void);
2233+extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
2234+extern const struct dma_map_ops *get_pci_dma_ops(void);
2235 #else /* CONFIG_PCI */
2236 #define set_pci_dma_ops(d)
2237 #define get_pci_dma_ops() NULL
2238diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/pgtable.h linux-2.6.32.43/arch/powerpc/include/asm/pgtable.h
2239--- linux-2.6.32.43/arch/powerpc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
2240+++ linux-2.6.32.43/arch/powerpc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
2241@@ -2,6 +2,7 @@
2242 #define _ASM_POWERPC_PGTABLE_H
2243 #ifdef __KERNEL__
2244
2245+#include <linux/const.h>
2246 #ifndef __ASSEMBLY__
2247 #include <asm/processor.h> /* For TASK_SIZE */
2248 #include <asm/mmu.h>
2249diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/pte-hash32.h linux-2.6.32.43/arch/powerpc/include/asm/pte-hash32.h
2250--- linux-2.6.32.43/arch/powerpc/include/asm/pte-hash32.h 2011-03-27 14:31:47.000000000 -0400
2251+++ linux-2.6.32.43/arch/powerpc/include/asm/pte-hash32.h 2011-04-17 15:56:45.000000000 -0400
2252@@ -21,6 +21,7 @@
2253 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2254 #define _PAGE_USER 0x004 /* usermode access allowed */
2255 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2256+#define _PAGE_EXEC _PAGE_GUARDED
2257 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2258 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2259 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2260diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/reg.h linux-2.6.32.43/arch/powerpc/include/asm/reg.h
2261--- linux-2.6.32.43/arch/powerpc/include/asm/reg.h 2011-03-27 14:31:47.000000000 -0400
2262+++ linux-2.6.32.43/arch/powerpc/include/asm/reg.h 2011-04-17 15:56:45.000000000 -0400
2263@@ -191,6 +191,7 @@
2264 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2265 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2266 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2267+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2268 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2269 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2270 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2271diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/swiotlb.h linux-2.6.32.43/arch/powerpc/include/asm/swiotlb.h
2272--- linux-2.6.32.43/arch/powerpc/include/asm/swiotlb.h 2011-03-27 14:31:47.000000000 -0400
2273+++ linux-2.6.32.43/arch/powerpc/include/asm/swiotlb.h 2011-04-17 15:56:45.000000000 -0400
2274@@ -13,7 +13,7 @@
2275
2276 #include <linux/swiotlb.h>
2277
2278-extern struct dma_map_ops swiotlb_dma_ops;
2279+extern const struct dma_map_ops swiotlb_dma_ops;
2280
2281 static inline void dma_mark_clean(void *addr, size_t size) {}
2282
2283diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/system.h linux-2.6.32.43/arch/powerpc/include/asm/system.h
2284--- linux-2.6.32.43/arch/powerpc/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
2285+++ linux-2.6.32.43/arch/powerpc/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
2286@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsi
2287 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2288 #endif
2289
2290-extern unsigned long arch_align_stack(unsigned long sp);
2291+#define arch_align_stack(x) ((x) & ~0xfUL)
2292
2293 /* Used in very early kernel initialization. */
2294 extern unsigned long reloc_offset(void);
2295diff -urNp linux-2.6.32.43/arch/powerpc/include/asm/uaccess.h linux-2.6.32.43/arch/powerpc/include/asm/uaccess.h
2296--- linux-2.6.32.43/arch/powerpc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
2297+++ linux-2.6.32.43/arch/powerpc/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
2298@@ -13,6 +13,8 @@
2299 #define VERIFY_READ 0
2300 #define VERIFY_WRITE 1
2301
2302+extern void check_object_size(const void *ptr, unsigned long n, bool to);
2303+
2304 /*
2305 * The fs value determines whether argument validity checking should be
2306 * performed or not. If get_fs() == USER_DS, checking is performed, with
2307@@ -327,52 +329,6 @@ do { \
2308 extern unsigned long __copy_tofrom_user(void __user *to,
2309 const void __user *from, unsigned long size);
2310
2311-#ifndef __powerpc64__
2312-
2313-static inline unsigned long copy_from_user(void *to,
2314- const void __user *from, unsigned long n)
2315-{
2316- unsigned long over;
2317-
2318- if (access_ok(VERIFY_READ, from, n))
2319- return __copy_tofrom_user((__force void __user *)to, from, n);
2320- if ((unsigned long)from < TASK_SIZE) {
2321- over = (unsigned long)from + n - TASK_SIZE;
2322- return __copy_tofrom_user((__force void __user *)to, from,
2323- n - over) + over;
2324- }
2325- return n;
2326-}
2327-
2328-static inline unsigned long copy_to_user(void __user *to,
2329- const void *from, unsigned long n)
2330-{
2331- unsigned long over;
2332-
2333- if (access_ok(VERIFY_WRITE, to, n))
2334- return __copy_tofrom_user(to, (__force void __user *)from, n);
2335- if ((unsigned long)to < TASK_SIZE) {
2336- over = (unsigned long)to + n - TASK_SIZE;
2337- return __copy_tofrom_user(to, (__force void __user *)from,
2338- n - over) + over;
2339- }
2340- return n;
2341-}
2342-
2343-#else /* __powerpc64__ */
2344-
2345-#define __copy_in_user(to, from, size) \
2346- __copy_tofrom_user((to), (from), (size))
2347-
2348-extern unsigned long copy_from_user(void *to, const void __user *from,
2349- unsigned long n);
2350-extern unsigned long copy_to_user(void __user *to, const void *from,
2351- unsigned long n);
2352-extern unsigned long copy_in_user(void __user *to, const void __user *from,
2353- unsigned long n);
2354-
2355-#endif /* __powerpc64__ */
2356-
2357 static inline unsigned long __copy_from_user_inatomic(void *to,
2358 const void __user *from, unsigned long n)
2359 {
2360@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
2361 if (ret == 0)
2362 return 0;
2363 }
2364+
2365+ if (!__builtin_constant_p(n))
2366+ check_object_size(to, n, false);
2367+
2368 return __copy_tofrom_user((__force void __user *)to, from, n);
2369 }
2370
2371@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
2372 if (ret == 0)
2373 return 0;
2374 }
2375+
2376+ if (!__builtin_constant_p(n))
2377+ check_object_size(from, n, true);
2378+
2379 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2380 }
2381
2382@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
2383 return __copy_to_user_inatomic(to, from, size);
2384 }
2385
2386+#ifndef __powerpc64__
2387+
2388+static inline unsigned long __must_check copy_from_user(void *to,
2389+ const void __user *from, unsigned long n)
2390+{
2391+ unsigned long over;
2392+
2393+ if ((long)n < 0)
2394+ return n;
2395+
2396+ if (access_ok(VERIFY_READ, from, n)) {
2397+ if (!__builtin_constant_p(n))
2398+ check_object_size(to, n, false);
2399+ return __copy_tofrom_user((__force void __user *)to, from, n);
2400+ }
2401+ if ((unsigned long)from < TASK_SIZE) {
2402+ over = (unsigned long)from + n - TASK_SIZE;
2403+ if (!__builtin_constant_p(n - over))
2404+ check_object_size(to, n - over, false);
2405+ return __copy_tofrom_user((__force void __user *)to, from,
2406+ n - over) + over;
2407+ }
2408+ return n;
2409+}
2410+
2411+static inline unsigned long __must_check copy_to_user(void __user *to,
2412+ const void *from, unsigned long n)
2413+{
2414+ unsigned long over;
2415+
2416+ if ((long)n < 0)
2417+ return n;
2418+
2419+ if (access_ok(VERIFY_WRITE, to, n)) {
2420+ if (!__builtin_constant_p(n))
2421+ check_object_size(from, n, true);
2422+ return __copy_tofrom_user(to, (__force void __user *)from, n);
2423+ }
2424+ if ((unsigned long)to < TASK_SIZE) {
2425+ over = (unsigned long)to + n - TASK_SIZE;
2426+ if (!__builtin_constant_p(n))
2427+ check_object_size(from, n - over, true);
2428+ return __copy_tofrom_user(to, (__force void __user *)from,
2429+ n - over) + over;
2430+ }
2431+ return n;
2432+}
2433+
2434+#else /* __powerpc64__ */
2435+
2436+#define __copy_in_user(to, from, size) \
2437+ __copy_tofrom_user((to), (from), (size))
2438+
2439+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2440+{
2441+ if ((long)n < 0 || n > INT_MAX)
2442+ return n;
2443+
2444+ if (!__builtin_constant_p(n))
2445+ check_object_size(to, n, false);
2446+
2447+ if (likely(access_ok(VERIFY_READ, from, n)))
2448+ n = __copy_from_user(to, from, n);
2449+ else
2450+ memset(to, 0, n);
2451+ return n;
2452+}
2453+
2454+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2455+{
2456+ if ((long)n < 0 || n > INT_MAX)
2457+ return n;
2458+
2459+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
2460+ if (!__builtin_constant_p(n))
2461+ check_object_size(from, n, true);
2462+ n = __copy_to_user(to, from, n);
2463+ }
2464+ return n;
2465+}
2466+
2467+extern unsigned long copy_in_user(void __user *to, const void __user *from,
2468+ unsigned long n);
2469+
2470+#endif /* __powerpc64__ */
2471+
2472 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2473
2474 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2475diff -urNp linux-2.6.32.43/arch/powerpc/kernel/cacheinfo.c linux-2.6.32.43/arch/powerpc/kernel/cacheinfo.c
2476--- linux-2.6.32.43/arch/powerpc/kernel/cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
2477+++ linux-2.6.32.43/arch/powerpc/kernel/cacheinfo.c 2011-04-17 15:56:45.000000000 -0400
2478@@ -642,7 +642,7 @@ static struct kobj_attribute *cache_inde
2479 &cache_assoc_attr,
2480 };
2481
2482-static struct sysfs_ops cache_index_ops = {
2483+static const struct sysfs_ops cache_index_ops = {
2484 .show = cache_index_show,
2485 };
2486
2487diff -urNp linux-2.6.32.43/arch/powerpc/kernel/dma.c linux-2.6.32.43/arch/powerpc/kernel/dma.c
2488--- linux-2.6.32.43/arch/powerpc/kernel/dma.c 2011-03-27 14:31:47.000000000 -0400
2489+++ linux-2.6.32.43/arch/powerpc/kernel/dma.c 2011-04-17 15:56:45.000000000 -0400
2490@@ -134,7 +134,7 @@ static inline void dma_direct_sync_singl
2491 }
2492 #endif
2493
2494-struct dma_map_ops dma_direct_ops = {
2495+const struct dma_map_ops dma_direct_ops = {
2496 .alloc_coherent = dma_direct_alloc_coherent,
2497 .free_coherent = dma_direct_free_coherent,
2498 .map_sg = dma_direct_map_sg,
2499diff -urNp linux-2.6.32.43/arch/powerpc/kernel/dma-iommu.c linux-2.6.32.43/arch/powerpc/kernel/dma-iommu.c
2500--- linux-2.6.32.43/arch/powerpc/kernel/dma-iommu.c 2011-03-27 14:31:47.000000000 -0400
2501+++ linux-2.6.32.43/arch/powerpc/kernel/dma-iommu.c 2011-04-17 15:56:45.000000000 -0400
2502@@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
2503 }
2504
2505 /* We support DMA to/from any memory page via the iommu */
2506-static int dma_iommu_dma_supported(struct device *dev, u64 mask)
2507+int dma_iommu_dma_supported(struct device *dev, u64 mask)
2508 {
2509 struct iommu_table *tbl = get_iommu_table_base(dev);
2510
2511diff -urNp linux-2.6.32.43/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.32.43/arch/powerpc/kernel/dma-swiotlb.c
2512--- linux-2.6.32.43/arch/powerpc/kernel/dma-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
2513+++ linux-2.6.32.43/arch/powerpc/kernel/dma-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
2514@@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
2515 * map_page, and unmap_page on highmem, use normal dma_ops
2516 * for everything else.
2517 */
2518-struct dma_map_ops swiotlb_dma_ops = {
2519+const struct dma_map_ops swiotlb_dma_ops = {
2520 .alloc_coherent = dma_direct_alloc_coherent,
2521 .free_coherent = dma_direct_free_coherent,
2522 .map_sg = swiotlb_map_sg_attrs,
2523diff -urNp linux-2.6.32.43/arch/powerpc/kernel/exceptions-64e.S linux-2.6.32.43/arch/powerpc/kernel/exceptions-64e.S
2524--- linux-2.6.32.43/arch/powerpc/kernel/exceptions-64e.S 2011-03-27 14:31:47.000000000 -0400
2525+++ linux-2.6.32.43/arch/powerpc/kernel/exceptions-64e.S 2011-04-17 15:56:45.000000000 -0400
2526@@ -455,6 +455,7 @@ storage_fault_common:
2527 std r14,_DAR(r1)
2528 std r15,_DSISR(r1)
2529 addi r3,r1,STACK_FRAME_OVERHEAD
2530+ bl .save_nvgprs
2531 mr r4,r14
2532 mr r5,r15
2533 ld r14,PACA_EXGEN+EX_R14(r13)
2534@@ -464,8 +465,7 @@ storage_fault_common:
2535 cmpdi r3,0
2536 bne- 1f
2537 b .ret_from_except_lite
2538-1: bl .save_nvgprs
2539- mr r5,r3
2540+1: mr r5,r3
2541 addi r3,r1,STACK_FRAME_OVERHEAD
2542 ld r4,_DAR(r1)
2543 bl .bad_page_fault
2544diff -urNp linux-2.6.32.43/arch/powerpc/kernel/exceptions-64s.S linux-2.6.32.43/arch/powerpc/kernel/exceptions-64s.S
2545--- linux-2.6.32.43/arch/powerpc/kernel/exceptions-64s.S 2011-03-27 14:31:47.000000000 -0400
2546+++ linux-2.6.32.43/arch/powerpc/kernel/exceptions-64s.S 2011-04-17 15:56:45.000000000 -0400
2547@@ -818,10 +818,10 @@ handle_page_fault:
2548 11: ld r4,_DAR(r1)
2549 ld r5,_DSISR(r1)
2550 addi r3,r1,STACK_FRAME_OVERHEAD
2551+ bl .save_nvgprs
2552 bl .do_page_fault
2553 cmpdi r3,0
2554 beq+ 13f
2555- bl .save_nvgprs
2556 mr r5,r3
2557 addi r3,r1,STACK_FRAME_OVERHEAD
2558 lwz r4,_DAR(r1)
2559diff -urNp linux-2.6.32.43/arch/powerpc/kernel/ibmebus.c linux-2.6.32.43/arch/powerpc/kernel/ibmebus.c
2560--- linux-2.6.32.43/arch/powerpc/kernel/ibmebus.c 2011-03-27 14:31:47.000000000 -0400
2561+++ linux-2.6.32.43/arch/powerpc/kernel/ibmebus.c 2011-04-17 15:56:45.000000000 -0400
2562@@ -127,7 +127,7 @@ static int ibmebus_dma_supported(struct
2563 return 1;
2564 }
2565
2566-static struct dma_map_ops ibmebus_dma_ops = {
2567+static const struct dma_map_ops ibmebus_dma_ops = {
2568 .alloc_coherent = ibmebus_alloc_coherent,
2569 .free_coherent = ibmebus_free_coherent,
2570 .map_sg = ibmebus_map_sg,
2571diff -urNp linux-2.6.32.43/arch/powerpc/kernel/kgdb.c linux-2.6.32.43/arch/powerpc/kernel/kgdb.c
2572--- linux-2.6.32.43/arch/powerpc/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
2573+++ linux-2.6.32.43/arch/powerpc/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
2574@@ -126,7 +126,7 @@ static int kgdb_handle_breakpoint(struct
2575 if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
2576 return 0;
2577
2578- if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2579+ if (*(u32 *) (regs->nip) == *(const u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2580 regs->nip += 4;
2581
2582 return 1;
2583@@ -353,7 +353,7 @@ int kgdb_arch_handle_exception(int vecto
2584 /*
2585 * Global data
2586 */
2587-struct kgdb_arch arch_kgdb_ops = {
2588+const struct kgdb_arch arch_kgdb_ops = {
2589 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
2590 };
2591
2592diff -urNp linux-2.6.32.43/arch/powerpc/kernel/module_32.c linux-2.6.32.43/arch/powerpc/kernel/module_32.c
2593--- linux-2.6.32.43/arch/powerpc/kernel/module_32.c 2011-03-27 14:31:47.000000000 -0400
2594+++ linux-2.6.32.43/arch/powerpc/kernel/module_32.c 2011-04-17 15:56:45.000000000 -0400
2595@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
2596 me->arch.core_plt_section = i;
2597 }
2598 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2599- printk("Module doesn't contain .plt or .init.plt sections.\n");
2600+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2601 return -ENOEXEC;
2602 }
2603
2604@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
2605
2606 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2607 /* Init, or core PLT? */
2608- if (location >= mod->module_core
2609- && location < mod->module_core + mod->core_size)
2610+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2611+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2612 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2613- else
2614+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2615+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2616 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2617+ else {
2618+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2619+ return ~0UL;
2620+ }
2621
2622 /* Find this entry, or if that fails, the next avail. entry */
2623 while (entry->jump[0]) {
2624diff -urNp linux-2.6.32.43/arch/powerpc/kernel/module.c linux-2.6.32.43/arch/powerpc/kernel/module.c
2625--- linux-2.6.32.43/arch/powerpc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
2626+++ linux-2.6.32.43/arch/powerpc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
2627@@ -31,11 +31,24 @@
2628
2629 LIST_HEAD(module_bug_list);
2630
2631+#ifdef CONFIG_PAX_KERNEXEC
2632 void *module_alloc(unsigned long size)
2633 {
2634 if (size == 0)
2635 return NULL;
2636
2637+ return vmalloc(size);
2638+}
2639+
2640+void *module_alloc_exec(unsigned long size)
2641+#else
2642+void *module_alloc(unsigned long size)
2643+#endif
2644+
2645+{
2646+ if (size == 0)
2647+ return NULL;
2648+
2649 return vmalloc_exec(size);
2650 }
2651
2652@@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
2653 vfree(module_region);
2654 }
2655
2656+#ifdef CONFIG_PAX_KERNEXEC
2657+void module_free_exec(struct module *mod, void *module_region)
2658+{
2659+ module_free(mod, module_region);
2660+}
2661+#endif
2662+
2663 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
2664 const Elf_Shdr *sechdrs,
2665 const char *name)
2666diff -urNp linux-2.6.32.43/arch/powerpc/kernel/pci-common.c linux-2.6.32.43/arch/powerpc/kernel/pci-common.c
2667--- linux-2.6.32.43/arch/powerpc/kernel/pci-common.c 2011-03-27 14:31:47.000000000 -0400
2668+++ linux-2.6.32.43/arch/powerpc/kernel/pci-common.c 2011-04-17 15:56:45.000000000 -0400
2669@@ -50,14 +50,14 @@ resource_size_t isa_mem_base;
2670 unsigned int ppc_pci_flags = 0;
2671
2672
2673-static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2674+static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2675
2676-void set_pci_dma_ops(struct dma_map_ops *dma_ops)
2677+void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
2678 {
2679 pci_dma_ops = dma_ops;
2680 }
2681
2682-struct dma_map_ops *get_pci_dma_ops(void)
2683+const struct dma_map_ops *get_pci_dma_ops(void)
2684 {
2685 return pci_dma_ops;
2686 }
2687diff -urNp linux-2.6.32.43/arch/powerpc/kernel/process.c linux-2.6.32.43/arch/powerpc/kernel/process.c
2688--- linux-2.6.32.43/arch/powerpc/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
2689+++ linux-2.6.32.43/arch/powerpc/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
2690@@ -539,8 +539,8 @@ void show_regs(struct pt_regs * regs)
2691 * Lookup NIP late so we have the best change of getting the
2692 * above info out without failing
2693 */
2694- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2695- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2696+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2697+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2698 #endif
2699 show_stack(current, (unsigned long *) regs->gpr[1]);
2700 if (!user_mode(regs))
2701@@ -1034,10 +1034,10 @@ void show_stack(struct task_struct *tsk,
2702 newsp = stack[0];
2703 ip = stack[STACK_FRAME_LR_SAVE];
2704 if (!firstframe || ip != lr) {
2705- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2706+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2707 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2708 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2709- printk(" (%pS)",
2710+ printk(" (%pA)",
2711 (void *)current->ret_stack[curr_frame].ret);
2712 curr_frame--;
2713 }
2714@@ -1057,7 +1057,7 @@ void show_stack(struct task_struct *tsk,
2715 struct pt_regs *regs = (struct pt_regs *)
2716 (sp + STACK_FRAME_OVERHEAD);
2717 lr = regs->link;
2718- printk("--- Exception: %lx at %pS\n LR = %pS\n",
2719+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
2720 regs->trap, (void *)regs->nip, (void *)lr);
2721 firstframe = 1;
2722 }
2723@@ -1134,58 +1134,3 @@ void thread_info_cache_init(void)
2724 }
2725
2726 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2727-
2728-unsigned long arch_align_stack(unsigned long sp)
2729-{
2730- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2731- sp -= get_random_int() & ~PAGE_MASK;
2732- return sp & ~0xf;
2733-}
2734-
2735-static inline unsigned long brk_rnd(void)
2736-{
2737- unsigned long rnd = 0;
2738-
2739- /* 8MB for 32bit, 1GB for 64bit */
2740- if (is_32bit_task())
2741- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2742- else
2743- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2744-
2745- return rnd << PAGE_SHIFT;
2746-}
2747-
2748-unsigned long arch_randomize_brk(struct mm_struct *mm)
2749-{
2750- unsigned long base = mm->brk;
2751- unsigned long ret;
2752-
2753-#ifdef CONFIG_PPC_STD_MMU_64
2754- /*
2755- * If we are using 1TB segments and we are allowed to randomise
2756- * the heap, we can put it above 1TB so it is backed by a 1TB
2757- * segment. Otherwise the heap will be in the bottom 1TB
2758- * which always uses 256MB segments and this may result in a
2759- * performance penalty.
2760- */
2761- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2762- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2763-#endif
2764-
2765- ret = PAGE_ALIGN(base + brk_rnd());
2766-
2767- if (ret < mm->brk)
2768- return mm->brk;
2769-
2770- return ret;
2771-}
2772-
2773-unsigned long randomize_et_dyn(unsigned long base)
2774-{
2775- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2776-
2777- if (ret < base)
2778- return base;
2779-
2780- return ret;
2781-}
2782diff -urNp linux-2.6.32.43/arch/powerpc/kernel/signal_32.c linux-2.6.32.43/arch/powerpc/kernel/signal_32.c
2783--- linux-2.6.32.43/arch/powerpc/kernel/signal_32.c 2011-03-27 14:31:47.000000000 -0400
2784+++ linux-2.6.32.43/arch/powerpc/kernel/signal_32.c 2011-04-17 15:56:45.000000000 -0400
2785@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
2786 /* Save user registers on the stack */
2787 frame = &rt_sf->uc.uc_mcontext;
2788 addr = frame;
2789- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2790+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2791 if (save_user_regs(regs, frame, 0, 1))
2792 goto badframe;
2793 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2794diff -urNp linux-2.6.32.43/arch/powerpc/kernel/signal_64.c linux-2.6.32.43/arch/powerpc/kernel/signal_64.c
2795--- linux-2.6.32.43/arch/powerpc/kernel/signal_64.c 2011-03-27 14:31:47.000000000 -0400
2796+++ linux-2.6.32.43/arch/powerpc/kernel/signal_64.c 2011-04-17 15:56:45.000000000 -0400
2797@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
2798 current->thread.fpscr.val = 0;
2799
2800 /* Set up to return from userspace. */
2801- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2802+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2803 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2804 } else {
2805 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2806diff -urNp linux-2.6.32.43/arch/powerpc/kernel/sys_ppc32.c linux-2.6.32.43/arch/powerpc/kernel/sys_ppc32.c
2807--- linux-2.6.32.43/arch/powerpc/kernel/sys_ppc32.c 2011-03-27 14:31:47.000000000 -0400
2808+++ linux-2.6.32.43/arch/powerpc/kernel/sys_ppc32.c 2011-04-17 15:56:45.000000000 -0400
2809@@ -563,10 +563,10 @@ asmlinkage long compat_sys_sysctl(struct
2810 if (oldlenp) {
2811 if (!error) {
2812 if (get_user(oldlen, oldlenp) ||
2813- put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
2814+ put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
2815+ copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
2816 error = -EFAULT;
2817 }
2818- copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
2819 }
2820 return error;
2821 }
2822diff -urNp linux-2.6.32.43/arch/powerpc/kernel/traps.c linux-2.6.32.43/arch/powerpc/kernel/traps.c
2823--- linux-2.6.32.43/arch/powerpc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
2824+++ linux-2.6.32.43/arch/powerpc/kernel/traps.c 2011-06-13 21:33:37.000000000 -0400
2825@@ -99,6 +99,8 @@ static void pmac_backlight_unblank(void)
2826 static inline void pmac_backlight_unblank(void) { }
2827 #endif
2828
2829+extern void gr_handle_kernel_exploit(void);
2830+
2831 int die(const char *str, struct pt_regs *regs, long err)
2832 {
2833 static struct {
2834@@ -168,6 +170,8 @@ int die(const char *str, struct pt_regs
2835 if (panic_on_oops)
2836 panic("Fatal exception");
2837
2838+ gr_handle_kernel_exploit();
2839+
2840 oops_exit();
2841 do_exit(err);
2842
2843diff -urNp linux-2.6.32.43/arch/powerpc/kernel/vdso.c linux-2.6.32.43/arch/powerpc/kernel/vdso.c
2844--- linux-2.6.32.43/arch/powerpc/kernel/vdso.c 2011-03-27 14:31:47.000000000 -0400
2845+++ linux-2.6.32.43/arch/powerpc/kernel/vdso.c 2011-04-17 15:56:45.000000000 -0400
2846@@ -36,6 +36,7 @@
2847 #include <asm/firmware.h>
2848 #include <asm/vdso.h>
2849 #include <asm/vdso_datapage.h>
2850+#include <asm/mman.h>
2851
2852 #include "setup.h"
2853
2854@@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
2855 vdso_base = VDSO32_MBASE;
2856 #endif
2857
2858- current->mm->context.vdso_base = 0;
2859+ current->mm->context.vdso_base = ~0UL;
2860
2861 /* vDSO has a problem and was disabled, just don't "enable" it for the
2862 * process
2863@@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
2864 vdso_base = get_unmapped_area(NULL, vdso_base,
2865 (vdso_pages << PAGE_SHIFT) +
2866 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2867- 0, 0);
2868+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
2869 if (IS_ERR_VALUE(vdso_base)) {
2870 rc = vdso_base;
2871 goto fail_mmapsem;
2872diff -urNp linux-2.6.32.43/arch/powerpc/kernel/vio.c linux-2.6.32.43/arch/powerpc/kernel/vio.c
2873--- linux-2.6.32.43/arch/powerpc/kernel/vio.c 2011-03-27 14:31:47.000000000 -0400
2874+++ linux-2.6.32.43/arch/powerpc/kernel/vio.c 2011-04-17 15:56:45.000000000 -0400
2875@@ -601,11 +601,12 @@ static void vio_dma_iommu_unmap_sg(struc
2876 vio_cmo_dealloc(viodev, alloc_size);
2877 }
2878
2879-struct dma_map_ops vio_dma_mapping_ops = {
2880+static const struct dma_map_ops vio_dma_mapping_ops = {
2881 .alloc_coherent = vio_dma_iommu_alloc_coherent,
2882 .free_coherent = vio_dma_iommu_free_coherent,
2883 .map_sg = vio_dma_iommu_map_sg,
2884 .unmap_sg = vio_dma_iommu_unmap_sg,
2885+ .dma_supported = dma_iommu_dma_supported,
2886 .map_page = vio_dma_iommu_map_page,
2887 .unmap_page = vio_dma_iommu_unmap_page,
2888
2889@@ -857,7 +858,6 @@ static void vio_cmo_bus_remove(struct vi
2890
2891 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
2892 {
2893- vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
2894 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
2895 }
2896
2897diff -urNp linux-2.6.32.43/arch/powerpc/lib/usercopy_64.c linux-2.6.32.43/arch/powerpc/lib/usercopy_64.c
2898--- linux-2.6.32.43/arch/powerpc/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
2899+++ linux-2.6.32.43/arch/powerpc/lib/usercopy_64.c 2011-04-17 15:56:45.000000000 -0400
2900@@ -9,22 +9,6 @@
2901 #include <linux/module.h>
2902 #include <asm/uaccess.h>
2903
2904-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2905-{
2906- if (likely(access_ok(VERIFY_READ, from, n)))
2907- n = __copy_from_user(to, from, n);
2908- else
2909- memset(to, 0, n);
2910- return n;
2911-}
2912-
2913-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2914-{
2915- if (likely(access_ok(VERIFY_WRITE, to, n)))
2916- n = __copy_to_user(to, from, n);
2917- return n;
2918-}
2919-
2920 unsigned long copy_in_user(void __user *to, const void __user *from,
2921 unsigned long n)
2922 {
2923@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
2924 return n;
2925 }
2926
2927-EXPORT_SYMBOL(copy_from_user);
2928-EXPORT_SYMBOL(copy_to_user);
2929 EXPORT_SYMBOL(copy_in_user);
2930
2931diff -urNp linux-2.6.32.43/arch/powerpc/mm/fault.c linux-2.6.32.43/arch/powerpc/mm/fault.c
2932--- linux-2.6.32.43/arch/powerpc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
2933+++ linux-2.6.32.43/arch/powerpc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
2934@@ -30,6 +30,10 @@
2935 #include <linux/kprobes.h>
2936 #include <linux/kdebug.h>
2937 #include <linux/perf_event.h>
2938+#include <linux/slab.h>
2939+#include <linux/pagemap.h>
2940+#include <linux/compiler.h>
2941+#include <linux/unistd.h>
2942
2943 #include <asm/firmware.h>
2944 #include <asm/page.h>
2945@@ -40,6 +44,7 @@
2946 #include <asm/uaccess.h>
2947 #include <asm/tlbflush.h>
2948 #include <asm/siginfo.h>
2949+#include <asm/ptrace.h>
2950
2951
2952 #ifdef CONFIG_KPROBES
2953@@ -64,6 +69,33 @@ static inline int notify_page_fault(stru
2954 }
2955 #endif
2956
2957+#ifdef CONFIG_PAX_PAGEEXEC
2958+/*
2959+ * PaX: decide what to do with offenders (regs->nip = fault address)
2960+ *
2961+ * returns 1 when task should be killed
2962+ */
2963+static int pax_handle_fetch_fault(struct pt_regs *regs)
2964+{
2965+ return 1;
2966+}
2967+
2968+void pax_report_insns(void *pc, void *sp)
2969+{
2970+ unsigned long i;
2971+
2972+ printk(KERN_ERR "PAX: bytes at PC: ");
2973+ for (i = 0; i < 5; i++) {
2974+ unsigned int c;
2975+ if (get_user(c, (unsigned int __user *)pc+i))
2976+ printk(KERN_CONT "???????? ");
2977+ else
2978+ printk(KERN_CONT "%08x ", c);
2979+ }
2980+ printk("\n");
2981+}
2982+#endif
2983+
2984 /*
2985 * Check whether the instruction at regs->nip is a store using
2986 * an update addressing form which will update r1.
2987@@ -134,7 +166,7 @@ int __kprobes do_page_fault(struct pt_re
2988 * indicate errors in DSISR but can validly be set in SRR1.
2989 */
2990 if (trap == 0x400)
2991- error_code &= 0x48200000;
2992+ error_code &= 0x58200000;
2993 else
2994 is_write = error_code & DSISR_ISSTORE;
2995 #else
2996@@ -250,7 +282,7 @@ good_area:
2997 * "undefined". Of those that can be set, this is the only
2998 * one which seems bad.
2999 */
3000- if (error_code & 0x10000000)
3001+ if (error_code & DSISR_GUARDED)
3002 /* Guarded storage error. */
3003 goto bad_area;
3004 #endif /* CONFIG_8xx */
3005@@ -265,7 +297,7 @@ good_area:
3006 * processors use the same I/D cache coherency mechanism
3007 * as embedded.
3008 */
3009- if (error_code & DSISR_PROTFAULT)
3010+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3011 goto bad_area;
3012 #endif /* CONFIG_PPC_STD_MMU */
3013
3014@@ -335,6 +367,23 @@ bad_area:
3015 bad_area_nosemaphore:
3016 /* User mode accesses cause a SIGSEGV */
3017 if (user_mode(regs)) {
3018+
3019+#ifdef CONFIG_PAX_PAGEEXEC
3020+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3021+#ifdef CONFIG_PPC_STD_MMU
3022+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
3023+#else
3024+ if (is_exec && regs->nip == address) {
3025+#endif
3026+ switch (pax_handle_fetch_fault(regs)) {
3027+ }
3028+
3029+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3030+ do_group_exit(SIGKILL);
3031+ }
3032+ }
3033+#endif
3034+
3035 _exception(SIGSEGV, regs, code, address);
3036 return 0;
3037 }
3038diff -urNp linux-2.6.32.43/arch/powerpc/mm/mmap_64.c linux-2.6.32.43/arch/powerpc/mm/mmap_64.c
3039--- linux-2.6.32.43/arch/powerpc/mm/mmap_64.c 2011-03-27 14:31:47.000000000 -0400
3040+++ linux-2.6.32.43/arch/powerpc/mm/mmap_64.c 2011-04-17 15:56:45.000000000 -0400
3041@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
3042 */
3043 if (mmap_is_legacy()) {
3044 mm->mmap_base = TASK_UNMAPPED_BASE;
3045+
3046+#ifdef CONFIG_PAX_RANDMMAP
3047+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3048+ mm->mmap_base += mm->delta_mmap;
3049+#endif
3050+
3051 mm->get_unmapped_area = arch_get_unmapped_area;
3052 mm->unmap_area = arch_unmap_area;
3053 } else {
3054 mm->mmap_base = mmap_base();
3055+
3056+#ifdef CONFIG_PAX_RANDMMAP
3057+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3058+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3059+#endif
3060+
3061 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3062 mm->unmap_area = arch_unmap_area_topdown;
3063 }
3064diff -urNp linux-2.6.32.43/arch/powerpc/mm/slice.c linux-2.6.32.43/arch/powerpc/mm/slice.c
3065--- linux-2.6.32.43/arch/powerpc/mm/slice.c 2011-03-27 14:31:47.000000000 -0400
3066+++ linux-2.6.32.43/arch/powerpc/mm/slice.c 2011-04-17 15:56:45.000000000 -0400
3067@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
3068 if ((mm->task_size - len) < addr)
3069 return 0;
3070 vma = find_vma(mm, addr);
3071- return (!vma || (addr + len) <= vma->vm_start);
3072+ return check_heap_stack_gap(vma, addr, len);
3073 }
3074
3075 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3076@@ -256,7 +256,7 @@ full_search:
3077 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3078 continue;
3079 }
3080- if (!vma || addr + len <= vma->vm_start) {
3081+ if (check_heap_stack_gap(vma, addr, len)) {
3082 /*
3083 * Remember the place where we stopped the search:
3084 */
3085@@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
3086 }
3087 }
3088
3089- addr = mm->mmap_base;
3090- while (addr > len) {
3091+ if (mm->mmap_base < len)
3092+ addr = -ENOMEM;
3093+ else
3094+ addr = mm->mmap_base - len;
3095+
3096+ while (!IS_ERR_VALUE(addr)) {
3097 /* Go down by chunk size */
3098- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3099+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
3100
3101 /* Check for hit with different page size */
3102 mask = slice_range_to_mask(addr, len);
3103@@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
3104 * return with success:
3105 */
3106 vma = find_vma(mm, addr);
3107- if (!vma || (addr + len) <= vma->vm_start) {
3108+ if (check_heap_stack_gap(vma, addr, len)) {
3109 /* remember the address as a hint for next time */
3110 if (use_cache)
3111 mm->free_area_cache = addr;
3112@@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
3113 mm->cached_hole_size = vma->vm_start - addr;
3114
3115 /* try just below the current vma->vm_start */
3116- addr = vma->vm_start;
3117+ addr = skip_heap_stack_gap(vma, len);
3118 }
3119
3120 /*
3121@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
3122 if (fixed && addr > (mm->task_size - len))
3123 return -EINVAL;
3124
3125+#ifdef CONFIG_PAX_RANDMMAP
3126+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3127+ addr = 0;
3128+#endif
3129+
3130 /* If hint, make sure it matches our alignment restrictions */
3131 if (!fixed && addr) {
3132 addr = _ALIGN_UP(addr, 1ul << pshift);
3133diff -urNp linux-2.6.32.43/arch/powerpc/platforms/52xx/lite5200_pm.c linux-2.6.32.43/arch/powerpc/platforms/52xx/lite5200_pm.c
3134--- linux-2.6.32.43/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-03-27 14:31:47.000000000 -0400
3135+++ linux-2.6.32.43/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-04-17 15:56:45.000000000 -0400
3136@@ -235,7 +235,7 @@ static void lite5200_pm_end(void)
3137 lite5200_pm_target_state = PM_SUSPEND_ON;
3138 }
3139
3140-static struct platform_suspend_ops lite5200_pm_ops = {
3141+static const struct platform_suspend_ops lite5200_pm_ops = {
3142 .valid = lite5200_pm_valid,
3143 .begin = lite5200_pm_begin,
3144 .prepare = lite5200_pm_prepare,
3145diff -urNp linux-2.6.32.43/arch/powerpc/platforms/52xx/mpc52xx_pm.c linux-2.6.32.43/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3146--- linux-2.6.32.43/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-03-27 14:31:47.000000000 -0400
3147+++ linux-2.6.32.43/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-04-17 15:56:45.000000000 -0400
3148@@ -180,7 +180,7 @@ void mpc52xx_pm_finish(void)
3149 iounmap(mbar);
3150 }
3151
3152-static struct platform_suspend_ops mpc52xx_pm_ops = {
3153+static const struct platform_suspend_ops mpc52xx_pm_ops = {
3154 .valid = mpc52xx_pm_valid,
3155 .prepare = mpc52xx_pm_prepare,
3156 .enter = mpc52xx_pm_enter,
3157diff -urNp linux-2.6.32.43/arch/powerpc/platforms/83xx/suspend.c linux-2.6.32.43/arch/powerpc/platforms/83xx/suspend.c
3158--- linux-2.6.32.43/arch/powerpc/platforms/83xx/suspend.c 2011-03-27 14:31:47.000000000 -0400
3159+++ linux-2.6.32.43/arch/powerpc/platforms/83xx/suspend.c 2011-04-17 15:56:45.000000000 -0400
3160@@ -273,7 +273,7 @@ static int mpc83xx_is_pci_agent(void)
3161 return ret;
3162 }
3163
3164-static struct platform_suspend_ops mpc83xx_suspend_ops = {
3165+static const struct platform_suspend_ops mpc83xx_suspend_ops = {
3166 .valid = mpc83xx_suspend_valid,
3167 .begin = mpc83xx_suspend_begin,
3168 .enter = mpc83xx_suspend_enter,
3169diff -urNp linux-2.6.32.43/arch/powerpc/platforms/cell/iommu.c linux-2.6.32.43/arch/powerpc/platforms/cell/iommu.c
3170--- linux-2.6.32.43/arch/powerpc/platforms/cell/iommu.c 2011-03-27 14:31:47.000000000 -0400
3171+++ linux-2.6.32.43/arch/powerpc/platforms/cell/iommu.c 2011-04-17 15:56:45.000000000 -0400
3172@@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
3173
3174 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3175
3176-struct dma_map_ops dma_iommu_fixed_ops = {
3177+const struct dma_map_ops dma_iommu_fixed_ops = {
3178 .alloc_coherent = dma_fixed_alloc_coherent,
3179 .free_coherent = dma_fixed_free_coherent,
3180 .map_sg = dma_fixed_map_sg,
3181diff -urNp linux-2.6.32.43/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.32.43/arch/powerpc/platforms/ps3/system-bus.c
3182--- linux-2.6.32.43/arch/powerpc/platforms/ps3/system-bus.c 2011-03-27 14:31:47.000000000 -0400
3183+++ linux-2.6.32.43/arch/powerpc/platforms/ps3/system-bus.c 2011-04-17 15:56:45.000000000 -0400
3184@@ -694,7 +694,7 @@ static int ps3_dma_supported(struct devi
3185 return mask >= DMA_BIT_MASK(32);
3186 }
3187
3188-static struct dma_map_ops ps3_sb_dma_ops = {
3189+static const struct dma_map_ops ps3_sb_dma_ops = {
3190 .alloc_coherent = ps3_alloc_coherent,
3191 .free_coherent = ps3_free_coherent,
3192 .map_sg = ps3_sb_map_sg,
3193@@ -704,7 +704,7 @@ static struct dma_map_ops ps3_sb_dma_ops
3194 .unmap_page = ps3_unmap_page,
3195 };
3196
3197-static struct dma_map_ops ps3_ioc0_dma_ops = {
3198+static const struct dma_map_ops ps3_ioc0_dma_ops = {
3199 .alloc_coherent = ps3_alloc_coherent,
3200 .free_coherent = ps3_free_coherent,
3201 .map_sg = ps3_ioc0_map_sg,
3202diff -urNp linux-2.6.32.43/arch/powerpc/platforms/pseries/Kconfig linux-2.6.32.43/arch/powerpc/platforms/pseries/Kconfig
3203--- linux-2.6.32.43/arch/powerpc/platforms/pseries/Kconfig 2011-03-27 14:31:47.000000000 -0400
3204+++ linux-2.6.32.43/arch/powerpc/platforms/pseries/Kconfig 2011-04-17 15:56:45.000000000 -0400
3205@@ -2,6 +2,8 @@ config PPC_PSERIES
3206 depends on PPC64 && PPC_BOOK3S
3207 bool "IBM pSeries & new (POWER5-based) iSeries"
3208 select MPIC
3209+ select PCI_MSI
3210+ select XICS
3211 select PPC_I8259
3212 select PPC_RTAS
3213 select RTAS_ERROR_LOGGING
3214diff -urNp linux-2.6.32.43/arch/s390/include/asm/elf.h linux-2.6.32.43/arch/s390/include/asm/elf.h
3215--- linux-2.6.32.43/arch/s390/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
3216+++ linux-2.6.32.43/arch/s390/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
3217@@ -164,6 +164,13 @@ extern unsigned int vdso_enabled;
3218 that it will "exec", and that there is sufficient room for the brk. */
3219 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3220
3221+#ifdef CONFIG_PAX_ASLR
3222+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3223+
3224+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3225+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3226+#endif
3227+
3228 /* This yields a mask that user programs can use to figure out what
3229 instruction set this CPU supports. */
3230
3231diff -urNp linux-2.6.32.43/arch/s390/include/asm/setup.h linux-2.6.32.43/arch/s390/include/asm/setup.h
3232--- linux-2.6.32.43/arch/s390/include/asm/setup.h 2011-03-27 14:31:47.000000000 -0400
3233+++ linux-2.6.32.43/arch/s390/include/asm/setup.h 2011-04-17 15:56:45.000000000 -0400
3234@@ -50,13 +50,13 @@ extern unsigned long memory_end;
3235 void detect_memory_layout(struct mem_chunk chunk[]);
3236
3237 #ifdef CONFIG_S390_SWITCH_AMODE
3238-extern unsigned int switch_amode;
3239+#define switch_amode (1)
3240 #else
3241 #define switch_amode (0)
3242 #endif
3243
3244 #ifdef CONFIG_S390_EXEC_PROTECT
3245-extern unsigned int s390_noexec;
3246+#define s390_noexec (1)
3247 #else
3248 #define s390_noexec (0)
3249 #endif
3250diff -urNp linux-2.6.32.43/arch/s390/include/asm/uaccess.h linux-2.6.32.43/arch/s390/include/asm/uaccess.h
3251--- linux-2.6.32.43/arch/s390/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
3252+++ linux-2.6.32.43/arch/s390/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
3253@@ -232,6 +232,10 @@ static inline unsigned long __must_check
3254 copy_to_user(void __user *to, const void *from, unsigned long n)
3255 {
3256 might_fault();
3257+
3258+ if ((long)n < 0)
3259+ return n;
3260+
3261 if (access_ok(VERIFY_WRITE, to, n))
3262 n = __copy_to_user(to, from, n);
3263 return n;
3264@@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void
3265 static inline unsigned long __must_check
3266 __copy_from_user(void *to, const void __user *from, unsigned long n)
3267 {
3268+ if ((long)n < 0)
3269+ return n;
3270+
3271 if (__builtin_constant_p(n) && (n <= 256))
3272 return uaccess.copy_from_user_small(n, from, to);
3273 else
3274@@ -283,6 +290,10 @@ static inline unsigned long __must_check
3275 copy_from_user(void *to, const void __user *from, unsigned long n)
3276 {
3277 might_fault();
3278+
3279+ if ((long)n < 0)
3280+ return n;
3281+
3282 if (access_ok(VERIFY_READ, from, n))
3283 n = __copy_from_user(to, from, n);
3284 else
3285diff -urNp linux-2.6.32.43/arch/s390/Kconfig linux-2.6.32.43/arch/s390/Kconfig
3286--- linux-2.6.32.43/arch/s390/Kconfig 2011-03-27 14:31:47.000000000 -0400
3287+++ linux-2.6.32.43/arch/s390/Kconfig 2011-04-17 15:56:45.000000000 -0400
3288@@ -194,28 +194,26 @@ config AUDIT_ARCH
3289
3290 config S390_SWITCH_AMODE
3291 bool "Switch kernel/user addressing modes"
3292+ default y
3293 help
3294 This option allows to switch the addressing modes of kernel and user
3295- space. The kernel parameter switch_amode=on will enable this feature,
3296- default is disabled. Enabling this (via kernel parameter) on machines
3297- earlier than IBM System z9-109 EC/BC will reduce system performance.
3298+ space. Enabling this on machines earlier than IBM System z9-109 EC/BC
3299+ will reduce system performance.
3300
3301 Note that this option will also be selected by selecting the execute
3302- protection option below. Enabling the execute protection via the
3303- noexec kernel parameter will also switch the addressing modes,
3304- independent of the switch_amode kernel parameter.
3305+ protection option below. Enabling the execute protection will also
3306+ switch the addressing modes, independent of this option.
3307
3308
3309 config S390_EXEC_PROTECT
3310 bool "Data execute protection"
3311+ default y
3312 select S390_SWITCH_AMODE
3313 help
3314 This option allows to enable a buffer overflow protection for user
3315 space programs and it also selects the addressing mode option above.
3316- The kernel parameter noexec=on will enable this feature and also
3317- switch the addressing modes, default is disabled. Enabling this (via
3318- kernel parameter) on machines earlier than IBM System z9-109 EC/BC
3319- will reduce system performance.
3320+ Enabling this on machines earlier than IBM System z9-109 EC/BC will
3321+ reduce system performance.
3322
3323 comment "Code generation options"
3324
3325diff -urNp linux-2.6.32.43/arch/s390/kernel/module.c linux-2.6.32.43/arch/s390/kernel/module.c
3326--- linux-2.6.32.43/arch/s390/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
3327+++ linux-2.6.32.43/arch/s390/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
3328@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3329
3330 /* Increase core size by size of got & plt and set start
3331 offsets for got and plt. */
3332- me->core_size = ALIGN(me->core_size, 4);
3333- me->arch.got_offset = me->core_size;
3334- me->core_size += me->arch.got_size;
3335- me->arch.plt_offset = me->core_size;
3336- me->core_size += me->arch.plt_size;
3337+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
3338+ me->arch.got_offset = me->core_size_rw;
3339+ me->core_size_rw += me->arch.got_size;
3340+ me->arch.plt_offset = me->core_size_rx;
3341+ me->core_size_rx += me->arch.plt_size;
3342 return 0;
3343 }
3344
3345@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3346 if (info->got_initialized == 0) {
3347 Elf_Addr *gotent;
3348
3349- gotent = me->module_core + me->arch.got_offset +
3350+ gotent = me->module_core_rw + me->arch.got_offset +
3351 info->got_offset;
3352 *gotent = val;
3353 info->got_initialized = 1;
3354@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3355 else if (r_type == R_390_GOTENT ||
3356 r_type == R_390_GOTPLTENT)
3357 *(unsigned int *) loc =
3358- (val + (Elf_Addr) me->module_core - loc) >> 1;
3359+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3360 else if (r_type == R_390_GOT64 ||
3361 r_type == R_390_GOTPLT64)
3362 *(unsigned long *) loc = val;
3363@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3364 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3365 if (info->plt_initialized == 0) {
3366 unsigned int *ip;
3367- ip = me->module_core + me->arch.plt_offset +
3368+ ip = me->module_core_rx + me->arch.plt_offset +
3369 info->plt_offset;
3370 #ifndef CONFIG_64BIT
3371 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3372@@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3373 val - loc + 0xffffUL < 0x1ffffeUL) ||
3374 (r_type == R_390_PLT32DBL &&
3375 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3376- val = (Elf_Addr) me->module_core +
3377+ val = (Elf_Addr) me->module_core_rx +
3378 me->arch.plt_offset +
3379 info->plt_offset;
3380 val += rela->r_addend - loc;
3381@@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3382 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3383 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3384 val = val + rela->r_addend -
3385- ((Elf_Addr) me->module_core + me->arch.got_offset);
3386+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3387 if (r_type == R_390_GOTOFF16)
3388 *(unsigned short *) loc = val;
3389 else if (r_type == R_390_GOTOFF32)
3390@@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3391 break;
3392 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3393 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3394- val = (Elf_Addr) me->module_core + me->arch.got_offset +
3395+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3396 rela->r_addend - loc;
3397 if (r_type == R_390_GOTPC)
3398 *(unsigned int *) loc = val;
3399diff -urNp linux-2.6.32.43/arch/s390/kernel/setup.c linux-2.6.32.43/arch/s390/kernel/setup.c
3400--- linux-2.6.32.43/arch/s390/kernel/setup.c 2011-03-27 14:31:47.000000000 -0400
3401+++ linux-2.6.32.43/arch/s390/kernel/setup.c 2011-04-17 15:56:45.000000000 -0400
3402@@ -306,9 +306,6 @@ static int __init early_parse_mem(char *
3403 early_param("mem", early_parse_mem);
3404
3405 #ifdef CONFIG_S390_SWITCH_AMODE
3406-unsigned int switch_amode = 0;
3407-EXPORT_SYMBOL_GPL(switch_amode);
3408-
3409 static int set_amode_and_uaccess(unsigned long user_amode,
3410 unsigned long user32_amode)
3411 {
3412@@ -334,17 +331,6 @@ static int set_amode_and_uaccess(unsigne
3413 return 0;
3414 }
3415 }
3416-
3417-/*
3418- * Switch kernel/user addressing modes?
3419- */
3420-static int __init early_parse_switch_amode(char *p)
3421-{
3422- switch_amode = 1;
3423- return 0;
3424-}
3425-early_param("switch_amode", early_parse_switch_amode);
3426-
3427 #else /* CONFIG_S390_SWITCH_AMODE */
3428 static inline int set_amode_and_uaccess(unsigned long user_amode,
3429 unsigned long user32_amode)
3430@@ -353,24 +339,6 @@ static inline int set_amode_and_uaccess(
3431 }
3432 #endif /* CONFIG_S390_SWITCH_AMODE */
3433
3434-#ifdef CONFIG_S390_EXEC_PROTECT
3435-unsigned int s390_noexec = 0;
3436-EXPORT_SYMBOL_GPL(s390_noexec);
3437-
3438-/*
3439- * Enable execute protection?
3440- */
3441-static int __init early_parse_noexec(char *p)
3442-{
3443- if (!strncmp(p, "off", 3))
3444- return 0;
3445- switch_amode = 1;
3446- s390_noexec = 1;
3447- return 0;
3448-}
3449-early_param("noexec", early_parse_noexec);
3450-#endif /* CONFIG_S390_EXEC_PROTECT */
3451-
3452 static void setup_addressing_mode(void)
3453 {
3454 if (s390_noexec) {
3455diff -urNp linux-2.6.32.43/arch/s390/mm/mmap.c linux-2.6.32.43/arch/s390/mm/mmap.c
3456--- linux-2.6.32.43/arch/s390/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3457+++ linux-2.6.32.43/arch/s390/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
3458@@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_str
3459 */
3460 if (mmap_is_legacy()) {
3461 mm->mmap_base = TASK_UNMAPPED_BASE;
3462+
3463+#ifdef CONFIG_PAX_RANDMMAP
3464+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3465+ mm->mmap_base += mm->delta_mmap;
3466+#endif
3467+
3468 mm->get_unmapped_area = arch_get_unmapped_area;
3469 mm->unmap_area = arch_unmap_area;
3470 } else {
3471 mm->mmap_base = mmap_base();
3472+
3473+#ifdef CONFIG_PAX_RANDMMAP
3474+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3475+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3476+#endif
3477+
3478 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3479 mm->unmap_area = arch_unmap_area_topdown;
3480 }
3481@@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_str
3482 */
3483 if (mmap_is_legacy()) {
3484 mm->mmap_base = TASK_UNMAPPED_BASE;
3485+
3486+#ifdef CONFIG_PAX_RANDMMAP
3487+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3488+ mm->mmap_base += mm->delta_mmap;
3489+#endif
3490+
3491 mm->get_unmapped_area = s390_get_unmapped_area;
3492 mm->unmap_area = arch_unmap_area;
3493 } else {
3494 mm->mmap_base = mmap_base();
3495+
3496+#ifdef CONFIG_PAX_RANDMMAP
3497+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3498+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3499+#endif
3500+
3501 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3502 mm->unmap_area = arch_unmap_area_topdown;
3503 }
3504diff -urNp linux-2.6.32.43/arch/score/include/asm/system.h linux-2.6.32.43/arch/score/include/asm/system.h
3505--- linux-2.6.32.43/arch/score/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
3506+++ linux-2.6.32.43/arch/score/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
3507@@ -17,7 +17,7 @@ do { \
3508 #define finish_arch_switch(prev) do {} while (0)
3509
3510 typedef void (*vi_handler_t)(void);
3511-extern unsigned long arch_align_stack(unsigned long sp);
3512+#define arch_align_stack(x) (x)
3513
3514 #define mb() barrier()
3515 #define rmb() barrier()
3516diff -urNp linux-2.6.32.43/arch/score/kernel/process.c linux-2.6.32.43/arch/score/kernel/process.c
3517--- linux-2.6.32.43/arch/score/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
3518+++ linux-2.6.32.43/arch/score/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
3519@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
3520
3521 return task_pt_regs(task)->cp0_epc;
3522 }
3523-
3524-unsigned long arch_align_stack(unsigned long sp)
3525-{
3526- return sp;
3527-}
3528diff -urNp linux-2.6.32.43/arch/sh/boards/mach-hp6xx/pm.c linux-2.6.32.43/arch/sh/boards/mach-hp6xx/pm.c
3529--- linux-2.6.32.43/arch/sh/boards/mach-hp6xx/pm.c 2011-03-27 14:31:47.000000000 -0400
3530+++ linux-2.6.32.43/arch/sh/boards/mach-hp6xx/pm.c 2011-04-17 15:56:45.000000000 -0400
3531@@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_
3532 return 0;
3533 }
3534
3535-static struct platform_suspend_ops hp6x0_pm_ops = {
3536+static const struct platform_suspend_ops hp6x0_pm_ops = {
3537 .enter = hp6x0_pm_enter,
3538 .valid = suspend_valid_only_mem,
3539 };
3540diff -urNp linux-2.6.32.43/arch/sh/kernel/cpu/sh4/sq.c linux-2.6.32.43/arch/sh/kernel/cpu/sh4/sq.c
3541--- linux-2.6.32.43/arch/sh/kernel/cpu/sh4/sq.c 2011-03-27 14:31:47.000000000 -0400
3542+++ linux-2.6.32.43/arch/sh/kernel/cpu/sh4/sq.c 2011-04-17 15:56:46.000000000 -0400
3543@@ -327,7 +327,7 @@ static struct attribute *sq_sysfs_attrs[
3544 NULL,
3545 };
3546
3547-static struct sysfs_ops sq_sysfs_ops = {
3548+static const struct sysfs_ops sq_sysfs_ops = {
3549 .show = sq_sysfs_show,
3550 .store = sq_sysfs_store,
3551 };
3552diff -urNp linux-2.6.32.43/arch/sh/kernel/cpu/shmobile/pm.c linux-2.6.32.43/arch/sh/kernel/cpu/shmobile/pm.c
3553--- linux-2.6.32.43/arch/sh/kernel/cpu/shmobile/pm.c 2011-03-27 14:31:47.000000000 -0400
3554+++ linux-2.6.32.43/arch/sh/kernel/cpu/shmobile/pm.c 2011-04-17 15:56:46.000000000 -0400
3555@@ -58,7 +58,7 @@ static int sh_pm_enter(suspend_state_t s
3556 return 0;
3557 }
3558
3559-static struct platform_suspend_ops sh_pm_ops = {
3560+static const struct platform_suspend_ops sh_pm_ops = {
3561 .enter = sh_pm_enter,
3562 .valid = suspend_valid_only_mem,
3563 };
3564diff -urNp linux-2.6.32.43/arch/sh/kernel/kgdb.c linux-2.6.32.43/arch/sh/kernel/kgdb.c
3565--- linux-2.6.32.43/arch/sh/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
3566+++ linux-2.6.32.43/arch/sh/kernel/kgdb.c 2011-04-17 15:56:46.000000000 -0400
3567@@ -271,7 +271,7 @@ void kgdb_arch_exit(void)
3568 {
3569 }
3570
3571-struct kgdb_arch arch_kgdb_ops = {
3572+const struct kgdb_arch arch_kgdb_ops = {
3573 /* Breakpoint instruction: trapa #0x3c */
3574 #ifdef CONFIG_CPU_LITTLE_ENDIAN
3575 .gdb_bpt_instr = { 0x3c, 0xc3 },
3576diff -urNp linux-2.6.32.43/arch/sh/mm/mmap.c linux-2.6.32.43/arch/sh/mm/mmap.c
3577--- linux-2.6.32.43/arch/sh/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3578+++ linux-2.6.32.43/arch/sh/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
3579@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
3580 addr = PAGE_ALIGN(addr);
3581
3582 vma = find_vma(mm, addr);
3583- if (TASK_SIZE - len >= addr &&
3584- (!vma || addr + len <= vma->vm_start))
3585+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3586 return addr;
3587 }
3588
3589@@ -106,7 +105,7 @@ full_search:
3590 }
3591 return -ENOMEM;
3592 }
3593- if (likely(!vma || addr + len <= vma->vm_start)) {
3594+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3595 /*
3596 * Remember the place where we stopped the search:
3597 */
3598@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
3599 addr = PAGE_ALIGN(addr);
3600
3601 vma = find_vma(mm, addr);
3602- if (TASK_SIZE - len >= addr &&
3603- (!vma || addr + len <= vma->vm_start))
3604+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3605 return addr;
3606 }
3607
3608@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
3609 /* make sure it can fit in the remaining address space */
3610 if (likely(addr > len)) {
3611 vma = find_vma(mm, addr-len);
3612- if (!vma || addr <= vma->vm_start) {
3613+ if (check_heap_stack_gap(vma, addr - len, len)) {
3614 /* remember the address as a hint for next time */
3615 return (mm->free_area_cache = addr-len);
3616 }
3617@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
3618 if (unlikely(mm->mmap_base < len))
3619 goto bottomup;
3620
3621- addr = mm->mmap_base-len;
3622- if (do_colour_align)
3623- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3624+ addr = mm->mmap_base - len;
3625
3626 do {
3627+ if (do_colour_align)
3628+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3629 /*
3630 * Lookup failure means no vma is above this address,
3631 * else if new region fits below vma->vm_start,
3632 * return with success:
3633 */
3634 vma = find_vma(mm, addr);
3635- if (likely(!vma || addr+len <= vma->vm_start)) {
3636+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3637 /* remember the address as a hint for next time */
3638 return (mm->free_area_cache = addr);
3639 }
3640@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
3641 mm->cached_hole_size = vma->vm_start - addr;
3642
3643 /* try just below the current vma->vm_start */
3644- addr = vma->vm_start-len;
3645- if (do_colour_align)
3646- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3647- } while (likely(len < vma->vm_start));
3648+ addr = skip_heap_stack_gap(vma, len);
3649+ } while (!IS_ERR_VALUE(addr));
3650
3651 bottomup:
3652 /*
3653diff -urNp linux-2.6.32.43/arch/sparc/include/asm/atomic_64.h linux-2.6.32.43/arch/sparc/include/asm/atomic_64.h
3654--- linux-2.6.32.43/arch/sparc/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
3655+++ linux-2.6.32.43/arch/sparc/include/asm/atomic_64.h 2011-07-13 22:22:56.000000000 -0400
3656@@ -14,18 +14,40 @@
3657 #define ATOMIC64_INIT(i) { (i) }
3658
3659 #define atomic_read(v) ((v)->counter)
3660+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3661+{
3662+ return v->counter;
3663+}
3664 #define atomic64_read(v) ((v)->counter)
3665+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3666+{
3667+ return v->counter;
3668+}
3669
3670 #define atomic_set(v, i) (((v)->counter) = i)
3671+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3672+{
3673+ v->counter = i;
3674+}
3675 #define atomic64_set(v, i) (((v)->counter) = i)
3676+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3677+{
3678+ v->counter = i;
3679+}
3680
3681 extern void atomic_add(int, atomic_t *);
3682+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3683 extern void atomic64_add(long, atomic64_t *);
3684+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3685 extern void atomic_sub(int, atomic_t *);
3686+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3687 extern void atomic64_sub(long, atomic64_t *);
3688+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3689
3690 extern int atomic_add_ret(int, atomic_t *);
3691+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3692 extern long atomic64_add_ret(long, atomic64_t *);
3693+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3694 extern int atomic_sub_ret(int, atomic_t *);
3695 extern long atomic64_sub_ret(long, atomic64_t *);
3696
3697@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomi
3698 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3699
3700 #define atomic_inc_return(v) atomic_add_ret(1, v)
3701+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3702+{
3703+ return atomic_add_ret_unchecked(1, v);
3704+}
3705 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3706+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3707+{
3708+ return atomic64_add_ret_unchecked(1, v);
3709+}
3710
3711 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3712 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3713
3714 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3715+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3716+{
3717+ return atomic_add_ret_unchecked(i, v);
3718+}
3719 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3720+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
3721+{
3722+ return atomic64_add_ret_unchecked(i, v);
3723+}
3724
3725 /*
3726 * atomic_inc_and_test - increment and test
3727@@ -50,6 +88,7 @@ extern long atomic64_sub_ret(long, atomi
3728 * other cases.
3729 */
3730 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3731+#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
3732 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3733
3734 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3735@@ -59,30 +98,59 @@ extern long atomic64_sub_ret(long, atomi
3736 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3737
3738 #define atomic_inc(v) atomic_add(1, v)
3739+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3740+{
3741+ atomic_add_unchecked(1, v);
3742+}
3743 #define atomic64_inc(v) atomic64_add(1, v)
3744+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3745+{
3746+ atomic64_add_unchecked(1, v);
3747+}
3748
3749 #define atomic_dec(v) atomic_sub(1, v)
3750+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3751+{
3752+ atomic_sub_unchecked(1, v);
3753+}
3754 #define atomic64_dec(v) atomic64_sub(1, v)
3755+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3756+{
3757+ atomic64_sub_unchecked(1, v);
3758+}
3759
3760 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3761 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3762
3763 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3764+#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3765 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3766+#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
3767
3768 static inline int atomic_add_unless(atomic_t *v, int a, int u)
3769 {
3770- int c, old;
3771+ int c, old, new;
3772 c = atomic_read(v);
3773 for (;;) {
3774- if (unlikely(c == (u)))
3775+ if (unlikely(c == u))
3776 break;
3777- old = atomic_cmpxchg((v), c, c + (a));
3778+
3779+ asm volatile("addcc %2, %0, %0\n"
3780+
3781+#ifdef CONFIG_PAX_REFCOUNT
3782+ "tvs %%icc, 6\n"
3783+#endif
3784+
3785+ : "=r" (new)
3786+ : "0" (c), "ir" (a)
3787+ : "cc");
3788+
3789+ old = atomic_cmpxchg(v, c, new);
3790 if (likely(old == c))
3791 break;
3792 c = old;
3793 }
3794- return c != (u);
3795+ return c != u;
3796 }
3797
3798 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
3799@@ -93,17 +161,28 @@ static inline int atomic_add_unless(atom
3800
3801 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3802 {
3803- long c, old;
3804+ long c, old, new;
3805 c = atomic64_read(v);
3806 for (;;) {
3807- if (unlikely(c == (u)))
3808+ if (unlikely(c == u))
3809 break;
3810- old = atomic64_cmpxchg((v), c, c + (a));
3811+
3812+ asm volatile("addcc %2, %0, %0\n"
3813+
3814+#ifdef CONFIG_PAX_REFCOUNT
3815+ "tvs %%xcc, 6\n"
3816+#endif
3817+
3818+ : "=r" (new)
3819+ : "0" (c), "ir" (a)
3820+ : "cc");
3821+
3822+ old = atomic64_cmpxchg(v, c, new);
3823 if (likely(old == c))
3824 break;
3825 c = old;
3826 }
3827- return c != (u);
3828+ return c != u;
3829 }
3830
3831 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3832diff -urNp linux-2.6.32.43/arch/sparc/include/asm/cache.h linux-2.6.32.43/arch/sparc/include/asm/cache.h
3833--- linux-2.6.32.43/arch/sparc/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
3834+++ linux-2.6.32.43/arch/sparc/include/asm/cache.h 2011-07-06 19:53:33.000000000 -0400
3835@@ -8,7 +8,7 @@
3836 #define _SPARC_CACHE_H
3837
3838 #define L1_CACHE_SHIFT 5
3839-#define L1_CACHE_BYTES 32
3840+#define L1_CACHE_BYTES 32UL
3841 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
3842
3843 #ifdef CONFIG_SPARC32
3844diff -urNp linux-2.6.32.43/arch/sparc/include/asm/dma-mapping.h linux-2.6.32.43/arch/sparc/include/asm/dma-mapping.h
3845--- linux-2.6.32.43/arch/sparc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
3846+++ linux-2.6.32.43/arch/sparc/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
3847@@ -14,10 +14,10 @@ extern int dma_set_mask(struct device *d
3848 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
3849 #define dma_is_consistent(d, h) (1)
3850
3851-extern struct dma_map_ops *dma_ops, pci32_dma_ops;
3852+extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
3853 extern struct bus_type pci_bus_type;
3854
3855-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3856+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3857 {
3858 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
3859 if (dev->bus == &pci_bus_type)
3860@@ -31,7 +31,7 @@ static inline struct dma_map_ops *get_dm
3861 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3862 dma_addr_t *dma_handle, gfp_t flag)
3863 {
3864- struct dma_map_ops *ops = get_dma_ops(dev);
3865+ const struct dma_map_ops *ops = get_dma_ops(dev);
3866 void *cpu_addr;
3867
3868 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
3869@@ -42,7 +42,7 @@ static inline void *dma_alloc_coherent(s
3870 static inline void dma_free_coherent(struct device *dev, size_t size,
3871 void *cpu_addr, dma_addr_t dma_handle)
3872 {
3873- struct dma_map_ops *ops = get_dma_ops(dev);
3874+ const struct dma_map_ops *ops = get_dma_ops(dev);
3875
3876 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
3877 ops->free_coherent(dev, size, cpu_addr, dma_handle);
3878diff -urNp linux-2.6.32.43/arch/sparc/include/asm/elf_32.h linux-2.6.32.43/arch/sparc/include/asm/elf_32.h
3879--- linux-2.6.32.43/arch/sparc/include/asm/elf_32.h 2011-03-27 14:31:47.000000000 -0400
3880+++ linux-2.6.32.43/arch/sparc/include/asm/elf_32.h 2011-04-17 15:56:46.000000000 -0400
3881@@ -116,6 +116,13 @@ typedef struct {
3882
3883 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3884
3885+#ifdef CONFIG_PAX_ASLR
3886+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3887+
3888+#define PAX_DELTA_MMAP_LEN 16
3889+#define PAX_DELTA_STACK_LEN 16
3890+#endif
3891+
3892 /* This yields a mask that user programs can use to figure out what
3893 instruction set this cpu supports. This can NOT be done in userspace
3894 on Sparc. */
3895diff -urNp linux-2.6.32.43/arch/sparc/include/asm/elf_64.h linux-2.6.32.43/arch/sparc/include/asm/elf_64.h
3896--- linux-2.6.32.43/arch/sparc/include/asm/elf_64.h 2011-03-27 14:31:47.000000000 -0400
3897+++ linux-2.6.32.43/arch/sparc/include/asm/elf_64.h 2011-04-17 15:56:46.000000000 -0400
3898@@ -163,6 +163,12 @@ typedef struct {
3899 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3900 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3901
3902+#ifdef CONFIG_PAX_ASLR
3903+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3904+
3905+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3906+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3907+#endif
3908
3909 /* This yields a mask that user programs can use to figure out what
3910 instruction set this cpu supports. */
3911diff -urNp linux-2.6.32.43/arch/sparc/include/asm/pgtable_32.h linux-2.6.32.43/arch/sparc/include/asm/pgtable_32.h
3912--- linux-2.6.32.43/arch/sparc/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
3913+++ linux-2.6.32.43/arch/sparc/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
3914@@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3915 BTFIXUPDEF_INT(page_none)
3916 BTFIXUPDEF_INT(page_copy)
3917 BTFIXUPDEF_INT(page_readonly)
3918+
3919+#ifdef CONFIG_PAX_PAGEEXEC
3920+BTFIXUPDEF_INT(page_shared_noexec)
3921+BTFIXUPDEF_INT(page_copy_noexec)
3922+BTFIXUPDEF_INT(page_readonly_noexec)
3923+#endif
3924+
3925 BTFIXUPDEF_INT(page_kernel)
3926
3927 #define PMD_SHIFT SUN4C_PMD_SHIFT
3928@@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
3929 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3930 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3931
3932+#ifdef CONFIG_PAX_PAGEEXEC
3933+extern pgprot_t PAGE_SHARED_NOEXEC;
3934+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3935+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3936+#else
3937+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3938+# define PAGE_COPY_NOEXEC PAGE_COPY
3939+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3940+#endif
3941+
3942 extern unsigned long page_kernel;
3943
3944 #ifdef MODULE
3945diff -urNp linux-2.6.32.43/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.32.43/arch/sparc/include/asm/pgtsrmmu.h
3946--- linux-2.6.32.43/arch/sparc/include/asm/pgtsrmmu.h 2011-03-27 14:31:47.000000000 -0400
3947+++ linux-2.6.32.43/arch/sparc/include/asm/pgtsrmmu.h 2011-04-17 15:56:46.000000000 -0400
3948@@ -115,6 +115,13 @@
3949 SRMMU_EXEC | SRMMU_REF)
3950 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3951 SRMMU_EXEC | SRMMU_REF)
3952+
3953+#ifdef CONFIG_PAX_PAGEEXEC
3954+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3955+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3956+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3957+#endif
3958+
3959 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3960 SRMMU_DIRTY | SRMMU_REF)
3961
3962diff -urNp linux-2.6.32.43/arch/sparc/include/asm/spinlock_64.h linux-2.6.32.43/arch/sparc/include/asm/spinlock_64.h
3963--- linux-2.6.32.43/arch/sparc/include/asm/spinlock_64.h 2011-03-27 14:31:47.000000000 -0400
3964+++ linux-2.6.32.43/arch/sparc/include/asm/spinlock_64.h 2011-05-04 17:56:20.000000000 -0400
3965@@ -92,14 +92,19 @@ static inline void __raw_spin_lock_flags
3966
3967 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3968
3969-static void inline arch_read_lock(raw_rwlock_t *lock)
3970+static inline void arch_read_lock(raw_rwlock_t *lock)
3971 {
3972 unsigned long tmp1, tmp2;
3973
3974 __asm__ __volatile__ (
3975 "1: ldsw [%2], %0\n"
3976 " brlz,pn %0, 2f\n"
3977-"4: add %0, 1, %1\n"
3978+"4: addcc %0, 1, %1\n"
3979+
3980+#ifdef CONFIG_PAX_REFCOUNT
3981+" tvs %%icc, 6\n"
3982+#endif
3983+
3984 " cas [%2], %0, %1\n"
3985 " cmp %0, %1\n"
3986 " bne,pn %%icc, 1b\n"
3987@@ -112,7 +117,7 @@ static void inline arch_read_lock(raw_rw
3988 " .previous"
3989 : "=&r" (tmp1), "=&r" (tmp2)
3990 : "r" (lock)
3991- : "memory");
3992+ : "memory", "cc");
3993 }
3994
3995 static int inline arch_read_trylock(raw_rwlock_t *lock)
3996@@ -123,7 +128,12 @@ static int inline arch_read_trylock(raw_
3997 "1: ldsw [%2], %0\n"
3998 " brlz,a,pn %0, 2f\n"
3999 " mov 0, %0\n"
4000-" add %0, 1, %1\n"
4001+" addcc %0, 1, %1\n"
4002+
4003+#ifdef CONFIG_PAX_REFCOUNT
4004+" tvs %%icc, 6\n"
4005+#endif
4006+
4007 " cas [%2], %0, %1\n"
4008 " cmp %0, %1\n"
4009 " bne,pn %%icc, 1b\n"
4010@@ -136,13 +146,18 @@ static int inline arch_read_trylock(raw_
4011 return tmp1;
4012 }
4013
4014-static void inline arch_read_unlock(raw_rwlock_t *lock)
4015+static inline void arch_read_unlock(raw_rwlock_t *lock)
4016 {
4017 unsigned long tmp1, tmp2;
4018
4019 __asm__ __volatile__(
4020 "1: lduw [%2], %0\n"
4021-" sub %0, 1, %1\n"
4022+" subcc %0, 1, %1\n"
4023+
4024+#ifdef CONFIG_PAX_REFCOUNT
4025+" tvs %%icc, 6\n"
4026+#endif
4027+
4028 " cas [%2], %0, %1\n"
4029 " cmp %0, %1\n"
4030 " bne,pn %%xcc, 1b\n"
4031@@ -152,7 +167,7 @@ static void inline arch_read_unlock(raw_
4032 : "memory");
4033 }
4034
4035-static void inline arch_write_lock(raw_rwlock_t *lock)
4036+static inline void arch_write_lock(raw_rwlock_t *lock)
4037 {
4038 unsigned long mask, tmp1, tmp2;
4039
4040@@ -177,7 +192,7 @@ static void inline arch_write_lock(raw_r
4041 : "memory");
4042 }
4043
4044-static void inline arch_write_unlock(raw_rwlock_t *lock)
4045+static inline void arch_write_unlock(raw_rwlock_t *lock)
4046 {
4047 __asm__ __volatile__(
4048 " stw %%g0, [%0]"
4049diff -urNp linux-2.6.32.43/arch/sparc/include/asm/thread_info_32.h linux-2.6.32.43/arch/sparc/include/asm/thread_info_32.h
4050--- linux-2.6.32.43/arch/sparc/include/asm/thread_info_32.h 2011-03-27 14:31:47.000000000 -0400
4051+++ linux-2.6.32.43/arch/sparc/include/asm/thread_info_32.h 2011-06-04 20:46:01.000000000 -0400
4052@@ -50,6 +50,8 @@ struct thread_info {
4053 unsigned long w_saved;
4054
4055 struct restart_block restart_block;
4056+
4057+ unsigned long lowest_stack;
4058 };
4059
4060 /*
4061diff -urNp linux-2.6.32.43/arch/sparc/include/asm/thread_info_64.h linux-2.6.32.43/arch/sparc/include/asm/thread_info_64.h
4062--- linux-2.6.32.43/arch/sparc/include/asm/thread_info_64.h 2011-03-27 14:31:47.000000000 -0400
4063+++ linux-2.6.32.43/arch/sparc/include/asm/thread_info_64.h 2011-06-04 20:46:21.000000000 -0400
4064@@ -68,6 +68,8 @@ struct thread_info {
4065 struct pt_regs *kern_una_regs;
4066 unsigned int kern_una_insn;
4067
4068+ unsigned long lowest_stack;
4069+
4070 unsigned long fpregs[0] __attribute__ ((aligned(64)));
4071 };
4072
4073diff -urNp linux-2.6.32.43/arch/sparc/include/asm/uaccess_32.h linux-2.6.32.43/arch/sparc/include/asm/uaccess_32.h
4074--- linux-2.6.32.43/arch/sparc/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
4075+++ linux-2.6.32.43/arch/sparc/include/asm/uaccess_32.h 2011-04-17 15:56:46.000000000 -0400
4076@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
4077
4078 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4079 {
4080- if (n && __access_ok((unsigned long) to, n))
4081+ if ((long)n < 0)
4082+ return n;
4083+
4084+ if (n && __access_ok((unsigned long) to, n)) {
4085+ if (!__builtin_constant_p(n))
4086+ check_object_size(from, n, true);
4087 return __copy_user(to, (__force void __user *) from, n);
4088- else
4089+ } else
4090 return n;
4091 }
4092
4093 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4094 {
4095+ if ((long)n < 0)
4096+ return n;
4097+
4098+ if (!__builtin_constant_p(n))
4099+ check_object_size(from, n, true);
4100+
4101 return __copy_user(to, (__force void __user *) from, n);
4102 }
4103
4104 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4105 {
4106- if (n && __access_ok((unsigned long) from, n))
4107+ if ((long)n < 0)
4108+ return n;
4109+
4110+ if (n && __access_ok((unsigned long) from, n)) {
4111+ if (!__builtin_constant_p(n))
4112+ check_object_size(to, n, false);
4113 return __copy_user((__force void __user *) to, from, n);
4114- else
4115+ } else
4116 return n;
4117 }
4118
4119 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4120 {
4121+ if ((long)n < 0)
4122+ return n;
4123+
4124 return __copy_user((__force void __user *) to, from, n);
4125 }
4126
4127diff -urNp linux-2.6.32.43/arch/sparc/include/asm/uaccess_64.h linux-2.6.32.43/arch/sparc/include/asm/uaccess_64.h
4128--- linux-2.6.32.43/arch/sparc/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
4129+++ linux-2.6.32.43/arch/sparc/include/asm/uaccess_64.h 2011-04-17 15:56:46.000000000 -0400
4130@@ -9,6 +9,7 @@
4131 #include <linux/compiler.h>
4132 #include <linux/string.h>
4133 #include <linux/thread_info.h>
4134+#include <linux/kernel.h>
4135 #include <asm/asi.h>
4136 #include <asm/system.h>
4137 #include <asm/spitfire.h>
4138@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixu
4139 static inline unsigned long __must_check
4140 copy_from_user(void *to, const void __user *from, unsigned long size)
4141 {
4142- unsigned long ret = ___copy_from_user(to, from, size);
4143+ unsigned long ret;
4144
4145+ if ((long)size < 0 || size > INT_MAX)
4146+ return size;
4147+
4148+ if (!__builtin_constant_p(size))
4149+ check_object_size(to, size, false);
4150+
4151+ ret = ___copy_from_user(to, from, size);
4152 if (unlikely(ret))
4153 ret = copy_from_user_fixup(to, from, size);
4154 return ret;
4155@@ -228,8 +236,15 @@ extern unsigned long copy_to_user_fixup(
4156 static inline unsigned long __must_check
4157 copy_to_user(void __user *to, const void *from, unsigned long size)
4158 {
4159- unsigned long ret = ___copy_to_user(to, from, size);
4160+ unsigned long ret;
4161+
4162+ if ((long)size < 0 || size > INT_MAX)
4163+ return size;
4164+
4165+ if (!__builtin_constant_p(size))
4166+ check_object_size(from, size, true);
4167
4168+ ret = ___copy_to_user(to, from, size);
4169 if (unlikely(ret))
4170 ret = copy_to_user_fixup(to, from, size);
4171 return ret;
4172diff -urNp linux-2.6.32.43/arch/sparc/include/asm/uaccess.h linux-2.6.32.43/arch/sparc/include/asm/uaccess.h
4173--- linux-2.6.32.43/arch/sparc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
4174+++ linux-2.6.32.43/arch/sparc/include/asm/uaccess.h 2011-04-17 15:56:46.000000000 -0400
4175@@ -1,5 +1,13 @@
4176 #ifndef ___ASM_SPARC_UACCESS_H
4177 #define ___ASM_SPARC_UACCESS_H
4178+
4179+#ifdef __KERNEL__
4180+#ifndef __ASSEMBLY__
4181+#include <linux/types.h>
4182+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4183+#endif
4184+#endif
4185+
4186 #if defined(__sparc__) && defined(__arch64__)
4187 #include <asm/uaccess_64.h>
4188 #else
4189diff -urNp linux-2.6.32.43/arch/sparc/kernel/iommu.c linux-2.6.32.43/arch/sparc/kernel/iommu.c
4190--- linux-2.6.32.43/arch/sparc/kernel/iommu.c 2011-03-27 14:31:47.000000000 -0400
4191+++ linux-2.6.32.43/arch/sparc/kernel/iommu.c 2011-04-17 15:56:46.000000000 -0400
4192@@ -826,7 +826,7 @@ static void dma_4u_sync_sg_for_cpu(struc
4193 spin_unlock_irqrestore(&iommu->lock, flags);
4194 }
4195
4196-static struct dma_map_ops sun4u_dma_ops = {
4197+static const struct dma_map_ops sun4u_dma_ops = {
4198 .alloc_coherent = dma_4u_alloc_coherent,
4199 .free_coherent = dma_4u_free_coherent,
4200 .map_page = dma_4u_map_page,
4201@@ -837,7 +837,7 @@ static struct dma_map_ops sun4u_dma_ops
4202 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
4203 };
4204
4205-struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4206+const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4207 EXPORT_SYMBOL(dma_ops);
4208
4209 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
4210diff -urNp linux-2.6.32.43/arch/sparc/kernel/ioport.c linux-2.6.32.43/arch/sparc/kernel/ioport.c
4211--- linux-2.6.32.43/arch/sparc/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
4212+++ linux-2.6.32.43/arch/sparc/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
4213@@ -392,7 +392,7 @@ static void sbus_sync_sg_for_device(stru
4214 BUG();
4215 }
4216
4217-struct dma_map_ops sbus_dma_ops = {
4218+const struct dma_map_ops sbus_dma_ops = {
4219 .alloc_coherent = sbus_alloc_coherent,
4220 .free_coherent = sbus_free_coherent,
4221 .map_page = sbus_map_page,
4222@@ -403,7 +403,7 @@ struct dma_map_ops sbus_dma_ops = {
4223 .sync_sg_for_device = sbus_sync_sg_for_device,
4224 };
4225
4226-struct dma_map_ops *dma_ops = &sbus_dma_ops;
4227+const struct dma_map_ops *dma_ops = &sbus_dma_ops;
4228 EXPORT_SYMBOL(dma_ops);
4229
4230 static int __init sparc_register_ioport(void)
4231@@ -640,7 +640,7 @@ static void pci32_sync_sg_for_device(str
4232 }
4233 }
4234
4235-struct dma_map_ops pci32_dma_ops = {
4236+const struct dma_map_ops pci32_dma_ops = {
4237 .alloc_coherent = pci32_alloc_coherent,
4238 .free_coherent = pci32_free_coherent,
4239 .map_page = pci32_map_page,
4240diff -urNp linux-2.6.32.43/arch/sparc/kernel/kgdb_32.c linux-2.6.32.43/arch/sparc/kernel/kgdb_32.c
4241--- linux-2.6.32.43/arch/sparc/kernel/kgdb_32.c 2011-03-27 14:31:47.000000000 -0400
4242+++ linux-2.6.32.43/arch/sparc/kernel/kgdb_32.c 2011-04-17 15:56:46.000000000 -0400
4243@@ -158,7 +158,7 @@ void kgdb_arch_exit(void)
4244 {
4245 }
4246
4247-struct kgdb_arch arch_kgdb_ops = {
4248+const struct kgdb_arch arch_kgdb_ops = {
4249 /* Breakpoint instruction: ta 0x7d */
4250 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
4251 };
4252diff -urNp linux-2.6.32.43/arch/sparc/kernel/kgdb_64.c linux-2.6.32.43/arch/sparc/kernel/kgdb_64.c
4253--- linux-2.6.32.43/arch/sparc/kernel/kgdb_64.c 2011-03-27 14:31:47.000000000 -0400
4254+++ linux-2.6.32.43/arch/sparc/kernel/kgdb_64.c 2011-04-17 15:56:46.000000000 -0400
4255@@ -180,7 +180,7 @@ void kgdb_arch_exit(void)
4256 {
4257 }
4258
4259-struct kgdb_arch arch_kgdb_ops = {
4260+const struct kgdb_arch arch_kgdb_ops = {
4261 /* Breakpoint instruction: ta 0x72 */
4262 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
4263 };
4264diff -urNp linux-2.6.32.43/arch/sparc/kernel/Makefile linux-2.6.32.43/arch/sparc/kernel/Makefile
4265--- linux-2.6.32.43/arch/sparc/kernel/Makefile 2011-03-27 14:31:47.000000000 -0400
4266+++ linux-2.6.32.43/arch/sparc/kernel/Makefile 2011-04-17 15:56:46.000000000 -0400
4267@@ -3,7 +3,7 @@
4268 #
4269
4270 asflags-y := -ansi
4271-ccflags-y := -Werror
4272+#ccflags-y := -Werror
4273
4274 extra-y := head_$(BITS).o
4275 extra-y += init_task.o
4276diff -urNp linux-2.6.32.43/arch/sparc/kernel/pci_sun4v.c linux-2.6.32.43/arch/sparc/kernel/pci_sun4v.c
4277--- linux-2.6.32.43/arch/sparc/kernel/pci_sun4v.c 2011-03-27 14:31:47.000000000 -0400
4278+++ linux-2.6.32.43/arch/sparc/kernel/pci_sun4v.c 2011-04-17 15:56:46.000000000 -0400
4279@@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
4280 spin_unlock_irqrestore(&iommu->lock, flags);
4281 }
4282
4283-static struct dma_map_ops sun4v_dma_ops = {
4284+static const struct dma_map_ops sun4v_dma_ops = {
4285 .alloc_coherent = dma_4v_alloc_coherent,
4286 .free_coherent = dma_4v_free_coherent,
4287 .map_page = dma_4v_map_page,
4288diff -urNp linux-2.6.32.43/arch/sparc/kernel/process_32.c linux-2.6.32.43/arch/sparc/kernel/process_32.c
4289--- linux-2.6.32.43/arch/sparc/kernel/process_32.c 2011-03-27 14:31:47.000000000 -0400
4290+++ linux-2.6.32.43/arch/sparc/kernel/process_32.c 2011-04-17 15:56:46.000000000 -0400
4291@@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4292 rw->ins[4], rw->ins[5],
4293 rw->ins[6],
4294 rw->ins[7]);
4295- printk("%pS\n", (void *) rw->ins[7]);
4296+ printk("%pA\n", (void *) rw->ins[7]);
4297 rw = (struct reg_window32 *) rw->ins[6];
4298 }
4299 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4300@@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4301
4302 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4303 r->psr, r->pc, r->npc, r->y, print_tainted());
4304- printk("PC: <%pS>\n", (void *) r->pc);
4305+ printk("PC: <%pA>\n", (void *) r->pc);
4306 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4307 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4308 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4309 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4310 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4311 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4312- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4313+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4314
4315 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4316 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4317@@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
4318 rw = (struct reg_window32 *) fp;
4319 pc = rw->ins[7];
4320 printk("[%08lx : ", pc);
4321- printk("%pS ] ", (void *) pc);
4322+ printk("%pA ] ", (void *) pc);
4323 fp = rw->ins[6];
4324 } while (++count < 16);
4325 printk("\n");
4326diff -urNp linux-2.6.32.43/arch/sparc/kernel/process_64.c linux-2.6.32.43/arch/sparc/kernel/process_64.c
4327--- linux-2.6.32.43/arch/sparc/kernel/process_64.c 2011-03-27 14:31:47.000000000 -0400
4328+++ linux-2.6.32.43/arch/sparc/kernel/process_64.c 2011-04-17 15:56:46.000000000 -0400
4329@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
4330 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4331 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4332 if (regs->tstate & TSTATE_PRIV)
4333- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4334+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4335 }
4336
4337 void show_regs(struct pt_regs *regs)
4338 {
4339 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4340 regs->tpc, regs->tnpc, regs->y, print_tainted());
4341- printk("TPC: <%pS>\n", (void *) regs->tpc);
4342+ printk("TPC: <%pA>\n", (void *) regs->tpc);
4343 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4344 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4345 regs->u_regs[3]);
4346@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4347 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4348 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4349 regs->u_regs[15]);
4350- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4351+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4352 show_regwindow(regs);
4353 }
4354
4355@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void
4356 ((tp && tp->task) ? tp->task->pid : -1));
4357
4358 if (gp->tstate & TSTATE_PRIV) {
4359- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4360+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4361 (void *) gp->tpc,
4362 (void *) gp->o7,
4363 (void *) gp->i7,
4364diff -urNp linux-2.6.32.43/arch/sparc/kernel/sys_sparc_32.c linux-2.6.32.43/arch/sparc/kernel/sys_sparc_32.c
4365--- linux-2.6.32.43/arch/sparc/kernel/sys_sparc_32.c 2011-03-27 14:31:47.000000000 -0400
4366+++ linux-2.6.32.43/arch/sparc/kernel/sys_sparc_32.c 2011-04-17 15:56:46.000000000 -0400
4367@@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(str
4368 if (ARCH_SUN4C && len > 0x20000000)
4369 return -ENOMEM;
4370 if (!addr)
4371- addr = TASK_UNMAPPED_BASE;
4372+ addr = current->mm->mmap_base;
4373
4374 if (flags & MAP_SHARED)
4375 addr = COLOUR_ALIGN(addr);
4376@@ -72,7 +72,7 @@ unsigned long arch_get_unmapped_area(str
4377 }
4378 if (TASK_SIZE - PAGE_SIZE - len < addr)
4379 return -ENOMEM;
4380- if (!vmm || addr + len <= vmm->vm_start)
4381+ if (check_heap_stack_gap(vmm, addr, len))
4382 return addr;
4383 addr = vmm->vm_end;
4384 if (flags & MAP_SHARED)
4385diff -urNp linux-2.6.32.43/arch/sparc/kernel/sys_sparc_64.c linux-2.6.32.43/arch/sparc/kernel/sys_sparc_64.c
4386--- linux-2.6.32.43/arch/sparc/kernel/sys_sparc_64.c 2011-03-27 14:31:47.000000000 -0400
4387+++ linux-2.6.32.43/arch/sparc/kernel/sys_sparc_64.c 2011-04-17 15:56:46.000000000 -0400
4388@@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(str
4389 /* We do not accept a shared mapping if it would violate
4390 * cache aliasing constraints.
4391 */
4392- if ((flags & MAP_SHARED) &&
4393+ if ((filp || (flags & MAP_SHARED)) &&
4394 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4395 return -EINVAL;
4396 return addr;
4397@@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(str
4398 if (filp || (flags & MAP_SHARED))
4399 do_color_align = 1;
4400
4401+#ifdef CONFIG_PAX_RANDMMAP
4402+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4403+#endif
4404+
4405 if (addr) {
4406 if (do_color_align)
4407 addr = COLOUR_ALIGN(addr, pgoff);
4408@@ -147,15 +151,14 @@ unsigned long arch_get_unmapped_area(str
4409 addr = PAGE_ALIGN(addr);
4410
4411 vma = find_vma(mm, addr);
4412- if (task_size - len >= addr &&
4413- (!vma || addr + len <= vma->vm_start))
4414+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4415 return addr;
4416 }
4417
4418 if (len > mm->cached_hole_size) {
4419- start_addr = addr = mm->free_area_cache;
4420+ start_addr = addr = mm->free_area_cache;
4421 } else {
4422- start_addr = addr = TASK_UNMAPPED_BASE;
4423+ start_addr = addr = mm->mmap_base;
4424 mm->cached_hole_size = 0;
4425 }
4426
4427@@ -175,14 +178,14 @@ full_search:
4428 vma = find_vma(mm, VA_EXCLUDE_END);
4429 }
4430 if (unlikely(task_size < addr)) {
4431- if (start_addr != TASK_UNMAPPED_BASE) {
4432- start_addr = addr = TASK_UNMAPPED_BASE;
4433+ if (start_addr != mm->mmap_base) {
4434+ start_addr = addr = mm->mmap_base;
4435 mm->cached_hole_size = 0;
4436 goto full_search;
4437 }
4438 return -ENOMEM;
4439 }
4440- if (likely(!vma || addr + len <= vma->vm_start)) {
4441+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4442 /*
4443 * Remember the place where we stopped the search:
4444 */
4445@@ -216,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
4446 /* We do not accept a shared mapping if it would violate
4447 * cache aliasing constraints.
4448 */
4449- if ((flags & MAP_SHARED) &&
4450+ if ((filp || (flags & MAP_SHARED)) &&
4451 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4452 return -EINVAL;
4453 return addr;
4454@@ -237,8 +240,7 @@ arch_get_unmapped_area_topdown(struct fi
4455 addr = PAGE_ALIGN(addr);
4456
4457 vma = find_vma(mm, addr);
4458- if (task_size - len >= addr &&
4459- (!vma || addr + len <= vma->vm_start))
4460+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4461 return addr;
4462 }
4463
4464@@ -259,7 +261,7 @@ arch_get_unmapped_area_topdown(struct fi
4465 /* make sure it can fit in the remaining address space */
4466 if (likely(addr > len)) {
4467 vma = find_vma(mm, addr-len);
4468- if (!vma || addr <= vma->vm_start) {
4469+ if (check_heap_stack_gap(vma, addr - len, len)) {
4470 /* remember the address as a hint for next time */
4471 return (mm->free_area_cache = addr-len);
4472 }
4473@@ -268,18 +270,18 @@ arch_get_unmapped_area_topdown(struct fi
4474 if (unlikely(mm->mmap_base < len))
4475 goto bottomup;
4476
4477- addr = mm->mmap_base-len;
4478- if (do_color_align)
4479- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4480+ addr = mm->mmap_base - len;
4481
4482 do {
4483+ if (do_color_align)
4484+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4485 /*
4486 * Lookup failure means no vma is above this address,
4487 * else if new region fits below vma->vm_start,
4488 * return with success:
4489 */
4490 vma = find_vma(mm, addr);
4491- if (likely(!vma || addr+len <= vma->vm_start)) {
4492+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4493 /* remember the address as a hint for next time */
4494 return (mm->free_area_cache = addr);
4495 }
4496@@ -289,10 +291,8 @@ arch_get_unmapped_area_topdown(struct fi
4497 mm->cached_hole_size = vma->vm_start - addr;
4498
4499 /* try just below the current vma->vm_start */
4500- addr = vma->vm_start-len;
4501- if (do_color_align)
4502- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4503- } while (likely(len < vma->vm_start));
4504+ addr = skip_heap_stack_gap(vma, len);
4505+ } while (!IS_ERR_VALUE(addr));
4506
4507 bottomup:
4508 /*
4509@@ -384,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_str
4510 current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
4511 sysctl_legacy_va_layout) {
4512 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4513+
4514+#ifdef CONFIG_PAX_RANDMMAP
4515+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4516+ mm->mmap_base += mm->delta_mmap;
4517+#endif
4518+
4519 mm->get_unmapped_area = arch_get_unmapped_area;
4520 mm->unmap_area = arch_unmap_area;
4521 } else {
4522@@ -398,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_str
4523 gap = (task_size / 6 * 5);
4524
4525 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4526+
4527+#ifdef CONFIG_PAX_RANDMMAP
4528+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4529+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4530+#endif
4531+
4532 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4533 mm->unmap_area = arch_unmap_area_topdown;
4534 }
4535diff -urNp linux-2.6.32.43/arch/sparc/kernel/traps_32.c linux-2.6.32.43/arch/sparc/kernel/traps_32.c
4536--- linux-2.6.32.43/arch/sparc/kernel/traps_32.c 2011-03-27 14:31:47.000000000 -0400
4537+++ linux-2.6.32.43/arch/sparc/kernel/traps_32.c 2011-06-13 21:25:39.000000000 -0400
4538@@ -44,6 +44,8 @@ static void instruction_dump(unsigned lo
4539 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
4540 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
4541
4542+extern void gr_handle_kernel_exploit(void);
4543+
4544 void die_if_kernel(char *str, struct pt_regs *regs)
4545 {
4546 static int die_counter;
4547@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_
4548 count++ < 30 &&
4549 (((unsigned long) rw) >= PAGE_OFFSET) &&
4550 !(((unsigned long) rw) & 0x7)) {
4551- printk("Caller[%08lx]: %pS\n", rw->ins[7],
4552+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
4553 (void *) rw->ins[7]);
4554 rw = (struct reg_window32 *)rw->ins[6];
4555 }
4556 }
4557 printk("Instruction DUMP:");
4558 instruction_dump ((unsigned long *) regs->pc);
4559- if(regs->psr & PSR_PS)
4560+ if(regs->psr & PSR_PS) {
4561+ gr_handle_kernel_exploit();
4562 do_exit(SIGKILL);
4563+ }
4564 do_exit(SIGSEGV);
4565 }
4566
4567diff -urNp linux-2.6.32.43/arch/sparc/kernel/traps_64.c linux-2.6.32.43/arch/sparc/kernel/traps_64.c
4568--- linux-2.6.32.43/arch/sparc/kernel/traps_64.c 2011-03-27 14:31:47.000000000 -0400
4569+++ linux-2.6.32.43/arch/sparc/kernel/traps_64.c 2011-06-13 21:24:11.000000000 -0400
4570@@ -73,7 +73,7 @@ static void dump_tl1_traplog(struct tl1_
4571 i + 1,
4572 p->trapstack[i].tstate, p->trapstack[i].tpc,
4573 p->trapstack[i].tnpc, p->trapstack[i].tt);
4574- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4575+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4576 }
4577 }
4578
4579@@ -93,6 +93,12 @@ void bad_trap(struct pt_regs *regs, long
4580
4581 lvl -= 0x100;
4582 if (regs->tstate & TSTATE_PRIV) {
4583+
4584+#ifdef CONFIG_PAX_REFCOUNT
4585+ if (lvl == 6)
4586+ pax_report_refcount_overflow(regs);
4587+#endif
4588+
4589 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4590 die_if_kernel(buffer, regs);
4591 }
4592@@ -111,11 +117,16 @@ void bad_trap(struct pt_regs *regs, long
4593 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4594 {
4595 char buffer[32];
4596-
4597+
4598 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4599 0, lvl, SIGTRAP) == NOTIFY_STOP)
4600 return;
4601
4602+#ifdef CONFIG_PAX_REFCOUNT
4603+ if (lvl == 6)
4604+ pax_report_refcount_overflow(regs);
4605+#endif
4606+
4607 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4608
4609 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4610@@ -1139,7 +1150,7 @@ static void cheetah_log_errors(struct pt
4611 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4612 printk("%s" "ERROR(%d): ",
4613 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4614- printk("TPC<%pS>\n", (void *) regs->tpc);
4615+ printk("TPC<%pA>\n", (void *) regs->tpc);
4616 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4617 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4618 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4619@@ -1746,7 +1757,7 @@ void cheetah_plus_parity_error(int type,
4620 smp_processor_id(),
4621 (type & 0x1) ? 'I' : 'D',
4622 regs->tpc);
4623- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4624+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4625 panic("Irrecoverable Cheetah+ parity error.");
4626 }
4627
4628@@ -1754,7 +1765,7 @@ void cheetah_plus_parity_error(int type,
4629 smp_processor_id(),
4630 (type & 0x1) ? 'I' : 'D',
4631 regs->tpc);
4632- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4633+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4634 }
4635
4636 struct sun4v_error_entry {
4637@@ -1961,9 +1972,9 @@ void sun4v_itlb_error_report(struct pt_r
4638
4639 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4640 regs->tpc, tl);
4641- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4642+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4643 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4644- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4645+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4646 (void *) regs->u_regs[UREG_I7]);
4647 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4648 "pte[%lx] error[%lx]\n",
4649@@ -1985,9 +1996,9 @@ void sun4v_dtlb_error_report(struct pt_r
4650
4651 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4652 regs->tpc, tl);
4653- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4654+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4655 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4656- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4657+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4658 (void *) regs->u_regs[UREG_I7]);
4659 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4660 "pte[%lx] error[%lx]\n",
4661@@ -2191,7 +2202,7 @@ void show_stack(struct task_struct *tsk,
4662 fp = (unsigned long)sf->fp + STACK_BIAS;
4663 }
4664
4665- printk(" [%016lx] %pS\n", pc, (void *) pc);
4666+ printk(" [%016lx] %pA\n", pc, (void *) pc);
4667 } while (++count < 16);
4668 }
4669
4670@@ -2233,6 +2244,8 @@ static inline struct reg_window *kernel_
4671 return (struct reg_window *) (fp + STACK_BIAS);
4672 }
4673
4674+extern void gr_handle_kernel_exploit(void);
4675+
4676 void die_if_kernel(char *str, struct pt_regs *regs)
4677 {
4678 static int die_counter;
4679@@ -2260,7 +2273,7 @@ void die_if_kernel(char *str, struct pt_
4680 while (rw &&
4681 count++ < 30&&
4682 is_kernel_stack(current, rw)) {
4683- printk("Caller[%016lx]: %pS\n", rw->ins[7],
4684+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
4685 (void *) rw->ins[7]);
4686
4687 rw = kernel_stack_up(rw);
4688@@ -2273,8 +2286,11 @@ void die_if_kernel(char *str, struct pt_
4689 }
4690 user_instruction_dump ((unsigned int __user *) regs->tpc);
4691 }
4692- if (regs->tstate & TSTATE_PRIV)
4693+ if (regs->tstate & TSTATE_PRIV) {
4694+ gr_handle_kernel_exploit();
4695 do_exit(SIGKILL);
4696+ }
4697+
4698 do_exit(SIGSEGV);
4699 }
4700 EXPORT_SYMBOL(die_if_kernel);
4701diff -urNp linux-2.6.32.43/arch/sparc/kernel/una_asm_64.S linux-2.6.32.43/arch/sparc/kernel/una_asm_64.S
4702--- linux-2.6.32.43/arch/sparc/kernel/una_asm_64.S 2011-03-27 14:31:47.000000000 -0400
4703+++ linux-2.6.32.43/arch/sparc/kernel/una_asm_64.S 2011-07-13 22:20:05.000000000 -0400
4704@@ -127,7 +127,7 @@ do_int_load:
4705 wr %o5, 0x0, %asi
4706 retl
4707 mov 0, %o0
4708- .size __do_int_load, .-__do_int_load
4709+ .size do_int_load, .-do_int_load
4710
4711 .section __ex_table,"a"
4712 .word 4b, __retl_efault
4713diff -urNp linux-2.6.32.43/arch/sparc/kernel/unaligned_64.c linux-2.6.32.43/arch/sparc/kernel/unaligned_64.c
4714--- linux-2.6.32.43/arch/sparc/kernel/unaligned_64.c 2011-03-27 14:31:47.000000000 -0400
4715+++ linux-2.6.32.43/arch/sparc/kernel/unaligned_64.c 2011-04-17 15:56:46.000000000 -0400
4716@@ -288,7 +288,7 @@ static void log_unaligned(struct pt_regs
4717 if (count < 5) {
4718 last_time = jiffies;
4719 count++;
4720- printk("Kernel unaligned access at TPC[%lx] %pS\n",
4721+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
4722 regs->tpc, (void *) regs->tpc);
4723 }
4724 }
4725diff -urNp linux-2.6.32.43/arch/sparc/lib/atomic_64.S linux-2.6.32.43/arch/sparc/lib/atomic_64.S
4726--- linux-2.6.32.43/arch/sparc/lib/atomic_64.S 2011-03-27 14:31:47.000000000 -0400
4727+++ linux-2.6.32.43/arch/sparc/lib/atomic_64.S 2011-04-17 15:56:46.000000000 -0400
4728@@ -18,7 +18,12 @@
4729 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4730 BACKOFF_SETUP(%o2)
4731 1: lduw [%o1], %g1
4732- add %g1, %o0, %g7
4733+ addcc %g1, %o0, %g7
4734+
4735+#ifdef CONFIG_PAX_REFCOUNT
4736+ tvs %icc, 6
4737+#endif
4738+
4739 cas [%o1], %g1, %g7
4740 cmp %g1, %g7
4741 bne,pn %icc, 2f
4742@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
4743 2: BACKOFF_SPIN(%o2, %o3, 1b)
4744 .size atomic_add, .-atomic_add
4745
4746+ .globl atomic_add_unchecked
4747+ .type atomic_add_unchecked,#function
4748+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4749+ BACKOFF_SETUP(%o2)
4750+1: lduw [%o1], %g1
4751+ add %g1, %o0, %g7
4752+ cas [%o1], %g1, %g7
4753+ cmp %g1, %g7
4754+ bne,pn %icc, 2f
4755+ nop
4756+ retl
4757+ nop
4758+2: BACKOFF_SPIN(%o2, %o3, 1b)
4759+ .size atomic_add_unchecked, .-atomic_add_unchecked
4760+
4761 .globl atomic_sub
4762 .type atomic_sub,#function
4763 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4764 BACKOFF_SETUP(%o2)
4765 1: lduw [%o1], %g1
4766- sub %g1, %o0, %g7
4767+ subcc %g1, %o0, %g7
4768+
4769+#ifdef CONFIG_PAX_REFCOUNT
4770+ tvs %icc, 6
4771+#endif
4772+
4773 cas [%o1], %g1, %g7
4774 cmp %g1, %g7
4775 bne,pn %icc, 2f
4776@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
4777 2: BACKOFF_SPIN(%o2, %o3, 1b)
4778 .size atomic_sub, .-atomic_sub
4779
4780+ .globl atomic_sub_unchecked
4781+ .type atomic_sub_unchecked,#function
4782+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4783+ BACKOFF_SETUP(%o2)
4784+1: lduw [%o1], %g1
4785+ sub %g1, %o0, %g7
4786+ cas [%o1], %g1, %g7
4787+ cmp %g1, %g7
4788+ bne,pn %icc, 2f
4789+ nop
4790+ retl
4791+ nop
4792+2: BACKOFF_SPIN(%o2, %o3, 1b)
4793+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
4794+
4795 .globl atomic_add_ret
4796 .type atomic_add_ret,#function
4797 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4798 BACKOFF_SETUP(%o2)
4799 1: lduw [%o1], %g1
4800- add %g1, %o0, %g7
4801+ addcc %g1, %o0, %g7
4802+
4803+#ifdef CONFIG_PAX_REFCOUNT
4804+ tvs %icc, 6
4805+#endif
4806+
4807 cas [%o1], %g1, %g7
4808 cmp %g1, %g7
4809 bne,pn %icc, 2f
4810@@ -59,12 +104,33 @@ atomic_add_ret: /* %o0 = increment, %o1
4811 2: BACKOFF_SPIN(%o2, %o3, 1b)
4812 .size atomic_add_ret, .-atomic_add_ret
4813
4814+ .globl atomic_add_ret_unchecked
4815+ .type atomic_add_ret_unchecked,#function
4816+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4817+ BACKOFF_SETUP(%o2)
4818+1: lduw [%o1], %g1
4819+ addcc %g1, %o0, %g7
4820+ cas [%o1], %g1, %g7
4821+ cmp %g1, %g7
4822+ bne,pn %icc, 2f
4823+ add %g7, %o0, %g7
4824+ sra %g7, 0, %o0
4825+ retl
4826+ nop
4827+2: BACKOFF_SPIN(%o2, %o3, 1b)
4828+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4829+
4830 .globl atomic_sub_ret
4831 .type atomic_sub_ret,#function
4832 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4833 BACKOFF_SETUP(%o2)
4834 1: lduw [%o1], %g1
4835- sub %g1, %o0, %g7
4836+ subcc %g1, %o0, %g7
4837+
4838+#ifdef CONFIG_PAX_REFCOUNT
4839+ tvs %icc, 6
4840+#endif
4841+
4842 cas [%o1], %g1, %g7
4843 cmp %g1, %g7
4844 bne,pn %icc, 2f
4845@@ -80,7 +146,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
4846 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4847 BACKOFF_SETUP(%o2)
4848 1: ldx [%o1], %g1
4849- add %g1, %o0, %g7
4850+ addcc %g1, %o0, %g7
4851+
4852+#ifdef CONFIG_PAX_REFCOUNT
4853+ tvs %xcc, 6
4854+#endif
4855+
4856 casx [%o1], %g1, %g7
4857 cmp %g1, %g7
4858 bne,pn %xcc, 2f
4859@@ -90,12 +161,32 @@ atomic64_add: /* %o0 = increment, %o1 =
4860 2: BACKOFF_SPIN(%o2, %o3, 1b)
4861 .size atomic64_add, .-atomic64_add
4862
4863+ .globl atomic64_add_unchecked
4864+ .type atomic64_add_unchecked,#function
4865+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4866+ BACKOFF_SETUP(%o2)
4867+1: ldx [%o1], %g1
4868+ addcc %g1, %o0, %g7
4869+ casx [%o1], %g1, %g7
4870+ cmp %g1, %g7
4871+ bne,pn %xcc, 2f
4872+ nop
4873+ retl
4874+ nop
4875+2: BACKOFF_SPIN(%o2, %o3, 1b)
4876+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
4877+
4878 .globl atomic64_sub
4879 .type atomic64_sub,#function
4880 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4881 BACKOFF_SETUP(%o2)
4882 1: ldx [%o1], %g1
4883- sub %g1, %o0, %g7
4884+ subcc %g1, %o0, %g7
4885+
4886+#ifdef CONFIG_PAX_REFCOUNT
4887+ tvs %xcc, 6
4888+#endif
4889+
4890 casx [%o1], %g1, %g7
4891 cmp %g1, %g7
4892 bne,pn %xcc, 2f
4893@@ -105,12 +196,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
4894 2: BACKOFF_SPIN(%o2, %o3, 1b)
4895 .size atomic64_sub, .-atomic64_sub
4896
4897+ .globl atomic64_sub_unchecked
4898+ .type atomic64_sub_unchecked,#function
4899+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4900+ BACKOFF_SETUP(%o2)
4901+1: ldx [%o1], %g1
4902+ subcc %g1, %o0, %g7
4903+ casx [%o1], %g1, %g7
4904+ cmp %g1, %g7
4905+ bne,pn %xcc, 2f
4906+ nop
4907+ retl
4908+ nop
4909+2: BACKOFF_SPIN(%o2, %o3, 1b)
4910+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4911+
4912 .globl atomic64_add_ret
4913 .type atomic64_add_ret,#function
4914 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4915 BACKOFF_SETUP(%o2)
4916 1: ldx [%o1], %g1
4917- add %g1, %o0, %g7
4918+ addcc %g1, %o0, %g7
4919+
4920+#ifdef CONFIG_PAX_REFCOUNT
4921+ tvs %xcc, 6
4922+#endif
4923+
4924 casx [%o1], %g1, %g7
4925 cmp %g1, %g7
4926 bne,pn %xcc, 2f
4927@@ -121,12 +232,33 @@ atomic64_add_ret: /* %o0 = increment, %o
4928 2: BACKOFF_SPIN(%o2, %o3, 1b)
4929 .size atomic64_add_ret, .-atomic64_add_ret
4930
4931+ .globl atomic64_add_ret_unchecked
4932+ .type atomic64_add_ret_unchecked,#function
4933+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4934+ BACKOFF_SETUP(%o2)
4935+1: ldx [%o1], %g1
4936+ addcc %g1, %o0, %g7
4937+ casx [%o1], %g1, %g7
4938+ cmp %g1, %g7
4939+ bne,pn %xcc, 2f
4940+ add %g7, %o0, %g7
4941+ mov %g7, %o0
4942+ retl
4943+ nop
4944+2: BACKOFF_SPIN(%o2, %o3, 1b)
4945+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4946+
4947 .globl atomic64_sub_ret
4948 .type atomic64_sub_ret,#function
4949 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4950 BACKOFF_SETUP(%o2)
4951 1: ldx [%o1], %g1
4952- sub %g1, %o0, %g7
4953+ subcc %g1, %o0, %g7
4954+
4955+#ifdef CONFIG_PAX_REFCOUNT
4956+ tvs %xcc, 6
4957+#endif
4958+
4959 casx [%o1], %g1, %g7
4960 cmp %g1, %g7
4961 bne,pn %xcc, 2f
4962diff -urNp linux-2.6.32.43/arch/sparc/lib/ksyms.c linux-2.6.32.43/arch/sparc/lib/ksyms.c
4963--- linux-2.6.32.43/arch/sparc/lib/ksyms.c 2011-03-27 14:31:47.000000000 -0400
4964+++ linux-2.6.32.43/arch/sparc/lib/ksyms.c 2011-04-17 15:56:46.000000000 -0400
4965@@ -144,12 +144,17 @@ EXPORT_SYMBOL(__downgrade_write);
4966
4967 /* Atomic counter implementation. */
4968 EXPORT_SYMBOL(atomic_add);
4969+EXPORT_SYMBOL(atomic_add_unchecked);
4970 EXPORT_SYMBOL(atomic_add_ret);
4971 EXPORT_SYMBOL(atomic_sub);
4972+EXPORT_SYMBOL(atomic_sub_unchecked);
4973 EXPORT_SYMBOL(atomic_sub_ret);
4974 EXPORT_SYMBOL(atomic64_add);
4975+EXPORT_SYMBOL(atomic64_add_unchecked);
4976 EXPORT_SYMBOL(atomic64_add_ret);
4977+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4978 EXPORT_SYMBOL(atomic64_sub);
4979+EXPORT_SYMBOL(atomic64_sub_unchecked);
4980 EXPORT_SYMBOL(atomic64_sub_ret);
4981
4982 /* Atomic bit operations. */
4983diff -urNp linux-2.6.32.43/arch/sparc/lib/Makefile linux-2.6.32.43/arch/sparc/lib/Makefile
4984--- linux-2.6.32.43/arch/sparc/lib/Makefile 2011-03-27 14:31:47.000000000 -0400
4985+++ linux-2.6.32.43/arch/sparc/lib/Makefile 2011-05-17 19:26:34.000000000 -0400
4986@@ -2,7 +2,7 @@
4987 #
4988
4989 asflags-y := -ansi -DST_DIV0=0x02
4990-ccflags-y := -Werror
4991+#ccflags-y := -Werror
4992
4993 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4994 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4995diff -urNp linux-2.6.32.43/arch/sparc/lib/rwsem_64.S linux-2.6.32.43/arch/sparc/lib/rwsem_64.S
4996--- linux-2.6.32.43/arch/sparc/lib/rwsem_64.S 2011-03-27 14:31:47.000000000 -0400
4997+++ linux-2.6.32.43/arch/sparc/lib/rwsem_64.S 2011-04-17 15:56:46.000000000 -0400
4998@@ -11,7 +11,12 @@
4999 .globl __down_read
5000 __down_read:
5001 1: lduw [%o0], %g1
5002- add %g1, 1, %g7
5003+ addcc %g1, 1, %g7
5004+
5005+#ifdef CONFIG_PAX_REFCOUNT
5006+ tvs %icc, 6
5007+#endif
5008+
5009 cas [%o0], %g1, %g7
5010 cmp %g1, %g7
5011 bne,pn %icc, 1b
5012@@ -33,7 +38,12 @@ __down_read:
5013 .globl __down_read_trylock
5014 __down_read_trylock:
5015 1: lduw [%o0], %g1
5016- add %g1, 1, %g7
5017+ addcc %g1, 1, %g7
5018+
5019+#ifdef CONFIG_PAX_REFCOUNT
5020+ tvs %icc, 6
5021+#endif
5022+
5023 cmp %g7, 0
5024 bl,pn %icc, 2f
5025 mov 0, %o1
5026@@ -51,7 +61,12 @@ __down_write:
5027 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5028 1:
5029 lduw [%o0], %g3
5030- add %g3, %g1, %g7
5031+ addcc %g3, %g1, %g7
5032+
5033+#ifdef CONFIG_PAX_REFCOUNT
5034+ tvs %icc, 6
5035+#endif
5036+
5037 cas [%o0], %g3, %g7
5038 cmp %g3, %g7
5039 bne,pn %icc, 1b
5040@@ -77,7 +92,12 @@ __down_write_trylock:
5041 cmp %g3, 0
5042 bne,pn %icc, 2f
5043 mov 0, %o1
5044- add %g3, %g1, %g7
5045+ addcc %g3, %g1, %g7
5046+
5047+#ifdef CONFIG_PAX_REFCOUNT
5048+ tvs %icc, 6
5049+#endif
5050+
5051 cas [%o0], %g3, %g7
5052 cmp %g3, %g7
5053 bne,pn %icc, 1b
5054@@ -90,7 +110,12 @@ __down_write_trylock:
5055 __up_read:
5056 1:
5057 lduw [%o0], %g1
5058- sub %g1, 1, %g7
5059+ subcc %g1, 1, %g7
5060+
5061+#ifdef CONFIG_PAX_REFCOUNT
5062+ tvs %icc, 6
5063+#endif
5064+
5065 cas [%o0], %g1, %g7
5066 cmp %g1, %g7
5067 bne,pn %icc, 1b
5068@@ -118,7 +143,12 @@ __up_write:
5069 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5070 1:
5071 lduw [%o0], %g3
5072- sub %g3, %g1, %g7
5073+ subcc %g3, %g1, %g7
5074+
5075+#ifdef CONFIG_PAX_REFCOUNT
5076+ tvs %icc, 6
5077+#endif
5078+
5079 cas [%o0], %g3, %g7
5080 cmp %g3, %g7
5081 bne,pn %icc, 1b
5082@@ -143,7 +173,12 @@ __downgrade_write:
5083 or %g1, %lo(RWSEM_WAITING_BIAS), %g1
5084 1:
5085 lduw [%o0], %g3
5086- sub %g3, %g1, %g7
5087+ subcc %g3, %g1, %g7
5088+
5089+#ifdef CONFIG_PAX_REFCOUNT
5090+ tvs %icc, 6
5091+#endif
5092+
5093 cas [%o0], %g3, %g7
5094 cmp %g3, %g7
5095 bne,pn %icc, 1b
5096diff -urNp linux-2.6.32.43/arch/sparc/Makefile linux-2.6.32.43/arch/sparc/Makefile
5097--- linux-2.6.32.43/arch/sparc/Makefile 2011-03-27 14:31:47.000000000 -0400
5098+++ linux-2.6.32.43/arch/sparc/Makefile 2011-04-17 15:56:46.000000000 -0400
5099@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
5100 # Export what is needed by arch/sparc/boot/Makefile
5101 export VMLINUX_INIT VMLINUX_MAIN
5102 VMLINUX_INIT := $(head-y) $(init-y)
5103-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5104+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5105 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5106 VMLINUX_MAIN += $(drivers-y) $(net-y)
5107
5108diff -urNp linux-2.6.32.43/arch/sparc/mm/fault_32.c linux-2.6.32.43/arch/sparc/mm/fault_32.c
5109--- linux-2.6.32.43/arch/sparc/mm/fault_32.c 2011-03-27 14:31:47.000000000 -0400
5110+++ linux-2.6.32.43/arch/sparc/mm/fault_32.c 2011-04-17 15:56:46.000000000 -0400
5111@@ -21,6 +21,9 @@
5112 #include <linux/interrupt.h>
5113 #include <linux/module.h>
5114 #include <linux/kdebug.h>
5115+#include <linux/slab.h>
5116+#include <linux/pagemap.h>
5117+#include <linux/compiler.h>
5118
5119 #include <asm/system.h>
5120 #include <asm/page.h>
5121@@ -167,6 +170,267 @@ static unsigned long compute_si_addr(str
5122 return safe_compute_effective_address(regs, insn);
5123 }
5124
5125+#ifdef CONFIG_PAX_PAGEEXEC
5126+#ifdef CONFIG_PAX_DLRESOLVE
5127+static void pax_emuplt_close(struct vm_area_struct *vma)
5128+{
5129+ vma->vm_mm->call_dl_resolve = 0UL;
5130+}
5131+
5132+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5133+{
5134+ unsigned int *kaddr;
5135+
5136+ vmf->page = alloc_page(GFP_HIGHUSER);
5137+ if (!vmf->page)
5138+ return VM_FAULT_OOM;
5139+
5140+ kaddr = kmap(vmf->page);
5141+ memset(kaddr, 0, PAGE_SIZE);
5142+ kaddr[0] = 0x9DE3BFA8U; /* save */
5143+ flush_dcache_page(vmf->page);
5144+ kunmap(vmf->page);
5145+ return VM_FAULT_MAJOR;
5146+}
5147+
5148+static const struct vm_operations_struct pax_vm_ops = {
5149+ .close = pax_emuplt_close,
5150+ .fault = pax_emuplt_fault
5151+};
5152+
5153+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5154+{
5155+ int ret;
5156+
5157+ vma->vm_mm = current->mm;
5158+ vma->vm_start = addr;
5159+ vma->vm_end = addr + PAGE_SIZE;
5160+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5161+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5162+ vma->vm_ops = &pax_vm_ops;
5163+
5164+ ret = insert_vm_struct(current->mm, vma);
5165+ if (ret)
5166+ return ret;
5167+
5168+ ++current->mm->total_vm;
5169+ return 0;
5170+}
5171+#endif
5172+
5173+/*
5174+ * PaX: decide what to do with offenders (regs->pc = fault address)
5175+ *
5176+ * returns 1 when task should be killed
5177+ * 2 when patched PLT trampoline was detected
5178+ * 3 when unpatched PLT trampoline was detected
5179+ */
5180+static int pax_handle_fetch_fault(struct pt_regs *regs)
5181+{
5182+
5183+#ifdef CONFIG_PAX_EMUPLT
5184+ int err;
5185+
5186+ do { /* PaX: patched PLT emulation #1 */
5187+ unsigned int sethi1, sethi2, jmpl;
5188+
5189+ err = get_user(sethi1, (unsigned int *)regs->pc);
5190+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5191+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5192+
5193+ if (err)
5194+ break;
5195+
5196+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5197+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
5198+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
5199+ {
5200+ unsigned int addr;
5201+
5202+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5203+ addr = regs->u_regs[UREG_G1];
5204+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5205+ regs->pc = addr;
5206+ regs->npc = addr+4;
5207+ return 2;
5208+ }
5209+ } while (0);
5210+
5211+ { /* PaX: patched PLT emulation #2 */
5212+ unsigned int ba;
5213+
5214+ err = get_user(ba, (unsigned int *)regs->pc);
5215+
5216+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5217+ unsigned int addr;
5218+
5219+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5220+ regs->pc = addr;
5221+ regs->npc = addr+4;
5222+ return 2;
5223+ }
5224+ }
5225+
5226+ do { /* PaX: patched PLT emulation #3 */
5227+ unsigned int sethi, jmpl, nop;
5228+
5229+ err = get_user(sethi, (unsigned int *)regs->pc);
5230+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5231+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
5232+
5233+ if (err)
5234+ break;
5235+
5236+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5237+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5238+ nop == 0x01000000U)
5239+ {
5240+ unsigned int addr;
5241+
5242+ addr = (sethi & 0x003FFFFFU) << 10;
5243+ regs->u_regs[UREG_G1] = addr;
5244+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5245+ regs->pc = addr;
5246+ regs->npc = addr+4;
5247+ return 2;
5248+ }
5249+ } while (0);
5250+
5251+ do { /* PaX: unpatched PLT emulation step 1 */
5252+ unsigned int sethi, ba, nop;
5253+
5254+ err = get_user(sethi, (unsigned int *)regs->pc);
5255+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
5256+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
5257+
5258+ if (err)
5259+ break;
5260+
5261+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5262+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5263+ nop == 0x01000000U)
5264+ {
5265+ unsigned int addr, save, call;
5266+
5267+ if ((ba & 0xFFC00000U) == 0x30800000U)
5268+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5269+ else
5270+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5271+
5272+ err = get_user(save, (unsigned int *)addr);
5273+ err |= get_user(call, (unsigned int *)(addr+4));
5274+ err |= get_user(nop, (unsigned int *)(addr+8));
5275+ if (err)
5276+ break;
5277+
5278+#ifdef CONFIG_PAX_DLRESOLVE
5279+ if (save == 0x9DE3BFA8U &&
5280+ (call & 0xC0000000U) == 0x40000000U &&
5281+ nop == 0x01000000U)
5282+ {
5283+ struct vm_area_struct *vma;
5284+ unsigned long call_dl_resolve;
5285+
5286+ down_read(&current->mm->mmap_sem);
5287+ call_dl_resolve = current->mm->call_dl_resolve;
5288+ up_read(&current->mm->mmap_sem);
5289+ if (likely(call_dl_resolve))
5290+ goto emulate;
5291+
5292+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5293+
5294+ down_write(&current->mm->mmap_sem);
5295+ if (current->mm->call_dl_resolve) {
5296+ call_dl_resolve = current->mm->call_dl_resolve;
5297+ up_write(&current->mm->mmap_sem);
5298+ if (vma)
5299+ kmem_cache_free(vm_area_cachep, vma);
5300+ goto emulate;
5301+ }
5302+
5303+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5304+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5305+ up_write(&current->mm->mmap_sem);
5306+ if (vma)
5307+ kmem_cache_free(vm_area_cachep, vma);
5308+ return 1;
5309+ }
5310+
5311+ if (pax_insert_vma(vma, call_dl_resolve)) {
5312+ up_write(&current->mm->mmap_sem);
5313+ kmem_cache_free(vm_area_cachep, vma);
5314+ return 1;
5315+ }
5316+
5317+ current->mm->call_dl_resolve = call_dl_resolve;
5318+ up_write(&current->mm->mmap_sem);
5319+
5320+emulate:
5321+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5322+ regs->pc = call_dl_resolve;
5323+ regs->npc = addr+4;
5324+ return 3;
5325+ }
5326+#endif
5327+
5328+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5329+ if ((save & 0xFFC00000U) == 0x05000000U &&
5330+ (call & 0xFFFFE000U) == 0x85C0A000U &&
5331+ nop == 0x01000000U)
5332+ {
5333+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5334+ regs->u_regs[UREG_G2] = addr + 4;
5335+ addr = (save & 0x003FFFFFU) << 10;
5336+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5337+ regs->pc = addr;
5338+ regs->npc = addr+4;
5339+ return 3;
5340+ }
5341+ }
5342+ } while (0);
5343+
5344+ do { /* PaX: unpatched PLT emulation step 2 */
5345+ unsigned int save, call, nop;
5346+
5347+ err = get_user(save, (unsigned int *)(regs->pc-4));
5348+ err |= get_user(call, (unsigned int *)regs->pc);
5349+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
5350+ if (err)
5351+ break;
5352+
5353+ if (save == 0x9DE3BFA8U &&
5354+ (call & 0xC0000000U) == 0x40000000U &&
5355+ nop == 0x01000000U)
5356+ {
5357+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5358+
5359+ regs->u_regs[UREG_RETPC] = regs->pc;
5360+ regs->pc = dl_resolve;
5361+ regs->npc = dl_resolve+4;
5362+ return 3;
5363+ }
5364+ } while (0);
5365+#endif
5366+
5367+ return 1;
5368+}
5369+
5370+void pax_report_insns(void *pc, void *sp)
5371+{
5372+ unsigned long i;
5373+
5374+ printk(KERN_ERR "PAX: bytes at PC: ");
5375+ for (i = 0; i < 8; i++) {
5376+ unsigned int c;
5377+ if (get_user(c, (unsigned int *)pc+i))
5378+ printk(KERN_CONT "???????? ");
5379+ else
5380+ printk(KERN_CONT "%08x ", c);
5381+ }
5382+ printk("\n");
5383+}
5384+#endif
5385+
5386 asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
5387 unsigned long address)
5388 {
5389@@ -231,6 +495,24 @@ good_area:
5390 if(!(vma->vm_flags & VM_WRITE))
5391 goto bad_area;
5392 } else {
5393+
5394+#ifdef CONFIG_PAX_PAGEEXEC
5395+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5396+ up_read(&mm->mmap_sem);
5397+ switch (pax_handle_fetch_fault(regs)) {
5398+
5399+#ifdef CONFIG_PAX_EMUPLT
5400+ case 2:
5401+ case 3:
5402+ return;
5403+#endif
5404+
5405+ }
5406+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5407+ do_group_exit(SIGKILL);
5408+ }
5409+#endif
5410+
5411 /* Allow reads even for write-only mappings */
5412 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5413 goto bad_area;
5414diff -urNp linux-2.6.32.43/arch/sparc/mm/fault_64.c linux-2.6.32.43/arch/sparc/mm/fault_64.c
5415--- linux-2.6.32.43/arch/sparc/mm/fault_64.c 2011-03-27 14:31:47.000000000 -0400
5416+++ linux-2.6.32.43/arch/sparc/mm/fault_64.c 2011-04-17 15:56:46.000000000 -0400
5417@@ -20,6 +20,9 @@
5418 #include <linux/kprobes.h>
5419 #include <linux/kdebug.h>
5420 #include <linux/percpu.h>
5421+#include <linux/slab.h>
5422+#include <linux/pagemap.h>
5423+#include <linux/compiler.h>
5424
5425 #include <asm/page.h>
5426 #include <asm/pgtable.h>
5427@@ -78,7 +81,7 @@ static void bad_kernel_pc(struct pt_regs
5428 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5429 regs->tpc);
5430 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5431- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5432+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5433 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5434 dump_stack();
5435 unhandled_fault(regs->tpc, current, regs);
5436@@ -249,6 +252,456 @@ static void noinline bogus_32bit_fault_a
5437 show_regs(regs);
5438 }
5439
5440+#ifdef CONFIG_PAX_PAGEEXEC
5441+#ifdef CONFIG_PAX_DLRESOLVE
5442+static void pax_emuplt_close(struct vm_area_struct *vma)
5443+{
5444+ vma->vm_mm->call_dl_resolve = 0UL;
5445+}
5446+
5447+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5448+{
5449+ unsigned int *kaddr;
5450+
5451+ vmf->page = alloc_page(GFP_HIGHUSER);
5452+ if (!vmf->page)
5453+ return VM_FAULT_OOM;
5454+
5455+ kaddr = kmap(vmf->page);
5456+ memset(kaddr, 0, PAGE_SIZE);
5457+ kaddr[0] = 0x9DE3BFA8U; /* save */
5458+ flush_dcache_page(vmf->page);
5459+ kunmap(vmf->page);
5460+ return VM_FAULT_MAJOR;
5461+}
5462+
5463+static const struct vm_operations_struct pax_vm_ops = {
5464+ .close = pax_emuplt_close,
5465+ .fault = pax_emuplt_fault
5466+};
5467+
5468+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5469+{
5470+ int ret;
5471+
5472+ vma->vm_mm = current->mm;
5473+ vma->vm_start = addr;
5474+ vma->vm_end = addr + PAGE_SIZE;
5475+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5476+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5477+ vma->vm_ops = &pax_vm_ops;
5478+
5479+ ret = insert_vm_struct(current->mm, vma);
5480+ if (ret)
5481+ return ret;
5482+
5483+ ++current->mm->total_vm;
5484+ return 0;
5485+}
5486+#endif
5487+
5488+/*
5489+ * PaX: decide what to do with offenders (regs->tpc = fault address)
5490+ *
5491+ * returns 1 when task should be killed
5492+ * 2 when patched PLT trampoline was detected
5493+ * 3 when unpatched PLT trampoline was detected
5494+ */
5495+static int pax_handle_fetch_fault(struct pt_regs *regs)
5496+{
5497+
5498+#ifdef CONFIG_PAX_EMUPLT
5499+ int err;
5500+
5501+ do { /* PaX: patched PLT emulation #1 */
5502+ unsigned int sethi1, sethi2, jmpl;
5503+
5504+ err = get_user(sethi1, (unsigned int *)regs->tpc);
5505+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5506+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5507+
5508+ if (err)
5509+ break;
5510+
5511+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5512+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
5513+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
5514+ {
5515+ unsigned long addr;
5516+
5517+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5518+ addr = regs->u_regs[UREG_G1];
5519+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5520+
5521+ if (test_thread_flag(TIF_32BIT))
5522+ addr &= 0xFFFFFFFFUL;
5523+
5524+ regs->tpc = addr;
5525+ regs->tnpc = addr+4;
5526+ return 2;
5527+ }
5528+ } while (0);
5529+
5530+ { /* PaX: patched PLT emulation #2 */
5531+ unsigned int ba;
5532+
5533+ err = get_user(ba, (unsigned int *)regs->tpc);
5534+
5535+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5536+ unsigned long addr;
5537+
5538+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5539+
5540+ if (test_thread_flag(TIF_32BIT))
5541+ addr &= 0xFFFFFFFFUL;
5542+
5543+ regs->tpc = addr;
5544+ regs->tnpc = addr+4;
5545+ return 2;
5546+ }
5547+ }
5548+
5549+ do { /* PaX: patched PLT emulation #3 */
5550+ unsigned int sethi, jmpl, nop;
5551+
5552+ err = get_user(sethi, (unsigned int *)regs->tpc);
5553+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5554+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5555+
5556+ if (err)
5557+ break;
5558+
5559+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5560+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5561+ nop == 0x01000000U)
5562+ {
5563+ unsigned long addr;
5564+
5565+ addr = (sethi & 0x003FFFFFU) << 10;
5566+ regs->u_regs[UREG_G1] = addr;
5567+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5568+
5569+ if (test_thread_flag(TIF_32BIT))
5570+ addr &= 0xFFFFFFFFUL;
5571+
5572+ regs->tpc = addr;
5573+ regs->tnpc = addr+4;
5574+ return 2;
5575+ }
5576+ } while (0);
5577+
5578+ do { /* PaX: patched PLT emulation #4 */
5579+ unsigned int sethi, mov1, call, mov2;
5580+
5581+ err = get_user(sethi, (unsigned int *)regs->tpc);
5582+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5583+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
5584+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5585+
5586+ if (err)
5587+ break;
5588+
5589+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5590+ mov1 == 0x8210000FU &&
5591+ (call & 0xC0000000U) == 0x40000000U &&
5592+ mov2 == 0x9E100001U)
5593+ {
5594+ unsigned long addr;
5595+
5596+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5597+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5598+
5599+ if (test_thread_flag(TIF_32BIT))
5600+ addr &= 0xFFFFFFFFUL;
5601+
5602+ regs->tpc = addr;
5603+ regs->tnpc = addr+4;
5604+ return 2;
5605+ }
5606+ } while (0);
5607+
5608+ do { /* PaX: patched PLT emulation #5 */
5609+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5610+
5611+ err = get_user(sethi, (unsigned int *)regs->tpc);
5612+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5613+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5614+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5615+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5616+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5617+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5618+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5619+
5620+ if (err)
5621+ break;
5622+
5623+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5624+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
5625+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5626+ (or1 & 0xFFFFE000U) == 0x82106000U &&
5627+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
5628+ sllx == 0x83287020U &&
5629+ jmpl == 0x81C04005U &&
5630+ nop == 0x01000000U)
5631+ {
5632+ unsigned long addr;
5633+
5634+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5635+ regs->u_regs[UREG_G1] <<= 32;
5636+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5637+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5638+ regs->tpc = addr;
5639+ regs->tnpc = addr+4;
5640+ return 2;
5641+ }
5642+ } while (0);
5643+
5644+ do { /* PaX: patched PLT emulation #6 */
5645+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5646+
5647+ err = get_user(sethi, (unsigned int *)regs->tpc);
5648+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5649+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5650+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5651+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
5652+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5653+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5654+
5655+ if (err)
5656+ break;
5657+
5658+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5659+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
5660+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5661+ sllx == 0x83287020U &&
5662+ (or & 0xFFFFE000U) == 0x8A116000U &&
5663+ jmpl == 0x81C04005U &&
5664+ nop == 0x01000000U)
5665+ {
5666+ unsigned long addr;
5667+
5668+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5669+ regs->u_regs[UREG_G1] <<= 32;
5670+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5671+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5672+ regs->tpc = addr;
5673+ regs->tnpc = addr+4;
5674+ return 2;
5675+ }
5676+ } while (0);
5677+
5678+ do { /* PaX: unpatched PLT emulation step 1 */
5679+ unsigned int sethi, ba, nop;
5680+
5681+ err = get_user(sethi, (unsigned int *)regs->tpc);
5682+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5683+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5684+
5685+ if (err)
5686+ break;
5687+
5688+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5689+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5690+ nop == 0x01000000U)
5691+ {
5692+ unsigned long addr;
5693+ unsigned int save, call;
5694+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5695+
5696+ if ((ba & 0xFFC00000U) == 0x30800000U)
5697+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5698+ else
5699+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5700+
5701+ if (test_thread_flag(TIF_32BIT))
5702+ addr &= 0xFFFFFFFFUL;
5703+
5704+ err = get_user(save, (unsigned int *)addr);
5705+ err |= get_user(call, (unsigned int *)(addr+4));
5706+ err |= get_user(nop, (unsigned int *)(addr+8));
5707+ if (err)
5708+ break;
5709+
5710+#ifdef CONFIG_PAX_DLRESOLVE
5711+ if (save == 0x9DE3BFA8U &&
5712+ (call & 0xC0000000U) == 0x40000000U &&
5713+ nop == 0x01000000U)
5714+ {
5715+ struct vm_area_struct *vma;
5716+ unsigned long call_dl_resolve;
5717+
5718+ down_read(&current->mm->mmap_sem);
5719+ call_dl_resolve = current->mm->call_dl_resolve;
5720+ up_read(&current->mm->mmap_sem);
5721+ if (likely(call_dl_resolve))
5722+ goto emulate;
5723+
5724+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5725+
5726+ down_write(&current->mm->mmap_sem);
5727+ if (current->mm->call_dl_resolve) {
5728+ call_dl_resolve = current->mm->call_dl_resolve;
5729+ up_write(&current->mm->mmap_sem);
5730+ if (vma)
5731+ kmem_cache_free(vm_area_cachep, vma);
5732+ goto emulate;
5733+ }
5734+
5735+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5736+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5737+ up_write(&current->mm->mmap_sem);
5738+ if (vma)
5739+ kmem_cache_free(vm_area_cachep, vma);
5740+ return 1;
5741+ }
5742+
5743+ if (pax_insert_vma(vma, call_dl_resolve)) {
5744+ up_write(&current->mm->mmap_sem);
5745+ kmem_cache_free(vm_area_cachep, vma);
5746+ return 1;
5747+ }
5748+
5749+ current->mm->call_dl_resolve = call_dl_resolve;
5750+ up_write(&current->mm->mmap_sem);
5751+
5752+emulate:
5753+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5754+ regs->tpc = call_dl_resolve;
5755+ regs->tnpc = addr+4;
5756+ return 3;
5757+ }
5758+#endif
5759+
5760+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5761+ if ((save & 0xFFC00000U) == 0x05000000U &&
5762+ (call & 0xFFFFE000U) == 0x85C0A000U &&
5763+ nop == 0x01000000U)
5764+ {
5765+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5766+ regs->u_regs[UREG_G2] = addr + 4;
5767+ addr = (save & 0x003FFFFFU) << 10;
5768+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5769+
5770+ if (test_thread_flag(TIF_32BIT))
5771+ addr &= 0xFFFFFFFFUL;
5772+
5773+ regs->tpc = addr;
5774+ regs->tnpc = addr+4;
5775+ return 3;
5776+ }
5777+
5778+ /* PaX: 64-bit PLT stub */
5779+ err = get_user(sethi1, (unsigned int *)addr);
5780+ err |= get_user(sethi2, (unsigned int *)(addr+4));
5781+ err |= get_user(or1, (unsigned int *)(addr+8));
5782+ err |= get_user(or2, (unsigned int *)(addr+12));
5783+ err |= get_user(sllx, (unsigned int *)(addr+16));
5784+ err |= get_user(add, (unsigned int *)(addr+20));
5785+ err |= get_user(jmpl, (unsigned int *)(addr+24));
5786+ err |= get_user(nop, (unsigned int *)(addr+28));
5787+ if (err)
5788+ break;
5789+
5790+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5791+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5792+ (or1 & 0xFFFFE000U) == 0x88112000U &&
5793+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
5794+ sllx == 0x89293020U &&
5795+ add == 0x8A010005U &&
5796+ jmpl == 0x89C14000U &&
5797+ nop == 0x01000000U)
5798+ {
5799+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5800+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5801+ regs->u_regs[UREG_G4] <<= 32;
5802+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5803+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5804+ regs->u_regs[UREG_G4] = addr + 24;
5805+ addr = regs->u_regs[UREG_G5];
5806+ regs->tpc = addr;
5807+ regs->tnpc = addr+4;
5808+ return 3;
5809+ }
5810+ }
5811+ } while (0);
5812+
5813+#ifdef CONFIG_PAX_DLRESOLVE
5814+ do { /* PaX: unpatched PLT emulation step 2 */
5815+ unsigned int save, call, nop;
5816+
5817+ err = get_user(save, (unsigned int *)(regs->tpc-4));
5818+ err |= get_user(call, (unsigned int *)regs->tpc);
5819+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5820+ if (err)
5821+ break;
5822+
5823+ if (save == 0x9DE3BFA8U &&
5824+ (call & 0xC0000000U) == 0x40000000U &&
5825+ nop == 0x01000000U)
5826+ {
5827+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5828+
5829+ if (test_thread_flag(TIF_32BIT))
5830+ dl_resolve &= 0xFFFFFFFFUL;
5831+
5832+ regs->u_regs[UREG_RETPC] = regs->tpc;
5833+ regs->tpc = dl_resolve;
5834+ regs->tnpc = dl_resolve+4;
5835+ return 3;
5836+ }
5837+ } while (0);
5838+#endif
5839+
5840+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5841+ unsigned int sethi, ba, nop;
5842+
5843+ err = get_user(sethi, (unsigned int *)regs->tpc);
5844+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5845+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5846+
5847+ if (err)
5848+ break;
5849+
5850+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5851+ (ba & 0xFFF00000U) == 0x30600000U &&
5852+ nop == 0x01000000U)
5853+ {
5854+ unsigned long addr;
5855+
5856+ addr = (sethi & 0x003FFFFFU) << 10;
5857+ regs->u_regs[UREG_G1] = addr;
5858+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5859+
5860+ if (test_thread_flag(TIF_32BIT))
5861+ addr &= 0xFFFFFFFFUL;
5862+
5863+ regs->tpc = addr;
5864+ regs->tnpc = addr+4;
5865+ return 2;
5866+ }
5867+ } while (0);
5868+
5869+#endif
5870+
5871+ return 1;
5872+}
5873+
5874+void pax_report_insns(void *pc, void *sp)
5875+{
5876+ unsigned long i;
5877+
5878+ printk(KERN_ERR "PAX: bytes at PC: ");
5879+ for (i = 0; i < 8; i++) {
5880+ unsigned int c;
5881+ if (get_user(c, (unsigned int *)pc+i))
5882+ printk(KERN_CONT "???????? ");
5883+ else
5884+ printk(KERN_CONT "%08x ", c);
5885+ }
5886+ printk("\n");
5887+}
5888+#endif
5889+
5890 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5891 {
5892 struct mm_struct *mm = current->mm;
5893@@ -315,6 +768,29 @@ asmlinkage void __kprobes do_sparc64_fau
5894 if (!vma)
5895 goto bad_area;
5896
5897+#ifdef CONFIG_PAX_PAGEEXEC
5898+ /* PaX: detect ITLB misses on non-exec pages */
5899+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5900+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5901+ {
5902+ if (address != regs->tpc)
5903+ goto good_area;
5904+
5905+ up_read(&mm->mmap_sem);
5906+ switch (pax_handle_fetch_fault(regs)) {
5907+
5908+#ifdef CONFIG_PAX_EMUPLT
5909+ case 2:
5910+ case 3:
5911+ return;
5912+#endif
5913+
5914+ }
5915+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5916+ do_group_exit(SIGKILL);
5917+ }
5918+#endif
5919+
5920 /* Pure DTLB misses do not tell us whether the fault causing
5921 * load/store/atomic was a write or not, it only says that there
5922 * was no match. So in such a case we (carefully) read the
5923diff -urNp linux-2.6.32.43/arch/sparc/mm/hugetlbpage.c linux-2.6.32.43/arch/sparc/mm/hugetlbpage.c
5924--- linux-2.6.32.43/arch/sparc/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
5925+++ linux-2.6.32.43/arch/sparc/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
5926@@ -69,7 +69,7 @@ full_search:
5927 }
5928 return -ENOMEM;
5929 }
5930- if (likely(!vma || addr + len <= vma->vm_start)) {
5931+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5932 /*
5933 * Remember the place where we stopped the search:
5934 */
5935@@ -108,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct
5936 /* make sure it can fit in the remaining address space */
5937 if (likely(addr > len)) {
5938 vma = find_vma(mm, addr-len);
5939- if (!vma || addr <= vma->vm_start) {
5940+ if (check_heap_stack_gap(vma, addr - len, len)) {
5941 /* remember the address as a hint for next time */
5942 return (mm->free_area_cache = addr-len);
5943 }
5944@@ -117,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct
5945 if (unlikely(mm->mmap_base < len))
5946 goto bottomup;
5947
5948- addr = (mm->mmap_base-len) & HPAGE_MASK;
5949+ addr = mm->mmap_base - len;
5950
5951 do {
5952+ addr &= HPAGE_MASK;
5953 /*
5954 * Lookup failure means no vma is above this address,
5955 * else if new region fits below vma->vm_start,
5956 * return with success:
5957 */
5958 vma = find_vma(mm, addr);
5959- if (likely(!vma || addr+len <= vma->vm_start)) {
5960+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5961 /* remember the address as a hint for next time */
5962 return (mm->free_area_cache = addr);
5963 }
5964@@ -136,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct
5965 mm->cached_hole_size = vma->vm_start - addr;
5966
5967 /* try just below the current vma->vm_start */
5968- addr = (vma->vm_start-len) & HPAGE_MASK;
5969- } while (likely(len < vma->vm_start));
5970+ addr = skip_heap_stack_gap(vma, len);
5971+ } while (!IS_ERR_VALUE(addr));
5972
5973 bottomup:
5974 /*
5975@@ -183,8 +184,7 @@ hugetlb_get_unmapped_area(struct file *f
5976 if (addr) {
5977 addr = ALIGN(addr, HPAGE_SIZE);
5978 vma = find_vma(mm, addr);
5979- if (task_size - len >= addr &&
5980- (!vma || addr + len <= vma->vm_start))
5981+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5982 return addr;
5983 }
5984 if (mm->get_unmapped_area == arch_get_unmapped_area)
5985diff -urNp linux-2.6.32.43/arch/sparc/mm/init_32.c linux-2.6.32.43/arch/sparc/mm/init_32.c
5986--- linux-2.6.32.43/arch/sparc/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
5987+++ linux-2.6.32.43/arch/sparc/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
5988@@ -317,6 +317,9 @@ extern void device_scan(void);
5989 pgprot_t PAGE_SHARED __read_mostly;
5990 EXPORT_SYMBOL(PAGE_SHARED);
5991
5992+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5993+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5994+
5995 void __init paging_init(void)
5996 {
5997 switch(sparc_cpu_model) {
5998@@ -345,17 +348,17 @@ void __init paging_init(void)
5999
6000 /* Initialize the protection map with non-constant, MMU dependent values. */
6001 protection_map[0] = PAGE_NONE;
6002- protection_map[1] = PAGE_READONLY;
6003- protection_map[2] = PAGE_COPY;
6004- protection_map[3] = PAGE_COPY;
6005+ protection_map[1] = PAGE_READONLY_NOEXEC;
6006+ protection_map[2] = PAGE_COPY_NOEXEC;
6007+ protection_map[3] = PAGE_COPY_NOEXEC;
6008 protection_map[4] = PAGE_READONLY;
6009 protection_map[5] = PAGE_READONLY;
6010 protection_map[6] = PAGE_COPY;
6011 protection_map[7] = PAGE_COPY;
6012 protection_map[8] = PAGE_NONE;
6013- protection_map[9] = PAGE_READONLY;
6014- protection_map[10] = PAGE_SHARED;
6015- protection_map[11] = PAGE_SHARED;
6016+ protection_map[9] = PAGE_READONLY_NOEXEC;
6017+ protection_map[10] = PAGE_SHARED_NOEXEC;
6018+ protection_map[11] = PAGE_SHARED_NOEXEC;
6019 protection_map[12] = PAGE_READONLY;
6020 protection_map[13] = PAGE_READONLY;
6021 protection_map[14] = PAGE_SHARED;
6022diff -urNp linux-2.6.32.43/arch/sparc/mm/Makefile linux-2.6.32.43/arch/sparc/mm/Makefile
6023--- linux-2.6.32.43/arch/sparc/mm/Makefile 2011-03-27 14:31:47.000000000 -0400
6024+++ linux-2.6.32.43/arch/sparc/mm/Makefile 2011-04-17 15:56:46.000000000 -0400
6025@@ -2,7 +2,7 @@
6026 #
6027
6028 asflags-y := -ansi
6029-ccflags-y := -Werror
6030+#ccflags-y := -Werror
6031
6032 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
6033 obj-y += fault_$(BITS).o
6034diff -urNp linux-2.6.32.43/arch/sparc/mm/srmmu.c linux-2.6.32.43/arch/sparc/mm/srmmu.c
6035--- linux-2.6.32.43/arch/sparc/mm/srmmu.c 2011-03-27 14:31:47.000000000 -0400
6036+++ linux-2.6.32.43/arch/sparc/mm/srmmu.c 2011-04-17 15:56:46.000000000 -0400
6037@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6038 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6039 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6040 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6041+
6042+#ifdef CONFIG_PAX_PAGEEXEC
6043+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6044+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6045+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6046+#endif
6047+
6048 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6049 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6050
6051diff -urNp linux-2.6.32.43/arch/um/include/asm/kmap_types.h linux-2.6.32.43/arch/um/include/asm/kmap_types.h
6052--- linux-2.6.32.43/arch/um/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
6053+++ linux-2.6.32.43/arch/um/include/asm/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
6054@@ -23,6 +23,7 @@ enum km_type {
6055 KM_IRQ1,
6056 KM_SOFTIRQ0,
6057 KM_SOFTIRQ1,
6058+ KM_CLEARPAGE,
6059 KM_TYPE_NR
6060 };
6061
6062diff -urNp linux-2.6.32.43/arch/um/include/asm/page.h linux-2.6.32.43/arch/um/include/asm/page.h
6063--- linux-2.6.32.43/arch/um/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
6064+++ linux-2.6.32.43/arch/um/include/asm/page.h 2011-04-17 15:56:46.000000000 -0400
6065@@ -14,6 +14,9 @@
6066 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6067 #define PAGE_MASK (~(PAGE_SIZE-1))
6068
6069+#define ktla_ktva(addr) (addr)
6070+#define ktva_ktla(addr) (addr)
6071+
6072 #ifndef __ASSEMBLY__
6073
6074 struct page;
6075diff -urNp linux-2.6.32.43/arch/um/kernel/process.c linux-2.6.32.43/arch/um/kernel/process.c
6076--- linux-2.6.32.43/arch/um/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
6077+++ linux-2.6.32.43/arch/um/kernel/process.c 2011-04-17 15:56:46.000000000 -0400
6078@@ -393,22 +393,6 @@ int singlestepping(void * t)
6079 return 2;
6080 }
6081
6082-/*
6083- * Only x86 and x86_64 have an arch_align_stack().
6084- * All other arches have "#define arch_align_stack(x) (x)"
6085- * in their asm/system.h
6086- * As this is included in UML from asm-um/system-generic.h,
6087- * we can use it to behave as the subarch does.
6088- */
6089-#ifndef arch_align_stack
6090-unsigned long arch_align_stack(unsigned long sp)
6091-{
6092- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6093- sp -= get_random_int() % 8192;
6094- return sp & ~0xf;
6095-}
6096-#endif
6097-
6098 unsigned long get_wchan(struct task_struct *p)
6099 {
6100 unsigned long stack_page, sp, ip;
6101diff -urNp linux-2.6.32.43/arch/um/sys-i386/syscalls.c linux-2.6.32.43/arch/um/sys-i386/syscalls.c
6102--- linux-2.6.32.43/arch/um/sys-i386/syscalls.c 2011-03-27 14:31:47.000000000 -0400
6103+++ linux-2.6.32.43/arch/um/sys-i386/syscalls.c 2011-04-17 15:56:46.000000000 -0400
6104@@ -11,6 +11,21 @@
6105 #include "asm/uaccess.h"
6106 #include "asm/unistd.h"
6107
6108+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6109+{
6110+ unsigned long pax_task_size = TASK_SIZE;
6111+
6112+#ifdef CONFIG_PAX_SEGMEXEC
6113+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6114+ pax_task_size = SEGMEXEC_TASK_SIZE;
6115+#endif
6116+
6117+ if (len > pax_task_size || addr > pax_task_size - len)
6118+ return -EINVAL;
6119+
6120+ return 0;
6121+}
6122+
6123 /*
6124 * Perform the select(nd, in, out, ex, tv) and mmap() system
6125 * calls. Linux/i386 didn't use to be able to handle more than
6126diff -urNp linux-2.6.32.43/arch/x86/boot/bitops.h linux-2.6.32.43/arch/x86/boot/bitops.h
6127--- linux-2.6.32.43/arch/x86/boot/bitops.h 2011-03-27 14:31:47.000000000 -0400
6128+++ linux-2.6.32.43/arch/x86/boot/bitops.h 2011-04-17 15:56:46.000000000 -0400
6129@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
6130 u8 v;
6131 const u32 *p = (const u32 *)addr;
6132
6133- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6134+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
6135 return v;
6136 }
6137
6138@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
6139
6140 static inline void set_bit(int nr, void *addr)
6141 {
6142- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6143+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
6144 }
6145
6146 #endif /* BOOT_BITOPS_H */
6147diff -urNp linux-2.6.32.43/arch/x86/boot/boot.h linux-2.6.32.43/arch/x86/boot/boot.h
6148--- linux-2.6.32.43/arch/x86/boot/boot.h 2011-03-27 14:31:47.000000000 -0400
6149+++ linux-2.6.32.43/arch/x86/boot/boot.h 2011-04-17 15:56:46.000000000 -0400
6150@@ -82,7 +82,7 @@ static inline void io_delay(void)
6151 static inline u16 ds(void)
6152 {
6153 u16 seg;
6154- asm("movw %%ds,%0" : "=rm" (seg));
6155+ asm volatile("movw %%ds,%0" : "=rm" (seg));
6156 return seg;
6157 }
6158
6159@@ -178,7 +178,7 @@ static inline void wrgs32(u32 v, addr_t
6160 static inline int memcmp(const void *s1, const void *s2, size_t len)
6161 {
6162 u8 diff;
6163- asm("repe; cmpsb; setnz %0"
6164+ asm volatile("repe; cmpsb; setnz %0"
6165 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
6166 return diff;
6167 }
6168diff -urNp linux-2.6.32.43/arch/x86/boot/compressed/head_32.S linux-2.6.32.43/arch/x86/boot/compressed/head_32.S
6169--- linux-2.6.32.43/arch/x86/boot/compressed/head_32.S 2011-03-27 14:31:47.000000000 -0400
6170+++ linux-2.6.32.43/arch/x86/boot/compressed/head_32.S 2011-04-17 15:56:46.000000000 -0400
6171@@ -76,7 +76,7 @@ ENTRY(startup_32)
6172 notl %eax
6173 andl %eax, %ebx
6174 #else
6175- movl $LOAD_PHYSICAL_ADDR, %ebx
6176+ movl $____LOAD_PHYSICAL_ADDR, %ebx
6177 #endif
6178
6179 /* Target address to relocate to for decompression */
6180@@ -149,7 +149,7 @@ relocated:
6181 * and where it was actually loaded.
6182 */
6183 movl %ebp, %ebx
6184- subl $LOAD_PHYSICAL_ADDR, %ebx
6185+ subl $____LOAD_PHYSICAL_ADDR, %ebx
6186 jz 2f /* Nothing to be done if loaded at compiled addr. */
6187 /*
6188 * Process relocations.
6189@@ -157,8 +157,7 @@ relocated:
6190
6191 1: subl $4, %edi
6192 movl (%edi), %ecx
6193- testl %ecx, %ecx
6194- jz 2f
6195+ jecxz 2f
6196 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
6197 jmp 1b
6198 2:
6199diff -urNp linux-2.6.32.43/arch/x86/boot/compressed/head_64.S linux-2.6.32.43/arch/x86/boot/compressed/head_64.S
6200--- linux-2.6.32.43/arch/x86/boot/compressed/head_64.S 2011-03-27 14:31:47.000000000 -0400
6201+++ linux-2.6.32.43/arch/x86/boot/compressed/head_64.S 2011-07-01 18:53:00.000000000 -0400
6202@@ -91,7 +91,7 @@ ENTRY(startup_32)
6203 notl %eax
6204 andl %eax, %ebx
6205 #else
6206- movl $LOAD_PHYSICAL_ADDR, %ebx
6207+ movl $____LOAD_PHYSICAL_ADDR, %ebx
6208 #endif
6209
6210 /* Target address to relocate to for decompression */
6211@@ -183,7 +183,7 @@ no_longmode:
6212 hlt
6213 jmp 1b
6214
6215-#include "../../kernel/verify_cpu_64.S"
6216+#include "../../kernel/verify_cpu.S"
6217
6218 /*
6219 * Be careful here startup_64 needs to be at a predictable
6220@@ -234,7 +234,7 @@ ENTRY(startup_64)
6221 notq %rax
6222 andq %rax, %rbp
6223 #else
6224- movq $LOAD_PHYSICAL_ADDR, %rbp
6225+ movq $____LOAD_PHYSICAL_ADDR, %rbp
6226 #endif
6227
6228 /* Target address to relocate to for decompression */
6229diff -urNp linux-2.6.32.43/arch/x86/boot/compressed/Makefile linux-2.6.32.43/arch/x86/boot/compressed/Makefile
6230--- linux-2.6.32.43/arch/x86/boot/compressed/Makefile 2011-03-27 14:31:47.000000000 -0400
6231+++ linux-2.6.32.43/arch/x86/boot/compressed/Makefile 2011-08-07 14:38:34.000000000 -0400
6232@@ -13,6 +13,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=smal
6233 KBUILD_CFLAGS += $(cflags-y)
6234 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
6235 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
6236+ifdef CONSTIFY_PLUGIN
6237+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6238+endif
6239
6240 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6241 GCOV_PROFILE := n
6242diff -urNp linux-2.6.32.43/arch/x86/boot/compressed/misc.c linux-2.6.32.43/arch/x86/boot/compressed/misc.c
6243--- linux-2.6.32.43/arch/x86/boot/compressed/misc.c 2011-03-27 14:31:47.000000000 -0400
6244+++ linux-2.6.32.43/arch/x86/boot/compressed/misc.c 2011-04-17 15:56:46.000000000 -0400
6245@@ -288,7 +288,7 @@ static void parse_elf(void *output)
6246 case PT_LOAD:
6247 #ifdef CONFIG_RELOCATABLE
6248 dest = output;
6249- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6250+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6251 #else
6252 dest = (void *)(phdr->p_paddr);
6253 #endif
6254@@ -335,7 +335,7 @@ asmlinkage void decompress_kernel(void *
6255 error("Destination address too large");
6256 #endif
6257 #ifndef CONFIG_RELOCATABLE
6258- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
6259+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
6260 error("Wrong destination address");
6261 #endif
6262
6263diff -urNp linux-2.6.32.43/arch/x86/boot/compressed/mkpiggy.c linux-2.6.32.43/arch/x86/boot/compressed/mkpiggy.c
6264--- linux-2.6.32.43/arch/x86/boot/compressed/mkpiggy.c 2011-03-27 14:31:47.000000000 -0400
6265+++ linux-2.6.32.43/arch/x86/boot/compressed/mkpiggy.c 2011-04-17 15:56:46.000000000 -0400
6266@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
6267
6268 offs = (olen > ilen) ? olen - ilen : 0;
6269 offs += olen >> 12; /* Add 8 bytes for each 32K block */
6270- offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
6271+ offs += 64*1024; /* Add 64K bytes slack */
6272 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
6273
6274 printf(".section \".rodata.compressed\",\"a\",@progbits\n");
6275diff -urNp linux-2.6.32.43/arch/x86/boot/compressed/relocs.c linux-2.6.32.43/arch/x86/boot/compressed/relocs.c
6276--- linux-2.6.32.43/arch/x86/boot/compressed/relocs.c 2011-03-27 14:31:47.000000000 -0400
6277+++ linux-2.6.32.43/arch/x86/boot/compressed/relocs.c 2011-04-17 15:56:46.000000000 -0400
6278@@ -10,8 +10,11 @@
6279 #define USE_BSD
6280 #include <endian.h>
6281
6282+#include "../../../../include/linux/autoconf.h"
6283+
6284 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
6285 static Elf32_Ehdr ehdr;
6286+static Elf32_Phdr *phdr;
6287 static unsigned long reloc_count, reloc_idx;
6288 static unsigned long *relocs;
6289
6290@@ -37,7 +40,7 @@ static const char* safe_abs_relocs[] = {
6291
6292 static int is_safe_abs_reloc(const char* sym_name)
6293 {
6294- int i;
6295+ unsigned int i;
6296
6297 for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
6298 if (!strcmp(sym_name, safe_abs_relocs[i]))
6299@@ -245,9 +248,39 @@ static void read_ehdr(FILE *fp)
6300 }
6301 }
6302
6303+static void read_phdrs(FILE *fp)
6304+{
6305+ unsigned int i;
6306+
6307+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6308+ if (!phdr) {
6309+ die("Unable to allocate %d program headers\n",
6310+ ehdr.e_phnum);
6311+ }
6312+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6313+ die("Seek to %d failed: %s\n",
6314+ ehdr.e_phoff, strerror(errno));
6315+ }
6316+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6317+ die("Cannot read ELF program headers: %s\n",
6318+ strerror(errno));
6319+ }
6320+ for(i = 0; i < ehdr.e_phnum; i++) {
6321+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
6322+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
6323+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
6324+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
6325+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
6326+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
6327+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
6328+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
6329+ }
6330+
6331+}
6332+
6333 static void read_shdrs(FILE *fp)
6334 {
6335- int i;
6336+ unsigned int i;
6337 Elf32_Shdr shdr;
6338
6339 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6340@@ -282,7 +315,7 @@ static void read_shdrs(FILE *fp)
6341
6342 static void read_strtabs(FILE *fp)
6343 {
6344- int i;
6345+ unsigned int i;
6346 for (i = 0; i < ehdr.e_shnum; i++) {
6347 struct section *sec = &secs[i];
6348 if (sec->shdr.sh_type != SHT_STRTAB) {
6349@@ -307,7 +340,7 @@ static void read_strtabs(FILE *fp)
6350
6351 static void read_symtabs(FILE *fp)
6352 {
6353- int i,j;
6354+ unsigned int i,j;
6355 for (i = 0; i < ehdr.e_shnum; i++) {
6356 struct section *sec = &secs[i];
6357 if (sec->shdr.sh_type != SHT_SYMTAB) {
6358@@ -340,7 +373,9 @@ static void read_symtabs(FILE *fp)
6359
6360 static void read_relocs(FILE *fp)
6361 {
6362- int i,j;
6363+ unsigned int i,j;
6364+ uint32_t base;
6365+
6366 for (i = 0; i < ehdr.e_shnum; i++) {
6367 struct section *sec = &secs[i];
6368 if (sec->shdr.sh_type != SHT_REL) {
6369@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
6370 die("Cannot read symbol table: %s\n",
6371 strerror(errno));
6372 }
6373+ base = 0;
6374+ for (j = 0; j < ehdr.e_phnum; j++) {
6375+ if (phdr[j].p_type != PT_LOAD )
6376+ continue;
6377+ 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)
6378+ continue;
6379+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6380+ break;
6381+ }
6382 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6383 Elf32_Rel *rel = &sec->reltab[j];
6384- rel->r_offset = elf32_to_cpu(rel->r_offset);
6385+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6386 rel->r_info = elf32_to_cpu(rel->r_info);
6387 }
6388 }
6389@@ -371,14 +415,14 @@ static void read_relocs(FILE *fp)
6390
6391 static void print_absolute_symbols(void)
6392 {
6393- int i;
6394+ unsigned int i;
6395 printf("Absolute symbols\n");
6396 printf(" Num: Value Size Type Bind Visibility Name\n");
6397 for (i = 0; i < ehdr.e_shnum; i++) {
6398 struct section *sec = &secs[i];
6399 char *sym_strtab;
6400 Elf32_Sym *sh_symtab;
6401- int j;
6402+ unsigned int j;
6403
6404 if (sec->shdr.sh_type != SHT_SYMTAB) {
6405 continue;
6406@@ -406,14 +450,14 @@ static void print_absolute_symbols(void)
6407
6408 static void print_absolute_relocs(void)
6409 {
6410- int i, printed = 0;
6411+ unsigned int i, printed = 0;
6412
6413 for (i = 0; i < ehdr.e_shnum; i++) {
6414 struct section *sec = &secs[i];
6415 struct section *sec_applies, *sec_symtab;
6416 char *sym_strtab;
6417 Elf32_Sym *sh_symtab;
6418- int j;
6419+ unsigned int j;
6420 if (sec->shdr.sh_type != SHT_REL) {
6421 continue;
6422 }
6423@@ -474,13 +518,13 @@ static void print_absolute_relocs(void)
6424
6425 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6426 {
6427- int i;
6428+ unsigned int i;
6429 /* Walk through the relocations */
6430 for (i = 0; i < ehdr.e_shnum; i++) {
6431 char *sym_strtab;
6432 Elf32_Sym *sh_symtab;
6433 struct section *sec_applies, *sec_symtab;
6434- int j;
6435+ unsigned int j;
6436 struct section *sec = &secs[i];
6437
6438 if (sec->shdr.sh_type != SHT_REL) {
6439@@ -504,6 +548,21 @@ static void walk_relocs(void (*visit)(El
6440 if (sym->st_shndx == SHN_ABS) {
6441 continue;
6442 }
6443+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6444+ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6445+ continue;
6446+
6447+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6448+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6449+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6450+ continue;
6451+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6452+ continue;
6453+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6454+ continue;
6455+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6456+ continue;
6457+#endif
6458 if (r_type == R_386_NONE || r_type == R_386_PC32) {
6459 /*
6460 * NONE can be ignored and and PC relative
6461@@ -541,7 +600,7 @@ static int cmp_relocs(const void *va, co
6462
6463 static void emit_relocs(int as_text)
6464 {
6465- int i;
6466+ unsigned int i;
6467 /* Count how many relocations I have and allocate space for them. */
6468 reloc_count = 0;
6469 walk_relocs(count_reloc);
6470@@ -634,6 +693,7 @@ int main(int argc, char **argv)
6471 fname, strerror(errno));
6472 }
6473 read_ehdr(fp);
6474+ read_phdrs(fp);
6475 read_shdrs(fp);
6476 read_strtabs(fp);
6477 read_symtabs(fp);
6478diff -urNp linux-2.6.32.43/arch/x86/boot/cpucheck.c linux-2.6.32.43/arch/x86/boot/cpucheck.c
6479--- linux-2.6.32.43/arch/x86/boot/cpucheck.c 2011-03-27 14:31:47.000000000 -0400
6480+++ linux-2.6.32.43/arch/x86/boot/cpucheck.c 2011-04-17 15:56:46.000000000 -0400
6481@@ -74,7 +74,7 @@ static int has_fpu(void)
6482 u16 fcw = -1, fsw = -1;
6483 u32 cr0;
6484
6485- asm("movl %%cr0,%0" : "=r" (cr0));
6486+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
6487 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6488 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6489 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6490@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6491 {
6492 u32 f0, f1;
6493
6494- asm("pushfl ; "
6495+ asm volatile("pushfl ; "
6496 "pushfl ; "
6497 "popl %0 ; "
6498 "movl %0,%1 ; "
6499@@ -115,7 +115,7 @@ static void get_flags(void)
6500 set_bit(X86_FEATURE_FPU, cpu.flags);
6501
6502 if (has_eflag(X86_EFLAGS_ID)) {
6503- asm("cpuid"
6504+ asm volatile("cpuid"
6505 : "=a" (max_intel_level),
6506 "=b" (cpu_vendor[0]),
6507 "=d" (cpu_vendor[1]),
6508@@ -124,7 +124,7 @@ static void get_flags(void)
6509
6510 if (max_intel_level >= 0x00000001 &&
6511 max_intel_level <= 0x0000ffff) {
6512- asm("cpuid"
6513+ asm volatile("cpuid"
6514 : "=a" (tfms),
6515 "=c" (cpu.flags[4]),
6516 "=d" (cpu.flags[0])
6517@@ -136,7 +136,7 @@ static void get_flags(void)
6518 cpu.model += ((tfms >> 16) & 0xf) << 4;
6519 }
6520
6521- asm("cpuid"
6522+ asm volatile("cpuid"
6523 : "=a" (max_amd_level)
6524 : "a" (0x80000000)
6525 : "ebx", "ecx", "edx");
6526@@ -144,7 +144,7 @@ static void get_flags(void)
6527 if (max_amd_level >= 0x80000001 &&
6528 max_amd_level <= 0x8000ffff) {
6529 u32 eax = 0x80000001;
6530- asm("cpuid"
6531+ asm volatile("cpuid"
6532 : "+a" (eax),
6533 "=c" (cpu.flags[6]),
6534 "=d" (cpu.flags[1])
6535@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6536 u32 ecx = MSR_K7_HWCR;
6537 u32 eax, edx;
6538
6539- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6540+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6541 eax &= ~(1 << 15);
6542- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6543+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6544
6545 get_flags(); /* Make sure it really did something */
6546 err = check_flags();
6547@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6548 u32 ecx = MSR_VIA_FCR;
6549 u32 eax, edx;
6550
6551- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6552+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6553 eax |= (1<<1)|(1<<7);
6554- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6555+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6556
6557 set_bit(X86_FEATURE_CX8, cpu.flags);
6558 err = check_flags();
6559@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
6560 u32 eax, edx;
6561 u32 level = 1;
6562
6563- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6564- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6565- asm("cpuid"
6566+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6567+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6568+ asm volatile("cpuid"
6569 : "+a" (level), "=d" (cpu.flags[0])
6570 : : "ecx", "ebx");
6571- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6572+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6573
6574 err = check_flags();
6575 }
6576diff -urNp linux-2.6.32.43/arch/x86/boot/header.S linux-2.6.32.43/arch/x86/boot/header.S
6577--- linux-2.6.32.43/arch/x86/boot/header.S 2011-03-27 14:31:47.000000000 -0400
6578+++ linux-2.6.32.43/arch/x86/boot/header.S 2011-04-17 15:56:46.000000000 -0400
6579@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
6580 # single linked list of
6581 # struct setup_data
6582
6583-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6584+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6585
6586 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6587 #define VO_INIT_SIZE (VO__end - VO__text)
6588diff -urNp linux-2.6.32.43/arch/x86/boot/Makefile linux-2.6.32.43/arch/x86/boot/Makefile
6589--- linux-2.6.32.43/arch/x86/boot/Makefile 2011-03-27 14:31:47.000000000 -0400
6590+++ linux-2.6.32.43/arch/x86/boot/Makefile 2011-08-07 14:38:13.000000000 -0400
6591@@ -69,6 +69,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
6592 $(call cc-option, -fno-stack-protector) \
6593 $(call cc-option, -mpreferred-stack-boundary=2)
6594 KBUILD_CFLAGS += $(call cc-option, -m32)
6595+ifdef CONSTIFY_PLUGIN
6596+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6597+endif
6598 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6599 GCOV_PROFILE := n
6600
6601diff -urNp linux-2.6.32.43/arch/x86/boot/memory.c linux-2.6.32.43/arch/x86/boot/memory.c
6602--- linux-2.6.32.43/arch/x86/boot/memory.c 2011-03-27 14:31:47.000000000 -0400
6603+++ linux-2.6.32.43/arch/x86/boot/memory.c 2011-04-17 15:56:46.000000000 -0400
6604@@ -19,7 +19,7 @@
6605
6606 static int detect_memory_e820(void)
6607 {
6608- int count = 0;
6609+ unsigned int count = 0;
6610 struct biosregs ireg, oreg;
6611 struct e820entry *desc = boot_params.e820_map;
6612 static struct e820entry buf; /* static so it is zeroed */
6613diff -urNp linux-2.6.32.43/arch/x86/boot/video.c linux-2.6.32.43/arch/x86/boot/video.c
6614--- linux-2.6.32.43/arch/x86/boot/video.c 2011-03-27 14:31:47.000000000 -0400
6615+++ linux-2.6.32.43/arch/x86/boot/video.c 2011-04-17 15:56:46.000000000 -0400
6616@@ -90,7 +90,7 @@ static void store_mode_params(void)
6617 static unsigned int get_entry(void)
6618 {
6619 char entry_buf[4];
6620- int i, len = 0;
6621+ unsigned int i, len = 0;
6622 int key;
6623 unsigned int v;
6624
6625diff -urNp linux-2.6.32.43/arch/x86/boot/video-vesa.c linux-2.6.32.43/arch/x86/boot/video-vesa.c
6626--- linux-2.6.32.43/arch/x86/boot/video-vesa.c 2011-03-27 14:31:47.000000000 -0400
6627+++ linux-2.6.32.43/arch/x86/boot/video-vesa.c 2011-04-17 15:56:46.000000000 -0400
6628@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6629
6630 boot_params.screen_info.vesapm_seg = oreg.es;
6631 boot_params.screen_info.vesapm_off = oreg.di;
6632+ boot_params.screen_info.vesapm_size = oreg.cx;
6633 }
6634
6635 /*
6636diff -urNp linux-2.6.32.43/arch/x86/ia32/ia32_aout.c linux-2.6.32.43/arch/x86/ia32/ia32_aout.c
6637--- linux-2.6.32.43/arch/x86/ia32/ia32_aout.c 2011-03-27 14:31:47.000000000 -0400
6638+++ linux-2.6.32.43/arch/x86/ia32/ia32_aout.c 2011-04-17 15:56:46.000000000 -0400
6639@@ -169,6 +169,8 @@ static int aout_core_dump(long signr, st
6640 unsigned long dump_start, dump_size;
6641 struct user32 dump;
6642
6643+ memset(&dump, 0, sizeof(dump));
6644+
6645 fs = get_fs();
6646 set_fs(KERNEL_DS);
6647 has_dumped = 1;
6648@@ -218,12 +220,6 @@ static int aout_core_dump(long signr, st
6649 dump_size = dump.u_ssize << PAGE_SHIFT;
6650 DUMP_WRITE(dump_start, dump_size);
6651 }
6652- /*
6653- * Finally dump the task struct. Not be used by gdb, but
6654- * could be useful
6655- */
6656- set_fs(KERNEL_DS);
6657- DUMP_WRITE(current, sizeof(*current));
6658 end_coredump:
6659 set_fs(fs);
6660 return has_dumped;
6661diff -urNp linux-2.6.32.43/arch/x86/ia32/ia32entry.S linux-2.6.32.43/arch/x86/ia32/ia32entry.S
6662--- linux-2.6.32.43/arch/x86/ia32/ia32entry.S 2011-03-27 14:31:47.000000000 -0400
6663+++ linux-2.6.32.43/arch/x86/ia32/ia32entry.S 2011-06-04 20:29:52.000000000 -0400
6664@@ -13,6 +13,7 @@
6665 #include <asm/thread_info.h>
6666 #include <asm/segment.h>
6667 #include <asm/irqflags.h>
6668+#include <asm/pgtable.h>
6669 #include <linux/linkage.h>
6670
6671 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6672@@ -93,6 +94,30 @@ ENTRY(native_irq_enable_sysexit)
6673 ENDPROC(native_irq_enable_sysexit)
6674 #endif
6675
6676+ .macro pax_enter_kernel_user
6677+#ifdef CONFIG_PAX_MEMORY_UDEREF
6678+ call pax_enter_kernel_user
6679+#endif
6680+ .endm
6681+
6682+ .macro pax_exit_kernel_user
6683+#ifdef CONFIG_PAX_MEMORY_UDEREF
6684+ call pax_exit_kernel_user
6685+#endif
6686+#ifdef CONFIG_PAX_RANDKSTACK
6687+ pushq %rax
6688+ call pax_randomize_kstack
6689+ popq %rax
6690+#endif
6691+ pax_erase_kstack
6692+ .endm
6693+
6694+.macro pax_erase_kstack
6695+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
6696+ call pax_erase_kstack
6697+#endif
6698+.endm
6699+
6700 /*
6701 * 32bit SYSENTER instruction entry.
6702 *
6703@@ -119,7 +144,7 @@ ENTRY(ia32_sysenter_target)
6704 CFI_REGISTER rsp,rbp
6705 SWAPGS_UNSAFE_STACK
6706 movq PER_CPU_VAR(kernel_stack), %rsp
6707- addq $(KERNEL_STACK_OFFSET),%rsp
6708+ pax_enter_kernel_user
6709 /*
6710 * No need to follow this irqs on/off section: the syscall
6711 * disabled irqs, here we enable it straight after entry:
6712@@ -135,7 +160,8 @@ ENTRY(ia32_sysenter_target)
6713 pushfq
6714 CFI_ADJUST_CFA_OFFSET 8
6715 /*CFI_REL_OFFSET rflags,0*/
6716- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
6717+ GET_THREAD_INFO(%r10)
6718+ movl TI_sysenter_return(%r10), %r10d
6719 CFI_REGISTER rip,r10
6720 pushq $__USER32_CS
6721 CFI_ADJUST_CFA_OFFSET 8
6722@@ -150,6 +176,12 @@ ENTRY(ia32_sysenter_target)
6723 SAVE_ARGS 0,0,1
6724 /* no need to do an access_ok check here because rbp has been
6725 32bit zero extended */
6726+
6727+#ifdef CONFIG_PAX_MEMORY_UDEREF
6728+ mov $PAX_USER_SHADOW_BASE,%r10
6729+ add %r10,%rbp
6730+#endif
6731+
6732 1: movl (%rbp),%ebp
6733 .section __ex_table,"a"
6734 .quad 1b,ia32_badarg
6735@@ -172,6 +204,7 @@ sysenter_dispatch:
6736 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6737 jnz sysexit_audit
6738 sysexit_from_sys_call:
6739+ pax_exit_kernel_user
6740 andl $~TS_COMPAT,TI_status(%r10)
6741 /* clear IF, that popfq doesn't enable interrupts early */
6742 andl $~0x200,EFLAGS-R11(%rsp)
6743@@ -200,6 +233,9 @@ sysexit_from_sys_call:
6744 movl %eax,%esi /* 2nd arg: syscall number */
6745 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
6746 call audit_syscall_entry
6747+
6748+ pax_erase_kstack
6749+
6750 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
6751 cmpq $(IA32_NR_syscalls-1),%rax
6752 ja ia32_badsys
6753@@ -252,6 +288,9 @@ sysenter_tracesys:
6754 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
6755 movq %rsp,%rdi /* &pt_regs -> arg1 */
6756 call syscall_trace_enter
6757+
6758+ pax_erase_kstack
6759+
6760 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6761 RESTORE_REST
6762 cmpq $(IA32_NR_syscalls-1),%rax
6763@@ -283,19 +322,24 @@ ENDPROC(ia32_sysenter_target)
6764 ENTRY(ia32_cstar_target)
6765 CFI_STARTPROC32 simple
6766 CFI_SIGNAL_FRAME
6767- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
6768+ CFI_DEF_CFA rsp,0
6769 CFI_REGISTER rip,rcx
6770 /*CFI_REGISTER rflags,r11*/
6771 SWAPGS_UNSAFE_STACK
6772 movl %esp,%r8d
6773 CFI_REGISTER rsp,r8
6774 movq PER_CPU_VAR(kernel_stack),%rsp
6775+
6776+#ifdef CONFIG_PAX_MEMORY_UDEREF
6777+ pax_enter_kernel_user
6778+#endif
6779+
6780 /*
6781 * No need to follow this irqs on/off section: the syscall
6782 * disabled irqs and here we enable it straight after entry:
6783 */
6784 ENABLE_INTERRUPTS(CLBR_NONE)
6785- SAVE_ARGS 8,1,1
6786+ SAVE_ARGS 8*6,1,1
6787 movl %eax,%eax /* zero extension */
6788 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
6789 movq %rcx,RIP-ARGOFFSET(%rsp)
6790@@ -311,6 +355,12 @@ ENTRY(ia32_cstar_target)
6791 /* no need to do an access_ok check here because r8 has been
6792 32bit zero extended */
6793 /* hardware stack frame is complete now */
6794+
6795+#ifdef CONFIG_PAX_MEMORY_UDEREF
6796+ mov $PAX_USER_SHADOW_BASE,%r10
6797+ add %r10,%r8
6798+#endif
6799+
6800 1: movl (%r8),%r9d
6801 .section __ex_table,"a"
6802 .quad 1b,ia32_badarg
6803@@ -333,6 +383,7 @@ cstar_dispatch:
6804 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6805 jnz sysretl_audit
6806 sysretl_from_sys_call:
6807+ pax_exit_kernel_user
6808 andl $~TS_COMPAT,TI_status(%r10)
6809 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
6810 movl RIP-ARGOFFSET(%rsp),%ecx
6811@@ -370,6 +421,9 @@ cstar_tracesys:
6812 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6813 movq %rsp,%rdi /* &pt_regs -> arg1 */
6814 call syscall_trace_enter
6815+
6816+ pax_erase_kstack
6817+
6818 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
6819 RESTORE_REST
6820 xchgl %ebp,%r9d
6821@@ -415,6 +469,7 @@ ENTRY(ia32_syscall)
6822 CFI_REL_OFFSET rip,RIP-RIP
6823 PARAVIRT_ADJUST_EXCEPTION_FRAME
6824 SWAPGS
6825+ pax_enter_kernel_user
6826 /*
6827 * No need to follow this irqs on/off section: the syscall
6828 * disabled irqs and here we enable it straight after entry:
6829@@ -448,6 +503,9 @@ ia32_tracesys:
6830 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6831 movq %rsp,%rdi /* &pt_regs -> arg1 */
6832 call syscall_trace_enter
6833+
6834+ pax_erase_kstack
6835+
6836 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6837 RESTORE_REST
6838 cmpq $(IA32_NR_syscalls-1),%rax
6839diff -urNp linux-2.6.32.43/arch/x86/ia32/ia32_signal.c linux-2.6.32.43/arch/x86/ia32/ia32_signal.c
6840--- linux-2.6.32.43/arch/x86/ia32/ia32_signal.c 2011-03-27 14:31:47.000000000 -0400
6841+++ linux-2.6.32.43/arch/x86/ia32/ia32_signal.c 2011-04-17 15:56:46.000000000 -0400
6842@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
6843 sp -= frame_size;
6844 /* Align the stack pointer according to the i386 ABI,
6845 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6846- sp = ((sp + 4) & -16ul) - 4;
6847+ sp = ((sp - 12) & -16ul) - 4;
6848 return (void __user *) sp;
6849 }
6850
6851@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
6852 * These are actually not used anymore, but left because some
6853 * gdb versions depend on them as a marker.
6854 */
6855- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6856+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6857 } put_user_catch(err);
6858
6859 if (err)
6860@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
6861 0xb8,
6862 __NR_ia32_rt_sigreturn,
6863 0x80cd,
6864- 0,
6865+ 0
6866 };
6867
6868 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6869@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
6870
6871 if (ka->sa.sa_flags & SA_RESTORER)
6872 restorer = ka->sa.sa_restorer;
6873+ else if (current->mm->context.vdso)
6874+ /* Return stub is in 32bit vsyscall page */
6875+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6876 else
6877- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6878- rt_sigreturn);
6879+ restorer = &frame->retcode;
6880 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6881
6882 /*
6883 * Not actually used anymore, but left because some gdb
6884 * versions need it.
6885 */
6886- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6887+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6888 } put_user_catch(err);
6889
6890 if (err)
6891diff -urNp linux-2.6.32.43/arch/x86/include/asm/alternative.h linux-2.6.32.43/arch/x86/include/asm/alternative.h
6892--- linux-2.6.32.43/arch/x86/include/asm/alternative.h 2011-03-27 14:31:47.000000000 -0400
6893+++ linux-2.6.32.43/arch/x86/include/asm/alternative.h 2011-04-17 15:56:46.000000000 -0400
6894@@ -85,7 +85,7 @@ static inline void alternatives_smp_swit
6895 " .byte 662b-661b\n" /* sourcelen */ \
6896 " .byte 664f-663f\n" /* replacementlen */ \
6897 ".previous\n" \
6898- ".section .altinstr_replacement, \"ax\"\n" \
6899+ ".section .altinstr_replacement, \"a\"\n" \
6900 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
6901 ".previous"
6902
6903diff -urNp linux-2.6.32.43/arch/x86/include/asm/apm.h linux-2.6.32.43/arch/x86/include/asm/apm.h
6904--- linux-2.6.32.43/arch/x86/include/asm/apm.h 2011-03-27 14:31:47.000000000 -0400
6905+++ linux-2.6.32.43/arch/x86/include/asm/apm.h 2011-04-17 15:56:46.000000000 -0400
6906@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
6907 __asm__ __volatile__(APM_DO_ZERO_SEGS
6908 "pushl %%edi\n\t"
6909 "pushl %%ebp\n\t"
6910- "lcall *%%cs:apm_bios_entry\n\t"
6911+ "lcall *%%ss:apm_bios_entry\n\t"
6912 "setc %%al\n\t"
6913 "popl %%ebp\n\t"
6914 "popl %%edi\n\t"
6915@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
6916 __asm__ __volatile__(APM_DO_ZERO_SEGS
6917 "pushl %%edi\n\t"
6918 "pushl %%ebp\n\t"
6919- "lcall *%%cs:apm_bios_entry\n\t"
6920+ "lcall *%%ss:apm_bios_entry\n\t"
6921 "setc %%bl\n\t"
6922 "popl %%ebp\n\t"
6923 "popl %%edi\n\t"
6924diff -urNp linux-2.6.32.43/arch/x86/include/asm/atomic_32.h linux-2.6.32.43/arch/x86/include/asm/atomic_32.h
6925--- linux-2.6.32.43/arch/x86/include/asm/atomic_32.h 2011-03-27 14:31:47.000000000 -0400
6926+++ linux-2.6.32.43/arch/x86/include/asm/atomic_32.h 2011-05-04 17:56:20.000000000 -0400
6927@@ -25,6 +25,17 @@ static inline int atomic_read(const atom
6928 }
6929
6930 /**
6931+ * atomic_read_unchecked - read atomic variable
6932+ * @v: pointer of type atomic_unchecked_t
6933+ *
6934+ * Atomically reads the value of @v.
6935+ */
6936+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6937+{
6938+ return v->counter;
6939+}
6940+
6941+/**
6942 * atomic_set - set atomic variable
6943 * @v: pointer of type atomic_t
6944 * @i: required value
6945@@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *
6946 }
6947
6948 /**
6949+ * atomic_set_unchecked - set atomic variable
6950+ * @v: pointer of type atomic_unchecked_t
6951+ * @i: required value
6952+ *
6953+ * Atomically sets the value of @v to @i.
6954+ */
6955+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6956+{
6957+ v->counter = i;
6958+}
6959+
6960+/**
6961 * atomic_add - add integer to atomic variable
6962 * @i: integer value to add
6963 * @v: pointer of type atomic_t
6964@@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *
6965 */
6966 static inline void atomic_add(int i, atomic_t *v)
6967 {
6968- asm volatile(LOCK_PREFIX "addl %1,%0"
6969+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6970+
6971+#ifdef CONFIG_PAX_REFCOUNT
6972+ "jno 0f\n"
6973+ LOCK_PREFIX "subl %1,%0\n"
6974+ "int $4\n0:\n"
6975+ _ASM_EXTABLE(0b, 0b)
6976+#endif
6977+
6978+ : "+m" (v->counter)
6979+ : "ir" (i));
6980+}
6981+
6982+/**
6983+ * atomic_add_unchecked - add integer to atomic variable
6984+ * @i: integer value to add
6985+ * @v: pointer of type atomic_unchecked_t
6986+ *
6987+ * Atomically adds @i to @v.
6988+ */
6989+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6990+{
6991+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6992 : "+m" (v->counter)
6993 : "ir" (i));
6994 }
6995@@ -59,7 +104,29 @@ static inline void atomic_add(int i, ato
6996 */
6997 static inline void atomic_sub(int i, atomic_t *v)
6998 {
6999- asm volatile(LOCK_PREFIX "subl %1,%0"
7000+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7001+
7002+#ifdef CONFIG_PAX_REFCOUNT
7003+ "jno 0f\n"
7004+ LOCK_PREFIX "addl %1,%0\n"
7005+ "int $4\n0:\n"
7006+ _ASM_EXTABLE(0b, 0b)
7007+#endif
7008+
7009+ : "+m" (v->counter)
7010+ : "ir" (i));
7011+}
7012+
7013+/**
7014+ * atomic_sub_unchecked - subtract integer from atomic variable
7015+ * @i: integer value to subtract
7016+ * @v: pointer of type atomic_unchecked_t
7017+ *
7018+ * Atomically subtracts @i from @v.
7019+ */
7020+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7021+{
7022+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7023 : "+m" (v->counter)
7024 : "ir" (i));
7025 }
7026@@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(in
7027 {
7028 unsigned char c;
7029
7030- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7031+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
7032+
7033+#ifdef CONFIG_PAX_REFCOUNT
7034+ "jno 0f\n"
7035+ LOCK_PREFIX "addl %2,%0\n"
7036+ "int $4\n0:\n"
7037+ _ASM_EXTABLE(0b, 0b)
7038+#endif
7039+
7040+ "sete %1\n"
7041 : "+m" (v->counter), "=qm" (c)
7042 : "ir" (i) : "memory");
7043 return c;
7044@@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(in
7045 */
7046 static inline void atomic_inc(atomic_t *v)
7047 {
7048- asm volatile(LOCK_PREFIX "incl %0"
7049+ asm volatile(LOCK_PREFIX "incl %0\n"
7050+
7051+#ifdef CONFIG_PAX_REFCOUNT
7052+ "jno 0f\n"
7053+ LOCK_PREFIX "decl %0\n"
7054+ "int $4\n0:\n"
7055+ _ASM_EXTABLE(0b, 0b)
7056+#endif
7057+
7058+ : "+m" (v->counter));
7059+}
7060+
7061+/**
7062+ * atomic_inc_unchecked - increment atomic variable
7063+ * @v: pointer of type atomic_unchecked_t
7064+ *
7065+ * Atomically increments @v by 1.
7066+ */
7067+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7068+{
7069+ asm volatile(LOCK_PREFIX "incl %0\n"
7070 : "+m" (v->counter));
7071 }
7072
7073@@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *
7074 */
7075 static inline void atomic_dec(atomic_t *v)
7076 {
7077- asm volatile(LOCK_PREFIX "decl %0"
7078+ asm volatile(LOCK_PREFIX "decl %0\n"
7079+
7080+#ifdef CONFIG_PAX_REFCOUNT
7081+ "jno 0f\n"
7082+ LOCK_PREFIX "incl %0\n"
7083+ "int $4\n0:\n"
7084+ _ASM_EXTABLE(0b, 0b)
7085+#endif
7086+
7087+ : "+m" (v->counter));
7088+}
7089+
7090+/**
7091+ * atomic_dec_unchecked - decrement atomic variable
7092+ * @v: pointer of type atomic_unchecked_t
7093+ *
7094+ * Atomically decrements @v by 1.
7095+ */
7096+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7097+{
7098+ asm volatile(LOCK_PREFIX "decl %0\n"
7099 : "+m" (v->counter));
7100 }
7101
7102@@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(at
7103 {
7104 unsigned char c;
7105
7106- asm volatile(LOCK_PREFIX "decl %0; sete %1"
7107+ asm volatile(LOCK_PREFIX "decl %0\n"
7108+
7109+#ifdef CONFIG_PAX_REFCOUNT
7110+ "jno 0f\n"
7111+ LOCK_PREFIX "incl %0\n"
7112+ "int $4\n0:\n"
7113+ _ASM_EXTABLE(0b, 0b)
7114+#endif
7115+
7116+ "sete %1\n"
7117 : "+m" (v->counter), "=qm" (c)
7118 : : "memory");
7119 return c != 0;
7120@@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(at
7121 {
7122 unsigned char c;
7123
7124- asm volatile(LOCK_PREFIX "incl %0; sete %1"
7125+ asm volatile(LOCK_PREFIX "incl %0\n"
7126+
7127+#ifdef CONFIG_PAX_REFCOUNT
7128+ "jno 0f\n"
7129+ LOCK_PREFIX "decl %0\n"
7130+ "into\n0:\n"
7131+ _ASM_EXTABLE(0b, 0b)
7132+#endif
7133+
7134+ "sete %1\n"
7135+ : "+m" (v->counter), "=qm" (c)
7136+ : : "memory");
7137+ return c != 0;
7138+}
7139+
7140+/**
7141+ * atomic_inc_and_test_unchecked - increment and test
7142+ * @v: pointer of type atomic_unchecked_t
7143+ *
7144+ * Atomically increments @v by 1
7145+ * and returns true if the result is zero, or false for all
7146+ * other cases.
7147+ */
7148+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7149+{
7150+ unsigned char c;
7151+
7152+ asm volatile(LOCK_PREFIX "incl %0\n"
7153+ "sete %1\n"
7154 : "+m" (v->counter), "=qm" (c)
7155 : : "memory");
7156 return c != 0;
7157@@ -156,7 +309,16 @@ static inline int atomic_add_negative(in
7158 {
7159 unsigned char c;
7160
7161- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7162+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
7163+
7164+#ifdef CONFIG_PAX_REFCOUNT
7165+ "jno 0f\n"
7166+ LOCK_PREFIX "subl %2,%0\n"
7167+ "int $4\n0:\n"
7168+ _ASM_EXTABLE(0b, 0b)
7169+#endif
7170+
7171+ "sets %1\n"
7172 : "+m" (v->counter), "=qm" (c)
7173 : "ir" (i) : "memory");
7174 return c;
7175@@ -179,6 +341,46 @@ static inline int atomic_add_return(int
7176 #endif
7177 /* Modern 486+ processor */
7178 __i = i;
7179+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7180+
7181+#ifdef CONFIG_PAX_REFCOUNT
7182+ "jno 0f\n"
7183+ "movl %0, %1\n"
7184+ "int $4\n0:\n"
7185+ _ASM_EXTABLE(0b, 0b)
7186+#endif
7187+
7188+ : "+r" (i), "+m" (v->counter)
7189+ : : "memory");
7190+ return i + __i;
7191+
7192+#ifdef CONFIG_M386
7193+no_xadd: /* Legacy 386 processor */
7194+ local_irq_save(flags);
7195+ __i = atomic_read(v);
7196+ atomic_set(v, i + __i);
7197+ local_irq_restore(flags);
7198+ return i + __i;
7199+#endif
7200+}
7201+
7202+/**
7203+ * atomic_add_return_unchecked - add integer and return
7204+ * @v: pointer of type atomic_unchecked_t
7205+ * @i: integer value to add
7206+ *
7207+ * Atomically adds @i to @v and returns @i + @v
7208+ */
7209+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7210+{
7211+ int __i;
7212+#ifdef CONFIG_M386
7213+ unsigned long flags;
7214+ if (unlikely(boot_cpu_data.x86 <= 3))
7215+ goto no_xadd;
7216+#endif
7217+ /* Modern 486+ processor */
7218+ __i = i;
7219 asm volatile(LOCK_PREFIX "xaddl %0, %1"
7220 : "+r" (i), "+m" (v->counter)
7221 : : "memory");
7222@@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_
7223 return cmpxchg(&v->counter, old, new);
7224 }
7225
7226+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7227+{
7228+ return cmpxchg(&v->counter, old, new);
7229+}
7230+
7231 static inline int atomic_xchg(atomic_t *v, int new)
7232 {
7233 return xchg(&v->counter, new);
7234 }
7235
7236+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7237+{
7238+ return xchg(&v->counter, new);
7239+}
7240+
7241 /**
7242 * atomic_add_unless - add unless the number is already a given value
7243 * @v: pointer of type atomic_t
7244@@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *
7245 */
7246 static inline int atomic_add_unless(atomic_t *v, int a, int u)
7247 {
7248- int c, old;
7249+ int c, old, new;
7250 c = atomic_read(v);
7251 for (;;) {
7252- if (unlikely(c == (u)))
7253+ if (unlikely(c == u))
7254 break;
7255- old = atomic_cmpxchg((v), c, c + (a));
7256+
7257+ asm volatile("addl %2,%0\n"
7258+
7259+#ifdef CONFIG_PAX_REFCOUNT
7260+ "jno 0f\n"
7261+ "subl %2,%0\n"
7262+ "int $4\n0:\n"
7263+ _ASM_EXTABLE(0b, 0b)
7264+#endif
7265+
7266+ : "=r" (new)
7267+ : "0" (c), "ir" (a));
7268+
7269+ old = atomic_cmpxchg(v, c, new);
7270 if (likely(old == c))
7271 break;
7272 c = old;
7273 }
7274- return c != (u);
7275+ return c != u;
7276 }
7277
7278 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
7279
7280 #define atomic_inc_return(v) (atomic_add_return(1, v))
7281+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7282+{
7283+ return atomic_add_return_unchecked(1, v);
7284+}
7285 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7286
7287 /* These are x86-specific, used by some header files */
7288@@ -266,9 +495,18 @@ typedef struct {
7289 u64 __aligned(8) counter;
7290 } atomic64_t;
7291
7292+#ifdef CONFIG_PAX_REFCOUNT
7293+typedef struct {
7294+ u64 __aligned(8) counter;
7295+} atomic64_unchecked_t;
7296+#else
7297+typedef atomic64_t atomic64_unchecked_t;
7298+#endif
7299+
7300 #define ATOMIC64_INIT(val) { (val) }
7301
7302 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
7303+extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
7304
7305 /**
7306 * atomic64_xchg - xchg atomic64 variable
7307@@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *
7308 * the old value.
7309 */
7310 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
7311+extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
7312
7313 /**
7314 * atomic64_set - set atomic64 variable
7315@@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr
7316 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
7317
7318 /**
7319+ * atomic64_unchecked_set - set atomic64 variable
7320+ * @ptr: pointer to type atomic64_unchecked_t
7321+ * @new_val: value to assign
7322+ *
7323+ * Atomically sets the value of @ptr to @new_val.
7324+ */
7325+extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
7326+
7327+/**
7328 * atomic64_read - read atomic64 variable
7329 * @ptr: pointer to type atomic64_t
7330 *
7331@@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64
7332 return res;
7333 }
7334
7335-extern u64 atomic64_read(atomic64_t *ptr);
7336+/**
7337+ * atomic64_read_unchecked - read atomic64 variable
7338+ * @ptr: pointer to type atomic64_unchecked_t
7339+ *
7340+ * Atomically reads the value of @ptr and returns it.
7341+ */
7342+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
7343+{
7344+ u64 res;
7345+
7346+ /*
7347+ * Note, we inline this atomic64_unchecked_t primitive because
7348+ * it only clobbers EAX/EDX and leaves the others
7349+ * untouched. We also (somewhat subtly) rely on the
7350+ * fact that cmpxchg8b returns the current 64-bit value
7351+ * of the memory location we are touching:
7352+ */
7353+ asm volatile(
7354+ "mov %%ebx, %%eax\n\t"
7355+ "mov %%ecx, %%edx\n\t"
7356+ LOCK_PREFIX "cmpxchg8b %1\n"
7357+ : "=&A" (res)
7358+ : "m" (*ptr)
7359+ );
7360+
7361+ return res;
7362+}
7363
7364 /**
7365 * atomic64_add_return - add and return
7366@@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta
7367 * Other variants with different arithmetic operators:
7368 */
7369 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
7370+extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7371 extern u64 atomic64_inc_return(atomic64_t *ptr);
7372+extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
7373 extern u64 atomic64_dec_return(atomic64_t *ptr);
7374+extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
7375
7376 /**
7377 * atomic64_add - add integer to atomic64 variable
7378@@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_
7379 extern void atomic64_add(u64 delta, atomic64_t *ptr);
7380
7381 /**
7382+ * atomic64_add_unchecked - add integer to atomic64 variable
7383+ * @delta: integer value to add
7384+ * @ptr: pointer to type atomic64_unchecked_t
7385+ *
7386+ * Atomically adds @delta to @ptr.
7387+ */
7388+extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7389+
7390+/**
7391 * atomic64_sub - subtract the atomic64 variable
7392 * @delta: integer value to subtract
7393 * @ptr: pointer to type atomic64_t
7394@@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atom
7395 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
7396
7397 /**
7398+ * atomic64_sub_unchecked - subtract the atomic64 variable
7399+ * @delta: integer value to subtract
7400+ * @ptr: pointer to type atomic64_unchecked_t
7401+ *
7402+ * Atomically subtracts @delta from @ptr.
7403+ */
7404+extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7405+
7406+/**
7407 * atomic64_sub_and_test - subtract value from variable and test result
7408 * @delta: integer value to subtract
7409 * @ptr: pointer to type atomic64_t
7410@@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 del
7411 extern void atomic64_inc(atomic64_t *ptr);
7412
7413 /**
7414+ * atomic64_inc_unchecked - increment atomic64 variable
7415+ * @ptr: pointer to type atomic64_unchecked_t
7416+ *
7417+ * Atomically increments @ptr by 1.
7418+ */
7419+extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
7420+
7421+/**
7422 * atomic64_dec - decrement atomic64 variable
7423 * @ptr: pointer to type atomic64_t
7424 *
7425@@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr
7426 extern void atomic64_dec(atomic64_t *ptr);
7427
7428 /**
7429+ * atomic64_dec_unchecked - decrement atomic64 variable
7430+ * @ptr: pointer to type atomic64_unchecked_t
7431+ *
7432+ * Atomically decrements @ptr by 1.
7433+ */
7434+extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
7435+
7436+/**
7437 * atomic64_dec_and_test - decrement and test
7438 * @ptr: pointer to type atomic64_t
7439 *
7440diff -urNp linux-2.6.32.43/arch/x86/include/asm/atomic_64.h linux-2.6.32.43/arch/x86/include/asm/atomic_64.h
7441--- linux-2.6.32.43/arch/x86/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
7442+++ linux-2.6.32.43/arch/x86/include/asm/atomic_64.h 2011-05-04 18:35:31.000000000 -0400
7443@@ -24,6 +24,17 @@ static inline int atomic_read(const atom
7444 }
7445
7446 /**
7447+ * atomic_read_unchecked - read atomic variable
7448+ * @v: pointer of type atomic_unchecked_t
7449+ *
7450+ * Atomically reads the value of @v.
7451+ */
7452+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7453+{
7454+ return v->counter;
7455+}
7456+
7457+/**
7458 * atomic_set - set atomic variable
7459 * @v: pointer of type atomic_t
7460 * @i: required value
7461@@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *
7462 }
7463
7464 /**
7465+ * atomic_set_unchecked - set atomic variable
7466+ * @v: pointer of type atomic_unchecked_t
7467+ * @i: required value
7468+ *
7469+ * Atomically sets the value of @v to @i.
7470+ */
7471+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7472+{
7473+ v->counter = i;
7474+}
7475+
7476+/**
7477 * atomic_add - add integer to atomic variable
7478 * @i: integer value to add
7479 * @v: pointer of type atomic_t
7480@@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *
7481 */
7482 static inline void atomic_add(int i, atomic_t *v)
7483 {
7484- asm volatile(LOCK_PREFIX "addl %1,%0"
7485+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7486+
7487+#ifdef CONFIG_PAX_REFCOUNT
7488+ "jno 0f\n"
7489+ LOCK_PREFIX "subl %1,%0\n"
7490+ "int $4\n0:\n"
7491+ _ASM_EXTABLE(0b, 0b)
7492+#endif
7493+
7494+ : "=m" (v->counter)
7495+ : "ir" (i), "m" (v->counter));
7496+}
7497+
7498+/**
7499+ * atomic_add_unchecked - add integer to atomic variable
7500+ * @i: integer value to add
7501+ * @v: pointer of type atomic_unchecked_t
7502+ *
7503+ * Atomically adds @i to @v.
7504+ */
7505+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7506+{
7507+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7508 : "=m" (v->counter)
7509 : "ir" (i), "m" (v->counter));
7510 }
7511@@ -58,7 +103,29 @@ static inline void atomic_add(int i, ato
7512 */
7513 static inline void atomic_sub(int i, atomic_t *v)
7514 {
7515- asm volatile(LOCK_PREFIX "subl %1,%0"
7516+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7517+
7518+#ifdef CONFIG_PAX_REFCOUNT
7519+ "jno 0f\n"
7520+ LOCK_PREFIX "addl %1,%0\n"
7521+ "int $4\n0:\n"
7522+ _ASM_EXTABLE(0b, 0b)
7523+#endif
7524+
7525+ : "=m" (v->counter)
7526+ : "ir" (i), "m" (v->counter));
7527+}
7528+
7529+/**
7530+ * atomic_sub_unchecked - subtract the atomic variable
7531+ * @i: integer value to subtract
7532+ * @v: pointer of type atomic_unchecked_t
7533+ *
7534+ * Atomically subtracts @i from @v.
7535+ */
7536+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7537+{
7538+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7539 : "=m" (v->counter)
7540 : "ir" (i), "m" (v->counter));
7541 }
7542@@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(in
7543 {
7544 unsigned char c;
7545
7546- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7547+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
7548+
7549+#ifdef CONFIG_PAX_REFCOUNT
7550+ "jno 0f\n"
7551+ LOCK_PREFIX "addl %2,%0\n"
7552+ "int $4\n0:\n"
7553+ _ASM_EXTABLE(0b, 0b)
7554+#endif
7555+
7556+ "sete %1\n"
7557 : "=m" (v->counter), "=qm" (c)
7558 : "ir" (i), "m" (v->counter) : "memory");
7559 return c;
7560@@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(in
7561 */
7562 static inline void atomic_inc(atomic_t *v)
7563 {
7564- asm volatile(LOCK_PREFIX "incl %0"
7565+ asm volatile(LOCK_PREFIX "incl %0\n"
7566+
7567+#ifdef CONFIG_PAX_REFCOUNT
7568+ "jno 0f\n"
7569+ LOCK_PREFIX "decl %0\n"
7570+ "int $4\n0:\n"
7571+ _ASM_EXTABLE(0b, 0b)
7572+#endif
7573+
7574+ : "=m" (v->counter)
7575+ : "m" (v->counter));
7576+}
7577+
7578+/**
7579+ * atomic_inc_unchecked - increment atomic variable
7580+ * @v: pointer of type atomic_unchecked_t
7581+ *
7582+ * Atomically increments @v by 1.
7583+ */
7584+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7585+{
7586+ asm volatile(LOCK_PREFIX "incl %0\n"
7587 : "=m" (v->counter)
7588 : "m" (v->counter));
7589 }
7590@@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *
7591 */
7592 static inline void atomic_dec(atomic_t *v)
7593 {
7594- asm volatile(LOCK_PREFIX "decl %0"
7595+ asm volatile(LOCK_PREFIX "decl %0\n"
7596+
7597+#ifdef CONFIG_PAX_REFCOUNT
7598+ "jno 0f\n"
7599+ LOCK_PREFIX "incl %0\n"
7600+ "int $4\n0:\n"
7601+ _ASM_EXTABLE(0b, 0b)
7602+#endif
7603+
7604+ : "=m" (v->counter)
7605+ : "m" (v->counter));
7606+}
7607+
7608+/**
7609+ * atomic_dec_unchecked - decrement atomic variable
7610+ * @v: pointer of type atomic_unchecked_t
7611+ *
7612+ * Atomically decrements @v by 1.
7613+ */
7614+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7615+{
7616+ asm volatile(LOCK_PREFIX "decl %0\n"
7617 : "=m" (v->counter)
7618 : "m" (v->counter));
7619 }
7620@@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(at
7621 {
7622 unsigned char c;
7623
7624- asm volatile(LOCK_PREFIX "decl %0; sete %1"
7625+ asm volatile(LOCK_PREFIX "decl %0\n"
7626+
7627+#ifdef CONFIG_PAX_REFCOUNT
7628+ "jno 0f\n"
7629+ LOCK_PREFIX "incl %0\n"
7630+ "int $4\n0:\n"
7631+ _ASM_EXTABLE(0b, 0b)
7632+#endif
7633+
7634+ "sete %1\n"
7635 : "=m" (v->counter), "=qm" (c)
7636 : "m" (v->counter) : "memory");
7637 return c != 0;
7638@@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(at
7639 {
7640 unsigned char c;
7641
7642- asm volatile(LOCK_PREFIX "incl %0; sete %1"
7643+ asm volatile(LOCK_PREFIX "incl %0\n"
7644+
7645+#ifdef CONFIG_PAX_REFCOUNT
7646+ "jno 0f\n"
7647+ LOCK_PREFIX "decl %0\n"
7648+ "int $4\n0:\n"
7649+ _ASM_EXTABLE(0b, 0b)
7650+#endif
7651+
7652+ "sete %1\n"
7653+ : "=m" (v->counter), "=qm" (c)
7654+ : "m" (v->counter) : "memory");
7655+ return c != 0;
7656+}
7657+
7658+/**
7659+ * atomic_inc_and_test_unchecked - increment and test
7660+ * @v: pointer of type atomic_unchecked_t
7661+ *
7662+ * Atomically increments @v by 1
7663+ * and returns true if the result is zero, or false for all
7664+ * other cases.
7665+ */
7666+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7667+{
7668+ unsigned char c;
7669+
7670+ asm volatile(LOCK_PREFIX "incl %0\n"
7671+ "sete %1\n"
7672 : "=m" (v->counter), "=qm" (c)
7673 : "m" (v->counter) : "memory");
7674 return c != 0;
7675@@ -157,7 +312,16 @@ static inline int atomic_add_negative(in
7676 {
7677 unsigned char c;
7678
7679- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7680+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
7681+
7682+#ifdef CONFIG_PAX_REFCOUNT
7683+ "jno 0f\n"
7684+ LOCK_PREFIX "subl %2,%0\n"
7685+ "int $4\n0:\n"
7686+ _ASM_EXTABLE(0b, 0b)
7687+#endif
7688+
7689+ "sets %1\n"
7690 : "=m" (v->counter), "=qm" (c)
7691 : "ir" (i), "m" (v->counter) : "memory");
7692 return c;
7693@@ -173,7 +337,31 @@ static inline int atomic_add_negative(in
7694 static inline int atomic_add_return(int i, atomic_t *v)
7695 {
7696 int __i = i;
7697- asm volatile(LOCK_PREFIX "xaddl %0, %1"
7698+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7699+
7700+#ifdef CONFIG_PAX_REFCOUNT
7701+ "jno 0f\n"
7702+ "movl %0, %1\n"
7703+ "int $4\n0:\n"
7704+ _ASM_EXTABLE(0b, 0b)
7705+#endif
7706+
7707+ : "+r" (i), "+m" (v->counter)
7708+ : : "memory");
7709+ return i + __i;
7710+}
7711+
7712+/**
7713+ * atomic_add_return_unchecked - add and return
7714+ * @i: integer value to add
7715+ * @v: pointer of type atomic_unchecked_t
7716+ *
7717+ * Atomically adds @i to @v and returns @i + @v
7718+ */
7719+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7720+{
7721+ int __i = i;
7722+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7723 : "+r" (i), "+m" (v->counter)
7724 : : "memory");
7725 return i + __i;
7726@@ -185,6 +373,10 @@ static inline int atomic_sub_return(int
7727 }
7728
7729 #define atomic_inc_return(v) (atomic_add_return(1, v))
7730+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7731+{
7732+ return atomic_add_return_unchecked(1, v);
7733+}
7734 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7735
7736 /* The 64-bit atomic type */
7737@@ -204,6 +396,18 @@ static inline long atomic64_read(const a
7738 }
7739
7740 /**
7741+ * atomic64_read_unchecked - read atomic64 variable
7742+ * @v: pointer of type atomic64_unchecked_t
7743+ *
7744+ * Atomically reads the value of @v.
7745+ * Doesn't imply a read memory barrier.
7746+ */
7747+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7748+{
7749+ return v->counter;
7750+}
7751+
7752+/**
7753 * atomic64_set - set atomic64 variable
7754 * @v: pointer to type atomic64_t
7755 * @i: required value
7756@@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64
7757 }
7758
7759 /**
7760+ * atomic64_set_unchecked - set atomic64 variable
7761+ * @v: pointer to type atomic64_unchecked_t
7762+ * @i: required value
7763+ *
7764+ * Atomically sets the value of @v to @i.
7765+ */
7766+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7767+{
7768+ v->counter = i;
7769+}
7770+
7771+/**
7772 * atomic64_add - add integer to atomic64 variable
7773 * @i: integer value to add
7774 * @v: pointer to type atomic64_t
7775@@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64
7776 */
7777 static inline void atomic64_add(long i, atomic64_t *v)
7778 {
7779+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
7780+
7781+#ifdef CONFIG_PAX_REFCOUNT
7782+ "jno 0f\n"
7783+ LOCK_PREFIX "subq %1,%0\n"
7784+ "int $4\n0:\n"
7785+ _ASM_EXTABLE(0b, 0b)
7786+#endif
7787+
7788+ : "=m" (v->counter)
7789+ : "er" (i), "m" (v->counter));
7790+}
7791+
7792+/**
7793+ * atomic64_add_unchecked - add integer to atomic64 variable
7794+ * @i: integer value to add
7795+ * @v: pointer to type atomic64_unchecked_t
7796+ *
7797+ * Atomically adds @i to @v.
7798+ */
7799+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
7800+{
7801 asm volatile(LOCK_PREFIX "addq %1,%0"
7802 : "=m" (v->counter)
7803 : "er" (i), "m" (v->counter));
7804@@ -238,7 +476,15 @@ static inline void atomic64_add(long i,
7805 */
7806 static inline void atomic64_sub(long i, atomic64_t *v)
7807 {
7808- asm volatile(LOCK_PREFIX "subq %1,%0"
7809+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
7810+
7811+#ifdef CONFIG_PAX_REFCOUNT
7812+ "jno 0f\n"
7813+ LOCK_PREFIX "addq %1,%0\n"
7814+ "int $4\n0:\n"
7815+ _ASM_EXTABLE(0b, 0b)
7816+#endif
7817+
7818 : "=m" (v->counter)
7819 : "er" (i), "m" (v->counter));
7820 }
7821@@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(
7822 {
7823 unsigned char c;
7824
7825- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
7826+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
7827+
7828+#ifdef CONFIG_PAX_REFCOUNT
7829+ "jno 0f\n"
7830+ LOCK_PREFIX "addq %2,%0\n"
7831+ "int $4\n0:\n"
7832+ _ASM_EXTABLE(0b, 0b)
7833+#endif
7834+
7835+ "sete %1\n"
7836 : "=m" (v->counter), "=qm" (c)
7837 : "er" (i), "m" (v->counter) : "memory");
7838 return c;
7839@@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(
7840 */
7841 static inline void atomic64_inc(atomic64_t *v)
7842 {
7843+ asm volatile(LOCK_PREFIX "incq %0\n"
7844+
7845+#ifdef CONFIG_PAX_REFCOUNT
7846+ "jno 0f\n"
7847+ LOCK_PREFIX "decq %0\n"
7848+ "int $4\n0:\n"
7849+ _ASM_EXTABLE(0b, 0b)
7850+#endif
7851+
7852+ : "=m" (v->counter)
7853+ : "m" (v->counter));
7854+}
7855+
7856+/**
7857+ * atomic64_inc_unchecked - increment atomic64 variable
7858+ * @v: pointer to type atomic64_unchecked_t
7859+ *
7860+ * Atomically increments @v by 1.
7861+ */
7862+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7863+{
7864 asm volatile(LOCK_PREFIX "incq %0"
7865 : "=m" (v->counter)
7866 : "m" (v->counter));
7867@@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64
7868 */
7869 static inline void atomic64_dec(atomic64_t *v)
7870 {
7871- asm volatile(LOCK_PREFIX "decq %0"
7872+ asm volatile(LOCK_PREFIX "decq %0\n"
7873+
7874+#ifdef CONFIG_PAX_REFCOUNT
7875+ "jno 0f\n"
7876+ LOCK_PREFIX "incq %0\n"
7877+ "int $4\n0:\n"
7878+ _ASM_EXTABLE(0b, 0b)
7879+#endif
7880+
7881+ : "=m" (v->counter)
7882+ : "m" (v->counter));
7883+}
7884+
7885+/**
7886+ * atomic64_dec_unchecked - decrement atomic64 variable
7887+ * @v: pointer to type atomic64_t
7888+ *
7889+ * Atomically decrements @v by 1.
7890+ */
7891+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7892+{
7893+ asm volatile(LOCK_PREFIX "decq %0\n"
7894 : "=m" (v->counter)
7895 : "m" (v->counter));
7896 }
7897@@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(
7898 {
7899 unsigned char c;
7900
7901- asm volatile(LOCK_PREFIX "decq %0; sete %1"
7902+ asm volatile(LOCK_PREFIX "decq %0\n"
7903+
7904+#ifdef CONFIG_PAX_REFCOUNT
7905+ "jno 0f\n"
7906+ LOCK_PREFIX "incq %0\n"
7907+ "int $4\n0:\n"
7908+ _ASM_EXTABLE(0b, 0b)
7909+#endif
7910+
7911+ "sete %1\n"
7912 : "=m" (v->counter), "=qm" (c)
7913 : "m" (v->counter) : "memory");
7914 return c != 0;
7915@@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(
7916 {
7917 unsigned char c;
7918
7919- asm volatile(LOCK_PREFIX "incq %0; sete %1"
7920+ asm volatile(LOCK_PREFIX "incq %0\n"
7921+
7922+#ifdef CONFIG_PAX_REFCOUNT
7923+ "jno 0f\n"
7924+ LOCK_PREFIX "decq %0\n"
7925+ "int $4\n0:\n"
7926+ _ASM_EXTABLE(0b, 0b)
7927+#endif
7928+
7929+ "sete %1\n"
7930 : "=m" (v->counter), "=qm" (c)
7931 : "m" (v->counter) : "memory");
7932 return c != 0;
7933@@ -337,7 +652,16 @@ static inline int atomic64_add_negative(
7934 {
7935 unsigned char c;
7936
7937- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
7938+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
7939+
7940+#ifdef CONFIG_PAX_REFCOUNT
7941+ "jno 0f\n"
7942+ LOCK_PREFIX "subq %2,%0\n"
7943+ "int $4\n0:\n"
7944+ _ASM_EXTABLE(0b, 0b)
7945+#endif
7946+
7947+ "sets %1\n"
7948 : "=m" (v->counter), "=qm" (c)
7949 : "er" (i), "m" (v->counter) : "memory");
7950 return c;
7951@@ -353,7 +677,31 @@ static inline int atomic64_add_negative(
7952 static inline long atomic64_add_return(long i, atomic64_t *v)
7953 {
7954 long __i = i;
7955- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
7956+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
7957+
7958+#ifdef CONFIG_PAX_REFCOUNT
7959+ "jno 0f\n"
7960+ "movq %0, %1\n"
7961+ "int $4\n0:\n"
7962+ _ASM_EXTABLE(0b, 0b)
7963+#endif
7964+
7965+ : "+r" (i), "+m" (v->counter)
7966+ : : "memory");
7967+ return i + __i;
7968+}
7969+
7970+/**
7971+ * atomic64_add_return_unchecked - add and return
7972+ * @i: integer value to add
7973+ * @v: pointer to type atomic64_unchecked_t
7974+ *
7975+ * Atomically adds @i to @v and returns @i + @v
7976+ */
7977+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7978+{
7979+ long __i = i;
7980+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
7981 : "+r" (i), "+m" (v->counter)
7982 : : "memory");
7983 return i + __i;
7984@@ -365,6 +713,10 @@ static inline long atomic64_sub_return(l
7985 }
7986
7987 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
7988+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7989+{
7990+ return atomic64_add_return_unchecked(1, v);
7991+}
7992 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
7993
7994 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7995@@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atom
7996 return cmpxchg(&v->counter, old, new);
7997 }
7998
7999+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8000+{
8001+ return cmpxchg(&v->counter, old, new);
8002+}
8003+
8004 static inline long atomic64_xchg(atomic64_t *v, long new)
8005 {
8006 return xchg(&v->counter, new);
8007 }
8008
8009+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8010+{
8011+ return xchg(&v->counter, new);
8012+}
8013+
8014 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
8015 {
8016 return cmpxchg(&v->counter, old, new);
8017 }
8018
8019+static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8020+{
8021+ return cmpxchg(&v->counter, old, new);
8022+}
8023+
8024 static inline long atomic_xchg(atomic_t *v, int new)
8025 {
8026 return xchg(&v->counter, new);
8027 }
8028
8029+static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8030+{
8031+ return xchg(&v->counter, new);
8032+}
8033+
8034 /**
8035 * atomic_add_unless - add unless the number is a given value
8036 * @v: pointer of type atomic_t
8037@@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t
8038 */
8039 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8040 {
8041- int c, old;
8042+ int c, old, new;
8043 c = atomic_read(v);
8044 for (;;) {
8045- if (unlikely(c == (u)))
8046+ if (unlikely(c == u))
8047 break;
8048- old = atomic_cmpxchg((v), c, c + (a));
8049+
8050+ asm volatile("addl %2,%0\n"
8051+
8052+#ifdef CONFIG_PAX_REFCOUNT
8053+ "jno 0f\n"
8054+ "subl %2,%0\n"
8055+ "int $4\n0:\n"
8056+ _ASM_EXTABLE(0b, 0b)
8057+#endif
8058+
8059+ : "=r" (new)
8060+ : "0" (c), "ir" (a));
8061+
8062+ old = atomic_cmpxchg(v, c, new);
8063 if (likely(old == c))
8064 break;
8065 c = old;
8066 }
8067- return c != (u);
8068+ return c != u;
8069 }
8070
8071 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8072@@ -424,17 +809,30 @@ static inline int atomic_add_unless(atom
8073 */
8074 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8075 {
8076- long c, old;
8077+ long c, old, new;
8078 c = atomic64_read(v);
8079 for (;;) {
8080- if (unlikely(c == (u)))
8081+ if (unlikely(c == u))
8082 break;
8083- old = atomic64_cmpxchg((v), c, c + (a));
8084+
8085+ asm volatile("addq %2,%0\n"
8086+
8087+#ifdef CONFIG_PAX_REFCOUNT
8088+ "jno 0f\n"
8089+ "subq %2,%0\n"
8090+ "int $4\n0:\n"
8091+ _ASM_EXTABLE(0b, 0b)
8092+#endif
8093+
8094+ : "=r" (new)
8095+ : "0" (c), "er" (a));
8096+
8097+ old = atomic64_cmpxchg(v, c, new);
8098 if (likely(old == c))
8099 break;
8100 c = old;
8101 }
8102- return c != (u);
8103+ return c != u;
8104 }
8105
8106 /**
8107diff -urNp linux-2.6.32.43/arch/x86/include/asm/bitops.h linux-2.6.32.43/arch/x86/include/asm/bitops.h
8108--- linux-2.6.32.43/arch/x86/include/asm/bitops.h 2011-03-27 14:31:47.000000000 -0400
8109+++ linux-2.6.32.43/arch/x86/include/asm/bitops.h 2011-04-17 15:56:46.000000000 -0400
8110@@ -38,7 +38,7 @@
8111 * a mask operation on a byte.
8112 */
8113 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8114-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8115+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8116 #define CONST_MASK(nr) (1 << ((nr) & 7))
8117
8118 /**
8119diff -urNp linux-2.6.32.43/arch/x86/include/asm/boot.h linux-2.6.32.43/arch/x86/include/asm/boot.h
8120--- linux-2.6.32.43/arch/x86/include/asm/boot.h 2011-03-27 14:31:47.000000000 -0400
8121+++ linux-2.6.32.43/arch/x86/include/asm/boot.h 2011-04-17 15:56:46.000000000 -0400
8122@@ -11,10 +11,15 @@
8123 #include <asm/pgtable_types.h>
8124
8125 /* Physical address where kernel should be loaded. */
8126-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8127+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8128 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8129 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8130
8131+#ifndef __ASSEMBLY__
8132+extern unsigned char __LOAD_PHYSICAL_ADDR[];
8133+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8134+#endif
8135+
8136 /* Minimum kernel alignment, as a power of two */
8137 #ifdef CONFIG_X86_64
8138 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8139diff -urNp linux-2.6.32.43/arch/x86/include/asm/cacheflush.h linux-2.6.32.43/arch/x86/include/asm/cacheflush.h
8140--- linux-2.6.32.43/arch/x86/include/asm/cacheflush.h 2011-03-27 14:31:47.000000000 -0400
8141+++ linux-2.6.32.43/arch/x86/include/asm/cacheflush.h 2011-04-17 15:56:46.000000000 -0400
8142@@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
8143 static inline unsigned long get_page_memtype(struct page *pg)
8144 {
8145 if (!PageUncached(pg) && !PageWC(pg))
8146- return -1;
8147+ return ~0UL;
8148 else if (!PageUncached(pg) && PageWC(pg))
8149 return _PAGE_CACHE_WC;
8150 else if (PageUncached(pg) && !PageWC(pg))
8151@@ -85,7 +85,7 @@ static inline void set_page_memtype(stru
8152 SetPageWC(pg);
8153 break;
8154 default:
8155- case -1:
8156+ case ~0UL:
8157 ClearPageUncached(pg);
8158 ClearPageWC(pg);
8159 break;
8160diff -urNp linux-2.6.32.43/arch/x86/include/asm/cache.h linux-2.6.32.43/arch/x86/include/asm/cache.h
8161--- linux-2.6.32.43/arch/x86/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
8162+++ linux-2.6.32.43/arch/x86/include/asm/cache.h 2011-07-06 19:53:33.000000000 -0400
8163@@ -5,9 +5,10 @@
8164
8165 /* L1 cache line size */
8166 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8167-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8168+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8169
8170 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
8171+#define __read_only __attribute__((__section__(".data.read_only")))
8172
8173 #ifdef CONFIG_X86_VSMP
8174 /* vSMP Internode cacheline shift */
8175diff -urNp linux-2.6.32.43/arch/x86/include/asm/checksum_32.h linux-2.6.32.43/arch/x86/include/asm/checksum_32.h
8176--- linux-2.6.32.43/arch/x86/include/asm/checksum_32.h 2011-03-27 14:31:47.000000000 -0400
8177+++ linux-2.6.32.43/arch/x86/include/asm/checksum_32.h 2011-04-17 15:56:46.000000000 -0400
8178@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
8179 int len, __wsum sum,
8180 int *src_err_ptr, int *dst_err_ptr);
8181
8182+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
8183+ int len, __wsum sum,
8184+ int *src_err_ptr, int *dst_err_ptr);
8185+
8186+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
8187+ int len, __wsum sum,
8188+ int *src_err_ptr, int *dst_err_ptr);
8189+
8190 /*
8191 * Note: when you get a NULL pointer exception here this means someone
8192 * passed in an incorrect kernel address to one of these functions.
8193@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
8194 int *err_ptr)
8195 {
8196 might_sleep();
8197- return csum_partial_copy_generic((__force void *)src, dst,
8198+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
8199 len, sum, err_ptr, NULL);
8200 }
8201
8202@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
8203 {
8204 might_sleep();
8205 if (access_ok(VERIFY_WRITE, dst, len))
8206- return csum_partial_copy_generic(src, (__force void *)dst,
8207+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
8208 len, sum, NULL, err_ptr);
8209
8210 if (len)
8211diff -urNp linux-2.6.32.43/arch/x86/include/asm/desc_defs.h linux-2.6.32.43/arch/x86/include/asm/desc_defs.h
8212--- linux-2.6.32.43/arch/x86/include/asm/desc_defs.h 2011-03-27 14:31:47.000000000 -0400
8213+++ linux-2.6.32.43/arch/x86/include/asm/desc_defs.h 2011-04-17 15:56:46.000000000 -0400
8214@@ -31,6 +31,12 @@ struct desc_struct {
8215 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
8216 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
8217 };
8218+ struct {
8219+ u16 offset_low;
8220+ u16 seg;
8221+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
8222+ unsigned offset_high: 16;
8223+ } gate;
8224 };
8225 } __attribute__((packed));
8226
8227diff -urNp linux-2.6.32.43/arch/x86/include/asm/desc.h linux-2.6.32.43/arch/x86/include/asm/desc.h
8228--- linux-2.6.32.43/arch/x86/include/asm/desc.h 2011-03-27 14:31:47.000000000 -0400
8229+++ linux-2.6.32.43/arch/x86/include/asm/desc.h 2011-04-23 12:56:10.000000000 -0400
8230@@ -4,6 +4,7 @@
8231 #include <asm/desc_defs.h>
8232 #include <asm/ldt.h>
8233 #include <asm/mmu.h>
8234+#include <asm/pgtable.h>
8235 #include <linux/smp.h>
8236
8237 static inline void fill_ldt(struct desc_struct *desc,
8238@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
8239 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
8240 desc->type = (info->read_exec_only ^ 1) << 1;
8241 desc->type |= info->contents << 2;
8242+ desc->type |= info->seg_not_present ^ 1;
8243 desc->s = 1;
8244 desc->dpl = 0x3;
8245 desc->p = info->seg_not_present ^ 1;
8246@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
8247 }
8248
8249 extern struct desc_ptr idt_descr;
8250-extern gate_desc idt_table[];
8251-
8252-struct gdt_page {
8253- struct desc_struct gdt[GDT_ENTRIES];
8254-} __attribute__((aligned(PAGE_SIZE)));
8255-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
8256+extern gate_desc idt_table[256];
8257
8258+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
8259 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
8260 {
8261- return per_cpu(gdt_page, cpu).gdt;
8262+ return cpu_gdt_table[cpu];
8263 }
8264
8265 #ifdef CONFIG_X86_64
8266@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
8267 unsigned long base, unsigned dpl, unsigned flags,
8268 unsigned short seg)
8269 {
8270- gate->a = (seg << 16) | (base & 0xffff);
8271- gate->b = (base & 0xffff0000) |
8272- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
8273+ gate->gate.offset_low = base;
8274+ gate->gate.seg = seg;
8275+ gate->gate.reserved = 0;
8276+ gate->gate.type = type;
8277+ gate->gate.s = 0;
8278+ gate->gate.dpl = dpl;
8279+ gate->gate.p = 1;
8280+ gate->gate.offset_high = base >> 16;
8281 }
8282
8283 #endif
8284@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
8285 static inline void native_write_idt_entry(gate_desc *idt, int entry,
8286 const gate_desc *gate)
8287 {
8288+ pax_open_kernel();
8289 memcpy(&idt[entry], gate, sizeof(*gate));
8290+ pax_close_kernel();
8291 }
8292
8293 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
8294 const void *desc)
8295 {
8296+ pax_open_kernel();
8297 memcpy(&ldt[entry], desc, 8);
8298+ pax_close_kernel();
8299 }
8300
8301 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
8302@@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
8303 size = sizeof(struct desc_struct);
8304 break;
8305 }
8306+
8307+ pax_open_kernel();
8308 memcpy(&gdt[entry], desc, size);
8309+ pax_close_kernel();
8310 }
8311
8312 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
8313@@ -211,7 +221,9 @@ static inline void native_set_ldt(const
8314
8315 static inline void native_load_tr_desc(void)
8316 {
8317+ pax_open_kernel();
8318 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
8319+ pax_close_kernel();
8320 }
8321
8322 static inline void native_load_gdt(const struct desc_ptr *dtr)
8323@@ -246,8 +258,10 @@ static inline void native_load_tls(struc
8324 unsigned int i;
8325 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
8326
8327+ pax_open_kernel();
8328 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
8329 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
8330+ pax_close_kernel();
8331 }
8332
8333 #define _LDT_empty(info) \
8334@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
8335 desc->limit = (limit >> 16) & 0xf;
8336 }
8337
8338-static inline void _set_gate(int gate, unsigned type, void *addr,
8339+static inline void _set_gate(int gate, unsigned type, const void *addr,
8340 unsigned dpl, unsigned ist, unsigned seg)
8341 {
8342 gate_desc s;
8343@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
8344 * Pentium F0 0F bugfix can have resulted in the mapped
8345 * IDT being write-protected.
8346 */
8347-static inline void set_intr_gate(unsigned int n, void *addr)
8348+static inline void set_intr_gate(unsigned int n, const void *addr)
8349 {
8350 BUG_ON((unsigned)n > 0xFF);
8351 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
8352@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
8353 /*
8354 * This routine sets up an interrupt gate at directory privilege level 3.
8355 */
8356-static inline void set_system_intr_gate(unsigned int n, void *addr)
8357+static inline void set_system_intr_gate(unsigned int n, const void *addr)
8358 {
8359 BUG_ON((unsigned)n > 0xFF);
8360 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
8361 }
8362
8363-static inline void set_system_trap_gate(unsigned int n, void *addr)
8364+static inline void set_system_trap_gate(unsigned int n, const void *addr)
8365 {
8366 BUG_ON((unsigned)n > 0xFF);
8367 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8368 }
8369
8370-static inline void set_trap_gate(unsigned int n, void *addr)
8371+static inline void set_trap_gate(unsigned int n, const void *addr)
8372 {
8373 BUG_ON((unsigned)n > 0xFF);
8374 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8375@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
8376 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8377 {
8378 BUG_ON((unsigned)n > 0xFF);
8379- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8380+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8381 }
8382
8383-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8384+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8385 {
8386 BUG_ON((unsigned)n > 0xFF);
8387 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8388 }
8389
8390-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8391+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8392 {
8393 BUG_ON((unsigned)n > 0xFF);
8394 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8395 }
8396
8397+#ifdef CONFIG_X86_32
8398+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8399+{
8400+ struct desc_struct d;
8401+
8402+ if (likely(limit))
8403+ limit = (limit - 1UL) >> PAGE_SHIFT;
8404+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
8405+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8406+}
8407+#endif
8408+
8409 #endif /* _ASM_X86_DESC_H */
8410diff -urNp linux-2.6.32.43/arch/x86/include/asm/device.h linux-2.6.32.43/arch/x86/include/asm/device.h
8411--- linux-2.6.32.43/arch/x86/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
8412+++ linux-2.6.32.43/arch/x86/include/asm/device.h 2011-04-17 15:56:46.000000000 -0400
8413@@ -6,7 +6,7 @@ struct dev_archdata {
8414 void *acpi_handle;
8415 #endif
8416 #ifdef CONFIG_X86_64
8417-struct dma_map_ops *dma_ops;
8418+ const struct dma_map_ops *dma_ops;
8419 #endif
8420 #ifdef CONFIG_DMAR
8421 void *iommu; /* hook for IOMMU specific extension */
8422diff -urNp linux-2.6.32.43/arch/x86/include/asm/dma-mapping.h linux-2.6.32.43/arch/x86/include/asm/dma-mapping.h
8423--- linux-2.6.32.43/arch/x86/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
8424+++ linux-2.6.32.43/arch/x86/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
8425@@ -25,9 +25,9 @@ extern int iommu_merge;
8426 extern struct device x86_dma_fallback_dev;
8427 extern int panic_on_overflow;
8428
8429-extern struct dma_map_ops *dma_ops;
8430+extern const struct dma_map_ops *dma_ops;
8431
8432-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
8433+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
8434 {
8435 #ifdef CONFIG_X86_32
8436 return dma_ops;
8437@@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dm
8438 /* Make sure we keep the same behaviour */
8439 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
8440 {
8441- struct dma_map_ops *ops = get_dma_ops(dev);
8442+ const struct dma_map_ops *ops = get_dma_ops(dev);
8443 if (ops->mapping_error)
8444 return ops->mapping_error(dev, dma_addr);
8445
8446@@ -122,7 +122,7 @@ static inline void *
8447 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
8448 gfp_t gfp)
8449 {
8450- struct dma_map_ops *ops = get_dma_ops(dev);
8451+ const struct dma_map_ops *ops = get_dma_ops(dev);
8452 void *memory;
8453
8454 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
8455@@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, s
8456 static inline void dma_free_coherent(struct device *dev, size_t size,
8457 void *vaddr, dma_addr_t bus)
8458 {
8459- struct dma_map_ops *ops = get_dma_ops(dev);
8460+ const struct dma_map_ops *ops = get_dma_ops(dev);
8461
8462 WARN_ON(irqs_disabled()); /* for portability */
8463
8464diff -urNp linux-2.6.32.43/arch/x86/include/asm/e820.h linux-2.6.32.43/arch/x86/include/asm/e820.h
8465--- linux-2.6.32.43/arch/x86/include/asm/e820.h 2011-03-27 14:31:47.000000000 -0400
8466+++ linux-2.6.32.43/arch/x86/include/asm/e820.h 2011-04-17 15:56:46.000000000 -0400
8467@@ -133,7 +133,7 @@ extern char *default_machine_specific_me
8468 #define ISA_END_ADDRESS 0x100000
8469 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
8470
8471-#define BIOS_BEGIN 0x000a0000
8472+#define BIOS_BEGIN 0x000c0000
8473 #define BIOS_END 0x00100000
8474
8475 #ifdef __KERNEL__
8476diff -urNp linux-2.6.32.43/arch/x86/include/asm/elf.h linux-2.6.32.43/arch/x86/include/asm/elf.h
8477--- linux-2.6.32.43/arch/x86/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
8478+++ linux-2.6.32.43/arch/x86/include/asm/elf.h 2011-04-17 15:56:46.000000000 -0400
8479@@ -257,7 +257,25 @@ extern int force_personality32;
8480 the loader. We need to make sure that it is out of the way of the program
8481 that it will "exec", and that there is sufficient room for the brk. */
8482
8483+#ifdef CONFIG_PAX_SEGMEXEC
8484+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8485+#else
8486 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8487+#endif
8488+
8489+#ifdef CONFIG_PAX_ASLR
8490+#ifdef CONFIG_X86_32
8491+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8492+
8493+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8494+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8495+#else
8496+#define PAX_ELF_ET_DYN_BASE 0x400000UL
8497+
8498+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8499+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8500+#endif
8501+#endif
8502
8503 /* This yields a mask that user programs can use to figure out what
8504 instruction set this CPU supports. This could be done in user space,
8505@@ -311,8 +329,7 @@ do { \
8506 #define ARCH_DLINFO \
8507 do { \
8508 if (vdso_enabled) \
8509- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8510- (unsigned long)current->mm->context.vdso); \
8511+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
8512 } while (0)
8513
8514 #define AT_SYSINFO 32
8515@@ -323,7 +340,7 @@ do { \
8516
8517 #endif /* !CONFIG_X86_32 */
8518
8519-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8520+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8521
8522 #define VDSO_ENTRY \
8523 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8524@@ -337,7 +354,4 @@ extern int arch_setup_additional_pages(s
8525 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8526 #define compat_arch_setup_additional_pages syscall32_setup_pages
8527
8528-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8529-#define arch_randomize_brk arch_randomize_brk
8530-
8531 #endif /* _ASM_X86_ELF_H */
8532diff -urNp linux-2.6.32.43/arch/x86/include/asm/emergency-restart.h linux-2.6.32.43/arch/x86/include/asm/emergency-restart.h
8533--- linux-2.6.32.43/arch/x86/include/asm/emergency-restart.h 2011-03-27 14:31:47.000000000 -0400
8534+++ linux-2.6.32.43/arch/x86/include/asm/emergency-restart.h 2011-05-22 23:02:06.000000000 -0400
8535@@ -15,6 +15,6 @@ enum reboot_type {
8536
8537 extern enum reboot_type reboot_type;
8538
8539-extern void machine_emergency_restart(void);
8540+extern void machine_emergency_restart(void) __noreturn;
8541
8542 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8543diff -urNp linux-2.6.32.43/arch/x86/include/asm/futex.h linux-2.6.32.43/arch/x86/include/asm/futex.h
8544--- linux-2.6.32.43/arch/x86/include/asm/futex.h 2011-03-27 14:31:47.000000000 -0400
8545+++ linux-2.6.32.43/arch/x86/include/asm/futex.h 2011-04-17 15:56:46.000000000 -0400
8546@@ -12,16 +12,18 @@
8547 #include <asm/system.h>
8548
8549 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8550+ typecheck(u32 *, uaddr); \
8551 asm volatile("1:\t" insn "\n" \
8552 "2:\t.section .fixup,\"ax\"\n" \
8553 "3:\tmov\t%3, %1\n" \
8554 "\tjmp\t2b\n" \
8555 "\t.previous\n" \
8556 _ASM_EXTABLE(1b, 3b) \
8557- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8558+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
8559 : "i" (-EFAULT), "0" (oparg), "1" (0))
8560
8561 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8562+ typecheck(u32 *, uaddr); \
8563 asm volatile("1:\tmovl %2, %0\n" \
8564 "\tmovl\t%0, %3\n" \
8565 "\t" insn "\n" \
8566@@ -34,10 +36,10 @@
8567 _ASM_EXTABLE(1b, 4b) \
8568 _ASM_EXTABLE(2b, 4b) \
8569 : "=&a" (oldval), "=&r" (ret), \
8570- "+m" (*uaddr), "=&r" (tem) \
8571+ "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
8572 : "r" (oparg), "i" (-EFAULT), "1" (0))
8573
8574-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
8575+static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8576 {
8577 int op = (encoded_op >> 28) & 7;
8578 int cmp = (encoded_op >> 24) & 15;
8579@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
8580
8581 switch (op) {
8582 case FUTEX_OP_SET:
8583- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8584+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8585 break;
8586 case FUTEX_OP_ADD:
8587- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8588+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8589 uaddr, oparg);
8590 break;
8591 case FUTEX_OP_OR:
8592@@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser
8593 return ret;
8594 }
8595
8596-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
8597+static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
8598 int newval)
8599 {
8600
8601@@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_i
8602 return -ENOSYS;
8603 #endif
8604
8605- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
8606+ if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8607 return -EFAULT;
8608
8609- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
8610+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
8611 "2:\t.section .fixup, \"ax\"\n"
8612 "3:\tmov %2, %0\n"
8613 "\tjmp 2b\n"
8614 "\t.previous\n"
8615 _ASM_EXTABLE(1b, 3b)
8616- : "=a" (oldval), "+m" (*uaddr)
8617+ : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
8618 : "i" (-EFAULT), "r" (newval), "0" (oldval)
8619 : "memory"
8620 );
8621diff -urNp linux-2.6.32.43/arch/x86/include/asm/hw_irq.h linux-2.6.32.43/arch/x86/include/asm/hw_irq.h
8622--- linux-2.6.32.43/arch/x86/include/asm/hw_irq.h 2011-03-27 14:31:47.000000000 -0400
8623+++ linux-2.6.32.43/arch/x86/include/asm/hw_irq.h 2011-05-04 17:56:28.000000000 -0400
8624@@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
8625 extern void enable_IO_APIC(void);
8626
8627 /* Statistics */
8628-extern atomic_t irq_err_count;
8629-extern atomic_t irq_mis_count;
8630+extern atomic_unchecked_t irq_err_count;
8631+extern atomic_unchecked_t irq_mis_count;
8632
8633 /* EISA */
8634 extern void eisa_set_level_irq(unsigned int irq);
8635diff -urNp linux-2.6.32.43/arch/x86/include/asm/i387.h linux-2.6.32.43/arch/x86/include/asm/i387.h
8636--- linux-2.6.32.43/arch/x86/include/asm/i387.h 2011-03-27 14:31:47.000000000 -0400
8637+++ linux-2.6.32.43/arch/x86/include/asm/i387.h 2011-04-17 15:56:46.000000000 -0400
8638@@ -60,6 +60,11 @@ static inline int fxrstor_checking(struc
8639 {
8640 int err;
8641
8642+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8643+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8644+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
8645+#endif
8646+
8647 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
8648 "2:\n"
8649 ".section .fixup,\"ax\"\n"
8650@@ -105,6 +110,11 @@ static inline int fxsave_user(struct i38
8651 {
8652 int err;
8653
8654+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8655+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8656+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8657+#endif
8658+
8659 asm volatile("1: rex64/fxsave (%[fx])\n\t"
8660 "2:\n"
8661 ".section .fixup,\"ax\"\n"
8662@@ -195,13 +205,8 @@ static inline int fxrstor_checking(struc
8663 }
8664
8665 /* We need a safe address that is cheap to find and that is already
8666- in L1 during context switch. The best choices are unfortunately
8667- different for UP and SMP */
8668-#ifdef CONFIG_SMP
8669-#define safe_address (__per_cpu_offset[0])
8670-#else
8671-#define safe_address (kstat_cpu(0).cpustat.user)
8672-#endif
8673+ in L1 during context switch. */
8674+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
8675
8676 /*
8677 * These must be called with preempt disabled
8678@@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void
8679 struct thread_info *me = current_thread_info();
8680 preempt_disable();
8681 if (me->status & TS_USEDFPU)
8682- __save_init_fpu(me->task);
8683+ __save_init_fpu(current);
8684 else
8685 clts();
8686 }
8687diff -urNp linux-2.6.32.43/arch/x86/include/asm/io_32.h linux-2.6.32.43/arch/x86/include/asm/io_32.h
8688--- linux-2.6.32.43/arch/x86/include/asm/io_32.h 2011-03-27 14:31:47.000000000 -0400
8689+++ linux-2.6.32.43/arch/x86/include/asm/io_32.h 2011-04-17 15:56:46.000000000 -0400
8690@@ -3,6 +3,7 @@
8691
8692 #include <linux/string.h>
8693 #include <linux/compiler.h>
8694+#include <asm/processor.h>
8695
8696 /*
8697 * This file contains the definitions for the x86 IO instructions
8698@@ -42,6 +43,17 @@
8699
8700 #ifdef __KERNEL__
8701
8702+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8703+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8704+{
8705+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8706+}
8707+
8708+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8709+{
8710+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8711+}
8712+
8713 #include <asm-generic/iomap.h>
8714
8715 #include <linux/vmalloc.h>
8716diff -urNp linux-2.6.32.43/arch/x86/include/asm/io_64.h linux-2.6.32.43/arch/x86/include/asm/io_64.h
8717--- linux-2.6.32.43/arch/x86/include/asm/io_64.h 2011-03-27 14:31:47.000000000 -0400
8718+++ linux-2.6.32.43/arch/x86/include/asm/io_64.h 2011-04-17 15:56:46.000000000 -0400
8719@@ -140,6 +140,17 @@ __OUTS(l)
8720
8721 #include <linux/vmalloc.h>
8722
8723+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8724+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8725+{
8726+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8727+}
8728+
8729+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8730+{
8731+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8732+}
8733+
8734 #include <asm-generic/iomap.h>
8735
8736 void __memcpy_fromio(void *, unsigned long, unsigned);
8737diff -urNp linux-2.6.32.43/arch/x86/include/asm/iommu.h linux-2.6.32.43/arch/x86/include/asm/iommu.h
8738--- linux-2.6.32.43/arch/x86/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
8739+++ linux-2.6.32.43/arch/x86/include/asm/iommu.h 2011-04-17 15:56:46.000000000 -0400
8740@@ -3,7 +3,7 @@
8741
8742 extern void pci_iommu_shutdown(void);
8743 extern void no_iommu_init(void);
8744-extern struct dma_map_ops nommu_dma_ops;
8745+extern const struct dma_map_ops nommu_dma_ops;
8746 extern int force_iommu, no_iommu;
8747 extern int iommu_detected;
8748 extern int iommu_pass_through;
8749diff -urNp linux-2.6.32.43/arch/x86/include/asm/irqflags.h linux-2.6.32.43/arch/x86/include/asm/irqflags.h
8750--- linux-2.6.32.43/arch/x86/include/asm/irqflags.h 2011-03-27 14:31:47.000000000 -0400
8751+++ linux-2.6.32.43/arch/x86/include/asm/irqflags.h 2011-04-17 15:56:46.000000000 -0400
8752@@ -142,6 +142,11 @@ static inline unsigned long __raw_local_
8753 sti; \
8754 sysexit
8755
8756+#define GET_CR0_INTO_RDI mov %cr0, %rdi
8757+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8758+#define GET_CR3_INTO_RDI mov %cr3, %rdi
8759+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8760+
8761 #else
8762 #define INTERRUPT_RETURN iret
8763 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8764diff -urNp linux-2.6.32.43/arch/x86/include/asm/kprobes.h linux-2.6.32.43/arch/x86/include/asm/kprobes.h
8765--- linux-2.6.32.43/arch/x86/include/asm/kprobes.h 2011-03-27 14:31:47.000000000 -0400
8766+++ linux-2.6.32.43/arch/x86/include/asm/kprobes.h 2011-04-23 12:56:12.000000000 -0400
8767@@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
8768 #define BREAKPOINT_INSTRUCTION 0xcc
8769 #define RELATIVEJUMP_INSTRUCTION 0xe9
8770 #define MAX_INSN_SIZE 16
8771-#define MAX_STACK_SIZE 64
8772-#define MIN_STACK_SIZE(ADDR) \
8773- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8774- THREAD_SIZE - (unsigned long)(ADDR))) \
8775- ? (MAX_STACK_SIZE) \
8776- : (((unsigned long)current_thread_info()) + \
8777- THREAD_SIZE - (unsigned long)(ADDR)))
8778+#define MAX_STACK_SIZE 64UL
8779+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8780
8781 #define flush_insn_slot(p) do { } while (0)
8782
8783diff -urNp linux-2.6.32.43/arch/x86/include/asm/kvm_host.h linux-2.6.32.43/arch/x86/include/asm/kvm_host.h
8784--- linux-2.6.32.43/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:01.000000000 -0400
8785+++ linux-2.6.32.43/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:26.000000000 -0400
8786@@ -536,7 +536,7 @@ struct kvm_x86_ops {
8787 const struct trace_print_flags *exit_reasons_str;
8788 };
8789
8790-extern struct kvm_x86_ops *kvm_x86_ops;
8791+extern const struct kvm_x86_ops *kvm_x86_ops;
8792
8793 int kvm_mmu_module_init(void);
8794 void kvm_mmu_module_exit(void);
8795diff -urNp linux-2.6.32.43/arch/x86/include/asm/local.h linux-2.6.32.43/arch/x86/include/asm/local.h
8796--- linux-2.6.32.43/arch/x86/include/asm/local.h 2011-03-27 14:31:47.000000000 -0400
8797+++ linux-2.6.32.43/arch/x86/include/asm/local.h 2011-04-17 15:56:46.000000000 -0400
8798@@ -18,26 +18,58 @@ typedef struct {
8799
8800 static inline void local_inc(local_t *l)
8801 {
8802- asm volatile(_ASM_INC "%0"
8803+ asm volatile(_ASM_INC "%0\n"
8804+
8805+#ifdef CONFIG_PAX_REFCOUNT
8806+ "jno 0f\n"
8807+ _ASM_DEC "%0\n"
8808+ "int $4\n0:\n"
8809+ _ASM_EXTABLE(0b, 0b)
8810+#endif
8811+
8812 : "+m" (l->a.counter));
8813 }
8814
8815 static inline void local_dec(local_t *l)
8816 {
8817- asm volatile(_ASM_DEC "%0"
8818+ asm volatile(_ASM_DEC "%0\n"
8819+
8820+#ifdef CONFIG_PAX_REFCOUNT
8821+ "jno 0f\n"
8822+ _ASM_INC "%0\n"
8823+ "int $4\n0:\n"
8824+ _ASM_EXTABLE(0b, 0b)
8825+#endif
8826+
8827 : "+m" (l->a.counter));
8828 }
8829
8830 static inline void local_add(long i, local_t *l)
8831 {
8832- asm volatile(_ASM_ADD "%1,%0"
8833+ asm volatile(_ASM_ADD "%1,%0\n"
8834+
8835+#ifdef CONFIG_PAX_REFCOUNT
8836+ "jno 0f\n"
8837+ _ASM_SUB "%1,%0\n"
8838+ "int $4\n0:\n"
8839+ _ASM_EXTABLE(0b, 0b)
8840+#endif
8841+
8842 : "+m" (l->a.counter)
8843 : "ir" (i));
8844 }
8845
8846 static inline void local_sub(long i, local_t *l)
8847 {
8848- asm volatile(_ASM_SUB "%1,%0"
8849+ asm volatile(_ASM_SUB "%1,%0\n"
8850+
8851+#ifdef CONFIG_PAX_REFCOUNT
8852+ "jno 0f\n"
8853+ _ASM_ADD "%1,%0\n"
8854+ "int $4\n0:\n"
8855+ _ASM_EXTABLE(0b, 0b)
8856+#endif
8857+
8858 : "+m" (l->a.counter)
8859 : "ir" (i));
8860 }
8861@@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
8862 {
8863 unsigned char c;
8864
8865- asm volatile(_ASM_SUB "%2,%0; sete %1"
8866+ asm volatile(_ASM_SUB "%2,%0\n"
8867+
8868+#ifdef CONFIG_PAX_REFCOUNT
8869+ "jno 0f\n"
8870+ _ASM_ADD "%2,%0\n"
8871+ "int $4\n0:\n"
8872+ _ASM_EXTABLE(0b, 0b)
8873+#endif
8874+
8875+ "sete %1\n"
8876 : "+m" (l->a.counter), "=qm" (c)
8877 : "ir" (i) : "memory");
8878 return c;
8879@@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
8880 {
8881 unsigned char c;
8882
8883- asm volatile(_ASM_DEC "%0; sete %1"
8884+ asm volatile(_ASM_DEC "%0\n"
8885+
8886+#ifdef CONFIG_PAX_REFCOUNT
8887+ "jno 0f\n"
8888+ _ASM_INC "%0\n"
8889+ "int $4\n0:\n"
8890+ _ASM_EXTABLE(0b, 0b)
8891+#endif
8892+
8893+ "sete %1\n"
8894 : "+m" (l->a.counter), "=qm" (c)
8895 : : "memory");
8896 return c != 0;
8897@@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
8898 {
8899 unsigned char c;
8900
8901- asm volatile(_ASM_INC "%0; sete %1"
8902+ asm volatile(_ASM_INC "%0\n"
8903+
8904+#ifdef CONFIG_PAX_REFCOUNT
8905+ "jno 0f\n"
8906+ _ASM_DEC "%0\n"
8907+ "int $4\n0:\n"
8908+ _ASM_EXTABLE(0b, 0b)
8909+#endif
8910+
8911+ "sete %1\n"
8912 : "+m" (l->a.counter), "=qm" (c)
8913 : : "memory");
8914 return c != 0;
8915@@ -110,7 +169,16 @@ static inline int local_add_negative(lon
8916 {
8917 unsigned char c;
8918
8919- asm volatile(_ASM_ADD "%2,%0; sets %1"
8920+ asm volatile(_ASM_ADD "%2,%0\n"
8921+
8922+#ifdef CONFIG_PAX_REFCOUNT
8923+ "jno 0f\n"
8924+ _ASM_SUB "%2,%0\n"
8925+ "int $4\n0:\n"
8926+ _ASM_EXTABLE(0b, 0b)
8927+#endif
8928+
8929+ "sets %1\n"
8930 : "+m" (l->a.counter), "=qm" (c)
8931 : "ir" (i) : "memory");
8932 return c;
8933@@ -133,7 +201,15 @@ static inline long local_add_return(long
8934 #endif
8935 /* Modern 486+ processor */
8936 __i = i;
8937- asm volatile(_ASM_XADD "%0, %1;"
8938+ asm volatile(_ASM_XADD "%0, %1\n"
8939+
8940+#ifdef CONFIG_PAX_REFCOUNT
8941+ "jno 0f\n"
8942+ _ASM_MOV "%0,%1\n"
8943+ "int $4\n0:\n"
8944+ _ASM_EXTABLE(0b, 0b)
8945+#endif
8946+
8947 : "+r" (i), "+m" (l->a.counter)
8948 : : "memory");
8949 return i + __i;
8950diff -urNp linux-2.6.32.43/arch/x86/include/asm/microcode.h linux-2.6.32.43/arch/x86/include/asm/microcode.h
8951--- linux-2.6.32.43/arch/x86/include/asm/microcode.h 2011-03-27 14:31:47.000000000 -0400
8952+++ linux-2.6.32.43/arch/x86/include/asm/microcode.h 2011-04-17 15:56:46.000000000 -0400
8953@@ -12,13 +12,13 @@ struct device;
8954 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
8955
8956 struct microcode_ops {
8957- enum ucode_state (*request_microcode_user) (int cpu,
8958+ enum ucode_state (* const request_microcode_user) (int cpu,
8959 const void __user *buf, size_t size);
8960
8961- enum ucode_state (*request_microcode_fw) (int cpu,
8962+ enum ucode_state (* const request_microcode_fw) (int cpu,
8963 struct device *device);
8964
8965- void (*microcode_fini_cpu) (int cpu);
8966+ void (* const microcode_fini_cpu) (int cpu);
8967
8968 /*
8969 * The generic 'microcode_core' part guarantees that
8970@@ -38,18 +38,18 @@ struct ucode_cpu_info {
8971 extern struct ucode_cpu_info ucode_cpu_info[];
8972
8973 #ifdef CONFIG_MICROCODE_INTEL
8974-extern struct microcode_ops * __init init_intel_microcode(void);
8975+extern const struct microcode_ops * __init init_intel_microcode(void);
8976 #else
8977-static inline struct microcode_ops * __init init_intel_microcode(void)
8978+static inline const struct microcode_ops * __init init_intel_microcode(void)
8979 {
8980 return NULL;
8981 }
8982 #endif /* CONFIG_MICROCODE_INTEL */
8983
8984 #ifdef CONFIG_MICROCODE_AMD
8985-extern struct microcode_ops * __init init_amd_microcode(void);
8986+extern const struct microcode_ops * __init init_amd_microcode(void);
8987 #else
8988-static inline struct microcode_ops * __init init_amd_microcode(void)
8989+static inline const struct microcode_ops * __init init_amd_microcode(void)
8990 {
8991 return NULL;
8992 }
8993diff -urNp linux-2.6.32.43/arch/x86/include/asm/mman.h linux-2.6.32.43/arch/x86/include/asm/mman.h
8994--- linux-2.6.32.43/arch/x86/include/asm/mman.h 2011-03-27 14:31:47.000000000 -0400
8995+++ linux-2.6.32.43/arch/x86/include/asm/mman.h 2011-04-17 15:56:46.000000000 -0400
8996@@ -5,4 +5,14 @@
8997
8998 #include <asm-generic/mman.h>
8999
9000+#ifdef __KERNEL__
9001+#ifndef __ASSEMBLY__
9002+#ifdef CONFIG_X86_32
9003+#define arch_mmap_check i386_mmap_check
9004+int i386_mmap_check(unsigned long addr, unsigned long len,
9005+ unsigned long flags);
9006+#endif
9007+#endif
9008+#endif
9009+
9010 #endif /* _ASM_X86_MMAN_H */
9011diff -urNp linux-2.6.32.43/arch/x86/include/asm/mmu_context.h linux-2.6.32.43/arch/x86/include/asm/mmu_context.h
9012--- linux-2.6.32.43/arch/x86/include/asm/mmu_context.h 2011-03-27 14:31:47.000000000 -0400
9013+++ linux-2.6.32.43/arch/x86/include/asm/mmu_context.h 2011-04-17 15:56:46.000000000 -0400
9014@@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
9015
9016 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9017 {
9018+
9019+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9020+ unsigned int i;
9021+ pgd_t *pgd;
9022+
9023+ pax_open_kernel();
9024+ pgd = get_cpu_pgd(smp_processor_id());
9025+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
9026+ if (paravirt_enabled())
9027+ set_pgd(pgd+i, native_make_pgd(0));
9028+ else
9029+ pgd[i] = native_make_pgd(0);
9030+ pax_close_kernel();
9031+#endif
9032+
9033 #ifdef CONFIG_SMP
9034 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
9035 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
9036@@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
9037 struct task_struct *tsk)
9038 {
9039 unsigned cpu = smp_processor_id();
9040+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
9041+ int tlbstate = TLBSTATE_OK;
9042+#endif
9043
9044 if (likely(prev != next)) {
9045 #ifdef CONFIG_SMP
9046+#ifdef CONFIG_X86_32
9047+ tlbstate = percpu_read(cpu_tlbstate.state);
9048+#endif
9049 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9050 percpu_write(cpu_tlbstate.active_mm, next);
9051 #endif
9052 cpumask_set_cpu(cpu, mm_cpumask(next));
9053
9054 /* Re-load page tables */
9055+#ifdef CONFIG_PAX_PER_CPU_PGD
9056+ pax_open_kernel();
9057+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9058+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9059+ pax_close_kernel();
9060+ load_cr3(get_cpu_pgd(cpu));
9061+#else
9062 load_cr3(next->pgd);
9063+#endif
9064
9065 /* stop flush ipis for the previous mm */
9066 cpumask_clear_cpu(cpu, mm_cpumask(prev));
9067@@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
9068 */
9069 if (unlikely(prev->context.ldt != next->context.ldt))
9070 load_LDT_nolock(&next->context);
9071- }
9072+
9073+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9074+ if (!nx_enabled) {
9075+ smp_mb__before_clear_bit();
9076+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
9077+ smp_mb__after_clear_bit();
9078+ cpu_set(cpu, next->context.cpu_user_cs_mask);
9079+ }
9080+#endif
9081+
9082+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9083+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
9084+ prev->context.user_cs_limit != next->context.user_cs_limit))
9085+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9086 #ifdef CONFIG_SMP
9087+ else if (unlikely(tlbstate != TLBSTATE_OK))
9088+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9089+#endif
9090+#endif
9091+
9092+ }
9093 else {
9094+
9095+#ifdef CONFIG_PAX_PER_CPU_PGD
9096+ pax_open_kernel();
9097+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9098+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9099+ pax_close_kernel();
9100+ load_cr3(get_cpu_pgd(cpu));
9101+#endif
9102+
9103+#ifdef CONFIG_SMP
9104 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9105 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
9106
9107@@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
9108 * tlb flush IPI delivery. We must reload CR3
9109 * to make sure to use no freed page tables.
9110 */
9111+
9112+#ifndef CONFIG_PAX_PER_CPU_PGD
9113 load_cr3(next->pgd);
9114+#endif
9115+
9116 load_LDT_nolock(&next->context);
9117+
9118+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9119+ if (!nx_enabled)
9120+ cpu_set(cpu, next->context.cpu_user_cs_mask);
9121+#endif
9122+
9123+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9124+#ifdef CONFIG_PAX_PAGEEXEC
9125+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
9126+#endif
9127+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9128+#endif
9129+
9130 }
9131- }
9132 #endif
9133+ }
9134 }
9135
9136 #define activate_mm(prev, next) \
9137diff -urNp linux-2.6.32.43/arch/x86/include/asm/mmu.h linux-2.6.32.43/arch/x86/include/asm/mmu.h
9138--- linux-2.6.32.43/arch/x86/include/asm/mmu.h 2011-03-27 14:31:47.000000000 -0400
9139+++ linux-2.6.32.43/arch/x86/include/asm/mmu.h 2011-04-17 15:56:46.000000000 -0400
9140@@ -9,10 +9,23 @@
9141 * we put the segment information here.
9142 */
9143 typedef struct {
9144- void *ldt;
9145+ struct desc_struct *ldt;
9146 int size;
9147 struct mutex lock;
9148- void *vdso;
9149+ unsigned long vdso;
9150+
9151+#ifdef CONFIG_X86_32
9152+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
9153+ unsigned long user_cs_base;
9154+ unsigned long user_cs_limit;
9155+
9156+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9157+ cpumask_t cpu_user_cs_mask;
9158+#endif
9159+
9160+#endif
9161+#endif
9162+
9163 } mm_context_t;
9164
9165 #ifdef CONFIG_SMP
9166diff -urNp linux-2.6.32.43/arch/x86/include/asm/module.h linux-2.6.32.43/arch/x86/include/asm/module.h
9167--- linux-2.6.32.43/arch/x86/include/asm/module.h 2011-03-27 14:31:47.000000000 -0400
9168+++ linux-2.6.32.43/arch/x86/include/asm/module.h 2011-04-23 13:18:57.000000000 -0400
9169@@ -5,6 +5,7 @@
9170
9171 #ifdef CONFIG_X86_64
9172 /* X86_64 does not define MODULE_PROC_FAMILY */
9173+#define MODULE_PROC_FAMILY ""
9174 #elif defined CONFIG_M386
9175 #define MODULE_PROC_FAMILY "386 "
9176 #elif defined CONFIG_M486
9177@@ -59,13 +60,36 @@
9178 #error unknown processor family
9179 #endif
9180
9181-#ifdef CONFIG_X86_32
9182-# ifdef CONFIG_4KSTACKS
9183-# define MODULE_STACKSIZE "4KSTACKS "
9184-# else
9185-# define MODULE_STACKSIZE ""
9186-# endif
9187-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
9188+#ifdef CONFIG_PAX_MEMORY_UDEREF
9189+#define MODULE_PAX_UDEREF "UDEREF "
9190+#else
9191+#define MODULE_PAX_UDEREF ""
9192+#endif
9193+
9194+#ifdef CONFIG_PAX_KERNEXEC
9195+#define MODULE_PAX_KERNEXEC "KERNEXEC "
9196+#else
9197+#define MODULE_PAX_KERNEXEC ""
9198+#endif
9199+
9200+#ifdef CONFIG_PAX_REFCOUNT
9201+#define MODULE_PAX_REFCOUNT "REFCOUNT "
9202+#else
9203+#define MODULE_PAX_REFCOUNT ""
9204 #endif
9205
9206+#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
9207+#define MODULE_STACKSIZE "4KSTACKS "
9208+#else
9209+#define MODULE_STACKSIZE ""
9210+#endif
9211+
9212+#ifdef CONFIG_GRKERNSEC
9213+#define MODULE_GRSEC "GRSECURITY "
9214+#else
9215+#define MODULE_GRSEC ""
9216+#endif
9217+
9218+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
9219+
9220 #endif /* _ASM_X86_MODULE_H */
9221diff -urNp linux-2.6.32.43/arch/x86/include/asm/page_64_types.h linux-2.6.32.43/arch/x86/include/asm/page_64_types.h
9222--- linux-2.6.32.43/arch/x86/include/asm/page_64_types.h 2011-03-27 14:31:47.000000000 -0400
9223+++ linux-2.6.32.43/arch/x86/include/asm/page_64_types.h 2011-04-17 15:56:46.000000000 -0400
9224@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
9225
9226 /* duplicated to the one in bootmem.h */
9227 extern unsigned long max_pfn;
9228-extern unsigned long phys_base;
9229+extern const unsigned long phys_base;
9230
9231 extern unsigned long __phys_addr(unsigned long);
9232 #define __phys_reloc_hide(x) (x)
9233diff -urNp linux-2.6.32.43/arch/x86/include/asm/paravirt.h linux-2.6.32.43/arch/x86/include/asm/paravirt.h
9234--- linux-2.6.32.43/arch/x86/include/asm/paravirt.h 2011-03-27 14:31:47.000000000 -0400
9235+++ linux-2.6.32.43/arch/x86/include/asm/paravirt.h 2011-04-17 15:56:46.000000000 -0400
9236@@ -729,6 +729,21 @@ static inline void __set_fixmap(unsigned
9237 pv_mmu_ops.set_fixmap(idx, phys, flags);
9238 }
9239
9240+#ifdef CONFIG_PAX_KERNEXEC
9241+static inline unsigned long pax_open_kernel(void)
9242+{
9243+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
9244+}
9245+
9246+static inline unsigned long pax_close_kernel(void)
9247+{
9248+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
9249+}
9250+#else
9251+static inline unsigned long pax_open_kernel(void) { return 0; }
9252+static inline unsigned long pax_close_kernel(void) { return 0; }
9253+#endif
9254+
9255 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
9256
9257 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
9258@@ -945,7 +960,7 @@ extern void default_banner(void);
9259
9260 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
9261 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
9262-#define PARA_INDIRECT(addr) *%cs:addr
9263+#define PARA_INDIRECT(addr) *%ss:addr
9264 #endif
9265
9266 #define INTERRUPT_RETURN \
9267@@ -1022,6 +1037,21 @@ extern void default_banner(void);
9268 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
9269 CLBR_NONE, \
9270 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
9271+
9272+#define GET_CR0_INTO_RDI \
9273+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
9274+ mov %rax,%rdi
9275+
9276+#define SET_RDI_INTO_CR0 \
9277+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
9278+
9279+#define GET_CR3_INTO_RDI \
9280+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
9281+ mov %rax,%rdi
9282+
9283+#define SET_RDI_INTO_CR3 \
9284+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
9285+
9286 #endif /* CONFIG_X86_32 */
9287
9288 #endif /* __ASSEMBLY__ */
9289diff -urNp linux-2.6.32.43/arch/x86/include/asm/paravirt_types.h linux-2.6.32.43/arch/x86/include/asm/paravirt_types.h
9290--- linux-2.6.32.43/arch/x86/include/asm/paravirt_types.h 2011-03-27 14:31:47.000000000 -0400
9291+++ linux-2.6.32.43/arch/x86/include/asm/paravirt_types.h 2011-08-05 20:33:55.000000000 -0400
9292@@ -78,19 +78,19 @@ struct pv_init_ops {
9293 */
9294 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
9295 unsigned long addr, unsigned len);
9296-};
9297+} __no_const;
9298
9299
9300 struct pv_lazy_ops {
9301 /* Set deferred update mode, used for batching operations. */
9302 void (*enter)(void);
9303 void (*leave)(void);
9304-};
9305+} __no_const;
9306
9307 struct pv_time_ops {
9308 unsigned long long (*sched_clock)(void);
9309 unsigned long (*get_tsc_khz)(void);
9310-};
9311+} __no_const;
9312
9313 struct pv_cpu_ops {
9314 /* hooks for various privileged instructions */
9315@@ -186,7 +186,7 @@ struct pv_cpu_ops {
9316
9317 void (*start_context_switch)(struct task_struct *prev);
9318 void (*end_context_switch)(struct task_struct *next);
9319-};
9320+} __no_const;
9321
9322 struct pv_irq_ops {
9323 /*
9324@@ -217,7 +217,7 @@ struct pv_apic_ops {
9325 unsigned long start_eip,
9326 unsigned long start_esp);
9327 #endif
9328-};
9329+} __no_const;
9330
9331 struct pv_mmu_ops {
9332 unsigned long (*read_cr2)(void);
9333@@ -316,6 +316,12 @@ struct pv_mmu_ops {
9334 an mfn. We can tell which is which from the index. */
9335 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
9336 phys_addr_t phys, pgprot_t flags);
9337+
9338+#ifdef CONFIG_PAX_KERNEXEC
9339+ unsigned long (*pax_open_kernel)(void);
9340+ unsigned long (*pax_close_kernel)(void);
9341+#endif
9342+
9343 };
9344
9345 struct raw_spinlock;
9346@@ -326,7 +332,7 @@ struct pv_lock_ops {
9347 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
9348 int (*spin_trylock)(struct raw_spinlock *lock);
9349 void (*spin_unlock)(struct raw_spinlock *lock);
9350-};
9351+} __no_const;
9352
9353 /* This contains all the paravirt structures: we get a convenient
9354 * number for each function using the offset which we use to indicate
9355diff -urNp linux-2.6.32.43/arch/x86/include/asm/pci_x86.h linux-2.6.32.43/arch/x86/include/asm/pci_x86.h
9356--- linux-2.6.32.43/arch/x86/include/asm/pci_x86.h 2011-03-27 14:31:47.000000000 -0400
9357+++ linux-2.6.32.43/arch/x86/include/asm/pci_x86.h 2011-04-17 15:56:46.000000000 -0400
9358@@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct
9359 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
9360
9361 struct pci_raw_ops {
9362- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
9363+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
9364 int reg, int len, u32 *val);
9365- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
9366+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
9367 int reg, int len, u32 val);
9368 };
9369
9370-extern struct pci_raw_ops *raw_pci_ops;
9371-extern struct pci_raw_ops *raw_pci_ext_ops;
9372+extern const struct pci_raw_ops *raw_pci_ops;
9373+extern const struct pci_raw_ops *raw_pci_ext_ops;
9374
9375-extern struct pci_raw_ops pci_direct_conf1;
9376+extern const struct pci_raw_ops pci_direct_conf1;
9377 extern bool port_cf9_safe;
9378
9379 /* arch_initcall level */
9380diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgalloc.h linux-2.6.32.43/arch/x86/include/asm/pgalloc.h
9381--- linux-2.6.32.43/arch/x86/include/asm/pgalloc.h 2011-03-27 14:31:47.000000000 -0400
9382+++ linux-2.6.32.43/arch/x86/include/asm/pgalloc.h 2011-04-17 15:56:46.000000000 -0400
9383@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
9384 pmd_t *pmd, pte_t *pte)
9385 {
9386 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9387+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
9388+}
9389+
9390+static inline void pmd_populate_user(struct mm_struct *mm,
9391+ pmd_t *pmd, pte_t *pte)
9392+{
9393+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9394 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
9395 }
9396
9397diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable-2level.h linux-2.6.32.43/arch/x86/include/asm/pgtable-2level.h
9398--- linux-2.6.32.43/arch/x86/include/asm/pgtable-2level.h 2011-03-27 14:31:47.000000000 -0400
9399+++ linux-2.6.32.43/arch/x86/include/asm/pgtable-2level.h 2011-04-17 15:56:46.000000000 -0400
9400@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
9401
9402 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9403 {
9404+ pax_open_kernel();
9405 *pmdp = pmd;
9406+ pax_close_kernel();
9407 }
9408
9409 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9410diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable_32.h linux-2.6.32.43/arch/x86/include/asm/pgtable_32.h
9411--- linux-2.6.32.43/arch/x86/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
9412+++ linux-2.6.32.43/arch/x86/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
9413@@ -26,9 +26,6 @@
9414 struct mm_struct;
9415 struct vm_area_struct;
9416
9417-extern pgd_t swapper_pg_dir[1024];
9418-extern pgd_t trampoline_pg_dir[1024];
9419-
9420 static inline void pgtable_cache_init(void) { }
9421 static inline void check_pgt_cache(void) { }
9422 void paging_init(void);
9423@@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, u
9424 # include <asm/pgtable-2level.h>
9425 #endif
9426
9427+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9428+extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
9429+#ifdef CONFIG_X86_PAE
9430+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9431+#endif
9432+
9433 #if defined(CONFIG_HIGHPTE)
9434 #define __KM_PTE \
9435 (in_nmi() ? KM_NMI_PTE : \
9436@@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, u
9437 /* Clear a kernel PTE and flush it from the TLB */
9438 #define kpte_clear_flush(ptep, vaddr) \
9439 do { \
9440+ pax_open_kernel(); \
9441 pte_clear(&init_mm, (vaddr), (ptep)); \
9442+ pax_close_kernel(); \
9443 __flush_tlb_one((vaddr)); \
9444 } while (0)
9445
9446@@ -85,6 +90,9 @@ do { \
9447
9448 #endif /* !__ASSEMBLY__ */
9449
9450+#define HAVE_ARCH_UNMAPPED_AREA
9451+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9452+
9453 /*
9454 * kern_addr_valid() is (1) for FLATMEM and (0) for
9455 * SPARSEMEM and DISCONTIGMEM
9456diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable_32_types.h linux-2.6.32.43/arch/x86/include/asm/pgtable_32_types.h
9457--- linux-2.6.32.43/arch/x86/include/asm/pgtable_32_types.h 2011-03-27 14:31:47.000000000 -0400
9458+++ linux-2.6.32.43/arch/x86/include/asm/pgtable_32_types.h 2011-04-17 15:56:46.000000000 -0400
9459@@ -8,7 +8,7 @@
9460 */
9461 #ifdef CONFIG_X86_PAE
9462 # include <asm/pgtable-3level_types.h>
9463-# define PMD_SIZE (1UL << PMD_SHIFT)
9464+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9465 # define PMD_MASK (~(PMD_SIZE - 1))
9466 #else
9467 # include <asm/pgtable-2level_types.h>
9468@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
9469 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9470 #endif
9471
9472+#ifdef CONFIG_PAX_KERNEXEC
9473+#ifndef __ASSEMBLY__
9474+extern unsigned char MODULES_EXEC_VADDR[];
9475+extern unsigned char MODULES_EXEC_END[];
9476+#endif
9477+#include <asm/boot.h>
9478+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9479+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9480+#else
9481+#define ktla_ktva(addr) (addr)
9482+#define ktva_ktla(addr) (addr)
9483+#endif
9484+
9485 #define MODULES_VADDR VMALLOC_START
9486 #define MODULES_END VMALLOC_END
9487 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9488diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable-3level.h linux-2.6.32.43/arch/x86/include/asm/pgtable-3level.h
9489--- linux-2.6.32.43/arch/x86/include/asm/pgtable-3level.h 2011-03-27 14:31:47.000000000 -0400
9490+++ linux-2.6.32.43/arch/x86/include/asm/pgtable-3level.h 2011-04-17 15:56:46.000000000 -0400
9491@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
9492
9493 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9494 {
9495+ pax_open_kernel();
9496 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9497+ pax_close_kernel();
9498 }
9499
9500 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9501 {
9502+ pax_open_kernel();
9503 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9504+ pax_close_kernel();
9505 }
9506
9507 /*
9508diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable_64.h linux-2.6.32.43/arch/x86/include/asm/pgtable_64.h
9509--- linux-2.6.32.43/arch/x86/include/asm/pgtable_64.h 2011-03-27 14:31:47.000000000 -0400
9510+++ linux-2.6.32.43/arch/x86/include/asm/pgtable_64.h 2011-04-17 15:56:46.000000000 -0400
9511@@ -16,10 +16,13 @@
9512
9513 extern pud_t level3_kernel_pgt[512];
9514 extern pud_t level3_ident_pgt[512];
9515+extern pud_t level3_vmalloc_pgt[512];
9516+extern pud_t level3_vmemmap_pgt[512];
9517+extern pud_t level2_vmemmap_pgt[512];
9518 extern pmd_t level2_kernel_pgt[512];
9519 extern pmd_t level2_fixmap_pgt[512];
9520-extern pmd_t level2_ident_pgt[512];
9521-extern pgd_t init_level4_pgt[];
9522+extern pmd_t level2_ident_pgt[512*2];
9523+extern pgd_t init_level4_pgt[512];
9524
9525 #define swapper_pg_dir init_level4_pgt
9526
9527@@ -74,7 +77,9 @@ static inline pte_t native_ptep_get_and_
9528
9529 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9530 {
9531+ pax_open_kernel();
9532 *pmdp = pmd;
9533+ pax_close_kernel();
9534 }
9535
9536 static inline void native_pmd_clear(pmd_t *pmd)
9537@@ -94,7 +99,9 @@ static inline void native_pud_clear(pud_
9538
9539 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9540 {
9541+ pax_open_kernel();
9542 *pgdp = pgd;
9543+ pax_close_kernel();
9544 }
9545
9546 static inline void native_pgd_clear(pgd_t *pgd)
9547diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable_64_types.h linux-2.6.32.43/arch/x86/include/asm/pgtable_64_types.h
9548--- linux-2.6.32.43/arch/x86/include/asm/pgtable_64_types.h 2011-03-27 14:31:47.000000000 -0400
9549+++ linux-2.6.32.43/arch/x86/include/asm/pgtable_64_types.h 2011-04-17 15:56:46.000000000 -0400
9550@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9551 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9552 #define MODULES_END _AC(0xffffffffff000000, UL)
9553 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9554+#define MODULES_EXEC_VADDR MODULES_VADDR
9555+#define MODULES_EXEC_END MODULES_END
9556+
9557+#define ktla_ktva(addr) (addr)
9558+#define ktva_ktla(addr) (addr)
9559
9560 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9561diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable.h linux-2.6.32.43/arch/x86/include/asm/pgtable.h
9562--- linux-2.6.32.43/arch/x86/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
9563+++ linux-2.6.32.43/arch/x86/include/asm/pgtable.h 2011-04-17 15:56:46.000000000 -0400
9564@@ -74,12 +74,51 @@ extern struct list_head pgd_list;
9565
9566 #define arch_end_context_switch(prev) do {} while(0)
9567
9568+#define pax_open_kernel() native_pax_open_kernel()
9569+#define pax_close_kernel() native_pax_close_kernel()
9570 #endif /* CONFIG_PARAVIRT */
9571
9572+#define __HAVE_ARCH_PAX_OPEN_KERNEL
9573+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9574+
9575+#ifdef CONFIG_PAX_KERNEXEC
9576+static inline unsigned long native_pax_open_kernel(void)
9577+{
9578+ unsigned long cr0;
9579+
9580+ preempt_disable();
9581+ barrier();
9582+ cr0 = read_cr0() ^ X86_CR0_WP;
9583+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
9584+ write_cr0(cr0);
9585+ return cr0 ^ X86_CR0_WP;
9586+}
9587+
9588+static inline unsigned long native_pax_close_kernel(void)
9589+{
9590+ unsigned long cr0;
9591+
9592+ cr0 = read_cr0() ^ X86_CR0_WP;
9593+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9594+ write_cr0(cr0);
9595+ barrier();
9596+ preempt_enable_no_resched();
9597+ return cr0 ^ X86_CR0_WP;
9598+}
9599+#else
9600+static inline unsigned long native_pax_open_kernel(void) { return 0; }
9601+static inline unsigned long native_pax_close_kernel(void) { return 0; }
9602+#endif
9603+
9604 /*
9605 * The following only work if pte_present() is true.
9606 * Undefined behaviour if not..
9607 */
9608+static inline int pte_user(pte_t pte)
9609+{
9610+ return pte_val(pte) & _PAGE_USER;
9611+}
9612+
9613 static inline int pte_dirty(pte_t pte)
9614 {
9615 return pte_flags(pte) & _PAGE_DIRTY;
9616@@ -167,9 +206,29 @@ static inline pte_t pte_wrprotect(pte_t
9617 return pte_clear_flags(pte, _PAGE_RW);
9618 }
9619
9620+static inline pte_t pte_mkread(pte_t pte)
9621+{
9622+ return __pte(pte_val(pte) | _PAGE_USER);
9623+}
9624+
9625 static inline pte_t pte_mkexec(pte_t pte)
9626 {
9627- return pte_clear_flags(pte, _PAGE_NX);
9628+#ifdef CONFIG_X86_PAE
9629+ if (__supported_pte_mask & _PAGE_NX)
9630+ return pte_clear_flags(pte, _PAGE_NX);
9631+ else
9632+#endif
9633+ return pte_set_flags(pte, _PAGE_USER);
9634+}
9635+
9636+static inline pte_t pte_exprotect(pte_t pte)
9637+{
9638+#ifdef CONFIG_X86_PAE
9639+ if (__supported_pte_mask & _PAGE_NX)
9640+ return pte_set_flags(pte, _PAGE_NX);
9641+ else
9642+#endif
9643+ return pte_clear_flags(pte, _PAGE_USER);
9644 }
9645
9646 static inline pte_t pte_mkdirty(pte_t pte)
9647@@ -302,6 +361,15 @@ pte_t *populate_extra_pte(unsigned long
9648 #endif
9649
9650 #ifndef __ASSEMBLY__
9651+
9652+#ifdef CONFIG_PAX_PER_CPU_PGD
9653+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9654+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9655+{
9656+ return cpu_pgd[cpu];
9657+}
9658+#endif
9659+
9660 #include <linux/mm_types.h>
9661
9662 static inline int pte_none(pte_t pte)
9663@@ -472,7 +540,7 @@ static inline pud_t *pud_offset(pgd_t *p
9664
9665 static inline int pgd_bad(pgd_t pgd)
9666 {
9667- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9668+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9669 }
9670
9671 static inline int pgd_none(pgd_t pgd)
9672@@ -495,7 +563,12 @@ static inline int pgd_none(pgd_t pgd)
9673 * pgd_offset() returns a (pgd_t *)
9674 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9675 */
9676-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9677+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9678+
9679+#ifdef CONFIG_PAX_PER_CPU_PGD
9680+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9681+#endif
9682+
9683 /*
9684 * a shortcut which implies the use of the kernel's pgd, instead
9685 * of a process's
9686@@ -506,6 +579,20 @@ static inline int pgd_none(pgd_t pgd)
9687 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9688 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9689
9690+#ifdef CONFIG_X86_32
9691+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9692+#else
9693+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9694+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9695+
9696+#ifdef CONFIG_PAX_MEMORY_UDEREF
9697+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9698+#else
9699+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9700+#endif
9701+
9702+#endif
9703+
9704 #ifndef __ASSEMBLY__
9705
9706 extern int direct_gbpages;
9707@@ -611,11 +698,23 @@ static inline void ptep_set_wrprotect(st
9708 * dst and src can be on the same page, but the range must not overlap,
9709 * and must not cross a page boundary.
9710 */
9711-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9712+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9713 {
9714- memcpy(dst, src, count * sizeof(pgd_t));
9715+ pax_open_kernel();
9716+ while (count--)
9717+ *dst++ = *src++;
9718+ pax_close_kernel();
9719 }
9720
9721+#ifdef CONFIG_PAX_PER_CPU_PGD
9722+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9723+#endif
9724+
9725+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9726+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9727+#else
9728+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9729+#endif
9730
9731 #include <asm-generic/pgtable.h>
9732 #endif /* __ASSEMBLY__ */
9733diff -urNp linux-2.6.32.43/arch/x86/include/asm/pgtable_types.h linux-2.6.32.43/arch/x86/include/asm/pgtable_types.h
9734--- linux-2.6.32.43/arch/x86/include/asm/pgtable_types.h 2011-03-27 14:31:47.000000000 -0400
9735+++ linux-2.6.32.43/arch/x86/include/asm/pgtable_types.h 2011-04-17 15:56:46.000000000 -0400
9736@@ -16,12 +16,11 @@
9737 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9738 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9739 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9740-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9741+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9742 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9743 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9744 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9745-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9746-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9747+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9748 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9749
9750 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9751@@ -39,7 +38,6 @@
9752 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9753 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9754 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9755-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9756 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9757 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9758 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9759@@ -55,8 +53,10 @@
9760
9761 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9762 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9763-#else
9764+#elif defined(CONFIG_KMEMCHECK)
9765 #define _PAGE_NX (_AT(pteval_t, 0))
9766+#else
9767+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9768 #endif
9769
9770 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9771@@ -93,6 +93,9 @@
9772 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9773 _PAGE_ACCESSED)
9774
9775+#define PAGE_READONLY_NOEXEC PAGE_READONLY
9776+#define PAGE_SHARED_NOEXEC PAGE_SHARED
9777+
9778 #define __PAGE_KERNEL_EXEC \
9779 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9780 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9781@@ -103,8 +106,8 @@
9782 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9783 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9784 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9785-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9786-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
9787+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9788+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
9789 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9790 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
9791 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
9792@@ -163,8 +166,8 @@
9793 * bits are combined, this will alow user to access the high address mapped
9794 * VDSO in the presence of CONFIG_COMPAT_VDSO
9795 */
9796-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9797-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9798+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9799+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9800 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9801 #endif
9802
9803@@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t p
9804 {
9805 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9806 }
9807+#endif
9808
9809+#if PAGETABLE_LEVELS == 3
9810+#include <asm-generic/pgtable-nopud.h>
9811+#endif
9812+
9813+#if PAGETABLE_LEVELS == 2
9814+#include <asm-generic/pgtable-nopmd.h>
9815+#endif
9816+
9817+#ifndef __ASSEMBLY__
9818 #if PAGETABLE_LEVELS > 3
9819 typedef struct { pudval_t pud; } pud_t;
9820
9821@@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pu
9822 return pud.pud;
9823 }
9824 #else
9825-#include <asm-generic/pgtable-nopud.h>
9826-
9827 static inline pudval_t native_pud_val(pud_t pud)
9828 {
9829 return native_pgd_val(pud.pgd);
9830@@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pm
9831 return pmd.pmd;
9832 }
9833 #else
9834-#include <asm-generic/pgtable-nopmd.h>
9835-
9836 static inline pmdval_t native_pmd_val(pmd_t pmd)
9837 {
9838 return native_pgd_val(pmd.pud.pgd);
9839@@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
9840
9841 extern pteval_t __supported_pte_mask;
9842 extern void set_nx(void);
9843+
9844+#ifdef CONFIG_X86_32
9845+#ifdef CONFIG_X86_PAE
9846 extern int nx_enabled;
9847+#else
9848+#define nx_enabled (0)
9849+#endif
9850+#else
9851+#define nx_enabled (1)
9852+#endif
9853
9854 #define pgprot_writecombine pgprot_writecombine
9855 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9856diff -urNp linux-2.6.32.43/arch/x86/include/asm/processor.h linux-2.6.32.43/arch/x86/include/asm/processor.h
9857--- linux-2.6.32.43/arch/x86/include/asm/processor.h 2011-04-22 19:16:29.000000000 -0400
9858+++ linux-2.6.32.43/arch/x86/include/asm/processor.h 2011-05-11 18:25:15.000000000 -0400
9859@@ -272,7 +272,7 @@ struct tss_struct {
9860
9861 } ____cacheline_aligned;
9862
9863-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
9864+extern struct tss_struct init_tss[NR_CPUS];
9865
9866 /*
9867 * Save the original ist values for checking stack pointers during debugging
9868@@ -888,11 +888,18 @@ static inline void spin_lock_prefetch(co
9869 */
9870 #define TASK_SIZE PAGE_OFFSET
9871 #define TASK_SIZE_MAX TASK_SIZE
9872+
9873+#ifdef CONFIG_PAX_SEGMEXEC
9874+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
9875+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
9876+#else
9877 #define STACK_TOP TASK_SIZE
9878-#define STACK_TOP_MAX STACK_TOP
9879+#endif
9880+
9881+#define STACK_TOP_MAX TASK_SIZE
9882
9883 #define INIT_THREAD { \
9884- .sp0 = sizeof(init_stack) + (long)&init_stack, \
9885+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9886 .vm86_info = NULL, \
9887 .sysenter_cs = __KERNEL_CS, \
9888 .io_bitmap_ptr = NULL, \
9889@@ -906,7 +913,7 @@ static inline void spin_lock_prefetch(co
9890 */
9891 #define INIT_TSS { \
9892 .x86_tss = { \
9893- .sp0 = sizeof(init_stack) + (long)&init_stack, \
9894+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9895 .ss0 = __KERNEL_DS, \
9896 .ss1 = __KERNEL_CS, \
9897 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
9898@@ -917,11 +924,7 @@ static inline void spin_lock_prefetch(co
9899 extern unsigned long thread_saved_pc(struct task_struct *tsk);
9900
9901 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
9902-#define KSTK_TOP(info) \
9903-({ \
9904- unsigned long *__ptr = (unsigned long *)(info); \
9905- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
9906-})
9907+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
9908
9909 /*
9910 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
9911@@ -936,7 +939,7 @@ extern unsigned long thread_saved_pc(str
9912 #define task_pt_regs(task) \
9913 ({ \
9914 struct pt_regs *__regs__; \
9915- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
9916+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
9917 __regs__ - 1; \
9918 })
9919
9920@@ -946,13 +949,13 @@ extern unsigned long thread_saved_pc(str
9921 /*
9922 * User space process size. 47bits minus one guard page.
9923 */
9924-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
9925+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
9926
9927 /* This decides where the kernel will search for a free chunk of vm
9928 * space during mmap's.
9929 */
9930 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
9931- 0xc0000000 : 0xFFFFe000)
9932+ 0xc0000000 : 0xFFFFf000)
9933
9934 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
9935 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
9936@@ -963,11 +966,11 @@ extern unsigned long thread_saved_pc(str
9937 #define STACK_TOP_MAX TASK_SIZE_MAX
9938
9939 #define INIT_THREAD { \
9940- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9941+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9942 }
9943
9944 #define INIT_TSS { \
9945- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9946+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9947 }
9948
9949 /*
9950@@ -989,6 +992,10 @@ extern void start_thread(struct pt_regs
9951 */
9952 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
9953
9954+#ifdef CONFIG_PAX_SEGMEXEC
9955+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
9956+#endif
9957+
9958 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
9959
9960 /* Get/set a process' ability to use the timestamp counter instruction */
9961diff -urNp linux-2.6.32.43/arch/x86/include/asm/ptrace.h linux-2.6.32.43/arch/x86/include/asm/ptrace.h
9962--- linux-2.6.32.43/arch/x86/include/asm/ptrace.h 2011-03-27 14:31:47.000000000 -0400
9963+++ linux-2.6.32.43/arch/x86/include/asm/ptrace.h 2011-04-17 15:56:46.000000000 -0400
9964@@ -151,28 +151,29 @@ static inline unsigned long regs_return_
9965 }
9966
9967 /*
9968- * user_mode_vm(regs) determines whether a register set came from user mode.
9969+ * user_mode(regs) determines whether a register set came from user mode.
9970 * This is true if V8086 mode was enabled OR if the register set was from
9971 * protected mode with RPL-3 CS value. This tricky test checks that with
9972 * one comparison. Many places in the kernel can bypass this full check
9973- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
9974+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
9975+ * be used.
9976 */
9977-static inline int user_mode(struct pt_regs *regs)
9978+static inline int user_mode_novm(struct pt_regs *regs)
9979 {
9980 #ifdef CONFIG_X86_32
9981 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
9982 #else
9983- return !!(regs->cs & 3);
9984+ return !!(regs->cs & SEGMENT_RPL_MASK);
9985 #endif
9986 }
9987
9988-static inline int user_mode_vm(struct pt_regs *regs)
9989+static inline int user_mode(struct pt_regs *regs)
9990 {
9991 #ifdef CONFIG_X86_32
9992 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
9993 USER_RPL;
9994 #else
9995- return user_mode(regs);
9996+ return user_mode_novm(regs);
9997 #endif
9998 }
9999
10000diff -urNp linux-2.6.32.43/arch/x86/include/asm/reboot.h linux-2.6.32.43/arch/x86/include/asm/reboot.h
10001--- linux-2.6.32.43/arch/x86/include/asm/reboot.h 2011-03-27 14:31:47.000000000 -0400
10002+++ linux-2.6.32.43/arch/x86/include/asm/reboot.h 2011-08-05 20:33:55.000000000 -0400
10003@@ -6,19 +6,19 @@
10004 struct pt_regs;
10005
10006 struct machine_ops {
10007- void (*restart)(char *cmd);
10008- void (*halt)(void);
10009- void (*power_off)(void);
10010+ void (* __noreturn restart)(char *cmd);
10011+ void (* __noreturn halt)(void);
10012+ void (* __noreturn power_off)(void);
10013 void (*shutdown)(void);
10014 void (*crash_shutdown)(struct pt_regs *);
10015- void (*emergency_restart)(void);
10016-};
10017+ void (* __noreturn emergency_restart)(void);
10018+} __no_const;
10019
10020 extern struct machine_ops machine_ops;
10021
10022 void native_machine_crash_shutdown(struct pt_regs *regs);
10023 void native_machine_shutdown(void);
10024-void machine_real_restart(const unsigned char *code, int length);
10025+void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
10026
10027 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
10028 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
10029diff -urNp linux-2.6.32.43/arch/x86/include/asm/rwsem.h linux-2.6.32.43/arch/x86/include/asm/rwsem.h
10030--- linux-2.6.32.43/arch/x86/include/asm/rwsem.h 2011-03-27 14:31:47.000000000 -0400
10031+++ linux-2.6.32.43/arch/x86/include/asm/rwsem.h 2011-04-17 15:56:46.000000000 -0400
10032@@ -118,6 +118,14 @@ static inline void __down_read(struct rw
10033 {
10034 asm volatile("# beginning down_read\n\t"
10035 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10036+
10037+#ifdef CONFIG_PAX_REFCOUNT
10038+ "jno 0f\n"
10039+ LOCK_PREFIX _ASM_DEC "(%1)\n\t"
10040+ "int $4\n0:\n"
10041+ _ASM_EXTABLE(0b, 0b)
10042+#endif
10043+
10044 /* adds 0x00000001, returns the old value */
10045 " jns 1f\n"
10046 " call call_rwsem_down_read_failed\n"
10047@@ -139,6 +147,14 @@ static inline int __down_read_trylock(st
10048 "1:\n\t"
10049 " mov %1,%2\n\t"
10050 " add %3,%2\n\t"
10051+
10052+#ifdef CONFIG_PAX_REFCOUNT
10053+ "jno 0f\n"
10054+ "sub %3,%2\n"
10055+ "int $4\n0:\n"
10056+ _ASM_EXTABLE(0b, 0b)
10057+#endif
10058+
10059 " jle 2f\n\t"
10060 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10061 " jnz 1b\n\t"
10062@@ -160,6 +176,14 @@ static inline void __down_write_nested(s
10063 tmp = RWSEM_ACTIVE_WRITE_BIAS;
10064 asm volatile("# beginning down_write\n\t"
10065 LOCK_PREFIX " xadd %1,(%2)\n\t"
10066+
10067+#ifdef CONFIG_PAX_REFCOUNT
10068+ "jno 0f\n"
10069+ "mov %1,(%2)\n"
10070+ "int $4\n0:\n"
10071+ _ASM_EXTABLE(0b, 0b)
10072+#endif
10073+
10074 /* subtract 0x0000ffff, returns the old value */
10075 " test %1,%1\n\t"
10076 /* was the count 0 before? */
10077@@ -198,6 +222,14 @@ static inline void __up_read(struct rw_s
10078 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
10079 asm volatile("# beginning __up_read\n\t"
10080 LOCK_PREFIX " xadd %1,(%2)\n\t"
10081+
10082+#ifdef CONFIG_PAX_REFCOUNT
10083+ "jno 0f\n"
10084+ "mov %1,(%2)\n"
10085+ "int $4\n0:\n"
10086+ _ASM_EXTABLE(0b, 0b)
10087+#endif
10088+
10089 /* subtracts 1, returns the old value */
10090 " jns 1f\n\t"
10091 " call call_rwsem_wake\n"
10092@@ -216,6 +248,14 @@ static inline void __up_write(struct rw_
10093 rwsem_count_t tmp;
10094 asm volatile("# beginning __up_write\n\t"
10095 LOCK_PREFIX " xadd %1,(%2)\n\t"
10096+
10097+#ifdef CONFIG_PAX_REFCOUNT
10098+ "jno 0f\n"
10099+ "mov %1,(%2)\n"
10100+ "int $4\n0:\n"
10101+ _ASM_EXTABLE(0b, 0b)
10102+#endif
10103+
10104 /* tries to transition
10105 0xffff0001 -> 0x00000000 */
10106 " jz 1f\n"
10107@@ -234,6 +274,14 @@ static inline void __downgrade_write(str
10108 {
10109 asm volatile("# beginning __downgrade_write\n\t"
10110 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
10111+
10112+#ifdef CONFIG_PAX_REFCOUNT
10113+ "jno 0f\n"
10114+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
10115+ "int $4\n0:\n"
10116+ _ASM_EXTABLE(0b, 0b)
10117+#endif
10118+
10119 /*
10120 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
10121 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
10122@@ -253,7 +301,15 @@ static inline void __downgrade_write(str
10123 static inline void rwsem_atomic_add(rwsem_count_t delta,
10124 struct rw_semaphore *sem)
10125 {
10126- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
10127+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
10128+
10129+#ifdef CONFIG_PAX_REFCOUNT
10130+ "jno 0f\n"
10131+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
10132+ "int $4\n0:\n"
10133+ _ASM_EXTABLE(0b, 0b)
10134+#endif
10135+
10136 : "+m" (sem->count)
10137 : "er" (delta));
10138 }
10139@@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic
10140 {
10141 rwsem_count_t tmp = delta;
10142
10143- asm volatile(LOCK_PREFIX "xadd %0,%1"
10144+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
10145+
10146+#ifdef CONFIG_PAX_REFCOUNT
10147+ "jno 0f\n"
10148+ "mov %0,%1\n"
10149+ "int $4\n0:\n"
10150+ _ASM_EXTABLE(0b, 0b)
10151+#endif
10152+
10153 : "+r" (tmp), "+m" (sem->count)
10154 : : "memory");
10155
10156diff -urNp linux-2.6.32.43/arch/x86/include/asm/segment.h linux-2.6.32.43/arch/x86/include/asm/segment.h
10157--- linux-2.6.32.43/arch/x86/include/asm/segment.h 2011-03-27 14:31:47.000000000 -0400
10158+++ linux-2.6.32.43/arch/x86/include/asm/segment.h 2011-04-17 15:56:46.000000000 -0400
10159@@ -62,8 +62,8 @@
10160 * 26 - ESPFIX small SS
10161 * 27 - per-cpu [ offset to per-cpu data area ]
10162 * 28 - stack_canary-20 [ for stack protector ]
10163- * 29 - unused
10164- * 30 - unused
10165+ * 29 - PCI BIOS CS
10166+ * 30 - PCI BIOS DS
10167 * 31 - TSS for double fault handler
10168 */
10169 #define GDT_ENTRY_TLS_MIN 6
10170@@ -77,6 +77,8 @@
10171
10172 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
10173
10174+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
10175+
10176 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
10177
10178 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
10179@@ -88,7 +90,7 @@
10180 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
10181 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
10182
10183-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
10184+#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
10185 #ifdef CONFIG_SMP
10186 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
10187 #else
10188@@ -102,6 +104,12 @@
10189 #define __KERNEL_STACK_CANARY 0
10190 #endif
10191
10192+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
10193+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
10194+
10195+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
10196+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
10197+
10198 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
10199
10200 /*
10201@@ -139,7 +147,7 @@
10202 */
10203
10204 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
10205-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
10206+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
10207
10208
10209 #else
10210@@ -163,6 +171,8 @@
10211 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
10212 #define __USER32_DS __USER_DS
10213
10214+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
10215+
10216 #define GDT_ENTRY_TSS 8 /* needs two entries */
10217 #define GDT_ENTRY_LDT 10 /* needs two entries */
10218 #define GDT_ENTRY_TLS_MIN 12
10219@@ -183,6 +193,7 @@
10220 #endif
10221
10222 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
10223+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
10224 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
10225 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
10226 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
10227diff -urNp linux-2.6.32.43/arch/x86/include/asm/smp.h linux-2.6.32.43/arch/x86/include/asm/smp.h
10228--- linux-2.6.32.43/arch/x86/include/asm/smp.h 2011-03-27 14:31:47.000000000 -0400
10229+++ linux-2.6.32.43/arch/x86/include/asm/smp.h 2011-08-05 20:33:55.000000000 -0400
10230@@ -24,7 +24,7 @@ extern unsigned int num_processors;
10231 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
10232 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
10233 DECLARE_PER_CPU(u16, cpu_llc_id);
10234-DECLARE_PER_CPU(int, cpu_number);
10235+DECLARE_PER_CPU(unsigned int, cpu_number);
10236
10237 static inline struct cpumask *cpu_sibling_mask(int cpu)
10238 {
10239@@ -40,10 +40,7 @@ DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_ap
10240 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
10241
10242 /* Static state in head.S used to set up a CPU */
10243-extern struct {
10244- void *sp;
10245- unsigned short ss;
10246-} stack_start;
10247+extern unsigned long stack_start; /* Initial stack pointer address */
10248
10249 struct smp_ops {
10250 void (*smp_prepare_boot_cpu)(void);
10251@@ -60,7 +57,7 @@ struct smp_ops {
10252
10253 void (*send_call_func_ipi)(const struct cpumask *mask);
10254 void (*send_call_func_single_ipi)(int cpu);
10255-};
10256+} __no_const;
10257
10258 /* Globals due to paravirt */
10259 extern void set_cpu_sibling_map(int cpu);
10260@@ -175,14 +172,8 @@ extern unsigned disabled_cpus __cpuinitd
10261 extern int safe_smp_processor_id(void);
10262
10263 #elif defined(CONFIG_X86_64_SMP)
10264-#define raw_smp_processor_id() (percpu_read(cpu_number))
10265-
10266-#define stack_smp_processor_id() \
10267-({ \
10268- struct thread_info *ti; \
10269- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
10270- ti->cpu; \
10271-})
10272+#define raw_smp_processor_id() (percpu_read(cpu_number))
10273+#define stack_smp_processor_id() raw_smp_processor_id()
10274 #define safe_smp_processor_id() smp_processor_id()
10275
10276 #endif
10277diff -urNp linux-2.6.32.43/arch/x86/include/asm/spinlock.h linux-2.6.32.43/arch/x86/include/asm/spinlock.h
10278--- linux-2.6.32.43/arch/x86/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
10279+++ linux-2.6.32.43/arch/x86/include/asm/spinlock.h 2011-04-17 15:56:46.000000000 -0400
10280@@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(r
10281 static inline void __raw_read_lock(raw_rwlock_t *rw)
10282 {
10283 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
10284+
10285+#ifdef CONFIG_PAX_REFCOUNT
10286+ "jno 0f\n"
10287+ LOCK_PREFIX " addl $1,(%0)\n"
10288+ "int $4\n0:\n"
10289+ _ASM_EXTABLE(0b, 0b)
10290+#endif
10291+
10292 "jns 1f\n"
10293 "call __read_lock_failed\n\t"
10294 "1:\n"
10295@@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_r
10296 static inline void __raw_write_lock(raw_rwlock_t *rw)
10297 {
10298 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
10299+
10300+#ifdef CONFIG_PAX_REFCOUNT
10301+ "jno 0f\n"
10302+ LOCK_PREFIX " addl %1,(%0)\n"
10303+ "int $4\n0:\n"
10304+ _ASM_EXTABLE(0b, 0b)
10305+#endif
10306+
10307 "jz 1f\n"
10308 "call __write_lock_failed\n\t"
10309 "1:\n"
10310@@ -286,12 +302,29 @@ static inline int __raw_write_trylock(ra
10311
10312 static inline void __raw_read_unlock(raw_rwlock_t *rw)
10313 {
10314- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
10315+ asm volatile(LOCK_PREFIX "incl %0\n"
10316+
10317+#ifdef CONFIG_PAX_REFCOUNT
10318+ "jno 0f\n"
10319+ LOCK_PREFIX "decl %0\n"
10320+ "int $4\n0:\n"
10321+ _ASM_EXTABLE(0b, 0b)
10322+#endif
10323+
10324+ :"+m" (rw->lock) : : "memory");
10325 }
10326
10327 static inline void __raw_write_unlock(raw_rwlock_t *rw)
10328 {
10329- asm volatile(LOCK_PREFIX "addl %1, %0"
10330+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
10331+
10332+#ifdef CONFIG_PAX_REFCOUNT
10333+ "jno 0f\n"
10334+ LOCK_PREFIX "subl %1, %0\n"
10335+ "int $4\n0:\n"
10336+ _ASM_EXTABLE(0b, 0b)
10337+#endif
10338+
10339 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
10340 }
10341
10342diff -urNp linux-2.6.32.43/arch/x86/include/asm/stackprotector.h linux-2.6.32.43/arch/x86/include/asm/stackprotector.h
10343--- linux-2.6.32.43/arch/x86/include/asm/stackprotector.h 2011-03-27 14:31:47.000000000 -0400
10344+++ linux-2.6.32.43/arch/x86/include/asm/stackprotector.h 2011-07-06 19:53:33.000000000 -0400
10345@@ -48,7 +48,7 @@
10346 * head_32 for boot CPU and setup_per_cpu_areas() for others.
10347 */
10348 #define GDT_STACK_CANARY_INIT \
10349- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
10350+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
10351
10352 /*
10353 * Initialize the stackprotector canary value.
10354@@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
10355
10356 static inline void load_stack_canary_segment(void)
10357 {
10358-#ifdef CONFIG_X86_32
10359+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
10360 asm volatile ("mov %0, %%gs" : : "r" (0));
10361 #endif
10362 }
10363diff -urNp linux-2.6.32.43/arch/x86/include/asm/system.h linux-2.6.32.43/arch/x86/include/asm/system.h
10364--- linux-2.6.32.43/arch/x86/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
10365+++ linux-2.6.32.43/arch/x86/include/asm/system.h 2011-05-22 23:02:03.000000000 -0400
10366@@ -132,7 +132,7 @@ do { \
10367 "thread_return:\n\t" \
10368 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
10369 __switch_canary \
10370- "movq %P[thread_info](%%rsi),%%r8\n\t" \
10371+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
10372 "movq %%rax,%%rdi\n\t" \
10373 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
10374 "jnz ret_from_fork\n\t" \
10375@@ -143,7 +143,7 @@ do { \
10376 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
10377 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
10378 [_tif_fork] "i" (_TIF_FORK), \
10379- [thread_info] "i" (offsetof(struct task_struct, stack)), \
10380+ [thread_info] "m" (per_cpu_var(current_tinfo)), \
10381 [current_task] "m" (per_cpu_var(current_task)) \
10382 __switch_canary_iparam \
10383 : "memory", "cc" __EXTRA_CLOBBER)
10384@@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
10385 {
10386 unsigned long __limit;
10387 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
10388- return __limit + 1;
10389+ return __limit;
10390 }
10391
10392 static inline void native_clts(void)
10393@@ -340,12 +340,12 @@ void enable_hlt(void);
10394
10395 void cpu_idle_wait(void);
10396
10397-extern unsigned long arch_align_stack(unsigned long sp);
10398+#define arch_align_stack(x) ((x) & ~0xfUL)
10399 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
10400
10401 void default_idle(void);
10402
10403-void stop_this_cpu(void *dummy);
10404+void stop_this_cpu(void *dummy) __noreturn;
10405
10406 /*
10407 * Force strict CPU ordering.
10408diff -urNp linux-2.6.32.43/arch/x86/include/asm/thread_info.h linux-2.6.32.43/arch/x86/include/asm/thread_info.h
10409--- linux-2.6.32.43/arch/x86/include/asm/thread_info.h 2011-03-27 14:31:47.000000000 -0400
10410+++ linux-2.6.32.43/arch/x86/include/asm/thread_info.h 2011-05-17 19:26:34.000000000 -0400
10411@@ -10,6 +10,7 @@
10412 #include <linux/compiler.h>
10413 #include <asm/page.h>
10414 #include <asm/types.h>
10415+#include <asm/percpu.h>
10416
10417 /*
10418 * low level task data that entry.S needs immediate access to
10419@@ -24,7 +25,6 @@ struct exec_domain;
10420 #include <asm/atomic.h>
10421
10422 struct thread_info {
10423- struct task_struct *task; /* main task structure */
10424 struct exec_domain *exec_domain; /* execution domain */
10425 __u32 flags; /* low level flags */
10426 __u32 status; /* thread synchronous flags */
10427@@ -34,18 +34,12 @@ struct thread_info {
10428 mm_segment_t addr_limit;
10429 struct restart_block restart_block;
10430 void __user *sysenter_return;
10431-#ifdef CONFIG_X86_32
10432- unsigned long previous_esp; /* ESP of the previous stack in
10433- case of nested (IRQ) stacks
10434- */
10435- __u8 supervisor_stack[0];
10436-#endif
10437+ unsigned long lowest_stack;
10438 int uaccess_err;
10439 };
10440
10441-#define INIT_THREAD_INFO(tsk) \
10442+#define INIT_THREAD_INFO \
10443 { \
10444- .task = &tsk, \
10445 .exec_domain = &default_exec_domain, \
10446 .flags = 0, \
10447 .cpu = 0, \
10448@@ -56,7 +50,7 @@ struct thread_info {
10449 }, \
10450 }
10451
10452-#define init_thread_info (init_thread_union.thread_info)
10453+#define init_thread_info (init_thread_union.stack)
10454 #define init_stack (init_thread_union.stack)
10455
10456 #else /* !__ASSEMBLY__ */
10457@@ -163,6 +157,23 @@ struct thread_info {
10458 #define alloc_thread_info(tsk) \
10459 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
10460
10461+#ifdef __ASSEMBLY__
10462+/* how to get the thread information struct from ASM */
10463+#define GET_THREAD_INFO(reg) \
10464+ mov PER_CPU_VAR(current_tinfo), reg
10465+
10466+/* use this one if reg already contains %esp */
10467+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10468+#else
10469+/* how to get the thread information struct from C */
10470+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10471+
10472+static __always_inline struct thread_info *current_thread_info(void)
10473+{
10474+ return percpu_read_stable(current_tinfo);
10475+}
10476+#endif
10477+
10478 #ifdef CONFIG_X86_32
10479
10480 #define STACK_WARN (THREAD_SIZE/8)
10481@@ -173,35 +184,13 @@ struct thread_info {
10482 */
10483 #ifndef __ASSEMBLY__
10484
10485-
10486 /* how to get the current stack pointer from C */
10487 register unsigned long current_stack_pointer asm("esp") __used;
10488
10489-/* how to get the thread information struct from C */
10490-static inline struct thread_info *current_thread_info(void)
10491-{
10492- return (struct thread_info *)
10493- (current_stack_pointer & ~(THREAD_SIZE - 1));
10494-}
10495-
10496-#else /* !__ASSEMBLY__ */
10497-
10498-/* how to get the thread information struct from ASM */
10499-#define GET_THREAD_INFO(reg) \
10500- movl $-THREAD_SIZE, reg; \
10501- andl %esp, reg
10502-
10503-/* use this one if reg already contains %esp */
10504-#define GET_THREAD_INFO_WITH_ESP(reg) \
10505- andl $-THREAD_SIZE, reg
10506-
10507 #endif
10508
10509 #else /* X86_32 */
10510
10511-#include <asm/percpu.h>
10512-#define KERNEL_STACK_OFFSET (5*8)
10513-
10514 /*
10515 * macros/functions for gaining access to the thread information structure
10516 * preempt_count needs to be 1 initially, until the scheduler is functional.
10517@@ -209,21 +198,8 @@ static inline struct thread_info *curren
10518 #ifndef __ASSEMBLY__
10519 DECLARE_PER_CPU(unsigned long, kernel_stack);
10520
10521-static inline struct thread_info *current_thread_info(void)
10522-{
10523- struct thread_info *ti;
10524- ti = (void *)(percpu_read_stable(kernel_stack) +
10525- KERNEL_STACK_OFFSET - THREAD_SIZE);
10526- return ti;
10527-}
10528-
10529-#else /* !__ASSEMBLY__ */
10530-
10531-/* how to get the thread information struct from ASM */
10532-#define GET_THREAD_INFO(reg) \
10533- movq PER_CPU_VAR(kernel_stack),reg ; \
10534- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10535-
10536+/* how to get the current stack pointer from C */
10537+register unsigned long current_stack_pointer asm("rsp") __used;
10538 #endif
10539
10540 #endif /* !X86_32 */
10541@@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
10542 extern void free_thread_info(struct thread_info *ti);
10543 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10544 #define arch_task_cache_init arch_task_cache_init
10545+
10546+#define __HAVE_THREAD_FUNCTIONS
10547+#define task_thread_info(task) (&(task)->tinfo)
10548+#define task_stack_page(task) ((task)->stack)
10549+#define setup_thread_stack(p, org) do {} while (0)
10550+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10551+
10552+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10553+extern struct task_struct *alloc_task_struct(void);
10554+extern void free_task_struct(struct task_struct *);
10555+
10556 #endif
10557 #endif /* _ASM_X86_THREAD_INFO_H */
10558diff -urNp linux-2.6.32.43/arch/x86/include/asm/uaccess_32.h linux-2.6.32.43/arch/x86/include/asm/uaccess_32.h
10559--- linux-2.6.32.43/arch/x86/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
10560+++ linux-2.6.32.43/arch/x86/include/asm/uaccess_32.h 2011-05-16 21:46:57.000000000 -0400
10561@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
10562 static __always_inline unsigned long __must_check
10563 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10564 {
10565+ pax_track_stack();
10566+
10567+ if ((long)n < 0)
10568+ return n;
10569+
10570 if (__builtin_constant_p(n)) {
10571 unsigned long ret;
10572
10573@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
10574 return ret;
10575 }
10576 }
10577+ if (!__builtin_constant_p(n))
10578+ check_object_size(from, n, true);
10579 return __copy_to_user_ll(to, from, n);
10580 }
10581
10582@@ -83,12 +90,16 @@ static __always_inline unsigned long __m
10583 __copy_to_user(void __user *to, const void *from, unsigned long n)
10584 {
10585 might_fault();
10586+
10587 return __copy_to_user_inatomic(to, from, n);
10588 }
10589
10590 static __always_inline unsigned long
10591 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
10592 {
10593+ if ((long)n < 0)
10594+ return n;
10595+
10596 /* Avoid zeroing the tail if the copy fails..
10597 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
10598 * but as the zeroing behaviour is only significant when n is not
10599@@ -138,6 +149,12 @@ static __always_inline unsigned long
10600 __copy_from_user(void *to, const void __user *from, unsigned long n)
10601 {
10602 might_fault();
10603+
10604+ pax_track_stack();
10605+
10606+ if ((long)n < 0)
10607+ return n;
10608+
10609 if (__builtin_constant_p(n)) {
10610 unsigned long ret;
10611
10612@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
10613 return ret;
10614 }
10615 }
10616+ if (!__builtin_constant_p(n))
10617+ check_object_size(to, n, false);
10618 return __copy_from_user_ll(to, from, n);
10619 }
10620
10621@@ -160,6 +179,10 @@ static __always_inline unsigned long __c
10622 const void __user *from, unsigned long n)
10623 {
10624 might_fault();
10625+
10626+ if ((long)n < 0)
10627+ return n;
10628+
10629 if (__builtin_constant_p(n)) {
10630 unsigned long ret;
10631
10632@@ -182,14 +205,62 @@ static __always_inline unsigned long
10633 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
10634 unsigned long n)
10635 {
10636- return __copy_from_user_ll_nocache_nozero(to, from, n);
10637+ if ((long)n < 0)
10638+ return n;
10639+
10640+ return __copy_from_user_ll_nocache_nozero(to, from, n);
10641+}
10642+
10643+/**
10644+ * copy_to_user: - Copy a block of data into user space.
10645+ * @to: Destination address, in user space.
10646+ * @from: Source address, in kernel space.
10647+ * @n: Number of bytes to copy.
10648+ *
10649+ * Context: User context only. This function may sleep.
10650+ *
10651+ * Copy data from kernel space to user space.
10652+ *
10653+ * Returns number of bytes that could not be copied.
10654+ * On success, this will be zero.
10655+ */
10656+static __always_inline unsigned long __must_check
10657+copy_to_user(void __user *to, const void *from, unsigned long n)
10658+{
10659+ if (access_ok(VERIFY_WRITE, to, n))
10660+ n = __copy_to_user(to, from, n);
10661+ return n;
10662+}
10663+
10664+/**
10665+ * copy_from_user: - Copy a block of data from user space.
10666+ * @to: Destination address, in kernel space.
10667+ * @from: Source address, in user space.
10668+ * @n: Number of bytes to copy.
10669+ *
10670+ * Context: User context only. This function may sleep.
10671+ *
10672+ * Copy data from user space to kernel space.
10673+ *
10674+ * Returns number of bytes that could not be copied.
10675+ * On success, this will be zero.
10676+ *
10677+ * If some data could not be copied, this function will pad the copied
10678+ * data to the requested size using zero bytes.
10679+ */
10680+static __always_inline unsigned long __must_check
10681+copy_from_user(void *to, const void __user *from, unsigned long n)
10682+{
10683+ if (access_ok(VERIFY_READ, from, n))
10684+ n = __copy_from_user(to, from, n);
10685+ else if ((long)n > 0) {
10686+ if (!__builtin_constant_p(n))
10687+ check_object_size(to, n, false);
10688+ memset(to, 0, n);
10689+ }
10690+ return n;
10691 }
10692
10693-unsigned long __must_check copy_to_user(void __user *to,
10694- const void *from, unsigned long n);
10695-unsigned long __must_check copy_from_user(void *to,
10696- const void __user *from,
10697- unsigned long n);
10698 long __must_check strncpy_from_user(char *dst, const char __user *src,
10699 long count);
10700 long __must_check __strncpy_from_user(char *dst,
10701diff -urNp linux-2.6.32.43/arch/x86/include/asm/uaccess_64.h linux-2.6.32.43/arch/x86/include/asm/uaccess_64.h
10702--- linux-2.6.32.43/arch/x86/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
10703+++ linux-2.6.32.43/arch/x86/include/asm/uaccess_64.h 2011-05-16 21:46:57.000000000 -0400
10704@@ -9,6 +9,9 @@
10705 #include <linux/prefetch.h>
10706 #include <linux/lockdep.h>
10707 #include <asm/page.h>
10708+#include <asm/pgtable.h>
10709+
10710+#define set_fs(x) (current_thread_info()->addr_limit = (x))
10711
10712 /*
10713 * Copy To/From Userspace
10714@@ -19,113 +22,203 @@ __must_check unsigned long
10715 copy_user_generic(void *to, const void *from, unsigned len);
10716
10717 __must_check unsigned long
10718-copy_to_user(void __user *to, const void *from, unsigned len);
10719-__must_check unsigned long
10720-copy_from_user(void *to, const void __user *from, unsigned len);
10721-__must_check unsigned long
10722 copy_in_user(void __user *to, const void __user *from, unsigned len);
10723
10724 static __always_inline __must_check
10725-int __copy_from_user(void *dst, const void __user *src, unsigned size)
10726+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
10727 {
10728- int ret = 0;
10729+ unsigned ret = 0;
10730
10731 might_fault();
10732- if (!__builtin_constant_p(size))
10733- return copy_user_generic(dst, (__force void *)src, size);
10734+
10735+ if ((int)size < 0)
10736+ return size;
10737+
10738+#ifdef CONFIG_PAX_MEMORY_UDEREF
10739+ if (!__access_ok(VERIFY_READ, src, size))
10740+ return size;
10741+#endif
10742+
10743+ if (!__builtin_constant_p(size)) {
10744+ check_object_size(dst, size, false);
10745+
10746+#ifdef CONFIG_PAX_MEMORY_UDEREF
10747+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10748+ src += PAX_USER_SHADOW_BASE;
10749+#endif
10750+
10751+ return copy_user_generic(dst, (__force const void *)src, size);
10752+ }
10753 switch (size) {
10754- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
10755+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
10756 ret, "b", "b", "=q", 1);
10757 return ret;
10758- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
10759+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
10760 ret, "w", "w", "=r", 2);
10761 return ret;
10762- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
10763+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
10764 ret, "l", "k", "=r", 4);
10765 return ret;
10766- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
10767+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10768 ret, "q", "", "=r", 8);
10769 return ret;
10770 case 10:
10771- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10772+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10773 ret, "q", "", "=r", 10);
10774 if (unlikely(ret))
10775 return ret;
10776 __get_user_asm(*(u16 *)(8 + (char *)dst),
10777- (u16 __user *)(8 + (char __user *)src),
10778+ (const u16 __user *)(8 + (const char __user *)src),
10779 ret, "w", "w", "=r", 2);
10780 return ret;
10781 case 16:
10782- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10783+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10784 ret, "q", "", "=r", 16);
10785 if (unlikely(ret))
10786 return ret;
10787 __get_user_asm(*(u64 *)(8 + (char *)dst),
10788- (u64 __user *)(8 + (char __user *)src),
10789+ (const u64 __user *)(8 + (const char __user *)src),
10790 ret, "q", "", "=r", 8);
10791 return ret;
10792 default:
10793- return copy_user_generic(dst, (__force void *)src, size);
10794+
10795+#ifdef CONFIG_PAX_MEMORY_UDEREF
10796+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10797+ src += PAX_USER_SHADOW_BASE;
10798+#endif
10799+
10800+ return copy_user_generic(dst, (__force const void *)src, size);
10801 }
10802 }
10803
10804 static __always_inline __must_check
10805-int __copy_to_user(void __user *dst, const void *src, unsigned size)
10806+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
10807 {
10808- int ret = 0;
10809+ unsigned ret = 0;
10810
10811 might_fault();
10812- if (!__builtin_constant_p(size))
10813+
10814+ pax_track_stack();
10815+
10816+ if ((int)size < 0)
10817+ return size;
10818+
10819+#ifdef CONFIG_PAX_MEMORY_UDEREF
10820+ if (!__access_ok(VERIFY_WRITE, dst, size))
10821+ return size;
10822+#endif
10823+
10824+ if (!__builtin_constant_p(size)) {
10825+ check_object_size(src, size, true);
10826+
10827+#ifdef CONFIG_PAX_MEMORY_UDEREF
10828+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10829+ dst += PAX_USER_SHADOW_BASE;
10830+#endif
10831+
10832 return copy_user_generic((__force void *)dst, src, size);
10833+ }
10834 switch (size) {
10835- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
10836+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
10837 ret, "b", "b", "iq", 1);
10838 return ret;
10839- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
10840+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
10841 ret, "w", "w", "ir", 2);
10842 return ret;
10843- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
10844+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
10845 ret, "l", "k", "ir", 4);
10846 return ret;
10847- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
10848+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10849 ret, "q", "", "er", 8);
10850 return ret;
10851 case 10:
10852- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
10853+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10854 ret, "q", "", "er", 10);
10855 if (unlikely(ret))
10856 return ret;
10857 asm("":::"memory");
10858- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
10859+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
10860 ret, "w", "w", "ir", 2);
10861 return ret;
10862 case 16:
10863- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
10864+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10865 ret, "q", "", "er", 16);
10866 if (unlikely(ret))
10867 return ret;
10868 asm("":::"memory");
10869- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
10870+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
10871 ret, "q", "", "er", 8);
10872 return ret;
10873 default:
10874+
10875+#ifdef CONFIG_PAX_MEMORY_UDEREF
10876+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10877+ dst += PAX_USER_SHADOW_BASE;
10878+#endif
10879+
10880 return copy_user_generic((__force void *)dst, src, size);
10881 }
10882 }
10883
10884 static __always_inline __must_check
10885-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
10886+unsigned long copy_to_user(void __user *to, const void *from, unsigned len)
10887+{
10888+ if (access_ok(VERIFY_WRITE, to, len))
10889+ len = __copy_to_user(to, from, len);
10890+ return len;
10891+}
10892+
10893+static __always_inline __must_check
10894+unsigned long copy_from_user(void *to, const void __user *from, unsigned len)
10895+{
10896+ if ((int)len < 0)
10897+ return len;
10898+
10899+ if (access_ok(VERIFY_READ, from, len))
10900+ len = __copy_from_user(to, from, len);
10901+ else if ((int)len > 0) {
10902+ if (!__builtin_constant_p(len))
10903+ check_object_size(to, len, false);
10904+ memset(to, 0, len);
10905+ }
10906+ return len;
10907+}
10908+
10909+static __always_inline __must_check
10910+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
10911 {
10912- int ret = 0;
10913+ unsigned ret = 0;
10914
10915 might_fault();
10916- if (!__builtin_constant_p(size))
10917+
10918+ pax_track_stack();
10919+
10920+ if ((int)size < 0)
10921+ return size;
10922+
10923+#ifdef CONFIG_PAX_MEMORY_UDEREF
10924+ if (!__access_ok(VERIFY_READ, src, size))
10925+ return size;
10926+ if (!__access_ok(VERIFY_WRITE, dst, size))
10927+ return size;
10928+#endif
10929+
10930+ if (!__builtin_constant_p(size)) {
10931+
10932+#ifdef CONFIG_PAX_MEMORY_UDEREF
10933+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10934+ src += PAX_USER_SHADOW_BASE;
10935+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10936+ dst += PAX_USER_SHADOW_BASE;
10937+#endif
10938+
10939 return copy_user_generic((__force void *)dst,
10940- (__force void *)src, size);
10941+ (__force const void *)src, size);
10942+ }
10943 switch (size) {
10944 case 1: {
10945 u8 tmp;
10946- __get_user_asm(tmp, (u8 __user *)src,
10947+ __get_user_asm(tmp, (const u8 __user *)src,
10948 ret, "b", "b", "=q", 1);
10949 if (likely(!ret))
10950 __put_user_asm(tmp, (u8 __user *)dst,
10951@@ -134,7 +227,7 @@ int __copy_in_user(void __user *dst, con
10952 }
10953 case 2: {
10954 u16 tmp;
10955- __get_user_asm(tmp, (u16 __user *)src,
10956+ __get_user_asm(tmp, (const u16 __user *)src,
10957 ret, "w", "w", "=r", 2);
10958 if (likely(!ret))
10959 __put_user_asm(tmp, (u16 __user *)dst,
10960@@ -144,7 +237,7 @@ int __copy_in_user(void __user *dst, con
10961
10962 case 4: {
10963 u32 tmp;
10964- __get_user_asm(tmp, (u32 __user *)src,
10965+ __get_user_asm(tmp, (const u32 __user *)src,
10966 ret, "l", "k", "=r", 4);
10967 if (likely(!ret))
10968 __put_user_asm(tmp, (u32 __user *)dst,
10969@@ -153,7 +246,7 @@ int __copy_in_user(void __user *dst, con
10970 }
10971 case 8: {
10972 u64 tmp;
10973- __get_user_asm(tmp, (u64 __user *)src,
10974+ __get_user_asm(tmp, (const u64 __user *)src,
10975 ret, "q", "", "=r", 8);
10976 if (likely(!ret))
10977 __put_user_asm(tmp, (u64 __user *)dst,
10978@@ -161,8 +254,16 @@ int __copy_in_user(void __user *dst, con
10979 return ret;
10980 }
10981 default:
10982+
10983+#ifdef CONFIG_PAX_MEMORY_UDEREF
10984+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10985+ src += PAX_USER_SHADOW_BASE;
10986+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10987+ dst += PAX_USER_SHADOW_BASE;
10988+#endif
10989+
10990 return copy_user_generic((__force void *)dst,
10991- (__force void *)src, size);
10992+ (__force const void *)src, size);
10993 }
10994 }
10995
10996@@ -176,33 +277,75 @@ __must_check long strlen_user(const char
10997 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
10998 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
10999
11000-__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
11001- unsigned size);
11002+static __must_check __always_inline unsigned long
11003+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11004+{
11005+ pax_track_stack();
11006+
11007+ if ((int)size < 0)
11008+ return size;
11009
11010-static __must_check __always_inline int
11011+#ifdef CONFIG_PAX_MEMORY_UDEREF
11012+ if (!__access_ok(VERIFY_READ, src, size))
11013+ return size;
11014+
11015+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11016+ src += PAX_USER_SHADOW_BASE;
11017+#endif
11018+
11019+ return copy_user_generic(dst, (__force const void *)src, size);
11020+}
11021+
11022+static __must_check __always_inline unsigned long
11023 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
11024 {
11025+ if ((int)size < 0)
11026+ return size;
11027+
11028+#ifdef CONFIG_PAX_MEMORY_UDEREF
11029+ if (!__access_ok(VERIFY_WRITE, dst, size))
11030+ return size;
11031+
11032+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11033+ dst += PAX_USER_SHADOW_BASE;
11034+#endif
11035+
11036 return copy_user_generic((__force void *)dst, src, size);
11037 }
11038
11039-extern long __copy_user_nocache(void *dst, const void __user *src,
11040+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
11041 unsigned size, int zerorest);
11042
11043-static inline int
11044-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
11045+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
11046 {
11047 might_sleep();
11048+
11049+ if ((int)size < 0)
11050+ return size;
11051+
11052+#ifdef CONFIG_PAX_MEMORY_UDEREF
11053+ if (!__access_ok(VERIFY_READ, src, size))
11054+ return size;
11055+#endif
11056+
11057 return __copy_user_nocache(dst, src, size, 1);
11058 }
11059
11060-static inline int
11061-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11062+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11063 unsigned size)
11064 {
11065+ if ((int)size < 0)
11066+ return size;
11067+
11068+#ifdef CONFIG_PAX_MEMORY_UDEREF
11069+ if (!__access_ok(VERIFY_READ, src, size))
11070+ return size;
11071+#endif
11072+
11073 return __copy_user_nocache(dst, src, size, 0);
11074 }
11075
11076-unsigned long
11077+extern unsigned long
11078 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
11079
11080 #endif /* _ASM_X86_UACCESS_64_H */
11081diff -urNp linux-2.6.32.43/arch/x86/include/asm/uaccess.h linux-2.6.32.43/arch/x86/include/asm/uaccess.h
11082--- linux-2.6.32.43/arch/x86/include/asm/uaccess.h 2011-06-25 12:55:34.000000000 -0400
11083+++ linux-2.6.32.43/arch/x86/include/asm/uaccess.h 2011-06-25 12:56:37.000000000 -0400
11084@@ -8,12 +8,15 @@
11085 #include <linux/thread_info.h>
11086 #include <linux/prefetch.h>
11087 #include <linux/string.h>
11088+#include <linux/sched.h>
11089 #include <asm/asm.h>
11090 #include <asm/page.h>
11091
11092 #define VERIFY_READ 0
11093 #define VERIFY_WRITE 1
11094
11095+extern void check_object_size(const void *ptr, unsigned long n, bool to);
11096+
11097 /*
11098 * The fs value determines whether argument validity checking should be
11099 * performed or not. If get_fs() == USER_DS, checking is performed, with
11100@@ -29,7 +32,12 @@
11101
11102 #define get_ds() (KERNEL_DS)
11103 #define get_fs() (current_thread_info()->addr_limit)
11104+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11105+void __set_fs(mm_segment_t x);
11106+void set_fs(mm_segment_t x);
11107+#else
11108 #define set_fs(x) (current_thread_info()->addr_limit = (x))
11109+#endif
11110
11111 #define segment_eq(a, b) ((a).seg == (b).seg)
11112
11113@@ -77,7 +85,33 @@
11114 * checks that the pointer is in the user space range - after calling
11115 * this function, memory access functions may still return -EFAULT.
11116 */
11117-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11118+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
11119+#define access_ok(type, addr, size) \
11120+({ \
11121+ long __size = size; \
11122+ unsigned long __addr = (unsigned long)addr; \
11123+ unsigned long __addr_ao = __addr & PAGE_MASK; \
11124+ unsigned long __end_ao = __addr + __size - 1; \
11125+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
11126+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
11127+ while(__addr_ao <= __end_ao) { \
11128+ char __c_ao; \
11129+ __addr_ao += PAGE_SIZE; \
11130+ if (__size > PAGE_SIZE) \
11131+ cond_resched(); \
11132+ if (__get_user(__c_ao, (char __user *)__addr)) \
11133+ break; \
11134+ if (type != VERIFY_WRITE) { \
11135+ __addr = __addr_ao; \
11136+ continue; \
11137+ } \
11138+ if (__put_user(__c_ao, (char __user *)__addr)) \
11139+ break; \
11140+ __addr = __addr_ao; \
11141+ } \
11142+ } \
11143+ __ret_ao; \
11144+})
11145
11146 /*
11147 * The exception table consists of pairs of addresses: the first is the
11148@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
11149 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
11150 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
11151
11152-
11153+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
11154+#define __copyuser_seg "gs;"
11155+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
11156+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
11157+#else
11158+#define __copyuser_seg
11159+#define __COPYUSER_SET_ES
11160+#define __COPYUSER_RESTORE_ES
11161+#endif
11162
11163 #ifdef CONFIG_X86_32
11164 #define __put_user_asm_u64(x, addr, err, errret) \
11165- asm volatile("1: movl %%eax,0(%2)\n" \
11166- "2: movl %%edx,4(%2)\n" \
11167+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
11168+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
11169 "3:\n" \
11170 ".section .fixup,\"ax\"\n" \
11171 "4: movl %3,%0\n" \
11172@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
11173 : "A" (x), "r" (addr), "i" (errret), "0" (err))
11174
11175 #define __put_user_asm_ex_u64(x, addr) \
11176- asm volatile("1: movl %%eax,0(%1)\n" \
11177- "2: movl %%edx,4(%1)\n" \
11178+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
11179+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
11180 "3:\n" \
11181 _ASM_EXTABLE(1b, 2b - 1b) \
11182 _ASM_EXTABLE(2b, 3b - 2b) \
11183@@ -374,7 +416,7 @@ do { \
11184 } while (0)
11185
11186 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11187- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
11188+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
11189 "2:\n" \
11190 ".section .fixup,\"ax\"\n" \
11191 "3: mov %3,%0\n" \
11192@@ -382,7 +424,7 @@ do { \
11193 " jmp 2b\n" \
11194 ".previous\n" \
11195 _ASM_EXTABLE(1b, 3b) \
11196- : "=r" (err), ltype(x) \
11197+ : "=r" (err), ltype (x) \
11198 : "m" (__m(addr)), "i" (errret), "0" (err))
11199
11200 #define __get_user_size_ex(x, ptr, size) \
11201@@ -407,7 +449,7 @@ do { \
11202 } while (0)
11203
11204 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
11205- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
11206+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
11207 "2:\n" \
11208 _ASM_EXTABLE(1b, 2b - 1b) \
11209 : ltype(x) : "m" (__m(addr)))
11210@@ -424,13 +466,24 @@ do { \
11211 int __gu_err; \
11212 unsigned long __gu_val; \
11213 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
11214- (x) = (__force __typeof__(*(ptr)))__gu_val; \
11215+ (x) = (__typeof__(*(ptr)))__gu_val; \
11216 __gu_err; \
11217 })
11218
11219 /* FIXME: this hack is definitely wrong -AK */
11220 struct __large_struct { unsigned long buf[100]; };
11221-#define __m(x) (*(struct __large_struct __user *)(x))
11222+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11223+#define ____m(x) \
11224+({ \
11225+ unsigned long ____x = (unsigned long)(x); \
11226+ if (____x < PAX_USER_SHADOW_BASE) \
11227+ ____x += PAX_USER_SHADOW_BASE; \
11228+ (void __user *)____x; \
11229+})
11230+#else
11231+#define ____m(x) (x)
11232+#endif
11233+#define __m(x) (*(struct __large_struct __user *)____m(x))
11234
11235 /*
11236 * Tell gcc we read from memory instead of writing: this is because
11237@@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
11238 * aliasing issues.
11239 */
11240 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
11241- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
11242+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
11243 "2:\n" \
11244 ".section .fixup,\"ax\"\n" \
11245 "3: mov %3,%0\n" \
11246@@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
11247 ".previous\n" \
11248 _ASM_EXTABLE(1b, 3b) \
11249 : "=r"(err) \
11250- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
11251+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
11252
11253 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
11254- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
11255+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
11256 "2:\n" \
11257 _ASM_EXTABLE(1b, 2b - 1b) \
11258 : : ltype(x), "m" (__m(addr)))
11259@@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
11260 * On error, the variable @x is set to zero.
11261 */
11262
11263+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11264+#define __get_user(x, ptr) get_user((x), (ptr))
11265+#else
11266 #define __get_user(x, ptr) \
11267 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
11268+#endif
11269
11270 /**
11271 * __put_user: - Write a simple value into user space, with less checking.
11272@@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
11273 * Returns zero on success, or -EFAULT on error.
11274 */
11275
11276+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11277+#define __put_user(x, ptr) put_user((x), (ptr))
11278+#else
11279 #define __put_user(x, ptr) \
11280 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
11281+#endif
11282
11283 #define __get_user_unaligned __get_user
11284 #define __put_user_unaligned __put_user
11285@@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
11286 #define get_user_ex(x, ptr) do { \
11287 unsigned long __gue_val; \
11288 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
11289- (x) = (__force __typeof__(*(ptr)))__gue_val; \
11290+ (x) = (__typeof__(*(ptr)))__gue_val; \
11291 } while (0)
11292
11293 #ifdef CONFIG_X86_WP_WORKS_OK
11294@@ -567,6 +628,7 @@ extern struct movsl_mask {
11295
11296 #define ARCH_HAS_NOCACHE_UACCESS 1
11297
11298+#define ARCH_HAS_SORT_EXTABLE
11299 #ifdef CONFIG_X86_32
11300 # include "uaccess_32.h"
11301 #else
11302diff -urNp linux-2.6.32.43/arch/x86/include/asm/vgtod.h linux-2.6.32.43/arch/x86/include/asm/vgtod.h
11303--- linux-2.6.32.43/arch/x86/include/asm/vgtod.h 2011-03-27 14:31:47.000000000 -0400
11304+++ linux-2.6.32.43/arch/x86/include/asm/vgtod.h 2011-04-17 15:56:46.000000000 -0400
11305@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
11306 int sysctl_enabled;
11307 struct timezone sys_tz;
11308 struct { /* extract of a clocksource struct */
11309+ char name[8];
11310 cycle_t (*vread)(void);
11311 cycle_t cycle_last;
11312 cycle_t mask;
11313diff -urNp linux-2.6.32.43/arch/x86/include/asm/vmi.h linux-2.6.32.43/arch/x86/include/asm/vmi.h
11314--- linux-2.6.32.43/arch/x86/include/asm/vmi.h 2011-03-27 14:31:47.000000000 -0400
11315+++ linux-2.6.32.43/arch/x86/include/asm/vmi.h 2011-04-17 15:56:46.000000000 -0400
11316@@ -191,6 +191,7 @@ struct vrom_header {
11317 u8 reserved[96]; /* Reserved for headers */
11318 char vmi_init[8]; /* VMI_Init jump point */
11319 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
11320+ char rom_data[8048]; /* rest of the option ROM */
11321 } __attribute__((packed));
11322
11323 struct pnp_header {
11324diff -urNp linux-2.6.32.43/arch/x86/include/asm/vmi_time.h linux-2.6.32.43/arch/x86/include/asm/vmi_time.h
11325--- linux-2.6.32.43/arch/x86/include/asm/vmi_time.h 2011-03-27 14:31:47.000000000 -0400
11326+++ linux-2.6.32.43/arch/x86/include/asm/vmi_time.h 2011-08-05 20:33:55.000000000 -0400
11327@@ -43,7 +43,7 @@ extern struct vmi_timer_ops {
11328 int (*wallclock_updated)(void);
11329 void (*set_alarm)(u32 flags, u64 expiry, u64 period);
11330 void (*cancel_alarm)(u32 flags);
11331-} vmi_timer_ops;
11332+} __no_const vmi_timer_ops;
11333
11334 /* Prototypes */
11335 extern void __init vmi_time_init(void);
11336diff -urNp linux-2.6.32.43/arch/x86/include/asm/vsyscall.h linux-2.6.32.43/arch/x86/include/asm/vsyscall.h
11337--- linux-2.6.32.43/arch/x86/include/asm/vsyscall.h 2011-03-27 14:31:47.000000000 -0400
11338+++ linux-2.6.32.43/arch/x86/include/asm/vsyscall.h 2011-04-17 15:56:46.000000000 -0400
11339@@ -15,9 +15,10 @@ enum vsyscall_num {
11340
11341 #ifdef __KERNEL__
11342 #include <linux/seqlock.h>
11343+#include <linux/getcpu.h>
11344+#include <linux/time.h>
11345
11346 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
11347-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
11348
11349 /* Definitions for CONFIG_GENERIC_TIME definitions */
11350 #define __section_vsyscall_gtod_data __attribute__ \
11351@@ -31,7 +32,6 @@ enum vsyscall_num {
11352 #define VGETCPU_LSL 2
11353
11354 extern int __vgetcpu_mode;
11355-extern volatile unsigned long __jiffies;
11356
11357 /* kernel space (writeable) */
11358 extern int vgetcpu_mode;
11359@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
11360
11361 extern void map_vsyscall(void);
11362
11363+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
11364+extern time_t vtime(time_t *t);
11365+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
11366 #endif /* __KERNEL__ */
11367
11368 #endif /* _ASM_X86_VSYSCALL_H */
11369diff -urNp linux-2.6.32.43/arch/x86/include/asm/x86_init.h linux-2.6.32.43/arch/x86/include/asm/x86_init.h
11370--- linux-2.6.32.43/arch/x86/include/asm/x86_init.h 2011-03-27 14:31:47.000000000 -0400
11371+++ linux-2.6.32.43/arch/x86/include/asm/x86_init.h 2011-08-05 20:33:55.000000000 -0400
11372@@ -28,7 +28,7 @@ struct x86_init_mpparse {
11373 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
11374 void (*find_smp_config)(unsigned int reserve);
11375 void (*get_smp_config)(unsigned int early);
11376-};
11377+} __no_const;
11378
11379 /**
11380 * struct x86_init_resources - platform specific resource related ops
11381@@ -42,7 +42,7 @@ struct x86_init_resources {
11382 void (*probe_roms)(void);
11383 void (*reserve_resources)(void);
11384 char *(*memory_setup)(void);
11385-};
11386+} __no_const;
11387
11388 /**
11389 * struct x86_init_irqs - platform specific interrupt setup
11390@@ -55,7 +55,7 @@ struct x86_init_irqs {
11391 void (*pre_vector_init)(void);
11392 void (*intr_init)(void);
11393 void (*trap_init)(void);
11394-};
11395+} __no_const;
11396
11397 /**
11398 * struct x86_init_oem - oem platform specific customizing functions
11399@@ -65,7 +65,7 @@ struct x86_init_irqs {
11400 struct x86_init_oem {
11401 void (*arch_setup)(void);
11402 void (*banner)(void);
11403-};
11404+} __no_const;
11405
11406 /**
11407 * struct x86_init_paging - platform specific paging functions
11408@@ -75,7 +75,7 @@ struct x86_init_oem {
11409 struct x86_init_paging {
11410 void (*pagetable_setup_start)(pgd_t *base);
11411 void (*pagetable_setup_done)(pgd_t *base);
11412-};
11413+} __no_const;
11414
11415 /**
11416 * struct x86_init_timers - platform specific timer setup
11417@@ -88,7 +88,7 @@ struct x86_init_timers {
11418 void (*setup_percpu_clockev)(void);
11419 void (*tsc_pre_init)(void);
11420 void (*timer_init)(void);
11421-};
11422+} __no_const;
11423
11424 /**
11425 * struct x86_init_ops - functions for platform specific setup
11426@@ -101,7 +101,7 @@ struct x86_init_ops {
11427 struct x86_init_oem oem;
11428 struct x86_init_paging paging;
11429 struct x86_init_timers timers;
11430-};
11431+} __no_const;
11432
11433 /**
11434 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
11435@@ -109,7 +109,7 @@ struct x86_init_ops {
11436 */
11437 struct x86_cpuinit_ops {
11438 void (*setup_percpu_clockev)(void);
11439-};
11440+} __no_const;
11441
11442 /**
11443 * struct x86_platform_ops - platform specific runtime functions
11444@@ -121,7 +121,7 @@ struct x86_platform_ops {
11445 unsigned long (*calibrate_tsc)(void);
11446 unsigned long (*get_wallclock)(void);
11447 int (*set_wallclock)(unsigned long nowtime);
11448-};
11449+} __no_const;
11450
11451 extern struct x86_init_ops x86_init;
11452 extern struct x86_cpuinit_ops x86_cpuinit;
11453diff -urNp linux-2.6.32.43/arch/x86/include/asm/xsave.h linux-2.6.32.43/arch/x86/include/asm/xsave.h
11454--- linux-2.6.32.43/arch/x86/include/asm/xsave.h 2011-03-27 14:31:47.000000000 -0400
11455+++ linux-2.6.32.43/arch/x86/include/asm/xsave.h 2011-04-17 15:56:46.000000000 -0400
11456@@ -56,6 +56,12 @@ static inline int xrstor_checking(struct
11457 static inline int xsave_user(struct xsave_struct __user *buf)
11458 {
11459 int err;
11460+
11461+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11462+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
11463+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
11464+#endif
11465+
11466 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
11467 "2:\n"
11468 ".section .fixup,\"ax\"\n"
11469@@ -82,6 +88,11 @@ static inline int xrestore_user(struct x
11470 u32 lmask = mask;
11471 u32 hmask = mask >> 32;
11472
11473+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11474+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
11475+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
11476+#endif
11477+
11478 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
11479 "2:\n"
11480 ".section .fixup,\"ax\"\n"
11481diff -urNp linux-2.6.32.43/arch/x86/Kconfig linux-2.6.32.43/arch/x86/Kconfig
11482--- linux-2.6.32.43/arch/x86/Kconfig 2011-03-27 14:31:47.000000000 -0400
11483+++ linux-2.6.32.43/arch/x86/Kconfig 2011-04-17 15:56:46.000000000 -0400
11484@@ -223,7 +223,7 @@ config X86_TRAMPOLINE
11485
11486 config X86_32_LAZY_GS
11487 def_bool y
11488- depends on X86_32 && !CC_STACKPROTECTOR
11489+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11490
11491 config KTIME_SCALAR
11492 def_bool X86_32
11493@@ -1008,7 +1008,7 @@ choice
11494
11495 config NOHIGHMEM
11496 bool "off"
11497- depends on !X86_NUMAQ
11498+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11499 ---help---
11500 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11501 However, the address space of 32-bit x86 processors is only 4
11502@@ -1045,7 +1045,7 @@ config NOHIGHMEM
11503
11504 config HIGHMEM4G
11505 bool "4GB"
11506- depends on !X86_NUMAQ
11507+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11508 ---help---
11509 Select this if you have a 32-bit processor and between 1 and 4
11510 gigabytes of physical RAM.
11511@@ -1099,7 +1099,7 @@ config PAGE_OFFSET
11512 hex
11513 default 0xB0000000 if VMSPLIT_3G_OPT
11514 default 0x80000000 if VMSPLIT_2G
11515- default 0x78000000 if VMSPLIT_2G_OPT
11516+ default 0x70000000 if VMSPLIT_2G_OPT
11517 default 0x40000000 if VMSPLIT_1G
11518 default 0xC0000000
11519 depends on X86_32
11520@@ -1430,7 +1430,7 @@ config ARCH_USES_PG_UNCACHED
11521
11522 config EFI
11523 bool "EFI runtime service support"
11524- depends on ACPI
11525+ depends on ACPI && !PAX_KERNEXEC
11526 ---help---
11527 This enables the kernel to use EFI runtime services that are
11528 available (such as the EFI variable services).
11529@@ -1460,6 +1460,7 @@ config SECCOMP
11530
11531 config CC_STACKPROTECTOR
11532 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
11533+ depends on X86_64 || !PAX_MEMORY_UDEREF
11534 ---help---
11535 This option turns on the -fstack-protector GCC feature. This
11536 feature puts, at the beginning of functions, a canary value on
11537@@ -1517,6 +1518,7 @@ config KEXEC_JUMP
11538 config PHYSICAL_START
11539 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
11540 default "0x1000000"
11541+ range 0x400000 0x40000000
11542 ---help---
11543 This gives the physical address where the kernel is loaded.
11544
11545@@ -1581,6 +1583,7 @@ config PHYSICAL_ALIGN
11546 hex
11547 prompt "Alignment value to which kernel should be aligned" if X86_32
11548 default "0x1000000"
11549+ range 0x400000 0x1000000 if PAX_KERNEXEC
11550 range 0x2000 0x1000000
11551 ---help---
11552 This value puts the alignment restrictions on physical address
11553@@ -1612,9 +1615,10 @@ config HOTPLUG_CPU
11554 Say N if you want to disable CPU hotplug.
11555
11556 config COMPAT_VDSO
11557- def_bool y
11558+ def_bool n
11559 prompt "Compat VDSO support"
11560 depends on X86_32 || IA32_EMULATION
11561+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
11562 ---help---
11563 Map the 32-bit VDSO to the predictable old-style address too.
11564 ---help---
11565diff -urNp linux-2.6.32.43/arch/x86/Kconfig.cpu linux-2.6.32.43/arch/x86/Kconfig.cpu
11566--- linux-2.6.32.43/arch/x86/Kconfig.cpu 2011-03-27 14:31:47.000000000 -0400
11567+++ linux-2.6.32.43/arch/x86/Kconfig.cpu 2011-04-17 15:56:46.000000000 -0400
11568@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
11569
11570 config X86_F00F_BUG
11571 def_bool y
11572- depends on M586MMX || M586TSC || M586 || M486 || M386
11573+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
11574
11575 config X86_WP_WORKS_OK
11576 def_bool y
11577@@ -360,7 +360,7 @@ config X86_POPAD_OK
11578
11579 config X86_ALIGNMENT_16
11580 def_bool y
11581- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11582+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11583
11584 config X86_INTEL_USERCOPY
11585 def_bool y
11586@@ -406,7 +406,7 @@ config X86_CMPXCHG64
11587 # generates cmov.
11588 config X86_CMOV
11589 def_bool y
11590- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
11591+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
11592
11593 config X86_MINIMUM_CPU_FAMILY
11594 int
11595diff -urNp linux-2.6.32.43/arch/x86/Kconfig.debug linux-2.6.32.43/arch/x86/Kconfig.debug
11596--- linux-2.6.32.43/arch/x86/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
11597+++ linux-2.6.32.43/arch/x86/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
11598@@ -99,7 +99,7 @@ config X86_PTDUMP
11599 config DEBUG_RODATA
11600 bool "Write protect kernel read-only data structures"
11601 default y
11602- depends on DEBUG_KERNEL
11603+ depends on DEBUG_KERNEL && BROKEN
11604 ---help---
11605 Mark the kernel read-only data as write-protected in the pagetables,
11606 in order to catch accidental (and incorrect) writes to such const
11607diff -urNp linux-2.6.32.43/arch/x86/kernel/acpi/realmode/Makefile linux-2.6.32.43/arch/x86/kernel/acpi/realmode/Makefile
11608--- linux-2.6.32.43/arch/x86/kernel/acpi/realmode/Makefile 2011-03-27 14:31:47.000000000 -0400
11609+++ linux-2.6.32.43/arch/x86/kernel/acpi/realmode/Makefile 2011-08-07 14:38:58.000000000 -0400
11610@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os
11611 $(call cc-option, -fno-stack-protector) \
11612 $(call cc-option, -mpreferred-stack-boundary=2)
11613 KBUILD_CFLAGS += $(call cc-option, -m32)
11614+ifdef CONSTIFY_PLUGIN
11615+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
11616+endif
11617 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11618 GCOV_PROFILE := n
11619
11620diff -urNp linux-2.6.32.43/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.32.43/arch/x86/kernel/acpi/realmode/wakeup.S
11621--- linux-2.6.32.43/arch/x86/kernel/acpi/realmode/wakeup.S 2011-03-27 14:31:47.000000000 -0400
11622+++ linux-2.6.32.43/arch/x86/kernel/acpi/realmode/wakeup.S 2011-07-01 18:53:40.000000000 -0400
11623@@ -91,6 +91,9 @@ _start:
11624 /* Do any other stuff... */
11625
11626 #ifndef CONFIG_64BIT
11627+ /* Recheck NX bit overrides (64bit path does this in trampoline) */
11628+ call verify_cpu
11629+
11630 /* This could also be done in C code... */
11631 movl pmode_cr3, %eax
11632 movl %eax, %cr3
11633@@ -104,7 +107,7 @@ _start:
11634 movl %eax, %ecx
11635 orl %edx, %ecx
11636 jz 1f
11637- movl $0xc0000080, %ecx
11638+ mov $MSR_EFER, %ecx
11639 wrmsr
11640 1:
11641
11642@@ -114,6 +117,7 @@ _start:
11643 movl pmode_cr0, %eax
11644 movl %eax, %cr0
11645 jmp pmode_return
11646+# include "../../verify_cpu.S"
11647 #else
11648 pushw $0
11649 pushw trampoline_segment
11650diff -urNp linux-2.6.32.43/arch/x86/kernel/acpi/sleep.c linux-2.6.32.43/arch/x86/kernel/acpi/sleep.c
11651--- linux-2.6.32.43/arch/x86/kernel/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
11652+++ linux-2.6.32.43/arch/x86/kernel/acpi/sleep.c 2011-07-01 19:01:34.000000000 -0400
11653@@ -11,11 +11,12 @@
11654 #include <linux/cpumask.h>
11655 #include <asm/segment.h>
11656 #include <asm/desc.h>
11657+#include <asm/e820.h>
11658
11659 #include "realmode/wakeup.h"
11660 #include "sleep.h"
11661
11662-unsigned long acpi_wakeup_address;
11663+unsigned long acpi_wakeup_address = 0x2000;
11664 unsigned long acpi_realmode_flags;
11665
11666 /* address in low memory of the wakeup routine. */
11667@@ -98,9 +99,13 @@ int acpi_save_state_mem(void)
11668 #else /* CONFIG_64BIT */
11669 header->trampoline_segment = setup_trampoline() >> 4;
11670 #ifdef CONFIG_SMP
11671- stack_start.sp = temp_stack + sizeof(temp_stack);
11672+ stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
11673+
11674+ pax_open_kernel();
11675 early_gdt_descr.address =
11676 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11677+ pax_close_kernel();
11678+
11679 initial_gs = per_cpu_offset(smp_processor_id());
11680 #endif
11681 initial_code = (unsigned long)wakeup_long64;
11682@@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
11683 return;
11684 }
11685
11686- acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
11687-
11688- if (!acpi_realmode) {
11689- printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
11690- return;
11691- }
11692-
11693- acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
11694+ reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
11695+ acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
11696 }
11697
11698
11699diff -urNp linux-2.6.32.43/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.32.43/arch/x86/kernel/acpi/wakeup_32.S
11700--- linux-2.6.32.43/arch/x86/kernel/acpi/wakeup_32.S 2011-03-27 14:31:47.000000000 -0400
11701+++ linux-2.6.32.43/arch/x86/kernel/acpi/wakeup_32.S 2011-04-17 15:56:46.000000000 -0400
11702@@ -30,13 +30,11 @@ wakeup_pmode_return:
11703 # and restore the stack ... but you need gdt for this to work
11704 movl saved_context_esp, %esp
11705
11706- movl %cs:saved_magic, %eax
11707- cmpl $0x12345678, %eax
11708+ cmpl $0x12345678, saved_magic
11709 jne bogus_magic
11710
11711 # jump to place where we left off
11712- movl saved_eip, %eax
11713- jmp *%eax
11714+ jmp *(saved_eip)
11715
11716 bogus_magic:
11717 jmp bogus_magic
11718diff -urNp linux-2.6.32.43/arch/x86/kernel/alternative.c linux-2.6.32.43/arch/x86/kernel/alternative.c
11719--- linux-2.6.32.43/arch/x86/kernel/alternative.c 2011-03-27 14:31:47.000000000 -0400
11720+++ linux-2.6.32.43/arch/x86/kernel/alternative.c 2011-04-17 15:56:46.000000000 -0400
11721@@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(str
11722
11723 BUG_ON(p->len > MAX_PATCH_LEN);
11724 /* prep the buffer with the original instructions */
11725- memcpy(insnbuf, p->instr, p->len);
11726+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11727 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11728 (unsigned long)p->instr, p->len);
11729
11730@@ -475,7 +475,7 @@ void __init alternative_instructions(voi
11731 if (smp_alt_once)
11732 free_init_pages("SMP alternatives",
11733 (unsigned long)__smp_locks,
11734- (unsigned long)__smp_locks_end);
11735+ PAGE_ALIGN((unsigned long)__smp_locks_end));
11736
11737 restart_nmi();
11738 }
11739@@ -492,13 +492,17 @@ void __init alternative_instructions(voi
11740 * instructions. And on the local CPU you need to be protected again NMI or MCE
11741 * handlers seeing an inconsistent instruction while you patch.
11742 */
11743-static void *__init_or_module text_poke_early(void *addr, const void *opcode,
11744+static void *__kprobes text_poke_early(void *addr, const void *opcode,
11745 size_t len)
11746 {
11747 unsigned long flags;
11748 local_irq_save(flags);
11749- memcpy(addr, opcode, len);
11750+
11751+ pax_open_kernel();
11752+ memcpy(ktla_ktva(addr), opcode, len);
11753 sync_core();
11754+ pax_close_kernel();
11755+
11756 local_irq_restore(flags);
11757 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11758 that causes hangs on some VIA CPUs. */
11759@@ -520,35 +524,21 @@ static void *__init_or_module text_poke_
11760 */
11761 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11762 {
11763- unsigned long flags;
11764- char *vaddr;
11765+ unsigned char *vaddr = ktla_ktva(addr);
11766 struct page *pages[2];
11767- int i;
11768+ size_t i;
11769
11770 if (!core_kernel_text((unsigned long)addr)) {
11771- pages[0] = vmalloc_to_page(addr);
11772- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11773+ pages[0] = vmalloc_to_page(vaddr);
11774+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11775 } else {
11776- pages[0] = virt_to_page(addr);
11777+ pages[0] = virt_to_page(vaddr);
11778 WARN_ON(!PageReserved(pages[0]));
11779- pages[1] = virt_to_page(addr + PAGE_SIZE);
11780+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11781 }
11782 BUG_ON(!pages[0]);
11783- local_irq_save(flags);
11784- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11785- if (pages[1])
11786- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11787- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11788- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11789- clear_fixmap(FIX_TEXT_POKE0);
11790- if (pages[1])
11791- clear_fixmap(FIX_TEXT_POKE1);
11792- local_flush_tlb();
11793- sync_core();
11794- /* Could also do a CLFLUSH here to speed up CPU recovery; but
11795- that causes hangs on some VIA CPUs. */
11796+ text_poke_early(addr, opcode, len);
11797 for (i = 0; i < len; i++)
11798- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11799- local_irq_restore(flags);
11800+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11801 return addr;
11802 }
11803diff -urNp linux-2.6.32.43/arch/x86/kernel/amd_iommu.c linux-2.6.32.43/arch/x86/kernel/amd_iommu.c
11804--- linux-2.6.32.43/arch/x86/kernel/amd_iommu.c 2011-03-27 14:31:47.000000000 -0400
11805+++ linux-2.6.32.43/arch/x86/kernel/amd_iommu.c 2011-04-17 15:56:46.000000000 -0400
11806@@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(
11807 }
11808 }
11809
11810-static struct dma_map_ops amd_iommu_dma_ops = {
11811+static const struct dma_map_ops amd_iommu_dma_ops = {
11812 .alloc_coherent = alloc_coherent,
11813 .free_coherent = free_coherent,
11814 .map_page = map_page,
11815diff -urNp linux-2.6.32.43/arch/x86/kernel/apic/apic.c linux-2.6.32.43/arch/x86/kernel/apic/apic.c
11816--- linux-2.6.32.43/arch/x86/kernel/apic/apic.c 2011-03-27 14:31:47.000000000 -0400
11817+++ linux-2.6.32.43/arch/x86/kernel/apic/apic.c 2011-05-16 21:46:57.000000000 -0400
11818@@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs
11819 apic_write(APIC_ESR, 0);
11820 v1 = apic_read(APIC_ESR);
11821 ack_APIC_irq();
11822- atomic_inc(&irq_err_count);
11823+ atomic_inc_unchecked(&irq_err_count);
11824
11825 /*
11826 * Here is what the APIC error bits mean:
11827@@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(vo
11828 u16 *bios_cpu_apicid;
11829 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
11830
11831+ pax_track_stack();
11832+
11833 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
11834 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
11835
11836diff -urNp linux-2.6.32.43/arch/x86/kernel/apic/io_apic.c linux-2.6.32.43/arch/x86/kernel/apic/io_apic.c
11837--- linux-2.6.32.43/arch/x86/kernel/apic/io_apic.c 2011-03-27 14:31:47.000000000 -0400
11838+++ linux-2.6.32.43/arch/x86/kernel/apic/io_apic.c 2011-05-04 17:56:20.000000000 -0400
11839@@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapi
11840 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
11841 GFP_ATOMIC);
11842 if (!ioapic_entries)
11843- return 0;
11844+ return NULL;
11845
11846 for (apic = 0; apic < nr_ioapics; apic++) {
11847 ioapic_entries[apic] =
11848@@ -733,7 +733,7 @@ nomem:
11849 kfree(ioapic_entries[apic]);
11850 kfree(ioapic_entries);
11851
11852- return 0;
11853+ return NULL;
11854 }
11855
11856 /*
11857@@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
11858 }
11859 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
11860
11861-void lock_vector_lock(void)
11862+void lock_vector_lock(void) __acquires(vector_lock)
11863 {
11864 /* Used to the online set of cpus does not change
11865 * during assign_irq_vector.
11866@@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
11867 spin_lock(&vector_lock);
11868 }
11869
11870-void unlock_vector_lock(void)
11871+void unlock_vector_lock(void) __releases(vector_lock)
11872 {
11873 spin_unlock(&vector_lock);
11874 }
11875@@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int i
11876 ack_APIC_irq();
11877 }
11878
11879-atomic_t irq_mis_count;
11880+atomic_unchecked_t irq_mis_count;
11881
11882 static void ack_apic_level(unsigned int irq)
11883 {
11884@@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int
11885
11886 /* Tail end of version 0x11 I/O APIC bug workaround */
11887 if (!(v & (1 << (i & 0x1f)))) {
11888- atomic_inc(&irq_mis_count);
11889+ atomic_inc_unchecked(&irq_mis_count);
11890 spin_lock(&ioapic_lock);
11891 __mask_and_edge_IO_APIC_irq(cfg);
11892 __unmask_and_level_IO_APIC_irq(cfg);
11893diff -urNp linux-2.6.32.43/arch/x86/kernel/apm_32.c linux-2.6.32.43/arch/x86/kernel/apm_32.c
11894--- linux-2.6.32.43/arch/x86/kernel/apm_32.c 2011-03-27 14:31:47.000000000 -0400
11895+++ linux-2.6.32.43/arch/x86/kernel/apm_32.c 2011-04-23 12:56:10.000000000 -0400
11896@@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
11897 * This is for buggy BIOS's that refer to (real mode) segment 0x40
11898 * even though they are called in protected mode.
11899 */
11900-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
11901+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
11902 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
11903
11904 static const char driver_version[] = "1.16ac"; /* no spaces */
11905@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
11906 BUG_ON(cpu != 0);
11907 gdt = get_cpu_gdt_table(cpu);
11908 save_desc_40 = gdt[0x40 / 8];
11909+
11910+ pax_open_kernel();
11911 gdt[0x40 / 8] = bad_bios_desc;
11912+ pax_close_kernel();
11913
11914 apm_irq_save(flags);
11915 APM_DO_SAVE_SEGS;
11916@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
11917 &call->esi);
11918 APM_DO_RESTORE_SEGS;
11919 apm_irq_restore(flags);
11920+
11921+ pax_open_kernel();
11922 gdt[0x40 / 8] = save_desc_40;
11923+ pax_close_kernel();
11924+
11925 put_cpu();
11926
11927 return call->eax & 0xff;
11928@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void
11929 BUG_ON(cpu != 0);
11930 gdt = get_cpu_gdt_table(cpu);
11931 save_desc_40 = gdt[0x40 / 8];
11932+
11933+ pax_open_kernel();
11934 gdt[0x40 / 8] = bad_bios_desc;
11935+ pax_close_kernel();
11936
11937 apm_irq_save(flags);
11938 APM_DO_SAVE_SEGS;
11939@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void
11940 &call->eax);
11941 APM_DO_RESTORE_SEGS;
11942 apm_irq_restore(flags);
11943+
11944+ pax_open_kernel();
11945 gdt[0x40 / 8] = save_desc_40;
11946+ pax_close_kernel();
11947+
11948 put_cpu();
11949 return error;
11950 }
11951@@ -975,7 +989,7 @@ recalc:
11952
11953 static void apm_power_off(void)
11954 {
11955- unsigned char po_bios_call[] = {
11956+ const unsigned char po_bios_call[] = {
11957 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
11958 0x8e, 0xd0, /* movw ax,ss */
11959 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
11960@@ -2357,12 +2371,15 @@ static int __init apm_init(void)
11961 * code to that CPU.
11962 */
11963 gdt = get_cpu_gdt_table(0);
11964+
11965+ pax_open_kernel();
11966 set_desc_base(&gdt[APM_CS >> 3],
11967 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
11968 set_desc_base(&gdt[APM_CS_16 >> 3],
11969 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
11970 set_desc_base(&gdt[APM_DS >> 3],
11971 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
11972+ pax_close_kernel();
11973
11974 proc_create("apm", 0, NULL, &apm_file_ops);
11975
11976diff -urNp linux-2.6.32.43/arch/x86/kernel/asm-offsets_32.c linux-2.6.32.43/arch/x86/kernel/asm-offsets_32.c
11977--- linux-2.6.32.43/arch/x86/kernel/asm-offsets_32.c 2011-03-27 14:31:47.000000000 -0400
11978+++ linux-2.6.32.43/arch/x86/kernel/asm-offsets_32.c 2011-05-16 21:46:57.000000000 -0400
11979@@ -51,7 +51,6 @@ void foo(void)
11980 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
11981 BLANK();
11982
11983- OFFSET(TI_task, thread_info, task);
11984 OFFSET(TI_exec_domain, thread_info, exec_domain);
11985 OFFSET(TI_flags, thread_info, flags);
11986 OFFSET(TI_status, thread_info, status);
11987@@ -60,6 +59,8 @@ void foo(void)
11988 OFFSET(TI_restart_block, thread_info, restart_block);
11989 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
11990 OFFSET(TI_cpu, thread_info, cpu);
11991+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
11992+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11993 BLANK();
11994
11995 OFFSET(GDS_size, desc_ptr, size);
11996@@ -99,6 +100,7 @@ void foo(void)
11997
11998 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
11999 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12000+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12001 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
12002 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
12003 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
12004@@ -115,6 +117,11 @@ void foo(void)
12005 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
12006 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12007 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12008+
12009+#ifdef CONFIG_PAX_KERNEXEC
12010+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12011+#endif
12012+
12013 #endif
12014
12015 #ifdef CONFIG_XEN
12016diff -urNp linux-2.6.32.43/arch/x86/kernel/asm-offsets_64.c linux-2.6.32.43/arch/x86/kernel/asm-offsets_64.c
12017--- linux-2.6.32.43/arch/x86/kernel/asm-offsets_64.c 2011-03-27 14:31:47.000000000 -0400
12018+++ linux-2.6.32.43/arch/x86/kernel/asm-offsets_64.c 2011-05-16 21:46:57.000000000 -0400
12019@@ -44,6 +44,8 @@ int main(void)
12020 ENTRY(addr_limit);
12021 ENTRY(preempt_count);
12022 ENTRY(status);
12023+ ENTRY(lowest_stack);
12024+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12025 #ifdef CONFIG_IA32_EMULATION
12026 ENTRY(sysenter_return);
12027 #endif
12028@@ -63,6 +65,18 @@ int main(void)
12029 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12030 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
12031 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12032+
12033+#ifdef CONFIG_PAX_KERNEXEC
12034+ OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12035+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12036+#endif
12037+
12038+#ifdef CONFIG_PAX_MEMORY_UDEREF
12039+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12040+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12041+ OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
12042+#endif
12043+
12044 #endif
12045
12046
12047@@ -115,6 +129,7 @@ int main(void)
12048 ENTRY(cr8);
12049 BLANK();
12050 #undef ENTRY
12051+ DEFINE(TSS_size, sizeof(struct tss_struct));
12052 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
12053 BLANK();
12054 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
12055@@ -130,6 +145,7 @@ int main(void)
12056
12057 BLANK();
12058 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12059+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12060 #ifdef CONFIG_XEN
12061 BLANK();
12062 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12063diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/amd.c linux-2.6.32.43/arch/x86/kernel/cpu/amd.c
12064--- linux-2.6.32.43/arch/x86/kernel/cpu/amd.c 2011-06-25 12:55:34.000000000 -0400
12065+++ linux-2.6.32.43/arch/x86/kernel/cpu/amd.c 2011-06-25 12:56:37.000000000 -0400
12066@@ -602,7 +602,7 @@ static unsigned int __cpuinit amd_size_c
12067 unsigned int size)
12068 {
12069 /* AMD errata T13 (order #21922) */
12070- if ((c->x86 == 6)) {
12071+ if (c->x86 == 6) {
12072 /* Duron Rev A0 */
12073 if (c->x86_model == 3 && c->x86_mask == 0)
12074 size = 64;
12075diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/common.c linux-2.6.32.43/arch/x86/kernel/cpu/common.c
12076--- linux-2.6.32.43/arch/x86/kernel/cpu/common.c 2011-03-27 14:31:47.000000000 -0400
12077+++ linux-2.6.32.43/arch/x86/kernel/cpu/common.c 2011-05-11 18:25:15.000000000 -0400
12078@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
12079
12080 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12081
12082-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12083-#ifdef CONFIG_X86_64
12084- /*
12085- * We need valid kernel segments for data and code in long mode too
12086- * IRET will check the segment types kkeil 2000/10/28
12087- * Also sysret mandates a special GDT layout
12088- *
12089- * TLS descriptors are currently at a different place compared to i386.
12090- * Hopefully nobody expects them at a fixed place (Wine?)
12091- */
12092- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12093- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12094- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12095- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12096- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12097- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12098-#else
12099- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12100- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12101- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12102- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12103- /*
12104- * Segments used for calling PnP BIOS have byte granularity.
12105- * They code segments and data segments have fixed 64k limits,
12106- * the transfer segment sizes are set at run time.
12107- */
12108- /* 32-bit code */
12109- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12110- /* 16-bit code */
12111- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12112- /* 16-bit data */
12113- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12114- /* 16-bit data */
12115- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12116- /* 16-bit data */
12117- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12118- /*
12119- * The APM segments have byte granularity and their bases
12120- * are set at run time. All have 64k limits.
12121- */
12122- /* 32-bit code */
12123- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12124- /* 16-bit code */
12125- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12126- /* data */
12127- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12128-
12129- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12130- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12131- GDT_STACK_CANARY_INIT
12132-#endif
12133-} };
12134-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12135-
12136 static int __init x86_xsave_setup(char *s)
12137 {
12138 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12139@@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
12140 {
12141 struct desc_ptr gdt_descr;
12142
12143- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12144+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12145 gdt_descr.size = GDT_SIZE - 1;
12146 load_gdt(&gdt_descr);
12147 /* Reload the per-cpu base */
12148@@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struc
12149 /* Filter out anything that depends on CPUID levels we don't have */
12150 filter_cpuid_features(c, true);
12151
12152+#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
12153+ setup_clear_cpu_cap(X86_FEATURE_SEP);
12154+#endif
12155+
12156 /* If the model name is still unset, do table lookup. */
12157 if (!c->x86_model_id[0]) {
12158 const char *p;
12159@@ -980,6 +930,9 @@ static __init int setup_disablecpuid(cha
12160 }
12161 __setup("clearcpuid=", setup_disablecpuid);
12162
12163+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12164+EXPORT_PER_CPU_SYMBOL(current_tinfo);
12165+
12166 #ifdef CONFIG_X86_64
12167 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12168
12169@@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
12170 EXPORT_PER_CPU_SYMBOL(current_task);
12171
12172 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12173- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12174+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12175 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12176
12177 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12178@@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(str
12179 {
12180 memset(regs, 0, sizeof(struct pt_regs));
12181 regs->fs = __KERNEL_PERCPU;
12182- regs->gs = __KERNEL_STACK_CANARY;
12183+ savesegment(gs, regs->gs);
12184
12185 return regs;
12186 }
12187@@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
12188 int i;
12189
12190 cpu = stack_smp_processor_id();
12191- t = &per_cpu(init_tss, cpu);
12192+ t = init_tss + cpu;
12193 orig_ist = &per_cpu(orig_ist, cpu);
12194
12195 #ifdef CONFIG_NUMA
12196@@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
12197 switch_to_new_gdt(cpu);
12198 loadsegment(fs, 0);
12199
12200- load_idt((const struct desc_ptr *)&idt_descr);
12201+ load_idt(&idt_descr);
12202
12203 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12204 syscall_init();
12205@@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
12206 wrmsrl(MSR_KERNEL_GS_BASE, 0);
12207 barrier();
12208
12209- check_efer();
12210 if (cpu != 0)
12211 enable_x2apic();
12212
12213@@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
12214 {
12215 int cpu = smp_processor_id();
12216 struct task_struct *curr = current;
12217- struct tss_struct *t = &per_cpu(init_tss, cpu);
12218+ struct tss_struct *t = init_tss + cpu;
12219 struct thread_struct *thread = &curr->thread;
12220
12221 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
12222diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/intel.c linux-2.6.32.43/arch/x86/kernel/cpu/intel.c
12223--- linux-2.6.32.43/arch/x86/kernel/cpu/intel.c 2011-03-27 14:31:47.000000000 -0400
12224+++ linux-2.6.32.43/arch/x86/kernel/cpu/intel.c 2011-04-17 15:56:46.000000000 -0400
12225@@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug
12226 * Update the IDT descriptor and reload the IDT so that
12227 * it uses the read-only mapped virtual address.
12228 */
12229- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
12230+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
12231 load_idt(&idt_descr);
12232 }
12233 #endif
12234diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/intel_cacheinfo.c linux-2.6.32.43/arch/x86/kernel/cpu/intel_cacheinfo.c
12235--- linux-2.6.32.43/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
12236+++ linux-2.6.32.43/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-04-17 15:56:46.000000000 -0400
12237@@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kob
12238 return ret;
12239 }
12240
12241-static struct sysfs_ops sysfs_ops = {
12242+static const struct sysfs_ops sysfs_ops = {
12243 .show = show,
12244 .store = store,
12245 };
12246diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/Makefile linux-2.6.32.43/arch/x86/kernel/cpu/Makefile
12247--- linux-2.6.32.43/arch/x86/kernel/cpu/Makefile 2011-03-27 14:31:47.000000000 -0400
12248+++ linux-2.6.32.43/arch/x86/kernel/cpu/Makefile 2011-04-17 15:56:46.000000000 -0400
12249@@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
12250 CFLAGS_REMOVE_common.o = -pg
12251 endif
12252
12253-# Make sure load_percpu_segment has no stackprotector
12254-nostackp := $(call cc-option, -fno-stack-protector)
12255-CFLAGS_common.o := $(nostackp)
12256-
12257 obj-y := intel_cacheinfo.o addon_cpuid_features.o
12258 obj-y += proc.o capflags.o powerflags.o common.o
12259 obj-y += vmware.o hypervisor.o sched.o
12260diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce_amd.c linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce_amd.c
12261--- linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:56:59.000000000 -0400
12262+++ linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:57:13.000000000 -0400
12263@@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kob
12264 return ret;
12265 }
12266
12267-static struct sysfs_ops threshold_ops = {
12268+static const struct sysfs_ops threshold_ops = {
12269 .show = show,
12270 .store = store,
12271 };
12272diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce.c
12273--- linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce.c 2011-03-27 14:31:47.000000000 -0400
12274+++ linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-04 17:56:20.000000000 -0400
12275@@ -43,6 +43,7 @@
12276 #include <asm/ipi.h>
12277 #include <asm/mce.h>
12278 #include <asm/msr.h>
12279+#include <asm/local.h>
12280
12281 #include "mce-internal.h"
12282
12283@@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
12284 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
12285 m->cs, m->ip);
12286
12287- if (m->cs == __KERNEL_CS)
12288+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
12289 print_symbol("{%s}", m->ip);
12290 pr_cont("\n");
12291 }
12292@@ -221,10 +222,10 @@ static void print_mce_tail(void)
12293
12294 #define PANIC_TIMEOUT 5 /* 5 seconds */
12295
12296-static atomic_t mce_paniced;
12297+static atomic_unchecked_t mce_paniced;
12298
12299 static int fake_panic;
12300-static atomic_t mce_fake_paniced;
12301+static atomic_unchecked_t mce_fake_paniced;
12302
12303 /* Panic in progress. Enable interrupts and wait for final IPI */
12304 static void wait_for_panic(void)
12305@@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct
12306 /*
12307 * Make sure only one CPU runs in machine check panic
12308 */
12309- if (atomic_inc_return(&mce_paniced) > 1)
12310+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
12311 wait_for_panic();
12312 barrier();
12313
12314@@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct
12315 console_verbose();
12316 } else {
12317 /* Don't log too much for fake panic */
12318- if (atomic_inc_return(&mce_fake_paniced) > 1)
12319+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
12320 return;
12321 }
12322 print_mce_head();
12323@@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
12324 * might have been modified by someone else.
12325 */
12326 rmb();
12327- if (atomic_read(&mce_paniced))
12328+ if (atomic_read_unchecked(&mce_paniced))
12329 wait_for_panic();
12330 if (!monarch_timeout)
12331 goto out;
12332@@ -1429,14 +1430,14 @@ void __cpuinit mcheck_init(struct cpuinf
12333 */
12334
12335 static DEFINE_SPINLOCK(mce_state_lock);
12336-static int open_count; /* #times opened */
12337+static local_t open_count; /* #times opened */
12338 static int open_exclu; /* already open exclusive? */
12339
12340 static int mce_open(struct inode *inode, struct file *file)
12341 {
12342 spin_lock(&mce_state_lock);
12343
12344- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
12345+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
12346 spin_unlock(&mce_state_lock);
12347
12348 return -EBUSY;
12349@@ -1444,7 +1445,7 @@ static int mce_open(struct inode *inode,
12350
12351 if (file->f_flags & O_EXCL)
12352 open_exclu = 1;
12353- open_count++;
12354+ local_inc(&open_count);
12355
12356 spin_unlock(&mce_state_lock);
12357
12358@@ -1455,7 +1456,7 @@ static int mce_release(struct inode *ino
12359 {
12360 spin_lock(&mce_state_lock);
12361
12362- open_count--;
12363+ local_dec(&open_count);
12364 open_exclu = 0;
12365
12366 spin_unlock(&mce_state_lock);
12367@@ -2082,7 +2083,7 @@ struct dentry *mce_get_debugfs_dir(void)
12368 static void mce_reset(void)
12369 {
12370 cpu_missing = 0;
12371- atomic_set(&mce_fake_paniced, 0);
12372+ atomic_set_unchecked(&mce_fake_paniced, 0);
12373 atomic_set(&mce_executing, 0);
12374 atomic_set(&mce_callin, 0);
12375 atomic_set(&global_nwo, 0);
12376diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce-inject.c linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce-inject.c
12377--- linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-03-27 14:31:47.000000000 -0400
12378+++ linux-2.6.32.43/arch/x86/kernel/cpu/mcheck/mce-inject.c 2011-08-05 20:33:55.000000000 -0400
12379@@ -211,7 +211,9 @@ static ssize_t mce_write(struct file *fi
12380 static int inject_init(void)
12381 {
12382 printk(KERN_INFO "Machine check injector initialized\n");
12383- mce_chrdev_ops.write = mce_write;
12384+ pax_open_kernel();
12385+ *(void **)&mce_chrdev_ops.write = mce_write;
12386+ pax_close_kernel();
12387 register_die_notifier(&mce_raise_nb);
12388 return 0;
12389 }
12390diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/amd.c linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/amd.c
12391--- linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/amd.c 2011-03-27 14:31:47.000000000 -0400
12392+++ linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/amd.c 2011-04-17 15:56:46.000000000 -0400
12393@@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base
12394 return 0;
12395 }
12396
12397-static struct mtrr_ops amd_mtrr_ops = {
12398+static const struct mtrr_ops amd_mtrr_ops = {
12399 .vendor = X86_VENDOR_AMD,
12400 .set = amd_set_mtrr,
12401 .get = amd_get_mtrr,
12402diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/centaur.c linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/centaur.c
12403--- linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/centaur.c 2011-03-27 14:31:47.000000000 -0400
12404+++ linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/centaur.c 2011-04-17 15:56:46.000000000 -0400
12405@@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long
12406 return 0;
12407 }
12408
12409-static struct mtrr_ops centaur_mtrr_ops = {
12410+static const struct mtrr_ops centaur_mtrr_ops = {
12411 .vendor = X86_VENDOR_CENTAUR,
12412 .set = centaur_set_mcr,
12413 .get = centaur_get_mcr,
12414diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/cyrix.c linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/cyrix.c
12415--- linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-03-27 14:31:47.000000000 -0400
12416+++ linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-04-17 15:56:46.000000000 -0400
12417@@ -265,7 +265,7 @@ static void cyrix_set_all(void)
12418 post_set();
12419 }
12420
12421-static struct mtrr_ops cyrix_mtrr_ops = {
12422+static const struct mtrr_ops cyrix_mtrr_ops = {
12423 .vendor = X86_VENDOR_CYRIX,
12424 .set_all = cyrix_set_all,
12425 .set = cyrix_set_arr,
12426diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/generic.c
12427--- linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/generic.c 2011-03-27 14:31:47.000000000 -0400
12428+++ linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/generic.c 2011-04-23 12:56:10.000000000 -0400
12429@@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
12430 /*
12431 * Generic structure...
12432 */
12433-struct mtrr_ops generic_mtrr_ops = {
12434+const struct mtrr_ops generic_mtrr_ops = {
12435 .use_intel_if = 1,
12436 .set_all = generic_set_all,
12437 .get = generic_get_mtrr,
12438diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/main.c
12439--- linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:00:52.000000000 -0400
12440+++ linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:03:05.000000000 -0400
12441@@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
12442 u64 size_or_mask, size_and_mask;
12443 static bool mtrr_aps_delayed_init;
12444
12445-static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12446+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12447
12448-struct mtrr_ops *mtrr_if;
12449+const struct mtrr_ops *mtrr_if;
12450
12451 static void set_mtrr(unsigned int reg, unsigned long base,
12452 unsigned long size, mtrr_type type);
12453
12454-void set_mtrr_ops(struct mtrr_ops *ops)
12455+void set_mtrr_ops(const struct mtrr_ops *ops)
12456 {
12457 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
12458 mtrr_ops[ops->vendor] = ops;
12459diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/mtrr.h
12460--- linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-03-27 14:31:47.000000000 -0400
12461+++ linux-2.6.32.43/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-04-17 15:56:46.000000000 -0400
12462@@ -12,19 +12,19 @@
12463 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
12464
12465 struct mtrr_ops {
12466- u32 vendor;
12467- u32 use_intel_if;
12468- void (*set)(unsigned int reg, unsigned long base,
12469+ const u32 vendor;
12470+ const u32 use_intel_if;
12471+ void (* const set)(unsigned int reg, unsigned long base,
12472 unsigned long size, mtrr_type type);
12473- void (*set_all)(void);
12474+ void (* const set_all)(void);
12475
12476- void (*get)(unsigned int reg, unsigned long *base,
12477+ void (* const get)(unsigned int reg, unsigned long *base,
12478 unsigned long *size, mtrr_type *type);
12479- int (*get_free_region)(unsigned long base, unsigned long size,
12480+ int (* const get_free_region)(unsigned long base, unsigned long size,
12481 int replace_reg);
12482- int (*validate_add_page)(unsigned long base, unsigned long size,
12483+ int (* const validate_add_page)(unsigned long base, unsigned long size,
12484 unsigned int type);
12485- int (*have_wrcomb)(void);
12486+ int (* const have_wrcomb)(void);
12487 };
12488
12489 extern int generic_get_free_region(unsigned long base, unsigned long size,
12490@@ -32,7 +32,7 @@ extern int generic_get_free_region(unsig
12491 extern int generic_validate_add_page(unsigned long base, unsigned long size,
12492 unsigned int type);
12493
12494-extern struct mtrr_ops generic_mtrr_ops;
12495+extern const struct mtrr_ops generic_mtrr_ops;
12496
12497 extern int positive_have_wrcomb(void);
12498
12499@@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int in
12500 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
12501 void get_mtrr_state(void);
12502
12503-extern void set_mtrr_ops(struct mtrr_ops *ops);
12504+extern void set_mtrr_ops(const struct mtrr_ops *ops);
12505
12506 extern u64 size_or_mask, size_and_mask;
12507-extern struct mtrr_ops *mtrr_if;
12508+extern const struct mtrr_ops *mtrr_if;
12509
12510 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
12511 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
12512diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/perfctr-watchdog.c linux-2.6.32.43/arch/x86/kernel/cpu/perfctr-watchdog.c
12513--- linux-2.6.32.43/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-03-27 14:31:47.000000000 -0400
12514+++ linux-2.6.32.43/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-04-17 15:56:46.000000000 -0400
12515@@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
12516
12517 /* Interface defining a CPU specific perfctr watchdog */
12518 struct wd_ops {
12519- int (*reserve)(void);
12520- void (*unreserve)(void);
12521- int (*setup)(unsigned nmi_hz);
12522- void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
12523- void (*stop)(void);
12524+ int (* const reserve)(void);
12525+ void (* const unreserve)(void);
12526+ int (* const setup)(unsigned nmi_hz);
12527+ void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
12528+ void (* const stop)(void);
12529 unsigned perfctr;
12530 unsigned evntsel;
12531 u64 checkbit;
12532@@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
12533 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
12534 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
12535
12536+/* cannot be const */
12537 static struct wd_ops intel_arch_wd_ops;
12538
12539 static int setup_intel_arch_watchdog(unsigned nmi_hz)
12540@@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(uns
12541 return 1;
12542 }
12543
12544+/* cannot be const */
12545 static struct wd_ops intel_arch_wd_ops __read_mostly = {
12546 .reserve = single_msr_reserve,
12547 .unreserve = single_msr_unreserve,
12548diff -urNp linux-2.6.32.43/arch/x86/kernel/cpu/perf_event.c linux-2.6.32.43/arch/x86/kernel/cpu/perf_event.c
12549--- linux-2.6.32.43/arch/x86/kernel/cpu/perf_event.c 2011-03-27 14:31:47.000000000 -0400
12550+++ linux-2.6.32.43/arch/x86/kernel/cpu/perf_event.c 2011-05-04 17:56:20.000000000 -0400
12551@@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event
12552 * count to the generic event atomically:
12553 */
12554 again:
12555- prev_raw_count = atomic64_read(&hwc->prev_count);
12556+ prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
12557 rdmsrl(hwc->event_base + idx, new_raw_count);
12558
12559- if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
12560+ if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
12561 new_raw_count) != prev_raw_count)
12562 goto again;
12563
12564@@ -741,7 +741,7 @@ again:
12565 delta = (new_raw_count << shift) - (prev_raw_count << shift);
12566 delta >>= shift;
12567
12568- atomic64_add(delta, &event->count);
12569+ atomic64_add_unchecked(delta, &event->count);
12570 atomic64_sub(delta, &hwc->period_left);
12571
12572 return new_raw_count;
12573@@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_ev
12574 * The hw event starts counting from this event offset,
12575 * mark it to be able to extra future deltas:
12576 */
12577- atomic64_set(&hwc->prev_count, (u64)-left);
12578+ atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
12579
12580 err = checking_wrmsrl(hwc->event_base + idx,
12581 (u64)(-left) & x86_pmu.event_mask);
12582@@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs
12583 break;
12584
12585 callchain_store(entry, frame.return_address);
12586- fp = frame.next_frame;
12587+ fp = (__force const void __user *)frame.next_frame;
12588 }
12589 }
12590
12591diff -urNp linux-2.6.32.43/arch/x86/kernel/crash.c linux-2.6.32.43/arch/x86/kernel/crash.c
12592--- linux-2.6.32.43/arch/x86/kernel/crash.c 2011-03-27 14:31:47.000000000 -0400
12593+++ linux-2.6.32.43/arch/x86/kernel/crash.c 2011-04-17 15:56:46.000000000 -0400
12594@@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu,
12595 regs = args->regs;
12596
12597 #ifdef CONFIG_X86_32
12598- if (!user_mode_vm(regs)) {
12599+ if (!user_mode(regs)) {
12600 crash_fixup_ss_esp(&fixed_regs, regs);
12601 regs = &fixed_regs;
12602 }
12603diff -urNp linux-2.6.32.43/arch/x86/kernel/doublefault_32.c linux-2.6.32.43/arch/x86/kernel/doublefault_32.c
12604--- linux-2.6.32.43/arch/x86/kernel/doublefault_32.c 2011-03-27 14:31:47.000000000 -0400
12605+++ linux-2.6.32.43/arch/x86/kernel/doublefault_32.c 2011-04-17 15:56:46.000000000 -0400
12606@@ -11,7 +11,7 @@
12607
12608 #define DOUBLEFAULT_STACKSIZE (1024)
12609 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12610-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12611+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12612
12613 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12614
12615@@ -21,7 +21,7 @@ static void doublefault_fn(void)
12616 unsigned long gdt, tss;
12617
12618 store_gdt(&gdt_desc);
12619- gdt = gdt_desc.address;
12620+ gdt = (unsigned long)gdt_desc.address;
12621
12622 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12623
12624@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
12625 /* 0x2 bit is always set */
12626 .flags = X86_EFLAGS_SF | 0x2,
12627 .sp = STACK_START,
12628- .es = __USER_DS,
12629+ .es = __KERNEL_DS,
12630 .cs = __KERNEL_CS,
12631 .ss = __KERNEL_DS,
12632- .ds = __USER_DS,
12633+ .ds = __KERNEL_DS,
12634 .fs = __KERNEL_PERCPU,
12635
12636 .__cr3 = __pa_nodebug(swapper_pg_dir),
12637diff -urNp linux-2.6.32.43/arch/x86/kernel/dumpstack_32.c linux-2.6.32.43/arch/x86/kernel/dumpstack_32.c
12638--- linux-2.6.32.43/arch/x86/kernel/dumpstack_32.c 2011-03-27 14:31:47.000000000 -0400
12639+++ linux-2.6.32.43/arch/x86/kernel/dumpstack_32.c 2011-04-17 15:56:46.000000000 -0400
12640@@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task
12641 #endif
12642
12643 for (;;) {
12644- struct thread_info *context;
12645+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12646+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12647
12648- context = (struct thread_info *)
12649- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12650- bp = print_context_stack(context, stack, bp, ops,
12651- data, NULL, &graph);
12652-
12653- stack = (unsigned long *)context->previous_esp;
12654- if (!stack)
12655+ if (stack_start == task_stack_page(task))
12656 break;
12657+ stack = *(unsigned long **)stack_start;
12658 if (ops->stack(data, "IRQ") < 0)
12659 break;
12660 touch_nmi_watchdog();
12661@@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs
12662 * When in-kernel, we also print out the stack and code at the
12663 * time of the fault..
12664 */
12665- if (!user_mode_vm(regs)) {
12666+ if (!user_mode(regs)) {
12667 unsigned int code_prologue = code_bytes * 43 / 64;
12668 unsigned int code_len = code_bytes;
12669 unsigned char c;
12670 u8 *ip;
12671+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12672
12673 printk(KERN_EMERG "Stack:\n");
12674 show_stack_log_lvl(NULL, regs, &regs->sp,
12675@@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs
12676
12677 printk(KERN_EMERG "Code: ");
12678
12679- ip = (u8 *)regs->ip - code_prologue;
12680+ ip = (u8 *)regs->ip - code_prologue + cs_base;
12681 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12682 /* try starting at IP */
12683- ip = (u8 *)regs->ip;
12684+ ip = (u8 *)regs->ip + cs_base;
12685 code_len = code_len - code_prologue + 1;
12686 }
12687 for (i = 0; i < code_len; i++, ip++) {
12688@@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs
12689 printk(" Bad EIP value.");
12690 break;
12691 }
12692- if (ip == (u8 *)regs->ip)
12693+ if (ip == (u8 *)regs->ip + cs_base)
12694 printk("<%02x> ", c);
12695 else
12696 printk("%02x ", c);
12697@@ -149,6 +146,7 @@ int is_valid_bugaddr(unsigned long ip)
12698 {
12699 unsigned short ud2;
12700
12701+ ip = ktla_ktva(ip);
12702 if (ip < PAGE_OFFSET)
12703 return 0;
12704 if (probe_kernel_address((unsigned short *)ip, ud2))
12705diff -urNp linux-2.6.32.43/arch/x86/kernel/dumpstack_64.c linux-2.6.32.43/arch/x86/kernel/dumpstack_64.c
12706--- linux-2.6.32.43/arch/x86/kernel/dumpstack_64.c 2011-03-27 14:31:47.000000000 -0400
12707+++ linux-2.6.32.43/arch/x86/kernel/dumpstack_64.c 2011-04-17 15:56:46.000000000 -0400
12708@@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task
12709 unsigned long *irq_stack_end =
12710 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12711 unsigned used = 0;
12712- struct thread_info *tinfo;
12713 int graph = 0;
12714+ void *stack_start;
12715
12716 if (!task)
12717 task = current;
12718@@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task
12719 * current stack address. If the stacks consist of nested
12720 * exceptions
12721 */
12722- tinfo = task_thread_info(task);
12723 for (;;) {
12724 char *id;
12725 unsigned long *estack_end;
12726+
12727 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12728 &used, &id);
12729
12730@@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task
12731 if (ops->stack(data, id) < 0)
12732 break;
12733
12734- bp = print_context_stack(tinfo, stack, bp, ops,
12735+ bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12736 data, estack_end, &graph);
12737 ops->stack(data, "<EOE>");
12738 /*
12739@@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task
12740 if (stack >= irq_stack && stack < irq_stack_end) {
12741 if (ops->stack(data, "IRQ") < 0)
12742 break;
12743- bp = print_context_stack(tinfo, stack, bp,
12744+ bp = print_context_stack(task, irq_stack, stack, bp,
12745 ops, data, irq_stack_end, &graph);
12746 /*
12747 * We link to the next stack (which would be
12748@@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task
12749 /*
12750 * This handles the process stack:
12751 */
12752- bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12753+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12754+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12755 put_cpu();
12756 }
12757 EXPORT_SYMBOL(dump_trace);
12758diff -urNp linux-2.6.32.43/arch/x86/kernel/dumpstack.c linux-2.6.32.43/arch/x86/kernel/dumpstack.c
12759--- linux-2.6.32.43/arch/x86/kernel/dumpstack.c 2011-03-27 14:31:47.000000000 -0400
12760+++ linux-2.6.32.43/arch/x86/kernel/dumpstack.c 2011-04-17 15:56:46.000000000 -0400
12761@@ -2,6 +2,9 @@
12762 * Copyright (C) 1991, 1992 Linus Torvalds
12763 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12764 */
12765+#ifdef CONFIG_GRKERNSEC_HIDESYM
12766+#define __INCLUDED_BY_HIDESYM 1
12767+#endif
12768 #include <linux/kallsyms.h>
12769 #include <linux/kprobes.h>
12770 #include <linux/uaccess.h>
12771@@ -28,7 +31,7 @@ static int die_counter;
12772
12773 void printk_address(unsigned long address, int reliable)
12774 {
12775- printk(" [<%p>] %s%pS\n", (void *) address,
12776+ printk(" [<%p>] %s%pA\n", (void *) address,
12777 reliable ? "" : "? ", (void *) address);
12778 }
12779
12780@@ -36,9 +39,8 @@ void printk_address(unsigned long addres
12781 static void
12782 print_ftrace_graph_addr(unsigned long addr, void *data,
12783 const struct stacktrace_ops *ops,
12784- struct thread_info *tinfo, int *graph)
12785+ struct task_struct *task, int *graph)
12786 {
12787- struct task_struct *task = tinfo->task;
12788 unsigned long ret_addr;
12789 int index = task->curr_ret_stack;
12790
12791@@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long ad
12792 static inline void
12793 print_ftrace_graph_addr(unsigned long addr, void *data,
12794 const struct stacktrace_ops *ops,
12795- struct thread_info *tinfo, int *graph)
12796+ struct task_struct *task, int *graph)
12797 { }
12798 #endif
12799
12800@@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long ad
12801 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12802 */
12803
12804-static inline int valid_stack_ptr(struct thread_info *tinfo,
12805- void *p, unsigned int size, void *end)
12806+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12807 {
12808- void *t = tinfo;
12809 if (end) {
12810 if (p < end && p >= (end-THREAD_SIZE))
12811 return 1;
12812@@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct
12813 }
12814
12815 unsigned long
12816-print_context_stack(struct thread_info *tinfo,
12817+print_context_stack(struct task_struct *task, void *stack_start,
12818 unsigned long *stack, unsigned long bp,
12819 const struct stacktrace_ops *ops, void *data,
12820 unsigned long *end, int *graph)
12821 {
12822 struct stack_frame *frame = (struct stack_frame *)bp;
12823
12824- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12825+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12826 unsigned long addr;
12827
12828 addr = *stack;
12829@@ -103,7 +103,7 @@ print_context_stack(struct thread_info *
12830 } else {
12831 ops->address(data, addr, 0);
12832 }
12833- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12834+ print_ftrace_graph_addr(addr, data, ops, task, graph);
12835 }
12836 stack++;
12837 }
12838@@ -180,7 +180,7 @@ void dump_stack(void)
12839 #endif
12840
12841 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12842- current->pid, current->comm, print_tainted(),
12843+ task_pid_nr(current), current->comm, print_tainted(),
12844 init_utsname()->release,
12845 (int)strcspn(init_utsname()->version, " "),
12846 init_utsname()->version);
12847@@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
12848 return flags;
12849 }
12850
12851+extern void gr_handle_kernel_exploit(void);
12852+
12853 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12854 {
12855 if (regs && kexec_should_crash(current))
12856@@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long fl
12857 panic("Fatal exception in interrupt");
12858 if (panic_on_oops)
12859 panic("Fatal exception");
12860- do_exit(signr);
12861+
12862+ gr_handle_kernel_exploit();
12863+
12864+ do_group_exit(signr);
12865 }
12866
12867 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12868@@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs
12869 unsigned long flags = oops_begin();
12870 int sig = SIGSEGV;
12871
12872- if (!user_mode_vm(regs))
12873+ if (!user_mode(regs))
12874 report_bug(regs->ip, regs);
12875
12876 if (__die(str, regs, err))
12877diff -urNp linux-2.6.32.43/arch/x86/kernel/dumpstack.h linux-2.6.32.43/arch/x86/kernel/dumpstack.h
12878--- linux-2.6.32.43/arch/x86/kernel/dumpstack.h 2011-03-27 14:31:47.000000000 -0400
12879+++ linux-2.6.32.43/arch/x86/kernel/dumpstack.h 2011-04-23 13:25:26.000000000 -0400
12880@@ -15,7 +15,7 @@
12881 #endif
12882
12883 extern unsigned long
12884-print_context_stack(struct thread_info *tinfo,
12885+print_context_stack(struct task_struct *task, void *stack_start,
12886 unsigned long *stack, unsigned long bp,
12887 const struct stacktrace_ops *ops, void *data,
12888 unsigned long *end, int *graph);
12889diff -urNp linux-2.6.32.43/arch/x86/kernel/e820.c linux-2.6.32.43/arch/x86/kernel/e820.c
12890--- linux-2.6.32.43/arch/x86/kernel/e820.c 2011-03-27 14:31:47.000000000 -0400
12891+++ linux-2.6.32.43/arch/x86/kernel/e820.c 2011-04-17 15:56:46.000000000 -0400
12892@@ -733,7 +733,7 @@ struct early_res {
12893 };
12894 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
12895 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
12896- {}
12897+ { 0, 0, {0}, 0 }
12898 };
12899
12900 static int __init find_overlapped_early(u64 start, u64 end)
12901diff -urNp linux-2.6.32.43/arch/x86/kernel/early_printk.c linux-2.6.32.43/arch/x86/kernel/early_printk.c
12902--- linux-2.6.32.43/arch/x86/kernel/early_printk.c 2011-03-27 14:31:47.000000000 -0400
12903+++ linux-2.6.32.43/arch/x86/kernel/early_printk.c 2011-05-16 21:46:57.000000000 -0400
12904@@ -7,6 +7,7 @@
12905 #include <linux/pci_regs.h>
12906 #include <linux/pci_ids.h>
12907 #include <linux/errno.h>
12908+#include <linux/sched.h>
12909 #include <asm/io.h>
12910 #include <asm/processor.h>
12911 #include <asm/fcntl.h>
12912@@ -170,6 +171,8 @@ asmlinkage void early_printk(const char
12913 int n;
12914 va_list ap;
12915
12916+ pax_track_stack();
12917+
12918 va_start(ap, fmt);
12919 n = vscnprintf(buf, sizeof(buf), fmt, ap);
12920 early_console->write(early_console, buf, n);
12921diff -urNp linux-2.6.32.43/arch/x86/kernel/efi_32.c linux-2.6.32.43/arch/x86/kernel/efi_32.c
12922--- linux-2.6.32.43/arch/x86/kernel/efi_32.c 2011-03-27 14:31:47.000000000 -0400
12923+++ linux-2.6.32.43/arch/x86/kernel/efi_32.c 2011-04-17 15:56:46.000000000 -0400
12924@@ -38,70 +38,38 @@
12925 */
12926
12927 static unsigned long efi_rt_eflags;
12928-static pgd_t efi_bak_pg_dir_pointer[2];
12929+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
12930
12931-void efi_call_phys_prelog(void)
12932+void __init efi_call_phys_prelog(void)
12933 {
12934- unsigned long cr4;
12935- unsigned long temp;
12936 struct desc_ptr gdt_descr;
12937
12938 local_irq_save(efi_rt_eflags);
12939
12940- /*
12941- * If I don't have PAE, I should just duplicate two entries in page
12942- * directory. If I have PAE, I just need to duplicate one entry in
12943- * page directory.
12944- */
12945- cr4 = read_cr4_safe();
12946
12947- if (cr4 & X86_CR4_PAE) {
12948- efi_bak_pg_dir_pointer[0].pgd =
12949- swapper_pg_dir[pgd_index(0)].pgd;
12950- swapper_pg_dir[0].pgd =
12951- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
12952- } else {
12953- efi_bak_pg_dir_pointer[0].pgd =
12954- swapper_pg_dir[pgd_index(0)].pgd;
12955- efi_bak_pg_dir_pointer[1].pgd =
12956- swapper_pg_dir[pgd_index(0x400000)].pgd;
12957- swapper_pg_dir[pgd_index(0)].pgd =
12958- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
12959- temp = PAGE_OFFSET + 0x400000;
12960- swapper_pg_dir[pgd_index(0x400000)].pgd =
12961- swapper_pg_dir[pgd_index(temp)].pgd;
12962- }
12963+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
12964+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
12965+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
12966
12967 /*
12968 * After the lock is released, the original page table is restored.
12969 */
12970 __flush_tlb_all();
12971
12972- gdt_descr.address = __pa(get_cpu_gdt_table(0));
12973+ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
12974 gdt_descr.size = GDT_SIZE - 1;
12975 load_gdt(&gdt_descr);
12976 }
12977
12978-void efi_call_phys_epilog(void)
12979+void __init efi_call_phys_epilog(void)
12980 {
12981- unsigned long cr4;
12982 struct desc_ptr gdt_descr;
12983
12984- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
12985+ gdt_descr.address = get_cpu_gdt_table(0);
12986 gdt_descr.size = GDT_SIZE - 1;
12987 load_gdt(&gdt_descr);
12988
12989- cr4 = read_cr4_safe();
12990-
12991- if (cr4 & X86_CR4_PAE) {
12992- swapper_pg_dir[pgd_index(0)].pgd =
12993- efi_bak_pg_dir_pointer[0].pgd;
12994- } else {
12995- swapper_pg_dir[pgd_index(0)].pgd =
12996- efi_bak_pg_dir_pointer[0].pgd;
12997- swapper_pg_dir[pgd_index(0x400000)].pgd =
12998- efi_bak_pg_dir_pointer[1].pgd;
12999- }
13000+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
13001
13002 /*
13003 * After the lock is released, the original page table is restored.
13004diff -urNp linux-2.6.32.43/arch/x86/kernel/efi_stub_32.S linux-2.6.32.43/arch/x86/kernel/efi_stub_32.S
13005--- linux-2.6.32.43/arch/x86/kernel/efi_stub_32.S 2011-03-27 14:31:47.000000000 -0400
13006+++ linux-2.6.32.43/arch/x86/kernel/efi_stub_32.S 2011-04-17 15:56:46.000000000 -0400
13007@@ -6,6 +6,7 @@
13008 */
13009
13010 #include <linux/linkage.h>
13011+#include <linux/init.h>
13012 #include <asm/page_types.h>
13013
13014 /*
13015@@ -20,7 +21,7 @@
13016 * service functions will comply with gcc calling convention, too.
13017 */
13018
13019-.text
13020+__INIT
13021 ENTRY(efi_call_phys)
13022 /*
13023 * 0. The function can only be called in Linux kernel. So CS has been
13024@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
13025 * The mapping of lower virtual memory has been created in prelog and
13026 * epilog.
13027 */
13028- movl $1f, %edx
13029- subl $__PAGE_OFFSET, %edx
13030- jmp *%edx
13031+ jmp 1f-__PAGE_OFFSET
13032 1:
13033
13034 /*
13035@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
13036 * parameter 2, ..., param n. To make things easy, we save the return
13037 * address of efi_call_phys in a global variable.
13038 */
13039- popl %edx
13040- movl %edx, saved_return_addr
13041- /* get the function pointer into ECX*/
13042- popl %ecx
13043- movl %ecx, efi_rt_function_ptr
13044- movl $2f, %edx
13045- subl $__PAGE_OFFSET, %edx
13046- pushl %edx
13047+ popl (saved_return_addr)
13048+ popl (efi_rt_function_ptr)
13049
13050 /*
13051 * 3. Clear PG bit in %CR0.
13052@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
13053 /*
13054 * 5. Call the physical function.
13055 */
13056- jmp *%ecx
13057+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
13058
13059-2:
13060 /*
13061 * 6. After EFI runtime service returns, control will return to
13062 * following instruction. We'd better readjust stack pointer first.
13063@@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
13064 movl %cr0, %edx
13065 orl $0x80000000, %edx
13066 movl %edx, %cr0
13067- jmp 1f
13068-1:
13069+
13070 /*
13071 * 8. Now restore the virtual mode from flat mode by
13072 * adding EIP with PAGE_OFFSET.
13073 */
13074- movl $1f, %edx
13075- jmp *%edx
13076+ jmp 1f+__PAGE_OFFSET
13077 1:
13078
13079 /*
13080 * 9. Balance the stack. And because EAX contain the return value,
13081 * we'd better not clobber it.
13082 */
13083- leal efi_rt_function_ptr, %edx
13084- movl (%edx), %ecx
13085- pushl %ecx
13086+ pushl (efi_rt_function_ptr)
13087
13088 /*
13089- * 10. Push the saved return address onto the stack and return.
13090+ * 10. Return to the saved return address.
13091 */
13092- leal saved_return_addr, %edx
13093- movl (%edx), %ecx
13094- pushl %ecx
13095- ret
13096+ jmpl *(saved_return_addr)
13097 ENDPROC(efi_call_phys)
13098 .previous
13099
13100-.data
13101+__INITDATA
13102 saved_return_addr:
13103 .long 0
13104 efi_rt_function_ptr:
13105diff -urNp linux-2.6.32.43/arch/x86/kernel/entry_32.S linux-2.6.32.43/arch/x86/kernel/entry_32.S
13106--- linux-2.6.32.43/arch/x86/kernel/entry_32.S 2011-03-27 14:31:47.000000000 -0400
13107+++ linux-2.6.32.43/arch/x86/kernel/entry_32.S 2011-05-22 23:02:03.000000000 -0400
13108@@ -185,13 +185,146 @@
13109 /*CFI_REL_OFFSET gs, PT_GS*/
13110 .endm
13111 .macro SET_KERNEL_GS reg
13112+
13113+#ifdef CONFIG_CC_STACKPROTECTOR
13114 movl $(__KERNEL_STACK_CANARY), \reg
13115+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13116+ movl $(__USER_DS), \reg
13117+#else
13118+ xorl \reg, \reg
13119+#endif
13120+
13121 movl \reg, %gs
13122 .endm
13123
13124 #endif /* CONFIG_X86_32_LAZY_GS */
13125
13126-.macro SAVE_ALL
13127+.macro pax_enter_kernel
13128+#ifdef CONFIG_PAX_KERNEXEC
13129+ call pax_enter_kernel
13130+#endif
13131+.endm
13132+
13133+.macro pax_exit_kernel
13134+#ifdef CONFIG_PAX_KERNEXEC
13135+ call pax_exit_kernel
13136+#endif
13137+.endm
13138+
13139+#ifdef CONFIG_PAX_KERNEXEC
13140+ENTRY(pax_enter_kernel)
13141+#ifdef CONFIG_PARAVIRT
13142+ pushl %eax
13143+ pushl %ecx
13144+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13145+ mov %eax, %esi
13146+#else
13147+ mov %cr0, %esi
13148+#endif
13149+ bts $16, %esi
13150+ jnc 1f
13151+ mov %cs, %esi
13152+ cmp $__KERNEL_CS, %esi
13153+ jz 3f
13154+ ljmp $__KERNEL_CS, $3f
13155+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13156+2:
13157+#ifdef CONFIG_PARAVIRT
13158+ mov %esi, %eax
13159+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13160+#else
13161+ mov %esi, %cr0
13162+#endif
13163+3:
13164+#ifdef CONFIG_PARAVIRT
13165+ popl %ecx
13166+ popl %eax
13167+#endif
13168+ ret
13169+ENDPROC(pax_enter_kernel)
13170+
13171+ENTRY(pax_exit_kernel)
13172+#ifdef CONFIG_PARAVIRT
13173+ pushl %eax
13174+ pushl %ecx
13175+#endif
13176+ mov %cs, %esi
13177+ cmp $__KERNEXEC_KERNEL_CS, %esi
13178+ jnz 2f
13179+#ifdef CONFIG_PARAVIRT
13180+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13181+ mov %eax, %esi
13182+#else
13183+ mov %cr0, %esi
13184+#endif
13185+ btr $16, %esi
13186+ ljmp $__KERNEL_CS, $1f
13187+1:
13188+#ifdef CONFIG_PARAVIRT
13189+ mov %esi, %eax
13190+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13191+#else
13192+ mov %esi, %cr0
13193+#endif
13194+2:
13195+#ifdef CONFIG_PARAVIRT
13196+ popl %ecx
13197+ popl %eax
13198+#endif
13199+ ret
13200+ENDPROC(pax_exit_kernel)
13201+#endif
13202+
13203+.macro pax_erase_kstack
13204+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13205+ call pax_erase_kstack
13206+#endif
13207+.endm
13208+
13209+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13210+/*
13211+ * ebp: thread_info
13212+ * ecx, edx: can be clobbered
13213+ */
13214+ENTRY(pax_erase_kstack)
13215+ pushl %edi
13216+ pushl %eax
13217+
13218+ mov TI_lowest_stack(%ebp), %edi
13219+ mov $-0xBEEF, %eax
13220+ std
13221+
13222+1: mov %edi, %ecx
13223+ and $THREAD_SIZE_asm - 1, %ecx
13224+ shr $2, %ecx
13225+ repne scasl
13226+ jecxz 2f
13227+
13228+ cmp $2*16, %ecx
13229+ jc 2f
13230+
13231+ mov $2*16, %ecx
13232+ repe scasl
13233+ jecxz 2f
13234+ jne 1b
13235+
13236+2: cld
13237+ mov %esp, %ecx
13238+ sub %edi, %ecx
13239+ shr $2, %ecx
13240+ rep stosl
13241+
13242+ mov TI_task_thread_sp0(%ebp), %edi
13243+ sub $128, %edi
13244+ mov %edi, TI_lowest_stack(%ebp)
13245+
13246+ popl %eax
13247+ popl %edi
13248+ ret
13249+ENDPROC(pax_erase_kstack)
13250+#endif
13251+
13252+.macro __SAVE_ALL _DS
13253 cld
13254 PUSH_GS
13255 pushl %fs
13256@@ -224,7 +357,7 @@
13257 pushl %ebx
13258 CFI_ADJUST_CFA_OFFSET 4
13259 CFI_REL_OFFSET ebx, 0
13260- movl $(__USER_DS), %edx
13261+ movl $\_DS, %edx
13262 movl %edx, %ds
13263 movl %edx, %es
13264 movl $(__KERNEL_PERCPU), %edx
13265@@ -232,6 +365,15 @@
13266 SET_KERNEL_GS %edx
13267 .endm
13268
13269+.macro SAVE_ALL
13270+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13271+ __SAVE_ALL __KERNEL_DS
13272+ pax_enter_kernel
13273+#else
13274+ __SAVE_ALL __USER_DS
13275+#endif
13276+.endm
13277+
13278 .macro RESTORE_INT_REGS
13279 popl %ebx
13280 CFI_ADJUST_CFA_OFFSET -4
13281@@ -352,7 +494,15 @@ check_userspace:
13282 movb PT_CS(%esp), %al
13283 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13284 cmpl $USER_RPL, %eax
13285+
13286+#ifdef CONFIG_PAX_KERNEXEC
13287+ jae resume_userspace
13288+
13289+ PAX_EXIT_KERNEL
13290+ jmp resume_kernel
13291+#else
13292 jb resume_kernel # not returning to v8086 or userspace
13293+#endif
13294
13295 ENTRY(resume_userspace)
13296 LOCKDEP_SYS_EXIT
13297@@ -364,7 +514,7 @@ ENTRY(resume_userspace)
13298 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13299 # int/exception return?
13300 jne work_pending
13301- jmp restore_all
13302+ jmp restore_all_pax
13303 END(ret_from_exception)
13304
13305 #ifdef CONFIG_PREEMPT
13306@@ -414,25 +564,36 @@ sysenter_past_esp:
13307 /*CFI_REL_OFFSET cs, 0*/
13308 /*
13309 * Push current_thread_info()->sysenter_return to the stack.
13310- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13311- * pushed above; +8 corresponds to copy_thread's esp0 setting.
13312 */
13313- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
13314+ pushl $0
13315 CFI_ADJUST_CFA_OFFSET 4
13316 CFI_REL_OFFSET eip, 0
13317
13318 pushl %eax
13319 CFI_ADJUST_CFA_OFFSET 4
13320 SAVE_ALL
13321+ GET_THREAD_INFO(%ebp)
13322+ movl TI_sysenter_return(%ebp),%ebp
13323+ movl %ebp,PT_EIP(%esp)
13324 ENABLE_INTERRUPTS(CLBR_NONE)
13325
13326 /*
13327 * Load the potential sixth argument from user stack.
13328 * Careful about security.
13329 */
13330+ movl PT_OLDESP(%esp),%ebp
13331+
13332+#ifdef CONFIG_PAX_MEMORY_UDEREF
13333+ mov PT_OLDSS(%esp),%ds
13334+1: movl %ds:(%ebp),%ebp
13335+ push %ss
13336+ pop %ds
13337+#else
13338 cmpl $__PAGE_OFFSET-3,%ebp
13339 jae syscall_fault
13340 1: movl (%ebp),%ebp
13341+#endif
13342+
13343 movl %ebp,PT_EBP(%esp)
13344 .section __ex_table,"a"
13345 .align 4
13346@@ -455,12 +616,23 @@ sysenter_do_call:
13347 testl $_TIF_ALLWORK_MASK, %ecx
13348 jne sysexit_audit
13349 sysenter_exit:
13350+
13351+#ifdef CONFIG_PAX_RANDKSTACK
13352+ pushl_cfi %eax
13353+ call pax_randomize_kstack
13354+ popl_cfi %eax
13355+#endif
13356+
13357+ pax_erase_kstack
13358+
13359 /* if something modifies registers it must also disable sysexit */
13360 movl PT_EIP(%esp), %edx
13361 movl PT_OLDESP(%esp), %ecx
13362 xorl %ebp,%ebp
13363 TRACE_IRQS_ON
13364 1: mov PT_FS(%esp), %fs
13365+2: mov PT_DS(%esp), %ds
13366+3: mov PT_ES(%esp), %es
13367 PTGS_TO_GS
13368 ENABLE_INTERRUPTS_SYSEXIT
13369
13370@@ -477,6 +649,9 @@ sysenter_audit:
13371 movl %eax,%edx /* 2nd arg: syscall number */
13372 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13373 call audit_syscall_entry
13374+
13375+ pax_erase_kstack
13376+
13377 pushl %ebx
13378 CFI_ADJUST_CFA_OFFSET 4
13379 movl PT_EAX(%esp),%eax /* reload syscall number */
13380@@ -504,11 +679,17 @@ sysexit_audit:
13381
13382 CFI_ENDPROC
13383 .pushsection .fixup,"ax"
13384-2: movl $0,PT_FS(%esp)
13385+4: movl $0,PT_FS(%esp)
13386+ jmp 1b
13387+5: movl $0,PT_DS(%esp)
13388+ jmp 1b
13389+6: movl $0,PT_ES(%esp)
13390 jmp 1b
13391 .section __ex_table,"a"
13392 .align 4
13393- .long 1b,2b
13394+ .long 1b,4b
13395+ .long 2b,5b
13396+ .long 3b,6b
13397 .popsection
13398 PTGS_TO_GS_EX
13399 ENDPROC(ia32_sysenter_target)
13400@@ -538,6 +719,14 @@ syscall_exit:
13401 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13402 jne syscall_exit_work
13403
13404+restore_all_pax:
13405+
13406+#ifdef CONFIG_PAX_RANDKSTACK
13407+ call pax_randomize_kstack
13408+#endif
13409+
13410+ pax_erase_kstack
13411+
13412 restore_all:
13413 TRACE_IRQS_IRET
13414 restore_all_notrace:
13415@@ -602,7 +791,13 @@ ldt_ss:
13416 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13417 mov %dx, %ax /* eax: new kernel esp */
13418 sub %eax, %edx /* offset (low word is 0) */
13419- PER_CPU(gdt_page, %ebx)
13420+#ifdef CONFIG_SMP
13421+ movl PER_CPU_VAR(cpu_number), %ebx
13422+ shll $PAGE_SHIFT_asm, %ebx
13423+ addl $cpu_gdt_table, %ebx
13424+#else
13425+ movl $cpu_gdt_table, %ebx
13426+#endif
13427 shr $16, %edx
13428 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
13429 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
13430@@ -636,31 +831,25 @@ work_resched:
13431 movl TI_flags(%ebp), %ecx
13432 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13433 # than syscall tracing?
13434- jz restore_all
13435+ jz restore_all_pax
13436 testb $_TIF_NEED_RESCHED, %cl
13437 jnz work_resched
13438
13439 work_notifysig: # deal with pending signals and
13440 # notify-resume requests
13441+ movl %esp, %eax
13442 #ifdef CONFIG_VM86
13443 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13444- movl %esp, %eax
13445- jne work_notifysig_v86 # returning to kernel-space or
13446+ jz 1f # returning to kernel-space or
13447 # vm86-space
13448- xorl %edx, %edx
13449- call do_notify_resume
13450- jmp resume_userspace_sig
13451
13452- ALIGN
13453-work_notifysig_v86:
13454 pushl %ecx # save ti_flags for do_notify_resume
13455 CFI_ADJUST_CFA_OFFSET 4
13456 call save_v86_state # %eax contains pt_regs pointer
13457 popl %ecx
13458 CFI_ADJUST_CFA_OFFSET -4
13459 movl %eax, %esp
13460-#else
13461- movl %esp, %eax
13462+1:
13463 #endif
13464 xorl %edx, %edx
13465 call do_notify_resume
13466@@ -673,6 +862,9 @@ syscall_trace_entry:
13467 movl $-ENOSYS,PT_EAX(%esp)
13468 movl %esp, %eax
13469 call syscall_trace_enter
13470+
13471+ pax_erase_kstack
13472+
13473 /* What it returned is what we'll actually use. */
13474 cmpl $(nr_syscalls), %eax
13475 jnae syscall_call
13476@@ -695,6 +887,10 @@ END(syscall_exit_work)
13477
13478 RING0_INT_FRAME # can't unwind into user space anyway
13479 syscall_fault:
13480+#ifdef CONFIG_PAX_MEMORY_UDEREF
13481+ push %ss
13482+ pop %ds
13483+#endif
13484 GET_THREAD_INFO(%ebp)
13485 movl $-EFAULT,PT_EAX(%esp)
13486 jmp resume_userspace
13487@@ -726,6 +922,33 @@ PTREGSCALL(rt_sigreturn)
13488 PTREGSCALL(vm86)
13489 PTREGSCALL(vm86old)
13490
13491+ ALIGN;
13492+ENTRY(kernel_execve)
13493+ push %ebp
13494+ sub $PT_OLDSS+4,%esp
13495+ push %edi
13496+ push %ecx
13497+ push %eax
13498+ lea 3*4(%esp),%edi
13499+ mov $PT_OLDSS/4+1,%ecx
13500+ xorl %eax,%eax
13501+ rep stosl
13502+ pop %eax
13503+ pop %ecx
13504+ pop %edi
13505+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13506+ mov %eax,PT_EBX(%esp)
13507+ mov %edx,PT_ECX(%esp)
13508+ mov %ecx,PT_EDX(%esp)
13509+ mov %esp,%eax
13510+ call sys_execve
13511+ GET_THREAD_INFO(%ebp)
13512+ test %eax,%eax
13513+ jz syscall_exit
13514+ add $PT_OLDSS+4,%esp
13515+ pop %ebp
13516+ ret
13517+
13518 .macro FIXUP_ESPFIX_STACK
13519 /*
13520 * Switch back for ESPFIX stack to the normal zerobased stack
13521@@ -735,7 +958,13 @@ PTREGSCALL(vm86old)
13522 * normal stack and adjusts ESP with the matching offset.
13523 */
13524 /* fixup the stack */
13525- PER_CPU(gdt_page, %ebx)
13526+#ifdef CONFIG_SMP
13527+ movl PER_CPU_VAR(cpu_number), %ebx
13528+ shll $PAGE_SHIFT_asm, %ebx
13529+ addl $cpu_gdt_table, %ebx
13530+#else
13531+ movl $cpu_gdt_table, %ebx
13532+#endif
13533 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
13534 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
13535 shl $16, %eax
13536@@ -1198,7 +1427,6 @@ return_to_handler:
13537 ret
13538 #endif
13539
13540-.section .rodata,"a"
13541 #include "syscall_table_32.S"
13542
13543 syscall_table_size=(.-sys_call_table)
13544@@ -1255,9 +1483,12 @@ error_code:
13545 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13546 REG_TO_PTGS %ecx
13547 SET_KERNEL_GS %ecx
13548- movl $(__USER_DS), %ecx
13549+ movl $(__KERNEL_DS), %ecx
13550 movl %ecx, %ds
13551 movl %ecx, %es
13552+
13553+ pax_enter_kernel
13554+
13555 TRACE_IRQS_OFF
13556 movl %esp,%eax # pt_regs pointer
13557 call *%edi
13558@@ -1351,6 +1582,9 @@ nmi_stack_correct:
13559 xorl %edx,%edx # zero error code
13560 movl %esp,%eax # pt_regs pointer
13561 call do_nmi
13562+
13563+ pax_exit_kernel
13564+
13565 jmp restore_all_notrace
13566 CFI_ENDPROC
13567
13568@@ -1391,6 +1625,9 @@ nmi_espfix_stack:
13569 FIXUP_ESPFIX_STACK # %eax == %esp
13570 xorl %edx,%edx # zero error code
13571 call do_nmi
13572+
13573+ pax_exit_kernel
13574+
13575 RESTORE_REGS
13576 lss 12+4(%esp), %esp # back to espfix stack
13577 CFI_ADJUST_CFA_OFFSET -24
13578diff -urNp linux-2.6.32.43/arch/x86/kernel/entry_64.S linux-2.6.32.43/arch/x86/kernel/entry_64.S
13579--- linux-2.6.32.43/arch/x86/kernel/entry_64.S 2011-03-27 14:31:47.000000000 -0400
13580+++ linux-2.6.32.43/arch/x86/kernel/entry_64.S 2011-06-04 20:30:53.000000000 -0400
13581@@ -53,6 +53,7 @@
13582 #include <asm/paravirt.h>
13583 #include <asm/ftrace.h>
13584 #include <asm/percpu.h>
13585+#include <asm/pgtable.h>
13586
13587 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13588 #include <linux/elf-em.h>
13589@@ -174,6 +175,257 @@ ENTRY(native_usergs_sysret64)
13590 ENDPROC(native_usergs_sysret64)
13591 #endif /* CONFIG_PARAVIRT */
13592
13593+ .macro ljmpq sel, off
13594+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13595+ .byte 0x48; ljmp *1234f(%rip)
13596+ .pushsection .rodata
13597+ .align 16
13598+ 1234: .quad \off; .word \sel
13599+ .popsection
13600+#else
13601+ pushq $\sel
13602+ pushq $\off
13603+ lretq
13604+#endif
13605+ .endm
13606+
13607+ .macro pax_enter_kernel
13608+#ifdef CONFIG_PAX_KERNEXEC
13609+ call pax_enter_kernel
13610+#endif
13611+ .endm
13612+
13613+ .macro pax_exit_kernel
13614+#ifdef CONFIG_PAX_KERNEXEC
13615+ call pax_exit_kernel
13616+#endif
13617+ .endm
13618+
13619+#ifdef CONFIG_PAX_KERNEXEC
13620+ENTRY(pax_enter_kernel)
13621+ pushq %rdi
13622+
13623+#ifdef CONFIG_PARAVIRT
13624+ PV_SAVE_REGS(CLBR_RDI)
13625+#endif
13626+
13627+ GET_CR0_INTO_RDI
13628+ bts $16,%rdi
13629+ jnc 1f
13630+ mov %cs,%edi
13631+ cmp $__KERNEL_CS,%edi
13632+ jz 3f
13633+ ljmpq __KERNEL_CS,3f
13634+1: ljmpq __KERNEXEC_KERNEL_CS,2f
13635+2: SET_RDI_INTO_CR0
13636+3:
13637+
13638+#ifdef CONFIG_PARAVIRT
13639+ PV_RESTORE_REGS(CLBR_RDI)
13640+#endif
13641+
13642+ popq %rdi
13643+ retq
13644+ENDPROC(pax_enter_kernel)
13645+
13646+ENTRY(pax_exit_kernel)
13647+ pushq %rdi
13648+
13649+#ifdef CONFIG_PARAVIRT
13650+ PV_SAVE_REGS(CLBR_RDI)
13651+#endif
13652+
13653+ mov %cs,%rdi
13654+ cmp $__KERNEXEC_KERNEL_CS,%edi
13655+ jnz 2f
13656+ GET_CR0_INTO_RDI
13657+ btr $16,%rdi
13658+ ljmpq __KERNEL_CS,1f
13659+1: SET_RDI_INTO_CR0
13660+2:
13661+
13662+#ifdef CONFIG_PARAVIRT
13663+ PV_RESTORE_REGS(CLBR_RDI);
13664+#endif
13665+
13666+ popq %rdi
13667+ retq
13668+ENDPROC(pax_exit_kernel)
13669+#endif
13670+
13671+ .macro pax_enter_kernel_user
13672+#ifdef CONFIG_PAX_MEMORY_UDEREF
13673+ call pax_enter_kernel_user
13674+#endif
13675+ .endm
13676+
13677+ .macro pax_exit_kernel_user
13678+#ifdef CONFIG_PAX_MEMORY_UDEREF
13679+ call pax_exit_kernel_user
13680+#endif
13681+#ifdef CONFIG_PAX_RANDKSTACK
13682+ push %rax
13683+ call pax_randomize_kstack
13684+ pop %rax
13685+#endif
13686+ pax_erase_kstack
13687+ .endm
13688+
13689+#ifdef CONFIG_PAX_MEMORY_UDEREF
13690+ENTRY(pax_enter_kernel_user)
13691+ pushq %rdi
13692+ pushq %rbx
13693+
13694+#ifdef CONFIG_PARAVIRT
13695+ PV_SAVE_REGS(CLBR_RDI)
13696+#endif
13697+
13698+ GET_CR3_INTO_RDI
13699+ mov %rdi,%rbx
13700+ add $__START_KERNEL_map,%rbx
13701+ sub phys_base(%rip),%rbx
13702+
13703+#ifdef CONFIG_PARAVIRT
13704+ pushq %rdi
13705+ cmpl $0, pv_info+PARAVIRT_enabled
13706+ jz 1f
13707+ i = 0
13708+ .rept USER_PGD_PTRS
13709+ mov i*8(%rbx),%rsi
13710+ mov $0,%sil
13711+ lea i*8(%rbx),%rdi
13712+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
13713+ i = i + 1
13714+ .endr
13715+ jmp 2f
13716+1:
13717+#endif
13718+
13719+ i = 0
13720+ .rept USER_PGD_PTRS
13721+ movb $0,i*8(%rbx)
13722+ i = i + 1
13723+ .endr
13724+
13725+#ifdef CONFIG_PARAVIRT
13726+2: popq %rdi
13727+#endif
13728+ SET_RDI_INTO_CR3
13729+
13730+#ifdef CONFIG_PAX_KERNEXEC
13731+ GET_CR0_INTO_RDI
13732+ bts $16,%rdi
13733+ SET_RDI_INTO_CR0
13734+#endif
13735+
13736+#ifdef CONFIG_PARAVIRT
13737+ PV_RESTORE_REGS(CLBR_RDI)
13738+#endif
13739+
13740+ popq %rbx
13741+ popq %rdi
13742+ retq
13743+ENDPROC(pax_enter_kernel_user)
13744+
13745+ENTRY(pax_exit_kernel_user)
13746+ push %rdi
13747+
13748+#ifdef CONFIG_PARAVIRT
13749+ pushq %rbx
13750+ PV_SAVE_REGS(CLBR_RDI)
13751+#endif
13752+
13753+#ifdef CONFIG_PAX_KERNEXEC
13754+ GET_CR0_INTO_RDI
13755+ btr $16,%rdi
13756+ SET_RDI_INTO_CR0
13757+#endif
13758+
13759+ GET_CR3_INTO_RDI
13760+ add $__START_KERNEL_map,%rdi
13761+ sub phys_base(%rip),%rdi
13762+
13763+#ifdef CONFIG_PARAVIRT
13764+ cmpl $0, pv_info+PARAVIRT_enabled
13765+ jz 1f
13766+ mov %rdi,%rbx
13767+ i = 0
13768+ .rept USER_PGD_PTRS
13769+ mov i*8(%rbx),%rsi
13770+ mov $0x67,%sil
13771+ lea i*8(%rbx),%rdi
13772+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
13773+ i = i + 1
13774+ .endr
13775+ jmp 2f
13776+1:
13777+#endif
13778+
13779+ i = 0
13780+ .rept USER_PGD_PTRS
13781+ movb $0x67,i*8(%rdi)
13782+ i = i + 1
13783+ .endr
13784+
13785+#ifdef CONFIG_PARAVIRT
13786+2: PV_RESTORE_REGS(CLBR_RDI)
13787+ popq %rbx
13788+#endif
13789+
13790+ popq %rdi
13791+ retq
13792+ENDPROC(pax_exit_kernel_user)
13793+#endif
13794+
13795+.macro pax_erase_kstack
13796+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13797+ call pax_erase_kstack
13798+#endif
13799+.endm
13800+
13801+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13802+/*
13803+ * r10: thread_info
13804+ * rcx, rdx: can be clobbered
13805+ */
13806+ENTRY(pax_erase_kstack)
13807+ pushq %rdi
13808+ pushq %rax
13809+
13810+ GET_THREAD_INFO(%r10)
13811+ mov TI_lowest_stack(%r10), %rdi
13812+ mov $-0xBEEF, %rax
13813+ std
13814+
13815+1: mov %edi, %ecx
13816+ and $THREAD_SIZE_asm - 1, %ecx
13817+ shr $3, %ecx
13818+ repne scasq
13819+ jecxz 2f
13820+
13821+ cmp $2*8, %ecx
13822+ jc 2f
13823+
13824+ mov $2*8, %ecx
13825+ repe scasq
13826+ jecxz 2f
13827+ jne 1b
13828+
13829+2: cld
13830+ mov %esp, %ecx
13831+ sub %edi, %ecx
13832+ shr $3, %ecx
13833+ rep stosq
13834+
13835+ mov TI_task_thread_sp0(%r10), %rdi
13836+ sub $256, %rdi
13837+ mov %rdi, TI_lowest_stack(%r10)
13838+
13839+ popq %rax
13840+ popq %rdi
13841+ ret
13842+ENDPROC(pax_erase_kstack)
13843+#endif
13844
13845 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
13846 #ifdef CONFIG_TRACE_IRQFLAGS
13847@@ -317,7 +569,7 @@ ENTRY(save_args)
13848 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
13849 movq_cfi rbp, 8 /* push %rbp */
13850 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
13851- testl $3, CS(%rdi)
13852+ testb $3, CS(%rdi)
13853 je 1f
13854 SWAPGS
13855 /*
13856@@ -409,7 +661,7 @@ ENTRY(ret_from_fork)
13857
13858 RESTORE_REST
13859
13860- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13861+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13862 je int_ret_from_sys_call
13863
13864 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
13865@@ -455,7 +707,7 @@ END(ret_from_fork)
13866 ENTRY(system_call)
13867 CFI_STARTPROC simple
13868 CFI_SIGNAL_FRAME
13869- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13870+ CFI_DEF_CFA rsp,0
13871 CFI_REGISTER rip,rcx
13872 /*CFI_REGISTER rflags,r11*/
13873 SWAPGS_UNSAFE_STACK
13874@@ -468,12 +720,13 @@ ENTRY(system_call_after_swapgs)
13875
13876 movq %rsp,PER_CPU_VAR(old_rsp)
13877 movq PER_CPU_VAR(kernel_stack),%rsp
13878+ pax_enter_kernel_user
13879 /*
13880 * No need to follow this irqs off/on section - it's straight
13881 * and short:
13882 */
13883 ENABLE_INTERRUPTS(CLBR_NONE)
13884- SAVE_ARGS 8,1
13885+ SAVE_ARGS 8*6,1
13886 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13887 movq %rcx,RIP-ARGOFFSET(%rsp)
13888 CFI_REL_OFFSET rip,RIP-ARGOFFSET
13889@@ -502,6 +755,7 @@ sysret_check:
13890 andl %edi,%edx
13891 jnz sysret_careful
13892 CFI_REMEMBER_STATE
13893+ pax_exit_kernel_user
13894 /*
13895 * sysretq will re-enable interrupts:
13896 */
13897@@ -562,6 +816,9 @@ auditsys:
13898 movq %rax,%rsi /* 2nd arg: syscall number */
13899 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
13900 call audit_syscall_entry
13901+
13902+ pax_erase_kstack
13903+
13904 LOAD_ARGS 0 /* reload call-clobbered registers */
13905 jmp system_call_fastpath
13906
13907@@ -592,6 +849,9 @@ tracesys:
13908 FIXUP_TOP_OF_STACK %rdi
13909 movq %rsp,%rdi
13910 call syscall_trace_enter
13911+
13912+ pax_erase_kstack
13913+
13914 /*
13915 * Reload arg registers from stack in case ptrace changed them.
13916 * We don't reload %rax because syscall_trace_enter() returned
13917@@ -613,7 +873,7 @@ tracesys:
13918 GLOBAL(int_ret_from_sys_call)
13919 DISABLE_INTERRUPTS(CLBR_NONE)
13920 TRACE_IRQS_OFF
13921- testl $3,CS-ARGOFFSET(%rsp)
13922+ testb $3,CS-ARGOFFSET(%rsp)
13923 je retint_restore_args
13924 movl $_TIF_ALLWORK_MASK,%edi
13925 /* edi: mask to check */
13926@@ -800,6 +1060,16 @@ END(interrupt)
13927 CFI_ADJUST_CFA_OFFSET 10*8
13928 call save_args
13929 PARTIAL_FRAME 0
13930+#ifdef CONFIG_PAX_MEMORY_UDEREF
13931+ testb $3, CS(%rdi)
13932+ jnz 1f
13933+ pax_enter_kernel
13934+ jmp 2f
13935+1: pax_enter_kernel_user
13936+2:
13937+#else
13938+ pax_enter_kernel
13939+#endif
13940 call \func
13941 .endm
13942
13943@@ -822,7 +1092,7 @@ ret_from_intr:
13944 CFI_ADJUST_CFA_OFFSET -8
13945 exit_intr:
13946 GET_THREAD_INFO(%rcx)
13947- testl $3,CS-ARGOFFSET(%rsp)
13948+ testb $3,CS-ARGOFFSET(%rsp)
13949 je retint_kernel
13950
13951 /* Interrupt came from user space */
13952@@ -844,12 +1114,14 @@ retint_swapgs: /* return to user-space
13953 * The iretq could re-enable interrupts:
13954 */
13955 DISABLE_INTERRUPTS(CLBR_ANY)
13956+ pax_exit_kernel_user
13957 TRACE_IRQS_IRETQ
13958 SWAPGS
13959 jmp restore_args
13960
13961 retint_restore_args: /* return to kernel space */
13962 DISABLE_INTERRUPTS(CLBR_ANY)
13963+ pax_exit_kernel
13964 /*
13965 * The iretq could re-enable interrupts:
13966 */
13967@@ -1032,6 +1304,16 @@ ENTRY(\sym)
13968 CFI_ADJUST_CFA_OFFSET 15*8
13969 call error_entry
13970 DEFAULT_FRAME 0
13971+#ifdef CONFIG_PAX_MEMORY_UDEREF
13972+ testb $3, CS(%rsp)
13973+ jnz 1f
13974+ pax_enter_kernel
13975+ jmp 2f
13976+1: pax_enter_kernel_user
13977+2:
13978+#else
13979+ pax_enter_kernel
13980+#endif
13981 movq %rsp,%rdi /* pt_regs pointer */
13982 xorl %esi,%esi /* no error code */
13983 call \do_sym
13984@@ -1049,6 +1331,16 @@ ENTRY(\sym)
13985 subq $15*8, %rsp
13986 call save_paranoid
13987 TRACE_IRQS_OFF
13988+#ifdef CONFIG_PAX_MEMORY_UDEREF
13989+ testb $3, CS(%rsp)
13990+ jnz 1f
13991+ pax_enter_kernel
13992+ jmp 2f
13993+1: pax_enter_kernel_user
13994+2:
13995+#else
13996+ pax_enter_kernel
13997+#endif
13998 movq %rsp,%rdi /* pt_regs pointer */
13999 xorl %esi,%esi /* no error code */
14000 call \do_sym
14001@@ -1066,9 +1358,24 @@ ENTRY(\sym)
14002 subq $15*8, %rsp
14003 call save_paranoid
14004 TRACE_IRQS_OFF
14005+#ifdef CONFIG_PAX_MEMORY_UDEREF
14006+ testb $3, CS(%rsp)
14007+ jnz 1f
14008+ pax_enter_kernel
14009+ jmp 2f
14010+1: pax_enter_kernel_user
14011+2:
14012+#else
14013+ pax_enter_kernel
14014+#endif
14015 movq %rsp,%rdi /* pt_regs pointer */
14016 xorl %esi,%esi /* no error code */
14017- PER_CPU(init_tss, %rbp)
14018+#ifdef CONFIG_SMP
14019+ imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
14020+ lea init_tss(%rbp), %rbp
14021+#else
14022+ lea init_tss(%rip), %rbp
14023+#endif
14024 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
14025 call \do_sym
14026 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
14027@@ -1085,6 +1392,16 @@ ENTRY(\sym)
14028 CFI_ADJUST_CFA_OFFSET 15*8
14029 call error_entry
14030 DEFAULT_FRAME 0
14031+#ifdef CONFIG_PAX_MEMORY_UDEREF
14032+ testb $3, CS(%rsp)
14033+ jnz 1f
14034+ pax_enter_kernel
14035+ jmp 2f
14036+1: pax_enter_kernel_user
14037+2:
14038+#else
14039+ pax_enter_kernel
14040+#endif
14041 movq %rsp,%rdi /* pt_regs pointer */
14042 movq ORIG_RAX(%rsp),%rsi /* get error code */
14043 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14044@@ -1104,6 +1421,16 @@ ENTRY(\sym)
14045 call save_paranoid
14046 DEFAULT_FRAME 0
14047 TRACE_IRQS_OFF
14048+#ifdef CONFIG_PAX_MEMORY_UDEREF
14049+ testb $3, CS(%rsp)
14050+ jnz 1f
14051+ pax_enter_kernel
14052+ jmp 2f
14053+1: pax_enter_kernel_user
14054+2:
14055+#else
14056+ pax_enter_kernel
14057+#endif
14058 movq %rsp,%rdi /* pt_regs pointer */
14059 movq ORIG_RAX(%rsp),%rsi /* get error code */
14060 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14061@@ -1405,14 +1732,27 @@ ENTRY(paranoid_exit)
14062 TRACE_IRQS_OFF
14063 testl %ebx,%ebx /* swapgs needed? */
14064 jnz paranoid_restore
14065- testl $3,CS(%rsp)
14066+ testb $3,CS(%rsp)
14067 jnz paranoid_userspace
14068+#ifdef CONFIG_PAX_MEMORY_UDEREF
14069+ pax_exit_kernel
14070+ TRACE_IRQS_IRETQ 0
14071+ SWAPGS_UNSAFE_STACK
14072+ RESTORE_ALL 8
14073+ jmp irq_return
14074+#endif
14075 paranoid_swapgs:
14076+#ifdef CONFIG_PAX_MEMORY_UDEREF
14077+ pax_exit_kernel_user
14078+#else
14079+ pax_exit_kernel
14080+#endif
14081 TRACE_IRQS_IRETQ 0
14082 SWAPGS_UNSAFE_STACK
14083 RESTORE_ALL 8
14084 jmp irq_return
14085 paranoid_restore:
14086+ pax_exit_kernel
14087 TRACE_IRQS_IRETQ 0
14088 RESTORE_ALL 8
14089 jmp irq_return
14090@@ -1470,7 +1810,7 @@ ENTRY(error_entry)
14091 movq_cfi r14, R14+8
14092 movq_cfi r15, R15+8
14093 xorl %ebx,%ebx
14094- testl $3,CS+8(%rsp)
14095+ testb $3,CS+8(%rsp)
14096 je error_kernelspace
14097 error_swapgs:
14098 SWAPGS
14099@@ -1529,6 +1869,16 @@ ENTRY(nmi)
14100 CFI_ADJUST_CFA_OFFSET 15*8
14101 call save_paranoid
14102 DEFAULT_FRAME 0
14103+#ifdef CONFIG_PAX_MEMORY_UDEREF
14104+ testb $3, CS(%rsp)
14105+ jnz 1f
14106+ pax_enter_kernel
14107+ jmp 2f
14108+1: pax_enter_kernel_user
14109+2:
14110+#else
14111+ pax_enter_kernel
14112+#endif
14113 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14114 movq %rsp,%rdi
14115 movq $-1,%rsi
14116@@ -1539,11 +1889,25 @@ ENTRY(nmi)
14117 DISABLE_INTERRUPTS(CLBR_NONE)
14118 testl %ebx,%ebx /* swapgs needed? */
14119 jnz nmi_restore
14120- testl $3,CS(%rsp)
14121+ testb $3,CS(%rsp)
14122 jnz nmi_userspace
14123+#ifdef CONFIG_PAX_MEMORY_UDEREF
14124+ pax_exit_kernel
14125+ SWAPGS_UNSAFE_STACK
14126+ RESTORE_ALL 8
14127+ jmp irq_return
14128+#endif
14129 nmi_swapgs:
14130+#ifdef CONFIG_PAX_MEMORY_UDEREF
14131+ pax_exit_kernel_user
14132+#else
14133+ pax_exit_kernel
14134+#endif
14135 SWAPGS_UNSAFE_STACK
14136+ RESTORE_ALL 8
14137+ jmp irq_return
14138 nmi_restore:
14139+ pax_exit_kernel
14140 RESTORE_ALL 8
14141 jmp irq_return
14142 nmi_userspace:
14143diff -urNp linux-2.6.32.43/arch/x86/kernel/ftrace.c linux-2.6.32.43/arch/x86/kernel/ftrace.c
14144--- linux-2.6.32.43/arch/x86/kernel/ftrace.c 2011-03-27 14:31:47.000000000 -0400
14145+++ linux-2.6.32.43/arch/x86/kernel/ftrace.c 2011-05-04 17:56:20.000000000 -0400
14146@@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the
14147 static void *mod_code_newcode; /* holds the text to write to the IP */
14148
14149 static unsigned nmi_wait_count;
14150-static atomic_t nmi_update_count = ATOMIC_INIT(0);
14151+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14152
14153 int ftrace_arch_read_dyn_info(char *buf, int size)
14154 {
14155@@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14156
14157 r = snprintf(buf, size, "%u %u",
14158 nmi_wait_count,
14159- atomic_read(&nmi_update_count));
14160+ atomic_read_unchecked(&nmi_update_count));
14161 return r;
14162 }
14163
14164@@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
14165 {
14166 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14167 smp_rmb();
14168+ pax_open_kernel();
14169 ftrace_mod_code();
14170- atomic_inc(&nmi_update_count);
14171+ pax_close_kernel();
14172+ atomic_inc_unchecked(&nmi_update_count);
14173 }
14174 /* Must have previous changes seen before executions */
14175 smp_mb();
14176@@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, voi
14177
14178
14179
14180-static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
14181+static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
14182
14183 static unsigned char *ftrace_nop_replace(void)
14184 {
14185@@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, uns
14186 {
14187 unsigned char replaced[MCOUNT_INSN_SIZE];
14188
14189+ ip = ktla_ktva(ip);
14190+
14191 /*
14192 * Note: Due to modules and __init, code can
14193 * disappear and change, we need to protect against faulting
14194@@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14195 unsigned char old[MCOUNT_INSN_SIZE], *new;
14196 int ret;
14197
14198- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14199+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14200 new = ftrace_call_replace(ip, (unsigned long)func);
14201 ret = ftrace_modify_code(ip, old, new);
14202
14203@@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *da
14204 switch (faulted) {
14205 case 0:
14206 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
14207- memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
14208+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
14209 break;
14210 case 1:
14211 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
14212- memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
14213+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
14214 break;
14215 case 2:
14216 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
14217- memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
14218+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
14219 break;
14220 }
14221
14222@@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long
14223 {
14224 unsigned char code[MCOUNT_INSN_SIZE];
14225
14226+ ip = ktla_ktva(ip);
14227+
14228 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14229 return -EFAULT;
14230
14231diff -urNp linux-2.6.32.43/arch/x86/kernel/head32.c linux-2.6.32.43/arch/x86/kernel/head32.c
14232--- linux-2.6.32.43/arch/x86/kernel/head32.c 2011-03-27 14:31:47.000000000 -0400
14233+++ linux-2.6.32.43/arch/x86/kernel/head32.c 2011-04-17 15:56:46.000000000 -0400
14234@@ -16,6 +16,7 @@
14235 #include <asm/apic.h>
14236 #include <asm/io_apic.h>
14237 #include <asm/bios_ebda.h>
14238+#include <asm/boot.h>
14239
14240 static void __init i386_default_early_setup(void)
14241 {
14242@@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
14243 {
14244 reserve_trampoline_memory();
14245
14246- reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14247+ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14248
14249 #ifdef CONFIG_BLK_DEV_INITRD
14250 /* Reserve INITRD */
14251diff -urNp linux-2.6.32.43/arch/x86/kernel/head_32.S linux-2.6.32.43/arch/x86/kernel/head_32.S
14252--- linux-2.6.32.43/arch/x86/kernel/head_32.S 2011-03-27 14:31:47.000000000 -0400
14253+++ linux-2.6.32.43/arch/x86/kernel/head_32.S 2011-07-06 19:53:33.000000000 -0400
14254@@ -19,10 +19,17 @@
14255 #include <asm/setup.h>
14256 #include <asm/processor-flags.h>
14257 #include <asm/percpu.h>
14258+#include <asm/msr-index.h>
14259
14260 /* Physical address */
14261 #define pa(X) ((X) - __PAGE_OFFSET)
14262
14263+#ifdef CONFIG_PAX_KERNEXEC
14264+#define ta(X) (X)
14265+#else
14266+#define ta(X) ((X) - __PAGE_OFFSET)
14267+#endif
14268+
14269 /*
14270 * References to members of the new_cpu_data structure.
14271 */
14272@@ -52,11 +59,7 @@
14273 * and small than max_low_pfn, otherwise will waste some page table entries
14274 */
14275
14276-#if PTRS_PER_PMD > 1
14277-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14278-#else
14279-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14280-#endif
14281+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14282
14283 /* Enough space to fit pagetables for the low memory linear map */
14284 MAPPING_BEYOND_END = \
14285@@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14286 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14287
14288 /*
14289+ * Real beginning of normal "text" segment
14290+ */
14291+ENTRY(stext)
14292+ENTRY(_stext)
14293+
14294+/*
14295 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14296 * %esi points to the real-mode code as a 32-bit pointer.
14297 * CS and DS must be 4 GB flat segments, but we don't depend on
14298@@ -80,7 +89,16 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14299 * can.
14300 */
14301 __HEAD
14302+
14303+#ifdef CONFIG_PAX_KERNEXEC
14304+ jmp startup_32
14305+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14306+.fill PAGE_SIZE-5,1,0xcc
14307+#endif
14308+
14309 ENTRY(startup_32)
14310+ movl pa(stack_start),%ecx
14311+
14312 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
14313 us to not reload segments */
14314 testb $(1<<6), BP_loadflags(%esi)
14315@@ -95,7 +113,60 @@ ENTRY(startup_32)
14316 movl %eax,%es
14317 movl %eax,%fs
14318 movl %eax,%gs
14319+ movl %eax,%ss
14320 2:
14321+ leal -__PAGE_OFFSET(%ecx),%esp
14322+
14323+#ifdef CONFIG_SMP
14324+ movl $pa(cpu_gdt_table),%edi
14325+ movl $__per_cpu_load,%eax
14326+ movw %ax,__KERNEL_PERCPU + 2(%edi)
14327+ rorl $16,%eax
14328+ movb %al,__KERNEL_PERCPU + 4(%edi)
14329+ movb %ah,__KERNEL_PERCPU + 7(%edi)
14330+ movl $__per_cpu_end - 1,%eax
14331+ subl $__per_cpu_start,%eax
14332+ movw %ax,__KERNEL_PERCPU + 0(%edi)
14333+#endif
14334+
14335+#ifdef CONFIG_PAX_MEMORY_UDEREF
14336+ movl $NR_CPUS,%ecx
14337+ movl $pa(cpu_gdt_table),%edi
14338+1:
14339+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14340+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14341+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14342+ addl $PAGE_SIZE_asm,%edi
14343+ loop 1b
14344+#endif
14345+
14346+#ifdef CONFIG_PAX_KERNEXEC
14347+ movl $pa(boot_gdt),%edi
14348+ movl $__LOAD_PHYSICAL_ADDR,%eax
14349+ movw %ax,__BOOT_CS + 2(%edi)
14350+ rorl $16,%eax
14351+ movb %al,__BOOT_CS + 4(%edi)
14352+ movb %ah,__BOOT_CS + 7(%edi)
14353+ rorl $16,%eax
14354+
14355+ ljmp $(__BOOT_CS),$1f
14356+1:
14357+
14358+ movl $NR_CPUS,%ecx
14359+ movl $pa(cpu_gdt_table),%edi
14360+ addl $__PAGE_OFFSET,%eax
14361+1:
14362+ movw %ax,__KERNEL_CS + 2(%edi)
14363+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14364+ rorl $16,%eax
14365+ movb %al,__KERNEL_CS + 4(%edi)
14366+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14367+ movb %ah,__KERNEL_CS + 7(%edi)
14368+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14369+ rorl $16,%eax
14370+ addl $PAGE_SIZE_asm,%edi
14371+ loop 1b
14372+#endif
14373
14374 /*
14375 * Clear BSS first so that there are no surprises...
14376@@ -140,9 +211,7 @@ ENTRY(startup_32)
14377 cmpl $num_subarch_entries, %eax
14378 jae bad_subarch
14379
14380- movl pa(subarch_entries)(,%eax,4), %eax
14381- subl $__PAGE_OFFSET, %eax
14382- jmp *%eax
14383+ jmp *pa(subarch_entries)(,%eax,4)
14384
14385 bad_subarch:
14386 WEAK(lguest_entry)
14387@@ -154,10 +223,10 @@ WEAK(xen_entry)
14388 __INITDATA
14389
14390 subarch_entries:
14391- .long default_entry /* normal x86/PC */
14392- .long lguest_entry /* lguest hypervisor */
14393- .long xen_entry /* Xen hypervisor */
14394- .long default_entry /* Moorestown MID */
14395+ .long ta(default_entry) /* normal x86/PC */
14396+ .long ta(lguest_entry) /* lguest hypervisor */
14397+ .long ta(xen_entry) /* Xen hypervisor */
14398+ .long ta(default_entry) /* Moorestown MID */
14399 num_subarch_entries = (. - subarch_entries) / 4
14400 .previous
14401 #endif /* CONFIG_PARAVIRT */
14402@@ -218,8 +287,11 @@ default_entry:
14403 movl %eax, pa(max_pfn_mapped)
14404
14405 /* Do early initialization of the fixmap area */
14406- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
14407- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
14408+#ifdef CONFIG_COMPAT_VDSO
14409+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
14410+#else
14411+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
14412+#endif
14413 #else /* Not PAE */
14414
14415 page_pde_offset = (__PAGE_OFFSET >> 20);
14416@@ -249,8 +321,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14417 movl %eax, pa(max_pfn_mapped)
14418
14419 /* Do early initialization of the fixmap area */
14420- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
14421- movl %eax,pa(swapper_pg_dir+0xffc)
14422+#ifdef CONFIG_COMPAT_VDSO
14423+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
14424+#else
14425+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
14426+#endif
14427 #endif
14428 jmp 3f
14429 /*
14430@@ -272,6 +347,9 @@ ENTRY(startup_32_smp)
14431 movl %eax,%es
14432 movl %eax,%fs
14433 movl %eax,%gs
14434+ movl pa(stack_start),%ecx
14435+ movl %eax,%ss
14436+ leal -__PAGE_OFFSET(%ecx),%esp
14437 #endif /* CONFIG_SMP */
14438 3:
14439
14440@@ -297,6 +375,7 @@ ENTRY(startup_32_smp)
14441 orl %edx,%eax
14442 movl %eax,%cr4
14443
14444+#ifdef CONFIG_X86_PAE
14445 btl $5, %eax # check if PAE is enabled
14446 jnc 6f
14447
14448@@ -305,6 +384,10 @@ ENTRY(startup_32_smp)
14449 cpuid
14450 cmpl $0x80000000, %eax
14451 jbe 6f
14452+
14453+ /* Clear bogus XD_DISABLE bits */
14454+ call verify_cpu
14455+
14456 mov $0x80000001, %eax
14457 cpuid
14458 /* Execute Disable bit supported? */
14459@@ -312,13 +395,17 @@ ENTRY(startup_32_smp)
14460 jnc 6f
14461
14462 /* Setup EFER (Extended Feature Enable Register) */
14463- movl $0xc0000080, %ecx
14464+ movl $MSR_EFER, %ecx
14465 rdmsr
14466
14467 btsl $11, %eax
14468 /* Make changes effective */
14469 wrmsr
14470
14471+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14472+ movl $1,pa(nx_enabled)
14473+#endif
14474+
14475 6:
14476
14477 /*
14478@@ -331,8 +418,8 @@ ENTRY(startup_32_smp)
14479 movl %eax,%cr0 /* ..and set paging (PG) bit */
14480 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
14481 1:
14482- /* Set up the stack pointer */
14483- lss stack_start,%esp
14484+ /* Shift the stack pointer to a virtual address */
14485+ addl $__PAGE_OFFSET, %esp
14486
14487 /*
14488 * Initialize eflags. Some BIOS's leave bits like NT set. This would
14489@@ -344,9 +431,7 @@ ENTRY(startup_32_smp)
14490
14491 #ifdef CONFIG_SMP
14492 cmpb $0, ready
14493- jz 1f /* Initial CPU cleans BSS */
14494- jmp checkCPUtype
14495-1:
14496+ jnz checkCPUtype
14497 #endif /* CONFIG_SMP */
14498
14499 /*
14500@@ -424,7 +509,7 @@ is386: movl $2,%ecx # set MP
14501 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14502 movl %eax,%ss # after changing gdt.
14503
14504- movl $(__USER_DS),%eax # DS/ES contains default USER segment
14505+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14506 movl %eax,%ds
14507 movl %eax,%es
14508
14509@@ -438,15 +523,22 @@ is386: movl $2,%ecx # set MP
14510 */
14511 cmpb $0,ready
14512 jne 1f
14513- movl $per_cpu__gdt_page,%eax
14514+ movl $cpu_gdt_table,%eax
14515 movl $per_cpu__stack_canary,%ecx
14516+#ifdef CONFIG_SMP
14517+ addl $__per_cpu_load,%ecx
14518+#endif
14519 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14520 shrl $16, %ecx
14521 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14522 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14523 1:
14524-#endif
14525 movl $(__KERNEL_STACK_CANARY),%eax
14526+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14527+ movl $(__USER_DS),%eax
14528+#else
14529+ xorl %eax,%eax
14530+#endif
14531 movl %eax,%gs
14532
14533 xorl %eax,%eax # Clear LDT
14534@@ -454,14 +546,7 @@ is386: movl $2,%ecx # set MP
14535
14536 cld # gcc2 wants the direction flag cleared at all times
14537 pushl $0 # fake return address for unwinder
14538-#ifdef CONFIG_SMP
14539- movb ready, %cl
14540 movb $1, ready
14541- cmpb $0,%cl # the first CPU calls start_kernel
14542- je 1f
14543- movl (stack_start), %esp
14544-1:
14545-#endif /* CONFIG_SMP */
14546 jmp *(initial_code)
14547
14548 /*
14549@@ -546,22 +631,22 @@ early_page_fault:
14550 jmp early_fault
14551
14552 early_fault:
14553- cld
14554 #ifdef CONFIG_PRINTK
14555+ cmpl $1,%ss:early_recursion_flag
14556+ je hlt_loop
14557+ incl %ss:early_recursion_flag
14558+ cld
14559 pusha
14560 movl $(__KERNEL_DS),%eax
14561 movl %eax,%ds
14562 movl %eax,%es
14563- cmpl $2,early_recursion_flag
14564- je hlt_loop
14565- incl early_recursion_flag
14566 movl %cr2,%eax
14567 pushl %eax
14568 pushl %edx /* trapno */
14569 pushl $fault_msg
14570 call printk
14571+; call dump_stack
14572 #endif
14573- call dump_stack
14574 hlt_loop:
14575 hlt
14576 jmp hlt_loop
14577@@ -569,8 +654,11 @@ hlt_loop:
14578 /* This is the default interrupt "handler" :-) */
14579 ALIGN
14580 ignore_int:
14581- cld
14582 #ifdef CONFIG_PRINTK
14583+ cmpl $2,%ss:early_recursion_flag
14584+ je hlt_loop
14585+ incl %ss:early_recursion_flag
14586+ cld
14587 pushl %eax
14588 pushl %ecx
14589 pushl %edx
14590@@ -579,9 +667,6 @@ ignore_int:
14591 movl $(__KERNEL_DS),%eax
14592 movl %eax,%ds
14593 movl %eax,%es
14594- cmpl $2,early_recursion_flag
14595- je hlt_loop
14596- incl early_recursion_flag
14597 pushl 16(%esp)
14598 pushl 24(%esp)
14599 pushl 32(%esp)
14600@@ -600,6 +685,8 @@ ignore_int:
14601 #endif
14602 iret
14603
14604+#include "verify_cpu.S"
14605+
14606 __REFDATA
14607 .align 4
14608 ENTRY(initial_code)
14609@@ -610,31 +697,47 @@ ENTRY(initial_page_table)
14610 /*
14611 * BSS section
14612 */
14613-__PAGE_ALIGNED_BSS
14614- .align PAGE_SIZE_asm
14615 #ifdef CONFIG_X86_PAE
14616+.section .swapper_pg_pmd,"a",@progbits
14617 swapper_pg_pmd:
14618 .fill 1024*KPMDS,4,0
14619 #else
14620+.section .swapper_pg_dir,"a",@progbits
14621 ENTRY(swapper_pg_dir)
14622 .fill 1024,4,0
14623 #endif
14624+.section .swapper_pg_fixmap,"a",@progbits
14625 swapper_pg_fixmap:
14626 .fill 1024,4,0
14627 #ifdef CONFIG_X86_TRAMPOLINE
14628+.section .trampoline_pg_dir,"a",@progbits
14629 ENTRY(trampoline_pg_dir)
14630+#ifdef CONFIG_X86_PAE
14631+ .fill 4,8,0
14632+#else
14633 .fill 1024,4,0
14634 #endif
14635+#endif
14636+
14637+.section .empty_zero_page,"a",@progbits
14638 ENTRY(empty_zero_page)
14639 .fill 4096,1,0
14640
14641 /*
14642+ * The IDT has to be page-aligned to simplify the Pentium
14643+ * F0 0F bug workaround.. We have a special link segment
14644+ * for this.
14645+ */
14646+.section .idt,"a",@progbits
14647+ENTRY(idt_table)
14648+ .fill 256,8,0
14649+
14650+/*
14651 * This starts the data section.
14652 */
14653 #ifdef CONFIG_X86_PAE
14654-__PAGE_ALIGNED_DATA
14655- /* Page-aligned for the benefit of paravirt? */
14656- .align PAGE_SIZE_asm
14657+.section .swapper_pg_dir,"a",@progbits
14658+
14659 ENTRY(swapper_pg_dir)
14660 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
14661 # if KPMDS == 3
14662@@ -653,15 +756,24 @@ ENTRY(swapper_pg_dir)
14663 # error "Kernel PMDs should be 1, 2 or 3"
14664 # endif
14665 .align PAGE_SIZE_asm /* needs to be page-sized too */
14666+
14667+#ifdef CONFIG_PAX_PER_CPU_PGD
14668+ENTRY(cpu_pgd)
14669+ .rept NR_CPUS
14670+ .fill 4,8,0
14671+ .endr
14672+#endif
14673+
14674 #endif
14675
14676 .data
14677+.balign 4
14678 ENTRY(stack_start)
14679- .long init_thread_union+THREAD_SIZE
14680- .long __BOOT_DS
14681+ .long init_thread_union+THREAD_SIZE-8
14682
14683 ready: .byte 0
14684
14685+.section .rodata,"a",@progbits
14686 early_recursion_flag:
14687 .long 0
14688
14689@@ -697,7 +809,7 @@ fault_msg:
14690 .word 0 # 32 bit align gdt_desc.address
14691 boot_gdt_descr:
14692 .word __BOOT_DS+7
14693- .long boot_gdt - __PAGE_OFFSET
14694+ .long pa(boot_gdt)
14695
14696 .word 0 # 32-bit align idt_desc.address
14697 idt_descr:
14698@@ -708,7 +820,7 @@ idt_descr:
14699 .word 0 # 32 bit align gdt_desc.address
14700 ENTRY(early_gdt_descr)
14701 .word GDT_ENTRIES*8-1
14702- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
14703+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
14704
14705 /*
14706 * The boot_gdt must mirror the equivalent in setup.S and is
14707@@ -717,5 +829,65 @@ ENTRY(early_gdt_descr)
14708 .align L1_CACHE_BYTES
14709 ENTRY(boot_gdt)
14710 .fill GDT_ENTRY_BOOT_CS,8,0
14711- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
14712- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
14713+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
14714+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
14715+
14716+ .align PAGE_SIZE_asm
14717+ENTRY(cpu_gdt_table)
14718+ .rept NR_CPUS
14719+ .quad 0x0000000000000000 /* NULL descriptor */
14720+ .quad 0x0000000000000000 /* 0x0b reserved */
14721+ .quad 0x0000000000000000 /* 0x13 reserved */
14722+ .quad 0x0000000000000000 /* 0x1b reserved */
14723+
14724+#ifdef CONFIG_PAX_KERNEXEC
14725+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
14726+#else
14727+ .quad 0x0000000000000000 /* 0x20 unused */
14728+#endif
14729+
14730+ .quad 0x0000000000000000 /* 0x28 unused */
14731+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
14732+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
14733+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
14734+ .quad 0x0000000000000000 /* 0x4b reserved */
14735+ .quad 0x0000000000000000 /* 0x53 reserved */
14736+ .quad 0x0000000000000000 /* 0x5b reserved */
14737+
14738+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
14739+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
14740+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
14741+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
14742+
14743+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
14744+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
14745+
14746+ /*
14747+ * Segments used for calling PnP BIOS have byte granularity.
14748+ * The code segments and data segments have fixed 64k limits,
14749+ * the transfer segment sizes are set at run time.
14750+ */
14751+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
14752+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
14753+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
14754+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
14755+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
14756+
14757+ /*
14758+ * The APM segments have byte granularity and their bases
14759+ * are set at run time. All have 64k limits.
14760+ */
14761+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
14762+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
14763+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
14764+
14765+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
14766+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
14767+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
14768+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
14769+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
14770+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
14771+
14772+ /* Be sure this is zeroed to avoid false validations in Xen */
14773+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
14774+ .endr
14775diff -urNp linux-2.6.32.43/arch/x86/kernel/head_64.S linux-2.6.32.43/arch/x86/kernel/head_64.S
14776--- linux-2.6.32.43/arch/x86/kernel/head_64.S 2011-03-27 14:31:47.000000000 -0400
14777+++ linux-2.6.32.43/arch/x86/kernel/head_64.S 2011-04-17 15:56:46.000000000 -0400
14778@@ -19,6 +19,7 @@
14779 #include <asm/cache.h>
14780 #include <asm/processor-flags.h>
14781 #include <asm/percpu.h>
14782+#include <asm/cpufeature.h>
14783
14784 #ifdef CONFIG_PARAVIRT
14785 #include <asm/asm-offsets.h>
14786@@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
14787 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
14788 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
14789 L3_START_KERNEL = pud_index(__START_KERNEL_map)
14790+L4_VMALLOC_START = pgd_index(VMALLOC_START)
14791+L3_VMALLOC_START = pud_index(VMALLOC_START)
14792+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
14793+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
14794
14795 .text
14796 __HEAD
14797@@ -85,35 +90,22 @@ startup_64:
14798 */
14799 addq %rbp, init_level4_pgt + 0(%rip)
14800 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
14801+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
14802+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
14803 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
14804
14805 addq %rbp, level3_ident_pgt + 0(%rip)
14806+#ifndef CONFIG_XEN
14807+ addq %rbp, level3_ident_pgt + 8(%rip)
14808+#endif
14809
14810- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
14811- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
14812+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
14813
14814- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14815+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
14816+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
14817
14818- /* Add an Identity mapping if I am above 1G */
14819- leaq _text(%rip), %rdi
14820- andq $PMD_PAGE_MASK, %rdi
14821-
14822- movq %rdi, %rax
14823- shrq $PUD_SHIFT, %rax
14824- andq $(PTRS_PER_PUD - 1), %rax
14825- jz ident_complete
14826-
14827- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
14828- leaq level3_ident_pgt(%rip), %rbx
14829- movq %rdx, 0(%rbx, %rax, 8)
14830-
14831- movq %rdi, %rax
14832- shrq $PMD_SHIFT, %rax
14833- andq $(PTRS_PER_PMD - 1), %rax
14834- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
14835- leaq level2_spare_pgt(%rip), %rbx
14836- movq %rdx, 0(%rbx, %rax, 8)
14837-ident_complete:
14838+ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14839+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
14840
14841 /*
14842 * Fixup the kernel text+data virtual addresses. Note that
14843@@ -161,8 +153,8 @@ ENTRY(secondary_startup_64)
14844 * after the boot processor executes this code.
14845 */
14846
14847- /* Enable PAE mode and PGE */
14848- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
14849+ /* Enable PAE mode and PSE/PGE */
14850+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
14851 movq %rax, %cr4
14852
14853 /* Setup early boot stage 4 level pagetables. */
14854@@ -184,9 +176,13 @@ ENTRY(secondary_startup_64)
14855 movl $MSR_EFER, %ecx
14856 rdmsr
14857 btsl $_EFER_SCE, %eax /* Enable System Call */
14858- btl $20,%edi /* No Execute supported? */
14859+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
14860 jnc 1f
14861 btsl $_EFER_NX, %eax
14862+ leaq init_level4_pgt(%rip), %rdi
14863+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
14864+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
14865+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
14866 1: wrmsr /* Make changes effective */
14867
14868 /* Setup cr0 */
14869@@ -262,16 +258,16 @@ ENTRY(secondary_startup_64)
14870 .quad x86_64_start_kernel
14871 ENTRY(initial_gs)
14872 .quad INIT_PER_CPU_VAR(irq_stack_union)
14873- __FINITDATA
14874
14875 ENTRY(stack_start)
14876 .quad init_thread_union+THREAD_SIZE-8
14877 .word 0
14878+ __FINITDATA
14879
14880 bad_address:
14881 jmp bad_address
14882
14883- .section ".init.text","ax"
14884+ __INIT
14885 #ifdef CONFIG_EARLY_PRINTK
14886 .globl early_idt_handlers
14887 early_idt_handlers:
14888@@ -316,18 +312,23 @@ ENTRY(early_idt_handler)
14889 #endif /* EARLY_PRINTK */
14890 1: hlt
14891 jmp 1b
14892+ .previous
14893
14894 #ifdef CONFIG_EARLY_PRINTK
14895+ __INITDATA
14896 early_recursion_flag:
14897 .long 0
14898+ .previous
14899
14900+ .section .rodata,"a",@progbits
14901 early_idt_msg:
14902 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
14903 early_idt_ripmsg:
14904 .asciz "RIP %s\n"
14905-#endif /* CONFIG_EARLY_PRINTK */
14906 .previous
14907+#endif /* CONFIG_EARLY_PRINTK */
14908
14909+ .section .rodata,"a",@progbits
14910 #define NEXT_PAGE(name) \
14911 .balign PAGE_SIZE; \
14912 ENTRY(name)
14913@@ -350,13 +351,36 @@ NEXT_PAGE(init_level4_pgt)
14914 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14915 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
14916 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14917+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
14918+ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
14919+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
14920+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
14921 .org init_level4_pgt + L4_START_KERNEL*8, 0
14922 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
14923 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
14924
14925+#ifdef CONFIG_PAX_PER_CPU_PGD
14926+NEXT_PAGE(cpu_pgd)
14927+ .rept NR_CPUS
14928+ .fill 512,8,0
14929+ .endr
14930+#endif
14931+
14932 NEXT_PAGE(level3_ident_pgt)
14933 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14934+#ifdef CONFIG_XEN
14935 .fill 511,8,0
14936+#else
14937+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
14938+ .fill 510,8,0
14939+#endif
14940+
14941+NEXT_PAGE(level3_vmalloc_pgt)
14942+ .fill 512,8,0
14943+
14944+NEXT_PAGE(level3_vmemmap_pgt)
14945+ .fill L3_VMEMMAP_START,8,0
14946+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
14947
14948 NEXT_PAGE(level3_kernel_pgt)
14949 .fill L3_START_KERNEL,8,0
14950@@ -364,20 +388,23 @@ NEXT_PAGE(level3_kernel_pgt)
14951 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
14952 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
14953
14954+NEXT_PAGE(level2_vmemmap_pgt)
14955+ .fill 512,8,0
14956+
14957 NEXT_PAGE(level2_fixmap_pgt)
14958- .fill 506,8,0
14959- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
14960- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
14961- .fill 5,8,0
14962+ .fill 507,8,0
14963+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
14964+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
14965+ .fill 4,8,0
14966
14967-NEXT_PAGE(level1_fixmap_pgt)
14968+NEXT_PAGE(level1_vsyscall_pgt)
14969 .fill 512,8,0
14970
14971-NEXT_PAGE(level2_ident_pgt)
14972- /* Since I easily can, map the first 1G.
14973+ /* Since I easily can, map the first 2G.
14974 * Don't set NX because code runs from these pages.
14975 */
14976- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
14977+NEXT_PAGE(level2_ident_pgt)
14978+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
14979
14980 NEXT_PAGE(level2_kernel_pgt)
14981 /*
14982@@ -390,33 +417,55 @@ NEXT_PAGE(level2_kernel_pgt)
14983 * If you want to increase this then increase MODULES_VADDR
14984 * too.)
14985 */
14986- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
14987- KERNEL_IMAGE_SIZE/PMD_SIZE)
14988-
14989-NEXT_PAGE(level2_spare_pgt)
14990- .fill 512, 8, 0
14991+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
14992
14993 #undef PMDS
14994 #undef NEXT_PAGE
14995
14996- .data
14997+ .align PAGE_SIZE
14998+ENTRY(cpu_gdt_table)
14999+ .rept NR_CPUS
15000+ .quad 0x0000000000000000 /* NULL descriptor */
15001+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15002+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
15003+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
15004+ .quad 0x00cffb000000ffff /* __USER32_CS */
15005+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15006+ .quad 0x00affb000000ffff /* __USER_CS */
15007+
15008+#ifdef CONFIG_PAX_KERNEXEC
15009+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15010+#else
15011+ .quad 0x0 /* unused */
15012+#endif
15013+
15014+ .quad 0,0 /* TSS */
15015+ .quad 0,0 /* LDT */
15016+ .quad 0,0,0 /* three TLS descriptors */
15017+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
15018+ /* asm/segment.h:GDT_ENTRIES must match this */
15019+
15020+ /* zero the remaining page */
15021+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15022+ .endr
15023+
15024 .align 16
15025 .globl early_gdt_descr
15026 early_gdt_descr:
15027 .word GDT_ENTRIES*8-1
15028 early_gdt_descr_base:
15029- .quad INIT_PER_CPU_VAR(gdt_page)
15030+ .quad cpu_gdt_table
15031
15032 ENTRY(phys_base)
15033 /* This must match the first entry in level2_kernel_pgt */
15034 .quad 0x0000000000000000
15035
15036 #include "../../x86/xen/xen-head.S"
15037-
15038- .section .bss, "aw", @nobits
15039+
15040+ .section .rodata,"a",@progbits
15041 .align L1_CACHE_BYTES
15042 ENTRY(idt_table)
15043- .skip IDT_ENTRIES * 16
15044+ .fill 512,8,0
15045
15046 __PAGE_ALIGNED_BSS
15047 .align PAGE_SIZE
15048diff -urNp linux-2.6.32.43/arch/x86/kernel/i386_ksyms_32.c linux-2.6.32.43/arch/x86/kernel/i386_ksyms_32.c
15049--- linux-2.6.32.43/arch/x86/kernel/i386_ksyms_32.c 2011-03-27 14:31:47.000000000 -0400
15050+++ linux-2.6.32.43/arch/x86/kernel/i386_ksyms_32.c 2011-04-17 15:56:46.000000000 -0400
15051@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15052 EXPORT_SYMBOL(cmpxchg8b_emu);
15053 #endif
15054
15055+EXPORT_SYMBOL_GPL(cpu_gdt_table);
15056+
15057 /* Networking helper routines. */
15058 EXPORT_SYMBOL(csum_partial_copy_generic);
15059+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15060+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15061
15062 EXPORT_SYMBOL(__get_user_1);
15063 EXPORT_SYMBOL(__get_user_2);
15064@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15065
15066 EXPORT_SYMBOL(csum_partial);
15067 EXPORT_SYMBOL(empty_zero_page);
15068+
15069+#ifdef CONFIG_PAX_KERNEXEC
15070+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15071+#endif
15072diff -urNp linux-2.6.32.43/arch/x86/kernel/i8259.c linux-2.6.32.43/arch/x86/kernel/i8259.c
15073--- linux-2.6.32.43/arch/x86/kernel/i8259.c 2011-03-27 14:31:47.000000000 -0400
15074+++ linux-2.6.32.43/arch/x86/kernel/i8259.c 2011-05-04 17:56:28.000000000 -0400
15075@@ -208,7 +208,7 @@ spurious_8259A_irq:
15076 "spurious 8259A interrupt: IRQ%d.\n", irq);
15077 spurious_irq_mask |= irqmask;
15078 }
15079- atomic_inc(&irq_err_count);
15080+ atomic_inc_unchecked(&irq_err_count);
15081 /*
15082 * Theoretically we do not have to handle this IRQ,
15083 * but in Linux this does not cause problems and is
15084diff -urNp linux-2.6.32.43/arch/x86/kernel/init_task.c linux-2.6.32.43/arch/x86/kernel/init_task.c
15085--- linux-2.6.32.43/arch/x86/kernel/init_task.c 2011-03-27 14:31:47.000000000 -0400
15086+++ linux-2.6.32.43/arch/x86/kernel/init_task.c 2011-04-17 15:56:46.000000000 -0400
15087@@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15088 * way process stacks are handled. This is done by having a special
15089 * "init_task" linker map entry..
15090 */
15091-union thread_union init_thread_union __init_task_data =
15092- { INIT_THREAD_INFO(init_task) };
15093+union thread_union init_thread_union __init_task_data;
15094
15095 /*
15096 * Initial task structure.
15097@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15098 * section. Since TSS's are completely CPU-local, we want them
15099 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15100 */
15101-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15102-
15103+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15104+EXPORT_SYMBOL(init_tss);
15105diff -urNp linux-2.6.32.43/arch/x86/kernel/ioport.c linux-2.6.32.43/arch/x86/kernel/ioport.c
15106--- linux-2.6.32.43/arch/x86/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
15107+++ linux-2.6.32.43/arch/x86/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
15108@@ -6,6 +6,7 @@
15109 #include <linux/sched.h>
15110 #include <linux/kernel.h>
15111 #include <linux/capability.h>
15112+#include <linux/security.h>
15113 #include <linux/errno.h>
15114 #include <linux/types.h>
15115 #include <linux/ioport.h>
15116@@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long
15117
15118 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15119 return -EINVAL;
15120+#ifdef CONFIG_GRKERNSEC_IO
15121+ if (turn_on && grsec_disable_privio) {
15122+ gr_handle_ioperm();
15123+ return -EPERM;
15124+ }
15125+#endif
15126 if (turn_on && !capable(CAP_SYS_RAWIO))
15127 return -EPERM;
15128
15129@@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
15130 * because the ->io_bitmap_max value must match the bitmap
15131 * contents:
15132 */
15133- tss = &per_cpu(init_tss, get_cpu());
15134+ tss = init_tss + get_cpu();
15135
15136 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
15137
15138@@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, s
15139 return -EINVAL;
15140 /* Trying to gain more privileges? */
15141 if (level > old) {
15142+#ifdef CONFIG_GRKERNSEC_IO
15143+ if (grsec_disable_privio) {
15144+ gr_handle_iopl();
15145+ return -EPERM;
15146+ }
15147+#endif
15148 if (!capable(CAP_SYS_RAWIO))
15149 return -EPERM;
15150 }
15151diff -urNp linux-2.6.32.43/arch/x86/kernel/irq_32.c linux-2.6.32.43/arch/x86/kernel/irq_32.c
15152--- linux-2.6.32.43/arch/x86/kernel/irq_32.c 2011-03-27 14:31:47.000000000 -0400
15153+++ linux-2.6.32.43/arch/x86/kernel/irq_32.c 2011-07-06 19:53:33.000000000 -0400
15154@@ -35,7 +35,7 @@ static int check_stack_overflow(void)
15155 __asm__ __volatile__("andl %%esp,%0" :
15156 "=r" (sp) : "0" (THREAD_SIZE - 1));
15157
15158- return sp < (sizeof(struct thread_info) + STACK_WARN);
15159+ return sp < STACK_WARN;
15160 }
15161
15162 static void print_stack_overflow(void)
15163@@ -54,9 +54,9 @@ static inline void print_stack_overflow(
15164 * per-CPU IRQ handling contexts (thread information and stack)
15165 */
15166 union irq_ctx {
15167- struct thread_info tinfo;
15168- u32 stack[THREAD_SIZE/sizeof(u32)];
15169-} __attribute__((aligned(PAGE_SIZE)));
15170+ unsigned long previous_esp;
15171+ u32 stack[THREAD_SIZE/sizeof(u32)];
15172+} __attribute__((aligned(THREAD_SIZE)));
15173
15174 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15175 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
15176@@ -78,10 +78,9 @@ static void call_on_stack(void *func, vo
15177 static inline int
15178 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15179 {
15180- union irq_ctx *curctx, *irqctx;
15181+ union irq_ctx *irqctx;
15182 u32 *isp, arg1, arg2;
15183
15184- curctx = (union irq_ctx *) current_thread_info();
15185 irqctx = __get_cpu_var(hardirq_ctx);
15186
15187 /*
15188@@ -90,21 +89,16 @@ execute_on_irq_stack(int overflow, struc
15189 * handler) we can't do that and just have to keep using the
15190 * current stack (which is the irq stack already after all)
15191 */
15192- if (unlikely(curctx == irqctx))
15193+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15194 return 0;
15195
15196 /* build the stack frame on the IRQ stack */
15197- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15198- irqctx->tinfo.task = curctx->tinfo.task;
15199- irqctx->tinfo.previous_esp = current_stack_pointer;
15200+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15201+ irqctx->previous_esp = current_stack_pointer;
15202
15203- /*
15204- * Copy the softirq bits in preempt_count so that the
15205- * softirq checks work in the hardirq context.
15206- */
15207- irqctx->tinfo.preempt_count =
15208- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15209- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15210+#ifdef CONFIG_PAX_MEMORY_UDEREF
15211+ __set_fs(MAKE_MM_SEG(0));
15212+#endif
15213
15214 if (unlikely(overflow))
15215 call_on_stack(print_stack_overflow, isp);
15216@@ -116,6 +110,11 @@ execute_on_irq_stack(int overflow, struc
15217 : "0" (irq), "1" (desc), "2" (isp),
15218 "D" (desc->handle_irq)
15219 : "memory", "cc", "ecx");
15220+
15221+#ifdef CONFIG_PAX_MEMORY_UDEREF
15222+ __set_fs(current_thread_info()->addr_limit);
15223+#endif
15224+
15225 return 1;
15226 }
15227
15228@@ -124,28 +123,11 @@ execute_on_irq_stack(int overflow, struc
15229 */
15230 void __cpuinit irq_ctx_init(int cpu)
15231 {
15232- union irq_ctx *irqctx;
15233-
15234 if (per_cpu(hardirq_ctx, cpu))
15235 return;
15236
15237- irqctx = &per_cpu(hardirq_stack, cpu);
15238- irqctx->tinfo.task = NULL;
15239- irqctx->tinfo.exec_domain = NULL;
15240- irqctx->tinfo.cpu = cpu;
15241- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15242- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15243-
15244- per_cpu(hardirq_ctx, cpu) = irqctx;
15245-
15246- irqctx = &per_cpu(softirq_stack, cpu);
15247- irqctx->tinfo.task = NULL;
15248- irqctx->tinfo.exec_domain = NULL;
15249- irqctx->tinfo.cpu = cpu;
15250- irqctx->tinfo.preempt_count = 0;
15251- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15252-
15253- per_cpu(softirq_ctx, cpu) = irqctx;
15254+ per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
15255+ per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
15256
15257 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15258 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15259@@ -159,7 +141,6 @@ void irq_ctx_exit(int cpu)
15260 asmlinkage void do_softirq(void)
15261 {
15262 unsigned long flags;
15263- struct thread_info *curctx;
15264 union irq_ctx *irqctx;
15265 u32 *isp;
15266
15267@@ -169,15 +150,22 @@ asmlinkage void do_softirq(void)
15268 local_irq_save(flags);
15269
15270 if (local_softirq_pending()) {
15271- curctx = current_thread_info();
15272 irqctx = __get_cpu_var(softirq_ctx);
15273- irqctx->tinfo.task = curctx->task;
15274- irqctx->tinfo.previous_esp = current_stack_pointer;
15275+ irqctx->previous_esp = current_stack_pointer;
15276
15277 /* build the stack frame on the softirq stack */
15278- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15279+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15280+
15281+#ifdef CONFIG_PAX_MEMORY_UDEREF
15282+ __set_fs(MAKE_MM_SEG(0));
15283+#endif
15284
15285 call_on_stack(__do_softirq, isp);
15286+
15287+#ifdef CONFIG_PAX_MEMORY_UDEREF
15288+ __set_fs(current_thread_info()->addr_limit);
15289+#endif
15290+
15291 /*
15292 * Shouldnt happen, we returned above if in_interrupt():
15293 */
15294diff -urNp linux-2.6.32.43/arch/x86/kernel/irq.c linux-2.6.32.43/arch/x86/kernel/irq.c
15295--- linux-2.6.32.43/arch/x86/kernel/irq.c 2011-03-27 14:31:47.000000000 -0400
15296+++ linux-2.6.32.43/arch/x86/kernel/irq.c 2011-05-04 17:56:28.000000000 -0400
15297@@ -15,7 +15,7 @@
15298 #include <asm/mce.h>
15299 #include <asm/hw_irq.h>
15300
15301-atomic_t irq_err_count;
15302+atomic_unchecked_t irq_err_count;
15303
15304 /* Function pointer for generic interrupt vector handling */
15305 void (*generic_interrupt_extension)(void) = NULL;
15306@@ -114,9 +114,9 @@ static int show_other_interrupts(struct
15307 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15308 seq_printf(p, " Machine check polls\n");
15309 #endif
15310- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15311+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15312 #if defined(CONFIG_X86_IO_APIC)
15313- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15314+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15315 #endif
15316 return 0;
15317 }
15318@@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15319
15320 u64 arch_irq_stat(void)
15321 {
15322- u64 sum = atomic_read(&irq_err_count);
15323+ u64 sum = atomic_read_unchecked(&irq_err_count);
15324
15325 #ifdef CONFIG_X86_IO_APIC
15326- sum += atomic_read(&irq_mis_count);
15327+ sum += atomic_read_unchecked(&irq_mis_count);
15328 #endif
15329 return sum;
15330 }
15331diff -urNp linux-2.6.32.43/arch/x86/kernel/kgdb.c linux-2.6.32.43/arch/x86/kernel/kgdb.c
15332--- linux-2.6.32.43/arch/x86/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
15333+++ linux-2.6.32.43/arch/x86/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
15334@@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vec
15335
15336 /* clear the trace bit */
15337 linux_regs->flags &= ~X86_EFLAGS_TF;
15338- atomic_set(&kgdb_cpu_doing_single_step, -1);
15339+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15340
15341 /* set the trace bit if we're stepping */
15342 if (remcomInBuffer[0] == 's') {
15343 linux_regs->flags |= X86_EFLAGS_TF;
15344 kgdb_single_step = 1;
15345- atomic_set(&kgdb_cpu_doing_single_step,
15346+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15347 raw_smp_processor_id());
15348 }
15349
15350@@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args
15351 break;
15352
15353 case DIE_DEBUG:
15354- if (atomic_read(&kgdb_cpu_doing_single_step) ==
15355+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
15356 raw_smp_processor_id()) {
15357 if (user_mode(regs))
15358 return single_step_cont(regs, args);
15359@@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception
15360 return instruction_pointer(regs);
15361 }
15362
15363-struct kgdb_arch arch_kgdb_ops = {
15364+const struct kgdb_arch arch_kgdb_ops = {
15365 /* Breakpoint instruction: */
15366 .gdb_bpt_instr = { 0xcc },
15367 .flags = KGDB_HW_BREAKPOINT,
15368diff -urNp linux-2.6.32.43/arch/x86/kernel/kprobes.c linux-2.6.32.43/arch/x86/kernel/kprobes.c
15369--- linux-2.6.32.43/arch/x86/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
15370+++ linux-2.6.32.43/arch/x86/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
15371@@ -166,9 +166,13 @@ static void __kprobes set_jmp_op(void *f
15372 char op;
15373 s32 raddr;
15374 } __attribute__((packed)) * jop;
15375- jop = (struct __arch_jmp_op *)from;
15376+
15377+ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
15378+
15379+ pax_open_kernel();
15380 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
15381 jop->op = RELATIVEJUMP_INSTRUCTION;
15382+ pax_close_kernel();
15383 }
15384
15385 /*
15386@@ -193,7 +197,7 @@ static int __kprobes can_boost(kprobe_op
15387 kprobe_opcode_t opcode;
15388 kprobe_opcode_t *orig_opcodes = opcodes;
15389
15390- if (search_exception_tables((unsigned long)opcodes))
15391+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15392 return 0; /* Page fault may occur on this address. */
15393
15394 retry:
15395@@ -337,7 +341,9 @@ static void __kprobes fix_riprel(struct
15396 disp = (u8 *) p->addr + *((s32 *) insn) -
15397 (u8 *) p->ainsn.insn;
15398 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
15399+ pax_open_kernel();
15400 *(s32 *)insn = (s32) disp;
15401+ pax_close_kernel();
15402 }
15403 }
15404 #endif
15405@@ -345,16 +351,18 @@ static void __kprobes fix_riprel(struct
15406
15407 static void __kprobes arch_copy_kprobe(struct kprobe *p)
15408 {
15409- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
15410+ pax_open_kernel();
15411+ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
15412+ pax_close_kernel();
15413
15414 fix_riprel(p);
15415
15416- if (can_boost(p->addr))
15417+ if (can_boost(ktla_ktva(p->addr)))
15418 p->ainsn.boostable = 0;
15419 else
15420 p->ainsn.boostable = -1;
15421
15422- p->opcode = *p->addr;
15423+ p->opcode = *(ktla_ktva(p->addr));
15424 }
15425
15426 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15427@@ -432,7 +440,7 @@ static void __kprobes prepare_singlestep
15428 if (p->opcode == BREAKPOINT_INSTRUCTION)
15429 regs->ip = (unsigned long)p->addr;
15430 else
15431- regs->ip = (unsigned long)p->ainsn.insn;
15432+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15433 }
15434
15435 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
15436@@ -453,7 +461,7 @@ static void __kprobes setup_singlestep(s
15437 if (p->ainsn.boostable == 1 && !p->post_handler) {
15438 /* Boost up -- we can execute copied instructions directly */
15439 reset_current_kprobe();
15440- regs->ip = (unsigned long)p->ainsn.insn;
15441+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15442 preempt_enable_no_resched();
15443 return;
15444 }
15445@@ -523,7 +531,7 @@ static int __kprobes kprobe_handler(stru
15446 struct kprobe_ctlblk *kcb;
15447
15448 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
15449- if (*addr != BREAKPOINT_INSTRUCTION) {
15450+ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15451 /*
15452 * The breakpoint instruction was removed right
15453 * after we hit it. Another cpu has removed
15454@@ -775,7 +783,7 @@ static void __kprobes resume_execution(s
15455 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15456 {
15457 unsigned long *tos = stack_addr(regs);
15458- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15459+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15460 unsigned long orig_ip = (unsigned long)p->addr;
15461 kprobe_opcode_t *insn = p->ainsn.insn;
15462
15463@@ -958,7 +966,7 @@ int __kprobes kprobe_exceptions_notify(s
15464 struct die_args *args = data;
15465 int ret = NOTIFY_DONE;
15466
15467- if (args->regs && user_mode_vm(args->regs))
15468+ if (args->regs && user_mode(args->regs))
15469 return ret;
15470
15471 switch (val) {
15472diff -urNp linux-2.6.32.43/arch/x86/kernel/ldt.c linux-2.6.32.43/arch/x86/kernel/ldt.c
15473--- linux-2.6.32.43/arch/x86/kernel/ldt.c 2011-03-27 14:31:47.000000000 -0400
15474+++ linux-2.6.32.43/arch/x86/kernel/ldt.c 2011-04-17 15:56:46.000000000 -0400
15475@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, i
15476 if (reload) {
15477 #ifdef CONFIG_SMP
15478 preempt_disable();
15479- load_LDT(pc);
15480+ load_LDT_nolock(pc);
15481 if (!cpumask_equal(mm_cpumask(current->mm),
15482 cpumask_of(smp_processor_id())))
15483 smp_call_function(flush_ldt, current->mm, 1);
15484 preempt_enable();
15485 #else
15486- load_LDT(pc);
15487+ load_LDT_nolock(pc);
15488 #endif
15489 }
15490 if (oldsize) {
15491@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t
15492 return err;
15493
15494 for (i = 0; i < old->size; i++)
15495- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
15496+ write_ldt_entry(new->ldt, i, old->ldt + i);
15497 return 0;
15498 }
15499
15500@@ -115,6 +115,24 @@ int init_new_context(struct task_struct
15501 retval = copy_ldt(&mm->context, &old_mm->context);
15502 mutex_unlock(&old_mm->context.lock);
15503 }
15504+
15505+ if (tsk == current) {
15506+ mm->context.vdso = 0;
15507+
15508+#ifdef CONFIG_X86_32
15509+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15510+ mm->context.user_cs_base = 0UL;
15511+ mm->context.user_cs_limit = ~0UL;
15512+
15513+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15514+ cpus_clear(mm->context.cpu_user_cs_mask);
15515+#endif
15516+
15517+#endif
15518+#endif
15519+
15520+ }
15521+
15522 return retval;
15523 }
15524
15525@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, u
15526 }
15527 }
15528
15529+#ifdef CONFIG_PAX_SEGMEXEC
15530+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
15531+ error = -EINVAL;
15532+ goto out_unlock;
15533+ }
15534+#endif
15535+
15536 fill_ldt(&ldt, &ldt_info);
15537 if (oldmode)
15538 ldt.avl = 0;
15539diff -urNp linux-2.6.32.43/arch/x86/kernel/machine_kexec_32.c linux-2.6.32.43/arch/x86/kernel/machine_kexec_32.c
15540--- linux-2.6.32.43/arch/x86/kernel/machine_kexec_32.c 2011-03-27 14:31:47.000000000 -0400
15541+++ linux-2.6.32.43/arch/x86/kernel/machine_kexec_32.c 2011-04-17 15:56:46.000000000 -0400
15542@@ -26,7 +26,7 @@
15543 #include <asm/system.h>
15544 #include <asm/cacheflush.h>
15545
15546-static void set_idt(void *newidt, __u16 limit)
15547+static void set_idt(struct desc_struct *newidt, __u16 limit)
15548 {
15549 struct desc_ptr curidt;
15550
15551@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16
15552 }
15553
15554
15555-static void set_gdt(void *newgdt, __u16 limit)
15556+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
15557 {
15558 struct desc_ptr curgdt;
15559
15560@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
15561 }
15562
15563 control_page = page_address(image->control_code_page);
15564- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
15565+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
15566
15567 relocate_kernel_ptr = control_page;
15568 page_list[PA_CONTROL_PAGE] = __pa(control_page);
15569diff -urNp linux-2.6.32.43/arch/x86/kernel/microcode_amd.c linux-2.6.32.43/arch/x86/kernel/microcode_amd.c
15570--- linux-2.6.32.43/arch/x86/kernel/microcode_amd.c 2011-04-17 17:00:52.000000000 -0400
15571+++ linux-2.6.32.43/arch/x86/kernel/microcode_amd.c 2011-04-17 17:03:05.000000000 -0400
15572@@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int c
15573 uci->mc = NULL;
15574 }
15575
15576-static struct microcode_ops microcode_amd_ops = {
15577+static const struct microcode_ops microcode_amd_ops = {
15578 .request_microcode_user = request_microcode_user,
15579 .request_microcode_fw = request_microcode_fw,
15580 .collect_cpu_info = collect_cpu_info_amd,
15581@@ -372,7 +372,7 @@ static struct microcode_ops microcode_am
15582 .microcode_fini_cpu = microcode_fini_cpu_amd,
15583 };
15584
15585-struct microcode_ops * __init init_amd_microcode(void)
15586+const struct microcode_ops * __init init_amd_microcode(void)
15587 {
15588 return &microcode_amd_ops;
15589 }
15590diff -urNp linux-2.6.32.43/arch/x86/kernel/microcode_core.c linux-2.6.32.43/arch/x86/kernel/microcode_core.c
15591--- linux-2.6.32.43/arch/x86/kernel/microcode_core.c 2011-03-27 14:31:47.000000000 -0400
15592+++ linux-2.6.32.43/arch/x86/kernel/microcode_core.c 2011-04-17 15:56:46.000000000 -0400
15593@@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
15594
15595 #define MICROCODE_VERSION "2.00"
15596
15597-static struct microcode_ops *microcode_ops;
15598+static const struct microcode_ops *microcode_ops;
15599
15600 /*
15601 * Synchronization.
15602diff -urNp linux-2.6.32.43/arch/x86/kernel/microcode_intel.c linux-2.6.32.43/arch/x86/kernel/microcode_intel.c
15603--- linux-2.6.32.43/arch/x86/kernel/microcode_intel.c 2011-03-27 14:31:47.000000000 -0400
15604+++ linux-2.6.32.43/arch/x86/kernel/microcode_intel.c 2011-04-17 15:56:46.000000000 -0400
15605@@ -443,13 +443,13 @@ static enum ucode_state request_microcod
15606
15607 static int get_ucode_user(void *to, const void *from, size_t n)
15608 {
15609- return copy_from_user(to, from, n);
15610+ return copy_from_user(to, (__force const void __user *)from, n);
15611 }
15612
15613 static enum ucode_state
15614 request_microcode_user(int cpu, const void __user *buf, size_t size)
15615 {
15616- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
15617+ return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
15618 }
15619
15620 static void microcode_fini_cpu(int cpu)
15621@@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
15622 uci->mc = NULL;
15623 }
15624
15625-static struct microcode_ops microcode_intel_ops = {
15626+static const struct microcode_ops microcode_intel_ops = {
15627 .request_microcode_user = request_microcode_user,
15628 .request_microcode_fw = request_microcode_fw,
15629 .collect_cpu_info = collect_cpu_info,
15630@@ -468,7 +468,7 @@ static struct microcode_ops microcode_in
15631 .microcode_fini_cpu = microcode_fini_cpu,
15632 };
15633
15634-struct microcode_ops * __init init_intel_microcode(void)
15635+const struct microcode_ops * __init init_intel_microcode(void)
15636 {
15637 return &microcode_intel_ops;
15638 }
15639diff -urNp linux-2.6.32.43/arch/x86/kernel/module.c linux-2.6.32.43/arch/x86/kernel/module.c
15640--- linux-2.6.32.43/arch/x86/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
15641+++ linux-2.6.32.43/arch/x86/kernel/module.c 2011-04-17 15:56:46.000000000 -0400
15642@@ -34,7 +34,7 @@
15643 #define DEBUGP(fmt...)
15644 #endif
15645
15646-void *module_alloc(unsigned long size)
15647+static void *__module_alloc(unsigned long size, pgprot_t prot)
15648 {
15649 struct vm_struct *area;
15650
15651@@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
15652 if (!area)
15653 return NULL;
15654
15655- return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
15656- PAGE_KERNEL_EXEC);
15657+ return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
15658+}
15659+
15660+void *module_alloc(unsigned long size)
15661+{
15662+
15663+#ifdef CONFIG_PAX_KERNEXEC
15664+ return __module_alloc(size, PAGE_KERNEL);
15665+#else
15666+ return __module_alloc(size, PAGE_KERNEL_EXEC);
15667+#endif
15668+
15669 }
15670
15671 /* Free memory returned from module_alloc */
15672@@ -58,6 +68,40 @@ void module_free(struct module *mod, voi
15673 vfree(module_region);
15674 }
15675
15676+#ifdef CONFIG_PAX_KERNEXEC
15677+#ifdef CONFIG_X86_32
15678+void *module_alloc_exec(unsigned long size)
15679+{
15680+ struct vm_struct *area;
15681+
15682+ if (size == 0)
15683+ return NULL;
15684+
15685+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
15686+ return area ? area->addr : NULL;
15687+}
15688+EXPORT_SYMBOL(module_alloc_exec);
15689+
15690+void module_free_exec(struct module *mod, void *module_region)
15691+{
15692+ vunmap(module_region);
15693+}
15694+EXPORT_SYMBOL(module_free_exec);
15695+#else
15696+void module_free_exec(struct module *mod, void *module_region)
15697+{
15698+ module_free(mod, module_region);
15699+}
15700+EXPORT_SYMBOL(module_free_exec);
15701+
15702+void *module_alloc_exec(unsigned long size)
15703+{
15704+ return __module_alloc(size, PAGE_KERNEL_RX);
15705+}
15706+EXPORT_SYMBOL(module_alloc_exec);
15707+#endif
15708+#endif
15709+
15710 /* We don't need anything special. */
15711 int module_frob_arch_sections(Elf_Ehdr *hdr,
15712 Elf_Shdr *sechdrs,
15713@@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15714 unsigned int i;
15715 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
15716 Elf32_Sym *sym;
15717- uint32_t *location;
15718+ uint32_t *plocation, location;
15719
15720 DEBUGP("Applying relocate section %u to %u\n", relsec,
15721 sechdrs[relsec].sh_info);
15722 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
15723 /* This is where to make the change */
15724- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
15725- + rel[i].r_offset;
15726+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
15727+ location = (uint32_t)plocation;
15728+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
15729+ plocation = ktla_ktva((void *)plocation);
15730 /* This is the symbol it is referring to. Note that all
15731 undefined symbols have been resolved. */
15732 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
15733@@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15734 switch (ELF32_R_TYPE(rel[i].r_info)) {
15735 case R_386_32:
15736 /* We add the value into the location given */
15737- *location += sym->st_value;
15738+ pax_open_kernel();
15739+ *plocation += sym->st_value;
15740+ pax_close_kernel();
15741 break;
15742 case R_386_PC32:
15743 /* Add the value, subtract its postition */
15744- *location += sym->st_value - (uint32_t)location;
15745+ pax_open_kernel();
15746+ *plocation += sym->st_value - location;
15747+ pax_close_kernel();
15748 break;
15749 default:
15750 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
15751@@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
15752 case R_X86_64_NONE:
15753 break;
15754 case R_X86_64_64:
15755+ pax_open_kernel();
15756 *(u64 *)loc = val;
15757+ pax_close_kernel();
15758 break;
15759 case R_X86_64_32:
15760+ pax_open_kernel();
15761 *(u32 *)loc = val;
15762+ pax_close_kernel();
15763 if (val != *(u32 *)loc)
15764 goto overflow;
15765 break;
15766 case R_X86_64_32S:
15767+ pax_open_kernel();
15768 *(s32 *)loc = val;
15769+ pax_close_kernel();
15770 if ((s64)val != *(s32 *)loc)
15771 goto overflow;
15772 break;
15773 case R_X86_64_PC32:
15774 val -= (u64)loc;
15775+ pax_open_kernel();
15776 *(u32 *)loc = val;
15777+ pax_close_kernel();
15778+
15779 #if 0
15780 if ((s64)val != *(s32 *)loc)
15781 goto overflow;
15782diff -urNp linux-2.6.32.43/arch/x86/kernel/paravirt.c linux-2.6.32.43/arch/x86/kernel/paravirt.c
15783--- linux-2.6.32.43/arch/x86/kernel/paravirt.c 2011-03-27 14:31:47.000000000 -0400
15784+++ linux-2.6.32.43/arch/x86/kernel/paravirt.c 2011-08-05 20:33:55.000000000 -0400
15785@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
15786 {
15787 return x;
15788 }
15789+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
15790+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
15791+#endif
15792
15793 void __init default_banner(void)
15794 {
15795@@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbu
15796 * corresponding structure. */
15797 static void *get_call_destination(u8 type)
15798 {
15799- struct paravirt_patch_template tmpl = {
15800+ const struct paravirt_patch_template tmpl = {
15801 .pv_init_ops = pv_init_ops,
15802 .pv_time_ops = pv_time_ops,
15803 .pv_cpu_ops = pv_cpu_ops,
15804@@ -133,6 +136,8 @@ static void *get_call_destination(u8 typ
15805 .pv_lock_ops = pv_lock_ops,
15806 #endif
15807 };
15808+
15809+ pax_track_stack();
15810 return *((void **)&tmpl + type);
15811 }
15812
15813@@ -145,15 +150,19 @@ unsigned paravirt_patch_default(u8 type,
15814 if (opfunc == NULL)
15815 /* If there's no function, patch it with a ud2a (BUG) */
15816 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
15817- else if (opfunc == _paravirt_nop)
15818+ else if (opfunc == (void *)_paravirt_nop)
15819 /* If the operation is a nop, then nop the callsite */
15820 ret = paravirt_patch_nop();
15821
15822 /* identity functions just return their single argument */
15823- else if (opfunc == _paravirt_ident_32)
15824+ else if (opfunc == (void *)_paravirt_ident_32)
15825 ret = paravirt_patch_ident_32(insnbuf, len);
15826- else if (opfunc == _paravirt_ident_64)
15827+ else if (opfunc == (void *)_paravirt_ident_64)
15828+ ret = paravirt_patch_ident_64(insnbuf, len);
15829+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
15830+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
15831 ret = paravirt_patch_ident_64(insnbuf, len);
15832+#endif
15833
15834 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
15835 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
15836@@ -178,7 +187,7 @@ unsigned paravirt_patch_insns(void *insn
15837 if (insn_len > len || start == NULL)
15838 insn_len = len;
15839 else
15840- memcpy(insnbuf, start, insn_len);
15841+ memcpy(insnbuf, ktla_ktva(start), insn_len);
15842
15843 return insn_len;
15844 }
15845@@ -294,22 +303,22 @@ void arch_flush_lazy_mmu_mode(void)
15846 preempt_enable();
15847 }
15848
15849-struct pv_info pv_info = {
15850+struct pv_info pv_info __read_only = {
15851 .name = "bare hardware",
15852 .paravirt_enabled = 0,
15853 .kernel_rpl = 0,
15854 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
15855 };
15856
15857-struct pv_init_ops pv_init_ops = {
15858+struct pv_init_ops pv_init_ops __read_only = {
15859 .patch = native_patch,
15860 };
15861
15862-struct pv_time_ops pv_time_ops = {
15863+struct pv_time_ops pv_time_ops __read_only = {
15864 .sched_clock = native_sched_clock,
15865 };
15866
15867-struct pv_irq_ops pv_irq_ops = {
15868+struct pv_irq_ops pv_irq_ops __read_only = {
15869 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
15870 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
15871 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
15872@@ -321,7 +330,7 @@ struct pv_irq_ops pv_irq_ops = {
15873 #endif
15874 };
15875
15876-struct pv_cpu_ops pv_cpu_ops = {
15877+struct pv_cpu_ops pv_cpu_ops __read_only = {
15878 .cpuid = native_cpuid,
15879 .get_debugreg = native_get_debugreg,
15880 .set_debugreg = native_set_debugreg,
15881@@ -382,21 +391,26 @@ struct pv_cpu_ops pv_cpu_ops = {
15882 .end_context_switch = paravirt_nop,
15883 };
15884
15885-struct pv_apic_ops pv_apic_ops = {
15886+struct pv_apic_ops pv_apic_ops __read_only = {
15887 #ifdef CONFIG_X86_LOCAL_APIC
15888 .startup_ipi_hook = paravirt_nop,
15889 #endif
15890 };
15891
15892-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
15893+#ifdef CONFIG_X86_32
15894+#ifdef CONFIG_X86_PAE
15895+/* 64-bit pagetable entries */
15896+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
15897+#else
15898 /* 32-bit pagetable entries */
15899 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
15900+#endif
15901 #else
15902 /* 64-bit pagetable entries */
15903 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
15904 #endif
15905
15906-struct pv_mmu_ops pv_mmu_ops = {
15907+struct pv_mmu_ops pv_mmu_ops __read_only = {
15908
15909 .read_cr2 = native_read_cr2,
15910 .write_cr2 = native_write_cr2,
15911@@ -467,6 +481,12 @@ struct pv_mmu_ops pv_mmu_ops = {
15912 },
15913
15914 .set_fixmap = native_set_fixmap,
15915+
15916+#ifdef CONFIG_PAX_KERNEXEC
15917+ .pax_open_kernel = native_pax_open_kernel,
15918+ .pax_close_kernel = native_pax_close_kernel,
15919+#endif
15920+
15921 };
15922
15923 EXPORT_SYMBOL_GPL(pv_time_ops);
15924diff -urNp linux-2.6.32.43/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.32.43/arch/x86/kernel/paravirt-spinlocks.c
15925--- linux-2.6.32.43/arch/x86/kernel/paravirt-spinlocks.c 2011-03-27 14:31:47.000000000 -0400
15926+++ linux-2.6.32.43/arch/x86/kernel/paravirt-spinlocks.c 2011-04-17 15:56:46.000000000 -0400
15927@@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *
15928 __raw_spin_lock(lock);
15929 }
15930
15931-struct pv_lock_ops pv_lock_ops = {
15932+struct pv_lock_ops pv_lock_ops __read_only = {
15933 #ifdef CONFIG_SMP
15934 .spin_is_locked = __ticket_spin_is_locked,
15935 .spin_is_contended = __ticket_spin_is_contended,
15936diff -urNp linux-2.6.32.43/arch/x86/kernel/pci-calgary_64.c linux-2.6.32.43/arch/x86/kernel/pci-calgary_64.c
15937--- linux-2.6.32.43/arch/x86/kernel/pci-calgary_64.c 2011-03-27 14:31:47.000000000 -0400
15938+++ linux-2.6.32.43/arch/x86/kernel/pci-calgary_64.c 2011-04-17 15:56:46.000000000 -0400
15939@@ -477,7 +477,7 @@ static void calgary_free_coherent(struct
15940 free_pages((unsigned long)vaddr, get_order(size));
15941 }
15942
15943-static struct dma_map_ops calgary_dma_ops = {
15944+static const struct dma_map_ops calgary_dma_ops = {
15945 .alloc_coherent = calgary_alloc_coherent,
15946 .free_coherent = calgary_free_coherent,
15947 .map_sg = calgary_map_sg,
15948diff -urNp linux-2.6.32.43/arch/x86/kernel/pci-dma.c linux-2.6.32.43/arch/x86/kernel/pci-dma.c
15949--- linux-2.6.32.43/arch/x86/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
15950+++ linux-2.6.32.43/arch/x86/kernel/pci-dma.c 2011-04-17 15:56:46.000000000 -0400
15951@@ -14,7 +14,7 @@
15952
15953 static int forbid_dac __read_mostly;
15954
15955-struct dma_map_ops *dma_ops;
15956+const struct dma_map_ops *dma_ops;
15957 EXPORT_SYMBOL(dma_ops);
15958
15959 static int iommu_sac_force __read_mostly;
15960@@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
15961
15962 int dma_supported(struct device *dev, u64 mask)
15963 {
15964- struct dma_map_ops *ops = get_dma_ops(dev);
15965+ const struct dma_map_ops *ops = get_dma_ops(dev);
15966
15967 #ifdef CONFIG_PCI
15968 if (mask > 0xffffffff && forbid_dac > 0) {
15969diff -urNp linux-2.6.32.43/arch/x86/kernel/pci-gart_64.c linux-2.6.32.43/arch/x86/kernel/pci-gart_64.c
15970--- linux-2.6.32.43/arch/x86/kernel/pci-gart_64.c 2011-03-27 14:31:47.000000000 -0400
15971+++ linux-2.6.32.43/arch/x86/kernel/pci-gart_64.c 2011-04-17 15:56:46.000000000 -0400
15972@@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct ag
15973 return -1;
15974 }
15975
15976-static struct dma_map_ops gart_dma_ops = {
15977+static const struct dma_map_ops gart_dma_ops = {
15978 .map_sg = gart_map_sg,
15979 .unmap_sg = gart_unmap_sg,
15980 .map_page = gart_map_page,
15981diff -urNp linux-2.6.32.43/arch/x86/kernel/pci-nommu.c linux-2.6.32.43/arch/x86/kernel/pci-nommu.c
15982--- linux-2.6.32.43/arch/x86/kernel/pci-nommu.c 2011-03-27 14:31:47.000000000 -0400
15983+++ linux-2.6.32.43/arch/x86/kernel/pci-nommu.c 2011-04-17 15:56:46.000000000 -0400
15984@@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(str
15985 flush_write_buffers();
15986 }
15987
15988-struct dma_map_ops nommu_dma_ops = {
15989+const struct dma_map_ops nommu_dma_ops = {
15990 .alloc_coherent = dma_generic_alloc_coherent,
15991 .free_coherent = nommu_free_coherent,
15992 .map_sg = nommu_map_sg,
15993diff -urNp linux-2.6.32.43/arch/x86/kernel/pci-swiotlb.c linux-2.6.32.43/arch/x86/kernel/pci-swiotlb.c
15994--- linux-2.6.32.43/arch/x86/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
15995+++ linux-2.6.32.43/arch/x86/kernel/pci-swiotlb.c 2011-04-17 15:56:46.000000000 -0400
15996@@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(
15997 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
15998 }
15999
16000-static struct dma_map_ops swiotlb_dma_ops = {
16001+static const struct dma_map_ops swiotlb_dma_ops = {
16002 .mapping_error = swiotlb_dma_mapping_error,
16003 .alloc_coherent = x86_swiotlb_alloc_coherent,
16004 .free_coherent = swiotlb_free_coherent,
16005diff -urNp linux-2.6.32.43/arch/x86/kernel/process_32.c linux-2.6.32.43/arch/x86/kernel/process_32.c
16006--- linux-2.6.32.43/arch/x86/kernel/process_32.c 2011-06-25 12:55:34.000000000 -0400
16007+++ linux-2.6.32.43/arch/x86/kernel/process_32.c 2011-06-25 12:56:37.000000000 -0400
16008@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __as
16009 unsigned long thread_saved_pc(struct task_struct *tsk)
16010 {
16011 return ((unsigned long *)tsk->thread.sp)[3];
16012+//XXX return tsk->thread.eip;
16013 }
16014
16015 #ifndef CONFIG_SMP
16016@@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, i
16017 unsigned short ss, gs;
16018 const char *board;
16019
16020- if (user_mode_vm(regs)) {
16021+ if (user_mode(regs)) {
16022 sp = regs->sp;
16023 ss = regs->ss & 0xffff;
16024- gs = get_user_gs(regs);
16025 } else {
16026 sp = (unsigned long) (&regs->sp);
16027 savesegment(ss, ss);
16028- savesegment(gs, gs);
16029 }
16030+ gs = get_user_gs(regs);
16031
16032 printk("\n");
16033
16034@@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), voi
16035 regs.bx = (unsigned long) fn;
16036 regs.dx = (unsigned long) arg;
16037
16038- regs.ds = __USER_DS;
16039- regs.es = __USER_DS;
16040+ regs.ds = __KERNEL_DS;
16041+ regs.es = __KERNEL_DS;
16042 regs.fs = __KERNEL_PERCPU;
16043- regs.gs = __KERNEL_STACK_CANARY;
16044+ savesegment(gs, regs.gs);
16045 regs.orig_ax = -1;
16046 regs.ip = (unsigned long) kernel_thread_helper;
16047 regs.cs = __KERNEL_CS | get_kernel_rpl();
16048@@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flag
16049 struct task_struct *tsk;
16050 int err;
16051
16052- childregs = task_pt_regs(p);
16053+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16054 *childregs = *regs;
16055 childregs->ax = 0;
16056 childregs->sp = sp;
16057
16058 p->thread.sp = (unsigned long) childregs;
16059 p->thread.sp0 = (unsigned long) (childregs+1);
16060+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16061
16062 p->thread.ip = (unsigned long) ret_from_fork;
16063
16064@@ -345,7 +346,7 @@ __switch_to(struct task_struct *prev_p,
16065 struct thread_struct *prev = &prev_p->thread,
16066 *next = &next_p->thread;
16067 int cpu = smp_processor_id();
16068- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16069+ struct tss_struct *tss = init_tss + cpu;
16070 bool preload_fpu;
16071
16072 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16073@@ -380,6 +381,10 @@ __switch_to(struct task_struct *prev_p,
16074 */
16075 lazy_save_gs(prev->gs);
16076
16077+#ifdef CONFIG_PAX_MEMORY_UDEREF
16078+ __set_fs(task_thread_info(next_p)->addr_limit);
16079+#endif
16080+
16081 /*
16082 * Load the per-thread Thread-Local Storage descriptor.
16083 */
16084@@ -415,6 +420,9 @@ __switch_to(struct task_struct *prev_p,
16085 */
16086 arch_end_context_switch(next_p);
16087
16088+ percpu_write(current_task, next_p);
16089+ percpu_write(current_tinfo, &next_p->tinfo);
16090+
16091 if (preload_fpu)
16092 __math_state_restore();
16093
16094@@ -424,8 +432,6 @@ __switch_to(struct task_struct *prev_p,
16095 if (prev->gs | next->gs)
16096 lazy_load_gs(next->gs);
16097
16098- percpu_write(current_task, next_p);
16099-
16100 return prev_p;
16101 }
16102
16103@@ -495,4 +501,3 @@ unsigned long get_wchan(struct task_stru
16104 } while (count++ < 16);
16105 return 0;
16106 }
16107-
16108diff -urNp linux-2.6.32.43/arch/x86/kernel/process_64.c linux-2.6.32.43/arch/x86/kernel/process_64.c
16109--- linux-2.6.32.43/arch/x86/kernel/process_64.c 2011-06-25 12:55:34.000000000 -0400
16110+++ linux-2.6.32.43/arch/x86/kernel/process_64.c 2011-06-25 12:56:37.000000000 -0400
16111@@ -91,7 +91,7 @@ static void __exit_idle(void)
16112 void exit_idle(void)
16113 {
16114 /* idle loop has pid 0 */
16115- if (current->pid)
16116+ if (task_pid_nr(current))
16117 return;
16118 __exit_idle();
16119 }
16120@@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, i
16121 if (!board)
16122 board = "";
16123 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
16124- current->pid, current->comm, print_tainted(),
16125+ task_pid_nr(current), current->comm, print_tainted(),
16126 init_utsname()->release,
16127 (int)strcspn(init_utsname()->version, " "),
16128 init_utsname()->version, board);
16129@@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flag
16130 struct pt_regs *childregs;
16131 struct task_struct *me = current;
16132
16133- childregs = ((struct pt_regs *)
16134- (THREAD_SIZE + task_stack_page(p))) - 1;
16135+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16136 *childregs = *regs;
16137
16138 childregs->ax = 0;
16139@@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flag
16140 p->thread.sp = (unsigned long) childregs;
16141 p->thread.sp0 = (unsigned long) (childregs+1);
16142 p->thread.usersp = me->thread.usersp;
16143+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16144
16145 set_tsk_thread_flag(p, TIF_FORK);
16146
16147@@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p,
16148 struct thread_struct *prev = &prev_p->thread;
16149 struct thread_struct *next = &next_p->thread;
16150 int cpu = smp_processor_id();
16151- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16152+ struct tss_struct *tss = init_tss + cpu;
16153 unsigned fsindex, gsindex;
16154 bool preload_fpu;
16155
16156@@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p,
16157 prev->usersp = percpu_read(old_rsp);
16158 percpu_write(old_rsp, next->usersp);
16159 percpu_write(current_task, next_p);
16160+ percpu_write(current_tinfo, &next_p->tinfo);
16161
16162- percpu_write(kernel_stack,
16163- (unsigned long)task_stack_page(next_p) +
16164- THREAD_SIZE - KERNEL_STACK_OFFSET);
16165+ percpu_write(kernel_stack, next->sp0);
16166
16167 /*
16168 * Now maybe reload the debug registers and handle I/O bitmaps
16169@@ -559,12 +558,11 @@ unsigned long get_wchan(struct task_stru
16170 if (!p || p == current || p->state == TASK_RUNNING)
16171 return 0;
16172 stack = (unsigned long)task_stack_page(p);
16173- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16174+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16175 return 0;
16176 fp = *(u64 *)(p->thread.sp);
16177 do {
16178- if (fp < (unsigned long)stack ||
16179- fp >= (unsigned long)stack+THREAD_SIZE)
16180+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16181 return 0;
16182 ip = *(u64 *)(fp+8);
16183 if (!in_sched_functions(ip))
16184diff -urNp linux-2.6.32.43/arch/x86/kernel/process.c linux-2.6.32.43/arch/x86/kernel/process.c
16185--- linux-2.6.32.43/arch/x86/kernel/process.c 2011-04-22 19:16:29.000000000 -0400
16186+++ linux-2.6.32.43/arch/x86/kernel/process.c 2011-05-22 23:02:03.000000000 -0400
16187@@ -51,16 +51,33 @@ void free_thread_xstate(struct task_stru
16188
16189 void free_thread_info(struct thread_info *ti)
16190 {
16191- free_thread_xstate(ti->task);
16192 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16193 }
16194
16195+static struct kmem_cache *task_struct_cachep;
16196+
16197 void arch_task_cache_init(void)
16198 {
16199- task_xstate_cachep =
16200- kmem_cache_create("task_xstate", xstate_size,
16201+ /* create a slab on which task_structs can be allocated */
16202+ task_struct_cachep =
16203+ kmem_cache_create("task_struct", sizeof(struct task_struct),
16204+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16205+
16206+ task_xstate_cachep =
16207+ kmem_cache_create("task_xstate", xstate_size,
16208 __alignof__(union thread_xstate),
16209- SLAB_PANIC | SLAB_NOTRACK, NULL);
16210+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16211+}
16212+
16213+struct task_struct *alloc_task_struct(void)
16214+{
16215+ return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
16216+}
16217+
16218+void free_task_struct(struct task_struct *task)
16219+{
16220+ free_thread_xstate(task);
16221+ kmem_cache_free(task_struct_cachep, task);
16222 }
16223
16224 /*
16225@@ -73,7 +90,7 @@ void exit_thread(void)
16226 unsigned long *bp = t->io_bitmap_ptr;
16227
16228 if (bp) {
16229- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16230+ struct tss_struct *tss = init_tss + get_cpu();
16231
16232 t->io_bitmap_ptr = NULL;
16233 clear_thread_flag(TIF_IO_BITMAP);
16234@@ -93,6 +110,9 @@ void flush_thread(void)
16235
16236 clear_tsk_thread_flag(tsk, TIF_DEBUG);
16237
16238+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16239+ loadsegment(gs, 0);
16240+#endif
16241 tsk->thread.debugreg0 = 0;
16242 tsk->thread.debugreg1 = 0;
16243 tsk->thread.debugreg2 = 0;
16244@@ -307,7 +327,7 @@ void default_idle(void)
16245 EXPORT_SYMBOL(default_idle);
16246 #endif
16247
16248-void stop_this_cpu(void *dummy)
16249+__noreturn void stop_this_cpu(void *dummy)
16250 {
16251 local_irq_disable();
16252 /*
16253@@ -568,16 +588,35 @@ static int __init idle_setup(char *str)
16254 }
16255 early_param("idle", idle_setup);
16256
16257-unsigned long arch_align_stack(unsigned long sp)
16258+#ifdef CONFIG_PAX_RANDKSTACK
16259+asmlinkage void pax_randomize_kstack(void)
16260 {
16261- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16262- sp -= get_random_int() % 8192;
16263- return sp & ~0xf;
16264-}
16265+ struct thread_struct *thread = &current->thread;
16266+ unsigned long time;
16267
16268-unsigned long arch_randomize_brk(struct mm_struct *mm)
16269-{
16270- unsigned long range_end = mm->brk + 0x02000000;
16271- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16272+ if (!randomize_va_space)
16273+ return;
16274+
16275+ rdtscl(time);
16276+
16277+ /* P4 seems to return a 0 LSB, ignore it */
16278+#ifdef CONFIG_MPENTIUM4
16279+ time &= 0x3EUL;
16280+ time <<= 2;
16281+#elif defined(CONFIG_X86_64)
16282+ time &= 0xFUL;
16283+ time <<= 4;
16284+#else
16285+ time &= 0x1FUL;
16286+ time <<= 3;
16287+#endif
16288+
16289+ thread->sp0 ^= time;
16290+ load_sp0(init_tss + smp_processor_id(), thread);
16291+
16292+#ifdef CONFIG_X86_64
16293+ percpu_write(kernel_stack, thread->sp0);
16294+#endif
16295 }
16296+#endif
16297
16298diff -urNp linux-2.6.32.43/arch/x86/kernel/ptrace.c linux-2.6.32.43/arch/x86/kernel/ptrace.c
16299--- linux-2.6.32.43/arch/x86/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
16300+++ linux-2.6.32.43/arch/x86/kernel/ptrace.c 2011-04-17 15:56:46.000000000 -0400
16301@@ -925,7 +925,7 @@ static const struct user_regset_view use
16302 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
16303 {
16304 int ret;
16305- unsigned long __user *datap = (unsigned long __user *)data;
16306+ unsigned long __user *datap = (__force unsigned long __user *)data;
16307
16308 switch (request) {
16309 /* read the word at location addr in the USER area. */
16310@@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *chi
16311 if (addr < 0)
16312 return -EIO;
16313 ret = do_get_thread_area(child, addr,
16314- (struct user_desc __user *) data);
16315+ (__force struct user_desc __user *) data);
16316 break;
16317
16318 case PTRACE_SET_THREAD_AREA:
16319 if (addr < 0)
16320 return -EIO;
16321 ret = do_set_thread_area(child, addr,
16322- (struct user_desc __user *) data, 0);
16323+ (__force struct user_desc __user *) data, 0);
16324 break;
16325 #endif
16326
16327@@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *chi
16328 #ifdef CONFIG_X86_PTRACE_BTS
16329 case PTRACE_BTS_CONFIG:
16330 ret = ptrace_bts_config
16331- (child, data, (struct ptrace_bts_config __user *)addr);
16332+ (child, data, (__force struct ptrace_bts_config __user *)addr);
16333 break;
16334
16335 case PTRACE_BTS_STATUS:
16336 ret = ptrace_bts_status
16337- (child, data, (struct ptrace_bts_config __user *)addr);
16338+ (child, data, (__force struct ptrace_bts_config __user *)addr);
16339 break;
16340
16341 case PTRACE_BTS_SIZE:
16342@@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *chi
16343
16344 case PTRACE_BTS_GET:
16345 ret = ptrace_bts_read_record
16346- (child, data, (struct bts_struct __user *) addr);
16347+ (child, data, (__force struct bts_struct __user *) addr);
16348 break;
16349
16350 case PTRACE_BTS_CLEAR:
16351@@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *chi
16352
16353 case PTRACE_BTS_DRAIN:
16354 ret = ptrace_bts_drain
16355- (child, data, (struct bts_struct __user *) addr);
16356+ (child, data, (__force struct bts_struct __user *) addr);
16357 break;
16358 #endif /* CONFIG_X86_PTRACE_BTS */
16359
16360@@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *ts
16361 info.si_code = si_code;
16362
16363 /* User-mode ip? */
16364- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
16365+ info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
16366
16367 /* Send us the fake SIGTRAP */
16368 force_sig_info(SIGTRAP, &info, tsk);
16369@@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *ts
16370 * We must return the syscall number to actually look up in the table.
16371 * This can be -1L to skip running any syscall at all.
16372 */
16373-asmregparm long syscall_trace_enter(struct pt_regs *regs)
16374+long syscall_trace_enter(struct pt_regs *regs)
16375 {
16376 long ret = 0;
16377
16378@@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(stru
16379 return ret ?: regs->orig_ax;
16380 }
16381
16382-asmregparm void syscall_trace_leave(struct pt_regs *regs)
16383+void syscall_trace_leave(struct pt_regs *regs)
16384 {
16385 if (unlikely(current->audit_context))
16386 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
16387diff -urNp linux-2.6.32.43/arch/x86/kernel/reboot.c linux-2.6.32.43/arch/x86/kernel/reboot.c
16388--- linux-2.6.32.43/arch/x86/kernel/reboot.c 2011-03-27 14:31:47.000000000 -0400
16389+++ linux-2.6.32.43/arch/x86/kernel/reboot.c 2011-05-22 23:02:03.000000000 -0400
16390@@ -33,7 +33,7 @@ void (*pm_power_off)(void);
16391 EXPORT_SYMBOL(pm_power_off);
16392
16393 static const struct desc_ptr no_idt = {};
16394-static int reboot_mode;
16395+static unsigned short reboot_mode;
16396 enum reboot_type reboot_type = BOOT_KBD;
16397 int reboot_force;
16398
16399@@ -292,12 +292,12 @@ core_initcall(reboot_init);
16400 controller to pulse the CPU reset line, which is more thorough, but
16401 doesn't work with at least one type of 486 motherboard. It is easy
16402 to stop this code working; hence the copious comments. */
16403-static const unsigned long long
16404-real_mode_gdt_entries [3] =
16405+static struct desc_struct
16406+real_mode_gdt_entries [3] __read_only =
16407 {
16408- 0x0000000000000000ULL, /* Null descriptor */
16409- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
16410- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
16411+ GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
16412+ GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
16413+ GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
16414 };
16415
16416 static const struct desc_ptr
16417@@ -346,7 +346,7 @@ static const unsigned char jump_to_bios
16418 * specified by the code and length parameters.
16419 * We assume that length will aways be less that 100!
16420 */
16421-void machine_real_restart(const unsigned char *code, int length)
16422+__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
16423 {
16424 local_irq_disable();
16425
16426@@ -366,8 +366,8 @@ void machine_real_restart(const unsigned
16427 /* Remap the kernel at virtual address zero, as well as offset zero
16428 from the kernel segment. This assumes the kernel segment starts at
16429 virtual address PAGE_OFFSET. */
16430- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16431- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
16432+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16433+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
16434
16435 /*
16436 * Use `swapper_pg_dir' as our page directory.
16437@@ -379,16 +379,15 @@ void machine_real_restart(const unsigned
16438 boot)". This seems like a fairly standard thing that gets set by
16439 REBOOT.COM programs, and the previous reset routine did this
16440 too. */
16441- *((unsigned short *)0x472) = reboot_mode;
16442+ *(unsigned short *)(__va(0x472)) = reboot_mode;
16443
16444 /* For the switch to real mode, copy some code to low memory. It has
16445 to be in the first 64k because it is running in 16-bit mode, and it
16446 has to have the same physical and virtual address, because it turns
16447 off paging. Copy it near the end of the first page, out of the way
16448 of BIOS variables. */
16449- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
16450- real_mode_switch, sizeof (real_mode_switch));
16451- memcpy((void *)(0x1000 - 100), code, length);
16452+ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
16453+ memcpy(__va(0x1000 - 100), code, length);
16454
16455 /* Set up the IDT for real mode. */
16456 load_idt(&real_mode_idt);
16457@@ -416,6 +415,7 @@ void machine_real_restart(const unsigned
16458 __asm__ __volatile__ ("ljmp $0x0008,%0"
16459 :
16460 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
16461+ do { } while (1);
16462 }
16463 #ifdef CONFIG_APM_MODULE
16464 EXPORT_SYMBOL(machine_real_restart);
16465@@ -536,7 +536,7 @@ void __attribute__((weak)) mach_reboot_f
16466 {
16467 }
16468
16469-static void native_machine_emergency_restart(void)
16470+__noreturn static void native_machine_emergency_restart(void)
16471 {
16472 int i;
16473
16474@@ -651,13 +651,13 @@ void native_machine_shutdown(void)
16475 #endif
16476 }
16477
16478-static void __machine_emergency_restart(int emergency)
16479+static __noreturn void __machine_emergency_restart(int emergency)
16480 {
16481 reboot_emergency = emergency;
16482 machine_ops.emergency_restart();
16483 }
16484
16485-static void native_machine_restart(char *__unused)
16486+static __noreturn void native_machine_restart(char *__unused)
16487 {
16488 printk("machine restart\n");
16489
16490@@ -666,7 +666,7 @@ static void native_machine_restart(char
16491 __machine_emergency_restart(0);
16492 }
16493
16494-static void native_machine_halt(void)
16495+static __noreturn void native_machine_halt(void)
16496 {
16497 /* stop other cpus and apics */
16498 machine_shutdown();
16499@@ -677,7 +677,7 @@ static void native_machine_halt(void)
16500 stop_this_cpu(NULL);
16501 }
16502
16503-static void native_machine_power_off(void)
16504+__noreturn static void native_machine_power_off(void)
16505 {
16506 if (pm_power_off) {
16507 if (!reboot_force)
16508@@ -686,6 +686,7 @@ static void native_machine_power_off(voi
16509 }
16510 /* a fallback in case there is no PM info available */
16511 tboot_shutdown(TB_SHUTDOWN_HALT);
16512+ do { } while (1);
16513 }
16514
16515 struct machine_ops machine_ops = {
16516diff -urNp linux-2.6.32.43/arch/x86/kernel/setup.c linux-2.6.32.43/arch/x86/kernel/setup.c
16517--- linux-2.6.32.43/arch/x86/kernel/setup.c 2011-04-17 17:00:52.000000000 -0400
16518+++ linux-2.6.32.43/arch/x86/kernel/setup.c 2011-04-17 17:03:05.000000000 -0400
16519@@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
16520
16521 if (!boot_params.hdr.root_flags)
16522 root_mountflags &= ~MS_RDONLY;
16523- init_mm.start_code = (unsigned long) _text;
16524- init_mm.end_code = (unsigned long) _etext;
16525+ init_mm.start_code = ktla_ktva((unsigned long) _text);
16526+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
16527 init_mm.end_data = (unsigned long) _edata;
16528 init_mm.brk = _brk_end;
16529
16530- code_resource.start = virt_to_phys(_text);
16531- code_resource.end = virt_to_phys(_etext)-1;
16532- data_resource.start = virt_to_phys(_etext);
16533+ code_resource.start = virt_to_phys(ktla_ktva(_text));
16534+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16535+ data_resource.start = virt_to_phys(_sdata);
16536 data_resource.end = virt_to_phys(_edata)-1;
16537 bss_resource.start = virt_to_phys(&__bss_start);
16538 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16539diff -urNp linux-2.6.32.43/arch/x86/kernel/setup_percpu.c linux-2.6.32.43/arch/x86/kernel/setup_percpu.c
16540--- linux-2.6.32.43/arch/x86/kernel/setup_percpu.c 2011-03-27 14:31:47.000000000 -0400
16541+++ linux-2.6.32.43/arch/x86/kernel/setup_percpu.c 2011-06-04 20:36:29.000000000 -0400
16542@@ -25,19 +25,17 @@
16543 # define DBG(x...)
16544 #endif
16545
16546-DEFINE_PER_CPU(int, cpu_number);
16547+#ifdef CONFIG_SMP
16548+DEFINE_PER_CPU(unsigned int, cpu_number);
16549 EXPORT_PER_CPU_SYMBOL(cpu_number);
16550+#endif
16551
16552-#ifdef CONFIG_X86_64
16553 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
16554-#else
16555-#define BOOT_PERCPU_OFFSET 0
16556-#endif
16557
16558 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
16559 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
16560
16561-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
16562+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
16563 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
16564 };
16565 EXPORT_SYMBOL(__per_cpu_offset);
16566@@ -159,10 +157,10 @@ static inline void setup_percpu_segment(
16567 {
16568 #ifdef CONFIG_X86_32
16569 struct desc_struct gdt;
16570+ unsigned long base = per_cpu_offset(cpu);
16571
16572- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
16573- 0x2 | DESCTYPE_S, 0x8);
16574- gdt.s = 1;
16575+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
16576+ 0x83 | DESCTYPE_S, 0xC);
16577 write_gdt_entry(get_cpu_gdt_table(cpu),
16578 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
16579 #endif
16580@@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
16581 /* alrighty, percpu areas up and running */
16582 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
16583 for_each_possible_cpu(cpu) {
16584+#ifdef CONFIG_CC_STACKPROTECTOR
16585+#ifdef CONFIG_X86_32
16586+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
16587+#endif
16588+#endif
16589 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
16590 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
16591 per_cpu(cpu_number, cpu) = cpu;
16592@@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
16593 early_per_cpu_map(x86_cpu_to_node_map, cpu);
16594 #endif
16595 #endif
16596+#ifdef CONFIG_CC_STACKPROTECTOR
16597+#ifdef CONFIG_X86_32
16598+ if (!cpu)
16599+ per_cpu(stack_canary.canary, cpu) = canary;
16600+#endif
16601+#endif
16602 /*
16603 * Up to this point, the boot CPU has been using .data.init
16604 * area. Reload any changed state for the boot CPU.
16605diff -urNp linux-2.6.32.43/arch/x86/kernel/signal.c linux-2.6.32.43/arch/x86/kernel/signal.c
16606--- linux-2.6.32.43/arch/x86/kernel/signal.c 2011-03-27 14:31:47.000000000 -0400
16607+++ linux-2.6.32.43/arch/x86/kernel/signal.c 2011-05-22 23:02:03.000000000 -0400
16608@@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsi
16609 * Align the stack pointer according to the i386 ABI,
16610 * i.e. so that on function entry ((sp + 4) & 15) == 0.
16611 */
16612- sp = ((sp + 4) & -16ul) - 4;
16613+ sp = ((sp - 12) & -16ul) - 4;
16614 #else /* !CONFIG_X86_32 */
16615 sp = round_down(sp, 16) - 8;
16616 #endif
16617@@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, str
16618 * Return an always-bogus address instead so we will die with SIGSEGV.
16619 */
16620 if (onsigstack && !likely(on_sig_stack(sp)))
16621- return (void __user *)-1L;
16622+ return (__force void __user *)-1L;
16623
16624 /* save i387 state */
16625 if (used_math() && save_i387_xstate(*fpstate) < 0)
16626- return (void __user *)-1L;
16627+ return (__force void __user *)-1L;
16628
16629 return (void __user *)sp;
16630 }
16631@@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigactio
16632 }
16633
16634 if (current->mm->context.vdso)
16635- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16636+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
16637 else
16638- restorer = &frame->retcode;
16639+ restorer = (void __user *)&frame->retcode;
16640 if (ka->sa.sa_flags & SA_RESTORER)
16641 restorer = ka->sa.sa_restorer;
16642
16643@@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigactio
16644 * reasons and because gdb uses it as a signature to notice
16645 * signal handler stack frames.
16646 */
16647- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
16648+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
16649
16650 if (err)
16651 return -EFAULT;
16652@@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, str
16653 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
16654
16655 /* Set up to return from userspace. */
16656- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16657+ if (current->mm->context.vdso)
16658+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
16659+ else
16660+ restorer = (void __user *)&frame->retcode;
16661 if (ka->sa.sa_flags & SA_RESTORER)
16662 restorer = ka->sa.sa_restorer;
16663 put_user_ex(restorer, &frame->pretcode);
16664@@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, str
16665 * reasons and because gdb uses it as a signature to notice
16666 * signal handler stack frames.
16667 */
16668- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
16669+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
16670 } put_user_catch(err);
16671
16672 if (err)
16673@@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *re
16674 int signr;
16675 sigset_t *oldset;
16676
16677+ pax_track_stack();
16678+
16679 /*
16680 * We want the common case to go fast, which is why we may in certain
16681 * cases get here from kernel mode. Just return without doing anything
16682@@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *re
16683 * X86_32: vm86 regs switched out by assembly code before reaching
16684 * here, so testing against kernel CS suffices.
16685 */
16686- if (!user_mode(regs))
16687+ if (!user_mode_novm(regs))
16688 return;
16689
16690 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
16691diff -urNp linux-2.6.32.43/arch/x86/kernel/smpboot.c linux-2.6.32.43/arch/x86/kernel/smpboot.c
16692--- linux-2.6.32.43/arch/x86/kernel/smpboot.c 2011-03-27 14:31:47.000000000 -0400
16693+++ linux-2.6.32.43/arch/x86/kernel/smpboot.c 2011-07-01 19:10:03.000000000 -0400
16694@@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct
16695 */
16696 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
16697
16698-void cpu_hotplug_driver_lock()
16699+void cpu_hotplug_driver_lock(void)
16700 {
16701- mutex_lock(&x86_cpu_hotplug_driver_mutex);
16702+ mutex_lock(&x86_cpu_hotplug_driver_mutex);
16703 }
16704
16705-void cpu_hotplug_driver_unlock()
16706+void cpu_hotplug_driver_unlock(void)
16707 {
16708- mutex_unlock(&x86_cpu_hotplug_driver_mutex);
16709+ mutex_unlock(&x86_cpu_hotplug_driver_mutex);
16710 }
16711
16712 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
16713@@ -625,7 +625,7 @@ wakeup_secondary_cpu_via_init(int phys_a
16714 * target processor state.
16715 */
16716 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
16717- (unsigned long)stack_start.sp);
16718+ stack_start);
16719
16720 /*
16721 * Run STARTUP IPI loop.
16722@@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int api
16723 set_idle_for_cpu(cpu, c_idle.idle);
16724 do_rest:
16725 per_cpu(current_task, cpu) = c_idle.idle;
16726+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
16727 #ifdef CONFIG_X86_32
16728 /* Stack for startup_32 can be just as for start_secondary onwards */
16729 irq_ctx_init(cpu);
16730@@ -750,13 +751,15 @@ do_rest:
16731 #else
16732 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
16733 initial_gs = per_cpu_offset(cpu);
16734- per_cpu(kernel_stack, cpu) =
16735- (unsigned long)task_stack_page(c_idle.idle) -
16736- KERNEL_STACK_OFFSET + THREAD_SIZE;
16737+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
16738 #endif
16739+
16740+ pax_open_kernel();
16741 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16742+ pax_close_kernel();
16743+
16744 initial_code = (unsigned long)start_secondary;
16745- stack_start.sp = (void *) c_idle.idle->thread.sp;
16746+ stack_start = c_idle.idle->thread.sp;
16747
16748 /* start_ip had better be page-aligned! */
16749 start_ip = setup_trampoline();
16750@@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int
16751
16752 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
16753
16754+#ifdef CONFIG_PAX_PER_CPU_PGD
16755+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
16756+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16757+ KERNEL_PGD_PTRS);
16758+#endif
16759+
16760 err = do_boot_cpu(apicid, cpu);
16761
16762 if (err) {
16763diff -urNp linux-2.6.32.43/arch/x86/kernel/step.c linux-2.6.32.43/arch/x86/kernel/step.c
16764--- linux-2.6.32.43/arch/x86/kernel/step.c 2011-03-27 14:31:47.000000000 -0400
16765+++ linux-2.6.32.43/arch/x86/kernel/step.c 2011-04-17 15:56:46.000000000 -0400
16766@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
16767 struct desc_struct *desc;
16768 unsigned long base;
16769
16770- seg &= ~7UL;
16771+ seg >>= 3;
16772
16773 mutex_lock(&child->mm->context.lock);
16774- if (unlikely((seg >> 3) >= child->mm->context.size))
16775+ if (unlikely(seg >= child->mm->context.size))
16776 addr = -1L; /* bogus selector, access would fault */
16777 else {
16778 desc = child->mm->context.ldt + seg;
16779@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
16780 addr += base;
16781 }
16782 mutex_unlock(&child->mm->context.lock);
16783- }
16784+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
16785+ addr = ktla_ktva(addr);
16786
16787 return addr;
16788 }
16789@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
16790 unsigned char opcode[15];
16791 unsigned long addr = convert_ip_to_linear(child, regs);
16792
16793+ if (addr == -EINVAL)
16794+ return 0;
16795+
16796 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
16797 for (i = 0; i < copied; i++) {
16798 switch (opcode[i]) {
16799@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
16800
16801 #ifdef CONFIG_X86_64
16802 case 0x40 ... 0x4f:
16803- if (regs->cs != __USER_CS)
16804+ if ((regs->cs & 0xffff) != __USER_CS)
16805 /* 32-bit mode: register increment */
16806 return 0;
16807 /* 64-bit mode: REX prefix */
16808diff -urNp linux-2.6.32.43/arch/x86/kernel/syscall_table_32.S linux-2.6.32.43/arch/x86/kernel/syscall_table_32.S
16809--- linux-2.6.32.43/arch/x86/kernel/syscall_table_32.S 2011-03-27 14:31:47.000000000 -0400
16810+++ linux-2.6.32.43/arch/x86/kernel/syscall_table_32.S 2011-04-17 15:56:46.000000000 -0400
16811@@ -1,3 +1,4 @@
16812+.section .rodata,"a",@progbits
16813 ENTRY(sys_call_table)
16814 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
16815 .long sys_exit
16816diff -urNp linux-2.6.32.43/arch/x86/kernel/sys_i386_32.c linux-2.6.32.43/arch/x86/kernel/sys_i386_32.c
16817--- linux-2.6.32.43/arch/x86/kernel/sys_i386_32.c 2011-03-27 14:31:47.000000000 -0400
16818+++ linux-2.6.32.43/arch/x86/kernel/sys_i386_32.c 2011-04-17 15:56:46.000000000 -0400
16819@@ -24,6 +24,21 @@
16820
16821 #include <asm/syscalls.h>
16822
16823+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
16824+{
16825+ unsigned long pax_task_size = TASK_SIZE;
16826+
16827+#ifdef CONFIG_PAX_SEGMEXEC
16828+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
16829+ pax_task_size = SEGMEXEC_TASK_SIZE;
16830+#endif
16831+
16832+ if (len > pax_task_size || addr > pax_task_size - len)
16833+ return -EINVAL;
16834+
16835+ return 0;
16836+}
16837+
16838 /*
16839 * Perform the select(nd, in, out, ex, tv) and mmap() system
16840 * calls. Linux/i386 didn't use to be able to handle more than
16841@@ -58,6 +73,212 @@ out:
16842 return err;
16843 }
16844
16845+unsigned long
16846+arch_get_unmapped_area(struct file *filp, unsigned long addr,
16847+ unsigned long len, unsigned long pgoff, unsigned long flags)
16848+{
16849+ struct mm_struct *mm = current->mm;
16850+ struct vm_area_struct *vma;
16851+ unsigned long start_addr, pax_task_size = TASK_SIZE;
16852+
16853+#ifdef CONFIG_PAX_SEGMEXEC
16854+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16855+ pax_task_size = SEGMEXEC_TASK_SIZE;
16856+#endif
16857+
16858+ pax_task_size -= PAGE_SIZE;
16859+
16860+ if (len > pax_task_size)
16861+ return -ENOMEM;
16862+
16863+ if (flags & MAP_FIXED)
16864+ return addr;
16865+
16866+#ifdef CONFIG_PAX_RANDMMAP
16867+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16868+#endif
16869+
16870+ if (addr) {
16871+ addr = PAGE_ALIGN(addr);
16872+ if (pax_task_size - len >= addr) {
16873+ vma = find_vma(mm, addr);
16874+ if (check_heap_stack_gap(vma, addr, len))
16875+ return addr;
16876+ }
16877+ }
16878+ if (len > mm->cached_hole_size) {
16879+ start_addr = addr = mm->free_area_cache;
16880+ } else {
16881+ start_addr = addr = mm->mmap_base;
16882+ mm->cached_hole_size = 0;
16883+ }
16884+
16885+#ifdef CONFIG_PAX_PAGEEXEC
16886+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
16887+ start_addr = 0x00110000UL;
16888+
16889+#ifdef CONFIG_PAX_RANDMMAP
16890+ if (mm->pax_flags & MF_PAX_RANDMMAP)
16891+ start_addr += mm->delta_mmap & 0x03FFF000UL;
16892+#endif
16893+
16894+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
16895+ start_addr = addr = mm->mmap_base;
16896+ else
16897+ addr = start_addr;
16898+ }
16899+#endif
16900+
16901+full_search:
16902+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
16903+ /* At this point: (!vma || addr < vma->vm_end). */
16904+ if (pax_task_size - len < addr) {
16905+ /*
16906+ * Start a new search - just in case we missed
16907+ * some holes.
16908+ */
16909+ if (start_addr != mm->mmap_base) {
16910+ start_addr = addr = mm->mmap_base;
16911+ mm->cached_hole_size = 0;
16912+ goto full_search;
16913+ }
16914+ return -ENOMEM;
16915+ }
16916+ if (check_heap_stack_gap(vma, addr, len))
16917+ break;
16918+ if (addr + mm->cached_hole_size < vma->vm_start)
16919+ mm->cached_hole_size = vma->vm_start - addr;
16920+ addr = vma->vm_end;
16921+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
16922+ start_addr = addr = mm->mmap_base;
16923+ mm->cached_hole_size = 0;
16924+ goto full_search;
16925+ }
16926+ }
16927+
16928+ /*
16929+ * Remember the place where we stopped the search:
16930+ */
16931+ mm->free_area_cache = addr + len;
16932+ return addr;
16933+}
16934+
16935+unsigned long
16936+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
16937+ const unsigned long len, const unsigned long pgoff,
16938+ const unsigned long flags)
16939+{
16940+ struct vm_area_struct *vma;
16941+ struct mm_struct *mm = current->mm;
16942+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
16943+
16944+#ifdef CONFIG_PAX_SEGMEXEC
16945+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16946+ pax_task_size = SEGMEXEC_TASK_SIZE;
16947+#endif
16948+
16949+ pax_task_size -= PAGE_SIZE;
16950+
16951+ /* requested length too big for entire address space */
16952+ if (len > pax_task_size)
16953+ return -ENOMEM;
16954+
16955+ if (flags & MAP_FIXED)
16956+ return addr;
16957+
16958+#ifdef CONFIG_PAX_PAGEEXEC
16959+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
16960+ goto bottomup;
16961+#endif
16962+
16963+#ifdef CONFIG_PAX_RANDMMAP
16964+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16965+#endif
16966+
16967+ /* requesting a specific address */
16968+ if (addr) {
16969+ addr = PAGE_ALIGN(addr);
16970+ if (pax_task_size - len >= addr) {
16971+ vma = find_vma(mm, addr);
16972+ if (check_heap_stack_gap(vma, addr, len))
16973+ return addr;
16974+ }
16975+ }
16976+
16977+ /* check if free_area_cache is useful for us */
16978+ if (len <= mm->cached_hole_size) {
16979+ mm->cached_hole_size = 0;
16980+ mm->free_area_cache = mm->mmap_base;
16981+ }
16982+
16983+ /* either no address requested or can't fit in requested address hole */
16984+ addr = mm->free_area_cache;
16985+
16986+ /* make sure it can fit in the remaining address space */
16987+ if (addr > len) {
16988+ vma = find_vma(mm, addr-len);
16989+ if (check_heap_stack_gap(vma, addr - len, len))
16990+ /* remember the address as a hint for next time */
16991+ return (mm->free_area_cache = addr-len);
16992+ }
16993+
16994+ if (mm->mmap_base < len)
16995+ goto bottomup;
16996+
16997+ addr = mm->mmap_base-len;
16998+
16999+ do {
17000+ /*
17001+ * Lookup failure means no vma is above this address,
17002+ * else if new region fits below vma->vm_start,
17003+ * return with success:
17004+ */
17005+ vma = find_vma(mm, addr);
17006+ if (check_heap_stack_gap(vma, addr, len))
17007+ /* remember the address as a hint for next time */
17008+ return (mm->free_area_cache = addr);
17009+
17010+ /* remember the largest hole we saw so far */
17011+ if (addr + mm->cached_hole_size < vma->vm_start)
17012+ mm->cached_hole_size = vma->vm_start - addr;
17013+
17014+ /* try just below the current vma->vm_start */
17015+ addr = skip_heap_stack_gap(vma, len);
17016+ } while (!IS_ERR_VALUE(addr));
17017+
17018+bottomup:
17019+ /*
17020+ * A failed mmap() very likely causes application failure,
17021+ * so fall back to the bottom-up function here. This scenario
17022+ * can happen with large stack limits and large mmap()
17023+ * allocations.
17024+ */
17025+
17026+#ifdef CONFIG_PAX_SEGMEXEC
17027+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
17028+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17029+ else
17030+#endif
17031+
17032+ mm->mmap_base = TASK_UNMAPPED_BASE;
17033+
17034+#ifdef CONFIG_PAX_RANDMMAP
17035+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17036+ mm->mmap_base += mm->delta_mmap;
17037+#endif
17038+
17039+ mm->free_area_cache = mm->mmap_base;
17040+ mm->cached_hole_size = ~0UL;
17041+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17042+ /*
17043+ * Restore the topdown base:
17044+ */
17045+ mm->mmap_base = base;
17046+ mm->free_area_cache = base;
17047+ mm->cached_hole_size = ~0UL;
17048+
17049+ return addr;
17050+}
17051
17052 struct sel_arg_struct {
17053 unsigned long n;
17054@@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int fi
17055 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
17056 case SEMTIMEDOP:
17057 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
17058- (const struct timespec __user *)fifth);
17059+ (__force const struct timespec __user *)fifth);
17060
17061 case SEMGET:
17062 return sys_semget(first, second, third);
17063@@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int fi
17064 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
17065 if (ret)
17066 return ret;
17067- return put_user(raddr, (ulong __user *) third);
17068+ return put_user(raddr, (__force ulong __user *) third);
17069 }
17070 case 1: /* iBCS2 emulator entry point */
17071 if (!segment_eq(get_fs(), get_ds()))
17072@@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldol
17073
17074 return error;
17075 }
17076-
17077-
17078-/*
17079- * Do a system call from kernel instead of calling sys_execve so we
17080- * end up with proper pt_regs.
17081- */
17082-int kernel_execve(const char *filename, char *const argv[], char *const envp[])
17083-{
17084- long __res;
17085- asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
17086- : "=a" (__res)
17087- : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
17088- return __res;
17089-}
17090diff -urNp linux-2.6.32.43/arch/x86/kernel/sys_x86_64.c linux-2.6.32.43/arch/x86/kernel/sys_x86_64.c
17091--- linux-2.6.32.43/arch/x86/kernel/sys_x86_64.c 2011-03-27 14:31:47.000000000 -0400
17092+++ linux-2.6.32.43/arch/x86/kernel/sys_x86_64.c 2011-04-17 15:56:46.000000000 -0400
17093@@ -32,8 +32,8 @@ out:
17094 return error;
17095 }
17096
17097-static void find_start_end(unsigned long flags, unsigned long *begin,
17098- unsigned long *end)
17099+static void find_start_end(struct mm_struct *mm, unsigned long flags,
17100+ unsigned long *begin, unsigned long *end)
17101 {
17102 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17103 unsigned long new_begin;
17104@@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17105 *begin = new_begin;
17106 }
17107 } else {
17108- *begin = TASK_UNMAPPED_BASE;
17109+ *begin = mm->mmap_base;
17110 *end = TASK_SIZE;
17111 }
17112 }
17113@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17114 if (flags & MAP_FIXED)
17115 return addr;
17116
17117- find_start_end(flags, &begin, &end);
17118+ find_start_end(mm, flags, &begin, &end);
17119
17120 if (len > end)
17121 return -ENOMEM;
17122
17123+#ifdef CONFIG_PAX_RANDMMAP
17124+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17125+#endif
17126+
17127 if (addr) {
17128 addr = PAGE_ALIGN(addr);
17129 vma = find_vma(mm, addr);
17130- if (end - len >= addr &&
17131- (!vma || addr + len <= vma->vm_start))
17132+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17133 return addr;
17134 }
17135 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17136@@ -106,7 +109,7 @@ full_search:
17137 }
17138 return -ENOMEM;
17139 }
17140- if (!vma || addr + len <= vma->vm_start) {
17141+ if (check_heap_stack_gap(vma, addr, len)) {
17142 /*
17143 * Remember the place where we stopped the search:
17144 */
17145@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17146 {
17147 struct vm_area_struct *vma;
17148 struct mm_struct *mm = current->mm;
17149- unsigned long addr = addr0;
17150+ unsigned long base = mm->mmap_base, addr = addr0;
17151
17152 /* requested length too big for entire address space */
17153 if (len > TASK_SIZE)
17154@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17155 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17156 goto bottomup;
17157
17158+#ifdef CONFIG_PAX_RANDMMAP
17159+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17160+#endif
17161+
17162 /* requesting a specific address */
17163 if (addr) {
17164 addr = PAGE_ALIGN(addr);
17165- vma = find_vma(mm, addr);
17166- if (TASK_SIZE - len >= addr &&
17167- (!vma || addr + len <= vma->vm_start))
17168- return addr;
17169+ if (TASK_SIZE - len >= addr) {
17170+ vma = find_vma(mm, addr);
17171+ if (check_heap_stack_gap(vma, addr, len))
17172+ return addr;
17173+ }
17174 }
17175
17176 /* check if free_area_cache is useful for us */
17177@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17178 /* make sure it can fit in the remaining address space */
17179 if (addr > len) {
17180 vma = find_vma(mm, addr-len);
17181- if (!vma || addr <= vma->vm_start)
17182+ if (check_heap_stack_gap(vma, addr - len, len))
17183 /* remember the address as a hint for next time */
17184 return mm->free_area_cache = addr-len;
17185 }
17186@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17187 * return with success:
17188 */
17189 vma = find_vma(mm, addr);
17190- if (!vma || addr+len <= vma->vm_start)
17191+ if (check_heap_stack_gap(vma, addr, len))
17192 /* remember the address as a hint for next time */
17193 return mm->free_area_cache = addr;
17194
17195@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17196 mm->cached_hole_size = vma->vm_start - addr;
17197
17198 /* try just below the current vma->vm_start */
17199- addr = vma->vm_start-len;
17200- } while (len < vma->vm_start);
17201+ addr = skip_heap_stack_gap(vma, len);
17202+ } while (!IS_ERR_VALUE(addr));
17203
17204 bottomup:
17205 /*
17206@@ -198,13 +206,21 @@ bottomup:
17207 * can happen with large stack limits and large mmap()
17208 * allocations.
17209 */
17210+ mm->mmap_base = TASK_UNMAPPED_BASE;
17211+
17212+#ifdef CONFIG_PAX_RANDMMAP
17213+ if (mm->pax_flags & MF_PAX_RANDMMAP)
17214+ mm->mmap_base += mm->delta_mmap;
17215+#endif
17216+
17217+ mm->free_area_cache = mm->mmap_base;
17218 mm->cached_hole_size = ~0UL;
17219- mm->free_area_cache = TASK_UNMAPPED_BASE;
17220 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17221 /*
17222 * Restore the topdown base:
17223 */
17224- mm->free_area_cache = mm->mmap_base;
17225+ mm->mmap_base = base;
17226+ mm->free_area_cache = base;
17227 mm->cached_hole_size = ~0UL;
17228
17229 return addr;
17230diff -urNp linux-2.6.32.43/arch/x86/kernel/tboot.c linux-2.6.32.43/arch/x86/kernel/tboot.c
17231--- linux-2.6.32.43/arch/x86/kernel/tboot.c 2011-03-27 14:31:47.000000000 -0400
17232+++ linux-2.6.32.43/arch/x86/kernel/tboot.c 2011-05-22 23:02:03.000000000 -0400
17233@@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
17234
17235 void tboot_shutdown(u32 shutdown_type)
17236 {
17237- void (*shutdown)(void);
17238+ void (* __noreturn shutdown)(void);
17239
17240 if (!tboot_enabled())
17241 return;
17242@@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
17243
17244 switch_to_tboot_pt();
17245
17246- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17247+ shutdown = (void *)tboot->shutdown_entry;
17248 shutdown();
17249
17250 /* should not reach here */
17251@@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17252 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17253 }
17254
17255-static atomic_t ap_wfs_count;
17256+static atomic_unchecked_t ap_wfs_count;
17257
17258 static int tboot_wait_for_aps(int num_aps)
17259 {
17260@@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(
17261 {
17262 switch (action) {
17263 case CPU_DYING:
17264- atomic_inc(&ap_wfs_count);
17265+ atomic_inc_unchecked(&ap_wfs_count);
17266 if (num_online_cpus() == 1)
17267- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17268+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17269 return NOTIFY_BAD;
17270 break;
17271 }
17272@@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
17273
17274 tboot_create_trampoline();
17275
17276- atomic_set(&ap_wfs_count, 0);
17277+ atomic_set_unchecked(&ap_wfs_count, 0);
17278 register_hotcpu_notifier(&tboot_cpu_notifier);
17279 return 0;
17280 }
17281diff -urNp linux-2.6.32.43/arch/x86/kernel/time.c linux-2.6.32.43/arch/x86/kernel/time.c
17282--- linux-2.6.32.43/arch/x86/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
17283+++ linux-2.6.32.43/arch/x86/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
17284@@ -26,17 +26,13 @@
17285 int timer_ack;
17286 #endif
17287
17288-#ifdef CONFIG_X86_64
17289-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17290-#endif
17291-
17292 unsigned long profile_pc(struct pt_regs *regs)
17293 {
17294 unsigned long pc = instruction_pointer(regs);
17295
17296- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17297+ if (!user_mode(regs) && in_lock_functions(pc)) {
17298 #ifdef CONFIG_FRAME_POINTER
17299- return *(unsigned long *)(regs->bp + sizeof(long));
17300+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17301 #else
17302 unsigned long *sp =
17303 (unsigned long *)kernel_stack_pointer(regs);
17304@@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
17305 * or above a saved flags. Eflags has bits 22-31 zero,
17306 * kernel addresses don't.
17307 */
17308+
17309+#ifdef CONFIG_PAX_KERNEXEC
17310+ return ktla_ktva(sp[0]);
17311+#else
17312 if (sp[0] >> 22)
17313 return sp[0];
17314 if (sp[1] >> 22)
17315 return sp[1];
17316 #endif
17317+
17318+#endif
17319 }
17320 return pc;
17321 }
17322diff -urNp linux-2.6.32.43/arch/x86/kernel/tls.c linux-2.6.32.43/arch/x86/kernel/tls.c
17323--- linux-2.6.32.43/arch/x86/kernel/tls.c 2011-03-27 14:31:47.000000000 -0400
17324+++ linux-2.6.32.43/arch/x86/kernel/tls.c 2011-04-17 15:56:46.000000000 -0400
17325@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17326 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17327 return -EINVAL;
17328
17329+#ifdef CONFIG_PAX_SEGMEXEC
17330+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17331+ return -EINVAL;
17332+#endif
17333+
17334 set_tls_desc(p, idx, &info, 1);
17335
17336 return 0;
17337diff -urNp linux-2.6.32.43/arch/x86/kernel/trampoline_32.S linux-2.6.32.43/arch/x86/kernel/trampoline_32.S
17338--- linux-2.6.32.43/arch/x86/kernel/trampoline_32.S 2011-03-27 14:31:47.000000000 -0400
17339+++ linux-2.6.32.43/arch/x86/kernel/trampoline_32.S 2011-04-17 15:56:46.000000000 -0400
17340@@ -32,6 +32,12 @@
17341 #include <asm/segment.h>
17342 #include <asm/page_types.h>
17343
17344+#ifdef CONFIG_PAX_KERNEXEC
17345+#define ta(X) (X)
17346+#else
17347+#define ta(X) ((X) - __PAGE_OFFSET)
17348+#endif
17349+
17350 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
17351 __CPUINITRODATA
17352 .code16
17353@@ -60,7 +66,7 @@ r_base = .
17354 inc %ax # protected mode (PE) bit
17355 lmsw %ax # into protected mode
17356 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17357- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17358+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
17359
17360 # These need to be in the same 64K segment as the above;
17361 # hence we don't use the boot_gdt_descr defined in head.S
17362diff -urNp linux-2.6.32.43/arch/x86/kernel/trampoline_64.S linux-2.6.32.43/arch/x86/kernel/trampoline_64.S
17363--- linux-2.6.32.43/arch/x86/kernel/trampoline_64.S 2011-03-27 14:31:47.000000000 -0400
17364+++ linux-2.6.32.43/arch/x86/kernel/trampoline_64.S 2011-07-01 18:53:26.000000000 -0400
17365@@ -91,7 +91,7 @@ startup_32:
17366 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17367 movl %eax, %ds
17368
17369- movl $X86_CR4_PAE, %eax
17370+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17371 movl %eax, %cr4 # Enable PAE mode
17372
17373 # Setup trampoline 4 level pagetables
17374@@ -127,7 +127,7 @@ startup_64:
17375 no_longmode:
17376 hlt
17377 jmp no_longmode
17378-#include "verify_cpu_64.S"
17379+#include "verify_cpu.S"
17380
17381 # Careful these need to be in the same 64K segment as the above;
17382 tidt:
17383@@ -138,7 +138,7 @@ tidt:
17384 # so the kernel can live anywhere
17385 .balign 4
17386 tgdt:
17387- .short tgdt_end - tgdt # gdt limit
17388+ .short tgdt_end - tgdt - 1 # gdt limit
17389 .long tgdt - r_base
17390 .short 0
17391 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17392diff -urNp linux-2.6.32.43/arch/x86/kernel/traps.c linux-2.6.32.43/arch/x86/kernel/traps.c
17393--- linux-2.6.32.43/arch/x86/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
17394+++ linux-2.6.32.43/arch/x86/kernel/traps.c 2011-07-06 19:53:33.000000000 -0400
17395@@ -69,12 +69,6 @@ asmlinkage int system_call(void);
17396
17397 /* Do we ignore FPU interrupts ? */
17398 char ignore_fpu_irq;
17399-
17400-/*
17401- * The IDT has to be page-aligned to simplify the Pentium
17402- * F0 0F bug workaround.
17403- */
17404-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17405 #endif
17406
17407 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17408@@ -112,19 +106,19 @@ static inline void preempt_conditional_c
17409 static inline void
17410 die_if_kernel(const char *str, struct pt_regs *regs, long err)
17411 {
17412- if (!user_mode_vm(regs))
17413+ if (!user_mode(regs))
17414 die(str, regs, err);
17415 }
17416 #endif
17417
17418 static void __kprobes
17419-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17420+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17421 long error_code, siginfo_t *info)
17422 {
17423 struct task_struct *tsk = current;
17424
17425 #ifdef CONFIG_X86_32
17426- if (regs->flags & X86_VM_MASK) {
17427+ if (v8086_mode(regs)) {
17428 /*
17429 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17430 * On nmi (interrupt 2), do_trap should not be called.
17431@@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str
17432 }
17433 #endif
17434
17435- if (!user_mode(regs))
17436+ if (!user_mode_novm(regs))
17437 goto kernel_trap;
17438
17439 #ifdef CONFIG_X86_32
17440@@ -158,7 +152,7 @@ trap_signal:
17441 printk_ratelimit()) {
17442 printk(KERN_INFO
17443 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17444- tsk->comm, tsk->pid, str,
17445+ tsk->comm, task_pid_nr(tsk), str,
17446 regs->ip, regs->sp, error_code);
17447 print_vma_addr(" in ", regs->ip);
17448 printk("\n");
17449@@ -175,8 +169,20 @@ kernel_trap:
17450 if (!fixup_exception(regs)) {
17451 tsk->thread.error_code = error_code;
17452 tsk->thread.trap_no = trapnr;
17453+
17454+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17455+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17456+ str = "PAX: suspicious stack segment fault";
17457+#endif
17458+
17459 die(str, regs, error_code);
17460 }
17461+
17462+#ifdef CONFIG_PAX_REFCOUNT
17463+ if (trapnr == 4)
17464+ pax_report_refcount_overflow(regs);
17465+#endif
17466+
17467 return;
17468
17469 #ifdef CONFIG_X86_32
17470@@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *re
17471 conditional_sti(regs);
17472
17473 #ifdef CONFIG_X86_32
17474- if (regs->flags & X86_VM_MASK)
17475+ if (v8086_mode(regs))
17476 goto gp_in_vm86;
17477 #endif
17478
17479 tsk = current;
17480- if (!user_mode(regs))
17481+ if (!user_mode_novm(regs))
17482 goto gp_in_kernel;
17483
17484+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17485+ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17486+ struct mm_struct *mm = tsk->mm;
17487+ unsigned long limit;
17488+
17489+ down_write(&mm->mmap_sem);
17490+ limit = mm->context.user_cs_limit;
17491+ if (limit < TASK_SIZE) {
17492+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17493+ up_write(&mm->mmap_sem);
17494+ return;
17495+ }
17496+ up_write(&mm->mmap_sem);
17497+ }
17498+#endif
17499+
17500 tsk->thread.error_code = error_code;
17501 tsk->thread.trap_no = 13;
17502
17503@@ -305,6 +327,13 @@ gp_in_kernel:
17504 if (notify_die(DIE_GPF, "general protection fault", regs,
17505 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17506 return;
17507+
17508+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17509+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17510+ die("PAX: suspicious general protection fault", regs, error_code);
17511+ else
17512+#endif
17513+
17514 die("general protection fault", regs, error_code);
17515 }
17516
17517@@ -435,6 +464,17 @@ static notrace __kprobes void default_do
17518 dotraplinkage notrace __kprobes void
17519 do_nmi(struct pt_regs *regs, long error_code)
17520 {
17521+
17522+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17523+ if (!user_mode(regs)) {
17524+ unsigned long cs = regs->cs & 0xFFFF;
17525+ unsigned long ip = ktva_ktla(regs->ip);
17526+
17527+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17528+ regs->ip = ip;
17529+ }
17530+#endif
17531+
17532 nmi_enter();
17533
17534 inc_irq_stat(__nmi_count);
17535@@ -558,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
17536 }
17537
17538 #ifdef CONFIG_X86_32
17539- if (regs->flags & X86_VM_MASK)
17540+ if (v8086_mode(regs))
17541 goto debug_vm86;
17542 #endif
17543
17544@@ -570,7 +610,7 @@ dotraplinkage void __kprobes do_debug(st
17545 * kernel space (but re-enable TF when returning to user mode).
17546 */
17547 if (condition & DR_STEP) {
17548- if (!user_mode(regs))
17549+ if (!user_mode_novm(regs))
17550 goto clear_TF_reenable;
17551 }
17552
17553@@ -757,7 +797,7 @@ do_simd_coprocessor_error(struct pt_regs
17554 * Handle strange cache flush from user space exception
17555 * in all other cases. This is undocumented behaviour.
17556 */
17557- if (regs->flags & X86_VM_MASK) {
17558+ if (v8086_mode(regs)) {
17559 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
17560 return;
17561 }
17562@@ -798,7 +838,7 @@ asmlinkage void __attribute__((weak)) sm
17563 void __math_state_restore(void)
17564 {
17565 struct thread_info *thread = current_thread_info();
17566- struct task_struct *tsk = thread->task;
17567+ struct task_struct *tsk = current;
17568
17569 /*
17570 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17571@@ -825,8 +865,7 @@ void __math_state_restore(void)
17572 */
17573 asmlinkage void math_state_restore(void)
17574 {
17575- struct thread_info *thread = current_thread_info();
17576- struct task_struct *tsk = thread->task;
17577+ struct task_struct *tsk = current;
17578
17579 if (!tsk_used_math(tsk)) {
17580 local_irq_enable();
17581diff -urNp linux-2.6.32.43/arch/x86/kernel/verify_cpu_64.S linux-2.6.32.43/arch/x86/kernel/verify_cpu_64.S
17582--- linux-2.6.32.43/arch/x86/kernel/verify_cpu_64.S 2011-03-27 14:31:47.000000000 -0400
17583+++ linux-2.6.32.43/arch/x86/kernel/verify_cpu_64.S 1969-12-31 19:00:00.000000000 -0500
17584@@ -1,105 +0,0 @@
17585-/*
17586- *
17587- * verify_cpu.S - Code for cpu long mode and SSE verification. This
17588- * code has been borrowed from boot/setup.S and was introduced by
17589- * Andi Kleen.
17590- *
17591- * Copyright (c) 2007 Andi Kleen (ak@suse.de)
17592- * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
17593- * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
17594- *
17595- * This source code is licensed under the GNU General Public License,
17596- * Version 2. See the file COPYING for more details.
17597- *
17598- * This is a common code for verification whether CPU supports
17599- * long mode and SSE or not. It is not called directly instead this
17600- * file is included at various places and compiled in that context.
17601- * Following are the current usage.
17602- *
17603- * This file is included by both 16bit and 32bit code.
17604- *
17605- * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
17606- * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
17607- * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
17608- * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
17609- *
17610- * verify_cpu, returns the status of cpu check in register %eax.
17611- * 0: Success 1: Failure
17612- *
17613- * The caller needs to check for the error code and take the action
17614- * appropriately. Either display a message or halt.
17615- */
17616-
17617-#include <asm/cpufeature.h>
17618-
17619-verify_cpu:
17620- pushfl # Save caller passed flags
17621- pushl $0 # Kill any dangerous flags
17622- popfl
17623-
17624- pushfl # standard way to check for cpuid
17625- popl %eax
17626- movl %eax,%ebx
17627- xorl $0x200000,%eax
17628- pushl %eax
17629- popfl
17630- pushfl
17631- popl %eax
17632- cmpl %eax,%ebx
17633- jz verify_cpu_no_longmode # cpu has no cpuid
17634-
17635- movl $0x0,%eax # See if cpuid 1 is implemented
17636- cpuid
17637- cmpl $0x1,%eax
17638- jb verify_cpu_no_longmode # no cpuid 1
17639-
17640- xor %di,%di
17641- cmpl $0x68747541,%ebx # AuthenticAMD
17642- jnz verify_cpu_noamd
17643- cmpl $0x69746e65,%edx
17644- jnz verify_cpu_noamd
17645- cmpl $0x444d4163,%ecx
17646- jnz verify_cpu_noamd
17647- mov $1,%di # cpu is from AMD
17648-
17649-verify_cpu_noamd:
17650- movl $0x1,%eax # Does the cpu have what it takes
17651- cpuid
17652- andl $REQUIRED_MASK0,%edx
17653- xorl $REQUIRED_MASK0,%edx
17654- jnz verify_cpu_no_longmode
17655-
17656- movl $0x80000000,%eax # See if extended cpuid is implemented
17657- cpuid
17658- cmpl $0x80000001,%eax
17659- jb verify_cpu_no_longmode # no extended cpuid
17660-
17661- movl $0x80000001,%eax # Does the cpu have what it takes
17662- cpuid
17663- andl $REQUIRED_MASK1,%edx
17664- xorl $REQUIRED_MASK1,%edx
17665- jnz verify_cpu_no_longmode
17666-
17667-verify_cpu_sse_test:
17668- movl $1,%eax
17669- cpuid
17670- andl $SSE_MASK,%edx
17671- cmpl $SSE_MASK,%edx
17672- je verify_cpu_sse_ok
17673- test %di,%di
17674- jz verify_cpu_no_longmode # only try to force SSE on AMD
17675- movl $0xc0010015,%ecx # HWCR
17676- rdmsr
17677- btr $15,%eax # enable SSE
17678- wrmsr
17679- xor %di,%di # don't loop
17680- jmp verify_cpu_sse_test # try again
17681-
17682-verify_cpu_no_longmode:
17683- popfl # Restore caller passed flags
17684- movl $1,%eax
17685- ret
17686-verify_cpu_sse_ok:
17687- popfl # Restore caller passed flags
17688- xorl %eax, %eax
17689- ret
17690diff -urNp linux-2.6.32.43/arch/x86/kernel/verify_cpu.S linux-2.6.32.43/arch/x86/kernel/verify_cpu.S
17691--- linux-2.6.32.43/arch/x86/kernel/verify_cpu.S 1969-12-31 19:00:00.000000000 -0500
17692+++ linux-2.6.32.43/arch/x86/kernel/verify_cpu.S 2011-07-01 18:28:42.000000000 -0400
17693@@ -0,0 +1,140 @@
17694+/*
17695+ *
17696+ * verify_cpu.S - Code for cpu long mode and SSE verification. This
17697+ * code has been borrowed from boot/setup.S and was introduced by
17698+ * Andi Kleen.
17699+ *
17700+ * Copyright (c) 2007 Andi Kleen (ak@suse.de)
17701+ * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
17702+ * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
17703+ * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com)
17704+ *
17705+ * This source code is licensed under the GNU General Public License,
17706+ * Version 2. See the file COPYING for more details.
17707+ *
17708+ * This is a common code for verification whether CPU supports
17709+ * long mode and SSE or not. It is not called directly instead this
17710+ * file is included at various places and compiled in that context.
17711+ * This file is expected to run in 32bit code. Currently:
17712+ *
17713+ * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17714+ * arch/x86/kernel/trampoline_64.S: secondary processor verification
17715+ * arch/x86/kernel/head_32.S: processor startup
17716+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
17717+ *
17718+ * verify_cpu, returns the status of longmode and SSE in register %eax.
17719+ * 0: Success 1: Failure
17720+ *
17721+ * On Intel, the XD_DISABLE flag will be cleared as a side-effect.
17722+ *
17723+ * The caller needs to check for the error code and take the action
17724+ * appropriately. Either display a message or halt.
17725+ */
17726+
17727+#include <asm/cpufeature.h>
17728+#include <asm/msr-index.h>
17729+
17730+verify_cpu:
17731+ pushfl # Save caller passed flags
17732+ pushl $0 # Kill any dangerous flags
17733+ popfl
17734+
17735+ pushfl # standard way to check for cpuid
17736+ popl %eax
17737+ movl %eax,%ebx
17738+ xorl $0x200000,%eax
17739+ pushl %eax
17740+ popfl
17741+ pushfl
17742+ popl %eax
17743+ cmpl %eax,%ebx
17744+ jz verify_cpu_no_longmode # cpu has no cpuid
17745+
17746+ movl $0x0,%eax # See if cpuid 1 is implemented
17747+ cpuid
17748+ cmpl $0x1,%eax
17749+ jb verify_cpu_no_longmode # no cpuid 1
17750+
17751+ xor %di,%di
17752+ cmpl $0x68747541,%ebx # AuthenticAMD
17753+ jnz verify_cpu_noamd
17754+ cmpl $0x69746e65,%edx
17755+ jnz verify_cpu_noamd
17756+ cmpl $0x444d4163,%ecx
17757+ jnz verify_cpu_noamd
17758+ mov $1,%di # cpu is from AMD
17759+ jmp verify_cpu_check
17760+
17761+verify_cpu_noamd:
17762+ cmpl $0x756e6547,%ebx # GenuineIntel?
17763+ jnz verify_cpu_check
17764+ cmpl $0x49656e69,%edx
17765+ jnz verify_cpu_check
17766+ cmpl $0x6c65746e,%ecx
17767+ jnz verify_cpu_check
17768+
17769+ # only call IA32_MISC_ENABLE when:
17770+ # family > 6 || (family == 6 && model >= 0xd)
17771+ movl $0x1, %eax # check CPU family and model
17772+ cpuid
17773+ movl %eax, %ecx
17774+
17775+ andl $0x0ff00f00, %eax # mask family and extended family
17776+ shrl $8, %eax
17777+ cmpl $6, %eax
17778+ ja verify_cpu_clear_xd # family > 6, ok
17779+ jb verify_cpu_check # family < 6, skip
17780+
17781+ andl $0x000f00f0, %ecx # mask model and extended model
17782+ shrl $4, %ecx
17783+ cmpl $0xd, %ecx
17784+ jb verify_cpu_check # family == 6, model < 0xd, skip
17785+
17786+verify_cpu_clear_xd:
17787+ movl $MSR_IA32_MISC_ENABLE, %ecx
17788+ rdmsr
17789+ btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE
17790+ jnc verify_cpu_check # only write MSR if bit was changed
17791+ wrmsr
17792+
17793+verify_cpu_check:
17794+ movl $0x1,%eax # Does the cpu have what it takes
17795+ cpuid
17796+ andl $REQUIRED_MASK0,%edx
17797+ xorl $REQUIRED_MASK0,%edx
17798+ jnz verify_cpu_no_longmode
17799+
17800+ movl $0x80000000,%eax # See if extended cpuid is implemented
17801+ cpuid
17802+ cmpl $0x80000001,%eax
17803+ jb verify_cpu_no_longmode # no extended cpuid
17804+
17805+ movl $0x80000001,%eax # Does the cpu have what it takes
17806+ cpuid
17807+ andl $REQUIRED_MASK1,%edx
17808+ xorl $REQUIRED_MASK1,%edx
17809+ jnz verify_cpu_no_longmode
17810+
17811+verify_cpu_sse_test:
17812+ movl $1,%eax
17813+ cpuid
17814+ andl $SSE_MASK,%edx
17815+ cmpl $SSE_MASK,%edx
17816+ je verify_cpu_sse_ok
17817+ test %di,%di
17818+ jz verify_cpu_no_longmode # only try to force SSE on AMD
17819+ movl $MSR_K7_HWCR,%ecx
17820+ rdmsr
17821+ btr $15,%eax # enable SSE
17822+ wrmsr
17823+ xor %di,%di # don't loop
17824+ jmp verify_cpu_sse_test # try again
17825+
17826+verify_cpu_no_longmode:
17827+ popfl # Restore caller passed flags
17828+ movl $1,%eax
17829+ ret
17830+verify_cpu_sse_ok:
17831+ popfl # Restore caller passed flags
17832+ xorl %eax, %eax
17833+ ret
17834diff -urNp linux-2.6.32.43/arch/x86/kernel/vm86_32.c linux-2.6.32.43/arch/x86/kernel/vm86_32.c
17835--- linux-2.6.32.43/arch/x86/kernel/vm86_32.c 2011-03-27 14:31:47.000000000 -0400
17836+++ linux-2.6.32.43/arch/x86/kernel/vm86_32.c 2011-04-17 15:56:46.000000000 -0400
17837@@ -41,6 +41,7 @@
17838 #include <linux/ptrace.h>
17839 #include <linux/audit.h>
17840 #include <linux/stddef.h>
17841+#include <linux/grsecurity.h>
17842
17843 #include <asm/uaccess.h>
17844 #include <asm/io.h>
17845@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
17846 do_exit(SIGSEGV);
17847 }
17848
17849- tss = &per_cpu(init_tss, get_cpu());
17850+ tss = init_tss + get_cpu();
17851 current->thread.sp0 = current->thread.saved_sp0;
17852 current->thread.sysenter_cs = __KERNEL_CS;
17853 load_sp0(tss, &current->thread);
17854@@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
17855 struct task_struct *tsk;
17856 int tmp, ret = -EPERM;
17857
17858+#ifdef CONFIG_GRKERNSEC_VM86
17859+ if (!capable(CAP_SYS_RAWIO)) {
17860+ gr_handle_vm86();
17861+ goto out;
17862+ }
17863+#endif
17864+
17865 tsk = current;
17866 if (tsk->thread.saved_sp0)
17867 goto out;
17868@@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
17869 int tmp, ret;
17870 struct vm86plus_struct __user *v86;
17871
17872+#ifdef CONFIG_GRKERNSEC_VM86
17873+ if (!capable(CAP_SYS_RAWIO)) {
17874+ gr_handle_vm86();
17875+ ret = -EPERM;
17876+ goto out;
17877+ }
17878+#endif
17879+
17880 tsk = current;
17881 switch (regs->bx) {
17882 case VM86_REQUEST_IRQ:
17883@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
17884 tsk->thread.saved_fs = info->regs32->fs;
17885 tsk->thread.saved_gs = get_user_gs(info->regs32);
17886
17887- tss = &per_cpu(init_tss, get_cpu());
17888+ tss = init_tss + get_cpu();
17889 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17890 if (cpu_has_sep)
17891 tsk->thread.sysenter_cs = 0;
17892@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
17893 goto cannot_handle;
17894 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17895 goto cannot_handle;
17896- intr_ptr = (unsigned long __user *) (i << 2);
17897+ intr_ptr = (__force unsigned long __user *) (i << 2);
17898 if (get_user(segoffs, intr_ptr))
17899 goto cannot_handle;
17900 if ((segoffs >> 16) == BIOSSEG)
17901diff -urNp linux-2.6.32.43/arch/x86/kernel/vmi_32.c linux-2.6.32.43/arch/x86/kernel/vmi_32.c
17902--- linux-2.6.32.43/arch/x86/kernel/vmi_32.c 2011-03-27 14:31:47.000000000 -0400
17903+++ linux-2.6.32.43/arch/x86/kernel/vmi_32.c 2011-08-05 20:33:55.000000000 -0400
17904@@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1)))
17905 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
17906
17907 #define call_vrom_func(rom,func) \
17908- (((VROMFUNC *)(rom->func))())
17909+ (((VROMFUNC *)(ktva_ktla(rom.func)))())
17910
17911 #define call_vrom_long_func(rom,func,arg) \
17912- (((VROMLONGFUNC *)(rom->func)) (arg))
17913+({\
17914+ u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
17915+ struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
17916+ __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
17917+ __reloc;\
17918+})
17919
17920-static struct vrom_header *vmi_rom;
17921+static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
17922 static int disable_pge;
17923 static int disable_pse;
17924 static int disable_sep;
17925@@ -76,10 +81,10 @@ static struct {
17926 void (*set_initial_ap_state)(int, int);
17927 void (*halt)(void);
17928 void (*set_lazy_mode)(int mode);
17929-} vmi_ops;
17930+} __no_const vmi_ops __read_only;
17931
17932 /* Cached VMI operations */
17933-struct vmi_timer_ops vmi_timer_ops;
17934+struct vmi_timer_ops vmi_timer_ops __read_only;
17935
17936 /*
17937 * VMI patching routines.
17938@@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
17939 static inline void patch_offset(void *insnbuf,
17940 unsigned long ip, unsigned long dest)
17941 {
17942- *(unsigned long *)(insnbuf+1) = dest-ip-5;
17943+ *(unsigned long *)(insnbuf+1) = dest-ip-5;
17944 }
17945
17946 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
17947@@ -102,6 +107,7 @@ static unsigned patch_internal(int call,
17948 {
17949 u64 reloc;
17950 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
17951+
17952 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
17953 switch(rel->type) {
17954 case VMI_RELOCATION_CALL_REL:
17955@@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud
17956
17957 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
17958 {
17959- const pte_t pte = { .pte = 0 };
17960+ const pte_t pte = __pte(0ULL);
17961 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
17962 }
17963
17964 static void vmi_pmd_clear(pmd_t *pmd)
17965 {
17966- const pte_t pte = { .pte = 0 };
17967+ const pte_t pte = __pte(0ULL);
17968 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
17969 }
17970 #endif
17971@@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, un
17972 ap.ss = __KERNEL_DS;
17973 ap.esp = (unsigned long) start_esp;
17974
17975- ap.ds = __USER_DS;
17976- ap.es = __USER_DS;
17977+ ap.ds = __KERNEL_DS;
17978+ ap.es = __KERNEL_DS;
17979 ap.fs = __KERNEL_PERCPU;
17980- ap.gs = __KERNEL_STACK_CANARY;
17981+ savesegment(gs, ap.gs);
17982
17983 ap.eflags = 0;
17984
17985@@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
17986 paravirt_leave_lazy_mmu();
17987 }
17988
17989+#ifdef CONFIG_PAX_KERNEXEC
17990+static unsigned long vmi_pax_open_kernel(void)
17991+{
17992+ return 0;
17993+}
17994+
17995+static unsigned long vmi_pax_close_kernel(void)
17996+{
17997+ return 0;
17998+}
17999+#endif
18000+
18001 static inline int __init check_vmi_rom(struct vrom_header *rom)
18002 {
18003 struct pci_header *pci;
18004@@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(s
18005 return 0;
18006 if (rom->vrom_signature != VMI_SIGNATURE)
18007 return 0;
18008+ if (rom->rom_length * 512 > sizeof(*rom)) {
18009+ printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
18010+ return 0;
18011+ }
18012 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
18013 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
18014 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
18015@@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(v
18016 struct vrom_header *romstart;
18017 romstart = (struct vrom_header *)isa_bus_to_virt(base);
18018 if (check_vmi_rom(romstart)) {
18019- vmi_rom = romstart;
18020+ vmi_rom = *romstart;
18021 return 1;
18022 }
18023 }
18024@@ -836,6 +858,11 @@ static inline int __init activate_vmi(vo
18025
18026 para_fill(pv_irq_ops.safe_halt, Halt);
18027
18028+#ifdef CONFIG_PAX_KERNEXEC
18029+ pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
18030+ pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
18031+#endif
18032+
18033 /*
18034 * Alternative instruction rewriting doesn't happen soon enough
18035 * to convert VMI_IRET to a call instead of a jump; so we have
18036@@ -853,16 +880,16 @@ static inline int __init activate_vmi(vo
18037
18038 void __init vmi_init(void)
18039 {
18040- if (!vmi_rom)
18041+ if (!vmi_rom.rom_signature)
18042 probe_vmi_rom();
18043 else
18044- check_vmi_rom(vmi_rom);
18045+ check_vmi_rom(&vmi_rom);
18046
18047 /* In case probing for or validating the ROM failed, basil */
18048- if (!vmi_rom)
18049+ if (!vmi_rom.rom_signature)
18050 return;
18051
18052- reserve_top_address(-vmi_rom->virtual_top);
18053+ reserve_top_address(-vmi_rom.virtual_top);
18054
18055 #ifdef CONFIG_X86_IO_APIC
18056 /* This is virtual hardware; timer routing is wired correctly */
18057@@ -874,7 +901,7 @@ void __init vmi_activate(void)
18058 {
18059 unsigned long flags;
18060
18061- if (!vmi_rom)
18062+ if (!vmi_rom.rom_signature)
18063 return;
18064
18065 local_irq_save(flags);
18066diff -urNp linux-2.6.32.43/arch/x86/kernel/vmlinux.lds.S linux-2.6.32.43/arch/x86/kernel/vmlinux.lds.S
18067--- linux-2.6.32.43/arch/x86/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
18068+++ linux-2.6.32.43/arch/x86/kernel/vmlinux.lds.S 2011-04-17 15:56:46.000000000 -0400
18069@@ -26,6 +26,13 @@
18070 #include <asm/page_types.h>
18071 #include <asm/cache.h>
18072 #include <asm/boot.h>
18073+#include <asm/segment.h>
18074+
18075+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18076+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
18077+#else
18078+#define __KERNEL_TEXT_OFFSET 0
18079+#endif
18080
18081 #undef i386 /* in case the preprocessor is a 32bit one */
18082
18083@@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
18084 #ifdef CONFIG_X86_32
18085 OUTPUT_ARCH(i386)
18086 ENTRY(phys_startup_32)
18087-jiffies = jiffies_64;
18088 #else
18089 OUTPUT_ARCH(i386:x86-64)
18090 ENTRY(phys_startup_64)
18091-jiffies_64 = jiffies;
18092 #endif
18093
18094 PHDRS {
18095 text PT_LOAD FLAGS(5); /* R_E */
18096- data PT_LOAD FLAGS(7); /* RWE */
18097+#ifdef CONFIG_X86_32
18098+ module PT_LOAD FLAGS(5); /* R_E */
18099+#endif
18100+#ifdef CONFIG_XEN
18101+ rodata PT_LOAD FLAGS(5); /* R_E */
18102+#else
18103+ rodata PT_LOAD FLAGS(4); /* R__ */
18104+#endif
18105+ data PT_LOAD FLAGS(6); /* RW_ */
18106 #ifdef CONFIG_X86_64
18107 user PT_LOAD FLAGS(5); /* R_E */
18108+#endif
18109+ init.begin PT_LOAD FLAGS(6); /* RW_ */
18110 #ifdef CONFIG_SMP
18111 percpu PT_LOAD FLAGS(6); /* RW_ */
18112 #endif
18113+ text.init PT_LOAD FLAGS(5); /* R_E */
18114+ text.exit PT_LOAD FLAGS(5); /* R_E */
18115 init PT_LOAD FLAGS(7); /* RWE */
18116-#endif
18117 note PT_NOTE FLAGS(0); /* ___ */
18118 }
18119
18120 SECTIONS
18121 {
18122 #ifdef CONFIG_X86_32
18123- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18124- phys_startup_32 = startup_32 - LOAD_OFFSET;
18125+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18126 #else
18127- . = __START_KERNEL;
18128- phys_startup_64 = startup_64 - LOAD_OFFSET;
18129+ . = __START_KERNEL;
18130 #endif
18131
18132 /* Text and read-only data */
18133- .text : AT(ADDR(.text) - LOAD_OFFSET) {
18134- _text = .;
18135+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18136 /* bootstrapping code */
18137+#ifdef CONFIG_X86_32
18138+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18139+#else
18140+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18141+#endif
18142+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18143+ _text = .;
18144 HEAD_TEXT
18145 #ifdef CONFIG_X86_32
18146 . = ALIGN(PAGE_SIZE);
18147@@ -82,28 +102,71 @@ SECTIONS
18148 IRQENTRY_TEXT
18149 *(.fixup)
18150 *(.gnu.warning)
18151- /* End of text section */
18152- _etext = .;
18153 } :text = 0x9090
18154
18155- NOTES :text :note
18156+ . += __KERNEL_TEXT_OFFSET;
18157+
18158+#ifdef CONFIG_X86_32
18159+ . = ALIGN(PAGE_SIZE);
18160+ .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
18161+ *(.vmi.rom)
18162+ } :module
18163+
18164+ . = ALIGN(PAGE_SIZE);
18165+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18166+
18167+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18168+ MODULES_EXEC_VADDR = .;
18169+ BYTE(0)
18170+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18171+ . = ALIGN(HPAGE_SIZE);
18172+ MODULES_EXEC_END = . - 1;
18173+#endif
18174+
18175+ } :module
18176+#endif
18177
18178- EXCEPTION_TABLE(16) :text = 0x9090
18179+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18180+ /* End of text section */
18181+ _etext = . - __KERNEL_TEXT_OFFSET;
18182+ }
18183+
18184+#ifdef CONFIG_X86_32
18185+ . = ALIGN(PAGE_SIZE);
18186+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18187+ *(.idt)
18188+ . = ALIGN(PAGE_SIZE);
18189+ *(.empty_zero_page)
18190+ *(.swapper_pg_fixmap)
18191+ *(.swapper_pg_pmd)
18192+ *(.swapper_pg_dir)
18193+ *(.trampoline_pg_dir)
18194+ } :rodata
18195+#endif
18196+
18197+ . = ALIGN(PAGE_SIZE);
18198+ NOTES :rodata :note
18199+
18200+ EXCEPTION_TABLE(16) :rodata
18201
18202 RO_DATA(PAGE_SIZE)
18203
18204 /* Data */
18205 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18206+
18207+#ifdef CONFIG_PAX_KERNEXEC
18208+ . = ALIGN(HPAGE_SIZE);
18209+#else
18210+ . = ALIGN(PAGE_SIZE);
18211+#endif
18212+
18213 /* Start of data section */
18214 _sdata = .;
18215
18216 /* init_task */
18217 INIT_TASK_DATA(THREAD_SIZE)
18218
18219-#ifdef CONFIG_X86_32
18220- /* 32 bit has nosave before _edata */
18221 NOSAVE_DATA
18222-#endif
18223
18224 PAGE_ALIGNED_DATA(PAGE_SIZE)
18225
18226@@ -112,6 +175,8 @@ SECTIONS
18227 DATA_DATA
18228 CONSTRUCTORS
18229
18230+ jiffies = jiffies_64;
18231+
18232 /* rarely changed data like cpu maps */
18233 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
18234
18235@@ -166,12 +231,6 @@ SECTIONS
18236 }
18237 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18238
18239- . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
18240- .jiffies : AT(VLOAD(.jiffies)) {
18241- *(.jiffies)
18242- }
18243- jiffies = VVIRT(.jiffies);
18244-
18245 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18246 *(.vsyscall_3)
18247 }
18248@@ -187,12 +246,19 @@ SECTIONS
18249 #endif /* CONFIG_X86_64 */
18250
18251 /* Init code and data - will be freed after init */
18252- . = ALIGN(PAGE_SIZE);
18253 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18254+ BYTE(0)
18255+
18256+#ifdef CONFIG_PAX_KERNEXEC
18257+ . = ALIGN(HPAGE_SIZE);
18258+#else
18259+ . = ALIGN(PAGE_SIZE);
18260+#endif
18261+
18262 __init_begin = .; /* paired with __init_end */
18263- }
18264+ } :init.begin
18265
18266-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18267+#ifdef CONFIG_SMP
18268 /*
18269 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18270 * output PHDR, so the next output section - .init.text - should
18271@@ -201,12 +267,27 @@ SECTIONS
18272 PERCPU_VADDR(0, :percpu)
18273 #endif
18274
18275- INIT_TEXT_SECTION(PAGE_SIZE)
18276-#ifdef CONFIG_X86_64
18277- :init
18278-#endif
18279+ . = ALIGN(PAGE_SIZE);
18280+ init_begin = .;
18281+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18282+ VMLINUX_SYMBOL(_sinittext) = .;
18283+ INIT_TEXT
18284+ VMLINUX_SYMBOL(_einittext) = .;
18285+ . = ALIGN(PAGE_SIZE);
18286+ } :text.init
18287
18288- INIT_DATA_SECTION(16)
18289+ /*
18290+ * .exit.text is discard at runtime, not link time, to deal with
18291+ * references from .altinstructions and .eh_frame
18292+ */
18293+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18294+ EXIT_TEXT
18295+ . = ALIGN(16);
18296+ } :text.exit
18297+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18298+
18299+ . = ALIGN(PAGE_SIZE);
18300+ INIT_DATA_SECTION(16) :init
18301
18302 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
18303 __x86_cpu_dev_start = .;
18304@@ -232,19 +313,11 @@ SECTIONS
18305 *(.altinstr_replacement)
18306 }
18307
18308- /*
18309- * .exit.text is discard at runtime, not link time, to deal with
18310- * references from .altinstructions and .eh_frame
18311- */
18312- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18313- EXIT_TEXT
18314- }
18315-
18316 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18317 EXIT_DATA
18318 }
18319
18320-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18321+#ifndef CONFIG_SMP
18322 PERCPU(PAGE_SIZE)
18323 #endif
18324
18325@@ -267,12 +340,6 @@ SECTIONS
18326 . = ALIGN(PAGE_SIZE);
18327 }
18328
18329-#ifdef CONFIG_X86_64
18330- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18331- NOSAVE_DATA
18332- }
18333-#endif
18334-
18335 /* BSS */
18336 . = ALIGN(PAGE_SIZE);
18337 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18338@@ -288,6 +355,7 @@ SECTIONS
18339 __brk_base = .;
18340 . += 64 * 1024; /* 64k alignment slop space */
18341 *(.brk_reservation) /* areas brk users have reserved */
18342+ . = ALIGN(HPAGE_SIZE);
18343 __brk_limit = .;
18344 }
18345
18346@@ -316,13 +384,12 @@ SECTIONS
18347 * for the boot processor.
18348 */
18349 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
18350-INIT_PER_CPU(gdt_page);
18351 INIT_PER_CPU(irq_stack_union);
18352
18353 /*
18354 * Build-time check on the image size:
18355 */
18356-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18357+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18358 "kernel image bigger than KERNEL_IMAGE_SIZE");
18359
18360 #ifdef CONFIG_SMP
18361diff -urNp linux-2.6.32.43/arch/x86/kernel/vsyscall_64.c linux-2.6.32.43/arch/x86/kernel/vsyscall_64.c
18362--- linux-2.6.32.43/arch/x86/kernel/vsyscall_64.c 2011-03-27 14:31:47.000000000 -0400
18363+++ linux-2.6.32.43/arch/x86/kernel/vsyscall_64.c 2011-04-23 12:56:10.000000000 -0400
18364@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18365
18366 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18367 /* copy vsyscall data */
18368+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18369 vsyscall_gtod_data.clock.vread = clock->vread;
18370 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18371 vsyscall_gtod_data.clock.mask = clock->mask;
18372@@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18373 We do this here because otherwise user space would do it on
18374 its own in a likely inferior way (no access to jiffies).
18375 If you don't like it pass NULL. */
18376- if (tcache && tcache->blob[0] == (j = __jiffies)) {
18377+ if (tcache && tcache->blob[0] == (j = jiffies)) {
18378 p = tcache->blob[1];
18379 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18380 /* Load per CPU data from RDTSCP */
18381diff -urNp linux-2.6.32.43/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.32.43/arch/x86/kernel/x8664_ksyms_64.c
18382--- linux-2.6.32.43/arch/x86/kernel/x8664_ksyms_64.c 2011-03-27 14:31:47.000000000 -0400
18383+++ linux-2.6.32.43/arch/x86/kernel/x8664_ksyms_64.c 2011-04-17 15:56:46.000000000 -0400
18384@@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
18385
18386 EXPORT_SYMBOL(copy_user_generic);
18387 EXPORT_SYMBOL(__copy_user_nocache);
18388-EXPORT_SYMBOL(copy_from_user);
18389-EXPORT_SYMBOL(copy_to_user);
18390 EXPORT_SYMBOL(__copy_from_user_inatomic);
18391
18392 EXPORT_SYMBOL(copy_page);
18393diff -urNp linux-2.6.32.43/arch/x86/kernel/xsave.c linux-2.6.32.43/arch/x86/kernel/xsave.c
18394--- linux-2.6.32.43/arch/x86/kernel/xsave.c 2011-03-27 14:31:47.000000000 -0400
18395+++ linux-2.6.32.43/arch/x86/kernel/xsave.c 2011-04-17 15:56:46.000000000 -0400
18396@@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_
18397 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18398 return -1;
18399
18400- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18401+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18402 fx_sw_user->extended_size -
18403 FP_XSTATE_MAGIC2_SIZE));
18404 /*
18405@@ -196,7 +196,7 @@ fx_only:
18406 * the other extended state.
18407 */
18408 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18409- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18410+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18411 }
18412
18413 /*
18414@@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf
18415 if (task_thread_info(tsk)->status & TS_XSAVE)
18416 err = restore_user_xstate(buf);
18417 else
18418- err = fxrstor_checking((__force struct i387_fxsave_struct *)
18419+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
18420 buf);
18421 if (unlikely(err)) {
18422 /*
18423diff -urNp linux-2.6.32.43/arch/x86/kvm/emulate.c linux-2.6.32.43/arch/x86/kvm/emulate.c
18424--- linux-2.6.32.43/arch/x86/kvm/emulate.c 2011-03-27 14:31:47.000000000 -0400
18425+++ linux-2.6.32.43/arch/x86/kvm/emulate.c 2011-04-17 15:56:46.000000000 -0400
18426@@ -81,8 +81,8 @@
18427 #define Src2CL (1<<29)
18428 #define Src2ImmByte (2<<29)
18429 #define Src2One (3<<29)
18430-#define Src2Imm16 (4<<29)
18431-#define Src2Mask (7<<29)
18432+#define Src2Imm16 (4U<<29)
18433+#define Src2Mask (7U<<29)
18434
18435 enum {
18436 Group1_80, Group1_81, Group1_82, Group1_83,
18437@@ -411,6 +411,7 @@ static u32 group2_table[] = {
18438
18439 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
18440 do { \
18441+ unsigned long _tmp; \
18442 __asm__ __volatile__ ( \
18443 _PRE_EFLAGS("0", "4", "2") \
18444 _op _suffix " %"_x"3,%1; " \
18445@@ -424,8 +425,6 @@ static u32 group2_table[] = {
18446 /* Raw emulation: instruction has two explicit operands. */
18447 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18448 do { \
18449- unsigned long _tmp; \
18450- \
18451 switch ((_dst).bytes) { \
18452 case 2: \
18453 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
18454@@ -441,7 +440,6 @@ static u32 group2_table[] = {
18455
18456 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18457 do { \
18458- unsigned long _tmp; \
18459 switch ((_dst).bytes) { \
18460 case 1: \
18461 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
18462diff -urNp linux-2.6.32.43/arch/x86/kvm/lapic.c linux-2.6.32.43/arch/x86/kvm/lapic.c
18463--- linux-2.6.32.43/arch/x86/kvm/lapic.c 2011-03-27 14:31:47.000000000 -0400
18464+++ linux-2.6.32.43/arch/x86/kvm/lapic.c 2011-04-17 15:56:46.000000000 -0400
18465@@ -52,7 +52,7 @@
18466 #define APIC_BUS_CYCLE_NS 1
18467
18468 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18469-#define apic_debug(fmt, arg...)
18470+#define apic_debug(fmt, arg...) do {} while (0)
18471
18472 #define APIC_LVT_NUM 6
18473 /* 14 is the version for Xeon and Pentium 8.4.8*/
18474diff -urNp linux-2.6.32.43/arch/x86/kvm/paging_tmpl.h linux-2.6.32.43/arch/x86/kvm/paging_tmpl.h
18475--- linux-2.6.32.43/arch/x86/kvm/paging_tmpl.h 2011-03-27 14:31:47.000000000 -0400
18476+++ linux-2.6.32.43/arch/x86/kvm/paging_tmpl.h 2011-05-16 21:46:57.000000000 -0400
18477@@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_
18478 int level = PT_PAGE_TABLE_LEVEL;
18479 unsigned long mmu_seq;
18480
18481+ pax_track_stack();
18482+
18483 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18484 kvm_mmu_audit(vcpu, "pre page fault");
18485
18486diff -urNp linux-2.6.32.43/arch/x86/kvm/svm.c linux-2.6.32.43/arch/x86/kvm/svm.c
18487--- linux-2.6.32.43/arch/x86/kvm/svm.c 2011-03-27 14:31:47.000000000 -0400
18488+++ linux-2.6.32.43/arch/x86/kvm/svm.c 2011-08-05 20:33:55.000000000 -0400
18489@@ -2485,7 +2485,11 @@ static void reload_tss(struct kvm_vcpu *
18490 int cpu = raw_smp_processor_id();
18491
18492 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
18493+
18494+ pax_open_kernel();
18495 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
18496+ pax_close_kernel();
18497+
18498 load_TR_desc();
18499 }
18500
18501@@ -2946,7 +2950,7 @@ static bool svm_gb_page_enable(void)
18502 return true;
18503 }
18504
18505-static struct kvm_x86_ops svm_x86_ops = {
18506+static const struct kvm_x86_ops svm_x86_ops = {
18507 .cpu_has_kvm_support = has_svm,
18508 .disabled_by_bios = is_disabled,
18509 .hardware_setup = svm_hardware_setup,
18510diff -urNp linux-2.6.32.43/arch/x86/kvm/vmx.c linux-2.6.32.43/arch/x86/kvm/vmx.c
18511--- linux-2.6.32.43/arch/x86/kvm/vmx.c 2011-03-27 14:31:47.000000000 -0400
18512+++ linux-2.6.32.43/arch/x86/kvm/vmx.c 2011-05-04 17:56:20.000000000 -0400
18513@@ -570,7 +570,11 @@ static void reload_tss(void)
18514
18515 kvm_get_gdt(&gdt);
18516 descs = (void *)gdt.base;
18517+
18518+ pax_open_kernel();
18519 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18520+ pax_close_kernel();
18521+
18522 load_TR_desc();
18523 }
18524
18525@@ -1409,8 +1413,11 @@ static __init int hardware_setup(void)
18526 if (!cpu_has_vmx_flexpriority())
18527 flexpriority_enabled = 0;
18528
18529- if (!cpu_has_vmx_tpr_shadow())
18530- kvm_x86_ops->update_cr8_intercept = NULL;
18531+ if (!cpu_has_vmx_tpr_shadow()) {
18532+ pax_open_kernel();
18533+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18534+ pax_close_kernel();
18535+ }
18536
18537 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18538 kvm_disable_largepages();
18539@@ -2361,7 +2368,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18540 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
18541
18542 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18543- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18544+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18545 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18546 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18547 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
18548@@ -3717,6 +3724,12 @@ static void vmx_vcpu_run(struct kvm_vcpu
18549 "jmp .Lkvm_vmx_return \n\t"
18550 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18551 ".Lkvm_vmx_return: "
18552+
18553+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18554+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18555+ ".Lkvm_vmx_return2: "
18556+#endif
18557+
18558 /* Save guest registers, load host registers, keep flags */
18559 "xchg %0, (%%"R"sp) \n\t"
18560 "mov %%"R"ax, %c[rax](%0) \n\t"
18561@@ -3763,8 +3776,13 @@ static void vmx_vcpu_run(struct kvm_vcpu
18562 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
18563 #endif
18564 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
18565+
18566+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18567+ ,[cs]"i"(__KERNEL_CS)
18568+#endif
18569+
18570 : "cc", "memory"
18571- , R"bx", R"di", R"si"
18572+ , R"ax", R"bx", R"di", R"si"
18573 #ifdef CONFIG_X86_64
18574 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
18575 #endif
18576@@ -3781,7 +3799,16 @@ static void vmx_vcpu_run(struct kvm_vcpu
18577 if (vmx->rmode.irq.pending)
18578 fixup_rmode_irq(vmx);
18579
18580- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18581+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18582+
18583+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18584+ loadsegment(fs, __KERNEL_PERCPU);
18585+#endif
18586+
18587+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18588+ __set_fs(current_thread_info()->addr_limit);
18589+#endif
18590+
18591 vmx->launched = 1;
18592
18593 vmx_complete_interrupts(vmx);
18594@@ -3956,7 +3983,7 @@ static bool vmx_gb_page_enable(void)
18595 return false;
18596 }
18597
18598-static struct kvm_x86_ops vmx_x86_ops = {
18599+static const struct kvm_x86_ops vmx_x86_ops = {
18600 .cpu_has_kvm_support = cpu_has_kvm_support,
18601 .disabled_by_bios = vmx_disabled_by_bios,
18602 .hardware_setup = hardware_setup,
18603diff -urNp linux-2.6.32.43/arch/x86/kvm/x86.c linux-2.6.32.43/arch/x86/kvm/x86.c
18604--- linux-2.6.32.43/arch/x86/kvm/x86.c 2011-05-10 22:12:01.000000000 -0400
18605+++ linux-2.6.32.43/arch/x86/kvm/x86.c 2011-05-10 22:12:26.000000000 -0400
18606@@ -82,7 +82,7 @@ static void update_cr8_intercept(struct
18607 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18608 struct kvm_cpuid_entry2 __user *entries);
18609
18610-struct kvm_x86_ops *kvm_x86_ops;
18611+const struct kvm_x86_ops *kvm_x86_ops;
18612 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18613
18614 int ignore_msrs = 0;
18615@@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18616 struct kvm_cpuid2 *cpuid,
18617 struct kvm_cpuid_entry2 __user *entries)
18618 {
18619- int r;
18620+ int r, i;
18621
18622 r = -E2BIG;
18623 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18624 goto out;
18625 r = -EFAULT;
18626- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18627- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18628+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18629 goto out;
18630+ for (i = 0; i < cpuid->nent; ++i) {
18631+ struct kvm_cpuid_entry2 cpuid_entry;
18632+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18633+ goto out;
18634+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
18635+ }
18636 vcpu->arch.cpuid_nent = cpuid->nent;
18637 kvm_apic_set_version(vcpu);
18638 return 0;
18639@@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18640 struct kvm_cpuid2 *cpuid,
18641 struct kvm_cpuid_entry2 __user *entries)
18642 {
18643- int r;
18644+ int r, i;
18645
18646 vcpu_load(vcpu);
18647 r = -E2BIG;
18648 if (cpuid->nent < vcpu->arch.cpuid_nent)
18649 goto out;
18650 r = -EFAULT;
18651- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18652- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18653+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18654 goto out;
18655+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18656+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18657+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18658+ goto out;
18659+ }
18660 return 0;
18661
18662 out:
18663@@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18664 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18665 struct kvm_interrupt *irq)
18666 {
18667- if (irq->irq < 0 || irq->irq >= 256)
18668+ if (irq->irq >= 256)
18669 return -EINVAL;
18670 if (irqchip_in_kernel(vcpu->kvm))
18671 return -ENXIO;
18672@@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cp
18673 .notifier_call = kvmclock_cpufreq_notifier
18674 };
18675
18676-int kvm_arch_init(void *opaque)
18677+int kvm_arch_init(const void *opaque)
18678 {
18679 int r, cpu;
18680- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18681+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18682
18683 if (kvm_x86_ops) {
18684 printk(KERN_ERR "kvm: already loaded the other module\n");
18685diff -urNp linux-2.6.32.43/arch/x86/lguest/boot.c linux-2.6.32.43/arch/x86/lguest/boot.c
18686--- linux-2.6.32.43/arch/x86/lguest/boot.c 2011-03-27 14:31:47.000000000 -0400
18687+++ linux-2.6.32.43/arch/x86/lguest/boot.c 2011-08-05 20:33:55.000000000 -0400
18688@@ -1172,9 +1172,10 @@ static __init int early_put_chars(u32 vt
18689 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18690 * Launcher to reboot us.
18691 */
18692-static void lguest_restart(char *reason)
18693+static __noreturn void lguest_restart(char *reason)
18694 {
18695 kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART);
18696+ BUG();
18697 }
18698
18699 /*G:050
18700diff -urNp linux-2.6.32.43/arch/x86/lib/atomic64_32.c linux-2.6.32.43/arch/x86/lib/atomic64_32.c
18701--- linux-2.6.32.43/arch/x86/lib/atomic64_32.c 2011-03-27 14:31:47.000000000 -0400
18702+++ linux-2.6.32.43/arch/x86/lib/atomic64_32.c 2011-05-04 17:56:28.000000000 -0400
18703@@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u6
18704 }
18705 EXPORT_SYMBOL(atomic64_cmpxchg);
18706
18707+u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
18708+{
18709+ return cmpxchg8b(&ptr->counter, old_val, new_val);
18710+}
18711+EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
18712+
18713 /**
18714 * atomic64_xchg - xchg atomic64 variable
18715 * @ptr: pointer to type atomic64_t
18716@@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 n
18717 EXPORT_SYMBOL(atomic64_xchg);
18718
18719 /**
18720+ * atomic64_xchg_unchecked - xchg atomic64 variable
18721+ * @ptr: pointer to type atomic64_unchecked_t
18722+ * @new_val: value to assign
18723+ *
18724+ * Atomically xchgs the value of @ptr to @new_val and returns
18725+ * the old value.
18726+ */
18727+u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
18728+{
18729+ /*
18730+ * Try first with a (possibly incorrect) assumption about
18731+ * what we have there. We'll do two loops most likely,
18732+ * but we'll get an ownership MESI transaction straight away
18733+ * instead of a read transaction followed by a
18734+ * flush-for-ownership transaction:
18735+ */
18736+ u64 old_val, real_val = 0;
18737+
18738+ do {
18739+ old_val = real_val;
18740+
18741+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
18742+
18743+ } while (real_val != old_val);
18744+
18745+ return old_val;
18746+}
18747+EXPORT_SYMBOL(atomic64_xchg_unchecked);
18748+
18749+/**
18750 * atomic64_set - set atomic64 variable
18751 * @ptr: pointer to type atomic64_t
18752 * @new_val: value to assign
18753@@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 n
18754 EXPORT_SYMBOL(atomic64_set);
18755
18756 /**
18757-EXPORT_SYMBOL(atomic64_read);
18758+ * atomic64_unchecked_set - set atomic64 variable
18759+ * @ptr: pointer to type atomic64_unchecked_t
18760+ * @new_val: value to assign
18761+ *
18762+ * Atomically sets the value of @ptr to @new_val.
18763+ */
18764+void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
18765+{
18766+ atomic64_xchg_unchecked(ptr, new_val);
18767+}
18768+EXPORT_SYMBOL(atomic64_set_unchecked);
18769+
18770+/**
18771 * atomic64_add_return - add and return
18772 * @delta: integer value to add
18773 * @ptr: pointer to type atomic64_t
18774@@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 del
18775 }
18776 EXPORT_SYMBOL(atomic64_add_return);
18777
18778+/**
18779+ * atomic64_add_return_unchecked - add and return
18780+ * @delta: integer value to add
18781+ * @ptr: pointer to type atomic64_unchecked_t
18782+ *
18783+ * Atomically adds @delta to @ptr and returns @delta + *@ptr
18784+ */
18785+noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18786+{
18787+ /*
18788+ * Try first with a (possibly incorrect) assumption about
18789+ * what we have there. We'll do two loops most likely,
18790+ * but we'll get an ownership MESI transaction straight away
18791+ * instead of a read transaction followed by a
18792+ * flush-for-ownership transaction:
18793+ */
18794+ u64 old_val, new_val, real_val = 0;
18795+
18796+ do {
18797+ old_val = real_val;
18798+ new_val = old_val + delta;
18799+
18800+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
18801+
18802+ } while (real_val != old_val);
18803+
18804+ return new_val;
18805+}
18806+EXPORT_SYMBOL(atomic64_add_return_unchecked);
18807+
18808 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
18809 {
18810 return atomic64_add_return(-delta, ptr);
18811 }
18812 EXPORT_SYMBOL(atomic64_sub_return);
18813
18814+u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18815+{
18816+ return atomic64_add_return_unchecked(-delta, ptr);
18817+}
18818+EXPORT_SYMBOL(atomic64_sub_return_unchecked);
18819+
18820 u64 atomic64_inc_return(atomic64_t *ptr)
18821 {
18822 return atomic64_add_return(1, ptr);
18823 }
18824 EXPORT_SYMBOL(atomic64_inc_return);
18825
18826+u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
18827+{
18828+ return atomic64_add_return_unchecked(1, ptr);
18829+}
18830+EXPORT_SYMBOL(atomic64_inc_return_unchecked);
18831+
18832 u64 atomic64_dec_return(atomic64_t *ptr)
18833 {
18834 return atomic64_sub_return(1, ptr);
18835 }
18836 EXPORT_SYMBOL(atomic64_dec_return);
18837
18838+u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
18839+{
18840+ return atomic64_sub_return_unchecked(1, ptr);
18841+}
18842+EXPORT_SYMBOL(atomic64_dec_return_unchecked);
18843+
18844 /**
18845 * atomic64_add - add integer to atomic64 variable
18846 * @delta: integer value to add
18847@@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t
18848 EXPORT_SYMBOL(atomic64_add);
18849
18850 /**
18851+ * atomic64_add_unchecked - add integer to atomic64 variable
18852+ * @delta: integer value to add
18853+ * @ptr: pointer to type atomic64_unchecked_t
18854+ *
18855+ * Atomically adds @delta to @ptr.
18856+ */
18857+void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18858+{
18859+ atomic64_add_return_unchecked(delta, ptr);
18860+}
18861+EXPORT_SYMBOL(atomic64_add_unchecked);
18862+
18863+/**
18864 * atomic64_sub - subtract the atomic64 variable
18865 * @delta: integer value to subtract
18866 * @ptr: pointer to type atomic64_t
18867@@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t
18868 EXPORT_SYMBOL(atomic64_sub);
18869
18870 /**
18871+ * atomic64_sub_unchecked - subtract the atomic64 variable
18872+ * @delta: integer value to subtract
18873+ * @ptr: pointer to type atomic64_unchecked_t
18874+ *
18875+ * Atomically subtracts @delta from @ptr.
18876+ */
18877+void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
18878+{
18879+ atomic64_add_unchecked(-delta, ptr);
18880+}
18881+EXPORT_SYMBOL(atomic64_sub_unchecked);
18882+
18883+/**
18884 * atomic64_sub_and_test - subtract value from variable and test result
18885 * @delta: integer value to subtract
18886 * @ptr: pointer to type atomic64_t
18887@@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
18888 EXPORT_SYMBOL(atomic64_inc);
18889
18890 /**
18891+ * atomic64_inc_unchecked - increment atomic64 variable
18892+ * @ptr: pointer to type atomic64_unchecked_t
18893+ *
18894+ * Atomically increments @ptr by 1.
18895+ */
18896+void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
18897+{
18898+ atomic64_add_unchecked(1, ptr);
18899+}
18900+EXPORT_SYMBOL(atomic64_inc_unchecked);
18901+
18902+/**
18903 * atomic64_dec - decrement atomic64 variable
18904 * @ptr: pointer to type atomic64_t
18905 *
18906@@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
18907 EXPORT_SYMBOL(atomic64_dec);
18908
18909 /**
18910+ * atomic64_dec_unchecked - decrement atomic64 variable
18911+ * @ptr: pointer to type atomic64_unchecked_t
18912+ *
18913+ * Atomically decrements @ptr by 1.
18914+ */
18915+void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
18916+{
18917+ atomic64_sub_unchecked(1, ptr);
18918+}
18919+EXPORT_SYMBOL(atomic64_dec_unchecked);
18920+
18921+/**
18922 * atomic64_dec_and_test - decrement and test
18923 * @ptr: pointer to type atomic64_t
18924 *
18925diff -urNp linux-2.6.32.43/arch/x86/lib/checksum_32.S linux-2.6.32.43/arch/x86/lib/checksum_32.S
18926--- linux-2.6.32.43/arch/x86/lib/checksum_32.S 2011-03-27 14:31:47.000000000 -0400
18927+++ linux-2.6.32.43/arch/x86/lib/checksum_32.S 2011-04-17 15:56:46.000000000 -0400
18928@@ -28,7 +28,8 @@
18929 #include <linux/linkage.h>
18930 #include <asm/dwarf2.h>
18931 #include <asm/errno.h>
18932-
18933+#include <asm/segment.h>
18934+
18935 /*
18936 * computes a partial checksum, e.g. for TCP/UDP fragments
18937 */
18938@@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (
18939
18940 #define ARGBASE 16
18941 #define FP 12
18942-
18943-ENTRY(csum_partial_copy_generic)
18944+
18945+ENTRY(csum_partial_copy_generic_to_user)
18946 CFI_STARTPROC
18947+
18948+#ifdef CONFIG_PAX_MEMORY_UDEREF
18949+ pushl %gs
18950+ CFI_ADJUST_CFA_OFFSET 4
18951+ popl %es
18952+ CFI_ADJUST_CFA_OFFSET -4
18953+ jmp csum_partial_copy_generic
18954+#endif
18955+
18956+ENTRY(csum_partial_copy_generic_from_user)
18957+
18958+#ifdef CONFIG_PAX_MEMORY_UDEREF
18959+ pushl %gs
18960+ CFI_ADJUST_CFA_OFFSET 4
18961+ popl %ds
18962+ CFI_ADJUST_CFA_OFFSET -4
18963+#endif
18964+
18965+ENTRY(csum_partial_copy_generic)
18966 subl $4,%esp
18967 CFI_ADJUST_CFA_OFFSET 4
18968 pushl %edi
18969@@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
18970 jmp 4f
18971 SRC(1: movw (%esi), %bx )
18972 addl $2, %esi
18973-DST( movw %bx, (%edi) )
18974+DST( movw %bx, %es:(%edi) )
18975 addl $2, %edi
18976 addw %bx, %ax
18977 adcl $0, %eax
18978@@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
18979 SRC(1: movl (%esi), %ebx )
18980 SRC( movl 4(%esi), %edx )
18981 adcl %ebx, %eax
18982-DST( movl %ebx, (%edi) )
18983+DST( movl %ebx, %es:(%edi) )
18984 adcl %edx, %eax
18985-DST( movl %edx, 4(%edi) )
18986+DST( movl %edx, %es:4(%edi) )
18987
18988 SRC( movl 8(%esi), %ebx )
18989 SRC( movl 12(%esi), %edx )
18990 adcl %ebx, %eax
18991-DST( movl %ebx, 8(%edi) )
18992+DST( movl %ebx, %es:8(%edi) )
18993 adcl %edx, %eax
18994-DST( movl %edx, 12(%edi) )
18995+DST( movl %edx, %es:12(%edi) )
18996
18997 SRC( movl 16(%esi), %ebx )
18998 SRC( movl 20(%esi), %edx )
18999 adcl %ebx, %eax
19000-DST( movl %ebx, 16(%edi) )
19001+DST( movl %ebx, %es:16(%edi) )
19002 adcl %edx, %eax
19003-DST( movl %edx, 20(%edi) )
19004+DST( movl %edx, %es:20(%edi) )
19005
19006 SRC( movl 24(%esi), %ebx )
19007 SRC( movl 28(%esi), %edx )
19008 adcl %ebx, %eax
19009-DST( movl %ebx, 24(%edi) )
19010+DST( movl %ebx, %es:24(%edi) )
19011 adcl %edx, %eax
19012-DST( movl %edx, 28(%edi) )
19013+DST( movl %edx, %es:28(%edi) )
19014
19015 lea 32(%esi), %esi
19016 lea 32(%edi), %edi
19017@@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
19018 shrl $2, %edx # This clears CF
19019 SRC(3: movl (%esi), %ebx )
19020 adcl %ebx, %eax
19021-DST( movl %ebx, (%edi) )
19022+DST( movl %ebx, %es:(%edi) )
19023 lea 4(%esi), %esi
19024 lea 4(%edi), %edi
19025 dec %edx
19026@@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
19027 jb 5f
19028 SRC( movw (%esi), %cx )
19029 leal 2(%esi), %esi
19030-DST( movw %cx, (%edi) )
19031+DST( movw %cx, %es:(%edi) )
19032 leal 2(%edi), %edi
19033 je 6f
19034 shll $16,%ecx
19035 SRC(5: movb (%esi), %cl )
19036-DST( movb %cl, (%edi) )
19037+DST( movb %cl, %es:(%edi) )
19038 6: addl %ecx, %eax
19039 adcl $0, %eax
19040 7:
19041@@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
19042
19043 6001:
19044 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19045- movl $-EFAULT, (%ebx)
19046+ movl $-EFAULT, %ss:(%ebx)
19047
19048 # zero the complete destination - computing the rest
19049 # is too much work
19050@@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
19051
19052 6002:
19053 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19054- movl $-EFAULT,(%ebx)
19055+ movl $-EFAULT,%ss:(%ebx)
19056 jmp 5000b
19057
19058 .previous
19059
19060+ pushl %ss
19061+ CFI_ADJUST_CFA_OFFSET 4
19062+ popl %ds
19063+ CFI_ADJUST_CFA_OFFSET -4
19064+ pushl %ss
19065+ CFI_ADJUST_CFA_OFFSET 4
19066+ popl %es
19067+ CFI_ADJUST_CFA_OFFSET -4
19068 popl %ebx
19069 CFI_ADJUST_CFA_OFFSET -4
19070 CFI_RESTORE ebx
19071@@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
19072 CFI_ADJUST_CFA_OFFSET -4
19073 ret
19074 CFI_ENDPROC
19075-ENDPROC(csum_partial_copy_generic)
19076+ENDPROC(csum_partial_copy_generic_to_user)
19077
19078 #else
19079
19080 /* Version for PentiumII/PPro */
19081
19082 #define ROUND1(x) \
19083+ nop; nop; nop; \
19084 SRC(movl x(%esi), %ebx ) ; \
19085 addl %ebx, %eax ; \
19086- DST(movl %ebx, x(%edi) ) ;
19087+ DST(movl %ebx, %es:x(%edi)) ;
19088
19089 #define ROUND(x) \
19090+ nop; nop; nop; \
19091 SRC(movl x(%esi), %ebx ) ; \
19092 adcl %ebx, %eax ; \
19093- DST(movl %ebx, x(%edi) ) ;
19094+ DST(movl %ebx, %es:x(%edi)) ;
19095
19096 #define ARGBASE 12
19097-
19098-ENTRY(csum_partial_copy_generic)
19099+
19100+ENTRY(csum_partial_copy_generic_to_user)
19101 CFI_STARTPROC
19102+
19103+#ifdef CONFIG_PAX_MEMORY_UDEREF
19104+ pushl %gs
19105+ CFI_ADJUST_CFA_OFFSET 4
19106+ popl %es
19107+ CFI_ADJUST_CFA_OFFSET -4
19108+ jmp csum_partial_copy_generic
19109+#endif
19110+
19111+ENTRY(csum_partial_copy_generic_from_user)
19112+
19113+#ifdef CONFIG_PAX_MEMORY_UDEREF
19114+ pushl %gs
19115+ CFI_ADJUST_CFA_OFFSET 4
19116+ popl %ds
19117+ CFI_ADJUST_CFA_OFFSET -4
19118+#endif
19119+
19120+ENTRY(csum_partial_copy_generic)
19121 pushl %ebx
19122 CFI_ADJUST_CFA_OFFSET 4
19123 CFI_REL_OFFSET ebx, 0
19124@@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
19125 subl %ebx, %edi
19126 lea -1(%esi),%edx
19127 andl $-32,%edx
19128- lea 3f(%ebx,%ebx), %ebx
19129+ lea 3f(%ebx,%ebx,2), %ebx
19130 testl %esi, %esi
19131 jmp *%ebx
19132 1: addl $64,%esi
19133@@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
19134 jb 5f
19135 SRC( movw (%esi), %dx )
19136 leal 2(%esi), %esi
19137-DST( movw %dx, (%edi) )
19138+DST( movw %dx, %es:(%edi) )
19139 leal 2(%edi), %edi
19140 je 6f
19141 shll $16,%edx
19142 5:
19143 SRC( movb (%esi), %dl )
19144-DST( movb %dl, (%edi) )
19145+DST( movb %dl, %es:(%edi) )
19146 6: addl %edx, %eax
19147 adcl $0, %eax
19148 7:
19149 .section .fixup, "ax"
19150 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19151- movl $-EFAULT, (%ebx)
19152+ movl $-EFAULT, %ss:(%ebx)
19153 # zero the complete destination (computing the rest is too much work)
19154 movl ARGBASE+8(%esp),%edi # dst
19155 movl ARGBASE+12(%esp),%ecx # len
19156@@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
19157 rep; stosb
19158 jmp 7b
19159 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19160- movl $-EFAULT, (%ebx)
19161+ movl $-EFAULT, %ss:(%ebx)
19162 jmp 7b
19163 .previous
19164
19165+#ifdef CONFIG_PAX_MEMORY_UDEREF
19166+ pushl %ss
19167+ CFI_ADJUST_CFA_OFFSET 4
19168+ popl %ds
19169+ CFI_ADJUST_CFA_OFFSET -4
19170+ pushl %ss
19171+ CFI_ADJUST_CFA_OFFSET 4
19172+ popl %es
19173+ CFI_ADJUST_CFA_OFFSET -4
19174+#endif
19175+
19176 popl %esi
19177 CFI_ADJUST_CFA_OFFSET -4
19178 CFI_RESTORE esi
19179@@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
19180 CFI_RESTORE ebx
19181 ret
19182 CFI_ENDPROC
19183-ENDPROC(csum_partial_copy_generic)
19184+ENDPROC(csum_partial_copy_generic_to_user)
19185
19186 #undef ROUND
19187 #undef ROUND1
19188diff -urNp linux-2.6.32.43/arch/x86/lib/clear_page_64.S linux-2.6.32.43/arch/x86/lib/clear_page_64.S
19189--- linux-2.6.32.43/arch/x86/lib/clear_page_64.S 2011-03-27 14:31:47.000000000 -0400
19190+++ linux-2.6.32.43/arch/x86/lib/clear_page_64.S 2011-04-17 15:56:46.000000000 -0400
19191@@ -43,7 +43,7 @@ ENDPROC(clear_page)
19192
19193 #include <asm/cpufeature.h>
19194
19195- .section .altinstr_replacement,"ax"
19196+ .section .altinstr_replacement,"a"
19197 1: .byte 0xeb /* jmp <disp8> */
19198 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19199 2:
19200diff -urNp linux-2.6.32.43/arch/x86/lib/copy_page_64.S linux-2.6.32.43/arch/x86/lib/copy_page_64.S
19201--- linux-2.6.32.43/arch/x86/lib/copy_page_64.S 2011-03-27 14:31:47.000000000 -0400
19202+++ linux-2.6.32.43/arch/x86/lib/copy_page_64.S 2011-04-17 15:56:46.000000000 -0400
19203@@ -104,7 +104,7 @@ ENDPROC(copy_page)
19204
19205 #include <asm/cpufeature.h>
19206
19207- .section .altinstr_replacement,"ax"
19208+ .section .altinstr_replacement,"a"
19209 1: .byte 0xeb /* jmp <disp8> */
19210 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19211 2:
19212diff -urNp linux-2.6.32.43/arch/x86/lib/copy_user_64.S linux-2.6.32.43/arch/x86/lib/copy_user_64.S
19213--- linux-2.6.32.43/arch/x86/lib/copy_user_64.S 2011-06-25 12:55:34.000000000 -0400
19214+++ linux-2.6.32.43/arch/x86/lib/copy_user_64.S 2011-06-25 12:56:37.000000000 -0400
19215@@ -15,13 +15,14 @@
19216 #include <asm/asm-offsets.h>
19217 #include <asm/thread_info.h>
19218 #include <asm/cpufeature.h>
19219+#include <asm/pgtable.h>
19220
19221 .macro ALTERNATIVE_JUMP feature,orig,alt
19222 0:
19223 .byte 0xe9 /* 32bit jump */
19224 .long \orig-1f /* by default jump to orig */
19225 1:
19226- .section .altinstr_replacement,"ax"
19227+ .section .altinstr_replacement,"a"
19228 2: .byte 0xe9 /* near jump with 32bit immediate */
19229 .long \alt-1b /* offset */ /* or alternatively to alt */
19230 .previous
19231@@ -64,49 +65,19 @@
19232 #endif
19233 .endm
19234
19235-/* Standard copy_to_user with segment limit checking */
19236-ENTRY(copy_to_user)
19237- CFI_STARTPROC
19238- GET_THREAD_INFO(%rax)
19239- movq %rdi,%rcx
19240- addq %rdx,%rcx
19241- jc bad_to_user
19242- cmpq TI_addr_limit(%rax),%rcx
19243- ja bad_to_user
19244- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19245- CFI_ENDPROC
19246-ENDPROC(copy_to_user)
19247-
19248-/* Standard copy_from_user with segment limit checking */
19249-ENTRY(copy_from_user)
19250- CFI_STARTPROC
19251- GET_THREAD_INFO(%rax)
19252- movq %rsi,%rcx
19253- addq %rdx,%rcx
19254- jc bad_from_user
19255- cmpq TI_addr_limit(%rax),%rcx
19256- ja bad_from_user
19257- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19258- CFI_ENDPROC
19259-ENDPROC(copy_from_user)
19260-
19261 ENTRY(copy_user_generic)
19262 CFI_STARTPROC
19263 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19264 CFI_ENDPROC
19265 ENDPROC(copy_user_generic)
19266
19267-ENTRY(__copy_from_user_inatomic)
19268- CFI_STARTPROC
19269- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19270- CFI_ENDPROC
19271-ENDPROC(__copy_from_user_inatomic)
19272-
19273 .section .fixup,"ax"
19274 /* must zero dest */
19275 ENTRY(bad_from_user)
19276 bad_from_user:
19277 CFI_STARTPROC
19278+ testl %edx,%edx
19279+ js bad_to_user
19280 movl %edx,%ecx
19281 xorl %eax,%eax
19282 rep
19283diff -urNp linux-2.6.32.43/arch/x86/lib/copy_user_nocache_64.S linux-2.6.32.43/arch/x86/lib/copy_user_nocache_64.S
19284--- linux-2.6.32.43/arch/x86/lib/copy_user_nocache_64.S 2011-03-27 14:31:47.000000000 -0400
19285+++ linux-2.6.32.43/arch/x86/lib/copy_user_nocache_64.S 2011-04-17 15:56:46.000000000 -0400
19286@@ -14,6 +14,7 @@
19287 #include <asm/current.h>
19288 #include <asm/asm-offsets.h>
19289 #include <asm/thread_info.h>
19290+#include <asm/pgtable.h>
19291
19292 .macro ALIGN_DESTINATION
19293 #ifdef FIX_ALIGNMENT
19294@@ -50,6 +51,15 @@
19295 */
19296 ENTRY(__copy_user_nocache)
19297 CFI_STARTPROC
19298+
19299+#ifdef CONFIG_PAX_MEMORY_UDEREF
19300+ mov $PAX_USER_SHADOW_BASE,%rcx
19301+ cmp %rcx,%rsi
19302+ jae 1f
19303+ add %rcx,%rsi
19304+1:
19305+#endif
19306+
19307 cmpl $8,%edx
19308 jb 20f /* less then 8 bytes, go to byte copy loop */
19309 ALIGN_DESTINATION
19310diff -urNp linux-2.6.32.43/arch/x86/lib/csum-wrappers_64.c linux-2.6.32.43/arch/x86/lib/csum-wrappers_64.c
19311--- linux-2.6.32.43/arch/x86/lib/csum-wrappers_64.c 2011-03-27 14:31:47.000000000 -0400
19312+++ linux-2.6.32.43/arch/x86/lib/csum-wrappers_64.c 2011-05-04 17:56:20.000000000 -0400
19313@@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19314 len -= 2;
19315 }
19316 }
19317+
19318+#ifdef CONFIG_PAX_MEMORY_UDEREF
19319+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19320+ src += PAX_USER_SHADOW_BASE;
19321+#endif
19322+
19323 isum = csum_partial_copy_generic((__force const void *)src,
19324 dst, len, isum, errp, NULL);
19325 if (unlikely(*errp))
19326@@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19327 }
19328
19329 *errp = 0;
19330+
19331+#ifdef CONFIG_PAX_MEMORY_UDEREF
19332+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19333+ dst += PAX_USER_SHADOW_BASE;
19334+#endif
19335+
19336 return csum_partial_copy_generic(src, (void __force *)dst,
19337 len, isum, NULL, errp);
19338 }
19339diff -urNp linux-2.6.32.43/arch/x86/lib/getuser.S linux-2.6.32.43/arch/x86/lib/getuser.S
19340--- linux-2.6.32.43/arch/x86/lib/getuser.S 2011-03-27 14:31:47.000000000 -0400
19341+++ linux-2.6.32.43/arch/x86/lib/getuser.S 2011-04-17 15:56:46.000000000 -0400
19342@@ -33,14 +33,35 @@
19343 #include <asm/asm-offsets.h>
19344 #include <asm/thread_info.h>
19345 #include <asm/asm.h>
19346+#include <asm/segment.h>
19347+#include <asm/pgtable.h>
19348+
19349+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19350+#define __copyuser_seg gs;
19351+#else
19352+#define __copyuser_seg
19353+#endif
19354
19355 .text
19356 ENTRY(__get_user_1)
19357 CFI_STARTPROC
19358+
19359+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19360 GET_THREAD_INFO(%_ASM_DX)
19361 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19362 jae bad_get_user
19363-1: movzb (%_ASM_AX),%edx
19364+
19365+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19366+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19367+ cmp %_ASM_DX,%_ASM_AX
19368+ jae 1234f
19369+ add %_ASM_DX,%_ASM_AX
19370+1234:
19371+#endif
19372+
19373+#endif
19374+
19375+1: __copyuser_seg movzb (%_ASM_AX),%edx
19376 xor %eax,%eax
19377 ret
19378 CFI_ENDPROC
19379@@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19380 ENTRY(__get_user_2)
19381 CFI_STARTPROC
19382 add $1,%_ASM_AX
19383+
19384+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19385 jc bad_get_user
19386 GET_THREAD_INFO(%_ASM_DX)
19387 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19388 jae bad_get_user
19389-2: movzwl -1(%_ASM_AX),%edx
19390+
19391+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19392+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19393+ cmp %_ASM_DX,%_ASM_AX
19394+ jae 1234f
19395+ add %_ASM_DX,%_ASM_AX
19396+1234:
19397+#endif
19398+
19399+#endif
19400+
19401+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19402 xor %eax,%eax
19403 ret
19404 CFI_ENDPROC
19405@@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19406 ENTRY(__get_user_4)
19407 CFI_STARTPROC
19408 add $3,%_ASM_AX
19409+
19410+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19411 jc bad_get_user
19412 GET_THREAD_INFO(%_ASM_DX)
19413 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19414 jae bad_get_user
19415-3: mov -3(%_ASM_AX),%edx
19416+
19417+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19418+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19419+ cmp %_ASM_DX,%_ASM_AX
19420+ jae 1234f
19421+ add %_ASM_DX,%_ASM_AX
19422+1234:
19423+#endif
19424+
19425+#endif
19426+
19427+3: __copyuser_seg mov -3(%_ASM_AX),%edx
19428 xor %eax,%eax
19429 ret
19430 CFI_ENDPROC
19431@@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19432 GET_THREAD_INFO(%_ASM_DX)
19433 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19434 jae bad_get_user
19435+
19436+#ifdef CONFIG_PAX_MEMORY_UDEREF
19437+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19438+ cmp %_ASM_DX,%_ASM_AX
19439+ jae 1234f
19440+ add %_ASM_DX,%_ASM_AX
19441+1234:
19442+#endif
19443+
19444 4: movq -7(%_ASM_AX),%_ASM_DX
19445 xor %eax,%eax
19446 ret
19447diff -urNp linux-2.6.32.43/arch/x86/lib/memcpy_64.S linux-2.6.32.43/arch/x86/lib/memcpy_64.S
19448--- linux-2.6.32.43/arch/x86/lib/memcpy_64.S 2011-03-27 14:31:47.000000000 -0400
19449+++ linux-2.6.32.43/arch/x86/lib/memcpy_64.S 2011-04-17 15:56:46.000000000 -0400
19450@@ -128,7 +128,7 @@ ENDPROC(__memcpy)
19451 * It is also a lot simpler. Use this when possible:
19452 */
19453
19454- .section .altinstr_replacement, "ax"
19455+ .section .altinstr_replacement, "a"
19456 1: .byte 0xeb /* jmp <disp8> */
19457 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
19458 2:
19459diff -urNp linux-2.6.32.43/arch/x86/lib/memset_64.S linux-2.6.32.43/arch/x86/lib/memset_64.S
19460--- linux-2.6.32.43/arch/x86/lib/memset_64.S 2011-03-27 14:31:47.000000000 -0400
19461+++ linux-2.6.32.43/arch/x86/lib/memset_64.S 2011-04-17 15:56:46.000000000 -0400
19462@@ -118,7 +118,7 @@ ENDPROC(__memset)
19463
19464 #include <asm/cpufeature.h>
19465
19466- .section .altinstr_replacement,"ax"
19467+ .section .altinstr_replacement,"a"
19468 1: .byte 0xeb /* jmp <disp8> */
19469 .byte (memset_c - memset) - (2f - 1b) /* offset */
19470 2:
19471diff -urNp linux-2.6.32.43/arch/x86/lib/mmx_32.c linux-2.6.32.43/arch/x86/lib/mmx_32.c
19472--- linux-2.6.32.43/arch/x86/lib/mmx_32.c 2011-03-27 14:31:47.000000000 -0400
19473+++ linux-2.6.32.43/arch/x86/lib/mmx_32.c 2011-04-17 15:56:46.000000000 -0400
19474@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19475 {
19476 void *p;
19477 int i;
19478+ unsigned long cr0;
19479
19480 if (unlikely(in_interrupt()))
19481 return __memcpy(to, from, len);
19482@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19483 kernel_fpu_begin();
19484
19485 __asm__ __volatile__ (
19486- "1: prefetch (%0)\n" /* This set is 28 bytes */
19487- " prefetch 64(%0)\n"
19488- " prefetch 128(%0)\n"
19489- " prefetch 192(%0)\n"
19490- " prefetch 256(%0)\n"
19491+ "1: prefetch (%1)\n" /* This set is 28 bytes */
19492+ " prefetch 64(%1)\n"
19493+ " prefetch 128(%1)\n"
19494+ " prefetch 192(%1)\n"
19495+ " prefetch 256(%1)\n"
19496 "2: \n"
19497 ".section .fixup, \"ax\"\n"
19498- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19499+ "3: \n"
19500+
19501+#ifdef CONFIG_PAX_KERNEXEC
19502+ " movl %%cr0, %0\n"
19503+ " movl %0, %%eax\n"
19504+ " andl $0xFFFEFFFF, %%eax\n"
19505+ " movl %%eax, %%cr0\n"
19506+#endif
19507+
19508+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19509+
19510+#ifdef CONFIG_PAX_KERNEXEC
19511+ " movl %0, %%cr0\n"
19512+#endif
19513+
19514 " jmp 2b\n"
19515 ".previous\n"
19516 _ASM_EXTABLE(1b, 3b)
19517- : : "r" (from));
19518+ : "=&r" (cr0) : "r" (from) : "ax");
19519
19520 for ( ; i > 5; i--) {
19521 __asm__ __volatile__ (
19522- "1: prefetch 320(%0)\n"
19523- "2: movq (%0), %%mm0\n"
19524- " movq 8(%0), %%mm1\n"
19525- " movq 16(%0), %%mm2\n"
19526- " movq 24(%0), %%mm3\n"
19527- " movq %%mm0, (%1)\n"
19528- " movq %%mm1, 8(%1)\n"
19529- " movq %%mm2, 16(%1)\n"
19530- " movq %%mm3, 24(%1)\n"
19531- " movq 32(%0), %%mm0\n"
19532- " movq 40(%0), %%mm1\n"
19533- " movq 48(%0), %%mm2\n"
19534- " movq 56(%0), %%mm3\n"
19535- " movq %%mm0, 32(%1)\n"
19536- " movq %%mm1, 40(%1)\n"
19537- " movq %%mm2, 48(%1)\n"
19538- " movq %%mm3, 56(%1)\n"
19539+ "1: prefetch 320(%1)\n"
19540+ "2: movq (%1), %%mm0\n"
19541+ " movq 8(%1), %%mm1\n"
19542+ " movq 16(%1), %%mm2\n"
19543+ " movq 24(%1), %%mm3\n"
19544+ " movq %%mm0, (%2)\n"
19545+ " movq %%mm1, 8(%2)\n"
19546+ " movq %%mm2, 16(%2)\n"
19547+ " movq %%mm3, 24(%2)\n"
19548+ " movq 32(%1), %%mm0\n"
19549+ " movq 40(%1), %%mm1\n"
19550+ " movq 48(%1), %%mm2\n"
19551+ " movq 56(%1), %%mm3\n"
19552+ " movq %%mm0, 32(%2)\n"
19553+ " movq %%mm1, 40(%2)\n"
19554+ " movq %%mm2, 48(%2)\n"
19555+ " movq %%mm3, 56(%2)\n"
19556 ".section .fixup, \"ax\"\n"
19557- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19558+ "3:\n"
19559+
19560+#ifdef CONFIG_PAX_KERNEXEC
19561+ " movl %%cr0, %0\n"
19562+ " movl %0, %%eax\n"
19563+ " andl $0xFFFEFFFF, %%eax\n"
19564+ " movl %%eax, %%cr0\n"
19565+#endif
19566+
19567+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19568+
19569+#ifdef CONFIG_PAX_KERNEXEC
19570+ " movl %0, %%cr0\n"
19571+#endif
19572+
19573 " jmp 2b\n"
19574 ".previous\n"
19575 _ASM_EXTABLE(1b, 3b)
19576- : : "r" (from), "r" (to) : "memory");
19577+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19578
19579 from += 64;
19580 to += 64;
19581@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19582 static void fast_copy_page(void *to, void *from)
19583 {
19584 int i;
19585+ unsigned long cr0;
19586
19587 kernel_fpu_begin();
19588
19589@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19590 * but that is for later. -AV
19591 */
19592 __asm__ __volatile__(
19593- "1: prefetch (%0)\n"
19594- " prefetch 64(%0)\n"
19595- " prefetch 128(%0)\n"
19596- " prefetch 192(%0)\n"
19597- " prefetch 256(%0)\n"
19598+ "1: prefetch (%1)\n"
19599+ " prefetch 64(%1)\n"
19600+ " prefetch 128(%1)\n"
19601+ " prefetch 192(%1)\n"
19602+ " prefetch 256(%1)\n"
19603 "2: \n"
19604 ".section .fixup, \"ax\"\n"
19605- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19606+ "3: \n"
19607+
19608+#ifdef CONFIG_PAX_KERNEXEC
19609+ " movl %%cr0, %0\n"
19610+ " movl %0, %%eax\n"
19611+ " andl $0xFFFEFFFF, %%eax\n"
19612+ " movl %%eax, %%cr0\n"
19613+#endif
19614+
19615+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19616+
19617+#ifdef CONFIG_PAX_KERNEXEC
19618+ " movl %0, %%cr0\n"
19619+#endif
19620+
19621 " jmp 2b\n"
19622 ".previous\n"
19623- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19624+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19625
19626 for (i = 0; i < (4096-320)/64; i++) {
19627 __asm__ __volatile__ (
19628- "1: prefetch 320(%0)\n"
19629- "2: movq (%0), %%mm0\n"
19630- " movntq %%mm0, (%1)\n"
19631- " movq 8(%0), %%mm1\n"
19632- " movntq %%mm1, 8(%1)\n"
19633- " movq 16(%0), %%mm2\n"
19634- " movntq %%mm2, 16(%1)\n"
19635- " movq 24(%0), %%mm3\n"
19636- " movntq %%mm3, 24(%1)\n"
19637- " movq 32(%0), %%mm4\n"
19638- " movntq %%mm4, 32(%1)\n"
19639- " movq 40(%0), %%mm5\n"
19640- " movntq %%mm5, 40(%1)\n"
19641- " movq 48(%0), %%mm6\n"
19642- " movntq %%mm6, 48(%1)\n"
19643- " movq 56(%0), %%mm7\n"
19644- " movntq %%mm7, 56(%1)\n"
19645+ "1: prefetch 320(%1)\n"
19646+ "2: movq (%1), %%mm0\n"
19647+ " movntq %%mm0, (%2)\n"
19648+ " movq 8(%1), %%mm1\n"
19649+ " movntq %%mm1, 8(%2)\n"
19650+ " movq 16(%1), %%mm2\n"
19651+ " movntq %%mm2, 16(%2)\n"
19652+ " movq 24(%1), %%mm3\n"
19653+ " movntq %%mm3, 24(%2)\n"
19654+ " movq 32(%1), %%mm4\n"
19655+ " movntq %%mm4, 32(%2)\n"
19656+ " movq 40(%1), %%mm5\n"
19657+ " movntq %%mm5, 40(%2)\n"
19658+ " movq 48(%1), %%mm6\n"
19659+ " movntq %%mm6, 48(%2)\n"
19660+ " movq 56(%1), %%mm7\n"
19661+ " movntq %%mm7, 56(%2)\n"
19662 ".section .fixup, \"ax\"\n"
19663- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19664+ "3:\n"
19665+
19666+#ifdef CONFIG_PAX_KERNEXEC
19667+ " movl %%cr0, %0\n"
19668+ " movl %0, %%eax\n"
19669+ " andl $0xFFFEFFFF, %%eax\n"
19670+ " movl %%eax, %%cr0\n"
19671+#endif
19672+
19673+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19674+
19675+#ifdef CONFIG_PAX_KERNEXEC
19676+ " movl %0, %%cr0\n"
19677+#endif
19678+
19679 " jmp 2b\n"
19680 ".previous\n"
19681- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
19682+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19683
19684 from += 64;
19685 to += 64;
19686@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
19687 static void fast_copy_page(void *to, void *from)
19688 {
19689 int i;
19690+ unsigned long cr0;
19691
19692 kernel_fpu_begin();
19693
19694 __asm__ __volatile__ (
19695- "1: prefetch (%0)\n"
19696- " prefetch 64(%0)\n"
19697- " prefetch 128(%0)\n"
19698- " prefetch 192(%0)\n"
19699- " prefetch 256(%0)\n"
19700+ "1: prefetch (%1)\n"
19701+ " prefetch 64(%1)\n"
19702+ " prefetch 128(%1)\n"
19703+ " prefetch 192(%1)\n"
19704+ " prefetch 256(%1)\n"
19705 "2: \n"
19706 ".section .fixup, \"ax\"\n"
19707- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19708+ "3: \n"
19709+
19710+#ifdef CONFIG_PAX_KERNEXEC
19711+ " movl %%cr0, %0\n"
19712+ " movl %0, %%eax\n"
19713+ " andl $0xFFFEFFFF, %%eax\n"
19714+ " movl %%eax, %%cr0\n"
19715+#endif
19716+
19717+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19718+
19719+#ifdef CONFIG_PAX_KERNEXEC
19720+ " movl %0, %%cr0\n"
19721+#endif
19722+
19723 " jmp 2b\n"
19724 ".previous\n"
19725- _ASM_EXTABLE(1b, 3b) : : "r" (from));
19726+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19727
19728 for (i = 0; i < 4096/64; i++) {
19729 __asm__ __volatile__ (
19730- "1: prefetch 320(%0)\n"
19731- "2: movq (%0), %%mm0\n"
19732- " movq 8(%0), %%mm1\n"
19733- " movq 16(%0), %%mm2\n"
19734- " movq 24(%0), %%mm3\n"
19735- " movq %%mm0, (%1)\n"
19736- " movq %%mm1, 8(%1)\n"
19737- " movq %%mm2, 16(%1)\n"
19738- " movq %%mm3, 24(%1)\n"
19739- " movq 32(%0), %%mm0\n"
19740- " movq 40(%0), %%mm1\n"
19741- " movq 48(%0), %%mm2\n"
19742- " movq 56(%0), %%mm3\n"
19743- " movq %%mm0, 32(%1)\n"
19744- " movq %%mm1, 40(%1)\n"
19745- " movq %%mm2, 48(%1)\n"
19746- " movq %%mm3, 56(%1)\n"
19747+ "1: prefetch 320(%1)\n"
19748+ "2: movq (%1), %%mm0\n"
19749+ " movq 8(%1), %%mm1\n"
19750+ " movq 16(%1), %%mm2\n"
19751+ " movq 24(%1), %%mm3\n"
19752+ " movq %%mm0, (%2)\n"
19753+ " movq %%mm1, 8(%2)\n"
19754+ " movq %%mm2, 16(%2)\n"
19755+ " movq %%mm3, 24(%2)\n"
19756+ " movq 32(%1), %%mm0\n"
19757+ " movq 40(%1), %%mm1\n"
19758+ " movq 48(%1), %%mm2\n"
19759+ " movq 56(%1), %%mm3\n"
19760+ " movq %%mm0, 32(%2)\n"
19761+ " movq %%mm1, 40(%2)\n"
19762+ " movq %%mm2, 48(%2)\n"
19763+ " movq %%mm3, 56(%2)\n"
19764 ".section .fixup, \"ax\"\n"
19765- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19766+ "3:\n"
19767+
19768+#ifdef CONFIG_PAX_KERNEXEC
19769+ " movl %%cr0, %0\n"
19770+ " movl %0, %%eax\n"
19771+ " andl $0xFFFEFFFF, %%eax\n"
19772+ " movl %%eax, %%cr0\n"
19773+#endif
19774+
19775+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19776+
19777+#ifdef CONFIG_PAX_KERNEXEC
19778+ " movl %0, %%cr0\n"
19779+#endif
19780+
19781 " jmp 2b\n"
19782 ".previous\n"
19783 _ASM_EXTABLE(1b, 3b)
19784- : : "r" (from), "r" (to) : "memory");
19785+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19786
19787 from += 64;
19788 to += 64;
19789diff -urNp linux-2.6.32.43/arch/x86/lib/putuser.S linux-2.6.32.43/arch/x86/lib/putuser.S
19790--- linux-2.6.32.43/arch/x86/lib/putuser.S 2011-03-27 14:31:47.000000000 -0400
19791+++ linux-2.6.32.43/arch/x86/lib/putuser.S 2011-04-17 15:56:46.000000000 -0400
19792@@ -15,7 +15,8 @@
19793 #include <asm/thread_info.h>
19794 #include <asm/errno.h>
19795 #include <asm/asm.h>
19796-
19797+#include <asm/segment.h>
19798+#include <asm/pgtable.h>
19799
19800 /*
19801 * __put_user_X
19802@@ -29,52 +30,119 @@
19803 * as they get called from within inline assembly.
19804 */
19805
19806-#define ENTER CFI_STARTPROC ; \
19807- GET_THREAD_INFO(%_ASM_BX)
19808+#define ENTER CFI_STARTPROC
19809 #define EXIT ret ; \
19810 CFI_ENDPROC
19811
19812+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19813+#define _DEST %_ASM_CX,%_ASM_BX
19814+#else
19815+#define _DEST %_ASM_CX
19816+#endif
19817+
19818+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19819+#define __copyuser_seg gs;
19820+#else
19821+#define __copyuser_seg
19822+#endif
19823+
19824 .text
19825 ENTRY(__put_user_1)
19826 ENTER
19827+
19828+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19829+ GET_THREAD_INFO(%_ASM_BX)
19830 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
19831 jae bad_put_user
19832-1: movb %al,(%_ASM_CX)
19833+
19834+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19835+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19836+ cmp %_ASM_BX,%_ASM_CX
19837+ jb 1234f
19838+ xor %ebx,%ebx
19839+1234:
19840+#endif
19841+
19842+#endif
19843+
19844+1: __copyuser_seg movb %al,(_DEST)
19845 xor %eax,%eax
19846 EXIT
19847 ENDPROC(__put_user_1)
19848
19849 ENTRY(__put_user_2)
19850 ENTER
19851+
19852+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19853+ GET_THREAD_INFO(%_ASM_BX)
19854 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
19855 sub $1,%_ASM_BX
19856 cmp %_ASM_BX,%_ASM_CX
19857 jae bad_put_user
19858-2: movw %ax,(%_ASM_CX)
19859+
19860+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19861+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19862+ cmp %_ASM_BX,%_ASM_CX
19863+ jb 1234f
19864+ xor %ebx,%ebx
19865+1234:
19866+#endif
19867+
19868+#endif
19869+
19870+2: __copyuser_seg movw %ax,(_DEST)
19871 xor %eax,%eax
19872 EXIT
19873 ENDPROC(__put_user_2)
19874
19875 ENTRY(__put_user_4)
19876 ENTER
19877+
19878+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19879+ GET_THREAD_INFO(%_ASM_BX)
19880 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
19881 sub $3,%_ASM_BX
19882 cmp %_ASM_BX,%_ASM_CX
19883 jae bad_put_user
19884-3: movl %eax,(%_ASM_CX)
19885+
19886+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19887+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19888+ cmp %_ASM_BX,%_ASM_CX
19889+ jb 1234f
19890+ xor %ebx,%ebx
19891+1234:
19892+#endif
19893+
19894+#endif
19895+
19896+3: __copyuser_seg movl %eax,(_DEST)
19897 xor %eax,%eax
19898 EXIT
19899 ENDPROC(__put_user_4)
19900
19901 ENTRY(__put_user_8)
19902 ENTER
19903+
19904+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19905+ GET_THREAD_INFO(%_ASM_BX)
19906 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
19907 sub $7,%_ASM_BX
19908 cmp %_ASM_BX,%_ASM_CX
19909 jae bad_put_user
19910-4: mov %_ASM_AX,(%_ASM_CX)
19911+
19912+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19913+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
19914+ cmp %_ASM_BX,%_ASM_CX
19915+ jb 1234f
19916+ xor %ebx,%ebx
19917+1234:
19918+#endif
19919+
19920+#endif
19921+
19922+4: __copyuser_seg mov %_ASM_AX,(_DEST)
19923 #ifdef CONFIG_X86_32
19924-5: movl %edx,4(%_ASM_CX)
19925+5: __copyuser_seg movl %edx,4(_DEST)
19926 #endif
19927 xor %eax,%eax
19928 EXIT
19929diff -urNp linux-2.6.32.43/arch/x86/lib/usercopy_32.c linux-2.6.32.43/arch/x86/lib/usercopy_32.c
19930--- linux-2.6.32.43/arch/x86/lib/usercopy_32.c 2011-03-27 14:31:47.000000000 -0400
19931+++ linux-2.6.32.43/arch/x86/lib/usercopy_32.c 2011-04-23 21:12:28.000000000 -0400
19932@@ -43,7 +43,7 @@ do { \
19933 __asm__ __volatile__( \
19934 " testl %1,%1\n" \
19935 " jz 2f\n" \
19936- "0: lodsb\n" \
19937+ "0: "__copyuser_seg"lodsb\n" \
19938 " stosb\n" \
19939 " testb %%al,%%al\n" \
19940 " jz 1f\n" \
19941@@ -128,10 +128,12 @@ do { \
19942 int __d0; \
19943 might_fault(); \
19944 __asm__ __volatile__( \
19945+ __COPYUSER_SET_ES \
19946 "0: rep; stosl\n" \
19947 " movl %2,%0\n" \
19948 "1: rep; stosb\n" \
19949 "2:\n" \
19950+ __COPYUSER_RESTORE_ES \
19951 ".section .fixup,\"ax\"\n" \
19952 "3: lea 0(%2,%0,4),%0\n" \
19953 " jmp 2b\n" \
19954@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
19955 might_fault();
19956
19957 __asm__ __volatile__(
19958+ __COPYUSER_SET_ES
19959 " testl %0, %0\n"
19960 " jz 3f\n"
19961 " andl %0,%%ecx\n"
19962@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
19963 " subl %%ecx,%0\n"
19964 " addl %0,%%eax\n"
19965 "1:\n"
19966+ __COPYUSER_RESTORE_ES
19967 ".section .fixup,\"ax\"\n"
19968 "2: xorl %%eax,%%eax\n"
19969 " jmp 1b\n"
19970@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
19971
19972 #ifdef CONFIG_X86_INTEL_USERCOPY
19973 static unsigned long
19974-__copy_user_intel(void __user *to, const void *from, unsigned long size)
19975+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
19976 {
19977 int d0, d1;
19978 __asm__ __volatile__(
19979@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
19980 " .align 2,0x90\n"
19981 "3: movl 0(%4), %%eax\n"
19982 "4: movl 4(%4), %%edx\n"
19983- "5: movl %%eax, 0(%3)\n"
19984- "6: movl %%edx, 4(%3)\n"
19985+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
19986+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
19987 "7: movl 8(%4), %%eax\n"
19988 "8: movl 12(%4),%%edx\n"
19989- "9: movl %%eax, 8(%3)\n"
19990- "10: movl %%edx, 12(%3)\n"
19991+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
19992+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
19993 "11: movl 16(%4), %%eax\n"
19994 "12: movl 20(%4), %%edx\n"
19995- "13: movl %%eax, 16(%3)\n"
19996- "14: movl %%edx, 20(%3)\n"
19997+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
19998+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
19999 "15: movl 24(%4), %%eax\n"
20000 "16: movl 28(%4), %%edx\n"
20001- "17: movl %%eax, 24(%3)\n"
20002- "18: movl %%edx, 28(%3)\n"
20003+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20004+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20005 "19: movl 32(%4), %%eax\n"
20006 "20: movl 36(%4), %%edx\n"
20007- "21: movl %%eax, 32(%3)\n"
20008- "22: movl %%edx, 36(%3)\n"
20009+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20010+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20011 "23: movl 40(%4), %%eax\n"
20012 "24: movl 44(%4), %%edx\n"
20013- "25: movl %%eax, 40(%3)\n"
20014- "26: movl %%edx, 44(%3)\n"
20015+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20016+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20017 "27: movl 48(%4), %%eax\n"
20018 "28: movl 52(%4), %%edx\n"
20019- "29: movl %%eax, 48(%3)\n"
20020- "30: movl %%edx, 52(%3)\n"
20021+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20022+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20023 "31: movl 56(%4), %%eax\n"
20024 "32: movl 60(%4), %%edx\n"
20025- "33: movl %%eax, 56(%3)\n"
20026- "34: movl %%edx, 60(%3)\n"
20027+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20028+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20029 " addl $-64, %0\n"
20030 " addl $64, %4\n"
20031 " addl $64, %3\n"
20032@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
20033 " shrl $2, %0\n"
20034 " andl $3, %%eax\n"
20035 " cld\n"
20036+ __COPYUSER_SET_ES
20037 "99: rep; movsl\n"
20038 "36: movl %%eax, %0\n"
20039 "37: rep; movsb\n"
20040 "100:\n"
20041+ __COPYUSER_RESTORE_ES
20042+ ".section .fixup,\"ax\"\n"
20043+ "101: lea 0(%%eax,%0,4),%0\n"
20044+ " jmp 100b\n"
20045+ ".previous\n"
20046+ ".section __ex_table,\"a\"\n"
20047+ " .align 4\n"
20048+ " .long 1b,100b\n"
20049+ " .long 2b,100b\n"
20050+ " .long 3b,100b\n"
20051+ " .long 4b,100b\n"
20052+ " .long 5b,100b\n"
20053+ " .long 6b,100b\n"
20054+ " .long 7b,100b\n"
20055+ " .long 8b,100b\n"
20056+ " .long 9b,100b\n"
20057+ " .long 10b,100b\n"
20058+ " .long 11b,100b\n"
20059+ " .long 12b,100b\n"
20060+ " .long 13b,100b\n"
20061+ " .long 14b,100b\n"
20062+ " .long 15b,100b\n"
20063+ " .long 16b,100b\n"
20064+ " .long 17b,100b\n"
20065+ " .long 18b,100b\n"
20066+ " .long 19b,100b\n"
20067+ " .long 20b,100b\n"
20068+ " .long 21b,100b\n"
20069+ " .long 22b,100b\n"
20070+ " .long 23b,100b\n"
20071+ " .long 24b,100b\n"
20072+ " .long 25b,100b\n"
20073+ " .long 26b,100b\n"
20074+ " .long 27b,100b\n"
20075+ " .long 28b,100b\n"
20076+ " .long 29b,100b\n"
20077+ " .long 30b,100b\n"
20078+ " .long 31b,100b\n"
20079+ " .long 32b,100b\n"
20080+ " .long 33b,100b\n"
20081+ " .long 34b,100b\n"
20082+ " .long 35b,100b\n"
20083+ " .long 36b,100b\n"
20084+ " .long 37b,100b\n"
20085+ " .long 99b,101b\n"
20086+ ".previous"
20087+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
20088+ : "1"(to), "2"(from), "0"(size)
20089+ : "eax", "edx", "memory");
20090+ return size;
20091+}
20092+
20093+static unsigned long
20094+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20095+{
20096+ int d0, d1;
20097+ __asm__ __volatile__(
20098+ " .align 2,0x90\n"
20099+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20100+ " cmpl $67, %0\n"
20101+ " jbe 3f\n"
20102+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20103+ " .align 2,0x90\n"
20104+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20105+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20106+ "5: movl %%eax, 0(%3)\n"
20107+ "6: movl %%edx, 4(%3)\n"
20108+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20109+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20110+ "9: movl %%eax, 8(%3)\n"
20111+ "10: movl %%edx, 12(%3)\n"
20112+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20113+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20114+ "13: movl %%eax, 16(%3)\n"
20115+ "14: movl %%edx, 20(%3)\n"
20116+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20117+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20118+ "17: movl %%eax, 24(%3)\n"
20119+ "18: movl %%edx, 28(%3)\n"
20120+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20121+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20122+ "21: movl %%eax, 32(%3)\n"
20123+ "22: movl %%edx, 36(%3)\n"
20124+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20125+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20126+ "25: movl %%eax, 40(%3)\n"
20127+ "26: movl %%edx, 44(%3)\n"
20128+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20129+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20130+ "29: movl %%eax, 48(%3)\n"
20131+ "30: movl %%edx, 52(%3)\n"
20132+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20133+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20134+ "33: movl %%eax, 56(%3)\n"
20135+ "34: movl %%edx, 60(%3)\n"
20136+ " addl $-64, %0\n"
20137+ " addl $64, %4\n"
20138+ " addl $64, %3\n"
20139+ " cmpl $63, %0\n"
20140+ " ja 1b\n"
20141+ "35: movl %0, %%eax\n"
20142+ " shrl $2, %0\n"
20143+ " andl $3, %%eax\n"
20144+ " cld\n"
20145+ "99: rep; "__copyuser_seg" movsl\n"
20146+ "36: movl %%eax, %0\n"
20147+ "37: rep; "__copyuser_seg" movsb\n"
20148+ "100:\n"
20149 ".section .fixup,\"ax\"\n"
20150 "101: lea 0(%%eax,%0,4),%0\n"
20151 " jmp 100b\n"
20152@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20153 int d0, d1;
20154 __asm__ __volatile__(
20155 " .align 2,0x90\n"
20156- "0: movl 32(%4), %%eax\n"
20157+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20158 " cmpl $67, %0\n"
20159 " jbe 2f\n"
20160- "1: movl 64(%4), %%eax\n"
20161+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20162 " .align 2,0x90\n"
20163- "2: movl 0(%4), %%eax\n"
20164- "21: movl 4(%4), %%edx\n"
20165+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20166+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20167 " movl %%eax, 0(%3)\n"
20168 " movl %%edx, 4(%3)\n"
20169- "3: movl 8(%4), %%eax\n"
20170- "31: movl 12(%4),%%edx\n"
20171+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20172+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20173 " movl %%eax, 8(%3)\n"
20174 " movl %%edx, 12(%3)\n"
20175- "4: movl 16(%4), %%eax\n"
20176- "41: movl 20(%4), %%edx\n"
20177+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20178+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20179 " movl %%eax, 16(%3)\n"
20180 " movl %%edx, 20(%3)\n"
20181- "10: movl 24(%4), %%eax\n"
20182- "51: movl 28(%4), %%edx\n"
20183+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20184+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20185 " movl %%eax, 24(%3)\n"
20186 " movl %%edx, 28(%3)\n"
20187- "11: movl 32(%4), %%eax\n"
20188- "61: movl 36(%4), %%edx\n"
20189+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20190+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20191 " movl %%eax, 32(%3)\n"
20192 " movl %%edx, 36(%3)\n"
20193- "12: movl 40(%4), %%eax\n"
20194- "71: movl 44(%4), %%edx\n"
20195+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20196+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20197 " movl %%eax, 40(%3)\n"
20198 " movl %%edx, 44(%3)\n"
20199- "13: movl 48(%4), %%eax\n"
20200- "81: movl 52(%4), %%edx\n"
20201+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20202+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20203 " movl %%eax, 48(%3)\n"
20204 " movl %%edx, 52(%3)\n"
20205- "14: movl 56(%4), %%eax\n"
20206- "91: movl 60(%4), %%edx\n"
20207+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20208+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20209 " movl %%eax, 56(%3)\n"
20210 " movl %%edx, 60(%3)\n"
20211 " addl $-64, %0\n"
20212@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20213 " shrl $2, %0\n"
20214 " andl $3, %%eax\n"
20215 " cld\n"
20216- "6: rep; movsl\n"
20217+ "6: rep; "__copyuser_seg" movsl\n"
20218 " movl %%eax,%0\n"
20219- "7: rep; movsb\n"
20220+ "7: rep; "__copyuser_seg" movsb\n"
20221 "8:\n"
20222 ".section .fixup,\"ax\"\n"
20223 "9: lea 0(%%eax,%0,4),%0\n"
20224@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20225
20226 __asm__ __volatile__(
20227 " .align 2,0x90\n"
20228- "0: movl 32(%4), %%eax\n"
20229+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20230 " cmpl $67, %0\n"
20231 " jbe 2f\n"
20232- "1: movl 64(%4), %%eax\n"
20233+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20234 " .align 2,0x90\n"
20235- "2: movl 0(%4), %%eax\n"
20236- "21: movl 4(%4), %%edx\n"
20237+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20238+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20239 " movnti %%eax, 0(%3)\n"
20240 " movnti %%edx, 4(%3)\n"
20241- "3: movl 8(%4), %%eax\n"
20242- "31: movl 12(%4),%%edx\n"
20243+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20244+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20245 " movnti %%eax, 8(%3)\n"
20246 " movnti %%edx, 12(%3)\n"
20247- "4: movl 16(%4), %%eax\n"
20248- "41: movl 20(%4), %%edx\n"
20249+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20250+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20251 " movnti %%eax, 16(%3)\n"
20252 " movnti %%edx, 20(%3)\n"
20253- "10: movl 24(%4), %%eax\n"
20254- "51: movl 28(%4), %%edx\n"
20255+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20256+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20257 " movnti %%eax, 24(%3)\n"
20258 " movnti %%edx, 28(%3)\n"
20259- "11: movl 32(%4), %%eax\n"
20260- "61: movl 36(%4), %%edx\n"
20261+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20262+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20263 " movnti %%eax, 32(%3)\n"
20264 " movnti %%edx, 36(%3)\n"
20265- "12: movl 40(%4), %%eax\n"
20266- "71: movl 44(%4), %%edx\n"
20267+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20268+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20269 " movnti %%eax, 40(%3)\n"
20270 " movnti %%edx, 44(%3)\n"
20271- "13: movl 48(%4), %%eax\n"
20272- "81: movl 52(%4), %%edx\n"
20273+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20274+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20275 " movnti %%eax, 48(%3)\n"
20276 " movnti %%edx, 52(%3)\n"
20277- "14: movl 56(%4), %%eax\n"
20278- "91: movl 60(%4), %%edx\n"
20279+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20280+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20281 " movnti %%eax, 56(%3)\n"
20282 " movnti %%edx, 60(%3)\n"
20283 " addl $-64, %0\n"
20284@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20285 " shrl $2, %0\n"
20286 " andl $3, %%eax\n"
20287 " cld\n"
20288- "6: rep; movsl\n"
20289+ "6: rep; "__copyuser_seg" movsl\n"
20290 " movl %%eax,%0\n"
20291- "7: rep; movsb\n"
20292+ "7: rep; "__copyuser_seg" movsb\n"
20293 "8:\n"
20294 ".section .fixup,\"ax\"\n"
20295 "9: lea 0(%%eax,%0,4),%0\n"
20296@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20297
20298 __asm__ __volatile__(
20299 " .align 2,0x90\n"
20300- "0: movl 32(%4), %%eax\n"
20301+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20302 " cmpl $67, %0\n"
20303 " jbe 2f\n"
20304- "1: movl 64(%4), %%eax\n"
20305+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20306 " .align 2,0x90\n"
20307- "2: movl 0(%4), %%eax\n"
20308- "21: movl 4(%4), %%edx\n"
20309+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20310+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20311 " movnti %%eax, 0(%3)\n"
20312 " movnti %%edx, 4(%3)\n"
20313- "3: movl 8(%4), %%eax\n"
20314- "31: movl 12(%4),%%edx\n"
20315+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20316+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20317 " movnti %%eax, 8(%3)\n"
20318 " movnti %%edx, 12(%3)\n"
20319- "4: movl 16(%4), %%eax\n"
20320- "41: movl 20(%4), %%edx\n"
20321+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20322+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20323 " movnti %%eax, 16(%3)\n"
20324 " movnti %%edx, 20(%3)\n"
20325- "10: movl 24(%4), %%eax\n"
20326- "51: movl 28(%4), %%edx\n"
20327+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20328+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20329 " movnti %%eax, 24(%3)\n"
20330 " movnti %%edx, 28(%3)\n"
20331- "11: movl 32(%4), %%eax\n"
20332- "61: movl 36(%4), %%edx\n"
20333+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20334+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20335 " movnti %%eax, 32(%3)\n"
20336 " movnti %%edx, 36(%3)\n"
20337- "12: movl 40(%4), %%eax\n"
20338- "71: movl 44(%4), %%edx\n"
20339+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20340+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20341 " movnti %%eax, 40(%3)\n"
20342 " movnti %%edx, 44(%3)\n"
20343- "13: movl 48(%4), %%eax\n"
20344- "81: movl 52(%4), %%edx\n"
20345+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20346+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20347 " movnti %%eax, 48(%3)\n"
20348 " movnti %%edx, 52(%3)\n"
20349- "14: movl 56(%4), %%eax\n"
20350- "91: movl 60(%4), %%edx\n"
20351+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20352+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20353 " movnti %%eax, 56(%3)\n"
20354 " movnti %%edx, 60(%3)\n"
20355 " addl $-64, %0\n"
20356@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20357 " shrl $2, %0\n"
20358 " andl $3, %%eax\n"
20359 " cld\n"
20360- "6: rep; movsl\n"
20361+ "6: rep; "__copyuser_seg" movsl\n"
20362 " movl %%eax,%0\n"
20363- "7: rep; movsb\n"
20364+ "7: rep; "__copyuser_seg" movsb\n"
20365 "8:\n"
20366 ".section .fixup,\"ax\"\n"
20367 "9: lea 0(%%eax,%0,4),%0\n"
20368@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20369 */
20370 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20371 unsigned long size);
20372-unsigned long __copy_user_intel(void __user *to, const void *from,
20373+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20374+ unsigned long size);
20375+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20376 unsigned long size);
20377 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20378 const void __user *from, unsigned long size);
20379 #endif /* CONFIG_X86_INTEL_USERCOPY */
20380
20381 /* Generic arbitrary sized copy. */
20382-#define __copy_user(to, from, size) \
20383+#define __copy_user(to, from, size, prefix, set, restore) \
20384 do { \
20385 int __d0, __d1, __d2; \
20386 __asm__ __volatile__( \
20387+ set \
20388 " cmp $7,%0\n" \
20389 " jbe 1f\n" \
20390 " movl %1,%0\n" \
20391 " negl %0\n" \
20392 " andl $7,%0\n" \
20393 " subl %0,%3\n" \
20394- "4: rep; movsb\n" \
20395+ "4: rep; "prefix"movsb\n" \
20396 " movl %3,%0\n" \
20397 " shrl $2,%0\n" \
20398 " andl $3,%3\n" \
20399 " .align 2,0x90\n" \
20400- "0: rep; movsl\n" \
20401+ "0: rep; "prefix"movsl\n" \
20402 " movl %3,%0\n" \
20403- "1: rep; movsb\n" \
20404+ "1: rep; "prefix"movsb\n" \
20405 "2:\n" \
20406+ restore \
20407 ".section .fixup,\"ax\"\n" \
20408 "5: addl %3,%0\n" \
20409 " jmp 2b\n" \
20410@@ -682,14 +799,14 @@ do { \
20411 " negl %0\n" \
20412 " andl $7,%0\n" \
20413 " subl %0,%3\n" \
20414- "4: rep; movsb\n" \
20415+ "4: rep; "__copyuser_seg"movsb\n" \
20416 " movl %3,%0\n" \
20417 " shrl $2,%0\n" \
20418 " andl $3,%3\n" \
20419 " .align 2,0x90\n" \
20420- "0: rep; movsl\n" \
20421+ "0: rep; "__copyuser_seg"movsl\n" \
20422 " movl %3,%0\n" \
20423- "1: rep; movsb\n" \
20424+ "1: rep; "__copyuser_seg"movsb\n" \
20425 "2:\n" \
20426 ".section .fixup,\"ax\"\n" \
20427 "5: addl %3,%0\n" \
20428@@ -775,9 +892,9 @@ survive:
20429 }
20430 #endif
20431 if (movsl_is_ok(to, from, n))
20432- __copy_user(to, from, n);
20433+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20434 else
20435- n = __copy_user_intel(to, from, n);
20436+ n = __generic_copy_to_user_intel(to, from, n);
20437 return n;
20438 }
20439 EXPORT_SYMBOL(__copy_to_user_ll);
20440@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20441 unsigned long n)
20442 {
20443 if (movsl_is_ok(to, from, n))
20444- __copy_user(to, from, n);
20445+ __copy_user(to, from, n, __copyuser_seg, "", "");
20446 else
20447- n = __copy_user_intel((void __user *)to,
20448- (const void *)from, n);
20449+ n = __generic_copy_from_user_intel(to, from, n);
20450 return n;
20451 }
20452 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20453@@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocach
20454 if (n > 64 && cpu_has_xmm2)
20455 n = __copy_user_intel_nocache(to, from, n);
20456 else
20457- __copy_user(to, from, n);
20458+ __copy_user(to, from, n, __copyuser_seg, "", "");
20459 #else
20460- __copy_user(to, from, n);
20461+ __copy_user(to, from, n, __copyuser_seg, "", "");
20462 #endif
20463 return n;
20464 }
20465 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20466
20467-/**
20468- * copy_to_user: - Copy a block of data into user space.
20469- * @to: Destination address, in user space.
20470- * @from: Source address, in kernel space.
20471- * @n: Number of bytes to copy.
20472- *
20473- * Context: User context only. This function may sleep.
20474- *
20475- * Copy data from kernel space to user space.
20476- *
20477- * Returns number of bytes that could not be copied.
20478- * On success, this will be zero.
20479- */
20480-unsigned long
20481-copy_to_user(void __user *to, const void *from, unsigned long n)
20482+#ifdef CONFIG_PAX_MEMORY_UDEREF
20483+void __set_fs(mm_segment_t x)
20484 {
20485- if (access_ok(VERIFY_WRITE, to, n))
20486- n = __copy_to_user(to, from, n);
20487- return n;
20488+ switch (x.seg) {
20489+ case 0:
20490+ loadsegment(gs, 0);
20491+ break;
20492+ case TASK_SIZE_MAX:
20493+ loadsegment(gs, __USER_DS);
20494+ break;
20495+ case -1UL:
20496+ loadsegment(gs, __KERNEL_DS);
20497+ break;
20498+ default:
20499+ BUG();
20500+ }
20501+ return;
20502 }
20503-EXPORT_SYMBOL(copy_to_user);
20504+EXPORT_SYMBOL(__set_fs);
20505
20506-/**
20507- * copy_from_user: - Copy a block of data from user space.
20508- * @to: Destination address, in kernel space.
20509- * @from: Source address, in user space.
20510- * @n: Number of bytes to copy.
20511- *
20512- * Context: User context only. This function may sleep.
20513- *
20514- * Copy data from user space to kernel space.
20515- *
20516- * Returns number of bytes that could not be copied.
20517- * On success, this will be zero.
20518- *
20519- * If some data could not be copied, this function will pad the copied
20520- * data to the requested size using zero bytes.
20521- */
20522-unsigned long
20523-copy_from_user(void *to, const void __user *from, unsigned long n)
20524+void set_fs(mm_segment_t x)
20525 {
20526- if (access_ok(VERIFY_READ, from, n))
20527- n = __copy_from_user(to, from, n);
20528- else
20529- memset(to, 0, n);
20530- return n;
20531+ current_thread_info()->addr_limit = x;
20532+ __set_fs(x);
20533 }
20534-EXPORT_SYMBOL(copy_from_user);
20535+EXPORT_SYMBOL(set_fs);
20536+#endif
20537diff -urNp linux-2.6.32.43/arch/x86/lib/usercopy_64.c linux-2.6.32.43/arch/x86/lib/usercopy_64.c
20538--- linux-2.6.32.43/arch/x86/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
20539+++ linux-2.6.32.43/arch/x86/lib/usercopy_64.c 2011-05-04 17:56:20.000000000 -0400
20540@@ -42,6 +42,12 @@ long
20541 __strncpy_from_user(char *dst, const char __user *src, long count)
20542 {
20543 long res;
20544+
20545+#ifdef CONFIG_PAX_MEMORY_UDEREF
20546+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20547+ src += PAX_USER_SHADOW_BASE;
20548+#endif
20549+
20550 __do_strncpy_from_user(dst, src, count, res);
20551 return res;
20552 }
20553@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20554 {
20555 long __d0;
20556 might_fault();
20557+
20558+#ifdef CONFIG_PAX_MEMORY_UDEREF
20559+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20560+ addr += PAX_USER_SHADOW_BASE;
20561+#endif
20562+
20563 /* no memory constraint because it doesn't change any memory gcc knows
20564 about */
20565 asm volatile(
20566@@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20567
20568 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20569 {
20570- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20571+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20572+
20573+#ifdef CONFIG_PAX_MEMORY_UDEREF
20574+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20575+ to += PAX_USER_SHADOW_BASE;
20576+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20577+ from += PAX_USER_SHADOW_BASE;
20578+#endif
20579+
20580 return copy_user_generic((__force void *)to, (__force void *)from, len);
20581- }
20582- return len;
20583+ }
20584+ return len;
20585 }
20586 EXPORT_SYMBOL(copy_in_user);
20587
20588diff -urNp linux-2.6.32.43/arch/x86/Makefile linux-2.6.32.43/arch/x86/Makefile
20589--- linux-2.6.32.43/arch/x86/Makefile 2011-03-27 14:31:47.000000000 -0400
20590+++ linux-2.6.32.43/arch/x86/Makefile 2011-07-19 18:16:02.000000000 -0400
20591@@ -44,6 +44,7 @@ ifeq ($(CONFIG_X86_32),y)
20592 else
20593 BITS := 64
20594 UTS_MACHINE := x86_64
20595+ biarch := $(call cc-option,-m64)
20596 CHECKFLAGS += -D__x86_64__ -m64
20597
20598 KBUILD_AFLAGS += -m64
20599@@ -189,3 +190,12 @@ define archhelp
20600 echo ' FDARGS="..." arguments for the booted kernel'
20601 echo ' FDINITRD=file initrd for the booted kernel'
20602 endef
20603+
20604+define OLD_LD
20605+
20606+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20607+*** Please upgrade your binutils to 2.18 or newer
20608+endef
20609+
20610+archprepare:
20611+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20612diff -urNp linux-2.6.32.43/arch/x86/mm/extable.c linux-2.6.32.43/arch/x86/mm/extable.c
20613--- linux-2.6.32.43/arch/x86/mm/extable.c 2011-03-27 14:31:47.000000000 -0400
20614+++ linux-2.6.32.43/arch/x86/mm/extable.c 2011-04-17 15:56:46.000000000 -0400
20615@@ -1,14 +1,71 @@
20616 #include <linux/module.h>
20617 #include <linux/spinlock.h>
20618+#include <linux/sort.h>
20619 #include <asm/uaccess.h>
20620+#include <asm/pgtable.h>
20621
20622+/*
20623+ * The exception table needs to be sorted so that the binary
20624+ * search that we use to find entries in it works properly.
20625+ * This is used both for the kernel exception table and for
20626+ * the exception tables of modules that get loaded.
20627+ */
20628+static int cmp_ex(const void *a, const void *b)
20629+{
20630+ const struct exception_table_entry *x = a, *y = b;
20631+
20632+ /* avoid overflow */
20633+ if (x->insn > y->insn)
20634+ return 1;
20635+ if (x->insn < y->insn)
20636+ return -1;
20637+ return 0;
20638+}
20639+
20640+static void swap_ex(void *a, void *b, int size)
20641+{
20642+ struct exception_table_entry t, *x = a, *y = b;
20643+
20644+ t = *x;
20645+
20646+ pax_open_kernel();
20647+ *x = *y;
20648+ *y = t;
20649+ pax_close_kernel();
20650+}
20651+
20652+void sort_extable(struct exception_table_entry *start,
20653+ struct exception_table_entry *finish)
20654+{
20655+ sort(start, finish - start, sizeof(struct exception_table_entry),
20656+ cmp_ex, swap_ex);
20657+}
20658+
20659+#ifdef CONFIG_MODULES
20660+/*
20661+ * If the exception table is sorted, any referring to the module init
20662+ * will be at the beginning or the end.
20663+ */
20664+void trim_init_extable(struct module *m)
20665+{
20666+ /*trim the beginning*/
20667+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
20668+ m->extable++;
20669+ m->num_exentries--;
20670+ }
20671+ /*trim the end*/
20672+ while (m->num_exentries &&
20673+ within_module_init(m->extable[m->num_exentries-1].insn, m))
20674+ m->num_exentries--;
20675+}
20676+#endif /* CONFIG_MODULES */
20677
20678 int fixup_exception(struct pt_regs *regs)
20679 {
20680 const struct exception_table_entry *fixup;
20681
20682 #ifdef CONFIG_PNPBIOS
20683- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
20684+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
20685 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
20686 extern u32 pnp_bios_is_utter_crap;
20687 pnp_bios_is_utter_crap = 1;
20688diff -urNp linux-2.6.32.43/arch/x86/mm/fault.c linux-2.6.32.43/arch/x86/mm/fault.c
20689--- linux-2.6.32.43/arch/x86/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
20690+++ linux-2.6.32.43/arch/x86/mm/fault.c 2011-06-06 17:35:16.000000000 -0400
20691@@ -11,10 +11,19 @@
20692 #include <linux/kprobes.h> /* __kprobes, ... */
20693 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
20694 #include <linux/perf_event.h> /* perf_sw_event */
20695+#include <linux/unistd.h>
20696+#include <linux/compiler.h>
20697
20698 #include <asm/traps.h> /* dotraplinkage, ... */
20699 #include <asm/pgalloc.h> /* pgd_*(), ... */
20700 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
20701+#include <asm/vsyscall.h>
20702+#include <asm/tlbflush.h>
20703+
20704+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20705+#include <asm/stacktrace.h>
20706+#include "../kernel/dumpstack.h"
20707+#endif
20708
20709 /*
20710 * Page fault error code bits:
20711@@ -51,7 +60,7 @@ static inline int notify_page_fault(stru
20712 int ret = 0;
20713
20714 /* kprobe_running() needs smp_processor_id() */
20715- if (kprobes_built_in() && !user_mode_vm(regs)) {
20716+ if (kprobes_built_in() && !user_mode(regs)) {
20717 preempt_disable();
20718 if (kprobe_running() && kprobe_fault_handler(regs, 14))
20719 ret = 1;
20720@@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *re
20721 return !instr_lo || (instr_lo>>1) == 1;
20722 case 0x00:
20723 /* Prefetch instruction is 0x0F0D or 0x0F18 */
20724- if (probe_kernel_address(instr, opcode))
20725+ if (user_mode(regs)) {
20726+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20727+ return 0;
20728+ } else if (probe_kernel_address(instr, opcode))
20729 return 0;
20730
20731 *prefetch = (instr_lo == 0xF) &&
20732@@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsign
20733 while (instr < max_instr) {
20734 unsigned char opcode;
20735
20736- if (probe_kernel_address(instr, opcode))
20737+ if (user_mode(regs)) {
20738+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
20739+ break;
20740+ } else if (probe_kernel_address(instr, opcode))
20741 break;
20742
20743 instr++;
20744@@ -172,6 +187,30 @@ force_sig_info_fault(int si_signo, int s
20745 force_sig_info(si_signo, &info, tsk);
20746 }
20747
20748+#ifdef CONFIG_PAX_EMUTRAMP
20749+static int pax_handle_fetch_fault(struct pt_regs *regs);
20750+#endif
20751+
20752+#ifdef CONFIG_PAX_PAGEEXEC
20753+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
20754+{
20755+ pgd_t *pgd;
20756+ pud_t *pud;
20757+ pmd_t *pmd;
20758+
20759+ pgd = pgd_offset(mm, address);
20760+ if (!pgd_present(*pgd))
20761+ return NULL;
20762+ pud = pud_offset(pgd, address);
20763+ if (!pud_present(*pud))
20764+ return NULL;
20765+ pmd = pmd_offset(pud, address);
20766+ if (!pmd_present(*pmd))
20767+ return NULL;
20768+ return pmd;
20769+}
20770+#endif
20771+
20772 DEFINE_SPINLOCK(pgd_lock);
20773 LIST_HEAD(pgd_list);
20774
20775@@ -224,11 +263,24 @@ void vmalloc_sync_all(void)
20776 address += PMD_SIZE) {
20777
20778 unsigned long flags;
20779+
20780+#ifdef CONFIG_PAX_PER_CPU_PGD
20781+ unsigned long cpu;
20782+#else
20783 struct page *page;
20784+#endif
20785
20786 spin_lock_irqsave(&pgd_lock, flags);
20787+
20788+#ifdef CONFIG_PAX_PER_CPU_PGD
20789+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
20790+ pgd_t *pgd = get_cpu_pgd(cpu);
20791+#else
20792 list_for_each_entry(page, &pgd_list, lru) {
20793- if (!vmalloc_sync_one(page_address(page), address))
20794+ pgd_t *pgd = page_address(page);
20795+#endif
20796+
20797+ if (!vmalloc_sync_one(pgd, address))
20798 break;
20799 }
20800 spin_unlock_irqrestore(&pgd_lock, flags);
20801@@ -258,6 +310,11 @@ static noinline int vmalloc_fault(unsign
20802 * an interrupt in the middle of a task switch..
20803 */
20804 pgd_paddr = read_cr3();
20805+
20806+#ifdef CONFIG_PAX_PER_CPU_PGD
20807+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
20808+#endif
20809+
20810 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
20811 if (!pmd_k)
20812 return -1;
20813@@ -332,15 +389,27 @@ void vmalloc_sync_all(void)
20814
20815 const pgd_t *pgd_ref = pgd_offset_k(address);
20816 unsigned long flags;
20817+
20818+#ifdef CONFIG_PAX_PER_CPU_PGD
20819+ unsigned long cpu;
20820+#else
20821 struct page *page;
20822+#endif
20823
20824 if (pgd_none(*pgd_ref))
20825 continue;
20826
20827 spin_lock_irqsave(&pgd_lock, flags);
20828+
20829+#ifdef CONFIG_PAX_PER_CPU_PGD
20830+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
20831+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
20832+#else
20833 list_for_each_entry(page, &pgd_list, lru) {
20834 pgd_t *pgd;
20835 pgd = (pgd_t *)page_address(page) + pgd_index(address);
20836+#endif
20837+
20838 if (pgd_none(*pgd))
20839 set_pgd(pgd, *pgd_ref);
20840 else
20841@@ -373,7 +442,14 @@ static noinline int vmalloc_fault(unsign
20842 * happen within a race in page table update. In the later
20843 * case just flush:
20844 */
20845+
20846+#ifdef CONFIG_PAX_PER_CPU_PGD
20847+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
20848+ pgd = pgd_offset_cpu(smp_processor_id(), address);
20849+#else
20850 pgd = pgd_offset(current->active_mm, address);
20851+#endif
20852+
20853 pgd_ref = pgd_offset_k(address);
20854 if (pgd_none(*pgd_ref))
20855 return -1;
20856@@ -535,7 +611,7 @@ static int is_errata93(struct pt_regs *r
20857 static int is_errata100(struct pt_regs *regs, unsigned long address)
20858 {
20859 #ifdef CONFIG_X86_64
20860- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
20861+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
20862 return 1;
20863 #endif
20864 return 0;
20865@@ -562,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *r
20866 }
20867
20868 static const char nx_warning[] = KERN_CRIT
20869-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
20870+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
20871
20872 static void
20873 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
20874@@ -571,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, un
20875 if (!oops_may_print())
20876 return;
20877
20878- if (error_code & PF_INSTR) {
20879+ if (nx_enabled && (error_code & PF_INSTR)) {
20880 unsigned int level;
20881
20882 pte_t *pte = lookup_address(address, &level);
20883
20884 if (pte && pte_present(*pte) && !pte_exec(*pte))
20885- printk(nx_warning, current_uid());
20886+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
20887 }
20888
20889+#ifdef CONFIG_PAX_KERNEXEC
20890+ if (init_mm.start_code <= address && address < init_mm.end_code) {
20891+ if (current->signal->curr_ip)
20892+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
20893+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
20894+ else
20895+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
20896+ current->comm, task_pid_nr(current), current_uid(), current_euid());
20897+ }
20898+#endif
20899+
20900 printk(KERN_ALERT "BUG: unable to handle kernel ");
20901 if (address < PAGE_SIZE)
20902 printk(KERN_CONT "NULL pointer dereference");
20903@@ -704,6 +791,68 @@ __bad_area_nosemaphore(struct pt_regs *r
20904 unsigned long address, int si_code)
20905 {
20906 struct task_struct *tsk = current;
20907+ struct mm_struct *mm = tsk->mm;
20908+
20909+#ifdef CONFIG_X86_64
20910+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
20911+ if (regs->ip == (unsigned long)vgettimeofday) {
20912+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
20913+ return;
20914+ } else if (regs->ip == (unsigned long)vtime) {
20915+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
20916+ return;
20917+ } else if (regs->ip == (unsigned long)vgetcpu) {
20918+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
20919+ return;
20920+ }
20921+ }
20922+#endif
20923+
20924+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20925+ if (mm && (error_code & PF_USER)) {
20926+ unsigned long ip = regs->ip;
20927+
20928+ if (v8086_mode(regs))
20929+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
20930+
20931+ /*
20932+ * It's possible to have interrupts off here:
20933+ */
20934+ local_irq_enable();
20935+
20936+#ifdef CONFIG_PAX_PAGEEXEC
20937+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
20938+ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
20939+
20940+#ifdef CONFIG_PAX_EMUTRAMP
20941+ switch (pax_handle_fetch_fault(regs)) {
20942+ case 2:
20943+ return;
20944+ }
20945+#endif
20946+
20947+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
20948+ do_group_exit(SIGKILL);
20949+ }
20950+#endif
20951+
20952+#ifdef CONFIG_PAX_SEGMEXEC
20953+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
20954+
20955+#ifdef CONFIG_PAX_EMUTRAMP
20956+ switch (pax_handle_fetch_fault(regs)) {
20957+ case 2:
20958+ return;
20959+ }
20960+#endif
20961+
20962+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
20963+ do_group_exit(SIGKILL);
20964+ }
20965+#endif
20966+
20967+ }
20968+#endif
20969
20970 /* User mode accesses just cause a SIGSEGV */
20971 if (error_code & PF_USER) {
20972@@ -857,6 +1006,99 @@ static int spurious_fault_check(unsigned
20973 return 1;
20974 }
20975
20976+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20977+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
20978+{
20979+ pte_t *pte;
20980+ pmd_t *pmd;
20981+ spinlock_t *ptl;
20982+ unsigned char pte_mask;
20983+
20984+ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
20985+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
20986+ return 0;
20987+
20988+ /* PaX: it's our fault, let's handle it if we can */
20989+
20990+ /* PaX: take a look at read faults before acquiring any locks */
20991+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
20992+ /* instruction fetch attempt from a protected page in user mode */
20993+ up_read(&mm->mmap_sem);
20994+
20995+#ifdef CONFIG_PAX_EMUTRAMP
20996+ switch (pax_handle_fetch_fault(regs)) {
20997+ case 2:
20998+ return 1;
20999+ }
21000+#endif
21001+
21002+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21003+ do_group_exit(SIGKILL);
21004+ }
21005+
21006+ pmd = pax_get_pmd(mm, address);
21007+ if (unlikely(!pmd))
21008+ return 0;
21009+
21010+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21011+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21012+ pte_unmap_unlock(pte, ptl);
21013+ return 0;
21014+ }
21015+
21016+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21017+ /* write attempt to a protected page in user mode */
21018+ pte_unmap_unlock(pte, ptl);
21019+ return 0;
21020+ }
21021+
21022+#ifdef CONFIG_SMP
21023+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21024+#else
21025+ if (likely(address > get_limit(regs->cs)))
21026+#endif
21027+ {
21028+ set_pte(pte, pte_mkread(*pte));
21029+ __flush_tlb_one(address);
21030+ pte_unmap_unlock(pte, ptl);
21031+ up_read(&mm->mmap_sem);
21032+ return 1;
21033+ }
21034+
21035+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21036+
21037+ /*
21038+ * PaX: fill DTLB with user rights and retry
21039+ */
21040+ __asm__ __volatile__ (
21041+ "orb %2,(%1)\n"
21042+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21043+/*
21044+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21045+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21046+ * page fault when examined during a TLB load attempt. this is true not only
21047+ * for PTEs holding a non-present entry but also present entries that will
21048+ * raise a page fault (such as those set up by PaX, or the copy-on-write
21049+ * mechanism). in effect it means that we do *not* need to flush the TLBs
21050+ * for our target pages since their PTEs are simply not in the TLBs at all.
21051+
21052+ * the best thing in omitting it is that we gain around 15-20% speed in the
21053+ * fast path of the page fault handler and can get rid of tracing since we
21054+ * can no longer flush unintended entries.
21055+ */
21056+ "invlpg (%0)\n"
21057+#endif
21058+ __copyuser_seg"testb $0,(%0)\n"
21059+ "xorb %3,(%1)\n"
21060+ :
21061+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21062+ : "memory", "cc");
21063+ pte_unmap_unlock(pte, ptl);
21064+ up_read(&mm->mmap_sem);
21065+ return 1;
21066+}
21067+#endif
21068+
21069 /*
21070 * Handle a spurious fault caused by a stale TLB entry.
21071 *
21072@@ -923,6 +1165,9 @@ int show_unhandled_signals = 1;
21073 static inline int
21074 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
21075 {
21076+ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21077+ return 1;
21078+
21079 if (write) {
21080 /* write, present and write, not present: */
21081 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21082@@ -956,17 +1201,31 @@ do_page_fault(struct pt_regs *regs, unsi
21083 {
21084 struct vm_area_struct *vma;
21085 struct task_struct *tsk;
21086- unsigned long address;
21087 struct mm_struct *mm;
21088 int write;
21089 int fault;
21090
21091+ /* Get the faulting address: */
21092+ unsigned long address = read_cr2();
21093+
21094+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21095+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21096+ if (!search_exception_tables(regs->ip)) {
21097+ bad_area_nosemaphore(regs, error_code, address);
21098+ return;
21099+ }
21100+ if (address < PAX_USER_SHADOW_BASE) {
21101+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21102+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21103+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21104+ } else
21105+ address -= PAX_USER_SHADOW_BASE;
21106+ }
21107+#endif
21108+
21109 tsk = current;
21110 mm = tsk->mm;
21111
21112- /* Get the faulting address: */
21113- address = read_cr2();
21114-
21115 /*
21116 * Detect and handle instructions that would cause a page fault for
21117 * both a tracked kernel page and a userspace page.
21118@@ -1026,7 +1285,7 @@ do_page_fault(struct pt_regs *regs, unsi
21119 * User-mode registers count as a user access even for any
21120 * potential system fault or CPU buglet:
21121 */
21122- if (user_mode_vm(regs)) {
21123+ if (user_mode(regs)) {
21124 local_irq_enable();
21125 error_code |= PF_USER;
21126 } else {
21127@@ -1080,6 +1339,11 @@ do_page_fault(struct pt_regs *regs, unsi
21128 might_sleep();
21129 }
21130
21131+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21132+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21133+ return;
21134+#endif
21135+
21136 vma = find_vma(mm, address);
21137 if (unlikely(!vma)) {
21138 bad_area(regs, error_code, address);
21139@@ -1091,18 +1355,24 @@ do_page_fault(struct pt_regs *regs, unsi
21140 bad_area(regs, error_code, address);
21141 return;
21142 }
21143- if (error_code & PF_USER) {
21144- /*
21145- * Accessing the stack below %sp is always a bug.
21146- * The large cushion allows instructions like enter
21147- * and pusha to work. ("enter $65535, $31" pushes
21148- * 32 pointers and then decrements %sp by 65535.)
21149- */
21150- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21151- bad_area(regs, error_code, address);
21152- return;
21153- }
21154+ /*
21155+ * Accessing the stack below %sp is always a bug.
21156+ * The large cushion allows instructions like enter
21157+ * and pusha to work. ("enter $65535, $31" pushes
21158+ * 32 pointers and then decrements %sp by 65535.)
21159+ */
21160+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21161+ bad_area(regs, error_code, address);
21162+ return;
21163+ }
21164+
21165+#ifdef CONFIG_PAX_SEGMEXEC
21166+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21167+ bad_area(regs, error_code, address);
21168+ return;
21169 }
21170+#endif
21171+
21172 if (unlikely(expand_stack(vma, address))) {
21173 bad_area(regs, error_code, address);
21174 return;
21175@@ -1146,3 +1416,199 @@ good_area:
21176
21177 up_read(&mm->mmap_sem);
21178 }
21179+
21180+#ifdef CONFIG_PAX_EMUTRAMP
21181+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21182+{
21183+ int err;
21184+
21185+ do { /* PaX: gcc trampoline emulation #1 */
21186+ unsigned char mov1, mov2;
21187+ unsigned short jmp;
21188+ unsigned int addr1, addr2;
21189+
21190+#ifdef CONFIG_X86_64
21191+ if ((regs->ip + 11) >> 32)
21192+ break;
21193+#endif
21194+
21195+ err = get_user(mov1, (unsigned char __user *)regs->ip);
21196+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21197+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21198+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21199+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21200+
21201+ if (err)
21202+ break;
21203+
21204+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21205+ regs->cx = addr1;
21206+ regs->ax = addr2;
21207+ regs->ip = addr2;
21208+ return 2;
21209+ }
21210+ } while (0);
21211+
21212+ do { /* PaX: gcc trampoline emulation #2 */
21213+ unsigned char mov, jmp;
21214+ unsigned int addr1, addr2;
21215+
21216+#ifdef CONFIG_X86_64
21217+ if ((regs->ip + 9) >> 32)
21218+ break;
21219+#endif
21220+
21221+ err = get_user(mov, (unsigned char __user *)regs->ip);
21222+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21223+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21224+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21225+
21226+ if (err)
21227+ break;
21228+
21229+ if (mov == 0xB9 && jmp == 0xE9) {
21230+ regs->cx = addr1;
21231+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21232+ return 2;
21233+ }
21234+ } while (0);
21235+
21236+ return 1; /* PaX in action */
21237+}
21238+
21239+#ifdef CONFIG_X86_64
21240+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21241+{
21242+ int err;
21243+
21244+ do { /* PaX: gcc trampoline emulation #1 */
21245+ unsigned short mov1, mov2, jmp1;
21246+ unsigned char jmp2;
21247+ unsigned int addr1;
21248+ unsigned long addr2;
21249+
21250+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21251+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21252+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21253+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21254+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21255+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21256+
21257+ if (err)
21258+ break;
21259+
21260+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21261+ regs->r11 = addr1;
21262+ regs->r10 = addr2;
21263+ regs->ip = addr1;
21264+ return 2;
21265+ }
21266+ } while (0);
21267+
21268+ do { /* PaX: gcc trampoline emulation #2 */
21269+ unsigned short mov1, mov2, jmp1;
21270+ unsigned char jmp2;
21271+ unsigned long addr1, addr2;
21272+
21273+ err = get_user(mov1, (unsigned short __user *)regs->ip);
21274+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21275+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21276+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21277+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21278+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21279+
21280+ if (err)
21281+ break;
21282+
21283+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21284+ regs->r11 = addr1;
21285+ regs->r10 = addr2;
21286+ regs->ip = addr1;
21287+ return 2;
21288+ }
21289+ } while (0);
21290+
21291+ return 1; /* PaX in action */
21292+}
21293+#endif
21294+
21295+/*
21296+ * PaX: decide what to do with offenders (regs->ip = fault address)
21297+ *
21298+ * returns 1 when task should be killed
21299+ * 2 when gcc trampoline was detected
21300+ */
21301+static int pax_handle_fetch_fault(struct pt_regs *regs)
21302+{
21303+ if (v8086_mode(regs))
21304+ return 1;
21305+
21306+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21307+ return 1;
21308+
21309+#ifdef CONFIG_X86_32
21310+ return pax_handle_fetch_fault_32(regs);
21311+#else
21312+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21313+ return pax_handle_fetch_fault_32(regs);
21314+ else
21315+ return pax_handle_fetch_fault_64(regs);
21316+#endif
21317+}
21318+#endif
21319+
21320+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21321+void pax_report_insns(void *pc, void *sp)
21322+{
21323+ long i;
21324+
21325+ printk(KERN_ERR "PAX: bytes at PC: ");
21326+ for (i = 0; i < 20; i++) {
21327+ unsigned char c;
21328+ if (get_user(c, (__force unsigned char __user *)pc+i))
21329+ printk(KERN_CONT "?? ");
21330+ else
21331+ printk(KERN_CONT "%02x ", c);
21332+ }
21333+ printk("\n");
21334+
21335+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21336+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
21337+ unsigned long c;
21338+ if (get_user(c, (__force unsigned long __user *)sp+i))
21339+#ifdef CONFIG_X86_32
21340+ printk(KERN_CONT "???????? ");
21341+#else
21342+ printk(KERN_CONT "???????????????? ");
21343+#endif
21344+ else
21345+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21346+ }
21347+ printk("\n");
21348+}
21349+#endif
21350+
21351+/**
21352+ * probe_kernel_write(): safely attempt to write to a location
21353+ * @dst: address to write to
21354+ * @src: pointer to the data that shall be written
21355+ * @size: size of the data chunk
21356+ *
21357+ * Safely write to address @dst from the buffer at @src. If a kernel fault
21358+ * happens, handle that and return -EFAULT.
21359+ */
21360+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21361+{
21362+ long ret;
21363+ mm_segment_t old_fs = get_fs();
21364+
21365+ set_fs(KERNEL_DS);
21366+ pagefault_disable();
21367+ pax_open_kernel();
21368+ ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21369+ pax_close_kernel();
21370+ pagefault_enable();
21371+ set_fs(old_fs);
21372+
21373+ return ret ? -EFAULT : 0;
21374+}
21375diff -urNp linux-2.6.32.43/arch/x86/mm/gup.c linux-2.6.32.43/arch/x86/mm/gup.c
21376--- linux-2.6.32.43/arch/x86/mm/gup.c 2011-03-27 14:31:47.000000000 -0400
21377+++ linux-2.6.32.43/arch/x86/mm/gup.c 2011-04-17 15:56:46.000000000 -0400
21378@@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long
21379 addr = start;
21380 len = (unsigned long) nr_pages << PAGE_SHIFT;
21381 end = start + len;
21382- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21383+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21384 (void __user *)start, len)))
21385 return 0;
21386
21387diff -urNp linux-2.6.32.43/arch/x86/mm/highmem_32.c linux-2.6.32.43/arch/x86/mm/highmem_32.c
21388--- linux-2.6.32.43/arch/x86/mm/highmem_32.c 2011-03-27 14:31:47.000000000 -0400
21389+++ linux-2.6.32.43/arch/x86/mm/highmem_32.c 2011-04-17 15:56:46.000000000 -0400
21390@@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page
21391 idx = type + KM_TYPE_NR*smp_processor_id();
21392 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21393 BUG_ON(!pte_none(*(kmap_pte-idx)));
21394+
21395+ pax_open_kernel();
21396 set_pte(kmap_pte-idx, mk_pte(page, prot));
21397+ pax_close_kernel();
21398
21399 return (void *)vaddr;
21400 }
21401diff -urNp linux-2.6.32.43/arch/x86/mm/hugetlbpage.c linux-2.6.32.43/arch/x86/mm/hugetlbpage.c
21402--- linux-2.6.32.43/arch/x86/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
21403+++ linux-2.6.32.43/arch/x86/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
21404@@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmappe
21405 struct hstate *h = hstate_file(file);
21406 struct mm_struct *mm = current->mm;
21407 struct vm_area_struct *vma;
21408- unsigned long start_addr;
21409+ unsigned long start_addr, pax_task_size = TASK_SIZE;
21410+
21411+#ifdef CONFIG_PAX_SEGMEXEC
21412+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21413+ pax_task_size = SEGMEXEC_TASK_SIZE;
21414+#endif
21415+
21416+ pax_task_size -= PAGE_SIZE;
21417
21418 if (len > mm->cached_hole_size) {
21419- start_addr = mm->free_area_cache;
21420+ start_addr = mm->free_area_cache;
21421 } else {
21422- start_addr = TASK_UNMAPPED_BASE;
21423- mm->cached_hole_size = 0;
21424+ start_addr = mm->mmap_base;
21425+ mm->cached_hole_size = 0;
21426 }
21427
21428 full_search:
21429@@ -281,26 +288,27 @@ full_search:
21430
21431 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21432 /* At this point: (!vma || addr < vma->vm_end). */
21433- if (TASK_SIZE - len < addr) {
21434+ if (pax_task_size - len < addr) {
21435 /*
21436 * Start a new search - just in case we missed
21437 * some holes.
21438 */
21439- if (start_addr != TASK_UNMAPPED_BASE) {
21440- start_addr = TASK_UNMAPPED_BASE;
21441+ if (start_addr != mm->mmap_base) {
21442+ start_addr = mm->mmap_base;
21443 mm->cached_hole_size = 0;
21444 goto full_search;
21445 }
21446 return -ENOMEM;
21447 }
21448- if (!vma || addr + len <= vma->vm_start) {
21449- mm->free_area_cache = addr + len;
21450- return addr;
21451- }
21452+ if (check_heap_stack_gap(vma, addr, len))
21453+ break;
21454 if (addr + mm->cached_hole_size < vma->vm_start)
21455 mm->cached_hole_size = vma->vm_start - addr;
21456 addr = ALIGN(vma->vm_end, huge_page_size(h));
21457 }
21458+
21459+ mm->free_area_cache = addr + len;
21460+ return addr;
21461 }
21462
21463 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21464@@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmappe
21465 {
21466 struct hstate *h = hstate_file(file);
21467 struct mm_struct *mm = current->mm;
21468- struct vm_area_struct *vma, *prev_vma;
21469- unsigned long base = mm->mmap_base, addr = addr0;
21470+ struct vm_area_struct *vma;
21471+ unsigned long base = mm->mmap_base, addr;
21472 unsigned long largest_hole = mm->cached_hole_size;
21473- int first_time = 1;
21474
21475 /* don't allow allocations above current base */
21476 if (mm->free_area_cache > base)
21477@@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmappe
21478 largest_hole = 0;
21479 mm->free_area_cache = base;
21480 }
21481-try_again:
21482+
21483 /* make sure it can fit in the remaining address space */
21484 if (mm->free_area_cache < len)
21485 goto fail;
21486
21487 /* either no address requested or cant fit in requested address hole */
21488- addr = (mm->free_area_cache - len) & huge_page_mask(h);
21489+ addr = (mm->free_area_cache - len);
21490 do {
21491+ addr &= huge_page_mask(h);
21492+ vma = find_vma(mm, addr);
21493 /*
21494 * Lookup failure means no vma is above this address,
21495 * i.e. return with success:
21496- */
21497- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21498- return addr;
21499-
21500- /*
21501 * new region fits between prev_vma->vm_end and
21502 * vma->vm_start, use it:
21503 */
21504- if (addr + len <= vma->vm_start &&
21505- (!prev_vma || (addr >= prev_vma->vm_end))) {
21506+ if (check_heap_stack_gap(vma, addr, len)) {
21507 /* remember the address as a hint for next time */
21508- mm->cached_hole_size = largest_hole;
21509- return (mm->free_area_cache = addr);
21510- } else {
21511- /* pull free_area_cache down to the first hole */
21512- if (mm->free_area_cache == vma->vm_end) {
21513- mm->free_area_cache = vma->vm_start;
21514- mm->cached_hole_size = largest_hole;
21515- }
21516+ mm->cached_hole_size = largest_hole;
21517+ return (mm->free_area_cache = addr);
21518+ }
21519+ /* pull free_area_cache down to the first hole */
21520+ if (mm->free_area_cache == vma->vm_end) {
21521+ mm->free_area_cache = vma->vm_start;
21522+ mm->cached_hole_size = largest_hole;
21523 }
21524
21525 /* remember the largest hole we saw so far */
21526 if (addr + largest_hole < vma->vm_start)
21527- largest_hole = vma->vm_start - addr;
21528+ largest_hole = vma->vm_start - addr;
21529
21530 /* try just below the current vma->vm_start */
21531- addr = (vma->vm_start - len) & huge_page_mask(h);
21532- } while (len <= vma->vm_start);
21533+ addr = skip_heap_stack_gap(vma, len);
21534+ } while (!IS_ERR_VALUE(addr));
21535
21536 fail:
21537 /*
21538- * if hint left us with no space for the requested
21539- * mapping then try again:
21540- */
21541- if (first_time) {
21542- mm->free_area_cache = base;
21543- largest_hole = 0;
21544- first_time = 0;
21545- goto try_again;
21546- }
21547- /*
21548 * A failed mmap() very likely causes application failure,
21549 * so fall back to the bottom-up function here. This scenario
21550 * can happen with large stack limits and large mmap()
21551 * allocations.
21552 */
21553- mm->free_area_cache = TASK_UNMAPPED_BASE;
21554+
21555+#ifdef CONFIG_PAX_SEGMEXEC
21556+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21557+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21558+ else
21559+#endif
21560+
21561+ mm->mmap_base = TASK_UNMAPPED_BASE;
21562+
21563+#ifdef CONFIG_PAX_RANDMMAP
21564+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21565+ mm->mmap_base += mm->delta_mmap;
21566+#endif
21567+
21568+ mm->free_area_cache = mm->mmap_base;
21569 mm->cached_hole_size = ~0UL;
21570 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21571 len, pgoff, flags);
21572@@ -387,6 +393,7 @@ fail:
21573 /*
21574 * Restore the topdown base:
21575 */
21576+ mm->mmap_base = base;
21577 mm->free_area_cache = base;
21578 mm->cached_hole_size = ~0UL;
21579
21580@@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *f
21581 struct hstate *h = hstate_file(file);
21582 struct mm_struct *mm = current->mm;
21583 struct vm_area_struct *vma;
21584+ unsigned long pax_task_size = TASK_SIZE;
21585
21586 if (len & ~huge_page_mask(h))
21587 return -EINVAL;
21588- if (len > TASK_SIZE)
21589+
21590+#ifdef CONFIG_PAX_SEGMEXEC
21591+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21592+ pax_task_size = SEGMEXEC_TASK_SIZE;
21593+#endif
21594+
21595+ pax_task_size -= PAGE_SIZE;
21596+
21597+ if (len > pax_task_size)
21598 return -ENOMEM;
21599
21600 if (flags & MAP_FIXED) {
21601@@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *f
21602 if (addr) {
21603 addr = ALIGN(addr, huge_page_size(h));
21604 vma = find_vma(mm, addr);
21605- if (TASK_SIZE - len >= addr &&
21606- (!vma || addr + len <= vma->vm_start))
21607+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21608 return addr;
21609 }
21610 if (mm->get_unmapped_area == arch_get_unmapped_area)
21611diff -urNp linux-2.6.32.43/arch/x86/mm/init_32.c linux-2.6.32.43/arch/x86/mm/init_32.c
21612--- linux-2.6.32.43/arch/x86/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
21613+++ linux-2.6.32.43/arch/x86/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
21614@@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
21615 }
21616
21617 /*
21618- * Creates a middle page table and puts a pointer to it in the
21619- * given global directory entry. This only returns the gd entry
21620- * in non-PAE compilation mode, since the middle layer is folded.
21621- */
21622-static pmd_t * __init one_md_table_init(pgd_t *pgd)
21623-{
21624- pud_t *pud;
21625- pmd_t *pmd_table;
21626-
21627-#ifdef CONFIG_X86_PAE
21628- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21629- if (after_bootmem)
21630- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21631- else
21632- pmd_table = (pmd_t *)alloc_low_page();
21633- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21634- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21635- pud = pud_offset(pgd, 0);
21636- BUG_ON(pmd_table != pmd_offset(pud, 0));
21637-
21638- return pmd_table;
21639- }
21640-#endif
21641- pud = pud_offset(pgd, 0);
21642- pmd_table = pmd_offset(pud, 0);
21643-
21644- return pmd_table;
21645-}
21646-
21647-/*
21648 * Create a page table and place a pointer to it in a middle page
21649 * directory entry:
21650 */
21651@@ -121,13 +91,28 @@ static pte_t * __init one_page_table_ini
21652 page_table = (pte_t *)alloc_low_page();
21653
21654 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
21655+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21656+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
21657+#else
21658 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
21659+#endif
21660 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
21661 }
21662
21663 return pte_offset_kernel(pmd, 0);
21664 }
21665
21666+static pmd_t * __init one_md_table_init(pgd_t *pgd)
21667+{
21668+ pud_t *pud;
21669+ pmd_t *pmd_table;
21670+
21671+ pud = pud_offset(pgd, 0);
21672+ pmd_table = pmd_offset(pud, 0);
21673+
21674+ return pmd_table;
21675+}
21676+
21677 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
21678 {
21679 int pgd_idx = pgd_index(vaddr);
21680@@ -201,6 +186,7 @@ page_table_range_init(unsigned long star
21681 int pgd_idx, pmd_idx;
21682 unsigned long vaddr;
21683 pgd_t *pgd;
21684+ pud_t *pud;
21685 pmd_t *pmd;
21686 pte_t *pte = NULL;
21687
21688@@ -210,8 +196,13 @@ page_table_range_init(unsigned long star
21689 pgd = pgd_base + pgd_idx;
21690
21691 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
21692- pmd = one_md_table_init(pgd);
21693- pmd = pmd + pmd_index(vaddr);
21694+ pud = pud_offset(pgd, vaddr);
21695+ pmd = pmd_offset(pud, vaddr);
21696+
21697+#ifdef CONFIG_X86_PAE
21698+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21699+#endif
21700+
21701 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
21702 pmd++, pmd_idx++) {
21703 pte = page_table_kmap_check(one_page_table_init(pmd),
21704@@ -223,11 +214,20 @@ page_table_range_init(unsigned long star
21705 }
21706 }
21707
21708-static inline int is_kernel_text(unsigned long addr)
21709+static inline int is_kernel_text(unsigned long start, unsigned long end)
21710 {
21711- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
21712- return 1;
21713- return 0;
21714+ if ((start > ktla_ktva((unsigned long)_etext) ||
21715+ end <= ktla_ktva((unsigned long)_stext)) &&
21716+ (start > ktla_ktva((unsigned long)_einittext) ||
21717+ end <= ktla_ktva((unsigned long)_sinittext)) &&
21718+
21719+#ifdef CONFIG_ACPI_SLEEP
21720+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
21721+#endif
21722+
21723+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
21724+ return 0;
21725+ return 1;
21726 }
21727
21728 /*
21729@@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned lo
21730 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
21731 unsigned long start_pfn, end_pfn;
21732 pgd_t *pgd_base = swapper_pg_dir;
21733- int pgd_idx, pmd_idx, pte_ofs;
21734+ unsigned int pgd_idx, pmd_idx, pte_ofs;
21735 unsigned long pfn;
21736 pgd_t *pgd;
21737+ pud_t *pud;
21738 pmd_t *pmd;
21739 pte_t *pte;
21740 unsigned pages_2m, pages_4k;
21741@@ -278,8 +279,13 @@ repeat:
21742 pfn = start_pfn;
21743 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21744 pgd = pgd_base + pgd_idx;
21745- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
21746- pmd = one_md_table_init(pgd);
21747+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
21748+ pud = pud_offset(pgd, 0);
21749+ pmd = pmd_offset(pud, 0);
21750+
21751+#ifdef CONFIG_X86_PAE
21752+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
21753+#endif
21754
21755 if (pfn >= end_pfn)
21756 continue;
21757@@ -291,14 +297,13 @@ repeat:
21758 #endif
21759 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
21760 pmd++, pmd_idx++) {
21761- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
21762+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
21763
21764 /*
21765 * Map with big pages if possible, otherwise
21766 * create normal page tables:
21767 */
21768 if (use_pse) {
21769- unsigned int addr2;
21770 pgprot_t prot = PAGE_KERNEL_LARGE;
21771 /*
21772 * first pass will use the same initial
21773@@ -308,11 +313,7 @@ repeat:
21774 __pgprot(PTE_IDENT_ATTR |
21775 _PAGE_PSE);
21776
21777- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
21778- PAGE_OFFSET + PAGE_SIZE-1;
21779-
21780- if (is_kernel_text(addr) ||
21781- is_kernel_text(addr2))
21782+ if (is_kernel_text(address, address + PMD_SIZE))
21783 prot = PAGE_KERNEL_LARGE_EXEC;
21784
21785 pages_2m++;
21786@@ -329,7 +330,7 @@ repeat:
21787 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
21788 pte += pte_ofs;
21789 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
21790- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
21791+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
21792 pgprot_t prot = PAGE_KERNEL;
21793 /*
21794 * first pass will use the same initial
21795@@ -337,7 +338,7 @@ repeat:
21796 */
21797 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
21798
21799- if (is_kernel_text(addr))
21800+ if (is_kernel_text(address, address + PAGE_SIZE))
21801 prot = PAGE_KERNEL_EXEC;
21802
21803 pages_4k++;
21804@@ -489,7 +490,7 @@ void __init native_pagetable_setup_start
21805
21806 pud = pud_offset(pgd, va);
21807 pmd = pmd_offset(pud, va);
21808- if (!pmd_present(*pmd))
21809+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
21810 break;
21811
21812 pte = pte_offset_kernel(pmd, va);
21813@@ -541,9 +542,7 @@ void __init early_ioremap_page_table_ran
21814
21815 static void __init pagetable_init(void)
21816 {
21817- pgd_t *pgd_base = swapper_pg_dir;
21818-
21819- permanent_kmaps_init(pgd_base);
21820+ permanent_kmaps_init(swapper_pg_dir);
21821 }
21822
21823 #ifdef CONFIG_ACPI_SLEEP
21824@@ -551,12 +550,12 @@ static void __init pagetable_init(void)
21825 * ACPI suspend needs this for resume, because things like the intel-agp
21826 * driver might have split up a kernel 4MB mapping.
21827 */
21828-char swsusp_pg_dir[PAGE_SIZE]
21829+pgd_t swsusp_pg_dir[PTRS_PER_PGD]
21830 __attribute__ ((aligned(PAGE_SIZE)));
21831
21832 static inline void save_pg_dir(void)
21833 {
21834- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
21835+ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
21836 }
21837 #else /* !CONFIG_ACPI_SLEEP */
21838 static inline void save_pg_dir(void)
21839@@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
21840 flush_tlb_all();
21841 }
21842
21843-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
21844+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
21845 EXPORT_SYMBOL_GPL(__supported_pte_mask);
21846
21847 /* user-defined highmem size */
21848@@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void
21849 * Initialize the boot-time allocator (with low memory only):
21850 */
21851 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
21852- bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
21853+ bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
21854 PAGE_SIZE);
21855 if (bootmap == -1L)
21856 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
21857@@ -864,6 +863,12 @@ void __init mem_init(void)
21858
21859 pci_iommu_alloc();
21860
21861+#ifdef CONFIG_PAX_PER_CPU_PGD
21862+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
21863+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21864+ KERNEL_PGD_PTRS);
21865+#endif
21866+
21867 #ifdef CONFIG_FLATMEM
21868 BUG_ON(!mem_map);
21869 #endif
21870@@ -881,7 +886,7 @@ void __init mem_init(void)
21871 set_highmem_pages_init();
21872
21873 codesize = (unsigned long) &_etext - (unsigned long) &_text;
21874- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
21875+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
21876 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
21877
21878 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
21879@@ -923,10 +928,10 @@ void __init mem_init(void)
21880 ((unsigned long)&__init_end -
21881 (unsigned long)&__init_begin) >> 10,
21882
21883- (unsigned long)&_etext, (unsigned long)&_edata,
21884- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
21885+ (unsigned long)&_sdata, (unsigned long)&_edata,
21886+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
21887
21888- (unsigned long)&_text, (unsigned long)&_etext,
21889+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
21890 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
21891
21892 /*
21893@@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
21894 if (!kernel_set_to_readonly)
21895 return;
21896
21897+ start = ktla_ktva(start);
21898 pr_debug("Set kernel text: %lx - %lx for read write\n",
21899 start, start+size);
21900
21901@@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
21902 if (!kernel_set_to_readonly)
21903 return;
21904
21905+ start = ktla_ktva(start);
21906 pr_debug("Set kernel text: %lx - %lx for read only\n",
21907 start, start+size);
21908
21909@@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
21910 unsigned long start = PFN_ALIGN(_text);
21911 unsigned long size = PFN_ALIGN(_etext) - start;
21912
21913+ start = ktla_ktva(start);
21914 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
21915 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
21916 size >> 10);
21917diff -urNp linux-2.6.32.43/arch/x86/mm/init_64.c linux-2.6.32.43/arch/x86/mm/init_64.c
21918--- linux-2.6.32.43/arch/x86/mm/init_64.c 2011-04-17 17:00:52.000000000 -0400
21919+++ linux-2.6.32.43/arch/x86/mm/init_64.c 2011-04-17 17:03:05.000000000 -0400
21920@@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
21921 pmd = fill_pmd(pud, vaddr);
21922 pte = fill_pte(pmd, vaddr);
21923
21924+ pax_open_kernel();
21925 set_pte(pte, new_pte);
21926+ pax_close_kernel();
21927
21928 /*
21929 * It's enough to flush this one mapping.
21930@@ -223,14 +225,12 @@ static void __init __init_extra_mapping(
21931 pgd = pgd_offset_k((unsigned long)__va(phys));
21932 if (pgd_none(*pgd)) {
21933 pud = (pud_t *) spp_getpage();
21934- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
21935- _PAGE_USER));
21936+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
21937 }
21938 pud = pud_offset(pgd, (unsigned long)__va(phys));
21939 if (pud_none(*pud)) {
21940 pmd = (pmd_t *) spp_getpage();
21941- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
21942- _PAGE_USER));
21943+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
21944 }
21945 pmd = pmd_offset(pud, phys);
21946 BUG_ON(!pmd_none(*pmd));
21947@@ -675,6 +675,12 @@ void __init mem_init(void)
21948
21949 pci_iommu_alloc();
21950
21951+#ifdef CONFIG_PAX_PER_CPU_PGD
21952+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
21953+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21954+ KERNEL_PGD_PTRS);
21955+#endif
21956+
21957 /* clear_bss() already clear the empty_zero_page */
21958
21959 reservedpages = 0;
21960@@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
21961 static struct vm_area_struct gate_vma = {
21962 .vm_start = VSYSCALL_START,
21963 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
21964- .vm_page_prot = PAGE_READONLY_EXEC,
21965- .vm_flags = VM_READ | VM_EXEC
21966+ .vm_page_prot = PAGE_READONLY,
21967+ .vm_flags = VM_READ
21968 };
21969
21970 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
21971@@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long a
21972
21973 const char *arch_vma_name(struct vm_area_struct *vma)
21974 {
21975- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
21976+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
21977 return "[vdso]";
21978 if (vma == &gate_vma)
21979 return "[vsyscall]";
21980diff -urNp linux-2.6.32.43/arch/x86/mm/init.c linux-2.6.32.43/arch/x86/mm/init.c
21981--- linux-2.6.32.43/arch/x86/mm/init.c 2011-04-17 17:00:52.000000000 -0400
21982+++ linux-2.6.32.43/arch/x86/mm/init.c 2011-06-07 19:06:09.000000000 -0400
21983@@ -69,11 +69,7 @@ static void __init find_early_table_spac
21984 * cause a hotspot and fill up ZONE_DMA. The page tables
21985 * need roughly 0.5KB per GB.
21986 */
21987-#ifdef CONFIG_X86_32
21988- start = 0x7000;
21989-#else
21990- start = 0x8000;
21991-#endif
21992+ start = 0x100000;
21993 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
21994 tables, PAGE_SIZE);
21995 if (e820_table_start == -1UL)
21996@@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_m
21997 #endif
21998
21999 set_nx();
22000- if (nx_enabled)
22001+ if (nx_enabled && cpu_has_nx)
22002 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
22003
22004 /* Enable PSE if available */
22005@@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_m
22006 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
22007 * mmio resources as well as potential bios/acpi data regions.
22008 */
22009+
22010 int devmem_is_allowed(unsigned long pagenr)
22011 {
22012+#ifdef CONFIG_GRKERNSEC_KMEM
22013+ /* allow BDA */
22014+ if (!pagenr)
22015+ return 1;
22016+ /* allow EBDA */
22017+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22018+ return 1;
22019+ /* allow ISA/video mem */
22020+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22021+ return 1;
22022+ /* throw out everything else below 1MB */
22023+ if (pagenr <= 256)
22024+ return 0;
22025+#else
22026 if (pagenr <= 256)
22027 return 1;
22028+#endif
22029+
22030 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22031 return 0;
22032 if (!page_is_ram(pagenr))
22033@@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigne
22034
22035 void free_initmem(void)
22036 {
22037+
22038+#ifdef CONFIG_PAX_KERNEXEC
22039+#ifdef CONFIG_X86_32
22040+ /* PaX: limit KERNEL_CS to actual size */
22041+ unsigned long addr, limit;
22042+ struct desc_struct d;
22043+ int cpu;
22044+
22045+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22046+ limit = (limit - 1UL) >> PAGE_SHIFT;
22047+
22048+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22049+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
22050+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22051+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22052+ }
22053+
22054+ /* PaX: make KERNEL_CS read-only */
22055+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22056+ if (!paravirt_enabled())
22057+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22058+/*
22059+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22060+ pgd = pgd_offset_k(addr);
22061+ pud = pud_offset(pgd, addr);
22062+ pmd = pmd_offset(pud, addr);
22063+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22064+ }
22065+*/
22066+#ifdef CONFIG_X86_PAE
22067+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22068+/*
22069+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22070+ pgd = pgd_offset_k(addr);
22071+ pud = pud_offset(pgd, addr);
22072+ pmd = pmd_offset(pud, addr);
22073+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22074+ }
22075+*/
22076+#endif
22077+
22078+#ifdef CONFIG_MODULES
22079+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22080+#endif
22081+
22082+#else
22083+ pgd_t *pgd;
22084+ pud_t *pud;
22085+ pmd_t *pmd;
22086+ unsigned long addr, end;
22087+
22088+ /* PaX: make kernel code/rodata read-only, rest non-executable */
22089+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22090+ pgd = pgd_offset_k(addr);
22091+ pud = pud_offset(pgd, addr);
22092+ pmd = pmd_offset(pud, addr);
22093+ if (!pmd_present(*pmd))
22094+ continue;
22095+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22096+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22097+ else
22098+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22099+ }
22100+
22101+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22102+ end = addr + KERNEL_IMAGE_SIZE;
22103+ for (; addr < end; addr += PMD_SIZE) {
22104+ pgd = pgd_offset_k(addr);
22105+ pud = pud_offset(pgd, addr);
22106+ pmd = pmd_offset(pud, addr);
22107+ if (!pmd_present(*pmd))
22108+ continue;
22109+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22110+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22111+ }
22112+#endif
22113+
22114+ flush_tlb_all();
22115+#endif
22116+
22117 free_init_pages("unused kernel memory",
22118 (unsigned long)(&__init_begin),
22119 (unsigned long)(&__init_end));
22120diff -urNp linux-2.6.32.43/arch/x86/mm/iomap_32.c linux-2.6.32.43/arch/x86/mm/iomap_32.c
22121--- linux-2.6.32.43/arch/x86/mm/iomap_32.c 2011-03-27 14:31:47.000000000 -0400
22122+++ linux-2.6.32.43/arch/x86/mm/iomap_32.c 2011-04-17 15:56:46.000000000 -0400
22123@@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22124 debug_kmap_atomic(type);
22125 idx = type + KM_TYPE_NR * smp_processor_id();
22126 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22127+
22128+ pax_open_kernel();
22129 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22130+ pax_close_kernel();
22131+
22132 arch_flush_lazy_mmu_mode();
22133
22134 return (void *)vaddr;
22135diff -urNp linux-2.6.32.43/arch/x86/mm/ioremap.c linux-2.6.32.43/arch/x86/mm/ioremap.c
22136--- linux-2.6.32.43/arch/x86/mm/ioremap.c 2011-03-27 14:31:47.000000000 -0400
22137+++ linux-2.6.32.43/arch/x86/mm/ioremap.c 2011-04-17 15:56:46.000000000 -0400
22138@@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
22139 * Second special case: Some BIOSen report the PC BIOS
22140 * area (640->1Mb) as ram even though it is not.
22141 */
22142- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
22143- pagenr < (BIOS_END >> PAGE_SHIFT))
22144+ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
22145+ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22146 return 0;
22147
22148 for (i = 0; i < e820.nr_map; i++) {
22149@@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(re
22150 /*
22151 * Don't allow anybody to remap normal RAM that we're using..
22152 */
22153- for (pfn = phys_addr >> PAGE_SHIFT;
22154- (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
22155- pfn++) {
22156-
22157+ for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
22158 int is_ram = page_is_ram(pfn);
22159
22160- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22161+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22162 return NULL;
22163 WARN_ON_ONCE(is_ram);
22164 }
22165@@ -407,7 +404,7 @@ static int __init early_ioremap_debug_se
22166 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22167
22168 static __initdata int after_paging_init;
22169-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22170+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22171
22172 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22173 {
22174@@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
22175 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22176
22177 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22178- memset(bm_pte, 0, sizeof(bm_pte));
22179- pmd_populate_kernel(&init_mm, pmd, bm_pte);
22180+ pmd_populate_user(&init_mm, pmd, bm_pte);
22181
22182 /*
22183 * The boot-ioremap range spans multiple pmds, for which
22184diff -urNp linux-2.6.32.43/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.32.43/arch/x86/mm/kmemcheck/kmemcheck.c
22185--- linux-2.6.32.43/arch/x86/mm/kmemcheck/kmemcheck.c 2011-03-27 14:31:47.000000000 -0400
22186+++ linux-2.6.32.43/arch/x86/mm/kmemcheck/kmemcheck.c 2011-04-17 15:56:46.000000000 -0400
22187@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22188 * memory (e.g. tracked pages)? For now, we need this to avoid
22189 * invoking kmemcheck for PnP BIOS calls.
22190 */
22191- if (regs->flags & X86_VM_MASK)
22192+ if (v8086_mode(regs))
22193 return false;
22194- if (regs->cs != __KERNEL_CS)
22195+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22196 return false;
22197
22198 pte = kmemcheck_pte_lookup(address);
22199diff -urNp linux-2.6.32.43/arch/x86/mm/mmap.c linux-2.6.32.43/arch/x86/mm/mmap.c
22200--- linux-2.6.32.43/arch/x86/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
22201+++ linux-2.6.32.43/arch/x86/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
22202@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22203 * Leave an at least ~128 MB hole with possible stack randomization.
22204 */
22205 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22206-#define MAX_GAP (TASK_SIZE/6*5)
22207+#define MAX_GAP (pax_task_size/6*5)
22208
22209 /*
22210 * True on X86_32 or when emulating IA32 on X86_64
22211@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22212 return rnd << PAGE_SHIFT;
22213 }
22214
22215-static unsigned long mmap_base(void)
22216+static unsigned long mmap_base(struct mm_struct *mm)
22217 {
22218 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
22219+ unsigned long pax_task_size = TASK_SIZE;
22220+
22221+#ifdef CONFIG_PAX_SEGMEXEC
22222+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22223+ pax_task_size = SEGMEXEC_TASK_SIZE;
22224+#endif
22225
22226 if (gap < MIN_GAP)
22227 gap = MIN_GAP;
22228 else if (gap > MAX_GAP)
22229 gap = MAX_GAP;
22230
22231- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22232+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22233 }
22234
22235 /*
22236 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22237 * does, but not when emulating X86_32
22238 */
22239-static unsigned long mmap_legacy_base(void)
22240+static unsigned long mmap_legacy_base(struct mm_struct *mm)
22241 {
22242- if (mmap_is_ia32())
22243+ if (mmap_is_ia32()) {
22244+
22245+#ifdef CONFIG_PAX_SEGMEXEC
22246+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22247+ return SEGMEXEC_TASK_UNMAPPED_BASE;
22248+ else
22249+#endif
22250+
22251 return TASK_UNMAPPED_BASE;
22252- else
22253+ } else
22254 return TASK_UNMAPPED_BASE + mmap_rnd();
22255 }
22256
22257@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22258 void arch_pick_mmap_layout(struct mm_struct *mm)
22259 {
22260 if (mmap_is_legacy()) {
22261- mm->mmap_base = mmap_legacy_base();
22262+ mm->mmap_base = mmap_legacy_base(mm);
22263+
22264+#ifdef CONFIG_PAX_RANDMMAP
22265+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22266+ mm->mmap_base += mm->delta_mmap;
22267+#endif
22268+
22269 mm->get_unmapped_area = arch_get_unmapped_area;
22270 mm->unmap_area = arch_unmap_area;
22271 } else {
22272- mm->mmap_base = mmap_base();
22273+ mm->mmap_base = mmap_base(mm);
22274+
22275+#ifdef CONFIG_PAX_RANDMMAP
22276+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22277+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22278+#endif
22279+
22280 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22281 mm->unmap_area = arch_unmap_area_topdown;
22282 }
22283diff -urNp linux-2.6.32.43/arch/x86/mm/mmio-mod.c linux-2.6.32.43/arch/x86/mm/mmio-mod.c
22284--- linux-2.6.32.43/arch/x86/mm/mmio-mod.c 2011-03-27 14:31:47.000000000 -0400
22285+++ linux-2.6.32.43/arch/x86/mm/mmio-mod.c 2011-07-06 19:53:33.000000000 -0400
22286@@ -193,7 +193,7 @@ static void pre(struct kmmio_probe *p, s
22287 break;
22288 default:
22289 {
22290- unsigned char *ip = (unsigned char *)instptr;
22291+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
22292 my_trace->opcode = MMIO_UNKNOWN_OP;
22293 my_trace->width = 0;
22294 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
22295@@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p,
22296 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22297 void __iomem *addr)
22298 {
22299- static atomic_t next_id;
22300+ static atomic_unchecked_t next_id;
22301 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22302 /* These are page-unaligned. */
22303 struct mmiotrace_map map = {
22304@@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_
22305 .private = trace
22306 },
22307 .phys = offset,
22308- .id = atomic_inc_return(&next_id)
22309+ .id = atomic_inc_return_unchecked(&next_id)
22310 };
22311 map.map_id = trace->id;
22312
22313diff -urNp linux-2.6.32.43/arch/x86/mm/numa_32.c linux-2.6.32.43/arch/x86/mm/numa_32.c
22314--- linux-2.6.32.43/arch/x86/mm/numa_32.c 2011-03-27 14:31:47.000000000 -0400
22315+++ linux-2.6.32.43/arch/x86/mm/numa_32.c 2011-04-17 15:56:46.000000000 -0400
22316@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
22317 }
22318 #endif
22319
22320-extern unsigned long find_max_low_pfn(void);
22321 extern unsigned long highend_pfn, highstart_pfn;
22322
22323 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22324diff -urNp linux-2.6.32.43/arch/x86/mm/pageattr.c linux-2.6.32.43/arch/x86/mm/pageattr.c
22325--- linux-2.6.32.43/arch/x86/mm/pageattr.c 2011-03-27 14:31:47.000000000 -0400
22326+++ linux-2.6.32.43/arch/x86/mm/pageattr.c 2011-04-17 15:56:46.000000000 -0400
22327@@ -261,16 +261,17 @@ static inline pgprot_t static_protection
22328 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
22329 */
22330 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22331- pgprot_val(forbidden) |= _PAGE_NX;
22332+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22333
22334 /*
22335 * The kernel text needs to be executable for obvious reasons
22336 * Does not cover __inittext since that is gone later on. On
22337 * 64bit we do not enforce !NX on the low mapping
22338 */
22339- if (within(address, (unsigned long)_text, (unsigned long)_etext))
22340- pgprot_val(forbidden) |= _PAGE_NX;
22341+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22342+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22343
22344+#ifdef CONFIG_DEBUG_RODATA
22345 /*
22346 * The .rodata section needs to be read-only. Using the pfn
22347 * catches all aliases.
22348@@ -278,6 +279,14 @@ static inline pgprot_t static_protection
22349 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22350 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22351 pgprot_val(forbidden) |= _PAGE_RW;
22352+#endif
22353+
22354+#ifdef CONFIG_PAX_KERNEXEC
22355+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22356+ pgprot_val(forbidden) |= _PAGE_RW;
22357+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22358+ }
22359+#endif
22360
22361 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22362
22363@@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22364 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22365 {
22366 /* change init_mm */
22367+ pax_open_kernel();
22368 set_pte_atomic(kpte, pte);
22369+
22370 #ifdef CONFIG_X86_32
22371 if (!SHARED_KERNEL_PMD) {
22372+
22373+#ifdef CONFIG_PAX_PER_CPU_PGD
22374+ unsigned long cpu;
22375+#else
22376 struct page *page;
22377+#endif
22378
22379+#ifdef CONFIG_PAX_PER_CPU_PGD
22380+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22381+ pgd_t *pgd = get_cpu_pgd(cpu);
22382+#else
22383 list_for_each_entry(page, &pgd_list, lru) {
22384- pgd_t *pgd;
22385+ pgd_t *pgd = (pgd_t *)page_address(page);
22386+#endif
22387+
22388 pud_t *pud;
22389 pmd_t *pmd;
22390
22391- pgd = (pgd_t *)page_address(page) + pgd_index(address);
22392+ pgd += pgd_index(address);
22393 pud = pud_offset(pgd, address);
22394 pmd = pmd_offset(pud, address);
22395 set_pte_atomic((pte_t *)pmd, pte);
22396 }
22397 }
22398 #endif
22399+ pax_close_kernel();
22400 }
22401
22402 static int
22403diff -urNp linux-2.6.32.43/arch/x86/mm/pageattr-test.c linux-2.6.32.43/arch/x86/mm/pageattr-test.c
22404--- linux-2.6.32.43/arch/x86/mm/pageattr-test.c 2011-03-27 14:31:47.000000000 -0400
22405+++ linux-2.6.32.43/arch/x86/mm/pageattr-test.c 2011-04-17 15:56:46.000000000 -0400
22406@@ -36,7 +36,7 @@ enum {
22407
22408 static int pte_testbit(pte_t pte)
22409 {
22410- return pte_flags(pte) & _PAGE_UNUSED1;
22411+ return pte_flags(pte) & _PAGE_CPA_TEST;
22412 }
22413
22414 struct split_state {
22415diff -urNp linux-2.6.32.43/arch/x86/mm/pat.c linux-2.6.32.43/arch/x86/mm/pat.c
22416--- linux-2.6.32.43/arch/x86/mm/pat.c 2011-03-27 14:31:47.000000000 -0400
22417+++ linux-2.6.32.43/arch/x86/mm/pat.c 2011-04-17 15:56:46.000000000 -0400
22418@@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct
22419
22420 conflict:
22421 printk(KERN_INFO "%s:%d conflicting memory types "
22422- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
22423+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
22424 new->end, cattr_name(new->type), cattr_name(entry->type));
22425 return -EBUSY;
22426 }
22427@@ -559,7 +559,7 @@ unlock_ret:
22428
22429 if (err) {
22430 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22431- current->comm, current->pid, start, end);
22432+ current->comm, task_pid_nr(current), start, end);
22433 }
22434
22435 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
22436@@ -689,8 +689,8 @@ static inline int range_is_allowed(unsig
22437 while (cursor < to) {
22438 if (!devmem_is_allowed(pfn)) {
22439 printk(KERN_INFO
22440- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22441- current->comm, from, to);
22442+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22443+ current->comm, from, to, cursor);
22444 return 0;
22445 }
22446 cursor += PAGE_SIZE;
22447@@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, un
22448 printk(KERN_INFO
22449 "%s:%d ioremap_change_attr failed %s "
22450 "for %Lx-%Lx\n",
22451- current->comm, current->pid,
22452+ current->comm, task_pid_nr(current),
22453 cattr_name(flags),
22454 base, (unsigned long long)(base + size));
22455 return -EINVAL;
22456@@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr,
22457 free_memtype(paddr, paddr + size);
22458 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22459 " for %Lx-%Lx, got %s\n",
22460- current->comm, current->pid,
22461+ current->comm, task_pid_nr(current),
22462 cattr_name(want_flags),
22463 (unsigned long long)paddr,
22464 (unsigned long long)(paddr + size),
22465diff -urNp linux-2.6.32.43/arch/x86/mm/pf_in.c linux-2.6.32.43/arch/x86/mm/pf_in.c
22466--- linux-2.6.32.43/arch/x86/mm/pf_in.c 2011-03-27 14:31:47.000000000 -0400
22467+++ linux-2.6.32.43/arch/x86/mm/pf_in.c 2011-07-06 19:53:33.000000000 -0400
22468@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned l
22469 int i;
22470 enum reason_type rv = OTHERS;
22471
22472- p = (unsigned char *)ins_addr;
22473+ p = (unsigned char *)ktla_ktva(ins_addr);
22474 p += skip_prefix(p, &prf);
22475 p += get_opcode(p, &opcode);
22476
22477@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(un
22478 struct prefix_bits prf;
22479 int i;
22480
22481- p = (unsigned char *)ins_addr;
22482+ p = (unsigned char *)ktla_ktva(ins_addr);
22483 p += skip_prefix(p, &prf);
22484 p += get_opcode(p, &opcode);
22485
22486@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned
22487 struct prefix_bits prf;
22488 int i;
22489
22490- p = (unsigned char *)ins_addr;
22491+ p = (unsigned char *)ktla_ktva(ins_addr);
22492 p += skip_prefix(p, &prf);
22493 p += get_opcode(p, &opcode);
22494
22495@@ -417,7 +417,7 @@ unsigned long get_ins_reg_val(unsigned l
22496 int i;
22497 unsigned long rv;
22498
22499- p = (unsigned char *)ins_addr;
22500+ p = (unsigned char *)ktla_ktva(ins_addr);
22501 p += skip_prefix(p, &prf);
22502 p += get_opcode(p, &opcode);
22503 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
22504@@ -472,7 +472,7 @@ unsigned long get_ins_imm_val(unsigned l
22505 int i;
22506 unsigned long rv;
22507
22508- p = (unsigned char *)ins_addr;
22509+ p = (unsigned char *)ktla_ktva(ins_addr);
22510 p += skip_prefix(p, &prf);
22511 p += get_opcode(p, &opcode);
22512 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
22513diff -urNp linux-2.6.32.43/arch/x86/mm/pgtable_32.c linux-2.6.32.43/arch/x86/mm/pgtable_32.c
22514--- linux-2.6.32.43/arch/x86/mm/pgtable_32.c 2011-03-27 14:31:47.000000000 -0400
22515+++ linux-2.6.32.43/arch/x86/mm/pgtable_32.c 2011-04-17 15:56:46.000000000 -0400
22516@@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr,
22517 return;
22518 }
22519 pte = pte_offset_kernel(pmd, vaddr);
22520+
22521+ pax_open_kernel();
22522 if (pte_val(pteval))
22523 set_pte_at(&init_mm, vaddr, pte, pteval);
22524 else
22525 pte_clear(&init_mm, vaddr, pte);
22526+ pax_close_kernel();
22527
22528 /*
22529 * It's enough to flush this one mapping.
22530diff -urNp linux-2.6.32.43/arch/x86/mm/pgtable.c linux-2.6.32.43/arch/x86/mm/pgtable.c
22531--- linux-2.6.32.43/arch/x86/mm/pgtable.c 2011-03-27 14:31:47.000000000 -0400
22532+++ linux-2.6.32.43/arch/x86/mm/pgtable.c 2011-05-11 18:25:15.000000000 -0400
22533@@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *p
22534 list_del(&page->lru);
22535 }
22536
22537-#define UNSHARED_PTRS_PER_PGD \
22538- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22539+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22540+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22541
22542+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22543+{
22544+ while (count--)
22545+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22546+}
22547+#endif
22548+
22549+#ifdef CONFIG_PAX_PER_CPU_PGD
22550+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22551+{
22552+ while (count--)
22553+
22554+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22555+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22556+#else
22557+ *dst++ = *src++;
22558+#endif
22559+
22560+}
22561+#endif
22562+
22563+#ifdef CONFIG_X86_64
22564+#define pxd_t pud_t
22565+#define pyd_t pgd_t
22566+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22567+#define pxd_free(mm, pud) pud_free((mm), (pud))
22568+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22569+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22570+#define PYD_SIZE PGDIR_SIZE
22571+#else
22572+#define pxd_t pmd_t
22573+#define pyd_t pud_t
22574+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22575+#define pxd_free(mm, pud) pmd_free((mm), (pud))
22576+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22577+#define pyd_offset(mm ,address) pud_offset((mm), (address))
22578+#define PYD_SIZE PUD_SIZE
22579+#endif
22580+
22581+#ifdef CONFIG_PAX_PER_CPU_PGD
22582+static inline void pgd_ctor(pgd_t *pgd) {}
22583+static inline void pgd_dtor(pgd_t *pgd) {}
22584+#else
22585 static void pgd_ctor(pgd_t *pgd)
22586 {
22587 /* If the pgd points to a shared pagetable level (either the
22588@@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
22589 pgd_list_del(pgd);
22590 spin_unlock_irqrestore(&pgd_lock, flags);
22591 }
22592+#endif
22593
22594 /*
22595 * List of all pgd's needed for non-PAE so it can invalidate entries
22596@@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
22597 * -- wli
22598 */
22599
22600-#ifdef CONFIG_X86_PAE
22601+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22602 /*
22603 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22604 * updating the top-level pagetable entries to guarantee the
22605@@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
22606 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22607 * and initialize the kernel pmds here.
22608 */
22609-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22610+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22611
22612 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22613 {
22614@@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm,
22615 */
22616 flush_tlb_mm(mm);
22617 }
22618+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22619+#define PREALLOCATED_PXDS USER_PGD_PTRS
22620 #else /* !CONFIG_X86_PAE */
22621
22622 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22623-#define PREALLOCATED_PMDS 0
22624+#define PREALLOCATED_PXDS 0
22625
22626 #endif /* CONFIG_X86_PAE */
22627
22628-static void free_pmds(pmd_t *pmds[])
22629+static void free_pxds(pxd_t *pxds[])
22630 {
22631 int i;
22632
22633- for(i = 0; i < PREALLOCATED_PMDS; i++)
22634- if (pmds[i])
22635- free_page((unsigned long)pmds[i]);
22636+ for(i = 0; i < PREALLOCATED_PXDS; i++)
22637+ if (pxds[i])
22638+ free_page((unsigned long)pxds[i]);
22639 }
22640
22641-static int preallocate_pmds(pmd_t *pmds[])
22642+static int preallocate_pxds(pxd_t *pxds[])
22643 {
22644 int i;
22645 bool failed = false;
22646
22647- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22648- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22649- if (pmd == NULL)
22650+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22651+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22652+ if (pxd == NULL)
22653 failed = true;
22654- pmds[i] = pmd;
22655+ pxds[i] = pxd;
22656 }
22657
22658 if (failed) {
22659- free_pmds(pmds);
22660+ free_pxds(pxds);
22661 return -ENOMEM;
22662 }
22663
22664@@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[
22665 * preallocate which never got a corresponding vma will need to be
22666 * freed manually.
22667 */
22668-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22669+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22670 {
22671 int i;
22672
22673- for(i = 0; i < PREALLOCATED_PMDS; i++) {
22674+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
22675 pgd_t pgd = pgdp[i];
22676
22677 if (pgd_val(pgd) != 0) {
22678- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22679+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22680
22681- pgdp[i] = native_make_pgd(0);
22682+ set_pgd(pgdp + i, native_make_pgd(0));
22683
22684- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22685- pmd_free(mm, pmd);
22686+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22687+ pxd_free(mm, pxd);
22688 }
22689 }
22690 }
22691
22692-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
22693+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
22694 {
22695- pud_t *pud;
22696+ pyd_t *pyd;
22697 unsigned long addr;
22698 int i;
22699
22700- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
22701+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
22702 return;
22703
22704- pud = pud_offset(pgd, 0);
22705+#ifdef CONFIG_X86_64
22706+ pyd = pyd_offset(mm, 0L);
22707+#else
22708+ pyd = pyd_offset(pgd, 0L);
22709+#endif
22710
22711- for (addr = i = 0; i < PREALLOCATED_PMDS;
22712- i++, pud++, addr += PUD_SIZE) {
22713- pmd_t *pmd = pmds[i];
22714+ for (addr = i = 0; i < PREALLOCATED_PXDS;
22715+ i++, pyd++, addr += PYD_SIZE) {
22716+ pxd_t *pxd = pxds[i];
22717
22718 if (i >= KERNEL_PGD_BOUNDARY)
22719- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22720- sizeof(pmd_t) * PTRS_PER_PMD);
22721+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
22722+ sizeof(pxd_t) * PTRS_PER_PMD);
22723
22724- pud_populate(mm, pud, pmd);
22725+ pyd_populate(mm, pyd, pxd);
22726 }
22727 }
22728
22729 pgd_t *pgd_alloc(struct mm_struct *mm)
22730 {
22731 pgd_t *pgd;
22732- pmd_t *pmds[PREALLOCATED_PMDS];
22733+ pxd_t *pxds[PREALLOCATED_PXDS];
22734+
22735 unsigned long flags;
22736
22737 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
22738@@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22739
22740 mm->pgd = pgd;
22741
22742- if (preallocate_pmds(pmds) != 0)
22743+ if (preallocate_pxds(pxds) != 0)
22744 goto out_free_pgd;
22745
22746 if (paravirt_pgd_alloc(mm) != 0)
22747- goto out_free_pmds;
22748+ goto out_free_pxds;
22749
22750 /*
22751 * Make sure that pre-populating the pmds is atomic with
22752@@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
22753 spin_lock_irqsave(&pgd_lock, flags);
22754
22755 pgd_ctor(pgd);
22756- pgd_prepopulate_pmd(mm, pgd, pmds);
22757+ pgd_prepopulate_pxd(mm, pgd, pxds);
22758
22759 spin_unlock_irqrestore(&pgd_lock, flags);
22760
22761 return pgd;
22762
22763-out_free_pmds:
22764- free_pmds(pmds);
22765+out_free_pxds:
22766+ free_pxds(pxds);
22767 out_free_pgd:
22768 free_page((unsigned long)pgd);
22769 out:
22770@@ -287,7 +338,7 @@ out:
22771
22772 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
22773 {
22774- pgd_mop_up_pmds(mm, pgd);
22775+ pgd_mop_up_pxds(mm, pgd);
22776 pgd_dtor(pgd);
22777 paravirt_pgd_free(mm, pgd);
22778 free_page((unsigned long)pgd);
22779diff -urNp linux-2.6.32.43/arch/x86/mm/setup_nx.c linux-2.6.32.43/arch/x86/mm/setup_nx.c
22780--- linux-2.6.32.43/arch/x86/mm/setup_nx.c 2011-03-27 14:31:47.000000000 -0400
22781+++ linux-2.6.32.43/arch/x86/mm/setup_nx.c 2011-04-17 15:56:46.000000000 -0400
22782@@ -4,11 +4,10 @@
22783
22784 #include <asm/pgtable.h>
22785
22786+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22787 int nx_enabled;
22788
22789-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22790-static int disable_nx __cpuinitdata;
22791-
22792+#ifndef CONFIG_PAX_PAGEEXEC
22793 /*
22794 * noexec = on|off
22795 *
22796@@ -22,32 +21,26 @@ static int __init noexec_setup(char *str
22797 if (!str)
22798 return -EINVAL;
22799 if (!strncmp(str, "on", 2)) {
22800- __supported_pte_mask |= _PAGE_NX;
22801- disable_nx = 0;
22802+ nx_enabled = 1;
22803 } else if (!strncmp(str, "off", 3)) {
22804- disable_nx = 1;
22805- __supported_pte_mask &= ~_PAGE_NX;
22806+ nx_enabled = 0;
22807 }
22808 return 0;
22809 }
22810 early_param("noexec", noexec_setup);
22811 #endif
22812+#endif
22813
22814 #ifdef CONFIG_X86_PAE
22815 void __init set_nx(void)
22816 {
22817- unsigned int v[4], l, h;
22818+ if (!nx_enabled && cpu_has_nx) {
22819+ unsigned l, h;
22820
22821- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
22822- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
22823-
22824- if ((v[3] & (1 << 20)) && !disable_nx) {
22825- rdmsr(MSR_EFER, l, h);
22826- l |= EFER_NX;
22827- wrmsr(MSR_EFER, l, h);
22828- nx_enabled = 1;
22829- __supported_pte_mask |= _PAGE_NX;
22830- }
22831+ __supported_pte_mask &= ~_PAGE_NX;
22832+ rdmsr(MSR_EFER, l, h);
22833+ l &= ~EFER_NX;
22834+ wrmsr(MSR_EFER, l, h);
22835 }
22836 }
22837 #else
22838@@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
22839 unsigned long efer;
22840
22841 rdmsrl(MSR_EFER, efer);
22842- if (!(efer & EFER_NX) || disable_nx)
22843+ if (!(efer & EFER_NX) || !nx_enabled)
22844 __supported_pte_mask &= ~_PAGE_NX;
22845 }
22846 #endif
22847diff -urNp linux-2.6.32.43/arch/x86/mm/tlb.c linux-2.6.32.43/arch/x86/mm/tlb.c
22848--- linux-2.6.32.43/arch/x86/mm/tlb.c 2011-03-27 14:31:47.000000000 -0400
22849+++ linux-2.6.32.43/arch/x86/mm/tlb.c 2011-04-23 12:56:10.000000000 -0400
22850@@ -61,7 +61,11 @@ void leave_mm(int cpu)
22851 BUG();
22852 cpumask_clear_cpu(cpu,
22853 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
22854+
22855+#ifndef CONFIG_PAX_PER_CPU_PGD
22856 load_cr3(swapper_pg_dir);
22857+#endif
22858+
22859 }
22860 EXPORT_SYMBOL_GPL(leave_mm);
22861
22862diff -urNp linux-2.6.32.43/arch/x86/oprofile/backtrace.c linux-2.6.32.43/arch/x86/oprofile/backtrace.c
22863--- linux-2.6.32.43/arch/x86/oprofile/backtrace.c 2011-03-27 14:31:47.000000000 -0400
22864+++ linux-2.6.32.43/arch/x86/oprofile/backtrace.c 2011-04-17 15:56:46.000000000 -0400
22865@@ -57,7 +57,7 @@ static struct frame_head *dump_user_back
22866 struct frame_head bufhead[2];
22867
22868 /* Also check accessibility of one struct frame_head beyond */
22869- if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
22870+ if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
22871 return NULL;
22872 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
22873 return NULL;
22874@@ -77,7 +77,7 @@ x86_backtrace(struct pt_regs * const reg
22875 {
22876 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
22877
22878- if (!user_mode_vm(regs)) {
22879+ if (!user_mode(regs)) {
22880 unsigned long stack = kernel_stack_pointer(regs);
22881 if (depth)
22882 dump_trace(NULL, regs, (unsigned long *)stack, 0,
22883diff -urNp linux-2.6.32.43/arch/x86/oprofile/op_model_p4.c linux-2.6.32.43/arch/x86/oprofile/op_model_p4.c
22884--- linux-2.6.32.43/arch/x86/oprofile/op_model_p4.c 2011-03-27 14:31:47.000000000 -0400
22885+++ linux-2.6.32.43/arch/x86/oprofile/op_model_p4.c 2011-04-17 15:56:46.000000000 -0400
22886@@ -50,7 +50,7 @@ static inline void setup_num_counters(vo
22887 #endif
22888 }
22889
22890-static int inline addr_increment(void)
22891+static inline int addr_increment(void)
22892 {
22893 #ifdef CONFIG_SMP
22894 return smp_num_siblings == 2 ? 2 : 1;
22895diff -urNp linux-2.6.32.43/arch/x86/pci/common.c linux-2.6.32.43/arch/x86/pci/common.c
22896--- linux-2.6.32.43/arch/x86/pci/common.c 2011-03-27 14:31:47.000000000 -0400
22897+++ linux-2.6.32.43/arch/x86/pci/common.c 2011-04-23 12:56:10.000000000 -0400
22898@@ -31,8 +31,8 @@ int noioapicreroute = 1;
22899 int pcibios_last_bus = -1;
22900 unsigned long pirq_table_addr;
22901 struct pci_bus *pci_root_bus;
22902-struct pci_raw_ops *raw_pci_ops;
22903-struct pci_raw_ops *raw_pci_ext_ops;
22904+const struct pci_raw_ops *raw_pci_ops;
22905+const struct pci_raw_ops *raw_pci_ext_ops;
22906
22907 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
22908 int reg, int len, u32 *val)
22909diff -urNp linux-2.6.32.43/arch/x86/pci/direct.c linux-2.6.32.43/arch/x86/pci/direct.c
22910--- linux-2.6.32.43/arch/x86/pci/direct.c 2011-03-27 14:31:47.000000000 -0400
22911+++ linux-2.6.32.43/arch/x86/pci/direct.c 2011-04-17 15:56:46.000000000 -0400
22912@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
22913
22914 #undef PCI_CONF1_ADDRESS
22915
22916-struct pci_raw_ops pci_direct_conf1 = {
22917+const struct pci_raw_ops pci_direct_conf1 = {
22918 .read = pci_conf1_read,
22919 .write = pci_conf1_write,
22920 };
22921@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
22922
22923 #undef PCI_CONF2_ADDRESS
22924
22925-struct pci_raw_ops pci_direct_conf2 = {
22926+const struct pci_raw_ops pci_direct_conf2 = {
22927 .read = pci_conf2_read,
22928 .write = pci_conf2_write,
22929 };
22930@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
22931 * This should be close to trivial, but it isn't, because there are buggy
22932 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
22933 */
22934-static int __init pci_sanity_check(struct pci_raw_ops *o)
22935+static int __init pci_sanity_check(const struct pci_raw_ops *o)
22936 {
22937 u32 x = 0;
22938 int year, devfn;
22939diff -urNp linux-2.6.32.43/arch/x86/pci/mmconfig_32.c linux-2.6.32.43/arch/x86/pci/mmconfig_32.c
22940--- linux-2.6.32.43/arch/x86/pci/mmconfig_32.c 2011-03-27 14:31:47.000000000 -0400
22941+++ linux-2.6.32.43/arch/x86/pci/mmconfig_32.c 2011-04-17 15:56:46.000000000 -0400
22942@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int
22943 return 0;
22944 }
22945
22946-static struct pci_raw_ops pci_mmcfg = {
22947+static const struct pci_raw_ops pci_mmcfg = {
22948 .read = pci_mmcfg_read,
22949 .write = pci_mmcfg_write,
22950 };
22951diff -urNp linux-2.6.32.43/arch/x86/pci/mmconfig_64.c linux-2.6.32.43/arch/x86/pci/mmconfig_64.c
22952--- linux-2.6.32.43/arch/x86/pci/mmconfig_64.c 2011-03-27 14:31:47.000000000 -0400
22953+++ linux-2.6.32.43/arch/x86/pci/mmconfig_64.c 2011-04-17 15:56:46.000000000 -0400
22954@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int
22955 return 0;
22956 }
22957
22958-static struct pci_raw_ops pci_mmcfg = {
22959+static const struct pci_raw_ops pci_mmcfg = {
22960 .read = pci_mmcfg_read,
22961 .write = pci_mmcfg_write,
22962 };
22963diff -urNp linux-2.6.32.43/arch/x86/pci/numaq_32.c linux-2.6.32.43/arch/x86/pci/numaq_32.c
22964--- linux-2.6.32.43/arch/x86/pci/numaq_32.c 2011-03-27 14:31:47.000000000 -0400
22965+++ linux-2.6.32.43/arch/x86/pci/numaq_32.c 2011-04-17 15:56:46.000000000 -0400
22966@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned i
22967
22968 #undef PCI_CONF1_MQ_ADDRESS
22969
22970-static struct pci_raw_ops pci_direct_conf1_mq = {
22971+static const struct pci_raw_ops pci_direct_conf1_mq = {
22972 .read = pci_conf1_mq_read,
22973 .write = pci_conf1_mq_write
22974 };
22975diff -urNp linux-2.6.32.43/arch/x86/pci/olpc.c linux-2.6.32.43/arch/x86/pci/olpc.c
22976--- linux-2.6.32.43/arch/x86/pci/olpc.c 2011-03-27 14:31:47.000000000 -0400
22977+++ linux-2.6.32.43/arch/x86/pci/olpc.c 2011-04-17 15:56:46.000000000 -0400
22978@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
22979 return 0;
22980 }
22981
22982-static struct pci_raw_ops pci_olpc_conf = {
22983+static const struct pci_raw_ops pci_olpc_conf = {
22984 .read = pci_olpc_read,
22985 .write = pci_olpc_write,
22986 };
22987diff -urNp linux-2.6.32.43/arch/x86/pci/pcbios.c linux-2.6.32.43/arch/x86/pci/pcbios.c
22988--- linux-2.6.32.43/arch/x86/pci/pcbios.c 2011-03-27 14:31:47.000000000 -0400
22989+++ linux-2.6.32.43/arch/x86/pci/pcbios.c 2011-04-17 15:56:46.000000000 -0400
22990@@ -56,50 +56,93 @@ union bios32 {
22991 static struct {
22992 unsigned long address;
22993 unsigned short segment;
22994-} bios32_indirect = { 0, __KERNEL_CS };
22995+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
22996
22997 /*
22998 * Returns the entry point for the given service, NULL on error
22999 */
23000
23001-static unsigned long bios32_service(unsigned long service)
23002+static unsigned long __devinit bios32_service(unsigned long service)
23003 {
23004 unsigned char return_code; /* %al */
23005 unsigned long address; /* %ebx */
23006 unsigned long length; /* %ecx */
23007 unsigned long entry; /* %edx */
23008 unsigned long flags;
23009+ struct desc_struct d, *gdt;
23010
23011 local_irq_save(flags);
23012- __asm__("lcall *(%%edi); cld"
23013+
23014+ gdt = get_cpu_gdt_table(smp_processor_id());
23015+
23016+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23017+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23018+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23019+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23020+
23021+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23022 : "=a" (return_code),
23023 "=b" (address),
23024 "=c" (length),
23025 "=d" (entry)
23026 : "0" (service),
23027 "1" (0),
23028- "D" (&bios32_indirect));
23029+ "D" (&bios32_indirect),
23030+ "r"(__PCIBIOS_DS)
23031+ : "memory");
23032+
23033+ pax_open_kernel();
23034+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23035+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23036+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23037+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23038+ pax_close_kernel();
23039+
23040 local_irq_restore(flags);
23041
23042 switch (return_code) {
23043- case 0:
23044- return address + entry;
23045- case 0x80: /* Not present */
23046- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23047- return 0;
23048- default: /* Shouldn't happen */
23049- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23050- service, return_code);
23051+ case 0: {
23052+ int cpu;
23053+ unsigned char flags;
23054+
23055+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23056+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23057+ printk(KERN_WARNING "bios32_service: not valid\n");
23058 return 0;
23059+ }
23060+ address = address + PAGE_OFFSET;
23061+ length += 16UL; /* some BIOSs underreport this... */
23062+ flags = 4;
23063+ if (length >= 64*1024*1024) {
23064+ length >>= PAGE_SHIFT;
23065+ flags |= 8;
23066+ }
23067+
23068+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
23069+ gdt = get_cpu_gdt_table(cpu);
23070+ pack_descriptor(&d, address, length, 0x9b, flags);
23071+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23072+ pack_descriptor(&d, address, length, 0x93, flags);
23073+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23074+ }
23075+ return entry;
23076+ }
23077+ case 0x80: /* Not present */
23078+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23079+ return 0;
23080+ default: /* Shouldn't happen */
23081+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23082+ service, return_code);
23083+ return 0;
23084 }
23085 }
23086
23087 static struct {
23088 unsigned long address;
23089 unsigned short segment;
23090-} pci_indirect = { 0, __KERNEL_CS };
23091+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23092
23093-static int pci_bios_present;
23094+static int pci_bios_present __read_only;
23095
23096 static int __devinit check_pcibios(void)
23097 {
23098@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
23099 unsigned long flags, pcibios_entry;
23100
23101 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23102- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23103+ pci_indirect.address = pcibios_entry;
23104
23105 local_irq_save(flags);
23106- __asm__(
23107- "lcall *(%%edi); cld\n\t"
23108+ __asm__("movw %w6, %%ds\n\t"
23109+ "lcall *%%ss:(%%edi); cld\n\t"
23110+ "push %%ss\n\t"
23111+ "pop %%ds\n\t"
23112 "jc 1f\n\t"
23113 "xor %%ah, %%ah\n"
23114 "1:"
23115@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
23116 "=b" (ebx),
23117 "=c" (ecx)
23118 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23119- "D" (&pci_indirect)
23120+ "D" (&pci_indirect),
23121+ "r" (__PCIBIOS_DS)
23122 : "memory");
23123 local_irq_restore(flags);
23124
23125@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int se
23126
23127 switch (len) {
23128 case 1:
23129- __asm__("lcall *(%%esi); cld\n\t"
23130+ __asm__("movw %w6, %%ds\n\t"
23131+ "lcall *%%ss:(%%esi); cld\n\t"
23132+ "push %%ss\n\t"
23133+ "pop %%ds\n\t"
23134 "jc 1f\n\t"
23135 "xor %%ah, %%ah\n"
23136 "1:"
23137@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int se
23138 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23139 "b" (bx),
23140 "D" ((long)reg),
23141- "S" (&pci_indirect));
23142+ "S" (&pci_indirect),
23143+ "r" (__PCIBIOS_DS));
23144 /*
23145 * Zero-extend the result beyond 8 bits, do not trust the
23146 * BIOS having done it:
23147@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int se
23148 *value &= 0xff;
23149 break;
23150 case 2:
23151- __asm__("lcall *(%%esi); cld\n\t"
23152+ __asm__("movw %w6, %%ds\n\t"
23153+ "lcall *%%ss:(%%esi); cld\n\t"
23154+ "push %%ss\n\t"
23155+ "pop %%ds\n\t"
23156 "jc 1f\n\t"
23157 "xor %%ah, %%ah\n"
23158 "1:"
23159@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int se
23160 : "1" (PCIBIOS_READ_CONFIG_WORD),
23161 "b" (bx),
23162 "D" ((long)reg),
23163- "S" (&pci_indirect));
23164+ "S" (&pci_indirect),
23165+ "r" (__PCIBIOS_DS));
23166 /*
23167 * Zero-extend the result beyond 16 bits, do not trust the
23168 * BIOS having done it:
23169@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int se
23170 *value &= 0xffff;
23171 break;
23172 case 4:
23173- __asm__("lcall *(%%esi); cld\n\t"
23174+ __asm__("movw %w6, %%ds\n\t"
23175+ "lcall *%%ss:(%%esi); cld\n\t"
23176+ "push %%ss\n\t"
23177+ "pop %%ds\n\t"
23178 "jc 1f\n\t"
23179 "xor %%ah, %%ah\n"
23180 "1:"
23181@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int se
23182 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23183 "b" (bx),
23184 "D" ((long)reg),
23185- "S" (&pci_indirect));
23186+ "S" (&pci_indirect),
23187+ "r" (__PCIBIOS_DS));
23188 break;
23189 }
23190
23191@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int s
23192
23193 switch (len) {
23194 case 1:
23195- __asm__("lcall *(%%esi); cld\n\t"
23196+ __asm__("movw %w6, %%ds\n\t"
23197+ "lcall *%%ss:(%%esi); cld\n\t"
23198+ "push %%ss\n\t"
23199+ "pop %%ds\n\t"
23200 "jc 1f\n\t"
23201 "xor %%ah, %%ah\n"
23202 "1:"
23203@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int s
23204 "c" (value),
23205 "b" (bx),
23206 "D" ((long)reg),
23207- "S" (&pci_indirect));
23208+ "S" (&pci_indirect),
23209+ "r" (__PCIBIOS_DS));
23210 break;
23211 case 2:
23212- __asm__("lcall *(%%esi); cld\n\t"
23213+ __asm__("movw %w6, %%ds\n\t"
23214+ "lcall *%%ss:(%%esi); cld\n\t"
23215+ "push %%ss\n\t"
23216+ "pop %%ds\n\t"
23217 "jc 1f\n\t"
23218 "xor %%ah, %%ah\n"
23219 "1:"
23220@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int s
23221 "c" (value),
23222 "b" (bx),
23223 "D" ((long)reg),
23224- "S" (&pci_indirect));
23225+ "S" (&pci_indirect),
23226+ "r" (__PCIBIOS_DS));
23227 break;
23228 case 4:
23229- __asm__("lcall *(%%esi); cld\n\t"
23230+ __asm__("movw %w6, %%ds\n\t"
23231+ "lcall *%%ss:(%%esi); cld\n\t"
23232+ "push %%ss\n\t"
23233+ "pop %%ds\n\t"
23234 "jc 1f\n\t"
23235 "xor %%ah, %%ah\n"
23236 "1:"
23237@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int s
23238 "c" (value),
23239 "b" (bx),
23240 "D" ((long)reg),
23241- "S" (&pci_indirect));
23242+ "S" (&pci_indirect),
23243+ "r" (__PCIBIOS_DS));
23244 break;
23245 }
23246
23247@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int s
23248 * Function table for BIOS32 access
23249 */
23250
23251-static struct pci_raw_ops pci_bios_access = {
23252+static const struct pci_raw_ops pci_bios_access = {
23253 .read = pci_bios_read,
23254 .write = pci_bios_write
23255 };
23256@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_acces
23257 * Try to find PCI BIOS.
23258 */
23259
23260-static struct pci_raw_ops * __devinit pci_find_bios(void)
23261+static const struct pci_raw_ops * __devinit pci_find_bios(void)
23262 {
23263 union bios32 *check;
23264 unsigned char sum;
23265@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_i
23266
23267 DBG("PCI: Fetching IRQ routing table... ");
23268 __asm__("push %%es\n\t"
23269+ "movw %w8, %%ds\n\t"
23270 "push %%ds\n\t"
23271 "pop %%es\n\t"
23272- "lcall *(%%esi); cld\n\t"
23273+ "lcall *%%ss:(%%esi); cld\n\t"
23274 "pop %%es\n\t"
23275+ "push %%ss\n\t"
23276+ "pop %%ds\n"
23277 "jc 1f\n\t"
23278 "xor %%ah, %%ah\n"
23279 "1:"
23280@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_i
23281 "1" (0),
23282 "D" ((long) &opt),
23283 "S" (&pci_indirect),
23284- "m" (opt)
23285+ "m" (opt),
23286+ "r" (__PCIBIOS_DS)
23287 : "memory");
23288 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23289 if (ret & 0xff00)
23290@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_d
23291 {
23292 int ret;
23293
23294- __asm__("lcall *(%%esi); cld\n\t"
23295+ __asm__("movw %w5, %%ds\n\t"
23296+ "lcall *%%ss:(%%esi); cld\n\t"
23297+ "push %%ss\n\t"
23298+ "pop %%ds\n"
23299 "jc 1f\n\t"
23300 "xor %%ah, %%ah\n"
23301 "1:"
23302@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_d
23303 : "0" (PCIBIOS_SET_PCI_HW_INT),
23304 "b" ((dev->bus->number << 8) | dev->devfn),
23305 "c" ((irq << 8) | (pin + 10)),
23306- "S" (&pci_indirect));
23307+ "S" (&pci_indirect),
23308+ "r" (__PCIBIOS_DS));
23309 return !(ret & 0xff00);
23310 }
23311 EXPORT_SYMBOL(pcibios_set_irq_routing);
23312diff -urNp linux-2.6.32.43/arch/x86/power/cpu.c linux-2.6.32.43/arch/x86/power/cpu.c
23313--- linux-2.6.32.43/arch/x86/power/cpu.c 2011-03-27 14:31:47.000000000 -0400
23314+++ linux-2.6.32.43/arch/x86/power/cpu.c 2011-04-17 15:56:46.000000000 -0400
23315@@ -129,7 +129,7 @@ static void do_fpu_end(void)
23316 static void fix_processor_context(void)
23317 {
23318 int cpu = smp_processor_id();
23319- struct tss_struct *t = &per_cpu(init_tss, cpu);
23320+ struct tss_struct *t = init_tss + cpu;
23321
23322 set_tss_desc(cpu, t); /*
23323 * This just modifies memory; should not be
23324@@ -139,7 +139,9 @@ static void fix_processor_context(void)
23325 */
23326
23327 #ifdef CONFIG_X86_64
23328+ pax_open_kernel();
23329 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23330+ pax_close_kernel();
23331
23332 syscall_init(); /* This sets MSR_*STAR and related */
23333 #endif
23334diff -urNp linux-2.6.32.43/arch/x86/vdso/Makefile linux-2.6.32.43/arch/x86/vdso/Makefile
23335--- linux-2.6.32.43/arch/x86/vdso/Makefile 2011-03-27 14:31:47.000000000 -0400
23336+++ linux-2.6.32.43/arch/x86/vdso/Makefile 2011-04-17 15:56:46.000000000 -0400
23337@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
23338 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
23339 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
23340
23341-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23342+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23343 GCOV_PROFILE := n
23344
23345 #
23346diff -urNp linux-2.6.32.43/arch/x86/vdso/vclock_gettime.c linux-2.6.32.43/arch/x86/vdso/vclock_gettime.c
23347--- linux-2.6.32.43/arch/x86/vdso/vclock_gettime.c 2011-03-27 14:31:47.000000000 -0400
23348+++ linux-2.6.32.43/arch/x86/vdso/vclock_gettime.c 2011-04-17 15:56:46.000000000 -0400
23349@@ -22,24 +22,48 @@
23350 #include <asm/hpet.h>
23351 #include <asm/unistd.h>
23352 #include <asm/io.h>
23353+#include <asm/fixmap.h>
23354 #include "vextern.h"
23355
23356 #define gtod vdso_vsyscall_gtod_data
23357
23358+notrace noinline long __vdso_fallback_time(long *t)
23359+{
23360+ long secs;
23361+ asm volatile("syscall"
23362+ : "=a" (secs)
23363+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23364+ return secs;
23365+}
23366+
23367 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23368 {
23369 long ret;
23370 asm("syscall" : "=a" (ret) :
23371- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23372+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23373 return ret;
23374 }
23375
23376+notrace static inline cycle_t __vdso_vread_hpet(void)
23377+{
23378+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23379+}
23380+
23381+notrace static inline cycle_t __vdso_vread_tsc(void)
23382+{
23383+ cycle_t ret = (cycle_t)vget_cycles();
23384+
23385+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23386+}
23387+
23388 notrace static inline long vgetns(void)
23389 {
23390 long v;
23391- cycles_t (*vread)(void);
23392- vread = gtod->clock.vread;
23393- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23394+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23395+ v = __vdso_vread_tsc();
23396+ else
23397+ v = __vdso_vread_hpet();
23398+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23399 return (v * gtod->clock.mult) >> gtod->clock.shift;
23400 }
23401
23402@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23403
23404 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23405 {
23406- if (likely(gtod->sysctl_enabled))
23407+ if (likely(gtod->sysctl_enabled &&
23408+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23409+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23410 switch (clock) {
23411 case CLOCK_REALTIME:
23412 if (likely(gtod->clock.vread))
23413@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23414 int clock_gettime(clockid_t, struct timespec *)
23415 __attribute__((weak, alias("__vdso_clock_gettime")));
23416
23417-notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23418+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23419 {
23420 long ret;
23421- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23422+ asm("syscall" : "=a" (ret) :
23423+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23424+ return ret;
23425+}
23426+
23427+notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23428+{
23429+ if (likely(gtod->sysctl_enabled &&
23430+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23431+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23432+ {
23433 if (likely(tv != NULL)) {
23434 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23435 offsetof(struct timespec, tv_nsec) ||
23436@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23437 }
23438 return 0;
23439 }
23440- asm("syscall" : "=a" (ret) :
23441- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23442- return ret;
23443+ return __vdso_fallback_gettimeofday(tv, tz);
23444 }
23445 int gettimeofday(struct timeval *, struct timezone *)
23446 __attribute__((weak, alias("__vdso_gettimeofday")));
23447diff -urNp linux-2.6.32.43/arch/x86/vdso/vdso32-setup.c linux-2.6.32.43/arch/x86/vdso/vdso32-setup.c
23448--- linux-2.6.32.43/arch/x86/vdso/vdso32-setup.c 2011-03-27 14:31:47.000000000 -0400
23449+++ linux-2.6.32.43/arch/x86/vdso/vdso32-setup.c 2011-04-23 12:56:10.000000000 -0400
23450@@ -25,6 +25,7 @@
23451 #include <asm/tlbflush.h>
23452 #include <asm/vdso.h>
23453 #include <asm/proto.h>
23454+#include <asm/mman.h>
23455
23456 enum {
23457 VDSO_DISABLED = 0,
23458@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23459 void enable_sep_cpu(void)
23460 {
23461 int cpu = get_cpu();
23462- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23463+ struct tss_struct *tss = init_tss + cpu;
23464
23465 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23466 put_cpu();
23467@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23468 gate_vma.vm_start = FIXADDR_USER_START;
23469 gate_vma.vm_end = FIXADDR_USER_END;
23470 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23471- gate_vma.vm_page_prot = __P101;
23472+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23473 /*
23474 * Make sure the vDSO gets into every core dump.
23475 * Dumping its contents makes post-mortem fully interpretable later
23476@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23477 if (compat)
23478 addr = VDSO_HIGH_BASE;
23479 else {
23480- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23481+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23482 if (IS_ERR_VALUE(addr)) {
23483 ret = addr;
23484 goto up_fail;
23485 }
23486 }
23487
23488- current->mm->context.vdso = (void *)addr;
23489+ current->mm->context.vdso = addr;
23490
23491 if (compat_uses_vma || !compat) {
23492 /*
23493@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
23494 }
23495
23496 current_thread_info()->sysenter_return =
23497- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23498+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
23499
23500 up_fail:
23501 if (ret)
23502- current->mm->context.vdso = NULL;
23503+ current->mm->context.vdso = 0;
23504
23505 up_write(&mm->mmap_sem);
23506
23507@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
23508
23509 const char *arch_vma_name(struct vm_area_struct *vma)
23510 {
23511- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23512+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23513 return "[vdso]";
23514+
23515+#ifdef CONFIG_PAX_SEGMEXEC
23516+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
23517+ return "[vdso]";
23518+#endif
23519+
23520 return NULL;
23521 }
23522
23523@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
23524 struct mm_struct *mm = tsk->mm;
23525
23526 /* Check to see if this task was created in compat vdso mode */
23527- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
23528+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
23529 return &gate_vma;
23530 return NULL;
23531 }
23532diff -urNp linux-2.6.32.43/arch/x86/vdso/vdso.lds.S linux-2.6.32.43/arch/x86/vdso/vdso.lds.S
23533--- linux-2.6.32.43/arch/x86/vdso/vdso.lds.S 2011-03-27 14:31:47.000000000 -0400
23534+++ linux-2.6.32.43/arch/x86/vdso/vdso.lds.S 2011-06-06 17:35:35.000000000 -0400
23535@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
23536 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
23537 #include "vextern.h"
23538 #undef VEXTERN
23539+
23540+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
23541+VEXTERN(fallback_gettimeofday)
23542+VEXTERN(fallback_time)
23543+VEXTERN(getcpu)
23544+#undef VEXTERN
23545diff -urNp linux-2.6.32.43/arch/x86/vdso/vextern.h linux-2.6.32.43/arch/x86/vdso/vextern.h
23546--- linux-2.6.32.43/arch/x86/vdso/vextern.h 2011-03-27 14:31:47.000000000 -0400
23547+++ linux-2.6.32.43/arch/x86/vdso/vextern.h 2011-04-17 15:56:46.000000000 -0400
23548@@ -11,6 +11,5 @@
23549 put into vextern.h and be referenced as a pointer with vdso prefix.
23550 The main kernel later fills in the values. */
23551
23552-VEXTERN(jiffies)
23553 VEXTERN(vgetcpu_mode)
23554 VEXTERN(vsyscall_gtod_data)
23555diff -urNp linux-2.6.32.43/arch/x86/vdso/vma.c linux-2.6.32.43/arch/x86/vdso/vma.c
23556--- linux-2.6.32.43/arch/x86/vdso/vma.c 2011-03-27 14:31:47.000000000 -0400
23557+++ linux-2.6.32.43/arch/x86/vdso/vma.c 2011-04-17 15:56:46.000000000 -0400
23558@@ -57,7 +57,7 @@ static int __init init_vdso_vars(void)
23559 if (!vbase)
23560 goto oom;
23561
23562- if (memcmp(vbase, "\177ELF", 4)) {
23563+ if (memcmp(vbase, ELFMAG, SELFMAG)) {
23564 printk("VDSO: I'm broken; not ELF\n");
23565 vdso_enabled = 0;
23566 }
23567@@ -66,6 +66,7 @@ static int __init init_vdso_vars(void)
23568 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
23569 #include "vextern.h"
23570 #undef VEXTERN
23571+ vunmap(vbase);
23572 return 0;
23573
23574 oom:
23575@@ -116,7 +117,7 @@ int arch_setup_additional_pages(struct l
23576 goto up_fail;
23577 }
23578
23579- current->mm->context.vdso = (void *)addr;
23580+ current->mm->context.vdso = addr;
23581
23582 ret = install_special_mapping(mm, addr, vdso_size,
23583 VM_READ|VM_EXEC|
23584@@ -124,7 +125,7 @@ int arch_setup_additional_pages(struct l
23585 VM_ALWAYSDUMP,
23586 vdso_pages);
23587 if (ret) {
23588- current->mm->context.vdso = NULL;
23589+ current->mm->context.vdso = 0;
23590 goto up_fail;
23591 }
23592
23593@@ -132,10 +133,3 @@ up_fail:
23594 up_write(&mm->mmap_sem);
23595 return ret;
23596 }
23597-
23598-static __init int vdso_setup(char *s)
23599-{
23600- vdso_enabled = simple_strtoul(s, NULL, 0);
23601- return 0;
23602-}
23603-__setup("vdso=", vdso_setup);
23604diff -urNp linux-2.6.32.43/arch/x86/xen/enlighten.c linux-2.6.32.43/arch/x86/xen/enlighten.c
23605--- linux-2.6.32.43/arch/x86/xen/enlighten.c 2011-03-27 14:31:47.000000000 -0400
23606+++ linux-2.6.32.43/arch/x86/xen/enlighten.c 2011-05-22 23:02:03.000000000 -0400
23607@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
23608
23609 struct shared_info xen_dummy_shared_info;
23610
23611-void *xen_initial_gdt;
23612-
23613 /*
23614 * Point at some empty memory to start with. We map the real shared_info
23615 * page as soon as fixmap is up and running.
23616@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_des
23617
23618 preempt_disable();
23619
23620- start = __get_cpu_var(idt_desc).address;
23621+ start = (unsigned long)__get_cpu_var(idt_desc).address;
23622 end = start + __get_cpu_var(idt_desc).size + 1;
23623
23624 xen_mc_flush();
23625@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic
23626 #endif
23627 };
23628
23629-static void xen_reboot(int reason)
23630+static __noreturn void xen_reboot(int reason)
23631 {
23632 struct sched_shutdown r = { .reason = reason };
23633
23634@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
23635 BUG();
23636 }
23637
23638-static void xen_restart(char *msg)
23639+static __noreturn void xen_restart(char *msg)
23640 {
23641 xen_reboot(SHUTDOWN_reboot);
23642 }
23643
23644-static void xen_emergency_restart(void)
23645+static __noreturn void xen_emergency_restart(void)
23646 {
23647 xen_reboot(SHUTDOWN_reboot);
23648 }
23649
23650-static void xen_machine_halt(void)
23651+static __noreturn void xen_machine_halt(void)
23652 {
23653 xen_reboot(SHUTDOWN_poweroff);
23654 }
23655@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(
23656 */
23657 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
23658
23659-#ifdef CONFIG_X86_64
23660 /* Work out if we support NX */
23661- check_efer();
23662+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23663+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
23664+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
23665+ unsigned l, h;
23666+
23667+#ifdef CONFIG_X86_PAE
23668+ nx_enabled = 1;
23669+#endif
23670+ __supported_pte_mask |= _PAGE_NX;
23671+ rdmsr(MSR_EFER, l, h);
23672+ l |= EFER_NX;
23673+ wrmsr(MSR_EFER, l, h);
23674+ }
23675 #endif
23676
23677 xen_setup_features();
23678@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(
23679
23680 machine_ops = xen_machine_ops;
23681
23682- /*
23683- * The only reliable way to retain the initial address of the
23684- * percpu gdt_page is to remember it here, so we can go and
23685- * mark it RW later, when the initial percpu area is freed.
23686- */
23687- xen_initial_gdt = &per_cpu(gdt_page, 0);
23688-
23689 xen_smp_init();
23690
23691 pgd = (pgd_t *)xen_start_info->pt_base;
23692diff -urNp linux-2.6.32.43/arch/x86/xen/mmu.c linux-2.6.32.43/arch/x86/xen/mmu.c
23693--- linux-2.6.32.43/arch/x86/xen/mmu.c 2011-07-13 17:23:04.000000000 -0400
23694+++ linux-2.6.32.43/arch/x86/xen/mmu.c 2011-07-13 17:23:18.000000000 -0400
23695@@ -1719,6 +1719,8 @@ __init pgd_t *xen_setup_kernel_pagetable
23696 convert_pfn_mfn(init_level4_pgt);
23697 convert_pfn_mfn(level3_ident_pgt);
23698 convert_pfn_mfn(level3_kernel_pgt);
23699+ convert_pfn_mfn(level3_vmalloc_pgt);
23700+ convert_pfn_mfn(level3_vmemmap_pgt);
23701
23702 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
23703 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
23704@@ -1737,7 +1739,10 @@ __init pgd_t *xen_setup_kernel_pagetable
23705 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
23706 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
23707 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
23708+ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
23709+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
23710 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
23711+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
23712 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
23713 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
23714
23715diff -urNp linux-2.6.32.43/arch/x86/xen/smp.c linux-2.6.32.43/arch/x86/xen/smp.c
23716--- linux-2.6.32.43/arch/x86/xen/smp.c 2011-03-27 14:31:47.000000000 -0400
23717+++ linux-2.6.32.43/arch/x86/xen/smp.c 2011-05-11 18:25:15.000000000 -0400
23718@@ -167,11 +167,6 @@ static void __init xen_smp_prepare_boot_
23719 {
23720 BUG_ON(smp_processor_id() != 0);
23721 native_smp_prepare_boot_cpu();
23722-
23723- /* We've switched to the "real" per-cpu gdt, so make sure the
23724- old memory can be recycled */
23725- make_lowmem_page_readwrite(xen_initial_gdt);
23726-
23727 xen_setup_vcpu_info_placement();
23728 }
23729
23730@@ -231,12 +226,12 @@ cpu_initialize_context(unsigned int cpu,
23731 gdt = get_cpu_gdt_table(cpu);
23732
23733 ctxt->flags = VGCF_IN_KERNEL;
23734- ctxt->user_regs.ds = __USER_DS;
23735- ctxt->user_regs.es = __USER_DS;
23736+ ctxt->user_regs.ds = __KERNEL_DS;
23737+ ctxt->user_regs.es = __KERNEL_DS;
23738 ctxt->user_regs.ss = __KERNEL_DS;
23739 #ifdef CONFIG_X86_32
23740 ctxt->user_regs.fs = __KERNEL_PERCPU;
23741- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
23742+ savesegment(gs, ctxt->user_regs.gs);
23743 #else
23744 ctxt->gs_base_kernel = per_cpu_offset(cpu);
23745 #endif
23746@@ -287,13 +282,12 @@ static int __cpuinit xen_cpu_up(unsigned
23747 int rc;
23748
23749 per_cpu(current_task, cpu) = idle;
23750+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23751 #ifdef CONFIG_X86_32
23752 irq_ctx_init(cpu);
23753 #else
23754 clear_tsk_thread_flag(idle, TIF_FORK);
23755- per_cpu(kernel_stack, cpu) =
23756- (unsigned long)task_stack_page(idle) -
23757- KERNEL_STACK_OFFSET + THREAD_SIZE;
23758+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23759 #endif
23760 xen_setup_runstate_info(cpu);
23761 xen_setup_timer(cpu);
23762diff -urNp linux-2.6.32.43/arch/x86/xen/xen-asm_32.S linux-2.6.32.43/arch/x86/xen/xen-asm_32.S
23763--- linux-2.6.32.43/arch/x86/xen/xen-asm_32.S 2011-03-27 14:31:47.000000000 -0400
23764+++ linux-2.6.32.43/arch/x86/xen/xen-asm_32.S 2011-04-22 19:13:13.000000000 -0400
23765@@ -83,14 +83,14 @@ ENTRY(xen_iret)
23766 ESP_OFFSET=4 # bytes pushed onto stack
23767
23768 /*
23769- * Store vcpu_info pointer for easy access. Do it this way to
23770- * avoid having to reload %fs
23771+ * Store vcpu_info pointer for easy access.
23772 */
23773 #ifdef CONFIG_SMP
23774- GET_THREAD_INFO(%eax)
23775- movl TI_cpu(%eax), %eax
23776- movl __per_cpu_offset(,%eax,4), %eax
23777- mov per_cpu__xen_vcpu(%eax), %eax
23778+ push %fs
23779+ mov $(__KERNEL_PERCPU), %eax
23780+ mov %eax, %fs
23781+ mov PER_CPU_VAR(xen_vcpu), %eax
23782+ pop %fs
23783 #else
23784 movl per_cpu__xen_vcpu, %eax
23785 #endif
23786diff -urNp linux-2.6.32.43/arch/x86/xen/xen-head.S linux-2.6.32.43/arch/x86/xen/xen-head.S
23787--- linux-2.6.32.43/arch/x86/xen/xen-head.S 2011-03-27 14:31:47.000000000 -0400
23788+++ linux-2.6.32.43/arch/x86/xen/xen-head.S 2011-04-17 15:56:46.000000000 -0400
23789@@ -19,6 +19,17 @@ ENTRY(startup_xen)
23790 #ifdef CONFIG_X86_32
23791 mov %esi,xen_start_info
23792 mov $init_thread_union+THREAD_SIZE,%esp
23793+#ifdef CONFIG_SMP
23794+ movl $cpu_gdt_table,%edi
23795+ movl $__per_cpu_load,%eax
23796+ movw %ax,__KERNEL_PERCPU + 2(%edi)
23797+ rorl $16,%eax
23798+ movb %al,__KERNEL_PERCPU + 4(%edi)
23799+ movb %ah,__KERNEL_PERCPU + 7(%edi)
23800+ movl $__per_cpu_end - 1,%eax
23801+ subl $__per_cpu_start,%eax
23802+ movw %ax,__KERNEL_PERCPU + 0(%edi)
23803+#endif
23804 #else
23805 mov %rsi,xen_start_info
23806 mov $init_thread_union+THREAD_SIZE,%rsp
23807diff -urNp linux-2.6.32.43/arch/x86/xen/xen-ops.h linux-2.6.32.43/arch/x86/xen/xen-ops.h
23808--- linux-2.6.32.43/arch/x86/xen/xen-ops.h 2011-03-27 14:31:47.000000000 -0400
23809+++ linux-2.6.32.43/arch/x86/xen/xen-ops.h 2011-04-17 15:56:46.000000000 -0400
23810@@ -10,8 +10,6 @@
23811 extern const char xen_hypervisor_callback[];
23812 extern const char xen_failsafe_callback[];
23813
23814-extern void *xen_initial_gdt;
23815-
23816 struct trap_info;
23817 void xen_copy_trap_info(struct trap_info *traps);
23818
23819diff -urNp linux-2.6.32.43/block/blk-integrity.c linux-2.6.32.43/block/blk-integrity.c
23820--- linux-2.6.32.43/block/blk-integrity.c 2011-03-27 14:31:47.000000000 -0400
23821+++ linux-2.6.32.43/block/blk-integrity.c 2011-04-17 15:56:46.000000000 -0400
23822@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs
23823 NULL,
23824 };
23825
23826-static struct sysfs_ops integrity_ops = {
23827+static const struct sysfs_ops integrity_ops = {
23828 .show = &integrity_attr_show,
23829 .store = &integrity_attr_store,
23830 };
23831diff -urNp linux-2.6.32.43/block/blk-iopoll.c linux-2.6.32.43/block/blk-iopoll.c
23832--- linux-2.6.32.43/block/blk-iopoll.c 2011-03-27 14:31:47.000000000 -0400
23833+++ linux-2.6.32.43/block/blk-iopoll.c 2011-04-17 15:56:46.000000000 -0400
23834@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
23835 }
23836 EXPORT_SYMBOL(blk_iopoll_complete);
23837
23838-static void blk_iopoll_softirq(struct softirq_action *h)
23839+static void blk_iopoll_softirq(void)
23840 {
23841 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
23842 int rearm = 0, budget = blk_iopoll_budget;
23843diff -urNp linux-2.6.32.43/block/blk-map.c linux-2.6.32.43/block/blk-map.c
23844--- linux-2.6.32.43/block/blk-map.c 2011-03-27 14:31:47.000000000 -0400
23845+++ linux-2.6.32.43/block/blk-map.c 2011-04-18 16:57:33.000000000 -0400
23846@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct requ
23847 * direct dma. else, set up kernel bounce buffers
23848 */
23849 uaddr = (unsigned long) ubuf;
23850- if (blk_rq_aligned(q, ubuf, len) && !map_data)
23851+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
23852 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
23853 else
23854 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
23855@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_q
23856 for (i = 0; i < iov_count; i++) {
23857 unsigned long uaddr = (unsigned long)iov[i].iov_base;
23858
23859+ if (!iov[i].iov_len)
23860+ return -EINVAL;
23861+
23862 if (uaddr & queue_dma_alignment(q)) {
23863 unaligned = 1;
23864 break;
23865 }
23866- if (!iov[i].iov_len)
23867- return -EINVAL;
23868 }
23869
23870 if (unaligned || (q->dma_pad_mask & len) || map_data)
23871@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue
23872 if (!len || !kbuf)
23873 return -EINVAL;
23874
23875- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
23876+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
23877 if (do_copy)
23878 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
23879 else
23880diff -urNp linux-2.6.32.43/block/blk-softirq.c linux-2.6.32.43/block/blk-softirq.c
23881--- linux-2.6.32.43/block/blk-softirq.c 2011-03-27 14:31:47.000000000 -0400
23882+++ linux-2.6.32.43/block/blk-softirq.c 2011-04-17 15:56:46.000000000 -0400
23883@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
23884 * Softirq action handler - move entries to local list and loop over them
23885 * while passing them to the queue registered handler.
23886 */
23887-static void blk_done_softirq(struct softirq_action *h)
23888+static void blk_done_softirq(void)
23889 {
23890 struct list_head *cpu_list, local_list;
23891
23892diff -urNp linux-2.6.32.43/block/blk-sysfs.c linux-2.6.32.43/block/blk-sysfs.c
23893--- linux-2.6.32.43/block/blk-sysfs.c 2011-05-10 22:12:01.000000000 -0400
23894+++ linux-2.6.32.43/block/blk-sysfs.c 2011-05-10 22:12:26.000000000 -0400
23895@@ -414,7 +414,7 @@ static void blk_release_queue(struct kob
23896 kmem_cache_free(blk_requestq_cachep, q);
23897 }
23898
23899-static struct sysfs_ops queue_sysfs_ops = {
23900+static const struct sysfs_ops queue_sysfs_ops = {
23901 .show = queue_attr_show,
23902 .store = queue_attr_store,
23903 };
23904diff -urNp linux-2.6.32.43/block/bsg.c linux-2.6.32.43/block/bsg.c
23905--- linux-2.6.32.43/block/bsg.c 2011-03-27 14:31:47.000000000 -0400
23906+++ linux-2.6.32.43/block/bsg.c 2011-04-17 15:56:46.000000000 -0400
23907@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
23908 struct sg_io_v4 *hdr, struct bsg_device *bd,
23909 fmode_t has_write_perm)
23910 {
23911+ unsigned char tmpcmd[sizeof(rq->__cmd)];
23912+ unsigned char *cmdptr;
23913+
23914 if (hdr->request_len > BLK_MAX_CDB) {
23915 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
23916 if (!rq->cmd)
23917 return -ENOMEM;
23918- }
23919+ cmdptr = rq->cmd;
23920+ } else
23921+ cmdptr = tmpcmd;
23922
23923- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
23924+ if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
23925 hdr->request_len))
23926 return -EFAULT;
23927
23928+ if (cmdptr != rq->cmd)
23929+ memcpy(rq->cmd, cmdptr, hdr->request_len);
23930+
23931 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
23932 if (blk_verify_command(rq->cmd, has_write_perm))
23933 return -EPERM;
23934diff -urNp linux-2.6.32.43/block/elevator.c linux-2.6.32.43/block/elevator.c
23935--- linux-2.6.32.43/block/elevator.c 2011-03-27 14:31:47.000000000 -0400
23936+++ linux-2.6.32.43/block/elevator.c 2011-04-17 15:56:46.000000000 -0400
23937@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, str
23938 return error;
23939 }
23940
23941-static struct sysfs_ops elv_sysfs_ops = {
23942+static const struct sysfs_ops elv_sysfs_ops = {
23943 .show = elv_attr_show,
23944 .store = elv_attr_store,
23945 };
23946diff -urNp linux-2.6.32.43/block/scsi_ioctl.c linux-2.6.32.43/block/scsi_ioctl.c
23947--- linux-2.6.32.43/block/scsi_ioctl.c 2011-03-27 14:31:47.000000000 -0400
23948+++ linux-2.6.32.43/block/scsi_ioctl.c 2011-04-23 13:28:22.000000000 -0400
23949@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
23950 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
23951 struct sg_io_hdr *hdr, fmode_t mode)
23952 {
23953- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
23954+ unsigned char tmpcmd[sizeof(rq->__cmd)];
23955+ unsigned char *cmdptr;
23956+
23957+ if (rq->cmd != rq->__cmd)
23958+ cmdptr = rq->cmd;
23959+ else
23960+ cmdptr = tmpcmd;
23961+
23962+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
23963 return -EFAULT;
23964+
23965+ if (cmdptr != rq->cmd)
23966+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
23967+
23968 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
23969 return -EPERM;
23970
23971@@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *
23972 int err;
23973 unsigned int in_len, out_len, bytes, opcode, cmdlen;
23974 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
23975+ unsigned char tmpcmd[sizeof(rq->__cmd)];
23976+ unsigned char *cmdptr;
23977
23978 if (!sic)
23979 return -EINVAL;
23980@@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *
23981 */
23982 err = -EFAULT;
23983 rq->cmd_len = cmdlen;
23984- if (copy_from_user(rq->cmd, sic->data, cmdlen))
23985+
23986+ if (rq->cmd != rq->__cmd)
23987+ cmdptr = rq->cmd;
23988+ else
23989+ cmdptr = tmpcmd;
23990+
23991+ if (copy_from_user(cmdptr, sic->data, cmdlen))
23992 goto error;
23993
23994+ if (rq->cmd != cmdptr)
23995+ memcpy(rq->cmd, cmdptr, cmdlen);
23996+
23997 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
23998 goto error;
23999
24000diff -urNp linux-2.6.32.43/crypto/cryptd.c linux-2.6.32.43/crypto/cryptd.c
24001--- linux-2.6.32.43/crypto/cryptd.c 2011-03-27 14:31:47.000000000 -0400
24002+++ linux-2.6.32.43/crypto/cryptd.c 2011-08-05 20:33:55.000000000 -0400
24003@@ -214,7 +214,7 @@ static int cryptd_blkcipher_enqueue(stru
24004 struct cryptd_queue *queue;
24005
24006 queue = cryptd_get_queue(crypto_ablkcipher_tfm(tfm));
24007- rctx->complete = req->base.complete;
24008+ *(void **)&rctx->complete = req->base.complete;
24009 req->base.complete = complete;
24010
24011 return cryptd_enqueue_request(queue, &req->base);
24012diff -urNp linux-2.6.32.43/crypto/gf128mul.c linux-2.6.32.43/crypto/gf128mul.c
24013--- linux-2.6.32.43/crypto/gf128mul.c 2011-03-27 14:31:47.000000000 -0400
24014+++ linux-2.6.32.43/crypto/gf128mul.c 2011-07-06 19:53:33.000000000 -0400
24015@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128
24016 for (i = 0; i < 7; ++i)
24017 gf128mul_x_lle(&p[i + 1], &p[i]);
24018
24019- memset(r, 0, sizeof(r));
24020+ memset(r, 0, sizeof(*r));
24021 for (i = 0;;) {
24022 u8 ch = ((u8 *)b)[15 - i];
24023
24024@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128
24025 for (i = 0; i < 7; ++i)
24026 gf128mul_x_bbe(&p[i + 1], &p[i]);
24027
24028- memset(r, 0, sizeof(r));
24029+ memset(r, 0, sizeof(*r));
24030 for (i = 0;;) {
24031 u8 ch = ((u8 *)b)[i];
24032
24033diff -urNp linux-2.6.32.43/crypto/serpent.c linux-2.6.32.43/crypto/serpent.c
24034--- linux-2.6.32.43/crypto/serpent.c 2011-03-27 14:31:47.000000000 -0400
24035+++ linux-2.6.32.43/crypto/serpent.c 2011-05-16 21:46:57.000000000 -0400
24036@@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24037 u32 r0,r1,r2,r3,r4;
24038 int i;
24039
24040+ pax_track_stack();
24041+
24042 /* Copy key, add padding */
24043
24044 for (i = 0; i < keylen; ++i)
24045diff -urNp linux-2.6.32.43/Documentation/dontdiff linux-2.6.32.43/Documentation/dontdiff
24046--- linux-2.6.32.43/Documentation/dontdiff 2011-03-27 14:31:47.000000000 -0400
24047+++ linux-2.6.32.43/Documentation/dontdiff 2011-05-18 20:09:36.000000000 -0400
24048@@ -1,13 +1,16 @@
24049 *.a
24050 *.aux
24051 *.bin
24052+*.cis
24053 *.cpio
24054 *.csp
24055+*.dbg
24056 *.dsp
24057 *.dvi
24058 *.elf
24059 *.eps
24060 *.fw
24061+*.gcno
24062 *.gen.S
24063 *.gif
24064 *.grep
24065@@ -38,8 +41,10 @@
24066 *.tab.h
24067 *.tex
24068 *.ver
24069+*.vim
24070 *.xml
24071 *_MODULES
24072+*_reg_safe.h
24073 *_vga16.c
24074 *~
24075 *.9
24076@@ -49,11 +54,16 @@
24077 53c700_d.h
24078 CVS
24079 ChangeSet
24080+GPATH
24081+GRTAGS
24082+GSYMS
24083+GTAGS
24084 Image
24085 Kerntypes
24086 Module.markers
24087 Module.symvers
24088 PENDING
24089+PERF*
24090 SCCS
24091 System.map*
24092 TAGS
24093@@ -76,7 +86,11 @@ btfixupprep
24094 build
24095 bvmlinux
24096 bzImage*
24097+capability_names.h
24098+capflags.c
24099 classlist.h*
24100+clut_vga16.c
24101+common-cmds.h
24102 comp*.log
24103 compile.h*
24104 conf
24105@@ -103,13 +117,14 @@ gen_crc32table
24106 gen_init_cpio
24107 genksyms
24108 *_gray256.c
24109+hash
24110 ihex2fw
24111 ikconfig.h*
24112 initramfs_data.cpio
24113+initramfs_data.cpio.bz2
24114 initramfs_data.cpio.gz
24115 initramfs_list
24116 kallsyms
24117-kconfig
24118 keywords.c
24119 ksym.c*
24120 ksym.h*
24121@@ -133,7 +148,9 @@ mkboot
24122 mkbugboot
24123 mkcpustr
24124 mkdep
24125+mkpiggy
24126 mkprep
24127+mkregtable
24128 mktables
24129 mktree
24130 modpost
24131@@ -149,6 +166,7 @@ patches*
24132 pca200e.bin
24133 pca200e_ecd.bin2
24134 piggy.gz
24135+piggy.S
24136 piggyback
24137 pnmtologo
24138 ppc_defs.h*
24139@@ -157,12 +175,15 @@ qconf
24140 raid6altivec*.c
24141 raid6int*.c
24142 raid6tables.c
24143+regdb.c
24144 relocs
24145+rlim_names.h
24146 series
24147 setup
24148 setup.bin
24149 setup.elf
24150 sImage
24151+slabinfo
24152 sm_tbl*
24153 split-include
24154 syscalltab.h
24155@@ -186,14 +207,20 @@ version.h*
24156 vmlinux
24157 vmlinux-*
24158 vmlinux.aout
24159+vmlinux.bin.all
24160+vmlinux.bin.bz2
24161 vmlinux.lds
24162+vmlinux.relocs
24163+voffset.h
24164 vsyscall.lds
24165 vsyscall_32.lds
24166 wanxlfw.inc
24167 uImage
24168 unifdef
24169+utsrelease.h
24170 wakeup.bin
24171 wakeup.elf
24172 wakeup.lds
24173 zImage*
24174 zconf.hash.c
24175+zoffset.h
24176diff -urNp linux-2.6.32.43/Documentation/kernel-parameters.txt linux-2.6.32.43/Documentation/kernel-parameters.txt
24177--- linux-2.6.32.43/Documentation/kernel-parameters.txt 2011-03-27 14:31:47.000000000 -0400
24178+++ linux-2.6.32.43/Documentation/kernel-parameters.txt 2011-04-17 15:56:45.000000000 -0400
24179@@ -1837,6 +1837,13 @@ and is between 256 and 4096 characters.
24180 the specified number of seconds. This is to be used if
24181 your oopses keep scrolling off the screen.
24182
24183+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24184+ virtualization environments that don't cope well with the
24185+ expand down segment used by UDEREF on X86-32 or the frequent
24186+ page table updates on X86-64.
24187+
24188+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24189+
24190 pcbit= [HW,ISDN]
24191
24192 pcd. [PARIDE]
24193diff -urNp linux-2.6.32.43/drivers/acpi/acpi_pad.c linux-2.6.32.43/drivers/acpi/acpi_pad.c
24194--- linux-2.6.32.43/drivers/acpi/acpi_pad.c 2011-03-27 14:31:47.000000000 -0400
24195+++ linux-2.6.32.43/drivers/acpi/acpi_pad.c 2011-04-17 15:56:46.000000000 -0400
24196@@ -30,7 +30,7 @@
24197 #include <acpi/acpi_bus.h>
24198 #include <acpi/acpi_drivers.h>
24199
24200-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
24201+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
24202 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
24203 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
24204 static DEFINE_MUTEX(isolated_cpus_lock);
24205diff -urNp linux-2.6.32.43/drivers/acpi/battery.c linux-2.6.32.43/drivers/acpi/battery.c
24206--- linux-2.6.32.43/drivers/acpi/battery.c 2011-03-27 14:31:47.000000000 -0400
24207+++ linux-2.6.32.43/drivers/acpi/battery.c 2011-04-17 15:56:46.000000000 -0400
24208@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24209 }
24210
24211 static struct battery_file {
24212- struct file_operations ops;
24213+ const struct file_operations ops;
24214 mode_t mode;
24215 const char *name;
24216 } acpi_battery_file[] = {
24217diff -urNp linux-2.6.32.43/drivers/acpi/dock.c linux-2.6.32.43/drivers/acpi/dock.c
24218--- linux-2.6.32.43/drivers/acpi/dock.c 2011-03-27 14:31:47.000000000 -0400
24219+++ linux-2.6.32.43/drivers/acpi/dock.c 2011-04-17 15:56:46.000000000 -0400
24220@@ -77,7 +77,7 @@ struct dock_dependent_device {
24221 struct list_head list;
24222 struct list_head hotplug_list;
24223 acpi_handle handle;
24224- struct acpi_dock_ops *ops;
24225+ const struct acpi_dock_ops *ops;
24226 void *context;
24227 };
24228
24229@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24230 * the dock driver after _DCK is executed.
24231 */
24232 int
24233-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24234+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24235 void *context)
24236 {
24237 struct dock_dependent_device *dd;
24238diff -urNp linux-2.6.32.43/drivers/acpi/osl.c linux-2.6.32.43/drivers/acpi/osl.c
24239--- linux-2.6.32.43/drivers/acpi/osl.c 2011-03-27 14:31:47.000000000 -0400
24240+++ linux-2.6.32.43/drivers/acpi/osl.c 2011-04-17 15:56:46.000000000 -0400
24241@@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_addres
24242 void __iomem *virt_addr;
24243
24244 virt_addr = ioremap(phys_addr, width);
24245+ if (!virt_addr)
24246+ return AE_NO_MEMORY;
24247 if (!value)
24248 value = &dummy;
24249
24250@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_addre
24251 void __iomem *virt_addr;
24252
24253 virt_addr = ioremap(phys_addr, width);
24254+ if (!virt_addr)
24255+ return AE_NO_MEMORY;
24256
24257 switch (width) {
24258 case 8:
24259diff -urNp linux-2.6.32.43/drivers/acpi/power_meter.c linux-2.6.32.43/drivers/acpi/power_meter.c
24260--- linux-2.6.32.43/drivers/acpi/power_meter.c 2011-03-27 14:31:47.000000000 -0400
24261+++ linux-2.6.32.43/drivers/acpi/power_meter.c 2011-04-17 15:56:46.000000000 -0400
24262@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *d
24263 return res;
24264
24265 temp /= 1000;
24266- if (temp < 0)
24267- return -EINVAL;
24268
24269 mutex_lock(&resource->lock);
24270 resource->trip[attr->index - 7] = temp;
24271diff -urNp linux-2.6.32.43/drivers/acpi/proc.c linux-2.6.32.43/drivers/acpi/proc.c
24272--- linux-2.6.32.43/drivers/acpi/proc.c 2011-03-27 14:31:47.000000000 -0400
24273+++ linux-2.6.32.43/drivers/acpi/proc.c 2011-04-17 15:56:46.000000000 -0400
24274@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct f
24275 size_t count, loff_t * ppos)
24276 {
24277 struct list_head *node, *next;
24278- char strbuf[5];
24279- char str[5] = "";
24280- unsigned int len = count;
24281+ char strbuf[5] = {0};
24282 struct acpi_device *found_dev = NULL;
24283
24284- if (len > 4)
24285- len = 4;
24286- if (len < 0)
24287- return -EFAULT;
24288+ if (count > 4)
24289+ count = 4;
24290
24291- if (copy_from_user(strbuf, buffer, len))
24292+ if (copy_from_user(strbuf, buffer, count))
24293 return -EFAULT;
24294- strbuf[len] = '\0';
24295- sscanf(strbuf, "%s", str);
24296+ strbuf[count] = '\0';
24297
24298 mutex_lock(&acpi_device_lock);
24299 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24300@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct f
24301 if (!dev->wakeup.flags.valid)
24302 continue;
24303
24304- if (!strncmp(dev->pnp.bus_id, str, 4)) {
24305+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24306 dev->wakeup.state.enabled =
24307 dev->wakeup.state.enabled ? 0 : 1;
24308 found_dev = dev;
24309diff -urNp linux-2.6.32.43/drivers/acpi/processor_core.c linux-2.6.32.43/drivers/acpi/processor_core.c
24310--- linux-2.6.32.43/drivers/acpi/processor_core.c 2011-03-27 14:31:47.000000000 -0400
24311+++ linux-2.6.32.43/drivers/acpi/processor_core.c 2011-04-17 15:56:46.000000000 -0400
24312@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(
24313 return 0;
24314 }
24315
24316- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24317+ BUG_ON(pr->id >= nr_cpu_ids);
24318
24319 /*
24320 * Buggy BIOS check
24321diff -urNp linux-2.6.32.43/drivers/acpi/sbshc.c linux-2.6.32.43/drivers/acpi/sbshc.c
24322--- linux-2.6.32.43/drivers/acpi/sbshc.c 2011-03-27 14:31:47.000000000 -0400
24323+++ linux-2.6.32.43/drivers/acpi/sbshc.c 2011-04-17 15:56:46.000000000 -0400
24324@@ -17,7 +17,7 @@
24325
24326 #define PREFIX "ACPI: "
24327
24328-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
24329+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
24330 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
24331
24332 struct acpi_smb_hc {
24333diff -urNp linux-2.6.32.43/drivers/acpi/sleep.c linux-2.6.32.43/drivers/acpi/sleep.c
24334--- linux-2.6.32.43/drivers/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
24335+++ linux-2.6.32.43/drivers/acpi/sleep.c 2011-04-17 15:56:46.000000000 -0400
24336@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(susp
24337 }
24338 }
24339
24340-static struct platform_suspend_ops acpi_suspend_ops = {
24341+static const struct platform_suspend_ops acpi_suspend_ops = {
24342 .valid = acpi_suspend_state_valid,
24343 .begin = acpi_suspend_begin,
24344 .prepare_late = acpi_pm_prepare,
24345@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspen
24346 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
24347 * been requested.
24348 */
24349-static struct platform_suspend_ops acpi_suspend_ops_old = {
24350+static const struct platform_suspend_ops acpi_suspend_ops_old = {
24351 .valid = acpi_suspend_state_valid,
24352 .begin = acpi_suspend_begin_old,
24353 .prepare_late = acpi_pm_disable_gpes,
24354@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
24355 acpi_enable_all_runtime_gpes();
24356 }
24357
24358-static struct platform_hibernation_ops acpi_hibernation_ops = {
24359+static const struct platform_hibernation_ops acpi_hibernation_ops = {
24360 .begin = acpi_hibernation_begin,
24361 .end = acpi_pm_end,
24362 .pre_snapshot = acpi_hibernation_pre_snapshot,
24363@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot
24364 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
24365 * been requested.
24366 */
24367-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
24368+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
24369 .begin = acpi_hibernation_begin_old,
24370 .end = acpi_pm_end,
24371 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
24372diff -urNp linux-2.6.32.43/drivers/acpi/video.c linux-2.6.32.43/drivers/acpi/video.c
24373--- linux-2.6.32.43/drivers/acpi/video.c 2011-03-27 14:31:47.000000000 -0400
24374+++ linux-2.6.32.43/drivers/acpi/video.c 2011-04-17 15:56:46.000000000 -0400
24375@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(str
24376 vd->brightness->levels[request_level]);
24377 }
24378
24379-static struct backlight_ops acpi_backlight_ops = {
24380+static const struct backlight_ops acpi_backlight_ops = {
24381 .get_brightness = acpi_video_get_brightness,
24382 .update_status = acpi_video_set_brightness,
24383 };
24384diff -urNp linux-2.6.32.43/drivers/ata/ahci.c linux-2.6.32.43/drivers/ata/ahci.c
24385--- linux-2.6.32.43/drivers/ata/ahci.c 2011-03-27 14:31:47.000000000 -0400
24386+++ linux-2.6.32.43/drivers/ata/ahci.c 2011-04-23 12:56:10.000000000 -0400
24387@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sh
24388 .sdev_attrs = ahci_sdev_attrs,
24389 };
24390
24391-static struct ata_port_operations ahci_ops = {
24392+static const struct ata_port_operations ahci_ops = {
24393 .inherits = &sata_pmp_port_ops,
24394
24395 .qc_defer = sata_pmp_qc_defer_cmd_switch,
24396@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_o
24397 .port_stop = ahci_port_stop,
24398 };
24399
24400-static struct ata_port_operations ahci_vt8251_ops = {
24401+static const struct ata_port_operations ahci_vt8251_ops = {
24402 .inherits = &ahci_ops,
24403 .hardreset = ahci_vt8251_hardreset,
24404 };
24405
24406-static struct ata_port_operations ahci_p5wdh_ops = {
24407+static const struct ata_port_operations ahci_p5wdh_ops = {
24408 .inherits = &ahci_ops,
24409 .hardreset = ahci_p5wdh_hardreset,
24410 };
24411
24412-static struct ata_port_operations ahci_sb600_ops = {
24413+static const struct ata_port_operations ahci_sb600_ops = {
24414 .inherits = &ahci_ops,
24415 .softreset = ahci_sb600_softreset,
24416 .pmp_softreset = ahci_sb600_softreset,
24417diff -urNp linux-2.6.32.43/drivers/ata/ata_generic.c linux-2.6.32.43/drivers/ata/ata_generic.c
24418--- linux-2.6.32.43/drivers/ata/ata_generic.c 2011-03-27 14:31:47.000000000 -0400
24419+++ linux-2.6.32.43/drivers/ata/ata_generic.c 2011-04-17 15:56:46.000000000 -0400
24420@@ -104,7 +104,7 @@ static struct scsi_host_template generic
24421 ATA_BMDMA_SHT(DRV_NAME),
24422 };
24423
24424-static struct ata_port_operations generic_port_ops = {
24425+static const struct ata_port_operations generic_port_ops = {
24426 .inherits = &ata_bmdma_port_ops,
24427 .cable_detect = ata_cable_unknown,
24428 .set_mode = generic_set_mode,
24429diff -urNp linux-2.6.32.43/drivers/ata/ata_piix.c linux-2.6.32.43/drivers/ata/ata_piix.c
24430--- linux-2.6.32.43/drivers/ata/ata_piix.c 2011-03-27 14:31:47.000000000 -0400
24431+++ linux-2.6.32.43/drivers/ata/ata_piix.c 2011-04-23 12:56:10.000000000 -0400
24432@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sh
24433 ATA_BMDMA_SHT(DRV_NAME),
24434 };
24435
24436-static struct ata_port_operations piix_pata_ops = {
24437+static const struct ata_port_operations piix_pata_ops = {
24438 .inherits = &ata_bmdma32_port_ops,
24439 .cable_detect = ata_cable_40wire,
24440 .set_piomode = piix_set_piomode,
24441@@ -326,22 +326,22 @@ static struct ata_port_operations piix_p
24442 .prereset = piix_pata_prereset,
24443 };
24444
24445-static struct ata_port_operations piix_vmw_ops = {
24446+static const struct ata_port_operations piix_vmw_ops = {
24447 .inherits = &piix_pata_ops,
24448 .bmdma_status = piix_vmw_bmdma_status,
24449 };
24450
24451-static struct ata_port_operations ich_pata_ops = {
24452+static const struct ata_port_operations ich_pata_ops = {
24453 .inherits = &piix_pata_ops,
24454 .cable_detect = ich_pata_cable_detect,
24455 .set_dmamode = ich_set_dmamode,
24456 };
24457
24458-static struct ata_port_operations piix_sata_ops = {
24459+static const struct ata_port_operations piix_sata_ops = {
24460 .inherits = &ata_bmdma_port_ops,
24461 };
24462
24463-static struct ata_port_operations piix_sidpr_sata_ops = {
24464+static const struct ata_port_operations piix_sidpr_sata_ops = {
24465 .inherits = &piix_sata_ops,
24466 .hardreset = sata_std_hardreset,
24467 .scr_read = piix_sidpr_scr_read,
24468diff -urNp linux-2.6.32.43/drivers/ata/libata-acpi.c linux-2.6.32.43/drivers/ata/libata-acpi.c
24469--- linux-2.6.32.43/drivers/ata/libata-acpi.c 2011-03-27 14:31:47.000000000 -0400
24470+++ linux-2.6.32.43/drivers/ata/libata-acpi.c 2011-04-17 15:56:46.000000000 -0400
24471@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_han
24472 ata_acpi_uevent(dev->link->ap, dev, event);
24473 }
24474
24475-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24476+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24477 .handler = ata_acpi_dev_notify_dock,
24478 .uevent = ata_acpi_dev_uevent,
24479 };
24480
24481-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24482+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24483 .handler = ata_acpi_ap_notify_dock,
24484 .uevent = ata_acpi_ap_uevent,
24485 };
24486diff -urNp linux-2.6.32.43/drivers/ata/libata-core.c linux-2.6.32.43/drivers/ata/libata-core.c
24487--- linux-2.6.32.43/drivers/ata/libata-core.c 2011-03-27 14:31:47.000000000 -0400
24488+++ linux-2.6.32.43/drivers/ata/libata-core.c 2011-08-05 20:33:55.000000000 -0400
24489@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *
24490 struct ata_port *ap;
24491 unsigned int tag;
24492
24493- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24494+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24495 ap = qc->ap;
24496
24497 qc->flags = 0;
24498@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued
24499 struct ata_port *ap;
24500 struct ata_link *link;
24501
24502- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24503+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24504 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
24505 ap = qc->ap;
24506 link = qc->dev->link;
24507@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device
24508 * LOCKING:
24509 * None.
24510 */
24511-static void ata_finalize_port_ops(struct ata_port_operations *ops)
24512+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
24513 {
24514 static DEFINE_SPINLOCK(lock);
24515 const struct ata_port_operations *cur;
24516@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct
24517 return;
24518
24519 spin_lock(&lock);
24520+ pax_open_kernel();
24521
24522 for (cur = ops->inherits; cur; cur = cur->inherits) {
24523 void **inherit = (void **)cur;
24524@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct
24525 if (IS_ERR(*pp))
24526 *pp = NULL;
24527
24528- ops->inherits = NULL;
24529+ *(struct ata_port_operations **)&ops->inherits = NULL;
24530
24531+ pax_close_kernel();
24532 spin_unlock(&lock);
24533 }
24534
24535@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host
24536 */
24537 /* KILLME - the only user left is ipr */
24538 void ata_host_init(struct ata_host *host, struct device *dev,
24539- unsigned long flags, struct ata_port_operations *ops)
24540+ unsigned long flags, const struct ata_port_operations *ops)
24541 {
24542 spin_lock_init(&host->lock);
24543 host->dev = dev;
24544@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(stru
24545 /* truly dummy */
24546 }
24547
24548-struct ata_port_operations ata_dummy_port_ops = {
24549+const struct ata_port_operations ata_dummy_port_ops = {
24550 .qc_prep = ata_noop_qc_prep,
24551 .qc_issue = ata_dummy_qc_issue,
24552 .error_handler = ata_dummy_error_handler,
24553diff -urNp linux-2.6.32.43/drivers/ata/libata-eh.c linux-2.6.32.43/drivers/ata/libata-eh.c
24554--- linux-2.6.32.43/drivers/ata/libata-eh.c 2011-03-27 14:31:47.000000000 -0400
24555+++ linux-2.6.32.43/drivers/ata/libata-eh.c 2011-05-16 21:46:57.000000000 -0400
24556@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
24557 {
24558 struct ata_link *link;
24559
24560+ pax_track_stack();
24561+
24562 ata_for_each_link(link, ap, HOST_FIRST)
24563 ata_eh_link_report(link);
24564 }
24565@@ -3590,7 +3592,7 @@ void ata_do_eh(struct ata_port *ap, ata_
24566 */
24567 void ata_std_error_handler(struct ata_port *ap)
24568 {
24569- struct ata_port_operations *ops = ap->ops;
24570+ const struct ata_port_operations *ops = ap->ops;
24571 ata_reset_fn_t hardreset = ops->hardreset;
24572
24573 /* ignore built-in hardreset if SCR access is not available */
24574diff -urNp linux-2.6.32.43/drivers/ata/libata-pmp.c linux-2.6.32.43/drivers/ata/libata-pmp.c
24575--- linux-2.6.32.43/drivers/ata/libata-pmp.c 2011-03-27 14:31:47.000000000 -0400
24576+++ linux-2.6.32.43/drivers/ata/libata-pmp.c 2011-04-17 15:56:46.000000000 -0400
24577@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(str
24578 */
24579 static int sata_pmp_eh_recover(struct ata_port *ap)
24580 {
24581- struct ata_port_operations *ops = ap->ops;
24582+ const struct ata_port_operations *ops = ap->ops;
24583 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
24584 struct ata_link *pmp_link = &ap->link;
24585 struct ata_device *pmp_dev = pmp_link->device;
24586diff -urNp linux-2.6.32.43/drivers/ata/pata_acpi.c linux-2.6.32.43/drivers/ata/pata_acpi.c
24587--- linux-2.6.32.43/drivers/ata/pata_acpi.c 2011-03-27 14:31:47.000000000 -0400
24588+++ linux-2.6.32.43/drivers/ata/pata_acpi.c 2011-04-17 15:56:46.000000000 -0400
24589@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_s
24590 ATA_BMDMA_SHT(DRV_NAME),
24591 };
24592
24593-static struct ata_port_operations pacpi_ops = {
24594+static const struct ata_port_operations pacpi_ops = {
24595 .inherits = &ata_bmdma_port_ops,
24596 .qc_issue = pacpi_qc_issue,
24597 .cable_detect = pacpi_cable_detect,
24598diff -urNp linux-2.6.32.43/drivers/ata/pata_ali.c linux-2.6.32.43/drivers/ata/pata_ali.c
24599--- linux-2.6.32.43/drivers/ata/pata_ali.c 2011-03-27 14:31:47.000000000 -0400
24600+++ linux-2.6.32.43/drivers/ata/pata_ali.c 2011-04-17 15:56:46.000000000 -0400
24601@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht
24602 * Port operations for PIO only ALi
24603 */
24604
24605-static struct ata_port_operations ali_early_port_ops = {
24606+static const struct ata_port_operations ali_early_port_ops = {
24607 .inherits = &ata_sff_port_ops,
24608 .cable_detect = ata_cable_40wire,
24609 .set_piomode = ali_set_piomode,
24610@@ -382,7 +382,7 @@ static const struct ata_port_operations
24611 * Port operations for DMA capable ALi without cable
24612 * detect
24613 */
24614-static struct ata_port_operations ali_20_port_ops = {
24615+static const struct ata_port_operations ali_20_port_ops = {
24616 .inherits = &ali_dma_base_ops,
24617 .cable_detect = ata_cable_40wire,
24618 .mode_filter = ali_20_filter,
24619@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20
24620 /*
24621 * Port operations for DMA capable ALi with cable detect
24622 */
24623-static struct ata_port_operations ali_c2_port_ops = {
24624+static const struct ata_port_operations ali_c2_port_ops = {
24625 .inherits = &ali_dma_base_ops,
24626 .check_atapi_dma = ali_check_atapi_dma,
24627 .cable_detect = ali_c2_cable_detect,
24628@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2
24629 /*
24630 * Port operations for DMA capable ALi with cable detect
24631 */
24632-static struct ata_port_operations ali_c4_port_ops = {
24633+static const struct ata_port_operations ali_c4_port_ops = {
24634 .inherits = &ali_dma_base_ops,
24635 .check_atapi_dma = ali_check_atapi_dma,
24636 .cable_detect = ali_c2_cable_detect,
24637@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4
24638 /*
24639 * Port operations for DMA capable ALi with cable detect and LBA48
24640 */
24641-static struct ata_port_operations ali_c5_port_ops = {
24642+static const struct ata_port_operations ali_c5_port_ops = {
24643 .inherits = &ali_dma_base_ops,
24644 .check_atapi_dma = ali_check_atapi_dma,
24645 .dev_config = ali_warn_atapi_dma,
24646diff -urNp linux-2.6.32.43/drivers/ata/pata_amd.c linux-2.6.32.43/drivers/ata/pata_amd.c
24647--- linux-2.6.32.43/drivers/ata/pata_amd.c 2011-03-27 14:31:47.000000000 -0400
24648+++ linux-2.6.32.43/drivers/ata/pata_amd.c 2011-04-17 15:56:46.000000000 -0400
24649@@ -397,28 +397,28 @@ static const struct ata_port_operations
24650 .prereset = amd_pre_reset,
24651 };
24652
24653-static struct ata_port_operations amd33_port_ops = {
24654+static const struct ata_port_operations amd33_port_ops = {
24655 .inherits = &amd_base_port_ops,
24656 .cable_detect = ata_cable_40wire,
24657 .set_piomode = amd33_set_piomode,
24658 .set_dmamode = amd33_set_dmamode,
24659 };
24660
24661-static struct ata_port_operations amd66_port_ops = {
24662+static const struct ata_port_operations amd66_port_ops = {
24663 .inherits = &amd_base_port_ops,
24664 .cable_detect = ata_cable_unknown,
24665 .set_piomode = amd66_set_piomode,
24666 .set_dmamode = amd66_set_dmamode,
24667 };
24668
24669-static struct ata_port_operations amd100_port_ops = {
24670+static const struct ata_port_operations amd100_port_ops = {
24671 .inherits = &amd_base_port_ops,
24672 .cable_detect = ata_cable_unknown,
24673 .set_piomode = amd100_set_piomode,
24674 .set_dmamode = amd100_set_dmamode,
24675 };
24676
24677-static struct ata_port_operations amd133_port_ops = {
24678+static const struct ata_port_operations amd133_port_ops = {
24679 .inherits = &amd_base_port_ops,
24680 .cable_detect = amd_cable_detect,
24681 .set_piomode = amd133_set_piomode,
24682@@ -433,13 +433,13 @@ static const struct ata_port_operations
24683 .host_stop = nv_host_stop,
24684 };
24685
24686-static struct ata_port_operations nv100_port_ops = {
24687+static const struct ata_port_operations nv100_port_ops = {
24688 .inherits = &nv_base_port_ops,
24689 .set_piomode = nv100_set_piomode,
24690 .set_dmamode = nv100_set_dmamode,
24691 };
24692
24693-static struct ata_port_operations nv133_port_ops = {
24694+static const struct ata_port_operations nv133_port_ops = {
24695 .inherits = &nv_base_port_ops,
24696 .set_piomode = nv133_set_piomode,
24697 .set_dmamode = nv133_set_dmamode,
24698diff -urNp linux-2.6.32.43/drivers/ata/pata_artop.c linux-2.6.32.43/drivers/ata/pata_artop.c
24699--- linux-2.6.32.43/drivers/ata/pata_artop.c 2011-03-27 14:31:47.000000000 -0400
24700+++ linux-2.6.32.43/drivers/ata/pata_artop.c 2011-04-17 15:56:46.000000000 -0400
24701@@ -311,7 +311,7 @@ static struct scsi_host_template artop_s
24702 ATA_BMDMA_SHT(DRV_NAME),
24703 };
24704
24705-static struct ata_port_operations artop6210_ops = {
24706+static const struct ata_port_operations artop6210_ops = {
24707 .inherits = &ata_bmdma_port_ops,
24708 .cable_detect = ata_cable_40wire,
24709 .set_piomode = artop6210_set_piomode,
24710@@ -320,7 +320,7 @@ static struct ata_port_operations artop6
24711 .qc_defer = artop6210_qc_defer,
24712 };
24713
24714-static struct ata_port_operations artop6260_ops = {
24715+static const struct ata_port_operations artop6260_ops = {
24716 .inherits = &ata_bmdma_port_ops,
24717 .cable_detect = artop6260_cable_detect,
24718 .set_piomode = artop6260_set_piomode,
24719diff -urNp linux-2.6.32.43/drivers/ata/pata_at32.c linux-2.6.32.43/drivers/ata/pata_at32.c
24720--- linux-2.6.32.43/drivers/ata/pata_at32.c 2011-03-27 14:31:47.000000000 -0400
24721+++ linux-2.6.32.43/drivers/ata/pata_at32.c 2011-04-17 15:56:46.000000000 -0400
24722@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sh
24723 ATA_PIO_SHT(DRV_NAME),
24724 };
24725
24726-static struct ata_port_operations at32_port_ops = {
24727+static const struct ata_port_operations at32_port_ops = {
24728 .inherits = &ata_sff_port_ops,
24729 .cable_detect = ata_cable_40wire,
24730 .set_piomode = pata_at32_set_piomode,
24731diff -urNp linux-2.6.32.43/drivers/ata/pata_at91.c linux-2.6.32.43/drivers/ata/pata_at91.c
24732--- linux-2.6.32.43/drivers/ata/pata_at91.c 2011-03-27 14:31:47.000000000 -0400
24733+++ linux-2.6.32.43/drivers/ata/pata_at91.c 2011-04-17 15:56:46.000000000 -0400
24734@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at
24735 ATA_PIO_SHT(DRV_NAME),
24736 };
24737
24738-static struct ata_port_operations pata_at91_port_ops = {
24739+static const struct ata_port_operations pata_at91_port_ops = {
24740 .inherits = &ata_sff_port_ops,
24741
24742 .sff_data_xfer = pata_at91_data_xfer_noirq,
24743diff -urNp linux-2.6.32.43/drivers/ata/pata_atiixp.c linux-2.6.32.43/drivers/ata/pata_atiixp.c
24744--- linux-2.6.32.43/drivers/ata/pata_atiixp.c 2011-03-27 14:31:47.000000000 -0400
24745+++ linux-2.6.32.43/drivers/ata/pata_atiixp.c 2011-04-17 15:56:46.000000000 -0400
24746@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_
24747 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24748 };
24749
24750-static struct ata_port_operations atiixp_port_ops = {
24751+static const struct ata_port_operations atiixp_port_ops = {
24752 .inherits = &ata_bmdma_port_ops,
24753
24754 .qc_prep = ata_sff_dumb_qc_prep,
24755diff -urNp linux-2.6.32.43/drivers/ata/pata_atp867x.c linux-2.6.32.43/drivers/ata/pata_atp867x.c
24756--- linux-2.6.32.43/drivers/ata/pata_atp867x.c 2011-03-27 14:31:47.000000000 -0400
24757+++ linux-2.6.32.43/drivers/ata/pata_atp867x.c 2011-04-17 15:56:46.000000000 -0400
24758@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x
24759 ATA_BMDMA_SHT(DRV_NAME),
24760 };
24761
24762-static struct ata_port_operations atp867x_ops = {
24763+static const struct ata_port_operations atp867x_ops = {
24764 .inherits = &ata_bmdma_port_ops,
24765 .cable_detect = atp867x_cable_detect,
24766 .set_piomode = atp867x_set_piomode,
24767diff -urNp linux-2.6.32.43/drivers/ata/pata_bf54x.c linux-2.6.32.43/drivers/ata/pata_bf54x.c
24768--- linux-2.6.32.43/drivers/ata/pata_bf54x.c 2011-03-27 14:31:47.000000000 -0400
24769+++ linux-2.6.32.43/drivers/ata/pata_bf54x.c 2011-04-17 15:56:46.000000000 -0400
24770@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sh
24771 .dma_boundary = ATA_DMA_BOUNDARY,
24772 };
24773
24774-static struct ata_port_operations bfin_pata_ops = {
24775+static const struct ata_port_operations bfin_pata_ops = {
24776 .inherits = &ata_sff_port_ops,
24777
24778 .set_piomode = bfin_set_piomode,
24779diff -urNp linux-2.6.32.43/drivers/ata/pata_cmd640.c linux-2.6.32.43/drivers/ata/pata_cmd640.c
24780--- linux-2.6.32.43/drivers/ata/pata_cmd640.c 2011-03-27 14:31:47.000000000 -0400
24781+++ linux-2.6.32.43/drivers/ata/pata_cmd640.c 2011-04-17 15:56:46.000000000 -0400
24782@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_
24783 ATA_BMDMA_SHT(DRV_NAME),
24784 };
24785
24786-static struct ata_port_operations cmd640_port_ops = {
24787+static const struct ata_port_operations cmd640_port_ops = {
24788 .inherits = &ata_bmdma_port_ops,
24789 /* In theory xfer_noirq is not needed once we kill the prefetcher */
24790 .sff_data_xfer = ata_sff_data_xfer_noirq,
24791diff -urNp linux-2.6.32.43/drivers/ata/pata_cmd64x.c linux-2.6.32.43/drivers/ata/pata_cmd64x.c
24792--- linux-2.6.32.43/drivers/ata/pata_cmd64x.c 2011-06-25 12:55:34.000000000 -0400
24793+++ linux-2.6.32.43/drivers/ata/pata_cmd64x.c 2011-06-25 12:56:37.000000000 -0400
24794@@ -271,18 +271,18 @@ static const struct ata_port_operations
24795 .set_dmamode = cmd64x_set_dmamode,
24796 };
24797
24798-static struct ata_port_operations cmd64x_port_ops = {
24799+static const struct ata_port_operations cmd64x_port_ops = {
24800 .inherits = &cmd64x_base_ops,
24801 .cable_detect = ata_cable_40wire,
24802 };
24803
24804-static struct ata_port_operations cmd646r1_port_ops = {
24805+static const struct ata_port_operations cmd646r1_port_ops = {
24806 .inherits = &cmd64x_base_ops,
24807 .bmdma_stop = cmd646r1_bmdma_stop,
24808 .cable_detect = ata_cable_40wire,
24809 };
24810
24811-static struct ata_port_operations cmd648_port_ops = {
24812+static const struct ata_port_operations cmd648_port_ops = {
24813 .inherits = &cmd64x_base_ops,
24814 .bmdma_stop = cmd648_bmdma_stop,
24815 .cable_detect = cmd648_cable_detect,
24816diff -urNp linux-2.6.32.43/drivers/ata/pata_cs5520.c linux-2.6.32.43/drivers/ata/pata_cs5520.c
24817--- linux-2.6.32.43/drivers/ata/pata_cs5520.c 2011-03-27 14:31:47.000000000 -0400
24818+++ linux-2.6.32.43/drivers/ata/pata_cs5520.c 2011-04-17 15:56:46.000000000 -0400
24819@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_
24820 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24821 };
24822
24823-static struct ata_port_operations cs5520_port_ops = {
24824+static const struct ata_port_operations cs5520_port_ops = {
24825 .inherits = &ata_bmdma_port_ops,
24826 .qc_prep = ata_sff_dumb_qc_prep,
24827 .cable_detect = ata_cable_40wire,
24828diff -urNp linux-2.6.32.43/drivers/ata/pata_cs5530.c linux-2.6.32.43/drivers/ata/pata_cs5530.c
24829--- linux-2.6.32.43/drivers/ata/pata_cs5530.c 2011-03-27 14:31:47.000000000 -0400
24830+++ linux-2.6.32.43/drivers/ata/pata_cs5530.c 2011-04-17 15:56:46.000000000 -0400
24831@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
24832 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24833 };
24834
24835-static struct ata_port_operations cs5530_port_ops = {
24836+static const struct ata_port_operations cs5530_port_ops = {
24837 .inherits = &ata_bmdma_port_ops,
24838
24839 .qc_prep = ata_sff_dumb_qc_prep,
24840diff -urNp linux-2.6.32.43/drivers/ata/pata_cs5535.c linux-2.6.32.43/drivers/ata/pata_cs5535.c
24841--- linux-2.6.32.43/drivers/ata/pata_cs5535.c 2011-03-27 14:31:47.000000000 -0400
24842+++ linux-2.6.32.43/drivers/ata/pata_cs5535.c 2011-04-17 15:56:46.000000000 -0400
24843@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
24844 ATA_BMDMA_SHT(DRV_NAME),
24845 };
24846
24847-static struct ata_port_operations cs5535_port_ops = {
24848+static const struct ata_port_operations cs5535_port_ops = {
24849 .inherits = &ata_bmdma_port_ops,
24850 .cable_detect = cs5535_cable_detect,
24851 .set_piomode = cs5535_set_piomode,
24852diff -urNp linux-2.6.32.43/drivers/ata/pata_cs5536.c linux-2.6.32.43/drivers/ata/pata_cs5536.c
24853--- linux-2.6.32.43/drivers/ata/pata_cs5536.c 2011-03-27 14:31:47.000000000 -0400
24854+++ linux-2.6.32.43/drivers/ata/pata_cs5536.c 2011-04-17 15:56:46.000000000 -0400
24855@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_
24856 ATA_BMDMA_SHT(DRV_NAME),
24857 };
24858
24859-static struct ata_port_operations cs5536_port_ops = {
24860+static const struct ata_port_operations cs5536_port_ops = {
24861 .inherits = &ata_bmdma_port_ops,
24862 .cable_detect = cs5536_cable_detect,
24863 .set_piomode = cs5536_set_piomode,
24864diff -urNp linux-2.6.32.43/drivers/ata/pata_cypress.c linux-2.6.32.43/drivers/ata/pata_cypress.c
24865--- linux-2.6.32.43/drivers/ata/pata_cypress.c 2011-03-27 14:31:47.000000000 -0400
24866+++ linux-2.6.32.43/drivers/ata/pata_cypress.c 2011-04-17 15:56:46.000000000 -0400
24867@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c69
24868 ATA_BMDMA_SHT(DRV_NAME),
24869 };
24870
24871-static struct ata_port_operations cy82c693_port_ops = {
24872+static const struct ata_port_operations cy82c693_port_ops = {
24873 .inherits = &ata_bmdma_port_ops,
24874 .cable_detect = ata_cable_40wire,
24875 .set_piomode = cy82c693_set_piomode,
24876diff -urNp linux-2.6.32.43/drivers/ata/pata_efar.c linux-2.6.32.43/drivers/ata/pata_efar.c
24877--- linux-2.6.32.43/drivers/ata/pata_efar.c 2011-03-27 14:31:47.000000000 -0400
24878+++ linux-2.6.32.43/drivers/ata/pata_efar.c 2011-04-17 15:56:46.000000000 -0400
24879@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sh
24880 ATA_BMDMA_SHT(DRV_NAME),
24881 };
24882
24883-static struct ata_port_operations efar_ops = {
24884+static const struct ata_port_operations efar_ops = {
24885 .inherits = &ata_bmdma_port_ops,
24886 .cable_detect = efar_cable_detect,
24887 .set_piomode = efar_set_piomode,
24888diff -urNp linux-2.6.32.43/drivers/ata/pata_hpt366.c linux-2.6.32.43/drivers/ata/pata_hpt366.c
24889--- linux-2.6.32.43/drivers/ata/pata_hpt366.c 2011-06-25 12:55:34.000000000 -0400
24890+++ linux-2.6.32.43/drivers/ata/pata_hpt366.c 2011-06-25 12:56:37.000000000 -0400
24891@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_
24892 * Configuration for HPT366/68
24893 */
24894
24895-static struct ata_port_operations hpt366_port_ops = {
24896+static const struct ata_port_operations hpt366_port_ops = {
24897 .inherits = &ata_bmdma_port_ops,
24898 .cable_detect = hpt36x_cable_detect,
24899 .mode_filter = hpt366_filter,
24900diff -urNp linux-2.6.32.43/drivers/ata/pata_hpt37x.c linux-2.6.32.43/drivers/ata/pata_hpt37x.c
24901--- linux-2.6.32.43/drivers/ata/pata_hpt37x.c 2011-06-25 12:55:34.000000000 -0400
24902+++ linux-2.6.32.43/drivers/ata/pata_hpt37x.c 2011-06-25 12:56:37.000000000 -0400
24903@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_
24904 * Configuration for HPT370
24905 */
24906
24907-static struct ata_port_operations hpt370_port_ops = {
24908+static const struct ata_port_operations hpt370_port_ops = {
24909 .inherits = &ata_bmdma_port_ops,
24910
24911 .bmdma_stop = hpt370_bmdma_stop,
24912@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370
24913 * Configuration for HPT370A. Close to 370 but less filters
24914 */
24915
24916-static struct ata_port_operations hpt370a_port_ops = {
24917+static const struct ata_port_operations hpt370a_port_ops = {
24918 .inherits = &hpt370_port_ops,
24919 .mode_filter = hpt370a_filter,
24920 };
24921@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370
24922 * and DMA mode setting functionality.
24923 */
24924
24925-static struct ata_port_operations hpt372_port_ops = {
24926+static const struct ata_port_operations hpt372_port_ops = {
24927 .inherits = &ata_bmdma_port_ops,
24928
24929 .bmdma_stop = hpt37x_bmdma_stop,
24930@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372
24931 * but we have a different cable detection procedure for function 1.
24932 */
24933
24934-static struct ata_port_operations hpt374_fn1_port_ops = {
24935+static const struct ata_port_operations hpt374_fn1_port_ops = {
24936 .inherits = &hpt372_port_ops,
24937 .prereset = hpt374_fn1_pre_reset,
24938 };
24939diff -urNp linux-2.6.32.43/drivers/ata/pata_hpt3x2n.c linux-2.6.32.43/drivers/ata/pata_hpt3x2n.c
24940--- linux-2.6.32.43/drivers/ata/pata_hpt3x2n.c 2011-06-25 12:55:34.000000000 -0400
24941+++ linux-2.6.32.43/drivers/ata/pata_hpt3x2n.c 2011-06-25 12:56:37.000000000 -0400
24942@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n
24943 * Configuration for HPT3x2n.
24944 */
24945
24946-static struct ata_port_operations hpt3x2n_port_ops = {
24947+static const struct ata_port_operations hpt3x2n_port_ops = {
24948 .inherits = &ata_bmdma_port_ops,
24949
24950 .bmdma_stop = hpt3x2n_bmdma_stop,
24951diff -urNp linux-2.6.32.43/drivers/ata/pata_hpt3x3.c linux-2.6.32.43/drivers/ata/pata_hpt3x3.c
24952--- linux-2.6.32.43/drivers/ata/pata_hpt3x3.c 2011-03-27 14:31:47.000000000 -0400
24953+++ linux-2.6.32.43/drivers/ata/pata_hpt3x3.c 2011-04-17 15:56:46.000000000 -0400
24954@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
24955 ATA_BMDMA_SHT(DRV_NAME),
24956 };
24957
24958-static struct ata_port_operations hpt3x3_port_ops = {
24959+static const struct ata_port_operations hpt3x3_port_ops = {
24960 .inherits = &ata_bmdma_port_ops,
24961 .cable_detect = ata_cable_40wire,
24962 .set_piomode = hpt3x3_set_piomode,
24963diff -urNp linux-2.6.32.43/drivers/ata/pata_icside.c linux-2.6.32.43/drivers/ata/pata_icside.c
24964--- linux-2.6.32.43/drivers/ata/pata_icside.c 2011-03-27 14:31:47.000000000 -0400
24965+++ linux-2.6.32.43/drivers/ata/pata_icside.c 2011-04-17 15:56:46.000000000 -0400
24966@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct
24967 }
24968 }
24969
24970-static struct ata_port_operations pata_icside_port_ops = {
24971+static const struct ata_port_operations pata_icside_port_ops = {
24972 .inherits = &ata_sff_port_ops,
24973 /* no need to build any PRD tables for DMA */
24974 .qc_prep = ata_noop_qc_prep,
24975diff -urNp linux-2.6.32.43/drivers/ata/pata_isapnp.c linux-2.6.32.43/drivers/ata/pata_isapnp.c
24976--- linux-2.6.32.43/drivers/ata/pata_isapnp.c 2011-03-27 14:31:47.000000000 -0400
24977+++ linux-2.6.32.43/drivers/ata/pata_isapnp.c 2011-04-17 15:56:46.000000000 -0400
24978@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
24979 ATA_PIO_SHT(DRV_NAME),
24980 };
24981
24982-static struct ata_port_operations isapnp_port_ops = {
24983+static const struct ata_port_operations isapnp_port_ops = {
24984 .inherits = &ata_sff_port_ops,
24985 .cable_detect = ata_cable_40wire,
24986 };
24987
24988-static struct ata_port_operations isapnp_noalt_port_ops = {
24989+static const struct ata_port_operations isapnp_noalt_port_ops = {
24990 .inherits = &ata_sff_port_ops,
24991 .cable_detect = ata_cable_40wire,
24992 /* No altstatus so we don't want to use the lost interrupt poll */
24993diff -urNp linux-2.6.32.43/drivers/ata/pata_it8213.c linux-2.6.32.43/drivers/ata/pata_it8213.c
24994--- linux-2.6.32.43/drivers/ata/pata_it8213.c 2011-03-27 14:31:47.000000000 -0400
24995+++ linux-2.6.32.43/drivers/ata/pata_it8213.c 2011-04-17 15:56:46.000000000 -0400
24996@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_
24997 };
24998
24999
25000-static struct ata_port_operations it8213_ops = {
25001+static const struct ata_port_operations it8213_ops = {
25002 .inherits = &ata_bmdma_port_ops,
25003 .cable_detect = it8213_cable_detect,
25004 .set_piomode = it8213_set_piomode,
25005diff -urNp linux-2.6.32.43/drivers/ata/pata_it821x.c linux-2.6.32.43/drivers/ata/pata_it821x.c
25006--- linux-2.6.32.43/drivers/ata/pata_it821x.c 2011-03-27 14:31:47.000000000 -0400
25007+++ linux-2.6.32.43/drivers/ata/pata_it821x.c 2011-04-17 15:56:46.000000000 -0400
25008@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_
25009 ATA_BMDMA_SHT(DRV_NAME),
25010 };
25011
25012-static struct ata_port_operations it821x_smart_port_ops = {
25013+static const struct ata_port_operations it821x_smart_port_ops = {
25014 .inherits = &ata_bmdma_port_ops,
25015
25016 .check_atapi_dma= it821x_check_atapi_dma,
25017@@ -814,7 +814,7 @@ static struct ata_port_operations it821x
25018 .port_start = it821x_port_start,
25019 };
25020
25021-static struct ata_port_operations it821x_passthru_port_ops = {
25022+static const struct ata_port_operations it821x_passthru_port_ops = {
25023 .inherits = &ata_bmdma_port_ops,
25024
25025 .check_atapi_dma= it821x_check_atapi_dma,
25026@@ -830,7 +830,7 @@ static struct ata_port_operations it821x
25027 .port_start = it821x_port_start,
25028 };
25029
25030-static struct ata_port_operations it821x_rdc_port_ops = {
25031+static const struct ata_port_operations it821x_rdc_port_ops = {
25032 .inherits = &ata_bmdma_port_ops,
25033
25034 .check_atapi_dma= it821x_check_atapi_dma,
25035diff -urNp linux-2.6.32.43/drivers/ata/pata_ixp4xx_cf.c linux-2.6.32.43/drivers/ata/pata_ixp4xx_cf.c
25036--- linux-2.6.32.43/drivers/ata/pata_ixp4xx_cf.c 2011-03-27 14:31:47.000000000 -0400
25037+++ linux-2.6.32.43/drivers/ata/pata_ixp4xx_cf.c 2011-04-17 15:56:46.000000000 -0400
25038@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25039 ATA_PIO_SHT(DRV_NAME),
25040 };
25041
25042-static struct ata_port_operations ixp4xx_port_ops = {
25043+static const struct ata_port_operations ixp4xx_port_ops = {
25044 .inherits = &ata_sff_port_ops,
25045 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25046 .cable_detect = ata_cable_40wire,
25047diff -urNp linux-2.6.32.43/drivers/ata/pata_jmicron.c linux-2.6.32.43/drivers/ata/pata_jmicron.c
25048--- linux-2.6.32.43/drivers/ata/pata_jmicron.c 2011-03-27 14:31:47.000000000 -0400
25049+++ linux-2.6.32.43/drivers/ata/pata_jmicron.c 2011-04-17 15:56:46.000000000 -0400
25050@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25051 ATA_BMDMA_SHT(DRV_NAME),
25052 };
25053
25054-static struct ata_port_operations jmicron_ops = {
25055+static const struct ata_port_operations jmicron_ops = {
25056 .inherits = &ata_bmdma_port_ops,
25057 .prereset = jmicron_pre_reset,
25058 };
25059diff -urNp linux-2.6.32.43/drivers/ata/pata_legacy.c linux-2.6.32.43/drivers/ata/pata_legacy.c
25060--- linux-2.6.32.43/drivers/ata/pata_legacy.c 2011-03-27 14:31:47.000000000 -0400
25061+++ linux-2.6.32.43/drivers/ata/pata_legacy.c 2011-04-17 15:56:46.000000000 -0400
25062@@ -106,7 +106,7 @@ struct legacy_probe {
25063
25064 struct legacy_controller {
25065 const char *name;
25066- struct ata_port_operations *ops;
25067+ const struct ata_port_operations *ops;
25068 unsigned int pio_mask;
25069 unsigned int flags;
25070 unsigned int pflags;
25071@@ -223,12 +223,12 @@ static const struct ata_port_operations
25072 * pio_mask as well.
25073 */
25074
25075-static struct ata_port_operations simple_port_ops = {
25076+static const struct ata_port_operations simple_port_ops = {
25077 .inherits = &legacy_base_port_ops,
25078 .sff_data_xfer = ata_sff_data_xfer_noirq,
25079 };
25080
25081-static struct ata_port_operations legacy_port_ops = {
25082+static const struct ata_port_operations legacy_port_ops = {
25083 .inherits = &legacy_base_port_ops,
25084 .sff_data_xfer = ata_sff_data_xfer_noirq,
25085 .set_mode = legacy_set_mode,
25086@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(st
25087 return buflen;
25088 }
25089
25090-static struct ata_port_operations pdc20230_port_ops = {
25091+static const struct ata_port_operations pdc20230_port_ops = {
25092 .inherits = &legacy_base_port_ops,
25093 .set_piomode = pdc20230_set_piomode,
25094 .sff_data_xfer = pdc_data_xfer_vlb,
25095@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct a
25096 ioread8(ap->ioaddr.status_addr);
25097 }
25098
25099-static struct ata_port_operations ht6560a_port_ops = {
25100+static const struct ata_port_operations ht6560a_port_ops = {
25101 .inherits = &legacy_base_port_ops,
25102 .set_piomode = ht6560a_set_piomode,
25103 };
25104@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct a
25105 ioread8(ap->ioaddr.status_addr);
25106 }
25107
25108-static struct ata_port_operations ht6560b_port_ops = {
25109+static const struct ata_port_operations ht6560b_port_ops = {
25110 .inherits = &legacy_base_port_ops,
25111 .set_piomode = ht6560b_set_piomode,
25112 };
25113@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(stru
25114 }
25115
25116
25117-static struct ata_port_operations opti82c611a_port_ops = {
25118+static const struct ata_port_operations opti82c611a_port_ops = {
25119 .inherits = &legacy_base_port_ops,
25120 .set_piomode = opti82c611a_set_piomode,
25121 };
25122@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(
25123 return ata_sff_qc_issue(qc);
25124 }
25125
25126-static struct ata_port_operations opti82c46x_port_ops = {
25127+static const struct ata_port_operations opti82c46x_port_ops = {
25128 .inherits = &legacy_base_port_ops,
25129 .set_piomode = opti82c46x_set_piomode,
25130 .qc_issue = opti82c46x_qc_issue,
25131@@ -771,20 +771,20 @@ static int qdi_port(struct platform_devi
25132 return 0;
25133 }
25134
25135-static struct ata_port_operations qdi6500_port_ops = {
25136+static const struct ata_port_operations qdi6500_port_ops = {
25137 .inherits = &legacy_base_port_ops,
25138 .set_piomode = qdi6500_set_piomode,
25139 .qc_issue = qdi_qc_issue,
25140 .sff_data_xfer = vlb32_data_xfer,
25141 };
25142
25143-static struct ata_port_operations qdi6580_port_ops = {
25144+static const struct ata_port_operations qdi6580_port_ops = {
25145 .inherits = &legacy_base_port_ops,
25146 .set_piomode = qdi6580_set_piomode,
25147 .sff_data_xfer = vlb32_data_xfer,
25148 };
25149
25150-static struct ata_port_operations qdi6580dp_port_ops = {
25151+static const struct ata_port_operations qdi6580dp_port_ops = {
25152 .inherits = &legacy_base_port_ops,
25153 .set_piomode = qdi6580dp_set_piomode,
25154 .sff_data_xfer = vlb32_data_xfer,
25155@@ -855,7 +855,7 @@ static int winbond_port(struct platform_
25156 return 0;
25157 }
25158
25159-static struct ata_port_operations winbond_port_ops = {
25160+static const struct ata_port_operations winbond_port_ops = {
25161 .inherits = &legacy_base_port_ops,
25162 .set_piomode = winbond_set_piomode,
25163 .sff_data_xfer = vlb32_data_xfer,
25164@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct
25165 int pio_modes = controller->pio_mask;
25166 unsigned long io = probe->port;
25167 u32 mask = (1 << probe->slot);
25168- struct ata_port_operations *ops = controller->ops;
25169+ const struct ata_port_operations *ops = controller->ops;
25170 struct legacy_data *ld = &legacy_data[probe->slot];
25171 struct ata_host *host = NULL;
25172 struct ata_port *ap;
25173diff -urNp linux-2.6.32.43/drivers/ata/pata_marvell.c linux-2.6.32.43/drivers/ata/pata_marvell.c
25174--- linux-2.6.32.43/drivers/ata/pata_marvell.c 2011-03-27 14:31:47.000000000 -0400
25175+++ linux-2.6.32.43/drivers/ata/pata_marvell.c 2011-04-17 15:56:46.000000000 -0400
25176@@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25177 ATA_BMDMA_SHT(DRV_NAME),
25178 };
25179
25180-static struct ata_port_operations marvell_ops = {
25181+static const struct ata_port_operations marvell_ops = {
25182 .inherits = &ata_bmdma_port_ops,
25183 .cable_detect = marvell_cable_detect,
25184 .prereset = marvell_pre_reset,
25185diff -urNp linux-2.6.32.43/drivers/ata/pata_mpc52xx.c linux-2.6.32.43/drivers/ata/pata_mpc52xx.c
25186--- linux-2.6.32.43/drivers/ata/pata_mpc52xx.c 2011-03-27 14:31:47.000000000 -0400
25187+++ linux-2.6.32.43/drivers/ata/pata_mpc52xx.c 2011-04-17 15:56:46.000000000 -0400
25188@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25189 ATA_PIO_SHT(DRV_NAME),
25190 };
25191
25192-static struct ata_port_operations mpc52xx_ata_port_ops = {
25193+static const struct ata_port_operations mpc52xx_ata_port_ops = {
25194 .inherits = &ata_bmdma_port_ops,
25195 .sff_dev_select = mpc52xx_ata_dev_select,
25196 .set_piomode = mpc52xx_ata_set_piomode,
25197diff -urNp linux-2.6.32.43/drivers/ata/pata_mpiix.c linux-2.6.32.43/drivers/ata/pata_mpiix.c
25198--- linux-2.6.32.43/drivers/ata/pata_mpiix.c 2011-03-27 14:31:47.000000000 -0400
25199+++ linux-2.6.32.43/drivers/ata/pata_mpiix.c 2011-04-17 15:56:46.000000000 -0400
25200@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25201 ATA_PIO_SHT(DRV_NAME),
25202 };
25203
25204-static struct ata_port_operations mpiix_port_ops = {
25205+static const struct ata_port_operations mpiix_port_ops = {
25206 .inherits = &ata_sff_port_ops,
25207 .qc_issue = mpiix_qc_issue,
25208 .cable_detect = ata_cable_40wire,
25209diff -urNp linux-2.6.32.43/drivers/ata/pata_netcell.c linux-2.6.32.43/drivers/ata/pata_netcell.c
25210--- linux-2.6.32.43/drivers/ata/pata_netcell.c 2011-03-27 14:31:47.000000000 -0400
25211+++ linux-2.6.32.43/drivers/ata/pata_netcell.c 2011-04-17 15:56:46.000000000 -0400
25212@@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25213 ATA_BMDMA_SHT(DRV_NAME),
25214 };
25215
25216-static struct ata_port_operations netcell_ops = {
25217+static const struct ata_port_operations netcell_ops = {
25218 .inherits = &ata_bmdma_port_ops,
25219 .cable_detect = ata_cable_80wire,
25220 .read_id = netcell_read_id,
25221diff -urNp linux-2.6.32.43/drivers/ata/pata_ninja32.c linux-2.6.32.43/drivers/ata/pata_ninja32.c
25222--- linux-2.6.32.43/drivers/ata/pata_ninja32.c 2011-03-27 14:31:47.000000000 -0400
25223+++ linux-2.6.32.43/drivers/ata/pata_ninja32.c 2011-04-17 15:56:46.000000000 -0400
25224@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25225 ATA_BMDMA_SHT(DRV_NAME),
25226 };
25227
25228-static struct ata_port_operations ninja32_port_ops = {
25229+static const struct ata_port_operations ninja32_port_ops = {
25230 .inherits = &ata_bmdma_port_ops,
25231 .sff_dev_select = ninja32_dev_select,
25232 .cable_detect = ata_cable_40wire,
25233diff -urNp linux-2.6.32.43/drivers/ata/pata_ns87410.c linux-2.6.32.43/drivers/ata/pata_ns87410.c
25234--- linux-2.6.32.43/drivers/ata/pata_ns87410.c 2011-03-27 14:31:47.000000000 -0400
25235+++ linux-2.6.32.43/drivers/ata/pata_ns87410.c 2011-04-17 15:56:46.000000000 -0400
25236@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25237 ATA_PIO_SHT(DRV_NAME),
25238 };
25239
25240-static struct ata_port_operations ns87410_port_ops = {
25241+static const struct ata_port_operations ns87410_port_ops = {
25242 .inherits = &ata_sff_port_ops,
25243 .qc_issue = ns87410_qc_issue,
25244 .cable_detect = ata_cable_40wire,
25245diff -urNp linux-2.6.32.43/drivers/ata/pata_ns87415.c linux-2.6.32.43/drivers/ata/pata_ns87415.c
25246--- linux-2.6.32.43/drivers/ata/pata_ns87415.c 2011-03-27 14:31:47.000000000 -0400
25247+++ linux-2.6.32.43/drivers/ata/pata_ns87415.c 2011-04-17 15:56:46.000000000 -0400
25248@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25249 }
25250 #endif /* 87560 SuperIO Support */
25251
25252-static struct ata_port_operations ns87415_pata_ops = {
25253+static const struct ata_port_operations ns87415_pata_ops = {
25254 .inherits = &ata_bmdma_port_ops,
25255
25256 .check_atapi_dma = ns87415_check_atapi_dma,
25257@@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25258 };
25259
25260 #if defined(CONFIG_SUPERIO)
25261-static struct ata_port_operations ns87560_pata_ops = {
25262+static const struct ata_port_operations ns87560_pata_ops = {
25263 .inherits = &ns87415_pata_ops,
25264 .sff_tf_read = ns87560_tf_read,
25265 .sff_check_status = ns87560_check_status,
25266diff -urNp linux-2.6.32.43/drivers/ata/pata_octeon_cf.c linux-2.6.32.43/drivers/ata/pata_octeon_cf.c
25267--- linux-2.6.32.43/drivers/ata/pata_octeon_cf.c 2011-03-27 14:31:47.000000000 -0400
25268+++ linux-2.6.32.43/drivers/ata/pata_octeon_cf.c 2011-04-17 15:56:46.000000000 -0400
25269@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(s
25270 return 0;
25271 }
25272
25273+/* cannot be const */
25274 static struct ata_port_operations octeon_cf_ops = {
25275 .inherits = &ata_sff_port_ops,
25276 .check_atapi_dma = octeon_cf_check_atapi_dma,
25277diff -urNp linux-2.6.32.43/drivers/ata/pata_oldpiix.c linux-2.6.32.43/drivers/ata/pata_oldpiix.c
25278--- linux-2.6.32.43/drivers/ata/pata_oldpiix.c 2011-03-27 14:31:47.000000000 -0400
25279+++ linux-2.6.32.43/drivers/ata/pata_oldpiix.c 2011-04-17 15:56:46.000000000 -0400
25280@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25281 ATA_BMDMA_SHT(DRV_NAME),
25282 };
25283
25284-static struct ata_port_operations oldpiix_pata_ops = {
25285+static const struct ata_port_operations oldpiix_pata_ops = {
25286 .inherits = &ata_bmdma_port_ops,
25287 .qc_issue = oldpiix_qc_issue,
25288 .cable_detect = ata_cable_40wire,
25289diff -urNp linux-2.6.32.43/drivers/ata/pata_opti.c linux-2.6.32.43/drivers/ata/pata_opti.c
25290--- linux-2.6.32.43/drivers/ata/pata_opti.c 2011-03-27 14:31:47.000000000 -0400
25291+++ linux-2.6.32.43/drivers/ata/pata_opti.c 2011-04-17 15:56:46.000000000 -0400
25292@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25293 ATA_PIO_SHT(DRV_NAME),
25294 };
25295
25296-static struct ata_port_operations opti_port_ops = {
25297+static const struct ata_port_operations opti_port_ops = {
25298 .inherits = &ata_sff_port_ops,
25299 .cable_detect = ata_cable_40wire,
25300 .set_piomode = opti_set_piomode,
25301diff -urNp linux-2.6.32.43/drivers/ata/pata_optidma.c linux-2.6.32.43/drivers/ata/pata_optidma.c
25302--- linux-2.6.32.43/drivers/ata/pata_optidma.c 2011-03-27 14:31:47.000000000 -0400
25303+++ linux-2.6.32.43/drivers/ata/pata_optidma.c 2011-04-17 15:56:46.000000000 -0400
25304@@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25305 ATA_BMDMA_SHT(DRV_NAME),
25306 };
25307
25308-static struct ata_port_operations optidma_port_ops = {
25309+static const struct ata_port_operations optidma_port_ops = {
25310 .inherits = &ata_bmdma_port_ops,
25311 .cable_detect = ata_cable_40wire,
25312 .set_piomode = optidma_set_pio_mode,
25313@@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25314 .prereset = optidma_pre_reset,
25315 };
25316
25317-static struct ata_port_operations optiplus_port_ops = {
25318+static const struct ata_port_operations optiplus_port_ops = {
25319 .inherits = &optidma_port_ops,
25320 .set_piomode = optiplus_set_pio_mode,
25321 .set_dmamode = optiplus_set_dma_mode,
25322diff -urNp linux-2.6.32.43/drivers/ata/pata_palmld.c linux-2.6.32.43/drivers/ata/pata_palmld.c
25323--- linux-2.6.32.43/drivers/ata/pata_palmld.c 2011-03-27 14:31:47.000000000 -0400
25324+++ linux-2.6.32.43/drivers/ata/pata_palmld.c 2011-04-17 15:56:46.000000000 -0400
25325@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_
25326 ATA_PIO_SHT(DRV_NAME),
25327 };
25328
25329-static struct ata_port_operations palmld_port_ops = {
25330+static const struct ata_port_operations palmld_port_ops = {
25331 .inherits = &ata_sff_port_ops,
25332 .sff_data_xfer = ata_sff_data_xfer_noirq,
25333 .cable_detect = ata_cable_40wire,
25334diff -urNp linux-2.6.32.43/drivers/ata/pata_pcmcia.c linux-2.6.32.43/drivers/ata/pata_pcmcia.c
25335--- linux-2.6.32.43/drivers/ata/pata_pcmcia.c 2011-03-27 14:31:47.000000000 -0400
25336+++ linux-2.6.32.43/drivers/ata/pata_pcmcia.c 2011-04-17 15:56:46.000000000 -0400
25337@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_
25338 ATA_PIO_SHT(DRV_NAME),
25339 };
25340
25341-static struct ata_port_operations pcmcia_port_ops = {
25342+static const struct ata_port_operations pcmcia_port_ops = {
25343 .inherits = &ata_sff_port_ops,
25344 .sff_data_xfer = ata_sff_data_xfer_noirq,
25345 .cable_detect = ata_cable_40wire,
25346 .set_mode = pcmcia_set_mode,
25347 };
25348
25349-static struct ata_port_operations pcmcia_8bit_port_ops = {
25350+static const struct ata_port_operations pcmcia_8bit_port_ops = {
25351 .inherits = &ata_sff_port_ops,
25352 .sff_data_xfer = ata_data_xfer_8bit,
25353 .cable_detect = ata_cable_40wire,
25354@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia
25355 unsigned long io_base, ctl_base;
25356 void __iomem *io_addr, *ctl_addr;
25357 int n_ports = 1;
25358- struct ata_port_operations *ops = &pcmcia_port_ops;
25359+ const struct ata_port_operations *ops = &pcmcia_port_ops;
25360
25361 info = kzalloc(sizeof(*info), GFP_KERNEL);
25362 if (info == NULL)
25363diff -urNp linux-2.6.32.43/drivers/ata/pata_pdc2027x.c linux-2.6.32.43/drivers/ata/pata_pdc2027x.c
25364--- linux-2.6.32.43/drivers/ata/pata_pdc2027x.c 2011-03-27 14:31:47.000000000 -0400
25365+++ linux-2.6.32.43/drivers/ata/pata_pdc2027x.c 2011-04-17 15:56:46.000000000 -0400
25366@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25367 ATA_BMDMA_SHT(DRV_NAME),
25368 };
25369
25370-static struct ata_port_operations pdc2027x_pata100_ops = {
25371+static const struct ata_port_operations pdc2027x_pata100_ops = {
25372 .inherits = &ata_bmdma_port_ops,
25373 .check_atapi_dma = pdc2027x_check_atapi_dma,
25374 .cable_detect = pdc2027x_cable_detect,
25375 .prereset = pdc2027x_prereset,
25376 };
25377
25378-static struct ata_port_operations pdc2027x_pata133_ops = {
25379+static const struct ata_port_operations pdc2027x_pata133_ops = {
25380 .inherits = &pdc2027x_pata100_ops,
25381 .mode_filter = pdc2027x_mode_filter,
25382 .set_piomode = pdc2027x_set_piomode,
25383diff -urNp linux-2.6.32.43/drivers/ata/pata_pdc202xx_old.c linux-2.6.32.43/drivers/ata/pata_pdc202xx_old.c
25384--- linux-2.6.32.43/drivers/ata/pata_pdc202xx_old.c 2011-03-27 14:31:47.000000000 -0400
25385+++ linux-2.6.32.43/drivers/ata/pata_pdc202xx_old.c 2011-04-17 15:56:46.000000000 -0400
25386@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202x
25387 ATA_BMDMA_SHT(DRV_NAME),
25388 };
25389
25390-static struct ata_port_operations pdc2024x_port_ops = {
25391+static const struct ata_port_operations pdc2024x_port_ops = {
25392 .inherits = &ata_bmdma_port_ops,
25393
25394 .cable_detect = ata_cable_40wire,
25395@@ -284,7 +284,7 @@ static struct ata_port_operations pdc202
25396 .sff_exec_command = pdc202xx_exec_command,
25397 };
25398
25399-static struct ata_port_operations pdc2026x_port_ops = {
25400+static const struct ata_port_operations pdc2026x_port_ops = {
25401 .inherits = &pdc2024x_port_ops,
25402
25403 .check_atapi_dma = pdc2026x_check_atapi_dma,
25404diff -urNp linux-2.6.32.43/drivers/ata/pata_platform.c linux-2.6.32.43/drivers/ata/pata_platform.c
25405--- linux-2.6.32.43/drivers/ata/pata_platform.c 2011-03-27 14:31:47.000000000 -0400
25406+++ linux-2.6.32.43/drivers/ata/pata_platform.c 2011-04-17 15:56:46.000000000 -0400
25407@@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25408 ATA_PIO_SHT(DRV_NAME),
25409 };
25410
25411-static struct ata_port_operations pata_platform_port_ops = {
25412+static const struct ata_port_operations pata_platform_port_ops = {
25413 .inherits = &ata_sff_port_ops,
25414 .sff_data_xfer = ata_sff_data_xfer_noirq,
25415 .cable_detect = ata_cable_unknown,
25416diff -urNp linux-2.6.32.43/drivers/ata/pata_qdi.c linux-2.6.32.43/drivers/ata/pata_qdi.c
25417--- linux-2.6.32.43/drivers/ata/pata_qdi.c 2011-03-27 14:31:47.000000000 -0400
25418+++ linux-2.6.32.43/drivers/ata/pata_qdi.c 2011-04-17 15:56:46.000000000 -0400
25419@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25420 ATA_PIO_SHT(DRV_NAME),
25421 };
25422
25423-static struct ata_port_operations qdi6500_port_ops = {
25424+static const struct ata_port_operations qdi6500_port_ops = {
25425 .inherits = &ata_sff_port_ops,
25426 .qc_issue = qdi_qc_issue,
25427 .sff_data_xfer = qdi_data_xfer,
25428@@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
25429 .set_piomode = qdi6500_set_piomode,
25430 };
25431
25432-static struct ata_port_operations qdi6580_port_ops = {
25433+static const struct ata_port_operations qdi6580_port_ops = {
25434 .inherits = &qdi6500_port_ops,
25435 .set_piomode = qdi6580_set_piomode,
25436 };
25437diff -urNp linux-2.6.32.43/drivers/ata/pata_radisys.c linux-2.6.32.43/drivers/ata/pata_radisys.c
25438--- linux-2.6.32.43/drivers/ata/pata_radisys.c 2011-03-27 14:31:47.000000000 -0400
25439+++ linux-2.6.32.43/drivers/ata/pata_radisys.c 2011-04-17 15:56:46.000000000 -0400
25440@@ -187,7 +187,7 @@ static struct scsi_host_template radisys
25441 ATA_BMDMA_SHT(DRV_NAME),
25442 };
25443
25444-static struct ata_port_operations radisys_pata_ops = {
25445+static const struct ata_port_operations radisys_pata_ops = {
25446 .inherits = &ata_bmdma_port_ops,
25447 .qc_issue = radisys_qc_issue,
25448 .cable_detect = ata_cable_unknown,
25449diff -urNp linux-2.6.32.43/drivers/ata/pata_rb532_cf.c linux-2.6.32.43/drivers/ata/pata_rb532_cf.c
25450--- linux-2.6.32.43/drivers/ata/pata_rb532_cf.c 2011-03-27 14:31:47.000000000 -0400
25451+++ linux-2.6.32.43/drivers/ata/pata_rb532_cf.c 2011-04-17 15:56:46.000000000 -0400
25452@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handle
25453 return IRQ_HANDLED;
25454 }
25455
25456-static struct ata_port_operations rb532_pata_port_ops = {
25457+static const struct ata_port_operations rb532_pata_port_ops = {
25458 .inherits = &ata_sff_port_ops,
25459 .sff_data_xfer = ata_sff_data_xfer32,
25460 };
25461diff -urNp linux-2.6.32.43/drivers/ata/pata_rdc.c linux-2.6.32.43/drivers/ata/pata_rdc.c
25462--- linux-2.6.32.43/drivers/ata/pata_rdc.c 2011-03-27 14:31:47.000000000 -0400
25463+++ linux-2.6.32.43/drivers/ata/pata_rdc.c 2011-04-17 15:56:46.000000000 -0400
25464@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_p
25465 pci_write_config_byte(dev, 0x48, udma_enable);
25466 }
25467
25468-static struct ata_port_operations rdc_pata_ops = {
25469+static const struct ata_port_operations rdc_pata_ops = {
25470 .inherits = &ata_bmdma32_port_ops,
25471 .cable_detect = rdc_pata_cable_detect,
25472 .set_piomode = rdc_set_piomode,
25473diff -urNp linux-2.6.32.43/drivers/ata/pata_rz1000.c linux-2.6.32.43/drivers/ata/pata_rz1000.c
25474--- linux-2.6.32.43/drivers/ata/pata_rz1000.c 2011-03-27 14:31:47.000000000 -0400
25475+++ linux-2.6.32.43/drivers/ata/pata_rz1000.c 2011-04-17 15:56:46.000000000 -0400
25476@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
25477 ATA_PIO_SHT(DRV_NAME),
25478 };
25479
25480-static struct ata_port_operations rz1000_port_ops = {
25481+static const struct ata_port_operations rz1000_port_ops = {
25482 .inherits = &ata_sff_port_ops,
25483 .cable_detect = ata_cable_40wire,
25484 .set_mode = rz1000_set_mode,
25485diff -urNp linux-2.6.32.43/drivers/ata/pata_sc1200.c linux-2.6.32.43/drivers/ata/pata_sc1200.c
25486--- linux-2.6.32.43/drivers/ata/pata_sc1200.c 2011-03-27 14:31:47.000000000 -0400
25487+++ linux-2.6.32.43/drivers/ata/pata_sc1200.c 2011-04-17 15:56:46.000000000 -0400
25488@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
25489 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25490 };
25491
25492-static struct ata_port_operations sc1200_port_ops = {
25493+static const struct ata_port_operations sc1200_port_ops = {
25494 .inherits = &ata_bmdma_port_ops,
25495 .qc_prep = ata_sff_dumb_qc_prep,
25496 .qc_issue = sc1200_qc_issue,
25497diff -urNp linux-2.6.32.43/drivers/ata/pata_scc.c linux-2.6.32.43/drivers/ata/pata_scc.c
25498--- linux-2.6.32.43/drivers/ata/pata_scc.c 2011-03-27 14:31:47.000000000 -0400
25499+++ linux-2.6.32.43/drivers/ata/pata_scc.c 2011-04-17 15:56:46.000000000 -0400
25500@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht
25501 ATA_BMDMA_SHT(DRV_NAME),
25502 };
25503
25504-static struct ata_port_operations scc_pata_ops = {
25505+static const struct ata_port_operations scc_pata_ops = {
25506 .inherits = &ata_bmdma_port_ops,
25507
25508 .set_piomode = scc_set_piomode,
25509diff -urNp linux-2.6.32.43/drivers/ata/pata_sch.c linux-2.6.32.43/drivers/ata/pata_sch.c
25510--- linux-2.6.32.43/drivers/ata/pata_sch.c 2011-03-27 14:31:47.000000000 -0400
25511+++ linux-2.6.32.43/drivers/ata/pata_sch.c 2011-04-17 15:56:46.000000000 -0400
25512@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
25513 ATA_BMDMA_SHT(DRV_NAME),
25514 };
25515
25516-static struct ata_port_operations sch_pata_ops = {
25517+static const struct ata_port_operations sch_pata_ops = {
25518 .inherits = &ata_bmdma_port_ops,
25519 .cable_detect = ata_cable_unknown,
25520 .set_piomode = sch_set_piomode,
25521diff -urNp linux-2.6.32.43/drivers/ata/pata_serverworks.c linux-2.6.32.43/drivers/ata/pata_serverworks.c
25522--- linux-2.6.32.43/drivers/ata/pata_serverworks.c 2011-03-27 14:31:47.000000000 -0400
25523+++ linux-2.6.32.43/drivers/ata/pata_serverworks.c 2011-04-17 15:56:46.000000000 -0400
25524@@ -299,7 +299,7 @@ static struct scsi_host_template serverw
25525 ATA_BMDMA_SHT(DRV_NAME),
25526 };
25527
25528-static struct ata_port_operations serverworks_osb4_port_ops = {
25529+static const struct ata_port_operations serverworks_osb4_port_ops = {
25530 .inherits = &ata_bmdma_port_ops,
25531 .cable_detect = serverworks_cable_detect,
25532 .mode_filter = serverworks_osb4_filter,
25533@@ -307,7 +307,7 @@ static struct ata_port_operations server
25534 .set_dmamode = serverworks_set_dmamode,
25535 };
25536
25537-static struct ata_port_operations serverworks_csb_port_ops = {
25538+static const struct ata_port_operations serverworks_csb_port_ops = {
25539 .inherits = &serverworks_osb4_port_ops,
25540 .mode_filter = serverworks_csb_filter,
25541 };
25542diff -urNp linux-2.6.32.43/drivers/ata/pata_sil680.c linux-2.6.32.43/drivers/ata/pata_sil680.c
25543--- linux-2.6.32.43/drivers/ata/pata_sil680.c 2011-06-25 12:55:34.000000000 -0400
25544+++ linux-2.6.32.43/drivers/ata/pata_sil680.c 2011-06-25 12:56:37.000000000 -0400
25545@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_
25546 ATA_BMDMA_SHT(DRV_NAME),
25547 };
25548
25549-static struct ata_port_operations sil680_port_ops = {
25550+static const struct ata_port_operations sil680_port_ops = {
25551 .inherits = &ata_bmdma32_port_ops,
25552 .cable_detect = sil680_cable_detect,
25553 .set_piomode = sil680_set_piomode,
25554diff -urNp linux-2.6.32.43/drivers/ata/pata_sis.c linux-2.6.32.43/drivers/ata/pata_sis.c
25555--- linux-2.6.32.43/drivers/ata/pata_sis.c 2011-03-27 14:31:47.000000000 -0400
25556+++ linux-2.6.32.43/drivers/ata/pata_sis.c 2011-04-17 15:56:46.000000000 -0400
25557@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
25558 ATA_BMDMA_SHT(DRV_NAME),
25559 };
25560
25561-static struct ata_port_operations sis_133_for_sata_ops = {
25562+static const struct ata_port_operations sis_133_for_sata_ops = {
25563 .inherits = &ata_bmdma_port_ops,
25564 .set_piomode = sis_133_set_piomode,
25565 .set_dmamode = sis_133_set_dmamode,
25566 .cable_detect = sis_133_cable_detect,
25567 };
25568
25569-static struct ata_port_operations sis_base_ops = {
25570+static const struct ata_port_operations sis_base_ops = {
25571 .inherits = &ata_bmdma_port_ops,
25572 .prereset = sis_pre_reset,
25573 };
25574
25575-static struct ata_port_operations sis_133_ops = {
25576+static const struct ata_port_operations sis_133_ops = {
25577 .inherits = &sis_base_ops,
25578 .set_piomode = sis_133_set_piomode,
25579 .set_dmamode = sis_133_set_dmamode,
25580 .cable_detect = sis_133_cable_detect,
25581 };
25582
25583-static struct ata_port_operations sis_133_early_ops = {
25584+static const struct ata_port_operations sis_133_early_ops = {
25585 .inherits = &sis_base_ops,
25586 .set_piomode = sis_100_set_piomode,
25587 .set_dmamode = sis_133_early_set_dmamode,
25588 .cable_detect = sis_66_cable_detect,
25589 };
25590
25591-static struct ata_port_operations sis_100_ops = {
25592+static const struct ata_port_operations sis_100_ops = {
25593 .inherits = &sis_base_ops,
25594 .set_piomode = sis_100_set_piomode,
25595 .set_dmamode = sis_100_set_dmamode,
25596 .cable_detect = sis_66_cable_detect,
25597 };
25598
25599-static struct ata_port_operations sis_66_ops = {
25600+static const struct ata_port_operations sis_66_ops = {
25601 .inherits = &sis_base_ops,
25602 .set_piomode = sis_old_set_piomode,
25603 .set_dmamode = sis_66_set_dmamode,
25604 .cable_detect = sis_66_cable_detect,
25605 };
25606
25607-static struct ata_port_operations sis_old_ops = {
25608+static const struct ata_port_operations sis_old_ops = {
25609 .inherits = &sis_base_ops,
25610 .set_piomode = sis_old_set_piomode,
25611 .set_dmamode = sis_old_set_dmamode,
25612diff -urNp linux-2.6.32.43/drivers/ata/pata_sl82c105.c linux-2.6.32.43/drivers/ata/pata_sl82c105.c
25613--- linux-2.6.32.43/drivers/ata/pata_sl82c105.c 2011-03-27 14:31:47.000000000 -0400
25614+++ linux-2.6.32.43/drivers/ata/pata_sl82c105.c 2011-04-17 15:56:46.000000000 -0400
25615@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c10
25616 ATA_BMDMA_SHT(DRV_NAME),
25617 };
25618
25619-static struct ata_port_operations sl82c105_port_ops = {
25620+static const struct ata_port_operations sl82c105_port_ops = {
25621 .inherits = &ata_bmdma_port_ops,
25622 .qc_defer = sl82c105_qc_defer,
25623 .bmdma_start = sl82c105_bmdma_start,
25624diff -urNp linux-2.6.32.43/drivers/ata/pata_triflex.c linux-2.6.32.43/drivers/ata/pata_triflex.c
25625--- linux-2.6.32.43/drivers/ata/pata_triflex.c 2011-03-27 14:31:47.000000000 -0400
25626+++ linux-2.6.32.43/drivers/ata/pata_triflex.c 2011-04-17 15:56:46.000000000 -0400
25627@@ -178,7 +178,7 @@ static struct scsi_host_template triflex
25628 ATA_BMDMA_SHT(DRV_NAME),
25629 };
25630
25631-static struct ata_port_operations triflex_port_ops = {
25632+static const struct ata_port_operations triflex_port_ops = {
25633 .inherits = &ata_bmdma_port_ops,
25634 .bmdma_start = triflex_bmdma_start,
25635 .bmdma_stop = triflex_bmdma_stop,
25636diff -urNp linux-2.6.32.43/drivers/ata/pata_via.c linux-2.6.32.43/drivers/ata/pata_via.c
25637--- linux-2.6.32.43/drivers/ata/pata_via.c 2011-03-27 14:31:47.000000000 -0400
25638+++ linux-2.6.32.43/drivers/ata/pata_via.c 2011-04-17 15:56:46.000000000 -0400
25639@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht
25640 ATA_BMDMA_SHT(DRV_NAME),
25641 };
25642
25643-static struct ata_port_operations via_port_ops = {
25644+static const struct ata_port_operations via_port_ops = {
25645 .inherits = &ata_bmdma_port_ops,
25646 .cable_detect = via_cable_detect,
25647 .set_piomode = via_set_piomode,
25648@@ -429,7 +429,7 @@ static struct ata_port_operations via_po
25649 .port_start = via_port_start,
25650 };
25651
25652-static struct ata_port_operations via_port_ops_noirq = {
25653+static const struct ata_port_operations via_port_ops_noirq = {
25654 .inherits = &via_port_ops,
25655 .sff_data_xfer = ata_sff_data_xfer_noirq,
25656 };
25657diff -urNp linux-2.6.32.43/drivers/ata/pata_winbond.c linux-2.6.32.43/drivers/ata/pata_winbond.c
25658--- linux-2.6.32.43/drivers/ata/pata_winbond.c 2011-03-27 14:31:47.000000000 -0400
25659+++ linux-2.6.32.43/drivers/ata/pata_winbond.c 2011-04-17 15:56:46.000000000 -0400
25660@@ -125,7 +125,7 @@ static struct scsi_host_template winbond
25661 ATA_PIO_SHT(DRV_NAME),
25662 };
25663
25664-static struct ata_port_operations winbond_port_ops = {
25665+static const struct ata_port_operations winbond_port_ops = {
25666 .inherits = &ata_sff_port_ops,
25667 .sff_data_xfer = winbond_data_xfer,
25668 .cable_detect = ata_cable_40wire,
25669diff -urNp linux-2.6.32.43/drivers/ata/pdc_adma.c linux-2.6.32.43/drivers/ata/pdc_adma.c
25670--- linux-2.6.32.43/drivers/ata/pdc_adma.c 2011-03-27 14:31:47.000000000 -0400
25671+++ linux-2.6.32.43/drivers/ata/pdc_adma.c 2011-04-17 15:56:46.000000000 -0400
25672@@ -145,7 +145,7 @@ static struct scsi_host_template adma_at
25673 .dma_boundary = ADMA_DMA_BOUNDARY,
25674 };
25675
25676-static struct ata_port_operations adma_ata_ops = {
25677+static const struct ata_port_operations adma_ata_ops = {
25678 .inherits = &ata_sff_port_ops,
25679
25680 .lost_interrupt = ATA_OP_NULL,
25681diff -urNp linux-2.6.32.43/drivers/ata/sata_fsl.c linux-2.6.32.43/drivers/ata/sata_fsl.c
25682--- linux-2.6.32.43/drivers/ata/sata_fsl.c 2011-03-27 14:31:47.000000000 -0400
25683+++ linux-2.6.32.43/drivers/ata/sata_fsl.c 2011-04-17 15:56:46.000000000 -0400
25684@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fs
25685 .dma_boundary = ATA_DMA_BOUNDARY,
25686 };
25687
25688-static struct ata_port_operations sata_fsl_ops = {
25689+static const struct ata_port_operations sata_fsl_ops = {
25690 .inherits = &sata_pmp_port_ops,
25691
25692 .qc_defer = ata_std_qc_defer,
25693diff -urNp linux-2.6.32.43/drivers/ata/sata_inic162x.c linux-2.6.32.43/drivers/ata/sata_inic162x.c
25694--- linux-2.6.32.43/drivers/ata/sata_inic162x.c 2011-03-27 14:31:47.000000000 -0400
25695+++ linux-2.6.32.43/drivers/ata/sata_inic162x.c 2011-04-17 15:56:46.000000000 -0400
25696@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_po
25697 return 0;
25698 }
25699
25700-static struct ata_port_operations inic_port_ops = {
25701+static const struct ata_port_operations inic_port_ops = {
25702 .inherits = &sata_port_ops,
25703
25704 .check_atapi_dma = inic_check_atapi_dma,
25705diff -urNp linux-2.6.32.43/drivers/ata/sata_mv.c linux-2.6.32.43/drivers/ata/sata_mv.c
25706--- linux-2.6.32.43/drivers/ata/sata_mv.c 2011-03-27 14:31:47.000000000 -0400
25707+++ linux-2.6.32.43/drivers/ata/sata_mv.c 2011-04-17 15:56:46.000000000 -0400
25708@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht
25709 .dma_boundary = MV_DMA_BOUNDARY,
25710 };
25711
25712-static struct ata_port_operations mv5_ops = {
25713+static const struct ata_port_operations mv5_ops = {
25714 .inherits = &ata_sff_port_ops,
25715
25716 .lost_interrupt = ATA_OP_NULL,
25717@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_op
25718 .port_stop = mv_port_stop,
25719 };
25720
25721-static struct ata_port_operations mv6_ops = {
25722+static const struct ata_port_operations mv6_ops = {
25723 .inherits = &mv5_ops,
25724 .dev_config = mv6_dev_config,
25725 .scr_read = mv_scr_read,
25726@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_op
25727 .bmdma_status = mv_bmdma_status,
25728 };
25729
25730-static struct ata_port_operations mv_iie_ops = {
25731+static const struct ata_port_operations mv_iie_ops = {
25732 .inherits = &mv6_ops,
25733 .dev_config = ATA_OP_NULL,
25734 .qc_prep = mv_qc_prep_iie,
25735diff -urNp linux-2.6.32.43/drivers/ata/sata_nv.c linux-2.6.32.43/drivers/ata/sata_nv.c
25736--- linux-2.6.32.43/drivers/ata/sata_nv.c 2011-03-27 14:31:47.000000000 -0400
25737+++ linux-2.6.32.43/drivers/ata/sata_nv.c 2011-04-17 15:56:46.000000000 -0400
25738@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swnc
25739 * cases. Define nv_hardreset() which only kicks in for post-boot
25740 * probing and use it for all variants.
25741 */
25742-static struct ata_port_operations nv_generic_ops = {
25743+static const struct ata_port_operations nv_generic_ops = {
25744 .inherits = &ata_bmdma_port_ops,
25745 .lost_interrupt = ATA_OP_NULL,
25746 .scr_read = nv_scr_read,
25747@@ -472,20 +472,20 @@ static struct ata_port_operations nv_gen
25748 .hardreset = nv_hardreset,
25749 };
25750
25751-static struct ata_port_operations nv_nf2_ops = {
25752+static const struct ata_port_operations nv_nf2_ops = {
25753 .inherits = &nv_generic_ops,
25754 .freeze = nv_nf2_freeze,
25755 .thaw = nv_nf2_thaw,
25756 };
25757
25758-static struct ata_port_operations nv_ck804_ops = {
25759+static const struct ata_port_operations nv_ck804_ops = {
25760 .inherits = &nv_generic_ops,
25761 .freeze = nv_ck804_freeze,
25762 .thaw = nv_ck804_thaw,
25763 .host_stop = nv_ck804_host_stop,
25764 };
25765
25766-static struct ata_port_operations nv_adma_ops = {
25767+static const struct ata_port_operations nv_adma_ops = {
25768 .inherits = &nv_ck804_ops,
25769
25770 .check_atapi_dma = nv_adma_check_atapi_dma,
25771@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adm
25772 .host_stop = nv_adma_host_stop,
25773 };
25774
25775-static struct ata_port_operations nv_swncq_ops = {
25776+static const struct ata_port_operations nv_swncq_ops = {
25777 .inherits = &nv_generic_ops,
25778
25779 .qc_defer = ata_std_qc_defer,
25780diff -urNp linux-2.6.32.43/drivers/ata/sata_promise.c linux-2.6.32.43/drivers/ata/sata_promise.c
25781--- linux-2.6.32.43/drivers/ata/sata_promise.c 2011-03-27 14:31:47.000000000 -0400
25782+++ linux-2.6.32.43/drivers/ata/sata_promise.c 2011-04-17 15:56:46.000000000 -0400
25783@@ -195,7 +195,7 @@ static const struct ata_port_operations
25784 .error_handler = pdc_error_handler,
25785 };
25786
25787-static struct ata_port_operations pdc_sata_ops = {
25788+static const struct ata_port_operations pdc_sata_ops = {
25789 .inherits = &pdc_common_ops,
25790 .cable_detect = pdc_sata_cable_detect,
25791 .freeze = pdc_sata_freeze,
25792@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sa
25793
25794 /* First-generation chips need a more restrictive ->check_atapi_dma op,
25795 and ->freeze/thaw that ignore the hotplug controls. */
25796-static struct ata_port_operations pdc_old_sata_ops = {
25797+static const struct ata_port_operations pdc_old_sata_ops = {
25798 .inherits = &pdc_sata_ops,
25799 .freeze = pdc_freeze,
25800 .thaw = pdc_thaw,
25801 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
25802 };
25803
25804-static struct ata_port_operations pdc_pata_ops = {
25805+static const struct ata_port_operations pdc_pata_ops = {
25806 .inherits = &pdc_common_ops,
25807 .cable_detect = pdc_pata_cable_detect,
25808 .freeze = pdc_freeze,
25809diff -urNp linux-2.6.32.43/drivers/ata/sata_qstor.c linux-2.6.32.43/drivers/ata/sata_qstor.c
25810--- linux-2.6.32.43/drivers/ata/sata_qstor.c 2011-03-27 14:31:47.000000000 -0400
25811+++ linux-2.6.32.43/drivers/ata/sata_qstor.c 2011-04-17 15:56:46.000000000 -0400
25812@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_
25813 .dma_boundary = QS_DMA_BOUNDARY,
25814 };
25815
25816-static struct ata_port_operations qs_ata_ops = {
25817+static const struct ata_port_operations qs_ata_ops = {
25818 .inherits = &ata_sff_port_ops,
25819
25820 .check_atapi_dma = qs_check_atapi_dma,
25821diff -urNp linux-2.6.32.43/drivers/ata/sata_sil24.c linux-2.6.32.43/drivers/ata/sata_sil24.c
25822--- linux-2.6.32.43/drivers/ata/sata_sil24.c 2011-03-27 14:31:47.000000000 -0400
25823+++ linux-2.6.32.43/drivers/ata/sata_sil24.c 2011-04-17 15:56:46.000000000 -0400
25824@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
25825 .dma_boundary = ATA_DMA_BOUNDARY,
25826 };
25827
25828-static struct ata_port_operations sil24_ops = {
25829+static const struct ata_port_operations sil24_ops = {
25830 .inherits = &sata_pmp_port_ops,
25831
25832 .qc_defer = sil24_qc_defer,
25833diff -urNp linux-2.6.32.43/drivers/ata/sata_sil.c linux-2.6.32.43/drivers/ata/sata_sil.c
25834--- linux-2.6.32.43/drivers/ata/sata_sil.c 2011-03-27 14:31:47.000000000 -0400
25835+++ linux-2.6.32.43/drivers/ata/sata_sil.c 2011-04-17 15:56:46.000000000 -0400
25836@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht
25837 .sg_tablesize = ATA_MAX_PRD
25838 };
25839
25840-static struct ata_port_operations sil_ops = {
25841+static const struct ata_port_operations sil_ops = {
25842 .inherits = &ata_bmdma32_port_ops,
25843 .dev_config = sil_dev_config,
25844 .set_mode = sil_set_mode,
25845diff -urNp linux-2.6.32.43/drivers/ata/sata_sis.c linux-2.6.32.43/drivers/ata/sata_sis.c
25846--- linux-2.6.32.43/drivers/ata/sata_sis.c 2011-03-27 14:31:47.000000000 -0400
25847+++ linux-2.6.32.43/drivers/ata/sata_sis.c 2011-04-17 15:56:46.000000000 -0400
25848@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
25849 ATA_BMDMA_SHT(DRV_NAME),
25850 };
25851
25852-static struct ata_port_operations sis_ops = {
25853+static const struct ata_port_operations sis_ops = {
25854 .inherits = &ata_bmdma_port_ops,
25855 .scr_read = sis_scr_read,
25856 .scr_write = sis_scr_write,
25857diff -urNp linux-2.6.32.43/drivers/ata/sata_svw.c linux-2.6.32.43/drivers/ata/sata_svw.c
25858--- linux-2.6.32.43/drivers/ata/sata_svw.c 2011-03-27 14:31:47.000000000 -0400
25859+++ linux-2.6.32.43/drivers/ata/sata_svw.c 2011-04-17 15:56:46.000000000 -0400
25860@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
25861 };
25862
25863
25864-static struct ata_port_operations k2_sata_ops = {
25865+static const struct ata_port_operations k2_sata_ops = {
25866 .inherits = &ata_bmdma_port_ops,
25867 .sff_tf_load = k2_sata_tf_load,
25868 .sff_tf_read = k2_sata_tf_read,
25869diff -urNp linux-2.6.32.43/drivers/ata/sata_sx4.c linux-2.6.32.43/drivers/ata/sata_sx4.c
25870--- linux-2.6.32.43/drivers/ata/sata_sx4.c 2011-03-27 14:31:47.000000000 -0400
25871+++ linux-2.6.32.43/drivers/ata/sata_sx4.c 2011-04-17 15:56:46.000000000 -0400
25872@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sat
25873 };
25874
25875 /* TODO: inherit from base port_ops after converting to new EH */
25876-static struct ata_port_operations pdc_20621_ops = {
25877+static const struct ata_port_operations pdc_20621_ops = {
25878 .inherits = &ata_sff_port_ops,
25879
25880 .check_atapi_dma = pdc_check_atapi_dma,
25881diff -urNp linux-2.6.32.43/drivers/ata/sata_uli.c linux-2.6.32.43/drivers/ata/sata_uli.c
25882--- linux-2.6.32.43/drivers/ata/sata_uli.c 2011-03-27 14:31:47.000000000 -0400
25883+++ linux-2.6.32.43/drivers/ata/sata_uli.c 2011-04-17 15:56:46.000000000 -0400
25884@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht
25885 ATA_BMDMA_SHT(DRV_NAME),
25886 };
25887
25888-static struct ata_port_operations uli_ops = {
25889+static const struct ata_port_operations uli_ops = {
25890 .inherits = &ata_bmdma_port_ops,
25891 .scr_read = uli_scr_read,
25892 .scr_write = uli_scr_write,
25893diff -urNp linux-2.6.32.43/drivers/ata/sata_via.c linux-2.6.32.43/drivers/ata/sata_via.c
25894--- linux-2.6.32.43/drivers/ata/sata_via.c 2011-05-10 22:12:01.000000000 -0400
25895+++ linux-2.6.32.43/drivers/ata/sata_via.c 2011-05-10 22:15:08.000000000 -0400
25896@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
25897 ATA_BMDMA_SHT(DRV_NAME),
25898 };
25899
25900-static struct ata_port_operations svia_base_ops = {
25901+static const struct ata_port_operations svia_base_ops = {
25902 .inherits = &ata_bmdma_port_ops,
25903 .sff_tf_load = svia_tf_load,
25904 };
25905
25906-static struct ata_port_operations vt6420_sata_ops = {
25907+static const struct ata_port_operations vt6420_sata_ops = {
25908 .inherits = &svia_base_ops,
25909 .freeze = svia_noop_freeze,
25910 .prereset = vt6420_prereset,
25911 .bmdma_start = vt6420_bmdma_start,
25912 };
25913
25914-static struct ata_port_operations vt6421_pata_ops = {
25915+static const struct ata_port_operations vt6421_pata_ops = {
25916 .inherits = &svia_base_ops,
25917 .cable_detect = vt6421_pata_cable_detect,
25918 .set_piomode = vt6421_set_pio_mode,
25919 .set_dmamode = vt6421_set_dma_mode,
25920 };
25921
25922-static struct ata_port_operations vt6421_sata_ops = {
25923+static const struct ata_port_operations vt6421_sata_ops = {
25924 .inherits = &svia_base_ops,
25925 .scr_read = svia_scr_read,
25926 .scr_write = svia_scr_write,
25927 };
25928
25929-static struct ata_port_operations vt8251_ops = {
25930+static const struct ata_port_operations vt8251_ops = {
25931 .inherits = &svia_base_ops,
25932 .hardreset = sata_std_hardreset,
25933 .scr_read = vt8251_scr_read,
25934diff -urNp linux-2.6.32.43/drivers/ata/sata_vsc.c linux-2.6.32.43/drivers/ata/sata_vsc.c
25935--- linux-2.6.32.43/drivers/ata/sata_vsc.c 2011-03-27 14:31:47.000000000 -0400
25936+++ linux-2.6.32.43/drivers/ata/sata_vsc.c 2011-04-17 15:56:46.000000000 -0400
25937@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sat
25938 };
25939
25940
25941-static struct ata_port_operations vsc_sata_ops = {
25942+static const struct ata_port_operations vsc_sata_ops = {
25943 .inherits = &ata_bmdma_port_ops,
25944 /* The IRQ handling is not quite standard SFF behaviour so we
25945 cannot use the default lost interrupt handler */
25946diff -urNp linux-2.6.32.43/drivers/atm/adummy.c linux-2.6.32.43/drivers/atm/adummy.c
25947--- linux-2.6.32.43/drivers/atm/adummy.c 2011-03-27 14:31:47.000000000 -0400
25948+++ linux-2.6.32.43/drivers/atm/adummy.c 2011-04-17 15:56:46.000000000 -0400
25949@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct
25950 vcc->pop(vcc, skb);
25951 else
25952 dev_kfree_skb_any(skb);
25953- atomic_inc(&vcc->stats->tx);
25954+ atomic_inc_unchecked(&vcc->stats->tx);
25955
25956 return 0;
25957 }
25958diff -urNp linux-2.6.32.43/drivers/atm/ambassador.c linux-2.6.32.43/drivers/atm/ambassador.c
25959--- linux-2.6.32.43/drivers/atm/ambassador.c 2011-03-27 14:31:47.000000000 -0400
25960+++ linux-2.6.32.43/drivers/atm/ambassador.c 2011-04-17 15:56:46.000000000 -0400
25961@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev,
25962 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25963
25964 // VC layer stats
25965- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25966+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25967
25968 // free the descriptor
25969 kfree (tx_descr);
25970@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev,
25971 dump_skb ("<<<", vc, skb);
25972
25973 // VC layer stats
25974- atomic_inc(&atm_vcc->stats->rx);
25975+ atomic_inc_unchecked(&atm_vcc->stats->rx);
25976 __net_timestamp(skb);
25977 // end of our responsability
25978 atm_vcc->push (atm_vcc, skb);
25979@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev,
25980 } else {
25981 PRINTK (KERN_INFO, "dropped over-size frame");
25982 // should we count this?
25983- atomic_inc(&atm_vcc->stats->rx_drop);
25984+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25985 }
25986
25987 } else {
25988@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * at
25989 }
25990
25991 if (check_area (skb->data, skb->len)) {
25992- atomic_inc(&atm_vcc->stats->tx_err);
25993+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25994 return -ENOMEM; // ?
25995 }
25996
25997diff -urNp linux-2.6.32.43/drivers/atm/atmtcp.c linux-2.6.32.43/drivers/atm/atmtcp.c
25998--- linux-2.6.32.43/drivers/atm/atmtcp.c 2011-03-27 14:31:47.000000000 -0400
25999+++ linux-2.6.32.43/drivers/atm/atmtcp.c 2011-04-17 15:56:46.000000000 -0400
26000@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc
26001 if (vcc->pop) vcc->pop(vcc,skb);
26002 else dev_kfree_skb(skb);
26003 if (dev_data) return 0;
26004- atomic_inc(&vcc->stats->tx_err);
26005+ atomic_inc_unchecked(&vcc->stats->tx_err);
26006 return -ENOLINK;
26007 }
26008 size = skb->len+sizeof(struct atmtcp_hdr);
26009@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc
26010 if (!new_skb) {
26011 if (vcc->pop) vcc->pop(vcc,skb);
26012 else dev_kfree_skb(skb);
26013- atomic_inc(&vcc->stats->tx_err);
26014+ atomic_inc_unchecked(&vcc->stats->tx_err);
26015 return -ENOBUFS;
26016 }
26017 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26018@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc
26019 if (vcc->pop) vcc->pop(vcc,skb);
26020 else dev_kfree_skb(skb);
26021 out_vcc->push(out_vcc,new_skb);
26022- atomic_inc(&vcc->stats->tx);
26023- atomic_inc(&out_vcc->stats->rx);
26024+ atomic_inc_unchecked(&vcc->stats->tx);
26025+ atomic_inc_unchecked(&out_vcc->stats->rx);
26026 return 0;
26027 }
26028
26029@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc
26030 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26031 read_unlock(&vcc_sklist_lock);
26032 if (!out_vcc) {
26033- atomic_inc(&vcc->stats->tx_err);
26034+ atomic_inc_unchecked(&vcc->stats->tx_err);
26035 goto done;
26036 }
26037 skb_pull(skb,sizeof(struct atmtcp_hdr));
26038@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc
26039 __net_timestamp(new_skb);
26040 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26041 out_vcc->push(out_vcc,new_skb);
26042- atomic_inc(&vcc->stats->tx);
26043- atomic_inc(&out_vcc->stats->rx);
26044+ atomic_inc_unchecked(&vcc->stats->tx);
26045+ atomic_inc_unchecked(&out_vcc->stats->rx);
26046 done:
26047 if (vcc->pop) vcc->pop(vcc,skb);
26048 else dev_kfree_skb(skb);
26049diff -urNp linux-2.6.32.43/drivers/atm/eni.c linux-2.6.32.43/drivers/atm/eni.c
26050--- linux-2.6.32.43/drivers/atm/eni.c 2011-03-27 14:31:47.000000000 -0400
26051+++ linux-2.6.32.43/drivers/atm/eni.c 2011-04-17 15:56:46.000000000 -0400
26052@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26053 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26054 vcc->dev->number);
26055 length = 0;
26056- atomic_inc(&vcc->stats->rx_err);
26057+ atomic_inc_unchecked(&vcc->stats->rx_err);
26058 }
26059 else {
26060 length = ATM_CELL_SIZE-1; /* no HEC */
26061@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26062 size);
26063 }
26064 eff = length = 0;
26065- atomic_inc(&vcc->stats->rx_err);
26066+ atomic_inc_unchecked(&vcc->stats->rx_err);
26067 }
26068 else {
26069 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26070@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26071 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26072 vcc->dev->number,vcc->vci,length,size << 2,descr);
26073 length = eff = 0;
26074- atomic_inc(&vcc->stats->rx_err);
26075+ atomic_inc_unchecked(&vcc->stats->rx_err);
26076 }
26077 }
26078 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26079@@ -770,7 +770,7 @@ rx_dequeued++;
26080 vcc->push(vcc,skb);
26081 pushed++;
26082 }
26083- atomic_inc(&vcc->stats->rx);
26084+ atomic_inc_unchecked(&vcc->stats->rx);
26085 }
26086 wake_up(&eni_dev->rx_wait);
26087 }
26088@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *d
26089 PCI_DMA_TODEVICE);
26090 if (vcc->pop) vcc->pop(vcc,skb);
26091 else dev_kfree_skb_irq(skb);
26092- atomic_inc(&vcc->stats->tx);
26093+ atomic_inc_unchecked(&vcc->stats->tx);
26094 wake_up(&eni_dev->tx_wait);
26095 dma_complete++;
26096 }
26097diff -urNp linux-2.6.32.43/drivers/atm/firestream.c linux-2.6.32.43/drivers/atm/firestream.c
26098--- linux-2.6.32.43/drivers/atm/firestream.c 2011-03-27 14:31:47.000000000 -0400
26099+++ linux-2.6.32.43/drivers/atm/firestream.c 2011-04-17 15:56:46.000000000 -0400
26100@@ -748,7 +748,7 @@ static void process_txdone_queue (struct
26101 }
26102 }
26103
26104- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26105+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26106
26107 fs_dprintk (FS_DEBUG_TXMEM, "i");
26108 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26109@@ -815,7 +815,7 @@ static void process_incoming (struct fs_
26110 #endif
26111 skb_put (skb, qe->p1 & 0xffff);
26112 ATM_SKB(skb)->vcc = atm_vcc;
26113- atomic_inc(&atm_vcc->stats->rx);
26114+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26115 __net_timestamp(skb);
26116 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26117 atm_vcc->push (atm_vcc, skb);
26118@@ -836,12 +836,12 @@ static void process_incoming (struct fs_
26119 kfree (pe);
26120 }
26121 if (atm_vcc)
26122- atomic_inc(&atm_vcc->stats->rx_drop);
26123+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26124 break;
26125 case 0x1f: /* Reassembly abort: no buffers. */
26126 /* Silently increment error counter. */
26127 if (atm_vcc)
26128- atomic_inc(&atm_vcc->stats->rx_drop);
26129+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26130 break;
26131 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26132 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26133diff -urNp linux-2.6.32.43/drivers/atm/fore200e.c linux-2.6.32.43/drivers/atm/fore200e.c
26134--- linux-2.6.32.43/drivers/atm/fore200e.c 2011-03-27 14:31:47.000000000 -0400
26135+++ linux-2.6.32.43/drivers/atm/fore200e.c 2011-04-17 15:56:46.000000000 -0400
26136@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200
26137 #endif
26138 /* check error condition */
26139 if (*entry->status & STATUS_ERROR)
26140- atomic_inc(&vcc->stats->tx_err);
26141+ atomic_inc_unchecked(&vcc->stats->tx_err);
26142 else
26143- atomic_inc(&vcc->stats->tx);
26144+ atomic_inc_unchecked(&vcc->stats->tx);
26145 }
26146 }
26147
26148@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore2
26149 if (skb == NULL) {
26150 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26151
26152- atomic_inc(&vcc->stats->rx_drop);
26153+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26154 return -ENOMEM;
26155 }
26156
26157@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore2
26158
26159 dev_kfree_skb_any(skb);
26160
26161- atomic_inc(&vcc->stats->rx_drop);
26162+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26163 return -ENOMEM;
26164 }
26165
26166 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26167
26168 vcc->push(vcc, skb);
26169- atomic_inc(&vcc->stats->rx);
26170+ atomic_inc_unchecked(&vcc->stats->rx);
26171
26172 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26173
26174@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200
26175 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26176 fore200e->atm_dev->number,
26177 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26178- atomic_inc(&vcc->stats->rx_err);
26179+ atomic_inc_unchecked(&vcc->stats->rx_err);
26180 }
26181 }
26182
26183@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26184 goto retry_here;
26185 }
26186
26187- atomic_inc(&vcc->stats->tx_err);
26188+ atomic_inc_unchecked(&vcc->stats->tx_err);
26189
26190 fore200e->tx_sat++;
26191 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26192diff -urNp linux-2.6.32.43/drivers/atm/he.c linux-2.6.32.43/drivers/atm/he.c
26193--- linux-2.6.32.43/drivers/atm/he.c 2011-03-27 14:31:47.000000000 -0400
26194+++ linux-2.6.32.43/drivers/atm/he.c 2011-04-17 15:56:46.000000000 -0400
26195@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26196
26197 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26198 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26199- atomic_inc(&vcc->stats->rx_drop);
26200+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26201 goto return_host_buffers;
26202 }
26203
26204@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26205 RBRQ_LEN_ERR(he_dev->rbrq_head)
26206 ? "LEN_ERR" : "",
26207 vcc->vpi, vcc->vci);
26208- atomic_inc(&vcc->stats->rx_err);
26209+ atomic_inc_unchecked(&vcc->stats->rx_err);
26210 goto return_host_buffers;
26211 }
26212
26213@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26214 vcc->push(vcc, skb);
26215 spin_lock(&he_dev->global_lock);
26216
26217- atomic_inc(&vcc->stats->rx);
26218+ atomic_inc_unchecked(&vcc->stats->rx);
26219
26220 return_host_buffers:
26221 ++pdus_assembled;
26222@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26223 tpd->vcc->pop(tpd->vcc, tpd->skb);
26224 else
26225 dev_kfree_skb_any(tpd->skb);
26226- atomic_inc(&tpd->vcc->stats->tx_err);
26227+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26228 }
26229 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26230 return;
26231@@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26232 vcc->pop(vcc, skb);
26233 else
26234 dev_kfree_skb_any(skb);
26235- atomic_inc(&vcc->stats->tx_err);
26236+ atomic_inc_unchecked(&vcc->stats->tx_err);
26237 return -EINVAL;
26238 }
26239
26240@@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26241 vcc->pop(vcc, skb);
26242 else
26243 dev_kfree_skb_any(skb);
26244- atomic_inc(&vcc->stats->tx_err);
26245+ atomic_inc_unchecked(&vcc->stats->tx_err);
26246 return -EINVAL;
26247 }
26248 #endif
26249@@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26250 vcc->pop(vcc, skb);
26251 else
26252 dev_kfree_skb_any(skb);
26253- atomic_inc(&vcc->stats->tx_err);
26254+ atomic_inc_unchecked(&vcc->stats->tx_err);
26255 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26256 return -ENOMEM;
26257 }
26258@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26259 vcc->pop(vcc, skb);
26260 else
26261 dev_kfree_skb_any(skb);
26262- atomic_inc(&vcc->stats->tx_err);
26263+ atomic_inc_unchecked(&vcc->stats->tx_err);
26264 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26265 return -ENOMEM;
26266 }
26267@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26268 __enqueue_tpd(he_dev, tpd, cid);
26269 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26270
26271- atomic_inc(&vcc->stats->tx);
26272+ atomic_inc_unchecked(&vcc->stats->tx);
26273
26274 return 0;
26275 }
26276diff -urNp linux-2.6.32.43/drivers/atm/horizon.c linux-2.6.32.43/drivers/atm/horizon.c
26277--- linux-2.6.32.43/drivers/atm/horizon.c 2011-03-27 14:31:47.000000000 -0400
26278+++ linux-2.6.32.43/drivers/atm/horizon.c 2011-04-17 15:56:46.000000000 -0400
26279@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev,
26280 {
26281 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26282 // VC layer stats
26283- atomic_inc(&vcc->stats->rx);
26284+ atomic_inc_unchecked(&vcc->stats->rx);
26285 __net_timestamp(skb);
26286 // end of our responsability
26287 vcc->push (vcc, skb);
26288@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const
26289 dev->tx_iovec = NULL;
26290
26291 // VC layer stats
26292- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26293+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26294
26295 // free the skb
26296 hrz_kfree_skb (skb);
26297diff -urNp linux-2.6.32.43/drivers/atm/idt77252.c linux-2.6.32.43/drivers/atm/idt77252.c
26298--- linux-2.6.32.43/drivers/atm/idt77252.c 2011-03-27 14:31:47.000000000 -0400
26299+++ linux-2.6.32.43/drivers/atm/idt77252.c 2011-04-17 15:56:46.000000000 -0400
26300@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, str
26301 else
26302 dev_kfree_skb(skb);
26303
26304- atomic_inc(&vcc->stats->tx);
26305+ atomic_inc_unchecked(&vcc->stats->tx);
26306 }
26307
26308 atomic_dec(&scq->used);
26309@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, st
26310 if ((sb = dev_alloc_skb(64)) == NULL) {
26311 printk("%s: Can't allocate buffers for aal0.\n",
26312 card->name);
26313- atomic_add(i, &vcc->stats->rx_drop);
26314+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
26315 break;
26316 }
26317 if (!atm_charge(vcc, sb->truesize)) {
26318 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26319 card->name);
26320- atomic_add(i - 1, &vcc->stats->rx_drop);
26321+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26322 dev_kfree_skb(sb);
26323 break;
26324 }
26325@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, st
26326 ATM_SKB(sb)->vcc = vcc;
26327 __net_timestamp(sb);
26328 vcc->push(vcc, sb);
26329- atomic_inc(&vcc->stats->rx);
26330+ atomic_inc_unchecked(&vcc->stats->rx);
26331
26332 cell += ATM_CELL_PAYLOAD;
26333 }
26334@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, st
26335 "(CDC: %08x)\n",
26336 card->name, len, rpp->len, readl(SAR_REG_CDC));
26337 recycle_rx_pool_skb(card, rpp);
26338- atomic_inc(&vcc->stats->rx_err);
26339+ atomic_inc_unchecked(&vcc->stats->rx_err);
26340 return;
26341 }
26342 if (stat & SAR_RSQE_CRC) {
26343 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26344 recycle_rx_pool_skb(card, rpp);
26345- atomic_inc(&vcc->stats->rx_err);
26346+ atomic_inc_unchecked(&vcc->stats->rx_err);
26347 return;
26348 }
26349 if (skb_queue_len(&rpp->queue) > 1) {
26350@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, st
26351 RXPRINTK("%s: Can't alloc RX skb.\n",
26352 card->name);
26353 recycle_rx_pool_skb(card, rpp);
26354- atomic_inc(&vcc->stats->rx_err);
26355+ atomic_inc_unchecked(&vcc->stats->rx_err);
26356 return;
26357 }
26358 if (!atm_charge(vcc, skb->truesize)) {
26359@@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, st
26360 __net_timestamp(skb);
26361
26362 vcc->push(vcc, skb);
26363- atomic_inc(&vcc->stats->rx);
26364+ atomic_inc_unchecked(&vcc->stats->rx);
26365
26366 return;
26367 }
26368@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, st
26369 __net_timestamp(skb);
26370
26371 vcc->push(vcc, skb);
26372- atomic_inc(&vcc->stats->rx);
26373+ atomic_inc_unchecked(&vcc->stats->rx);
26374
26375 if (skb->truesize > SAR_FB_SIZE_3)
26376 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26377@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26378 if (vcc->qos.aal != ATM_AAL0) {
26379 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26380 card->name, vpi, vci);
26381- atomic_inc(&vcc->stats->rx_drop);
26382+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26383 goto drop;
26384 }
26385
26386 if ((sb = dev_alloc_skb(64)) == NULL) {
26387 printk("%s: Can't allocate buffers for AAL0.\n",
26388 card->name);
26389- atomic_inc(&vcc->stats->rx_err);
26390+ atomic_inc_unchecked(&vcc->stats->rx_err);
26391 goto drop;
26392 }
26393
26394@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26395 ATM_SKB(sb)->vcc = vcc;
26396 __net_timestamp(sb);
26397 vcc->push(vcc, sb);
26398- atomic_inc(&vcc->stats->rx);
26399+ atomic_inc_unchecked(&vcc->stats->rx);
26400
26401 drop:
26402 skb_pull(queue, 64);
26403@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26404
26405 if (vc == NULL) {
26406 printk("%s: NULL connection in send().\n", card->name);
26407- atomic_inc(&vcc->stats->tx_err);
26408+ atomic_inc_unchecked(&vcc->stats->tx_err);
26409 dev_kfree_skb(skb);
26410 return -EINVAL;
26411 }
26412 if (!test_bit(VCF_TX, &vc->flags)) {
26413 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
26414- atomic_inc(&vcc->stats->tx_err);
26415+ atomic_inc_unchecked(&vcc->stats->tx_err);
26416 dev_kfree_skb(skb);
26417 return -EINVAL;
26418 }
26419@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26420 break;
26421 default:
26422 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
26423- atomic_inc(&vcc->stats->tx_err);
26424+ atomic_inc_unchecked(&vcc->stats->tx_err);
26425 dev_kfree_skb(skb);
26426 return -EINVAL;
26427 }
26428
26429 if (skb_shinfo(skb)->nr_frags != 0) {
26430 printk("%s: No scatter-gather yet.\n", card->name);
26431- atomic_inc(&vcc->stats->tx_err);
26432+ atomic_inc_unchecked(&vcc->stats->tx_err);
26433 dev_kfree_skb(skb);
26434 return -EINVAL;
26435 }
26436@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
26437
26438 err = queue_skb(card, vc, skb, oam);
26439 if (err) {
26440- atomic_inc(&vcc->stats->tx_err);
26441+ atomic_inc_unchecked(&vcc->stats->tx_err);
26442 dev_kfree_skb(skb);
26443 return err;
26444 }
26445@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
26446 skb = dev_alloc_skb(64);
26447 if (!skb) {
26448 printk("%s: Out of memory in send_oam().\n", card->name);
26449- atomic_inc(&vcc->stats->tx_err);
26450+ atomic_inc_unchecked(&vcc->stats->tx_err);
26451 return -ENOMEM;
26452 }
26453 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
26454diff -urNp linux-2.6.32.43/drivers/atm/iphase.c linux-2.6.32.43/drivers/atm/iphase.c
26455--- linux-2.6.32.43/drivers/atm/iphase.c 2011-03-27 14:31:47.000000000 -0400
26456+++ linux-2.6.32.43/drivers/atm/iphase.c 2011-04-17 15:56:46.000000000 -0400
26457@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
26458 status = (u_short) (buf_desc_ptr->desc_mode);
26459 if (status & (RX_CER | RX_PTE | RX_OFL))
26460 {
26461- atomic_inc(&vcc->stats->rx_err);
26462+ atomic_inc_unchecked(&vcc->stats->rx_err);
26463 IF_ERR(printk("IA: bad packet, dropping it");)
26464 if (status & RX_CER) {
26465 IF_ERR(printk(" cause: packet CRC error\n");)
26466@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
26467 len = dma_addr - buf_addr;
26468 if (len > iadev->rx_buf_sz) {
26469 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
26470- atomic_inc(&vcc->stats->rx_err);
26471+ atomic_inc_unchecked(&vcc->stats->rx_err);
26472 goto out_free_desc;
26473 }
26474
26475@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *
26476 ia_vcc = INPH_IA_VCC(vcc);
26477 if (ia_vcc == NULL)
26478 {
26479- atomic_inc(&vcc->stats->rx_err);
26480+ atomic_inc_unchecked(&vcc->stats->rx_err);
26481 dev_kfree_skb_any(skb);
26482 atm_return(vcc, atm_guess_pdu2truesize(len));
26483 goto INCR_DLE;
26484@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *
26485 if ((length > iadev->rx_buf_sz) || (length >
26486 (skb->len - sizeof(struct cpcs_trailer))))
26487 {
26488- atomic_inc(&vcc->stats->rx_err);
26489+ atomic_inc_unchecked(&vcc->stats->rx_err);
26490 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
26491 length, skb->len);)
26492 dev_kfree_skb_any(skb);
26493@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *
26494
26495 IF_RX(printk("rx_dle_intr: skb push");)
26496 vcc->push(vcc,skb);
26497- atomic_inc(&vcc->stats->rx);
26498+ atomic_inc_unchecked(&vcc->stats->rx);
26499 iadev->rx_pkt_cnt++;
26500 }
26501 INCR_DLE:
26502@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev,
26503 {
26504 struct k_sonet_stats *stats;
26505 stats = &PRIV(_ia_dev[board])->sonet_stats;
26506- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
26507- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
26508- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
26509- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
26510- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
26511- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
26512- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
26513- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
26514- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
26515+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
26516+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26517+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26518+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26519+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26520+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26521+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26522+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26523+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26524 }
26525 ia_cmds.status = 0;
26526 break;
26527@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
26528 if ((desc == 0) || (desc > iadev->num_tx_desc))
26529 {
26530 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26531- atomic_inc(&vcc->stats->tx);
26532+ atomic_inc_unchecked(&vcc->stats->tx);
26533 if (vcc->pop)
26534 vcc->pop(vcc, skb);
26535 else
26536@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
26537 ATM_DESC(skb) = vcc->vci;
26538 skb_queue_tail(&iadev->tx_dma_q, skb);
26539
26540- atomic_inc(&vcc->stats->tx);
26541+ atomic_inc_unchecked(&vcc->stats->tx);
26542 iadev->tx_pkt_cnt++;
26543 /* Increment transaction counter */
26544 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
26545
26546 #if 0
26547 /* add flow control logic */
26548- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
26549+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
26550 if (iavcc->vc_desc_cnt > 10) {
26551 vcc->tx_quota = vcc->tx_quota * 3 / 4;
26552 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
26553diff -urNp linux-2.6.32.43/drivers/atm/lanai.c linux-2.6.32.43/drivers/atm/lanai.c
26554--- linux-2.6.32.43/drivers/atm/lanai.c 2011-03-27 14:31:47.000000000 -0400
26555+++ linux-2.6.32.43/drivers/atm/lanai.c 2011-04-17 15:56:46.000000000 -0400
26556@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct l
26557 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
26558 lanai_endtx(lanai, lvcc);
26559 lanai_free_skb(lvcc->tx.atmvcc, skb);
26560- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
26561+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
26562 }
26563
26564 /* Try to fill the buffer - don't call unless there is backlog */
26565@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc
26566 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
26567 __net_timestamp(skb);
26568 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
26569- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
26570+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
26571 out:
26572 lvcc->rx.buf.ptr = end;
26573 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
26574@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_d
26575 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
26576 "vcc %d\n", lanai->number, (unsigned int) s, vci);
26577 lanai->stats.service_rxnotaal5++;
26578- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26579+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26580 return 0;
26581 }
26582 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
26583@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_d
26584 int bytes;
26585 read_unlock(&vcc_sklist_lock);
26586 DPRINTK("got trashed rx pdu on vci %d\n", vci);
26587- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26588+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26589 lvcc->stats.x.aal5.service_trash++;
26590 bytes = (SERVICE_GET_END(s) * 16) -
26591 (((unsigned long) lvcc->rx.buf.ptr) -
26592@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_d
26593 }
26594 if (s & SERVICE_STREAM) {
26595 read_unlock(&vcc_sklist_lock);
26596- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26597+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26598 lvcc->stats.x.aal5.service_stream++;
26599 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
26600 "PDU on VCI %d!\n", lanai->number, vci);
26601@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_d
26602 return 0;
26603 }
26604 DPRINTK("got rx crc error on vci %d\n", vci);
26605- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26606+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26607 lvcc->stats.x.aal5.service_rxcrc++;
26608 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
26609 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
26610diff -urNp linux-2.6.32.43/drivers/atm/nicstar.c linux-2.6.32.43/drivers/atm/nicstar.c
26611--- linux-2.6.32.43/drivers/atm/nicstar.c 2011-03-27 14:31:47.000000000 -0400
26612+++ linux-2.6.32.43/drivers/atm/nicstar.c 2011-04-17 15:56:46.000000000 -0400
26613@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc,
26614 if ((vc = (vc_map *) vcc->dev_data) == NULL)
26615 {
26616 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
26617- atomic_inc(&vcc->stats->tx_err);
26618+ atomic_inc_unchecked(&vcc->stats->tx_err);
26619 dev_kfree_skb_any(skb);
26620 return -EINVAL;
26621 }
26622@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc,
26623 if (!vc->tx)
26624 {
26625 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
26626- atomic_inc(&vcc->stats->tx_err);
26627+ atomic_inc_unchecked(&vcc->stats->tx_err);
26628 dev_kfree_skb_any(skb);
26629 return -EINVAL;
26630 }
26631@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc,
26632 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
26633 {
26634 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
26635- atomic_inc(&vcc->stats->tx_err);
26636+ atomic_inc_unchecked(&vcc->stats->tx_err);
26637 dev_kfree_skb_any(skb);
26638 return -EINVAL;
26639 }
26640@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc,
26641 if (skb_shinfo(skb)->nr_frags != 0)
26642 {
26643 printk("nicstar%d: No scatter-gather yet.\n", card->index);
26644- atomic_inc(&vcc->stats->tx_err);
26645+ atomic_inc_unchecked(&vcc->stats->tx_err);
26646 dev_kfree_skb_any(skb);
26647 return -EINVAL;
26648 }
26649@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc,
26650
26651 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
26652 {
26653- atomic_inc(&vcc->stats->tx_err);
26654+ atomic_inc_unchecked(&vcc->stats->tx_err);
26655 dev_kfree_skb_any(skb);
26656 return -EIO;
26657 }
26658- atomic_inc(&vcc->stats->tx);
26659+ atomic_inc_unchecked(&vcc->stats->tx);
26660
26661 return 0;
26662 }
26663@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_
26664 {
26665 printk("nicstar%d: Can't allocate buffers for aal0.\n",
26666 card->index);
26667- atomic_add(i,&vcc->stats->rx_drop);
26668+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
26669 break;
26670 }
26671 if (!atm_charge(vcc, sb->truesize))
26672 {
26673 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
26674 card->index);
26675- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
26676+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
26677 dev_kfree_skb_any(sb);
26678 break;
26679 }
26680@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_
26681 ATM_SKB(sb)->vcc = vcc;
26682 __net_timestamp(sb);
26683 vcc->push(vcc, sb);
26684- atomic_inc(&vcc->stats->rx);
26685+ atomic_inc_unchecked(&vcc->stats->rx);
26686 cell += ATM_CELL_PAYLOAD;
26687 }
26688
26689@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_
26690 if (iovb == NULL)
26691 {
26692 printk("nicstar%d: Out of iovec buffers.\n", card->index);
26693- atomic_inc(&vcc->stats->rx_drop);
26694+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26695 recycle_rx_buf(card, skb);
26696 return;
26697 }
26698@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_
26699 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
26700 {
26701 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26702- atomic_inc(&vcc->stats->rx_err);
26703+ atomic_inc_unchecked(&vcc->stats->rx_err);
26704 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
26705 NS_SKB(iovb)->iovcnt = 0;
26706 iovb->len = 0;
26707@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_
26708 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
26709 card->index);
26710 which_list(card, skb);
26711- atomic_inc(&vcc->stats->rx_err);
26712+ atomic_inc_unchecked(&vcc->stats->rx_err);
26713 recycle_rx_buf(card, skb);
26714 vc->rx_iov = NULL;
26715 recycle_iov_buf(card, iovb);
26716@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_
26717 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
26718 card->index);
26719 which_list(card, skb);
26720- atomic_inc(&vcc->stats->rx_err);
26721+ atomic_inc_unchecked(&vcc->stats->rx_err);
26722 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
26723 NS_SKB(iovb)->iovcnt);
26724 vc->rx_iov = NULL;
26725@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_
26726 printk(" - PDU size mismatch.\n");
26727 else
26728 printk(".\n");
26729- atomic_inc(&vcc->stats->rx_err);
26730+ atomic_inc_unchecked(&vcc->stats->rx_err);
26731 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
26732 NS_SKB(iovb)->iovcnt);
26733 vc->rx_iov = NULL;
26734@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_
26735 if (!atm_charge(vcc, skb->truesize))
26736 {
26737 push_rxbufs(card, skb);
26738- atomic_inc(&vcc->stats->rx_drop);
26739+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26740 }
26741 else
26742 {
26743@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_
26744 ATM_SKB(skb)->vcc = vcc;
26745 __net_timestamp(skb);
26746 vcc->push(vcc, skb);
26747- atomic_inc(&vcc->stats->rx);
26748+ atomic_inc_unchecked(&vcc->stats->rx);
26749 }
26750 }
26751 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
26752@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_
26753 if (!atm_charge(vcc, sb->truesize))
26754 {
26755 push_rxbufs(card, sb);
26756- atomic_inc(&vcc->stats->rx_drop);
26757+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26758 }
26759 else
26760 {
26761@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_
26762 ATM_SKB(sb)->vcc = vcc;
26763 __net_timestamp(sb);
26764 vcc->push(vcc, sb);
26765- atomic_inc(&vcc->stats->rx);
26766+ atomic_inc_unchecked(&vcc->stats->rx);
26767 }
26768
26769 push_rxbufs(card, skb);
26770@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_
26771 if (!atm_charge(vcc, skb->truesize))
26772 {
26773 push_rxbufs(card, skb);
26774- atomic_inc(&vcc->stats->rx_drop);
26775+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26776 }
26777 else
26778 {
26779@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_
26780 ATM_SKB(skb)->vcc = vcc;
26781 __net_timestamp(skb);
26782 vcc->push(vcc, skb);
26783- atomic_inc(&vcc->stats->rx);
26784+ atomic_inc_unchecked(&vcc->stats->rx);
26785 }
26786
26787 push_rxbufs(card, sb);
26788@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_
26789 if (hb == NULL)
26790 {
26791 printk("nicstar%d: Out of huge buffers.\n", card->index);
26792- atomic_inc(&vcc->stats->rx_drop);
26793+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26794 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
26795 NS_SKB(iovb)->iovcnt);
26796 vc->rx_iov = NULL;
26797@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_
26798 }
26799 else
26800 dev_kfree_skb_any(hb);
26801- atomic_inc(&vcc->stats->rx_drop);
26802+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26803 }
26804 else
26805 {
26806@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_
26807 #endif /* NS_USE_DESTRUCTORS */
26808 __net_timestamp(hb);
26809 vcc->push(vcc, hb);
26810- atomic_inc(&vcc->stats->rx);
26811+ atomic_inc_unchecked(&vcc->stats->rx);
26812 }
26813 }
26814
26815diff -urNp linux-2.6.32.43/drivers/atm/solos-pci.c linux-2.6.32.43/drivers/atm/solos-pci.c
26816--- linux-2.6.32.43/drivers/atm/solos-pci.c 2011-04-17 17:00:52.000000000 -0400
26817+++ linux-2.6.32.43/drivers/atm/solos-pci.c 2011-05-16 21:46:57.000000000 -0400
26818@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
26819 }
26820 atm_charge(vcc, skb->truesize);
26821 vcc->push(vcc, skb);
26822- atomic_inc(&vcc->stats->rx);
26823+ atomic_inc_unchecked(&vcc->stats->rx);
26824 break;
26825
26826 case PKT_STATUS:
26827@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *
26828 char msg[500];
26829 char item[10];
26830
26831+ pax_track_stack();
26832+
26833 len = buf->len;
26834 for (i = 0; i < len; i++){
26835 if(i % 8 == 0)
26836@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_car
26837 vcc = SKB_CB(oldskb)->vcc;
26838
26839 if (vcc) {
26840- atomic_inc(&vcc->stats->tx);
26841+ atomic_inc_unchecked(&vcc->stats->tx);
26842 solos_pop(vcc, oldskb);
26843 } else
26844 dev_kfree_skb_irq(oldskb);
26845diff -urNp linux-2.6.32.43/drivers/atm/suni.c linux-2.6.32.43/drivers/atm/suni.c
26846--- linux-2.6.32.43/drivers/atm/suni.c 2011-03-27 14:31:47.000000000 -0400
26847+++ linux-2.6.32.43/drivers/atm/suni.c 2011-04-17 15:56:46.000000000 -0400
26848@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26849
26850
26851 #define ADD_LIMITED(s,v) \
26852- atomic_add((v),&stats->s); \
26853- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26854+ atomic_add_unchecked((v),&stats->s); \
26855+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26856
26857
26858 static void suni_hz(unsigned long from_timer)
26859diff -urNp linux-2.6.32.43/drivers/atm/uPD98402.c linux-2.6.32.43/drivers/atm/uPD98402.c
26860--- linux-2.6.32.43/drivers/atm/uPD98402.c 2011-03-27 14:31:47.000000000 -0400
26861+++ linux-2.6.32.43/drivers/atm/uPD98402.c 2011-04-17 15:56:46.000000000 -0400
26862@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *d
26863 struct sonet_stats tmp;
26864 int error = 0;
26865
26866- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26867+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26868 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26869 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26870 if (zero && !error) {
26871@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev
26872
26873
26874 #define ADD_LIMITED(s,v) \
26875- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26876- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26877- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26878+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26879+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26880+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26881
26882
26883 static void stat_event(struct atm_dev *dev)
26884@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev
26885 if (reason & uPD98402_INT_PFM) stat_event(dev);
26886 if (reason & uPD98402_INT_PCO) {
26887 (void) GET(PCOCR); /* clear interrupt cause */
26888- atomic_add(GET(HECCT),
26889+ atomic_add_unchecked(GET(HECCT),
26890 &PRIV(dev)->sonet_stats.uncorr_hcs);
26891 }
26892 if ((reason & uPD98402_INT_RFO) &&
26893@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev
26894 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26895 uPD98402_INT_LOS),PIMR); /* enable them */
26896 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26897- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26898- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26899- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26900+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26901+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26902+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26903 return 0;
26904 }
26905
26906diff -urNp linux-2.6.32.43/drivers/atm/zatm.c linux-2.6.32.43/drivers/atm/zatm.c
26907--- linux-2.6.32.43/drivers/atm/zatm.c 2011-03-27 14:31:47.000000000 -0400
26908+++ linux-2.6.32.43/drivers/atm/zatm.c 2011-04-17 15:56:46.000000000 -0400
26909@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
26910 }
26911 if (!size) {
26912 dev_kfree_skb_irq(skb);
26913- if (vcc) atomic_inc(&vcc->stats->rx_err);
26914+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26915 continue;
26916 }
26917 if (!atm_charge(vcc,skb->truesize)) {
26918@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
26919 skb->len = size;
26920 ATM_SKB(skb)->vcc = vcc;
26921 vcc->push(vcc,skb);
26922- atomic_inc(&vcc->stats->rx);
26923+ atomic_inc_unchecked(&vcc->stats->rx);
26924 }
26925 zout(pos & 0xffff,MTA(mbx));
26926 #if 0 /* probably a stupid idea */
26927@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
26928 skb_queue_head(&zatm_vcc->backlog,skb);
26929 break;
26930 }
26931- atomic_inc(&vcc->stats->tx);
26932+ atomic_inc_unchecked(&vcc->stats->tx);
26933 wake_up(&zatm_vcc->tx_wait);
26934 }
26935
26936diff -urNp linux-2.6.32.43/drivers/base/bus.c linux-2.6.32.43/drivers/base/bus.c
26937--- linux-2.6.32.43/drivers/base/bus.c 2011-03-27 14:31:47.000000000 -0400
26938+++ linux-2.6.32.43/drivers/base/bus.c 2011-04-17 15:56:46.000000000 -0400
26939@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kob
26940 return ret;
26941 }
26942
26943-static struct sysfs_ops driver_sysfs_ops = {
26944+static const struct sysfs_ops driver_sysfs_ops = {
26945 .show = drv_attr_show,
26946 .store = drv_attr_store,
26947 };
26948@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kob
26949 return ret;
26950 }
26951
26952-static struct sysfs_ops bus_sysfs_ops = {
26953+static const struct sysfs_ops bus_sysfs_ops = {
26954 .show = bus_attr_show,
26955 .store = bus_attr_store,
26956 };
26957@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset
26958 return 0;
26959 }
26960
26961-static struct kset_uevent_ops bus_uevent_ops = {
26962+static const struct kset_uevent_ops bus_uevent_ops = {
26963 .filter = bus_uevent_filter,
26964 };
26965
26966diff -urNp linux-2.6.32.43/drivers/base/class.c linux-2.6.32.43/drivers/base/class.c
26967--- linux-2.6.32.43/drivers/base/class.c 2011-03-27 14:31:47.000000000 -0400
26968+++ linux-2.6.32.43/drivers/base/class.c 2011-04-17 15:56:46.000000000 -0400
26969@@ -63,7 +63,7 @@ static void class_release(struct kobject
26970 kfree(cp);
26971 }
26972
26973-static struct sysfs_ops class_sysfs_ops = {
26974+static const struct sysfs_ops class_sysfs_ops = {
26975 .show = class_attr_show,
26976 .store = class_attr_store,
26977 };
26978diff -urNp linux-2.6.32.43/drivers/base/core.c linux-2.6.32.43/drivers/base/core.c
26979--- linux-2.6.32.43/drivers/base/core.c 2011-03-27 14:31:47.000000000 -0400
26980+++ linux-2.6.32.43/drivers/base/core.c 2011-04-17 15:56:46.000000000 -0400
26981@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kob
26982 return ret;
26983 }
26984
26985-static struct sysfs_ops dev_sysfs_ops = {
26986+static const struct sysfs_ops dev_sysfs_ops = {
26987 .show = dev_attr_show,
26988 .store = dev_attr_store,
26989 };
26990@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset,
26991 return retval;
26992 }
26993
26994-static struct kset_uevent_ops device_uevent_ops = {
26995+static const struct kset_uevent_ops device_uevent_ops = {
26996 .filter = dev_uevent_filter,
26997 .name = dev_uevent_name,
26998 .uevent = dev_uevent,
26999diff -urNp linux-2.6.32.43/drivers/base/memory.c linux-2.6.32.43/drivers/base/memory.c
27000--- linux-2.6.32.43/drivers/base/memory.c 2011-03-27 14:31:47.000000000 -0400
27001+++ linux-2.6.32.43/drivers/base/memory.c 2011-04-17 15:56:46.000000000 -0400
27002@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *ks
27003 return retval;
27004 }
27005
27006-static struct kset_uevent_ops memory_uevent_ops = {
27007+static const struct kset_uevent_ops memory_uevent_ops = {
27008 .name = memory_uevent_name,
27009 .uevent = memory_uevent,
27010 };
27011diff -urNp linux-2.6.32.43/drivers/base/sys.c linux-2.6.32.43/drivers/base/sys.c
27012--- linux-2.6.32.43/drivers/base/sys.c 2011-03-27 14:31:47.000000000 -0400
27013+++ linux-2.6.32.43/drivers/base/sys.c 2011-04-17 15:56:46.000000000 -0400
27014@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struc
27015 return -EIO;
27016 }
27017
27018-static struct sysfs_ops sysfs_ops = {
27019+static const struct sysfs_ops sysfs_ops = {
27020 .show = sysdev_show,
27021 .store = sysdev_store,
27022 };
27023@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct
27024 return -EIO;
27025 }
27026
27027-static struct sysfs_ops sysfs_class_ops = {
27028+static const struct sysfs_ops sysfs_class_ops = {
27029 .show = sysdev_class_show,
27030 .store = sysdev_class_store,
27031 };
27032diff -urNp linux-2.6.32.43/drivers/block/cciss.c linux-2.6.32.43/drivers/block/cciss.c
27033--- linux-2.6.32.43/drivers/block/cciss.c 2011-03-27 14:31:47.000000000 -0400
27034+++ linux-2.6.32.43/drivers/block/cciss.c 2011-08-05 20:33:55.000000000 -0400
27035@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct
27036 int err;
27037 u32 cp;
27038
27039+ memset(&arg64, 0, sizeof(arg64));
27040+
27041 err = 0;
27042 err |=
27043 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27044@@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ct
27045 /* Wait (up to 20 seconds) for a command to complete */
27046
27047 for (i = 20 * HZ; i > 0; i--) {
27048- done = hba[ctlr]->access.command_completed(hba[ctlr]);
27049+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
27050 if (done == FIFO_EMPTY)
27051 schedule_timeout_uninterruptible(1);
27052 else
27053@@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h,
27054 resend_cmd1:
27055
27056 /* Disable interrupt on the board. */
27057- h->access.set_intr_mask(h, CCISS_INTR_OFF);
27058+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
27059
27060 /* Make sure there is room in the command FIFO */
27061 /* Actually it should be completely empty at this time */
27062@@ -2884,13 +2886,13 @@ resend_cmd1:
27063 /* tape side of the driver. */
27064 for (i = 200000; i > 0; i--) {
27065 /* if fifo isn't full go */
27066- if (!(h->access.fifo_full(h)))
27067+ if (!(h->access->fifo_full(h)))
27068 break;
27069 udelay(10);
27070 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
27071 " waiting!\n", h->ctlr);
27072 }
27073- h->access.submit_command(h, c); /* Send the cmd */
27074+ h->access->submit_command(h, c); /* Send the cmd */
27075 do {
27076 complete = pollcomplete(h->ctlr);
27077
27078@@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
27079 while (!hlist_empty(&h->reqQ)) {
27080 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
27081 /* can't do anything if fifo is full */
27082- if ((h->access.fifo_full(h))) {
27083+ if ((h->access->fifo_full(h))) {
27084 printk(KERN_WARNING "cciss: fifo full\n");
27085 break;
27086 }
27087@@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
27088 h->Qdepth--;
27089
27090 /* Tell the controller execute command */
27091- h->access.submit_command(h, c);
27092+ h->access->submit_command(h, c);
27093
27094 /* Put job onto the completed Q */
27095 addQ(&h->cmpQ, c);
27096@@ -3393,17 +3395,17 @@ startio:
27097
27098 static inline unsigned long get_next_completion(ctlr_info_t *h)
27099 {
27100- return h->access.command_completed(h);
27101+ return h->access->command_completed(h);
27102 }
27103
27104 static inline int interrupt_pending(ctlr_info_t *h)
27105 {
27106- return h->access.intr_pending(h);
27107+ return h->access->intr_pending(h);
27108 }
27109
27110 static inline long interrupt_not_for_us(ctlr_info_t *h)
27111 {
27112- return (((h->access.intr_pending(h) == 0) ||
27113+ return (((h->access->intr_pending(h) == 0) ||
27114 (h->interrupts_enabled == 0)));
27115 }
27116
27117@@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr
27118 */
27119 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
27120 c->product_name = products[prod_index].product_name;
27121- c->access = *(products[prod_index].access);
27122+ c->access = products[prod_index].access;
27123 c->nr_cmds = c->max_commands - 4;
27124 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
27125 (readb(&c->cfgtable->Signature[1]) != 'I') ||
27126@@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(stru
27127 }
27128
27129 /* make sure the board interrupts are off */
27130- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
27131+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
27132 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
27133 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
27134 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
27135@@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(stru
27136 cciss_scsi_setup(i);
27137
27138 /* Turn the interrupts on so we can service requests */
27139- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
27140+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
27141
27142 /* Get the firmware version */
27143 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
27144diff -urNp linux-2.6.32.43/drivers/block/cciss.h linux-2.6.32.43/drivers/block/cciss.h
27145--- linux-2.6.32.43/drivers/block/cciss.h 2011-04-17 17:00:52.000000000 -0400
27146+++ linux-2.6.32.43/drivers/block/cciss.h 2011-08-05 20:33:55.000000000 -0400
27147@@ -90,7 +90,7 @@ struct ctlr_info
27148 // information about each logical volume
27149 drive_info_struct *drv[CISS_MAX_LUN];
27150
27151- struct access_method access;
27152+ struct access_method *access;
27153
27154 /* queue and queue Info */
27155 struct hlist_head reqQ;
27156diff -urNp linux-2.6.32.43/drivers/block/cpqarray.c linux-2.6.32.43/drivers/block/cpqarray.c
27157--- linux-2.6.32.43/drivers/block/cpqarray.c 2011-03-27 14:31:47.000000000 -0400
27158+++ linux-2.6.32.43/drivers/block/cpqarray.c 2011-08-05 20:33:55.000000000 -0400
27159@@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr
27160 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
27161 goto Enomem4;
27162 }
27163- hba[i]->access.set_intr_mask(hba[i], 0);
27164+ hba[i]->access->set_intr_mask(hba[i], 0);
27165 if (request_irq(hba[i]->intr, do_ida_intr,
27166 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
27167 {
27168@@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr
27169 add_timer(&hba[i]->timer);
27170
27171 /* Enable IRQ now that spinlock and rate limit timer are set up */
27172- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27173+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27174
27175 for(j=0; j<NWD; j++) {
27176 struct gendisk *disk = ida_gendisk[i][j];
27177@@ -695,7 +695,7 @@ DBGINFO(
27178 for(i=0; i<NR_PRODUCTS; i++) {
27179 if (board_id == products[i].board_id) {
27180 c->product_name = products[i].product_name;
27181- c->access = *(products[i].access);
27182+ c->access = products[i].access;
27183 break;
27184 }
27185 }
27186@@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(v
27187 hba[ctlr]->intr = intr;
27188 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
27189 hba[ctlr]->product_name = products[j].product_name;
27190- hba[ctlr]->access = *(products[j].access);
27191+ hba[ctlr]->access = products[j].access;
27192 hba[ctlr]->ctlr = ctlr;
27193 hba[ctlr]->board_id = board_id;
27194 hba[ctlr]->pci_dev = NULL; /* not PCI */
27195@@ -896,6 +896,8 @@ static void do_ida_request(struct reques
27196 struct scatterlist tmp_sg[SG_MAX];
27197 int i, dir, seg;
27198
27199+ pax_track_stack();
27200+
27201 if (blk_queue_plugged(q))
27202 goto startio;
27203
27204@@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
27205
27206 while((c = h->reqQ) != NULL) {
27207 /* Can't do anything if we're busy */
27208- if (h->access.fifo_full(h) == 0)
27209+ if (h->access->fifo_full(h) == 0)
27210 return;
27211
27212 /* Get the first entry from the request Q */
27213@@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
27214 h->Qdepth--;
27215
27216 /* Tell the controller to do our bidding */
27217- h->access.submit_command(h, c);
27218+ h->access->submit_command(h, c);
27219
27220 /* Get onto the completion Q */
27221 addQ(&h->cmpQ, c);
27222@@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq,
27223 unsigned long flags;
27224 __u32 a,a1;
27225
27226- istat = h->access.intr_pending(h);
27227+ istat = h->access->intr_pending(h);
27228 /* Is this interrupt for us? */
27229 if (istat == 0)
27230 return IRQ_NONE;
27231@@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq,
27232 */
27233 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
27234 if (istat & FIFO_NOT_EMPTY) {
27235- while((a = h->access.command_completed(h))) {
27236+ while((a = h->access->command_completed(h))) {
27237 a1 = a; a &= ~3;
27238 if ((c = h->cmpQ) == NULL)
27239 {
27240@@ -1434,11 +1436,11 @@ static int sendcmd(
27241 /*
27242 * Disable interrupt
27243 */
27244- info_p->access.set_intr_mask(info_p, 0);
27245+ info_p->access->set_intr_mask(info_p, 0);
27246 /* Make sure there is room in the command FIFO */
27247 /* Actually it should be completely empty at this time. */
27248 for (i = 200000; i > 0; i--) {
27249- temp = info_p->access.fifo_full(info_p);
27250+ temp = info_p->access->fifo_full(info_p);
27251 if (temp != 0) {
27252 break;
27253 }
27254@@ -1451,7 +1453,7 @@ DBG(
27255 /*
27256 * Send the cmd
27257 */
27258- info_p->access.submit_command(info_p, c);
27259+ info_p->access->submit_command(info_p, c);
27260 complete = pollcomplete(ctlr);
27261
27262 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
27263@@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t
27264 * we check the new geometry. Then turn interrupts back on when
27265 * we're done.
27266 */
27267- host->access.set_intr_mask(host, 0);
27268+ host->access->set_intr_mask(host, 0);
27269 getgeometry(ctlr);
27270- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
27271+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
27272
27273 for(i=0; i<NWD; i++) {
27274 struct gendisk *disk = ida_gendisk[ctlr][i];
27275@@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
27276 /* Wait (up to 2 seconds) for a command to complete */
27277
27278 for (i = 200000; i > 0; i--) {
27279- done = hba[ctlr]->access.command_completed(hba[ctlr]);
27280+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
27281 if (done == 0) {
27282 udelay(10); /* a short fixed delay */
27283 } else
27284diff -urNp linux-2.6.32.43/drivers/block/cpqarray.h linux-2.6.32.43/drivers/block/cpqarray.h
27285--- linux-2.6.32.43/drivers/block/cpqarray.h 2011-03-27 14:31:47.000000000 -0400
27286+++ linux-2.6.32.43/drivers/block/cpqarray.h 2011-08-05 20:33:55.000000000 -0400
27287@@ -99,7 +99,7 @@ struct ctlr_info {
27288 drv_info_t drv[NWD];
27289 struct proc_dir_entry *proc;
27290
27291- struct access_method access;
27292+ struct access_method *access;
27293
27294 cmdlist_t *reqQ;
27295 cmdlist_t *cmpQ;
27296diff -urNp linux-2.6.32.43/drivers/block/DAC960.c linux-2.6.32.43/drivers/block/DAC960.c
27297--- linux-2.6.32.43/drivers/block/DAC960.c 2011-03-27 14:31:47.000000000 -0400
27298+++ linux-2.6.32.43/drivers/block/DAC960.c 2011-05-16 21:46:57.000000000 -0400
27299@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27300 unsigned long flags;
27301 int Channel, TargetID;
27302
27303+ pax_track_stack();
27304+
27305 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27306 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27307 sizeof(DAC960_SCSI_Inquiry_T) +
27308diff -urNp linux-2.6.32.43/drivers/block/nbd.c linux-2.6.32.43/drivers/block/nbd.c
27309--- linux-2.6.32.43/drivers/block/nbd.c 2011-06-25 12:55:34.000000000 -0400
27310+++ linux-2.6.32.43/drivers/block/nbd.c 2011-06-25 12:56:37.000000000 -0400
27311@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *
27312 struct kvec iov;
27313 sigset_t blocked, oldset;
27314
27315+ pax_track_stack();
27316+
27317 if (unlikely(!sock)) {
27318 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27319 lo->disk->disk_name, (send ? "send" : "recv"));
27320@@ -569,6 +571,8 @@ static void do_nbd_request(struct reques
27321 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27322 unsigned int cmd, unsigned long arg)
27323 {
27324+ pax_track_stack();
27325+
27326 switch (cmd) {
27327 case NBD_DISCONNECT: {
27328 struct request sreq;
27329diff -urNp linux-2.6.32.43/drivers/block/pktcdvd.c linux-2.6.32.43/drivers/block/pktcdvd.c
27330--- linux-2.6.32.43/drivers/block/pktcdvd.c 2011-03-27 14:31:47.000000000 -0400
27331+++ linux-2.6.32.43/drivers/block/pktcdvd.c 2011-04-17 15:56:46.000000000 -0400
27332@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kob
27333 return len;
27334 }
27335
27336-static struct sysfs_ops kobj_pkt_ops = {
27337+static const struct sysfs_ops kobj_pkt_ops = {
27338 .show = kobj_pkt_show,
27339 .store = kobj_pkt_store
27340 };
27341diff -urNp linux-2.6.32.43/drivers/char/agp/frontend.c linux-2.6.32.43/drivers/char/agp/frontend.c
27342--- linux-2.6.32.43/drivers/char/agp/frontend.c 2011-03-27 14:31:47.000000000 -0400
27343+++ linux-2.6.32.43/drivers/char/agp/frontend.c 2011-04-17 15:56:46.000000000 -0400
27344@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
27345 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27346 return -EFAULT;
27347
27348- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27349+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27350 return -EFAULT;
27351
27352 client = agp_find_client_by_pid(reserve.pid);
27353diff -urNp linux-2.6.32.43/drivers/char/briq_panel.c linux-2.6.32.43/drivers/char/briq_panel.c
27354--- linux-2.6.32.43/drivers/char/briq_panel.c 2011-03-27 14:31:47.000000000 -0400
27355+++ linux-2.6.32.43/drivers/char/briq_panel.c 2011-04-18 19:48:57.000000000 -0400
27356@@ -10,6 +10,7 @@
27357 #include <linux/types.h>
27358 #include <linux/errno.h>
27359 #include <linux/tty.h>
27360+#include <linux/mutex.h>
27361 #include <linux/timer.h>
27362 #include <linux/kernel.h>
27363 #include <linux/wait.h>
27364@@ -36,6 +37,7 @@ static int vfd_is_open;
27365 static unsigned char vfd[40];
27366 static int vfd_cursor;
27367 static unsigned char ledpb, led;
27368+static DEFINE_MUTEX(vfd_mutex);
27369
27370 static void update_vfd(void)
27371 {
27372@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct f
27373 if (!vfd_is_open)
27374 return -EBUSY;
27375
27376+ mutex_lock(&vfd_mutex);
27377 for (;;) {
27378 char c;
27379 if (!indx)
27380 break;
27381- if (get_user(c, buf))
27382+ if (get_user(c, buf)) {
27383+ mutex_unlock(&vfd_mutex);
27384 return -EFAULT;
27385+ }
27386 if (esc) {
27387 set_led(c);
27388 esc = 0;
27389@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct f
27390 buf++;
27391 }
27392 update_vfd();
27393+ mutex_unlock(&vfd_mutex);
27394
27395 return len;
27396 }
27397diff -urNp linux-2.6.32.43/drivers/char/genrtc.c linux-2.6.32.43/drivers/char/genrtc.c
27398--- linux-2.6.32.43/drivers/char/genrtc.c 2011-03-27 14:31:47.000000000 -0400
27399+++ linux-2.6.32.43/drivers/char/genrtc.c 2011-04-18 19:45:42.000000000 -0400
27400@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *i
27401 switch (cmd) {
27402
27403 case RTC_PLL_GET:
27404+ memset(&pll, 0, sizeof(pll));
27405 if (get_rtc_pll(&pll))
27406 return -EINVAL;
27407 else
27408diff -urNp linux-2.6.32.43/drivers/char/hpet.c linux-2.6.32.43/drivers/char/hpet.c
27409--- linux-2.6.32.43/drivers/char/hpet.c 2011-03-27 14:31:47.000000000 -0400
27410+++ linux-2.6.32.43/drivers/char/hpet.c 2011-04-23 12:56:11.000000000 -0400
27411@@ -430,7 +430,7 @@ static int hpet_release(struct inode *in
27412 return 0;
27413 }
27414
27415-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
27416+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
27417
27418 static int
27419 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
27420@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_di
27421 }
27422
27423 static int
27424-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
27425+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
27426 {
27427 struct hpet_timer __iomem *timer;
27428 struct hpet __iomem *hpet;
27429@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp,
27430 {
27431 struct hpet_info info;
27432
27433+ memset(&info, 0, sizeof(info));
27434+
27435 if (devp->hd_ireqfreq)
27436 info.hi_ireqfreq =
27437 hpet_time_div(hpetp, devp->hd_ireqfreq);
27438- else
27439- info.hi_ireqfreq = 0;
27440 info.hi_flags =
27441 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
27442 info.hi_hpet = hpetp->hp_which;
27443diff -urNp linux-2.6.32.43/drivers/char/hvc_beat.c linux-2.6.32.43/drivers/char/hvc_beat.c
27444--- linux-2.6.32.43/drivers/char/hvc_beat.c 2011-03-27 14:31:47.000000000 -0400
27445+++ linux-2.6.32.43/drivers/char/hvc_beat.c 2011-04-17 15:56:46.000000000 -0400
27446@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t v
27447 return cnt;
27448 }
27449
27450-static struct hv_ops hvc_beat_get_put_ops = {
27451+static const struct hv_ops hvc_beat_get_put_ops = {
27452 .get_chars = hvc_beat_get_chars,
27453 .put_chars = hvc_beat_put_chars,
27454 };
27455diff -urNp linux-2.6.32.43/drivers/char/hvc_console.c linux-2.6.32.43/drivers/char/hvc_console.c
27456--- linux-2.6.32.43/drivers/char/hvc_console.c 2011-03-27 14:31:47.000000000 -0400
27457+++ linux-2.6.32.43/drivers/char/hvc_console.c 2011-04-17 15:56:46.000000000 -0400
27458@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_ind
27459 * console interfaces but can still be used as a tty device. This has to be
27460 * static because kmalloc will not work during early console init.
27461 */
27462-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
27463+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
27464 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
27465 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
27466
27467@@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kr
27468 * vty adapters do NOT get an hvc_instantiate() callback since they
27469 * appear after early console init.
27470 */
27471-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
27472+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
27473 {
27474 struct hvc_struct *hp;
27475
27476@@ -756,7 +756,7 @@ static const struct tty_operations hvc_o
27477 };
27478
27479 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
27480- struct hv_ops *ops, int outbuf_size)
27481+ const struct hv_ops *ops, int outbuf_size)
27482 {
27483 struct hvc_struct *hp;
27484 int i;
27485diff -urNp linux-2.6.32.43/drivers/char/hvc_console.h linux-2.6.32.43/drivers/char/hvc_console.h
27486--- linux-2.6.32.43/drivers/char/hvc_console.h 2011-03-27 14:31:47.000000000 -0400
27487+++ linux-2.6.32.43/drivers/char/hvc_console.h 2011-04-17 15:56:46.000000000 -0400
27488@@ -55,7 +55,7 @@ struct hvc_struct {
27489 int outbuf_size;
27490 int n_outbuf;
27491 uint32_t vtermno;
27492- struct hv_ops *ops;
27493+ const struct hv_ops *ops;
27494 int irq_requested;
27495 int data;
27496 struct winsize ws;
27497@@ -76,11 +76,11 @@ struct hv_ops {
27498 };
27499
27500 /* Register a vterm and a slot index for use as a console (console_init) */
27501-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
27502+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
27503
27504 /* register a vterm for hvc tty operation (module_init or hotplug add) */
27505 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
27506- struct hv_ops *ops, int outbuf_size);
27507+ const struct hv_ops *ops, int outbuf_size);
27508 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
27509 extern int hvc_remove(struct hvc_struct *hp);
27510
27511diff -urNp linux-2.6.32.43/drivers/char/hvc_iseries.c linux-2.6.32.43/drivers/char/hvc_iseries.c
27512--- linux-2.6.32.43/drivers/char/hvc_iseries.c 2011-03-27 14:31:47.000000000 -0400
27513+++ linux-2.6.32.43/drivers/char/hvc_iseries.c 2011-04-17 15:56:46.000000000 -0400
27514@@ -197,7 +197,7 @@ done:
27515 return sent;
27516 }
27517
27518-static struct hv_ops hvc_get_put_ops = {
27519+static const struct hv_ops hvc_get_put_ops = {
27520 .get_chars = get_chars,
27521 .put_chars = put_chars,
27522 .notifier_add = notifier_add_irq,
27523diff -urNp linux-2.6.32.43/drivers/char/hvc_iucv.c linux-2.6.32.43/drivers/char/hvc_iucv.c
27524--- linux-2.6.32.43/drivers/char/hvc_iucv.c 2011-03-27 14:31:47.000000000 -0400
27525+++ linux-2.6.32.43/drivers/char/hvc_iucv.c 2011-04-17 15:56:46.000000000 -0400
27526@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(stru
27527
27528
27529 /* HVC operations */
27530-static struct hv_ops hvc_iucv_ops = {
27531+static const struct hv_ops hvc_iucv_ops = {
27532 .get_chars = hvc_iucv_get_chars,
27533 .put_chars = hvc_iucv_put_chars,
27534 .notifier_add = hvc_iucv_notifier_add,
27535diff -urNp linux-2.6.32.43/drivers/char/hvc_rtas.c linux-2.6.32.43/drivers/char/hvc_rtas.c
27536--- linux-2.6.32.43/drivers/char/hvc_rtas.c 2011-03-27 14:31:47.000000000 -0400
27537+++ linux-2.6.32.43/drivers/char/hvc_rtas.c 2011-04-17 15:56:46.000000000 -0400
27538@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_
27539 return i;
27540 }
27541
27542-static struct hv_ops hvc_rtas_get_put_ops = {
27543+static const struct hv_ops hvc_rtas_get_put_ops = {
27544 .get_chars = hvc_rtas_read_console,
27545 .put_chars = hvc_rtas_write_console,
27546 };
27547diff -urNp linux-2.6.32.43/drivers/char/hvcs.c linux-2.6.32.43/drivers/char/hvcs.c
27548--- linux-2.6.32.43/drivers/char/hvcs.c 2011-03-27 14:31:47.000000000 -0400
27549+++ linux-2.6.32.43/drivers/char/hvcs.c 2011-04-17 15:56:46.000000000 -0400
27550@@ -82,6 +82,7 @@
27551 #include <asm/hvcserver.h>
27552 #include <asm/uaccess.h>
27553 #include <asm/vio.h>
27554+#include <asm/local.h>
27555
27556 /*
27557 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
27558@@ -269,7 +270,7 @@ struct hvcs_struct {
27559 unsigned int index;
27560
27561 struct tty_struct *tty;
27562- int open_count;
27563+ local_t open_count;
27564
27565 /*
27566 * Used to tell the driver kernel_thread what operations need to take
27567@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(st
27568
27569 spin_lock_irqsave(&hvcsd->lock, flags);
27570
27571- if (hvcsd->open_count > 0) {
27572+ if (local_read(&hvcsd->open_count) > 0) {
27573 spin_unlock_irqrestore(&hvcsd->lock, flags);
27574 printk(KERN_INFO "HVCS: vterm state unchanged. "
27575 "The hvcs device node is still in use.\n");
27576@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *
27577 if ((retval = hvcs_partner_connect(hvcsd)))
27578 goto error_release;
27579
27580- hvcsd->open_count = 1;
27581+ local_set(&hvcsd->open_count, 1);
27582 hvcsd->tty = tty;
27583 tty->driver_data = hvcsd;
27584
27585@@ -1169,7 +1170,7 @@ fast_open:
27586
27587 spin_lock_irqsave(&hvcsd->lock, flags);
27588 kref_get(&hvcsd->kref);
27589- hvcsd->open_count++;
27590+ local_inc(&hvcsd->open_count);
27591 hvcsd->todo_mask |= HVCS_SCHED_READ;
27592 spin_unlock_irqrestore(&hvcsd->lock, flags);
27593
27594@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct
27595 hvcsd = tty->driver_data;
27596
27597 spin_lock_irqsave(&hvcsd->lock, flags);
27598- if (--hvcsd->open_count == 0) {
27599+ if (local_dec_and_test(&hvcsd->open_count)) {
27600
27601 vio_disable_interrupts(hvcsd->vdev);
27602
27603@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct
27604 free_irq(irq, hvcsd);
27605 kref_put(&hvcsd->kref, destroy_hvcs_struct);
27606 return;
27607- } else if (hvcsd->open_count < 0) {
27608+ } else if (local_read(&hvcsd->open_count) < 0) {
27609 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
27610 " is missmanaged.\n",
27611- hvcsd->vdev->unit_address, hvcsd->open_count);
27612+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
27613 }
27614
27615 spin_unlock_irqrestore(&hvcsd->lock, flags);
27616@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struc
27617
27618 spin_lock_irqsave(&hvcsd->lock, flags);
27619 /* Preserve this so that we know how many kref refs to put */
27620- temp_open_count = hvcsd->open_count;
27621+ temp_open_count = local_read(&hvcsd->open_count);
27622
27623 /*
27624 * Don't kref put inside the spinlock because the destruction
27625@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struc
27626 hvcsd->tty->driver_data = NULL;
27627 hvcsd->tty = NULL;
27628
27629- hvcsd->open_count = 0;
27630+ local_set(&hvcsd->open_count, 0);
27631
27632 /* This will drop any buffered data on the floor which is OK in a hangup
27633 * scenario. */
27634@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct
27635 * the middle of a write operation? This is a crummy place to do this
27636 * but we want to keep it all in the spinlock.
27637 */
27638- if (hvcsd->open_count <= 0) {
27639+ if (local_read(&hvcsd->open_count) <= 0) {
27640 spin_unlock_irqrestore(&hvcsd->lock, flags);
27641 return -ENODEV;
27642 }
27643@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_st
27644 {
27645 struct hvcs_struct *hvcsd = tty->driver_data;
27646
27647- if (!hvcsd || hvcsd->open_count <= 0)
27648+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
27649 return 0;
27650
27651 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
27652diff -urNp linux-2.6.32.43/drivers/char/hvc_udbg.c linux-2.6.32.43/drivers/char/hvc_udbg.c
27653--- linux-2.6.32.43/drivers/char/hvc_udbg.c 2011-03-27 14:31:47.000000000 -0400
27654+++ linux-2.6.32.43/drivers/char/hvc_udbg.c 2011-04-17 15:56:46.000000000 -0400
27655@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno
27656 return i;
27657 }
27658
27659-static struct hv_ops hvc_udbg_ops = {
27660+static const struct hv_ops hvc_udbg_ops = {
27661 .get_chars = hvc_udbg_get,
27662 .put_chars = hvc_udbg_put,
27663 };
27664diff -urNp linux-2.6.32.43/drivers/char/hvc_vio.c linux-2.6.32.43/drivers/char/hvc_vio.c
27665--- linux-2.6.32.43/drivers/char/hvc_vio.c 2011-03-27 14:31:47.000000000 -0400
27666+++ linux-2.6.32.43/drivers/char/hvc_vio.c 2011-04-17 15:56:46.000000000 -0400
27667@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t v
27668 return got;
27669 }
27670
27671-static struct hv_ops hvc_get_put_ops = {
27672+static const struct hv_ops hvc_get_put_ops = {
27673 .get_chars = filtered_get_chars,
27674 .put_chars = hvc_put_chars,
27675 .notifier_add = notifier_add_irq,
27676diff -urNp linux-2.6.32.43/drivers/char/hvc_xen.c linux-2.6.32.43/drivers/char/hvc_xen.c
27677--- linux-2.6.32.43/drivers/char/hvc_xen.c 2011-03-27 14:31:47.000000000 -0400
27678+++ linux-2.6.32.43/drivers/char/hvc_xen.c 2011-04-17 15:56:46.000000000 -0400
27679@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno
27680 return recv;
27681 }
27682
27683-static struct hv_ops hvc_ops = {
27684+static const struct hv_ops hvc_ops = {
27685 .get_chars = read_console,
27686 .put_chars = write_console,
27687 .notifier_add = notifier_add_irq,
27688diff -urNp linux-2.6.32.43/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.32.43/drivers/char/ipmi/ipmi_msghandler.c
27689--- linux-2.6.32.43/drivers/char/ipmi/ipmi_msghandler.c 2011-03-27 14:31:47.000000000 -0400
27690+++ linux-2.6.32.43/drivers/char/ipmi/ipmi_msghandler.c 2011-05-16 21:46:57.000000000 -0400
27691@@ -414,7 +414,7 @@ struct ipmi_smi {
27692 struct proc_dir_entry *proc_dir;
27693 char proc_dir_name[10];
27694
27695- atomic_t stats[IPMI_NUM_STATS];
27696+ atomic_unchecked_t stats[IPMI_NUM_STATS];
27697
27698 /*
27699 * run_to_completion duplicate of smb_info, smi_info
27700@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27701
27702
27703 #define ipmi_inc_stat(intf, stat) \
27704- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27705+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27706 #define ipmi_get_stat(intf, stat) \
27707- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27708+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27709
27710 static int is_lan_addr(struct ipmi_addr *addr)
27711 {
27712@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
27713 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27714 init_waitqueue_head(&intf->waitq);
27715 for (i = 0; i < IPMI_NUM_STATS; i++)
27716- atomic_set(&intf->stats[i], 0);
27717+ atomic_set_unchecked(&intf->stats[i], 0);
27718
27719 intf->proc_dir = NULL;
27720
27721@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
27722 struct ipmi_smi_msg smi_msg;
27723 struct ipmi_recv_msg recv_msg;
27724
27725+ pax_track_stack();
27726+
27727 si = (struct ipmi_system_interface_addr *) &addr;
27728 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
27729 si->channel = IPMI_BMC_CHANNEL;
27730diff -urNp linux-2.6.32.43/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.32.43/drivers/char/ipmi/ipmi_si_intf.c
27731--- linux-2.6.32.43/drivers/char/ipmi/ipmi_si_intf.c 2011-03-27 14:31:47.000000000 -0400
27732+++ linux-2.6.32.43/drivers/char/ipmi/ipmi_si_intf.c 2011-04-17 15:56:46.000000000 -0400
27733@@ -277,7 +277,7 @@ struct smi_info {
27734 unsigned char slave_addr;
27735
27736 /* Counters and things for the proc filesystem. */
27737- atomic_t stats[SI_NUM_STATS];
27738+ atomic_unchecked_t stats[SI_NUM_STATS];
27739
27740 struct task_struct *thread;
27741
27742@@ -285,9 +285,9 @@ struct smi_info {
27743 };
27744
27745 #define smi_inc_stat(smi, stat) \
27746- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27747+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27748 #define smi_get_stat(smi, stat) \
27749- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27750+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27751
27752 #define SI_MAX_PARMS 4
27753
27754@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info
27755 atomic_set(&new_smi->req_events, 0);
27756 new_smi->run_to_completion = 0;
27757 for (i = 0; i < SI_NUM_STATS; i++)
27758- atomic_set(&new_smi->stats[i], 0);
27759+ atomic_set_unchecked(&new_smi->stats[i], 0);
27760
27761 new_smi->interrupt_disabled = 0;
27762 atomic_set(&new_smi->stop_operation, 0);
27763diff -urNp linux-2.6.32.43/drivers/char/istallion.c linux-2.6.32.43/drivers/char/istallion.c
27764--- linux-2.6.32.43/drivers/char/istallion.c 2011-03-27 14:31:47.000000000 -0400
27765+++ linux-2.6.32.43/drivers/char/istallion.c 2011-05-16 21:46:57.000000000 -0400
27766@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios
27767 * re-used for each stats call.
27768 */
27769 static comstats_t stli_comstats;
27770-static combrd_t stli_brdstats;
27771 static struct asystats stli_cdkstats;
27772
27773 /*****************************************************************************/
27774@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __u
27775 {
27776 struct stlibrd *brdp;
27777 unsigned int i;
27778+ combrd_t stli_brdstats;
27779
27780 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
27781 return -EFAULT;
27782@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stl
27783 struct stliport stli_dummyport;
27784 struct stliport *portp;
27785
27786+ pax_track_stack();
27787+
27788 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
27789 return -EFAULT;
27790 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
27791@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stli
27792 struct stlibrd stli_dummybrd;
27793 struct stlibrd *brdp;
27794
27795+ pax_track_stack();
27796+
27797 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
27798 return -EFAULT;
27799 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
27800diff -urNp linux-2.6.32.43/drivers/char/Kconfig linux-2.6.32.43/drivers/char/Kconfig
27801--- linux-2.6.32.43/drivers/char/Kconfig 2011-03-27 14:31:47.000000000 -0400
27802+++ linux-2.6.32.43/drivers/char/Kconfig 2011-04-18 19:20:15.000000000 -0400
27803@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
27804
27805 config DEVKMEM
27806 bool "/dev/kmem virtual device support"
27807- default y
27808+ default n
27809+ depends on !GRKERNSEC_KMEM
27810 help
27811 Say Y here if you want to support the /dev/kmem device. The
27812 /dev/kmem device is rarely used, but can be used for certain
27813@@ -1114,6 +1115,7 @@ config DEVPORT
27814 bool
27815 depends on !M68K
27816 depends on ISA || PCI
27817+ depends on !GRKERNSEC_KMEM
27818 default y
27819
27820 source "drivers/s390/char/Kconfig"
27821diff -urNp linux-2.6.32.43/drivers/char/keyboard.c linux-2.6.32.43/drivers/char/keyboard.c
27822--- linux-2.6.32.43/drivers/char/keyboard.c 2011-03-27 14:31:47.000000000 -0400
27823+++ linux-2.6.32.43/drivers/char/keyboard.c 2011-04-17 15:56:46.000000000 -0400
27824@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
27825 kbd->kbdmode == VC_MEDIUMRAW) &&
27826 value != KVAL(K_SAK))
27827 return; /* SAK is allowed even in raw mode */
27828+
27829+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
27830+ {
27831+ void *func = fn_handler[value];
27832+ if (func == fn_show_state || func == fn_show_ptregs ||
27833+ func == fn_show_mem)
27834+ return;
27835+ }
27836+#endif
27837+
27838 fn_handler[value](vc);
27839 }
27840
27841@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_
27842 .evbit = { BIT_MASK(EV_SND) },
27843 },
27844
27845- { }, /* Terminating entry */
27846+ { 0 }, /* Terminating entry */
27847 };
27848
27849 MODULE_DEVICE_TABLE(input, kbd_ids);
27850diff -urNp linux-2.6.32.43/drivers/char/mem.c linux-2.6.32.43/drivers/char/mem.c
27851--- linux-2.6.32.43/drivers/char/mem.c 2011-03-27 14:31:47.000000000 -0400
27852+++ linux-2.6.32.43/drivers/char/mem.c 2011-04-17 15:56:46.000000000 -0400
27853@@ -18,6 +18,7 @@
27854 #include <linux/raw.h>
27855 #include <linux/tty.h>
27856 #include <linux/capability.h>
27857+#include <linux/security.h>
27858 #include <linux/ptrace.h>
27859 #include <linux/device.h>
27860 #include <linux/highmem.h>
27861@@ -35,6 +36,10 @@
27862 # include <linux/efi.h>
27863 #endif
27864
27865+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27866+extern struct file_operations grsec_fops;
27867+#endif
27868+
27869 static inline unsigned long size_inside_page(unsigned long start,
27870 unsigned long size)
27871 {
27872@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsig
27873
27874 while (cursor < to) {
27875 if (!devmem_is_allowed(pfn)) {
27876+#ifdef CONFIG_GRKERNSEC_KMEM
27877+ gr_handle_mem_readwrite(from, to);
27878+#else
27879 printk(KERN_INFO
27880 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27881 current->comm, from, to);
27882+#endif
27883 return 0;
27884 }
27885 cursor += PAGE_SIZE;
27886@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsig
27887 }
27888 return 1;
27889 }
27890+#elif defined(CONFIG_GRKERNSEC_KMEM)
27891+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27892+{
27893+ return 0;
27894+}
27895 #else
27896 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27897 {
27898@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * fi
27899 #endif
27900
27901 while (count > 0) {
27902+ char *temp;
27903+
27904 /*
27905 * Handle first page in case it's not aligned
27906 */
27907@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * fi
27908 if (!ptr)
27909 return -EFAULT;
27910
27911- if (copy_to_user(buf, ptr, sz)) {
27912+#ifdef CONFIG_PAX_USERCOPY
27913+ temp = kmalloc(sz, GFP_KERNEL);
27914+ if (!temp) {
27915+ unxlate_dev_mem_ptr(p, ptr);
27916+ return -ENOMEM;
27917+ }
27918+ memcpy(temp, ptr, sz);
27919+#else
27920+ temp = ptr;
27921+#endif
27922+
27923+ if (copy_to_user(buf, temp, sz)) {
27924+
27925+#ifdef CONFIG_PAX_USERCOPY
27926+ kfree(temp);
27927+#endif
27928+
27929 unxlate_dev_mem_ptr(p, ptr);
27930 return -EFAULT;
27931 }
27932
27933+#ifdef CONFIG_PAX_USERCOPY
27934+ kfree(temp);
27935+#endif
27936+
27937 unxlate_dev_mem_ptr(p, ptr);
27938
27939 buf += sz;
27940@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *fi
27941 size_t count, loff_t *ppos)
27942 {
27943 unsigned long p = *ppos;
27944- ssize_t low_count, read, sz;
27945+ ssize_t low_count, read, sz, err = 0;
27946 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27947- int err = 0;
27948
27949 read = 0;
27950 if (p < (unsigned long) high_memory) {
27951@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *fi
27952 }
27953 #endif
27954 while (low_count > 0) {
27955+ char *temp;
27956+
27957 sz = size_inside_page(p, low_count);
27958
27959 /*
27960@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *fi
27961 */
27962 kbuf = xlate_dev_kmem_ptr((char *)p);
27963
27964- if (copy_to_user(buf, kbuf, sz))
27965+#ifdef CONFIG_PAX_USERCOPY
27966+ temp = kmalloc(sz, GFP_KERNEL);
27967+ if (!temp)
27968+ return -ENOMEM;
27969+ memcpy(temp, kbuf, sz);
27970+#else
27971+ temp = kbuf;
27972+#endif
27973+
27974+ err = copy_to_user(buf, temp, sz);
27975+
27976+#ifdef CONFIG_PAX_USERCOPY
27977+ kfree(temp);
27978+#endif
27979+
27980+ if (err)
27981 return -EFAULT;
27982 buf += sz;
27983 p += sz;
27984@@ -889,6 +941,9 @@ static const struct memdev {
27985 #ifdef CONFIG_CRASH_DUMP
27986 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27987 #endif
27988+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27989+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27990+#endif
27991 };
27992
27993 static int memory_open(struct inode *inode, struct file *filp)
27994diff -urNp linux-2.6.32.43/drivers/char/pcmcia/ipwireless/tty.c linux-2.6.32.43/drivers/char/pcmcia/ipwireless/tty.c
27995--- linux-2.6.32.43/drivers/char/pcmcia/ipwireless/tty.c 2011-03-27 14:31:47.000000000 -0400
27996+++ linux-2.6.32.43/drivers/char/pcmcia/ipwireless/tty.c 2011-04-17 15:56:46.000000000 -0400
27997@@ -29,6 +29,7 @@
27998 #include <linux/tty_driver.h>
27999 #include <linux/tty_flip.h>
28000 #include <linux/uaccess.h>
28001+#include <asm/local.h>
28002
28003 #include "tty.h"
28004 #include "network.h"
28005@@ -51,7 +52,7 @@ struct ipw_tty {
28006 int tty_type;
28007 struct ipw_network *network;
28008 struct tty_struct *linux_tty;
28009- int open_count;
28010+ local_t open_count;
28011 unsigned int control_lines;
28012 struct mutex ipw_tty_mutex;
28013 int tx_bytes_queued;
28014@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
28015 mutex_unlock(&tty->ipw_tty_mutex);
28016 return -ENODEV;
28017 }
28018- if (tty->open_count == 0)
28019+ if (local_read(&tty->open_count) == 0)
28020 tty->tx_bytes_queued = 0;
28021
28022- tty->open_count++;
28023+ local_inc(&tty->open_count);
28024
28025 tty->linux_tty = linux_tty;
28026 linux_tty->driver_data = tty;
28027@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
28028
28029 static void do_ipw_close(struct ipw_tty *tty)
28030 {
28031- tty->open_count--;
28032-
28033- if (tty->open_count == 0) {
28034+ if (local_dec_return(&tty->open_count) == 0) {
28035 struct tty_struct *linux_tty = tty->linux_tty;
28036
28037 if (linux_tty != NULL) {
28038@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
28039 return;
28040
28041 mutex_lock(&tty->ipw_tty_mutex);
28042- if (tty->open_count == 0) {
28043+ if (local_read(&tty->open_count) == 0) {
28044 mutex_unlock(&tty->ipw_tty_mutex);
28045 return;
28046 }
28047@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
28048 return;
28049 }
28050
28051- if (!tty->open_count) {
28052+ if (!local_read(&tty->open_count)) {
28053 mutex_unlock(&tty->ipw_tty_mutex);
28054 return;
28055 }
28056@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
28057 return -ENODEV;
28058
28059 mutex_lock(&tty->ipw_tty_mutex);
28060- if (!tty->open_count) {
28061+ if (!local_read(&tty->open_count)) {
28062 mutex_unlock(&tty->ipw_tty_mutex);
28063 return -EINVAL;
28064 }
28065@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
28066 if (!tty)
28067 return -ENODEV;
28068
28069- if (!tty->open_count)
28070+ if (!local_read(&tty->open_count))
28071 return -EINVAL;
28072
28073 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
28074@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
28075 if (!tty)
28076 return 0;
28077
28078- if (!tty->open_count)
28079+ if (!local_read(&tty->open_count))
28080 return 0;
28081
28082 return tty->tx_bytes_queued;
28083@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
28084 if (!tty)
28085 return -ENODEV;
28086
28087- if (!tty->open_count)
28088+ if (!local_read(&tty->open_count))
28089 return -EINVAL;
28090
28091 return get_control_lines(tty);
28092@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
28093 if (!tty)
28094 return -ENODEV;
28095
28096- if (!tty->open_count)
28097+ if (!local_read(&tty->open_count))
28098 return -EINVAL;
28099
28100 return set_control_lines(tty, set, clear);
28101@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
28102 if (!tty)
28103 return -ENODEV;
28104
28105- if (!tty->open_count)
28106+ if (!local_read(&tty->open_count))
28107 return -EINVAL;
28108
28109 /* FIXME: Exactly how is the tty object locked here .. */
28110@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty
28111 against a parallel ioctl etc */
28112 mutex_lock(&ttyj->ipw_tty_mutex);
28113 }
28114- while (ttyj->open_count)
28115+ while (local_read(&ttyj->open_count))
28116 do_ipw_close(ttyj);
28117 ipwireless_disassociate_network_ttys(network,
28118 ttyj->channel_idx);
28119diff -urNp linux-2.6.32.43/drivers/char/pty.c linux-2.6.32.43/drivers/char/pty.c
28120--- linux-2.6.32.43/drivers/char/pty.c 2011-03-27 14:31:47.000000000 -0400
28121+++ linux-2.6.32.43/drivers/char/pty.c 2011-08-05 20:33:55.000000000 -0400
28122@@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
28123 register_sysctl_table(pty_root_table);
28124
28125 /* Now create the /dev/ptmx special device */
28126+ pax_open_kernel();
28127 tty_default_fops(&ptmx_fops);
28128- ptmx_fops.open = ptmx_open;
28129+ *(void **)&ptmx_fops.open = ptmx_open;
28130+ pax_close_kernel();
28131
28132 cdev_init(&ptmx_cdev, &ptmx_fops);
28133 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
28134diff -urNp linux-2.6.32.43/drivers/char/random.c linux-2.6.32.43/drivers/char/random.c
28135--- linux-2.6.32.43/drivers/char/random.c 2011-03-27 14:31:47.000000000 -0400
28136+++ linux-2.6.32.43/drivers/char/random.c 2011-04-17 15:56:46.000000000 -0400
28137@@ -254,8 +254,13 @@
28138 /*
28139 * Configuration information
28140 */
28141+#ifdef CONFIG_GRKERNSEC_RANDNET
28142+#define INPUT_POOL_WORDS 512
28143+#define OUTPUT_POOL_WORDS 128
28144+#else
28145 #define INPUT_POOL_WORDS 128
28146 #define OUTPUT_POOL_WORDS 32
28147+#endif
28148 #define SEC_XFER_SIZE 512
28149
28150 /*
28151@@ -292,10 +297,17 @@ static struct poolinfo {
28152 int poolwords;
28153 int tap1, tap2, tap3, tap4, tap5;
28154 } poolinfo_table[] = {
28155+#ifdef CONFIG_GRKERNSEC_RANDNET
28156+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28157+ { 512, 411, 308, 208, 104, 1 },
28158+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28159+ { 128, 103, 76, 51, 25, 1 },
28160+#else
28161 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28162 { 128, 103, 76, 51, 25, 1 },
28163 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28164 { 32, 26, 20, 14, 7, 1 },
28165+#endif
28166 #if 0
28167 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28168 { 2048, 1638, 1231, 819, 411, 1 },
28169@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28170 #include <linux/sysctl.h>
28171
28172 static int min_read_thresh = 8, min_write_thresh;
28173-static int max_read_thresh = INPUT_POOL_WORDS * 32;
28174+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28175 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28176 static char sysctl_bootid[16];
28177
28178diff -urNp linux-2.6.32.43/drivers/char/rocket.c linux-2.6.32.43/drivers/char/rocket.c
28179--- linux-2.6.32.43/drivers/char/rocket.c 2011-03-27 14:31:47.000000000 -0400
28180+++ linux-2.6.32.43/drivers/char/rocket.c 2011-05-16 21:46:57.000000000 -0400
28181@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info
28182 struct rocket_ports tmp;
28183 int board;
28184
28185+ pax_track_stack();
28186+
28187 if (!retports)
28188 return -EFAULT;
28189 memset(&tmp, 0, sizeof (tmp));
28190diff -urNp linux-2.6.32.43/drivers/char/sonypi.c linux-2.6.32.43/drivers/char/sonypi.c
28191--- linux-2.6.32.43/drivers/char/sonypi.c 2011-03-27 14:31:47.000000000 -0400
28192+++ linux-2.6.32.43/drivers/char/sonypi.c 2011-04-17 15:56:46.000000000 -0400
28193@@ -55,6 +55,7 @@
28194 #include <asm/uaccess.h>
28195 #include <asm/io.h>
28196 #include <asm/system.h>
28197+#include <asm/local.h>
28198
28199 #include <linux/sonypi.h>
28200
28201@@ -491,7 +492,7 @@ static struct sonypi_device {
28202 spinlock_t fifo_lock;
28203 wait_queue_head_t fifo_proc_list;
28204 struct fasync_struct *fifo_async;
28205- int open_count;
28206+ local_t open_count;
28207 int model;
28208 struct input_dev *input_jog_dev;
28209 struct input_dev *input_key_dev;
28210@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, st
28211 static int sonypi_misc_release(struct inode *inode, struct file *file)
28212 {
28213 mutex_lock(&sonypi_device.lock);
28214- sonypi_device.open_count--;
28215+ local_dec(&sonypi_device.open_count);
28216 mutex_unlock(&sonypi_device.lock);
28217 return 0;
28218 }
28219@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode
28220 lock_kernel();
28221 mutex_lock(&sonypi_device.lock);
28222 /* Flush input queue on first open */
28223- if (!sonypi_device.open_count)
28224+ if (!local_read(&sonypi_device.open_count))
28225 kfifo_reset(sonypi_device.fifo);
28226- sonypi_device.open_count++;
28227+ local_inc(&sonypi_device.open_count);
28228 mutex_unlock(&sonypi_device.lock);
28229 unlock_kernel();
28230 return 0;
28231diff -urNp linux-2.6.32.43/drivers/char/stallion.c linux-2.6.32.43/drivers/char/stallion.c
28232--- linux-2.6.32.43/drivers/char/stallion.c 2011-03-27 14:31:47.000000000 -0400
28233+++ linux-2.6.32.43/drivers/char/stallion.c 2011-05-16 21:46:57.000000000 -0400
28234@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlp
28235 struct stlport stl_dummyport;
28236 struct stlport *portp;
28237
28238+ pax_track_stack();
28239+
28240 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
28241 return -EFAULT;
28242 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
28243diff -urNp linux-2.6.32.43/drivers/char/tpm/tpm_bios.c linux-2.6.32.43/drivers/char/tpm/tpm_bios.c
28244--- linux-2.6.32.43/drivers/char/tpm/tpm_bios.c 2011-03-27 14:31:47.000000000 -0400
28245+++ linux-2.6.32.43/drivers/char/tpm/tpm_bios.c 2011-04-17 15:56:46.000000000 -0400
28246@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start
28247 event = addr;
28248
28249 if ((event->event_type == 0 && event->event_size == 0) ||
28250- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28251+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28252 return NULL;
28253
28254 return addr;
28255@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(
28256 return NULL;
28257
28258 if ((event->event_type == 0 && event->event_size == 0) ||
28259- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28260+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28261 return NULL;
28262
28263 (*pos)++;
28264@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_
28265 int i;
28266
28267 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28268- seq_putc(m, data[i]);
28269+ if (!seq_putc(m, data[i]))
28270+ return -EFAULT;
28271
28272 return 0;
28273 }
28274@@ -409,6 +410,11 @@ static int read_log(struct tpm_bios_log
28275 log->bios_event_log_end = log->bios_event_log + len;
28276
28277 virt = acpi_os_map_memory(start, len);
28278+ if (!virt) {
28279+ kfree(log->bios_event_log);
28280+ log->bios_event_log = NULL;
28281+ return -EFAULT;
28282+ }
28283
28284 memcpy(log->bios_event_log, virt, len);
28285
28286diff -urNp linux-2.6.32.43/drivers/char/tpm/tpm.c linux-2.6.32.43/drivers/char/tpm/tpm.c
28287--- linux-2.6.32.43/drivers/char/tpm/tpm.c 2011-04-17 17:00:52.000000000 -0400
28288+++ linux-2.6.32.43/drivers/char/tpm/tpm.c 2011-05-16 21:46:57.000000000 -0400
28289@@ -402,7 +402,7 @@ static ssize_t tpm_transmit(struct tpm_c
28290 chip->vendor.req_complete_val)
28291 goto out_recv;
28292
28293- if ((status == chip->vendor.req_canceled)) {
28294+ if (status == chip->vendor.req_canceled) {
28295 dev_err(chip->dev, "Operation Canceled\n");
28296 rc = -ECANCELED;
28297 goto out;
28298@@ -821,6 +821,8 @@ ssize_t tpm_show_pubek(struct device *de
28299
28300 struct tpm_chip *chip = dev_get_drvdata(dev);
28301
28302+ pax_track_stack();
28303+
28304 tpm_cmd.header.in = tpm_readpubek_header;
28305 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28306 "attempting to read the PUBEK");
28307diff -urNp linux-2.6.32.43/drivers/char/tty_io.c linux-2.6.32.43/drivers/char/tty_io.c
28308--- linux-2.6.32.43/drivers/char/tty_io.c 2011-03-27 14:31:47.000000000 -0400
28309+++ linux-2.6.32.43/drivers/char/tty_io.c 2011-08-05 20:33:55.000000000 -0400
28310@@ -2582,8 +2582,10 @@ long tty_ioctl(struct file *file, unsign
28311 return retval;
28312 }
28313
28314+EXPORT_SYMBOL(tty_ioctl);
28315+
28316 #ifdef CONFIG_COMPAT
28317-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
28318+long tty_compat_ioctl(struct file *file, unsigned int cmd,
28319 unsigned long arg)
28320 {
28321 struct inode *inode = file->f_dentry->d_inode;
28322@@ -2607,6 +2609,8 @@ static long tty_compat_ioctl(struct file
28323
28324 return retval;
28325 }
28326+
28327+EXPORT_SYMBOL(tty_compat_ioctl);
28328 #endif
28329
28330 /*
28331@@ -3052,7 +3056,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
28332
28333 void tty_default_fops(struct file_operations *fops)
28334 {
28335- *fops = tty_fops;
28336+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
28337 }
28338
28339 /*
28340diff -urNp linux-2.6.32.43/drivers/char/tty_ldisc.c linux-2.6.32.43/drivers/char/tty_ldisc.c
28341--- linux-2.6.32.43/drivers/char/tty_ldisc.c 2011-07-13 17:23:04.000000000 -0400
28342+++ linux-2.6.32.43/drivers/char/tty_ldisc.c 2011-07-13 17:23:18.000000000 -0400
28343@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
28344 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
28345 struct tty_ldisc_ops *ldo = ld->ops;
28346
28347- ldo->refcount--;
28348+ atomic_dec(&ldo->refcount);
28349 module_put(ldo->owner);
28350 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
28351
28352@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
28353 spin_lock_irqsave(&tty_ldisc_lock, flags);
28354 tty_ldiscs[disc] = new_ldisc;
28355 new_ldisc->num = disc;
28356- new_ldisc->refcount = 0;
28357+ atomic_set(&new_ldisc->refcount, 0);
28358 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
28359
28360 return ret;
28361@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
28362 return -EINVAL;
28363
28364 spin_lock_irqsave(&tty_ldisc_lock, flags);
28365- if (tty_ldiscs[disc]->refcount)
28366+ if (atomic_read(&tty_ldiscs[disc]->refcount))
28367 ret = -EBUSY;
28368 else
28369 tty_ldiscs[disc] = NULL;
28370@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
28371 if (ldops) {
28372 ret = ERR_PTR(-EAGAIN);
28373 if (try_module_get(ldops->owner)) {
28374- ldops->refcount++;
28375+ atomic_inc(&ldops->refcount);
28376 ret = ldops;
28377 }
28378 }
28379@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
28380 unsigned long flags;
28381
28382 spin_lock_irqsave(&tty_ldisc_lock, flags);
28383- ldops->refcount--;
28384+ atomic_dec(&ldops->refcount);
28385 module_put(ldops->owner);
28386 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
28387 }
28388diff -urNp linux-2.6.32.43/drivers/char/virtio_console.c linux-2.6.32.43/drivers/char/virtio_console.c
28389--- linux-2.6.32.43/drivers/char/virtio_console.c 2011-03-27 14:31:47.000000000 -0400
28390+++ linux-2.6.32.43/drivers/char/virtio_console.c 2011-08-05 20:33:55.000000000 -0400
28391@@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *
28392 * virtqueue, so we let the drivers do some boutique early-output thing. */
28393 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
28394 {
28395- virtio_cons.put_chars = put_chars;
28396+ pax_open_kernel();
28397+ *(void **)&virtio_cons.put_chars = put_chars;
28398+ pax_close_kernel();
28399 return hvc_instantiate(0, 0, &virtio_cons);
28400 }
28401
28402@@ -213,11 +215,13 @@ static int __devinit virtcons_probe(stru
28403 out_vq = vqs[1];
28404
28405 /* Start using the new console output. */
28406- virtio_cons.get_chars = get_chars;
28407- virtio_cons.put_chars = put_chars;
28408- virtio_cons.notifier_add = notifier_add_vio;
28409- virtio_cons.notifier_del = notifier_del_vio;
28410- virtio_cons.notifier_hangup = notifier_del_vio;
28411+ pax_open_kernel();
28412+ *(void **)&virtio_cons.get_chars = get_chars;
28413+ *(void **)&virtio_cons.put_chars = put_chars;
28414+ *(void **)&virtio_cons.notifier_add = notifier_add_vio;
28415+ *(void **)&virtio_cons.notifier_del = notifier_del_vio;
28416+ *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
28417+ pax_close_kernel();
28418
28419 /* The first argument of hvc_alloc() is the virtual console number, so
28420 * we use zero. The second argument is the parameter for the
28421diff -urNp linux-2.6.32.43/drivers/char/vt.c linux-2.6.32.43/drivers/char/vt.c
28422--- linux-2.6.32.43/drivers/char/vt.c 2011-03-27 14:31:47.000000000 -0400
28423+++ linux-2.6.32.43/drivers/char/vt.c 2011-04-17 15:56:46.000000000 -0400
28424@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
28425
28426 static void notify_write(struct vc_data *vc, unsigned int unicode)
28427 {
28428- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
28429+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
28430 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
28431 }
28432
28433diff -urNp linux-2.6.32.43/drivers/char/vt_ioctl.c linux-2.6.32.43/drivers/char/vt_ioctl.c
28434--- linux-2.6.32.43/drivers/char/vt_ioctl.c 2011-03-27 14:31:47.000000000 -0400
28435+++ linux-2.6.32.43/drivers/char/vt_ioctl.c 2011-04-17 15:56:46.000000000 -0400
28436@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28437 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
28438 return -EFAULT;
28439
28440- if (!capable(CAP_SYS_TTY_CONFIG))
28441- perm = 0;
28442-
28443 switch (cmd) {
28444 case KDGKBENT:
28445 key_map = key_maps[s];
28446@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28447 val = (i ? K_HOLE : K_NOSUCHMAP);
28448 return put_user(val, &user_kbe->kb_value);
28449 case KDSKBENT:
28450+ if (!capable(CAP_SYS_TTY_CONFIG))
28451+ perm = 0;
28452+
28453 if (!perm)
28454 return -EPERM;
28455+
28456 if (!i && v == K_NOSUCHMAP) {
28457 /* deallocate map */
28458 key_map = key_maps[s];
28459@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28460 int i, j, k;
28461 int ret;
28462
28463- if (!capable(CAP_SYS_TTY_CONFIG))
28464- perm = 0;
28465-
28466 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
28467 if (!kbs) {
28468 ret = -ENOMEM;
28469@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28470 kfree(kbs);
28471 return ((p && *p) ? -EOVERFLOW : 0);
28472 case KDSKBSENT:
28473+ if (!capable(CAP_SYS_TTY_CONFIG))
28474+ perm = 0;
28475+
28476 if (!perm) {
28477 ret = -EPERM;
28478 goto reterr;
28479diff -urNp linux-2.6.32.43/drivers/cpufreq/cpufreq.c linux-2.6.32.43/drivers/cpufreq/cpufreq.c
28480--- linux-2.6.32.43/drivers/cpufreq/cpufreq.c 2011-06-25 12:55:34.000000000 -0400
28481+++ linux-2.6.32.43/drivers/cpufreq/cpufreq.c 2011-06-25 12:56:37.000000000 -0400
28482@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct
28483 complete(&policy->kobj_unregister);
28484 }
28485
28486-static struct sysfs_ops sysfs_ops = {
28487+static const struct sysfs_ops sysfs_ops = {
28488 .show = show,
28489 .store = store,
28490 };
28491diff -urNp linux-2.6.32.43/drivers/cpuidle/sysfs.c linux-2.6.32.43/drivers/cpuidle/sysfs.c
28492--- linux-2.6.32.43/drivers/cpuidle/sysfs.c 2011-03-27 14:31:47.000000000 -0400
28493+++ linux-2.6.32.43/drivers/cpuidle/sysfs.c 2011-04-17 15:56:46.000000000 -0400
28494@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobj
28495 return ret;
28496 }
28497
28498-static struct sysfs_ops cpuidle_sysfs_ops = {
28499+static const struct sysfs_ops cpuidle_sysfs_ops = {
28500 .show = cpuidle_show,
28501 .store = cpuidle_store,
28502 };
28503@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct
28504 return ret;
28505 }
28506
28507-static struct sysfs_ops cpuidle_state_sysfs_ops = {
28508+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
28509 .show = cpuidle_state_show,
28510 };
28511
28512@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpui
28513 .release = cpuidle_state_sysfs_release,
28514 };
28515
28516-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
28517+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
28518 {
28519 kobject_put(&device->kobjs[i]->kobj);
28520 wait_for_completion(&device->kobjs[i]->kobj_unregister);
28521diff -urNp linux-2.6.32.43/drivers/crypto/hifn_795x.c linux-2.6.32.43/drivers/crypto/hifn_795x.c
28522--- linux-2.6.32.43/drivers/crypto/hifn_795x.c 2011-03-27 14:31:47.000000000 -0400
28523+++ linux-2.6.32.43/drivers/crypto/hifn_795x.c 2011-05-16 21:46:57.000000000 -0400
28524@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28525 0xCA, 0x34, 0x2B, 0x2E};
28526 struct scatterlist sg;
28527
28528+ pax_track_stack();
28529+
28530 memset(src, 0, sizeof(src));
28531 memset(ctx.key, 0, sizeof(ctx.key));
28532
28533diff -urNp linux-2.6.32.43/drivers/crypto/padlock-aes.c linux-2.6.32.43/drivers/crypto/padlock-aes.c
28534--- linux-2.6.32.43/drivers/crypto/padlock-aes.c 2011-03-27 14:31:47.000000000 -0400
28535+++ linux-2.6.32.43/drivers/crypto/padlock-aes.c 2011-05-16 21:46:57.000000000 -0400
28536@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm
28537 struct crypto_aes_ctx gen_aes;
28538 int cpu;
28539
28540+ pax_track_stack();
28541+
28542 if (key_len % 8) {
28543 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28544 return -EINVAL;
28545diff -urNp linux-2.6.32.43/drivers/dma/ioat/dma.c linux-2.6.32.43/drivers/dma/ioat/dma.c
28546--- linux-2.6.32.43/drivers/dma/ioat/dma.c 2011-03-27 14:31:47.000000000 -0400
28547+++ linux-2.6.32.43/drivers/dma/ioat/dma.c 2011-04-17 15:56:46.000000000 -0400
28548@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, str
28549 return entry->show(&chan->common, page);
28550 }
28551
28552-struct sysfs_ops ioat_sysfs_ops = {
28553+const struct sysfs_ops ioat_sysfs_ops = {
28554 .show = ioat_attr_show,
28555 };
28556
28557diff -urNp linux-2.6.32.43/drivers/dma/ioat/dma.h linux-2.6.32.43/drivers/dma/ioat/dma.h
28558--- linux-2.6.32.43/drivers/dma/ioat/dma.h 2011-03-27 14:31:47.000000000 -0400
28559+++ linux-2.6.32.43/drivers/dma/ioat/dma.h 2011-04-17 15:56:46.000000000 -0400
28560@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_c
28561 unsigned long *phys_complete);
28562 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
28563 void ioat_kobject_del(struct ioatdma_device *device);
28564-extern struct sysfs_ops ioat_sysfs_ops;
28565+extern const struct sysfs_ops ioat_sysfs_ops;
28566 extern struct ioat_sysfs_entry ioat_version_attr;
28567 extern struct ioat_sysfs_entry ioat_cap_attr;
28568 #endif /* IOATDMA_H */
28569diff -urNp linux-2.6.32.43/drivers/edac/edac_device_sysfs.c linux-2.6.32.43/drivers/edac/edac_device_sysfs.c
28570--- linux-2.6.32.43/drivers/edac/edac_device_sysfs.c 2011-03-27 14:31:47.000000000 -0400
28571+++ linux-2.6.32.43/drivers/edac/edac_device_sysfs.c 2011-04-17 15:56:46.000000000 -0400
28572@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(s
28573 }
28574
28575 /* edac_dev file operations for an 'ctl_info' */
28576-static struct sysfs_ops device_ctl_info_ops = {
28577+static const struct sysfs_ops device_ctl_info_ops = {
28578 .show = edac_dev_ctl_info_show,
28579 .store = edac_dev_ctl_info_store
28580 };
28581@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(s
28582 }
28583
28584 /* edac_dev file operations for an 'instance' */
28585-static struct sysfs_ops device_instance_ops = {
28586+static const struct sysfs_ops device_instance_ops = {
28587 .show = edac_dev_instance_show,
28588 .store = edac_dev_instance_store
28589 };
28590@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(stru
28591 }
28592
28593 /* edac_dev file operations for a 'block' */
28594-static struct sysfs_ops device_block_ops = {
28595+static const struct sysfs_ops device_block_ops = {
28596 .show = edac_dev_block_show,
28597 .store = edac_dev_block_store
28598 };
28599diff -urNp linux-2.6.32.43/drivers/edac/edac_mc_sysfs.c linux-2.6.32.43/drivers/edac/edac_mc_sysfs.c
28600--- linux-2.6.32.43/drivers/edac/edac_mc_sysfs.c 2011-03-27 14:31:47.000000000 -0400
28601+++ linux-2.6.32.43/drivers/edac/edac_mc_sysfs.c 2011-04-17 15:56:46.000000000 -0400
28602@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kob
28603 return -EIO;
28604 }
28605
28606-static struct sysfs_ops csrowfs_ops = {
28607+static const struct sysfs_ops csrowfs_ops = {
28608 .show = csrowdev_show,
28609 .store = csrowdev_store
28610 };
28611@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobje
28612 }
28613
28614 /* Intermediate show/store table */
28615-static struct sysfs_ops mci_ops = {
28616+static const struct sysfs_ops mci_ops = {
28617 .show = mcidev_show,
28618 .store = mcidev_store
28619 };
28620diff -urNp linux-2.6.32.43/drivers/edac/edac_pci_sysfs.c linux-2.6.32.43/drivers/edac/edac_pci_sysfs.c
28621--- linux-2.6.32.43/drivers/edac/edac_pci_sysfs.c 2011-03-27 14:31:47.000000000 -0400
28622+++ linux-2.6.32.43/drivers/edac/edac_pci_sysfs.c 2011-05-04 17:56:20.000000000 -0400
28623@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log
28624 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28625 static int edac_pci_poll_msec = 1000; /* one second workq period */
28626
28627-static atomic_t pci_parity_count = ATOMIC_INIT(0);
28628-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28629+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28630+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28631
28632 static struct kobject *edac_pci_top_main_kobj;
28633 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28634@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(s
28635 }
28636
28637 /* fs_ops table */
28638-static struct sysfs_ops pci_instance_ops = {
28639+static const struct sysfs_ops pci_instance_ops = {
28640 .show = edac_pci_instance_show,
28641 .store = edac_pci_instance_store
28642 };
28643@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct
28644 return -EIO;
28645 }
28646
28647-static struct sysfs_ops edac_pci_sysfs_ops = {
28648+static const struct sysfs_ops edac_pci_sysfs_ops = {
28649 .show = edac_pci_dev_show,
28650 .store = edac_pci_dev_store
28651 };
28652@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(str
28653 edac_printk(KERN_CRIT, EDAC_PCI,
28654 "Signaled System Error on %s\n",
28655 pci_name(dev));
28656- atomic_inc(&pci_nonparity_count);
28657+ atomic_inc_unchecked(&pci_nonparity_count);
28658 }
28659
28660 if (status & (PCI_STATUS_PARITY)) {
28661@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(str
28662 "Master Data Parity Error on %s\n",
28663 pci_name(dev));
28664
28665- atomic_inc(&pci_parity_count);
28666+ atomic_inc_unchecked(&pci_parity_count);
28667 }
28668
28669 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28670@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(str
28671 "Detected Parity Error on %s\n",
28672 pci_name(dev));
28673
28674- atomic_inc(&pci_parity_count);
28675+ atomic_inc_unchecked(&pci_parity_count);
28676 }
28677 }
28678
28679@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(str
28680 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28681 "Signaled System Error on %s\n",
28682 pci_name(dev));
28683- atomic_inc(&pci_nonparity_count);
28684+ atomic_inc_unchecked(&pci_nonparity_count);
28685 }
28686
28687 if (status & (PCI_STATUS_PARITY)) {
28688@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(str
28689 "Master Data Parity Error on "
28690 "%s\n", pci_name(dev));
28691
28692- atomic_inc(&pci_parity_count);
28693+ atomic_inc_unchecked(&pci_parity_count);
28694 }
28695
28696 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28697@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(str
28698 "Detected Parity Error on %s\n",
28699 pci_name(dev));
28700
28701- atomic_inc(&pci_parity_count);
28702+ atomic_inc_unchecked(&pci_parity_count);
28703 }
28704 }
28705 }
28706@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
28707 if (!check_pci_errors)
28708 return;
28709
28710- before_count = atomic_read(&pci_parity_count);
28711+ before_count = atomic_read_unchecked(&pci_parity_count);
28712
28713 /* scan all PCI devices looking for a Parity Error on devices and
28714 * bridges.
28715@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
28716 /* Only if operator has selected panic on PCI Error */
28717 if (edac_pci_get_panic_on_pe()) {
28718 /* If the count is different 'after' from 'before' */
28719- if (before_count != atomic_read(&pci_parity_count))
28720+ if (before_count != atomic_read_unchecked(&pci_parity_count))
28721 panic("EDAC: PCI Parity Error");
28722 }
28723 }
28724diff -urNp linux-2.6.32.43/drivers/firewire/core-card.c linux-2.6.32.43/drivers/firewire/core-card.c
28725--- linux-2.6.32.43/drivers/firewire/core-card.c 2011-03-27 14:31:47.000000000 -0400
28726+++ linux-2.6.32.43/drivers/firewire/core-card.c 2011-08-05 20:33:55.000000000 -0400
28727@@ -569,8 +569,10 @@ void fw_core_remove_card(struct fw_card
28728 mutex_unlock(&card_mutex);
28729
28730 /* Switch off most of the card driver interface. */
28731- dummy_driver.free_iso_context = card->driver->free_iso_context;
28732- dummy_driver.stop_iso = card->driver->stop_iso;
28733+ pax_open_kernel();
28734+ *(void **)&dummy_driver.free_iso_context = card->driver->free_iso_context;
28735+ *(void **)&dummy_driver.stop_iso = card->driver->stop_iso;
28736+ pax_close_kernel();
28737 card->driver = &dummy_driver;
28738
28739 fw_destroy_nodes(card);
28740diff -urNp linux-2.6.32.43/drivers/firewire/core-cdev.c linux-2.6.32.43/drivers/firewire/core-cdev.c
28741--- linux-2.6.32.43/drivers/firewire/core-cdev.c 2011-03-27 14:31:47.000000000 -0400
28742+++ linux-2.6.32.43/drivers/firewire/core-cdev.c 2011-04-17 15:56:46.000000000 -0400
28743@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct clie
28744 int ret;
28745
28746 if ((request->channels == 0 && request->bandwidth == 0) ||
28747- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28748- request->bandwidth < 0)
28749+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28750 return -EINVAL;
28751
28752 r = kmalloc(sizeof(*r), GFP_KERNEL);
28753diff -urNp linux-2.6.32.43/drivers/firewire/core-transaction.c linux-2.6.32.43/drivers/firewire/core-transaction.c
28754--- linux-2.6.32.43/drivers/firewire/core-transaction.c 2011-03-27 14:31:47.000000000 -0400
28755+++ linux-2.6.32.43/drivers/firewire/core-transaction.c 2011-05-16 21:46:57.000000000 -0400
28756@@ -36,6 +36,7 @@
28757 #include <linux/string.h>
28758 #include <linux/timer.h>
28759 #include <linux/types.h>
28760+#include <linux/sched.h>
28761
28762 #include <asm/byteorder.h>
28763
28764@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *c
28765 struct transaction_callback_data d;
28766 struct fw_transaction t;
28767
28768+ pax_track_stack();
28769+
28770 init_completion(&d.done);
28771 d.payload = payload;
28772 fw_send_request(card, &t, tcode, destination_id, generation, speed,
28773diff -urNp linux-2.6.32.43/drivers/firmware/dmi_scan.c linux-2.6.32.43/drivers/firmware/dmi_scan.c
28774--- linux-2.6.32.43/drivers/firmware/dmi_scan.c 2011-03-27 14:31:47.000000000 -0400
28775+++ linux-2.6.32.43/drivers/firmware/dmi_scan.c 2011-04-17 15:56:46.000000000 -0400
28776@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
28777 }
28778 }
28779 else {
28780- /*
28781- * no iounmap() for that ioremap(); it would be a no-op, but
28782- * it's so early in setup that sucker gets confused into doing
28783- * what it shouldn't if we actually call it.
28784- */
28785 p = dmi_ioremap(0xF0000, 0x10000);
28786 if (p == NULL)
28787 goto error;
28788diff -urNp linux-2.6.32.43/drivers/firmware/edd.c linux-2.6.32.43/drivers/firmware/edd.c
28789--- linux-2.6.32.43/drivers/firmware/edd.c 2011-03-27 14:31:47.000000000 -0400
28790+++ linux-2.6.32.43/drivers/firmware/edd.c 2011-04-17 15:56:46.000000000 -0400
28791@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, str
28792 return ret;
28793 }
28794
28795-static struct sysfs_ops edd_attr_ops = {
28796+static const struct sysfs_ops edd_attr_ops = {
28797 .show = edd_attr_show,
28798 };
28799
28800diff -urNp linux-2.6.32.43/drivers/firmware/efivars.c linux-2.6.32.43/drivers/firmware/efivars.c
28801--- linux-2.6.32.43/drivers/firmware/efivars.c 2011-03-27 14:31:47.000000000 -0400
28802+++ linux-2.6.32.43/drivers/firmware/efivars.c 2011-04-17 15:56:46.000000000 -0400
28803@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct
28804 return ret;
28805 }
28806
28807-static struct sysfs_ops efivar_attr_ops = {
28808+static const struct sysfs_ops efivar_attr_ops = {
28809 .show = efivar_attr_show,
28810 .store = efivar_attr_store,
28811 };
28812diff -urNp linux-2.6.32.43/drivers/firmware/iscsi_ibft.c linux-2.6.32.43/drivers/firmware/iscsi_ibft.c
28813--- linux-2.6.32.43/drivers/firmware/iscsi_ibft.c 2011-03-27 14:31:47.000000000 -0400
28814+++ linux-2.6.32.43/drivers/firmware/iscsi_ibft.c 2011-04-17 15:56:46.000000000 -0400
28815@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struc
28816 return ret;
28817 }
28818
28819-static struct sysfs_ops ibft_attr_ops = {
28820+static const struct sysfs_ops ibft_attr_ops = {
28821 .show = ibft_show_attribute,
28822 };
28823
28824diff -urNp linux-2.6.32.43/drivers/firmware/memmap.c linux-2.6.32.43/drivers/firmware/memmap.c
28825--- linux-2.6.32.43/drivers/firmware/memmap.c 2011-03-27 14:31:47.000000000 -0400
28826+++ linux-2.6.32.43/drivers/firmware/memmap.c 2011-04-17 15:56:46.000000000 -0400
28827@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
28828 NULL
28829 };
28830
28831-static struct sysfs_ops memmap_attr_ops = {
28832+static const struct sysfs_ops memmap_attr_ops = {
28833 .show = memmap_attr_show,
28834 };
28835
28836diff -urNp linux-2.6.32.43/drivers/gpio/vr41xx_giu.c linux-2.6.32.43/drivers/gpio/vr41xx_giu.c
28837--- linux-2.6.32.43/drivers/gpio/vr41xx_giu.c 2011-03-27 14:31:47.000000000 -0400
28838+++ linux-2.6.32.43/drivers/gpio/vr41xx_giu.c 2011-05-04 17:56:28.000000000 -0400
28839@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28840 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28841 maskl, pendl, maskh, pendh);
28842
28843- atomic_inc(&irq_err_count);
28844+ atomic_inc_unchecked(&irq_err_count);
28845
28846 return -EINVAL;
28847 }
28848diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.32.43/drivers/gpu/drm/drm_crtc_helper.c
28849--- linux-2.6.32.43/drivers/gpu/drm/drm_crtc_helper.c 2011-03-27 14:31:47.000000000 -0400
28850+++ linux-2.6.32.43/drivers/gpu/drm/drm_crtc_helper.c 2011-05-16 21:46:57.000000000 -0400
28851@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct d
28852 struct drm_crtc *tmp;
28853 int crtc_mask = 1;
28854
28855- WARN(!crtc, "checking null crtc?");
28856+ BUG_ON(!crtc);
28857
28858 dev = crtc->dev;
28859
28860@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm
28861
28862 adjusted_mode = drm_mode_duplicate(dev, mode);
28863
28864+ pax_track_stack();
28865+
28866 crtc->enabled = drm_helper_crtc_in_use(crtc);
28867
28868 if (!crtc->enabled)
28869diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_drv.c linux-2.6.32.43/drivers/gpu/drm/drm_drv.c
28870--- linux-2.6.32.43/drivers/gpu/drm/drm_drv.c 2011-03-27 14:31:47.000000000 -0400
28871+++ linux-2.6.32.43/drivers/gpu/drm/drm_drv.c 2011-04-17 15:56:46.000000000 -0400
28872@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struc
28873 char *kdata = NULL;
28874
28875 atomic_inc(&dev->ioctl_count);
28876- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28877+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28878 ++file_priv->ioctl_count;
28879
28880 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28881diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_fops.c linux-2.6.32.43/drivers/gpu/drm/drm_fops.c
28882--- linux-2.6.32.43/drivers/gpu/drm/drm_fops.c 2011-03-27 14:31:47.000000000 -0400
28883+++ linux-2.6.32.43/drivers/gpu/drm/drm_fops.c 2011-04-17 15:56:46.000000000 -0400
28884@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device *
28885 }
28886
28887 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28888- atomic_set(&dev->counts[i], 0);
28889+ atomic_set_unchecked(&dev->counts[i], 0);
28890
28891 dev->sigdata.lock = NULL;
28892
28893@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct
28894
28895 retcode = drm_open_helper(inode, filp, dev);
28896 if (!retcode) {
28897- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28898+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28899 spin_lock(&dev->count_lock);
28900- if (!dev->open_count++) {
28901+ if (local_inc_return(&dev->open_count) == 1) {
28902 spin_unlock(&dev->count_lock);
28903 retcode = drm_setup(dev);
28904 goto out;
28905@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, str
28906
28907 lock_kernel();
28908
28909- DRM_DEBUG("open_count = %d\n", dev->open_count);
28910+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28911
28912 if (dev->driver->preclose)
28913 dev->driver->preclose(dev, file_priv);
28914@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, str
28915 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28916 task_pid_nr(current),
28917 (long)old_encode_dev(file_priv->minor->device),
28918- dev->open_count);
28919+ local_read(&dev->open_count));
28920
28921 /* if the master has gone away we can't do anything with the lock */
28922 if (file_priv->minor->master)
28923@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, str
28924 * End inline drm_release
28925 */
28926
28927- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28928+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28929 spin_lock(&dev->count_lock);
28930- if (!--dev->open_count) {
28931+ if (local_dec_and_test(&dev->open_count)) {
28932 if (atomic_read(&dev->ioctl_count)) {
28933 DRM_ERROR("Device busy: %d\n",
28934 atomic_read(&dev->ioctl_count));
28935diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_gem.c linux-2.6.32.43/drivers/gpu/drm/drm_gem.c
28936--- linux-2.6.32.43/drivers/gpu/drm/drm_gem.c 2011-03-27 14:31:47.000000000 -0400
28937+++ linux-2.6.32.43/drivers/gpu/drm/drm_gem.c 2011-04-17 15:56:46.000000000 -0400
28938@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
28939 spin_lock_init(&dev->object_name_lock);
28940 idr_init(&dev->object_name_idr);
28941 atomic_set(&dev->object_count, 0);
28942- atomic_set(&dev->object_memory, 0);
28943+ atomic_set_unchecked(&dev->object_memory, 0);
28944 atomic_set(&dev->pin_count, 0);
28945- atomic_set(&dev->pin_memory, 0);
28946+ atomic_set_unchecked(&dev->pin_memory, 0);
28947 atomic_set(&dev->gtt_count, 0);
28948- atomic_set(&dev->gtt_memory, 0);
28949+ atomic_set_unchecked(&dev->gtt_memory, 0);
28950
28951 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
28952 if (!mm) {
28953@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *
28954 goto fput;
28955 }
28956 atomic_inc(&dev->object_count);
28957- atomic_add(obj->size, &dev->object_memory);
28958+ atomic_add_unchecked(obj->size, &dev->object_memory);
28959 return obj;
28960 fput:
28961 fput(obj->filp);
28962@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
28963
28964 fput(obj->filp);
28965 atomic_dec(&dev->object_count);
28966- atomic_sub(obj->size, &dev->object_memory);
28967+ atomic_sub_unchecked(obj->size, &dev->object_memory);
28968 kfree(obj);
28969 }
28970 EXPORT_SYMBOL(drm_gem_object_free);
28971diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_info.c linux-2.6.32.43/drivers/gpu/drm/drm_info.c
28972--- linux-2.6.32.43/drivers/gpu/drm/drm_info.c 2011-03-27 14:31:47.000000000 -0400
28973+++ linux-2.6.32.43/drivers/gpu/drm/drm_info.c 2011-04-17 15:56:46.000000000 -0400
28974@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
28975 struct drm_local_map *map;
28976 struct drm_map_list *r_list;
28977
28978- /* Hardcoded from _DRM_FRAME_BUFFER,
28979- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28980- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28981- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28982+ static const char * const types[] = {
28983+ [_DRM_FRAME_BUFFER] = "FB",
28984+ [_DRM_REGISTERS] = "REG",
28985+ [_DRM_SHM] = "SHM",
28986+ [_DRM_AGP] = "AGP",
28987+ [_DRM_SCATTER_GATHER] = "SG",
28988+ [_DRM_CONSISTENT] = "PCI",
28989+ [_DRM_GEM] = "GEM" };
28990 const char *type;
28991 int i;
28992
28993@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
28994 map = r_list->map;
28995 if (!map)
28996 continue;
28997- if (map->type < 0 || map->type > 5)
28998+ if (map->type >= ARRAY_SIZE(types))
28999 type = "??";
29000 else
29001 type = types[map->type];
29002@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file
29003 struct drm_device *dev = node->minor->dev;
29004
29005 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
29006- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
29007+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
29008 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
29009- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
29010- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
29011+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
29012+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
29013 seq_printf(m, "%d gtt total\n", dev->gtt_total);
29014 return 0;
29015 }
29016@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, voi
29017 mutex_lock(&dev->struct_mutex);
29018 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
29019 atomic_read(&dev->vma_count),
29020+#ifdef CONFIG_GRKERNSEC_HIDESYM
29021+ NULL, 0);
29022+#else
29023 high_memory, (u64)virt_to_phys(high_memory));
29024+#endif
29025
29026 list_for_each_entry(pt, &dev->vmalist, head) {
29027 vma = pt->vma;
29028@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, voi
29029 continue;
29030 seq_printf(m,
29031 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
29032- pt->pid, vma->vm_start, vma->vm_end,
29033+ pt->pid,
29034+#ifdef CONFIG_GRKERNSEC_HIDESYM
29035+ 0, 0,
29036+#else
29037+ vma->vm_start, vma->vm_end,
29038+#endif
29039 vma->vm_flags & VM_READ ? 'r' : '-',
29040 vma->vm_flags & VM_WRITE ? 'w' : '-',
29041 vma->vm_flags & VM_EXEC ? 'x' : '-',
29042 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29043 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29044 vma->vm_flags & VM_IO ? 'i' : '-',
29045+#ifdef CONFIG_GRKERNSEC_HIDESYM
29046+ 0);
29047+#else
29048 vma->vm_pgoff);
29049+#endif
29050
29051 #if defined(__i386__)
29052 pgprot = pgprot_val(vma->vm_page_prot);
29053diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_ioctl.c linux-2.6.32.43/drivers/gpu/drm/drm_ioctl.c
29054--- linux-2.6.32.43/drivers/gpu/drm/drm_ioctl.c 2011-03-27 14:31:47.000000000 -0400
29055+++ linux-2.6.32.43/drivers/gpu/drm/drm_ioctl.c 2011-04-17 15:56:46.000000000 -0400
29056@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev,
29057 stats->data[i].value =
29058 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29059 else
29060- stats->data[i].value = atomic_read(&dev->counts[i]);
29061+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29062 stats->data[i].type = dev->types[i];
29063 }
29064
29065diff -urNp linux-2.6.32.43/drivers/gpu/drm/drm_lock.c linux-2.6.32.43/drivers/gpu/drm/drm_lock.c
29066--- linux-2.6.32.43/drivers/gpu/drm/drm_lock.c 2011-03-27 14:31:47.000000000 -0400
29067+++ linux-2.6.32.43/drivers/gpu/drm/drm_lock.c 2011-04-17 15:56:46.000000000 -0400
29068@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, voi
29069 if (drm_lock_take(&master->lock, lock->context)) {
29070 master->lock.file_priv = file_priv;
29071 master->lock.lock_time = jiffies;
29072- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29073+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29074 break; /* Got lock */
29075 }
29076
29077@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, v
29078 return -EINVAL;
29079 }
29080
29081- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29082+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29083
29084 /* kernel_context_switch isn't used by any of the x86 drm
29085 * modules but is required by the Sparc driver.
29086diff -urNp linux-2.6.32.43/drivers/gpu/drm/i810/i810_dma.c linux-2.6.32.43/drivers/gpu/drm/i810/i810_dma.c
29087--- linux-2.6.32.43/drivers/gpu/drm/i810/i810_dma.c 2011-03-27 14:31:47.000000000 -0400
29088+++ linux-2.6.32.43/drivers/gpu/drm/i810/i810_dma.c 2011-04-17 15:56:46.000000000 -0400
29089@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_de
29090 dma->buflist[vertex->idx],
29091 vertex->discard, vertex->used);
29092
29093- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29094- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29095+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29096+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29097 sarea_priv->last_enqueue = dev_priv->counter - 1;
29098 sarea_priv->last_dispatch = (int)hw_status[5];
29099
29100@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device
29101 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29102 mc->last_render);
29103
29104- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29105- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29106+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29107+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29108 sarea_priv->last_enqueue = dev_priv->counter - 1;
29109 sarea_priv->last_dispatch = (int)hw_status[5];
29110
29111diff -urNp linux-2.6.32.43/drivers/gpu/drm/i810/i810_drv.h linux-2.6.32.43/drivers/gpu/drm/i810/i810_drv.h
29112--- linux-2.6.32.43/drivers/gpu/drm/i810/i810_drv.h 2011-03-27 14:31:47.000000000 -0400
29113+++ linux-2.6.32.43/drivers/gpu/drm/i810/i810_drv.h 2011-05-04 17:56:28.000000000 -0400
29114@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29115 int page_flipping;
29116
29117 wait_queue_head_t irq_queue;
29118- atomic_t irq_received;
29119- atomic_t irq_emitted;
29120+ atomic_unchecked_t irq_received;
29121+ atomic_unchecked_t irq_emitted;
29122
29123 int front_offset;
29124 } drm_i810_private_t;
29125diff -urNp linux-2.6.32.43/drivers/gpu/drm/i830/i830_drv.h linux-2.6.32.43/drivers/gpu/drm/i830/i830_drv.h
29126--- linux-2.6.32.43/drivers/gpu/drm/i830/i830_drv.h 2011-03-27 14:31:47.000000000 -0400
29127+++ linux-2.6.32.43/drivers/gpu/drm/i830/i830_drv.h 2011-05-04 17:56:28.000000000 -0400
29128@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
29129 int page_flipping;
29130
29131 wait_queue_head_t irq_queue;
29132- atomic_t irq_received;
29133- atomic_t irq_emitted;
29134+ atomic_unchecked_t irq_received;
29135+ atomic_unchecked_t irq_emitted;
29136
29137 int use_mi_batchbuffer_start;
29138
29139diff -urNp linux-2.6.32.43/drivers/gpu/drm/i830/i830_irq.c linux-2.6.32.43/drivers/gpu/drm/i830/i830_irq.c
29140--- linux-2.6.32.43/drivers/gpu/drm/i830/i830_irq.c 2011-03-27 14:31:47.000000000 -0400
29141+++ linux-2.6.32.43/drivers/gpu/drm/i830/i830_irq.c 2011-05-04 17:56:28.000000000 -0400
29142@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_
29143
29144 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
29145
29146- atomic_inc(&dev_priv->irq_received);
29147+ atomic_inc_unchecked(&dev_priv->irq_received);
29148 wake_up_interruptible(&dev_priv->irq_queue);
29149
29150 return IRQ_HANDLED;
29151@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_devi
29152
29153 DRM_DEBUG("%s\n", __func__);
29154
29155- atomic_inc(&dev_priv->irq_emitted);
29156+ atomic_inc_unchecked(&dev_priv->irq_emitted);
29157
29158 BEGIN_LP_RING(2);
29159 OUT_RING(0);
29160 OUT_RING(GFX_OP_USER_INTERRUPT);
29161 ADVANCE_LP_RING();
29162
29163- return atomic_read(&dev_priv->irq_emitted);
29164+ return atomic_read_unchecked(&dev_priv->irq_emitted);
29165 }
29166
29167 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
29168@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_devi
29169
29170 DRM_DEBUG("%s\n", __func__);
29171
29172- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
29173+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
29174 return 0;
29175
29176 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
29177@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_devi
29178
29179 for (;;) {
29180 __set_current_state(TASK_INTERRUPTIBLE);
29181- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
29182+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
29183 break;
29184 if ((signed)(end - jiffies) <= 0) {
29185 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
29186@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct d
29187 I830_WRITE16(I830REG_HWSTAM, 0xffff);
29188 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
29189 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
29190- atomic_set(&dev_priv->irq_received, 0);
29191- atomic_set(&dev_priv->irq_emitted, 0);
29192+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29193+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
29194 init_waitqueue_head(&dev_priv->irq_queue);
29195 }
29196
29197diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7017.c
29198--- linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7017.c 2011-03-27 14:31:47.000000000 -0400
29199+++ linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7017.c 2011-04-17 15:56:46.000000000 -0400
29200@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_
29201 }
29202 }
29203
29204-struct intel_dvo_dev_ops ch7017_ops = {
29205+const struct intel_dvo_dev_ops ch7017_ops = {
29206 .init = ch7017_init,
29207 .detect = ch7017_detect,
29208 .mode_valid = ch7017_mode_valid,
29209diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7xxx.c
29210--- linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-03-27 14:31:47.000000000 -0400
29211+++ linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-04-17 15:56:46.000000000 -0400
29212@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_
29213 }
29214 }
29215
29216-struct intel_dvo_dev_ops ch7xxx_ops = {
29217+const struct intel_dvo_dev_ops ch7xxx_ops = {
29218 .init = ch7xxx_init,
29219 .detect = ch7xxx_detect,
29220 .mode_valid = ch7xxx_mode_valid,
29221diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/dvo.h linux-2.6.32.43/drivers/gpu/drm/i915/dvo.h
29222--- linux-2.6.32.43/drivers/gpu/drm/i915/dvo.h 2011-03-27 14:31:47.000000000 -0400
29223+++ linux-2.6.32.43/drivers/gpu/drm/i915/dvo.h 2011-04-17 15:56:46.000000000 -0400
29224@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
29225 *
29226 * \return singly-linked list of modes or NULL if no modes found.
29227 */
29228- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
29229+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
29230
29231 /**
29232 * Clean up driver-specific bits of the output
29233 */
29234- void (*destroy) (struct intel_dvo_device *dvo);
29235+ void (* const destroy) (struct intel_dvo_device *dvo);
29236
29237 /**
29238 * Debugging hook to dump device registers to log file
29239 */
29240- void (*dump_regs)(struct intel_dvo_device *dvo);
29241+ void (* const dump_regs)(struct intel_dvo_device *dvo);
29242 };
29243
29244-extern struct intel_dvo_dev_ops sil164_ops;
29245-extern struct intel_dvo_dev_ops ch7xxx_ops;
29246-extern struct intel_dvo_dev_ops ivch_ops;
29247-extern struct intel_dvo_dev_ops tfp410_ops;
29248-extern struct intel_dvo_dev_ops ch7017_ops;
29249+extern const struct intel_dvo_dev_ops sil164_ops;
29250+extern const struct intel_dvo_dev_ops ch7xxx_ops;
29251+extern const struct intel_dvo_dev_ops ivch_ops;
29252+extern const struct intel_dvo_dev_ops tfp410_ops;
29253+extern const struct intel_dvo_dev_ops ch7017_ops;
29254
29255 #endif /* _INTEL_DVO_H */
29256diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ivch.c
29257--- linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ivch.c 2011-03-27 14:31:47.000000000 -0400
29258+++ linux-2.6.32.43/drivers/gpu/drm/i915/dvo_ivch.c 2011-04-17 15:56:46.000000000 -0400
29259@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dv
29260 }
29261 }
29262
29263-struct intel_dvo_dev_ops ivch_ops= {
29264+const struct intel_dvo_dev_ops ivch_ops= {
29265 .init = ivch_init,
29266 .dpms = ivch_dpms,
29267 .save = ivch_save,
29268diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.32.43/drivers/gpu/drm/i915/dvo_sil164.c
29269--- linux-2.6.32.43/drivers/gpu/drm/i915/dvo_sil164.c 2011-03-27 14:31:47.000000000 -0400
29270+++ linux-2.6.32.43/drivers/gpu/drm/i915/dvo_sil164.c 2011-04-17 15:56:46.000000000 -0400
29271@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_
29272 }
29273 }
29274
29275-struct intel_dvo_dev_ops sil164_ops = {
29276+const struct intel_dvo_dev_ops sil164_ops = {
29277 .init = sil164_init,
29278 .detect = sil164_detect,
29279 .mode_valid = sil164_mode_valid,
29280diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.32.43/drivers/gpu/drm/i915/dvo_tfp410.c
29281--- linux-2.6.32.43/drivers/gpu/drm/i915/dvo_tfp410.c 2011-03-27 14:31:47.000000000 -0400
29282+++ linux-2.6.32.43/drivers/gpu/drm/i915/dvo_tfp410.c 2011-04-17 15:56:46.000000000 -0400
29283@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_
29284 }
29285 }
29286
29287-struct intel_dvo_dev_ops tfp410_ops = {
29288+const struct intel_dvo_dev_ops tfp410_ops = {
29289 .init = tfp410_init,
29290 .detect = tfp410_detect,
29291 .mode_valid = tfp410_mode_valid,
29292diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.32.43/drivers/gpu/drm/i915/i915_debugfs.c
29293--- linux-2.6.32.43/drivers/gpu/drm/i915/i915_debugfs.c 2011-03-27 14:31:47.000000000 -0400
29294+++ linux-2.6.32.43/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-04 17:56:28.000000000 -0400
29295@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct se
29296 I915_READ(GTIMR));
29297 }
29298 seq_printf(m, "Interrupts received: %d\n",
29299- atomic_read(&dev_priv->irq_received));
29300+ atomic_read_unchecked(&dev_priv->irq_received));
29301 if (dev_priv->hw_status_page != NULL) {
29302 seq_printf(m, "Current sequence: %d\n",
29303 i915_get_gem_seqno(dev));
29304diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.c linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.c
29305--- linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.c 2011-03-27 14:31:47.000000000 -0400
29306+++ linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.c 2011-04-17 15:56:46.000000000 -0400
29307@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
29308 return i915_resume(dev);
29309 }
29310
29311-static struct vm_operations_struct i915_gem_vm_ops = {
29312+static const struct vm_operations_struct i915_gem_vm_ops = {
29313 .fault = i915_gem_fault,
29314 .open = drm_gem_vm_open,
29315 .close = drm_gem_vm_close,
29316diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.h linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.h
29317--- linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.h 2011-03-27 14:31:47.000000000 -0400
29318+++ linux-2.6.32.43/drivers/gpu/drm/i915/i915_drv.h 2011-08-05 20:33:55.000000000 -0400
29319@@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
29320 /* display clock increase/decrease */
29321 /* pll clock increase/decrease */
29322 /* clock gating init */
29323-};
29324+} __no_const;
29325
29326 typedef struct drm_i915_private {
29327 struct drm_device *dev;
29328@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
29329 int page_flipping;
29330
29331 wait_queue_head_t irq_queue;
29332- atomic_t irq_received;
29333+ atomic_unchecked_t irq_received;
29334 /** Protects user_irq_refcount and irq_mask_reg */
29335 spinlock_t user_irq_lock;
29336 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
29337diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/i915_gem.c linux-2.6.32.43/drivers/gpu/drm/i915/i915_gem.c
29338--- linux-2.6.32.43/drivers/gpu/drm/i915/i915_gem.c 2011-03-27 14:31:47.000000000 -0400
29339+++ linux-2.6.32.43/drivers/gpu/drm/i915/i915_gem.c 2011-04-17 15:56:46.000000000 -0400
29340@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_d
29341
29342 args->aper_size = dev->gtt_total;
29343 args->aper_available_size = (args->aper_size -
29344- atomic_read(&dev->pin_memory));
29345+ atomic_read_unchecked(&dev->pin_memory));
29346
29347 return 0;
29348 }
29349@@ -492,6 +492,11 @@ i915_gem_pread_ioctl(struct drm_device *
29350 return -EINVAL;
29351 }
29352
29353+ if (!access_ok(VERIFY_WRITE, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
29354+ drm_gem_object_unreference(obj);
29355+ return -EFAULT;
29356+ }
29357+
29358 if (i915_gem_object_needs_bit17_swizzle(obj)) {
29359 ret = i915_gem_shmem_pread_slow(dev, obj, args, file_priv);
29360 } else {
29361@@ -965,6 +970,11 @@ i915_gem_pwrite_ioctl(struct drm_device
29362 return -EINVAL;
29363 }
29364
29365+ if (!access_ok(VERIFY_READ, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
29366+ drm_gem_object_unreference(obj);
29367+ return -EFAULT;
29368+ }
29369+
29370 /* We can only do the GTT pwrite on untiled buffers, as otherwise
29371 * it would end up going through the fenced access, and we'll get
29372 * different detiling behavior between reading and writing.
29373@@ -2054,7 +2064,7 @@ i915_gem_object_unbind(struct drm_gem_ob
29374
29375 if (obj_priv->gtt_space) {
29376 atomic_dec(&dev->gtt_count);
29377- atomic_sub(obj->size, &dev->gtt_memory);
29378+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
29379
29380 drm_mm_put_block(obj_priv->gtt_space);
29381 obj_priv->gtt_space = NULL;
29382@@ -2697,7 +2707,7 @@ i915_gem_object_bind_to_gtt(struct drm_g
29383 goto search_free;
29384 }
29385 atomic_inc(&dev->gtt_count);
29386- atomic_add(obj->size, &dev->gtt_memory);
29387+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
29388
29389 /* Assert that the object is not currently in any GPU domain. As it
29390 * wasn't in the GTT, there shouldn't be any way it could have been in
29391@@ -3751,9 +3761,9 @@ i915_gem_execbuffer(struct drm_device *d
29392 "%d/%d gtt bytes\n",
29393 atomic_read(&dev->object_count),
29394 atomic_read(&dev->pin_count),
29395- atomic_read(&dev->object_memory),
29396- atomic_read(&dev->pin_memory),
29397- atomic_read(&dev->gtt_memory),
29398+ atomic_read_unchecked(&dev->object_memory),
29399+ atomic_read_unchecked(&dev->pin_memory),
29400+ atomic_read_unchecked(&dev->gtt_memory),
29401 dev->gtt_total);
29402 }
29403 goto err;
29404@@ -3985,7 +3995,7 @@ i915_gem_object_pin(struct drm_gem_objec
29405 */
29406 if (obj_priv->pin_count == 1) {
29407 atomic_inc(&dev->pin_count);
29408- atomic_add(obj->size, &dev->pin_memory);
29409+ atomic_add_unchecked(obj->size, &dev->pin_memory);
29410 if (!obj_priv->active &&
29411 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
29412 !list_empty(&obj_priv->list))
29413@@ -4018,7 +4028,7 @@ i915_gem_object_unpin(struct drm_gem_obj
29414 list_move_tail(&obj_priv->list,
29415 &dev_priv->mm.inactive_list);
29416 atomic_dec(&dev->pin_count);
29417- atomic_sub(obj->size, &dev->pin_memory);
29418+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
29419 }
29420 i915_verify_inactive(dev, __FILE__, __LINE__);
29421 }
29422diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/i915_irq.c linux-2.6.32.43/drivers/gpu/drm/i915/i915_irq.c
29423--- linux-2.6.32.43/drivers/gpu/drm/i915/i915_irq.c 2011-03-27 14:31:47.000000000 -0400
29424+++ linux-2.6.32.43/drivers/gpu/drm/i915/i915_irq.c 2011-05-04 17:56:28.000000000 -0400
29425@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29426 int irq_received;
29427 int ret = IRQ_NONE;
29428
29429- atomic_inc(&dev_priv->irq_received);
29430+ atomic_inc_unchecked(&dev_priv->irq_received);
29431
29432 if (IS_IGDNG(dev))
29433 return igdng_irq_handler(dev);
29434@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct d
29435 {
29436 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29437
29438- atomic_set(&dev_priv->irq_received, 0);
29439+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29440
29441 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29442 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29443diff -urNp linux-2.6.32.43/drivers/gpu/drm/i915/intel_sdvo.c linux-2.6.32.43/drivers/gpu/drm/i915/intel_sdvo.c
29444--- linux-2.6.32.43/drivers/gpu/drm/i915/intel_sdvo.c 2011-03-27 14:31:47.000000000 -0400
29445+++ linux-2.6.32.43/drivers/gpu/drm/i915/intel_sdvo.c 2011-08-05 20:33:55.000000000 -0400
29446@@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *
29447 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
29448
29449 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
29450- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
29451+ pax_open_kernel();
29452+ *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
29453+ pax_close_kernel();
29454
29455 /* Read the regs to test if we can talk to the device */
29456 for (i = 0; i < 0x40; i++) {
29457diff -urNp linux-2.6.32.43/drivers/gpu/drm/mga/mga_drv.h linux-2.6.32.43/drivers/gpu/drm/mga/mga_drv.h
29458--- linux-2.6.32.43/drivers/gpu/drm/mga/mga_drv.h 2011-03-27 14:31:47.000000000 -0400
29459+++ linux-2.6.32.43/drivers/gpu/drm/mga/mga_drv.h 2011-05-04 17:56:28.000000000 -0400
29460@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29461 u32 clear_cmd;
29462 u32 maccess;
29463
29464- atomic_t vbl_received; /**< Number of vblanks received. */
29465+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29466 wait_queue_head_t fence_queue;
29467- atomic_t last_fence_retired;
29468+ atomic_unchecked_t last_fence_retired;
29469 u32 next_fence_to_post;
29470
29471 unsigned int fb_cpp;
29472diff -urNp linux-2.6.32.43/drivers/gpu/drm/mga/mga_irq.c linux-2.6.32.43/drivers/gpu/drm/mga/mga_irq.c
29473--- linux-2.6.32.43/drivers/gpu/drm/mga/mga_irq.c 2011-03-27 14:31:47.000000000 -0400
29474+++ linux-2.6.32.43/drivers/gpu/drm/mga/mga_irq.c 2011-05-04 17:56:28.000000000 -0400
29475@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29476 if (crtc != 0)
29477 return 0;
29478
29479- return atomic_read(&dev_priv->vbl_received);
29480+ return atomic_read_unchecked(&dev_priv->vbl_received);
29481 }
29482
29483
29484@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29485 /* VBLANK interrupt */
29486 if (status & MGA_VLINEPEN) {
29487 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29488- atomic_inc(&dev_priv->vbl_received);
29489+ atomic_inc_unchecked(&dev_priv->vbl_received);
29490 drm_handle_vblank(dev, 0);
29491 handled = 1;
29492 }
29493@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29494 MGA_WRITE(MGA_PRIMEND, prim_end);
29495 }
29496
29497- atomic_inc(&dev_priv->last_fence_retired);
29498+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
29499 DRM_WAKEUP(&dev_priv->fence_queue);
29500 handled = 1;
29501 }
29502@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_dev
29503 * using fences.
29504 */
29505 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29506- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29507+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29508 - *sequence) <= (1 << 23)));
29509
29510 *sequence = cur_fence;
29511diff -urNp linux-2.6.32.43/drivers/gpu/drm/r128/r128_cce.c linux-2.6.32.43/drivers/gpu/drm/r128/r128_cce.c
29512--- linux-2.6.32.43/drivers/gpu/drm/r128/r128_cce.c 2011-03-27 14:31:47.000000000 -0400
29513+++ linux-2.6.32.43/drivers/gpu/drm/r128/r128_cce.c 2011-05-04 17:56:28.000000000 -0400
29514@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29515
29516 /* GH: Simple idle check.
29517 */
29518- atomic_set(&dev_priv->idle_count, 0);
29519+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29520
29521 /* We don't support anything other than bus-mastering ring mode,
29522 * but the ring can be in either AGP or PCI space for the ring
29523diff -urNp linux-2.6.32.43/drivers/gpu/drm/r128/r128_drv.h linux-2.6.32.43/drivers/gpu/drm/r128/r128_drv.h
29524--- linux-2.6.32.43/drivers/gpu/drm/r128/r128_drv.h 2011-03-27 14:31:47.000000000 -0400
29525+++ linux-2.6.32.43/drivers/gpu/drm/r128/r128_drv.h 2011-05-04 17:56:28.000000000 -0400
29526@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29527 int is_pci;
29528 unsigned long cce_buffers_offset;
29529
29530- atomic_t idle_count;
29531+ atomic_unchecked_t idle_count;
29532
29533 int page_flipping;
29534 int current_page;
29535 u32 crtc_offset;
29536 u32 crtc_offset_cntl;
29537
29538- atomic_t vbl_received;
29539+ atomic_unchecked_t vbl_received;
29540
29541 u32 color_fmt;
29542 unsigned int front_offset;
29543diff -urNp linux-2.6.32.43/drivers/gpu/drm/r128/r128_irq.c linux-2.6.32.43/drivers/gpu/drm/r128/r128_irq.c
29544--- linux-2.6.32.43/drivers/gpu/drm/r128/r128_irq.c 2011-03-27 14:31:47.000000000 -0400
29545+++ linux-2.6.32.43/drivers/gpu/drm/r128/r128_irq.c 2011-05-04 17:56:28.000000000 -0400
29546@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29547 if (crtc != 0)
29548 return 0;
29549
29550- return atomic_read(&dev_priv->vbl_received);
29551+ return atomic_read_unchecked(&dev_priv->vbl_received);
29552 }
29553
29554 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29555@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29556 /* VBLANK interrupt */
29557 if (status & R128_CRTC_VBLANK_INT) {
29558 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29559- atomic_inc(&dev_priv->vbl_received);
29560+ atomic_inc_unchecked(&dev_priv->vbl_received);
29561 drm_handle_vblank(dev, 0);
29562 return IRQ_HANDLED;
29563 }
29564diff -urNp linux-2.6.32.43/drivers/gpu/drm/r128/r128_state.c linux-2.6.32.43/drivers/gpu/drm/r128/r128_state.c
29565--- linux-2.6.32.43/drivers/gpu/drm/r128/r128_state.c 2011-03-27 14:31:47.000000000 -0400
29566+++ linux-2.6.32.43/drivers/gpu/drm/r128/r128_state.c 2011-05-04 17:56:28.000000000 -0400
29567@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_priv
29568
29569 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
29570 {
29571- if (atomic_read(&dev_priv->idle_count) == 0) {
29572+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
29573 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29574 } else {
29575- atomic_set(&dev_priv->idle_count, 0);
29576+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29577 }
29578 }
29579
29580diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/atom.c linux-2.6.32.43/drivers/gpu/drm/radeon/atom.c
29581--- linux-2.6.32.43/drivers/gpu/drm/radeon/atom.c 2011-05-10 22:12:01.000000000 -0400
29582+++ linux-2.6.32.43/drivers/gpu/drm/radeon/atom.c 2011-05-16 21:46:57.000000000 -0400
29583@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct c
29584 char name[512];
29585 int i;
29586
29587+ pax_track_stack();
29588+
29589 ctx->card = card;
29590 ctx->bios = bios;
29591
29592diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.32.43/drivers/gpu/drm/radeon/mkregtable.c
29593--- linux-2.6.32.43/drivers/gpu/drm/radeon/mkregtable.c 2011-03-27 14:31:47.000000000 -0400
29594+++ linux-2.6.32.43/drivers/gpu/drm/radeon/mkregtable.c 2011-04-17 15:56:46.000000000 -0400
29595@@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
29596 regex_t mask_rex;
29597 regmatch_t match[4];
29598 char buf[1024];
29599- size_t end;
29600+ long end;
29601 int len;
29602 int done = 0;
29603 int r;
29604 unsigned o;
29605 struct offset *offset;
29606 char last_reg_s[10];
29607- int last_reg;
29608+ unsigned long last_reg;
29609
29610 if (regcomp
29611 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29612diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_atombios.c
29613--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_atombios.c 2011-03-27 14:31:47.000000000 -0400
29614+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-16 21:46:57.000000000 -0400
29615@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from
29616 bool linkb;
29617 struct radeon_i2c_bus_rec ddc_bus;
29618
29619+ pax_track_stack();
29620+
29621 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
29622
29623 if (data_offset == 0)
29624@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_o
29625 }
29626 }
29627
29628-struct bios_connector {
29629+static struct bios_connector {
29630 bool valid;
29631 uint16_t line_mux;
29632 uint16_t devices;
29633 int connector_type;
29634 struct radeon_i2c_bus_rec ddc_bus;
29635-};
29636+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
29637
29638 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
29639 drm_device
29640@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from
29641 uint8_t dac;
29642 union atom_supported_devices *supported_devices;
29643 int i, j;
29644- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
29645
29646 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
29647
29648diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_display.c
29649--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_display.c 2011-03-27 14:31:47.000000000 -0400
29650+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_display.c 2011-04-17 15:56:46.000000000 -0400
29651@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pl
29652
29653 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
29654 error = freq - current_freq;
29655- error = error < 0 ? 0xffffffff : error;
29656+ error = (int32_t)error < 0 ? 0xffffffff : error;
29657 } else
29658 error = abs(current_freq - freq);
29659 vco_diff = abs(vco - best_vco);
29660diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_drv.h
29661--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_drv.h 2011-03-27 14:31:47.000000000 -0400
29662+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-04 17:56:28.000000000 -0400
29663@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
29664
29665 /* SW interrupt */
29666 wait_queue_head_t swi_queue;
29667- atomic_t swi_emitted;
29668+ atomic_unchecked_t swi_emitted;
29669 int vblank_crtc;
29670 uint32_t irq_enable_reg;
29671 uint32_t r500_disp_irq_reg;
29672diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_fence.c
29673--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_fence.c 2011-03-27 14:31:47.000000000 -0400
29674+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-04 17:56:28.000000000 -0400
29675@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_devi
29676 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29677 return 0;
29678 }
29679- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29680+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29681 if (!rdev->cp.ready) {
29682 /* FIXME: cp is not running assume everythings is done right
29683 * away
29684@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct rade
29685 return r;
29686 }
29687 WREG32(rdev->fence_drv.scratch_reg, 0);
29688- atomic_set(&rdev->fence_drv.seq, 0);
29689+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
29690 INIT_LIST_HEAD(&rdev->fence_drv.created);
29691 INIT_LIST_HEAD(&rdev->fence_drv.emited);
29692 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
29693diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon.h linux-2.6.32.43/drivers/gpu/drm/radeon/radeon.h
29694--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon.h 2011-03-27 14:31:47.000000000 -0400
29695+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon.h 2011-08-05 20:33:55.000000000 -0400
29696@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device
29697 */
29698 struct radeon_fence_driver {
29699 uint32_t scratch_reg;
29700- atomic_t seq;
29701+ atomic_unchecked_t seq;
29702 uint32_t last_seq;
29703 unsigned long count_timeout;
29704 wait_queue_head_t queue;
29705@@ -640,7 +640,7 @@ struct radeon_asic {
29706 uint32_t offset, uint32_t obj_size);
29707 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
29708 void (*bandwidth_update)(struct radeon_device *rdev);
29709-};
29710+} __no_const;
29711
29712 /*
29713 * Asic structures
29714diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ioc32.c
29715--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-03-27 14:31:47.000000000 -0400
29716+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-04-23 13:57:24.000000000 -0400
29717@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(str
29718 request = compat_alloc_user_space(sizeof(*request));
29719 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
29720 || __put_user(req32.param, &request->param)
29721- || __put_user((void __user *)(unsigned long)req32.value,
29722+ || __put_user((unsigned long)req32.value,
29723 &request->value))
29724 return -EFAULT;
29725
29726diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_irq.c
29727--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_irq.c 2011-03-27 14:31:47.000000000 -0400
29728+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-04 17:56:28.000000000 -0400
29729@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
29730 unsigned int ret;
29731 RING_LOCALS;
29732
29733- atomic_inc(&dev_priv->swi_emitted);
29734- ret = atomic_read(&dev_priv->swi_emitted);
29735+ atomic_inc_unchecked(&dev_priv->swi_emitted);
29736+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29737
29738 BEGIN_RING(4);
29739 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29740@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
29741 drm_radeon_private_t *dev_priv =
29742 (drm_radeon_private_t *) dev->dev_private;
29743
29744- atomic_set(&dev_priv->swi_emitted, 0);
29745+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29746 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29747
29748 dev->max_vblank_count = 0x001fffff;
29749diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_state.c
29750--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_state.c 2011-03-27 14:31:47.000000000 -0400
29751+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_state.c 2011-04-17 15:56:46.000000000 -0400
29752@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm
29753 {
29754 drm_radeon_private_t *dev_priv = dev->dev_private;
29755 drm_radeon_getparam_t *param = data;
29756- int value;
29757+ int value = 0;
29758
29759 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29760
29761diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ttm.c
29762--- linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ttm.c 2011-03-27 14:31:47.000000000 -0400
29763+++ linux-2.6.32.43/drivers/gpu/drm/radeon/radeon_ttm.c 2011-04-17 15:56:46.000000000 -0400
29764@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_devic
29765 DRM_INFO("radeon: ttm finalized\n");
29766 }
29767
29768-static struct vm_operations_struct radeon_ttm_vm_ops;
29769-static const struct vm_operations_struct *ttm_vm_ops = NULL;
29770-
29771-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29772-{
29773- struct ttm_buffer_object *bo;
29774- int r;
29775-
29776- bo = (struct ttm_buffer_object *)vma->vm_private_data;
29777- if (bo == NULL) {
29778- return VM_FAULT_NOPAGE;
29779- }
29780- r = ttm_vm_ops->fault(vma, vmf);
29781- return r;
29782-}
29783-
29784 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29785 {
29786 struct drm_file *file_priv;
29787 struct radeon_device *rdev;
29788- int r;
29789
29790 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
29791 return drm_mmap(filp, vma);
29792@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struc
29793
29794 file_priv = (struct drm_file *)filp->private_data;
29795 rdev = file_priv->minor->dev->dev_private;
29796- if (rdev == NULL) {
29797+ if (!rdev)
29798 return -EINVAL;
29799- }
29800- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29801- if (unlikely(r != 0)) {
29802- return r;
29803- }
29804- if (unlikely(ttm_vm_ops == NULL)) {
29805- ttm_vm_ops = vma->vm_ops;
29806- radeon_ttm_vm_ops = *ttm_vm_ops;
29807- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29808- }
29809- vma->vm_ops = &radeon_ttm_vm_ops;
29810- return 0;
29811+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29812 }
29813
29814
29815diff -urNp linux-2.6.32.43/drivers/gpu/drm/radeon/rs690.c linux-2.6.32.43/drivers/gpu/drm/radeon/rs690.c
29816--- linux-2.6.32.43/drivers/gpu/drm/radeon/rs690.c 2011-03-27 14:31:47.000000000 -0400
29817+++ linux-2.6.32.43/drivers/gpu/drm/radeon/rs690.c 2011-04-17 15:56:46.000000000 -0400
29818@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct
29819 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29820 rdev->pm.sideport_bandwidth.full)
29821 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29822- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
29823+ read_delay_latency.full = rfixed_const(800 * 1000);
29824 read_delay_latency.full = rfixed_div(read_delay_latency,
29825 rdev->pm.igp_sideport_mclk);
29826+ a.full = rfixed_const(370);
29827+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
29828 } else {
29829 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29830 rdev->pm.k8_bandwidth.full)
29831diff -urNp linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo.c linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo.c
29832--- linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo.c 2011-03-27 14:31:47.000000000 -0400
29833+++ linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo.c 2011-04-23 12:56:11.000000000 -0400
29834@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_a
29835 NULL
29836 };
29837
29838-static struct sysfs_ops ttm_bo_global_ops = {
29839+static const struct sysfs_ops ttm_bo_global_ops = {
29840 .show = &ttm_bo_global_show
29841 };
29842
29843diff -urNp linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo_vm.c
29844--- linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-03-27 14:31:47.000000000 -0400
29845+++ linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-04-17 15:56:46.000000000 -0400
29846@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_are
29847 {
29848 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
29849 vma->vm_private_data;
29850- struct ttm_bo_device *bdev = bo->bdev;
29851+ struct ttm_bo_device *bdev;
29852 unsigned long bus_base;
29853 unsigned long bus_offset;
29854 unsigned long bus_size;
29855@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_are
29856 unsigned long address = (unsigned long)vmf->virtual_address;
29857 int retval = VM_FAULT_NOPAGE;
29858
29859+ if (!bo)
29860+ return VM_FAULT_NOPAGE;
29861+ bdev = bo->bdev;
29862+
29863 /*
29864 * Work around locking order reversal in fault / nopfn
29865 * between mmap_sem and bo_reserve: Perform a trylock operation
29866diff -urNp linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_global.c linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_global.c
29867--- linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_global.c 2011-03-27 14:31:47.000000000 -0400
29868+++ linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_global.c 2011-04-17 15:56:46.000000000 -0400
29869@@ -36,7 +36,7 @@
29870 struct ttm_global_item {
29871 struct mutex mutex;
29872 void *object;
29873- int refcount;
29874+ atomic_t refcount;
29875 };
29876
29877 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
29878@@ -49,7 +49,7 @@ void ttm_global_init(void)
29879 struct ttm_global_item *item = &glob[i];
29880 mutex_init(&item->mutex);
29881 item->object = NULL;
29882- item->refcount = 0;
29883+ atomic_set(&item->refcount, 0);
29884 }
29885 }
29886
29887@@ -59,7 +59,7 @@ void ttm_global_release(void)
29888 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
29889 struct ttm_global_item *item = &glob[i];
29890 BUG_ON(item->object != NULL);
29891- BUG_ON(item->refcount != 0);
29892+ BUG_ON(atomic_read(&item->refcount) != 0);
29893 }
29894 }
29895
29896@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_globa
29897 void *object;
29898
29899 mutex_lock(&item->mutex);
29900- if (item->refcount == 0) {
29901+ if (atomic_read(&item->refcount) == 0) {
29902 item->object = kzalloc(ref->size, GFP_KERNEL);
29903 if (unlikely(item->object == NULL)) {
29904 ret = -ENOMEM;
29905@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_globa
29906 goto out_err;
29907
29908 }
29909- ++item->refcount;
29910+ atomic_inc(&item->refcount);
29911 ref->object = item->object;
29912 object = item->object;
29913 mutex_unlock(&item->mutex);
29914@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_gl
29915 struct ttm_global_item *item = &glob[ref->global_type];
29916
29917 mutex_lock(&item->mutex);
29918- BUG_ON(item->refcount == 0);
29919+ BUG_ON(atomic_read(&item->refcount) == 0);
29920 BUG_ON(ref->object != item->object);
29921- if (--item->refcount == 0) {
29922+ if (atomic_dec_and_test(&item->refcount)) {
29923 ref->release(ref);
29924 item->object = NULL;
29925 }
29926diff -urNp linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_memory.c linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_memory.c
29927--- linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_memory.c 2011-03-27 14:31:47.000000000 -0400
29928+++ linux-2.6.32.43/drivers/gpu/drm/ttm/ttm_memory.c 2011-04-17 15:56:46.000000000 -0400
29929@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_at
29930 NULL
29931 };
29932
29933-static struct sysfs_ops ttm_mem_zone_ops = {
29934+static const struct sysfs_ops ttm_mem_zone_ops = {
29935 .show = &ttm_mem_zone_show,
29936 .store = &ttm_mem_zone_store
29937 };
29938diff -urNp linux-2.6.32.43/drivers/gpu/drm/via/via_drv.h linux-2.6.32.43/drivers/gpu/drm/via/via_drv.h
29939--- linux-2.6.32.43/drivers/gpu/drm/via/via_drv.h 2011-03-27 14:31:47.000000000 -0400
29940+++ linux-2.6.32.43/drivers/gpu/drm/via/via_drv.h 2011-05-04 17:56:28.000000000 -0400
29941@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29942 typedef uint32_t maskarray_t[5];
29943
29944 typedef struct drm_via_irq {
29945- atomic_t irq_received;
29946+ atomic_unchecked_t irq_received;
29947 uint32_t pending_mask;
29948 uint32_t enable_mask;
29949 wait_queue_head_t irq_queue;
29950@@ -75,7 +75,7 @@ typedef struct drm_via_private {
29951 struct timeval last_vblank;
29952 int last_vblank_valid;
29953 unsigned usec_per_vblank;
29954- atomic_t vbl_received;
29955+ atomic_unchecked_t vbl_received;
29956 drm_via_state_t hc_state;
29957 char pci_buf[VIA_PCI_BUF_SIZE];
29958 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29959diff -urNp linux-2.6.32.43/drivers/gpu/drm/via/via_irq.c linux-2.6.32.43/drivers/gpu/drm/via/via_irq.c
29960--- linux-2.6.32.43/drivers/gpu/drm/via/via_irq.c 2011-03-27 14:31:47.000000000 -0400
29961+++ linux-2.6.32.43/drivers/gpu/drm/via/via_irq.c 2011-05-04 17:56:28.000000000 -0400
29962@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
29963 if (crtc != 0)
29964 return 0;
29965
29966- return atomic_read(&dev_priv->vbl_received);
29967+ return atomic_read_unchecked(&dev_priv->vbl_received);
29968 }
29969
29970 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29971@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
29972
29973 status = VIA_READ(VIA_REG_INTERRUPT);
29974 if (status & VIA_IRQ_VBLANK_PENDING) {
29975- atomic_inc(&dev_priv->vbl_received);
29976- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29977+ atomic_inc_unchecked(&dev_priv->vbl_received);
29978+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29979 do_gettimeofday(&cur_vblank);
29980 if (dev_priv->last_vblank_valid) {
29981 dev_priv->usec_per_vblank =
29982@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29983 dev_priv->last_vblank = cur_vblank;
29984 dev_priv->last_vblank_valid = 1;
29985 }
29986- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29987+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29988 DRM_DEBUG("US per vblank is: %u\n",
29989 dev_priv->usec_per_vblank);
29990 }
29991@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29992
29993 for (i = 0; i < dev_priv->num_irqs; ++i) {
29994 if (status & cur_irq->pending_mask) {
29995- atomic_inc(&cur_irq->irq_received);
29996+ atomic_inc_unchecked(&cur_irq->irq_received);
29997 DRM_WAKEUP(&cur_irq->irq_queue);
29998 handled = 1;
29999 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
30000@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device *
30001 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30002 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30003 masks[irq][4]));
30004- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30005+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30006 } else {
30007 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30008 (((cur_irq_sequence =
30009- atomic_read(&cur_irq->irq_received)) -
30010+ atomic_read_unchecked(&cur_irq->irq_received)) -
30011 *sequence) <= (1 << 23)));
30012 }
30013 *sequence = cur_irq_sequence;
30014@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct dr
30015 }
30016
30017 for (i = 0; i < dev_priv->num_irqs; ++i) {
30018- atomic_set(&cur_irq->irq_received, 0);
30019+ atomic_set_unchecked(&cur_irq->irq_received, 0);
30020 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30021 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30022 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30023@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev,
30024 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30025 case VIA_IRQ_RELATIVE:
30026 irqwait->request.sequence +=
30027- atomic_read(&cur_irq->irq_received);
30028+ atomic_read_unchecked(&cur_irq->irq_received);
30029 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30030 case VIA_IRQ_ABSOLUTE:
30031 break;
30032diff -urNp linux-2.6.32.43/drivers/hid/hid-core.c linux-2.6.32.43/drivers/hid/hid-core.c
30033--- linux-2.6.32.43/drivers/hid/hid-core.c 2011-05-10 22:12:01.000000000 -0400
30034+++ linux-2.6.32.43/drivers/hid/hid-core.c 2011-05-10 22:12:32.000000000 -0400
30035@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device
30036
30037 int hid_add_device(struct hid_device *hdev)
30038 {
30039- static atomic_t id = ATOMIC_INIT(0);
30040+ static atomic_unchecked_t id = ATOMIC_INIT(0);
30041 int ret;
30042
30043 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30044@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hd
30045 /* XXX hack, any other cleaner solution after the driver core
30046 * is converted to allow more than 20 bytes as the device name? */
30047 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30048- hdev->vendor, hdev->product, atomic_inc_return(&id));
30049+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30050
30051 ret = device_add(&hdev->dev);
30052 if (!ret)
30053diff -urNp linux-2.6.32.43/drivers/hid/usbhid/hiddev.c linux-2.6.32.43/drivers/hid/usbhid/hiddev.c
30054--- linux-2.6.32.43/drivers/hid/usbhid/hiddev.c 2011-03-27 14:31:47.000000000 -0400
30055+++ linux-2.6.32.43/drivers/hid/usbhid/hiddev.c 2011-04-17 15:56:46.000000000 -0400
30056@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *fi
30057 return put_user(HID_VERSION, (int __user *)arg);
30058
30059 case HIDIOCAPPLICATION:
30060- if (arg < 0 || arg >= hid->maxapplication)
30061+ if (arg >= hid->maxapplication)
30062 return -EINVAL;
30063
30064 for (i = 0; i < hid->maxcollection; i++)
30065diff -urNp linux-2.6.32.43/drivers/hwmon/lis3lv02d.c linux-2.6.32.43/drivers/hwmon/lis3lv02d.c
30066--- linux-2.6.32.43/drivers/hwmon/lis3lv02d.c 2011-03-27 14:31:47.000000000 -0400
30067+++ linux-2.6.32.43/drivers/hwmon/lis3lv02d.c 2011-05-04 17:56:28.000000000 -0400
30068@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(in
30069 * the lid is closed. This leads to interrupts as soon as a little move
30070 * is done.
30071 */
30072- atomic_inc(&lis3_dev.count);
30073+ atomic_inc_unchecked(&lis3_dev.count);
30074
30075 wake_up_interruptible(&lis3_dev.misc_wait);
30076 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
30077@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct in
30078 if (test_and_set_bit(0, &lis3_dev.misc_opened))
30079 return -EBUSY; /* already open */
30080
30081- atomic_set(&lis3_dev.count, 0);
30082+ atomic_set_unchecked(&lis3_dev.count, 0);
30083
30084 /*
30085 * The sensor can generate interrupts for free-fall and direction
30086@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struc
30087 add_wait_queue(&lis3_dev.misc_wait, &wait);
30088 while (true) {
30089 set_current_state(TASK_INTERRUPTIBLE);
30090- data = atomic_xchg(&lis3_dev.count, 0);
30091+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
30092 if (data)
30093 break;
30094
30095@@ -244,7 +244,7 @@ out:
30096 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
30097 {
30098 poll_wait(file, &lis3_dev.misc_wait, wait);
30099- if (atomic_read(&lis3_dev.count))
30100+ if (atomic_read_unchecked(&lis3_dev.count))
30101 return POLLIN | POLLRDNORM;
30102 return 0;
30103 }
30104diff -urNp linux-2.6.32.43/drivers/hwmon/lis3lv02d.h linux-2.6.32.43/drivers/hwmon/lis3lv02d.h
30105--- linux-2.6.32.43/drivers/hwmon/lis3lv02d.h 2011-03-27 14:31:47.000000000 -0400
30106+++ linux-2.6.32.43/drivers/hwmon/lis3lv02d.h 2011-05-04 17:56:28.000000000 -0400
30107@@ -201,7 +201,7 @@ struct lis3lv02d {
30108
30109 struct input_polled_dev *idev; /* input device */
30110 struct platform_device *pdev; /* platform device */
30111- atomic_t count; /* interrupt count after last read */
30112+ atomic_unchecked_t count; /* interrupt count after last read */
30113 int xcalib; /* calibrated null value for x */
30114 int ycalib; /* calibrated null value for y */
30115 int zcalib; /* calibrated null value for z */
30116diff -urNp linux-2.6.32.43/drivers/hwmon/sht15.c linux-2.6.32.43/drivers/hwmon/sht15.c
30117--- linux-2.6.32.43/drivers/hwmon/sht15.c 2011-03-27 14:31:47.000000000 -0400
30118+++ linux-2.6.32.43/drivers/hwmon/sht15.c 2011-05-04 17:56:28.000000000 -0400
30119@@ -112,7 +112,7 @@ struct sht15_data {
30120 int supply_uV;
30121 int supply_uV_valid;
30122 struct work_struct update_supply_work;
30123- atomic_t interrupt_handled;
30124+ atomic_unchecked_t interrupt_handled;
30125 };
30126
30127 /**
30128@@ -245,13 +245,13 @@ static inline int sht15_update_single_va
30129 return ret;
30130
30131 gpio_direction_input(data->pdata->gpio_data);
30132- atomic_set(&data->interrupt_handled, 0);
30133+ atomic_set_unchecked(&data->interrupt_handled, 0);
30134
30135 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30136 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30137 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30138 /* Only relevant if the interrupt hasn't occured. */
30139- if (!atomic_read(&data->interrupt_handled))
30140+ if (!atomic_read_unchecked(&data->interrupt_handled))
30141 schedule_work(&data->read_work);
30142 }
30143 ret = wait_event_timeout(data->wait_queue,
30144@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired
30145 struct sht15_data *data = d;
30146 /* First disable the interrupt */
30147 disable_irq_nosync(irq);
30148- atomic_inc(&data->interrupt_handled);
30149+ atomic_inc_unchecked(&data->interrupt_handled);
30150 /* Then schedule a reading work struct */
30151 if (data->flag != SHT15_READING_NOTHING)
30152 schedule_work(&data->read_work);
30153@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct wo
30154 here as could have gone low in meantime so verify
30155 it hasn't!
30156 */
30157- atomic_set(&data->interrupt_handled, 0);
30158+ atomic_set_unchecked(&data->interrupt_handled, 0);
30159 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30160 /* If still not occured or another handler has been scheduled */
30161 if (gpio_get_value(data->pdata->gpio_data)
30162- || atomic_read(&data->interrupt_handled))
30163+ || atomic_read_unchecked(&data->interrupt_handled))
30164 return;
30165 }
30166 /* Read the data back from the device */
30167diff -urNp linux-2.6.32.43/drivers/hwmon/w83791d.c linux-2.6.32.43/drivers/hwmon/w83791d.c
30168--- linux-2.6.32.43/drivers/hwmon/w83791d.c 2011-03-27 14:31:47.000000000 -0400
30169+++ linux-2.6.32.43/drivers/hwmon/w83791d.c 2011-04-17 15:56:46.000000000 -0400
30170@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_cli
30171 struct i2c_board_info *info);
30172 static int w83791d_remove(struct i2c_client *client);
30173
30174-static int w83791d_read(struct i2c_client *client, u8 register);
30175-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30176+static int w83791d_read(struct i2c_client *client, u8 reg);
30177+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30178 static struct w83791d_data *w83791d_update_device(struct device *dev);
30179
30180 #ifdef DEBUG
30181diff -urNp linux-2.6.32.43/drivers/i2c/busses/i2c-amd756-s4882.c linux-2.6.32.43/drivers/i2c/busses/i2c-amd756-s4882.c
30182--- linux-2.6.32.43/drivers/i2c/busses/i2c-amd756-s4882.c 2011-03-27 14:31:47.000000000 -0400
30183+++ linux-2.6.32.43/drivers/i2c/busses/i2c-amd756-s4882.c 2011-08-05 20:33:55.000000000 -0400
30184@@ -189,23 +189,23 @@ static int __init amd756_s4882_init(void
30185 }
30186
30187 /* Fill in the new structures */
30188- s4882_algo[0] = *(amd756_smbus.algo);
30189- s4882_algo[0].smbus_xfer = amd756_access_virt0;
30190+ memcpy((void *)&s4882_algo[0], amd756_smbus.algo, sizeof(s4882_algo[0]));
30191+ *(void **)&s4882_algo[0].smbus_xfer = amd756_access_virt0;
30192 s4882_adapter[0] = amd756_smbus;
30193 s4882_adapter[0].algo = s4882_algo;
30194- s4882_adapter[0].dev.parent = amd756_smbus.dev.parent;
30195+ *(void **)&s4882_adapter[0].dev.parent = amd756_smbus.dev.parent;
30196 for (i = 1; i < 5; i++) {
30197- s4882_algo[i] = *(amd756_smbus.algo);
30198+ memcpy((void *)&s4882_algo[i], amd756_smbus.algo, sizeof(s4882_algo[i]));
30199 s4882_adapter[i] = amd756_smbus;
30200 snprintf(s4882_adapter[i].name, sizeof(s4882_adapter[i].name),
30201 "SMBus 8111 adapter (CPU%d)", i-1);
30202 s4882_adapter[i].algo = s4882_algo+i;
30203 s4882_adapter[i].dev.parent = amd756_smbus.dev.parent;
30204 }
30205- s4882_algo[1].smbus_xfer = amd756_access_virt1;
30206- s4882_algo[2].smbus_xfer = amd756_access_virt2;
30207- s4882_algo[3].smbus_xfer = amd756_access_virt3;
30208- s4882_algo[4].smbus_xfer = amd756_access_virt4;
30209+ *(void **)&s4882_algo[1].smbus_xfer = amd756_access_virt1;
30210+ *(void **)&s4882_algo[2].smbus_xfer = amd756_access_virt2;
30211+ *(void **)&s4882_algo[3].smbus_xfer = amd756_access_virt3;
30212+ *(void **)&s4882_algo[4].smbus_xfer = amd756_access_virt4;
30213
30214 /* Register virtual adapters */
30215 for (i = 0; i < 5; i++) {
30216diff -urNp linux-2.6.32.43/drivers/i2c/busses/i2c-nforce2-s4985.c linux-2.6.32.43/drivers/i2c/busses/i2c-nforce2-s4985.c
30217--- linux-2.6.32.43/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-03-27 14:31:47.000000000 -0400
30218+++ linux-2.6.32.43/drivers/i2c/busses/i2c-nforce2-s4985.c 2011-08-05 20:33:55.000000000 -0400
30219@@ -184,23 +184,23 @@ static int __init nforce2_s4985_init(voi
30220 }
30221
30222 /* Fill in the new structures */
30223- s4985_algo[0] = *(nforce2_smbus->algo);
30224- s4985_algo[0].smbus_xfer = nforce2_access_virt0;
30225+ memcpy((void *)&s4985_algo[0], nforce2_smbus->algo, sizeof(s4985_algo[0]));
30226+ *(void **)&s4985_algo[0].smbus_xfer = nforce2_access_virt0;
30227 s4985_adapter[0] = *nforce2_smbus;
30228 s4985_adapter[0].algo = s4985_algo;
30229 s4985_adapter[0].dev.parent = nforce2_smbus->dev.parent;
30230 for (i = 1; i < 5; i++) {
30231- s4985_algo[i] = *(nforce2_smbus->algo);
30232+ memcpy((void *)&s4985_algo[i], nforce2_smbus->algo, sizeof(s4985_algo[i]));
30233 s4985_adapter[i] = *nforce2_smbus;
30234 snprintf(s4985_adapter[i].name, sizeof(s4985_adapter[i].name),
30235 "SMBus nForce2 adapter (CPU%d)", i - 1);
30236 s4985_adapter[i].algo = s4985_algo + i;
30237 s4985_adapter[i].dev.parent = nforce2_smbus->dev.parent;
30238 }
30239- s4985_algo[1].smbus_xfer = nforce2_access_virt1;
30240- s4985_algo[2].smbus_xfer = nforce2_access_virt2;
30241- s4985_algo[3].smbus_xfer = nforce2_access_virt3;
30242- s4985_algo[4].smbus_xfer = nforce2_access_virt4;
30243+ *(void **)&s4985_algo[1].smbus_xfer = nforce2_access_virt1;
30244+ *(void **)&s4985_algo[2].smbus_xfer = nforce2_access_virt2;
30245+ *(void **)&s4985_algo[3].smbus_xfer = nforce2_access_virt3;
30246+ *(void **)&s4985_algo[4].smbus_xfer = nforce2_access_virt4;
30247
30248 /* Register virtual adapters */
30249 for (i = 0; i < 5; i++) {
30250diff -urNp linux-2.6.32.43/drivers/ide/ide-cd.c linux-2.6.32.43/drivers/ide/ide-cd.c
30251--- linux-2.6.32.43/drivers/ide/ide-cd.c 2011-03-27 14:31:47.000000000 -0400
30252+++ linux-2.6.32.43/drivers/ide/ide-cd.c 2011-04-17 15:56:46.000000000 -0400
30253@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_
30254 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30255 if ((unsigned long)buf & alignment
30256 || blk_rq_bytes(rq) & q->dma_pad_mask
30257- || object_is_on_stack(buf))
30258+ || object_starts_on_stack(buf))
30259 drive->dma = 0;
30260 }
30261 }
30262diff -urNp linux-2.6.32.43/drivers/ide/ide-floppy.c linux-2.6.32.43/drivers/ide/ide-floppy.c
30263--- linux-2.6.32.43/drivers/ide/ide-floppy.c 2011-03-27 14:31:47.000000000 -0400
30264+++ linux-2.6.32.43/drivers/ide/ide-floppy.c 2011-05-16 21:46:57.000000000 -0400
30265@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_d
30266 u8 pc_buf[256], header_len, desc_cnt;
30267 int i, rc = 1, blocks, length;
30268
30269+ pax_track_stack();
30270+
30271 ide_debug_log(IDE_DBG_FUNC, "enter");
30272
30273 drive->bios_cyl = 0;
30274diff -urNp linux-2.6.32.43/drivers/ide/setup-pci.c linux-2.6.32.43/drivers/ide/setup-pci.c
30275--- linux-2.6.32.43/drivers/ide/setup-pci.c 2011-03-27 14:31:47.000000000 -0400
30276+++ linux-2.6.32.43/drivers/ide/setup-pci.c 2011-05-16 21:46:57.000000000 -0400
30277@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30278 int ret, i, n_ports = dev2 ? 4 : 2;
30279 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30280
30281+ pax_track_stack();
30282+
30283 for (i = 0; i < n_ports / 2; i++) {
30284 ret = ide_setup_pci_controller(pdev[i], d, !i);
30285 if (ret < 0)
30286diff -urNp linux-2.6.32.43/drivers/ieee1394/dv1394.c linux-2.6.32.43/drivers/ieee1394/dv1394.c
30287--- linux-2.6.32.43/drivers/ieee1394/dv1394.c 2011-03-27 14:31:47.000000000 -0400
30288+++ linux-2.6.32.43/drivers/ieee1394/dv1394.c 2011-04-23 12:56:11.000000000 -0400
30289@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
30290 based upon DIF section and sequence
30291 */
30292
30293-static void inline
30294+static inline void
30295 frame_put_packet (struct frame *f, struct packet *p)
30296 {
30297 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
30298diff -urNp linux-2.6.32.43/drivers/ieee1394/hosts.c linux-2.6.32.43/drivers/ieee1394/hosts.c
30299--- linux-2.6.32.43/drivers/ieee1394/hosts.c 2011-03-27 14:31:47.000000000 -0400
30300+++ linux-2.6.32.43/drivers/ieee1394/hosts.c 2011-04-17 15:56:46.000000000 -0400
30301@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
30302 }
30303
30304 static struct hpsb_host_driver dummy_driver = {
30305+ .name = "dummy",
30306 .transmit_packet = dummy_transmit_packet,
30307 .devctl = dummy_devctl,
30308 .isoctl = dummy_isoctl
30309diff -urNp linux-2.6.32.43/drivers/ieee1394/init_ohci1394_dma.c linux-2.6.32.43/drivers/ieee1394/init_ohci1394_dma.c
30310--- linux-2.6.32.43/drivers/ieee1394/init_ohci1394_dma.c 2011-03-27 14:31:47.000000000 -0400
30311+++ linux-2.6.32.43/drivers/ieee1394/init_ohci1394_dma.c 2011-04-17 15:56:46.000000000 -0400
30312@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_con
30313 for (func = 0; func < 8; func++) {
30314 u32 class = read_pci_config(num,slot,func,
30315 PCI_CLASS_REVISION);
30316- if ((class == 0xffffffff))
30317+ if (class == 0xffffffff)
30318 continue; /* No device at this func */
30319
30320 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
30321diff -urNp linux-2.6.32.43/drivers/ieee1394/ohci1394.c linux-2.6.32.43/drivers/ieee1394/ohci1394.c
30322--- linux-2.6.32.43/drivers/ieee1394/ohci1394.c 2011-03-27 14:31:47.000000000 -0400
30323+++ linux-2.6.32.43/drivers/ieee1394/ohci1394.c 2011-04-23 12:56:11.000000000 -0400
30324@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
30325 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
30326
30327 /* Module Parameters */
30328-static int phys_dma = 1;
30329+static int phys_dma;
30330 module_param(phys_dma, int, 0444);
30331-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
30332+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
30333
30334 static void dma_trm_tasklet(unsigned long data);
30335 static void dma_trm_reset(struct dma_trm_ctx *d);
30336diff -urNp linux-2.6.32.43/drivers/ieee1394/sbp2.c linux-2.6.32.43/drivers/ieee1394/sbp2.c
30337--- linux-2.6.32.43/drivers/ieee1394/sbp2.c 2011-03-27 14:31:47.000000000 -0400
30338+++ linux-2.6.32.43/drivers/ieee1394/sbp2.c 2011-04-23 12:56:11.000000000 -0400
30339@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
30340 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
30341 MODULE_LICENSE("GPL");
30342
30343-static int sbp2_module_init(void)
30344+static int __init sbp2_module_init(void)
30345 {
30346 int ret;
30347
30348diff -urNp linux-2.6.32.43/drivers/infiniband/core/cm.c linux-2.6.32.43/drivers/infiniband/core/cm.c
30349--- linux-2.6.32.43/drivers/infiniband/core/cm.c 2011-03-27 14:31:47.000000000 -0400
30350+++ linux-2.6.32.43/drivers/infiniband/core/cm.c 2011-04-17 15:56:46.000000000 -0400
30351@@ -112,7 +112,7 @@ static char const counter_group_names[CM
30352
30353 struct cm_counter_group {
30354 struct kobject obj;
30355- atomic_long_t counter[CM_ATTR_COUNT];
30356+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30357 };
30358
30359 struct cm_counter_attribute {
30360@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm
30361 struct ib_mad_send_buf *msg = NULL;
30362 int ret;
30363
30364- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30365+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30366 counter[CM_REQ_COUNTER]);
30367
30368 /* Quick state check to discard duplicate REQs. */
30369@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm
30370 if (!cm_id_priv)
30371 return;
30372
30373- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30374+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30375 counter[CM_REP_COUNTER]);
30376 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30377 if (ret)
30378@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work
30379 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30380 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30381 spin_unlock_irq(&cm_id_priv->lock);
30382- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30383+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30384 counter[CM_RTU_COUNTER]);
30385 goto out;
30386 }
30387@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_wor
30388 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30389 dreq_msg->local_comm_id);
30390 if (!cm_id_priv) {
30391- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30392+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30393 counter[CM_DREQ_COUNTER]);
30394 cm_issue_drep(work->port, work->mad_recv_wc);
30395 return -EINVAL;
30396@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_wor
30397 case IB_CM_MRA_REP_RCVD:
30398 break;
30399 case IB_CM_TIMEWAIT:
30400- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30401+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30402 counter[CM_DREQ_COUNTER]);
30403 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30404 goto unlock;
30405@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_wor
30406 cm_free_msg(msg);
30407 goto deref;
30408 case IB_CM_DREQ_RCVD:
30409- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30410+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30411 counter[CM_DREQ_COUNTER]);
30412 goto unlock;
30413 default:
30414@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work
30415 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30416 cm_id_priv->msg, timeout)) {
30417 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30418- atomic_long_inc(&work->port->
30419+ atomic_long_inc_unchecked(&work->port->
30420 counter_group[CM_RECV_DUPLICATES].
30421 counter[CM_MRA_COUNTER]);
30422 goto out;
30423@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work
30424 break;
30425 case IB_CM_MRA_REQ_RCVD:
30426 case IB_CM_MRA_REP_RCVD:
30427- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30428+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30429 counter[CM_MRA_COUNTER]);
30430 /* fall through */
30431 default:
30432@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work
30433 case IB_CM_LAP_IDLE:
30434 break;
30435 case IB_CM_MRA_LAP_SENT:
30436- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30437+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30438 counter[CM_LAP_COUNTER]);
30439 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30440 goto unlock;
30441@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work
30442 cm_free_msg(msg);
30443 goto deref;
30444 case IB_CM_LAP_RCVD:
30445- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30446+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30447 counter[CM_LAP_COUNTER]);
30448 goto unlock;
30449 default:
30450@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm
30451 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30452 if (cur_cm_id_priv) {
30453 spin_unlock_irq(&cm.lock);
30454- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30455+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30456 counter[CM_SIDR_REQ_COUNTER]);
30457 goto out; /* Duplicate message. */
30458 }
30459@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_ma
30460 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30461 msg->retries = 1;
30462
30463- atomic_long_add(1 + msg->retries,
30464+ atomic_long_add_unchecked(1 + msg->retries,
30465 &port->counter_group[CM_XMIT].counter[attr_index]);
30466 if (msg->retries)
30467- atomic_long_add(msg->retries,
30468+ atomic_long_add_unchecked(msg->retries,
30469 &port->counter_group[CM_XMIT_RETRIES].
30470 counter[attr_index]);
30471
30472@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_ma
30473 }
30474
30475 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30476- atomic_long_inc(&port->counter_group[CM_RECV].
30477+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30478 counter[attr_id - CM_ATTR_ID_OFFSET]);
30479
30480 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30481@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct ko
30482 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30483
30484 return sprintf(buf, "%ld\n",
30485- atomic_long_read(&group->counter[cm_attr->index]));
30486+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30487 }
30488
30489-static struct sysfs_ops cm_counter_ops = {
30490+static const struct sysfs_ops cm_counter_ops = {
30491 .show = cm_show_counter
30492 };
30493
30494diff -urNp linux-2.6.32.43/drivers/infiniband/core/fmr_pool.c linux-2.6.32.43/drivers/infiniband/core/fmr_pool.c
30495--- linux-2.6.32.43/drivers/infiniband/core/fmr_pool.c 2011-03-27 14:31:47.000000000 -0400
30496+++ linux-2.6.32.43/drivers/infiniband/core/fmr_pool.c 2011-05-04 17:56:28.000000000 -0400
30497@@ -97,8 +97,8 @@ struct ib_fmr_pool {
30498
30499 struct task_struct *thread;
30500
30501- atomic_t req_ser;
30502- atomic_t flush_ser;
30503+ atomic_unchecked_t req_ser;
30504+ atomic_unchecked_t flush_ser;
30505
30506 wait_queue_head_t force_wait;
30507 };
30508@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30509 struct ib_fmr_pool *pool = pool_ptr;
30510
30511 do {
30512- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30513+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30514 ib_fmr_batch_release(pool);
30515
30516- atomic_inc(&pool->flush_ser);
30517+ atomic_inc_unchecked(&pool->flush_ser);
30518 wake_up_interruptible(&pool->force_wait);
30519
30520 if (pool->flush_function)
30521@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30522 }
30523
30524 set_current_state(TASK_INTERRUPTIBLE);
30525- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30526+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30527 !kthread_should_stop())
30528 schedule();
30529 __set_current_state(TASK_RUNNING);
30530@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30531 pool->dirty_watermark = params->dirty_watermark;
30532 pool->dirty_len = 0;
30533 spin_lock_init(&pool->pool_lock);
30534- atomic_set(&pool->req_ser, 0);
30535- atomic_set(&pool->flush_ser, 0);
30536+ atomic_set_unchecked(&pool->req_ser, 0);
30537+ atomic_set_unchecked(&pool->flush_ser, 0);
30538 init_waitqueue_head(&pool->force_wait);
30539
30540 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30541@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30542 }
30543 spin_unlock_irq(&pool->pool_lock);
30544
30545- serial = atomic_inc_return(&pool->req_ser);
30546+ serial = atomic_inc_return_unchecked(&pool->req_ser);
30547 wake_up_process(pool->thread);
30548
30549 if (wait_event_interruptible(pool->force_wait,
30550- atomic_read(&pool->flush_ser) - serial >= 0))
30551+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30552 return -EINTR;
30553
30554 return 0;
30555@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30556 } else {
30557 list_add_tail(&fmr->list, &pool->dirty_list);
30558 if (++pool->dirty_len >= pool->dirty_watermark) {
30559- atomic_inc(&pool->req_ser);
30560+ atomic_inc_unchecked(&pool->req_ser);
30561 wake_up_process(pool->thread);
30562 }
30563 }
30564diff -urNp linux-2.6.32.43/drivers/infiniband/core/sysfs.c linux-2.6.32.43/drivers/infiniband/core/sysfs.c
30565--- linux-2.6.32.43/drivers/infiniband/core/sysfs.c 2011-03-27 14:31:47.000000000 -0400
30566+++ linux-2.6.32.43/drivers/infiniband/core/sysfs.c 2011-04-17 15:56:46.000000000 -0400
30567@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kob
30568 return port_attr->show(p, port_attr, buf);
30569 }
30570
30571-static struct sysfs_ops port_sysfs_ops = {
30572+static const struct sysfs_ops port_sysfs_ops = {
30573 .show = port_attr_show
30574 };
30575
30576diff -urNp linux-2.6.32.43/drivers/infiniband/core/uverbs_marshall.c linux-2.6.32.43/drivers/infiniband/core/uverbs_marshall.c
30577--- linux-2.6.32.43/drivers/infiniband/core/uverbs_marshall.c 2011-03-27 14:31:47.000000000 -0400
30578+++ linux-2.6.32.43/drivers/infiniband/core/uverbs_marshall.c 2011-04-17 15:56:46.000000000 -0400
30579@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_u
30580 dst->grh.sgid_index = src->grh.sgid_index;
30581 dst->grh.hop_limit = src->grh.hop_limit;
30582 dst->grh.traffic_class = src->grh.traffic_class;
30583+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
30584 dst->dlid = src->dlid;
30585 dst->sl = src->sl;
30586 dst->src_path_bits = src->src_path_bits;
30587 dst->static_rate = src->static_rate;
30588 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
30589 dst->port_num = src->port_num;
30590+ dst->reserved = 0;
30591 }
30592 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
30593
30594 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
30595 struct ib_qp_attr *src)
30596 {
30597+ dst->qp_state = src->qp_state;
30598 dst->cur_qp_state = src->cur_qp_state;
30599 dst->path_mtu = src->path_mtu;
30600 dst->path_mig_state = src->path_mig_state;
30601@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_u
30602 dst->rnr_retry = src->rnr_retry;
30603 dst->alt_port_num = src->alt_port_num;
30604 dst->alt_timeout = src->alt_timeout;
30605+ memset(dst->reserved, 0, sizeof(dst->reserved));
30606 }
30607 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
30608
30609diff -urNp linux-2.6.32.43/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.32.43/drivers/infiniband/hw/ipath/ipath_fs.c
30610--- linux-2.6.32.43/drivers/infiniband/hw/ipath/ipath_fs.c 2011-03-27 14:31:47.000000000 -0400
30611+++ linux-2.6.32.43/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-16 21:46:57.000000000 -0400
30612@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(stru
30613 struct infinipath_counters counters;
30614 struct ipath_devdata *dd;
30615
30616+ pax_track_stack();
30617+
30618 dd = file->f_path.dentry->d_inode->i_private;
30619 dd->ipath_f_read_counters(dd, &counters);
30620
30621diff -urNp linux-2.6.32.43/drivers/infiniband/hw/nes/nes.c linux-2.6.32.43/drivers/infiniband/hw/nes/nes.c
30622--- linux-2.6.32.43/drivers/infiniband/hw/nes/nes.c 2011-03-27 14:31:47.000000000 -0400
30623+++ linux-2.6.32.43/drivers/infiniband/hw/nes/nes.c 2011-05-04 17:56:28.000000000 -0400
30624@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
30625 LIST_HEAD(nes_adapter_list);
30626 static LIST_HEAD(nes_dev_list);
30627
30628-atomic_t qps_destroyed;
30629+atomic_unchecked_t qps_destroyed;
30630
30631 static unsigned int ee_flsh_adapter;
30632 static unsigned int sysfs_nonidx_addr;
30633@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(str
30634 struct nes_adapter *nesadapter = nesdev->nesadapter;
30635 u32 qp_id;
30636
30637- atomic_inc(&qps_destroyed);
30638+ atomic_inc_unchecked(&qps_destroyed);
30639
30640 /* Free the control structures */
30641
30642diff -urNp linux-2.6.32.43/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.32.43/drivers/infiniband/hw/nes/nes_cm.c
30643--- linux-2.6.32.43/drivers/infiniband/hw/nes/nes_cm.c 2011-03-27 14:31:47.000000000 -0400
30644+++ linux-2.6.32.43/drivers/infiniband/hw/nes/nes_cm.c 2011-05-04 17:56:28.000000000 -0400
30645@@ -69,11 +69,11 @@ u32 cm_packets_received;
30646 u32 cm_listens_created;
30647 u32 cm_listens_destroyed;
30648 u32 cm_backlog_drops;
30649-atomic_t cm_loopbacks;
30650-atomic_t cm_nodes_created;
30651-atomic_t cm_nodes_destroyed;
30652-atomic_t cm_accel_dropped_pkts;
30653-atomic_t cm_resets_recvd;
30654+atomic_unchecked_t cm_loopbacks;
30655+atomic_unchecked_t cm_nodes_created;
30656+atomic_unchecked_t cm_nodes_destroyed;
30657+atomic_unchecked_t cm_accel_dropped_pkts;
30658+atomic_unchecked_t cm_resets_recvd;
30659
30660 static inline int mini_cm_accelerated(struct nes_cm_core *,
30661 struct nes_cm_node *);
30662@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
30663
30664 static struct nes_cm_core *g_cm_core;
30665
30666-atomic_t cm_connects;
30667-atomic_t cm_accepts;
30668-atomic_t cm_disconnects;
30669-atomic_t cm_closes;
30670-atomic_t cm_connecteds;
30671-atomic_t cm_connect_reqs;
30672-atomic_t cm_rejects;
30673+atomic_unchecked_t cm_connects;
30674+atomic_unchecked_t cm_accepts;
30675+atomic_unchecked_t cm_disconnects;
30676+atomic_unchecked_t cm_closes;
30677+atomic_unchecked_t cm_connecteds;
30678+atomic_unchecked_t cm_connect_reqs;
30679+atomic_unchecked_t cm_rejects;
30680
30681
30682 /**
30683@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(
30684 cm_node->rem_mac);
30685
30686 add_hte_node(cm_core, cm_node);
30687- atomic_inc(&cm_nodes_created);
30688+ atomic_inc_unchecked(&cm_nodes_created);
30689
30690 return cm_node;
30691 }
30692@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm
30693 }
30694
30695 atomic_dec(&cm_core->node_cnt);
30696- atomic_inc(&cm_nodes_destroyed);
30697+ atomic_inc_unchecked(&cm_nodes_destroyed);
30698 nesqp = cm_node->nesqp;
30699 if (nesqp) {
30700 nesqp->cm_node = NULL;
30701@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm
30702
30703 static void drop_packet(struct sk_buff *skb)
30704 {
30705- atomic_inc(&cm_accel_dropped_pkts);
30706+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
30707 dev_kfree_skb_any(skb);
30708 }
30709
30710@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm
30711
30712 int reset = 0; /* whether to send reset in case of err.. */
30713 int passive_state;
30714- atomic_inc(&cm_resets_recvd);
30715+ atomic_inc_unchecked(&cm_resets_recvd);
30716 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30717 " refcnt=%d\n", cm_node, cm_node->state,
30718 atomic_read(&cm_node->ref_count));
30719@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_conne
30720 rem_ref_cm_node(cm_node->cm_core, cm_node);
30721 return NULL;
30722 }
30723- atomic_inc(&cm_loopbacks);
30724+ atomic_inc_unchecked(&cm_loopbacks);
30725 loopbackremotenode->loopbackpartner = cm_node;
30726 loopbackremotenode->tcp_cntxt.rcv_wscale =
30727 NES_CM_DEFAULT_RCV_WND_SCALE;
30728@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_c
30729 add_ref_cm_node(cm_node);
30730 } else if (cm_node->state == NES_CM_STATE_TSA) {
30731 rem_ref_cm_node(cm_core, cm_node);
30732- atomic_inc(&cm_accel_dropped_pkts);
30733+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
30734 dev_kfree_skb_any(skb);
30735 break;
30736 }
30737@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct ne
30738
30739 if ((cm_id) && (cm_id->event_handler)) {
30740 if (issue_disconn) {
30741- atomic_inc(&cm_disconnects);
30742+ atomic_inc_unchecked(&cm_disconnects);
30743 cm_event.event = IW_CM_EVENT_DISCONNECT;
30744 cm_event.status = disconn_status;
30745 cm_event.local_addr = cm_id->local_addr;
30746@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct ne
30747 }
30748
30749 if (issue_close) {
30750- atomic_inc(&cm_closes);
30751+ atomic_inc_unchecked(&cm_closes);
30752 nes_disconnect(nesqp, 1);
30753
30754 cm_id->provider_data = nesqp;
30755@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
30756
30757 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30758 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30759- atomic_inc(&cm_accepts);
30760+ atomic_inc_unchecked(&cm_accepts);
30761
30762 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30763 atomic_read(&nesvnic->netdev->refcnt));
30764@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
30765
30766 struct nes_cm_core *cm_core;
30767
30768- atomic_inc(&cm_rejects);
30769+ atomic_inc_unchecked(&cm_rejects);
30770 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30771 loopback = cm_node->loopbackpartner;
30772 cm_core = cm_node->cm_core;
30773@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id,
30774 ntohl(cm_id->local_addr.sin_addr.s_addr),
30775 ntohs(cm_id->local_addr.sin_port));
30776
30777- atomic_inc(&cm_connects);
30778+ atomic_inc_unchecked(&cm_connects);
30779 nesqp->active_conn = 1;
30780
30781 /* cache the cm_id in the qp */
30782@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct ne
30783 if (nesqp->destroyed) {
30784 return;
30785 }
30786- atomic_inc(&cm_connecteds);
30787+ atomic_inc_unchecked(&cm_connecteds);
30788 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30789 " local port 0x%04X. jiffies = %lu.\n",
30790 nesqp->hwqp.qp_id,
30791@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm
30792
30793 ret = cm_id->event_handler(cm_id, &cm_event);
30794 cm_id->add_ref(cm_id);
30795- atomic_inc(&cm_closes);
30796+ atomic_inc_unchecked(&cm_closes);
30797 cm_event.event = IW_CM_EVENT_CLOSE;
30798 cm_event.status = IW_CM_EVENT_STATUS_OK;
30799 cm_event.provider_data = cm_id->provider_data;
30800@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_
30801 return;
30802 cm_id = cm_node->cm_id;
30803
30804- atomic_inc(&cm_connect_reqs);
30805+ atomic_inc_unchecked(&cm_connect_reqs);
30806 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30807 cm_node, cm_id, jiffies);
30808
30809@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct n
30810 return;
30811 cm_id = cm_node->cm_id;
30812
30813- atomic_inc(&cm_connect_reqs);
30814+ atomic_inc_unchecked(&cm_connect_reqs);
30815 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30816 cm_node, cm_id, jiffies);
30817
30818diff -urNp linux-2.6.32.43/drivers/infiniband/hw/nes/nes.h linux-2.6.32.43/drivers/infiniband/hw/nes/nes.h
30819--- linux-2.6.32.43/drivers/infiniband/hw/nes/nes.h 2011-03-27 14:31:47.000000000 -0400
30820+++ linux-2.6.32.43/drivers/infiniband/hw/nes/nes.h 2011-05-04 17:56:28.000000000 -0400
30821@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
30822 extern unsigned int wqm_quanta;
30823 extern struct list_head nes_adapter_list;
30824
30825-extern atomic_t cm_connects;
30826-extern atomic_t cm_accepts;
30827-extern atomic_t cm_disconnects;
30828-extern atomic_t cm_closes;
30829-extern atomic_t cm_connecteds;
30830-extern atomic_t cm_connect_reqs;
30831-extern atomic_t cm_rejects;
30832-extern atomic_t mod_qp_timouts;
30833-extern atomic_t qps_created;
30834-extern atomic_t qps_destroyed;
30835-extern atomic_t sw_qps_destroyed;
30836+extern atomic_unchecked_t cm_connects;
30837+extern atomic_unchecked_t cm_accepts;
30838+extern atomic_unchecked_t cm_disconnects;
30839+extern atomic_unchecked_t cm_closes;
30840+extern atomic_unchecked_t cm_connecteds;
30841+extern atomic_unchecked_t cm_connect_reqs;
30842+extern atomic_unchecked_t cm_rejects;
30843+extern atomic_unchecked_t mod_qp_timouts;
30844+extern atomic_unchecked_t qps_created;
30845+extern atomic_unchecked_t qps_destroyed;
30846+extern atomic_unchecked_t sw_qps_destroyed;
30847 extern u32 mh_detected;
30848 extern u32 mh_pauses_sent;
30849 extern u32 cm_packets_sent;
30850@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
30851 extern u32 cm_listens_created;
30852 extern u32 cm_listens_destroyed;
30853 extern u32 cm_backlog_drops;
30854-extern atomic_t cm_loopbacks;
30855-extern atomic_t cm_nodes_created;
30856-extern atomic_t cm_nodes_destroyed;
30857-extern atomic_t cm_accel_dropped_pkts;
30858-extern atomic_t cm_resets_recvd;
30859+extern atomic_unchecked_t cm_loopbacks;
30860+extern atomic_unchecked_t cm_nodes_created;
30861+extern atomic_unchecked_t cm_nodes_destroyed;
30862+extern atomic_unchecked_t cm_accel_dropped_pkts;
30863+extern atomic_unchecked_t cm_resets_recvd;
30864
30865 extern u32 int_mod_timer_init;
30866 extern u32 int_mod_cq_depth_256;
30867diff -urNp linux-2.6.32.43/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.32.43/drivers/infiniband/hw/nes/nes_nic.c
30868--- linux-2.6.32.43/drivers/infiniband/hw/nes/nes_nic.c 2011-03-27 14:31:47.000000000 -0400
30869+++ linux-2.6.32.43/drivers/infiniband/hw/nes/nes_nic.c 2011-05-04 17:56:28.000000000 -0400
30870@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats
30871 target_stat_values[++index] = mh_detected;
30872 target_stat_values[++index] = mh_pauses_sent;
30873 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30874- target_stat_values[++index] = atomic_read(&cm_connects);
30875- target_stat_values[++index] = atomic_read(&cm_accepts);
30876- target_stat_values[++index] = atomic_read(&cm_disconnects);
30877- target_stat_values[++index] = atomic_read(&cm_connecteds);
30878- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30879- target_stat_values[++index] = atomic_read(&cm_rejects);
30880- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30881- target_stat_values[++index] = atomic_read(&qps_created);
30882- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30883- target_stat_values[++index] = atomic_read(&qps_destroyed);
30884- target_stat_values[++index] = atomic_read(&cm_closes);
30885+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30886+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30887+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30888+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30889+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30890+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30891+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30892+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30893+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30894+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30895+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30896 target_stat_values[++index] = cm_packets_sent;
30897 target_stat_values[++index] = cm_packets_bounced;
30898 target_stat_values[++index] = cm_packets_created;
30899@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats
30900 target_stat_values[++index] = cm_listens_created;
30901 target_stat_values[++index] = cm_listens_destroyed;
30902 target_stat_values[++index] = cm_backlog_drops;
30903- target_stat_values[++index] = atomic_read(&cm_loopbacks);
30904- target_stat_values[++index] = atomic_read(&cm_nodes_created);
30905- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30906- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30907- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30908+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30909+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30910+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30911+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30912+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30913 target_stat_values[++index] = int_mod_timer_init;
30914 target_stat_values[++index] = int_mod_cq_depth_1;
30915 target_stat_values[++index] = int_mod_cq_depth_4;
30916diff -urNp linux-2.6.32.43/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.32.43/drivers/infiniband/hw/nes/nes_verbs.c
30917--- linux-2.6.32.43/drivers/infiniband/hw/nes/nes_verbs.c 2011-03-27 14:31:47.000000000 -0400
30918+++ linux-2.6.32.43/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-04 17:56:28.000000000 -0400
30919@@ -45,9 +45,9 @@
30920
30921 #include <rdma/ib_umem.h>
30922
30923-atomic_t mod_qp_timouts;
30924-atomic_t qps_created;
30925-atomic_t sw_qps_destroyed;
30926+atomic_unchecked_t mod_qp_timouts;
30927+atomic_unchecked_t qps_created;
30928+atomic_unchecked_t sw_qps_destroyed;
30929
30930 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30931
30932@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struc
30933 if (init_attr->create_flags)
30934 return ERR_PTR(-EINVAL);
30935
30936- atomic_inc(&qps_created);
30937+ atomic_inc_unchecked(&qps_created);
30938 switch (init_attr->qp_type) {
30939 case IB_QPT_RC:
30940 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30941@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *
30942 struct iw_cm_event cm_event;
30943 int ret;
30944
30945- atomic_inc(&sw_qps_destroyed);
30946+ atomic_inc_unchecked(&sw_qps_destroyed);
30947 nesqp->destroyed = 1;
30948
30949 /* Blow away the connection if it exists. */
30950diff -urNp linux-2.6.32.43/drivers/input/gameport/gameport.c linux-2.6.32.43/drivers/input/gameport/gameport.c
30951--- linux-2.6.32.43/drivers/input/gameport/gameport.c 2011-03-27 14:31:47.000000000 -0400
30952+++ linux-2.6.32.43/drivers/input/gameport/gameport.c 2011-05-04 17:56:28.000000000 -0400
30953@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
30954 */
30955 static void gameport_init_port(struct gameport *gameport)
30956 {
30957- static atomic_t gameport_no = ATOMIC_INIT(0);
30958+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30959
30960 __module_get(THIS_MODULE);
30961
30962 mutex_init(&gameport->drv_mutex);
30963 device_initialize(&gameport->dev);
30964- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
30965+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30966 gameport->dev.bus = &gameport_bus;
30967 gameport->dev.release = gameport_release_port;
30968 if (gameport->parent)
30969diff -urNp linux-2.6.32.43/drivers/input/input.c linux-2.6.32.43/drivers/input/input.c
30970--- linux-2.6.32.43/drivers/input/input.c 2011-03-27 14:31:47.000000000 -0400
30971+++ linux-2.6.32.43/drivers/input/input.c 2011-05-04 17:56:28.000000000 -0400
30972@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
30973 */
30974 int input_register_device(struct input_dev *dev)
30975 {
30976- static atomic_t input_no = ATOMIC_INIT(0);
30977+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30978 struct input_handler *handler;
30979 const char *path;
30980 int error;
30981@@ -1585,7 +1585,7 @@ int input_register_device(struct input_d
30982 dev->setkeycode = input_default_setkeycode;
30983
30984 dev_set_name(&dev->dev, "input%ld",
30985- (unsigned long) atomic_inc_return(&input_no) - 1);
30986+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30987
30988 error = device_add(&dev->dev);
30989 if (error)
30990diff -urNp linux-2.6.32.43/drivers/input/joystick/sidewinder.c linux-2.6.32.43/drivers/input/joystick/sidewinder.c
30991--- linux-2.6.32.43/drivers/input/joystick/sidewinder.c 2011-03-27 14:31:47.000000000 -0400
30992+++ linux-2.6.32.43/drivers/input/joystick/sidewinder.c 2011-05-18 20:09:36.000000000 -0400
30993@@ -30,6 +30,7 @@
30994 #include <linux/kernel.h>
30995 #include <linux/module.h>
30996 #include <linux/slab.h>
30997+#include <linux/sched.h>
30998 #include <linux/init.h>
30999 #include <linux/input.h>
31000 #include <linux/gameport.h>
31001@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31002 unsigned char buf[SW_LENGTH];
31003 int i;
31004
31005+ pax_track_stack();
31006+
31007 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31008
31009 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31010diff -urNp linux-2.6.32.43/drivers/input/joystick/xpad.c linux-2.6.32.43/drivers/input/joystick/xpad.c
31011--- linux-2.6.32.43/drivers/input/joystick/xpad.c 2011-03-27 14:31:47.000000000 -0400
31012+++ linux-2.6.32.43/drivers/input/joystick/xpad.c 2011-05-04 17:56:28.000000000 -0400
31013@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_clas
31014
31015 static int xpad_led_probe(struct usb_xpad *xpad)
31016 {
31017- static atomic_t led_seq = ATOMIC_INIT(0);
31018+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31019 long led_no;
31020 struct xpad_led *led;
31021 struct led_classdev *led_cdev;
31022@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpa
31023 if (!led)
31024 return -ENOMEM;
31025
31026- led_no = (long)atomic_inc_return(&led_seq) - 1;
31027+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31028
31029 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31030 led->xpad = xpad;
31031diff -urNp linux-2.6.32.43/drivers/input/serio/serio.c linux-2.6.32.43/drivers/input/serio/serio.c
31032--- linux-2.6.32.43/drivers/input/serio/serio.c 2011-03-27 14:31:47.000000000 -0400
31033+++ linux-2.6.32.43/drivers/input/serio/serio.c 2011-05-04 17:56:28.000000000 -0400
31034@@ -527,7 +527,7 @@ static void serio_release_port(struct de
31035 */
31036 static void serio_init_port(struct serio *serio)
31037 {
31038- static atomic_t serio_no = ATOMIC_INIT(0);
31039+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31040
31041 __module_get(THIS_MODULE);
31042
31043@@ -536,7 +536,7 @@ static void serio_init_port(struct serio
31044 mutex_init(&serio->drv_mutex);
31045 device_initialize(&serio->dev);
31046 dev_set_name(&serio->dev, "serio%ld",
31047- (long)atomic_inc_return(&serio_no) - 1);
31048+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
31049 serio->dev.bus = &serio_bus;
31050 serio->dev.release = serio_release_port;
31051 if (serio->parent) {
31052diff -urNp linux-2.6.32.43/drivers/isdn/gigaset/common.c linux-2.6.32.43/drivers/isdn/gigaset/common.c
31053--- linux-2.6.32.43/drivers/isdn/gigaset/common.c 2011-03-27 14:31:47.000000000 -0400
31054+++ linux-2.6.32.43/drivers/isdn/gigaset/common.c 2011-04-17 15:56:46.000000000 -0400
31055@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct
31056 cs->commands_pending = 0;
31057 cs->cur_at_seq = 0;
31058 cs->gotfwver = -1;
31059- cs->open_count = 0;
31060+ local_set(&cs->open_count, 0);
31061 cs->dev = NULL;
31062 cs->tty = NULL;
31063 cs->tty_dev = NULL;
31064diff -urNp linux-2.6.32.43/drivers/isdn/gigaset/gigaset.h linux-2.6.32.43/drivers/isdn/gigaset/gigaset.h
31065--- linux-2.6.32.43/drivers/isdn/gigaset/gigaset.h 2011-03-27 14:31:47.000000000 -0400
31066+++ linux-2.6.32.43/drivers/isdn/gigaset/gigaset.h 2011-04-17 15:56:46.000000000 -0400
31067@@ -34,6 +34,7 @@
31068 #include <linux/tty_driver.h>
31069 #include <linux/list.h>
31070 #include <asm/atomic.h>
31071+#include <asm/local.h>
31072
31073 #define GIG_VERSION {0,5,0,0}
31074 #define GIG_COMPAT {0,4,0,0}
31075@@ -446,7 +447,7 @@ struct cardstate {
31076 spinlock_t cmdlock;
31077 unsigned curlen, cmdbytes;
31078
31079- unsigned open_count;
31080+ local_t open_count;
31081 struct tty_struct *tty;
31082 struct tasklet_struct if_wake_tasklet;
31083 unsigned control_state;
31084diff -urNp linux-2.6.32.43/drivers/isdn/gigaset/interface.c linux-2.6.32.43/drivers/isdn/gigaset/interface.c
31085--- linux-2.6.32.43/drivers/isdn/gigaset/interface.c 2011-03-27 14:31:47.000000000 -0400
31086+++ linux-2.6.32.43/drivers/isdn/gigaset/interface.c 2011-04-17 15:56:46.000000000 -0400
31087@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tt
31088 return -ERESTARTSYS; // FIXME -EINTR?
31089 tty->driver_data = cs;
31090
31091- ++cs->open_count;
31092-
31093- if (cs->open_count == 1) {
31094+ if (local_inc_return(&cs->open_count) == 1) {
31095 spin_lock_irqsave(&cs->lock, flags);
31096 cs->tty = tty;
31097 spin_unlock_irqrestore(&cs->lock, flags);
31098@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *
31099
31100 if (!cs->connected)
31101 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31102- else if (!cs->open_count)
31103+ else if (!local_read(&cs->open_count))
31104 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31105 else {
31106- if (!--cs->open_count) {
31107+ if (!local_dec_return(&cs->open_count)) {
31108 spin_lock_irqsave(&cs->lock, flags);
31109 cs->tty = NULL;
31110 spin_unlock_irqrestore(&cs->lock, flags);
31111@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *t
31112 if (!cs->connected) {
31113 gig_dbg(DEBUG_IF, "not connected");
31114 retval = -ENODEV;
31115- } else if (!cs->open_count)
31116+ } else if (!local_read(&cs->open_count))
31117 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31118 else {
31119 retval = 0;
31120@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *t
31121 if (!cs->connected) {
31122 gig_dbg(DEBUG_IF, "not connected");
31123 retval = -ENODEV;
31124- } else if (!cs->open_count)
31125+ } else if (!local_read(&cs->open_count))
31126 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31127 else if (cs->mstate != MS_LOCKED) {
31128 dev_warn(cs->dev, "can't write to unlocked device\n");
31129@@ -395,7 +393,7 @@ static int if_write_room(struct tty_stru
31130 if (!cs->connected) {
31131 gig_dbg(DEBUG_IF, "not connected");
31132 retval = -ENODEV;
31133- } else if (!cs->open_count)
31134+ } else if (!local_read(&cs->open_count))
31135 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31136 else if (cs->mstate != MS_LOCKED) {
31137 dev_warn(cs->dev, "can't write to unlocked device\n");
31138@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty
31139
31140 if (!cs->connected)
31141 gig_dbg(DEBUG_IF, "not connected");
31142- else if (!cs->open_count)
31143+ else if (!local_read(&cs->open_count))
31144 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31145 else if (cs->mstate != MS_LOCKED)
31146 dev_warn(cs->dev, "can't write to unlocked device\n");
31147@@ -453,7 +451,7 @@ static void if_throttle(struct tty_struc
31148
31149 if (!cs->connected)
31150 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31151- else if (!cs->open_count)
31152+ else if (!local_read(&cs->open_count))
31153 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31154 else {
31155 //FIXME
31156@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_str
31157
31158 if (!cs->connected)
31159 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31160- else if (!cs->open_count)
31161+ else if (!local_read(&cs->open_count))
31162 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31163 else {
31164 //FIXME
31165@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_st
31166 goto out;
31167 }
31168
31169- if (!cs->open_count) {
31170+ if (!local_read(&cs->open_count)) {
31171 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31172 goto out;
31173 }
31174diff -urNp linux-2.6.32.43/drivers/isdn/hardware/avm/b1.c linux-2.6.32.43/drivers/isdn/hardware/avm/b1.c
31175--- linux-2.6.32.43/drivers/isdn/hardware/avm/b1.c 2011-03-27 14:31:47.000000000 -0400
31176+++ linux-2.6.32.43/drivers/isdn/hardware/avm/b1.c 2011-04-17 15:56:46.000000000 -0400
31177@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capilo
31178 }
31179 if (left) {
31180 if (t4file->user) {
31181- if (copy_from_user(buf, dp, left))
31182+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31183 return -EFAULT;
31184 } else {
31185 memcpy(buf, dp, left);
31186@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capilo
31187 }
31188 if (left) {
31189 if (config->user) {
31190- if (copy_from_user(buf, dp, left))
31191+ if (left > sizeof buf || copy_from_user(buf, dp, left))
31192 return -EFAULT;
31193 } else {
31194 memcpy(buf, dp, left);
31195diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.32.43/drivers/isdn/hardware/eicon/capidtmf.c
31196--- linux-2.6.32.43/drivers/isdn/hardware/eicon/capidtmf.c 2011-03-27 14:31:47.000000000 -0400
31197+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-16 21:46:57.000000000 -0400
31198@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31199 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31200 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31201
31202+ pax_track_stack();
31203
31204 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31205 {
31206diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.32.43/drivers/isdn/hardware/eicon/capifunc.c
31207--- linux-2.6.32.43/drivers/isdn/hardware/eicon/capifunc.c 2011-03-27 14:31:47.000000000 -0400
31208+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/capifunc.c 2011-05-16 21:46:57.000000000 -0400
31209@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31210 IDI_SYNC_REQ req;
31211 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31212
31213+ pax_track_stack();
31214+
31215 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31216
31217 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31218diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.32.43/drivers/isdn/hardware/eicon/diddfunc.c
31219--- linux-2.6.32.43/drivers/isdn/hardware/eicon/diddfunc.c 2011-03-27 14:31:47.000000000 -0400
31220+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-16 21:46:57.000000000 -0400
31221@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31222 IDI_SYNC_REQ req;
31223 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31224
31225+ pax_track_stack();
31226+
31227 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31228
31229 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31230diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.32.43/drivers/isdn/hardware/eicon/divasfunc.c
31231--- linux-2.6.32.43/drivers/isdn/hardware/eicon/divasfunc.c 2011-03-27 14:31:47.000000000 -0400
31232+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-16 21:46:57.000000000 -0400
31233@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31234 IDI_SYNC_REQ req;
31235 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31236
31237+ pax_track_stack();
31238+
31239 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31240
31241 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31242diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/divasync.h linux-2.6.32.43/drivers/isdn/hardware/eicon/divasync.h
31243--- linux-2.6.32.43/drivers/isdn/hardware/eicon/divasync.h 2011-03-27 14:31:47.000000000 -0400
31244+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/divasync.h 2011-08-05 20:33:55.000000000 -0400
31245@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
31246 } diva_didd_add_adapter_t;
31247 typedef struct _diva_didd_remove_adapter {
31248 IDI_CALL p_request;
31249-} diva_didd_remove_adapter_t;
31250+} __no_const diva_didd_remove_adapter_t;
31251 typedef struct _diva_didd_read_adapter_array {
31252 void * buffer;
31253 dword length;
31254diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.32.43/drivers/isdn/hardware/eicon/idifunc.c
31255--- linux-2.6.32.43/drivers/isdn/hardware/eicon/idifunc.c 2011-03-27 14:31:47.000000000 -0400
31256+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/idifunc.c 2011-05-16 21:46:57.000000000 -0400
31257@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31258 IDI_SYNC_REQ req;
31259 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31260
31261+ pax_track_stack();
31262+
31263 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31264
31265 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31266diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/message.c linux-2.6.32.43/drivers/isdn/hardware/eicon/message.c
31267--- linux-2.6.32.43/drivers/isdn/hardware/eicon/message.c 2011-03-27 14:31:47.000000000 -0400
31268+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/message.c 2011-05-16 21:46:57.000000000 -0400
31269@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31270 dword d;
31271 word w;
31272
31273+ pax_track_stack();
31274+
31275 a = plci->adapter;
31276 Id = ((word)plci->Id<<8)|a->Id;
31277 PUT_WORD(&SS_Ind[4],0x0000);
31278@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31279 word j, n, w;
31280 dword d;
31281
31282+ pax_track_stack();
31283+
31284
31285 for(i=0;i<8;i++) bp_parms[i].length = 0;
31286 for(i=0;i<2;i++) global_config[i].length = 0;
31287@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31288 const byte llc3[] = {4,3,2,2,6,6,0};
31289 const byte header[] = {0,2,3,3,0,0,0};
31290
31291+ pax_track_stack();
31292+
31293 for(i=0;i<8;i++) bp_parms[i].length = 0;
31294 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31295 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31296@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI
31297 word appl_number_group_type[MAX_APPL];
31298 PLCI *auxplci;
31299
31300+ pax_track_stack();
31301+
31302 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31303
31304 if(!a->group_optimization_enabled)
31305diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.32.43/drivers/isdn/hardware/eicon/mntfunc.c
31306--- linux-2.6.32.43/drivers/isdn/hardware/eicon/mntfunc.c 2011-03-27 14:31:47.000000000 -0400
31307+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-16 21:46:57.000000000 -0400
31308@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31309 IDI_SYNC_REQ req;
31310 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31311
31312+ pax_track_stack();
31313+
31314 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31315
31316 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31317diff -urNp linux-2.6.32.43/drivers/isdn/hardware/eicon/xdi_adapter.h linux-2.6.32.43/drivers/isdn/hardware/eicon/xdi_adapter.h
31318--- linux-2.6.32.43/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-03-27 14:31:47.000000000 -0400
31319+++ linux-2.6.32.43/drivers/isdn/hardware/eicon/xdi_adapter.h 2011-08-05 20:33:55.000000000 -0400
31320@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
31321 typedef struct _diva_os_idi_adapter_interface {
31322 diva_init_card_proc_t cleanup_adapter_proc;
31323 diva_cmd_card_proc_t cmd_proc;
31324-} diva_os_idi_adapter_interface_t;
31325+} __no_const diva_os_idi_adapter_interface_t;
31326
31327 typedef struct _diva_os_xdi_adapter {
31328 struct list_head link;
31329diff -urNp linux-2.6.32.43/drivers/isdn/i4l/isdn_common.c linux-2.6.32.43/drivers/isdn/i4l/isdn_common.c
31330--- linux-2.6.32.43/drivers/isdn/i4l/isdn_common.c 2011-03-27 14:31:47.000000000 -0400
31331+++ linux-2.6.32.43/drivers/isdn/i4l/isdn_common.c 2011-05-16 21:46:57.000000000 -0400
31332@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct f
31333 } iocpar;
31334 void __user *argp = (void __user *)arg;
31335
31336+ pax_track_stack();
31337+
31338 #define name iocpar.name
31339 #define bname iocpar.bname
31340 #define iocts iocpar.iocts
31341diff -urNp linux-2.6.32.43/drivers/isdn/icn/icn.c linux-2.6.32.43/drivers/isdn/icn/icn.c
31342--- linux-2.6.32.43/drivers/isdn/icn/icn.c 2011-03-27 14:31:47.000000000 -0400
31343+++ linux-2.6.32.43/drivers/isdn/icn/icn.c 2011-04-17 15:56:46.000000000 -0400
31344@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len
31345 if (count > len)
31346 count = len;
31347 if (user) {
31348- if (copy_from_user(msg, buf, count))
31349+ if (count > sizeof msg || copy_from_user(msg, buf, count))
31350 return -EFAULT;
31351 } else
31352 memcpy(msg, buf, count);
31353diff -urNp linux-2.6.32.43/drivers/isdn/mISDN/socket.c linux-2.6.32.43/drivers/isdn/mISDN/socket.c
31354--- linux-2.6.32.43/drivers/isdn/mISDN/socket.c 2011-03-27 14:31:47.000000000 -0400
31355+++ linux-2.6.32.43/drivers/isdn/mISDN/socket.c 2011-04-17 15:56:46.000000000 -0400
31356@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, uns
31357 if (dev) {
31358 struct mISDN_devinfo di;
31359
31360+ memset(&di, 0, sizeof(di));
31361 di.id = dev->id;
31362 di.Dprotocols = dev->Dprotocols;
31363 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
31364@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, uns
31365 if (dev) {
31366 struct mISDN_devinfo di;
31367
31368+ memset(&di, 0, sizeof(di));
31369 di.id = dev->id;
31370 di.Dprotocols = dev->Dprotocols;
31371 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
31372diff -urNp linux-2.6.32.43/drivers/isdn/sc/interrupt.c linux-2.6.32.43/drivers/isdn/sc/interrupt.c
31373--- linux-2.6.32.43/drivers/isdn/sc/interrupt.c 2011-03-27 14:31:47.000000000 -0400
31374+++ linux-2.6.32.43/drivers/isdn/sc/interrupt.c 2011-04-17 15:56:46.000000000 -0400
31375@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy,
31376 }
31377 else if(callid>=0x0000 && callid<=0x7FFF)
31378 {
31379+ int len;
31380+
31381 pr_debug("%s: Got Incoming Call\n",
31382 sc_adapter[card]->devicename);
31383- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
31384- strcpy(setup.eazmsn,
31385- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
31386+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
31387+ sizeof(setup.phone));
31388+ if (len >= sizeof(setup.phone))
31389+ continue;
31390+ len = strlcpy(setup.eazmsn,
31391+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
31392+ sizeof(setup.eazmsn));
31393+ if (len >= sizeof(setup.eazmsn))
31394+ continue;
31395 setup.si1 = 7;
31396 setup.si2 = 0;
31397 setup.plan = 0;
31398@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy,
31399 * Handle a GetMyNumber Rsp
31400 */
31401 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
31402- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
31403+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
31404+ rcvmsg.msg_data.byte_array,
31405+ sizeof(rcvmsg.msg_data.byte_array));
31406 continue;
31407 }
31408
31409diff -urNp linux-2.6.32.43/drivers/lguest/core.c linux-2.6.32.43/drivers/lguest/core.c
31410--- linux-2.6.32.43/drivers/lguest/core.c 2011-03-27 14:31:47.000000000 -0400
31411+++ linux-2.6.32.43/drivers/lguest/core.c 2011-04-17 15:56:46.000000000 -0400
31412@@ -91,9 +91,17 @@ static __init int map_switcher(void)
31413 * it's worked so far. The end address needs +1 because __get_vm_area
31414 * allocates an extra guard page, so we need space for that.
31415 */
31416+
31417+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31418+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31419+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31420+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31421+#else
31422 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31423 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31424 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31425+#endif
31426+
31427 if (!switcher_vma) {
31428 err = -ENOMEM;
31429 printk("lguest: could not map switcher pages high\n");
31430@@ -118,7 +126,7 @@ static __init int map_switcher(void)
31431 * Now the Switcher is mapped at the right address, we can't fail!
31432 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31433 */
31434- memcpy(switcher_vma->addr, start_switcher_text,
31435+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31436 end_switcher_text - start_switcher_text);
31437
31438 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31439diff -urNp linux-2.6.32.43/drivers/lguest/x86/core.c linux-2.6.32.43/drivers/lguest/x86/core.c
31440--- linux-2.6.32.43/drivers/lguest/x86/core.c 2011-03-27 14:31:47.000000000 -0400
31441+++ linux-2.6.32.43/drivers/lguest/x86/core.c 2011-04-17 15:56:46.000000000 -0400
31442@@ -59,7 +59,7 @@ static struct {
31443 /* Offset from where switcher.S was compiled to where we've copied it */
31444 static unsigned long switcher_offset(void)
31445 {
31446- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31447+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31448 }
31449
31450 /* This cpu's struct lguest_pages. */
31451@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31452 * These copies are pretty cheap, so we do them unconditionally: */
31453 /* Save the current Host top-level page directory.
31454 */
31455+
31456+#ifdef CONFIG_PAX_PER_CPU_PGD
31457+ pages->state.host_cr3 = read_cr3();
31458+#else
31459 pages->state.host_cr3 = __pa(current->mm->pgd);
31460+#endif
31461+
31462 /*
31463 * Set up the Guest's page tables to see this CPU's pages (and no
31464 * other CPU's pages).
31465@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
31466 * compiled-in switcher code and the high-mapped copy we just made.
31467 */
31468 for (i = 0; i < IDT_ENTRIES; i++)
31469- default_idt_entries[i] += switcher_offset();
31470+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31471
31472 /*
31473 * Set up the Switcher's per-cpu areas.
31474@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
31475 * it will be undisturbed when we switch. To change %cs and jump we
31476 * need this structure to feed to Intel's "lcall" instruction.
31477 */
31478- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31479+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31480 lguest_entry.segment = LGUEST_CS;
31481
31482 /*
31483diff -urNp linux-2.6.32.43/drivers/lguest/x86/switcher_32.S linux-2.6.32.43/drivers/lguest/x86/switcher_32.S
31484--- linux-2.6.32.43/drivers/lguest/x86/switcher_32.S 2011-03-27 14:31:47.000000000 -0400
31485+++ linux-2.6.32.43/drivers/lguest/x86/switcher_32.S 2011-04-17 15:56:46.000000000 -0400
31486@@ -87,6 +87,7 @@
31487 #include <asm/page.h>
31488 #include <asm/segment.h>
31489 #include <asm/lguest.h>
31490+#include <asm/processor-flags.h>
31491
31492 // We mark the start of the code to copy
31493 // It's placed in .text tho it's never run here
31494@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31495 // Changes type when we load it: damn Intel!
31496 // For after we switch over our page tables
31497 // That entry will be read-only: we'd crash.
31498+
31499+#ifdef CONFIG_PAX_KERNEXEC
31500+ mov %cr0, %edx
31501+ xor $X86_CR0_WP, %edx
31502+ mov %edx, %cr0
31503+#endif
31504+
31505 movl $(GDT_ENTRY_TSS*8), %edx
31506 ltr %dx
31507
31508@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31509 // Let's clear it again for our return.
31510 // The GDT descriptor of the Host
31511 // Points to the table after two "size" bytes
31512- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31513+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31514 // Clear "used" from type field (byte 5, bit 2)
31515- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31516+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31517+
31518+#ifdef CONFIG_PAX_KERNEXEC
31519+ mov %cr0, %eax
31520+ xor $X86_CR0_WP, %eax
31521+ mov %eax, %cr0
31522+#endif
31523
31524 // Once our page table's switched, the Guest is live!
31525 // The Host fades as we run this final step.
31526@@ -295,13 +309,12 @@ deliver_to_host:
31527 // I consulted gcc, and it gave
31528 // These instructions, which I gladly credit:
31529 leal (%edx,%ebx,8), %eax
31530- movzwl (%eax),%edx
31531- movl 4(%eax), %eax
31532- xorw %ax, %ax
31533- orl %eax, %edx
31534+ movl 4(%eax), %edx
31535+ movw (%eax), %dx
31536 // Now the address of the handler's in %edx
31537 // We call it now: its "iret" drops us home.
31538- jmp *%edx
31539+ ljmp $__KERNEL_CS, $1f
31540+1: jmp *%edx
31541
31542 // Every interrupt can come to us here
31543 // But we must truly tell each apart.
31544diff -urNp linux-2.6.32.43/drivers/macintosh/via-pmu-backlight.c linux-2.6.32.43/drivers/macintosh/via-pmu-backlight.c
31545--- linux-2.6.32.43/drivers/macintosh/via-pmu-backlight.c 2011-03-27 14:31:47.000000000 -0400
31546+++ linux-2.6.32.43/drivers/macintosh/via-pmu-backlight.c 2011-04-17 15:56:46.000000000 -0400
31547@@ -15,7 +15,7 @@
31548
31549 #define MAX_PMU_LEVEL 0xFF
31550
31551-static struct backlight_ops pmu_backlight_data;
31552+static const struct backlight_ops pmu_backlight_data;
31553 static DEFINE_SPINLOCK(pmu_backlight_lock);
31554 static int sleeping, uses_pmu_bl;
31555 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
31556@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(
31557 return bd->props.brightness;
31558 }
31559
31560-static struct backlight_ops pmu_backlight_data = {
31561+static const struct backlight_ops pmu_backlight_data = {
31562 .get_brightness = pmu_backlight_get_brightness,
31563 .update_status = pmu_backlight_update_status,
31564
31565diff -urNp linux-2.6.32.43/drivers/macintosh/via-pmu.c linux-2.6.32.43/drivers/macintosh/via-pmu.c
31566--- linux-2.6.32.43/drivers/macintosh/via-pmu.c 2011-03-27 14:31:47.000000000 -0400
31567+++ linux-2.6.32.43/drivers/macintosh/via-pmu.c 2011-04-17 15:56:46.000000000 -0400
31568@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state
31569 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
31570 }
31571
31572-static struct platform_suspend_ops pmu_pm_ops = {
31573+static const struct platform_suspend_ops pmu_pm_ops = {
31574 .enter = powerbook_sleep,
31575 .valid = pmu_sleep_valid,
31576 };
31577diff -urNp linux-2.6.32.43/drivers/md/dm.c linux-2.6.32.43/drivers/md/dm.c
31578--- linux-2.6.32.43/drivers/md/dm.c 2011-03-27 14:31:47.000000000 -0400
31579+++ linux-2.6.32.43/drivers/md/dm.c 2011-05-04 17:56:28.000000000 -0400
31580@@ -163,9 +163,9 @@ struct mapped_device {
31581 /*
31582 * Event handling.
31583 */
31584- atomic_t event_nr;
31585+ atomic_unchecked_t event_nr;
31586 wait_queue_head_t eventq;
31587- atomic_t uevent_seq;
31588+ atomic_unchecked_t uevent_seq;
31589 struct list_head uevent_list;
31590 spinlock_t uevent_lock; /* Protect access to uevent_list */
31591
31592@@ -1770,8 +1770,8 @@ static struct mapped_device *alloc_dev(i
31593 rwlock_init(&md->map_lock);
31594 atomic_set(&md->holders, 1);
31595 atomic_set(&md->open_count, 0);
31596- atomic_set(&md->event_nr, 0);
31597- atomic_set(&md->uevent_seq, 0);
31598+ atomic_set_unchecked(&md->event_nr, 0);
31599+ atomic_set_unchecked(&md->uevent_seq, 0);
31600 INIT_LIST_HEAD(&md->uevent_list);
31601 spin_lock_init(&md->uevent_lock);
31602
31603@@ -1921,7 +1921,7 @@ static void event_callback(void *context
31604
31605 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31606
31607- atomic_inc(&md->event_nr);
31608+ atomic_inc_unchecked(&md->event_nr);
31609 wake_up(&md->eventq);
31610 }
31611
31612@@ -2556,18 +2556,18 @@ void dm_kobject_uevent(struct mapped_dev
31613
31614 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31615 {
31616- return atomic_add_return(1, &md->uevent_seq);
31617+ return atomic_add_return_unchecked(1, &md->uevent_seq);
31618 }
31619
31620 uint32_t dm_get_event_nr(struct mapped_device *md)
31621 {
31622- return atomic_read(&md->event_nr);
31623+ return atomic_read_unchecked(&md->event_nr);
31624 }
31625
31626 int dm_wait_event(struct mapped_device *md, int event_nr)
31627 {
31628 return wait_event_interruptible(md->eventq,
31629- (event_nr != atomic_read(&md->event_nr)));
31630+ (event_nr != atomic_read_unchecked(&md->event_nr)));
31631 }
31632
31633 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31634diff -urNp linux-2.6.32.43/drivers/md/dm-ioctl.c linux-2.6.32.43/drivers/md/dm-ioctl.c
31635--- linux-2.6.32.43/drivers/md/dm-ioctl.c 2011-03-27 14:31:47.000000000 -0400
31636+++ linux-2.6.32.43/drivers/md/dm-ioctl.c 2011-04-17 15:56:46.000000000 -0400
31637@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, str
31638 cmd == DM_LIST_VERSIONS_CMD)
31639 return 0;
31640
31641- if ((cmd == DM_DEV_CREATE_CMD)) {
31642+ if (cmd == DM_DEV_CREATE_CMD) {
31643 if (!*param->name) {
31644 DMWARN("name not supplied when creating device");
31645 return -EINVAL;
31646diff -urNp linux-2.6.32.43/drivers/md/dm-raid1.c linux-2.6.32.43/drivers/md/dm-raid1.c
31647--- linux-2.6.32.43/drivers/md/dm-raid1.c 2011-03-27 14:31:47.000000000 -0400
31648+++ linux-2.6.32.43/drivers/md/dm-raid1.c 2011-05-04 17:56:28.000000000 -0400
31649@@ -41,7 +41,7 @@ enum dm_raid1_error {
31650
31651 struct mirror {
31652 struct mirror_set *ms;
31653- atomic_t error_count;
31654+ atomic_unchecked_t error_count;
31655 unsigned long error_type;
31656 struct dm_dev *dev;
31657 sector_t offset;
31658@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m
31659 * simple way to tell if a device has encountered
31660 * errors.
31661 */
31662- atomic_inc(&m->error_count);
31663+ atomic_inc_unchecked(&m->error_count);
31664
31665 if (test_and_set_bit(error_type, &m->error_type))
31666 return;
31667@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m
31668 }
31669
31670 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
31671- if (!atomic_read(&new->error_count)) {
31672+ if (!atomic_read_unchecked(&new->error_count)) {
31673 set_default_mirror(new);
31674 break;
31675 }
31676@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(stru
31677 struct mirror *m = get_default_mirror(ms);
31678
31679 do {
31680- if (likely(!atomic_read(&m->error_count)))
31681+ if (likely(!atomic_read_unchecked(&m->error_count)))
31682 return m;
31683
31684 if (m-- == ms->mirror)
31685@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
31686 {
31687 struct mirror *default_mirror = get_default_mirror(m->ms);
31688
31689- return !atomic_read(&default_mirror->error_count);
31690+ return !atomic_read_unchecked(&default_mirror->error_count);
31691 }
31692
31693 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31694@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *
31695 */
31696 if (likely(region_in_sync(ms, region, 1)))
31697 m = choose_mirror(ms, bio->bi_sector);
31698- else if (m && atomic_read(&m->error_count))
31699+ else if (m && atomic_read_unchecked(&m->error_count))
31700 m = NULL;
31701
31702 if (likely(m))
31703@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set
31704 }
31705
31706 ms->mirror[mirror].ms = ms;
31707- atomic_set(&(ms->mirror[mirror].error_count), 0);
31708+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31709 ms->mirror[mirror].error_type = 0;
31710 ms->mirror[mirror].offset = offset;
31711
31712@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_targ
31713 */
31714 static char device_status_char(struct mirror *m)
31715 {
31716- if (!atomic_read(&(m->error_count)))
31717+ if (!atomic_read_unchecked(&(m->error_count)))
31718 return 'A';
31719
31720 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
31721diff -urNp linux-2.6.32.43/drivers/md/dm-stripe.c linux-2.6.32.43/drivers/md/dm-stripe.c
31722--- linux-2.6.32.43/drivers/md/dm-stripe.c 2011-03-27 14:31:47.000000000 -0400
31723+++ linux-2.6.32.43/drivers/md/dm-stripe.c 2011-05-04 17:56:28.000000000 -0400
31724@@ -20,7 +20,7 @@ struct stripe {
31725 struct dm_dev *dev;
31726 sector_t physical_start;
31727
31728- atomic_t error_count;
31729+ atomic_unchecked_t error_count;
31730 };
31731
31732 struct stripe_c {
31733@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *
31734 kfree(sc);
31735 return r;
31736 }
31737- atomic_set(&(sc->stripe[i].error_count), 0);
31738+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31739 }
31740
31741 ti->private = sc;
31742@@ -257,7 +257,7 @@ static int stripe_status(struct dm_targe
31743 DMEMIT("%d ", sc->stripes);
31744 for (i = 0; i < sc->stripes; i++) {
31745 DMEMIT("%s ", sc->stripe[i].dev->name);
31746- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31747+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31748 'D' : 'A';
31749 }
31750 buffer[i] = '\0';
31751@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_targe
31752 */
31753 for (i = 0; i < sc->stripes; i++)
31754 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31755- atomic_inc(&(sc->stripe[i].error_count));
31756- if (atomic_read(&(sc->stripe[i].error_count)) <
31757+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
31758+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31759 DM_IO_ERROR_THRESHOLD)
31760 queue_work(kstriped, &sc->kstriped_ws);
31761 }
31762diff -urNp linux-2.6.32.43/drivers/md/dm-sysfs.c linux-2.6.32.43/drivers/md/dm-sysfs.c
31763--- linux-2.6.32.43/drivers/md/dm-sysfs.c 2011-03-27 14:31:47.000000000 -0400
31764+++ linux-2.6.32.43/drivers/md/dm-sysfs.c 2011-04-17 15:56:46.000000000 -0400
31765@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
31766 NULL,
31767 };
31768
31769-static struct sysfs_ops dm_sysfs_ops = {
31770+static const struct sysfs_ops dm_sysfs_ops = {
31771 .show = dm_attr_show,
31772 };
31773
31774diff -urNp linux-2.6.32.43/drivers/md/dm-table.c linux-2.6.32.43/drivers/md/dm-table.c
31775--- linux-2.6.32.43/drivers/md/dm-table.c 2011-06-25 12:55:34.000000000 -0400
31776+++ linux-2.6.32.43/drivers/md/dm-table.c 2011-06-25 12:56:37.000000000 -0400
31777@@ -376,7 +376,7 @@ static int device_area_is_invalid(struct
31778 if (!dev_size)
31779 return 0;
31780
31781- if ((start >= dev_size) || (start + len > dev_size)) {
31782+ if ((start >= dev_size) || (len > dev_size - start)) {
31783 DMWARN("%s: %s too small for target: "
31784 "start=%llu, len=%llu, dev_size=%llu",
31785 dm_device_name(ti->table->md), bdevname(bdev, b),
31786diff -urNp linux-2.6.32.43/drivers/md/md.c linux-2.6.32.43/drivers/md/md.c
31787--- linux-2.6.32.43/drivers/md/md.c 2011-07-13 17:23:04.000000000 -0400
31788+++ linux-2.6.32.43/drivers/md/md.c 2011-07-13 17:23:18.000000000 -0400
31789@@ -153,10 +153,10 @@ static int start_readonly;
31790 * start build, activate spare
31791 */
31792 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31793-static atomic_t md_event_count;
31794+static atomic_unchecked_t md_event_count;
31795 void md_new_event(mddev_t *mddev)
31796 {
31797- atomic_inc(&md_event_count);
31798+ atomic_inc_unchecked(&md_event_count);
31799 wake_up(&md_event_waiters);
31800 }
31801 EXPORT_SYMBOL_GPL(md_new_event);
31802@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31803 */
31804 static void md_new_event_inintr(mddev_t *mddev)
31805 {
31806- atomic_inc(&md_event_count);
31807+ atomic_inc_unchecked(&md_event_count);
31808 wake_up(&md_event_waiters);
31809 }
31810
31811@@ -1218,7 +1218,7 @@ static int super_1_load(mdk_rdev_t *rdev
31812
31813 rdev->preferred_minor = 0xffff;
31814 rdev->data_offset = le64_to_cpu(sb->data_offset);
31815- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31816+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31817
31818 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31819 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31820@@ -1392,7 +1392,7 @@ static void super_1_sync(mddev_t *mddev,
31821 else
31822 sb->resync_offset = cpu_to_le64(0);
31823
31824- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31825+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31826
31827 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31828 sb->size = cpu_to_le64(mddev->dev_sectors);
31829@@ -2214,7 +2214,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
31830 static ssize_t
31831 errors_show(mdk_rdev_t *rdev, char *page)
31832 {
31833- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31834+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31835 }
31836
31837 static ssize_t
31838@@ -2223,7 +2223,7 @@ errors_store(mdk_rdev_t *rdev, const cha
31839 char *e;
31840 unsigned long n = simple_strtoul(buf, &e, 10);
31841 if (*buf && (*e == 0 || *e == '\n')) {
31842- atomic_set(&rdev->corrected_errors, n);
31843+ atomic_set_unchecked(&rdev->corrected_errors, n);
31844 return len;
31845 }
31846 return -EINVAL;
31847@@ -2517,7 +2517,7 @@ static void rdev_free(struct kobject *ko
31848 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
31849 kfree(rdev);
31850 }
31851-static struct sysfs_ops rdev_sysfs_ops = {
31852+static const struct sysfs_ops rdev_sysfs_ops = {
31853 .show = rdev_attr_show,
31854 .store = rdev_attr_store,
31855 };
31856@@ -2566,8 +2566,8 @@ static mdk_rdev_t *md_import_device(dev_
31857 rdev->data_offset = 0;
31858 rdev->sb_events = 0;
31859 atomic_set(&rdev->nr_pending, 0);
31860- atomic_set(&rdev->read_errors, 0);
31861- atomic_set(&rdev->corrected_errors, 0);
31862+ atomic_set_unchecked(&rdev->read_errors, 0);
31863+ atomic_set_unchecked(&rdev->corrected_errors, 0);
31864
31865 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
31866 if (!size) {
31867@@ -3887,7 +3887,7 @@ static void md_free(struct kobject *ko)
31868 kfree(mddev);
31869 }
31870
31871-static struct sysfs_ops md_sysfs_ops = {
31872+static const struct sysfs_ops md_sysfs_ops = {
31873 .show = md_attr_show,
31874 .store = md_attr_store,
31875 };
31876@@ -4474,7 +4474,8 @@ out:
31877 err = 0;
31878 blk_integrity_unregister(disk);
31879 md_new_event(mddev);
31880- sysfs_notify_dirent(mddev->sysfs_state);
31881+ if (mddev->sysfs_state)
31882+ sysfs_notify_dirent(mddev->sysfs_state);
31883 return err;
31884 }
31885
31886@@ -5954,7 +5955,7 @@ static int md_seq_show(struct seq_file *
31887
31888 spin_unlock(&pers_lock);
31889 seq_printf(seq, "\n");
31890- mi->event = atomic_read(&md_event_count);
31891+ mi->event = atomic_read_unchecked(&md_event_count);
31892 return 0;
31893 }
31894 if (v == (void*)2) {
31895@@ -6043,7 +6044,7 @@ static int md_seq_show(struct seq_file *
31896 chunk_kb ? "KB" : "B");
31897 if (bitmap->file) {
31898 seq_printf(seq, ", file: ");
31899- seq_path(seq, &bitmap->file->f_path, " \t\n");
31900+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31901 }
31902
31903 seq_printf(seq, "\n");
31904@@ -6077,7 +6078,7 @@ static int md_seq_open(struct inode *ino
31905 else {
31906 struct seq_file *p = file->private_data;
31907 p->private = mi;
31908- mi->event = atomic_read(&md_event_count);
31909+ mi->event = atomic_read_unchecked(&md_event_count);
31910 }
31911 return error;
31912 }
31913@@ -6093,7 +6094,7 @@ static unsigned int mdstat_poll(struct f
31914 /* always allow read */
31915 mask = POLLIN | POLLRDNORM;
31916
31917- if (mi->event != atomic_read(&md_event_count))
31918+ if (mi->event != atomic_read_unchecked(&md_event_count))
31919 mask |= POLLERR | POLLPRI;
31920 return mask;
31921 }
31922@@ -6137,7 +6138,7 @@ static int is_mddev_idle(mddev_t *mddev,
31923 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31924 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31925 (int)part_stat_read(&disk->part0, sectors[1]) -
31926- atomic_read(&disk->sync_io);
31927+ atomic_read_unchecked(&disk->sync_io);
31928 /* sync IO will cause sync_io to increase before the disk_stats
31929 * as sync_io is counted when a request starts, and
31930 * disk_stats is counted when it completes.
31931diff -urNp linux-2.6.32.43/drivers/md/md.h linux-2.6.32.43/drivers/md/md.h
31932--- linux-2.6.32.43/drivers/md/md.h 2011-03-27 14:31:47.000000000 -0400
31933+++ linux-2.6.32.43/drivers/md/md.h 2011-05-04 17:56:20.000000000 -0400
31934@@ -94,10 +94,10 @@ struct mdk_rdev_s
31935 * only maintained for arrays that
31936 * support hot removal
31937 */
31938- atomic_t read_errors; /* number of consecutive read errors that
31939+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
31940 * we have tried to ignore.
31941 */
31942- atomic_t corrected_errors; /* number of corrected read errors,
31943+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31944 * for reporting to userspace and storing
31945 * in superblock.
31946 */
31947@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_
31948
31949 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31950 {
31951- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31952+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31953 }
31954
31955 struct mdk_personality
31956diff -urNp linux-2.6.32.43/drivers/md/raid10.c linux-2.6.32.43/drivers/md/raid10.c
31957--- linux-2.6.32.43/drivers/md/raid10.c 2011-03-27 14:31:47.000000000 -0400
31958+++ linux-2.6.32.43/drivers/md/raid10.c 2011-05-04 17:56:28.000000000 -0400
31959@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bi
31960 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
31961 set_bit(R10BIO_Uptodate, &r10_bio->state);
31962 else {
31963- atomic_add(r10_bio->sectors,
31964+ atomic_add_unchecked(r10_bio->sectors,
31965 &conf->mirrors[d].rdev->corrected_errors);
31966 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
31967 md_error(r10_bio->mddev,
31968@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf,
31969 test_bit(In_sync, &rdev->flags)) {
31970 atomic_inc(&rdev->nr_pending);
31971 rcu_read_unlock();
31972- atomic_add(s, &rdev->corrected_errors);
31973+ atomic_add_unchecked(s, &rdev->corrected_errors);
31974 if (sync_page_io(rdev->bdev,
31975 r10_bio->devs[sl].addr +
31976 sect + rdev->data_offset,
31977diff -urNp linux-2.6.32.43/drivers/md/raid1.c linux-2.6.32.43/drivers/md/raid1.c
31978--- linux-2.6.32.43/drivers/md/raid1.c 2011-03-27 14:31:47.000000000 -0400
31979+++ linux-2.6.32.43/drivers/md/raid1.c 2011-05-04 17:56:28.000000000 -0400
31980@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *
31981 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
31982 continue;
31983 rdev = conf->mirrors[d].rdev;
31984- atomic_add(s, &rdev->corrected_errors);
31985+ atomic_add_unchecked(s, &rdev->corrected_errors);
31986 if (sync_page_io(rdev->bdev,
31987 sect + rdev->data_offset,
31988 s<<9,
31989@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf,
31990 /* Well, this device is dead */
31991 md_error(mddev, rdev);
31992 else {
31993- atomic_add(s, &rdev->corrected_errors);
31994+ atomic_add_unchecked(s, &rdev->corrected_errors);
31995 printk(KERN_INFO
31996 "raid1:%s: read error corrected "
31997 "(%d sectors at %llu on %s)\n",
31998diff -urNp linux-2.6.32.43/drivers/md/raid5.c linux-2.6.32.43/drivers/md/raid5.c
31999--- linux-2.6.32.43/drivers/md/raid5.c 2011-06-25 12:55:34.000000000 -0400
32000+++ linux-2.6.32.43/drivers/md/raid5.c 2011-06-25 12:58:39.000000000 -0400
32001@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_hea
32002 bi->bi_next = NULL;
32003 if ((rw & WRITE) &&
32004 test_bit(R5_ReWrite, &sh->dev[i].flags))
32005- atomic_add(STRIPE_SECTORS,
32006+ atomic_add_unchecked(STRIPE_SECTORS,
32007 &rdev->corrected_errors);
32008 generic_make_request(bi);
32009 } else {
32010@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struc
32011 clear_bit(R5_ReadError, &sh->dev[i].flags);
32012 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32013 }
32014- if (atomic_read(&conf->disks[i].rdev->read_errors))
32015- atomic_set(&conf->disks[i].rdev->read_errors, 0);
32016+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32017+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32018 } else {
32019 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32020 int retry = 0;
32021 rdev = conf->disks[i].rdev;
32022
32023 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32024- atomic_inc(&rdev->read_errors);
32025+ atomic_inc_unchecked(&rdev->read_errors);
32026 if (conf->mddev->degraded >= conf->max_degraded)
32027 printk_rl(KERN_WARNING
32028 "raid5:%s: read error not correctable "
32029@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struc
32030 (unsigned long long)(sh->sector
32031 + rdev->data_offset),
32032 bdn);
32033- else if (atomic_read(&rdev->read_errors)
32034+ else if (atomic_read_unchecked(&rdev->read_errors)
32035 > conf->max_nr_stripes)
32036 printk(KERN_WARNING
32037 "raid5:%s: Too many read errors, failing device %s.\n",
32038@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct s
32039 sector_t r_sector;
32040 struct stripe_head sh2;
32041
32042+ pax_track_stack();
32043
32044 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32045 stripe = new_sector;
32046diff -urNp linux-2.6.32.43/drivers/media/common/saa7146_fops.c linux-2.6.32.43/drivers/media/common/saa7146_fops.c
32047--- linux-2.6.32.43/drivers/media/common/saa7146_fops.c 2011-03-27 14:31:47.000000000 -0400
32048+++ linux-2.6.32.43/drivers/media/common/saa7146_fops.c 2011-08-05 20:33:55.000000000 -0400
32049@@ -458,7 +458,7 @@ int saa7146_vv_init(struct saa7146_dev*
32050 ERR(("out of memory. aborting.\n"));
32051 return -ENOMEM;
32052 }
32053- ext_vv->ops = saa7146_video_ioctl_ops;
32054+ memcpy((void *)&ext_vv->ops, &saa7146_video_ioctl_ops, sizeof(saa7146_video_ioctl_ops));
32055 ext_vv->core_ops = &saa7146_video_ioctl_ops;
32056
32057 DEB_EE(("dev:%p\n",dev));
32058diff -urNp linux-2.6.32.43/drivers/media/common/saa7146_hlp.c linux-2.6.32.43/drivers/media/common/saa7146_hlp.c
32059--- linux-2.6.32.43/drivers/media/common/saa7146_hlp.c 2011-03-27 14:31:47.000000000 -0400
32060+++ linux-2.6.32.43/drivers/media/common/saa7146_hlp.c 2011-05-16 21:46:57.000000000 -0400
32061@@ -353,6 +353,8 @@ static void calculate_clipping_registers
32062
32063 int x[32], y[32], w[32], h[32];
32064
32065+ pax_track_stack();
32066+
32067 /* clear out memory */
32068 memset(&line_list[0], 0x00, sizeof(u32)*32);
32069 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32070diff -urNp linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
32071--- linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-03-27 14:31:47.000000000 -0400
32072+++ linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-16 21:46:57.000000000 -0400
32073@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32074 u8 buf[HOST_LINK_BUF_SIZE];
32075 int i;
32076
32077+ pax_track_stack();
32078+
32079 dprintk("%s\n", __func__);
32080
32081 /* check if we have space for a link buf in the rx_buffer */
32082@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32083 unsigned long timeout;
32084 int written;
32085
32086+ pax_track_stack();
32087+
32088 dprintk("%s\n", __func__);
32089
32090 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32091diff -urNp linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_demux.h linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_demux.h
32092--- linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_demux.h 2011-03-27 14:31:47.000000000 -0400
32093+++ linux-2.6.32.43/drivers/media/dvb/dvb-core/dvb_demux.h 2011-08-05 20:33:55.000000000 -0400
32094@@ -71,7 +71,7 @@ struct dvb_demux_feed {
32095 union {
32096 dmx_ts_cb ts;
32097 dmx_section_cb sec;
32098- } cb;
32099+ } __no_const cb;
32100
32101 struct dvb_demux *demux;
32102 void *priv;
32103diff -urNp linux-2.6.32.43/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.32.43/drivers/media/dvb/dvb-core/dvbdev.c
32104--- linux-2.6.32.43/drivers/media/dvb/dvb-core/dvbdev.c 2011-03-27 14:31:47.000000000 -0400
32105+++ linux-2.6.32.43/drivers/media/dvb/dvb-core/dvbdev.c 2011-08-05 20:33:55.000000000 -0400
32106@@ -228,8 +228,8 @@ int dvb_register_device(struct dvb_adapt
32107 dvbdev->fops = dvbdevfops;
32108 init_waitqueue_head (&dvbdev->wait_queue);
32109
32110- memcpy(dvbdevfops, template->fops, sizeof(struct file_operations));
32111- dvbdevfops->owner = adap->module;
32112+ memcpy((void *)dvbdevfops, template->fops, sizeof(struct file_operations));
32113+ *(void **)&dvbdevfops->owner = adap->module;
32114
32115 list_add_tail (&dvbdev->list_head, &adap->device_list);
32116
32117diff -urNp linux-2.6.32.43/drivers/media/dvb/dvb-usb/cxusb.c linux-2.6.32.43/drivers/media/dvb/dvb-usb/cxusb.c
32118--- linux-2.6.32.43/drivers/media/dvb/dvb-usb/cxusb.c 2011-03-27 14:31:47.000000000 -0400
32119+++ linux-2.6.32.43/drivers/media/dvb/dvb-usb/cxusb.c 2011-08-05 20:33:55.000000000 -0400
32120@@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_di
32121 struct dib0700_adapter_state {
32122 int (*set_param_save) (struct dvb_frontend *,
32123 struct dvb_frontend_parameters *);
32124-};
32125+} __no_const;
32126
32127 static int dib7070_set_param_override(struct dvb_frontend *fe,
32128 struct dvb_frontend_parameters *fep)
32129diff -urNp linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_core.c
32130--- linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-03-27 14:31:47.000000000 -0400
32131+++ linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-16 21:46:57.000000000 -0400
32132@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb
32133
32134 u8 buf[260];
32135
32136+ pax_track_stack();
32137+
32138 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32139 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
32140
32141diff -urNp linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_devices.c linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_devices.c
32142--- linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_devices.c 2011-05-10 22:12:01.000000000 -0400
32143+++ linux-2.6.32.43/drivers/media/dvb/dvb-usb/dib0700_devices.c 2011-08-05 20:33:55.000000000 -0400
32144@@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "
32145
32146 struct dib0700_adapter_state {
32147 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
32148-};
32149+} __no_const;
32150
32151 /* Hauppauge Nova-T 500 (aka Bristol)
32152 * has a LNA on GPIO0 which is enabled by setting 1 */
32153diff -urNp linux-2.6.32.43/drivers/media/dvb/frontends/dib3000.h linux-2.6.32.43/drivers/media/dvb/frontends/dib3000.h
32154--- linux-2.6.32.43/drivers/media/dvb/frontends/dib3000.h 2011-03-27 14:31:47.000000000 -0400
32155+++ linux-2.6.32.43/drivers/media/dvb/frontends/dib3000.h 2011-08-05 20:33:55.000000000 -0400
32156@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
32157 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
32158 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
32159 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
32160-};
32161+} __no_const;
32162
32163 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
32164 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
32165diff -urNp linux-2.6.32.43/drivers/media/dvb/frontends/or51211.c linux-2.6.32.43/drivers/media/dvb/frontends/or51211.c
32166--- linux-2.6.32.43/drivers/media/dvb/frontends/or51211.c 2011-03-27 14:31:47.000000000 -0400
32167+++ linux-2.6.32.43/drivers/media/dvb/frontends/or51211.c 2011-05-16 21:46:57.000000000 -0400
32168@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32169 u8 tudata[585];
32170 int i;
32171
32172+ pax_track_stack();
32173+
32174 dprintk("Firmware is %zd bytes\n",fw->size);
32175
32176 /* Get eprom data */
32177diff -urNp linux-2.6.32.43/drivers/media/dvb/ttpci/av7110_v4l.c linux-2.6.32.43/drivers/media/dvb/ttpci/av7110_v4l.c
32178--- linux-2.6.32.43/drivers/media/dvb/ttpci/av7110_v4l.c 2011-03-27 14:31:47.000000000 -0400
32179+++ linux-2.6.32.43/drivers/media/dvb/ttpci/av7110_v4l.c 2011-08-05 20:33:55.000000000 -0400
32180@@ -796,18 +796,18 @@ int av7110_init_v4l(struct av7110 *av711
32181 ERR(("cannot init capture device. skipping.\n"));
32182 return -ENODEV;
32183 }
32184- vv_data->ops.vidioc_enum_input = vidioc_enum_input;
32185- vv_data->ops.vidioc_g_input = vidioc_g_input;
32186- vv_data->ops.vidioc_s_input = vidioc_s_input;
32187- vv_data->ops.vidioc_g_tuner = vidioc_g_tuner;
32188- vv_data->ops.vidioc_s_tuner = vidioc_s_tuner;
32189- vv_data->ops.vidioc_g_frequency = vidioc_g_frequency;
32190- vv_data->ops.vidioc_s_frequency = vidioc_s_frequency;
32191- vv_data->ops.vidioc_g_audio = vidioc_g_audio;
32192- vv_data->ops.vidioc_s_audio = vidioc_s_audio;
32193- vv_data->ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
32194- vv_data->ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
32195- vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
32196+ *(void **)&vv_data->ops.vidioc_enum_input = vidioc_enum_input;
32197+ *(void **)&vv_data->ops.vidioc_g_input = vidioc_g_input;
32198+ *(void **)&vv_data->ops.vidioc_s_input = vidioc_s_input;
32199+ *(void **)&vv_data->ops.vidioc_g_tuner = vidioc_g_tuner;
32200+ *(void **)&vv_data->ops.vidioc_s_tuner = vidioc_s_tuner;
32201+ *(void **)&vv_data->ops.vidioc_g_frequency = vidioc_g_frequency;
32202+ *(void **)&vv_data->ops.vidioc_s_frequency = vidioc_s_frequency;
32203+ *(void **)&vv_data->ops.vidioc_g_audio = vidioc_g_audio;
32204+ *(void **)&vv_data->ops.vidioc_s_audio = vidioc_s_audio;
32205+ *(void **)&vv_data->ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
32206+ *(void **)&vv_data->ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
32207+ *(void **)&vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
32208
32209 if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
32210 ERR(("cannot register capture device. skipping.\n"));
32211diff -urNp linux-2.6.32.43/drivers/media/dvb/ttpci/budget-av.c linux-2.6.32.43/drivers/media/dvb/ttpci/budget-av.c
32212--- linux-2.6.32.43/drivers/media/dvb/ttpci/budget-av.c 2011-03-27 14:31:47.000000000 -0400
32213+++ linux-2.6.32.43/drivers/media/dvb/ttpci/budget-av.c 2011-08-05 20:33:55.000000000 -0400
32214@@ -1477,9 +1477,9 @@ static int budget_av_attach(struct saa71
32215 ERR(("cannot init vv subsystem.\n"));
32216 return err;
32217 }
32218- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32219- vv_data.ops.vidioc_g_input = vidioc_g_input;
32220- vv_data.ops.vidioc_s_input = vidioc_s_input;
32221+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32222+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32223+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32224
32225 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) {
32226 /* fixme: proper cleanup here */
32227diff -urNp linux-2.6.32.43/drivers/media/radio/radio-cadet.c linux-2.6.32.43/drivers/media/radio/radio-cadet.c
32228--- linux-2.6.32.43/drivers/media/radio/radio-cadet.c 2011-03-27 14:31:47.000000000 -0400
32229+++ linux-2.6.32.43/drivers/media/radio/radio-cadet.c 2011-04-17 15:56:46.000000000 -0400
32230@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *f
32231 while (i < count && dev->rdsin != dev->rdsout)
32232 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32233
32234- if (copy_to_user(data, readbuf, i))
32235+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32236 return -EFAULT;
32237 return i;
32238 }
32239diff -urNp linux-2.6.32.43/drivers/media/video/cx18/cx18-driver.c linux-2.6.32.43/drivers/media/video/cx18/cx18-driver.c
32240--- linux-2.6.32.43/drivers/media/video/cx18/cx18-driver.c 2011-03-27 14:31:47.000000000 -0400
32241+++ linux-2.6.32.43/drivers/media/video/cx18/cx18-driver.c 2011-05-16 21:46:57.000000000 -0400
32242@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl
32243
32244 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32245
32246-static atomic_t cx18_instance = ATOMIC_INIT(0);
32247+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32248
32249 /* Parameter declarations */
32250 static int cardtype[CX18_MAX_CARDS];
32251@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32252 struct i2c_client c;
32253 u8 eedata[256];
32254
32255+ pax_track_stack();
32256+
32257 memset(&c, 0, sizeof(c));
32258 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32259 c.adapter = &cx->i2c_adap[0];
32260@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct p
32261 struct cx18 *cx;
32262
32263 /* FIXME - module parameter arrays constrain max instances */
32264- i = atomic_inc_return(&cx18_instance) - 1;
32265+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32266 if (i >= CX18_MAX_CARDS) {
32267 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32268 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32269diff -urNp linux-2.6.32.43/drivers/media/video/hexium_gemini.c linux-2.6.32.43/drivers/media/video/hexium_gemini.c
32270--- linux-2.6.32.43/drivers/media/video/hexium_gemini.c 2011-03-27 14:31:47.000000000 -0400
32271+++ linux-2.6.32.43/drivers/media/video/hexium_gemini.c 2011-08-05 20:33:55.000000000 -0400
32272@@ -394,12 +394,12 @@ static int hexium_attach(struct saa7146_
32273 hexium->cur_input = 0;
32274
32275 saa7146_vv_init(dev, &vv_data);
32276- vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32277- vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32278- vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32279- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32280- vv_data.ops.vidioc_g_input = vidioc_g_input;
32281- vv_data.ops.vidioc_s_input = vidioc_s_input;
32282+ *(void **)&vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32283+ *(void **)&vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32284+ *(void **)&vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32285+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32286+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32287+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32288 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER)) {
32289 printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n");
32290 return -1;
32291diff -urNp linux-2.6.32.43/drivers/media/video/hexium_orion.c linux-2.6.32.43/drivers/media/video/hexium_orion.c
32292--- linux-2.6.32.43/drivers/media/video/hexium_orion.c 2011-03-27 14:31:47.000000000 -0400
32293+++ linux-2.6.32.43/drivers/media/video/hexium_orion.c 2011-08-05 20:33:55.000000000 -0400
32294@@ -369,9 +369,9 @@ static int hexium_attach(struct saa7146_
32295 DEB_EE((".\n"));
32296
32297 saa7146_vv_init(dev, &vv_data);
32298- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32299- vv_data.ops.vidioc_g_input = vidioc_g_input;
32300- vv_data.ops.vidioc_s_input = vidioc_s_input;
32301+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32302+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32303+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32304 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium orion", VFL_TYPE_GRABBER)) {
32305 printk("hexium_orion: cannot register capture v4l2 device. skipping.\n");
32306 return -1;
32307diff -urNp linux-2.6.32.43/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.32.43/drivers/media/video/ivtv/ivtv-driver.c
32308--- linux-2.6.32.43/drivers/media/video/ivtv/ivtv-driver.c 2011-03-27 14:31:47.000000000 -0400
32309+++ linux-2.6.32.43/drivers/media/video/ivtv/ivtv-driver.c 2011-05-04 17:56:28.000000000 -0400
32310@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl
32311 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32312
32313 /* ivtv instance counter */
32314-static atomic_t ivtv_instance = ATOMIC_INIT(0);
32315+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32316
32317 /* Parameter declarations */
32318 static int cardtype[IVTV_MAX_CARDS];
32319diff -urNp linux-2.6.32.43/drivers/media/video/mxb.c linux-2.6.32.43/drivers/media/video/mxb.c
32320--- linux-2.6.32.43/drivers/media/video/mxb.c 2011-03-27 14:31:47.000000000 -0400
32321+++ linux-2.6.32.43/drivers/media/video/mxb.c 2011-08-05 20:33:55.000000000 -0400
32322@@ -703,23 +703,23 @@ static int mxb_attach(struct saa7146_dev
32323 already did this in "mxb_vl42_probe" */
32324
32325 saa7146_vv_init(dev, &vv_data);
32326- vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32327- vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32328- vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32329- vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32330- vv_data.ops.vidioc_g_input = vidioc_g_input;
32331- vv_data.ops.vidioc_s_input = vidioc_s_input;
32332- vv_data.ops.vidioc_g_tuner = vidioc_g_tuner;
32333- vv_data.ops.vidioc_s_tuner = vidioc_s_tuner;
32334- vv_data.ops.vidioc_g_frequency = vidioc_g_frequency;
32335- vv_data.ops.vidioc_s_frequency = vidioc_s_frequency;
32336- vv_data.ops.vidioc_g_audio = vidioc_g_audio;
32337- vv_data.ops.vidioc_s_audio = vidioc_s_audio;
32338+ *(void **)&vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
32339+ *(void **)&vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
32340+ *(void **)&vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
32341+ *(void **)&vv_data.ops.vidioc_enum_input = vidioc_enum_input;
32342+ *(void **)&vv_data.ops.vidioc_g_input = vidioc_g_input;
32343+ *(void **)&vv_data.ops.vidioc_s_input = vidioc_s_input;
32344+ *(void **)&vv_data.ops.vidioc_g_tuner = vidioc_g_tuner;
32345+ *(void **)&vv_data.ops.vidioc_s_tuner = vidioc_s_tuner;
32346+ *(void **)&vv_data.ops.vidioc_g_frequency = vidioc_g_frequency;
32347+ *(void **)&vv_data.ops.vidioc_s_frequency = vidioc_s_frequency;
32348+ *(void **)&vv_data.ops.vidioc_g_audio = vidioc_g_audio;
32349+ *(void **)&vv_data.ops.vidioc_s_audio = vidioc_s_audio;
32350 #ifdef CONFIG_VIDEO_ADV_DEBUG
32351- vv_data.ops.vidioc_g_register = vidioc_g_register;
32352- vv_data.ops.vidioc_s_register = vidioc_s_register;
32353+ *(void **)&vv_data.ops.vidioc_g_register = vidioc_g_register;
32354+ *(void **)&vv_data.ops.vidioc_s_register = vidioc_s_register;
32355 #endif
32356- vv_data.ops.vidioc_default = vidioc_default;
32357+ *(void **)&vv_data.ops.vidioc_default = vidioc_default;
32358 if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
32359 ERR(("cannot register capture v4l2 device. skipping.\n"));
32360 return -1;
32361diff -urNp linux-2.6.32.43/drivers/media/video/omap24xxcam.c linux-2.6.32.43/drivers/media/video/omap24xxcam.c
32362--- linux-2.6.32.43/drivers/media/video/omap24xxcam.c 2011-03-27 14:31:47.000000000 -0400
32363+++ linux-2.6.32.43/drivers/media/video/omap24xxcam.c 2011-05-04 17:56:28.000000000 -0400
32364@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(str
32365 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32366
32367 do_gettimeofday(&vb->ts);
32368- vb->field_count = atomic_add_return(2, &fh->field_count);
32369+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32370 if (csr & csr_error) {
32371 vb->state = VIDEOBUF_ERROR;
32372 if (!atomic_read(&fh->cam->in_reset)) {
32373diff -urNp linux-2.6.32.43/drivers/media/video/omap24xxcam.h linux-2.6.32.43/drivers/media/video/omap24xxcam.h
32374--- linux-2.6.32.43/drivers/media/video/omap24xxcam.h 2011-03-27 14:31:47.000000000 -0400
32375+++ linux-2.6.32.43/drivers/media/video/omap24xxcam.h 2011-05-04 17:56:28.000000000 -0400
32376@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32377 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32378 struct videobuf_queue vbq;
32379 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32380- atomic_t field_count; /* field counter for videobuf_buffer */
32381+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32382 /* accessing cam here doesn't need serialisation: it's constant */
32383 struct omap24xxcam_device *cam;
32384 };
32385diff -urNp linux-2.6.32.43/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.32.43/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
32386--- linux-2.6.32.43/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-03-27 14:31:47.000000000 -0400
32387+++ linux-2.6.32.43/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-16 21:46:57.000000000 -0400
32388@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
32389 u8 *eeprom;
32390 struct tveeprom tvdata;
32391
32392+ pax_track_stack();
32393+
32394 memset(&tvdata,0,sizeof(tvdata));
32395
32396 eeprom = pvr2_eeprom_fetch(hdw);
32397diff -urNp linux-2.6.32.43/drivers/media/video/saa7134/saa6752hs.c linux-2.6.32.43/drivers/media/video/saa7134/saa6752hs.c
32398--- linux-2.6.32.43/drivers/media/video/saa7134/saa6752hs.c 2011-03-27 14:31:47.000000000 -0400
32399+++ linux-2.6.32.43/drivers/media/video/saa7134/saa6752hs.c 2011-05-16 21:46:57.000000000 -0400
32400@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_su
32401 unsigned char localPAT[256];
32402 unsigned char localPMT[256];
32403
32404+ pax_track_stack();
32405+
32406 /* Set video format - must be done first as it resets other settings */
32407 set_reg8(client, 0x41, h->video_format);
32408
32409diff -urNp linux-2.6.32.43/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.32.43/drivers/media/video/saa7164/saa7164-cmd.c
32410--- linux-2.6.32.43/drivers/media/video/saa7164/saa7164-cmd.c 2011-03-27 14:31:47.000000000 -0400
32411+++ linux-2.6.32.43/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-16 21:46:57.000000000 -0400
32412@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_d
32413 wait_queue_head_t *q = 0;
32414 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32415
32416+ pax_track_stack();
32417+
32418 /* While any outstand message on the bus exists... */
32419 do {
32420
32421@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
32422 u8 tmp[512];
32423 dprintk(DBGLVL_CMD, "%s()\n", __func__);
32424
32425+ pax_track_stack();
32426+
32427 while (loop) {
32428
32429 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
32430diff -urNp linux-2.6.32.43/drivers/media/video/usbvideo/ibmcam.c linux-2.6.32.43/drivers/media/video/usbvideo/ibmcam.c
32431--- linux-2.6.32.43/drivers/media/video/usbvideo/ibmcam.c 2011-03-27 14:31:47.000000000 -0400
32432+++ linux-2.6.32.43/drivers/media/video/usbvideo/ibmcam.c 2011-08-05 20:33:55.000000000 -0400
32433@@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] =
32434 static int __init ibmcam_init(void)
32435 {
32436 struct usbvideo_cb cbTbl;
32437- memset(&cbTbl, 0, sizeof(cbTbl));
32438- cbTbl.probe = ibmcam_probe;
32439- cbTbl.setupOnOpen = ibmcam_setup_on_open;
32440- cbTbl.videoStart = ibmcam_video_start;
32441- cbTbl.videoStop = ibmcam_video_stop;
32442- cbTbl.processData = ibmcam_ProcessIsocData;
32443- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32444- cbTbl.adjustPicture = ibmcam_adjust_picture;
32445- cbTbl.getFPS = ibmcam_calculate_fps;
32446+ memset((void *)&cbTbl, 0, sizeof(cbTbl));
32447+ *(void **)&cbTbl.probe = ibmcam_probe;
32448+ *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
32449+ *(void **)&cbTbl.videoStart = ibmcam_video_start;
32450+ *(void **)&cbTbl.videoStop = ibmcam_video_stop;
32451+ *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
32452+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32453+ *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
32454+ *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
32455 return usbvideo_register(
32456 &cams,
32457 MAX_IBMCAM,
32458diff -urNp linux-2.6.32.43/drivers/media/video/usbvideo/konicawc.c linux-2.6.32.43/drivers/media/video/usbvideo/konicawc.c
32459--- linux-2.6.32.43/drivers/media/video/usbvideo/konicawc.c 2011-03-27 14:31:47.000000000 -0400
32460+++ linux-2.6.32.43/drivers/media/video/usbvideo/konicawc.c 2011-08-05 20:33:55.000000000 -0400
32461@@ -225,7 +225,7 @@ static void konicawc_register_input(stru
32462 int error;
32463
32464 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
32465- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32466+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32467
32468 cam->input = input_dev = input_allocate_device();
32469 if (!input_dev) {
32470@@ -935,16 +935,16 @@ static int __init konicawc_init(void)
32471 struct usbvideo_cb cbTbl;
32472 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
32473 DRIVER_DESC "\n");
32474- memset(&cbTbl, 0, sizeof(cbTbl));
32475- cbTbl.probe = konicawc_probe;
32476- cbTbl.setupOnOpen = konicawc_setup_on_open;
32477- cbTbl.processData = konicawc_process_isoc;
32478- cbTbl.getFPS = konicawc_calculate_fps;
32479- cbTbl.setVideoMode = konicawc_set_video_mode;
32480- cbTbl.startDataPump = konicawc_start_data;
32481- cbTbl.stopDataPump = konicawc_stop_data;
32482- cbTbl.adjustPicture = konicawc_adjust_picture;
32483- cbTbl.userFree = konicawc_free_uvd;
32484+ memset((void * )&cbTbl, 0, sizeof(cbTbl));
32485+ *(void **)&cbTbl.probe = konicawc_probe;
32486+ *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
32487+ *(void **)&cbTbl.processData = konicawc_process_isoc;
32488+ *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
32489+ *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
32490+ *(void **)&cbTbl.startDataPump = konicawc_start_data;
32491+ *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
32492+ *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
32493+ *(void **)&cbTbl.userFree = konicawc_free_uvd;
32494 return usbvideo_register(
32495 &cams,
32496 MAX_CAMERAS,
32497diff -urNp linux-2.6.32.43/drivers/media/video/usbvideo/quickcam_messenger.c linux-2.6.32.43/drivers/media/video/usbvideo/quickcam_messenger.c
32498--- linux-2.6.32.43/drivers/media/video/usbvideo/quickcam_messenger.c 2011-03-27 14:31:47.000000000 -0400
32499+++ linux-2.6.32.43/drivers/media/video/usbvideo/quickcam_messenger.c 2011-04-17 15:56:46.000000000 -0400
32500@@ -89,7 +89,7 @@ static void qcm_register_input(struct qc
32501 int error;
32502
32503 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
32504- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32505+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
32506
32507 cam->input = input_dev = input_allocate_device();
32508 if (!input_dev) {
32509diff -urNp linux-2.6.32.43/drivers/media/video/usbvideo/ultracam.c linux-2.6.32.43/drivers/media/video/usbvideo/ultracam.c
32510--- linux-2.6.32.43/drivers/media/video/usbvideo/ultracam.c 2011-03-27 14:31:47.000000000 -0400
32511+++ linux-2.6.32.43/drivers/media/video/usbvideo/ultracam.c 2011-08-05 20:33:55.000000000 -0400
32512@@ -655,14 +655,14 @@ static int __init ultracam_init(void)
32513 {
32514 struct usbvideo_cb cbTbl;
32515 memset(&cbTbl, 0, sizeof(cbTbl));
32516- cbTbl.probe = ultracam_probe;
32517- cbTbl.setupOnOpen = ultracam_setup_on_open;
32518- cbTbl.videoStart = ultracam_video_start;
32519- cbTbl.videoStop = ultracam_video_stop;
32520- cbTbl.processData = ultracam_ProcessIsocData;
32521- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32522- cbTbl.adjustPicture = ultracam_adjust_picture;
32523- cbTbl.getFPS = ultracam_calculate_fps;
32524+ *(void **)&cbTbl.probe = ultracam_probe;
32525+ *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
32526+ *(void **)&cbTbl.videoStart = ultracam_video_start;
32527+ *(void **)&cbTbl.videoStop = ultracam_video_stop;
32528+ *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
32529+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
32530+ *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
32531+ *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
32532 return usbvideo_register(
32533 &cams,
32534 MAX_CAMERAS,
32535diff -urNp linux-2.6.32.43/drivers/media/video/usbvideo/usbvideo.c linux-2.6.32.43/drivers/media/video/usbvideo/usbvideo.c
32536--- linux-2.6.32.43/drivers/media/video/usbvideo/usbvideo.c 2011-03-27 14:31:47.000000000 -0400
32537+++ linux-2.6.32.43/drivers/media/video/usbvideo/usbvideo.c 2011-08-05 20:33:55.000000000 -0400
32538@@ -697,15 +697,15 @@ int usbvideo_register(
32539 __func__, cams, base_size, num_cams);
32540
32541 /* Copy callbacks, apply defaults for those that are not set */
32542- memmove(&cams->cb, cbTbl, sizeof(cams->cb));
32543+ memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
32544 if (cams->cb.getFrame == NULL)
32545- cams->cb.getFrame = usbvideo_GetFrame;
32546+ *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
32547 if (cams->cb.disconnect == NULL)
32548- cams->cb.disconnect = usbvideo_Disconnect;
32549+ *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
32550 if (cams->cb.startDataPump == NULL)
32551- cams->cb.startDataPump = usbvideo_StartDataPump;
32552+ *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
32553 if (cams->cb.stopDataPump == NULL)
32554- cams->cb.stopDataPump = usbvideo_StopDataPump;
32555+ *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
32556
32557 cams->num_cameras = num_cams;
32558 cams->cam = (struct uvd *) &cams[1];
32559diff -urNp linux-2.6.32.43/drivers/media/video/usbvision/usbvision-core.c linux-2.6.32.43/drivers/media/video/usbvision/usbvision-core.c
32560--- linux-2.6.32.43/drivers/media/video/usbvision/usbvision-core.c 2011-03-27 14:31:47.000000000 -0400
32561+++ linux-2.6.32.43/drivers/media/video/usbvision/usbvision-core.c 2011-05-16 21:46:57.000000000 -0400
32562@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_c
32563 unsigned char rv, gv, bv;
32564 static unsigned char *Y, *U, *V;
32565
32566+ pax_track_stack();
32567+
32568 frame = usbvision->curFrame;
32569 imageSize = frame->frmwidth * frame->frmheight;
32570 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
32571diff -urNp linux-2.6.32.43/drivers/media/video/v4l2-device.c linux-2.6.32.43/drivers/media/video/v4l2-device.c
32572--- linux-2.6.32.43/drivers/media/video/v4l2-device.c 2011-03-27 14:31:47.000000000 -0400
32573+++ linux-2.6.32.43/drivers/media/video/v4l2-device.c 2011-05-04 17:56:28.000000000 -0400
32574@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *
32575 EXPORT_SYMBOL_GPL(v4l2_device_register);
32576
32577 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
32578- atomic_t *instance)
32579+ atomic_unchecked_t *instance)
32580 {
32581- int num = atomic_inc_return(instance) - 1;
32582+ int num = atomic_inc_return_unchecked(instance) - 1;
32583 int len = strlen(basename);
32584
32585 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
32586diff -urNp linux-2.6.32.43/drivers/media/video/videobuf-dma-sg.c linux-2.6.32.43/drivers/media/video/videobuf-dma-sg.c
32587--- linux-2.6.32.43/drivers/media/video/videobuf-dma-sg.c 2011-03-27 14:31:47.000000000 -0400
32588+++ linux-2.6.32.43/drivers/media/video/videobuf-dma-sg.c 2011-05-16 21:46:57.000000000 -0400
32589@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
32590 {
32591 struct videobuf_queue q;
32592
32593+ pax_track_stack();
32594+
32595 /* Required to make generic handler to call __videobuf_alloc */
32596 q.int_ops = &sg_ops;
32597
32598diff -urNp linux-2.6.32.43/drivers/message/fusion/mptbase.c linux-2.6.32.43/drivers/message/fusion/mptbase.c
32599--- linux-2.6.32.43/drivers/message/fusion/mptbase.c 2011-03-27 14:31:47.000000000 -0400
32600+++ linux-2.6.32.43/drivers/message/fusion/mptbase.c 2011-04-17 15:56:46.000000000 -0400
32601@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **s
32602 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
32603 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
32604
32605+#ifdef CONFIG_GRKERNSEC_HIDESYM
32606+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
32607+ NULL, NULL);
32608+#else
32609 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
32610 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
32611+#endif
32612+
32613 /*
32614 * Rounding UP to nearest 4-kB boundary here...
32615 */
32616diff -urNp linux-2.6.32.43/drivers/message/fusion/mptsas.c linux-2.6.32.43/drivers/message/fusion/mptsas.c
32617--- linux-2.6.32.43/drivers/message/fusion/mptsas.c 2011-03-27 14:31:47.000000000 -0400
32618+++ linux-2.6.32.43/drivers/message/fusion/mptsas.c 2011-04-17 15:56:46.000000000 -0400
32619@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devin
32620 return 0;
32621 }
32622
32623+static inline void
32624+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32625+{
32626+ if (phy_info->port_details) {
32627+ phy_info->port_details->rphy = rphy;
32628+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32629+ ioc->name, rphy));
32630+ }
32631+
32632+ if (rphy) {
32633+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32634+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32635+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32636+ ioc->name, rphy, rphy->dev.release));
32637+ }
32638+}
32639+
32640 /* no mutex */
32641 static void
32642 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
32643@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
32644 return NULL;
32645 }
32646
32647-static inline void
32648-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32649-{
32650- if (phy_info->port_details) {
32651- phy_info->port_details->rphy = rphy;
32652- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32653- ioc->name, rphy));
32654- }
32655-
32656- if (rphy) {
32657- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32658- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32659- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32660- ioc->name, rphy, rphy->dev.release));
32661- }
32662-}
32663-
32664 static inline struct sas_port *
32665 mptsas_get_port(struct mptsas_phyinfo *phy_info)
32666 {
32667diff -urNp linux-2.6.32.43/drivers/message/fusion/mptscsih.c linux-2.6.32.43/drivers/message/fusion/mptscsih.c
32668--- linux-2.6.32.43/drivers/message/fusion/mptscsih.c 2011-03-27 14:31:47.000000000 -0400
32669+++ linux-2.6.32.43/drivers/message/fusion/mptscsih.c 2011-04-17 15:56:46.000000000 -0400
32670@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
32671
32672 h = shost_priv(SChost);
32673
32674- if (h) {
32675- if (h->info_kbuf == NULL)
32676- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32677- return h->info_kbuf;
32678- h->info_kbuf[0] = '\0';
32679+ if (!h)
32680+ return NULL;
32681
32682- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32683- h->info_kbuf[size-1] = '\0';
32684- }
32685+ if (h->info_kbuf == NULL)
32686+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32687+ return h->info_kbuf;
32688+ h->info_kbuf[0] = '\0';
32689+
32690+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32691+ h->info_kbuf[size-1] = '\0';
32692
32693 return h->info_kbuf;
32694 }
32695diff -urNp linux-2.6.32.43/drivers/message/i2o/i2o_config.c linux-2.6.32.43/drivers/message/i2o/i2o_config.c
32696--- linux-2.6.32.43/drivers/message/i2o/i2o_config.c 2011-03-27 14:31:47.000000000 -0400
32697+++ linux-2.6.32.43/drivers/message/i2o/i2o_config.c 2011-05-16 21:46:57.000000000 -0400
32698@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned lon
32699 struct i2o_message *msg;
32700 unsigned int iop;
32701
32702+ pax_track_stack();
32703+
32704 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
32705 return -EFAULT;
32706
32707diff -urNp linux-2.6.32.43/drivers/message/i2o/i2o_proc.c linux-2.6.32.43/drivers/message/i2o/i2o_proc.c
32708--- linux-2.6.32.43/drivers/message/i2o/i2o_proc.c 2011-03-27 14:31:47.000000000 -0400
32709+++ linux-2.6.32.43/drivers/message/i2o/i2o_proc.c 2011-04-17 15:56:46.000000000 -0400
32710@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
32711 "Array Controller Device"
32712 };
32713
32714-static char *chtostr(u8 * chars, int n)
32715-{
32716- char tmp[256];
32717- tmp[0] = 0;
32718- return strncat(tmp, (char *)chars, n);
32719-}
32720-
32721 static int i2o_report_query_status(struct seq_file *seq, int block_status,
32722 char *group)
32723 {
32724@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct
32725
32726 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
32727 seq_printf(seq, "%-#8x", ddm_table.module_id);
32728- seq_printf(seq, "%-29s",
32729- chtostr(ddm_table.module_name_version, 28));
32730+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
32731 seq_printf(seq, "%9d ", ddm_table.data_size);
32732 seq_printf(seq, "%8d", ddm_table.code_size);
32733
32734@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(s
32735
32736 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
32737 seq_printf(seq, "%-#8x", dst->module_id);
32738- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
32739- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
32740+ seq_printf(seq, "%-.28s", dst->module_name_version);
32741+ seq_printf(seq, "%-.8s", dst->date);
32742 seq_printf(seq, "%8d ", dst->module_size);
32743 seq_printf(seq, "%8d ", dst->mpb_size);
32744 seq_printf(seq, "0x%04x", dst->module_flags);
32745@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(str
32746 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
32747 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
32748 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
32749- seq_printf(seq, "Vendor info : %s\n",
32750- chtostr((u8 *) (work32 + 2), 16));
32751- seq_printf(seq, "Product info : %s\n",
32752- chtostr((u8 *) (work32 + 6), 16));
32753- seq_printf(seq, "Description : %s\n",
32754- chtostr((u8 *) (work32 + 10), 16));
32755- seq_printf(seq, "Product rev. : %s\n",
32756- chtostr((u8 *) (work32 + 14), 8));
32757+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
32758+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
32759+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
32760+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
32761
32762 seq_printf(seq, "Serial number : ");
32763 print_serial_number(seq, (u8 *) (work32 + 16),
32764@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(str
32765 }
32766
32767 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
32768- seq_printf(seq, "Module name : %s\n",
32769- chtostr(result.module_name, 24));
32770- seq_printf(seq, "Module revision : %s\n",
32771- chtostr(result.module_rev, 8));
32772+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
32773+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
32774
32775 seq_printf(seq, "Serial number : ");
32776 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
32777@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq
32778 return 0;
32779 }
32780
32781- seq_printf(seq, "Device name : %s\n",
32782- chtostr(result.device_name, 64));
32783- seq_printf(seq, "Service name : %s\n",
32784- chtostr(result.service_name, 64));
32785- seq_printf(seq, "Physical name : %s\n",
32786- chtostr(result.physical_location, 64));
32787- seq_printf(seq, "Instance number : %s\n",
32788- chtostr(result.instance_number, 4));
32789+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
32790+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
32791+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
32792+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
32793
32794 return 0;
32795 }
32796diff -urNp linux-2.6.32.43/drivers/message/i2o/iop.c linux-2.6.32.43/drivers/message/i2o/iop.c
32797--- linux-2.6.32.43/drivers/message/i2o/iop.c 2011-03-27 14:31:47.000000000 -0400
32798+++ linux-2.6.32.43/drivers/message/i2o/iop.c 2011-05-04 17:56:28.000000000 -0400
32799@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
32800
32801 spin_lock_irqsave(&c->context_list_lock, flags);
32802
32803- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
32804- atomic_inc(&c->context_list_counter);
32805+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
32806+ atomic_inc_unchecked(&c->context_list_counter);
32807
32808- entry->context = atomic_read(&c->context_list_counter);
32809+ entry->context = atomic_read_unchecked(&c->context_list_counter);
32810
32811 list_add(&entry->list, &c->context_list);
32812
32813@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(voi
32814
32815 #if BITS_PER_LONG == 64
32816 spin_lock_init(&c->context_list_lock);
32817- atomic_set(&c->context_list_counter, 0);
32818+ atomic_set_unchecked(&c->context_list_counter, 0);
32819 INIT_LIST_HEAD(&c->context_list);
32820 #endif
32821
32822diff -urNp linux-2.6.32.43/drivers/mfd/wm8350-i2c.c linux-2.6.32.43/drivers/mfd/wm8350-i2c.c
32823--- linux-2.6.32.43/drivers/mfd/wm8350-i2c.c 2011-03-27 14:31:47.000000000 -0400
32824+++ linux-2.6.32.43/drivers/mfd/wm8350-i2c.c 2011-05-16 21:46:57.000000000 -0400
32825@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struc
32826 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
32827 int ret;
32828
32829+ pax_track_stack();
32830+
32831 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
32832 return -EINVAL;
32833
32834diff -urNp linux-2.6.32.43/drivers/misc/kgdbts.c linux-2.6.32.43/drivers/misc/kgdbts.c
32835--- linux-2.6.32.43/drivers/misc/kgdbts.c 2011-03-27 14:31:47.000000000 -0400
32836+++ linux-2.6.32.43/drivers/misc/kgdbts.c 2011-04-17 15:56:46.000000000 -0400
32837@@ -118,7 +118,7 @@
32838 } while (0)
32839 #define MAX_CONFIG_LEN 40
32840
32841-static struct kgdb_io kgdbts_io_ops;
32842+static const struct kgdb_io kgdbts_io_ops;
32843 static char get_buf[BUFMAX];
32844 static int get_buf_cnt;
32845 static char put_buf[BUFMAX];
32846@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void
32847 module_put(THIS_MODULE);
32848 }
32849
32850-static struct kgdb_io kgdbts_io_ops = {
32851+static const struct kgdb_io kgdbts_io_ops = {
32852 .name = "kgdbts",
32853 .read_char = kgdbts_get_char,
32854 .write_char = kgdbts_put_char,
32855diff -urNp linux-2.6.32.43/drivers/misc/sgi-gru/gruhandles.c linux-2.6.32.43/drivers/misc/sgi-gru/gruhandles.c
32856--- linux-2.6.32.43/drivers/misc/sgi-gru/gruhandles.c 2011-03-27 14:31:47.000000000 -0400
32857+++ linux-2.6.32.43/drivers/misc/sgi-gru/gruhandles.c 2011-04-17 15:56:46.000000000 -0400
32858@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistic
32859
32860 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
32861 {
32862- atomic_long_inc(&mcs_op_statistics[op].count);
32863- atomic_long_add(clks, &mcs_op_statistics[op].total);
32864+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
32865+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
32866 if (mcs_op_statistics[op].max < clks)
32867 mcs_op_statistics[op].max = clks;
32868 }
32869diff -urNp linux-2.6.32.43/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.32.43/drivers/misc/sgi-gru/gruprocfs.c
32870--- linux-2.6.32.43/drivers/misc/sgi-gru/gruprocfs.c 2011-03-27 14:31:47.000000000 -0400
32871+++ linux-2.6.32.43/drivers/misc/sgi-gru/gruprocfs.c 2011-04-17 15:56:46.000000000 -0400
32872@@ -32,9 +32,9 @@
32873
32874 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
32875
32876-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
32877+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
32878 {
32879- unsigned long val = atomic_long_read(v);
32880+ unsigned long val = atomic_long_read_unchecked(v);
32881
32882 if (val)
32883 seq_printf(s, "%16lu %s\n", val, id);
32884@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct se
32885 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
32886
32887 for (op = 0; op < mcsop_last; op++) {
32888- count = atomic_long_read(&mcs_op_statistics[op].count);
32889- total = atomic_long_read(&mcs_op_statistics[op].total);
32890+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32891+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32892 max = mcs_op_statistics[op].max;
32893 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32894 count ? total / count : 0, max);
32895diff -urNp linux-2.6.32.43/drivers/misc/sgi-gru/grutables.h linux-2.6.32.43/drivers/misc/sgi-gru/grutables.h
32896--- linux-2.6.32.43/drivers/misc/sgi-gru/grutables.h 2011-03-27 14:31:47.000000000 -0400
32897+++ linux-2.6.32.43/drivers/misc/sgi-gru/grutables.h 2011-04-17 15:56:46.000000000 -0400
32898@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
32899 * GRU statistics.
32900 */
32901 struct gru_stats_s {
32902- atomic_long_t vdata_alloc;
32903- atomic_long_t vdata_free;
32904- atomic_long_t gts_alloc;
32905- atomic_long_t gts_free;
32906- atomic_long_t vdata_double_alloc;
32907- atomic_long_t gts_double_allocate;
32908- atomic_long_t assign_context;
32909- atomic_long_t assign_context_failed;
32910- atomic_long_t free_context;
32911- atomic_long_t load_user_context;
32912- atomic_long_t load_kernel_context;
32913- atomic_long_t lock_kernel_context;
32914- atomic_long_t unlock_kernel_context;
32915- atomic_long_t steal_user_context;
32916- atomic_long_t steal_kernel_context;
32917- atomic_long_t steal_context_failed;
32918- atomic_long_t nopfn;
32919- atomic_long_t break_cow;
32920- atomic_long_t asid_new;
32921- atomic_long_t asid_next;
32922- atomic_long_t asid_wrap;
32923- atomic_long_t asid_reuse;
32924- atomic_long_t intr;
32925- atomic_long_t intr_mm_lock_failed;
32926- atomic_long_t call_os;
32927- atomic_long_t call_os_offnode_reference;
32928- atomic_long_t call_os_check_for_bug;
32929- atomic_long_t call_os_wait_queue;
32930- atomic_long_t user_flush_tlb;
32931- atomic_long_t user_unload_context;
32932- atomic_long_t user_exception;
32933- atomic_long_t set_context_option;
32934- atomic_long_t migrate_check;
32935- atomic_long_t migrated_retarget;
32936- atomic_long_t migrated_unload;
32937- atomic_long_t migrated_unload_delay;
32938- atomic_long_t migrated_nopfn_retarget;
32939- atomic_long_t migrated_nopfn_unload;
32940- atomic_long_t tlb_dropin;
32941- atomic_long_t tlb_dropin_fail_no_asid;
32942- atomic_long_t tlb_dropin_fail_upm;
32943- atomic_long_t tlb_dropin_fail_invalid;
32944- atomic_long_t tlb_dropin_fail_range_active;
32945- atomic_long_t tlb_dropin_fail_idle;
32946- atomic_long_t tlb_dropin_fail_fmm;
32947- atomic_long_t tlb_dropin_fail_no_exception;
32948- atomic_long_t tlb_dropin_fail_no_exception_war;
32949- atomic_long_t tfh_stale_on_fault;
32950- atomic_long_t mmu_invalidate_range;
32951- atomic_long_t mmu_invalidate_page;
32952- atomic_long_t mmu_clear_flush_young;
32953- atomic_long_t flush_tlb;
32954- atomic_long_t flush_tlb_gru;
32955- atomic_long_t flush_tlb_gru_tgh;
32956- atomic_long_t flush_tlb_gru_zero_asid;
32957-
32958- atomic_long_t copy_gpa;
32959-
32960- atomic_long_t mesq_receive;
32961- atomic_long_t mesq_receive_none;
32962- atomic_long_t mesq_send;
32963- atomic_long_t mesq_send_failed;
32964- atomic_long_t mesq_noop;
32965- atomic_long_t mesq_send_unexpected_error;
32966- atomic_long_t mesq_send_lb_overflow;
32967- atomic_long_t mesq_send_qlimit_reached;
32968- atomic_long_t mesq_send_amo_nacked;
32969- atomic_long_t mesq_send_put_nacked;
32970- atomic_long_t mesq_qf_not_full;
32971- atomic_long_t mesq_qf_locked;
32972- atomic_long_t mesq_qf_noop_not_full;
32973- atomic_long_t mesq_qf_switch_head_failed;
32974- atomic_long_t mesq_qf_unexpected_error;
32975- atomic_long_t mesq_noop_unexpected_error;
32976- atomic_long_t mesq_noop_lb_overflow;
32977- atomic_long_t mesq_noop_qlimit_reached;
32978- atomic_long_t mesq_noop_amo_nacked;
32979- atomic_long_t mesq_noop_put_nacked;
32980+ atomic_long_unchecked_t vdata_alloc;
32981+ atomic_long_unchecked_t vdata_free;
32982+ atomic_long_unchecked_t gts_alloc;
32983+ atomic_long_unchecked_t gts_free;
32984+ atomic_long_unchecked_t vdata_double_alloc;
32985+ atomic_long_unchecked_t gts_double_allocate;
32986+ atomic_long_unchecked_t assign_context;
32987+ atomic_long_unchecked_t assign_context_failed;
32988+ atomic_long_unchecked_t free_context;
32989+ atomic_long_unchecked_t load_user_context;
32990+ atomic_long_unchecked_t load_kernel_context;
32991+ atomic_long_unchecked_t lock_kernel_context;
32992+ atomic_long_unchecked_t unlock_kernel_context;
32993+ atomic_long_unchecked_t steal_user_context;
32994+ atomic_long_unchecked_t steal_kernel_context;
32995+ atomic_long_unchecked_t steal_context_failed;
32996+ atomic_long_unchecked_t nopfn;
32997+ atomic_long_unchecked_t break_cow;
32998+ atomic_long_unchecked_t asid_new;
32999+ atomic_long_unchecked_t asid_next;
33000+ atomic_long_unchecked_t asid_wrap;
33001+ atomic_long_unchecked_t asid_reuse;
33002+ atomic_long_unchecked_t intr;
33003+ atomic_long_unchecked_t intr_mm_lock_failed;
33004+ atomic_long_unchecked_t call_os;
33005+ atomic_long_unchecked_t call_os_offnode_reference;
33006+ atomic_long_unchecked_t call_os_check_for_bug;
33007+ atomic_long_unchecked_t call_os_wait_queue;
33008+ atomic_long_unchecked_t user_flush_tlb;
33009+ atomic_long_unchecked_t user_unload_context;
33010+ atomic_long_unchecked_t user_exception;
33011+ atomic_long_unchecked_t set_context_option;
33012+ atomic_long_unchecked_t migrate_check;
33013+ atomic_long_unchecked_t migrated_retarget;
33014+ atomic_long_unchecked_t migrated_unload;
33015+ atomic_long_unchecked_t migrated_unload_delay;
33016+ atomic_long_unchecked_t migrated_nopfn_retarget;
33017+ atomic_long_unchecked_t migrated_nopfn_unload;
33018+ atomic_long_unchecked_t tlb_dropin;
33019+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33020+ atomic_long_unchecked_t tlb_dropin_fail_upm;
33021+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
33022+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
33023+ atomic_long_unchecked_t tlb_dropin_fail_idle;
33024+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
33025+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33026+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
33027+ atomic_long_unchecked_t tfh_stale_on_fault;
33028+ atomic_long_unchecked_t mmu_invalidate_range;
33029+ atomic_long_unchecked_t mmu_invalidate_page;
33030+ atomic_long_unchecked_t mmu_clear_flush_young;
33031+ atomic_long_unchecked_t flush_tlb;
33032+ atomic_long_unchecked_t flush_tlb_gru;
33033+ atomic_long_unchecked_t flush_tlb_gru_tgh;
33034+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33035+
33036+ atomic_long_unchecked_t copy_gpa;
33037+
33038+ atomic_long_unchecked_t mesq_receive;
33039+ atomic_long_unchecked_t mesq_receive_none;
33040+ atomic_long_unchecked_t mesq_send;
33041+ atomic_long_unchecked_t mesq_send_failed;
33042+ atomic_long_unchecked_t mesq_noop;
33043+ atomic_long_unchecked_t mesq_send_unexpected_error;
33044+ atomic_long_unchecked_t mesq_send_lb_overflow;
33045+ atomic_long_unchecked_t mesq_send_qlimit_reached;
33046+ atomic_long_unchecked_t mesq_send_amo_nacked;
33047+ atomic_long_unchecked_t mesq_send_put_nacked;
33048+ atomic_long_unchecked_t mesq_qf_not_full;
33049+ atomic_long_unchecked_t mesq_qf_locked;
33050+ atomic_long_unchecked_t mesq_qf_noop_not_full;
33051+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
33052+ atomic_long_unchecked_t mesq_qf_unexpected_error;
33053+ atomic_long_unchecked_t mesq_noop_unexpected_error;
33054+ atomic_long_unchecked_t mesq_noop_lb_overflow;
33055+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
33056+ atomic_long_unchecked_t mesq_noop_amo_nacked;
33057+ atomic_long_unchecked_t mesq_noop_put_nacked;
33058
33059 };
33060
33061@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start
33062 cchop_deallocate, tghop_invalidate, mcsop_last};
33063
33064 struct mcs_op_statistic {
33065- atomic_long_t count;
33066- atomic_long_t total;
33067+ atomic_long_unchecked_t count;
33068+ atomic_long_unchecked_t total;
33069 unsigned long max;
33070 };
33071
33072@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_st
33073
33074 #define STAT(id) do { \
33075 if (gru_options & OPT_STATS) \
33076- atomic_long_inc(&gru_stats.id); \
33077+ atomic_long_inc_unchecked(&gru_stats.id); \
33078 } while (0)
33079
33080 #ifdef CONFIG_SGI_GRU_DEBUG
33081diff -urNp linux-2.6.32.43/drivers/misc/sgi-xp/xpc.h linux-2.6.32.43/drivers/misc/sgi-xp/xpc.h
33082--- linux-2.6.32.43/drivers/misc/sgi-xp/xpc.h 2011-03-27 14:31:47.000000000 -0400
33083+++ linux-2.6.32.43/drivers/misc/sgi-xp/xpc.h 2011-08-05 20:33:55.000000000 -0400
33084@@ -876,7 +876,7 @@ extern struct xpc_registration xpc_regis
33085 /* found in xpc_main.c */
33086 extern struct device *xpc_part;
33087 extern struct device *xpc_chan;
33088-extern struct xpc_arch_operations xpc_arch_ops;
33089+extern const struct xpc_arch_operations xpc_arch_ops;
33090 extern int xpc_disengage_timelimit;
33091 extern int xpc_disengage_timedout;
33092 extern int xpc_activate_IRQ_rcvd;
33093diff -urNp linux-2.6.32.43/drivers/misc/sgi-xp/xpc_main.c linux-2.6.32.43/drivers/misc/sgi-xp/xpc_main.c
33094--- linux-2.6.32.43/drivers/misc/sgi-xp/xpc_main.c 2011-03-27 14:31:47.000000000 -0400
33095+++ linux-2.6.32.43/drivers/misc/sgi-xp/xpc_main.c 2011-08-05 20:33:55.000000000 -0400
33096@@ -169,7 +169,7 @@ static struct notifier_block xpc_die_not
33097 .notifier_call = xpc_system_die,
33098 };
33099
33100-struct xpc_arch_operations xpc_arch_ops;
33101+const struct xpc_arch_operations xpc_arch_ops;
33102
33103 /*
33104 * Timer function to enforce the timelimit on the partition disengage.
33105diff -urNp linux-2.6.32.43/drivers/misc/sgi-xp/xpc_sn2.c linux-2.6.32.43/drivers/misc/sgi-xp/xpc_sn2.c
33106--- linux-2.6.32.43/drivers/misc/sgi-xp/xpc_sn2.c 2011-03-27 14:31:47.000000000 -0400
33107+++ linux-2.6.32.43/drivers/misc/sgi-xp/xpc_sn2.c 2011-08-05 20:33:55.000000000 -0400
33108@@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_chan
33109 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33110 }
33111
33112-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33113+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33114 .setup_partitions = xpc_setup_partitions_sn2,
33115 .teardown_partitions = xpc_teardown_partitions_sn2,
33116 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33117@@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
33118 int ret;
33119 size_t buf_size;
33120
33121- xpc_arch_ops = xpc_arch_ops_sn2;
33122+ pax_open_kernel();
33123+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
33124+ pax_close_kernel();
33125
33126 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
33127 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
33128diff -urNp linux-2.6.32.43/drivers/misc/sgi-xp/xpc_uv.c linux-2.6.32.43/drivers/misc/sgi-xp/xpc_uv.c
33129--- linux-2.6.32.43/drivers/misc/sgi-xp/xpc_uv.c 2011-03-27 14:31:47.000000000 -0400
33130+++ linux-2.6.32.43/drivers/misc/sgi-xp/xpc_uv.c 2011-08-05 20:33:55.000000000 -0400
33131@@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_chann
33132 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33133 }
33134
33135-static struct xpc_arch_operations xpc_arch_ops_uv = {
33136+static const struct xpc_arch_operations xpc_arch_ops_uv = {
33137 .setup_partitions = xpc_setup_partitions_uv,
33138 .teardown_partitions = xpc_teardown_partitions_uv,
33139 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33140@@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_ar
33141 int
33142 xpc_init_uv(void)
33143 {
33144- xpc_arch_ops = xpc_arch_ops_uv;
33145+ pax_open_kernel();
33146+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
33147+ pax_close_kernel();
33148
33149 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
33150 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
33151diff -urNp linux-2.6.32.43/drivers/misc/sgi-xp/xp.h linux-2.6.32.43/drivers/misc/sgi-xp/xp.h
33152--- linux-2.6.32.43/drivers/misc/sgi-xp/xp.h 2011-03-27 14:31:47.000000000 -0400
33153+++ linux-2.6.32.43/drivers/misc/sgi-xp/xp.h 2011-08-05 20:33:55.000000000 -0400
33154@@ -289,7 +289,7 @@ struct xpc_interface {
33155 xpc_notify_func, void *);
33156 void (*received) (short, int, void *);
33157 enum xp_retval (*partid_to_nasids) (short, void *);
33158-};
33159+} __no_const;
33160
33161 extern struct xpc_interface xpc_interface;
33162
33163diff -urNp linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0001.c
33164--- linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0001.c 2011-03-27 14:31:47.000000000 -0400
33165+++ linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-16 21:46:57.000000000 -0400
33166@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *
33167 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
33168 unsigned long timeo = jiffies + HZ;
33169
33170+ pax_track_stack();
33171+
33172 /* Prevent setting state FL_SYNCING for chip in suspended state. */
33173 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
33174 goto sleep;
33175@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(stru
33176 unsigned long initial_adr;
33177 int initial_len = len;
33178
33179+ pax_track_stack();
33180+
33181 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
33182 adr += chip->start;
33183 initial_adr = adr;
33184@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(st
33185 int retries = 3;
33186 int ret;
33187
33188+ pax_track_stack();
33189+
33190 adr += chip->start;
33191
33192 retry:
33193diff -urNp linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0020.c
33194--- linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0020.c 2011-03-27 14:31:47.000000000 -0400
33195+++ linux-2.6.32.43/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-16 21:46:57.000000000 -0400
33196@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
33197 unsigned long cmd_addr;
33198 struct cfi_private *cfi = map->fldrv_priv;
33199
33200+ pax_track_stack();
33201+
33202 adr += chip->start;
33203
33204 /* Ensure cmd read/writes are aligned. */
33205@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
33206 DECLARE_WAITQUEUE(wait, current);
33207 int wbufsize, z;
33208
33209+ pax_track_stack();
33210+
33211 /* M58LW064A requires bus alignment for buffer wriets -- saw */
33212 if (adr & (map_bankwidth(map)-1))
33213 return -EINVAL;
33214@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
33215 DECLARE_WAITQUEUE(wait, current);
33216 int ret = 0;
33217
33218+ pax_track_stack();
33219+
33220 adr += chip->start;
33221
33222 /* Let's determine this according to the interleave only once */
33223@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
33224 unsigned long timeo = jiffies + HZ;
33225 DECLARE_WAITQUEUE(wait, current);
33226
33227+ pax_track_stack();
33228+
33229 adr += chip->start;
33230
33231 /* Let's determine this according to the interleave only once */
33232@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
33233 unsigned long timeo = jiffies + HZ;
33234 DECLARE_WAITQUEUE(wait, current);
33235
33236+ pax_track_stack();
33237+
33238 adr += chip->start;
33239
33240 /* Let's determine this according to the interleave only once */
33241diff -urNp linux-2.6.32.43/drivers/mtd/devices/doc2000.c linux-2.6.32.43/drivers/mtd/devices/doc2000.c
33242--- linux-2.6.32.43/drivers/mtd/devices/doc2000.c 2011-03-27 14:31:47.000000000 -0400
33243+++ linux-2.6.32.43/drivers/mtd/devices/doc2000.c 2011-04-17 15:56:46.000000000 -0400
33244@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
33245
33246 /* The ECC will not be calculated correctly if less than 512 is written */
33247 /* DBB-
33248- if (len != 0x200 && eccbuf)
33249+ if (len != 0x200)
33250 printk(KERN_WARNING
33251 "ECC needs a full sector write (adr: %lx size %lx)\n",
33252 (long) to, (long) len);
33253diff -urNp linux-2.6.32.43/drivers/mtd/devices/doc2001.c linux-2.6.32.43/drivers/mtd/devices/doc2001.c
33254--- linux-2.6.32.43/drivers/mtd/devices/doc2001.c 2011-03-27 14:31:47.000000000 -0400
33255+++ linux-2.6.32.43/drivers/mtd/devices/doc2001.c 2011-04-17 15:56:46.000000000 -0400
33256@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
33257 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
33258
33259 /* Don't allow read past end of device */
33260- if (from >= this->totlen)
33261+ if (from >= this->totlen || !len)
33262 return -EINVAL;
33263
33264 /* Don't allow a single read to cross a 512-byte block boundary */
33265diff -urNp linux-2.6.32.43/drivers/mtd/ftl.c linux-2.6.32.43/drivers/mtd/ftl.c
33266--- linux-2.6.32.43/drivers/mtd/ftl.c 2011-03-27 14:31:47.000000000 -0400
33267+++ linux-2.6.32.43/drivers/mtd/ftl.c 2011-05-16 21:46:57.000000000 -0400
33268@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
33269 loff_t offset;
33270 uint16_t srcunitswap = cpu_to_le16(srcunit);
33271
33272+ pax_track_stack();
33273+
33274 eun = &part->EUNInfo[srcunit];
33275 xfer = &part->XferInfo[xferunit];
33276 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
33277diff -urNp linux-2.6.32.43/drivers/mtd/inftlcore.c linux-2.6.32.43/drivers/mtd/inftlcore.c
33278--- linux-2.6.32.43/drivers/mtd/inftlcore.c 2011-03-27 14:31:47.000000000 -0400
33279+++ linux-2.6.32.43/drivers/mtd/inftlcore.c 2011-05-16 21:46:57.000000000 -0400
33280@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLr
33281 struct inftl_oob oob;
33282 size_t retlen;
33283
33284+ pax_track_stack();
33285+
33286 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
33287 "pending=%d)\n", inftl, thisVUC, pendingblock);
33288
33289diff -urNp linux-2.6.32.43/drivers/mtd/inftlmount.c linux-2.6.32.43/drivers/mtd/inftlmount.c
33290--- linux-2.6.32.43/drivers/mtd/inftlmount.c 2011-03-27 14:31:47.000000000 -0400
33291+++ linux-2.6.32.43/drivers/mtd/inftlmount.c 2011-05-16 21:46:57.000000000 -0400
33292@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTL
33293 struct INFTLPartition *ip;
33294 size_t retlen;
33295
33296+ pax_track_stack();
33297+
33298 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
33299
33300 /*
33301diff -urNp linux-2.6.32.43/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.32.43/drivers/mtd/lpddr/qinfo_probe.c
33302--- linux-2.6.32.43/drivers/mtd/lpddr/qinfo_probe.c 2011-03-27 14:31:47.000000000 -0400
33303+++ linux-2.6.32.43/drivers/mtd/lpddr/qinfo_probe.c 2011-05-16 21:46:57.000000000 -0400
33304@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
33305 {
33306 map_word pfow_val[4];
33307
33308+ pax_track_stack();
33309+
33310 /* Check identification string */
33311 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
33312 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
33313diff -urNp linux-2.6.32.43/drivers/mtd/mtdchar.c linux-2.6.32.43/drivers/mtd/mtdchar.c
33314--- linux-2.6.32.43/drivers/mtd/mtdchar.c 2011-03-27 14:31:47.000000000 -0400
33315+++ linux-2.6.32.43/drivers/mtd/mtdchar.c 2011-05-16 21:46:57.000000000 -0400
33316@@ -460,6 +460,8 @@ static int mtd_ioctl(struct inode *inode
33317 u_long size;
33318 struct mtd_info_user info;
33319
33320+ pax_track_stack();
33321+
33322 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
33323
33324 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
33325diff -urNp linux-2.6.32.43/drivers/mtd/nftlcore.c linux-2.6.32.43/drivers/mtd/nftlcore.c
33326--- linux-2.6.32.43/drivers/mtd/nftlcore.c 2011-03-27 14:31:47.000000000 -0400
33327+++ linux-2.6.32.43/drivers/mtd/nftlcore.c 2011-05-16 21:46:57.000000000 -0400
33328@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLre
33329 int inplace = 1;
33330 size_t retlen;
33331
33332+ pax_track_stack();
33333+
33334 memset(BlockMap, 0xff, sizeof(BlockMap));
33335 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
33336
33337diff -urNp linux-2.6.32.43/drivers/mtd/nftlmount.c linux-2.6.32.43/drivers/mtd/nftlmount.c
33338--- linux-2.6.32.43/drivers/mtd/nftlmount.c 2011-03-27 14:31:47.000000000 -0400
33339+++ linux-2.6.32.43/drivers/mtd/nftlmount.c 2011-05-18 20:09:37.000000000 -0400
33340@@ -23,6 +23,7 @@
33341 #include <asm/errno.h>
33342 #include <linux/delay.h>
33343 #include <linux/slab.h>
33344+#include <linux/sched.h>
33345 #include <linux/mtd/mtd.h>
33346 #include <linux/mtd/nand.h>
33347 #include <linux/mtd/nftl.h>
33348@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLr
33349 struct mtd_info *mtd = nftl->mbd.mtd;
33350 unsigned int i;
33351
33352+ pax_track_stack();
33353+
33354 /* Assume logical EraseSize == physical erasesize for starting the scan.
33355 We'll sort it out later if we find a MediaHeader which says otherwise */
33356 /* Actually, we won't. The new DiskOnChip driver has already scanned
33357diff -urNp linux-2.6.32.43/drivers/mtd/ubi/build.c linux-2.6.32.43/drivers/mtd/ubi/build.c
33358--- linux-2.6.32.43/drivers/mtd/ubi/build.c 2011-03-27 14:31:47.000000000 -0400
33359+++ linux-2.6.32.43/drivers/mtd/ubi/build.c 2011-04-17 15:56:46.000000000 -0400
33360@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
33361 static int __init bytes_str_to_int(const char *str)
33362 {
33363 char *endp;
33364- unsigned long result;
33365+ unsigned long result, scale = 1;
33366
33367 result = simple_strtoul(str, &endp, 0);
33368 if (str == endp || result >= INT_MAX) {
33369@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const
33370
33371 switch (*endp) {
33372 case 'G':
33373- result *= 1024;
33374+ scale *= 1024;
33375 case 'M':
33376- result *= 1024;
33377+ scale *= 1024;
33378 case 'K':
33379- result *= 1024;
33380+ scale *= 1024;
33381 if (endp[1] == 'i' && endp[2] == 'B')
33382 endp += 2;
33383 case '\0':
33384@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const
33385 return -EINVAL;
33386 }
33387
33388- return result;
33389+ if ((intoverflow_t)result*scale >= INT_MAX) {
33390+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33391+ str);
33392+ return -EINVAL;
33393+ }
33394+
33395+ return result*scale;
33396 }
33397
33398 /**
33399diff -urNp linux-2.6.32.43/drivers/net/bnx2.c linux-2.6.32.43/drivers/net/bnx2.c
33400--- linux-2.6.32.43/drivers/net/bnx2.c 2011-03-27 14:31:47.000000000 -0400
33401+++ linux-2.6.32.43/drivers/net/bnx2.c 2011-05-16 21:46:57.000000000 -0400
33402@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
33403 int rc = 0;
33404 u32 magic, csum;
33405
33406+ pax_track_stack();
33407+
33408 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
33409 goto test_nvram_done;
33410
33411diff -urNp linux-2.6.32.43/drivers/net/cxgb3/l2t.h linux-2.6.32.43/drivers/net/cxgb3/l2t.h
33412--- linux-2.6.32.43/drivers/net/cxgb3/l2t.h 2011-03-27 14:31:47.000000000 -0400
33413+++ linux-2.6.32.43/drivers/net/cxgb3/l2t.h 2011-08-05 20:33:55.000000000 -0400
33414@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)
33415 */
33416 struct l2t_skb_cb {
33417 arp_failure_handler_func arp_failure_handler;
33418-};
33419+} __no_const;
33420
33421 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33422
33423diff -urNp linux-2.6.32.43/drivers/net/cxgb3/t3_hw.c linux-2.6.32.43/drivers/net/cxgb3/t3_hw.c
33424--- linux-2.6.32.43/drivers/net/cxgb3/t3_hw.c 2011-03-27 14:31:47.000000000 -0400
33425+++ linux-2.6.32.43/drivers/net/cxgb3/t3_hw.c 2011-05-16 21:46:57.000000000 -0400
33426@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter
33427 int i, addr, ret;
33428 struct t3_vpd vpd;
33429
33430+ pax_track_stack();
33431+
33432 /*
33433 * Card information is normally at VPD_BASE but some early cards had
33434 * it at 0.
33435diff -urNp linux-2.6.32.43/drivers/net/e1000e/82571.c linux-2.6.32.43/drivers/net/e1000e/82571.c
33436--- linux-2.6.32.43/drivers/net/e1000e/82571.c 2011-03-27 14:31:47.000000000 -0400
33437+++ linux-2.6.32.43/drivers/net/e1000e/82571.c 2011-08-05 20:33:55.000000000 -0400
33438@@ -245,22 +245,22 @@ static s32 e1000_init_mac_params_82571(s
33439 /* check for link */
33440 switch (hw->phy.media_type) {
33441 case e1000_media_type_copper:
33442- func->setup_physical_interface = e1000_setup_copper_link_82571;
33443- func->check_for_link = e1000e_check_for_copper_link;
33444- func->get_link_up_info = e1000e_get_speed_and_duplex_copper;
33445+ *(void **)&func->setup_physical_interface = e1000_setup_copper_link_82571;
33446+ *(void **)&func->check_for_link = e1000e_check_for_copper_link;
33447+ *(void **)&func->get_link_up_info = e1000e_get_speed_and_duplex_copper;
33448 break;
33449 case e1000_media_type_fiber:
33450- func->setup_physical_interface =
33451+ *(void **)&func->setup_physical_interface =
33452 e1000_setup_fiber_serdes_link_82571;
33453- func->check_for_link = e1000e_check_for_fiber_link;
33454- func->get_link_up_info =
33455+ *(void **)&func->check_for_link = e1000e_check_for_fiber_link;
33456+ *(void **)&func->get_link_up_info =
33457 e1000e_get_speed_and_duplex_fiber_serdes;
33458 break;
33459 case e1000_media_type_internal_serdes:
33460- func->setup_physical_interface =
33461+ *(void **)&func->setup_physical_interface =
33462 e1000_setup_fiber_serdes_link_82571;
33463- func->check_for_link = e1000_check_for_serdes_link_82571;
33464- func->get_link_up_info =
33465+ *(void **)&func->check_for_link = e1000_check_for_serdes_link_82571;
33466+ *(void **)&func->get_link_up_info =
33467 e1000e_get_speed_and_duplex_fiber_serdes;
33468 break;
33469 default:
33470@@ -271,12 +271,12 @@ static s32 e1000_init_mac_params_82571(s
33471 switch (hw->mac.type) {
33472 case e1000_82574:
33473 case e1000_82583:
33474- func->check_mng_mode = e1000_check_mng_mode_82574;
33475- func->led_on = e1000_led_on_82574;
33476+ *(void **)&func->check_mng_mode = e1000_check_mng_mode_82574;
33477+ *(void **)&func->led_on = e1000_led_on_82574;
33478 break;
33479 default:
33480- func->check_mng_mode = e1000e_check_mng_mode_generic;
33481- func->led_on = e1000e_led_on_generic;
33482+ *(void **)&func->check_mng_mode = e1000e_check_mng_mode_generic;
33483+ *(void **)&func->led_on = e1000e_led_on_generic;
33484 break;
33485 }
33486
33487@@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(s
33488 temp = er32(ICRXDMTC);
33489 }
33490
33491-static struct e1000_mac_operations e82571_mac_ops = {
33492+static const struct e1000_mac_operations e82571_mac_ops = {
33493 /* .check_mng_mode: mac type dependent */
33494 /* .check_for_link: media type dependent */
33495 .id_led_init = e1000e_id_led_init,
33496@@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e8257
33497 .setup_led = e1000e_setup_led_generic,
33498 };
33499
33500-static struct e1000_phy_operations e82_phy_ops_igp = {
33501+static const struct e1000_phy_operations e82_phy_ops_igp = {
33502 .acquire_phy = e1000_get_hw_semaphore_82571,
33503 .check_reset_block = e1000e_check_reset_block_generic,
33504 .commit_phy = NULL,
33505@@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_p
33506 .cfg_on_link_up = NULL,
33507 };
33508
33509-static struct e1000_phy_operations e82_phy_ops_m88 = {
33510+static const struct e1000_phy_operations e82_phy_ops_m88 = {
33511 .acquire_phy = e1000_get_hw_semaphore_82571,
33512 .check_reset_block = e1000e_check_reset_block_generic,
33513 .commit_phy = e1000e_phy_sw_reset,
33514@@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_p
33515 .cfg_on_link_up = NULL,
33516 };
33517
33518-static struct e1000_phy_operations e82_phy_ops_bm = {
33519+static const struct e1000_phy_operations e82_phy_ops_bm = {
33520 .acquire_phy = e1000_get_hw_semaphore_82571,
33521 .check_reset_block = e1000e_check_reset_block_generic,
33522 .commit_phy = e1000e_phy_sw_reset,
33523@@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_p
33524 .cfg_on_link_up = NULL,
33525 };
33526
33527-static struct e1000_nvm_operations e82571_nvm_ops = {
33528+static const struct e1000_nvm_operations e82571_nvm_ops = {
33529 .acquire_nvm = e1000_acquire_nvm_82571,
33530 .read_nvm = e1000e_read_nvm_eerd,
33531 .release_nvm = e1000_release_nvm_82571,
33532diff -urNp linux-2.6.32.43/drivers/net/e1000e/e1000.h linux-2.6.32.43/drivers/net/e1000e/e1000.h
33533--- linux-2.6.32.43/drivers/net/e1000e/e1000.h 2011-03-27 14:31:47.000000000 -0400
33534+++ linux-2.6.32.43/drivers/net/e1000e/e1000.h 2011-04-17 15:56:46.000000000 -0400
33535@@ -375,9 +375,9 @@ struct e1000_info {
33536 u32 pba;
33537 u32 max_hw_frame_size;
33538 s32 (*get_variants)(struct e1000_adapter *);
33539- struct e1000_mac_operations *mac_ops;
33540- struct e1000_phy_operations *phy_ops;
33541- struct e1000_nvm_operations *nvm_ops;
33542+ const struct e1000_mac_operations *mac_ops;
33543+ const struct e1000_phy_operations *phy_ops;
33544+ const struct e1000_nvm_operations *nvm_ops;
33545 };
33546
33547 /* hardware capability, feature, and workaround flags */
33548diff -urNp linux-2.6.32.43/drivers/net/e1000e/es2lan.c linux-2.6.32.43/drivers/net/e1000e/es2lan.c
33549--- linux-2.6.32.43/drivers/net/e1000e/es2lan.c 2011-03-27 14:31:47.000000000 -0400
33550+++ linux-2.6.32.43/drivers/net/e1000e/es2lan.c 2011-08-05 20:33:55.000000000 -0400
33551@@ -229,16 +229,16 @@ static s32 e1000_init_mac_params_80003es
33552 /* check for link */
33553 switch (hw->phy.media_type) {
33554 case e1000_media_type_copper:
33555- func->setup_physical_interface = e1000_setup_copper_link_80003es2lan;
33556- func->check_for_link = e1000e_check_for_copper_link;
33557+ *(void **)&func->setup_physical_interface = e1000_setup_copper_link_80003es2lan;
33558+ *(void **)&func->check_for_link = e1000e_check_for_copper_link;
33559 break;
33560 case e1000_media_type_fiber:
33561- func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33562- func->check_for_link = e1000e_check_for_fiber_link;
33563+ *(void **)&func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33564+ *(void **)&func->check_for_link = e1000e_check_for_fiber_link;
33565 break;
33566 case e1000_media_type_internal_serdes:
33567- func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33568- func->check_for_link = e1000e_check_for_serdes_link;
33569+ *(void **)&func->setup_physical_interface = e1000e_setup_fiber_serdes_link;
33570+ *(void **)&func->check_for_link = e1000e_check_for_serdes_link;
33571 break;
33572 default:
33573 return -E1000_ERR_CONFIG;
33574@@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es
33575 temp = er32(ICRXDMTC);
33576 }
33577
33578-static struct e1000_mac_operations es2_mac_ops = {
33579+static const struct e1000_mac_operations es2_mac_ops = {
33580 .id_led_init = e1000e_id_led_init,
33581 .check_mng_mode = e1000e_check_mng_mode_generic,
33582 /* check_for_link dependent on media type */
33583@@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_m
33584 .setup_led = e1000e_setup_led_generic,
33585 };
33586
33587-static struct e1000_phy_operations es2_phy_ops = {
33588+static const struct e1000_phy_operations es2_phy_ops = {
33589 .acquire_phy = e1000_acquire_phy_80003es2lan,
33590 .check_reset_block = e1000e_check_reset_block_generic,
33591 .commit_phy = e1000e_phy_sw_reset,
33592@@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_p
33593 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
33594 };
33595
33596-static struct e1000_nvm_operations es2_nvm_ops = {
33597+static const struct e1000_nvm_operations es2_nvm_ops = {
33598 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
33599 .read_nvm = e1000e_read_nvm_eerd,
33600 .release_nvm = e1000_release_nvm_80003es2lan,
33601diff -urNp linux-2.6.32.43/drivers/net/e1000e/hw.h linux-2.6.32.43/drivers/net/e1000e/hw.h
33602--- linux-2.6.32.43/drivers/net/e1000e/hw.h 2011-03-27 14:31:47.000000000 -0400
33603+++ linux-2.6.32.43/drivers/net/e1000e/hw.h 2011-04-17 15:56:46.000000000 -0400
33604@@ -756,34 +756,34 @@ struct e1000_mac_operations {
33605
33606 /* Function pointers for the PHY. */
33607 struct e1000_phy_operations {
33608- s32 (*acquire_phy)(struct e1000_hw *);
33609- s32 (*check_polarity)(struct e1000_hw *);
33610- s32 (*check_reset_block)(struct e1000_hw *);
33611- s32 (*commit_phy)(struct e1000_hw *);
33612- s32 (*force_speed_duplex)(struct e1000_hw *);
33613- s32 (*get_cfg_done)(struct e1000_hw *hw);
33614- s32 (*get_cable_length)(struct e1000_hw *);
33615- s32 (*get_phy_info)(struct e1000_hw *);
33616- s32 (*read_phy_reg)(struct e1000_hw *, u32, u16 *);
33617- s32 (*read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
33618- void (*release_phy)(struct e1000_hw *);
33619- s32 (*reset_phy)(struct e1000_hw *);
33620- s32 (*set_d0_lplu_state)(struct e1000_hw *, bool);
33621- s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
33622- s32 (*write_phy_reg)(struct e1000_hw *, u32, u16);
33623- s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
33624- s32 (*cfg_on_link_up)(struct e1000_hw *);
33625+ s32 (* acquire_phy)(struct e1000_hw *);
33626+ s32 (* check_polarity)(struct e1000_hw *);
33627+ s32 (* check_reset_block)(struct e1000_hw *);
33628+ s32 (* commit_phy)(struct e1000_hw *);
33629+ s32 (* force_speed_duplex)(struct e1000_hw *);
33630+ s32 (* get_cfg_done)(struct e1000_hw *hw);
33631+ s32 (* get_cable_length)(struct e1000_hw *);
33632+ s32 (* get_phy_info)(struct e1000_hw *);
33633+ s32 (* read_phy_reg)(struct e1000_hw *, u32, u16 *);
33634+ s32 (* read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
33635+ void (* release_phy)(struct e1000_hw *);
33636+ s32 (* reset_phy)(struct e1000_hw *);
33637+ s32 (* set_d0_lplu_state)(struct e1000_hw *, bool);
33638+ s32 (* set_d3_lplu_state)(struct e1000_hw *, bool);
33639+ s32 (* write_phy_reg)(struct e1000_hw *, u32, u16);
33640+ s32 (* write_phy_reg_locked)(struct e1000_hw *, u32, u16);
33641+ s32 (* cfg_on_link_up)(struct e1000_hw *);
33642 };
33643
33644 /* Function pointers for the NVM. */
33645 struct e1000_nvm_operations {
33646- s32 (*acquire_nvm)(struct e1000_hw *);
33647- s32 (*read_nvm)(struct e1000_hw *, u16, u16, u16 *);
33648- void (*release_nvm)(struct e1000_hw *);
33649- s32 (*update_nvm)(struct e1000_hw *);
33650- s32 (*valid_led_default)(struct e1000_hw *, u16 *);
33651- s32 (*validate_nvm)(struct e1000_hw *);
33652- s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
33653+ s32 (* const acquire_nvm)(struct e1000_hw *);
33654+ s32 (* const read_nvm)(struct e1000_hw *, u16, u16, u16 *);
33655+ void (* const release_nvm)(struct e1000_hw *);
33656+ s32 (* const update_nvm)(struct e1000_hw *);
33657+ s32 (* const valid_led_default)(struct e1000_hw *, u16 *);
33658+ s32 (* const validate_nvm)(struct e1000_hw *);
33659+ s32 (* const write_nvm)(struct e1000_hw *, u16, u16, u16 *);
33660 };
33661
33662 struct e1000_mac_info {
33663diff -urNp linux-2.6.32.43/drivers/net/e1000e/ich8lan.c linux-2.6.32.43/drivers/net/e1000e/ich8lan.c
33664--- linux-2.6.32.43/drivers/net/e1000e/ich8lan.c 2011-05-10 22:12:01.000000000 -0400
33665+++ linux-2.6.32.43/drivers/net/e1000e/ich8lan.c 2011-08-05 20:33:55.000000000 -0400
33666@@ -265,13 +265,13 @@ static s32 e1000_init_phy_params_pchlan(
33667 phy->addr = 1;
33668 phy->reset_delay_us = 100;
33669
33670- phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
33671- phy->ops.read_phy_reg = e1000_read_phy_reg_hv;
33672- phy->ops.read_phy_reg_locked = e1000_read_phy_reg_hv_locked;
33673- phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
33674- phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
33675- phy->ops.write_phy_reg = e1000_write_phy_reg_hv;
33676- phy->ops.write_phy_reg_locked = e1000_write_phy_reg_hv_locked;
33677+ *(void **)&phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
33678+ *(void **)&phy->ops.read_phy_reg = e1000_read_phy_reg_hv;
33679+ *(void **)&phy->ops.read_phy_reg_locked = e1000_read_phy_reg_hv_locked;
33680+ *(void **)&phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
33681+ *(void **)&phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
33682+ *(void **)&phy->ops.write_phy_reg = e1000_write_phy_reg_hv;
33683+ *(void **)&phy->ops.write_phy_reg_locked = e1000_write_phy_reg_hv_locked;
33684 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
33685
33686 /*
33687@@ -289,12 +289,12 @@ static s32 e1000_init_phy_params_pchlan(
33688 phy->type = e1000e_get_phy_type_from_id(phy->id);
33689
33690 if (phy->type == e1000_phy_82577) {
33691- phy->ops.check_polarity = e1000_check_polarity_82577;
33692- phy->ops.force_speed_duplex =
33693+ *(void **)&phy->ops.check_polarity = e1000_check_polarity_82577;
33694+ *(void **)&phy->ops.force_speed_duplex =
33695 e1000_phy_force_speed_duplex_82577;
33696- phy->ops.get_cable_length = e1000_get_cable_length_82577;
33697- phy->ops.get_phy_info = e1000_get_phy_info_82577;
33698- phy->ops.commit_phy = e1000e_phy_sw_reset;
33699+ *(void **)&phy->ops.get_cable_length = e1000_get_cable_length_82577;
33700+ *(void **)&phy->ops.get_phy_info = e1000_get_phy_info_82577;
33701+ *(void **)&phy->ops.commit_phy = e1000e_phy_sw_reset;
33702 }
33703
33704 out:
33705@@ -322,8 +322,8 @@ static s32 e1000_init_phy_params_ich8lan
33706 */
33707 ret_val = e1000e_determine_phy_address(hw);
33708 if (ret_val) {
33709- hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
33710- hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
33711+ *(void **)&hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
33712+ *(void **)&hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
33713 ret_val = e1000e_determine_phy_address(hw);
33714 if (ret_val)
33715 return ret_val;
33716@@ -343,8 +343,8 @@ static s32 e1000_init_phy_params_ich8lan
33717 case IGP03E1000_E_PHY_ID:
33718 phy->type = e1000_phy_igp_3;
33719 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
33720- phy->ops.read_phy_reg_locked = e1000e_read_phy_reg_igp_locked;
33721- phy->ops.write_phy_reg_locked = e1000e_write_phy_reg_igp_locked;
33722+ *(void **)&phy->ops.read_phy_reg_locked = e1000e_read_phy_reg_igp_locked;
33723+ *(void **)&phy->ops.write_phy_reg_locked = e1000e_write_phy_reg_igp_locked;
33724 break;
33725 case IFE_E_PHY_ID:
33726 case IFE_PLUS_E_PHY_ID:
33727@@ -355,16 +355,16 @@ static s32 e1000_init_phy_params_ich8lan
33728 case BME1000_E_PHY_ID:
33729 phy->type = e1000_phy_bm;
33730 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
33731- hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
33732- hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
33733- hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
33734+ *(void **)&hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
33735+ *(void **)&hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
33736+ *(void **)&hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
33737 break;
33738 default:
33739 return -E1000_ERR_PHY;
33740 break;
33741 }
33742
33743- phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
33744+ *(void **)&phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
33745
33746 return 0;
33747 }
33748@@ -455,25 +455,25 @@ static s32 e1000_init_mac_params_ich8lan
33749 case e1000_ich9lan:
33750 case e1000_ich10lan:
33751 /* ID LED init */
33752- mac->ops.id_led_init = e1000e_id_led_init;
33753+ *(void **)&mac->ops.id_led_init = e1000e_id_led_init;
33754 /* setup LED */
33755- mac->ops.setup_led = e1000e_setup_led_generic;
33756+ *(void **)&mac->ops.setup_led = e1000e_setup_led_generic;
33757 /* cleanup LED */
33758- mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
33759+ *(void **)&mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
33760 /* turn on/off LED */
33761- mac->ops.led_on = e1000_led_on_ich8lan;
33762- mac->ops.led_off = e1000_led_off_ich8lan;
33763+ *(void **)&mac->ops.led_on = e1000_led_on_ich8lan;
33764+ *(void **)&mac->ops.led_off = e1000_led_off_ich8lan;
33765 break;
33766 case e1000_pchlan:
33767 /* ID LED init */
33768- mac->ops.id_led_init = e1000_id_led_init_pchlan;
33769+ *(void **)&mac->ops.id_led_init = e1000_id_led_init_pchlan;
33770 /* setup LED */
33771- mac->ops.setup_led = e1000_setup_led_pchlan;
33772+ *(void **)&mac->ops.setup_led = e1000_setup_led_pchlan;
33773 /* cleanup LED */
33774- mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
33775+ *(void **)&mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
33776 /* turn on/off LED */
33777- mac->ops.led_on = e1000_led_on_pchlan;
33778- mac->ops.led_off = e1000_led_off_pchlan;
33779+ *(void **)&mac->ops.led_on = e1000_led_on_pchlan;
33780+ *(void **)&mac->ops.led_off = e1000_led_off_pchlan;
33781 break;
33782 default:
33783 break;
33784@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan
33785 }
33786 }
33787
33788-static struct e1000_mac_operations ich8_mac_ops = {
33789+static const struct e1000_mac_operations ich8_mac_ops = {
33790 .id_led_init = e1000e_id_led_init,
33791 .check_mng_mode = e1000_check_mng_mode_ich8lan,
33792 .check_for_link = e1000_check_for_copper_link_ich8lan,
33793@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_
33794 /* id_led_init dependent on mac type */
33795 };
33796
33797-static struct e1000_phy_operations ich8_phy_ops = {
33798+static const struct e1000_phy_operations ich8_phy_ops = {
33799 .acquire_phy = e1000_acquire_swflag_ich8lan,
33800 .check_reset_block = e1000_check_reset_block_ich8lan,
33801 .commit_phy = NULL,
33802@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_
33803 .write_phy_reg = e1000e_write_phy_reg_igp,
33804 };
33805
33806-static struct e1000_nvm_operations ich8_nvm_ops = {
33807+static const struct e1000_nvm_operations ich8_nvm_ops = {
33808 .acquire_nvm = e1000_acquire_nvm_ich8lan,
33809 .read_nvm = e1000_read_nvm_ich8lan,
33810 .release_nvm = e1000_release_nvm_ich8lan,
33811diff -urNp linux-2.6.32.43/drivers/net/e1000e/netdev.c linux-2.6.32.43/drivers/net/e1000e/netdev.c
33812--- linux-2.6.32.43/drivers/net/e1000e/netdev.c 2011-03-27 14:31:47.000000000 -0400
33813+++ linux-2.6.32.43/drivers/net/e1000e/netdev.c 2011-08-05 20:33:55.000000000 -0400
33814@@ -5071,9 +5071,9 @@ static int __devinit e1000_probe(struct
33815
33816 err = -EIO;
33817
33818- memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
33819- memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
33820- memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
33821+ memcpy((void *)&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
33822+ memcpy((void *)&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
33823+ memcpy((void *)&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
33824
33825 err = ei->get_variants(adapter);
33826 if (err)
33827diff -urNp linux-2.6.32.43/drivers/net/hamradio/6pack.c linux-2.6.32.43/drivers/net/hamradio/6pack.c
33828--- linux-2.6.32.43/drivers/net/hamradio/6pack.c 2011-07-13 17:23:04.000000000 -0400
33829+++ linux-2.6.32.43/drivers/net/hamradio/6pack.c 2011-07-13 17:23:18.000000000 -0400
33830@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct t
33831 unsigned char buf[512];
33832 int count1;
33833
33834+ pax_track_stack();
33835+
33836 if (!count)
33837 return;
33838
33839diff -urNp linux-2.6.32.43/drivers/net/ibmveth.c linux-2.6.32.43/drivers/net/ibmveth.c
33840--- linux-2.6.32.43/drivers/net/ibmveth.c 2011-03-27 14:31:47.000000000 -0400
33841+++ linux-2.6.32.43/drivers/net/ibmveth.c 2011-04-17 15:56:46.000000000 -0400
33842@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attr
33843 NULL,
33844 };
33845
33846-static struct sysfs_ops veth_pool_ops = {
33847+static const struct sysfs_ops veth_pool_ops = {
33848 .show = veth_pool_show,
33849 .store = veth_pool_store,
33850 };
33851diff -urNp linux-2.6.32.43/drivers/net/igb/e1000_82575.c linux-2.6.32.43/drivers/net/igb/e1000_82575.c
33852--- linux-2.6.32.43/drivers/net/igb/e1000_82575.c 2011-03-27 14:31:47.000000000 -0400
33853+++ linux-2.6.32.43/drivers/net/igb/e1000_82575.c 2011-08-05 20:33:55.000000000 -0400
33854@@ -135,7 +135,7 @@ static s32 igb_get_invariants_82575(stru
33855 ? true : false;
33856
33857 /* physical interface link setup */
33858- mac->ops.setup_physical_interface =
33859+ *(void **)&mac->ops.setup_physical_interface =
33860 (hw->phy.media_type == e1000_media_type_copper)
33861 ? igb_setup_copper_link_82575
33862 : igb_setup_serdes_link_82575;
33863@@ -191,13 +191,13 @@ static s32 igb_get_invariants_82575(stru
33864
33865 /* PHY function pointers */
33866 if (igb_sgmii_active_82575(hw)) {
33867- phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
33868- phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
33869- phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
33870+ *(void **)&phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
33871+ *(void **)&phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
33872+ *(void **)&phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
33873 } else {
33874- phy->ops.reset = igb_phy_hw_reset;
33875- phy->ops.read_reg = igb_read_phy_reg_igp;
33876- phy->ops.write_reg = igb_write_phy_reg_igp;
33877+ *(void **)&phy->ops.reset = igb_phy_hw_reset;
33878+ *(void **)&phy->ops.read_reg = igb_read_phy_reg_igp;
33879+ *(void **)&phy->ops.write_reg = igb_write_phy_reg_igp;
33880 }
33881
33882 /* set lan id */
33883@@ -213,17 +213,17 @@ static s32 igb_get_invariants_82575(stru
33884 switch (phy->id) {
33885 case M88E1111_I_PHY_ID:
33886 phy->type = e1000_phy_m88;
33887- phy->ops.get_phy_info = igb_get_phy_info_m88;
33888- phy->ops.get_cable_length = igb_get_cable_length_m88;
33889- phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
33890+ *(void **)&phy->ops.get_phy_info = igb_get_phy_info_m88;
33891+ *(void **)&phy->ops.get_cable_length = igb_get_cable_length_m88;
33892+ *(void **)&phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
33893 break;
33894 case IGP03E1000_E_PHY_ID:
33895 phy->type = e1000_phy_igp_3;
33896- phy->ops.get_phy_info = igb_get_phy_info_igp;
33897- phy->ops.get_cable_length = igb_get_cable_length_igp_2;
33898- phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
33899- phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
33900- phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
33901+ *(void **)&phy->ops.get_phy_info = igb_get_phy_info_igp;
33902+ *(void **)&phy->ops.get_cable_length = igb_get_cable_length_igp_2;
33903+ *(void **)&phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
33904+ *(void **)&phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
33905+ *(void **)&phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
33906 break;
33907 default:
33908 return -E1000_ERR_PHY;
33909@@ -1410,7 +1410,7 @@ void igb_vmdq_set_replication_pf(struct
33910 wr32(E1000_VT_CTL, vt_ctl);
33911 }
33912
33913-static struct e1000_mac_operations e1000_mac_ops_82575 = {
33914+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
33915 .reset_hw = igb_reset_hw_82575,
33916 .init_hw = igb_init_hw_82575,
33917 .check_for_link = igb_check_for_link_82575,
33918@@ -1419,13 +1419,13 @@ static struct e1000_mac_operations e1000
33919 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
33920 };
33921
33922-static struct e1000_phy_operations e1000_phy_ops_82575 = {
33923+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
33924 .acquire = igb_acquire_phy_82575,
33925 .get_cfg_done = igb_get_cfg_done_82575,
33926 .release = igb_release_phy_82575,
33927 };
33928
33929-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
33930+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
33931 .acquire = igb_acquire_nvm_82575,
33932 .read = igb_read_nvm_eerd,
33933 .release = igb_release_nvm_82575,
33934diff -urNp linux-2.6.32.43/drivers/net/igb/e1000_hw.h linux-2.6.32.43/drivers/net/igb/e1000_hw.h
33935--- linux-2.6.32.43/drivers/net/igb/e1000_hw.h 2011-03-27 14:31:47.000000000 -0400
33936+++ linux-2.6.32.43/drivers/net/igb/e1000_hw.h 2011-04-17 15:56:46.000000000 -0400
33937@@ -305,17 +305,17 @@ struct e1000_phy_operations {
33938 };
33939
33940 struct e1000_nvm_operations {
33941- s32 (*acquire)(struct e1000_hw *);
33942- s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
33943- void (*release)(struct e1000_hw *);
33944- s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
33945+ s32 (* const acquire)(struct e1000_hw *);
33946+ s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
33947+ void (* const release)(struct e1000_hw *);
33948+ s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
33949 };
33950
33951 struct e1000_info {
33952 s32 (*get_invariants)(struct e1000_hw *);
33953- struct e1000_mac_operations *mac_ops;
33954- struct e1000_phy_operations *phy_ops;
33955- struct e1000_nvm_operations *nvm_ops;
33956+ const struct e1000_mac_operations *mac_ops;
33957+ const struct e1000_phy_operations *phy_ops;
33958+ const struct e1000_nvm_operations *nvm_ops;
33959 };
33960
33961 extern const struct e1000_info e1000_82575_info;
33962diff -urNp linux-2.6.32.43/drivers/net/igb/e1000_mbx.c linux-2.6.32.43/drivers/net/igb/e1000_mbx.c
33963--- linux-2.6.32.43/drivers/net/igb/e1000_mbx.c 2011-03-27 14:31:47.000000000 -0400
33964+++ linux-2.6.32.43/drivers/net/igb/e1000_mbx.c 2011-08-05 20:33:55.000000000 -0400
33965@@ -414,13 +414,13 @@ s32 igb_init_mbx_params_pf(struct e1000_
33966
33967 mbx->size = E1000_VFMAILBOX_SIZE;
33968
33969- mbx->ops.read = igb_read_mbx_pf;
33970- mbx->ops.write = igb_write_mbx_pf;
33971- mbx->ops.read_posted = igb_read_posted_mbx;
33972- mbx->ops.write_posted = igb_write_posted_mbx;
33973- mbx->ops.check_for_msg = igb_check_for_msg_pf;
33974- mbx->ops.check_for_ack = igb_check_for_ack_pf;
33975- mbx->ops.check_for_rst = igb_check_for_rst_pf;
33976+ *(void **)&mbx->ops.read = igb_read_mbx_pf;
33977+ *(void **)&mbx->ops.write = igb_write_mbx_pf;
33978+ *(void **)&mbx->ops.read_posted = igb_read_posted_mbx;
33979+ *(void **)&mbx->ops.write_posted = igb_write_posted_mbx;
33980+ *(void **)&mbx->ops.check_for_msg = igb_check_for_msg_pf;
33981+ *(void **)&mbx->ops.check_for_ack = igb_check_for_ack_pf;
33982+ *(void **)&mbx->ops.check_for_rst = igb_check_for_rst_pf;
33983
33984 mbx->stats.msgs_tx = 0;
33985 mbx->stats.msgs_rx = 0;
33986diff -urNp linux-2.6.32.43/drivers/net/igb/igb_main.c linux-2.6.32.43/drivers/net/igb/igb_main.c
33987--- linux-2.6.32.43/drivers/net/igb/igb_main.c 2011-03-27 14:31:47.000000000 -0400
33988+++ linux-2.6.32.43/drivers/net/igb/igb_main.c 2011-08-05 20:33:55.000000000 -0400
33989@@ -1295,9 +1295,9 @@ static int __devinit igb_probe(struct pc
33990 /* setup the private structure */
33991 hw->back = adapter;
33992 /* Copy the default MAC, PHY and NVM function pointers */
33993- memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
33994- memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
33995- memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
33996+ memcpy((void *)&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
33997+ memcpy((void *)&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
33998+ memcpy((void *)&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
33999 /* Initialize skew-specific constants */
34000 err = ei->get_invariants(hw);
34001 if (err)
34002diff -urNp linux-2.6.32.43/drivers/net/igbvf/mbx.c linux-2.6.32.43/drivers/net/igbvf/mbx.c
34003--- linux-2.6.32.43/drivers/net/igbvf/mbx.c 2011-03-27 14:31:47.000000000 -0400
34004+++ linux-2.6.32.43/drivers/net/igbvf/mbx.c 2011-08-05 20:33:55.000000000 -0400
34005@@ -331,13 +331,13 @@ s32 e1000_init_mbx_params_vf(struct e100
34006
34007 mbx->size = E1000_VFMAILBOX_SIZE;
34008
34009- mbx->ops.read = e1000_read_mbx_vf;
34010- mbx->ops.write = e1000_write_mbx_vf;
34011- mbx->ops.read_posted = e1000_read_posted_mbx;
34012- mbx->ops.write_posted = e1000_write_posted_mbx;
34013- mbx->ops.check_for_msg = e1000_check_for_msg_vf;
34014- mbx->ops.check_for_ack = e1000_check_for_ack_vf;
34015- mbx->ops.check_for_rst = e1000_check_for_rst_vf;
34016+ *(void **)&mbx->ops.read = e1000_read_mbx_vf;
34017+ *(void **)&mbx->ops.write = e1000_write_mbx_vf;
34018+ *(void **)&mbx->ops.read_posted = e1000_read_posted_mbx;
34019+ *(void **)&mbx->ops.write_posted = e1000_write_posted_mbx;
34020+ *(void **)&mbx->ops.check_for_msg = e1000_check_for_msg_vf;
34021+ *(void **)&mbx->ops.check_for_ack = e1000_check_for_ack_vf;
34022+ *(void **)&mbx->ops.check_for_rst = e1000_check_for_rst_vf;
34023
34024 mbx->stats.msgs_tx = 0;
34025 mbx->stats.msgs_rx = 0;
34026diff -urNp linux-2.6.32.43/drivers/net/igbvf/vf.c linux-2.6.32.43/drivers/net/igbvf/vf.c
34027--- linux-2.6.32.43/drivers/net/igbvf/vf.c 2011-03-27 14:31:47.000000000 -0400
34028+++ linux-2.6.32.43/drivers/net/igbvf/vf.c 2011-08-05 20:33:55.000000000 -0400
34029@@ -55,21 +55,21 @@ static s32 e1000_init_mac_params_vf(stru
34030
34031 /* Function pointers */
34032 /* reset */
34033- mac->ops.reset_hw = e1000_reset_hw_vf;
34034+ *(void **)&mac->ops.reset_hw = e1000_reset_hw_vf;
34035 /* hw initialization */
34036- mac->ops.init_hw = e1000_init_hw_vf;
34037+ *(void **)&mac->ops.init_hw = e1000_init_hw_vf;
34038 /* check for link */
34039- mac->ops.check_for_link = e1000_check_for_link_vf;
34040+ *(void **)&mac->ops.check_for_link = e1000_check_for_link_vf;
34041 /* link info */
34042- mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
34043+ *(void **)&mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
34044 /* multicast address update */
34045- mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
34046+ *(void **)&mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
34047 /* set mac address */
34048- mac->ops.rar_set = e1000_rar_set_vf;
34049+ *(void **)&mac->ops.rar_set = e1000_rar_set_vf;
34050 /* read mac address */
34051- mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
34052+ *(void **)&mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
34053 /* set vlan filter table array */
34054- mac->ops.set_vfta = e1000_set_vfta_vf;
34055+ *(void **)&mac->ops.set_vfta = e1000_set_vfta_vf;
34056
34057 return E1000_SUCCESS;
34058 }
34059@@ -80,8 +80,8 @@ static s32 e1000_init_mac_params_vf(stru
34060 **/
34061 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
34062 {
34063- hw->mac.ops.init_params = e1000_init_mac_params_vf;
34064- hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
34065+ *(void **)&hw->mac.ops.init_params = e1000_init_mac_params_vf;
34066+ *(void **)&hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
34067 }
34068
34069 /**
34070diff -urNp linux-2.6.32.43/drivers/net/iseries_veth.c linux-2.6.32.43/drivers/net/iseries_veth.c
34071--- linux-2.6.32.43/drivers/net/iseries_veth.c 2011-03-27 14:31:47.000000000 -0400
34072+++ linux-2.6.32.43/drivers/net/iseries_veth.c 2011-04-17 15:56:46.000000000 -0400
34073@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_defaul
34074 NULL
34075 };
34076
34077-static struct sysfs_ops veth_cnx_sysfs_ops = {
34078+static const struct sysfs_ops veth_cnx_sysfs_ops = {
34079 .show = veth_cnx_attribute_show
34080 };
34081
34082@@ -441,7 +441,7 @@ static struct attribute *veth_port_defau
34083 NULL
34084 };
34085
34086-static struct sysfs_ops veth_port_sysfs_ops = {
34087+static const struct sysfs_ops veth_port_sysfs_ops = {
34088 .show = veth_port_attribute_show
34089 };
34090
34091diff -urNp linux-2.6.32.43/drivers/net/ixgb/ixgb_main.c linux-2.6.32.43/drivers/net/ixgb/ixgb_main.c
34092--- linux-2.6.32.43/drivers/net/ixgb/ixgb_main.c 2011-03-27 14:31:47.000000000 -0400
34093+++ linux-2.6.32.43/drivers/net/ixgb/ixgb_main.c 2011-05-16 21:46:57.000000000 -0400
34094@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev
34095 u32 rctl;
34096 int i;
34097
34098+ pax_track_stack();
34099+
34100 /* Check for Promiscuous and All Multicast modes */
34101
34102 rctl = IXGB_READ_REG(hw, RCTL);
34103diff -urNp linux-2.6.32.43/drivers/net/ixgb/ixgb_param.c linux-2.6.32.43/drivers/net/ixgb/ixgb_param.c
34104--- linux-2.6.32.43/drivers/net/ixgb/ixgb_param.c 2011-03-27 14:31:47.000000000 -0400
34105+++ linux-2.6.32.43/drivers/net/ixgb/ixgb_param.c 2011-05-16 21:46:57.000000000 -0400
34106@@ -260,6 +260,9 @@ void __devinit
34107 ixgb_check_options(struct ixgb_adapter *adapter)
34108 {
34109 int bd = adapter->bd_number;
34110+
34111+ pax_track_stack();
34112+
34113 if (bd >= IXGB_MAX_NIC) {
34114 printk(KERN_NOTICE
34115 "Warning: no configuration for board #%i\n", bd);
34116diff -urNp linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82598.c linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82598.c
34117--- linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82598.c 2011-03-27 14:31:47.000000000 -0400
34118+++ linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82598.c 2011-08-05 20:33:55.000000000 -0400
34119@@ -154,19 +154,19 @@ static s32 ixgbe_init_phy_ops_82598(stru
34120
34121 /* Overwrite the link function pointers if copper PHY */
34122 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
34123- mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
34124- mac->ops.get_link_capabilities =
34125+ *(void **)&mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
34126+ *(void **)&mac->ops.get_link_capabilities =
34127 &ixgbe_get_copper_link_capabilities_82598;
34128 }
34129
34130 switch (hw->phy.type) {
34131 case ixgbe_phy_tn:
34132- phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34133- phy->ops.get_firmware_version =
34134+ *(void **)&phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34135+ *(void **)&phy->ops.get_firmware_version =
34136 &ixgbe_get_phy_firmware_version_tnx;
34137 break;
34138 case ixgbe_phy_nl:
34139- phy->ops.reset = &ixgbe_reset_phy_nl;
34140+ *(void **)&phy->ops.reset = &ixgbe_reset_phy_nl;
34141
34142 /* Call SFP+ identify routine to get the SFP+ module type */
34143 ret_val = phy->ops.identify_sfp(hw);
34144diff -urNp linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82599.c
34145--- linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82599.c 2011-03-27 14:31:47.000000000 -0400
34146+++ linux-2.6.32.43/drivers/net/ixgbe/ixgbe_82599.c 2011-08-05 20:33:55.000000000 -0400
34147@@ -62,9 +62,9 @@ static void ixgbe_init_mac_link_ops_8259
34148 struct ixgbe_mac_info *mac = &hw->mac;
34149 if (hw->phy.multispeed_fiber) {
34150 /* Set up dual speed SFP+ support */
34151- mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
34152+ *(void **)&mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
34153 } else {
34154- mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
34155+ *(void **)&mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
34156 }
34157 }
34158
34159@@ -76,7 +76,7 @@ static s32 ixgbe_setup_sfp_modules_82599
34160 if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
34161 ixgbe_init_mac_link_ops_82599(hw);
34162
34163- hw->phy.ops.reset = NULL;
34164+ *(void **)&hw->phy.ops.reset = NULL;
34165
34166 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
34167 &data_offset);
34168@@ -171,16 +171,16 @@ static s32 ixgbe_init_phy_ops_82599(stru
34169
34170 /* If copper media, overwrite with copper function pointers */
34171 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
34172- mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
34173- mac->ops.get_link_capabilities =
34174+ *(void **)&mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
34175+ *(void **)&mac->ops.get_link_capabilities =
34176 &ixgbe_get_copper_link_capabilities_82599;
34177 }
34178
34179 /* Set necessary function pointers based on phy type */
34180 switch (hw->phy.type) {
34181 case ixgbe_phy_tn:
34182- phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34183- phy->ops.get_firmware_version =
34184+ *(void **)&phy->ops.check_link = &ixgbe_check_phy_link_tnx;
34185+ *(void **)&phy->ops.get_firmware_version =
34186 &ixgbe_get_phy_firmware_version_tnx;
34187 break;
34188 default:
34189diff -urNp linux-2.6.32.43/drivers/net/ixgbe/ixgbe_main.c linux-2.6.32.43/drivers/net/ixgbe/ixgbe_main.c
34190--- linux-2.6.32.43/drivers/net/ixgbe/ixgbe_main.c 2011-03-27 14:31:47.000000000 -0400
34191+++ linux-2.6.32.43/drivers/net/ixgbe/ixgbe_main.c 2011-08-05 20:33:55.000000000 -0400
34192@@ -5638,18 +5638,18 @@ static int __devinit ixgbe_probe(struct
34193 adapter->bd_number = cards_found;
34194
34195 /* Setup hw api */
34196- memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
34197+ memcpy((void *)&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
34198 hw->mac.type = ii->mac;
34199
34200 /* EEPROM */
34201- memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
34202+ memcpy((void *)&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
34203 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
34204 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
34205 if (!(eec & (1 << 8)))
34206- hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
34207+ *(void **)&hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
34208
34209 /* PHY */
34210- memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
34211+ memcpy((void *)&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
34212 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
34213 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
34214 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
34215diff -urNp linux-2.6.32.43/drivers/net/mlx4/main.c linux-2.6.32.43/drivers/net/mlx4/main.c
34216--- linux-2.6.32.43/drivers/net/mlx4/main.c 2011-03-27 14:31:47.000000000 -0400
34217+++ linux-2.6.32.43/drivers/net/mlx4/main.c 2011-05-18 20:09:37.000000000 -0400
34218@@ -38,6 +38,7 @@
34219 #include <linux/errno.h>
34220 #include <linux/pci.h>
34221 #include <linux/dma-mapping.h>
34222+#include <linux/sched.h>
34223
34224 #include <linux/mlx4/device.h>
34225 #include <linux/mlx4/doorbell.h>
34226@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev
34227 u64 icm_size;
34228 int err;
34229
34230+ pax_track_stack();
34231+
34232 err = mlx4_QUERY_FW(dev);
34233 if (err) {
34234 if (err == -EACCES)
34235diff -urNp linux-2.6.32.43/drivers/net/niu.c linux-2.6.32.43/drivers/net/niu.c
34236--- linux-2.6.32.43/drivers/net/niu.c 2011-05-10 22:12:01.000000000 -0400
34237+++ linux-2.6.32.43/drivers/net/niu.c 2011-05-16 21:46:57.000000000 -0400
34238@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struc
34239 int i, num_irqs, err;
34240 u8 first_ldg;
34241
34242+ pax_track_stack();
34243+
34244 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
34245 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
34246 ldg_num_map[i] = first_ldg + i;
34247diff -urNp linux-2.6.32.43/drivers/net/pcnet32.c linux-2.6.32.43/drivers/net/pcnet32.c
34248--- linux-2.6.32.43/drivers/net/pcnet32.c 2011-03-27 14:31:47.000000000 -0400
34249+++ linux-2.6.32.43/drivers/net/pcnet32.c 2011-08-05 20:33:55.000000000 -0400
34250@@ -79,7 +79,7 @@ static int cards_found;
34251 /*
34252 * VLB I/O addresses
34253 */
34254-static unsigned int pcnet32_portlist[] __initdata =
34255+static unsigned int pcnet32_portlist[] __devinitdata =
34256 { 0x300, 0x320, 0x340, 0x360, 0 };
34257
34258 static int pcnet32_debug = 0;
34259@@ -267,7 +267,7 @@ struct pcnet32_private {
34260 struct sk_buff **rx_skbuff;
34261 dma_addr_t *tx_dma_addr;
34262 dma_addr_t *rx_dma_addr;
34263- struct pcnet32_access a;
34264+ struct pcnet32_access *a;
34265 spinlock_t lock; /* Guard lock */
34266 unsigned int cur_rx, cur_tx; /* The next free ring entry */
34267 unsigned int rx_ring_size; /* current rx ring size */
34268@@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct n
34269 u16 val;
34270
34271 netif_wake_queue(dev);
34272- val = lp->a.read_csr(ioaddr, CSR3);
34273+ val = lp->a->read_csr(ioaddr, CSR3);
34274 val &= 0x00ff;
34275- lp->a.write_csr(ioaddr, CSR3, val);
34276+ lp->a->write_csr(ioaddr, CSR3, val);
34277 napi_enable(&lp->napi);
34278 }
34279
34280@@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_d
34281 r = mii_link_ok(&lp->mii_if);
34282 } else if (lp->chip_version >= PCNET32_79C970A) {
34283 ulong ioaddr = dev->base_addr; /* card base I/O address */
34284- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
34285+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
34286 } else { /* can not detect link on really old chips */
34287 r = 1;
34288 }
34289@@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct
34290 pcnet32_netif_stop(dev);
34291
34292 spin_lock_irqsave(&lp->lock, flags);
34293- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34294+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34295
34296 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
34297
34298@@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct
34299 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
34300 {
34301 struct pcnet32_private *lp = netdev_priv(dev);
34302- struct pcnet32_access *a = &lp->a; /* access to registers */
34303+ struct pcnet32_access *a = lp->a; /* access to registers */
34304 ulong ioaddr = dev->base_addr; /* card base I/O address */
34305 struct sk_buff *skb; /* sk buff */
34306 int x, i; /* counters */
34307@@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct
34308 pcnet32_netif_stop(dev);
34309
34310 spin_lock_irqsave(&lp->lock, flags);
34311- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34312+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
34313
34314 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
34315
34316 /* Reset the PCNET32 */
34317- lp->a.reset(ioaddr);
34318- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34319+ lp->a->reset(ioaddr);
34320+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34321
34322 /* switch pcnet32 to 32bit mode */
34323- lp->a.write_bcr(ioaddr, 20, 2);
34324+ lp->a->write_bcr(ioaddr, 20, 2);
34325
34326 /* purge & init rings but don't actually restart */
34327 pcnet32_restart(dev, 0x0000);
34328
34329- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34330+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34331
34332 /* Initialize Transmit buffers. */
34333 size = data_len + 15;
34334@@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct
34335
34336 /* set int loopback in CSR15 */
34337 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
34338- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
34339+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
34340
34341 teststatus = cpu_to_le16(0x8000);
34342- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
34343+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
34344
34345 /* Check status of descriptors */
34346 for (x = 0; x < numbuffs; x++) {
34347@@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct
34348 }
34349 }
34350
34351- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34352+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
34353 wmb();
34354 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
34355 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
34356@@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct
34357 pcnet32_restart(dev, CSR0_NORMAL);
34358 } else {
34359 pcnet32_purge_rx_ring(dev);
34360- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
34361+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
34362 }
34363 spin_unlock_irqrestore(&lp->lock, flags);
34364
34365@@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct
34366 static void pcnet32_led_blink_callback(struct net_device *dev)
34367 {
34368 struct pcnet32_private *lp = netdev_priv(dev);
34369- struct pcnet32_access *a = &lp->a;
34370+ struct pcnet32_access *a = lp->a;
34371 ulong ioaddr = dev->base_addr;
34372 unsigned long flags;
34373 int i;
34374@@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(s
34375 static int pcnet32_phys_id(struct net_device *dev, u32 data)
34376 {
34377 struct pcnet32_private *lp = netdev_priv(dev);
34378- struct pcnet32_access *a = &lp->a;
34379+ struct pcnet32_access *a = lp->a;
34380 ulong ioaddr = dev->base_addr;
34381 unsigned long flags;
34382 int i, regs[4];
34383@@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_de
34384 {
34385 int csr5;
34386 struct pcnet32_private *lp = netdev_priv(dev);
34387- struct pcnet32_access *a = &lp->a;
34388+ struct pcnet32_access *a = lp->a;
34389 ulong ioaddr = dev->base_addr;
34390 int ticks;
34391
34392@@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_stru
34393 spin_lock_irqsave(&lp->lock, flags);
34394 if (pcnet32_tx(dev)) {
34395 /* reset the chip to clear the error condition, then restart */
34396- lp->a.reset(ioaddr);
34397- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34398+ lp->a->reset(ioaddr);
34399+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34400 pcnet32_restart(dev, CSR0_START);
34401 netif_wake_queue(dev);
34402 }
34403@@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_stru
34404 __napi_complete(napi);
34405
34406 /* clear interrupt masks */
34407- val = lp->a.read_csr(ioaddr, CSR3);
34408+ val = lp->a->read_csr(ioaddr, CSR3);
34409 val &= 0x00ff;
34410- lp->a.write_csr(ioaddr, CSR3, val);
34411+ lp->a->write_csr(ioaddr, CSR3, val);
34412
34413 /* Set interrupt enable. */
34414- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
34415+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
34416
34417 spin_unlock_irqrestore(&lp->lock, flags);
34418 }
34419@@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_
34420 int i, csr0;
34421 u16 *buff = ptr;
34422 struct pcnet32_private *lp = netdev_priv(dev);
34423- struct pcnet32_access *a = &lp->a;
34424+ struct pcnet32_access *a = lp->a;
34425 ulong ioaddr = dev->base_addr;
34426 unsigned long flags;
34427
34428@@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_
34429 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
34430 if (lp->phymask & (1 << j)) {
34431 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
34432- lp->a.write_bcr(ioaddr, 33,
34433+ lp->a->write_bcr(ioaddr, 33,
34434 (j << 5) | i);
34435- *buff++ = lp->a.read_bcr(ioaddr, 34);
34436+ *buff++ = lp->a->read_bcr(ioaddr, 34);
34437 }
34438 }
34439 }
34440@@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int
34441 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
34442 lp->options |= PCNET32_PORT_FD;
34443
34444- lp->a = *a;
34445+ lp->a = a;
34446
34447 /* prior to register_netdev, dev->name is not yet correct */
34448 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
34449@@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int
34450 if (lp->mii) {
34451 /* lp->phycount and lp->phymask are set to 0 by memset above */
34452
34453- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
34454+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
34455 /* scan for PHYs */
34456 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
34457 unsigned short id1, id2;
34458@@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int
34459 "Found PHY %04x:%04x at address %d.\n",
34460 id1, id2, i);
34461 }
34462- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
34463+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
34464 if (lp->phycount > 1) {
34465 lp->options |= PCNET32_PORT_MII;
34466 }
34467@@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_devic
34468 }
34469
34470 /* Reset the PCNET32 */
34471- lp->a.reset(ioaddr);
34472+ lp->a->reset(ioaddr);
34473
34474 /* switch pcnet32 to 32bit mode */
34475- lp->a.write_bcr(ioaddr, 20, 2);
34476+ lp->a->write_bcr(ioaddr, 20, 2);
34477
34478 if (netif_msg_ifup(lp))
34479 printk(KERN_DEBUG
34480@@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_devic
34481 (u32) (lp->init_dma_addr));
34482
34483 /* set/reset autoselect bit */
34484- val = lp->a.read_bcr(ioaddr, 2) & ~2;
34485+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
34486 if (lp->options & PCNET32_PORT_ASEL)
34487 val |= 2;
34488- lp->a.write_bcr(ioaddr, 2, val);
34489+ lp->a->write_bcr(ioaddr, 2, val);
34490
34491 /* handle full duplex setting */
34492 if (lp->mii_if.full_duplex) {
34493- val = lp->a.read_bcr(ioaddr, 9) & ~3;
34494+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
34495 if (lp->options & PCNET32_PORT_FD) {
34496 val |= 1;
34497 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
34498@@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_devic
34499 if (lp->chip_version == 0x2627)
34500 val |= 3;
34501 }
34502- lp->a.write_bcr(ioaddr, 9, val);
34503+ lp->a->write_bcr(ioaddr, 9, val);
34504 }
34505
34506 /* set/reset GPSI bit in test register */
34507- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
34508+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
34509 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
34510 val |= 0x10;
34511- lp->a.write_csr(ioaddr, 124, val);
34512+ lp->a->write_csr(ioaddr, 124, val);
34513
34514 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
34515 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
34516@@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_devic
34517 * duplex, and/or enable auto negotiation, and clear DANAS
34518 */
34519 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
34520- lp->a.write_bcr(ioaddr, 32,
34521- lp->a.read_bcr(ioaddr, 32) | 0x0080);
34522+ lp->a->write_bcr(ioaddr, 32,
34523+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
34524 /* disable Auto Negotiation, set 10Mpbs, HD */
34525- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
34526+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
34527 if (lp->options & PCNET32_PORT_FD)
34528 val |= 0x10;
34529 if (lp->options & PCNET32_PORT_100)
34530 val |= 0x08;
34531- lp->a.write_bcr(ioaddr, 32, val);
34532+ lp->a->write_bcr(ioaddr, 32, val);
34533 } else {
34534 if (lp->options & PCNET32_PORT_ASEL) {
34535- lp->a.write_bcr(ioaddr, 32,
34536- lp->a.read_bcr(ioaddr,
34537+ lp->a->write_bcr(ioaddr, 32,
34538+ lp->a->read_bcr(ioaddr,
34539 32) | 0x0080);
34540 /* enable auto negotiate, setup, disable fd */
34541- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
34542+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
34543 val |= 0x20;
34544- lp->a.write_bcr(ioaddr, 32, val);
34545+ lp->a->write_bcr(ioaddr, 32, val);
34546 }
34547 }
34548 } else {
34549@@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_devic
34550 * There is really no good other way to handle multiple PHYs
34551 * other than turning off all automatics
34552 */
34553- val = lp->a.read_bcr(ioaddr, 2);
34554- lp->a.write_bcr(ioaddr, 2, val & ~2);
34555- val = lp->a.read_bcr(ioaddr, 32);
34556- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
34557+ val = lp->a->read_bcr(ioaddr, 2);
34558+ lp->a->write_bcr(ioaddr, 2, val & ~2);
34559+ val = lp->a->read_bcr(ioaddr, 32);
34560+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
34561
34562 if (!(lp->options & PCNET32_PORT_ASEL)) {
34563 /* setup ecmd */
34564@@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_devic
34565 ecmd.speed =
34566 lp->
34567 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
34568- bcr9 = lp->a.read_bcr(ioaddr, 9);
34569+ bcr9 = lp->a->read_bcr(ioaddr, 9);
34570
34571 if (lp->options & PCNET32_PORT_FD) {
34572 ecmd.duplex = DUPLEX_FULL;
34573@@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_devic
34574 ecmd.duplex = DUPLEX_HALF;
34575 bcr9 |= ~(1 << 0);
34576 }
34577- lp->a.write_bcr(ioaddr, 9, bcr9);
34578+ lp->a->write_bcr(ioaddr, 9, bcr9);
34579 }
34580
34581 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
34582@@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_devic
34583
34584 #ifdef DO_DXSUFLO
34585 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
34586- val = lp->a.read_csr(ioaddr, CSR3);
34587+ val = lp->a->read_csr(ioaddr, CSR3);
34588 val |= 0x40;
34589- lp->a.write_csr(ioaddr, CSR3, val);
34590+ lp->a->write_csr(ioaddr, CSR3, val);
34591 }
34592 #endif
34593
34594@@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_devic
34595 napi_enable(&lp->napi);
34596
34597 /* Re-initialize the PCNET32, and start it when done. */
34598- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
34599- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
34600+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
34601+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
34602
34603- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34604- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
34605+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
34606+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
34607
34608 netif_start_queue(dev);
34609
34610@@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_devic
34611
34612 i = 0;
34613 while (i++ < 100)
34614- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
34615+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
34616 break;
34617 /*
34618 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
34619 * reports that doing so triggers a bug in the '974.
34620 */
34621- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
34622+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
34623
34624 if (netif_msg_ifup(lp))
34625 printk(KERN_DEBUG
34626 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
34627 dev->name, i,
34628 (u32) (lp->init_dma_addr),
34629- lp->a.read_csr(ioaddr, CSR0));
34630+ lp->a->read_csr(ioaddr, CSR0));
34631
34632 spin_unlock_irqrestore(&lp->lock, flags);
34633
34634@@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_devic
34635 * Switch back to 16bit mode to avoid problems with dumb
34636 * DOS packet driver after a warm reboot
34637 */
34638- lp->a.write_bcr(ioaddr, 20, 4);
34639+ lp->a->write_bcr(ioaddr, 20, 4);
34640
34641 err_free_irq:
34642 spin_unlock_irqrestore(&lp->lock, flags);
34643@@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_d
34644
34645 /* wait for stop */
34646 for (i = 0; i < 100; i++)
34647- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
34648+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
34649 break;
34650
34651 if (i >= 100 && netif_msg_drv(lp))
34652@@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_d
34653 return;
34654
34655 /* ReInit Ring */
34656- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
34657+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
34658 i = 0;
34659 while (i++ < 1000)
34660- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
34661+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
34662 break;
34663
34664- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
34665+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
34666 }
34667
34668 static void pcnet32_tx_timeout(struct net_device *dev)
34669@@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct ne
34670 if (pcnet32_debug & NETIF_MSG_DRV)
34671 printk(KERN_ERR
34672 "%s: transmit timed out, status %4.4x, resetting.\n",
34673- dev->name, lp->a.read_csr(ioaddr, CSR0));
34674- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34675+ dev->name, lp->a->read_csr(ioaddr, CSR0));
34676+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34677 dev->stats.tx_errors++;
34678 if (netif_msg_tx_err(lp)) {
34679 int i;
34680@@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(st
34681 if (netif_msg_tx_queued(lp)) {
34682 printk(KERN_DEBUG
34683 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
34684- dev->name, lp->a.read_csr(ioaddr, CSR0));
34685+ dev->name, lp->a->read_csr(ioaddr, CSR0));
34686 }
34687
34688 /* Default status -- will not enable Successful-TxDone
34689@@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(st
34690 dev->stats.tx_bytes += skb->len;
34691
34692 /* Trigger an immediate send poll. */
34693- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
34694+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
34695
34696 dev->trans_start = jiffies;
34697
34698@@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
34699
34700 spin_lock(&lp->lock);
34701
34702- csr0 = lp->a.read_csr(ioaddr, CSR0);
34703+ csr0 = lp->a->read_csr(ioaddr, CSR0);
34704 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
34705 if (csr0 == 0xffff) {
34706 break; /* PCMCIA remove happened */
34707 }
34708 /* Acknowledge all of the current interrupt sources ASAP. */
34709- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
34710+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
34711
34712 if (netif_msg_intr(lp))
34713 printk(KERN_DEBUG
34714 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
34715- dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
34716+ dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
34717
34718 /* Log misc errors. */
34719 if (csr0 & 0x4000)
34720@@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
34721 if (napi_schedule_prep(&lp->napi)) {
34722 u16 val;
34723 /* set interrupt masks */
34724- val = lp->a.read_csr(ioaddr, CSR3);
34725+ val = lp->a->read_csr(ioaddr, CSR3);
34726 val |= 0x5f00;
34727- lp->a.write_csr(ioaddr, CSR3, val);
34728+ lp->a->write_csr(ioaddr, CSR3, val);
34729
34730 __napi_schedule(&lp->napi);
34731 break;
34732 }
34733- csr0 = lp->a.read_csr(ioaddr, CSR0);
34734+ csr0 = lp->a->read_csr(ioaddr, CSR0);
34735 }
34736
34737 if (netif_msg_intr(lp))
34738 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
34739- dev->name, lp->a.read_csr(ioaddr, CSR0));
34740+ dev->name, lp->a->read_csr(ioaddr, CSR0));
34741
34742 spin_unlock(&lp->lock);
34743
34744@@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_devi
34745
34746 spin_lock_irqsave(&lp->lock, flags);
34747
34748- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
34749+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
34750
34751 if (netif_msg_ifdown(lp))
34752 printk(KERN_DEBUG
34753 "%s: Shutting down ethercard, status was %2.2x.\n",
34754- dev->name, lp->a.read_csr(ioaddr, CSR0));
34755+ dev->name, lp->a->read_csr(ioaddr, CSR0));
34756
34757 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
34758- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34759+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34760
34761 /*
34762 * Switch back to 16bit mode to avoid problems with dumb
34763 * DOS packet driver after a warm reboot
34764 */
34765- lp->a.write_bcr(ioaddr, 20, 4);
34766+ lp->a->write_bcr(ioaddr, 20, 4);
34767
34768 spin_unlock_irqrestore(&lp->lock, flags);
34769
34770@@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_
34771 unsigned long flags;
34772
34773 spin_lock_irqsave(&lp->lock, flags);
34774- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
34775+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
34776 spin_unlock_irqrestore(&lp->lock, flags);
34777
34778 return &dev->stats;
34779@@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struc
34780 if (dev->flags & IFF_ALLMULTI) {
34781 ib->filter[0] = cpu_to_le32(~0U);
34782 ib->filter[1] = cpu_to_le32(~0U);
34783- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
34784- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
34785- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
34786- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
34787+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
34788+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
34789+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
34790+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
34791 return;
34792 }
34793 /* clear the multicast filter */
34794@@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struc
34795 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
34796 }
34797 for (i = 0; i < 4; i++)
34798- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
34799+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
34800 le16_to_cpu(mcast_table[i]));
34801 return;
34802 }
34803@@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(s
34804
34805 spin_lock_irqsave(&lp->lock, flags);
34806 suspended = pcnet32_suspend(dev, &flags, 0);
34807- csr15 = lp->a.read_csr(ioaddr, CSR15);
34808+ csr15 = lp->a->read_csr(ioaddr, CSR15);
34809 if (dev->flags & IFF_PROMISC) {
34810 /* Log any net taps. */
34811 if (netif_msg_hw(lp))
34812@@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(s
34813 lp->init_block->mode =
34814 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
34815 7);
34816- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
34817+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
34818 } else {
34819 lp->init_block->mode =
34820 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
34821- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
34822+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
34823 pcnet32_load_multicast(dev);
34824 }
34825
34826 if (suspended) {
34827 int csr5;
34828 /* clear SUSPEND (SPND) - CSR5 bit 0 */
34829- csr5 = lp->a.read_csr(ioaddr, CSR5);
34830- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
34831+ csr5 = lp->a->read_csr(ioaddr, CSR5);
34832+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
34833 } else {
34834- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
34835+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
34836 pcnet32_restart(dev, CSR0_NORMAL);
34837 netif_wake_queue(dev);
34838 }
34839@@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *
34840 if (!lp->mii)
34841 return 0;
34842
34843- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34844- val_out = lp->a.read_bcr(ioaddr, 34);
34845+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34846+ val_out = lp->a->read_bcr(ioaddr, 34);
34847
34848 return val_out;
34849 }
34850@@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device
34851 if (!lp->mii)
34852 return;
34853
34854- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34855- lp->a.write_bcr(ioaddr, 34, val);
34856+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
34857+ lp->a->write_bcr(ioaddr, 34, val);
34858 }
34859
34860 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34861@@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct n
34862 curr_link = mii_link_ok(&lp->mii_if);
34863 } else {
34864 ulong ioaddr = dev->base_addr; /* card base I/O address */
34865- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
34866+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
34867 }
34868 if (!curr_link) {
34869 if (prev_link || verbose) {
34870@@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct n
34871 (ecmd.duplex ==
34872 DUPLEX_FULL) ? "full" : "half");
34873 }
34874- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
34875+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
34876 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
34877 if (lp->mii_if.full_duplex)
34878 bcr9 |= (1 << 0);
34879 else
34880 bcr9 &= ~(1 << 0);
34881- lp->a.write_bcr(dev->base_addr, 9, bcr9);
34882+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
34883 }
34884 } else {
34885 if (netif_msg_link(lp))
34886diff -urNp linux-2.6.32.43/drivers/net/tg3.h linux-2.6.32.43/drivers/net/tg3.h
34887--- linux-2.6.32.43/drivers/net/tg3.h 2011-03-27 14:31:47.000000000 -0400
34888+++ linux-2.6.32.43/drivers/net/tg3.h 2011-04-17 15:56:46.000000000 -0400
34889@@ -95,6 +95,7 @@
34890 #define CHIPREV_ID_5750_A0 0x4000
34891 #define CHIPREV_ID_5750_A1 0x4001
34892 #define CHIPREV_ID_5750_A3 0x4003
34893+#define CHIPREV_ID_5750_C1 0x4201
34894 #define CHIPREV_ID_5750_C2 0x4202
34895 #define CHIPREV_ID_5752_A0_HW 0x5000
34896 #define CHIPREV_ID_5752_A0 0x6000
34897diff -urNp linux-2.6.32.43/drivers/net/tokenring/abyss.c linux-2.6.32.43/drivers/net/tokenring/abyss.c
34898--- linux-2.6.32.43/drivers/net/tokenring/abyss.c 2011-03-27 14:31:47.000000000 -0400
34899+++ linux-2.6.32.43/drivers/net/tokenring/abyss.c 2011-08-05 20:33:55.000000000 -0400
34900@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver =
34901
34902 static int __init abyss_init (void)
34903 {
34904- abyss_netdev_ops = tms380tr_netdev_ops;
34905+ pax_open_kernel();
34906+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34907
34908- abyss_netdev_ops.ndo_open = abyss_open;
34909- abyss_netdev_ops.ndo_stop = abyss_close;
34910+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34911+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34912+ pax_close_kernel();
34913
34914 return pci_register_driver(&abyss_driver);
34915 }
34916diff -urNp linux-2.6.32.43/drivers/net/tokenring/madgemc.c linux-2.6.32.43/drivers/net/tokenring/madgemc.c
34917--- linux-2.6.32.43/drivers/net/tokenring/madgemc.c 2011-03-27 14:31:47.000000000 -0400
34918+++ linux-2.6.32.43/drivers/net/tokenring/madgemc.c 2011-08-05 20:33:55.000000000 -0400
34919@@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver
34920
34921 static int __init madgemc_init (void)
34922 {
34923- madgemc_netdev_ops = tms380tr_netdev_ops;
34924- madgemc_netdev_ops.ndo_open = madgemc_open;
34925- madgemc_netdev_ops.ndo_stop = madgemc_close;
34926+ pax_open_kernel();
34927+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34928+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34929+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34930+ pax_close_kernel();
34931
34932 return mca_register_driver (&madgemc_driver);
34933 }
34934diff -urNp linux-2.6.32.43/drivers/net/tokenring/proteon.c linux-2.6.32.43/drivers/net/tokenring/proteon.c
34935--- linux-2.6.32.43/drivers/net/tokenring/proteon.c 2011-03-27 14:31:47.000000000 -0400
34936+++ linux-2.6.32.43/drivers/net/tokenring/proteon.c 2011-08-05 20:33:55.000000000 -0400
34937@@ -353,9 +353,11 @@ static int __init proteon_init(void)
34938 struct platform_device *pdev;
34939 int i, num = 0, err = 0;
34940
34941- proteon_netdev_ops = tms380tr_netdev_ops;
34942- proteon_netdev_ops.ndo_open = proteon_open;
34943- proteon_netdev_ops.ndo_stop = tms380tr_close;
34944+ pax_open_kernel();
34945+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34946+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34947+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34948+ pax_close_kernel();
34949
34950 err = platform_driver_register(&proteon_driver);
34951 if (err)
34952diff -urNp linux-2.6.32.43/drivers/net/tokenring/skisa.c linux-2.6.32.43/drivers/net/tokenring/skisa.c
34953--- linux-2.6.32.43/drivers/net/tokenring/skisa.c 2011-03-27 14:31:47.000000000 -0400
34954+++ linux-2.6.32.43/drivers/net/tokenring/skisa.c 2011-08-05 20:33:55.000000000 -0400
34955@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34956 struct platform_device *pdev;
34957 int i, num = 0, err = 0;
34958
34959- sk_isa_netdev_ops = tms380tr_netdev_ops;
34960- sk_isa_netdev_ops.ndo_open = sk_isa_open;
34961- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34962+ pax_open_kernel();
34963+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34964+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34965+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34966+ pax_close_kernel();
34967
34968 err = platform_driver_register(&sk_isa_driver);
34969 if (err)
34970diff -urNp linux-2.6.32.43/drivers/net/tulip/de2104x.c linux-2.6.32.43/drivers/net/tulip/de2104x.c
34971--- linux-2.6.32.43/drivers/net/tulip/de2104x.c 2011-03-27 14:31:47.000000000 -0400
34972+++ linux-2.6.32.43/drivers/net/tulip/de2104x.c 2011-05-16 21:46:57.000000000 -0400
34973@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_i
34974 struct de_srom_info_leaf *il;
34975 void *bufp;
34976
34977+ pax_track_stack();
34978+
34979 /* download entire eeprom */
34980 for (i = 0; i < DE_EEPROM_WORDS; i++)
34981 ((__le16 *)ee_data)[i] =
34982diff -urNp linux-2.6.32.43/drivers/net/tulip/de4x5.c linux-2.6.32.43/drivers/net/tulip/de4x5.c
34983--- linux-2.6.32.43/drivers/net/tulip/de4x5.c 2011-03-27 14:31:47.000000000 -0400
34984+++ linux-2.6.32.43/drivers/net/tulip/de4x5.c 2011-04-17 15:56:46.000000000 -0400
34985@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, stru
34986 for (i=0; i<ETH_ALEN; i++) {
34987 tmp.addr[i] = dev->dev_addr[i];
34988 }
34989- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34990+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34991 break;
34992
34993 case DE4X5_SET_HWADDR: /* Set the hardware address */
34994@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, stru
34995 spin_lock_irqsave(&lp->lock, flags);
34996 memcpy(&statbuf, &lp->pktStats, ioc->len);
34997 spin_unlock_irqrestore(&lp->lock, flags);
34998- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34999+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35000 return -EFAULT;
35001 break;
35002 }
35003diff -urNp linux-2.6.32.43/drivers/net/usb/hso.c linux-2.6.32.43/drivers/net/usb/hso.c
35004--- linux-2.6.32.43/drivers/net/usb/hso.c 2011-03-27 14:31:47.000000000 -0400
35005+++ linux-2.6.32.43/drivers/net/usb/hso.c 2011-04-17 15:56:46.000000000 -0400
35006@@ -71,7 +71,7 @@
35007 #include <asm/byteorder.h>
35008 #include <linux/serial_core.h>
35009 #include <linux/serial.h>
35010-
35011+#include <asm/local.h>
35012
35013 #define DRIVER_VERSION "1.2"
35014 #define MOD_AUTHOR "Option Wireless"
35015@@ -258,7 +258,7 @@ struct hso_serial {
35016
35017 /* from usb_serial_port */
35018 struct tty_struct *tty;
35019- int open_count;
35020+ local_t open_count;
35021 spinlock_t serial_lock;
35022
35023 int (*write_data) (struct hso_serial *serial);
35024@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_
35025 struct urb *urb;
35026
35027 urb = serial->rx_urb[0];
35028- if (serial->open_count > 0) {
35029+ if (local_read(&serial->open_count) > 0) {
35030 count = put_rxbuf_data(urb, serial);
35031 if (count == -1)
35032 return;
35033@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_cal
35034 DUMP1(urb->transfer_buffer, urb->actual_length);
35035
35036 /* Anyone listening? */
35037- if (serial->open_count == 0)
35038+ if (local_read(&serial->open_count) == 0)
35039 return;
35040
35041 if (status == 0) {
35042@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35043 spin_unlock_irq(&serial->serial_lock);
35044
35045 /* check for port already opened, if not set the termios */
35046- serial->open_count++;
35047- if (serial->open_count == 1) {
35048+ if (local_inc_return(&serial->open_count) == 1) {
35049 tty->low_latency = 1;
35050 serial->rx_state = RX_IDLE;
35051 /* Force default termio settings */
35052@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_st
35053 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35054 if (result) {
35055 hso_stop_serial_device(serial->parent);
35056- serial->open_count--;
35057+ local_dec(&serial->open_count);
35058 kref_put(&serial->parent->ref, hso_serial_ref_free);
35059 }
35060 } else {
35061@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_
35062
35063 /* reset the rts and dtr */
35064 /* do the actual close */
35065- serial->open_count--;
35066+ local_dec(&serial->open_count);
35067
35068- if (serial->open_count <= 0) {
35069- serial->open_count = 0;
35070+ if (local_read(&serial->open_count) <= 0) {
35071+ local_set(&serial->open_count, 0);
35072 spin_lock_irq(&serial->serial_lock);
35073 if (serial->tty == tty) {
35074 serial->tty->driver_data = NULL;
35075@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struc
35076
35077 /* the actual setup */
35078 spin_lock_irqsave(&serial->serial_lock, flags);
35079- if (serial->open_count)
35080+ if (local_read(&serial->open_count))
35081 _hso_serial_set_termios(tty, old);
35082 else
35083 tty->termios = old;
35084@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35085 /* Start all serial ports */
35086 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35087 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35088- if (dev2ser(serial_table[i])->open_count) {
35089+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35090 result =
35091 hso_start_serial_device(serial_table[i], GFP_NOIO);
35092 hso_kick_transmit(dev2ser(serial_table[i]));
35093diff -urNp linux-2.6.32.43/drivers/net/vxge/vxge-config.h linux-2.6.32.43/drivers/net/vxge/vxge-config.h
35094--- linux-2.6.32.43/drivers/net/vxge/vxge-config.h 2011-03-27 14:31:47.000000000 -0400
35095+++ linux-2.6.32.43/drivers/net/vxge/vxge-config.h 2011-08-05 20:33:55.000000000 -0400
35096@@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
35097 void (*link_down)(struct __vxge_hw_device *devh);
35098 void (*crit_err)(struct __vxge_hw_device *devh,
35099 enum vxge_hw_event type, u64 ext_data);
35100-};
35101+} __no_const;
35102
35103 /*
35104 * struct __vxge_hw_blockpool_entry - Block private data structure
35105diff -urNp linux-2.6.32.43/drivers/net/vxge/vxge-main.c linux-2.6.32.43/drivers/net/vxge/vxge-main.c
35106--- linux-2.6.32.43/drivers/net/vxge/vxge-main.c 2011-03-27 14:31:47.000000000 -0400
35107+++ linux-2.6.32.43/drivers/net/vxge/vxge-main.c 2011-05-16 21:46:57.000000000 -0400
35108@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35109 struct sk_buff *completed[NR_SKB_COMPLETED];
35110 int more;
35111
35112+ pax_track_stack();
35113+
35114 do {
35115 more = 0;
35116 skb_ptr = completed;
35117@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_conf
35118 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35119 int index;
35120
35121+ pax_track_stack();
35122+
35123 /*
35124 * Filling
35125 * - itable with bucket numbers
35126diff -urNp linux-2.6.32.43/drivers/net/vxge/vxge-traffic.h linux-2.6.32.43/drivers/net/vxge/vxge-traffic.h
35127--- linux-2.6.32.43/drivers/net/vxge/vxge-traffic.h 2011-03-27 14:31:47.000000000 -0400
35128+++ linux-2.6.32.43/drivers/net/vxge/vxge-traffic.h 2011-08-05 20:33:55.000000000 -0400
35129@@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
35130 struct vxge_hw_mempool_dma *dma_object,
35131 u32 index,
35132 u32 is_last);
35133-};
35134+} __no_const;
35135
35136 void
35137 __vxge_hw_mempool_destroy(
35138diff -urNp linux-2.6.32.43/drivers/net/wan/cycx_x25.c linux-2.6.32.43/drivers/net/wan/cycx_x25.c
35139--- linux-2.6.32.43/drivers/net/wan/cycx_x25.c 2011-03-27 14:31:47.000000000 -0400
35140+++ linux-2.6.32.43/drivers/net/wan/cycx_x25.c 2011-05-16 21:46:57.000000000 -0400
35141@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned
35142 unsigned char hex[1024],
35143 * phex = hex;
35144
35145+ pax_track_stack();
35146+
35147 if (len >= (sizeof(hex) / 2))
35148 len = (sizeof(hex) / 2) - 1;
35149
35150diff -urNp linux-2.6.32.43/drivers/net/wan/hdlc_x25.c linux-2.6.32.43/drivers/net/wan/hdlc_x25.c
35151--- linux-2.6.32.43/drivers/net/wan/hdlc_x25.c 2011-03-27 14:31:47.000000000 -0400
35152+++ linux-2.6.32.43/drivers/net/wan/hdlc_x25.c 2011-08-05 20:33:55.000000000 -0400
35153@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_bu
35154
35155 static int x25_open(struct net_device *dev)
35156 {
35157- struct lapb_register_struct cb;
35158+ static struct lapb_register_struct cb = {
35159+ .connect_confirmation = x25_connected,
35160+ .connect_indication = x25_connected,
35161+ .disconnect_confirmation = x25_disconnected,
35162+ .disconnect_indication = x25_disconnected,
35163+ .data_indication = x25_data_indication,
35164+ .data_transmit = x25_data_transmit
35165+ };
35166 int result;
35167
35168- cb.connect_confirmation = x25_connected;
35169- cb.connect_indication = x25_connected;
35170- cb.disconnect_confirmation = x25_disconnected;
35171- cb.disconnect_indication = x25_disconnected;
35172- cb.data_indication = x25_data_indication;
35173- cb.data_transmit = x25_data_transmit;
35174-
35175 result = lapb_register(dev, &cb);
35176 if (result != LAPB_OK)
35177 return result;
35178diff -urNp linux-2.6.32.43/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.32.43/drivers/net/wimax/i2400m/usb-fw.c
35179--- linux-2.6.32.43/drivers/net/wimax/i2400m/usb-fw.c 2011-03-27 14:31:47.000000000 -0400
35180+++ linux-2.6.32.43/drivers/net/wimax/i2400m/usb-fw.c 2011-05-16 21:46:57.000000000 -0400
35181@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35182 int do_autopm = 1;
35183 DECLARE_COMPLETION_ONSTACK(notif_completion);
35184
35185+ pax_track_stack();
35186+
35187 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35188 i2400m, ack, ack_size);
35189 BUG_ON(_ack == i2400m->bm_ack_buf);
35190diff -urNp linux-2.6.32.43/drivers/net/wireless/airo.c linux-2.6.32.43/drivers/net/wireless/airo.c
35191--- linux-2.6.32.43/drivers/net/wireless/airo.c 2011-03-27 14:31:47.000000000 -0400
35192+++ linux-2.6.32.43/drivers/net/wireless/airo.c 2011-05-16 21:46:57.000000000 -0400
35193@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (s
35194 BSSListElement * loop_net;
35195 BSSListElement * tmp_net;
35196
35197+ pax_track_stack();
35198+
35199 /* Blow away current list of scan results */
35200 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35201 list_move_tail (&loop_net->list, &ai->network_free_list);
35202@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *
35203 WepKeyRid wkr;
35204 int rc;
35205
35206+ pax_track_stack();
35207+
35208 memset( &mySsid, 0, sizeof( mySsid ) );
35209 kfree (ai->flash);
35210 ai->flash = NULL;
35211@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct i
35212 __le32 *vals = stats.vals;
35213 int len;
35214
35215+ pax_track_stack();
35216+
35217 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35218 return -ENOMEM;
35219 data = (struct proc_data *)file->private_data;
35220@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct ino
35221 /* If doLoseSync is not 1, we won't do a Lose Sync */
35222 int doLoseSync = -1;
35223
35224+ pax_track_stack();
35225+
35226 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35227 return -ENOMEM;
35228 data = (struct proc_data *)file->private_data;
35229@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_de
35230 int i;
35231 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35232
35233+ pax_track_stack();
35234+
35235 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35236 if (!qual)
35237 return -ENOMEM;
35238@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(str
35239 CapabilityRid cap_rid;
35240 __le32 *vals = stats_rid.vals;
35241
35242+ pax_track_stack();
35243+
35244 /* Get stats out of the card */
35245 clear_bit(JOB_WSTATS, &local->jobs);
35246 if (local->power.event) {
35247diff -urNp linux-2.6.32.43/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.32.43/drivers/net/wireless/ath/ath5k/debug.c
35248--- linux-2.6.32.43/drivers/net/wireless/ath/ath5k/debug.c 2011-03-27 14:31:47.000000000 -0400
35249+++ linux-2.6.32.43/drivers/net/wireless/ath/ath5k/debug.c 2011-05-16 21:46:57.000000000 -0400
35250@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct f
35251 unsigned int v;
35252 u64 tsf;
35253
35254+ pax_track_stack();
35255+
35256 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35257 len += snprintf(buf+len, sizeof(buf)-len,
35258 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35259@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct fi
35260 unsigned int len = 0;
35261 unsigned int i;
35262
35263+ pax_track_stack();
35264+
35265 len += snprintf(buf+len, sizeof(buf)-len,
35266 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35267
35268diff -urNp linux-2.6.32.43/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.32.43/drivers/net/wireless/ath/ath9k/debug.c
35269--- linux-2.6.32.43/drivers/net/wireless/ath/ath9k/debug.c 2011-03-27 14:31:47.000000000 -0400
35270+++ linux-2.6.32.43/drivers/net/wireless/ath/ath9k/debug.c 2011-05-16 21:46:57.000000000 -0400
35271@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struc
35272 char buf[512];
35273 unsigned int len = 0;
35274
35275+ pax_track_stack();
35276+
35277 len += snprintf(buf + len, sizeof(buf) - len,
35278 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
35279 len += snprintf(buf + len, sizeof(buf) - len,
35280@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct fi
35281 int i;
35282 u8 addr[ETH_ALEN];
35283
35284+ pax_track_stack();
35285+
35286 len += snprintf(buf + len, sizeof(buf) - len,
35287 "primary: %s (%s chan=%d ht=%d)\n",
35288 wiphy_name(sc->pri_wiphy->hw->wiphy),
35289diff -urNp linux-2.6.32.43/drivers/net/wireless/b43/debugfs.c linux-2.6.32.43/drivers/net/wireless/b43/debugfs.c
35290--- linux-2.6.32.43/drivers/net/wireless/b43/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35291+++ linux-2.6.32.43/drivers/net/wireless/b43/debugfs.c 2011-04-17 15:56:46.000000000 -0400
35292@@ -43,7 +43,7 @@ static struct dentry *rootdir;
35293 struct b43_debugfs_fops {
35294 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35295 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35296- struct file_operations fops;
35297+ const struct file_operations fops;
35298 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35299 size_t file_struct_offset;
35300 };
35301diff -urNp linux-2.6.32.43/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.32.43/drivers/net/wireless/b43legacy/debugfs.c
35302--- linux-2.6.32.43/drivers/net/wireless/b43legacy/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35303+++ linux-2.6.32.43/drivers/net/wireless/b43legacy/debugfs.c 2011-04-17 15:56:46.000000000 -0400
35304@@ -44,7 +44,7 @@ static struct dentry *rootdir;
35305 struct b43legacy_debugfs_fops {
35306 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35307 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35308- struct file_operations fops;
35309+ const struct file_operations fops;
35310 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35311 size_t file_struct_offset;
35312 /* Take wl->irq_lock before calling read/write? */
35313diff -urNp linux-2.6.32.43/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.32.43/drivers/net/wireless/ipw2x00/ipw2100.c
35314--- linux-2.6.32.43/drivers/net/wireless/ipw2x00/ipw2100.c 2011-03-27 14:31:47.000000000 -0400
35315+++ linux-2.6.32.43/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-16 21:46:57.000000000 -0400
35316@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2
35317 int err;
35318 DECLARE_SSID_BUF(ssid);
35319
35320+ pax_track_stack();
35321+
35322 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35323
35324 if (ssid_len)
35325@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw210
35326 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
35327 int err;
35328
35329+ pax_track_stack();
35330+
35331 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
35332 idx, keylen, len);
35333
35334diff -urNp linux-2.6.32.43/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.32.43/drivers/net/wireless/ipw2x00/libipw_rx.c
35335--- linux-2.6.32.43/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-03-27 14:31:47.000000000 -0400
35336+++ linux-2.6.32.43/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-16 21:46:57.000000000 -0400
35337@@ -1566,6 +1566,8 @@ static void libipw_process_probe_respons
35338 unsigned long flags;
35339 DECLARE_SSID_BUF(ssid);
35340
35341+ pax_track_stack();
35342+
35343 LIBIPW_DEBUG_SCAN("'%s' (%pM"
35344 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
35345 print_ssid(ssid, info_element->data, info_element->len),
35346diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-1000.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-1000.c
35347--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-03-27 14:31:47.000000000 -0400
35348+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-04-17 15:56:46.000000000 -0400
35349@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib =
35350 },
35351 };
35352
35353-static struct iwl_ops iwl1000_ops = {
35354+static const struct iwl_ops iwl1000_ops = {
35355 .ucode = &iwl5000_ucode,
35356 .lib = &iwl1000_lib,
35357 .hcmd = &iwl5000_hcmd,
35358diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl3945-base.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl3945-base.c
35359--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl3945-base.c 2011-03-27 14:31:47.000000000 -0400
35360+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl3945-base.c 2011-08-05 20:33:55.000000000 -0400
35361@@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_
35362 */
35363 if (iwl3945_mod_params.disable_hw_scan) {
35364 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
35365- iwl3945_hw_ops.hw_scan = NULL;
35366+ pax_open_kernel();
35367+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
35368+ pax_close_kernel();
35369 }
35370
35371
35372diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-3945.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-3945.c
35373--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-03-27 14:31:47.000000000 -0400
35374+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-04-17 15:56:46.000000000 -0400
35375@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945
35376 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
35377 };
35378
35379-static struct iwl_ops iwl3945_ops = {
35380+static const struct iwl_ops iwl3945_ops = {
35381 .ucode = &iwl3945_ucode,
35382 .lib = &iwl3945_lib,
35383 .hcmd = &iwl3945_hcmd,
35384diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-4965.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-4965.c
35385--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-03-27 14:31:47.000000000 -0400
35386+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-04-17 15:56:46.000000000 -0400
35387@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib =
35388 },
35389 };
35390
35391-static struct iwl_ops iwl4965_ops = {
35392+static const struct iwl_ops iwl4965_ops = {
35393 .ucode = &iwl4965_ucode,
35394 .lib = &iwl4965_lib,
35395 .hcmd = &iwl4965_hcmd,
35396diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-5000.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-5000.c
35397--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-06-25 12:55:34.000000000 -0400
35398+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-06-25 12:56:37.000000000 -0400
35399@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib =
35400 },
35401 };
35402
35403-struct iwl_ops iwl5000_ops = {
35404+const struct iwl_ops iwl5000_ops = {
35405 .ucode = &iwl5000_ucode,
35406 .lib = &iwl5000_lib,
35407 .hcmd = &iwl5000_hcmd,
35408 .utils = &iwl5000_hcmd_utils,
35409 };
35410
35411-static struct iwl_ops iwl5150_ops = {
35412+static const struct iwl_ops iwl5150_ops = {
35413 .ucode = &iwl5000_ucode,
35414 .lib = &iwl5150_lib,
35415 .hcmd = &iwl5000_hcmd,
35416diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-6000.c
35417--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-03-27 14:31:47.000000000 -0400
35418+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-04-17 15:56:46.000000000 -0400
35419@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000
35420 .calc_rssi = iwl5000_calc_rssi,
35421 };
35422
35423-static struct iwl_ops iwl6000_ops = {
35424+static const struct iwl_ops iwl6000_ops = {
35425 .ucode = &iwl5000_ucode,
35426 .lib = &iwl6000_lib,
35427 .hcmd = &iwl5000_hcmd,
35428diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn.c
35429--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn.c 2011-03-27 14:31:47.000000000 -0400
35430+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn.c 2011-08-05 20:33:55.000000000 -0400
35431@@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev
35432 if (iwl_debug_level & IWL_DL_INFO)
35433 dev_printk(KERN_DEBUG, &(pdev->dev),
35434 "Disabling hw_scan\n");
35435- iwl_hw_ops.hw_scan = NULL;
35436+ pax_open_kernel();
35437+ *(void **)&iwl_hw_ops.hw_scan = NULL;
35438+ pax_close_kernel();
35439 }
35440
35441 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
35442diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
35443--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-03-27 14:31:47.000000000 -0400
35444+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-16 21:46:57.000000000 -0400
35445@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, s
35446 u8 active_index = 0;
35447 s32 tpt = 0;
35448
35449+ pax_track_stack();
35450+
35451 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
35452
35453 if (!ieee80211_is_data(hdr->frame_control) ||
35454@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_
35455 u8 valid_tx_ant = 0;
35456 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
35457
35458+ pax_track_stack();
35459+
35460 /* Override starting rate (index 0) if needed for debug purposes */
35461 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
35462
35463diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35464--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-03-27 14:31:47.000000000 -0400
35465+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-16 21:46:57.000000000 -0400
35466@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(str
35467 int pos = 0;
35468 const size_t bufsz = sizeof(buf);
35469
35470+ pax_track_stack();
35471+
35472 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
35473 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
35474 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
35475@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
35476 const size_t bufsz = sizeof(buf);
35477 ssize_t ret;
35478
35479+ pax_track_stack();
35480+
35481 for (i = 0; i < AC_NUM; i++) {
35482 pos += scnprintf(buf + pos, bufsz - pos,
35483 "\tcw_min\tcw_max\taifsn\ttxop\n");
35484diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debug.h
35485--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-03-27 14:31:47.000000000 -0400
35486+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-04-17 15:56:46.000000000 -0400
35487@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_pri
35488 #endif
35489
35490 #else
35491-#define IWL_DEBUG(__priv, level, fmt, args...)
35492-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
35493+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
35494+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
35495 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
35496 void *p, u32 len)
35497 {}
35498diff -urNp linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-dev.h linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-dev.h
35499--- linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-03-27 14:31:47.000000000 -0400
35500+++ linux-2.6.32.43/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-04-17 15:56:46.000000000 -0400
35501@@ -68,7 +68,7 @@ struct iwl_tx_queue;
35502
35503 /* shared structures from iwl-5000.c */
35504 extern struct iwl_mod_params iwl50_mod_params;
35505-extern struct iwl_ops iwl5000_ops;
35506+extern const struct iwl_ops iwl5000_ops;
35507 extern struct iwl_ucode_ops iwl5000_ucode;
35508 extern struct iwl_lib_ops iwl5000_lib;
35509 extern struct iwl_hcmd_ops iwl5000_hcmd;
35510diff -urNp linux-2.6.32.43/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.32.43/drivers/net/wireless/iwmc3200wifi/debugfs.c
35511--- linux-2.6.32.43/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35512+++ linux-2.6.32.43/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-16 21:46:57.000000000 -0400
35513@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
35514 int buf_len = 512;
35515 size_t len = 0;
35516
35517+ pax_track_stack();
35518+
35519 if (*ppos != 0)
35520 return 0;
35521 if (count < sizeof(buf))
35522diff -urNp linux-2.6.32.43/drivers/net/wireless/libertas/debugfs.c linux-2.6.32.43/drivers/net/wireless/libertas/debugfs.c
35523--- linux-2.6.32.43/drivers/net/wireless/libertas/debugfs.c 2011-03-27 14:31:47.000000000 -0400
35524+++ linux-2.6.32.43/drivers/net/wireless/libertas/debugfs.c 2011-04-17 15:56:46.000000000 -0400
35525@@ -708,7 +708,7 @@ out_unlock:
35526 struct lbs_debugfs_files {
35527 const char *name;
35528 int perm;
35529- struct file_operations fops;
35530+ const struct file_operations fops;
35531 };
35532
35533 static const struct lbs_debugfs_files debugfs_files[] = {
35534diff -urNp linux-2.6.32.43/drivers/net/wireless/rndis_wlan.c linux-2.6.32.43/drivers/net/wireless/rndis_wlan.c
35535--- linux-2.6.32.43/drivers/net/wireless/rndis_wlan.c 2011-03-27 14:31:47.000000000 -0400
35536+++ linux-2.6.32.43/drivers/net/wireless/rndis_wlan.c 2011-04-17 15:56:46.000000000 -0400
35537@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbn
35538
35539 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
35540
35541- if (rts_threshold < 0 || rts_threshold > 2347)
35542+ if (rts_threshold > 2347)
35543 rts_threshold = 2347;
35544
35545 tmp = cpu_to_le32(rts_threshold);
35546diff -urNp linux-2.6.32.43/drivers/oprofile/buffer_sync.c linux-2.6.32.43/drivers/oprofile/buffer_sync.c
35547--- linux-2.6.32.43/drivers/oprofile/buffer_sync.c 2011-03-27 14:31:47.000000000 -0400
35548+++ linux-2.6.32.43/drivers/oprofile/buffer_sync.c 2011-04-17 15:56:46.000000000 -0400
35549@@ -341,7 +341,7 @@ static void add_data(struct op_entry *en
35550 if (cookie == NO_COOKIE)
35551 offset = pc;
35552 if (cookie == INVALID_COOKIE) {
35553- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35554+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35555 offset = pc;
35556 }
35557 if (cookie != last_cookie) {
35558@@ -385,14 +385,14 @@ add_sample(struct mm_struct *mm, struct
35559 /* add userspace sample */
35560
35561 if (!mm) {
35562- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35563+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35564 return 0;
35565 }
35566
35567 cookie = lookup_dcookie(mm, s->eip, &offset);
35568
35569 if (cookie == INVALID_COOKIE) {
35570- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35571+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35572 return 0;
35573 }
35574
35575@@ -561,7 +561,7 @@ void sync_buffer(int cpu)
35576 /* ignore backtraces if failed to add a sample */
35577 if (state == sb_bt_start) {
35578 state = sb_bt_ignore;
35579- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35580+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35581 }
35582 }
35583 release_mm(mm);
35584diff -urNp linux-2.6.32.43/drivers/oprofile/event_buffer.c linux-2.6.32.43/drivers/oprofile/event_buffer.c
35585--- linux-2.6.32.43/drivers/oprofile/event_buffer.c 2011-03-27 14:31:47.000000000 -0400
35586+++ linux-2.6.32.43/drivers/oprofile/event_buffer.c 2011-04-17 15:56:46.000000000 -0400
35587@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
35588 }
35589
35590 if (buffer_pos == buffer_size) {
35591- atomic_inc(&oprofile_stats.event_lost_overflow);
35592+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35593 return;
35594 }
35595
35596diff -urNp linux-2.6.32.43/drivers/oprofile/oprof.c linux-2.6.32.43/drivers/oprofile/oprof.c
35597--- linux-2.6.32.43/drivers/oprofile/oprof.c 2011-03-27 14:31:47.000000000 -0400
35598+++ linux-2.6.32.43/drivers/oprofile/oprof.c 2011-04-17 15:56:46.000000000 -0400
35599@@ -110,7 +110,7 @@ static void switch_worker(struct work_st
35600 if (oprofile_ops.switch_events())
35601 return;
35602
35603- atomic_inc(&oprofile_stats.multiplex_counter);
35604+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35605 start_switch_worker();
35606 }
35607
35608diff -urNp linux-2.6.32.43/drivers/oprofile/oprofilefs.c linux-2.6.32.43/drivers/oprofile/oprofilefs.c
35609--- linux-2.6.32.43/drivers/oprofile/oprofilefs.c 2011-03-27 14:31:47.000000000 -0400
35610+++ linux-2.6.32.43/drivers/oprofile/oprofilefs.c 2011-04-17 15:56:46.000000000 -0400
35611@@ -187,7 +187,7 @@ static const struct file_operations atom
35612
35613
35614 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35615- char const *name, atomic_t *val)
35616+ char const *name, atomic_unchecked_t *val)
35617 {
35618 struct dentry *d = __oprofilefs_create_file(sb, root, name,
35619 &atomic_ro_fops, 0444);
35620diff -urNp linux-2.6.32.43/drivers/oprofile/oprofile_stats.c linux-2.6.32.43/drivers/oprofile/oprofile_stats.c
35621--- linux-2.6.32.43/drivers/oprofile/oprofile_stats.c 2011-03-27 14:31:47.000000000 -0400
35622+++ linux-2.6.32.43/drivers/oprofile/oprofile_stats.c 2011-04-17 15:56:46.000000000 -0400
35623@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35624 cpu_buf->sample_invalid_eip = 0;
35625 }
35626
35627- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35628- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35629- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35630- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35631- atomic_set(&oprofile_stats.multiplex_counter, 0);
35632+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35633+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35634+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35635+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35636+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35637 }
35638
35639
35640diff -urNp linux-2.6.32.43/drivers/oprofile/oprofile_stats.h linux-2.6.32.43/drivers/oprofile/oprofile_stats.h
35641--- linux-2.6.32.43/drivers/oprofile/oprofile_stats.h 2011-03-27 14:31:47.000000000 -0400
35642+++ linux-2.6.32.43/drivers/oprofile/oprofile_stats.h 2011-04-17 15:56:46.000000000 -0400
35643@@ -13,11 +13,11 @@
35644 #include <asm/atomic.h>
35645
35646 struct oprofile_stat_struct {
35647- atomic_t sample_lost_no_mm;
35648- atomic_t sample_lost_no_mapping;
35649- atomic_t bt_lost_no_mapping;
35650- atomic_t event_lost_overflow;
35651- atomic_t multiplex_counter;
35652+ atomic_unchecked_t sample_lost_no_mm;
35653+ atomic_unchecked_t sample_lost_no_mapping;
35654+ atomic_unchecked_t bt_lost_no_mapping;
35655+ atomic_unchecked_t event_lost_overflow;
35656+ atomic_unchecked_t multiplex_counter;
35657 };
35658
35659 extern struct oprofile_stat_struct oprofile_stats;
35660diff -urNp linux-2.6.32.43/drivers/parisc/pdc_stable.c linux-2.6.32.43/drivers/parisc/pdc_stable.c
35661--- linux-2.6.32.43/drivers/parisc/pdc_stable.c 2011-03-27 14:31:47.000000000 -0400
35662+++ linux-2.6.32.43/drivers/parisc/pdc_stable.c 2011-04-17 15:56:46.000000000 -0400
35663@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj
35664 return ret;
35665 }
35666
35667-static struct sysfs_ops pdcspath_attr_ops = {
35668+static const struct sysfs_ops pdcspath_attr_ops = {
35669 .show = pdcspath_attr_show,
35670 .store = pdcspath_attr_store,
35671 };
35672diff -urNp linux-2.6.32.43/drivers/parport/procfs.c linux-2.6.32.43/drivers/parport/procfs.c
35673--- linux-2.6.32.43/drivers/parport/procfs.c 2011-03-27 14:31:47.000000000 -0400
35674+++ linux-2.6.32.43/drivers/parport/procfs.c 2011-04-17 15:56:46.000000000 -0400
35675@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
35676
35677 *ppos += len;
35678
35679- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35680+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35681 }
35682
35683 #ifdef CONFIG_PARPORT_1284
35684@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
35685
35686 *ppos += len;
35687
35688- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35689+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35690 }
35691 #endif /* IEEE1284.3 support. */
35692
35693diff -urNp linux-2.6.32.43/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.32.43/drivers/pci/hotplug/acpiphp_glue.c
35694--- linux-2.6.32.43/drivers/pci/hotplug/acpiphp_glue.c 2011-03-27 14:31:47.000000000 -0400
35695+++ linux-2.6.32.43/drivers/pci/hotplug/acpiphp_glue.c 2011-04-17 15:56:46.000000000 -0400
35696@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notif
35697 }
35698
35699
35700-static struct acpi_dock_ops acpiphp_dock_ops = {
35701+static const struct acpi_dock_ops acpiphp_dock_ops = {
35702 .handler = handle_hotplug_event_func,
35703 };
35704
35705diff -urNp linux-2.6.32.43/drivers/pci/hotplug/cpci_hotplug.h linux-2.6.32.43/drivers/pci/hotplug/cpci_hotplug.h
35706--- linux-2.6.32.43/drivers/pci/hotplug/cpci_hotplug.h 2011-03-27 14:31:47.000000000 -0400
35707+++ linux-2.6.32.43/drivers/pci/hotplug/cpci_hotplug.h 2011-08-05 20:33:55.000000000 -0400
35708@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35709 int (*hardware_test) (struct slot* slot, u32 value);
35710 u8 (*get_power) (struct slot* slot);
35711 int (*set_power) (struct slot* slot, int value);
35712-};
35713+} __no_const;
35714
35715 struct cpci_hp_controller {
35716 unsigned int irq;
35717diff -urNp linux-2.6.32.43/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.32.43/drivers/pci/hotplug/cpqphp_nvram.c
35718--- linux-2.6.32.43/drivers/pci/hotplug/cpqphp_nvram.c 2011-03-27 14:31:47.000000000 -0400
35719+++ linux-2.6.32.43/drivers/pci/hotplug/cpqphp_nvram.c 2011-04-17 15:56:46.000000000 -0400
35720@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
35721
35722 void compaq_nvram_init (void __iomem *rom_start)
35723 {
35724+
35725+#ifndef CONFIG_PAX_KERNEXEC
35726 if (rom_start) {
35727 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35728 }
35729+#endif
35730+
35731 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35732
35733 /* initialize our int15 lock */
35734diff -urNp linux-2.6.32.43/drivers/pci/hotplug/fakephp.c linux-2.6.32.43/drivers/pci/hotplug/fakephp.c
35735--- linux-2.6.32.43/drivers/pci/hotplug/fakephp.c 2011-03-27 14:31:47.000000000 -0400
35736+++ linux-2.6.32.43/drivers/pci/hotplug/fakephp.c 2011-04-17 15:56:46.000000000 -0400
35737@@ -73,7 +73,7 @@ static void legacy_release(struct kobjec
35738 }
35739
35740 static struct kobj_type legacy_ktype = {
35741- .sysfs_ops = &(struct sysfs_ops){
35742+ .sysfs_ops = &(const struct sysfs_ops){
35743 .store = legacy_store, .show = legacy_show
35744 },
35745 .release = &legacy_release,
35746diff -urNp linux-2.6.32.43/drivers/pci/intel-iommu.c linux-2.6.32.43/drivers/pci/intel-iommu.c
35747--- linux-2.6.32.43/drivers/pci/intel-iommu.c 2011-05-10 22:12:01.000000000 -0400
35748+++ linux-2.6.32.43/drivers/pci/intel-iommu.c 2011-05-10 22:12:33.000000000 -0400
35749@@ -2643,7 +2643,7 @@ error:
35750 return 0;
35751 }
35752
35753-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
35754+dma_addr_t intel_map_page(struct device *dev, struct page *page,
35755 unsigned long offset, size_t size,
35756 enum dma_data_direction dir,
35757 struct dma_attrs *attrs)
35758@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain
35759 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
35760 }
35761
35762-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
35763+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
35764 size_t size, enum dma_data_direction dir,
35765 struct dma_attrs *attrs)
35766 {
35767@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct devi
35768 }
35769 }
35770
35771-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
35772+void *intel_alloc_coherent(struct device *hwdev, size_t size,
35773 dma_addr_t *dma_handle, gfp_t flags)
35774 {
35775 void *vaddr;
35776@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct
35777 return NULL;
35778 }
35779
35780-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
35781+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
35782 dma_addr_t dma_handle)
35783 {
35784 int order;
35785@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct d
35786 free_pages((unsigned long)vaddr, order);
35787 }
35788
35789-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
35790+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
35791 int nelems, enum dma_data_direction dir,
35792 struct dma_attrs *attrs)
35793 {
35794@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(str
35795 return nelems;
35796 }
35797
35798-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
35799+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
35800 enum dma_data_direction dir, struct dma_attrs *attrs)
35801 {
35802 int i;
35803@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *h
35804 return nelems;
35805 }
35806
35807-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
35808+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
35809 {
35810 return !dma_addr;
35811 }
35812
35813-struct dma_map_ops intel_dma_ops = {
35814+const struct dma_map_ops intel_dma_ops = {
35815 .alloc_coherent = intel_alloc_coherent,
35816 .free_coherent = intel_free_coherent,
35817 .map_sg = intel_map_sg,
35818diff -urNp linux-2.6.32.43/drivers/pci/pcie/aspm.c linux-2.6.32.43/drivers/pci/pcie/aspm.c
35819--- linux-2.6.32.43/drivers/pci/pcie/aspm.c 2011-03-27 14:31:47.000000000 -0400
35820+++ linux-2.6.32.43/drivers/pci/pcie/aspm.c 2011-04-17 15:56:46.000000000 -0400
35821@@ -27,9 +27,9 @@
35822 #define MODULE_PARAM_PREFIX "pcie_aspm."
35823
35824 /* Note: those are not register definitions */
35825-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35826-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35827-#define ASPM_STATE_L1 (4) /* L1 state */
35828+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35829+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35830+#define ASPM_STATE_L1 (4U) /* L1 state */
35831 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35832 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35833
35834diff -urNp linux-2.6.32.43/drivers/pci/probe.c linux-2.6.32.43/drivers/pci/probe.c
35835--- linux-2.6.32.43/drivers/pci/probe.c 2011-03-27 14:31:47.000000000 -0400
35836+++ linux-2.6.32.43/drivers/pci/probe.c 2011-04-17 15:56:46.000000000 -0400
35837@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
35838 return ret;
35839 }
35840
35841-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
35842+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
35843 struct device_attribute *attr,
35844 char *buf)
35845 {
35846 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
35847 }
35848
35849-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
35850+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
35851 struct device_attribute *attr,
35852 char *buf)
35853 {
35854diff -urNp linux-2.6.32.43/drivers/pci/proc.c linux-2.6.32.43/drivers/pci/proc.c
35855--- linux-2.6.32.43/drivers/pci/proc.c 2011-03-27 14:31:47.000000000 -0400
35856+++ linux-2.6.32.43/drivers/pci/proc.c 2011-04-17 15:56:46.000000000 -0400
35857@@ -480,7 +480,16 @@ static const struct file_operations proc
35858 static int __init pci_proc_init(void)
35859 {
35860 struct pci_dev *dev = NULL;
35861+
35862+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35863+#ifdef CONFIG_GRKERNSEC_PROC_USER
35864+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35865+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35866+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35867+#endif
35868+#else
35869 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35870+#endif
35871 proc_create("devices", 0, proc_bus_pci_dir,
35872 &proc_bus_pci_dev_operations);
35873 proc_initialized = 1;
35874diff -urNp linux-2.6.32.43/drivers/pci/slot.c linux-2.6.32.43/drivers/pci/slot.c
35875--- linux-2.6.32.43/drivers/pci/slot.c 2011-03-27 14:31:47.000000000 -0400
35876+++ linux-2.6.32.43/drivers/pci/slot.c 2011-04-17 15:56:46.000000000 -0400
35877@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struc
35878 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
35879 }
35880
35881-static struct sysfs_ops pci_slot_sysfs_ops = {
35882+static const struct sysfs_ops pci_slot_sysfs_ops = {
35883 .show = pci_slot_attr_show,
35884 .store = pci_slot_attr_store,
35885 };
35886diff -urNp linux-2.6.32.43/drivers/pcmcia/pcmcia_ioctl.c linux-2.6.32.43/drivers/pcmcia/pcmcia_ioctl.c
35887--- linux-2.6.32.43/drivers/pcmcia/pcmcia_ioctl.c 2011-03-27 14:31:47.000000000 -0400
35888+++ linux-2.6.32.43/drivers/pcmcia/pcmcia_ioctl.c 2011-04-17 15:56:46.000000000 -0400
35889@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode
35890 return -EFAULT;
35891 }
35892 }
35893- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
35894+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
35895 if (!buf)
35896 return -ENOMEM;
35897
35898diff -urNp linux-2.6.32.43/drivers/platform/x86/acer-wmi.c linux-2.6.32.43/drivers/platform/x86/acer-wmi.c
35899--- linux-2.6.32.43/drivers/platform/x86/acer-wmi.c 2011-03-27 14:31:47.000000000 -0400
35900+++ linux-2.6.32.43/drivers/platform/x86/acer-wmi.c 2011-04-17 15:56:46.000000000 -0400
35901@@ -918,7 +918,7 @@ static int update_bl_status(struct backl
35902 return 0;
35903 }
35904
35905-static struct backlight_ops acer_bl_ops = {
35906+static const struct backlight_ops acer_bl_ops = {
35907 .get_brightness = read_brightness,
35908 .update_status = update_bl_status,
35909 };
35910diff -urNp linux-2.6.32.43/drivers/platform/x86/asus_acpi.c linux-2.6.32.43/drivers/platform/x86/asus_acpi.c
35911--- linux-2.6.32.43/drivers/platform/x86/asus_acpi.c 2011-03-27 14:31:47.000000000 -0400
35912+++ linux-2.6.32.43/drivers/platform/x86/asus_acpi.c 2011-04-17 15:56:46.000000000 -0400
35913@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_
35914 return 0;
35915 }
35916
35917-static struct backlight_ops asus_backlight_data = {
35918+static const struct backlight_ops asus_backlight_data = {
35919 .get_brightness = read_brightness,
35920 .update_status = set_brightness_status,
35921 };
35922diff -urNp linux-2.6.32.43/drivers/platform/x86/asus-laptop.c linux-2.6.32.43/drivers/platform/x86/asus-laptop.c
35923--- linux-2.6.32.43/drivers/platform/x86/asus-laptop.c 2011-03-27 14:31:47.000000000 -0400
35924+++ linux-2.6.32.43/drivers/platform/x86/asus-laptop.c 2011-04-17 15:56:46.000000000 -0400
35925@@ -250,7 +250,7 @@ static struct backlight_device *asus_bac
35926 */
35927 static int read_brightness(struct backlight_device *bd);
35928 static int update_bl_status(struct backlight_device *bd);
35929-static struct backlight_ops asusbl_ops = {
35930+static const struct backlight_ops asusbl_ops = {
35931 .get_brightness = read_brightness,
35932 .update_status = update_bl_status,
35933 };
35934diff -urNp linux-2.6.32.43/drivers/platform/x86/compal-laptop.c linux-2.6.32.43/drivers/platform/x86/compal-laptop.c
35935--- linux-2.6.32.43/drivers/platform/x86/compal-laptop.c 2011-03-27 14:31:47.000000000 -0400
35936+++ linux-2.6.32.43/drivers/platform/x86/compal-laptop.c 2011-04-17 15:56:46.000000000 -0400
35937@@ -163,7 +163,7 @@ static int bl_update_status(struct backl
35938 return set_lcd_level(b->props.brightness);
35939 }
35940
35941-static struct backlight_ops compalbl_ops = {
35942+static const struct backlight_ops compalbl_ops = {
35943 .get_brightness = bl_get_brightness,
35944 .update_status = bl_update_status,
35945 };
35946diff -urNp linux-2.6.32.43/drivers/platform/x86/dell-laptop.c linux-2.6.32.43/drivers/platform/x86/dell-laptop.c
35947--- linux-2.6.32.43/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:01.000000000 -0400
35948+++ linux-2.6.32.43/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:33.000000000 -0400
35949@@ -318,7 +318,7 @@ static int dell_get_intensity(struct bac
35950 return buffer.output[1];
35951 }
35952
35953-static struct backlight_ops dell_ops = {
35954+static const struct backlight_ops dell_ops = {
35955 .get_brightness = dell_get_intensity,
35956 .update_status = dell_send_intensity,
35957 };
35958diff -urNp linux-2.6.32.43/drivers/platform/x86/eeepc-laptop.c linux-2.6.32.43/drivers/platform/x86/eeepc-laptop.c
35959--- linux-2.6.32.43/drivers/platform/x86/eeepc-laptop.c 2011-03-27 14:31:47.000000000 -0400
35960+++ linux-2.6.32.43/drivers/platform/x86/eeepc-laptop.c 2011-04-17 15:56:46.000000000 -0400
35961@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device
35962 */
35963 static int read_brightness(struct backlight_device *bd);
35964 static int update_bl_status(struct backlight_device *bd);
35965-static struct backlight_ops eeepcbl_ops = {
35966+static const struct backlight_ops eeepcbl_ops = {
35967 .get_brightness = read_brightness,
35968 .update_status = update_bl_status,
35969 };
35970diff -urNp linux-2.6.32.43/drivers/platform/x86/fujitsu-laptop.c linux-2.6.32.43/drivers/platform/x86/fujitsu-laptop.c
35971--- linux-2.6.32.43/drivers/platform/x86/fujitsu-laptop.c 2011-03-27 14:31:47.000000000 -0400
35972+++ linux-2.6.32.43/drivers/platform/x86/fujitsu-laptop.c 2011-04-17 15:56:46.000000000 -0400
35973@@ -436,7 +436,7 @@ static int bl_update_status(struct backl
35974 return ret;
35975 }
35976
35977-static struct backlight_ops fujitsubl_ops = {
35978+static const struct backlight_ops fujitsubl_ops = {
35979 .get_brightness = bl_get_brightness,
35980 .update_status = bl_update_status,
35981 };
35982diff -urNp linux-2.6.32.43/drivers/platform/x86/msi-laptop.c linux-2.6.32.43/drivers/platform/x86/msi-laptop.c
35983--- linux-2.6.32.43/drivers/platform/x86/msi-laptop.c 2011-03-27 14:31:47.000000000 -0400
35984+++ linux-2.6.32.43/drivers/platform/x86/msi-laptop.c 2011-04-17 15:56:46.000000000 -0400
35985@@ -161,7 +161,7 @@ static int bl_update_status(struct backl
35986 return set_lcd_level(b->props.brightness);
35987 }
35988
35989-static struct backlight_ops msibl_ops = {
35990+static const struct backlight_ops msibl_ops = {
35991 .get_brightness = bl_get_brightness,
35992 .update_status = bl_update_status,
35993 };
35994diff -urNp linux-2.6.32.43/drivers/platform/x86/panasonic-laptop.c linux-2.6.32.43/drivers/platform/x86/panasonic-laptop.c
35995--- linux-2.6.32.43/drivers/platform/x86/panasonic-laptop.c 2011-03-27 14:31:47.000000000 -0400
35996+++ linux-2.6.32.43/drivers/platform/x86/panasonic-laptop.c 2011-04-17 15:56:46.000000000 -0400
35997@@ -352,7 +352,7 @@ static int bl_set_status(struct backligh
35998 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
35999 }
36000
36001-static struct backlight_ops pcc_backlight_ops = {
36002+static const struct backlight_ops pcc_backlight_ops = {
36003 .get_brightness = bl_get,
36004 .update_status = bl_set_status,
36005 };
36006diff -urNp linux-2.6.32.43/drivers/platform/x86/sony-laptop.c linux-2.6.32.43/drivers/platform/x86/sony-laptop.c
36007--- linux-2.6.32.43/drivers/platform/x86/sony-laptop.c 2011-03-27 14:31:47.000000000 -0400
36008+++ linux-2.6.32.43/drivers/platform/x86/sony-laptop.c 2011-04-17 15:56:46.000000000 -0400
36009@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness
36010 }
36011
36012 static struct backlight_device *sony_backlight_device;
36013-static struct backlight_ops sony_backlight_ops = {
36014+static const struct backlight_ops sony_backlight_ops = {
36015 .update_status = sony_backlight_update_status,
36016 .get_brightness = sony_backlight_get_brightness,
36017 };
36018diff -urNp linux-2.6.32.43/drivers/platform/x86/thinkpad_acpi.c linux-2.6.32.43/drivers/platform/x86/thinkpad_acpi.c
36019--- linux-2.6.32.43/drivers/platform/x86/thinkpad_acpi.c 2011-03-27 14:31:47.000000000 -0400
36020+++ linux-2.6.32.43/drivers/platform/x86/thinkpad_acpi.c 2011-08-05 20:33:55.000000000 -0400
36021@@ -2137,7 +2137,7 @@ static int hotkey_mask_get(void)
36022 return 0;
36023 }
36024
36025-void static hotkey_mask_warn_incomplete_mask(void)
36026+static void hotkey_mask_warn_incomplete_mask(void)
36027 {
36028 /* log only what the user can fix... */
36029 const u32 wantedmask = hotkey_driver_mask &
36030@@ -6122,7 +6122,7 @@ static void tpacpi_brightness_notify_cha
36031 BACKLIGHT_UPDATE_HOTKEY);
36032 }
36033
36034-static struct backlight_ops ibm_backlight_data = {
36035+static const struct backlight_ops ibm_backlight_data = {
36036 .get_brightness = brightness_get,
36037 .update_status = brightness_update_status,
36038 };
36039diff -urNp linux-2.6.32.43/drivers/platform/x86/toshiba_acpi.c linux-2.6.32.43/drivers/platform/x86/toshiba_acpi.c
36040--- linux-2.6.32.43/drivers/platform/x86/toshiba_acpi.c 2011-03-27 14:31:47.000000000 -0400
36041+++ linux-2.6.32.43/drivers/platform/x86/toshiba_acpi.c 2011-04-17 15:56:46.000000000 -0400
36042@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
36043 return AE_OK;
36044 }
36045
36046-static struct backlight_ops toshiba_backlight_data = {
36047+static const struct backlight_ops toshiba_backlight_data = {
36048 .get_brightness = get_lcd,
36049 .update_status = set_lcd_status,
36050 };
36051diff -urNp linux-2.6.32.43/drivers/pnp/pnpbios/bioscalls.c linux-2.6.32.43/drivers/pnp/pnpbios/bioscalls.c
36052--- linux-2.6.32.43/drivers/pnp/pnpbios/bioscalls.c 2011-03-27 14:31:47.000000000 -0400
36053+++ linux-2.6.32.43/drivers/pnp/pnpbios/bioscalls.c 2011-04-17 15:56:46.000000000 -0400
36054@@ -60,7 +60,7 @@ do { \
36055 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36056 } while(0)
36057
36058-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36059+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36060 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36061
36062 /*
36063@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func
36064
36065 cpu = get_cpu();
36066 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36067+
36068+ pax_open_kernel();
36069 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36070+ pax_close_kernel();
36071
36072 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36073 spin_lock_irqsave(&pnp_bios_lock, flags);
36074@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func
36075 :"memory");
36076 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36077
36078+ pax_open_kernel();
36079 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36080+ pax_close_kernel();
36081+
36082 put_cpu();
36083
36084 /* If we get here and this is set then the PnP BIOS faulted on us. */
36085@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 n
36086 return status;
36087 }
36088
36089-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36090+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36091 {
36092 int i;
36093
36094@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_i
36095 pnp_bios_callpoint.offset = header->fields.pm16offset;
36096 pnp_bios_callpoint.segment = PNP_CS16;
36097
36098+ pax_open_kernel();
36099+
36100 for_each_possible_cpu(i) {
36101 struct desc_struct *gdt = get_cpu_gdt_table(i);
36102 if (!gdt)
36103@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_i
36104 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36105 (unsigned long)__va(header->fields.pm16dseg));
36106 }
36107+
36108+ pax_close_kernel();
36109 }
36110diff -urNp linux-2.6.32.43/drivers/pnp/resource.c linux-2.6.32.43/drivers/pnp/resource.c
36111--- linux-2.6.32.43/drivers/pnp/resource.c 2011-03-27 14:31:47.000000000 -0400
36112+++ linux-2.6.32.43/drivers/pnp/resource.c 2011-04-17 15:56:46.000000000 -0400
36113@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
36114 return 1;
36115
36116 /* check if the resource is valid */
36117- if (*irq < 0 || *irq > 15)
36118+ if (*irq > 15)
36119 return 0;
36120
36121 /* check if the resource is reserved */
36122@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
36123 return 1;
36124
36125 /* check if the resource is valid */
36126- if (*dma < 0 || *dma == 4 || *dma > 7)
36127+ if (*dma == 4 || *dma > 7)
36128 return 0;
36129
36130 /* check if the resource is reserved */
36131diff -urNp linux-2.6.32.43/drivers/power/bq27x00_battery.c linux-2.6.32.43/drivers/power/bq27x00_battery.c
36132--- linux-2.6.32.43/drivers/power/bq27x00_battery.c 2011-03-27 14:31:47.000000000 -0400
36133+++ linux-2.6.32.43/drivers/power/bq27x00_battery.c 2011-08-05 20:33:55.000000000 -0400
36134@@ -44,7 +44,7 @@ struct bq27x00_device_info;
36135 struct bq27x00_access_methods {
36136 int (*read)(u8 reg, int *rt_value, int b_single,
36137 struct bq27x00_device_info *di);
36138-};
36139+} __no_const;
36140
36141 struct bq27x00_device_info {
36142 struct device *dev;
36143diff -urNp linux-2.6.32.43/drivers/rtc/rtc-dev.c linux-2.6.32.43/drivers/rtc/rtc-dev.c
36144--- linux-2.6.32.43/drivers/rtc/rtc-dev.c 2011-03-27 14:31:47.000000000 -0400
36145+++ linux-2.6.32.43/drivers/rtc/rtc-dev.c 2011-04-17 15:56:46.000000000 -0400
36146@@ -14,6 +14,7 @@
36147 #include <linux/module.h>
36148 #include <linux/rtc.h>
36149 #include <linux/sched.h>
36150+#include <linux/grsecurity.h>
36151 #include "rtc-core.h"
36152
36153 static dev_t rtc_devt;
36154@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *f
36155 if (copy_from_user(&tm, uarg, sizeof(tm)))
36156 return -EFAULT;
36157
36158+ gr_log_timechange();
36159+
36160 return rtc_set_time(rtc, &tm);
36161
36162 case RTC_PIE_ON:
36163diff -urNp linux-2.6.32.43/drivers/s390/cio/qdio_perf.c linux-2.6.32.43/drivers/s390/cio/qdio_perf.c
36164--- linux-2.6.32.43/drivers/s390/cio/qdio_perf.c 2011-03-27 14:31:47.000000000 -0400
36165+++ linux-2.6.32.43/drivers/s390/cio/qdio_perf.c 2011-04-17 15:56:46.000000000 -0400
36166@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_
36167 static int qdio_perf_proc_show(struct seq_file *m, void *v)
36168 {
36169 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
36170- (long)atomic_long_read(&perf_stats.qdio_int));
36171+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
36172 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
36173- (long)atomic_long_read(&perf_stats.pci_int));
36174+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
36175 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
36176- (long)atomic_long_read(&perf_stats.thin_int));
36177+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
36178 seq_printf(m, "\n");
36179 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
36180- (long)atomic_long_read(&perf_stats.tasklet_inbound));
36181+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
36182 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
36183- (long)atomic_long_read(&perf_stats.tasklet_outbound));
36184+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
36185 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
36186- (long)atomic_long_read(&perf_stats.tasklet_thinint),
36187- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
36188+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
36189+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
36190 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
36191- (long)atomic_long_read(&perf_stats.thinint_inbound),
36192- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
36193+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
36194+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
36195 seq_printf(m, "\n");
36196 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
36197- (long)atomic_long_read(&perf_stats.siga_in));
36198+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
36199 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
36200- (long)atomic_long_read(&perf_stats.siga_out));
36201+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
36202 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
36203- (long)atomic_long_read(&perf_stats.siga_sync));
36204+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
36205 seq_printf(m, "\n");
36206 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
36207- (long)atomic_long_read(&perf_stats.inbound_handler));
36208+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
36209 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
36210- (long)atomic_long_read(&perf_stats.outbound_handler));
36211+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
36212 seq_printf(m, "\n");
36213 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
36214- (long)atomic_long_read(&perf_stats.fast_requeue));
36215+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
36216 seq_printf(m, "Number of outbound target full condition\t: %li\n",
36217- (long)atomic_long_read(&perf_stats.outbound_target_full));
36218+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
36219 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
36220- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
36221+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
36222 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
36223- (long)atomic_long_read(&perf_stats.debug_stop_polling));
36224+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
36225 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
36226- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
36227+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
36228 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
36229- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
36230- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
36231+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
36232+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
36233 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
36234- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
36235- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
36236+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
36237+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
36238 seq_printf(m, "\n");
36239 return 0;
36240 }
36241diff -urNp linux-2.6.32.43/drivers/s390/cio/qdio_perf.h linux-2.6.32.43/drivers/s390/cio/qdio_perf.h
36242--- linux-2.6.32.43/drivers/s390/cio/qdio_perf.h 2011-03-27 14:31:47.000000000 -0400
36243+++ linux-2.6.32.43/drivers/s390/cio/qdio_perf.h 2011-04-17 15:56:46.000000000 -0400
36244@@ -13,46 +13,46 @@
36245
36246 struct qdio_perf_stats {
36247 /* interrupt handler calls */
36248- atomic_long_t qdio_int;
36249- atomic_long_t pci_int;
36250- atomic_long_t thin_int;
36251+ atomic_long_unchecked_t qdio_int;
36252+ atomic_long_unchecked_t pci_int;
36253+ atomic_long_unchecked_t thin_int;
36254
36255 /* tasklet runs */
36256- atomic_long_t tasklet_inbound;
36257- atomic_long_t tasklet_outbound;
36258- atomic_long_t tasklet_thinint;
36259- atomic_long_t tasklet_thinint_loop;
36260- atomic_long_t thinint_inbound;
36261- atomic_long_t thinint_inbound_loop;
36262- atomic_long_t thinint_inbound_loop2;
36263+ atomic_long_unchecked_t tasklet_inbound;
36264+ atomic_long_unchecked_t tasklet_outbound;
36265+ atomic_long_unchecked_t tasklet_thinint;
36266+ atomic_long_unchecked_t tasklet_thinint_loop;
36267+ atomic_long_unchecked_t thinint_inbound;
36268+ atomic_long_unchecked_t thinint_inbound_loop;
36269+ atomic_long_unchecked_t thinint_inbound_loop2;
36270
36271 /* signal adapter calls */
36272- atomic_long_t siga_out;
36273- atomic_long_t siga_in;
36274- atomic_long_t siga_sync;
36275+ atomic_long_unchecked_t siga_out;
36276+ atomic_long_unchecked_t siga_in;
36277+ atomic_long_unchecked_t siga_sync;
36278
36279 /* misc */
36280- atomic_long_t inbound_handler;
36281- atomic_long_t outbound_handler;
36282- atomic_long_t fast_requeue;
36283- atomic_long_t outbound_target_full;
36284+ atomic_long_unchecked_t inbound_handler;
36285+ atomic_long_unchecked_t outbound_handler;
36286+ atomic_long_unchecked_t fast_requeue;
36287+ atomic_long_unchecked_t outbound_target_full;
36288
36289 /* for debugging */
36290- atomic_long_t debug_tl_out_timer;
36291- atomic_long_t debug_stop_polling;
36292- atomic_long_t debug_eqbs_all;
36293- atomic_long_t debug_eqbs_incomplete;
36294- atomic_long_t debug_sqbs_all;
36295- atomic_long_t debug_sqbs_incomplete;
36296+ atomic_long_unchecked_t debug_tl_out_timer;
36297+ atomic_long_unchecked_t debug_stop_polling;
36298+ atomic_long_unchecked_t debug_eqbs_all;
36299+ atomic_long_unchecked_t debug_eqbs_incomplete;
36300+ atomic_long_unchecked_t debug_sqbs_all;
36301+ atomic_long_unchecked_t debug_sqbs_incomplete;
36302 };
36303
36304 extern struct qdio_perf_stats perf_stats;
36305 extern int qdio_performance_stats;
36306
36307-static inline void qdio_perf_stat_inc(atomic_long_t *count)
36308+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
36309 {
36310 if (qdio_performance_stats)
36311- atomic_long_inc(count);
36312+ atomic_long_inc_unchecked(count);
36313 }
36314
36315 int qdio_setup_perf_stats(void);
36316diff -urNp linux-2.6.32.43/drivers/scsi/aacraid/aacraid.h linux-2.6.32.43/drivers/scsi/aacraid/aacraid.h
36317--- linux-2.6.32.43/drivers/scsi/aacraid/aacraid.h 2011-03-27 14:31:47.000000000 -0400
36318+++ linux-2.6.32.43/drivers/scsi/aacraid/aacraid.h 2011-08-05 20:33:55.000000000 -0400
36319@@ -471,7 +471,7 @@ struct adapter_ops
36320 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36321 /* Administrative operations */
36322 int (*adapter_comm)(struct aac_dev * dev, int comm);
36323-};
36324+} __no_const;
36325
36326 /*
36327 * Define which interrupt handler needs to be installed
36328diff -urNp linux-2.6.32.43/drivers/scsi/aacraid/commctrl.c linux-2.6.32.43/drivers/scsi/aacraid/commctrl.c
36329--- linux-2.6.32.43/drivers/scsi/aacraid/commctrl.c 2011-03-27 14:31:47.000000000 -0400
36330+++ linux-2.6.32.43/drivers/scsi/aacraid/commctrl.c 2011-05-16 21:46:57.000000000 -0400
36331@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_d
36332 u32 actual_fibsize64, actual_fibsize = 0;
36333 int i;
36334
36335+ pax_track_stack();
36336
36337 if (dev->in_reset) {
36338 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
36339diff -urNp linux-2.6.32.43/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.32.43/drivers/scsi/aic94xx/aic94xx_init.c
36340--- linux-2.6.32.43/drivers/scsi/aic94xx/aic94xx_init.c 2011-03-27 14:31:47.000000000 -0400
36341+++ linux-2.6.32.43/drivers/scsi/aic94xx/aic94xx_init.c 2011-04-17 15:56:46.000000000 -0400
36342@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(stru
36343 flash_error_table[i].reason);
36344 }
36345
36346-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
36347+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
36348 asd_show_update_bios, asd_store_update_bios);
36349
36350 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
36351diff -urNp linux-2.6.32.43/drivers/scsi/bfa/bfa_iocfc.h linux-2.6.32.43/drivers/scsi/bfa/bfa_iocfc.h
36352--- linux-2.6.32.43/drivers/scsi/bfa/bfa_iocfc.h 2011-03-27 14:31:47.000000000 -0400
36353+++ linux-2.6.32.43/drivers/scsi/bfa/bfa_iocfc.h 2011-08-05 20:33:55.000000000 -0400
36354@@ -61,7 +61,7 @@ struct bfa_hwif_s {
36355 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
36356 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
36357 u32 *nvecs, u32 *maxvec);
36358-};
36359+} __no_const;
36360 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36361
36362 struct bfa_iocfc_s {
36363diff -urNp linux-2.6.32.43/drivers/scsi/bfa/bfa_ioc.h linux-2.6.32.43/drivers/scsi/bfa/bfa_ioc.h
36364--- linux-2.6.32.43/drivers/scsi/bfa/bfa_ioc.h 2011-03-27 14:31:47.000000000 -0400
36365+++ linux-2.6.32.43/drivers/scsi/bfa/bfa_ioc.h 2011-08-05 20:33:55.000000000 -0400
36366@@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
36367 bfa_ioc_disable_cbfn_t disable_cbfn;
36368 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36369 bfa_ioc_reset_cbfn_t reset_cbfn;
36370-};
36371+} __no_const;
36372
36373 /**
36374 * Heartbeat failure notification queue element.
36375diff -urNp linux-2.6.32.43/drivers/scsi/BusLogic.c linux-2.6.32.43/drivers/scsi/BusLogic.c
36376--- linux-2.6.32.43/drivers/scsi/BusLogic.c 2011-03-27 14:31:47.000000000 -0400
36377+++ linux-2.6.32.43/drivers/scsi/BusLogic.c 2011-05-16 21:46:57.000000000 -0400
36378@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFla
36379 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
36380 *PrototypeHostAdapter)
36381 {
36382+ pax_track_stack();
36383+
36384 /*
36385 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
36386 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
36387diff -urNp linux-2.6.32.43/drivers/scsi/dpt_i2o.c linux-2.6.32.43/drivers/scsi/dpt_i2o.c
36388--- linux-2.6.32.43/drivers/scsi/dpt_i2o.c 2011-03-27 14:31:47.000000000 -0400
36389+++ linux-2.6.32.43/drivers/scsi/dpt_i2o.c 2011-05-16 21:46:57.000000000 -0400
36390@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* p
36391 dma_addr_t addr;
36392 ulong flags = 0;
36393
36394+ pax_track_stack();
36395+
36396 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
36397 // get user msg size in u32s
36398 if(get_user(size, &user_msg[0])){
36399@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
36400 s32 rcode;
36401 dma_addr_t addr;
36402
36403+ pax_track_stack();
36404+
36405 memset(msg, 0 , sizeof(msg));
36406 len = scsi_bufflen(cmd);
36407 direction = 0x00000000;
36408diff -urNp linux-2.6.32.43/drivers/scsi/eata.c linux-2.6.32.43/drivers/scsi/eata.c
36409--- linux-2.6.32.43/drivers/scsi/eata.c 2011-03-27 14:31:47.000000000 -0400
36410+++ linux-2.6.32.43/drivers/scsi/eata.c 2011-05-16 21:46:57.000000000 -0400
36411@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
36412 struct hostdata *ha;
36413 char name[16];
36414
36415+ pax_track_stack();
36416+
36417 sprintf(name, "%s%d", driver_name, j);
36418
36419 if (!request_region(port_base, REGION_SIZE, driver_name)) {
36420diff -urNp linux-2.6.32.43/drivers/scsi/fcoe/libfcoe.c linux-2.6.32.43/drivers/scsi/fcoe/libfcoe.c
36421--- linux-2.6.32.43/drivers/scsi/fcoe/libfcoe.c 2011-03-27 14:31:47.000000000 -0400
36422+++ linux-2.6.32.43/drivers/scsi/fcoe/libfcoe.c 2011-05-16 21:46:57.000000000 -0400
36423@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fc
36424 size_t rlen;
36425 size_t dlen;
36426
36427+ pax_track_stack();
36428+
36429 fiph = (struct fip_header *)skb->data;
36430 sub = fiph->fip_subcode;
36431 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
36432diff -urNp linux-2.6.32.43/drivers/scsi/fnic/fnic_main.c linux-2.6.32.43/drivers/scsi/fnic/fnic_main.c
36433--- linux-2.6.32.43/drivers/scsi/fnic/fnic_main.c 2011-03-27 14:31:47.000000000 -0400
36434+++ linux-2.6.32.43/drivers/scsi/fnic/fnic_main.c 2011-08-05 20:33:55.000000000 -0400
36435@@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct p
36436 /* Start local port initiatialization */
36437
36438 lp->link_up = 0;
36439- lp->tt = fnic_transport_template;
36440+ memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
36441
36442 lp->max_retry_count = fnic->config.flogi_retries;
36443 lp->max_rport_retry_count = fnic->config.plogi_retries;
36444diff -urNp linux-2.6.32.43/drivers/scsi/gdth.c linux-2.6.32.43/drivers/scsi/gdth.c
36445--- linux-2.6.32.43/drivers/scsi/gdth.c 2011-03-27 14:31:47.000000000 -0400
36446+++ linux-2.6.32.43/drivers/scsi/gdth.c 2011-05-16 21:46:57.000000000 -0400
36447@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
36448 ulong flags;
36449 gdth_ha_str *ha;
36450
36451+ pax_track_stack();
36452+
36453 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
36454 return -EFAULT;
36455 ha = gdth_find_ha(ldrv.ionode);
36456@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg
36457 gdth_ha_str *ha;
36458 int rval;
36459
36460+ pax_track_stack();
36461+
36462 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
36463 res.number >= MAX_HDRIVES)
36464 return -EFAULT;
36465@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg,
36466 gdth_ha_str *ha;
36467 int rval;
36468
36469+ pax_track_stack();
36470+
36471 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
36472 return -EFAULT;
36473 ha = gdth_find_ha(gen.ionode);
36474@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
36475 int i;
36476 gdth_cmd_str gdtcmd;
36477 char cmnd[MAX_COMMAND_SIZE];
36478+
36479+ pax_track_stack();
36480+
36481 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
36482
36483 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
36484diff -urNp linux-2.6.32.43/drivers/scsi/gdth_proc.c linux-2.6.32.43/drivers/scsi/gdth_proc.c
36485--- linux-2.6.32.43/drivers/scsi/gdth_proc.c 2011-03-27 14:31:47.000000000 -0400
36486+++ linux-2.6.32.43/drivers/scsi/gdth_proc.c 2011-05-16 21:46:57.000000000 -0400
36487@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi
36488 ulong64 paddr;
36489
36490 char cmnd[MAX_COMMAND_SIZE];
36491+
36492+ pax_track_stack();
36493+
36494 memset(cmnd, 0xff, 12);
36495 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
36496
36497@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,ch
36498 gdth_hget_str *phg;
36499 char cmnd[MAX_COMMAND_SIZE];
36500
36501+ pax_track_stack();
36502+
36503 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
36504 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
36505 if (!gdtcmd || !estr)
36506diff -urNp linux-2.6.32.43/drivers/scsi/hosts.c linux-2.6.32.43/drivers/scsi/hosts.c
36507--- linux-2.6.32.43/drivers/scsi/hosts.c 2011-03-27 14:31:47.000000000 -0400
36508+++ linux-2.6.32.43/drivers/scsi/hosts.c 2011-05-04 17:56:28.000000000 -0400
36509@@ -40,7 +40,7 @@
36510 #include "scsi_logging.h"
36511
36512
36513-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36514+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36515
36516
36517 static void scsi_host_cls_release(struct device *dev)
36518@@ -344,7 +344,7 @@ struct Scsi_Host *scsi_host_alloc(struct
36519 * subtract one because we increment first then return, but we need to
36520 * know what the next host number was before increment
36521 */
36522- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36523+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36524 shost->dma_channel = 0xff;
36525
36526 /* These three are default values which can be overridden */
36527diff -urNp linux-2.6.32.43/drivers/scsi/ipr.c linux-2.6.32.43/drivers/scsi/ipr.c
36528--- linux-2.6.32.43/drivers/scsi/ipr.c 2011-03-27 14:31:47.000000000 -0400
36529+++ linux-2.6.32.43/drivers/scsi/ipr.c 2011-04-17 15:56:46.000000000 -0400
36530@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
36531 return true;
36532 }
36533
36534-static struct ata_port_operations ipr_sata_ops = {
36535+static const struct ata_port_operations ipr_sata_ops = {
36536 .phy_reset = ipr_ata_phy_reset,
36537 .hardreset = ipr_sata_reset,
36538 .post_internal_cmd = ipr_ata_post_internal,
36539diff -urNp linux-2.6.32.43/drivers/scsi/ips.h linux-2.6.32.43/drivers/scsi/ips.h
36540--- linux-2.6.32.43/drivers/scsi/ips.h 2011-03-27 14:31:47.000000000 -0400
36541+++ linux-2.6.32.43/drivers/scsi/ips.h 2011-08-05 20:33:55.000000000 -0400
36542@@ -1027,7 +1027,7 @@ typedef struct {
36543 int (*intr)(struct ips_ha *);
36544 void (*enableint)(struct ips_ha *);
36545 uint32_t (*statupd)(struct ips_ha *);
36546-} ips_hw_func_t;
36547+} __no_const ips_hw_func_t;
36548
36549 typedef struct ips_ha {
36550 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36551diff -urNp linux-2.6.32.43/drivers/scsi/libfc/fc_disc.c linux-2.6.32.43/drivers/scsi/libfc/fc_disc.c
36552--- linux-2.6.32.43/drivers/scsi/libfc/fc_disc.c 2011-03-27 14:31:47.000000000 -0400
36553+++ linux-2.6.32.43/drivers/scsi/libfc/fc_disc.c 2011-08-05 20:33:55.000000000 -0400
36554@@ -715,16 +715,16 @@ int fc_disc_init(struct fc_lport *lport)
36555 struct fc_disc *disc;
36556
36557 if (!lport->tt.disc_start)
36558- lport->tt.disc_start = fc_disc_start;
36559+ *(void **)&lport->tt.disc_start = fc_disc_start;
36560
36561 if (!lport->tt.disc_stop)
36562- lport->tt.disc_stop = fc_disc_stop;
36563+ *(void **)&lport->tt.disc_stop = fc_disc_stop;
36564
36565 if (!lport->tt.disc_stop_final)
36566- lport->tt.disc_stop_final = fc_disc_stop_final;
36567+ *(void **)&lport->tt.disc_stop_final = fc_disc_stop_final;
36568
36569 if (!lport->tt.disc_recv_req)
36570- lport->tt.disc_recv_req = fc_disc_recv_req;
36571+ *(void **)&lport->tt.disc_recv_req = fc_disc_recv_req;
36572
36573 disc = &lport->disc;
36574 INIT_DELAYED_WORK(&disc->disc_work, fc_disc_timeout);
36575diff -urNp linux-2.6.32.43/drivers/scsi/libfc/fc_elsct.c linux-2.6.32.43/drivers/scsi/libfc/fc_elsct.c
36576--- linux-2.6.32.43/drivers/scsi/libfc/fc_elsct.c 2011-03-27 14:31:47.000000000 -0400
36577+++ linux-2.6.32.43/drivers/scsi/libfc/fc_elsct.c 2011-08-05 20:33:55.000000000 -0400
36578@@ -67,7 +67,7 @@ static struct fc_seq *fc_elsct_send(stru
36579 int fc_elsct_init(struct fc_lport *lport)
36580 {
36581 if (!lport->tt.elsct_send)
36582- lport->tt.elsct_send = fc_elsct_send;
36583+ *(void **)&lport->tt.elsct_send = fc_elsct_send;
36584
36585 return 0;
36586 }
36587diff -urNp linux-2.6.32.43/drivers/scsi/libfc/fc_exch.c linux-2.6.32.43/drivers/scsi/libfc/fc_exch.c
36588--- linux-2.6.32.43/drivers/scsi/libfc/fc_exch.c 2011-03-27 14:31:47.000000000 -0400
36589+++ linux-2.6.32.43/drivers/scsi/libfc/fc_exch.c 2011-08-05 20:33:55.000000000 -0400
36590@@ -86,12 +86,12 @@ struct fc_exch_mgr {
36591 * all together if not used XXX
36592 */
36593 struct {
36594- atomic_t no_free_exch;
36595- atomic_t no_free_exch_xid;
36596- atomic_t xid_not_found;
36597- atomic_t xid_busy;
36598- atomic_t seq_not_found;
36599- atomic_t non_bls_resp;
36600+ atomic_unchecked_t no_free_exch;
36601+ atomic_unchecked_t no_free_exch_xid;
36602+ atomic_unchecked_t xid_not_found;
36603+ atomic_unchecked_t xid_busy;
36604+ atomic_unchecked_t seq_not_found;
36605+ atomic_unchecked_t non_bls_resp;
36606 } stats;
36607 };
36608 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
36609@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(
36610 /* allocate memory for exchange */
36611 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36612 if (!ep) {
36613- atomic_inc(&mp->stats.no_free_exch);
36614+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36615 goto out;
36616 }
36617 memset(ep, 0, sizeof(*ep));
36618@@ -557,7 +557,7 @@ out:
36619 return ep;
36620 err:
36621 spin_unlock_bh(&pool->lock);
36622- atomic_inc(&mp->stats.no_free_exch_xid);
36623+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36624 mempool_free(ep, mp->ep_pool);
36625 return NULL;
36626 }
36627@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_look
36628 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36629 ep = fc_exch_find(mp, xid);
36630 if (!ep) {
36631- atomic_inc(&mp->stats.xid_not_found);
36632+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36633 reject = FC_RJT_OX_ID;
36634 goto out;
36635 }
36636@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_look
36637 ep = fc_exch_find(mp, xid);
36638 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36639 if (ep) {
36640- atomic_inc(&mp->stats.xid_busy);
36641+ atomic_inc_unchecked(&mp->stats.xid_busy);
36642 reject = FC_RJT_RX_ID;
36643 goto rel;
36644 }
36645@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_look
36646 }
36647 xid = ep->xid; /* get our XID */
36648 } else if (!ep) {
36649- atomic_inc(&mp->stats.xid_not_found);
36650+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36651 reject = FC_RJT_RX_ID; /* XID not found */
36652 goto out;
36653 }
36654@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_look
36655 } else {
36656 sp = &ep->seq;
36657 if (sp->id != fh->fh_seq_id) {
36658- atomic_inc(&mp->stats.seq_not_found);
36659+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36660 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
36661 goto rel;
36662 }
36663@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct
36664
36665 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36666 if (!ep) {
36667- atomic_inc(&mp->stats.xid_not_found);
36668+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36669 goto out;
36670 }
36671 if (ep->esb_stat & ESB_ST_COMPLETE) {
36672- atomic_inc(&mp->stats.xid_not_found);
36673+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36674 goto out;
36675 }
36676 if (ep->rxid == FC_XID_UNKNOWN)
36677 ep->rxid = ntohs(fh->fh_rx_id);
36678 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36679- atomic_inc(&mp->stats.xid_not_found);
36680+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36681 goto rel;
36682 }
36683 if (ep->did != ntoh24(fh->fh_s_id) &&
36684 ep->did != FC_FID_FLOGI) {
36685- atomic_inc(&mp->stats.xid_not_found);
36686+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36687 goto rel;
36688 }
36689 sof = fr_sof(fp);
36690@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct
36691 } else {
36692 sp = &ep->seq;
36693 if (sp->id != fh->fh_seq_id) {
36694- atomic_inc(&mp->stats.seq_not_found);
36695+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36696 goto rel;
36697 }
36698 }
36699@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_
36700 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36701
36702 if (!sp)
36703- atomic_inc(&mp->stats.xid_not_found);
36704+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36705 else
36706- atomic_inc(&mp->stats.non_bls_resp);
36707+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36708
36709 fc_frame_free(fp);
36710 }
36711@@ -2027,25 +2027,25 @@ EXPORT_SYMBOL(fc_exch_recv);
36712 int fc_exch_init(struct fc_lport *lp)
36713 {
36714 if (!lp->tt.seq_start_next)
36715- lp->tt.seq_start_next = fc_seq_start_next;
36716+ *(void **)&lp->tt.seq_start_next = fc_seq_start_next;
36717
36718 if (!lp->tt.exch_seq_send)
36719- lp->tt.exch_seq_send = fc_exch_seq_send;
36720+ *(void **)&lp->tt.exch_seq_send = fc_exch_seq_send;
36721
36722 if (!lp->tt.seq_send)
36723- lp->tt.seq_send = fc_seq_send;
36724+ *(void **)&lp->tt.seq_send = fc_seq_send;
36725
36726 if (!lp->tt.seq_els_rsp_send)
36727- lp->tt.seq_els_rsp_send = fc_seq_els_rsp_send;
36728+ *(void **)&lp->tt.seq_els_rsp_send = fc_seq_els_rsp_send;
36729
36730 if (!lp->tt.exch_done)
36731- lp->tt.exch_done = fc_exch_done;
36732+ *(void **)&lp->tt.exch_done = fc_exch_done;
36733
36734 if (!lp->tt.exch_mgr_reset)
36735- lp->tt.exch_mgr_reset = fc_exch_mgr_reset;
36736+ *(void **)&lp->tt.exch_mgr_reset = fc_exch_mgr_reset;
36737
36738 if (!lp->tt.seq_exch_abort)
36739- lp->tt.seq_exch_abort = fc_seq_exch_abort;
36740+ *(void **)&lp->tt.seq_exch_abort = fc_seq_exch_abort;
36741
36742 /*
36743 * Initialize fc_cpu_mask and fc_cpu_order. The
36744diff -urNp linux-2.6.32.43/drivers/scsi/libfc/fc_fcp.c linux-2.6.32.43/drivers/scsi/libfc/fc_fcp.c
36745--- linux-2.6.32.43/drivers/scsi/libfc/fc_fcp.c 2011-03-27 14:31:47.000000000 -0400
36746+++ linux-2.6.32.43/drivers/scsi/libfc/fc_fcp.c 2011-08-05 20:33:55.000000000 -0400
36747@@ -2105,13 +2105,13 @@ int fc_fcp_init(struct fc_lport *lp)
36748 struct fc_fcp_internal *si;
36749
36750 if (!lp->tt.fcp_cmd_send)
36751- lp->tt.fcp_cmd_send = fc_fcp_cmd_send;
36752+ *(void **)&lp->tt.fcp_cmd_send = fc_fcp_cmd_send;
36753
36754 if (!lp->tt.fcp_cleanup)
36755- lp->tt.fcp_cleanup = fc_fcp_cleanup;
36756+ *(void **)&lp->tt.fcp_cleanup = fc_fcp_cleanup;
36757
36758 if (!lp->tt.fcp_abort_io)
36759- lp->tt.fcp_abort_io = fc_fcp_abort_io;
36760+ *(void **)&lp->tt.fcp_abort_io = fc_fcp_abort_io;
36761
36762 si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL);
36763 if (!si)
36764diff -urNp linux-2.6.32.43/drivers/scsi/libfc/fc_lport.c linux-2.6.32.43/drivers/scsi/libfc/fc_lport.c
36765--- linux-2.6.32.43/drivers/scsi/libfc/fc_lport.c 2011-03-27 14:31:47.000000000 -0400
36766+++ linux-2.6.32.43/drivers/scsi/libfc/fc_lport.c 2011-08-05 20:33:55.000000000 -0400
36767@@ -569,7 +569,7 @@ int fc_lport_destroy(struct fc_lport *lp
36768 mutex_lock(&lport->lp_mutex);
36769 lport->state = LPORT_ST_DISABLED;
36770 lport->link_up = 0;
36771- lport->tt.frame_send = fc_frame_drop;
36772+ *(void **)&lport->tt.frame_send = fc_frame_drop;
36773 mutex_unlock(&lport->lp_mutex);
36774
36775 lport->tt.fcp_abort_io(lport);
36776@@ -1477,10 +1477,10 @@ EXPORT_SYMBOL(fc_lport_config);
36777 int fc_lport_init(struct fc_lport *lport)
36778 {
36779 if (!lport->tt.lport_recv)
36780- lport->tt.lport_recv = fc_lport_recv_req;
36781+ *(void **)&lport->tt.lport_recv = fc_lport_recv_req;
36782
36783 if (!lport->tt.lport_reset)
36784- lport->tt.lport_reset = fc_lport_reset;
36785+ *(void **)&lport->tt.lport_reset = fc_lport_reset;
36786
36787 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
36788 fc_host_node_name(lport->host) = lport->wwnn;
36789diff -urNp linux-2.6.32.43/drivers/scsi/libfc/fc_rport.c linux-2.6.32.43/drivers/scsi/libfc/fc_rport.c
36790--- linux-2.6.32.43/drivers/scsi/libfc/fc_rport.c 2011-03-27 14:31:47.000000000 -0400
36791+++ linux-2.6.32.43/drivers/scsi/libfc/fc_rport.c 2011-08-05 20:33:55.000000000 -0400
36792@@ -1566,25 +1566,25 @@ static void fc_rport_flush_queue(void)
36793 int fc_rport_init(struct fc_lport *lport)
36794 {
36795 if (!lport->tt.rport_lookup)
36796- lport->tt.rport_lookup = fc_rport_lookup;
36797+ *(void **)&lport->tt.rport_lookup = fc_rport_lookup;
36798
36799 if (!lport->tt.rport_create)
36800- lport->tt.rport_create = fc_rport_create;
36801+ *(void **)&lport->tt.rport_create = fc_rport_create;
36802
36803 if (!lport->tt.rport_login)
36804- lport->tt.rport_login = fc_rport_login;
36805+ *(void **)&lport->tt.rport_login = fc_rport_login;
36806
36807 if (!lport->tt.rport_logoff)
36808- lport->tt.rport_logoff = fc_rport_logoff;
36809+ *(void **)&lport->tt.rport_logoff = fc_rport_logoff;
36810
36811 if (!lport->tt.rport_recv_req)
36812- lport->tt.rport_recv_req = fc_rport_recv_req;
36813+ *(void **)&lport->tt.rport_recv_req = fc_rport_recv_req;
36814
36815 if (!lport->tt.rport_flush_queue)
36816- lport->tt.rport_flush_queue = fc_rport_flush_queue;
36817+ *(void **)&lport->tt.rport_flush_queue = fc_rport_flush_queue;
36818
36819 if (!lport->tt.rport_destroy)
36820- lport->tt.rport_destroy = fc_rport_destroy;
36821+ *(void **)&lport->tt.rport_destroy = fc_rport_destroy;
36822
36823 return 0;
36824 }
36825diff -urNp linux-2.6.32.43/drivers/scsi/libsas/sas_ata.c linux-2.6.32.43/drivers/scsi/libsas/sas_ata.c
36826--- linux-2.6.32.43/drivers/scsi/libsas/sas_ata.c 2011-03-27 14:31:47.000000000 -0400
36827+++ linux-2.6.32.43/drivers/scsi/libsas/sas_ata.c 2011-04-23 12:56:11.000000000 -0400
36828@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_l
36829 }
36830 }
36831
36832-static struct ata_port_operations sas_sata_ops = {
36833+static const struct ata_port_operations sas_sata_ops = {
36834 .phy_reset = sas_ata_phy_reset,
36835 .post_internal_cmd = sas_ata_post_internal,
36836 .qc_defer = ata_std_qc_defer,
36837diff -urNp linux-2.6.32.43/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.32.43/drivers/scsi/lpfc/lpfc_debugfs.c
36838--- linux-2.6.32.43/drivers/scsi/lpfc/lpfc_debugfs.c 2011-03-27 14:31:47.000000000 -0400
36839+++ linux-2.6.32.43/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-16 21:46:57.000000000 -0400
36840@@ -124,7 +124,7 @@ struct lpfc_debug {
36841 int len;
36842 };
36843
36844-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36845+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36846 static unsigned long lpfc_debugfs_start_time = 0L;
36847
36848 /**
36849@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
36850 lpfc_debugfs_enable = 0;
36851
36852 len = 0;
36853- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36854+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36855 (lpfc_debugfs_max_disc_trc - 1);
36856 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36857 dtp = vport->disc_trc + i;
36858@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
36859 lpfc_debugfs_enable = 0;
36860
36861 len = 0;
36862- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36863+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36864 (lpfc_debugfs_max_slow_ring_trc - 1);
36865 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36866 dtp = phba->slow_ring_trc + i;
36867@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
36868 uint32_t *ptr;
36869 char buffer[1024];
36870
36871+ pax_track_stack();
36872+
36873 off = 0;
36874 spin_lock_irq(&phba->hbalock);
36875
36876@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
36877 !vport || !vport->disc_trc)
36878 return;
36879
36880- index = atomic_inc_return(&vport->disc_trc_cnt) &
36881+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36882 (lpfc_debugfs_max_disc_trc - 1);
36883 dtp = vport->disc_trc + index;
36884 dtp->fmt = fmt;
36885 dtp->data1 = data1;
36886 dtp->data2 = data2;
36887 dtp->data3 = data3;
36888- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36889+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36890 dtp->jif = jiffies;
36891 #endif
36892 return;
36893@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
36894 !phba || !phba->slow_ring_trc)
36895 return;
36896
36897- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36898+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36899 (lpfc_debugfs_max_slow_ring_trc - 1);
36900 dtp = phba->slow_ring_trc + index;
36901 dtp->fmt = fmt;
36902 dtp->data1 = data1;
36903 dtp->data2 = data2;
36904 dtp->data3 = data3;
36905- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36906+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36907 dtp->jif = jiffies;
36908 #endif
36909 return;
36910@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
36911 "slow_ring buffer\n");
36912 goto debug_failed;
36913 }
36914- atomic_set(&phba->slow_ring_trc_cnt, 0);
36915+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36916 memset(phba->slow_ring_trc, 0,
36917 (sizeof(struct lpfc_debugfs_trc) *
36918 lpfc_debugfs_max_slow_ring_trc));
36919@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
36920 "buffer\n");
36921 goto debug_failed;
36922 }
36923- atomic_set(&vport->disc_trc_cnt, 0);
36924+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36925
36926 snprintf(name, sizeof(name), "discovery_trace");
36927 vport->debug_disc_trc =
36928diff -urNp linux-2.6.32.43/drivers/scsi/lpfc/lpfc.h linux-2.6.32.43/drivers/scsi/lpfc/lpfc.h
36929--- linux-2.6.32.43/drivers/scsi/lpfc/lpfc.h 2011-03-27 14:31:47.000000000 -0400
36930+++ linux-2.6.32.43/drivers/scsi/lpfc/lpfc.h 2011-05-04 17:56:28.000000000 -0400
36931@@ -400,7 +400,7 @@ struct lpfc_vport {
36932 struct dentry *debug_nodelist;
36933 struct dentry *vport_debugfs_root;
36934 struct lpfc_debugfs_trc *disc_trc;
36935- atomic_t disc_trc_cnt;
36936+ atomic_unchecked_t disc_trc_cnt;
36937 #endif
36938 uint8_t stat_data_enabled;
36939 uint8_t stat_data_blocked;
36940@@ -725,8 +725,8 @@ struct lpfc_hba {
36941 struct timer_list fabric_block_timer;
36942 unsigned long bit_flags;
36943 #define FABRIC_COMANDS_BLOCKED 0
36944- atomic_t num_rsrc_err;
36945- atomic_t num_cmd_success;
36946+ atomic_unchecked_t num_rsrc_err;
36947+ atomic_unchecked_t num_cmd_success;
36948 unsigned long last_rsrc_error_time;
36949 unsigned long last_ramp_down_time;
36950 unsigned long last_ramp_up_time;
36951@@ -740,7 +740,7 @@ struct lpfc_hba {
36952 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
36953 struct dentry *debug_slow_ring_trc;
36954 struct lpfc_debugfs_trc *slow_ring_trc;
36955- atomic_t slow_ring_trc_cnt;
36956+ atomic_unchecked_t slow_ring_trc_cnt;
36957 #endif
36958
36959 /* Used for deferred freeing of ELS data buffers */
36960diff -urNp linux-2.6.32.43/drivers/scsi/lpfc/lpfc_init.c linux-2.6.32.43/drivers/scsi/lpfc/lpfc_init.c
36961--- linux-2.6.32.43/drivers/scsi/lpfc/lpfc_init.c 2011-03-27 14:31:47.000000000 -0400
36962+++ linux-2.6.32.43/drivers/scsi/lpfc/lpfc_init.c 2011-08-05 20:33:55.000000000 -0400
36963@@ -8021,8 +8021,10 @@ lpfc_init(void)
36964 printk(LPFC_COPYRIGHT "\n");
36965
36966 if (lpfc_enable_npiv) {
36967- lpfc_transport_functions.vport_create = lpfc_vport_create;
36968- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36969+ pax_open_kernel();
36970+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36971+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36972+ pax_close_kernel();
36973 }
36974 lpfc_transport_template =
36975 fc_attach_transport(&lpfc_transport_functions);
36976diff -urNp linux-2.6.32.43/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.32.43/drivers/scsi/lpfc/lpfc_scsi.c
36977--- linux-2.6.32.43/drivers/scsi/lpfc/lpfc_scsi.c 2011-03-27 14:31:47.000000000 -0400
36978+++ linux-2.6.32.43/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-04 17:56:28.000000000 -0400
36979@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
36980 uint32_t evt_posted;
36981
36982 spin_lock_irqsave(&phba->hbalock, flags);
36983- atomic_inc(&phba->num_rsrc_err);
36984+ atomic_inc_unchecked(&phba->num_rsrc_err);
36985 phba->last_rsrc_error_time = jiffies;
36986
36987 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36988@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
36989 unsigned long flags;
36990 struct lpfc_hba *phba = vport->phba;
36991 uint32_t evt_posted;
36992- atomic_inc(&phba->num_cmd_success);
36993+ atomic_inc_unchecked(&phba->num_cmd_success);
36994
36995 if (vport->cfg_lun_queue_depth <= queue_depth)
36996 return;
36997@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
36998 int i;
36999 struct lpfc_rport_data *rdata;
37000
37001- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37002- num_cmd_success = atomic_read(&phba->num_cmd_success);
37003+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37004+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37005
37006 vports = lpfc_create_vport_work_array(phba);
37007 if (vports != NULL)
37008@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
37009 }
37010 }
37011 lpfc_destroy_vport_work_array(phba, vports);
37012- atomic_set(&phba->num_rsrc_err, 0);
37013- atomic_set(&phba->num_cmd_success, 0);
37014+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37015+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37016 }
37017
37018 /**
37019@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
37020 }
37021 }
37022 lpfc_destroy_vport_work_array(phba, vports);
37023- atomic_set(&phba->num_rsrc_err, 0);
37024- atomic_set(&phba->num_cmd_success, 0);
37025+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37026+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37027 }
37028
37029 /**
37030diff -urNp linux-2.6.32.43/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.32.43/drivers/scsi/megaraid/megaraid_mbox.c
37031--- linux-2.6.32.43/drivers/scsi/megaraid/megaraid_mbox.c 2011-03-27 14:31:47.000000000 -0400
37032+++ linux-2.6.32.43/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-16 21:46:57.000000000 -0400
37033@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter
37034 int rval;
37035 int i;
37036
37037+ pax_track_stack();
37038+
37039 // Allocate memory for the base list of scb for management module.
37040 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
37041
37042diff -urNp linux-2.6.32.43/drivers/scsi/osd/osd_initiator.c linux-2.6.32.43/drivers/scsi/osd/osd_initiator.c
37043--- linux-2.6.32.43/drivers/scsi/osd/osd_initiator.c 2011-03-27 14:31:47.000000000 -0400
37044+++ linux-2.6.32.43/drivers/scsi/osd/osd_initiator.c 2011-05-16 21:46:57.000000000 -0400
37045@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct
37046 int nelem = ARRAY_SIZE(get_attrs), a = 0;
37047 int ret;
37048
37049+ pax_track_stack();
37050+
37051 or = osd_start_request(od, GFP_KERNEL);
37052 if (!or)
37053 return -ENOMEM;
37054diff -urNp linux-2.6.32.43/drivers/scsi/pmcraid.c linux-2.6.32.43/drivers/scsi/pmcraid.c
37055--- linux-2.6.32.43/drivers/scsi/pmcraid.c 2011-05-10 22:12:01.000000000 -0400
37056+++ linux-2.6.32.43/drivers/scsi/pmcraid.c 2011-05-10 22:12:33.000000000 -0400
37057@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct sc
37058 res->scsi_dev = scsi_dev;
37059 scsi_dev->hostdata = res;
37060 res->change_detected = 0;
37061- atomic_set(&res->read_failures, 0);
37062- atomic_set(&res->write_failures, 0);
37063+ atomic_set_unchecked(&res->read_failures, 0);
37064+ atomic_set_unchecked(&res->write_failures, 0);
37065 rc = 0;
37066 }
37067 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37068@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct
37069
37070 /* If this was a SCSI read/write command keep count of errors */
37071 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37072- atomic_inc(&res->read_failures);
37073+ atomic_inc_unchecked(&res->read_failures);
37074 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37075- atomic_inc(&res->write_failures);
37076+ atomic_inc_unchecked(&res->write_failures);
37077
37078 if (!RES_IS_GSCSI(res->cfg_entry) &&
37079 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37080@@ -4113,7 +4113,7 @@ static void pmcraid_worker_function(stru
37081
37082 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37083 /* add resources only after host is added into system */
37084- if (!atomic_read(&pinstance->expose_resources))
37085+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37086 return;
37087
37088 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
37089@@ -4847,7 +4847,7 @@ static int __devinit pmcraid_init_instan
37090 init_waitqueue_head(&pinstance->reset_wait_q);
37091
37092 atomic_set(&pinstance->outstanding_cmds, 0);
37093- atomic_set(&pinstance->expose_resources, 0);
37094+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37095
37096 INIT_LIST_HEAD(&pinstance->free_res_q);
37097 INIT_LIST_HEAD(&pinstance->used_res_q);
37098@@ -5499,7 +5499,7 @@ static int __devinit pmcraid_probe(
37099 /* Schedule worker thread to handle CCN and take care of adding and
37100 * removing devices to OS
37101 */
37102- atomic_set(&pinstance->expose_resources, 1);
37103+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37104 schedule_work(&pinstance->worker_q);
37105 return rc;
37106
37107diff -urNp linux-2.6.32.43/drivers/scsi/pmcraid.h linux-2.6.32.43/drivers/scsi/pmcraid.h
37108--- linux-2.6.32.43/drivers/scsi/pmcraid.h 2011-03-27 14:31:47.000000000 -0400
37109+++ linux-2.6.32.43/drivers/scsi/pmcraid.h 2011-05-04 17:56:28.000000000 -0400
37110@@ -690,7 +690,7 @@ struct pmcraid_instance {
37111 atomic_t outstanding_cmds;
37112
37113 /* should add/delete resources to mid-layer now ?*/
37114- atomic_t expose_resources;
37115+ atomic_unchecked_t expose_resources;
37116
37117 /* Tasklet to handle deferred processing */
37118 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
37119@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
37120 struct list_head queue; /* link to "to be exposed" resources */
37121 struct pmcraid_config_table_entry cfg_entry;
37122 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37123- atomic_t read_failures; /* count of failed READ commands */
37124- atomic_t write_failures; /* count of failed WRITE commands */
37125+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37126+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37127
37128 /* To indicate add/delete/modify during CCN */
37129 u8 change_detected;
37130diff -urNp linux-2.6.32.43/drivers/scsi/qla2xxx/qla_def.h linux-2.6.32.43/drivers/scsi/qla2xxx/qla_def.h
37131--- linux-2.6.32.43/drivers/scsi/qla2xxx/qla_def.h 2011-03-27 14:31:47.000000000 -0400
37132+++ linux-2.6.32.43/drivers/scsi/qla2xxx/qla_def.h 2011-08-05 20:33:55.000000000 -0400
37133@@ -2089,7 +2089,7 @@ struct isp_operations {
37134
37135 int (*get_flash_version) (struct scsi_qla_host *, void *);
37136 int (*start_scsi) (srb_t *);
37137-};
37138+} __no_const;
37139
37140 /* MSI-X Support *************************************************************/
37141
37142diff -urNp linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_def.h
37143--- linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_def.h 2011-03-27 14:31:47.000000000 -0400
37144+++ linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_def.h 2011-05-04 17:56:28.000000000 -0400
37145@@ -240,7 +240,7 @@ struct ddb_entry {
37146 atomic_t retry_relogin_timer; /* Min Time between relogins
37147 * (4000 only) */
37148 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
37149- atomic_t relogin_retry_count; /* Num of times relogin has been
37150+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37151 * retried */
37152
37153 uint16_t port;
37154diff -urNp linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_init.c
37155--- linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_init.c 2011-03-27 14:31:47.000000000 -0400
37156+++ linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_init.c 2011-05-04 17:56:28.000000000 -0400
37157@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_
37158 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
37159 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37160 atomic_set(&ddb_entry->relogin_timer, 0);
37161- atomic_set(&ddb_entry->relogin_retry_count, 0);
37162+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37163 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
37164 list_add_tail(&ddb_entry->list, &ha->ddb_list);
37165 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
37166@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct s
37167 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
37168 atomic_set(&ddb_entry->port_down_timer,
37169 ha->port_down_retry_count);
37170- atomic_set(&ddb_entry->relogin_retry_count, 0);
37171+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37172 atomic_set(&ddb_entry->relogin_timer, 0);
37173 clear_bit(DF_RELOGIN, &ddb_entry->flags);
37174 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
37175diff -urNp linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_os.c
37176--- linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_os.c 2011-03-27 14:31:47.000000000 -0400
37177+++ linux-2.6.32.43/drivers/scsi/qla4xxx/ql4_os.c 2011-05-04 17:56:28.000000000 -0400
37178@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_ql
37179 ddb_entry->fw_ddb_device_state ==
37180 DDB_DS_SESSION_FAILED) {
37181 /* Reset retry relogin timer */
37182- atomic_inc(&ddb_entry->relogin_retry_count);
37183+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37184 DEBUG2(printk("scsi%ld: index[%d] relogin"
37185 " timed out-retrying"
37186 " relogin (%d)\n",
37187 ha->host_no,
37188 ddb_entry->fw_ddb_index,
37189- atomic_read(&ddb_entry->
37190+ atomic_read_unchecked(&ddb_entry->
37191 relogin_retry_count))
37192 );
37193 start_dpc++;
37194diff -urNp linux-2.6.32.43/drivers/scsi/scsi.c linux-2.6.32.43/drivers/scsi/scsi.c
37195--- linux-2.6.32.43/drivers/scsi/scsi.c 2011-03-27 14:31:47.000000000 -0400
37196+++ linux-2.6.32.43/drivers/scsi/scsi.c 2011-05-04 17:56:28.000000000 -0400
37197@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
37198 unsigned long timeout;
37199 int rtn = 0;
37200
37201- atomic_inc(&cmd->device->iorequest_cnt);
37202+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37203
37204 /* check if the device is still usable */
37205 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37206diff -urNp linux-2.6.32.43/drivers/scsi/scsi_debug.c linux-2.6.32.43/drivers/scsi/scsi_debug.c
37207--- linux-2.6.32.43/drivers/scsi/scsi_debug.c 2011-03-27 14:31:47.000000000 -0400
37208+++ linux-2.6.32.43/drivers/scsi/scsi_debug.c 2011-05-16 21:46:57.000000000 -0400
37209@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_
37210 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
37211 unsigned char *cmd = (unsigned char *)scp->cmnd;
37212
37213+ pax_track_stack();
37214+
37215 if ((errsts = check_readiness(scp, 1, devip)))
37216 return errsts;
37217 memset(arr, 0, sizeof(arr));
37218@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cm
37219 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
37220 unsigned char *cmd = (unsigned char *)scp->cmnd;
37221
37222+ pax_track_stack();
37223+
37224 if ((errsts = check_readiness(scp, 1, devip)))
37225 return errsts;
37226 memset(arr, 0, sizeof(arr));
37227diff -urNp linux-2.6.32.43/drivers/scsi/scsi_lib.c linux-2.6.32.43/drivers/scsi/scsi_lib.c
37228--- linux-2.6.32.43/drivers/scsi/scsi_lib.c 2011-05-10 22:12:01.000000000 -0400
37229+++ linux-2.6.32.43/drivers/scsi/scsi_lib.c 2011-05-10 22:12:33.000000000 -0400
37230@@ -1384,7 +1384,7 @@ static void scsi_kill_request(struct req
37231
37232 scsi_init_cmd_errh(cmd);
37233 cmd->result = DID_NO_CONNECT << 16;
37234- atomic_inc(&cmd->device->iorequest_cnt);
37235+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37236
37237 /*
37238 * SCSI request completion path will do scsi_device_unbusy(),
37239@@ -1415,9 +1415,9 @@ static void scsi_softirq_done(struct req
37240 */
37241 cmd->serial_number = 0;
37242
37243- atomic_inc(&cmd->device->iodone_cnt);
37244+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37245 if (cmd->result)
37246- atomic_inc(&cmd->device->ioerr_cnt);
37247+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37248
37249 disposition = scsi_decide_disposition(cmd);
37250 if (disposition != SUCCESS &&
37251diff -urNp linux-2.6.32.43/drivers/scsi/scsi_sysfs.c linux-2.6.32.43/drivers/scsi/scsi_sysfs.c
37252--- linux-2.6.32.43/drivers/scsi/scsi_sysfs.c 2011-06-25 12:55:34.000000000 -0400
37253+++ linux-2.6.32.43/drivers/scsi/scsi_sysfs.c 2011-06-25 12:56:37.000000000 -0400
37254@@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev,
37255 char *buf) \
37256 { \
37257 struct scsi_device *sdev = to_scsi_device(dev); \
37258- unsigned long long count = atomic_read(&sdev->field); \
37259+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37260 return snprintf(buf, 20, "0x%llx\n", count); \
37261 } \
37262 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37263diff -urNp linux-2.6.32.43/drivers/scsi/scsi_transport_fc.c linux-2.6.32.43/drivers/scsi/scsi_transport_fc.c
37264--- linux-2.6.32.43/drivers/scsi/scsi_transport_fc.c 2011-03-27 14:31:47.000000000 -0400
37265+++ linux-2.6.32.43/drivers/scsi/scsi_transport_fc.c 2011-05-04 17:56:28.000000000 -0400
37266@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
37267 * Netlink Infrastructure
37268 */
37269
37270-static atomic_t fc_event_seq;
37271+static atomic_unchecked_t fc_event_seq;
37272
37273 /**
37274 * fc_get_event_number - Obtain the next sequential FC event number
37275@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
37276 u32
37277 fc_get_event_number(void)
37278 {
37279- return atomic_add_return(1, &fc_event_seq);
37280+ return atomic_add_return_unchecked(1, &fc_event_seq);
37281 }
37282 EXPORT_SYMBOL(fc_get_event_number);
37283
37284@@ -641,7 +641,7 @@ static __init int fc_transport_init(void
37285 {
37286 int error;
37287
37288- atomic_set(&fc_event_seq, 0);
37289+ atomic_set_unchecked(&fc_event_seq, 0);
37290
37291 error = transport_class_register(&fc_host_class);
37292 if (error)
37293diff -urNp linux-2.6.32.43/drivers/scsi/scsi_transport_iscsi.c linux-2.6.32.43/drivers/scsi/scsi_transport_iscsi.c
37294--- linux-2.6.32.43/drivers/scsi/scsi_transport_iscsi.c 2011-03-27 14:31:47.000000000 -0400
37295+++ linux-2.6.32.43/drivers/scsi/scsi_transport_iscsi.c 2011-05-04 17:56:28.000000000 -0400
37296@@ -81,7 +81,7 @@ struct iscsi_internal {
37297 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
37298 };
37299
37300-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37301+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37302 static struct workqueue_struct *iscsi_eh_timer_workq;
37303
37304 /*
37305@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_s
37306 int err;
37307
37308 ihost = shost->shost_data;
37309- session->sid = atomic_add_return(1, &iscsi_session_nr);
37310+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37311
37312 if (id == ISCSI_MAX_TARGET) {
37313 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
37314@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(v
37315 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37316 ISCSI_TRANSPORT_VERSION);
37317
37318- atomic_set(&iscsi_session_nr, 0);
37319+ atomic_set_unchecked(&iscsi_session_nr, 0);
37320
37321 err = class_register(&iscsi_transport_class);
37322 if (err)
37323diff -urNp linux-2.6.32.43/drivers/scsi/scsi_transport_srp.c linux-2.6.32.43/drivers/scsi/scsi_transport_srp.c
37324--- linux-2.6.32.43/drivers/scsi/scsi_transport_srp.c 2011-03-27 14:31:47.000000000 -0400
37325+++ linux-2.6.32.43/drivers/scsi/scsi_transport_srp.c 2011-05-04 17:56:28.000000000 -0400
37326@@ -33,7 +33,7 @@
37327 #include "scsi_transport_srp_internal.h"
37328
37329 struct srp_host_attrs {
37330- atomic_t next_port_id;
37331+ atomic_unchecked_t next_port_id;
37332 };
37333 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37334
37335@@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
37336 struct Scsi_Host *shost = dev_to_shost(dev);
37337 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37338
37339- atomic_set(&srp_host->next_port_id, 0);
37340+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37341 return 0;
37342 }
37343
37344@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
37345 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37346 rport->roles = ids->roles;
37347
37348- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37349+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37350 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37351
37352 transport_setup_device(&rport->dev);
37353diff -urNp linux-2.6.32.43/drivers/scsi/sg.c linux-2.6.32.43/drivers/scsi/sg.c
37354--- linux-2.6.32.43/drivers/scsi/sg.c 2011-03-27 14:31:47.000000000 -0400
37355+++ linux-2.6.32.43/drivers/scsi/sg.c 2011-04-17 15:56:46.000000000 -0400
37356@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
37357 const struct file_operations * fops;
37358 };
37359
37360-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37361+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37362 {"allow_dio", &adio_fops},
37363 {"debug", &debug_fops},
37364 {"def_reserved_size", &dressz_fops},
37365@@ -2307,7 +2307,7 @@ sg_proc_init(void)
37366 {
37367 int k, mask;
37368 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
37369- struct sg_proc_leaf * leaf;
37370+ const struct sg_proc_leaf * leaf;
37371
37372 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
37373 if (!sg_proc_sgp)
37374diff -urNp linux-2.6.32.43/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.32.43/drivers/scsi/sym53c8xx_2/sym_glue.c
37375--- linux-2.6.32.43/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-03-27 14:31:47.000000000 -0400
37376+++ linux-2.6.32.43/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-16 21:46:57.000000000 -0400
37377@@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct p
37378 int do_iounmap = 0;
37379 int do_disable_device = 1;
37380
37381+ pax_track_stack();
37382+
37383 memset(&sym_dev, 0, sizeof(sym_dev));
37384 memset(&nvram, 0, sizeof(nvram));
37385 sym_dev.pdev = pdev;
37386diff -urNp linux-2.6.32.43/drivers/serial/kgdboc.c linux-2.6.32.43/drivers/serial/kgdboc.c
37387--- linux-2.6.32.43/drivers/serial/kgdboc.c 2011-03-27 14:31:47.000000000 -0400
37388+++ linux-2.6.32.43/drivers/serial/kgdboc.c 2011-04-17 15:56:46.000000000 -0400
37389@@ -18,7 +18,7 @@
37390
37391 #define MAX_CONFIG_LEN 40
37392
37393-static struct kgdb_io kgdboc_io_ops;
37394+static const struct kgdb_io kgdboc_io_ops;
37395
37396 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37397 static int configured = -1;
37398@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void
37399 module_put(THIS_MODULE);
37400 }
37401
37402-static struct kgdb_io kgdboc_io_ops = {
37403+static const struct kgdb_io kgdboc_io_ops = {
37404 .name = "kgdboc",
37405 .read_char = kgdboc_get_char,
37406 .write_char = kgdboc_put_char,
37407diff -urNp linux-2.6.32.43/drivers/spi/spi.c linux-2.6.32.43/drivers/spi/spi.c
37408--- linux-2.6.32.43/drivers/spi/spi.c 2011-03-27 14:31:47.000000000 -0400
37409+++ linux-2.6.32.43/drivers/spi/spi.c 2011-05-04 17:56:28.000000000 -0400
37410@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, str
37411 EXPORT_SYMBOL_GPL(spi_sync);
37412
37413 /* portable code must never pass more than 32 bytes */
37414-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37415+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
37416
37417 static u8 *buf;
37418
37419diff -urNp linux-2.6.32.43/drivers/ssb/driver_gige.c linux-2.6.32.43/drivers/ssb/driver_gige.c
37420--- linux-2.6.32.43/drivers/ssb/driver_gige.c 2011-03-27 14:31:47.000000000 -0400
37421+++ linux-2.6.32.43/drivers/ssb/driver_gige.c 2011-08-05 20:33:55.000000000 -0400
37422@@ -180,8 +180,8 @@ static int ssb_gige_probe(struct ssb_dev
37423 dev->pci_controller.io_resource = &dev->io_resource;
37424 dev->pci_controller.mem_resource = &dev->mem_resource;
37425 dev->pci_controller.io_map_base = 0x800;
37426- dev->pci_ops.read = ssb_gige_pci_read_config;
37427- dev->pci_ops.write = ssb_gige_pci_write_config;
37428+ *(void **)&dev->pci_ops.read = ssb_gige_pci_read_config;
37429+ *(void **)&dev->pci_ops.write = ssb_gige_pci_write_config;
37430
37431 dev->io_resource.name = SSB_GIGE_IO_RES_NAME;
37432 dev->io_resource.start = 0x800;
37433diff -urNp linux-2.6.32.43/drivers/staging/android/binder.c linux-2.6.32.43/drivers/staging/android/binder.c
37434--- linux-2.6.32.43/drivers/staging/android/binder.c 2011-03-27 14:31:47.000000000 -0400
37435+++ linux-2.6.32.43/drivers/staging/android/binder.c 2011-04-17 15:56:46.000000000 -0400
37436@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_a
37437 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
37438 }
37439
37440-static struct vm_operations_struct binder_vm_ops = {
37441+static const struct vm_operations_struct binder_vm_ops = {
37442 .open = binder_vma_open,
37443 .close = binder_vma_close,
37444 };
37445diff -urNp linux-2.6.32.43/drivers/staging/b3dfg/b3dfg.c linux-2.6.32.43/drivers/staging/b3dfg/b3dfg.c
37446--- linux-2.6.32.43/drivers/staging/b3dfg/b3dfg.c 2011-03-27 14:31:47.000000000 -0400
37447+++ linux-2.6.32.43/drivers/staging/b3dfg/b3dfg.c 2011-04-17 15:56:46.000000000 -0400
37448@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_are
37449 return VM_FAULT_NOPAGE;
37450 }
37451
37452-static struct vm_operations_struct b3dfg_vm_ops = {
37453+static const struct vm_operations_struct b3dfg_vm_ops = {
37454 .fault = b3dfg_vma_fault,
37455 };
37456
37457@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp,
37458 return r;
37459 }
37460
37461-static struct file_operations b3dfg_fops = {
37462+static const struct file_operations b3dfg_fops = {
37463 .owner = THIS_MODULE,
37464 .open = b3dfg_open,
37465 .release = b3dfg_release,
37466diff -urNp linux-2.6.32.43/drivers/staging/comedi/comedi_fops.c linux-2.6.32.43/drivers/staging/comedi/comedi_fops.c
37467--- linux-2.6.32.43/drivers/staging/comedi/comedi_fops.c 2011-03-27 14:31:47.000000000 -0400
37468+++ linux-2.6.32.43/drivers/staging/comedi/comedi_fops.c 2011-04-17 15:56:46.000000000 -0400
37469@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct
37470 mutex_unlock(&dev->mutex);
37471 }
37472
37473-static struct vm_operations_struct comedi_vm_ops = {
37474+static const struct vm_operations_struct comedi_vm_ops = {
37475 .close = comedi_unmap,
37476 };
37477
37478diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/adsp_driver.c linux-2.6.32.43/drivers/staging/dream/qdsp5/adsp_driver.c
37479--- linux-2.6.32.43/drivers/staging/dream/qdsp5/adsp_driver.c 2011-03-27 14:31:47.000000000 -0400
37480+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/adsp_driver.c 2011-04-17 15:56:46.000000000 -0400
37481@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_devi
37482 static dev_t adsp_devno;
37483 static struct class *adsp_class;
37484
37485-static struct file_operations adsp_fops = {
37486+static const struct file_operations adsp_fops = {
37487 .owner = THIS_MODULE,
37488 .open = adsp_open,
37489 .unlocked_ioctl = adsp_ioctl,
37490diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_aac.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_aac.c
37491--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_aac.c 2011-03-27 14:31:47.000000000 -0400
37492+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_aac.c 2011-04-17 15:56:46.000000000 -0400
37493@@ -1022,7 +1022,7 @@ done:
37494 return rc;
37495 }
37496
37497-static struct file_operations audio_aac_fops = {
37498+static const struct file_operations audio_aac_fops = {
37499 .owner = THIS_MODULE,
37500 .open = audio_open,
37501 .release = audio_release,
37502diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_amrnb.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_amrnb.c
37503--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-03-27 14:31:47.000000000 -0400
37504+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-04-17 15:56:46.000000000 -0400
37505@@ -833,7 +833,7 @@ done:
37506 return rc;
37507 }
37508
37509-static struct file_operations audio_amrnb_fops = {
37510+static const struct file_operations audio_amrnb_fops = {
37511 .owner = THIS_MODULE,
37512 .open = audamrnb_open,
37513 .release = audamrnb_release,
37514diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_evrc.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_evrc.c
37515--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_evrc.c 2011-03-27 14:31:47.000000000 -0400
37516+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_evrc.c 2011-04-17 15:56:46.000000000 -0400
37517@@ -805,7 +805,7 @@ dma_fail:
37518 return rc;
37519 }
37520
37521-static struct file_operations audio_evrc_fops = {
37522+static const struct file_operations audio_evrc_fops = {
37523 .owner = THIS_MODULE,
37524 .open = audevrc_open,
37525 .release = audevrc_release,
37526diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_in.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_in.c
37527--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_in.c 2011-03-27 14:31:47.000000000 -0400
37528+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_in.c 2011-04-17 15:56:46.000000000 -0400
37529@@ -913,7 +913,7 @@ static int audpre_open(struct inode *ino
37530 return 0;
37531 }
37532
37533-static struct file_operations audio_fops = {
37534+static const struct file_operations audio_fops = {
37535 .owner = THIS_MODULE,
37536 .open = audio_in_open,
37537 .release = audio_in_release,
37538@@ -922,7 +922,7 @@ static struct file_operations audio_fops
37539 .unlocked_ioctl = audio_in_ioctl,
37540 };
37541
37542-static struct file_operations audpre_fops = {
37543+static const struct file_operations audpre_fops = {
37544 .owner = THIS_MODULE,
37545 .open = audpre_open,
37546 .unlocked_ioctl = audpre_ioctl,
37547diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_mp3.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_mp3.c
37548--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_mp3.c 2011-03-27 14:31:47.000000000 -0400
37549+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_mp3.c 2011-04-17 15:56:46.000000000 -0400
37550@@ -941,7 +941,7 @@ done:
37551 return rc;
37552 }
37553
37554-static struct file_operations audio_mp3_fops = {
37555+static const struct file_operations audio_mp3_fops = {
37556 .owner = THIS_MODULE,
37557 .open = audio_open,
37558 .release = audio_release,
37559diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_out.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_out.c
37560--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_out.c 2011-03-27 14:31:47.000000000 -0400
37561+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_out.c 2011-04-17 15:56:46.000000000 -0400
37562@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inod
37563 return 0;
37564 }
37565
37566-static struct file_operations audio_fops = {
37567+static const struct file_operations audio_fops = {
37568 .owner = THIS_MODULE,
37569 .open = audio_open,
37570 .release = audio_release,
37571@@ -819,7 +819,7 @@ static struct file_operations audio_fops
37572 .unlocked_ioctl = audio_ioctl,
37573 };
37574
37575-static struct file_operations audpp_fops = {
37576+static const struct file_operations audpp_fops = {
37577 .owner = THIS_MODULE,
37578 .open = audpp_open,
37579 .unlocked_ioctl = audpp_ioctl,
37580diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_qcelp.c linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_qcelp.c
37581--- linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-03-27 14:31:47.000000000 -0400
37582+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-04-17 15:56:46.000000000 -0400
37583@@ -816,7 +816,7 @@ err:
37584 return rc;
37585 }
37586
37587-static struct file_operations audio_qcelp_fops = {
37588+static const struct file_operations audio_qcelp_fops = {
37589 .owner = THIS_MODULE,
37590 .open = audqcelp_open,
37591 .release = audqcelp_release,
37592diff -urNp linux-2.6.32.43/drivers/staging/dream/qdsp5/snd.c linux-2.6.32.43/drivers/staging/dream/qdsp5/snd.c
37593--- linux-2.6.32.43/drivers/staging/dream/qdsp5/snd.c 2011-03-27 14:31:47.000000000 -0400
37594+++ linux-2.6.32.43/drivers/staging/dream/qdsp5/snd.c 2011-04-17 15:56:46.000000000 -0400
37595@@ -242,7 +242,7 @@ err:
37596 return rc;
37597 }
37598
37599-static struct file_operations snd_fops = {
37600+static const struct file_operations snd_fops = {
37601 .owner = THIS_MODULE,
37602 .open = snd_open,
37603 .release = snd_release,
37604diff -urNp linux-2.6.32.43/drivers/staging/dream/smd/smd_qmi.c linux-2.6.32.43/drivers/staging/dream/smd/smd_qmi.c
37605--- linux-2.6.32.43/drivers/staging/dream/smd/smd_qmi.c 2011-03-27 14:31:47.000000000 -0400
37606+++ linux-2.6.32.43/drivers/staging/dream/smd/smd_qmi.c 2011-04-17 15:56:46.000000000 -0400
37607@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip,
37608 return 0;
37609 }
37610
37611-static struct file_operations qmi_fops = {
37612+static const struct file_operations qmi_fops = {
37613 .owner = THIS_MODULE,
37614 .read = qmi_read,
37615 .write = qmi_write,
37616diff -urNp linux-2.6.32.43/drivers/staging/dream/smd/smd_rpcrouter_device.c linux-2.6.32.43/drivers/staging/dream/smd/smd_rpcrouter_device.c
37617--- linux-2.6.32.43/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-03-27 14:31:47.000000000 -0400
37618+++ linux-2.6.32.43/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-04-17 15:56:46.000000000 -0400
37619@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file
37620 return rc;
37621 }
37622
37623-static struct file_operations rpcrouter_server_fops = {
37624+static const struct file_operations rpcrouter_server_fops = {
37625 .owner = THIS_MODULE,
37626 .open = rpcrouter_open,
37627 .release = rpcrouter_release,
37628@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_
37629 .unlocked_ioctl = rpcrouter_ioctl,
37630 };
37631
37632-static struct file_operations rpcrouter_router_fops = {
37633+static const struct file_operations rpcrouter_router_fops = {
37634 .owner = THIS_MODULE,
37635 .open = rpcrouter_open,
37636 .release = rpcrouter_release,
37637diff -urNp linux-2.6.32.43/drivers/staging/dst/dcore.c linux-2.6.32.43/drivers/staging/dst/dcore.c
37638--- linux-2.6.32.43/drivers/staging/dst/dcore.c 2011-03-27 14:31:47.000000000 -0400
37639+++ linux-2.6.32.43/drivers/staging/dst/dcore.c 2011-04-17 15:56:46.000000000 -0400
37640@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendi
37641 return 0;
37642 }
37643
37644-static struct block_device_operations dst_blk_ops = {
37645+static const struct block_device_operations dst_blk_ops = {
37646 .open = dst_bdev_open,
37647 .release = dst_bdev_release,
37648 .owner = THIS_MODULE,
37649@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(s
37650 n->size = ctl->size;
37651
37652 atomic_set(&n->refcnt, 1);
37653- atomic_long_set(&n->gen, 0);
37654+ atomic_long_set_unchecked(&n->gen, 0);
37655 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
37656
37657 err = dst_node_sysfs_init(n);
37658diff -urNp linux-2.6.32.43/drivers/staging/dst/trans.c linux-2.6.32.43/drivers/staging/dst/trans.c
37659--- linux-2.6.32.43/drivers/staging/dst/trans.c 2011-03-27 14:31:47.000000000 -0400
37660+++ linux-2.6.32.43/drivers/staging/dst/trans.c 2011-04-17 15:56:46.000000000 -0400
37661@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n,
37662 t->error = 0;
37663 t->retries = 0;
37664 atomic_set(&t->refcnt, 1);
37665- t->gen = atomic_long_inc_return(&n->gen);
37666+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
37667
37668 t->enc = bio_data_dir(bio);
37669 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
37670diff -urNp linux-2.6.32.43/drivers/staging/et131x/et1310_tx.c linux-2.6.32.43/drivers/staging/et131x/et1310_tx.c
37671--- linux-2.6.32.43/drivers/staging/et131x/et1310_tx.c 2011-03-27 14:31:47.000000000 -0400
37672+++ linux-2.6.32.43/drivers/staging/et131x/et1310_tx.c 2011-05-04 17:56:28.000000000 -0400
37673@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(stru
37674 struct net_device_stats *stats = &etdev->net_stats;
37675
37676 if (pMpTcb->Flags & fMP_DEST_BROAD)
37677- atomic_inc(&etdev->Stats.brdcstxmt);
37678+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
37679 else if (pMpTcb->Flags & fMP_DEST_MULTI)
37680- atomic_inc(&etdev->Stats.multixmt);
37681+ atomic_inc_unchecked(&etdev->Stats.multixmt);
37682 else
37683- atomic_inc(&etdev->Stats.unixmt);
37684+ atomic_inc_unchecked(&etdev->Stats.unixmt);
37685
37686 if (pMpTcb->Packet) {
37687 stats->tx_bytes += pMpTcb->Packet->len;
37688diff -urNp linux-2.6.32.43/drivers/staging/et131x/et131x_adapter.h linux-2.6.32.43/drivers/staging/et131x/et131x_adapter.h
37689--- linux-2.6.32.43/drivers/staging/et131x/et131x_adapter.h 2011-03-27 14:31:47.000000000 -0400
37690+++ linux-2.6.32.43/drivers/staging/et131x/et131x_adapter.h 2011-05-04 17:56:28.000000000 -0400
37691@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
37692 * operations
37693 */
37694 u32 unircv; /* # multicast packets received */
37695- atomic_t unixmt; /* # multicast packets for Tx */
37696+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
37697 u32 multircv; /* # multicast packets received */
37698- atomic_t multixmt; /* # multicast packets for Tx */
37699+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
37700 u32 brdcstrcv; /* # broadcast packets received */
37701- atomic_t brdcstxmt; /* # broadcast packets for Tx */
37702+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
37703 u32 norcvbuf; /* # Rx packets discarded */
37704 u32 noxmtbuf; /* # Tx packets discarded */
37705
37706diff -urNp linux-2.6.32.43/drivers/staging/go7007/go7007-v4l2.c linux-2.6.32.43/drivers/staging/go7007/go7007-v4l2.c
37707--- linux-2.6.32.43/drivers/staging/go7007/go7007-v4l2.c 2011-03-27 14:31:47.000000000 -0400
37708+++ linux-2.6.32.43/drivers/staging/go7007/go7007-v4l2.c 2011-04-17 15:56:46.000000000 -0400
37709@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_are
37710 return 0;
37711 }
37712
37713-static struct vm_operations_struct go7007_vm_ops = {
37714+static const struct vm_operations_struct go7007_vm_ops = {
37715 .open = go7007_vm_open,
37716 .close = go7007_vm_close,
37717 .fault = go7007_vm_fault,
37718diff -urNp linux-2.6.32.43/drivers/staging/hv/blkvsc_drv.c linux-2.6.32.43/drivers/staging/hv/blkvsc_drv.c
37719--- linux-2.6.32.43/drivers/staging/hv/blkvsc_drv.c 2011-03-27 14:31:47.000000000 -0400
37720+++ linux-2.6.32.43/drivers/staging/hv/blkvsc_drv.c 2011-04-17 15:56:46.000000000 -0400
37721@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKV
37722 /* The one and only one */
37723 static struct blkvsc_driver_context g_blkvsc_drv;
37724
37725-static struct block_device_operations block_ops = {
37726+static const struct block_device_operations block_ops = {
37727 .owner = THIS_MODULE,
37728 .open = blkvsc_open,
37729 .release = blkvsc_release,
37730diff -urNp linux-2.6.32.43/drivers/staging/hv/Channel.c linux-2.6.32.43/drivers/staging/hv/Channel.c
37731--- linux-2.6.32.43/drivers/staging/hv/Channel.c 2011-04-17 17:00:52.000000000 -0400
37732+++ linux-2.6.32.43/drivers/staging/hv/Channel.c 2011-05-04 17:56:28.000000000 -0400
37733@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vm
37734
37735 DPRINT_ENTER(VMBUS);
37736
37737- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
37738- atomic_inc(&gVmbusConnection.NextGpadlHandle);
37739+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
37740+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
37741
37742 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
37743 ASSERT(msgInfo != NULL);
37744diff -urNp linux-2.6.32.43/drivers/staging/hv/Hv.c linux-2.6.32.43/drivers/staging/hv/Hv.c
37745--- linux-2.6.32.43/drivers/staging/hv/Hv.c 2011-03-27 14:31:47.000000000 -0400
37746+++ linux-2.6.32.43/drivers/staging/hv/Hv.c 2011-04-17 15:56:46.000000000 -0400
37747@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, vo
37748 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
37749 u32 outputAddressHi = outputAddress >> 32;
37750 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
37751- volatile void *hypercallPage = gHvContext.HypercallPage;
37752+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
37753
37754 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
37755 Control, Input, Output);
37756diff -urNp linux-2.6.32.43/drivers/staging/hv/vmbus_drv.c linux-2.6.32.43/drivers/staging/hv/vmbus_drv.c
37757--- linux-2.6.32.43/drivers/staging/hv/vmbus_drv.c 2011-03-27 14:31:47.000000000 -0400
37758+++ linux-2.6.32.43/drivers/staging/hv/vmbus_drv.c 2011-05-04 17:56:28.000000000 -0400
37759@@ -532,7 +532,7 @@ static int vmbus_child_device_register(s
37760 to_device_context(root_device_obj);
37761 struct device_context *child_device_ctx =
37762 to_device_context(child_device_obj);
37763- static atomic_t device_num = ATOMIC_INIT(0);
37764+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
37765
37766 DPRINT_ENTER(VMBUS_DRV);
37767
37768@@ -541,7 +541,7 @@ static int vmbus_child_device_register(s
37769
37770 /* Set the device name. Otherwise, device_register() will fail. */
37771 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
37772- atomic_inc_return(&device_num));
37773+ atomic_inc_return_unchecked(&device_num));
37774
37775 /* The new device belongs to this bus */
37776 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
37777diff -urNp linux-2.6.32.43/drivers/staging/hv/VmbusPrivate.h linux-2.6.32.43/drivers/staging/hv/VmbusPrivate.h
37778--- linux-2.6.32.43/drivers/staging/hv/VmbusPrivate.h 2011-04-17 17:00:52.000000000 -0400
37779+++ linux-2.6.32.43/drivers/staging/hv/VmbusPrivate.h 2011-05-04 17:56:28.000000000 -0400
37780@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
37781 struct VMBUS_CONNECTION {
37782 enum VMBUS_CONNECT_STATE ConnectState;
37783
37784- atomic_t NextGpadlHandle;
37785+ atomic_unchecked_t NextGpadlHandle;
37786
37787 /*
37788 * Represents channel interrupts. Each bit position represents a
37789diff -urNp linux-2.6.32.43/drivers/staging/octeon/ethernet.c linux-2.6.32.43/drivers/staging/octeon/ethernet.c
37790--- linux-2.6.32.43/drivers/staging/octeon/ethernet.c 2011-03-27 14:31:47.000000000 -0400
37791+++ linux-2.6.32.43/drivers/staging/octeon/ethernet.c 2011-05-04 17:56:28.000000000 -0400
37792@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_
37793 * since the RX tasklet also increments it.
37794 */
37795 #ifdef CONFIG_64BIT
37796- atomic64_add(rx_status.dropped_packets,
37797- (atomic64_t *)&priv->stats.rx_dropped);
37798+ atomic64_add_unchecked(rx_status.dropped_packets,
37799+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37800 #else
37801- atomic_add(rx_status.dropped_packets,
37802- (atomic_t *)&priv->stats.rx_dropped);
37803+ atomic_add_unchecked(rx_status.dropped_packets,
37804+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37805 #endif
37806 }
37807
37808diff -urNp linux-2.6.32.43/drivers/staging/octeon/ethernet-rx.c linux-2.6.32.43/drivers/staging/octeon/ethernet-rx.c
37809--- linux-2.6.32.43/drivers/staging/octeon/ethernet-rx.c 2011-03-27 14:31:47.000000000 -0400
37810+++ linux-2.6.32.43/drivers/staging/octeon/ethernet-rx.c 2011-05-04 17:56:28.000000000 -0400
37811@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long un
37812 /* Increment RX stats for virtual ports */
37813 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37814 #ifdef CONFIG_64BIT
37815- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37816- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37817+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37818+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37819 #else
37820- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37821- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37822+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37823+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37824 #endif
37825 }
37826 netif_receive_skb(skb);
37827@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long un
37828 dev->name);
37829 */
37830 #ifdef CONFIG_64BIT
37831- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37832+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
37833 #else
37834- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37835+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
37836 #endif
37837 dev_kfree_skb_irq(skb);
37838 }
37839diff -urNp linux-2.6.32.43/drivers/staging/panel/panel.c linux-2.6.32.43/drivers/staging/panel/panel.c
37840--- linux-2.6.32.43/drivers/staging/panel/panel.c 2011-03-27 14:31:47.000000000 -0400
37841+++ linux-2.6.32.43/drivers/staging/panel/panel.c 2011-04-17 15:56:46.000000000 -0400
37842@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *ino
37843 return 0;
37844 }
37845
37846-static struct file_operations lcd_fops = {
37847+static const struct file_operations lcd_fops = {
37848 .write = lcd_write,
37849 .open = lcd_open,
37850 .release = lcd_release,
37851@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *
37852 return 0;
37853 }
37854
37855-static struct file_operations keypad_fops = {
37856+static const struct file_operations keypad_fops = {
37857 .read = keypad_read, /* read */
37858 .open = keypad_open, /* open */
37859 .release = keypad_release, /* close */
37860diff -urNp linux-2.6.32.43/drivers/staging/phison/phison.c linux-2.6.32.43/drivers/staging/phison/phison.c
37861--- linux-2.6.32.43/drivers/staging/phison/phison.c 2011-03-27 14:31:47.000000000 -0400
37862+++ linux-2.6.32.43/drivers/staging/phison/phison.c 2011-04-17 15:56:46.000000000 -0400
37863@@ -43,7 +43,7 @@ static struct scsi_host_template phison_
37864 ATA_BMDMA_SHT(DRV_NAME),
37865 };
37866
37867-static struct ata_port_operations phison_ops = {
37868+static const struct ata_port_operations phison_ops = {
37869 .inherits = &ata_bmdma_port_ops,
37870 .prereset = phison_pre_reset,
37871 };
37872diff -urNp linux-2.6.32.43/drivers/staging/poch/poch.c linux-2.6.32.43/drivers/staging/poch/poch.c
37873--- linux-2.6.32.43/drivers/staging/poch/poch.c 2011-03-27 14:31:47.000000000 -0400
37874+++ linux-2.6.32.43/drivers/staging/poch/poch.c 2011-04-17 15:56:46.000000000 -0400
37875@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inod
37876 return 0;
37877 }
37878
37879-static struct file_operations poch_fops = {
37880+static const struct file_operations poch_fops = {
37881 .owner = THIS_MODULE,
37882 .open = poch_open,
37883 .release = poch_release,
37884diff -urNp linux-2.6.32.43/drivers/staging/pohmelfs/inode.c linux-2.6.32.43/drivers/staging/pohmelfs/inode.c
37885--- linux-2.6.32.43/drivers/staging/pohmelfs/inode.c 2011-03-27 14:31:47.000000000 -0400
37886+++ linux-2.6.32.43/drivers/staging/pohmelfs/inode.c 2011-05-04 17:56:20.000000000 -0400
37887@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct su
37888 mutex_init(&psb->mcache_lock);
37889 psb->mcache_root = RB_ROOT;
37890 psb->mcache_timeout = msecs_to_jiffies(5000);
37891- atomic_long_set(&psb->mcache_gen, 0);
37892+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
37893
37894 psb->trans_max_pages = 100;
37895
37896@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct su
37897 INIT_LIST_HEAD(&psb->crypto_ready_list);
37898 INIT_LIST_HEAD(&psb->crypto_active_list);
37899
37900- atomic_set(&psb->trans_gen, 1);
37901+ atomic_set_unchecked(&psb->trans_gen, 1);
37902 atomic_long_set(&psb->total_inodes, 0);
37903
37904 mutex_init(&psb->state_lock);
37905diff -urNp linux-2.6.32.43/drivers/staging/pohmelfs/mcache.c linux-2.6.32.43/drivers/staging/pohmelfs/mcache.c
37906--- linux-2.6.32.43/drivers/staging/pohmelfs/mcache.c 2011-03-27 14:31:47.000000000 -0400
37907+++ linux-2.6.32.43/drivers/staging/pohmelfs/mcache.c 2011-04-17 15:56:46.000000000 -0400
37908@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
37909 m->data = data;
37910 m->start = start;
37911 m->size = size;
37912- m->gen = atomic_long_inc_return(&psb->mcache_gen);
37913+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
37914
37915 mutex_lock(&psb->mcache_lock);
37916 err = pohmelfs_mcache_insert(psb, m);
37917diff -urNp linux-2.6.32.43/drivers/staging/pohmelfs/netfs.h linux-2.6.32.43/drivers/staging/pohmelfs/netfs.h
37918--- linux-2.6.32.43/drivers/staging/pohmelfs/netfs.h 2011-03-27 14:31:47.000000000 -0400
37919+++ linux-2.6.32.43/drivers/staging/pohmelfs/netfs.h 2011-05-04 17:56:20.000000000 -0400
37920@@ -570,14 +570,14 @@ struct pohmelfs_config;
37921 struct pohmelfs_sb {
37922 struct rb_root mcache_root;
37923 struct mutex mcache_lock;
37924- atomic_long_t mcache_gen;
37925+ atomic_long_unchecked_t mcache_gen;
37926 unsigned long mcache_timeout;
37927
37928 unsigned int idx;
37929
37930 unsigned int trans_retries;
37931
37932- atomic_t trans_gen;
37933+ atomic_unchecked_t trans_gen;
37934
37935 unsigned int crypto_attached_size;
37936 unsigned int crypto_align_size;
37937diff -urNp linux-2.6.32.43/drivers/staging/pohmelfs/trans.c linux-2.6.32.43/drivers/staging/pohmelfs/trans.c
37938--- linux-2.6.32.43/drivers/staging/pohmelfs/trans.c 2011-03-27 14:31:47.000000000 -0400
37939+++ linux-2.6.32.43/drivers/staging/pohmelfs/trans.c 2011-05-04 17:56:28.000000000 -0400
37940@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
37941 int err;
37942 struct netfs_cmd *cmd = t->iovec.iov_base;
37943
37944- t->gen = atomic_inc_return(&psb->trans_gen);
37945+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
37946
37947 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
37948 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
37949diff -urNp linux-2.6.32.43/drivers/staging/sep/sep_driver.c linux-2.6.32.43/drivers/staging/sep/sep_driver.c
37950--- linux-2.6.32.43/drivers/staging/sep/sep_driver.c 2011-03-27 14:31:47.000000000 -0400
37951+++ linux-2.6.32.43/drivers/staging/sep/sep_driver.c 2011-04-17 15:56:46.000000000 -0400
37952@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver
37953 static dev_t sep_devno;
37954
37955 /* the files operations structure of the driver */
37956-static struct file_operations sep_file_operations = {
37957+static const struct file_operations sep_file_operations = {
37958 .owner = THIS_MODULE,
37959 .ioctl = sep_ioctl,
37960 .poll = sep_poll,
37961diff -urNp linux-2.6.32.43/drivers/staging/usbip/vhci.h linux-2.6.32.43/drivers/staging/usbip/vhci.h
37962--- linux-2.6.32.43/drivers/staging/usbip/vhci.h 2011-03-27 14:31:47.000000000 -0400
37963+++ linux-2.6.32.43/drivers/staging/usbip/vhci.h 2011-05-04 17:56:28.000000000 -0400
37964@@ -92,7 +92,7 @@ struct vhci_hcd {
37965 unsigned resuming:1;
37966 unsigned long re_timeout;
37967
37968- atomic_t seqnum;
37969+ atomic_unchecked_t seqnum;
37970
37971 /*
37972 * NOTE:
37973diff -urNp linux-2.6.32.43/drivers/staging/usbip/vhci_hcd.c linux-2.6.32.43/drivers/staging/usbip/vhci_hcd.c
37974--- linux-2.6.32.43/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:01.000000000 -0400
37975+++ linux-2.6.32.43/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:33.000000000 -0400
37976@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
37977 return;
37978 }
37979
37980- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37981+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37982 if (priv->seqnum == 0xffff)
37983 usbip_uinfo("seqnum max\n");
37984
37985@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_h
37986 return -ENOMEM;
37987 }
37988
37989- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37990+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37991 if (unlink->seqnum == 0xffff)
37992 usbip_uinfo("seqnum max\n");
37993
37994@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hc
37995 vdev->rhport = rhport;
37996 }
37997
37998- atomic_set(&vhci->seqnum, 0);
37999+ atomic_set_unchecked(&vhci->seqnum, 0);
38000 spin_lock_init(&vhci->lock);
38001
38002
38003diff -urNp linux-2.6.32.43/drivers/staging/usbip/vhci_rx.c linux-2.6.32.43/drivers/staging/usbip/vhci_rx.c
38004--- linux-2.6.32.43/drivers/staging/usbip/vhci_rx.c 2011-04-17 17:00:52.000000000 -0400
38005+++ linux-2.6.32.43/drivers/staging/usbip/vhci_rx.c 2011-05-04 17:56:28.000000000 -0400
38006@@ -78,7 +78,7 @@ static void vhci_recv_ret_submit(struct
38007 usbip_uerr("cannot find a urb of seqnum %u\n",
38008 pdu->base.seqnum);
38009 usbip_uinfo("max seqnum %d\n",
38010- atomic_read(&the_controller->seqnum));
38011+ atomic_read_unchecked(&the_controller->seqnum));
38012 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38013 return;
38014 }
38015diff -urNp linux-2.6.32.43/drivers/staging/vme/devices/vme_user.c linux-2.6.32.43/drivers/staging/vme/devices/vme_user.c
38016--- linux-2.6.32.43/drivers/staging/vme/devices/vme_user.c 2011-03-27 14:31:47.000000000 -0400
38017+++ linux-2.6.32.43/drivers/staging/vme/devices/vme_user.c 2011-04-17 15:56:46.000000000 -0400
38018@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *
38019 static int __init vme_user_probe(struct device *, int, int);
38020 static int __exit vme_user_remove(struct device *, int, int);
38021
38022-static struct file_operations vme_user_fops = {
38023+static const struct file_operations vme_user_fops = {
38024 .open = vme_user_open,
38025 .release = vme_user_release,
38026 .read = vme_user_read,
38027diff -urNp linux-2.6.32.43/drivers/telephony/ixj.c linux-2.6.32.43/drivers/telephony/ixj.c
38028--- linux-2.6.32.43/drivers/telephony/ixj.c 2011-03-27 14:31:47.000000000 -0400
38029+++ linux-2.6.32.43/drivers/telephony/ixj.c 2011-05-16 21:46:57.000000000 -0400
38030@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
38031 bool mContinue;
38032 char *pIn, *pOut;
38033
38034+ pax_track_stack();
38035+
38036 if (!SCI_Prepare(j))
38037 return 0;
38038
38039diff -urNp linux-2.6.32.43/drivers/uio/uio.c linux-2.6.32.43/drivers/uio/uio.c
38040--- linux-2.6.32.43/drivers/uio/uio.c 2011-03-27 14:31:47.000000000 -0400
38041+++ linux-2.6.32.43/drivers/uio/uio.c 2011-05-04 17:56:20.000000000 -0400
38042@@ -23,6 +23,7 @@
38043 #include <linux/string.h>
38044 #include <linux/kobject.h>
38045 #include <linux/uio_driver.h>
38046+#include <asm/local.h>
38047
38048 #define UIO_MAX_DEVICES 255
38049
38050@@ -30,10 +31,10 @@ struct uio_device {
38051 struct module *owner;
38052 struct device *dev;
38053 int minor;
38054- atomic_t event;
38055+ atomic_unchecked_t event;
38056 struct fasync_struct *async_queue;
38057 wait_queue_head_t wait;
38058- int vma_count;
38059+ local_t vma_count;
38060 struct uio_info *info;
38061 struct kobject *map_dir;
38062 struct kobject *portio_dir;
38063@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobj
38064 return entry->show(mem, buf);
38065 }
38066
38067-static struct sysfs_ops map_sysfs_ops = {
38068+static const struct sysfs_ops map_sysfs_ops = {
38069 .show = map_type_show,
38070 };
38071
38072@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct k
38073 return entry->show(port, buf);
38074 }
38075
38076-static struct sysfs_ops portio_sysfs_ops = {
38077+static const struct sysfs_ops portio_sysfs_ops = {
38078 .show = portio_type_show,
38079 };
38080
38081@@ -255,7 +256,7 @@ static ssize_t show_event(struct device
38082 struct uio_device *idev = dev_get_drvdata(dev);
38083 if (idev)
38084 return sprintf(buf, "%u\n",
38085- (unsigned int)atomic_read(&idev->event));
38086+ (unsigned int)atomic_read_unchecked(&idev->event));
38087 else
38088 return -ENODEV;
38089 }
38090@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *i
38091 {
38092 struct uio_device *idev = info->uio_dev;
38093
38094- atomic_inc(&idev->event);
38095+ atomic_inc_unchecked(&idev->event);
38096 wake_up_interruptible(&idev->wait);
38097 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38098 }
38099@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode,
38100 }
38101
38102 listener->dev = idev;
38103- listener->event_count = atomic_read(&idev->event);
38104+ listener->event_count = atomic_read_unchecked(&idev->event);
38105 filep->private_data = listener;
38106
38107 if (idev->info->open) {
38108@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file
38109 return -EIO;
38110
38111 poll_wait(filep, &idev->wait, wait);
38112- if (listener->event_count != atomic_read(&idev->event))
38113+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38114 return POLLIN | POLLRDNORM;
38115 return 0;
38116 }
38117@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *fil
38118 do {
38119 set_current_state(TASK_INTERRUPTIBLE);
38120
38121- event_count = atomic_read(&idev->event);
38122+ event_count = atomic_read_unchecked(&idev->event);
38123 if (event_count != listener->event_count) {
38124 if (copy_to_user(buf, &event_count, count))
38125 retval = -EFAULT;
38126@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_
38127 static void uio_vma_open(struct vm_area_struct *vma)
38128 {
38129 struct uio_device *idev = vma->vm_private_data;
38130- idev->vma_count++;
38131+ local_inc(&idev->vma_count);
38132 }
38133
38134 static void uio_vma_close(struct vm_area_struct *vma)
38135 {
38136 struct uio_device *idev = vma->vm_private_data;
38137- idev->vma_count--;
38138+ local_dec(&idev->vma_count);
38139 }
38140
38141 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38142@@ -840,7 +841,7 @@ int __uio_register_device(struct module
38143 idev->owner = owner;
38144 idev->info = info;
38145 init_waitqueue_head(&idev->wait);
38146- atomic_set(&idev->event, 0);
38147+ atomic_set_unchecked(&idev->event, 0);
38148
38149 ret = uio_get_minor(idev);
38150 if (ret)
38151diff -urNp linux-2.6.32.43/drivers/usb/atm/usbatm.c linux-2.6.32.43/drivers/usb/atm/usbatm.c
38152--- linux-2.6.32.43/drivers/usb/atm/usbatm.c 2011-03-27 14:31:47.000000000 -0400
38153+++ linux-2.6.32.43/drivers/usb/atm/usbatm.c 2011-04-17 15:56:46.000000000 -0400
38154@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(stru
38155 if (printk_ratelimit())
38156 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38157 __func__, vpi, vci);
38158- atomic_inc(&vcc->stats->rx_err);
38159+ atomic_inc_unchecked(&vcc->stats->rx_err);
38160 return;
38161 }
38162
38163@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(stru
38164 if (length > ATM_MAX_AAL5_PDU) {
38165 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38166 __func__, length, vcc);
38167- atomic_inc(&vcc->stats->rx_err);
38168+ atomic_inc_unchecked(&vcc->stats->rx_err);
38169 goto out;
38170 }
38171
38172@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(stru
38173 if (sarb->len < pdu_length) {
38174 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38175 __func__, pdu_length, sarb->len, vcc);
38176- atomic_inc(&vcc->stats->rx_err);
38177+ atomic_inc_unchecked(&vcc->stats->rx_err);
38178 goto out;
38179 }
38180
38181 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38182 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38183 __func__, vcc);
38184- atomic_inc(&vcc->stats->rx_err);
38185+ atomic_inc_unchecked(&vcc->stats->rx_err);
38186 goto out;
38187 }
38188
38189@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(stru
38190 if (printk_ratelimit())
38191 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38192 __func__, length);
38193- atomic_inc(&vcc->stats->rx_drop);
38194+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38195 goto out;
38196 }
38197
38198@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(stru
38199
38200 vcc->push(vcc, skb);
38201
38202- atomic_inc(&vcc->stats->rx);
38203+ atomic_inc_unchecked(&vcc->stats->rx);
38204 out:
38205 skb_trim(sarb, 0);
38206 }
38207@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned l
38208 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38209
38210 usbatm_pop(vcc, skb);
38211- atomic_inc(&vcc->stats->tx);
38212+ atomic_inc_unchecked(&vcc->stats->tx);
38213
38214 skb = skb_dequeue(&instance->sndqueue);
38215 }
38216@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct a
38217 if (!left--)
38218 return sprintf(page,
38219 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38220- atomic_read(&atm_dev->stats.aal5.tx),
38221- atomic_read(&atm_dev->stats.aal5.tx_err),
38222- atomic_read(&atm_dev->stats.aal5.rx),
38223- atomic_read(&atm_dev->stats.aal5.rx_err),
38224- atomic_read(&atm_dev->stats.aal5.rx_drop));
38225+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38226+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38227+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38228+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38229+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38230
38231 if (!left--) {
38232 if (instance->disconnected)
38233diff -urNp linux-2.6.32.43/drivers/usb/class/cdc-wdm.c linux-2.6.32.43/drivers/usb/class/cdc-wdm.c
38234--- linux-2.6.32.43/drivers/usb/class/cdc-wdm.c 2011-03-27 14:31:47.000000000 -0400
38235+++ linux-2.6.32.43/drivers/usb/class/cdc-wdm.c 2011-04-17 15:56:46.000000000 -0400
38236@@ -314,7 +314,7 @@ static ssize_t wdm_write
38237 if (r < 0)
38238 goto outnp;
38239
38240- if (!file->f_flags && O_NONBLOCK)
38241+ if (!(file->f_flags & O_NONBLOCK))
38242 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
38243 &desc->flags));
38244 else
38245diff -urNp linux-2.6.32.43/drivers/usb/core/hcd.c linux-2.6.32.43/drivers/usb/core/hcd.c
38246--- linux-2.6.32.43/drivers/usb/core/hcd.c 2011-03-27 14:31:47.000000000 -0400
38247+++ linux-2.6.32.43/drivers/usb/core/hcd.c 2011-04-17 15:56:46.000000000 -0400
38248@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
38249
38250 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
38251
38252-struct usb_mon_operations *mon_ops;
38253+const struct usb_mon_operations *mon_ops;
38254
38255 /*
38256 * The registration is unlocked.
38257@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
38258 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
38259 */
38260
38261-int usb_mon_register (struct usb_mon_operations *ops)
38262+int usb_mon_register (const struct usb_mon_operations *ops)
38263 {
38264
38265 if (mon_ops)
38266diff -urNp linux-2.6.32.43/drivers/usb/core/hcd.h linux-2.6.32.43/drivers/usb/core/hcd.h
38267--- linux-2.6.32.43/drivers/usb/core/hcd.h 2011-03-27 14:31:47.000000000 -0400
38268+++ linux-2.6.32.43/drivers/usb/core/hcd.h 2011-04-17 15:56:46.000000000 -0400
38269@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) {
38270 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
38271
38272 struct usb_mon_operations {
38273- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
38274- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
38275- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
38276+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
38277+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
38278+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
38279 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
38280 };
38281
38282-extern struct usb_mon_operations *mon_ops;
38283+extern const struct usb_mon_operations *mon_ops;
38284
38285 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
38286 {
38287@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(s
38288 (*mon_ops->urb_complete)(bus, urb, status);
38289 }
38290
38291-int usb_mon_register(struct usb_mon_operations *ops);
38292+int usb_mon_register(const struct usb_mon_operations *ops);
38293 void usb_mon_deregister(void);
38294
38295 #else
38296diff -urNp linux-2.6.32.43/drivers/usb/core/message.c linux-2.6.32.43/drivers/usb/core/message.c
38297--- linux-2.6.32.43/drivers/usb/core/message.c 2011-03-27 14:31:47.000000000 -0400
38298+++ linux-2.6.32.43/drivers/usb/core/message.c 2011-04-17 15:56:46.000000000 -0400
38299@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device
38300 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
38301 if (buf) {
38302 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
38303- if (len > 0) {
38304- smallbuf = kmalloc(++len, GFP_NOIO);
38305+ if (len++ > 0) {
38306+ smallbuf = kmalloc(len, GFP_NOIO);
38307 if (!smallbuf)
38308 return buf;
38309 memcpy(smallbuf, buf, len);
38310diff -urNp linux-2.6.32.43/drivers/usb/misc/appledisplay.c linux-2.6.32.43/drivers/usb/misc/appledisplay.c
38311--- linux-2.6.32.43/drivers/usb/misc/appledisplay.c 2011-03-27 14:31:47.000000000 -0400
38312+++ linux-2.6.32.43/drivers/usb/misc/appledisplay.c 2011-04-17 15:56:46.000000000 -0400
38313@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightnes
38314 return pdata->msgdata[1];
38315 }
38316
38317-static struct backlight_ops appledisplay_bl_data = {
38318+static const struct backlight_ops appledisplay_bl_data = {
38319 .get_brightness = appledisplay_bl_get_brightness,
38320 .update_status = appledisplay_bl_update_status,
38321 };
38322diff -urNp linux-2.6.32.43/drivers/usb/mon/mon_main.c linux-2.6.32.43/drivers/usb/mon/mon_main.c
38323--- linux-2.6.32.43/drivers/usb/mon/mon_main.c 2011-03-27 14:31:47.000000000 -0400
38324+++ linux-2.6.32.43/drivers/usb/mon/mon_main.c 2011-04-17 15:56:46.000000000 -0400
38325@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
38326 /*
38327 * Ops
38328 */
38329-static struct usb_mon_operations mon_ops_0 = {
38330+static const struct usb_mon_operations mon_ops_0 = {
38331 .urb_submit = mon_submit,
38332 .urb_submit_error = mon_submit_error,
38333 .urb_complete = mon_complete,
38334diff -urNp linux-2.6.32.43/drivers/usb/wusbcore/wa-hc.h linux-2.6.32.43/drivers/usb/wusbcore/wa-hc.h
38335--- linux-2.6.32.43/drivers/usb/wusbcore/wa-hc.h 2011-03-27 14:31:47.000000000 -0400
38336+++ linux-2.6.32.43/drivers/usb/wusbcore/wa-hc.h 2011-05-04 17:56:28.000000000 -0400
38337@@ -192,7 +192,7 @@ struct wahc {
38338 struct list_head xfer_delayed_list;
38339 spinlock_t xfer_list_lock;
38340 struct work_struct xfer_work;
38341- atomic_t xfer_id_count;
38342+ atomic_unchecked_t xfer_id_count;
38343 };
38344
38345
38346@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
38347 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38348 spin_lock_init(&wa->xfer_list_lock);
38349 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38350- atomic_set(&wa->xfer_id_count, 1);
38351+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38352 }
38353
38354 /**
38355diff -urNp linux-2.6.32.43/drivers/usb/wusbcore/wa-xfer.c linux-2.6.32.43/drivers/usb/wusbcore/wa-xfer.c
38356--- linux-2.6.32.43/drivers/usb/wusbcore/wa-xfer.c 2011-03-27 14:31:47.000000000 -0400
38357+++ linux-2.6.32.43/drivers/usb/wusbcore/wa-xfer.c 2011-05-04 17:56:28.000000000 -0400
38358@@ -293,7 +293,7 @@ out:
38359 */
38360 static void wa_xfer_id_init(struct wa_xfer *xfer)
38361 {
38362- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38363+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38364 }
38365
38366 /*
38367diff -urNp linux-2.6.32.43/drivers/uwb/wlp/messages.c linux-2.6.32.43/drivers/uwb/wlp/messages.c
38368--- linux-2.6.32.43/drivers/uwb/wlp/messages.c 2011-03-27 14:31:47.000000000 -0400
38369+++ linux-2.6.32.43/drivers/uwb/wlp/messages.c 2011-04-17 15:56:46.000000000 -0400
38370@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct
38371 size_t len = skb->len;
38372 size_t used;
38373 ssize_t result;
38374- struct wlp_nonce enonce, rnonce;
38375+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
38376 enum wlp_assc_error assc_err;
38377 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
38378 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
38379diff -urNp linux-2.6.32.43/drivers/uwb/wlp/sysfs.c linux-2.6.32.43/drivers/uwb/wlp/sysfs.c
38380--- linux-2.6.32.43/drivers/uwb/wlp/sysfs.c 2011-03-27 14:31:47.000000000 -0400
38381+++ linux-2.6.32.43/drivers/uwb/wlp/sysfs.c 2011-04-17 15:56:46.000000000 -0400
38382@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobjec
38383 return ret;
38384 }
38385
38386-static
38387-struct sysfs_ops wss_sysfs_ops = {
38388+static const struct sysfs_ops wss_sysfs_ops = {
38389 .show = wlp_wss_attr_show,
38390 .store = wlp_wss_attr_store,
38391 };
38392diff -urNp linux-2.6.32.43/drivers/video/atmel_lcdfb.c linux-2.6.32.43/drivers/video/atmel_lcdfb.c
38393--- linux-2.6.32.43/drivers/video/atmel_lcdfb.c 2011-03-27 14:31:47.000000000 -0400
38394+++ linux-2.6.32.43/drivers/video/atmel_lcdfb.c 2011-04-17 15:56:46.000000000 -0400
38395@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struc
38396 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
38397 }
38398
38399-static struct backlight_ops atmel_lcdc_bl_ops = {
38400+static const struct backlight_ops atmel_lcdc_bl_ops = {
38401 .update_status = atmel_bl_update_status,
38402 .get_brightness = atmel_bl_get_brightness,
38403 };
38404diff -urNp linux-2.6.32.43/drivers/video/aty/aty128fb.c linux-2.6.32.43/drivers/video/aty/aty128fb.c
38405--- linux-2.6.32.43/drivers/video/aty/aty128fb.c 2011-03-27 14:31:47.000000000 -0400
38406+++ linux-2.6.32.43/drivers/video/aty/aty128fb.c 2011-04-17 15:56:46.000000000 -0400
38407@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(stru
38408 return bd->props.brightness;
38409 }
38410
38411-static struct backlight_ops aty128_bl_data = {
38412+static const struct backlight_ops aty128_bl_data = {
38413 .get_brightness = aty128_bl_get_brightness,
38414 .update_status = aty128_bl_update_status,
38415 };
38416diff -urNp linux-2.6.32.43/drivers/video/aty/atyfb_base.c linux-2.6.32.43/drivers/video/aty/atyfb_base.c
38417--- linux-2.6.32.43/drivers/video/aty/atyfb_base.c 2011-03-27 14:31:47.000000000 -0400
38418+++ linux-2.6.32.43/drivers/video/aty/atyfb_base.c 2011-04-17 15:56:46.000000000 -0400
38419@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct
38420 return bd->props.brightness;
38421 }
38422
38423-static struct backlight_ops aty_bl_data = {
38424+static const struct backlight_ops aty_bl_data = {
38425 .get_brightness = aty_bl_get_brightness,
38426 .update_status = aty_bl_update_status,
38427 };
38428diff -urNp linux-2.6.32.43/drivers/video/aty/radeon_backlight.c linux-2.6.32.43/drivers/video/aty/radeon_backlight.c
38429--- linux-2.6.32.43/drivers/video/aty/radeon_backlight.c 2011-03-27 14:31:47.000000000 -0400
38430+++ linux-2.6.32.43/drivers/video/aty/radeon_backlight.c 2011-04-17 15:56:46.000000000 -0400
38431@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(stru
38432 return bd->props.brightness;
38433 }
38434
38435-static struct backlight_ops radeon_bl_data = {
38436+static const struct backlight_ops radeon_bl_data = {
38437 .get_brightness = radeon_bl_get_brightness,
38438 .update_status = radeon_bl_update_status,
38439 };
38440diff -urNp linux-2.6.32.43/drivers/video/backlight/adp5520_bl.c linux-2.6.32.43/drivers/video/backlight/adp5520_bl.c
38441--- linux-2.6.32.43/drivers/video/backlight/adp5520_bl.c 2011-03-27 14:31:47.000000000 -0400
38442+++ linux-2.6.32.43/drivers/video/backlight/adp5520_bl.c 2011-04-17 15:56:46.000000000 -0400
38443@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(str
38444 return error ? data->current_brightness : reg_val;
38445 }
38446
38447-static struct backlight_ops adp5520_bl_ops = {
38448+static const struct backlight_ops adp5520_bl_ops = {
38449 .update_status = adp5520_bl_update_status,
38450 .get_brightness = adp5520_bl_get_brightness,
38451 };
38452diff -urNp linux-2.6.32.43/drivers/video/backlight/adx_bl.c linux-2.6.32.43/drivers/video/backlight/adx_bl.c
38453--- linux-2.6.32.43/drivers/video/backlight/adx_bl.c 2011-03-27 14:31:47.000000000 -0400
38454+++ linux-2.6.32.43/drivers/video/backlight/adx_bl.c 2011-04-17 15:56:46.000000000 -0400
38455@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct
38456 return 1;
38457 }
38458
38459-static struct backlight_ops adx_backlight_ops = {
38460+static const struct backlight_ops adx_backlight_ops = {
38461 .options = 0,
38462 .update_status = adx_backlight_update_status,
38463 .get_brightness = adx_backlight_get_brightness,
38464diff -urNp linux-2.6.32.43/drivers/video/backlight/atmel-pwm-bl.c linux-2.6.32.43/drivers/video/backlight/atmel-pwm-bl.c
38465--- linux-2.6.32.43/drivers/video/backlight/atmel-pwm-bl.c 2011-03-27 14:31:47.000000000 -0400
38466+++ linux-2.6.32.43/drivers/video/backlight/atmel-pwm-bl.c 2011-04-17 15:56:46.000000000 -0400
38467@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct
38468 return pwm_channel_enable(&pwmbl->pwmc);
38469 }
38470
38471-static struct backlight_ops atmel_pwm_bl_ops = {
38472+static const struct backlight_ops atmel_pwm_bl_ops = {
38473 .get_brightness = atmel_pwm_bl_get_intensity,
38474 .update_status = atmel_pwm_bl_set_intensity,
38475 };
38476diff -urNp linux-2.6.32.43/drivers/video/backlight/backlight.c linux-2.6.32.43/drivers/video/backlight/backlight.c
38477--- linux-2.6.32.43/drivers/video/backlight/backlight.c 2011-03-27 14:31:47.000000000 -0400
38478+++ linux-2.6.32.43/drivers/video/backlight/backlight.c 2011-04-17 15:56:46.000000000 -0400
38479@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
38480 * ERR_PTR() or a pointer to the newly allocated device.
38481 */
38482 struct backlight_device *backlight_device_register(const char *name,
38483- struct device *parent, void *devdata, struct backlight_ops *ops)
38484+ struct device *parent, void *devdata, const struct backlight_ops *ops)
38485 {
38486 struct backlight_device *new_bd;
38487 int rc;
38488diff -urNp linux-2.6.32.43/drivers/video/backlight/corgi_lcd.c linux-2.6.32.43/drivers/video/backlight/corgi_lcd.c
38489--- linux-2.6.32.43/drivers/video/backlight/corgi_lcd.c 2011-03-27 14:31:47.000000000 -0400
38490+++ linux-2.6.32.43/drivers/video/backlight/corgi_lcd.c 2011-04-17 15:56:46.000000000 -0400
38491@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit
38492 }
38493 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
38494
38495-static struct backlight_ops corgi_bl_ops = {
38496+static const struct backlight_ops corgi_bl_ops = {
38497 .get_brightness = corgi_bl_get_intensity,
38498 .update_status = corgi_bl_update_status,
38499 };
38500diff -urNp linux-2.6.32.43/drivers/video/backlight/cr_bllcd.c linux-2.6.32.43/drivers/video/backlight/cr_bllcd.c
38501--- linux-2.6.32.43/drivers/video/backlight/cr_bllcd.c 2011-03-27 14:31:47.000000000 -0400
38502+++ linux-2.6.32.43/drivers/video/backlight/cr_bllcd.c 2011-04-17 15:56:46.000000000 -0400
38503@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(st
38504 return intensity;
38505 }
38506
38507-static struct backlight_ops cr_backlight_ops = {
38508+static const struct backlight_ops cr_backlight_ops = {
38509 .get_brightness = cr_backlight_get_intensity,
38510 .update_status = cr_backlight_set_intensity,
38511 };
38512diff -urNp linux-2.6.32.43/drivers/video/backlight/da903x_bl.c linux-2.6.32.43/drivers/video/backlight/da903x_bl.c
38513--- linux-2.6.32.43/drivers/video/backlight/da903x_bl.c 2011-03-27 14:31:47.000000000 -0400
38514+++ linux-2.6.32.43/drivers/video/backlight/da903x_bl.c 2011-04-17 15:56:46.000000000 -0400
38515@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightne
38516 return data->current_brightness;
38517 }
38518
38519-static struct backlight_ops da903x_backlight_ops = {
38520+static const struct backlight_ops da903x_backlight_ops = {
38521 .update_status = da903x_backlight_update_status,
38522 .get_brightness = da903x_backlight_get_brightness,
38523 };
38524diff -urNp linux-2.6.32.43/drivers/video/backlight/generic_bl.c linux-2.6.32.43/drivers/video/backlight/generic_bl.c
38525--- linux-2.6.32.43/drivers/video/backlight/generic_bl.c 2011-03-27 14:31:47.000000000 -0400
38526+++ linux-2.6.32.43/drivers/video/backlight/generic_bl.c 2011-04-17 15:56:46.000000000 -0400
38527@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
38528 }
38529 EXPORT_SYMBOL(corgibl_limit_intensity);
38530
38531-static struct backlight_ops genericbl_ops = {
38532+static const struct backlight_ops genericbl_ops = {
38533 .options = BL_CORE_SUSPENDRESUME,
38534 .get_brightness = genericbl_get_intensity,
38535 .update_status = genericbl_send_intensity,
38536diff -urNp linux-2.6.32.43/drivers/video/backlight/hp680_bl.c linux-2.6.32.43/drivers/video/backlight/hp680_bl.c
38537--- linux-2.6.32.43/drivers/video/backlight/hp680_bl.c 2011-03-27 14:31:47.000000000 -0400
38538+++ linux-2.6.32.43/drivers/video/backlight/hp680_bl.c 2011-04-17 15:56:46.000000000 -0400
38539@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct
38540 return current_intensity;
38541 }
38542
38543-static struct backlight_ops hp680bl_ops = {
38544+static const struct backlight_ops hp680bl_ops = {
38545 .get_brightness = hp680bl_get_intensity,
38546 .update_status = hp680bl_set_intensity,
38547 };
38548diff -urNp linux-2.6.32.43/drivers/video/backlight/jornada720_bl.c linux-2.6.32.43/drivers/video/backlight/jornada720_bl.c
38549--- linux-2.6.32.43/drivers/video/backlight/jornada720_bl.c 2011-03-27 14:31:47.000000000 -0400
38550+++ linux-2.6.32.43/drivers/video/backlight/jornada720_bl.c 2011-04-17 15:56:46.000000000 -0400
38551@@ -93,7 +93,7 @@ out:
38552 return ret;
38553 }
38554
38555-static struct backlight_ops jornada_bl_ops = {
38556+static const struct backlight_ops jornada_bl_ops = {
38557 .get_brightness = jornada_bl_get_brightness,
38558 .update_status = jornada_bl_update_status,
38559 .options = BL_CORE_SUSPENDRESUME,
38560diff -urNp linux-2.6.32.43/drivers/video/backlight/kb3886_bl.c linux-2.6.32.43/drivers/video/backlight/kb3886_bl.c
38561--- linux-2.6.32.43/drivers/video/backlight/kb3886_bl.c 2011-03-27 14:31:47.000000000 -0400
38562+++ linux-2.6.32.43/drivers/video/backlight/kb3886_bl.c 2011-04-17 15:56:46.000000000 -0400
38563@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct
38564 return kb3886bl_intensity;
38565 }
38566
38567-static struct backlight_ops kb3886bl_ops = {
38568+static const struct backlight_ops kb3886bl_ops = {
38569 .get_brightness = kb3886bl_get_intensity,
38570 .update_status = kb3886bl_send_intensity,
38571 };
38572diff -urNp linux-2.6.32.43/drivers/video/backlight/locomolcd.c linux-2.6.32.43/drivers/video/backlight/locomolcd.c
38573--- linux-2.6.32.43/drivers/video/backlight/locomolcd.c 2011-03-27 14:31:47.000000000 -0400
38574+++ linux-2.6.32.43/drivers/video/backlight/locomolcd.c 2011-04-17 15:56:46.000000000 -0400
38575@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struc
38576 return current_intensity;
38577 }
38578
38579-static struct backlight_ops locomobl_data = {
38580+static const struct backlight_ops locomobl_data = {
38581 .get_brightness = locomolcd_get_intensity,
38582 .update_status = locomolcd_set_intensity,
38583 };
38584diff -urNp linux-2.6.32.43/drivers/video/backlight/mbp_nvidia_bl.c linux-2.6.32.43/drivers/video/backlight/mbp_nvidia_bl.c
38585--- linux-2.6.32.43/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:01.000000000 -0400
38586+++ linux-2.6.32.43/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:33.000000000 -0400
38587@@ -33,7 +33,7 @@ struct dmi_match_data {
38588 unsigned long iostart;
38589 unsigned long iolen;
38590 /* Backlight operations structure. */
38591- struct backlight_ops backlight_ops;
38592+ const struct backlight_ops backlight_ops;
38593 };
38594
38595 /* Module parameters. */
38596diff -urNp linux-2.6.32.43/drivers/video/backlight/omap1_bl.c linux-2.6.32.43/drivers/video/backlight/omap1_bl.c
38597--- linux-2.6.32.43/drivers/video/backlight/omap1_bl.c 2011-03-27 14:31:47.000000000 -0400
38598+++ linux-2.6.32.43/drivers/video/backlight/omap1_bl.c 2011-04-17 15:56:46.000000000 -0400
38599@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct b
38600 return bl->current_intensity;
38601 }
38602
38603-static struct backlight_ops omapbl_ops = {
38604+static const struct backlight_ops omapbl_ops = {
38605 .get_brightness = omapbl_get_intensity,
38606 .update_status = omapbl_update_status,
38607 };
38608diff -urNp linux-2.6.32.43/drivers/video/backlight/progear_bl.c linux-2.6.32.43/drivers/video/backlight/progear_bl.c
38609--- linux-2.6.32.43/drivers/video/backlight/progear_bl.c 2011-03-27 14:31:47.000000000 -0400
38610+++ linux-2.6.32.43/drivers/video/backlight/progear_bl.c 2011-04-17 15:56:46.000000000 -0400
38611@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struc
38612 return intensity - HW_LEVEL_MIN;
38613 }
38614
38615-static struct backlight_ops progearbl_ops = {
38616+static const struct backlight_ops progearbl_ops = {
38617 .get_brightness = progearbl_get_intensity,
38618 .update_status = progearbl_set_intensity,
38619 };
38620diff -urNp linux-2.6.32.43/drivers/video/backlight/pwm_bl.c linux-2.6.32.43/drivers/video/backlight/pwm_bl.c
38621--- linux-2.6.32.43/drivers/video/backlight/pwm_bl.c 2011-03-27 14:31:47.000000000 -0400
38622+++ linux-2.6.32.43/drivers/video/backlight/pwm_bl.c 2011-04-17 15:56:46.000000000 -0400
38623@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(
38624 return bl->props.brightness;
38625 }
38626
38627-static struct backlight_ops pwm_backlight_ops = {
38628+static const struct backlight_ops pwm_backlight_ops = {
38629 .update_status = pwm_backlight_update_status,
38630 .get_brightness = pwm_backlight_get_brightness,
38631 };
38632diff -urNp linux-2.6.32.43/drivers/video/backlight/tosa_bl.c linux-2.6.32.43/drivers/video/backlight/tosa_bl.c
38633--- linux-2.6.32.43/drivers/video/backlight/tosa_bl.c 2011-03-27 14:31:47.000000000 -0400
38634+++ linux-2.6.32.43/drivers/video/backlight/tosa_bl.c 2011-04-17 15:56:46.000000000 -0400
38635@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct
38636 return props->brightness;
38637 }
38638
38639-static struct backlight_ops bl_ops = {
38640+static const struct backlight_ops bl_ops = {
38641 .get_brightness = tosa_bl_get_brightness,
38642 .update_status = tosa_bl_update_status,
38643 };
38644diff -urNp linux-2.6.32.43/drivers/video/backlight/wm831x_bl.c linux-2.6.32.43/drivers/video/backlight/wm831x_bl.c
38645--- linux-2.6.32.43/drivers/video/backlight/wm831x_bl.c 2011-03-27 14:31:47.000000000 -0400
38646+++ linux-2.6.32.43/drivers/video/backlight/wm831x_bl.c 2011-04-17 15:56:46.000000000 -0400
38647@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightne
38648 return data->current_brightness;
38649 }
38650
38651-static struct backlight_ops wm831x_backlight_ops = {
38652+static const struct backlight_ops wm831x_backlight_ops = {
38653 .options = BL_CORE_SUSPENDRESUME,
38654 .update_status = wm831x_backlight_update_status,
38655 .get_brightness = wm831x_backlight_get_brightness,
38656diff -urNp linux-2.6.32.43/drivers/video/bf54x-lq043fb.c linux-2.6.32.43/drivers/video/bf54x-lq043fb.c
38657--- linux-2.6.32.43/drivers/video/bf54x-lq043fb.c 2011-03-27 14:31:47.000000000 -0400
38658+++ linux-2.6.32.43/drivers/video/bf54x-lq043fb.c 2011-04-17 15:56:46.000000000 -0400
38659@@ -463,7 +463,7 @@ static int bl_get_brightness(struct back
38660 return 0;
38661 }
38662
38663-static struct backlight_ops bfin_lq043fb_bl_ops = {
38664+static const struct backlight_ops bfin_lq043fb_bl_ops = {
38665 .get_brightness = bl_get_brightness,
38666 };
38667
38668diff -urNp linux-2.6.32.43/drivers/video/bfin-t350mcqb-fb.c linux-2.6.32.43/drivers/video/bfin-t350mcqb-fb.c
38669--- linux-2.6.32.43/drivers/video/bfin-t350mcqb-fb.c 2011-03-27 14:31:47.000000000 -0400
38670+++ linux-2.6.32.43/drivers/video/bfin-t350mcqb-fb.c 2011-04-17 15:56:46.000000000 -0400
38671@@ -381,7 +381,7 @@ static int bl_get_brightness(struct back
38672 return 0;
38673 }
38674
38675-static struct backlight_ops bfin_lq043fb_bl_ops = {
38676+static const struct backlight_ops bfin_lq043fb_bl_ops = {
38677 .get_brightness = bl_get_brightness,
38678 };
38679
38680diff -urNp linux-2.6.32.43/drivers/video/fbcmap.c linux-2.6.32.43/drivers/video/fbcmap.c
38681--- linux-2.6.32.43/drivers/video/fbcmap.c 2011-03-27 14:31:47.000000000 -0400
38682+++ linux-2.6.32.43/drivers/video/fbcmap.c 2011-04-17 15:56:46.000000000 -0400
38683@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user
38684 rc = -ENODEV;
38685 goto out;
38686 }
38687- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38688- !info->fbops->fb_setcmap)) {
38689+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38690 rc = -EINVAL;
38691 goto out1;
38692 }
38693diff -urNp linux-2.6.32.43/drivers/video/fbmem.c linux-2.6.32.43/drivers/video/fbmem.c
38694--- linux-2.6.32.43/drivers/video/fbmem.c 2011-03-27 14:31:47.000000000 -0400
38695+++ linux-2.6.32.43/drivers/video/fbmem.c 2011-05-16 21:46:57.000000000 -0400
38696@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_in
38697 image->dx += image->width + 8;
38698 }
38699 } else if (rotate == FB_ROTATE_UD) {
38700- for (x = 0; x < num && image->dx >= 0; x++) {
38701+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38702 info->fbops->fb_imageblit(info, image);
38703 image->dx -= image->width + 8;
38704 }
38705@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_in
38706 image->dy += image->height + 8;
38707 }
38708 } else if (rotate == FB_ROTATE_CCW) {
38709- for (x = 0; x < num && image->dy >= 0; x++) {
38710+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38711 info->fbops->fb_imageblit(info, image);
38712 image->dy -= image->height + 8;
38713 }
38714@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct
38715 int flags = info->flags;
38716 int ret = 0;
38717
38718+ pax_track_stack();
38719+
38720 if (var->activate & FB_ACTIVATE_INV_MODE) {
38721 struct fb_videomode mode1, mode2;
38722
38723@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *
38724 void __user *argp = (void __user *)arg;
38725 long ret = 0;
38726
38727+ pax_track_stack();
38728+
38729 switch (cmd) {
38730 case FBIOGET_VSCREENINFO:
38731 if (!lock_fb_info(info))
38732@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *
38733 return -EFAULT;
38734 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38735 return -EINVAL;
38736- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38737+ if (con2fb.framebuffer >= FB_MAX)
38738 return -EINVAL;
38739 if (!registered_fb[con2fb.framebuffer])
38740 request_module("fb%d", con2fb.framebuffer);
38741diff -urNp linux-2.6.32.43/drivers/video/i810/i810_accel.c linux-2.6.32.43/drivers/video/i810/i810_accel.c
38742--- linux-2.6.32.43/drivers/video/i810/i810_accel.c 2011-03-27 14:31:47.000000000 -0400
38743+++ linux-2.6.32.43/drivers/video/i810/i810_accel.c 2011-04-17 15:56:46.000000000 -0400
38744@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
38745 }
38746 }
38747 printk("ringbuffer lockup!!!\n");
38748+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38749 i810_report_error(mmio);
38750 par->dev_flags |= LOCKUP;
38751 info->pixmap.scan_align = 1;
38752diff -urNp linux-2.6.32.43/drivers/video/nvidia/nv_backlight.c linux-2.6.32.43/drivers/video/nvidia/nv_backlight.c
38753--- linux-2.6.32.43/drivers/video/nvidia/nv_backlight.c 2011-03-27 14:31:47.000000000 -0400
38754+++ linux-2.6.32.43/drivers/video/nvidia/nv_backlight.c 2011-04-17 15:56:46.000000000 -0400
38755@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(stru
38756 return bd->props.brightness;
38757 }
38758
38759-static struct backlight_ops nvidia_bl_ops = {
38760+static const struct backlight_ops nvidia_bl_ops = {
38761 .get_brightness = nvidia_bl_get_brightness,
38762 .update_status = nvidia_bl_update_status,
38763 };
38764diff -urNp linux-2.6.32.43/drivers/video/riva/fbdev.c linux-2.6.32.43/drivers/video/riva/fbdev.c
38765--- linux-2.6.32.43/drivers/video/riva/fbdev.c 2011-03-27 14:31:47.000000000 -0400
38766+++ linux-2.6.32.43/drivers/video/riva/fbdev.c 2011-04-17 15:56:46.000000000 -0400
38767@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct
38768 return bd->props.brightness;
38769 }
38770
38771-static struct backlight_ops riva_bl_ops = {
38772+static const struct backlight_ops riva_bl_ops = {
38773 .get_brightness = riva_bl_get_brightness,
38774 .update_status = riva_bl_update_status,
38775 };
38776diff -urNp linux-2.6.32.43/drivers/video/uvesafb.c linux-2.6.32.43/drivers/video/uvesafb.c
38777--- linux-2.6.32.43/drivers/video/uvesafb.c 2011-03-27 14:31:47.000000000 -0400
38778+++ linux-2.6.32.43/drivers/video/uvesafb.c 2011-04-17 15:56:46.000000000 -0400
38779@@ -18,6 +18,7 @@
38780 #include <linux/fb.h>
38781 #include <linux/io.h>
38782 #include <linux/mutex.h>
38783+#include <linux/moduleloader.h>
38784 #include <video/edid.h>
38785 #include <video/uvesafb.h>
38786 #ifdef CONFIG_X86
38787@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
38788 NULL,
38789 };
38790
38791- return call_usermodehelper(v86d_path, argv, envp, 1);
38792+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
38793 }
38794
38795 /*
38796@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(
38797 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
38798 par->pmi_setpal = par->ypan = 0;
38799 } else {
38800+
38801+#ifdef CONFIG_PAX_KERNEXEC
38802+#ifdef CONFIG_MODULES
38803+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
38804+#endif
38805+ if (!par->pmi_code) {
38806+ par->pmi_setpal = par->ypan = 0;
38807+ return 0;
38808+ }
38809+#endif
38810+
38811 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
38812 + task->t.regs.edi);
38813+
38814+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38815+ pax_open_kernel();
38816+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
38817+ pax_close_kernel();
38818+
38819+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
38820+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
38821+#else
38822 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
38823 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
38824+#endif
38825+
38826 printk(KERN_INFO "uvesafb: protected mode interface info at "
38827 "%04x:%04x\n",
38828 (u16)task->t.regs.es, (u16)task->t.regs.edi);
38829@@ -1799,6 +1822,11 @@ out:
38830 if (par->vbe_modes)
38831 kfree(par->vbe_modes);
38832
38833+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38834+ if (par->pmi_code)
38835+ module_free_exec(NULL, par->pmi_code);
38836+#endif
38837+
38838 framebuffer_release(info);
38839 return err;
38840 }
38841@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platfor
38842 kfree(par->vbe_state_orig);
38843 if (par->vbe_state_saved)
38844 kfree(par->vbe_state_saved);
38845+
38846+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38847+ if (par->pmi_code)
38848+ module_free_exec(NULL, par->pmi_code);
38849+#endif
38850+
38851 }
38852
38853 framebuffer_release(info);
38854diff -urNp linux-2.6.32.43/drivers/video/vesafb.c linux-2.6.32.43/drivers/video/vesafb.c
38855--- linux-2.6.32.43/drivers/video/vesafb.c 2011-03-27 14:31:47.000000000 -0400
38856+++ linux-2.6.32.43/drivers/video/vesafb.c 2011-08-05 20:33:55.000000000 -0400
38857@@ -9,6 +9,7 @@
38858 */
38859
38860 #include <linux/module.h>
38861+#include <linux/moduleloader.h>
38862 #include <linux/kernel.h>
38863 #include <linux/errno.h>
38864 #include <linux/string.h>
38865@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
38866 static int vram_total __initdata; /* Set total amount of memory */
38867 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
38868 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
38869-static void (*pmi_start)(void) __read_mostly;
38870-static void (*pmi_pal) (void) __read_mostly;
38871+static void (*pmi_start)(void) __read_only;
38872+static void (*pmi_pal) (void) __read_only;
38873 static int depth __read_mostly;
38874 static int vga_compat __read_mostly;
38875 /* --------------------------------------------------------------------- */
38876@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct pl
38877 unsigned int size_vmode;
38878 unsigned int size_remap;
38879 unsigned int size_total;
38880+ void *pmi_code = NULL;
38881
38882 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
38883 return -ENODEV;
38884@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct pl
38885 size_remap = size_total;
38886 vesafb_fix.smem_len = size_remap;
38887
38888-#ifndef __i386__
38889- screen_info.vesapm_seg = 0;
38890-#endif
38891-
38892 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
38893 printk(KERN_WARNING
38894 "vesafb: cannot reserve video memory at 0x%lx\n",
38895@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct pl
38896 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
38897 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
38898
38899+#ifdef __i386__
38900+
38901+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38902+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
38903+ if (!pmi_code)
38904+#elif !defined(CONFIG_PAX_KERNEXEC)
38905+ if (0)
38906+#endif
38907+
38908+#endif
38909+ screen_info.vesapm_seg = 0;
38910+
38911 if (screen_info.vesapm_seg) {
38912- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
38913- screen_info.vesapm_seg,screen_info.vesapm_off);
38914+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
38915+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
38916 }
38917
38918 if (screen_info.vesapm_seg < 0xc000)
38919@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct pl
38920
38921 if (ypan || pmi_setpal) {
38922 unsigned short *pmi_base;
38923+
38924 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
38925- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
38926- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
38927+
38928+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38929+ pax_open_kernel();
38930+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
38931+#else
38932+ pmi_code = pmi_base;
38933+#endif
38934+
38935+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
38936+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
38937+
38938+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38939+ pmi_start = ktva_ktla(pmi_start);
38940+ pmi_pal = ktva_ktla(pmi_pal);
38941+ pax_close_kernel();
38942+#endif
38943+
38944 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
38945 if (pmi_base[3]) {
38946 printk(KERN_INFO "vesafb: pmi: ports = ");
38947@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct pl
38948 info->node, info->fix.id);
38949 return 0;
38950 err:
38951+
38952+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
38953+ module_free_exec(NULL, pmi_code);
38954+#endif
38955+
38956 if (info->screen_base)
38957 iounmap(info->screen_base);
38958 framebuffer_release(info);
38959diff -urNp linux-2.6.32.43/drivers/xen/sys-hypervisor.c linux-2.6.32.43/drivers/xen/sys-hypervisor.c
38960--- linux-2.6.32.43/drivers/xen/sys-hypervisor.c 2011-03-27 14:31:47.000000000 -0400
38961+++ linux-2.6.32.43/drivers/xen/sys-hypervisor.c 2011-04-17 15:56:46.000000000 -0400
38962@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct ko
38963 return 0;
38964 }
38965
38966-static struct sysfs_ops hyp_sysfs_ops = {
38967+static const struct sysfs_ops hyp_sysfs_ops = {
38968 .show = hyp_sysfs_show,
38969 .store = hyp_sysfs_store,
38970 };
38971diff -urNp linux-2.6.32.43/fs/9p/vfs_inode.c linux-2.6.32.43/fs/9p/vfs_inode.c
38972--- linux-2.6.32.43/fs/9p/vfs_inode.c 2011-03-27 14:31:47.000000000 -0400
38973+++ linux-2.6.32.43/fs/9p/vfs_inode.c 2011-04-17 15:56:46.000000000 -0400
38974@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct
38975 static void
38976 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
38977 {
38978- char *s = nd_get_link(nd);
38979+ const char *s = nd_get_link(nd);
38980
38981 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
38982 IS_ERR(s) ? "<error>" : s);
38983diff -urNp linux-2.6.32.43/fs/aio.c linux-2.6.32.43/fs/aio.c
38984--- linux-2.6.32.43/fs/aio.c 2011-03-27 14:31:47.000000000 -0400
38985+++ linux-2.6.32.43/fs/aio.c 2011-06-04 20:40:21.000000000 -0400
38986@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx
38987 size += sizeof(struct io_event) * nr_events;
38988 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
38989
38990- if (nr_pages < 0)
38991+ if (nr_pages <= 0)
38992 return -EINVAL;
38993
38994 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
38995@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ct
38996 struct aio_timeout to;
38997 int retry = 0;
38998
38999+ pax_track_stack();
39000+
39001 /* needed to zero any padding within an entry (there shouldn't be
39002 * any, but C is fun!
39003 */
39004@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *i
39005 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
39006 {
39007 ssize_t ret;
39008+ struct iovec iovstack;
39009
39010 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
39011 kiocb->ki_nbytes, 1,
39012- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
39013+ &iovstack, &kiocb->ki_iovec);
39014 if (ret < 0)
39015 goto out;
39016
39017+ if (kiocb->ki_iovec == &iovstack) {
39018+ kiocb->ki_inline_vec = iovstack;
39019+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
39020+ }
39021 kiocb->ki_nr_segs = kiocb->ki_nbytes;
39022 kiocb->ki_cur_seg = 0;
39023 /* ki_nbytes/left now reflect bytes instead of segs */
39024diff -urNp linux-2.6.32.43/fs/attr.c linux-2.6.32.43/fs/attr.c
39025--- linux-2.6.32.43/fs/attr.c 2011-03-27 14:31:47.000000000 -0400
39026+++ linux-2.6.32.43/fs/attr.c 2011-04-17 15:56:46.000000000 -0400
39027@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode
39028 unsigned long limit;
39029
39030 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
39031+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
39032 if (limit != RLIM_INFINITY && offset > limit)
39033 goto out_sig;
39034 if (offset > inode->i_sb->s_maxbytes)
39035diff -urNp linux-2.6.32.43/fs/autofs/root.c linux-2.6.32.43/fs/autofs/root.c
39036--- linux-2.6.32.43/fs/autofs/root.c 2011-03-27 14:31:47.000000000 -0400
39037+++ linux-2.6.32.43/fs/autofs/root.c 2011-04-17 15:56:46.000000000 -0400
39038@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct in
39039 set_bit(n,sbi->symlink_bitmap);
39040 sl = &sbi->symlink[n];
39041 sl->len = strlen(symname);
39042- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
39043+ slsize = sl->len+1;
39044+ sl->data = kmalloc(slsize, GFP_KERNEL);
39045 if (!sl->data) {
39046 clear_bit(n,sbi->symlink_bitmap);
39047 unlock_kernel();
39048diff -urNp linux-2.6.32.43/fs/autofs4/symlink.c linux-2.6.32.43/fs/autofs4/symlink.c
39049--- linux-2.6.32.43/fs/autofs4/symlink.c 2011-03-27 14:31:47.000000000 -0400
39050+++ linux-2.6.32.43/fs/autofs4/symlink.c 2011-04-17 15:56:46.000000000 -0400
39051@@ -15,7 +15,7 @@
39052 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
39053 {
39054 struct autofs_info *ino = autofs4_dentry_ino(dentry);
39055- nd_set_link(nd, (char *)ino->u.symlink);
39056+ nd_set_link(nd, ino->u.symlink);
39057 return NULL;
39058 }
39059
39060diff -urNp linux-2.6.32.43/fs/befs/linuxvfs.c linux-2.6.32.43/fs/befs/linuxvfs.c
39061--- linux-2.6.32.43/fs/befs/linuxvfs.c 2011-03-27 14:31:47.000000000 -0400
39062+++ linux-2.6.32.43/fs/befs/linuxvfs.c 2011-04-17 15:56:46.000000000 -0400
39063@@ -493,7 +493,7 @@ static void befs_put_link(struct dentry
39064 {
39065 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
39066 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
39067- char *link = nd_get_link(nd);
39068+ const char *link = nd_get_link(nd);
39069 if (!IS_ERR(link))
39070 kfree(link);
39071 }
39072diff -urNp linux-2.6.32.43/fs/binfmt_aout.c linux-2.6.32.43/fs/binfmt_aout.c
39073--- linux-2.6.32.43/fs/binfmt_aout.c 2011-03-27 14:31:47.000000000 -0400
39074+++ linux-2.6.32.43/fs/binfmt_aout.c 2011-04-17 15:56:46.000000000 -0400
39075@@ -16,6 +16,7 @@
39076 #include <linux/string.h>
39077 #include <linux/fs.h>
39078 #include <linux/file.h>
39079+#include <linux/security.h>
39080 #include <linux/stat.h>
39081 #include <linux/fcntl.h>
39082 #include <linux/ptrace.h>
39083@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, st
39084 #endif
39085 # define START_STACK(u) (u.start_stack)
39086
39087+ memset(&dump, 0, sizeof(dump));
39088+
39089 fs = get_fs();
39090 set_fs(KERNEL_DS);
39091 has_dumped = 1;
39092@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, st
39093
39094 /* If the size of the dump file exceeds the rlimit, then see what would happen
39095 if we wrote the stack, but not the data area. */
39096+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
39097 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
39098 dump.u_dsize = 0;
39099
39100 /* Make sure we have enough room to write the stack and data areas. */
39101+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
39102 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
39103 dump.u_ssize = 0;
39104
39105@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, st
39106 dump_size = dump.u_ssize << PAGE_SHIFT;
39107 DUMP_WRITE(dump_start,dump_size);
39108 }
39109-/* Finally dump the task struct. Not be used by gdb, but could be useful */
39110- set_fs(KERNEL_DS);
39111- DUMP_WRITE(current,sizeof(*current));
39112+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
39113 end_coredump:
39114 set_fs(fs);
39115 return has_dumped;
39116@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux
39117 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
39118 if (rlim >= RLIM_INFINITY)
39119 rlim = ~0;
39120+
39121+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
39122 if (ex.a_data + ex.a_bss > rlim)
39123 return -ENOMEM;
39124
39125@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux
39126 install_exec_creds(bprm);
39127 current->flags &= ~PF_FORKNOEXEC;
39128
39129+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39130+ current->mm->pax_flags = 0UL;
39131+#endif
39132+
39133+#ifdef CONFIG_PAX_PAGEEXEC
39134+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
39135+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
39136+
39137+#ifdef CONFIG_PAX_EMUTRAMP
39138+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
39139+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
39140+#endif
39141+
39142+#ifdef CONFIG_PAX_MPROTECT
39143+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
39144+ current->mm->pax_flags |= MF_PAX_MPROTECT;
39145+#endif
39146+
39147+ }
39148+#endif
39149+
39150 if (N_MAGIC(ex) == OMAGIC) {
39151 unsigned long text_addr, map_size;
39152 loff_t pos;
39153@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux
39154
39155 down_write(&current->mm->mmap_sem);
39156 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
39157- PROT_READ | PROT_WRITE | PROT_EXEC,
39158+ PROT_READ | PROT_WRITE,
39159 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
39160 fd_offset + ex.a_text);
39161 up_write(&current->mm->mmap_sem);
39162diff -urNp linux-2.6.32.43/fs/binfmt_elf.c linux-2.6.32.43/fs/binfmt_elf.c
39163--- linux-2.6.32.43/fs/binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
39164+++ linux-2.6.32.43/fs/binfmt_elf.c 2011-05-16 21:46:57.000000000 -0400
39165@@ -50,6 +50,10 @@ static int elf_core_dump(long signr, str
39166 #define elf_core_dump NULL
39167 #endif
39168
39169+#ifdef CONFIG_PAX_MPROTECT
39170+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
39171+#endif
39172+
39173 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
39174 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
39175 #else
39176@@ -69,6 +73,11 @@ static struct linux_binfmt elf_format =
39177 .load_binary = load_elf_binary,
39178 .load_shlib = load_elf_library,
39179 .core_dump = elf_core_dump,
39180+
39181+#ifdef CONFIG_PAX_MPROTECT
39182+ .handle_mprotect= elf_handle_mprotect,
39183+#endif
39184+
39185 .min_coredump = ELF_EXEC_PAGESIZE,
39186 .hasvdso = 1
39187 };
39188@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
39189
39190 static int set_brk(unsigned long start, unsigned long end)
39191 {
39192+ unsigned long e = end;
39193+
39194 start = ELF_PAGEALIGN(start);
39195 end = ELF_PAGEALIGN(end);
39196 if (end > start) {
39197@@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
39198 if (BAD_ADDR(addr))
39199 return addr;
39200 }
39201- current->mm->start_brk = current->mm->brk = end;
39202+ current->mm->start_brk = current->mm->brk = e;
39203 return 0;
39204 }
39205
39206@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
39207 elf_addr_t __user *u_rand_bytes;
39208 const char *k_platform = ELF_PLATFORM;
39209 const char *k_base_platform = ELF_BASE_PLATFORM;
39210- unsigned char k_rand_bytes[16];
39211+ u32 k_rand_bytes[4];
39212 int items;
39213 elf_addr_t *elf_info;
39214 int ei_index = 0;
39215 const struct cred *cred = current_cred();
39216 struct vm_area_struct *vma;
39217+ unsigned long saved_auxv[AT_VECTOR_SIZE];
39218+
39219+ pax_track_stack();
39220
39221 /*
39222 * In some cases (e.g. Hyper-Threading), we want to avoid L1
39223@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
39224 * Generate 16 random bytes for userspace PRNG seeding.
39225 */
39226 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
39227- u_rand_bytes = (elf_addr_t __user *)
39228- STACK_ALLOC(p, sizeof(k_rand_bytes));
39229+ srandom32(k_rand_bytes[0] ^ random32());
39230+ srandom32(k_rand_bytes[1] ^ random32());
39231+ srandom32(k_rand_bytes[2] ^ random32());
39232+ srandom32(k_rand_bytes[3] ^ random32());
39233+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
39234+ u_rand_bytes = (elf_addr_t __user *) p;
39235 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
39236 return -EFAULT;
39237
39238@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
39239 return -EFAULT;
39240 current->mm->env_end = p;
39241
39242+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
39243+
39244 /* Put the elf_info on the stack in the right place. */
39245 sp = (elf_addr_t __user *)envp + 1;
39246- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
39247+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
39248 return -EFAULT;
39249 return 0;
39250 }
39251@@ -385,10 +405,10 @@ static unsigned long load_elf_interp(str
39252 {
39253 struct elf_phdr *elf_phdata;
39254 struct elf_phdr *eppnt;
39255- unsigned long load_addr = 0;
39256+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
39257 int load_addr_set = 0;
39258 unsigned long last_bss = 0, elf_bss = 0;
39259- unsigned long error = ~0UL;
39260+ unsigned long error = -EINVAL;
39261 unsigned long total_size;
39262 int retval, i, size;
39263
39264@@ -434,6 +454,11 @@ static unsigned long load_elf_interp(str
39265 goto out_close;
39266 }
39267
39268+#ifdef CONFIG_PAX_SEGMEXEC
39269+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
39270+ pax_task_size = SEGMEXEC_TASK_SIZE;
39271+#endif
39272+
39273 eppnt = elf_phdata;
39274 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
39275 if (eppnt->p_type == PT_LOAD) {
39276@@ -477,8 +502,8 @@ static unsigned long load_elf_interp(str
39277 k = load_addr + eppnt->p_vaddr;
39278 if (BAD_ADDR(k) ||
39279 eppnt->p_filesz > eppnt->p_memsz ||
39280- eppnt->p_memsz > TASK_SIZE ||
39281- TASK_SIZE - eppnt->p_memsz < k) {
39282+ eppnt->p_memsz > pax_task_size ||
39283+ pax_task_size - eppnt->p_memsz < k) {
39284 error = -ENOMEM;
39285 goto out_close;
39286 }
39287@@ -532,6 +557,194 @@ out:
39288 return error;
39289 }
39290
39291+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
39292+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
39293+{
39294+ unsigned long pax_flags = 0UL;
39295+
39296+#ifdef CONFIG_PAX_PAGEEXEC
39297+ if (elf_phdata->p_flags & PF_PAGEEXEC)
39298+ pax_flags |= MF_PAX_PAGEEXEC;
39299+#endif
39300+
39301+#ifdef CONFIG_PAX_SEGMEXEC
39302+ if (elf_phdata->p_flags & PF_SEGMEXEC)
39303+ pax_flags |= MF_PAX_SEGMEXEC;
39304+#endif
39305+
39306+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39307+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39308+ if (nx_enabled)
39309+ pax_flags &= ~MF_PAX_SEGMEXEC;
39310+ else
39311+ pax_flags &= ~MF_PAX_PAGEEXEC;
39312+ }
39313+#endif
39314+
39315+#ifdef CONFIG_PAX_EMUTRAMP
39316+ if (elf_phdata->p_flags & PF_EMUTRAMP)
39317+ pax_flags |= MF_PAX_EMUTRAMP;
39318+#endif
39319+
39320+#ifdef CONFIG_PAX_MPROTECT
39321+ if (elf_phdata->p_flags & PF_MPROTECT)
39322+ pax_flags |= MF_PAX_MPROTECT;
39323+#endif
39324+
39325+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39326+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
39327+ pax_flags |= MF_PAX_RANDMMAP;
39328+#endif
39329+
39330+ return pax_flags;
39331+}
39332+#endif
39333+
39334+#ifdef CONFIG_PAX_PT_PAX_FLAGS
39335+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
39336+{
39337+ unsigned long pax_flags = 0UL;
39338+
39339+#ifdef CONFIG_PAX_PAGEEXEC
39340+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
39341+ pax_flags |= MF_PAX_PAGEEXEC;
39342+#endif
39343+
39344+#ifdef CONFIG_PAX_SEGMEXEC
39345+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
39346+ pax_flags |= MF_PAX_SEGMEXEC;
39347+#endif
39348+
39349+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39350+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39351+ if (nx_enabled)
39352+ pax_flags &= ~MF_PAX_SEGMEXEC;
39353+ else
39354+ pax_flags &= ~MF_PAX_PAGEEXEC;
39355+ }
39356+#endif
39357+
39358+#ifdef CONFIG_PAX_EMUTRAMP
39359+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
39360+ pax_flags |= MF_PAX_EMUTRAMP;
39361+#endif
39362+
39363+#ifdef CONFIG_PAX_MPROTECT
39364+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
39365+ pax_flags |= MF_PAX_MPROTECT;
39366+#endif
39367+
39368+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39369+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
39370+ pax_flags |= MF_PAX_RANDMMAP;
39371+#endif
39372+
39373+ return pax_flags;
39374+}
39375+#endif
39376+
39377+#ifdef CONFIG_PAX_EI_PAX
39378+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
39379+{
39380+ unsigned long pax_flags = 0UL;
39381+
39382+#ifdef CONFIG_PAX_PAGEEXEC
39383+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
39384+ pax_flags |= MF_PAX_PAGEEXEC;
39385+#endif
39386+
39387+#ifdef CONFIG_PAX_SEGMEXEC
39388+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
39389+ pax_flags |= MF_PAX_SEGMEXEC;
39390+#endif
39391+
39392+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39393+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39394+ if (nx_enabled)
39395+ pax_flags &= ~MF_PAX_SEGMEXEC;
39396+ else
39397+ pax_flags &= ~MF_PAX_PAGEEXEC;
39398+ }
39399+#endif
39400+
39401+#ifdef CONFIG_PAX_EMUTRAMP
39402+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
39403+ pax_flags |= MF_PAX_EMUTRAMP;
39404+#endif
39405+
39406+#ifdef CONFIG_PAX_MPROTECT
39407+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
39408+ pax_flags |= MF_PAX_MPROTECT;
39409+#endif
39410+
39411+#ifdef CONFIG_PAX_ASLR
39412+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
39413+ pax_flags |= MF_PAX_RANDMMAP;
39414+#endif
39415+
39416+ return pax_flags;
39417+}
39418+#endif
39419+
39420+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
39421+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
39422+{
39423+ unsigned long pax_flags = 0UL;
39424+
39425+#ifdef CONFIG_PAX_PT_PAX_FLAGS
39426+ unsigned long i;
39427+ int found_flags = 0;
39428+#endif
39429+
39430+#ifdef CONFIG_PAX_EI_PAX
39431+ pax_flags = pax_parse_ei_pax(elf_ex);
39432+#endif
39433+
39434+#ifdef CONFIG_PAX_PT_PAX_FLAGS
39435+ for (i = 0UL; i < elf_ex->e_phnum; i++)
39436+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
39437+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
39438+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
39439+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
39440+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
39441+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
39442+ return -EINVAL;
39443+
39444+#ifdef CONFIG_PAX_SOFTMODE
39445+ if (pax_softmode)
39446+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
39447+ else
39448+#endif
39449+
39450+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
39451+ found_flags = 1;
39452+ break;
39453+ }
39454+#endif
39455+
39456+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
39457+ if (found_flags == 0) {
39458+ struct elf_phdr phdr;
39459+ memset(&phdr, 0, sizeof(phdr));
39460+ phdr.p_flags = PF_NOEMUTRAMP;
39461+#ifdef CONFIG_PAX_SOFTMODE
39462+ if (pax_softmode)
39463+ pax_flags = pax_parse_softmode(&phdr);
39464+ else
39465+#endif
39466+ pax_flags = pax_parse_hardmode(&phdr);
39467+ }
39468+#endif
39469+
39470+
39471+ if (0 > pax_check_flags(&pax_flags))
39472+ return -EINVAL;
39473+
39474+ current->mm->pax_flags = pax_flags;
39475+ return 0;
39476+}
39477+#endif
39478+
39479 /*
39480 * These are the functions used to load ELF style executables and shared
39481 * libraries. There is no binary dependent code anywhere else.
39482@@ -548,6 +761,11 @@ static unsigned long randomize_stack_top
39483 {
39484 unsigned int random_variable = 0;
39485
39486+#ifdef CONFIG_PAX_RANDUSTACK
39487+ if (randomize_va_space)
39488+ return stack_top - current->mm->delta_stack;
39489+#endif
39490+
39491 if ((current->flags & PF_RANDOMIZE) &&
39492 !(current->personality & ADDR_NO_RANDOMIZE)) {
39493 random_variable = get_random_int() & STACK_RND_MASK;
39494@@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_
39495 unsigned long load_addr = 0, load_bias = 0;
39496 int load_addr_set = 0;
39497 char * elf_interpreter = NULL;
39498- unsigned long error;
39499+ unsigned long error = 0;
39500 struct elf_phdr *elf_ppnt, *elf_phdata;
39501 unsigned long elf_bss, elf_brk;
39502 int retval, i;
39503@@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_
39504 unsigned long start_code, end_code, start_data, end_data;
39505 unsigned long reloc_func_desc = 0;
39506 int executable_stack = EXSTACK_DEFAULT;
39507- unsigned long def_flags = 0;
39508 struct {
39509 struct elfhdr elf_ex;
39510 struct elfhdr interp_elf_ex;
39511 } *loc;
39512+ unsigned long pax_task_size = TASK_SIZE;
39513
39514 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
39515 if (!loc) {
39516@@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_
39517
39518 /* OK, This is the point of no return */
39519 current->flags &= ~PF_FORKNOEXEC;
39520- current->mm->def_flags = def_flags;
39521+
39522+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39523+ current->mm->pax_flags = 0UL;
39524+#endif
39525+
39526+#ifdef CONFIG_PAX_DLRESOLVE
39527+ current->mm->call_dl_resolve = 0UL;
39528+#endif
39529+
39530+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
39531+ current->mm->call_syscall = 0UL;
39532+#endif
39533+
39534+#ifdef CONFIG_PAX_ASLR
39535+ current->mm->delta_mmap = 0UL;
39536+ current->mm->delta_stack = 0UL;
39537+#endif
39538+
39539+ current->mm->def_flags = 0;
39540+
39541+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
39542+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
39543+ send_sig(SIGKILL, current, 0);
39544+ goto out_free_dentry;
39545+ }
39546+#endif
39547+
39548+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
39549+ pax_set_initial_flags(bprm);
39550+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
39551+ if (pax_set_initial_flags_func)
39552+ (pax_set_initial_flags_func)(bprm);
39553+#endif
39554+
39555+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
39556+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
39557+ current->mm->context.user_cs_limit = PAGE_SIZE;
39558+ current->mm->def_flags |= VM_PAGEEXEC;
39559+ }
39560+#endif
39561+
39562+#ifdef CONFIG_PAX_SEGMEXEC
39563+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
39564+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
39565+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
39566+ pax_task_size = SEGMEXEC_TASK_SIZE;
39567+ }
39568+#endif
39569+
39570+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
39571+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39572+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
39573+ put_cpu();
39574+ }
39575+#endif
39576
39577 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
39578 may depend on the personality. */
39579 SET_PERSONALITY(loc->elf_ex);
39580+
39581+#ifdef CONFIG_PAX_ASLR
39582+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
39583+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
39584+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
39585+ }
39586+#endif
39587+
39588+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
39589+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39590+ executable_stack = EXSTACK_DISABLE_X;
39591+ current->personality &= ~READ_IMPLIES_EXEC;
39592+ } else
39593+#endif
39594+
39595 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
39596 current->personality |= READ_IMPLIES_EXEC;
39597
39598@@ -804,6 +1091,20 @@ static int load_elf_binary(struct linux_
39599 #else
39600 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
39601 #endif
39602+
39603+#ifdef CONFIG_PAX_RANDMMAP
39604+ /* PaX: randomize base address at the default exe base if requested */
39605+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
39606+#ifdef CONFIG_SPARC64
39607+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
39608+#else
39609+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
39610+#endif
39611+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
39612+ elf_flags |= MAP_FIXED;
39613+ }
39614+#endif
39615+
39616 }
39617
39618 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
39619@@ -836,9 +1137,9 @@ static int load_elf_binary(struct linux_
39620 * allowed task size. Note that p_filesz must always be
39621 * <= p_memsz so it is only necessary to check p_memsz.
39622 */
39623- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
39624- elf_ppnt->p_memsz > TASK_SIZE ||
39625- TASK_SIZE - elf_ppnt->p_memsz < k) {
39626+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
39627+ elf_ppnt->p_memsz > pax_task_size ||
39628+ pax_task_size - elf_ppnt->p_memsz < k) {
39629 /* set_brk can never work. Avoid overflows. */
39630 send_sig(SIGKILL, current, 0);
39631 retval = -EINVAL;
39632@@ -866,6 +1167,11 @@ static int load_elf_binary(struct linux_
39633 start_data += load_bias;
39634 end_data += load_bias;
39635
39636+#ifdef CONFIG_PAX_RANDMMAP
39637+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
39638+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
39639+#endif
39640+
39641 /* Calling set_brk effectively mmaps the pages that we need
39642 * for the bss and break sections. We must do this before
39643 * mapping in the interpreter, to make sure it doesn't wind
39644@@ -877,9 +1183,11 @@ static int load_elf_binary(struct linux_
39645 goto out_free_dentry;
39646 }
39647 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
39648- send_sig(SIGSEGV, current, 0);
39649- retval = -EFAULT; /* Nobody gets to see this, but.. */
39650- goto out_free_dentry;
39651+ /*
39652+ * This bss-zeroing can fail if the ELF
39653+ * file specifies odd protections. So
39654+ * we don't check the return value
39655+ */
39656 }
39657
39658 if (elf_interpreter) {
39659@@ -1112,8 +1420,10 @@ static int dump_seek(struct file *file,
39660 unsigned long n = off;
39661 if (n > PAGE_SIZE)
39662 n = PAGE_SIZE;
39663- if (!dump_write(file, buf, n))
39664+ if (!dump_write(file, buf, n)) {
39665+ free_page((unsigned long)buf);
39666 return 0;
39667+ }
39668 off -= n;
39669 }
39670 free_page((unsigned long)buf);
39671@@ -1125,7 +1435,7 @@ static int dump_seek(struct file *file,
39672 * Decide what to dump of a segment, part, all or none.
39673 */
39674 static unsigned long vma_dump_size(struct vm_area_struct *vma,
39675- unsigned long mm_flags)
39676+ unsigned long mm_flags, long signr)
39677 {
39678 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
39679
39680@@ -1159,7 +1469,7 @@ static unsigned long vma_dump_size(struc
39681 if (vma->vm_file == NULL)
39682 return 0;
39683
39684- if (FILTER(MAPPED_PRIVATE))
39685+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
39686 goto whole;
39687
39688 /*
39689@@ -1255,8 +1565,11 @@ static int writenote(struct memelfnote *
39690 #undef DUMP_WRITE
39691
39692 #define DUMP_WRITE(addr, nr) \
39693+ do { \
39694+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
39695 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
39696- goto end_coredump;
39697+ goto end_coredump; \
39698+ } while (0);
39699
39700 static void fill_elf_header(struct elfhdr *elf, int segs,
39701 u16 machine, u32 flags, u8 osabi)
39702@@ -1385,9 +1698,9 @@ static void fill_auxv_note(struct memelf
39703 {
39704 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
39705 int i = 0;
39706- do
39707+ do {
39708 i += 2;
39709- while (auxv[i - 2] != AT_NULL);
39710+ } while (auxv[i - 2] != AT_NULL);
39711 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
39712 }
39713
39714@@ -1973,7 +2286,7 @@ static int elf_core_dump(long signr, str
39715 phdr.p_offset = offset;
39716 phdr.p_vaddr = vma->vm_start;
39717 phdr.p_paddr = 0;
39718- phdr.p_filesz = vma_dump_size(vma, mm_flags);
39719+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
39720 phdr.p_memsz = vma->vm_end - vma->vm_start;
39721 offset += phdr.p_filesz;
39722 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
39723@@ -2006,7 +2319,7 @@ static int elf_core_dump(long signr, str
39724 unsigned long addr;
39725 unsigned long end;
39726
39727- end = vma->vm_start + vma_dump_size(vma, mm_flags);
39728+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
39729
39730 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
39731 struct page *page;
39732@@ -2015,6 +2328,7 @@ static int elf_core_dump(long signr, str
39733 page = get_dump_page(addr);
39734 if (page) {
39735 void *kaddr = kmap(page);
39736+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
39737 stop = ((size += PAGE_SIZE) > limit) ||
39738 !dump_write(file, kaddr, PAGE_SIZE);
39739 kunmap(page);
39740@@ -2042,6 +2356,97 @@ out:
39741
39742 #endif /* USE_ELF_CORE_DUMP */
39743
39744+#ifdef CONFIG_PAX_MPROTECT
39745+/* PaX: non-PIC ELF libraries need relocations on their executable segments
39746+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
39747+ * we'll remove VM_MAYWRITE for good on RELRO segments.
39748+ *
39749+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
39750+ * basis because we want to allow the common case and not the special ones.
39751+ */
39752+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
39753+{
39754+ struct elfhdr elf_h;
39755+ struct elf_phdr elf_p;
39756+ unsigned long i;
39757+ unsigned long oldflags;
39758+ bool is_textrel_rw, is_textrel_rx, is_relro;
39759+
39760+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
39761+ return;
39762+
39763+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
39764+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
39765+
39766+#ifdef CONFIG_PAX_ELFRELOCS
39767+ /* possible TEXTREL */
39768+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
39769+ 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);
39770+#else
39771+ is_textrel_rw = false;
39772+ is_textrel_rx = false;
39773+#endif
39774+
39775+ /* possible RELRO */
39776+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
39777+
39778+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
39779+ return;
39780+
39781+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
39782+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
39783+
39784+#ifdef CONFIG_PAX_ETEXECRELOCS
39785+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
39786+#else
39787+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
39788+#endif
39789+
39790+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
39791+ !elf_check_arch(&elf_h) ||
39792+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
39793+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
39794+ return;
39795+
39796+ for (i = 0UL; i < elf_h.e_phnum; i++) {
39797+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
39798+ return;
39799+ switch (elf_p.p_type) {
39800+ case PT_DYNAMIC:
39801+ if (!is_textrel_rw && !is_textrel_rx)
39802+ continue;
39803+ i = 0UL;
39804+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
39805+ elf_dyn dyn;
39806+
39807+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
39808+ return;
39809+ if (dyn.d_tag == DT_NULL)
39810+ return;
39811+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
39812+ gr_log_textrel(vma);
39813+ if (is_textrel_rw)
39814+ vma->vm_flags |= VM_MAYWRITE;
39815+ else
39816+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
39817+ vma->vm_flags &= ~VM_MAYWRITE;
39818+ return;
39819+ }
39820+ i++;
39821+ }
39822+ return;
39823+
39824+ case PT_GNU_RELRO:
39825+ if (!is_relro)
39826+ continue;
39827+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
39828+ vma->vm_flags &= ~VM_MAYWRITE;
39829+ return;
39830+ }
39831+ }
39832+}
39833+#endif
39834+
39835 static int __init init_elf_binfmt(void)
39836 {
39837 return register_binfmt(&elf_format);
39838diff -urNp linux-2.6.32.43/fs/binfmt_flat.c linux-2.6.32.43/fs/binfmt_flat.c
39839--- linux-2.6.32.43/fs/binfmt_flat.c 2011-03-27 14:31:47.000000000 -0400
39840+++ linux-2.6.32.43/fs/binfmt_flat.c 2011-04-17 15:56:46.000000000 -0400
39841@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_b
39842 realdatastart = (unsigned long) -ENOMEM;
39843 printk("Unable to allocate RAM for process data, errno %d\n",
39844 (int)-realdatastart);
39845+ down_write(&current->mm->mmap_sem);
39846 do_munmap(current->mm, textpos, text_len);
39847+ up_write(&current->mm->mmap_sem);
39848 ret = realdatastart;
39849 goto err;
39850 }
39851@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_b
39852 }
39853 if (IS_ERR_VALUE(result)) {
39854 printk("Unable to read data+bss, errno %d\n", (int)-result);
39855+ down_write(&current->mm->mmap_sem);
39856 do_munmap(current->mm, textpos, text_len);
39857 do_munmap(current->mm, realdatastart, data_len + extra);
39858+ up_write(&current->mm->mmap_sem);
39859 ret = result;
39860 goto err;
39861 }
39862@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_b
39863 }
39864 if (IS_ERR_VALUE(result)) {
39865 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
39866+ down_write(&current->mm->mmap_sem);
39867 do_munmap(current->mm, textpos, text_len + data_len + extra +
39868 MAX_SHARED_LIBS * sizeof(unsigned long));
39869+ up_write(&current->mm->mmap_sem);
39870 ret = result;
39871 goto err;
39872 }
39873diff -urNp linux-2.6.32.43/fs/bio.c linux-2.6.32.43/fs/bio.c
39874--- linux-2.6.32.43/fs/bio.c 2011-03-27 14:31:47.000000000 -0400
39875+++ linux-2.6.32.43/fs/bio.c 2011-04-17 15:56:46.000000000 -0400
39876@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_cr
39877
39878 i = 0;
39879 while (i < bio_slab_nr) {
39880- struct bio_slab *bslab = &bio_slabs[i];
39881+ bslab = &bio_slabs[i];
39882
39883 if (!bslab->slab && entry == -1)
39884 entry = i;
39885@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct b
39886 const int read = bio_data_dir(bio) == READ;
39887 struct bio_map_data *bmd = bio->bi_private;
39888 int i;
39889- char *p = bmd->sgvecs[0].iov_base;
39890+ char *p = (__force char *)bmd->sgvecs[0].iov_base;
39891
39892 __bio_for_each_segment(bvec, bio, i, 0) {
39893 char *addr = page_address(bvec->bv_page);
39894diff -urNp linux-2.6.32.43/fs/block_dev.c linux-2.6.32.43/fs/block_dev.c
39895--- linux-2.6.32.43/fs/block_dev.c 2011-06-25 12:55:34.000000000 -0400
39896+++ linux-2.6.32.43/fs/block_dev.c 2011-06-25 12:56:37.000000000 -0400
39897@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev,
39898 else if (bdev->bd_contains == bdev)
39899 res = 0; /* is a whole device which isn't held */
39900
39901- else if (bdev->bd_contains->bd_holder == bd_claim)
39902+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
39903 res = 0; /* is a partition of a device that is being partitioned */
39904 else if (bdev->bd_contains->bd_holder != NULL)
39905 res = -EBUSY; /* is a partition of a held device */
39906diff -urNp linux-2.6.32.43/fs/btrfs/ctree.c linux-2.6.32.43/fs/btrfs/ctree.c
39907--- linux-2.6.32.43/fs/btrfs/ctree.c 2011-03-27 14:31:47.000000000 -0400
39908+++ linux-2.6.32.43/fs/btrfs/ctree.c 2011-04-17 15:56:46.000000000 -0400
39909@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
39910 free_extent_buffer(buf);
39911 add_root_to_dirty_list(root);
39912 } else {
39913- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
39914- parent_start = parent->start;
39915- else
39916+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
39917+ if (parent)
39918+ parent_start = parent->start;
39919+ else
39920+ parent_start = 0;
39921+ } else
39922 parent_start = 0;
39923
39924 WARN_ON(trans->transid != btrfs_header_generation(parent));
39925@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_tran
39926
39927 ret = 0;
39928 if (slot == 0) {
39929- struct btrfs_disk_key disk_key;
39930 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
39931 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
39932 }
39933diff -urNp linux-2.6.32.43/fs/btrfs/disk-io.c linux-2.6.32.43/fs/btrfs/disk-io.c
39934--- linux-2.6.32.43/fs/btrfs/disk-io.c 2011-04-17 17:00:52.000000000 -0400
39935+++ linux-2.6.32.43/fs/btrfs/disk-io.c 2011-04-17 17:03:11.000000000 -0400
39936@@ -39,7 +39,7 @@
39937 #include "tree-log.h"
39938 #include "free-space-cache.h"
39939
39940-static struct extent_io_ops btree_extent_io_ops;
39941+static const struct extent_io_ops btree_extent_io_ops;
39942 static void end_workqueue_fn(struct btrfs_work *work);
39943 static void free_fs_root(struct btrfs_root *root);
39944
39945@@ -2607,7 +2607,7 @@ out:
39946 return 0;
39947 }
39948
39949-static struct extent_io_ops btree_extent_io_ops = {
39950+static const struct extent_io_ops btree_extent_io_ops = {
39951 .write_cache_pages_lock_hook = btree_lock_page_hook,
39952 .readpage_end_io_hook = btree_readpage_end_io_hook,
39953 .submit_bio_hook = btree_submit_bio_hook,
39954diff -urNp linux-2.6.32.43/fs/btrfs/extent_io.h linux-2.6.32.43/fs/btrfs/extent_io.h
39955--- linux-2.6.32.43/fs/btrfs/extent_io.h 2011-03-27 14:31:47.000000000 -0400
39956+++ linux-2.6.32.43/fs/btrfs/extent_io.h 2011-04-17 15:56:46.000000000 -0400
39957@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(s
39958 struct bio *bio, int mirror_num,
39959 unsigned long bio_flags);
39960 struct extent_io_ops {
39961- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
39962+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
39963 u64 start, u64 end, int *page_started,
39964 unsigned long *nr_written);
39965- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
39966- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
39967+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
39968+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
39969 extent_submit_bio_hook_t *submit_bio_hook;
39970- int (*merge_bio_hook)(struct page *page, unsigned long offset,
39971+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
39972 size_t size, struct bio *bio,
39973 unsigned long bio_flags);
39974- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
39975- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
39976+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
39977+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
39978 u64 start, u64 end,
39979 struct extent_state *state);
39980- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
39981+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
39982 u64 start, u64 end,
39983 struct extent_state *state);
39984- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
39985+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
39986 struct extent_state *state);
39987- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
39988+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
39989 struct extent_state *state, int uptodate);
39990- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
39991+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
39992 unsigned long old, unsigned long bits);
39993- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
39994+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
39995 unsigned long bits);
39996- int (*merge_extent_hook)(struct inode *inode,
39997+ int (* const merge_extent_hook)(struct inode *inode,
39998 struct extent_state *new,
39999 struct extent_state *other);
40000- int (*split_extent_hook)(struct inode *inode,
40001+ int (* const split_extent_hook)(struct inode *inode,
40002 struct extent_state *orig, u64 split);
40003- int (*write_cache_pages_lock_hook)(struct page *page);
40004+ int (* const write_cache_pages_lock_hook)(struct page *page);
40005 };
40006
40007 struct extent_io_tree {
40008@@ -88,7 +88,7 @@ struct extent_io_tree {
40009 u64 dirty_bytes;
40010 spinlock_t lock;
40011 spinlock_t buffer_lock;
40012- struct extent_io_ops *ops;
40013+ const struct extent_io_ops *ops;
40014 };
40015
40016 struct extent_state {
40017diff -urNp linux-2.6.32.43/fs/btrfs/extent-tree.c linux-2.6.32.43/fs/btrfs/extent-tree.c
40018--- linux-2.6.32.43/fs/btrfs/extent-tree.c 2011-03-27 14:31:47.000000000 -0400
40019+++ linux-2.6.32.43/fs/btrfs/extent-tree.c 2011-06-12 06:39:08.000000000 -0400
40020@@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(
40021 u64 group_start = group->key.objectid;
40022 new_extents = kmalloc(sizeof(*new_extents),
40023 GFP_NOFS);
40024+ if (!new_extents) {
40025+ ret = -ENOMEM;
40026+ goto out;
40027+ }
40028 nr_extents = 1;
40029 ret = get_new_locations(reloc_inode,
40030 extent_key,
40031diff -urNp linux-2.6.32.43/fs/btrfs/free-space-cache.c linux-2.6.32.43/fs/btrfs/free-space-cache.c
40032--- linux-2.6.32.43/fs/btrfs/free-space-cache.c 2011-03-27 14:31:47.000000000 -0400
40033+++ linux-2.6.32.43/fs/btrfs/free-space-cache.c 2011-04-17 15:56:46.000000000 -0400
40034@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
40035
40036 while(1) {
40037 if (entry->bytes < bytes || entry->offset < min_start) {
40038- struct rb_node *node;
40039-
40040 node = rb_next(&entry->offset_index);
40041 if (!node)
40042 break;
40043@@ -1226,7 +1224,7 @@ again:
40044 */
40045 while (entry->bitmap || found_bitmap ||
40046 (!entry->bitmap && entry->bytes < min_bytes)) {
40047- struct rb_node *node = rb_next(&entry->offset_index);
40048+ node = rb_next(&entry->offset_index);
40049
40050 if (entry->bitmap && entry->bytes > bytes + empty_size) {
40051 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
40052diff -urNp linux-2.6.32.43/fs/btrfs/inode.c linux-2.6.32.43/fs/btrfs/inode.c
40053--- linux-2.6.32.43/fs/btrfs/inode.c 2011-03-27 14:31:47.000000000 -0400
40054+++ linux-2.6.32.43/fs/btrfs/inode.c 2011-06-12 06:39:58.000000000 -0400
40055@@ -63,7 +63,7 @@ static const struct inode_operations btr
40056 static const struct address_space_operations btrfs_aops;
40057 static const struct address_space_operations btrfs_symlink_aops;
40058 static const struct file_operations btrfs_dir_file_operations;
40059-static struct extent_io_ops btrfs_extent_io_ops;
40060+static const struct extent_io_ops btrfs_extent_io_ops;
40061
40062 static struct kmem_cache *btrfs_inode_cachep;
40063 struct kmem_cache *btrfs_trans_handle_cachep;
40064@@ -925,6 +925,7 @@ static int cow_file_range_async(struct i
40065 1, 0, NULL, GFP_NOFS);
40066 while (start < end) {
40067 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
40068+ BUG_ON(!async_cow);
40069 async_cow->inode = inode;
40070 async_cow->root = root;
40071 async_cow->locked_page = locked_page;
40072@@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(st
40073 inline_size = btrfs_file_extent_inline_item_len(leaf,
40074 btrfs_item_nr(leaf, path->slots[0]));
40075 tmp = kmalloc(inline_size, GFP_NOFS);
40076+ if (!tmp)
40077+ return -ENOMEM;
40078 ptr = btrfs_file_extent_inline_start(item);
40079
40080 read_extent_buffer(leaf, tmp, ptr, inline_size);
40081@@ -5410,7 +5413,7 @@ fail:
40082 return -ENOMEM;
40083 }
40084
40085-static int btrfs_getattr(struct vfsmount *mnt,
40086+int btrfs_getattr(struct vfsmount *mnt,
40087 struct dentry *dentry, struct kstat *stat)
40088 {
40089 struct inode *inode = dentry->d_inode;
40090@@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount
40091 return 0;
40092 }
40093
40094+EXPORT_SYMBOL(btrfs_getattr);
40095+
40096+dev_t get_btrfs_dev_from_inode(struct inode *inode)
40097+{
40098+ return BTRFS_I(inode)->root->anon_super.s_dev;
40099+}
40100+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
40101+
40102 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
40103 struct inode *new_dir, struct dentry *new_dentry)
40104 {
40105@@ -5972,7 +5983,7 @@ static const struct file_operations btrf
40106 .fsync = btrfs_sync_file,
40107 };
40108
40109-static struct extent_io_ops btrfs_extent_io_ops = {
40110+static const struct extent_io_ops btrfs_extent_io_ops = {
40111 .fill_delalloc = run_delalloc_range,
40112 .submit_bio_hook = btrfs_submit_bio_hook,
40113 .merge_bio_hook = btrfs_merge_bio_hook,
40114diff -urNp linux-2.6.32.43/fs/btrfs/relocation.c linux-2.6.32.43/fs/btrfs/relocation.c
40115--- linux-2.6.32.43/fs/btrfs/relocation.c 2011-03-27 14:31:47.000000000 -0400
40116+++ linux-2.6.32.43/fs/btrfs/relocation.c 2011-04-17 15:56:46.000000000 -0400
40117@@ -884,7 +884,7 @@ static int __update_reloc_root(struct bt
40118 }
40119 spin_unlock(&rc->reloc_root_tree.lock);
40120
40121- BUG_ON((struct btrfs_root *)node->data != root);
40122+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
40123
40124 if (!del) {
40125 spin_lock(&rc->reloc_root_tree.lock);
40126diff -urNp linux-2.6.32.43/fs/btrfs/sysfs.c linux-2.6.32.43/fs/btrfs/sysfs.c
40127--- linux-2.6.32.43/fs/btrfs/sysfs.c 2011-03-27 14:31:47.000000000 -0400
40128+++ linux-2.6.32.43/fs/btrfs/sysfs.c 2011-04-17 15:56:46.000000000 -0400
40129@@ -164,12 +164,12 @@ static void btrfs_root_release(struct ko
40130 complete(&root->kobj_unregister);
40131 }
40132
40133-static struct sysfs_ops btrfs_super_attr_ops = {
40134+static const struct sysfs_ops btrfs_super_attr_ops = {
40135 .show = btrfs_super_attr_show,
40136 .store = btrfs_super_attr_store,
40137 };
40138
40139-static struct sysfs_ops btrfs_root_attr_ops = {
40140+static const struct sysfs_ops btrfs_root_attr_ops = {
40141 .show = btrfs_root_attr_show,
40142 .store = btrfs_root_attr_store,
40143 };
40144diff -urNp linux-2.6.32.43/fs/buffer.c linux-2.6.32.43/fs/buffer.c
40145--- linux-2.6.32.43/fs/buffer.c 2011-03-27 14:31:47.000000000 -0400
40146+++ linux-2.6.32.43/fs/buffer.c 2011-04-17 15:56:46.000000000 -0400
40147@@ -25,6 +25,7 @@
40148 #include <linux/percpu.h>
40149 #include <linux/slab.h>
40150 #include <linux/capability.h>
40151+#include <linux/security.h>
40152 #include <linux/blkdev.h>
40153 #include <linux/file.h>
40154 #include <linux/quotaops.h>
40155diff -urNp linux-2.6.32.43/fs/cachefiles/bind.c linux-2.6.32.43/fs/cachefiles/bind.c
40156--- linux-2.6.32.43/fs/cachefiles/bind.c 2011-03-27 14:31:47.000000000 -0400
40157+++ linux-2.6.32.43/fs/cachefiles/bind.c 2011-04-17 15:56:46.000000000 -0400
40158@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
40159 args);
40160
40161 /* start by checking things over */
40162- ASSERT(cache->fstop_percent >= 0 &&
40163- cache->fstop_percent < cache->fcull_percent &&
40164+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
40165 cache->fcull_percent < cache->frun_percent &&
40166 cache->frun_percent < 100);
40167
40168- ASSERT(cache->bstop_percent >= 0 &&
40169- cache->bstop_percent < cache->bcull_percent &&
40170+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
40171 cache->bcull_percent < cache->brun_percent &&
40172 cache->brun_percent < 100);
40173
40174diff -urNp linux-2.6.32.43/fs/cachefiles/daemon.c linux-2.6.32.43/fs/cachefiles/daemon.c
40175--- linux-2.6.32.43/fs/cachefiles/daemon.c 2011-03-27 14:31:47.000000000 -0400
40176+++ linux-2.6.32.43/fs/cachefiles/daemon.c 2011-04-17 15:56:46.000000000 -0400
40177@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(s
40178 if (test_bit(CACHEFILES_DEAD, &cache->flags))
40179 return -EIO;
40180
40181- if (datalen < 0 || datalen > PAGE_SIZE - 1)
40182+ if (datalen > PAGE_SIZE - 1)
40183 return -EOPNOTSUPP;
40184
40185 /* drag the command string into the kernel so we can parse it */
40186@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struc
40187 if (args[0] != '%' || args[1] != '\0')
40188 return -EINVAL;
40189
40190- if (fstop < 0 || fstop >= cache->fcull_percent)
40191+ if (fstop >= cache->fcull_percent)
40192 return cachefiles_daemon_range_error(cache, args);
40193
40194 cache->fstop_percent = fstop;
40195@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struc
40196 if (args[0] != '%' || args[1] != '\0')
40197 return -EINVAL;
40198
40199- if (bstop < 0 || bstop >= cache->bcull_percent)
40200+ if (bstop >= cache->bcull_percent)
40201 return cachefiles_daemon_range_error(cache, args);
40202
40203 cache->bstop_percent = bstop;
40204diff -urNp linux-2.6.32.43/fs/cachefiles/internal.h linux-2.6.32.43/fs/cachefiles/internal.h
40205--- linux-2.6.32.43/fs/cachefiles/internal.h 2011-03-27 14:31:47.000000000 -0400
40206+++ linux-2.6.32.43/fs/cachefiles/internal.h 2011-05-04 17:56:28.000000000 -0400
40207@@ -56,7 +56,7 @@ struct cachefiles_cache {
40208 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
40209 struct rb_root active_nodes; /* active nodes (can't be culled) */
40210 rwlock_t active_lock; /* lock for active_nodes */
40211- atomic_t gravecounter; /* graveyard uniquifier */
40212+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
40213 unsigned frun_percent; /* when to stop culling (% files) */
40214 unsigned fcull_percent; /* when to start culling (% files) */
40215 unsigned fstop_percent; /* when to stop allocating (% files) */
40216@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struc
40217 * proc.c
40218 */
40219 #ifdef CONFIG_CACHEFILES_HISTOGRAM
40220-extern atomic_t cachefiles_lookup_histogram[HZ];
40221-extern atomic_t cachefiles_mkdir_histogram[HZ];
40222-extern atomic_t cachefiles_create_histogram[HZ];
40223+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40224+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40225+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
40226
40227 extern int __init cachefiles_proc_init(void);
40228 extern void cachefiles_proc_cleanup(void);
40229 static inline
40230-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
40231+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
40232 {
40233 unsigned long jif = jiffies - start_jif;
40234 if (jif >= HZ)
40235 jif = HZ - 1;
40236- atomic_inc(&histogram[jif]);
40237+ atomic_inc_unchecked(&histogram[jif]);
40238 }
40239
40240 #else
40241diff -urNp linux-2.6.32.43/fs/cachefiles/namei.c linux-2.6.32.43/fs/cachefiles/namei.c
40242--- linux-2.6.32.43/fs/cachefiles/namei.c 2011-03-27 14:31:47.000000000 -0400
40243+++ linux-2.6.32.43/fs/cachefiles/namei.c 2011-05-04 17:56:28.000000000 -0400
40244@@ -250,7 +250,7 @@ try_again:
40245 /* first step is to make up a grave dentry in the graveyard */
40246 sprintf(nbuffer, "%08x%08x",
40247 (uint32_t) get_seconds(),
40248- (uint32_t) atomic_inc_return(&cache->gravecounter));
40249+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
40250
40251 /* do the multiway lock magic */
40252 trap = lock_rename(cache->graveyard, dir);
40253diff -urNp linux-2.6.32.43/fs/cachefiles/proc.c linux-2.6.32.43/fs/cachefiles/proc.c
40254--- linux-2.6.32.43/fs/cachefiles/proc.c 2011-03-27 14:31:47.000000000 -0400
40255+++ linux-2.6.32.43/fs/cachefiles/proc.c 2011-05-04 17:56:28.000000000 -0400
40256@@ -14,9 +14,9 @@
40257 #include <linux/seq_file.h>
40258 #include "internal.h"
40259
40260-atomic_t cachefiles_lookup_histogram[HZ];
40261-atomic_t cachefiles_mkdir_histogram[HZ];
40262-atomic_t cachefiles_create_histogram[HZ];
40263+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40264+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40265+atomic_unchecked_t cachefiles_create_histogram[HZ];
40266
40267 /*
40268 * display the latency histogram
40269@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
40270 return 0;
40271 default:
40272 index = (unsigned long) v - 3;
40273- x = atomic_read(&cachefiles_lookup_histogram[index]);
40274- y = atomic_read(&cachefiles_mkdir_histogram[index]);
40275- z = atomic_read(&cachefiles_create_histogram[index]);
40276+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
40277+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
40278+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
40279 if (x == 0 && y == 0 && z == 0)
40280 return 0;
40281
40282diff -urNp linux-2.6.32.43/fs/cachefiles/rdwr.c linux-2.6.32.43/fs/cachefiles/rdwr.c
40283--- linux-2.6.32.43/fs/cachefiles/rdwr.c 2011-03-27 14:31:47.000000000 -0400
40284+++ linux-2.6.32.43/fs/cachefiles/rdwr.c 2011-04-17 15:56:46.000000000 -0400
40285@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache
40286 old_fs = get_fs();
40287 set_fs(KERNEL_DS);
40288 ret = file->f_op->write(
40289- file, (const void __user *) data, len, &pos);
40290+ file, (__force const void __user *) data, len, &pos);
40291 set_fs(old_fs);
40292 kunmap(page);
40293 if (ret != len)
40294diff -urNp linux-2.6.32.43/fs/cifs/cifs_debug.c linux-2.6.32.43/fs/cifs/cifs_debug.c
40295--- linux-2.6.32.43/fs/cifs/cifs_debug.c 2011-03-27 14:31:47.000000000 -0400
40296+++ linux-2.6.32.43/fs/cifs/cifs_debug.c 2011-05-04 17:56:28.000000000 -0400
40297@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(str
40298 tcon = list_entry(tmp3,
40299 struct cifsTconInfo,
40300 tcon_list);
40301- atomic_set(&tcon->num_smbs_sent, 0);
40302- atomic_set(&tcon->num_writes, 0);
40303- atomic_set(&tcon->num_reads, 0);
40304- atomic_set(&tcon->num_oplock_brks, 0);
40305- atomic_set(&tcon->num_opens, 0);
40306- atomic_set(&tcon->num_posixopens, 0);
40307- atomic_set(&tcon->num_posixmkdirs, 0);
40308- atomic_set(&tcon->num_closes, 0);
40309- atomic_set(&tcon->num_deletes, 0);
40310- atomic_set(&tcon->num_mkdirs, 0);
40311- atomic_set(&tcon->num_rmdirs, 0);
40312- atomic_set(&tcon->num_renames, 0);
40313- atomic_set(&tcon->num_t2renames, 0);
40314- atomic_set(&tcon->num_ffirst, 0);
40315- atomic_set(&tcon->num_fnext, 0);
40316- atomic_set(&tcon->num_fclose, 0);
40317- atomic_set(&tcon->num_hardlinks, 0);
40318- atomic_set(&tcon->num_symlinks, 0);
40319- atomic_set(&tcon->num_locks, 0);
40320+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
40321+ atomic_set_unchecked(&tcon->num_writes, 0);
40322+ atomic_set_unchecked(&tcon->num_reads, 0);
40323+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
40324+ atomic_set_unchecked(&tcon->num_opens, 0);
40325+ atomic_set_unchecked(&tcon->num_posixopens, 0);
40326+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
40327+ atomic_set_unchecked(&tcon->num_closes, 0);
40328+ atomic_set_unchecked(&tcon->num_deletes, 0);
40329+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
40330+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
40331+ atomic_set_unchecked(&tcon->num_renames, 0);
40332+ atomic_set_unchecked(&tcon->num_t2renames, 0);
40333+ atomic_set_unchecked(&tcon->num_ffirst, 0);
40334+ atomic_set_unchecked(&tcon->num_fnext, 0);
40335+ atomic_set_unchecked(&tcon->num_fclose, 0);
40336+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
40337+ atomic_set_unchecked(&tcon->num_symlinks, 0);
40338+ atomic_set_unchecked(&tcon->num_locks, 0);
40339 }
40340 }
40341 }
40342@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct s
40343 if (tcon->need_reconnect)
40344 seq_puts(m, "\tDISCONNECTED ");
40345 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
40346- atomic_read(&tcon->num_smbs_sent),
40347- atomic_read(&tcon->num_oplock_brks));
40348+ atomic_read_unchecked(&tcon->num_smbs_sent),
40349+ atomic_read_unchecked(&tcon->num_oplock_brks));
40350 seq_printf(m, "\nReads: %d Bytes: %lld",
40351- atomic_read(&tcon->num_reads),
40352+ atomic_read_unchecked(&tcon->num_reads),
40353 (long long)(tcon->bytes_read));
40354 seq_printf(m, "\nWrites: %d Bytes: %lld",
40355- atomic_read(&tcon->num_writes),
40356+ atomic_read_unchecked(&tcon->num_writes),
40357 (long long)(tcon->bytes_written));
40358 seq_printf(m, "\nFlushes: %d",
40359- atomic_read(&tcon->num_flushes));
40360+ atomic_read_unchecked(&tcon->num_flushes));
40361 seq_printf(m, "\nLocks: %d HardLinks: %d "
40362 "Symlinks: %d",
40363- atomic_read(&tcon->num_locks),
40364- atomic_read(&tcon->num_hardlinks),
40365- atomic_read(&tcon->num_symlinks));
40366+ atomic_read_unchecked(&tcon->num_locks),
40367+ atomic_read_unchecked(&tcon->num_hardlinks),
40368+ atomic_read_unchecked(&tcon->num_symlinks));
40369 seq_printf(m, "\nOpens: %d Closes: %d "
40370 "Deletes: %d",
40371- atomic_read(&tcon->num_opens),
40372- atomic_read(&tcon->num_closes),
40373- atomic_read(&tcon->num_deletes));
40374+ atomic_read_unchecked(&tcon->num_opens),
40375+ atomic_read_unchecked(&tcon->num_closes),
40376+ atomic_read_unchecked(&tcon->num_deletes));
40377 seq_printf(m, "\nPosix Opens: %d "
40378 "Posix Mkdirs: %d",
40379- atomic_read(&tcon->num_posixopens),
40380- atomic_read(&tcon->num_posixmkdirs));
40381+ atomic_read_unchecked(&tcon->num_posixopens),
40382+ atomic_read_unchecked(&tcon->num_posixmkdirs));
40383 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
40384- atomic_read(&tcon->num_mkdirs),
40385- atomic_read(&tcon->num_rmdirs));
40386+ atomic_read_unchecked(&tcon->num_mkdirs),
40387+ atomic_read_unchecked(&tcon->num_rmdirs));
40388 seq_printf(m, "\nRenames: %d T2 Renames %d",
40389- atomic_read(&tcon->num_renames),
40390- atomic_read(&tcon->num_t2renames));
40391+ atomic_read_unchecked(&tcon->num_renames),
40392+ atomic_read_unchecked(&tcon->num_t2renames));
40393 seq_printf(m, "\nFindFirst: %d FNext %d "
40394 "FClose %d",
40395- atomic_read(&tcon->num_ffirst),
40396- atomic_read(&tcon->num_fnext),
40397- atomic_read(&tcon->num_fclose));
40398+ atomic_read_unchecked(&tcon->num_ffirst),
40399+ atomic_read_unchecked(&tcon->num_fnext),
40400+ atomic_read_unchecked(&tcon->num_fclose));
40401 }
40402 }
40403 }
40404diff -urNp linux-2.6.32.43/fs/cifs/cifsglob.h linux-2.6.32.43/fs/cifs/cifsglob.h
40405--- linux-2.6.32.43/fs/cifs/cifsglob.h 2011-03-27 14:31:47.000000000 -0400
40406+++ linux-2.6.32.43/fs/cifs/cifsglob.h 2011-05-04 17:56:28.000000000 -0400
40407@@ -252,28 +252,28 @@ struct cifsTconInfo {
40408 __u16 Flags; /* optional support bits */
40409 enum statusEnum tidStatus;
40410 #ifdef CONFIG_CIFS_STATS
40411- atomic_t num_smbs_sent;
40412- atomic_t num_writes;
40413- atomic_t num_reads;
40414- atomic_t num_flushes;
40415- atomic_t num_oplock_brks;
40416- atomic_t num_opens;
40417- atomic_t num_closes;
40418- atomic_t num_deletes;
40419- atomic_t num_mkdirs;
40420- atomic_t num_posixopens;
40421- atomic_t num_posixmkdirs;
40422- atomic_t num_rmdirs;
40423- atomic_t num_renames;
40424- atomic_t num_t2renames;
40425- atomic_t num_ffirst;
40426- atomic_t num_fnext;
40427- atomic_t num_fclose;
40428- atomic_t num_hardlinks;
40429- atomic_t num_symlinks;
40430- atomic_t num_locks;
40431- atomic_t num_acl_get;
40432- atomic_t num_acl_set;
40433+ atomic_unchecked_t num_smbs_sent;
40434+ atomic_unchecked_t num_writes;
40435+ atomic_unchecked_t num_reads;
40436+ atomic_unchecked_t num_flushes;
40437+ atomic_unchecked_t num_oplock_brks;
40438+ atomic_unchecked_t num_opens;
40439+ atomic_unchecked_t num_closes;
40440+ atomic_unchecked_t num_deletes;
40441+ atomic_unchecked_t num_mkdirs;
40442+ atomic_unchecked_t num_posixopens;
40443+ atomic_unchecked_t num_posixmkdirs;
40444+ atomic_unchecked_t num_rmdirs;
40445+ atomic_unchecked_t num_renames;
40446+ atomic_unchecked_t num_t2renames;
40447+ atomic_unchecked_t num_ffirst;
40448+ atomic_unchecked_t num_fnext;
40449+ atomic_unchecked_t num_fclose;
40450+ atomic_unchecked_t num_hardlinks;
40451+ atomic_unchecked_t num_symlinks;
40452+ atomic_unchecked_t num_locks;
40453+ atomic_unchecked_t num_acl_get;
40454+ atomic_unchecked_t num_acl_set;
40455 #ifdef CONFIG_CIFS_STATS2
40456 unsigned long long time_writes;
40457 unsigned long long time_reads;
40458@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const st
40459 }
40460
40461 #ifdef CONFIG_CIFS_STATS
40462-#define cifs_stats_inc atomic_inc
40463+#define cifs_stats_inc atomic_inc_unchecked
40464
40465 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
40466 unsigned int bytes)
40467diff -urNp linux-2.6.32.43/fs/cifs/link.c linux-2.6.32.43/fs/cifs/link.c
40468--- linux-2.6.32.43/fs/cifs/link.c 2011-03-27 14:31:47.000000000 -0400
40469+++ linux-2.6.32.43/fs/cifs/link.c 2011-04-17 15:56:46.000000000 -0400
40470@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct
40471
40472 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
40473 {
40474- char *p = nd_get_link(nd);
40475+ const char *p = nd_get_link(nd);
40476 if (!IS_ERR(p))
40477 kfree(p);
40478 }
40479diff -urNp linux-2.6.32.43/fs/coda/cache.c linux-2.6.32.43/fs/coda/cache.c
40480--- linux-2.6.32.43/fs/coda/cache.c 2011-03-27 14:31:47.000000000 -0400
40481+++ linux-2.6.32.43/fs/coda/cache.c 2011-05-04 17:56:28.000000000 -0400
40482@@ -24,14 +24,14 @@
40483 #include <linux/coda_fs_i.h>
40484 #include <linux/coda_cache.h>
40485
40486-static atomic_t permission_epoch = ATOMIC_INIT(0);
40487+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
40488
40489 /* replace or extend an acl cache hit */
40490 void coda_cache_enter(struct inode *inode, int mask)
40491 {
40492 struct coda_inode_info *cii = ITOC(inode);
40493
40494- cii->c_cached_epoch = atomic_read(&permission_epoch);
40495+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
40496 if (cii->c_uid != current_fsuid()) {
40497 cii->c_uid = current_fsuid();
40498 cii->c_cached_perm = mask;
40499@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inod
40500 void coda_cache_clear_inode(struct inode *inode)
40501 {
40502 struct coda_inode_info *cii = ITOC(inode);
40503- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
40504+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
40505 }
40506
40507 /* remove all acl caches */
40508 void coda_cache_clear_all(struct super_block *sb)
40509 {
40510- atomic_inc(&permission_epoch);
40511+ atomic_inc_unchecked(&permission_epoch);
40512 }
40513
40514
40515@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode
40516
40517 hit = (mask & cii->c_cached_perm) == mask &&
40518 cii->c_uid == current_fsuid() &&
40519- cii->c_cached_epoch == atomic_read(&permission_epoch);
40520+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
40521
40522 return hit;
40523 }
40524diff -urNp linux-2.6.32.43/fs/compat_binfmt_elf.c linux-2.6.32.43/fs/compat_binfmt_elf.c
40525--- linux-2.6.32.43/fs/compat_binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
40526+++ linux-2.6.32.43/fs/compat_binfmt_elf.c 2011-04-17 15:56:46.000000000 -0400
40527@@ -29,10 +29,12 @@
40528 #undef elfhdr
40529 #undef elf_phdr
40530 #undef elf_note
40531+#undef elf_dyn
40532 #undef elf_addr_t
40533 #define elfhdr elf32_hdr
40534 #define elf_phdr elf32_phdr
40535 #define elf_note elf32_note
40536+#define elf_dyn Elf32_Dyn
40537 #define elf_addr_t Elf32_Addr
40538
40539 /*
40540diff -urNp linux-2.6.32.43/fs/compat.c linux-2.6.32.43/fs/compat.c
40541--- linux-2.6.32.43/fs/compat.c 2011-04-17 17:00:52.000000000 -0400
40542+++ linux-2.6.32.43/fs/compat.c 2011-05-16 21:46:57.000000000 -0400
40543@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
40544
40545 struct compat_readdir_callback {
40546 struct compat_old_linux_dirent __user *dirent;
40547+ struct file * file;
40548 int result;
40549 };
40550
40551@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf
40552 buf->result = -EOVERFLOW;
40553 return -EOVERFLOW;
40554 }
40555+
40556+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
40557+ return 0;
40558+
40559 buf->result++;
40560 dirent = buf->dirent;
40561 if (!access_ok(VERIFY_WRITE, dirent,
40562@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(u
40563
40564 buf.result = 0;
40565 buf.dirent = dirent;
40566+ buf.file = file;
40567
40568 error = vfs_readdir(file, compat_fillonedir, &buf);
40569 if (buf.result)
40570@@ -899,6 +905,7 @@ struct compat_linux_dirent {
40571 struct compat_getdents_callback {
40572 struct compat_linux_dirent __user *current_dir;
40573 struct compat_linux_dirent __user *previous;
40574+ struct file * file;
40575 int count;
40576 int error;
40577 };
40578@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, c
40579 buf->error = -EOVERFLOW;
40580 return -EOVERFLOW;
40581 }
40582+
40583+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
40584+ return 0;
40585+
40586 dirent = buf->previous;
40587 if (dirent) {
40588 if (__put_user(offset, &dirent->d_off))
40589@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsi
40590 buf.previous = NULL;
40591 buf.count = count;
40592 buf.error = 0;
40593+ buf.file = file;
40594
40595 error = vfs_readdir(file, compat_filldir, &buf);
40596 if (error >= 0)
40597@@ -987,6 +999,7 @@ out:
40598 struct compat_getdents_callback64 {
40599 struct linux_dirent64 __user *current_dir;
40600 struct linux_dirent64 __user *previous;
40601+ struct file * file;
40602 int count;
40603 int error;
40604 };
40605@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf
40606 buf->error = -EINVAL; /* only used if we fail.. */
40607 if (reclen > buf->count)
40608 return -EINVAL;
40609+
40610+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
40611+ return 0;
40612+
40613 dirent = buf->previous;
40614
40615 if (dirent) {
40616@@ -1054,6 +1071,7 @@ asmlinkage long compat_sys_getdents64(un
40617 buf.previous = NULL;
40618 buf.count = count;
40619 buf.error = 0;
40620+ buf.file = file;
40621
40622 error = vfs_readdir(file, compat_filldir64, &buf);
40623 if (error >= 0)
40624@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(in
40625 * verify all the pointers
40626 */
40627 ret = -EINVAL;
40628- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
40629+ if (nr_segs > UIO_MAXIOV)
40630 goto out;
40631 if (!file->f_op)
40632 goto out;
40633@@ -1463,6 +1481,11 @@ int compat_do_execve(char * filename,
40634 compat_uptr_t __user *envp,
40635 struct pt_regs * regs)
40636 {
40637+#ifdef CONFIG_GRKERNSEC
40638+ struct file *old_exec_file;
40639+ struct acl_subject_label *old_acl;
40640+ struct rlimit old_rlim[RLIM_NLIMITS];
40641+#endif
40642 struct linux_binprm *bprm;
40643 struct file *file;
40644 struct files_struct *displaced;
40645@@ -1499,6 +1522,19 @@ int compat_do_execve(char * filename,
40646 bprm->filename = filename;
40647 bprm->interp = filename;
40648
40649+ if (gr_process_user_ban()) {
40650+ retval = -EPERM;
40651+ goto out_file;
40652+ }
40653+
40654+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
40655+ retval = -EAGAIN;
40656+ if (gr_handle_nproc())
40657+ goto out_file;
40658+ retval = -EACCES;
40659+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
40660+ goto out_file;
40661+
40662 retval = bprm_mm_init(bprm);
40663 if (retval)
40664 goto out_file;
40665@@ -1528,9 +1564,40 @@ int compat_do_execve(char * filename,
40666 if (retval < 0)
40667 goto out;
40668
40669+ if (!gr_tpe_allow(file)) {
40670+ retval = -EACCES;
40671+ goto out;
40672+ }
40673+
40674+ if (gr_check_crash_exec(file)) {
40675+ retval = -EACCES;
40676+ goto out;
40677+ }
40678+
40679+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
40680+
40681+ gr_handle_exec_args_compat(bprm, argv);
40682+
40683+#ifdef CONFIG_GRKERNSEC
40684+ old_acl = current->acl;
40685+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
40686+ old_exec_file = current->exec_file;
40687+ get_file(file);
40688+ current->exec_file = file;
40689+#endif
40690+
40691+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
40692+ bprm->unsafe & LSM_UNSAFE_SHARE);
40693+ if (retval < 0)
40694+ goto out_fail;
40695+
40696 retval = search_binary_handler(bprm, regs);
40697 if (retval < 0)
40698- goto out;
40699+ goto out_fail;
40700+#ifdef CONFIG_GRKERNSEC
40701+ if (old_exec_file)
40702+ fput(old_exec_file);
40703+#endif
40704
40705 /* execve succeeded */
40706 current->fs->in_exec = 0;
40707@@ -1541,6 +1608,14 @@ int compat_do_execve(char * filename,
40708 put_files_struct(displaced);
40709 return retval;
40710
40711+out_fail:
40712+#ifdef CONFIG_GRKERNSEC
40713+ current->acl = old_acl;
40714+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
40715+ fput(current->exec_file);
40716+ current->exec_file = old_exec_file;
40717+#endif
40718+
40719 out:
40720 if (bprm->mm) {
40721 acct_arg_size(bprm, 0);
40722@@ -1711,6 +1786,8 @@ int compat_core_sys_select(int n, compat
40723 struct fdtable *fdt;
40724 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
40725
40726+ pax_track_stack();
40727+
40728 if (n < 0)
40729 goto out_nofds;
40730
40731diff -urNp linux-2.6.32.43/fs/compat_ioctl.c linux-2.6.32.43/fs/compat_ioctl.c
40732--- linux-2.6.32.43/fs/compat_ioctl.c 2011-03-27 14:31:47.000000000 -0400
40733+++ linux-2.6.32.43/fs/compat_ioctl.c 2011-04-23 12:56:11.000000000 -0400
40734@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsi
40735 up = (struct compat_video_spu_palette __user *) arg;
40736 err = get_user(palp, &up->palette);
40737 err |= get_user(length, &up->length);
40738+ if (err)
40739+ return -EFAULT;
40740
40741 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
40742 err = put_user(compat_ptr(palp), &up_native->palette);
40743diff -urNp linux-2.6.32.43/fs/configfs/dir.c linux-2.6.32.43/fs/configfs/dir.c
40744--- linux-2.6.32.43/fs/configfs/dir.c 2011-03-27 14:31:47.000000000 -0400
40745+++ linux-2.6.32.43/fs/configfs/dir.c 2011-05-11 18:25:15.000000000 -0400
40746@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file
40747 }
40748 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
40749 struct configfs_dirent *next;
40750- const char * name;
40751+ const unsigned char * name;
40752+ char d_name[sizeof(next->s_dentry->d_iname)];
40753 int len;
40754
40755 next = list_entry(p, struct configfs_dirent,
40756@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file
40757 continue;
40758
40759 name = configfs_get_name(next);
40760- len = strlen(name);
40761+ if (next->s_dentry && name == next->s_dentry->d_iname) {
40762+ len = next->s_dentry->d_name.len;
40763+ memcpy(d_name, name, len);
40764+ name = d_name;
40765+ } else
40766+ len = strlen(name);
40767 if (next->s_dentry)
40768 ino = next->s_dentry->d_inode->i_ino;
40769 else
40770diff -urNp linux-2.6.32.43/fs/dcache.c linux-2.6.32.43/fs/dcache.c
40771--- linux-2.6.32.43/fs/dcache.c 2011-03-27 14:31:47.000000000 -0400
40772+++ linux-2.6.32.43/fs/dcache.c 2011-04-23 13:32:21.000000000 -0400
40773@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
40774
40775 static struct kmem_cache *dentry_cache __read_mostly;
40776
40777-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
40778-
40779 /*
40780 * This is the single most critical data structure when it comes
40781 * to the dcache: the hashtable for lookups. Somebody should try
40782@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned lon
40783 mempages -= reserve;
40784
40785 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
40786- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
40787+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
40788
40789 dcache_init();
40790 inode_init();
40791diff -urNp linux-2.6.32.43/fs/dlm/lockspace.c linux-2.6.32.43/fs/dlm/lockspace.c
40792--- linux-2.6.32.43/fs/dlm/lockspace.c 2011-03-27 14:31:47.000000000 -0400
40793+++ linux-2.6.32.43/fs/dlm/lockspace.c 2011-04-17 15:56:46.000000000 -0400
40794@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struc
40795 kfree(ls);
40796 }
40797
40798-static struct sysfs_ops dlm_attr_ops = {
40799+static const struct sysfs_ops dlm_attr_ops = {
40800 .show = dlm_attr_show,
40801 .store = dlm_attr_store,
40802 };
40803diff -urNp linux-2.6.32.43/fs/ecryptfs/inode.c linux-2.6.32.43/fs/ecryptfs/inode.c
40804--- linux-2.6.32.43/fs/ecryptfs/inode.c 2011-03-27 14:31:47.000000000 -0400
40805+++ linux-2.6.32.43/fs/ecryptfs/inode.c 2011-04-17 15:56:46.000000000 -0400
40806@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struc
40807 old_fs = get_fs();
40808 set_fs(get_ds());
40809 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
40810- (char __user *)lower_buf,
40811+ (__force char __user *)lower_buf,
40812 lower_bufsiz);
40813 set_fs(old_fs);
40814 if (rc < 0)
40815@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct
40816 }
40817 old_fs = get_fs();
40818 set_fs(get_ds());
40819- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
40820+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
40821 set_fs(old_fs);
40822 if (rc < 0)
40823 goto out_free;
40824diff -urNp linux-2.6.32.43/fs/exec.c linux-2.6.32.43/fs/exec.c
40825--- linux-2.6.32.43/fs/exec.c 2011-06-25 12:55:34.000000000 -0400
40826+++ linux-2.6.32.43/fs/exec.c 2011-07-06 19:53:33.000000000 -0400
40827@@ -56,12 +56,24 @@
40828 #include <linux/fsnotify.h>
40829 #include <linux/fs_struct.h>
40830 #include <linux/pipe_fs_i.h>
40831+#include <linux/random.h>
40832+#include <linux/seq_file.h>
40833+
40834+#ifdef CONFIG_PAX_REFCOUNT
40835+#include <linux/kallsyms.h>
40836+#include <linux/kdebug.h>
40837+#endif
40838
40839 #include <asm/uaccess.h>
40840 #include <asm/mmu_context.h>
40841 #include <asm/tlb.h>
40842 #include "internal.h"
40843
40844+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
40845+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
40846+EXPORT_SYMBOL(pax_set_initial_flags_func);
40847+#endif
40848+
40849 int core_uses_pid;
40850 char core_pattern[CORENAME_MAX_SIZE] = "core";
40851 unsigned int core_pipe_limit;
40852@@ -115,7 +127,7 @@ SYSCALL_DEFINE1(uselib, const char __use
40853 goto out;
40854
40855 file = do_filp_open(AT_FDCWD, tmp,
40856- O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
40857+ O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
40858 MAY_READ | MAY_EXEC | MAY_OPEN);
40859 putname(tmp);
40860 error = PTR_ERR(file);
40861@@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_b
40862 int write)
40863 {
40864 struct page *page;
40865- int ret;
40866
40867-#ifdef CONFIG_STACK_GROWSUP
40868- if (write) {
40869- ret = expand_stack_downwards(bprm->vma, pos);
40870- if (ret < 0)
40871- return NULL;
40872- }
40873-#endif
40874- ret = get_user_pages(current, bprm->mm, pos,
40875- 1, write, 1, &page, NULL);
40876- if (ret <= 0)
40877+ if (0 > expand_stack_downwards(bprm->vma, pos))
40878+ return NULL;
40879+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
40880 return NULL;
40881
40882 if (write) {
40883@@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_b
40884 vma->vm_end = STACK_TOP_MAX;
40885 vma->vm_start = vma->vm_end - PAGE_SIZE;
40886 vma->vm_flags = VM_STACK_FLAGS;
40887+
40888+#ifdef CONFIG_PAX_SEGMEXEC
40889+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
40890+#endif
40891+
40892 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
40893
40894 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
40895@@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_b
40896 mm->stack_vm = mm->total_vm = 1;
40897 up_write(&mm->mmap_sem);
40898 bprm->p = vma->vm_end - sizeof(void *);
40899+
40900+#ifdef CONFIG_PAX_RANDUSTACK
40901+ if (randomize_va_space)
40902+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
40903+#endif
40904+
40905 return 0;
40906 err:
40907 up_write(&mm->mmap_sem);
40908@@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char **
40909 int r;
40910 mm_segment_t oldfs = get_fs();
40911 set_fs(KERNEL_DS);
40912- r = copy_strings(argc, (char __user * __user *)argv, bprm);
40913+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
40914 set_fs(oldfs);
40915 return r;
40916 }
40917@@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_are
40918 unsigned long new_end = old_end - shift;
40919 struct mmu_gather *tlb;
40920
40921- BUG_ON(new_start > new_end);
40922+ if (new_start >= new_end || new_start < mmap_min_addr)
40923+ return -ENOMEM;
40924
40925 /*
40926 * ensure there are no vmas between where we want to go
40927@@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_are
40928 if (vma != find_vma(mm, new_start))
40929 return -EFAULT;
40930
40931+#ifdef CONFIG_PAX_SEGMEXEC
40932+ BUG_ON(pax_find_mirror_vma(vma));
40933+#endif
40934+
40935 /*
40936 * cover the whole range: [new_start, old_end)
40937 */
40938@@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm
40939 stack_top = arch_align_stack(stack_top);
40940 stack_top = PAGE_ALIGN(stack_top);
40941
40942- if (unlikely(stack_top < mmap_min_addr) ||
40943- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
40944- return -ENOMEM;
40945-
40946 stack_shift = vma->vm_end - stack_top;
40947
40948 bprm->p -= stack_shift;
40949@@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm
40950 bprm->exec -= stack_shift;
40951
40952 down_write(&mm->mmap_sem);
40953+
40954+ /* Move stack pages down in memory. */
40955+ if (stack_shift) {
40956+ ret = shift_arg_pages(vma, stack_shift);
40957+ if (ret)
40958+ goto out_unlock;
40959+ }
40960+
40961 vm_flags = VM_STACK_FLAGS;
40962
40963 /*
40964@@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm
40965 vm_flags &= ~VM_EXEC;
40966 vm_flags |= mm->def_flags;
40967
40968+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
40969+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40970+ vm_flags &= ~VM_EXEC;
40971+
40972+#ifdef CONFIG_PAX_MPROTECT
40973+ if (mm->pax_flags & MF_PAX_MPROTECT)
40974+ vm_flags &= ~VM_MAYEXEC;
40975+#endif
40976+
40977+ }
40978+#endif
40979+
40980 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
40981 vm_flags);
40982 if (ret)
40983 goto out_unlock;
40984 BUG_ON(prev != vma);
40985
40986- /* Move stack pages down in memory. */
40987- if (stack_shift) {
40988- ret = shift_arg_pages(vma, stack_shift);
40989- if (ret)
40990- goto out_unlock;
40991- }
40992-
40993 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
40994 stack_size = vma->vm_end - vma->vm_start;
40995 /*
40996@@ -707,7 +736,7 @@ struct file *open_exec(const char *name)
40997 int err;
40998
40999 file = do_filp_open(AT_FDCWD, name,
41000- O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
41001+ O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
41002 MAY_EXEC | MAY_OPEN);
41003 if (IS_ERR(file))
41004 goto out;
41005@@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_
41006 old_fs = get_fs();
41007 set_fs(get_ds());
41008 /* The cast to a user pointer is valid due to the set_fs() */
41009- result = vfs_read(file, (void __user *)addr, count, &pos);
41010+ result = vfs_read(file, (__force void __user *)addr, count, &pos);
41011 set_fs(old_fs);
41012 return result;
41013 }
41014@@ -1152,7 +1181,7 @@ int check_unsafe_exec(struct linux_binpr
41015 }
41016 rcu_read_unlock();
41017
41018- if (p->fs->users > n_fs) {
41019+ if (atomic_read(&p->fs->users) > n_fs) {
41020 bprm->unsafe |= LSM_UNSAFE_SHARE;
41021 } else {
41022 res = -EAGAIN;
41023@@ -1347,6 +1376,11 @@ int do_execve(char * filename,
41024 char __user *__user *envp,
41025 struct pt_regs * regs)
41026 {
41027+#ifdef CONFIG_GRKERNSEC
41028+ struct file *old_exec_file;
41029+ struct acl_subject_label *old_acl;
41030+ struct rlimit old_rlim[RLIM_NLIMITS];
41031+#endif
41032 struct linux_binprm *bprm;
41033 struct file *file;
41034 struct files_struct *displaced;
41035@@ -1383,6 +1417,23 @@ int do_execve(char * filename,
41036 bprm->filename = filename;
41037 bprm->interp = filename;
41038
41039+ if (gr_process_user_ban()) {
41040+ retval = -EPERM;
41041+ goto out_file;
41042+ }
41043+
41044+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
41045+
41046+ if (gr_handle_nproc()) {
41047+ retval = -EAGAIN;
41048+ goto out_file;
41049+ }
41050+
41051+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
41052+ retval = -EACCES;
41053+ goto out_file;
41054+ }
41055+
41056 retval = bprm_mm_init(bprm);
41057 if (retval)
41058 goto out_file;
41059@@ -1412,10 +1463,41 @@ int do_execve(char * filename,
41060 if (retval < 0)
41061 goto out;
41062
41063+ if (!gr_tpe_allow(file)) {
41064+ retval = -EACCES;
41065+ goto out;
41066+ }
41067+
41068+ if (gr_check_crash_exec(file)) {
41069+ retval = -EACCES;
41070+ goto out;
41071+ }
41072+
41073+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
41074+
41075+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
41076+
41077+#ifdef CONFIG_GRKERNSEC
41078+ old_acl = current->acl;
41079+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
41080+ old_exec_file = current->exec_file;
41081+ get_file(file);
41082+ current->exec_file = file;
41083+#endif
41084+
41085+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
41086+ bprm->unsafe & LSM_UNSAFE_SHARE);
41087+ if (retval < 0)
41088+ goto out_fail;
41089+
41090 current->flags &= ~PF_KTHREAD;
41091 retval = search_binary_handler(bprm,regs);
41092 if (retval < 0)
41093- goto out;
41094+ goto out_fail;
41095+#ifdef CONFIG_GRKERNSEC
41096+ if (old_exec_file)
41097+ fput(old_exec_file);
41098+#endif
41099
41100 /* execve succeeded */
41101 current->fs->in_exec = 0;
41102@@ -1426,6 +1508,14 @@ int do_execve(char * filename,
41103 put_files_struct(displaced);
41104 return retval;
41105
41106+out_fail:
41107+#ifdef CONFIG_GRKERNSEC
41108+ current->acl = old_acl;
41109+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
41110+ fput(current->exec_file);
41111+ current->exec_file = old_exec_file;
41112+#endif
41113+
41114 out:
41115 if (bprm->mm) {
41116 acct_arg_size(bprm, 0);
41117@@ -1591,6 +1681,220 @@ out:
41118 return ispipe;
41119 }
41120
41121+int pax_check_flags(unsigned long *flags)
41122+{
41123+ int retval = 0;
41124+
41125+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
41126+ if (*flags & MF_PAX_SEGMEXEC)
41127+ {
41128+ *flags &= ~MF_PAX_SEGMEXEC;
41129+ retval = -EINVAL;
41130+ }
41131+#endif
41132+
41133+ if ((*flags & MF_PAX_PAGEEXEC)
41134+
41135+#ifdef CONFIG_PAX_PAGEEXEC
41136+ && (*flags & MF_PAX_SEGMEXEC)
41137+#endif
41138+
41139+ )
41140+ {
41141+ *flags &= ~MF_PAX_PAGEEXEC;
41142+ retval = -EINVAL;
41143+ }
41144+
41145+ if ((*flags & MF_PAX_MPROTECT)
41146+
41147+#ifdef CONFIG_PAX_MPROTECT
41148+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41149+#endif
41150+
41151+ )
41152+ {
41153+ *flags &= ~MF_PAX_MPROTECT;
41154+ retval = -EINVAL;
41155+ }
41156+
41157+ if ((*flags & MF_PAX_EMUTRAMP)
41158+
41159+#ifdef CONFIG_PAX_EMUTRAMP
41160+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
41161+#endif
41162+
41163+ )
41164+ {
41165+ *flags &= ~MF_PAX_EMUTRAMP;
41166+ retval = -EINVAL;
41167+ }
41168+
41169+ return retval;
41170+}
41171+
41172+EXPORT_SYMBOL(pax_check_flags);
41173+
41174+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41175+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
41176+{
41177+ struct task_struct *tsk = current;
41178+ struct mm_struct *mm = current->mm;
41179+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
41180+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
41181+ char *path_exec = NULL;
41182+ char *path_fault = NULL;
41183+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
41184+
41185+ if (buffer_exec && buffer_fault) {
41186+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
41187+
41188+ down_read(&mm->mmap_sem);
41189+ vma = mm->mmap;
41190+ while (vma && (!vma_exec || !vma_fault)) {
41191+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
41192+ vma_exec = vma;
41193+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
41194+ vma_fault = vma;
41195+ vma = vma->vm_next;
41196+ }
41197+ if (vma_exec) {
41198+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
41199+ if (IS_ERR(path_exec))
41200+ path_exec = "<path too long>";
41201+ else {
41202+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
41203+ if (path_exec) {
41204+ *path_exec = 0;
41205+ path_exec = buffer_exec;
41206+ } else
41207+ path_exec = "<path too long>";
41208+ }
41209+ }
41210+ if (vma_fault) {
41211+ start = vma_fault->vm_start;
41212+ end = vma_fault->vm_end;
41213+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
41214+ if (vma_fault->vm_file) {
41215+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
41216+ if (IS_ERR(path_fault))
41217+ path_fault = "<path too long>";
41218+ else {
41219+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
41220+ if (path_fault) {
41221+ *path_fault = 0;
41222+ path_fault = buffer_fault;
41223+ } else
41224+ path_fault = "<path too long>";
41225+ }
41226+ } else
41227+ path_fault = "<anonymous mapping>";
41228+ }
41229+ up_read(&mm->mmap_sem);
41230+ }
41231+ if (tsk->signal->curr_ip)
41232+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
41233+ else
41234+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
41235+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
41236+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
41237+ task_uid(tsk), task_euid(tsk), pc, sp);
41238+ free_page((unsigned long)buffer_exec);
41239+ free_page((unsigned long)buffer_fault);
41240+ pax_report_insns(pc, sp);
41241+ do_coredump(SIGKILL, SIGKILL, regs);
41242+}
41243+#endif
41244+
41245+#ifdef CONFIG_PAX_REFCOUNT
41246+void pax_report_refcount_overflow(struct pt_regs *regs)
41247+{
41248+ if (current->signal->curr_ip)
41249+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
41250+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
41251+ else
41252+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
41253+ current->comm, task_pid_nr(current), current_uid(), current_euid());
41254+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
41255+ show_regs(regs);
41256+ force_sig_specific(SIGKILL, current);
41257+}
41258+#endif
41259+
41260+#ifdef CONFIG_PAX_USERCOPY
41261+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
41262+int object_is_on_stack(const void *obj, unsigned long len)
41263+{
41264+ const void * const stack = task_stack_page(current);
41265+ const void * const stackend = stack + THREAD_SIZE;
41266+
41267+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
41268+ const void *frame = NULL;
41269+ const void *oldframe;
41270+#endif
41271+
41272+ if (obj + len < obj)
41273+ return -1;
41274+
41275+ if (obj + len <= stack || stackend <= obj)
41276+ return 0;
41277+
41278+ if (obj < stack || stackend < obj + len)
41279+ return -1;
41280+
41281+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
41282+ oldframe = __builtin_frame_address(1);
41283+ if (oldframe)
41284+ frame = __builtin_frame_address(2);
41285+ /*
41286+ low ----------------------------------------------> high
41287+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
41288+ ^----------------^
41289+ allow copies only within here
41290+ */
41291+ while (stack <= frame && frame < stackend) {
41292+ /* if obj + len extends past the last frame, this
41293+ check won't pass and the next frame will be 0,
41294+ causing us to bail out and correctly report
41295+ the copy as invalid
41296+ */
41297+ if (obj + len <= frame)
41298+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
41299+ oldframe = frame;
41300+ frame = *(const void * const *)frame;
41301+ }
41302+ return -1;
41303+#else
41304+ return 1;
41305+#endif
41306+}
41307+
41308+
41309+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
41310+{
41311+ if (current->signal->curr_ip)
41312+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
41313+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
41314+ else
41315+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
41316+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
41317+
41318+ dump_stack();
41319+ gr_handle_kernel_exploit();
41320+ do_group_exit(SIGKILL);
41321+}
41322+#endif
41323+
41324+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
41325+void pax_track_stack(void)
41326+{
41327+ unsigned long sp = (unsigned long)&sp;
41328+ if (sp < current_thread_info()->lowest_stack &&
41329+ sp > (unsigned long)task_stack_page(current))
41330+ current_thread_info()->lowest_stack = sp;
41331+}
41332+EXPORT_SYMBOL(pax_track_stack);
41333+#endif
41334+
41335 static int zap_process(struct task_struct *start)
41336 {
41337 struct task_struct *t;
41338@@ -1793,17 +2097,17 @@ static void wait_for_dump_helpers(struct
41339 pipe = file->f_path.dentry->d_inode->i_pipe;
41340
41341 pipe_lock(pipe);
41342- pipe->readers++;
41343- pipe->writers--;
41344+ atomic_inc(&pipe->readers);
41345+ atomic_dec(&pipe->writers);
41346
41347- while ((pipe->readers > 1) && (!signal_pending(current))) {
41348+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
41349 wake_up_interruptible_sync(&pipe->wait);
41350 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
41351 pipe_wait(pipe);
41352 }
41353
41354- pipe->readers--;
41355- pipe->writers++;
41356+ atomic_dec(&pipe->readers);
41357+ atomic_inc(&pipe->writers);
41358 pipe_unlock(pipe);
41359
41360 }
41361@@ -1826,10 +2130,13 @@ void do_coredump(long signr, int exit_co
41362 char **helper_argv = NULL;
41363 int helper_argc = 0;
41364 int dump_count = 0;
41365- static atomic_t core_dump_count = ATOMIC_INIT(0);
41366+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
41367
41368 audit_core_dumps(signr);
41369
41370+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
41371+ gr_handle_brute_attach(current, mm->flags);
41372+
41373 binfmt = mm->binfmt;
41374 if (!binfmt || !binfmt->core_dump)
41375 goto fail;
41376@@ -1874,6 +2181,8 @@ void do_coredump(long signr, int exit_co
41377 */
41378 clear_thread_flag(TIF_SIGPENDING);
41379
41380+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
41381+
41382 /*
41383 * lock_kernel() because format_corename() is controlled by sysctl, which
41384 * uses lock_kernel()
41385@@ -1908,7 +2217,7 @@ void do_coredump(long signr, int exit_co
41386 goto fail_unlock;
41387 }
41388
41389- dump_count = atomic_inc_return(&core_dump_count);
41390+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
41391 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
41392 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
41393 task_tgid_vnr(current), current->comm);
41394@@ -1972,7 +2281,7 @@ close_fail:
41395 filp_close(file, NULL);
41396 fail_dropcount:
41397 if (dump_count)
41398- atomic_dec(&core_dump_count);
41399+ atomic_dec_unchecked(&core_dump_count);
41400 fail_unlock:
41401 if (helper_argv)
41402 argv_free(helper_argv);
41403diff -urNp linux-2.6.32.43/fs/ext2/balloc.c linux-2.6.32.43/fs/ext2/balloc.c
41404--- linux-2.6.32.43/fs/ext2/balloc.c 2011-03-27 14:31:47.000000000 -0400
41405+++ linux-2.6.32.43/fs/ext2/balloc.c 2011-04-17 15:56:46.000000000 -0400
41406@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
41407
41408 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
41409 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
41410- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
41411+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
41412 sbi->s_resuid != current_fsuid() &&
41413 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
41414 return 0;
41415diff -urNp linux-2.6.32.43/fs/ext3/balloc.c linux-2.6.32.43/fs/ext3/balloc.c
41416--- linux-2.6.32.43/fs/ext3/balloc.c 2011-03-27 14:31:47.000000000 -0400
41417+++ linux-2.6.32.43/fs/ext3/balloc.c 2011-04-17 15:56:46.000000000 -0400
41418@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
41419
41420 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
41421 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
41422- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
41423+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
41424 sbi->s_resuid != current_fsuid() &&
41425 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
41426 return 0;
41427diff -urNp linux-2.6.32.43/fs/ext4/balloc.c linux-2.6.32.43/fs/ext4/balloc.c
41428--- linux-2.6.32.43/fs/ext4/balloc.c 2011-03-27 14:31:47.000000000 -0400
41429+++ linux-2.6.32.43/fs/ext4/balloc.c 2011-04-17 15:56:46.000000000 -0400
41430@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_
41431 /* Hm, nope. Are (enough) root reserved blocks available? */
41432 if (sbi->s_resuid == current_fsuid() ||
41433 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
41434- capable(CAP_SYS_RESOURCE)) {
41435+ capable_nolog(CAP_SYS_RESOURCE)) {
41436 if (free_blocks >= (nblocks + dirty_blocks))
41437 return 1;
41438 }
41439diff -urNp linux-2.6.32.43/fs/ext4/ext4.h linux-2.6.32.43/fs/ext4/ext4.h
41440--- linux-2.6.32.43/fs/ext4/ext4.h 2011-03-27 14:31:47.000000000 -0400
41441+++ linux-2.6.32.43/fs/ext4/ext4.h 2011-04-17 15:56:46.000000000 -0400
41442@@ -1078,19 +1078,19 @@ struct ext4_sb_info {
41443
41444 /* stats for buddy allocator */
41445 spinlock_t s_mb_pa_lock;
41446- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
41447- atomic_t s_bal_success; /* we found long enough chunks */
41448- atomic_t s_bal_allocated; /* in blocks */
41449- atomic_t s_bal_ex_scanned; /* total extents scanned */
41450- atomic_t s_bal_goals; /* goal hits */
41451- atomic_t s_bal_breaks; /* too long searches */
41452- atomic_t s_bal_2orders; /* 2^order hits */
41453+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
41454+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
41455+ atomic_unchecked_t s_bal_allocated; /* in blocks */
41456+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
41457+ atomic_unchecked_t s_bal_goals; /* goal hits */
41458+ atomic_unchecked_t s_bal_breaks; /* too long searches */
41459+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
41460 spinlock_t s_bal_lock;
41461 unsigned long s_mb_buddies_generated;
41462 unsigned long long s_mb_generation_time;
41463- atomic_t s_mb_lost_chunks;
41464- atomic_t s_mb_preallocated;
41465- atomic_t s_mb_discarded;
41466+ atomic_unchecked_t s_mb_lost_chunks;
41467+ atomic_unchecked_t s_mb_preallocated;
41468+ atomic_unchecked_t s_mb_discarded;
41469 atomic_t s_lock_busy;
41470
41471 /* locality groups */
41472diff -urNp linux-2.6.32.43/fs/ext4/mballoc.c linux-2.6.32.43/fs/ext4/mballoc.c
41473--- linux-2.6.32.43/fs/ext4/mballoc.c 2011-06-25 12:55:34.000000000 -0400
41474+++ linux-2.6.32.43/fs/ext4/mballoc.c 2011-06-25 12:56:37.000000000 -0400
41475@@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ex
41476 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
41477
41478 if (EXT4_SB(sb)->s_mb_stats)
41479- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
41480+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
41481
41482 break;
41483 }
41484@@ -2131,7 +2131,7 @@ repeat:
41485 ac->ac_status = AC_STATUS_CONTINUE;
41486 ac->ac_flags |= EXT4_MB_HINT_FIRST;
41487 cr = 3;
41488- atomic_inc(&sbi->s_mb_lost_chunks);
41489+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
41490 goto repeat;
41491 }
41492 }
41493@@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struc
41494 ext4_grpblk_t counters[16];
41495 } sg;
41496
41497+ pax_track_stack();
41498+
41499 group--;
41500 if (group == 0)
41501 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
41502@@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *
41503 if (sbi->s_mb_stats) {
41504 printk(KERN_INFO
41505 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
41506- atomic_read(&sbi->s_bal_allocated),
41507- atomic_read(&sbi->s_bal_reqs),
41508- atomic_read(&sbi->s_bal_success));
41509+ atomic_read_unchecked(&sbi->s_bal_allocated),
41510+ atomic_read_unchecked(&sbi->s_bal_reqs),
41511+ atomic_read_unchecked(&sbi->s_bal_success));
41512 printk(KERN_INFO
41513 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
41514 "%u 2^N hits, %u breaks, %u lost\n",
41515- atomic_read(&sbi->s_bal_ex_scanned),
41516- atomic_read(&sbi->s_bal_goals),
41517- atomic_read(&sbi->s_bal_2orders),
41518- atomic_read(&sbi->s_bal_breaks),
41519- atomic_read(&sbi->s_mb_lost_chunks));
41520+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
41521+ atomic_read_unchecked(&sbi->s_bal_goals),
41522+ atomic_read_unchecked(&sbi->s_bal_2orders),
41523+ atomic_read_unchecked(&sbi->s_bal_breaks),
41524+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
41525 printk(KERN_INFO
41526 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
41527 sbi->s_mb_buddies_generated++,
41528 sbi->s_mb_generation_time);
41529 printk(KERN_INFO
41530 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
41531- atomic_read(&sbi->s_mb_preallocated),
41532- atomic_read(&sbi->s_mb_discarded));
41533+ atomic_read_unchecked(&sbi->s_mb_preallocated),
41534+ atomic_read_unchecked(&sbi->s_mb_discarded));
41535 }
41536
41537 free_percpu(sbi->s_locality_groups);
41538@@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct
41539 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
41540
41541 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
41542- atomic_inc(&sbi->s_bal_reqs);
41543- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
41544+ atomic_inc_unchecked(&sbi->s_bal_reqs);
41545+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
41546 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
41547- atomic_inc(&sbi->s_bal_success);
41548- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
41549+ atomic_inc_unchecked(&sbi->s_bal_success);
41550+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
41551 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
41552 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
41553- atomic_inc(&sbi->s_bal_goals);
41554+ atomic_inc_unchecked(&sbi->s_bal_goals);
41555 if (ac->ac_found > sbi->s_mb_max_to_scan)
41556- atomic_inc(&sbi->s_bal_breaks);
41557+ atomic_inc_unchecked(&sbi->s_bal_breaks);
41558 }
41559
41560 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
41561@@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
41562 trace_ext4_mb_new_inode_pa(ac, pa);
41563
41564 ext4_mb_use_inode_pa(ac, pa);
41565- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
41566+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
41567
41568 ei = EXT4_I(ac->ac_inode);
41569 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
41570@@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
41571 trace_ext4_mb_new_group_pa(ac, pa);
41572
41573 ext4_mb_use_group_pa(ac, pa);
41574- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
41575+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
41576
41577 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
41578 lg = ac->ac_lg;
41579@@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
41580 * from the bitmap and continue.
41581 */
41582 }
41583- atomic_add(free, &sbi->s_mb_discarded);
41584+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
41585
41586 return err;
41587 }
41588@@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_bud
41589 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
41590 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
41591 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
41592- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
41593+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
41594
41595 if (ac) {
41596 ac->ac_sb = sb;
41597diff -urNp linux-2.6.32.43/fs/ext4/super.c linux-2.6.32.43/fs/ext4/super.c
41598--- linux-2.6.32.43/fs/ext4/super.c 2011-03-27 14:31:47.000000000 -0400
41599+++ linux-2.6.32.43/fs/ext4/super.c 2011-04-17 15:56:46.000000000 -0400
41600@@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobje
41601 }
41602
41603
41604-static struct sysfs_ops ext4_attr_ops = {
41605+static const struct sysfs_ops ext4_attr_ops = {
41606 .show = ext4_attr_show,
41607 .store = ext4_attr_store,
41608 };
41609diff -urNp linux-2.6.32.43/fs/fcntl.c linux-2.6.32.43/fs/fcntl.c
41610--- linux-2.6.32.43/fs/fcntl.c 2011-03-27 14:31:47.000000000 -0400
41611+++ linux-2.6.32.43/fs/fcntl.c 2011-04-17 15:56:46.000000000 -0400
41612@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct
41613 if (err)
41614 return err;
41615
41616+ if (gr_handle_chroot_fowner(pid, type))
41617+ return -ENOENT;
41618+ if (gr_check_protected_task_fowner(pid, type))
41619+ return -EACCES;
41620+
41621 f_modown(filp, pid, type, force);
41622 return 0;
41623 }
41624@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned in
41625 switch (cmd) {
41626 case F_DUPFD:
41627 case F_DUPFD_CLOEXEC:
41628+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
41629 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
41630 break;
41631 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
41632diff -urNp linux-2.6.32.43/fs/fifo.c linux-2.6.32.43/fs/fifo.c
41633--- linux-2.6.32.43/fs/fifo.c 2011-03-27 14:31:47.000000000 -0400
41634+++ linux-2.6.32.43/fs/fifo.c 2011-04-17 15:56:46.000000000 -0400
41635@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode
41636 */
41637 filp->f_op = &read_pipefifo_fops;
41638 pipe->r_counter++;
41639- if (pipe->readers++ == 0)
41640+ if (atomic_inc_return(&pipe->readers) == 1)
41641 wake_up_partner(inode);
41642
41643- if (!pipe->writers) {
41644+ if (!atomic_read(&pipe->writers)) {
41645 if ((filp->f_flags & O_NONBLOCK)) {
41646 /* suppress POLLHUP until we have
41647 * seen a writer */
41648@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode
41649 * errno=ENXIO when there is no process reading the FIFO.
41650 */
41651 ret = -ENXIO;
41652- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
41653+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
41654 goto err;
41655
41656 filp->f_op = &write_pipefifo_fops;
41657 pipe->w_counter++;
41658- if (!pipe->writers++)
41659+ if (atomic_inc_return(&pipe->writers) == 1)
41660 wake_up_partner(inode);
41661
41662- if (!pipe->readers) {
41663+ if (!atomic_read(&pipe->readers)) {
41664 wait_for_partner(inode, &pipe->r_counter);
41665 if (signal_pending(current))
41666 goto err_wr;
41667@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode
41668 */
41669 filp->f_op = &rdwr_pipefifo_fops;
41670
41671- pipe->readers++;
41672- pipe->writers++;
41673+ atomic_inc(&pipe->readers);
41674+ atomic_inc(&pipe->writers);
41675 pipe->r_counter++;
41676 pipe->w_counter++;
41677- if (pipe->readers == 1 || pipe->writers == 1)
41678+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
41679 wake_up_partner(inode);
41680 break;
41681
41682@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode
41683 return 0;
41684
41685 err_rd:
41686- if (!--pipe->readers)
41687+ if (atomic_dec_and_test(&pipe->readers))
41688 wake_up_interruptible(&pipe->wait);
41689 ret = -ERESTARTSYS;
41690 goto err;
41691
41692 err_wr:
41693- if (!--pipe->writers)
41694+ if (atomic_dec_and_test(&pipe->writers))
41695 wake_up_interruptible(&pipe->wait);
41696 ret = -ERESTARTSYS;
41697 goto err;
41698
41699 err:
41700- if (!pipe->readers && !pipe->writers)
41701+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
41702 free_pipe_info(inode);
41703
41704 err_nocleanup:
41705diff -urNp linux-2.6.32.43/fs/file.c linux-2.6.32.43/fs/file.c
41706--- linux-2.6.32.43/fs/file.c 2011-03-27 14:31:47.000000000 -0400
41707+++ linux-2.6.32.43/fs/file.c 2011-04-17 15:56:46.000000000 -0400
41708@@ -14,6 +14,7 @@
41709 #include <linux/slab.h>
41710 #include <linux/vmalloc.h>
41711 #include <linux/file.h>
41712+#include <linux/security.h>
41713 #include <linux/fdtable.h>
41714 #include <linux/bitops.h>
41715 #include <linux/interrupt.h>
41716@@ -257,6 +258,8 @@ int expand_files(struct files_struct *fi
41717 * N.B. For clone tasks sharing a files structure, this test
41718 * will limit the total number of files that can be opened.
41719 */
41720+
41721+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
41722 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
41723 return -EMFILE;
41724
41725diff -urNp linux-2.6.32.43/fs/filesystems.c linux-2.6.32.43/fs/filesystems.c
41726--- linux-2.6.32.43/fs/filesystems.c 2011-03-27 14:31:47.000000000 -0400
41727+++ linux-2.6.32.43/fs/filesystems.c 2011-04-17 15:56:46.000000000 -0400
41728@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(con
41729 int len = dot ? dot - name : strlen(name);
41730
41731 fs = __get_fs_type(name, len);
41732+
41733+#ifdef CONFIG_GRKERNSEC_MODHARDEN
41734+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
41735+#else
41736 if (!fs && (request_module("%.*s", len, name) == 0))
41737+#endif
41738 fs = __get_fs_type(name, len);
41739
41740 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
41741diff -urNp linux-2.6.32.43/fs/fscache/cookie.c linux-2.6.32.43/fs/fscache/cookie.c
41742--- linux-2.6.32.43/fs/fscache/cookie.c 2011-03-27 14:31:47.000000000 -0400
41743+++ linux-2.6.32.43/fs/fscache/cookie.c 2011-05-04 17:56:28.000000000 -0400
41744@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
41745 parent ? (char *) parent->def->name : "<no-parent>",
41746 def->name, netfs_data);
41747
41748- fscache_stat(&fscache_n_acquires);
41749+ fscache_stat_unchecked(&fscache_n_acquires);
41750
41751 /* if there's no parent cookie, then we don't create one here either */
41752 if (!parent) {
41753- fscache_stat(&fscache_n_acquires_null);
41754+ fscache_stat_unchecked(&fscache_n_acquires_null);
41755 _leave(" [no parent]");
41756 return NULL;
41757 }
41758@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
41759 /* allocate and initialise a cookie */
41760 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
41761 if (!cookie) {
41762- fscache_stat(&fscache_n_acquires_oom);
41763+ fscache_stat_unchecked(&fscache_n_acquires_oom);
41764 _leave(" [ENOMEM]");
41765 return NULL;
41766 }
41767@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
41768
41769 switch (cookie->def->type) {
41770 case FSCACHE_COOKIE_TYPE_INDEX:
41771- fscache_stat(&fscache_n_cookie_index);
41772+ fscache_stat_unchecked(&fscache_n_cookie_index);
41773 break;
41774 case FSCACHE_COOKIE_TYPE_DATAFILE:
41775- fscache_stat(&fscache_n_cookie_data);
41776+ fscache_stat_unchecked(&fscache_n_cookie_data);
41777 break;
41778 default:
41779- fscache_stat(&fscache_n_cookie_special);
41780+ fscache_stat_unchecked(&fscache_n_cookie_special);
41781 break;
41782 }
41783
41784@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
41785 if (fscache_acquire_non_index_cookie(cookie) < 0) {
41786 atomic_dec(&parent->n_children);
41787 __fscache_cookie_put(cookie);
41788- fscache_stat(&fscache_n_acquires_nobufs);
41789+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
41790 _leave(" = NULL");
41791 return NULL;
41792 }
41793 }
41794
41795- fscache_stat(&fscache_n_acquires_ok);
41796+ fscache_stat_unchecked(&fscache_n_acquires_ok);
41797 _leave(" = %p", cookie);
41798 return cookie;
41799 }
41800@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
41801 cache = fscache_select_cache_for_object(cookie->parent);
41802 if (!cache) {
41803 up_read(&fscache_addremove_sem);
41804- fscache_stat(&fscache_n_acquires_no_cache);
41805+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
41806 _leave(" = -ENOMEDIUM [no cache]");
41807 return -ENOMEDIUM;
41808 }
41809@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
41810 object = cache->ops->alloc_object(cache, cookie);
41811 fscache_stat_d(&fscache_n_cop_alloc_object);
41812 if (IS_ERR(object)) {
41813- fscache_stat(&fscache_n_object_no_alloc);
41814+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
41815 ret = PTR_ERR(object);
41816 goto error;
41817 }
41818
41819- fscache_stat(&fscache_n_object_alloc);
41820+ fscache_stat_unchecked(&fscache_n_object_alloc);
41821
41822 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
41823
41824@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
41825 struct fscache_object *object;
41826 struct hlist_node *_p;
41827
41828- fscache_stat(&fscache_n_updates);
41829+ fscache_stat_unchecked(&fscache_n_updates);
41830
41831 if (!cookie) {
41832- fscache_stat(&fscache_n_updates_null);
41833+ fscache_stat_unchecked(&fscache_n_updates_null);
41834 _leave(" [no cookie]");
41835 return;
41836 }
41837@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
41838 struct fscache_object *object;
41839 unsigned long event;
41840
41841- fscache_stat(&fscache_n_relinquishes);
41842+ fscache_stat_unchecked(&fscache_n_relinquishes);
41843 if (retire)
41844- fscache_stat(&fscache_n_relinquishes_retire);
41845+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
41846
41847 if (!cookie) {
41848- fscache_stat(&fscache_n_relinquishes_null);
41849+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
41850 _leave(" [no cookie]");
41851 return;
41852 }
41853@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
41854
41855 /* wait for the cookie to finish being instantiated (or to fail) */
41856 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
41857- fscache_stat(&fscache_n_relinquishes_waitcrt);
41858+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
41859 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
41860 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
41861 }
41862diff -urNp linux-2.6.32.43/fs/fscache/internal.h linux-2.6.32.43/fs/fscache/internal.h
41863--- linux-2.6.32.43/fs/fscache/internal.h 2011-03-27 14:31:47.000000000 -0400
41864+++ linux-2.6.32.43/fs/fscache/internal.h 2011-05-04 17:56:28.000000000 -0400
41865@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
41866 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
41867 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
41868
41869-extern atomic_t fscache_n_op_pend;
41870-extern atomic_t fscache_n_op_run;
41871-extern atomic_t fscache_n_op_enqueue;
41872-extern atomic_t fscache_n_op_deferred_release;
41873-extern atomic_t fscache_n_op_release;
41874-extern atomic_t fscache_n_op_gc;
41875-extern atomic_t fscache_n_op_cancelled;
41876-extern atomic_t fscache_n_op_rejected;
41877-
41878-extern atomic_t fscache_n_attr_changed;
41879-extern atomic_t fscache_n_attr_changed_ok;
41880-extern atomic_t fscache_n_attr_changed_nobufs;
41881-extern atomic_t fscache_n_attr_changed_nomem;
41882-extern atomic_t fscache_n_attr_changed_calls;
41883-
41884-extern atomic_t fscache_n_allocs;
41885-extern atomic_t fscache_n_allocs_ok;
41886-extern atomic_t fscache_n_allocs_wait;
41887-extern atomic_t fscache_n_allocs_nobufs;
41888-extern atomic_t fscache_n_allocs_intr;
41889-extern atomic_t fscache_n_allocs_object_dead;
41890-extern atomic_t fscache_n_alloc_ops;
41891-extern atomic_t fscache_n_alloc_op_waits;
41892-
41893-extern atomic_t fscache_n_retrievals;
41894-extern atomic_t fscache_n_retrievals_ok;
41895-extern atomic_t fscache_n_retrievals_wait;
41896-extern atomic_t fscache_n_retrievals_nodata;
41897-extern atomic_t fscache_n_retrievals_nobufs;
41898-extern atomic_t fscache_n_retrievals_intr;
41899-extern atomic_t fscache_n_retrievals_nomem;
41900-extern atomic_t fscache_n_retrievals_object_dead;
41901-extern atomic_t fscache_n_retrieval_ops;
41902-extern atomic_t fscache_n_retrieval_op_waits;
41903-
41904-extern atomic_t fscache_n_stores;
41905-extern atomic_t fscache_n_stores_ok;
41906-extern atomic_t fscache_n_stores_again;
41907-extern atomic_t fscache_n_stores_nobufs;
41908-extern atomic_t fscache_n_stores_oom;
41909-extern atomic_t fscache_n_store_ops;
41910-extern atomic_t fscache_n_store_calls;
41911-extern atomic_t fscache_n_store_pages;
41912-extern atomic_t fscache_n_store_radix_deletes;
41913-extern atomic_t fscache_n_store_pages_over_limit;
41914-
41915-extern atomic_t fscache_n_store_vmscan_not_storing;
41916-extern atomic_t fscache_n_store_vmscan_gone;
41917-extern atomic_t fscache_n_store_vmscan_busy;
41918-extern atomic_t fscache_n_store_vmscan_cancelled;
41919-
41920-extern atomic_t fscache_n_marks;
41921-extern atomic_t fscache_n_uncaches;
41922-
41923-extern atomic_t fscache_n_acquires;
41924-extern atomic_t fscache_n_acquires_null;
41925-extern atomic_t fscache_n_acquires_no_cache;
41926-extern atomic_t fscache_n_acquires_ok;
41927-extern atomic_t fscache_n_acquires_nobufs;
41928-extern atomic_t fscache_n_acquires_oom;
41929-
41930-extern atomic_t fscache_n_updates;
41931-extern atomic_t fscache_n_updates_null;
41932-extern atomic_t fscache_n_updates_run;
41933-
41934-extern atomic_t fscache_n_relinquishes;
41935-extern atomic_t fscache_n_relinquishes_null;
41936-extern atomic_t fscache_n_relinquishes_waitcrt;
41937-extern atomic_t fscache_n_relinquishes_retire;
41938-
41939-extern atomic_t fscache_n_cookie_index;
41940-extern atomic_t fscache_n_cookie_data;
41941-extern atomic_t fscache_n_cookie_special;
41942-
41943-extern atomic_t fscache_n_object_alloc;
41944-extern atomic_t fscache_n_object_no_alloc;
41945-extern atomic_t fscache_n_object_lookups;
41946-extern atomic_t fscache_n_object_lookups_negative;
41947-extern atomic_t fscache_n_object_lookups_positive;
41948-extern atomic_t fscache_n_object_lookups_timed_out;
41949-extern atomic_t fscache_n_object_created;
41950-extern atomic_t fscache_n_object_avail;
41951-extern atomic_t fscache_n_object_dead;
41952-
41953-extern atomic_t fscache_n_checkaux_none;
41954-extern atomic_t fscache_n_checkaux_okay;
41955-extern atomic_t fscache_n_checkaux_update;
41956-extern atomic_t fscache_n_checkaux_obsolete;
41957+extern atomic_unchecked_t fscache_n_op_pend;
41958+extern atomic_unchecked_t fscache_n_op_run;
41959+extern atomic_unchecked_t fscache_n_op_enqueue;
41960+extern atomic_unchecked_t fscache_n_op_deferred_release;
41961+extern atomic_unchecked_t fscache_n_op_release;
41962+extern atomic_unchecked_t fscache_n_op_gc;
41963+extern atomic_unchecked_t fscache_n_op_cancelled;
41964+extern atomic_unchecked_t fscache_n_op_rejected;
41965+
41966+extern atomic_unchecked_t fscache_n_attr_changed;
41967+extern atomic_unchecked_t fscache_n_attr_changed_ok;
41968+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
41969+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
41970+extern atomic_unchecked_t fscache_n_attr_changed_calls;
41971+
41972+extern atomic_unchecked_t fscache_n_allocs;
41973+extern atomic_unchecked_t fscache_n_allocs_ok;
41974+extern atomic_unchecked_t fscache_n_allocs_wait;
41975+extern atomic_unchecked_t fscache_n_allocs_nobufs;
41976+extern atomic_unchecked_t fscache_n_allocs_intr;
41977+extern atomic_unchecked_t fscache_n_allocs_object_dead;
41978+extern atomic_unchecked_t fscache_n_alloc_ops;
41979+extern atomic_unchecked_t fscache_n_alloc_op_waits;
41980+
41981+extern atomic_unchecked_t fscache_n_retrievals;
41982+extern atomic_unchecked_t fscache_n_retrievals_ok;
41983+extern atomic_unchecked_t fscache_n_retrievals_wait;
41984+extern atomic_unchecked_t fscache_n_retrievals_nodata;
41985+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
41986+extern atomic_unchecked_t fscache_n_retrievals_intr;
41987+extern atomic_unchecked_t fscache_n_retrievals_nomem;
41988+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
41989+extern atomic_unchecked_t fscache_n_retrieval_ops;
41990+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
41991+
41992+extern atomic_unchecked_t fscache_n_stores;
41993+extern atomic_unchecked_t fscache_n_stores_ok;
41994+extern atomic_unchecked_t fscache_n_stores_again;
41995+extern atomic_unchecked_t fscache_n_stores_nobufs;
41996+extern atomic_unchecked_t fscache_n_stores_oom;
41997+extern atomic_unchecked_t fscache_n_store_ops;
41998+extern atomic_unchecked_t fscache_n_store_calls;
41999+extern atomic_unchecked_t fscache_n_store_pages;
42000+extern atomic_unchecked_t fscache_n_store_radix_deletes;
42001+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
42002+
42003+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
42004+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
42005+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
42006+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
42007+
42008+extern atomic_unchecked_t fscache_n_marks;
42009+extern atomic_unchecked_t fscache_n_uncaches;
42010+
42011+extern atomic_unchecked_t fscache_n_acquires;
42012+extern atomic_unchecked_t fscache_n_acquires_null;
42013+extern atomic_unchecked_t fscache_n_acquires_no_cache;
42014+extern atomic_unchecked_t fscache_n_acquires_ok;
42015+extern atomic_unchecked_t fscache_n_acquires_nobufs;
42016+extern atomic_unchecked_t fscache_n_acquires_oom;
42017+
42018+extern atomic_unchecked_t fscache_n_updates;
42019+extern atomic_unchecked_t fscache_n_updates_null;
42020+extern atomic_unchecked_t fscache_n_updates_run;
42021+
42022+extern atomic_unchecked_t fscache_n_relinquishes;
42023+extern atomic_unchecked_t fscache_n_relinquishes_null;
42024+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
42025+extern atomic_unchecked_t fscache_n_relinquishes_retire;
42026+
42027+extern atomic_unchecked_t fscache_n_cookie_index;
42028+extern atomic_unchecked_t fscache_n_cookie_data;
42029+extern atomic_unchecked_t fscache_n_cookie_special;
42030+
42031+extern atomic_unchecked_t fscache_n_object_alloc;
42032+extern atomic_unchecked_t fscache_n_object_no_alloc;
42033+extern atomic_unchecked_t fscache_n_object_lookups;
42034+extern atomic_unchecked_t fscache_n_object_lookups_negative;
42035+extern atomic_unchecked_t fscache_n_object_lookups_positive;
42036+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
42037+extern atomic_unchecked_t fscache_n_object_created;
42038+extern atomic_unchecked_t fscache_n_object_avail;
42039+extern atomic_unchecked_t fscache_n_object_dead;
42040+
42041+extern atomic_unchecked_t fscache_n_checkaux_none;
42042+extern atomic_unchecked_t fscache_n_checkaux_okay;
42043+extern atomic_unchecked_t fscache_n_checkaux_update;
42044+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
42045
42046 extern atomic_t fscache_n_cop_alloc_object;
42047 extern atomic_t fscache_n_cop_lookup_object;
42048@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t
42049 atomic_inc(stat);
42050 }
42051
42052+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
42053+{
42054+ atomic_inc_unchecked(stat);
42055+}
42056+
42057 static inline void fscache_stat_d(atomic_t *stat)
42058 {
42059 atomic_dec(stat);
42060@@ -259,6 +264,7 @@ extern const struct file_operations fsca
42061
42062 #define __fscache_stat(stat) (NULL)
42063 #define fscache_stat(stat) do {} while (0)
42064+#define fscache_stat_unchecked(stat) do {} while (0)
42065 #define fscache_stat_d(stat) do {} while (0)
42066 #endif
42067
42068diff -urNp linux-2.6.32.43/fs/fscache/object.c linux-2.6.32.43/fs/fscache/object.c
42069--- linux-2.6.32.43/fs/fscache/object.c 2011-03-27 14:31:47.000000000 -0400
42070+++ linux-2.6.32.43/fs/fscache/object.c 2011-05-04 17:56:28.000000000 -0400
42071@@ -144,7 +144,7 @@ static void fscache_object_state_machine
42072 /* update the object metadata on disk */
42073 case FSCACHE_OBJECT_UPDATING:
42074 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
42075- fscache_stat(&fscache_n_updates_run);
42076+ fscache_stat_unchecked(&fscache_n_updates_run);
42077 fscache_stat(&fscache_n_cop_update_object);
42078 object->cache->ops->update_object(object);
42079 fscache_stat_d(&fscache_n_cop_update_object);
42080@@ -233,7 +233,7 @@ static void fscache_object_state_machine
42081 spin_lock(&object->lock);
42082 object->state = FSCACHE_OBJECT_DEAD;
42083 spin_unlock(&object->lock);
42084- fscache_stat(&fscache_n_object_dead);
42085+ fscache_stat_unchecked(&fscache_n_object_dead);
42086 goto terminal_transit;
42087
42088 /* handle the parent cache of this object being withdrawn from
42089@@ -248,7 +248,7 @@ static void fscache_object_state_machine
42090 spin_lock(&object->lock);
42091 object->state = FSCACHE_OBJECT_DEAD;
42092 spin_unlock(&object->lock);
42093- fscache_stat(&fscache_n_object_dead);
42094+ fscache_stat_unchecked(&fscache_n_object_dead);
42095 goto terminal_transit;
42096
42097 /* complain about the object being woken up once it is
42098@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct
42099 parent->cookie->def->name, cookie->def->name,
42100 object->cache->tag->name);
42101
42102- fscache_stat(&fscache_n_object_lookups);
42103+ fscache_stat_unchecked(&fscache_n_object_lookups);
42104 fscache_stat(&fscache_n_cop_lookup_object);
42105 ret = object->cache->ops->lookup_object(object);
42106 fscache_stat_d(&fscache_n_cop_lookup_object);
42107@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct
42108 if (ret == -ETIMEDOUT) {
42109 /* probably stuck behind another object, so move this one to
42110 * the back of the queue */
42111- fscache_stat(&fscache_n_object_lookups_timed_out);
42112+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
42113 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
42114 }
42115
42116@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(stru
42117
42118 spin_lock(&object->lock);
42119 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
42120- fscache_stat(&fscache_n_object_lookups_negative);
42121+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
42122
42123 /* transit here to allow write requests to begin stacking up
42124 * and read requests to begin returning ENODATA */
42125@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fsca
42126 * result, in which case there may be data available */
42127 spin_lock(&object->lock);
42128 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
42129- fscache_stat(&fscache_n_object_lookups_positive);
42130+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
42131
42132 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
42133
42134@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fsca
42135 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
42136 } else {
42137 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
42138- fscache_stat(&fscache_n_object_created);
42139+ fscache_stat_unchecked(&fscache_n_object_created);
42140
42141 object->state = FSCACHE_OBJECT_AVAILABLE;
42142 spin_unlock(&object->lock);
42143@@ -633,7 +633,7 @@ static void fscache_object_available(str
42144 fscache_enqueue_dependents(object);
42145
42146 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
42147- fscache_stat(&fscache_n_object_avail);
42148+ fscache_stat_unchecked(&fscache_n_object_avail);
42149
42150 _leave("");
42151 }
42152@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
42153 enum fscache_checkaux result;
42154
42155 if (!object->cookie->def->check_aux) {
42156- fscache_stat(&fscache_n_checkaux_none);
42157+ fscache_stat_unchecked(&fscache_n_checkaux_none);
42158 return FSCACHE_CHECKAUX_OKAY;
42159 }
42160
42161@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
42162 switch (result) {
42163 /* entry okay as is */
42164 case FSCACHE_CHECKAUX_OKAY:
42165- fscache_stat(&fscache_n_checkaux_okay);
42166+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
42167 break;
42168
42169 /* entry requires update */
42170 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
42171- fscache_stat(&fscache_n_checkaux_update);
42172+ fscache_stat_unchecked(&fscache_n_checkaux_update);
42173 break;
42174
42175 /* entry requires deletion */
42176 case FSCACHE_CHECKAUX_OBSOLETE:
42177- fscache_stat(&fscache_n_checkaux_obsolete);
42178+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
42179 break;
42180
42181 default:
42182diff -urNp linux-2.6.32.43/fs/fscache/operation.c linux-2.6.32.43/fs/fscache/operation.c
42183--- linux-2.6.32.43/fs/fscache/operation.c 2011-03-27 14:31:47.000000000 -0400
42184+++ linux-2.6.32.43/fs/fscache/operation.c 2011-05-04 17:56:28.000000000 -0400
42185@@ -16,7 +16,7 @@
42186 #include <linux/seq_file.h>
42187 #include "internal.h"
42188
42189-atomic_t fscache_op_debug_id;
42190+atomic_unchecked_t fscache_op_debug_id;
42191 EXPORT_SYMBOL(fscache_op_debug_id);
42192
42193 /**
42194@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fs
42195 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
42196 ASSERTCMP(atomic_read(&op->usage), >, 0);
42197
42198- fscache_stat(&fscache_n_op_enqueue);
42199+ fscache_stat_unchecked(&fscache_n_op_enqueue);
42200 switch (op->flags & FSCACHE_OP_TYPE) {
42201 case FSCACHE_OP_FAST:
42202 _debug("queue fast");
42203@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscach
42204 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
42205 if (op->processor)
42206 fscache_enqueue_operation(op);
42207- fscache_stat(&fscache_n_op_run);
42208+ fscache_stat_unchecked(&fscache_n_op_run);
42209 }
42210
42211 /*
42212@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct f
42213 if (object->n_ops > 0) {
42214 atomic_inc(&op->usage);
42215 list_add_tail(&op->pend_link, &object->pending_ops);
42216- fscache_stat(&fscache_n_op_pend);
42217+ fscache_stat_unchecked(&fscache_n_op_pend);
42218 } else if (!list_empty(&object->pending_ops)) {
42219 atomic_inc(&op->usage);
42220 list_add_tail(&op->pend_link, &object->pending_ops);
42221- fscache_stat(&fscache_n_op_pend);
42222+ fscache_stat_unchecked(&fscache_n_op_pend);
42223 fscache_start_operations(object);
42224 } else {
42225 ASSERTCMP(object->n_in_progress, ==, 0);
42226@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct f
42227 object->n_exclusive++; /* reads and writes must wait */
42228 atomic_inc(&op->usage);
42229 list_add_tail(&op->pend_link, &object->pending_ops);
42230- fscache_stat(&fscache_n_op_pend);
42231+ fscache_stat_unchecked(&fscache_n_op_pend);
42232 ret = 0;
42233 } else {
42234 /* not allowed to submit ops in any other state */
42235@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_obj
42236 if (object->n_exclusive > 0) {
42237 atomic_inc(&op->usage);
42238 list_add_tail(&op->pend_link, &object->pending_ops);
42239- fscache_stat(&fscache_n_op_pend);
42240+ fscache_stat_unchecked(&fscache_n_op_pend);
42241 } else if (!list_empty(&object->pending_ops)) {
42242 atomic_inc(&op->usage);
42243 list_add_tail(&op->pend_link, &object->pending_ops);
42244- fscache_stat(&fscache_n_op_pend);
42245+ fscache_stat_unchecked(&fscache_n_op_pend);
42246 fscache_start_operations(object);
42247 } else {
42248 ASSERTCMP(object->n_exclusive, ==, 0);
42249@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_obj
42250 object->n_ops++;
42251 atomic_inc(&op->usage);
42252 list_add_tail(&op->pend_link, &object->pending_ops);
42253- fscache_stat(&fscache_n_op_pend);
42254+ fscache_stat_unchecked(&fscache_n_op_pend);
42255 ret = 0;
42256 } else if (object->state == FSCACHE_OBJECT_DYING ||
42257 object->state == FSCACHE_OBJECT_LC_DYING ||
42258 object->state == FSCACHE_OBJECT_WITHDRAWING) {
42259- fscache_stat(&fscache_n_op_rejected);
42260+ fscache_stat_unchecked(&fscache_n_op_rejected);
42261 ret = -ENOBUFS;
42262 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
42263 fscache_report_unexpected_submission(object, op, ostate);
42264@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_ope
42265
42266 ret = -EBUSY;
42267 if (!list_empty(&op->pend_link)) {
42268- fscache_stat(&fscache_n_op_cancelled);
42269+ fscache_stat_unchecked(&fscache_n_op_cancelled);
42270 list_del_init(&op->pend_link);
42271 object->n_ops--;
42272 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
42273@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscach
42274 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
42275 BUG();
42276
42277- fscache_stat(&fscache_n_op_release);
42278+ fscache_stat_unchecked(&fscache_n_op_release);
42279
42280 if (op->release) {
42281 op->release(op);
42282@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscach
42283 * lock, and defer it otherwise */
42284 if (!spin_trylock(&object->lock)) {
42285 _debug("defer put");
42286- fscache_stat(&fscache_n_op_deferred_release);
42287+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
42288
42289 cache = object->cache;
42290 spin_lock(&cache->op_gc_list_lock);
42291@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_st
42292
42293 _debug("GC DEFERRED REL OBJ%x OP%x",
42294 object->debug_id, op->debug_id);
42295- fscache_stat(&fscache_n_op_gc);
42296+ fscache_stat_unchecked(&fscache_n_op_gc);
42297
42298 ASSERTCMP(atomic_read(&op->usage), ==, 0);
42299
42300diff -urNp linux-2.6.32.43/fs/fscache/page.c linux-2.6.32.43/fs/fscache/page.c
42301--- linux-2.6.32.43/fs/fscache/page.c 2011-03-27 14:31:47.000000000 -0400
42302+++ linux-2.6.32.43/fs/fscache/page.c 2011-05-04 17:56:28.000000000 -0400
42303@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct
42304 val = radix_tree_lookup(&cookie->stores, page->index);
42305 if (!val) {
42306 rcu_read_unlock();
42307- fscache_stat(&fscache_n_store_vmscan_not_storing);
42308+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
42309 __fscache_uncache_page(cookie, page);
42310 return true;
42311 }
42312@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct
42313 spin_unlock(&cookie->stores_lock);
42314
42315 if (xpage) {
42316- fscache_stat(&fscache_n_store_vmscan_cancelled);
42317- fscache_stat(&fscache_n_store_radix_deletes);
42318+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
42319+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
42320 ASSERTCMP(xpage, ==, page);
42321 } else {
42322- fscache_stat(&fscache_n_store_vmscan_gone);
42323+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
42324 }
42325
42326 wake_up_bit(&cookie->flags, 0);
42327@@ -106,7 +106,7 @@ page_busy:
42328 /* we might want to wait here, but that could deadlock the allocator as
42329 * the slow-work threads writing to the cache may all end up sleeping
42330 * on memory allocation */
42331- fscache_stat(&fscache_n_store_vmscan_busy);
42332+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
42333 return false;
42334 }
42335 EXPORT_SYMBOL(__fscache_maybe_release_page);
42336@@ -130,7 +130,7 @@ static void fscache_end_page_write(struc
42337 FSCACHE_COOKIE_STORING_TAG);
42338 if (!radix_tree_tag_get(&cookie->stores, page->index,
42339 FSCACHE_COOKIE_PENDING_TAG)) {
42340- fscache_stat(&fscache_n_store_radix_deletes);
42341+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
42342 xpage = radix_tree_delete(&cookie->stores, page->index);
42343 }
42344 spin_unlock(&cookie->stores_lock);
42345@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(stru
42346
42347 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
42348
42349- fscache_stat(&fscache_n_attr_changed_calls);
42350+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
42351
42352 if (fscache_object_is_active(object)) {
42353 fscache_set_op_state(op, "CallFS");
42354@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscach
42355
42356 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
42357
42358- fscache_stat(&fscache_n_attr_changed);
42359+ fscache_stat_unchecked(&fscache_n_attr_changed);
42360
42361 op = kzalloc(sizeof(*op), GFP_KERNEL);
42362 if (!op) {
42363- fscache_stat(&fscache_n_attr_changed_nomem);
42364+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
42365 _leave(" = -ENOMEM");
42366 return -ENOMEM;
42367 }
42368@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
42369 if (fscache_submit_exclusive_op(object, op) < 0)
42370 goto nobufs;
42371 spin_unlock(&cookie->lock);
42372- fscache_stat(&fscache_n_attr_changed_ok);
42373+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
42374 fscache_put_operation(op);
42375 _leave(" = 0");
42376 return 0;
42377@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
42378 nobufs:
42379 spin_unlock(&cookie->lock);
42380 kfree(op);
42381- fscache_stat(&fscache_n_attr_changed_nobufs);
42382+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
42383 _leave(" = %d", -ENOBUFS);
42384 return -ENOBUFS;
42385 }
42386@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache
42387 /* allocate a retrieval operation and attempt to submit it */
42388 op = kzalloc(sizeof(*op), GFP_NOIO);
42389 if (!op) {
42390- fscache_stat(&fscache_n_retrievals_nomem);
42391+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
42392 return NULL;
42393 }
42394
42395@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_loo
42396 return 0;
42397 }
42398
42399- fscache_stat(&fscache_n_retrievals_wait);
42400+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
42401
42402 jif = jiffies;
42403 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
42404 fscache_wait_bit_interruptible,
42405 TASK_INTERRUPTIBLE) != 0) {
42406- fscache_stat(&fscache_n_retrievals_intr);
42407+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
42408 _leave(" = -ERESTARTSYS");
42409 return -ERESTARTSYS;
42410 }
42411@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_loo
42412 */
42413 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
42414 struct fscache_retrieval *op,
42415- atomic_t *stat_op_waits,
42416- atomic_t *stat_object_dead)
42417+ atomic_unchecked_t *stat_op_waits,
42418+ atomic_unchecked_t *stat_object_dead)
42419 {
42420 int ret;
42421
42422@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_ac
42423 goto check_if_dead;
42424
42425 _debug(">>> WT");
42426- fscache_stat(stat_op_waits);
42427+ fscache_stat_unchecked(stat_op_waits);
42428 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
42429 fscache_wait_bit_interruptible,
42430 TASK_INTERRUPTIBLE) < 0) {
42431@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_ac
42432
42433 check_if_dead:
42434 if (unlikely(fscache_object_is_dead(object))) {
42435- fscache_stat(stat_object_dead);
42436+ fscache_stat_unchecked(stat_object_dead);
42437 return -ENOBUFS;
42438 }
42439 return 0;
42440@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct
42441
42442 _enter("%p,%p,,,", cookie, page);
42443
42444- fscache_stat(&fscache_n_retrievals);
42445+ fscache_stat_unchecked(&fscache_n_retrievals);
42446
42447 if (hlist_empty(&cookie->backing_objects))
42448 goto nobufs;
42449@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct
42450 goto nobufs_unlock;
42451 spin_unlock(&cookie->lock);
42452
42453- fscache_stat(&fscache_n_retrieval_ops);
42454+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
42455
42456 /* pin the netfs read context in case we need to do the actual netfs
42457 * read because we've encountered a cache read failure */
42458@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct
42459
42460 error:
42461 if (ret == -ENOMEM)
42462- fscache_stat(&fscache_n_retrievals_nomem);
42463+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
42464 else if (ret == -ERESTARTSYS)
42465- fscache_stat(&fscache_n_retrievals_intr);
42466+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
42467 else if (ret == -ENODATA)
42468- fscache_stat(&fscache_n_retrievals_nodata);
42469+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
42470 else if (ret < 0)
42471- fscache_stat(&fscache_n_retrievals_nobufs);
42472+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42473 else
42474- fscache_stat(&fscache_n_retrievals_ok);
42475+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
42476
42477 fscache_put_retrieval(op);
42478 _leave(" = %d", ret);
42479@@ -453,7 +453,7 @@ nobufs_unlock:
42480 spin_unlock(&cookie->lock);
42481 kfree(op);
42482 nobufs:
42483- fscache_stat(&fscache_n_retrievals_nobufs);
42484+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42485 _leave(" = -ENOBUFS");
42486 return -ENOBUFS;
42487 }
42488@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct
42489
42490 _enter("%p,,%d,,,", cookie, *nr_pages);
42491
42492- fscache_stat(&fscache_n_retrievals);
42493+ fscache_stat_unchecked(&fscache_n_retrievals);
42494
42495 if (hlist_empty(&cookie->backing_objects))
42496 goto nobufs;
42497@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct
42498 goto nobufs_unlock;
42499 spin_unlock(&cookie->lock);
42500
42501- fscache_stat(&fscache_n_retrieval_ops);
42502+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
42503
42504 /* pin the netfs read context in case we need to do the actual netfs
42505 * read because we've encountered a cache read failure */
42506@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct
42507
42508 error:
42509 if (ret == -ENOMEM)
42510- fscache_stat(&fscache_n_retrievals_nomem);
42511+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
42512 else if (ret == -ERESTARTSYS)
42513- fscache_stat(&fscache_n_retrievals_intr);
42514+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
42515 else if (ret == -ENODATA)
42516- fscache_stat(&fscache_n_retrievals_nodata);
42517+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
42518 else if (ret < 0)
42519- fscache_stat(&fscache_n_retrievals_nobufs);
42520+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42521 else
42522- fscache_stat(&fscache_n_retrievals_ok);
42523+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
42524
42525 fscache_put_retrieval(op);
42526 _leave(" = %d", ret);
42527@@ -570,7 +570,7 @@ nobufs_unlock:
42528 spin_unlock(&cookie->lock);
42529 kfree(op);
42530 nobufs:
42531- fscache_stat(&fscache_n_retrievals_nobufs);
42532+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
42533 _leave(" = -ENOBUFS");
42534 return -ENOBUFS;
42535 }
42536@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_
42537
42538 _enter("%p,%p,,,", cookie, page);
42539
42540- fscache_stat(&fscache_n_allocs);
42541+ fscache_stat_unchecked(&fscache_n_allocs);
42542
42543 if (hlist_empty(&cookie->backing_objects))
42544 goto nobufs;
42545@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_
42546 goto nobufs_unlock;
42547 spin_unlock(&cookie->lock);
42548
42549- fscache_stat(&fscache_n_alloc_ops);
42550+ fscache_stat_unchecked(&fscache_n_alloc_ops);
42551
42552 ret = fscache_wait_for_retrieval_activation(
42553 object, op,
42554@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_
42555
42556 error:
42557 if (ret == -ERESTARTSYS)
42558- fscache_stat(&fscache_n_allocs_intr);
42559+ fscache_stat_unchecked(&fscache_n_allocs_intr);
42560 else if (ret < 0)
42561- fscache_stat(&fscache_n_allocs_nobufs);
42562+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
42563 else
42564- fscache_stat(&fscache_n_allocs_ok);
42565+ fscache_stat_unchecked(&fscache_n_allocs_ok);
42566
42567 fscache_put_retrieval(op);
42568 _leave(" = %d", ret);
42569@@ -651,7 +651,7 @@ nobufs_unlock:
42570 spin_unlock(&cookie->lock);
42571 kfree(op);
42572 nobufs:
42573- fscache_stat(&fscache_n_allocs_nobufs);
42574+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
42575 _leave(" = -ENOBUFS");
42576 return -ENOBUFS;
42577 }
42578@@ -694,7 +694,7 @@ static void fscache_write_op(struct fsca
42579
42580 spin_lock(&cookie->stores_lock);
42581
42582- fscache_stat(&fscache_n_store_calls);
42583+ fscache_stat_unchecked(&fscache_n_store_calls);
42584
42585 /* find a page to store */
42586 page = NULL;
42587@@ -705,7 +705,7 @@ static void fscache_write_op(struct fsca
42588 page = results[0];
42589 _debug("gang %d [%lx]", n, page->index);
42590 if (page->index > op->store_limit) {
42591- fscache_stat(&fscache_n_store_pages_over_limit);
42592+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
42593 goto superseded;
42594 }
42595
42596@@ -721,7 +721,7 @@ static void fscache_write_op(struct fsca
42597
42598 if (page) {
42599 fscache_set_op_state(&op->op, "Store");
42600- fscache_stat(&fscache_n_store_pages);
42601+ fscache_stat_unchecked(&fscache_n_store_pages);
42602 fscache_stat(&fscache_n_cop_write_page);
42603 ret = object->cache->ops->write_page(op, page);
42604 fscache_stat_d(&fscache_n_cop_write_page);
42605@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_
42606 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
42607 ASSERT(PageFsCache(page));
42608
42609- fscache_stat(&fscache_n_stores);
42610+ fscache_stat_unchecked(&fscache_n_stores);
42611
42612 op = kzalloc(sizeof(*op), GFP_NOIO);
42613 if (!op)
42614@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_
42615 spin_unlock(&cookie->stores_lock);
42616 spin_unlock(&object->lock);
42617
42618- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
42619+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
42620 op->store_limit = object->store_limit;
42621
42622 if (fscache_submit_op(object, &op->op) < 0)
42623@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_
42624
42625 spin_unlock(&cookie->lock);
42626 radix_tree_preload_end();
42627- fscache_stat(&fscache_n_store_ops);
42628- fscache_stat(&fscache_n_stores_ok);
42629+ fscache_stat_unchecked(&fscache_n_store_ops);
42630+ fscache_stat_unchecked(&fscache_n_stores_ok);
42631
42632 /* the slow work queue now carries its own ref on the object */
42633 fscache_put_operation(&op->op);
42634@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_
42635 return 0;
42636
42637 already_queued:
42638- fscache_stat(&fscache_n_stores_again);
42639+ fscache_stat_unchecked(&fscache_n_stores_again);
42640 already_pending:
42641 spin_unlock(&cookie->stores_lock);
42642 spin_unlock(&object->lock);
42643 spin_unlock(&cookie->lock);
42644 radix_tree_preload_end();
42645 kfree(op);
42646- fscache_stat(&fscache_n_stores_ok);
42647+ fscache_stat_unchecked(&fscache_n_stores_ok);
42648 _leave(" = 0");
42649 return 0;
42650
42651@@ -886,14 +886,14 @@ nobufs:
42652 spin_unlock(&cookie->lock);
42653 radix_tree_preload_end();
42654 kfree(op);
42655- fscache_stat(&fscache_n_stores_nobufs);
42656+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
42657 _leave(" = -ENOBUFS");
42658 return -ENOBUFS;
42659
42660 nomem_free:
42661 kfree(op);
42662 nomem:
42663- fscache_stat(&fscache_n_stores_oom);
42664+ fscache_stat_unchecked(&fscache_n_stores_oom);
42665 _leave(" = -ENOMEM");
42666 return -ENOMEM;
42667 }
42668@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscac
42669 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
42670 ASSERTCMP(page, !=, NULL);
42671
42672- fscache_stat(&fscache_n_uncaches);
42673+ fscache_stat_unchecked(&fscache_n_uncaches);
42674
42675 /* cache withdrawal may beat us to it */
42676 if (!PageFsCache(page))
42677@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fs
42678 unsigned long loop;
42679
42680 #ifdef CONFIG_FSCACHE_STATS
42681- atomic_add(pagevec->nr, &fscache_n_marks);
42682+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
42683 #endif
42684
42685 for (loop = 0; loop < pagevec->nr; loop++) {
42686diff -urNp linux-2.6.32.43/fs/fscache/stats.c linux-2.6.32.43/fs/fscache/stats.c
42687--- linux-2.6.32.43/fs/fscache/stats.c 2011-03-27 14:31:47.000000000 -0400
42688+++ linux-2.6.32.43/fs/fscache/stats.c 2011-05-04 17:56:28.000000000 -0400
42689@@ -18,95 +18,95 @@
42690 /*
42691 * operation counters
42692 */
42693-atomic_t fscache_n_op_pend;
42694-atomic_t fscache_n_op_run;
42695-atomic_t fscache_n_op_enqueue;
42696-atomic_t fscache_n_op_requeue;
42697-atomic_t fscache_n_op_deferred_release;
42698-atomic_t fscache_n_op_release;
42699-atomic_t fscache_n_op_gc;
42700-atomic_t fscache_n_op_cancelled;
42701-atomic_t fscache_n_op_rejected;
42702-
42703-atomic_t fscache_n_attr_changed;
42704-atomic_t fscache_n_attr_changed_ok;
42705-atomic_t fscache_n_attr_changed_nobufs;
42706-atomic_t fscache_n_attr_changed_nomem;
42707-atomic_t fscache_n_attr_changed_calls;
42708-
42709-atomic_t fscache_n_allocs;
42710-atomic_t fscache_n_allocs_ok;
42711-atomic_t fscache_n_allocs_wait;
42712-atomic_t fscache_n_allocs_nobufs;
42713-atomic_t fscache_n_allocs_intr;
42714-atomic_t fscache_n_allocs_object_dead;
42715-atomic_t fscache_n_alloc_ops;
42716-atomic_t fscache_n_alloc_op_waits;
42717-
42718-atomic_t fscache_n_retrievals;
42719-atomic_t fscache_n_retrievals_ok;
42720-atomic_t fscache_n_retrievals_wait;
42721-atomic_t fscache_n_retrievals_nodata;
42722-atomic_t fscache_n_retrievals_nobufs;
42723-atomic_t fscache_n_retrievals_intr;
42724-atomic_t fscache_n_retrievals_nomem;
42725-atomic_t fscache_n_retrievals_object_dead;
42726-atomic_t fscache_n_retrieval_ops;
42727-atomic_t fscache_n_retrieval_op_waits;
42728-
42729-atomic_t fscache_n_stores;
42730-atomic_t fscache_n_stores_ok;
42731-atomic_t fscache_n_stores_again;
42732-atomic_t fscache_n_stores_nobufs;
42733-atomic_t fscache_n_stores_oom;
42734-atomic_t fscache_n_store_ops;
42735-atomic_t fscache_n_store_calls;
42736-atomic_t fscache_n_store_pages;
42737-atomic_t fscache_n_store_radix_deletes;
42738-atomic_t fscache_n_store_pages_over_limit;
42739-
42740-atomic_t fscache_n_store_vmscan_not_storing;
42741-atomic_t fscache_n_store_vmscan_gone;
42742-atomic_t fscache_n_store_vmscan_busy;
42743-atomic_t fscache_n_store_vmscan_cancelled;
42744-
42745-atomic_t fscache_n_marks;
42746-atomic_t fscache_n_uncaches;
42747-
42748-atomic_t fscache_n_acquires;
42749-atomic_t fscache_n_acquires_null;
42750-atomic_t fscache_n_acquires_no_cache;
42751-atomic_t fscache_n_acquires_ok;
42752-atomic_t fscache_n_acquires_nobufs;
42753-atomic_t fscache_n_acquires_oom;
42754-
42755-atomic_t fscache_n_updates;
42756-atomic_t fscache_n_updates_null;
42757-atomic_t fscache_n_updates_run;
42758-
42759-atomic_t fscache_n_relinquishes;
42760-atomic_t fscache_n_relinquishes_null;
42761-atomic_t fscache_n_relinquishes_waitcrt;
42762-atomic_t fscache_n_relinquishes_retire;
42763-
42764-atomic_t fscache_n_cookie_index;
42765-atomic_t fscache_n_cookie_data;
42766-atomic_t fscache_n_cookie_special;
42767-
42768-atomic_t fscache_n_object_alloc;
42769-atomic_t fscache_n_object_no_alloc;
42770-atomic_t fscache_n_object_lookups;
42771-atomic_t fscache_n_object_lookups_negative;
42772-atomic_t fscache_n_object_lookups_positive;
42773-atomic_t fscache_n_object_lookups_timed_out;
42774-atomic_t fscache_n_object_created;
42775-atomic_t fscache_n_object_avail;
42776-atomic_t fscache_n_object_dead;
42777-
42778-atomic_t fscache_n_checkaux_none;
42779-atomic_t fscache_n_checkaux_okay;
42780-atomic_t fscache_n_checkaux_update;
42781-atomic_t fscache_n_checkaux_obsolete;
42782+atomic_unchecked_t fscache_n_op_pend;
42783+atomic_unchecked_t fscache_n_op_run;
42784+atomic_unchecked_t fscache_n_op_enqueue;
42785+atomic_unchecked_t fscache_n_op_requeue;
42786+atomic_unchecked_t fscache_n_op_deferred_release;
42787+atomic_unchecked_t fscache_n_op_release;
42788+atomic_unchecked_t fscache_n_op_gc;
42789+atomic_unchecked_t fscache_n_op_cancelled;
42790+atomic_unchecked_t fscache_n_op_rejected;
42791+
42792+atomic_unchecked_t fscache_n_attr_changed;
42793+atomic_unchecked_t fscache_n_attr_changed_ok;
42794+atomic_unchecked_t fscache_n_attr_changed_nobufs;
42795+atomic_unchecked_t fscache_n_attr_changed_nomem;
42796+atomic_unchecked_t fscache_n_attr_changed_calls;
42797+
42798+atomic_unchecked_t fscache_n_allocs;
42799+atomic_unchecked_t fscache_n_allocs_ok;
42800+atomic_unchecked_t fscache_n_allocs_wait;
42801+atomic_unchecked_t fscache_n_allocs_nobufs;
42802+atomic_unchecked_t fscache_n_allocs_intr;
42803+atomic_unchecked_t fscache_n_allocs_object_dead;
42804+atomic_unchecked_t fscache_n_alloc_ops;
42805+atomic_unchecked_t fscache_n_alloc_op_waits;
42806+
42807+atomic_unchecked_t fscache_n_retrievals;
42808+atomic_unchecked_t fscache_n_retrievals_ok;
42809+atomic_unchecked_t fscache_n_retrievals_wait;
42810+atomic_unchecked_t fscache_n_retrievals_nodata;
42811+atomic_unchecked_t fscache_n_retrievals_nobufs;
42812+atomic_unchecked_t fscache_n_retrievals_intr;
42813+atomic_unchecked_t fscache_n_retrievals_nomem;
42814+atomic_unchecked_t fscache_n_retrievals_object_dead;
42815+atomic_unchecked_t fscache_n_retrieval_ops;
42816+atomic_unchecked_t fscache_n_retrieval_op_waits;
42817+
42818+atomic_unchecked_t fscache_n_stores;
42819+atomic_unchecked_t fscache_n_stores_ok;
42820+atomic_unchecked_t fscache_n_stores_again;
42821+atomic_unchecked_t fscache_n_stores_nobufs;
42822+atomic_unchecked_t fscache_n_stores_oom;
42823+atomic_unchecked_t fscache_n_store_ops;
42824+atomic_unchecked_t fscache_n_store_calls;
42825+atomic_unchecked_t fscache_n_store_pages;
42826+atomic_unchecked_t fscache_n_store_radix_deletes;
42827+atomic_unchecked_t fscache_n_store_pages_over_limit;
42828+
42829+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
42830+atomic_unchecked_t fscache_n_store_vmscan_gone;
42831+atomic_unchecked_t fscache_n_store_vmscan_busy;
42832+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
42833+
42834+atomic_unchecked_t fscache_n_marks;
42835+atomic_unchecked_t fscache_n_uncaches;
42836+
42837+atomic_unchecked_t fscache_n_acquires;
42838+atomic_unchecked_t fscache_n_acquires_null;
42839+atomic_unchecked_t fscache_n_acquires_no_cache;
42840+atomic_unchecked_t fscache_n_acquires_ok;
42841+atomic_unchecked_t fscache_n_acquires_nobufs;
42842+atomic_unchecked_t fscache_n_acquires_oom;
42843+
42844+atomic_unchecked_t fscache_n_updates;
42845+atomic_unchecked_t fscache_n_updates_null;
42846+atomic_unchecked_t fscache_n_updates_run;
42847+
42848+atomic_unchecked_t fscache_n_relinquishes;
42849+atomic_unchecked_t fscache_n_relinquishes_null;
42850+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
42851+atomic_unchecked_t fscache_n_relinquishes_retire;
42852+
42853+atomic_unchecked_t fscache_n_cookie_index;
42854+atomic_unchecked_t fscache_n_cookie_data;
42855+atomic_unchecked_t fscache_n_cookie_special;
42856+
42857+atomic_unchecked_t fscache_n_object_alloc;
42858+atomic_unchecked_t fscache_n_object_no_alloc;
42859+atomic_unchecked_t fscache_n_object_lookups;
42860+atomic_unchecked_t fscache_n_object_lookups_negative;
42861+atomic_unchecked_t fscache_n_object_lookups_positive;
42862+atomic_unchecked_t fscache_n_object_lookups_timed_out;
42863+atomic_unchecked_t fscache_n_object_created;
42864+atomic_unchecked_t fscache_n_object_avail;
42865+atomic_unchecked_t fscache_n_object_dead;
42866+
42867+atomic_unchecked_t fscache_n_checkaux_none;
42868+atomic_unchecked_t fscache_n_checkaux_okay;
42869+atomic_unchecked_t fscache_n_checkaux_update;
42870+atomic_unchecked_t fscache_n_checkaux_obsolete;
42871
42872 atomic_t fscache_n_cop_alloc_object;
42873 atomic_t fscache_n_cop_lookup_object;
42874@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
42875 seq_puts(m, "FS-Cache statistics\n");
42876
42877 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
42878- atomic_read(&fscache_n_cookie_index),
42879- atomic_read(&fscache_n_cookie_data),
42880- atomic_read(&fscache_n_cookie_special));
42881+ atomic_read_unchecked(&fscache_n_cookie_index),
42882+ atomic_read_unchecked(&fscache_n_cookie_data),
42883+ atomic_read_unchecked(&fscache_n_cookie_special));
42884
42885 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
42886- atomic_read(&fscache_n_object_alloc),
42887- atomic_read(&fscache_n_object_no_alloc),
42888- atomic_read(&fscache_n_object_avail),
42889- atomic_read(&fscache_n_object_dead));
42890+ atomic_read_unchecked(&fscache_n_object_alloc),
42891+ atomic_read_unchecked(&fscache_n_object_no_alloc),
42892+ atomic_read_unchecked(&fscache_n_object_avail),
42893+ atomic_read_unchecked(&fscache_n_object_dead));
42894 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
42895- atomic_read(&fscache_n_checkaux_none),
42896- atomic_read(&fscache_n_checkaux_okay),
42897- atomic_read(&fscache_n_checkaux_update),
42898- atomic_read(&fscache_n_checkaux_obsolete));
42899+ atomic_read_unchecked(&fscache_n_checkaux_none),
42900+ atomic_read_unchecked(&fscache_n_checkaux_okay),
42901+ atomic_read_unchecked(&fscache_n_checkaux_update),
42902+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
42903
42904 seq_printf(m, "Pages : mrk=%u unc=%u\n",
42905- atomic_read(&fscache_n_marks),
42906- atomic_read(&fscache_n_uncaches));
42907+ atomic_read_unchecked(&fscache_n_marks),
42908+ atomic_read_unchecked(&fscache_n_uncaches));
42909
42910 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
42911 " oom=%u\n",
42912- atomic_read(&fscache_n_acquires),
42913- atomic_read(&fscache_n_acquires_null),
42914- atomic_read(&fscache_n_acquires_no_cache),
42915- atomic_read(&fscache_n_acquires_ok),
42916- atomic_read(&fscache_n_acquires_nobufs),
42917- atomic_read(&fscache_n_acquires_oom));
42918+ atomic_read_unchecked(&fscache_n_acquires),
42919+ atomic_read_unchecked(&fscache_n_acquires_null),
42920+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
42921+ atomic_read_unchecked(&fscache_n_acquires_ok),
42922+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
42923+ atomic_read_unchecked(&fscache_n_acquires_oom));
42924
42925 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
42926- atomic_read(&fscache_n_object_lookups),
42927- atomic_read(&fscache_n_object_lookups_negative),
42928- atomic_read(&fscache_n_object_lookups_positive),
42929- atomic_read(&fscache_n_object_lookups_timed_out),
42930- atomic_read(&fscache_n_object_created));
42931+ atomic_read_unchecked(&fscache_n_object_lookups),
42932+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
42933+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
42934+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
42935+ atomic_read_unchecked(&fscache_n_object_created));
42936
42937 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
42938- atomic_read(&fscache_n_updates),
42939- atomic_read(&fscache_n_updates_null),
42940- atomic_read(&fscache_n_updates_run));
42941+ atomic_read_unchecked(&fscache_n_updates),
42942+ atomic_read_unchecked(&fscache_n_updates_null),
42943+ atomic_read_unchecked(&fscache_n_updates_run));
42944
42945 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
42946- atomic_read(&fscache_n_relinquishes),
42947- atomic_read(&fscache_n_relinquishes_null),
42948- atomic_read(&fscache_n_relinquishes_waitcrt),
42949- atomic_read(&fscache_n_relinquishes_retire));
42950+ atomic_read_unchecked(&fscache_n_relinquishes),
42951+ atomic_read_unchecked(&fscache_n_relinquishes_null),
42952+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
42953+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
42954
42955 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
42956- atomic_read(&fscache_n_attr_changed),
42957- atomic_read(&fscache_n_attr_changed_ok),
42958- atomic_read(&fscache_n_attr_changed_nobufs),
42959- atomic_read(&fscache_n_attr_changed_nomem),
42960- atomic_read(&fscache_n_attr_changed_calls));
42961+ atomic_read_unchecked(&fscache_n_attr_changed),
42962+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
42963+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
42964+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
42965+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
42966
42967 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
42968- atomic_read(&fscache_n_allocs),
42969- atomic_read(&fscache_n_allocs_ok),
42970- atomic_read(&fscache_n_allocs_wait),
42971- atomic_read(&fscache_n_allocs_nobufs),
42972- atomic_read(&fscache_n_allocs_intr));
42973+ atomic_read_unchecked(&fscache_n_allocs),
42974+ atomic_read_unchecked(&fscache_n_allocs_ok),
42975+ atomic_read_unchecked(&fscache_n_allocs_wait),
42976+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
42977+ atomic_read_unchecked(&fscache_n_allocs_intr));
42978 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
42979- atomic_read(&fscache_n_alloc_ops),
42980- atomic_read(&fscache_n_alloc_op_waits),
42981- atomic_read(&fscache_n_allocs_object_dead));
42982+ atomic_read_unchecked(&fscache_n_alloc_ops),
42983+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
42984+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
42985
42986 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
42987 " int=%u oom=%u\n",
42988- atomic_read(&fscache_n_retrievals),
42989- atomic_read(&fscache_n_retrievals_ok),
42990- atomic_read(&fscache_n_retrievals_wait),
42991- atomic_read(&fscache_n_retrievals_nodata),
42992- atomic_read(&fscache_n_retrievals_nobufs),
42993- atomic_read(&fscache_n_retrievals_intr),
42994- atomic_read(&fscache_n_retrievals_nomem));
42995+ atomic_read_unchecked(&fscache_n_retrievals),
42996+ atomic_read_unchecked(&fscache_n_retrievals_ok),
42997+ atomic_read_unchecked(&fscache_n_retrievals_wait),
42998+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
42999+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
43000+ atomic_read_unchecked(&fscache_n_retrievals_intr),
43001+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
43002 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
43003- atomic_read(&fscache_n_retrieval_ops),
43004- atomic_read(&fscache_n_retrieval_op_waits),
43005- atomic_read(&fscache_n_retrievals_object_dead));
43006+ atomic_read_unchecked(&fscache_n_retrieval_ops),
43007+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
43008+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
43009
43010 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
43011- atomic_read(&fscache_n_stores),
43012- atomic_read(&fscache_n_stores_ok),
43013- atomic_read(&fscache_n_stores_again),
43014- atomic_read(&fscache_n_stores_nobufs),
43015- atomic_read(&fscache_n_stores_oom));
43016+ atomic_read_unchecked(&fscache_n_stores),
43017+ atomic_read_unchecked(&fscache_n_stores_ok),
43018+ atomic_read_unchecked(&fscache_n_stores_again),
43019+ atomic_read_unchecked(&fscache_n_stores_nobufs),
43020+ atomic_read_unchecked(&fscache_n_stores_oom));
43021 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
43022- atomic_read(&fscache_n_store_ops),
43023- atomic_read(&fscache_n_store_calls),
43024- atomic_read(&fscache_n_store_pages),
43025- atomic_read(&fscache_n_store_radix_deletes),
43026- atomic_read(&fscache_n_store_pages_over_limit));
43027+ atomic_read_unchecked(&fscache_n_store_ops),
43028+ atomic_read_unchecked(&fscache_n_store_calls),
43029+ atomic_read_unchecked(&fscache_n_store_pages),
43030+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
43031+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
43032
43033 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
43034- atomic_read(&fscache_n_store_vmscan_not_storing),
43035- atomic_read(&fscache_n_store_vmscan_gone),
43036- atomic_read(&fscache_n_store_vmscan_busy),
43037- atomic_read(&fscache_n_store_vmscan_cancelled));
43038+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
43039+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
43040+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
43041+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
43042
43043 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
43044- atomic_read(&fscache_n_op_pend),
43045- atomic_read(&fscache_n_op_run),
43046- atomic_read(&fscache_n_op_enqueue),
43047- atomic_read(&fscache_n_op_cancelled),
43048- atomic_read(&fscache_n_op_rejected));
43049+ atomic_read_unchecked(&fscache_n_op_pend),
43050+ atomic_read_unchecked(&fscache_n_op_run),
43051+ atomic_read_unchecked(&fscache_n_op_enqueue),
43052+ atomic_read_unchecked(&fscache_n_op_cancelled),
43053+ atomic_read_unchecked(&fscache_n_op_rejected));
43054 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
43055- atomic_read(&fscache_n_op_deferred_release),
43056- atomic_read(&fscache_n_op_release),
43057- atomic_read(&fscache_n_op_gc));
43058+ atomic_read_unchecked(&fscache_n_op_deferred_release),
43059+ atomic_read_unchecked(&fscache_n_op_release),
43060+ atomic_read_unchecked(&fscache_n_op_gc));
43061
43062 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
43063 atomic_read(&fscache_n_cop_alloc_object),
43064diff -urNp linux-2.6.32.43/fs/fs_struct.c linux-2.6.32.43/fs/fs_struct.c
43065--- linux-2.6.32.43/fs/fs_struct.c 2011-03-27 14:31:47.000000000 -0400
43066+++ linux-2.6.32.43/fs/fs_struct.c 2011-04-17 15:56:46.000000000 -0400
43067@@ -4,6 +4,7 @@
43068 #include <linux/path.h>
43069 #include <linux/slab.h>
43070 #include <linux/fs_struct.h>
43071+#include <linux/grsecurity.h>
43072
43073 /*
43074 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
43075@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, s
43076 old_root = fs->root;
43077 fs->root = *path;
43078 path_get(path);
43079+ gr_set_chroot_entries(current, path);
43080 write_unlock(&fs->lock);
43081 if (old_root.dentry)
43082 path_put(&old_root);
43083@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_roo
43084 && fs->root.mnt == old_root->mnt) {
43085 path_get(new_root);
43086 fs->root = *new_root;
43087+ gr_set_chroot_entries(p, new_root);
43088 count++;
43089 }
43090 if (fs->pwd.dentry == old_root->dentry
43091@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
43092 task_lock(tsk);
43093 write_lock(&fs->lock);
43094 tsk->fs = NULL;
43095- kill = !--fs->users;
43096+ gr_clear_chroot_entries(tsk);
43097+ kill = !atomic_dec_return(&fs->users);
43098 write_unlock(&fs->lock);
43099 task_unlock(tsk);
43100 if (kill)
43101@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct
43102 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
43103 /* We don't need to lock fs - think why ;-) */
43104 if (fs) {
43105- fs->users = 1;
43106+ atomic_set(&fs->users, 1);
43107 fs->in_exec = 0;
43108 rwlock_init(&fs->lock);
43109 fs->umask = old->umask;
43110@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
43111
43112 task_lock(current);
43113 write_lock(&fs->lock);
43114- kill = !--fs->users;
43115+ kill = !atomic_dec_return(&fs->users);
43116 current->fs = new_fs;
43117+ gr_set_chroot_entries(current, &new_fs->root);
43118 write_unlock(&fs->lock);
43119 task_unlock(current);
43120
43121@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
43122
43123 /* to be mentioned only in INIT_TASK */
43124 struct fs_struct init_fs = {
43125- .users = 1,
43126+ .users = ATOMIC_INIT(1),
43127 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
43128 .umask = 0022,
43129 };
43130@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
43131 task_lock(current);
43132
43133 write_lock(&init_fs.lock);
43134- init_fs.users++;
43135+ atomic_inc(&init_fs.users);
43136 write_unlock(&init_fs.lock);
43137
43138 write_lock(&fs->lock);
43139 current->fs = &init_fs;
43140- kill = !--fs->users;
43141+ gr_set_chroot_entries(current, &current->fs->root);
43142+ kill = !atomic_dec_return(&fs->users);
43143 write_unlock(&fs->lock);
43144
43145 task_unlock(current);
43146diff -urNp linux-2.6.32.43/fs/fuse/cuse.c linux-2.6.32.43/fs/fuse/cuse.c
43147--- linux-2.6.32.43/fs/fuse/cuse.c 2011-03-27 14:31:47.000000000 -0400
43148+++ linux-2.6.32.43/fs/fuse/cuse.c 2011-08-05 20:33:55.000000000 -0400
43149@@ -576,10 +576,12 @@ static int __init cuse_init(void)
43150 INIT_LIST_HEAD(&cuse_conntbl[i]);
43151
43152 /* inherit and extend fuse_dev_operations */
43153- cuse_channel_fops = fuse_dev_operations;
43154- cuse_channel_fops.owner = THIS_MODULE;
43155- cuse_channel_fops.open = cuse_channel_open;
43156- cuse_channel_fops.release = cuse_channel_release;
43157+ pax_open_kernel();
43158+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
43159+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
43160+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
43161+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
43162+ pax_close_kernel();
43163
43164 cuse_class = class_create(THIS_MODULE, "cuse");
43165 if (IS_ERR(cuse_class))
43166diff -urNp linux-2.6.32.43/fs/fuse/dev.c linux-2.6.32.43/fs/fuse/dev.c
43167--- linux-2.6.32.43/fs/fuse/dev.c 2011-03-27 14:31:47.000000000 -0400
43168+++ linux-2.6.32.43/fs/fuse/dev.c 2011-08-05 20:33:55.000000000 -0400
43169@@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struc
43170 {
43171 struct fuse_notify_inval_entry_out outarg;
43172 int err = -EINVAL;
43173- char buf[FUSE_NAME_MAX+1];
43174+ char *buf = NULL;
43175 struct qstr name;
43176
43177 if (size < sizeof(outarg))
43178@@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struc
43179 if (outarg.namelen > FUSE_NAME_MAX)
43180 goto err;
43181
43182+ err = -ENOMEM;
43183+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
43184+ if (!buf)
43185+ goto err;
43186+
43187 name.name = buf;
43188 name.len = outarg.namelen;
43189 err = fuse_copy_one(cs, buf, outarg.namelen + 1);
43190@@ -910,17 +915,15 @@ static int fuse_notify_inval_entry(struc
43191
43192 down_read(&fc->killsb);
43193 err = -ENOENT;
43194- if (!fc->sb)
43195- goto err_unlock;
43196-
43197- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
43198-
43199-err_unlock:
43200+ if (fc->sb)
43201+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
43202 up_read(&fc->killsb);
43203+ kfree(buf);
43204 return err;
43205
43206 err:
43207 fuse_copy_finish(cs);
43208+ kfree(buf);
43209 return err;
43210 }
43211
43212diff -urNp linux-2.6.32.43/fs/fuse/dir.c linux-2.6.32.43/fs/fuse/dir.c
43213--- linux-2.6.32.43/fs/fuse/dir.c 2011-03-27 14:31:47.000000000 -0400
43214+++ linux-2.6.32.43/fs/fuse/dir.c 2011-04-17 15:56:46.000000000 -0400
43215@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *de
43216 return link;
43217 }
43218
43219-static void free_link(char *link)
43220+static void free_link(const char *link)
43221 {
43222 if (!IS_ERR(link))
43223 free_page((unsigned long) link);
43224diff -urNp linux-2.6.32.43/fs/gfs2/ops_inode.c linux-2.6.32.43/fs/gfs2/ops_inode.c
43225--- linux-2.6.32.43/fs/gfs2/ops_inode.c 2011-03-27 14:31:47.000000000 -0400
43226+++ linux-2.6.32.43/fs/gfs2/ops_inode.c 2011-05-16 21:46:57.000000000 -0400
43227@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odi
43228 unsigned int x;
43229 int error;
43230
43231+ pax_track_stack();
43232+
43233 if (ndentry->d_inode) {
43234 nip = GFS2_I(ndentry->d_inode);
43235 if (ip == nip)
43236diff -urNp linux-2.6.32.43/fs/gfs2/sys.c linux-2.6.32.43/fs/gfs2/sys.c
43237--- linux-2.6.32.43/fs/gfs2/sys.c 2011-03-27 14:31:47.000000000 -0400
43238+++ linux-2.6.32.43/fs/gfs2/sys.c 2011-04-17 15:56:46.000000000 -0400
43239@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct ko
43240 return a->store ? a->store(sdp, buf, len) : len;
43241 }
43242
43243-static struct sysfs_ops gfs2_attr_ops = {
43244+static const struct sysfs_ops gfs2_attr_ops = {
43245 .show = gfs2_attr_show,
43246 .store = gfs2_attr_store,
43247 };
43248@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset
43249 return 0;
43250 }
43251
43252-static struct kset_uevent_ops gfs2_uevent_ops = {
43253+static const struct kset_uevent_ops gfs2_uevent_ops = {
43254 .uevent = gfs2_uevent,
43255 };
43256
43257diff -urNp linux-2.6.32.43/fs/hfsplus/catalog.c linux-2.6.32.43/fs/hfsplus/catalog.c
43258--- linux-2.6.32.43/fs/hfsplus/catalog.c 2011-03-27 14:31:47.000000000 -0400
43259+++ linux-2.6.32.43/fs/hfsplus/catalog.c 2011-05-16 21:46:57.000000000 -0400
43260@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block
43261 int err;
43262 u16 type;
43263
43264+ pax_track_stack();
43265+
43266 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
43267 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
43268 if (err)
43269@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct
43270 int entry_size;
43271 int err;
43272
43273+ pax_track_stack();
43274+
43275 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
43276 sb = dir->i_sb;
43277 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
43278@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
43279 int entry_size, type;
43280 int err = 0;
43281
43282+ pax_track_stack();
43283+
43284 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
43285 dst_dir->i_ino, dst_name->name);
43286 sb = src_dir->i_sb;
43287diff -urNp linux-2.6.32.43/fs/hfsplus/dir.c linux-2.6.32.43/fs/hfsplus/dir.c
43288--- linux-2.6.32.43/fs/hfsplus/dir.c 2011-03-27 14:31:47.000000000 -0400
43289+++ linux-2.6.32.43/fs/hfsplus/dir.c 2011-05-16 21:46:57.000000000 -0400
43290@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *
43291 struct hfsplus_readdir_data *rd;
43292 u16 type;
43293
43294+ pax_track_stack();
43295+
43296 if (filp->f_pos >= inode->i_size)
43297 return 0;
43298
43299diff -urNp linux-2.6.32.43/fs/hfsplus/inode.c linux-2.6.32.43/fs/hfsplus/inode.c
43300--- linux-2.6.32.43/fs/hfsplus/inode.c 2011-03-27 14:31:47.000000000 -0400
43301+++ linux-2.6.32.43/fs/hfsplus/inode.c 2011-05-16 21:46:57.000000000 -0400
43302@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode
43303 int res = 0;
43304 u16 type;
43305
43306+ pax_track_stack();
43307+
43308 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
43309
43310 HFSPLUS_I(inode).dev = 0;
43311@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode
43312 struct hfs_find_data fd;
43313 hfsplus_cat_entry entry;
43314
43315+ pax_track_stack();
43316+
43317 if (HFSPLUS_IS_RSRC(inode))
43318 main_inode = HFSPLUS_I(inode).rsrc_inode;
43319
43320diff -urNp linux-2.6.32.43/fs/hfsplus/ioctl.c linux-2.6.32.43/fs/hfsplus/ioctl.c
43321--- linux-2.6.32.43/fs/hfsplus/ioctl.c 2011-03-27 14:31:47.000000000 -0400
43322+++ linux-2.6.32.43/fs/hfsplus/ioctl.c 2011-05-16 21:46:57.000000000 -0400
43323@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dent
43324 struct hfsplus_cat_file *file;
43325 int res;
43326
43327+ pax_track_stack();
43328+
43329 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
43330 return -EOPNOTSUPP;
43331
43332@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *
43333 struct hfsplus_cat_file *file;
43334 ssize_t res = 0;
43335
43336+ pax_track_stack();
43337+
43338 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
43339 return -EOPNOTSUPP;
43340
43341diff -urNp linux-2.6.32.43/fs/hfsplus/super.c linux-2.6.32.43/fs/hfsplus/super.c
43342--- linux-2.6.32.43/fs/hfsplus/super.c 2011-03-27 14:31:47.000000000 -0400
43343+++ linux-2.6.32.43/fs/hfsplus/super.c 2011-05-16 21:46:57.000000000 -0400
43344@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct sup
43345 struct nls_table *nls = NULL;
43346 int err = -EINVAL;
43347
43348+ pax_track_stack();
43349+
43350 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
43351 if (!sbi)
43352 return -ENOMEM;
43353diff -urNp linux-2.6.32.43/fs/hugetlbfs/inode.c linux-2.6.32.43/fs/hugetlbfs/inode.c
43354--- linux-2.6.32.43/fs/hugetlbfs/inode.c 2011-03-27 14:31:47.000000000 -0400
43355+++ linux-2.6.32.43/fs/hugetlbfs/inode.c 2011-04-17 15:56:46.000000000 -0400
43356@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs
43357 .kill_sb = kill_litter_super,
43358 };
43359
43360-static struct vfsmount *hugetlbfs_vfsmount;
43361+struct vfsmount *hugetlbfs_vfsmount;
43362
43363 static int can_do_hugetlb_shm(void)
43364 {
43365diff -urNp linux-2.6.32.43/fs/ioctl.c linux-2.6.32.43/fs/ioctl.c
43366--- linux-2.6.32.43/fs/ioctl.c 2011-03-27 14:31:47.000000000 -0400
43367+++ linux-2.6.32.43/fs/ioctl.c 2011-04-17 15:56:46.000000000 -0400
43368@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiema
43369 u64 phys, u64 len, u32 flags)
43370 {
43371 struct fiemap_extent extent;
43372- struct fiemap_extent *dest = fieinfo->fi_extents_start;
43373+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
43374
43375 /* only count the extents */
43376 if (fieinfo->fi_extents_max == 0) {
43377@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *fil
43378
43379 fieinfo.fi_flags = fiemap.fm_flags;
43380 fieinfo.fi_extents_max = fiemap.fm_extent_count;
43381- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
43382+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
43383
43384 if (fiemap.fm_extent_count != 0 &&
43385 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
43386@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *fil
43387 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
43388 fiemap.fm_flags = fieinfo.fi_flags;
43389 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
43390- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
43391+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
43392 error = -EFAULT;
43393
43394 return error;
43395diff -urNp linux-2.6.32.43/fs/jbd/checkpoint.c linux-2.6.32.43/fs/jbd/checkpoint.c
43396--- linux-2.6.32.43/fs/jbd/checkpoint.c 2011-03-27 14:31:47.000000000 -0400
43397+++ linux-2.6.32.43/fs/jbd/checkpoint.c 2011-05-16 21:46:57.000000000 -0400
43398@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal
43399 tid_t this_tid;
43400 int result;
43401
43402+ pax_track_stack();
43403+
43404 jbd_debug(1, "Start checkpoint\n");
43405
43406 /*
43407diff -urNp linux-2.6.32.43/fs/jffs2/compr_rtime.c linux-2.6.32.43/fs/jffs2/compr_rtime.c
43408--- linux-2.6.32.43/fs/jffs2/compr_rtime.c 2011-03-27 14:31:47.000000000 -0400
43409+++ linux-2.6.32.43/fs/jffs2/compr_rtime.c 2011-05-16 21:46:57.000000000 -0400
43410@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
43411 int outpos = 0;
43412 int pos=0;
43413
43414+ pax_track_stack();
43415+
43416 memset(positions,0,sizeof(positions));
43417
43418 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
43419@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsign
43420 int outpos = 0;
43421 int pos=0;
43422
43423+ pax_track_stack();
43424+
43425 memset(positions,0,sizeof(positions));
43426
43427 while (outpos<destlen) {
43428diff -urNp linux-2.6.32.43/fs/jffs2/compr_rubin.c linux-2.6.32.43/fs/jffs2/compr_rubin.c
43429--- linux-2.6.32.43/fs/jffs2/compr_rubin.c 2011-03-27 14:31:47.000000000 -0400
43430+++ linux-2.6.32.43/fs/jffs2/compr_rubin.c 2011-05-16 21:46:57.000000000 -0400
43431@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
43432 int ret;
43433 uint32_t mysrclen, mydstlen;
43434
43435+ pax_track_stack();
43436+
43437 mysrclen = *sourcelen;
43438 mydstlen = *dstlen - 8;
43439
43440diff -urNp linux-2.6.32.43/fs/jffs2/erase.c linux-2.6.32.43/fs/jffs2/erase.c
43441--- linux-2.6.32.43/fs/jffs2/erase.c 2011-03-27 14:31:47.000000000 -0400
43442+++ linux-2.6.32.43/fs/jffs2/erase.c 2011-04-17 15:56:46.000000000 -0400
43443@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(stru
43444 struct jffs2_unknown_node marker = {
43445 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
43446 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
43447- .totlen = cpu_to_je32(c->cleanmarker_size)
43448+ .totlen = cpu_to_je32(c->cleanmarker_size),
43449+ .hdr_crc = cpu_to_je32(0)
43450 };
43451
43452 jffs2_prealloc_raw_node_refs(c, jeb, 1);
43453diff -urNp linux-2.6.32.43/fs/jffs2/wbuf.c linux-2.6.32.43/fs/jffs2/wbuf.c
43454--- linux-2.6.32.43/fs/jffs2/wbuf.c 2011-03-27 14:31:47.000000000 -0400
43455+++ linux-2.6.32.43/fs/jffs2/wbuf.c 2011-04-17 15:56:46.000000000 -0400
43456@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
43457 {
43458 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
43459 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
43460- .totlen = constant_cpu_to_je32(8)
43461+ .totlen = constant_cpu_to_je32(8),
43462+ .hdr_crc = constant_cpu_to_je32(0)
43463 };
43464
43465 /*
43466diff -urNp linux-2.6.32.43/fs/jffs2/xattr.c linux-2.6.32.43/fs/jffs2/xattr.c
43467--- linux-2.6.32.43/fs/jffs2/xattr.c 2011-03-27 14:31:47.000000000 -0400
43468+++ linux-2.6.32.43/fs/jffs2/xattr.c 2011-05-16 21:46:57.000000000 -0400
43469@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
43470
43471 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
43472
43473+ pax_track_stack();
43474+
43475 /* Phase.1 : Merge same xref */
43476 for (i=0; i < XREF_TMPHASH_SIZE; i++)
43477 xref_tmphash[i] = NULL;
43478diff -urNp linux-2.6.32.43/fs/jfs/super.c linux-2.6.32.43/fs/jfs/super.c
43479--- linux-2.6.32.43/fs/jfs/super.c 2011-03-27 14:31:47.000000000 -0400
43480+++ linux-2.6.32.43/fs/jfs/super.c 2011-06-07 18:06:04.000000000 -0400
43481@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
43482
43483 jfs_inode_cachep =
43484 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
43485- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
43486+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
43487 init_once);
43488 if (jfs_inode_cachep == NULL)
43489 return -ENOMEM;
43490diff -urNp linux-2.6.32.43/fs/Kconfig.binfmt linux-2.6.32.43/fs/Kconfig.binfmt
43491--- linux-2.6.32.43/fs/Kconfig.binfmt 2011-03-27 14:31:47.000000000 -0400
43492+++ linux-2.6.32.43/fs/Kconfig.binfmt 2011-04-17 15:56:46.000000000 -0400
43493@@ -86,7 +86,7 @@ config HAVE_AOUT
43494
43495 config BINFMT_AOUT
43496 tristate "Kernel support for a.out and ECOFF binaries"
43497- depends on HAVE_AOUT
43498+ depends on HAVE_AOUT && BROKEN
43499 ---help---
43500 A.out (Assembler.OUTput) is a set of formats for libraries and
43501 executables used in the earliest versions of UNIX. Linux used
43502diff -urNp linux-2.6.32.43/fs/libfs.c linux-2.6.32.43/fs/libfs.c
43503--- linux-2.6.32.43/fs/libfs.c 2011-03-27 14:31:47.000000000 -0400
43504+++ linux-2.6.32.43/fs/libfs.c 2011-05-11 18:25:15.000000000 -0400
43505@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, v
43506
43507 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
43508 struct dentry *next;
43509+ char d_name[sizeof(next->d_iname)];
43510+ const unsigned char *name;
43511+
43512 next = list_entry(p, struct dentry, d_u.d_child);
43513 if (d_unhashed(next) || !next->d_inode)
43514 continue;
43515
43516 spin_unlock(&dcache_lock);
43517- if (filldir(dirent, next->d_name.name,
43518+ name = next->d_name.name;
43519+ if (name == next->d_iname) {
43520+ memcpy(d_name, name, next->d_name.len);
43521+ name = d_name;
43522+ }
43523+ if (filldir(dirent, name,
43524 next->d_name.len, filp->f_pos,
43525 next->d_inode->i_ino,
43526 dt_type(next->d_inode)) < 0)
43527diff -urNp linux-2.6.32.43/fs/lockd/clntproc.c linux-2.6.32.43/fs/lockd/clntproc.c
43528--- linux-2.6.32.43/fs/lockd/clntproc.c 2011-03-27 14:31:47.000000000 -0400
43529+++ linux-2.6.32.43/fs/lockd/clntproc.c 2011-05-16 21:46:57.000000000 -0400
43530@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
43531 /*
43532 * Cookie counter for NLM requests
43533 */
43534-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
43535+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
43536
43537 void nlmclnt_next_cookie(struct nlm_cookie *c)
43538 {
43539- u32 cookie = atomic_inc_return(&nlm_cookie);
43540+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
43541
43542 memcpy(c->data, &cookie, 4);
43543 c->len=4;
43544@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
43545 struct nlm_rqst reqst, *req;
43546 int status;
43547
43548+ pax_track_stack();
43549+
43550 req = &reqst;
43551 memset(req, 0, sizeof(*req));
43552 locks_init_lock(&req->a_args.lock.fl);
43553diff -urNp linux-2.6.32.43/fs/lockd/svc.c linux-2.6.32.43/fs/lockd/svc.c
43554--- linux-2.6.32.43/fs/lockd/svc.c 2011-03-27 14:31:47.000000000 -0400
43555+++ linux-2.6.32.43/fs/lockd/svc.c 2011-04-17 15:56:46.000000000 -0400
43556@@ -43,7 +43,7 @@
43557
43558 static struct svc_program nlmsvc_program;
43559
43560-struct nlmsvc_binding * nlmsvc_ops;
43561+const struct nlmsvc_binding * nlmsvc_ops;
43562 EXPORT_SYMBOL_GPL(nlmsvc_ops);
43563
43564 static DEFINE_MUTEX(nlmsvc_mutex);
43565diff -urNp linux-2.6.32.43/fs/locks.c linux-2.6.32.43/fs/locks.c
43566--- linux-2.6.32.43/fs/locks.c 2011-03-27 14:31:47.000000000 -0400
43567+++ linux-2.6.32.43/fs/locks.c 2011-07-06 19:47:11.000000000 -0400
43568@@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
43569
43570 static struct kmem_cache *filelock_cache __read_mostly;
43571
43572+static void locks_init_lock_always(struct file_lock *fl)
43573+{
43574+ fl->fl_next = NULL;
43575+ fl->fl_fasync = NULL;
43576+ fl->fl_owner = NULL;
43577+ fl->fl_pid = 0;
43578+ fl->fl_nspid = NULL;
43579+ fl->fl_file = NULL;
43580+ fl->fl_flags = 0;
43581+ fl->fl_type = 0;
43582+ fl->fl_start = fl->fl_end = 0;
43583+}
43584+
43585 /* Allocate an empty lock structure. */
43586 static struct file_lock *locks_alloc_lock(void)
43587 {
43588- return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
43589+ struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
43590+
43591+ if (fl)
43592+ locks_init_lock_always(fl);
43593+
43594+ return fl;
43595 }
43596
43597 void locks_release_private(struct file_lock *fl)
43598@@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *f
43599 INIT_LIST_HEAD(&fl->fl_link);
43600 INIT_LIST_HEAD(&fl->fl_block);
43601 init_waitqueue_head(&fl->fl_wait);
43602- fl->fl_next = NULL;
43603- fl->fl_fasync = NULL;
43604- fl->fl_owner = NULL;
43605- fl->fl_pid = 0;
43606- fl->fl_nspid = NULL;
43607- fl->fl_file = NULL;
43608- fl->fl_flags = 0;
43609- fl->fl_type = 0;
43610- fl->fl_start = fl->fl_end = 0;
43611 fl->fl_ops = NULL;
43612 fl->fl_lmops = NULL;
43613+ locks_init_lock_always(fl);
43614 }
43615
43616 EXPORT_SYMBOL(locks_init_lock);
43617@@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *fil
43618 return;
43619
43620 if (filp->f_op && filp->f_op->flock) {
43621- struct file_lock fl = {
43622+ struct file_lock flock = {
43623 .fl_pid = current->tgid,
43624 .fl_file = filp,
43625 .fl_flags = FL_FLOCK,
43626 .fl_type = F_UNLCK,
43627 .fl_end = OFFSET_MAX,
43628 };
43629- filp->f_op->flock(filp, F_SETLKW, &fl);
43630- if (fl.fl_ops && fl.fl_ops->fl_release_private)
43631- fl.fl_ops->fl_release_private(&fl);
43632+ filp->f_op->flock(filp, F_SETLKW, &flock);
43633+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
43634+ flock.fl_ops->fl_release_private(&flock);
43635 }
43636
43637 lock_kernel();
43638diff -urNp linux-2.6.32.43/fs/mbcache.c linux-2.6.32.43/fs/mbcache.c
43639--- linux-2.6.32.43/fs/mbcache.c 2011-03-27 14:31:47.000000000 -0400
43640+++ linux-2.6.32.43/fs/mbcache.c 2011-08-05 20:33:55.000000000 -0400
43641@@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct
43642 if (!cache)
43643 goto fail;
43644 cache->c_name = name;
43645- cache->c_op.free = NULL;
43646+ *(void **)&cache->c_op.free = NULL;
43647 if (cache_op)
43648- cache->c_op.free = cache_op->free;
43649+ *(void **)&cache->c_op.free = cache_op->free;
43650 atomic_set(&cache->c_entry_count, 0);
43651 cache->c_bucket_bits = bucket_bits;
43652 #ifdef MB_CACHE_INDEXES_COUNT
43653diff -urNp linux-2.6.32.43/fs/namei.c linux-2.6.32.43/fs/namei.c
43654--- linux-2.6.32.43/fs/namei.c 2011-03-27 14:31:47.000000000 -0400
43655+++ linux-2.6.32.43/fs/namei.c 2011-05-16 21:46:57.000000000 -0400
43656@@ -224,14 +224,6 @@ int generic_permission(struct inode *ino
43657 return ret;
43658
43659 /*
43660- * Read/write DACs are always overridable.
43661- * Executable DACs are overridable if at least one exec bit is set.
43662- */
43663- if (!(mask & MAY_EXEC) || execute_ok(inode))
43664- if (capable(CAP_DAC_OVERRIDE))
43665- return 0;
43666-
43667- /*
43668 * Searching includes executable on directories, else just read.
43669 */
43670 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
43671@@ -239,6 +231,14 @@ int generic_permission(struct inode *ino
43672 if (capable(CAP_DAC_READ_SEARCH))
43673 return 0;
43674
43675+ /*
43676+ * Read/write DACs are always overridable.
43677+ * Executable DACs are overridable if at least one exec bit is set.
43678+ */
43679+ if (!(mask & MAY_EXEC) || execute_ok(inode))
43680+ if (capable(CAP_DAC_OVERRIDE))
43681+ return 0;
43682+
43683 return -EACCES;
43684 }
43685
43686@@ -458,7 +458,8 @@ static int exec_permission_lite(struct i
43687 if (!ret)
43688 goto ok;
43689
43690- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
43691+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
43692+ capable(CAP_DAC_OVERRIDE))
43693 goto ok;
43694
43695 return ret;
43696@@ -638,7 +639,7 @@ static __always_inline int __do_follow_l
43697 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
43698 error = PTR_ERR(cookie);
43699 if (!IS_ERR(cookie)) {
43700- char *s = nd_get_link(nd);
43701+ const char *s = nd_get_link(nd);
43702 error = 0;
43703 if (s)
43704 error = __vfs_follow_link(nd, s);
43705@@ -669,6 +670,13 @@ static inline int do_follow_link(struct
43706 err = security_inode_follow_link(path->dentry, nd);
43707 if (err)
43708 goto loop;
43709+
43710+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
43711+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
43712+ err = -EACCES;
43713+ goto loop;
43714+ }
43715+
43716 current->link_count++;
43717 current->total_link_count++;
43718 nd->depth++;
43719@@ -1016,11 +1024,18 @@ return_reval:
43720 break;
43721 }
43722 return_base:
43723+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
43724+ path_put(&nd->path);
43725+ return -ENOENT;
43726+ }
43727 return 0;
43728 out_dput:
43729 path_put_conditional(&next, nd);
43730 break;
43731 }
43732+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
43733+ err = -ENOENT;
43734+
43735 path_put(&nd->path);
43736 return_err:
43737 return err;
43738@@ -1091,13 +1106,20 @@ static int do_path_lookup(int dfd, const
43739 int retval = path_init(dfd, name, flags, nd);
43740 if (!retval)
43741 retval = path_walk(name, nd);
43742- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
43743- nd->path.dentry->d_inode))
43744- audit_inode(name, nd->path.dentry);
43745+
43746+ if (likely(!retval)) {
43747+ if (nd->path.dentry && nd->path.dentry->d_inode) {
43748+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
43749+ retval = -ENOENT;
43750+ if (!audit_dummy_context())
43751+ audit_inode(name, nd->path.dentry);
43752+ }
43753+ }
43754 if (nd->root.mnt) {
43755 path_put(&nd->root);
43756 nd->root.mnt = NULL;
43757 }
43758+
43759 return retval;
43760 }
43761
43762@@ -1576,6 +1598,20 @@ int may_open(struct path *path, int acc_
43763 if (error)
43764 goto err_out;
43765
43766+
43767+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
43768+ error = -EPERM;
43769+ goto err_out;
43770+ }
43771+ if (gr_handle_rawio(inode)) {
43772+ error = -EPERM;
43773+ goto err_out;
43774+ }
43775+ if (!gr_acl_handle_open(dentry, path->mnt, flag)) {
43776+ error = -EACCES;
43777+ goto err_out;
43778+ }
43779+
43780 if (flag & O_TRUNC) {
43781 error = get_write_access(inode);
43782 if (error)
43783@@ -1621,12 +1657,19 @@ static int __open_namei_create(struct na
43784 int error;
43785 struct dentry *dir = nd->path.dentry;
43786
43787+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
43788+ error = -EACCES;
43789+ goto out_unlock;
43790+ }
43791+
43792 if (!IS_POSIXACL(dir->d_inode))
43793 mode &= ~current_umask();
43794 error = security_path_mknod(&nd->path, path->dentry, mode, 0);
43795 if (error)
43796 goto out_unlock;
43797 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
43798+ if (!error)
43799+ gr_handle_create(path->dentry, nd->path.mnt);
43800 out_unlock:
43801 mutex_unlock(&dir->d_inode->i_mutex);
43802 dput(nd->path.dentry);
43803@@ -1709,6 +1752,22 @@ struct file *do_filp_open(int dfd, const
43804 &nd, flag);
43805 if (error)
43806 return ERR_PTR(error);
43807+
43808+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
43809+ error = -EPERM;
43810+ goto exit;
43811+ }
43812+
43813+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
43814+ error = -EPERM;
43815+ goto exit;
43816+ }
43817+
43818+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
43819+ error = -EACCES;
43820+ goto exit;
43821+ }
43822+
43823 goto ok;
43824 }
43825
43826@@ -1795,6 +1854,14 @@ do_last:
43827 /*
43828 * It already exists.
43829 */
43830+
43831+ /* only check if O_CREAT is specified, all other checks need
43832+ to go into may_open */
43833+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
43834+ error = -EACCES;
43835+ goto exit_mutex_unlock;
43836+ }
43837+
43838 mutex_unlock(&dir->d_inode->i_mutex);
43839 audit_inode(pathname, path.dentry);
43840
43841@@ -1887,6 +1954,13 @@ do_link:
43842 error = security_inode_follow_link(path.dentry, &nd);
43843 if (error)
43844 goto exit_dput;
43845+
43846+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
43847+ path.dentry, nd.path.mnt)) {
43848+ error = -EACCES;
43849+ goto exit_dput;
43850+ }
43851+
43852 error = __do_follow_link(&path, &nd);
43853 if (error) {
43854 /* Does someone understand code flow here? Or it is only
43855@@ -2061,6 +2135,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
43856 error = may_mknod(mode);
43857 if (error)
43858 goto out_dput;
43859+
43860+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
43861+ error = -EPERM;
43862+ goto out_dput;
43863+ }
43864+
43865+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
43866+ error = -EACCES;
43867+ goto out_dput;
43868+ }
43869+
43870 error = mnt_want_write(nd.path.mnt);
43871 if (error)
43872 goto out_dput;
43873@@ -2081,6 +2166,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
43874 }
43875 out_drop_write:
43876 mnt_drop_write(nd.path.mnt);
43877+
43878+ if (!error)
43879+ gr_handle_create(dentry, nd.path.mnt);
43880 out_dput:
43881 dput(dentry);
43882 out_unlock:
43883@@ -2134,6 +2222,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
43884 if (IS_ERR(dentry))
43885 goto out_unlock;
43886
43887+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
43888+ error = -EACCES;
43889+ goto out_dput;
43890+ }
43891+
43892 if (!IS_POSIXACL(nd.path.dentry->d_inode))
43893 mode &= ~current_umask();
43894 error = mnt_want_write(nd.path.mnt);
43895@@ -2145,6 +2238,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
43896 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
43897 out_drop_write:
43898 mnt_drop_write(nd.path.mnt);
43899+
43900+ if (!error)
43901+ gr_handle_create(dentry, nd.path.mnt);
43902+
43903 out_dput:
43904 dput(dentry);
43905 out_unlock:
43906@@ -2226,6 +2323,8 @@ static long do_rmdir(int dfd, const char
43907 char * name;
43908 struct dentry *dentry;
43909 struct nameidata nd;
43910+ ino_t saved_ino = 0;
43911+ dev_t saved_dev = 0;
43912
43913 error = user_path_parent(dfd, pathname, &nd, &name);
43914 if (error)
43915@@ -2250,6 +2349,19 @@ static long do_rmdir(int dfd, const char
43916 error = PTR_ERR(dentry);
43917 if (IS_ERR(dentry))
43918 goto exit2;
43919+
43920+ if (dentry->d_inode != NULL) {
43921+ if (dentry->d_inode->i_nlink <= 1) {
43922+ saved_ino = dentry->d_inode->i_ino;
43923+ saved_dev = gr_get_dev_from_dentry(dentry);
43924+ }
43925+
43926+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
43927+ error = -EACCES;
43928+ goto exit3;
43929+ }
43930+ }
43931+
43932 error = mnt_want_write(nd.path.mnt);
43933 if (error)
43934 goto exit3;
43935@@ -2257,6 +2369,8 @@ static long do_rmdir(int dfd, const char
43936 if (error)
43937 goto exit4;
43938 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
43939+ if (!error && (saved_dev || saved_ino))
43940+ gr_handle_delete(saved_ino, saved_dev);
43941 exit4:
43942 mnt_drop_write(nd.path.mnt);
43943 exit3:
43944@@ -2318,6 +2432,8 @@ static long do_unlinkat(int dfd, const c
43945 struct dentry *dentry;
43946 struct nameidata nd;
43947 struct inode *inode = NULL;
43948+ ino_t saved_ino = 0;
43949+ dev_t saved_dev = 0;
43950
43951 error = user_path_parent(dfd, pathname, &nd, &name);
43952 if (error)
43953@@ -2337,8 +2453,19 @@ static long do_unlinkat(int dfd, const c
43954 if (nd.last.name[nd.last.len])
43955 goto slashes;
43956 inode = dentry->d_inode;
43957- if (inode)
43958+ if (inode) {
43959+ if (inode->i_nlink <= 1) {
43960+ saved_ino = inode->i_ino;
43961+ saved_dev = gr_get_dev_from_dentry(dentry);
43962+ }
43963+
43964 atomic_inc(&inode->i_count);
43965+
43966+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
43967+ error = -EACCES;
43968+ goto exit2;
43969+ }
43970+ }
43971 error = mnt_want_write(nd.path.mnt);
43972 if (error)
43973 goto exit2;
43974@@ -2346,6 +2473,8 @@ static long do_unlinkat(int dfd, const c
43975 if (error)
43976 goto exit3;
43977 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
43978+ if (!error && (saved_ino || saved_dev))
43979+ gr_handle_delete(saved_ino, saved_dev);
43980 exit3:
43981 mnt_drop_write(nd.path.mnt);
43982 exit2:
43983@@ -2424,6 +2553,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
43984 if (IS_ERR(dentry))
43985 goto out_unlock;
43986
43987+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
43988+ error = -EACCES;
43989+ goto out_dput;
43990+ }
43991+
43992 error = mnt_want_write(nd.path.mnt);
43993 if (error)
43994 goto out_dput;
43995@@ -2431,6 +2565,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
43996 if (error)
43997 goto out_drop_write;
43998 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
43999+ if (!error)
44000+ gr_handle_create(dentry, nd.path.mnt);
44001 out_drop_write:
44002 mnt_drop_write(nd.path.mnt);
44003 out_dput:
44004@@ -2524,6 +2660,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
44005 error = PTR_ERR(new_dentry);
44006 if (IS_ERR(new_dentry))
44007 goto out_unlock;
44008+
44009+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
44010+ old_path.dentry->d_inode,
44011+ old_path.dentry->d_inode->i_mode, to)) {
44012+ error = -EACCES;
44013+ goto out_dput;
44014+ }
44015+
44016+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
44017+ old_path.dentry, old_path.mnt, to)) {
44018+ error = -EACCES;
44019+ goto out_dput;
44020+ }
44021+
44022 error = mnt_want_write(nd.path.mnt);
44023 if (error)
44024 goto out_dput;
44025@@ -2531,6 +2681,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
44026 if (error)
44027 goto out_drop_write;
44028 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
44029+ if (!error)
44030+ gr_handle_create(new_dentry, nd.path.mnt);
44031 out_drop_write:
44032 mnt_drop_write(nd.path.mnt);
44033 out_dput:
44034@@ -2708,6 +2860,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
44035 char *to;
44036 int error;
44037
44038+ pax_track_stack();
44039+
44040 error = user_path_parent(olddfd, oldname, &oldnd, &from);
44041 if (error)
44042 goto exit;
44043@@ -2764,6 +2918,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
44044 if (new_dentry == trap)
44045 goto exit5;
44046
44047+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
44048+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
44049+ to);
44050+ if (error)
44051+ goto exit5;
44052+
44053 error = mnt_want_write(oldnd.path.mnt);
44054 if (error)
44055 goto exit5;
44056@@ -2773,6 +2933,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
44057 goto exit6;
44058 error = vfs_rename(old_dir->d_inode, old_dentry,
44059 new_dir->d_inode, new_dentry);
44060+ if (!error)
44061+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
44062+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
44063 exit6:
44064 mnt_drop_write(oldnd.path.mnt);
44065 exit5:
44066@@ -2798,6 +2961,8 @@ SYSCALL_DEFINE2(rename, const char __use
44067
44068 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
44069 {
44070+ char tmpbuf[64];
44071+ const char *newlink;
44072 int len;
44073
44074 len = PTR_ERR(link);
44075@@ -2807,7 +2972,14 @@ int vfs_readlink(struct dentry *dentry,
44076 len = strlen(link);
44077 if (len > (unsigned) buflen)
44078 len = buflen;
44079- if (copy_to_user(buffer, link, len))
44080+
44081+ if (len < sizeof(tmpbuf)) {
44082+ memcpy(tmpbuf, link, len);
44083+ newlink = tmpbuf;
44084+ } else
44085+ newlink = link;
44086+
44087+ if (copy_to_user(buffer, newlink, len))
44088 len = -EFAULT;
44089 out:
44090 return len;
44091diff -urNp linux-2.6.32.43/fs/namespace.c linux-2.6.32.43/fs/namespace.c
44092--- linux-2.6.32.43/fs/namespace.c 2011-03-27 14:31:47.000000000 -0400
44093+++ linux-2.6.32.43/fs/namespace.c 2011-04-17 15:56:46.000000000 -0400
44094@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mn
44095 if (!(sb->s_flags & MS_RDONLY))
44096 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
44097 up_write(&sb->s_umount);
44098+
44099+ gr_log_remount(mnt->mnt_devname, retval);
44100+
44101 return retval;
44102 }
44103
44104@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mn
44105 security_sb_umount_busy(mnt);
44106 up_write(&namespace_sem);
44107 release_mounts(&umount_list);
44108+
44109+ gr_log_unmount(mnt->mnt_devname, retval);
44110+
44111 return retval;
44112 }
44113
44114@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_
44115 if (retval)
44116 goto dput_out;
44117
44118+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
44119+ retval = -EPERM;
44120+ goto dput_out;
44121+ }
44122+
44123+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
44124+ retval = -EPERM;
44125+ goto dput_out;
44126+ }
44127+
44128 if (flags & MS_REMOUNT)
44129 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
44130 data_page);
44131@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_
44132 dev_name, data_page);
44133 dput_out:
44134 path_put(&path);
44135+
44136+ gr_log_mount(dev_name, dir_name, retval);
44137+
44138 return retval;
44139 }
44140
44141@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char _
44142 goto out1;
44143 }
44144
44145+ if (gr_handle_chroot_pivot()) {
44146+ error = -EPERM;
44147+ path_put(&old);
44148+ goto out1;
44149+ }
44150+
44151 read_lock(&current->fs->lock);
44152 root = current->fs->root;
44153 path_get(&current->fs->root);
44154diff -urNp linux-2.6.32.43/fs/ncpfs/dir.c linux-2.6.32.43/fs/ncpfs/dir.c
44155--- linux-2.6.32.43/fs/ncpfs/dir.c 2011-03-27 14:31:47.000000000 -0400
44156+++ linux-2.6.32.43/fs/ncpfs/dir.c 2011-05-16 21:46:57.000000000 -0400
44157@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *den
44158 int res, val = 0, len;
44159 __u8 __name[NCP_MAXPATHLEN + 1];
44160
44161+ pax_track_stack();
44162+
44163 parent = dget_parent(dentry);
44164 dir = parent->d_inode;
44165
44166@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct
44167 int error, res, len;
44168 __u8 __name[NCP_MAXPATHLEN + 1];
44169
44170+ pax_track_stack();
44171+
44172 lock_kernel();
44173 error = -EIO;
44174 if (!ncp_conn_valid(server))
44175@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, st
44176 int error, result, len;
44177 int opmode;
44178 __u8 __name[NCP_MAXPATHLEN + 1];
44179-
44180+
44181 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
44182 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
44183
44184+ pax_track_stack();
44185+
44186 error = -EIO;
44187 lock_kernel();
44188 if (!ncp_conn_valid(server))
44189@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir,
44190 int error, len;
44191 __u8 __name[NCP_MAXPATHLEN + 1];
44192
44193+ pax_track_stack();
44194+
44195 DPRINTK("ncp_mkdir: making %s/%s\n",
44196 dentry->d_parent->d_name.name, dentry->d_name.name);
44197
44198@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir,
44199 if (!ncp_conn_valid(server))
44200 goto out;
44201
44202+ pax_track_stack();
44203+
44204 ncp_age_dentry(server, dentry);
44205 len = sizeof(__name);
44206 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
44207@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_
44208 int old_len, new_len;
44209 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
44210
44211+ pax_track_stack();
44212+
44213 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
44214 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
44215 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
44216diff -urNp linux-2.6.32.43/fs/ncpfs/inode.c linux-2.6.32.43/fs/ncpfs/inode.c
44217--- linux-2.6.32.43/fs/ncpfs/inode.c 2011-03-27 14:31:47.000000000 -0400
44218+++ linux-2.6.32.43/fs/ncpfs/inode.c 2011-05-16 21:46:57.000000000 -0400
44219@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_b
44220 #endif
44221 struct ncp_entry_info finfo;
44222
44223+ pax_track_stack();
44224+
44225 data.wdog_pid = NULL;
44226 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
44227 if (!server)
44228diff -urNp linux-2.6.32.43/fs/nfs/inode.c linux-2.6.32.43/fs/nfs/inode.c
44229--- linux-2.6.32.43/fs/nfs/inode.c 2011-05-10 22:12:01.000000000 -0400
44230+++ linux-2.6.32.43/fs/nfs/inode.c 2011-07-06 19:53:33.000000000 -0400
44231@@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct
44232 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
44233 nfsi->attrtimeo_timestamp = jiffies;
44234
44235- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
44236+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
44237 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
44238 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
44239 else
44240@@ -973,16 +973,16 @@ static int nfs_size_need_update(const st
44241 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
44242 }
44243
44244-static atomic_long_t nfs_attr_generation_counter;
44245+static atomic_long_unchecked_t nfs_attr_generation_counter;
44246
44247 static unsigned long nfs_read_attr_generation_counter(void)
44248 {
44249- return atomic_long_read(&nfs_attr_generation_counter);
44250+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
44251 }
44252
44253 unsigned long nfs_inc_attr_generation_counter(void)
44254 {
44255- return atomic_long_inc_return(&nfs_attr_generation_counter);
44256+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
44257 }
44258
44259 void nfs_fattr_init(struct nfs_fattr *fattr)
44260diff -urNp linux-2.6.32.43/fs/nfsd/lockd.c linux-2.6.32.43/fs/nfsd/lockd.c
44261--- linux-2.6.32.43/fs/nfsd/lockd.c 2011-04-17 17:00:52.000000000 -0400
44262+++ linux-2.6.32.43/fs/nfsd/lockd.c 2011-04-17 17:03:15.000000000 -0400
44263@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
44264 fput(filp);
44265 }
44266
44267-static struct nlmsvc_binding nfsd_nlm_ops = {
44268+static const struct nlmsvc_binding nfsd_nlm_ops = {
44269 .fopen = nlm_fopen, /* open file for locking */
44270 .fclose = nlm_fclose, /* close file */
44271 };
44272diff -urNp linux-2.6.32.43/fs/nfsd/nfs4state.c linux-2.6.32.43/fs/nfsd/nfs4state.c
44273--- linux-2.6.32.43/fs/nfsd/nfs4state.c 2011-03-27 14:31:47.000000000 -0400
44274+++ linux-2.6.32.43/fs/nfsd/nfs4state.c 2011-05-16 21:46:57.000000000 -0400
44275@@ -3457,6 +3457,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
44276 unsigned int cmd;
44277 int err;
44278
44279+ pax_track_stack();
44280+
44281 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
44282 (long long) lock->lk_offset,
44283 (long long) lock->lk_length);
44284diff -urNp linux-2.6.32.43/fs/nfsd/nfs4xdr.c linux-2.6.32.43/fs/nfsd/nfs4xdr.c
44285--- linux-2.6.32.43/fs/nfsd/nfs4xdr.c 2011-03-27 14:31:47.000000000 -0400
44286+++ linux-2.6.32.43/fs/nfsd/nfs4xdr.c 2011-05-16 21:46:57.000000000 -0400
44287@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
44288 struct nfsd4_compoundres *resp = rqstp->rq_resp;
44289 u32 minorversion = resp->cstate.minorversion;
44290
44291+ pax_track_stack();
44292+
44293 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
44294 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
44295 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
44296diff -urNp linux-2.6.32.43/fs/nfsd/vfs.c linux-2.6.32.43/fs/nfsd/vfs.c
44297--- linux-2.6.32.43/fs/nfsd/vfs.c 2011-05-10 22:12:01.000000000 -0400
44298+++ linux-2.6.32.43/fs/nfsd/vfs.c 2011-05-10 22:12:33.000000000 -0400
44299@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
44300 } else {
44301 oldfs = get_fs();
44302 set_fs(KERNEL_DS);
44303- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
44304+ host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
44305 set_fs(oldfs);
44306 }
44307
44308@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
44309
44310 /* Write the data. */
44311 oldfs = get_fs(); set_fs(KERNEL_DS);
44312- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
44313+ host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
44314 set_fs(oldfs);
44315 if (host_err < 0)
44316 goto out_nfserr;
44317@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
44318 */
44319
44320 oldfs = get_fs(); set_fs(KERNEL_DS);
44321- host_err = inode->i_op->readlink(dentry, buf, *lenp);
44322+ host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
44323 set_fs(oldfs);
44324
44325 if (host_err < 0)
44326diff -urNp linux-2.6.32.43/fs/nilfs2/ioctl.c linux-2.6.32.43/fs/nilfs2/ioctl.c
44327--- linux-2.6.32.43/fs/nilfs2/ioctl.c 2011-03-27 14:31:47.000000000 -0400
44328+++ linux-2.6.32.43/fs/nilfs2/ioctl.c 2011-05-04 17:56:28.000000000 -0400
44329@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(st
44330 unsigned int cmd, void __user *argp)
44331 {
44332 struct nilfs_argv argv[5];
44333- const static size_t argsz[5] = {
44334+ static const size_t argsz[5] = {
44335 sizeof(struct nilfs_vdesc),
44336 sizeof(struct nilfs_period),
44337 sizeof(__u64),
44338diff -urNp linux-2.6.32.43/fs/notify/dnotify/dnotify.c linux-2.6.32.43/fs/notify/dnotify/dnotify.c
44339--- linux-2.6.32.43/fs/notify/dnotify/dnotify.c 2011-03-27 14:31:47.000000000 -0400
44340+++ linux-2.6.32.43/fs/notify/dnotify/dnotify.c 2011-04-17 15:56:46.000000000 -0400
44341@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsn
44342 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
44343 }
44344
44345-static struct fsnotify_ops dnotify_fsnotify_ops = {
44346+static const struct fsnotify_ops dnotify_fsnotify_ops = {
44347 .handle_event = dnotify_handle_event,
44348 .should_send_event = dnotify_should_send_event,
44349 .free_group_priv = NULL,
44350diff -urNp linux-2.6.32.43/fs/notify/notification.c linux-2.6.32.43/fs/notify/notification.c
44351--- linux-2.6.32.43/fs/notify/notification.c 2011-03-27 14:31:47.000000000 -0400
44352+++ linux-2.6.32.43/fs/notify/notification.c 2011-05-04 17:56:28.000000000 -0400
44353@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
44354 * get set to 0 so it will never get 'freed'
44355 */
44356 static struct fsnotify_event q_overflow_event;
44357-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44358+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
44359
44360 /**
44361 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
44362@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
44363 */
44364 u32 fsnotify_get_cookie(void)
44365 {
44366- return atomic_inc_return(&fsnotify_sync_cookie);
44367+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
44368 }
44369 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
44370
44371diff -urNp linux-2.6.32.43/fs/ntfs/dir.c linux-2.6.32.43/fs/ntfs/dir.c
44372--- linux-2.6.32.43/fs/ntfs/dir.c 2011-03-27 14:31:47.000000000 -0400
44373+++ linux-2.6.32.43/fs/ntfs/dir.c 2011-04-17 15:56:46.000000000 -0400
44374@@ -1328,7 +1328,7 @@ find_next_index_buffer:
44375 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
44376 ~(s64)(ndir->itype.index.block_size - 1)));
44377 /* Bounds checks. */
44378- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44379+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
44380 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
44381 "inode 0x%lx or driver bug.", vdir->i_ino);
44382 goto err_out;
44383diff -urNp linux-2.6.32.43/fs/ntfs/file.c linux-2.6.32.43/fs/ntfs/file.c
44384--- linux-2.6.32.43/fs/ntfs/file.c 2011-03-27 14:31:47.000000000 -0400
44385+++ linux-2.6.32.43/fs/ntfs/file.c 2011-04-17 15:56:46.000000000 -0400
44386@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_
44387 #endif /* NTFS_RW */
44388 };
44389
44390-const struct file_operations ntfs_empty_file_ops = {};
44391+const struct file_operations ntfs_empty_file_ops __read_only;
44392
44393-const struct inode_operations ntfs_empty_inode_ops = {};
44394+const struct inode_operations ntfs_empty_inode_ops __read_only;
44395diff -urNp linux-2.6.32.43/fs/ocfs2/cluster/masklog.c linux-2.6.32.43/fs/ocfs2/cluster/masklog.c
44396--- linux-2.6.32.43/fs/ocfs2/cluster/masklog.c 2011-03-27 14:31:47.000000000 -0400
44397+++ linux-2.6.32.43/fs/ocfs2/cluster/masklog.c 2011-04-17 15:56:46.000000000 -0400
44398@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject
44399 return mlog_mask_store(mlog_attr->mask, buf, count);
44400 }
44401
44402-static struct sysfs_ops mlog_attr_ops = {
44403+static const struct sysfs_ops mlog_attr_ops = {
44404 .show = mlog_show,
44405 .store = mlog_store,
44406 };
44407diff -urNp linux-2.6.32.43/fs/ocfs2/localalloc.c linux-2.6.32.43/fs/ocfs2/localalloc.c
44408--- linux-2.6.32.43/fs/ocfs2/localalloc.c 2011-03-27 14:31:47.000000000 -0400
44409+++ linux-2.6.32.43/fs/ocfs2/localalloc.c 2011-04-17 15:56:46.000000000 -0400
44410@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_windo
44411 goto bail;
44412 }
44413
44414- atomic_inc(&osb->alloc_stats.moves);
44415+ atomic_inc_unchecked(&osb->alloc_stats.moves);
44416
44417 status = 0;
44418 bail:
44419diff -urNp linux-2.6.32.43/fs/ocfs2/namei.c linux-2.6.32.43/fs/ocfs2/namei.c
44420--- linux-2.6.32.43/fs/ocfs2/namei.c 2011-03-27 14:31:47.000000000 -0400
44421+++ linux-2.6.32.43/fs/ocfs2/namei.c 2011-05-16 21:46:57.000000000 -0400
44422@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *ol
44423 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
44424 struct ocfs2_dir_lookup_result target_insert = { NULL, };
44425
44426+ pax_track_stack();
44427+
44428 /* At some point it might be nice to break this function up a
44429 * bit. */
44430
44431diff -urNp linux-2.6.32.43/fs/ocfs2/ocfs2.h linux-2.6.32.43/fs/ocfs2/ocfs2.h
44432--- linux-2.6.32.43/fs/ocfs2/ocfs2.h 2011-03-27 14:31:47.000000000 -0400
44433+++ linux-2.6.32.43/fs/ocfs2/ocfs2.h 2011-04-17 15:56:46.000000000 -0400
44434@@ -217,11 +217,11 @@ enum ocfs2_vol_state
44435
44436 struct ocfs2_alloc_stats
44437 {
44438- atomic_t moves;
44439- atomic_t local_data;
44440- atomic_t bitmap_data;
44441- atomic_t bg_allocs;
44442- atomic_t bg_extends;
44443+ atomic_unchecked_t moves;
44444+ atomic_unchecked_t local_data;
44445+ atomic_unchecked_t bitmap_data;
44446+ atomic_unchecked_t bg_allocs;
44447+ atomic_unchecked_t bg_extends;
44448 };
44449
44450 enum ocfs2_local_alloc_state
44451diff -urNp linux-2.6.32.43/fs/ocfs2/suballoc.c linux-2.6.32.43/fs/ocfs2/suballoc.c
44452--- linux-2.6.32.43/fs/ocfs2/suballoc.c 2011-03-27 14:31:47.000000000 -0400
44453+++ linux-2.6.32.43/fs/ocfs2/suballoc.c 2011-04-17 15:56:46.000000000 -0400
44454@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(s
44455 mlog_errno(status);
44456 goto bail;
44457 }
44458- atomic_inc(&osb->alloc_stats.bg_extends);
44459+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
44460
44461 /* You should never ask for this much metadata */
44462 BUG_ON(bits_wanted >
44463@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_su
44464 mlog_errno(status);
44465 goto bail;
44466 }
44467- atomic_inc(&osb->alloc_stats.bg_allocs);
44468+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
44469
44470 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
44471 ac->ac_bits_given += (*num_bits);
44472@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_s
44473 mlog_errno(status);
44474 goto bail;
44475 }
44476- atomic_inc(&osb->alloc_stats.bg_allocs);
44477+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
44478
44479 BUG_ON(num_bits != 1);
44480
44481@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
44482 cluster_start,
44483 num_clusters);
44484 if (!status)
44485- atomic_inc(&osb->alloc_stats.local_data);
44486+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
44487 } else {
44488 if (min_clusters > (osb->bitmap_cpg - 1)) {
44489 /* The only paths asking for contiguousness
44490@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
44491 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
44492 bg_blkno,
44493 bg_bit_off);
44494- atomic_inc(&osb->alloc_stats.bitmap_data);
44495+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
44496 }
44497 }
44498 if (status < 0) {
44499diff -urNp linux-2.6.32.43/fs/ocfs2/super.c linux-2.6.32.43/fs/ocfs2/super.c
44500--- linux-2.6.32.43/fs/ocfs2/super.c 2011-03-27 14:31:47.000000000 -0400
44501+++ linux-2.6.32.43/fs/ocfs2/super.c 2011-04-17 15:56:46.000000000 -0400
44502@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
44503 "%10s => GlobalAllocs: %d LocalAllocs: %d "
44504 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
44505 "Stats",
44506- atomic_read(&osb->alloc_stats.bitmap_data),
44507- atomic_read(&osb->alloc_stats.local_data),
44508- atomic_read(&osb->alloc_stats.bg_allocs),
44509- atomic_read(&osb->alloc_stats.moves),
44510- atomic_read(&osb->alloc_stats.bg_extends));
44511+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
44512+ atomic_read_unchecked(&osb->alloc_stats.local_data),
44513+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
44514+ atomic_read_unchecked(&osb->alloc_stats.moves),
44515+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
44516
44517 out += snprintf(buf + out, len - out,
44518 "%10s => State: %u Descriptor: %llu Size: %u bits "
44519@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct
44520 spin_lock_init(&osb->osb_xattr_lock);
44521 ocfs2_init_inode_steal_slot(osb);
44522
44523- atomic_set(&osb->alloc_stats.moves, 0);
44524- atomic_set(&osb->alloc_stats.local_data, 0);
44525- atomic_set(&osb->alloc_stats.bitmap_data, 0);
44526- atomic_set(&osb->alloc_stats.bg_allocs, 0);
44527- atomic_set(&osb->alloc_stats.bg_extends, 0);
44528+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
44529+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
44530+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
44531+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
44532+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
44533
44534 /* Copy the blockcheck stats from the superblock probe */
44535 osb->osb_ecc_stats = *stats;
44536diff -urNp linux-2.6.32.43/fs/open.c linux-2.6.32.43/fs/open.c
44537--- linux-2.6.32.43/fs/open.c 2011-03-27 14:31:47.000000000 -0400
44538+++ linux-2.6.32.43/fs/open.c 2011-04-17 15:56:46.000000000 -0400
44539@@ -275,6 +275,10 @@ static long do_sys_truncate(const char _
44540 error = locks_verify_truncate(inode, NULL, length);
44541 if (!error)
44542 error = security_path_truncate(&path, length, 0);
44543+
44544+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
44545+ error = -EACCES;
44546+
44547 if (!error) {
44548 vfs_dq_init(inode);
44549 error = do_truncate(path.dentry, length, 0, NULL);
44550@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
44551 if (__mnt_is_readonly(path.mnt))
44552 res = -EROFS;
44553
44554+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
44555+ res = -EACCES;
44556+
44557 out_path_release:
44558 path_put(&path);
44559 out:
44560@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user
44561 if (error)
44562 goto dput_and_out;
44563
44564+ gr_log_chdir(path.dentry, path.mnt);
44565+
44566 set_fs_pwd(current->fs, &path);
44567
44568 dput_and_out:
44569@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
44570 goto out_putf;
44571
44572 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
44573+
44574+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
44575+ error = -EPERM;
44576+
44577+ if (!error)
44578+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
44579+
44580 if (!error)
44581 set_fs_pwd(current->fs, &file->f_path);
44582 out_putf:
44583@@ -588,7 +604,18 @@ SYSCALL_DEFINE1(chroot, const char __use
44584 if (!capable(CAP_SYS_CHROOT))
44585 goto dput_and_out;
44586
44587+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
44588+ goto dput_and_out;
44589+
44590+ if (gr_handle_chroot_caps(&path)) {
44591+ error = -ENOMEM;
44592+ goto dput_and_out;
44593+ }
44594+
44595 set_fs_root(current->fs, &path);
44596+
44597+ gr_handle_chroot_chdir(&path);
44598+
44599 error = 0;
44600 dput_and_out:
44601 path_put(&path);
44602@@ -616,12 +643,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
44603 err = mnt_want_write_file(file);
44604 if (err)
44605 goto out_putf;
44606+
44607 mutex_lock(&inode->i_mutex);
44608+
44609+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
44610+ err = -EACCES;
44611+ goto out_unlock;
44612+ }
44613+
44614 if (mode == (mode_t) -1)
44615 mode = inode->i_mode;
44616+
44617+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
44618+ err = -EPERM;
44619+ goto out_unlock;
44620+ }
44621+
44622 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
44623 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
44624 err = notify_change(dentry, &newattrs);
44625+
44626+out_unlock:
44627 mutex_unlock(&inode->i_mutex);
44628 mnt_drop_write(file->f_path.mnt);
44629 out_putf:
44630@@ -645,12 +687,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
44631 error = mnt_want_write(path.mnt);
44632 if (error)
44633 goto dput_and_out;
44634+
44635 mutex_lock(&inode->i_mutex);
44636+
44637+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
44638+ error = -EACCES;
44639+ goto out_unlock;
44640+ }
44641+
44642 if (mode == (mode_t) -1)
44643 mode = inode->i_mode;
44644+
44645+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
44646+ error = -EACCES;
44647+ goto out_unlock;
44648+ }
44649+
44650 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
44651 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
44652 error = notify_change(path.dentry, &newattrs);
44653+
44654+out_unlock:
44655 mutex_unlock(&inode->i_mutex);
44656 mnt_drop_write(path.mnt);
44657 dput_and_out:
44658@@ -664,12 +721,15 @@ SYSCALL_DEFINE2(chmod, const char __user
44659 return sys_fchmodat(AT_FDCWD, filename, mode);
44660 }
44661
44662-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
44663+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
44664 {
44665 struct inode *inode = dentry->d_inode;
44666 int error;
44667 struct iattr newattrs;
44668
44669+ if (!gr_acl_handle_chown(dentry, mnt))
44670+ return -EACCES;
44671+
44672 newattrs.ia_valid = ATTR_CTIME;
44673 if (user != (uid_t) -1) {
44674 newattrs.ia_valid |= ATTR_UID;
44675@@ -700,7 +760,7 @@ SYSCALL_DEFINE3(chown, const char __user
44676 error = mnt_want_write(path.mnt);
44677 if (error)
44678 goto out_release;
44679- error = chown_common(path.dentry, user, group);
44680+ error = chown_common(path.dentry, user, group, path.mnt);
44681 mnt_drop_write(path.mnt);
44682 out_release:
44683 path_put(&path);
44684@@ -725,7 +785,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
44685 error = mnt_want_write(path.mnt);
44686 if (error)
44687 goto out_release;
44688- error = chown_common(path.dentry, user, group);
44689+ error = chown_common(path.dentry, user, group, path.mnt);
44690 mnt_drop_write(path.mnt);
44691 out_release:
44692 path_put(&path);
44693@@ -744,7 +804,7 @@ SYSCALL_DEFINE3(lchown, const char __use
44694 error = mnt_want_write(path.mnt);
44695 if (error)
44696 goto out_release;
44697- error = chown_common(path.dentry, user, group);
44698+ error = chown_common(path.dentry, user, group, path.mnt);
44699 mnt_drop_write(path.mnt);
44700 out_release:
44701 path_put(&path);
44702@@ -767,7 +827,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd
44703 goto out_fput;
44704 dentry = file->f_path.dentry;
44705 audit_inode(NULL, dentry);
44706- error = chown_common(dentry, user, group);
44707+ error = chown_common(dentry, user, group, file->f_path.mnt);
44708 mnt_drop_write(file->f_path.mnt);
44709 out_fput:
44710 fput(file);
44711@@ -1036,7 +1096,10 @@ long do_sys_open(int dfd, const char __u
44712 if (!IS_ERR(tmp)) {
44713 fd = get_unused_fd_flags(flags);
44714 if (fd >= 0) {
44715- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
44716+ struct file *f;
44717+ /* don't allow to be set by userland */
44718+ flags &= ~FMODE_GREXEC;
44719+ f = do_filp_open(dfd, tmp, flags, mode, 0);
44720 if (IS_ERR(f)) {
44721 put_unused_fd(fd);
44722 fd = PTR_ERR(f);
44723diff -urNp linux-2.6.32.43/fs/partitions/ldm.c linux-2.6.32.43/fs/partitions/ldm.c
44724--- linux-2.6.32.43/fs/partitions/ldm.c 2011-06-25 12:55:34.000000000 -0400
44725+++ linux-2.6.32.43/fs/partitions/ldm.c 2011-06-25 12:56:37.000000000 -0400
44726@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
44727 ldm_error ("A VBLK claims to have %d parts.", num);
44728 return false;
44729 }
44730+
44731 if (rec >= num) {
44732 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
44733 return false;
44734@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
44735 goto found;
44736 }
44737
44738- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
44739+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
44740 if (!f) {
44741 ldm_crit ("Out of memory.");
44742 return false;
44743diff -urNp linux-2.6.32.43/fs/partitions/mac.c linux-2.6.32.43/fs/partitions/mac.c
44744--- linux-2.6.32.43/fs/partitions/mac.c 2011-03-27 14:31:47.000000000 -0400
44745+++ linux-2.6.32.43/fs/partitions/mac.c 2011-04-17 15:56:46.000000000 -0400
44746@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitio
44747 return 0; /* not a MacOS disk */
44748 }
44749 blocks_in_map = be32_to_cpu(part->map_count);
44750+ printk(" [mac]");
44751 if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
44752 put_dev_sector(sect);
44753 return 0;
44754 }
44755- printk(" [mac]");
44756 for (slot = 1; slot <= blocks_in_map; ++slot) {
44757 int pos = slot * secsize;
44758 put_dev_sector(sect);
44759diff -urNp linux-2.6.32.43/fs/pipe.c linux-2.6.32.43/fs/pipe.c
44760--- linux-2.6.32.43/fs/pipe.c 2011-03-27 14:31:47.000000000 -0400
44761+++ linux-2.6.32.43/fs/pipe.c 2011-04-23 13:37:17.000000000 -0400
44762@@ -401,9 +401,9 @@ redo:
44763 }
44764 if (bufs) /* More to do? */
44765 continue;
44766- if (!pipe->writers)
44767+ if (!atomic_read(&pipe->writers))
44768 break;
44769- if (!pipe->waiting_writers) {
44770+ if (!atomic_read(&pipe->waiting_writers)) {
44771 /* syscall merging: Usually we must not sleep
44772 * if O_NONBLOCK is set, or if we got some data.
44773 * But if a writer sleeps in kernel space, then
44774@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const str
44775 mutex_lock(&inode->i_mutex);
44776 pipe = inode->i_pipe;
44777
44778- if (!pipe->readers) {
44779+ if (!atomic_read(&pipe->readers)) {
44780 send_sig(SIGPIPE, current, 0);
44781 ret = -EPIPE;
44782 goto out;
44783@@ -511,7 +511,7 @@ redo1:
44784 for (;;) {
44785 int bufs;
44786
44787- if (!pipe->readers) {
44788+ if (!atomic_read(&pipe->readers)) {
44789 send_sig(SIGPIPE, current, 0);
44790 if (!ret)
44791 ret = -EPIPE;
44792@@ -597,9 +597,9 @@ redo2:
44793 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44794 do_wakeup = 0;
44795 }
44796- pipe->waiting_writers++;
44797+ atomic_inc(&pipe->waiting_writers);
44798 pipe_wait(pipe);
44799- pipe->waiting_writers--;
44800+ atomic_dec(&pipe->waiting_writers);
44801 }
44802 out:
44803 mutex_unlock(&inode->i_mutex);
44804@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table
44805 mask = 0;
44806 if (filp->f_mode & FMODE_READ) {
44807 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
44808- if (!pipe->writers && filp->f_version != pipe->w_counter)
44809+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
44810 mask |= POLLHUP;
44811 }
44812
44813@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table
44814 * Most Unices do not set POLLERR for FIFOs but on Linux they
44815 * behave exactly like pipes for poll().
44816 */
44817- if (!pipe->readers)
44818+ if (!atomic_read(&pipe->readers))
44819 mask |= POLLERR;
44820 }
44821
44822@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int de
44823
44824 mutex_lock(&inode->i_mutex);
44825 pipe = inode->i_pipe;
44826- pipe->readers -= decr;
44827- pipe->writers -= decw;
44828+ atomic_sub(decr, &pipe->readers);
44829+ atomic_sub(decw, &pipe->writers);
44830
44831- if (!pipe->readers && !pipe->writers) {
44832+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
44833 free_pipe_info(inode);
44834 } else {
44835 wake_up_interruptible_sync(&pipe->wait);
44836@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, stru
44837
44838 if (inode->i_pipe) {
44839 ret = 0;
44840- inode->i_pipe->readers++;
44841+ atomic_inc(&inode->i_pipe->readers);
44842 }
44843
44844 mutex_unlock(&inode->i_mutex);
44845@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, str
44846
44847 if (inode->i_pipe) {
44848 ret = 0;
44849- inode->i_pipe->writers++;
44850+ atomic_inc(&inode->i_pipe->writers);
44851 }
44852
44853 mutex_unlock(&inode->i_mutex);
44854@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, stru
44855 if (inode->i_pipe) {
44856 ret = 0;
44857 if (filp->f_mode & FMODE_READ)
44858- inode->i_pipe->readers++;
44859+ atomic_inc(&inode->i_pipe->readers);
44860 if (filp->f_mode & FMODE_WRITE)
44861- inode->i_pipe->writers++;
44862+ atomic_inc(&inode->i_pipe->writers);
44863 }
44864
44865 mutex_unlock(&inode->i_mutex);
44866@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
44867 inode->i_pipe = NULL;
44868 }
44869
44870-static struct vfsmount *pipe_mnt __read_mostly;
44871+struct vfsmount *pipe_mnt __read_mostly;
44872 static int pipefs_delete_dentry(struct dentry *dentry)
44873 {
44874 /*
44875@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(voi
44876 goto fail_iput;
44877 inode->i_pipe = pipe;
44878
44879- pipe->readers = pipe->writers = 1;
44880+ atomic_set(&pipe->readers, 1);
44881+ atomic_set(&pipe->writers, 1);
44882 inode->i_fop = &rdwr_pipefifo_fops;
44883
44884 /*
44885diff -urNp linux-2.6.32.43/fs/proc/array.c linux-2.6.32.43/fs/proc/array.c
44886--- linux-2.6.32.43/fs/proc/array.c 2011-03-27 14:31:47.000000000 -0400
44887+++ linux-2.6.32.43/fs/proc/array.c 2011-05-16 21:46:57.000000000 -0400
44888@@ -60,6 +60,7 @@
44889 #include <linux/tty.h>
44890 #include <linux/string.h>
44891 #include <linux/mman.h>
44892+#include <linux/grsecurity.h>
44893 #include <linux/proc_fs.h>
44894 #include <linux/ioport.h>
44895 #include <linux/uaccess.h>
44896@@ -321,6 +322,21 @@ static inline void task_context_switch_c
44897 p->nivcsw);
44898 }
44899
44900+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44901+static inline void task_pax(struct seq_file *m, struct task_struct *p)
44902+{
44903+ if (p->mm)
44904+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
44905+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
44906+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
44907+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
44908+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
44909+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
44910+ else
44911+ seq_printf(m, "PaX:\t-----\n");
44912+}
44913+#endif
44914+
44915 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
44916 struct pid *pid, struct task_struct *task)
44917 {
44918@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m,
44919 task_cap(m, task);
44920 cpuset_task_status_allowed(m, task);
44921 task_context_switch_counts(m, task);
44922+
44923+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44924+ task_pax(m, task);
44925+#endif
44926+
44927+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
44928+ task_grsec_rbac(m, task);
44929+#endif
44930+
44931 return 0;
44932 }
44933
44934+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44935+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
44936+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
44937+ _mm->pax_flags & MF_PAX_SEGMEXEC))
44938+#endif
44939+
44940 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
44941 struct pid *pid, struct task_struct *task, int whole)
44942 {
44943@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file
44944 cputime_t cutime, cstime, utime, stime;
44945 cputime_t cgtime, gtime;
44946 unsigned long rsslim = 0;
44947- char tcomm[sizeof(task->comm)];
44948+ char tcomm[sizeof(task->comm)] = { 0 };
44949 unsigned long flags;
44950
44951+ pax_track_stack();
44952+
44953 state = *get_task_state(task);
44954 vsize = eip = esp = 0;
44955 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
44956@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file
44957 gtime = task_gtime(task);
44958 }
44959
44960+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44961+ if (PAX_RAND_FLAGS(mm)) {
44962+ eip = 0;
44963+ esp = 0;
44964+ wchan = 0;
44965+ }
44966+#endif
44967+#ifdef CONFIG_GRKERNSEC_HIDESYM
44968+ wchan = 0;
44969+ eip =0;
44970+ esp =0;
44971+#endif
44972+
44973 /* scale priority and nice values from timeslices to -20..20 */
44974 /* to make it look like a "normal" Unix priority/nice value */
44975 priority = task_prio(task);
44976@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file
44977 vsize,
44978 mm ? get_mm_rss(mm) : 0,
44979 rsslim,
44980+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44981+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
44982+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
44983+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
44984+#else
44985 mm ? (permitted ? mm->start_code : 1) : 0,
44986 mm ? (permitted ? mm->end_code : 1) : 0,
44987 (permitted && mm) ? mm->start_stack : 0,
44988+#endif
44989 esp,
44990 eip,
44991 /* The signal information here is obsolete.
44992@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, s
44993
44994 return 0;
44995 }
44996+
44997+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
44998+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
44999+{
45000+ u32 curr_ip = 0;
45001+ unsigned long flags;
45002+
45003+ if (lock_task_sighand(task, &flags)) {
45004+ curr_ip = task->signal->curr_ip;
45005+ unlock_task_sighand(task, &flags);
45006+ }
45007+
45008+ return sprintf(buffer, "%pI4\n", &curr_ip);
45009+}
45010+#endif
45011diff -urNp linux-2.6.32.43/fs/proc/base.c linux-2.6.32.43/fs/proc/base.c
45012--- linux-2.6.32.43/fs/proc/base.c 2011-04-22 19:16:29.000000000 -0400
45013+++ linux-2.6.32.43/fs/proc/base.c 2011-06-04 21:20:50.000000000 -0400
45014@@ -102,6 +102,22 @@ struct pid_entry {
45015 union proc_op op;
45016 };
45017
45018+struct getdents_callback {
45019+ struct linux_dirent __user * current_dir;
45020+ struct linux_dirent __user * previous;
45021+ struct file * file;
45022+ int count;
45023+ int error;
45024+};
45025+
45026+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
45027+ loff_t offset, u64 ino, unsigned int d_type)
45028+{
45029+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
45030+ buf->error = -EINVAL;
45031+ return 0;
45032+}
45033+
45034 #define NOD(NAME, MODE, IOP, FOP, OP) { \
45035 .name = (NAME), \
45036 .len = sizeof(NAME) - 1, \
45037@@ -213,6 +229,9 @@ static int check_mem_permission(struct t
45038 if (task == current)
45039 return 0;
45040
45041+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
45042+ return -EPERM;
45043+
45044 /*
45045 * If current is actively ptrace'ing, and would also be
45046 * permitted to freshly attach with ptrace now, permit it.
45047@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_
45048 if (!mm->arg_end)
45049 goto out_mm; /* Shh! No looking before we're done */
45050
45051+ if (gr_acl_handle_procpidmem(task))
45052+ goto out_mm;
45053+
45054 len = mm->arg_end - mm->arg_start;
45055
45056 if (len > PAGE_SIZE)
45057@@ -287,12 +309,28 @@ out:
45058 return res;
45059 }
45060
45061+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45062+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45063+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
45064+ _mm->pax_flags & MF_PAX_SEGMEXEC))
45065+#endif
45066+
45067 static int proc_pid_auxv(struct task_struct *task, char *buffer)
45068 {
45069 int res = 0;
45070 struct mm_struct *mm = get_task_mm(task);
45071 if (mm) {
45072 unsigned int nwords = 0;
45073+
45074+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45075+ /* allow if we're currently ptracing this task */
45076+ if (PAX_RAND_FLAGS(mm) &&
45077+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
45078+ mmput(mm);
45079+ return res;
45080+ }
45081+#endif
45082+
45083 do {
45084 nwords += 2;
45085 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
45086@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_str
45087 }
45088
45089
45090-#ifdef CONFIG_KALLSYMS
45091+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45092 /*
45093 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
45094 * Returns the resolved symbol. If that fails, simply return the address.
45095@@ -328,7 +366,7 @@ static int proc_pid_wchan(struct task_st
45096 }
45097 #endif /* CONFIG_KALLSYMS */
45098
45099-#ifdef CONFIG_STACKTRACE
45100+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45101
45102 #define MAX_STACK_TRACE_DEPTH 64
45103
45104@@ -522,7 +560,7 @@ static int proc_pid_limits(struct task_s
45105 return count;
45106 }
45107
45108-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45109+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45110 static int proc_pid_syscall(struct task_struct *task, char *buffer)
45111 {
45112 long nr;
45113@@ -547,7 +585,7 @@ static int proc_pid_syscall(struct task_
45114 /************************************************************************/
45115
45116 /* permission checks */
45117-static int proc_fd_access_allowed(struct inode *inode)
45118+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
45119 {
45120 struct task_struct *task;
45121 int allowed = 0;
45122@@ -557,7 +595,10 @@ static int proc_fd_access_allowed(struct
45123 */
45124 task = get_proc_task(inode);
45125 if (task) {
45126- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45127+ if (log)
45128+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
45129+ else
45130+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45131 put_task_struct(task);
45132 }
45133 return allowed;
45134@@ -936,6 +977,9 @@ static ssize_t environ_read(struct file
45135 if (!task)
45136 goto out_no_task;
45137
45138+ if (gr_acl_handle_procpidmem(task))
45139+ goto out;
45140+
45141 if (!ptrace_may_access(task, PTRACE_MODE_READ))
45142 goto out;
45143
45144@@ -1350,7 +1394,7 @@ static void *proc_pid_follow_link(struct
45145 path_put(&nd->path);
45146
45147 /* Are we allowed to snoop on the tasks file descriptors? */
45148- if (!proc_fd_access_allowed(inode))
45149+ if (!proc_fd_access_allowed(inode,0))
45150 goto out;
45151
45152 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
45153@@ -1390,8 +1434,18 @@ static int proc_pid_readlink(struct dent
45154 struct path path;
45155
45156 /* Are we allowed to snoop on the tasks file descriptors? */
45157- if (!proc_fd_access_allowed(inode))
45158- goto out;
45159+ /* logging this is needed for learning on chromium to work properly,
45160+ but we don't want to flood the logs from 'ps' which does a readlink
45161+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
45162+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
45163+ */
45164+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
45165+ if (!proc_fd_access_allowed(inode,0))
45166+ goto out;
45167+ } else {
45168+ if (!proc_fd_access_allowed(inode,1))
45169+ goto out;
45170+ }
45171
45172 error = PROC_I(inode)->op.proc_get_link(inode, &path);
45173 if (error)
45174@@ -1456,7 +1510,11 @@ static struct inode *proc_pid_make_inode
45175 rcu_read_lock();
45176 cred = __task_cred(task);
45177 inode->i_uid = cred->euid;
45178+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45179+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45180+#else
45181 inode->i_gid = cred->egid;
45182+#endif
45183 rcu_read_unlock();
45184 }
45185 security_task_to_inode(task, inode);
45186@@ -1474,6 +1532,9 @@ static int pid_getattr(struct vfsmount *
45187 struct inode *inode = dentry->d_inode;
45188 struct task_struct *task;
45189 const struct cred *cred;
45190+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45191+ const struct cred *tmpcred = current_cred();
45192+#endif
45193
45194 generic_fillattr(inode, stat);
45195
45196@@ -1481,13 +1542,41 @@ static int pid_getattr(struct vfsmount *
45197 stat->uid = 0;
45198 stat->gid = 0;
45199 task = pid_task(proc_pid(inode), PIDTYPE_PID);
45200+
45201+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
45202+ rcu_read_unlock();
45203+ return -ENOENT;
45204+ }
45205+
45206 if (task) {
45207+ cred = __task_cred(task);
45208+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45209+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
45210+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45211+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45212+#endif
45213+ ) {
45214+#endif
45215 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45216+#ifdef CONFIG_GRKERNSEC_PROC_USER
45217+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45218+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45219+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45220+#endif
45221 task_dumpable(task)) {
45222- cred = __task_cred(task);
45223 stat->uid = cred->euid;
45224+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45225+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
45226+#else
45227 stat->gid = cred->egid;
45228+#endif
45229 }
45230+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45231+ } else {
45232+ rcu_read_unlock();
45233+ return -ENOENT;
45234+ }
45235+#endif
45236 }
45237 rcu_read_unlock();
45238 return 0;
45239@@ -1518,11 +1607,20 @@ static int pid_revalidate(struct dentry
45240
45241 if (task) {
45242 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45243+#ifdef CONFIG_GRKERNSEC_PROC_USER
45244+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45245+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45246+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45247+#endif
45248 task_dumpable(task)) {
45249 rcu_read_lock();
45250 cred = __task_cred(task);
45251 inode->i_uid = cred->euid;
45252+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45253+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45254+#else
45255 inode->i_gid = cred->egid;
45256+#endif
45257 rcu_read_unlock();
45258 } else {
45259 inode->i_uid = 0;
45260@@ -1643,7 +1741,8 @@ static int proc_fd_info(struct inode *in
45261 int fd = proc_fd(inode);
45262
45263 if (task) {
45264- files = get_files_struct(task);
45265+ if (!gr_acl_handle_procpidmem(task))
45266+ files = get_files_struct(task);
45267 put_task_struct(task);
45268 }
45269 if (files) {
45270@@ -1895,12 +1994,22 @@ static const struct file_operations proc
45271 static int proc_fd_permission(struct inode *inode, int mask)
45272 {
45273 int rv;
45274+ struct task_struct *task;
45275
45276 rv = generic_permission(inode, mask, NULL);
45277- if (rv == 0)
45278- return 0;
45279+
45280 if (task_pid(current) == proc_pid(inode))
45281 rv = 0;
45282+
45283+ task = get_proc_task(inode);
45284+ if (task == NULL)
45285+ return rv;
45286+
45287+ if (gr_acl_handle_procpidmem(task))
45288+ rv = -EACCES;
45289+
45290+ put_task_struct(task);
45291+
45292 return rv;
45293 }
45294
45295@@ -2009,6 +2118,9 @@ static struct dentry *proc_pident_lookup
45296 if (!task)
45297 goto out_no_task;
45298
45299+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45300+ goto out;
45301+
45302 /*
45303 * Yes, it does not scale. And it should not. Don't add
45304 * new entries into /proc/<tgid>/ without very good reasons.
45305@@ -2053,6 +2165,9 @@ static int proc_pident_readdir(struct fi
45306 if (!task)
45307 goto out_no_task;
45308
45309+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45310+ goto out;
45311+
45312 ret = 0;
45313 i = filp->f_pos;
45314 switch (i) {
45315@@ -2320,7 +2435,7 @@ static void *proc_self_follow_link(struc
45316 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
45317 void *cookie)
45318 {
45319- char *s = nd_get_link(nd);
45320+ const char *s = nd_get_link(nd);
45321 if (!IS_ERR(s))
45322 __putname(s);
45323 }
45324@@ -2519,7 +2634,7 @@ static const struct pid_entry tgid_base_
45325 #ifdef CONFIG_SCHED_DEBUG
45326 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
45327 #endif
45328-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45329+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45330 INF("syscall", S_IRUSR, proc_pid_syscall),
45331 #endif
45332 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45333@@ -2544,10 +2659,10 @@ static const struct pid_entry tgid_base_
45334 #ifdef CONFIG_SECURITY
45335 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45336 #endif
45337-#ifdef CONFIG_KALLSYMS
45338+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45339 INF("wchan", S_IRUGO, proc_pid_wchan),
45340 #endif
45341-#ifdef CONFIG_STACKTRACE
45342+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45343 ONE("stack", S_IRUSR, proc_pid_stack),
45344 #endif
45345 #ifdef CONFIG_SCHEDSTATS
45346@@ -2577,6 +2692,9 @@ static const struct pid_entry tgid_base_
45347 #ifdef CONFIG_TASK_IO_ACCOUNTING
45348 INF("io", S_IRUGO, proc_tgid_io_accounting),
45349 #endif
45350+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45351+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
45352+#endif
45353 };
45354
45355 static int proc_tgid_base_readdir(struct file * filp,
45356@@ -2701,7 +2819,14 @@ static struct dentry *proc_pid_instantia
45357 if (!inode)
45358 goto out;
45359
45360+#ifdef CONFIG_GRKERNSEC_PROC_USER
45361+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
45362+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45363+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45364+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
45365+#else
45366 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
45367+#endif
45368 inode->i_op = &proc_tgid_base_inode_operations;
45369 inode->i_fop = &proc_tgid_base_operations;
45370 inode->i_flags|=S_IMMUTABLE;
45371@@ -2743,7 +2868,11 @@ struct dentry *proc_pid_lookup(struct in
45372 if (!task)
45373 goto out;
45374
45375+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45376+ goto out_put_task;
45377+
45378 result = proc_pid_instantiate(dir, dentry, task, NULL);
45379+out_put_task:
45380 put_task_struct(task);
45381 out:
45382 return result;
45383@@ -2808,6 +2937,11 @@ int proc_pid_readdir(struct file * filp,
45384 {
45385 unsigned int nr;
45386 struct task_struct *reaper;
45387+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45388+ const struct cred *tmpcred = current_cred();
45389+ const struct cred *itercred;
45390+#endif
45391+ filldir_t __filldir = filldir;
45392 struct tgid_iter iter;
45393 struct pid_namespace *ns;
45394
45395@@ -2831,8 +2965,27 @@ int proc_pid_readdir(struct file * filp,
45396 for (iter = next_tgid(ns, iter);
45397 iter.task;
45398 iter.tgid += 1, iter = next_tgid(ns, iter)) {
45399+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45400+ rcu_read_lock();
45401+ itercred = __task_cred(iter.task);
45402+#endif
45403+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
45404+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45405+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
45406+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45407+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45408+#endif
45409+ )
45410+#endif
45411+ )
45412+ __filldir = &gr_fake_filldir;
45413+ else
45414+ __filldir = filldir;
45415+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45416+ rcu_read_unlock();
45417+#endif
45418 filp->f_pos = iter.tgid + TGID_OFFSET;
45419- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
45420+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
45421 put_task_struct(iter.task);
45422 goto out;
45423 }
45424@@ -2858,7 +3011,7 @@ static const struct pid_entry tid_base_s
45425 #ifdef CONFIG_SCHED_DEBUG
45426 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
45427 #endif
45428-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45429+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45430 INF("syscall", S_IRUSR, proc_pid_syscall),
45431 #endif
45432 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45433@@ -2882,10 +3035,10 @@ static const struct pid_entry tid_base_s
45434 #ifdef CONFIG_SECURITY
45435 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45436 #endif
45437-#ifdef CONFIG_KALLSYMS
45438+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45439 INF("wchan", S_IRUGO, proc_pid_wchan),
45440 #endif
45441-#ifdef CONFIG_STACKTRACE
45442+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45443 ONE("stack", S_IRUSR, proc_pid_stack),
45444 #endif
45445 #ifdef CONFIG_SCHEDSTATS
45446diff -urNp linux-2.6.32.43/fs/proc/cmdline.c linux-2.6.32.43/fs/proc/cmdline.c
45447--- linux-2.6.32.43/fs/proc/cmdline.c 2011-03-27 14:31:47.000000000 -0400
45448+++ linux-2.6.32.43/fs/proc/cmdline.c 2011-04-17 15:56:46.000000000 -0400
45449@@ -23,7 +23,11 @@ static const struct file_operations cmdl
45450
45451 static int __init proc_cmdline_init(void)
45452 {
45453+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45454+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
45455+#else
45456 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
45457+#endif
45458 return 0;
45459 }
45460 module_init(proc_cmdline_init);
45461diff -urNp linux-2.6.32.43/fs/proc/devices.c linux-2.6.32.43/fs/proc/devices.c
45462--- linux-2.6.32.43/fs/proc/devices.c 2011-03-27 14:31:47.000000000 -0400
45463+++ linux-2.6.32.43/fs/proc/devices.c 2011-04-17 15:56:46.000000000 -0400
45464@@ -64,7 +64,11 @@ static const struct file_operations proc
45465
45466 static int __init proc_devices_init(void)
45467 {
45468+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45469+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
45470+#else
45471 proc_create("devices", 0, NULL, &proc_devinfo_operations);
45472+#endif
45473 return 0;
45474 }
45475 module_init(proc_devices_init);
45476diff -urNp linux-2.6.32.43/fs/proc/inode.c linux-2.6.32.43/fs/proc/inode.c
45477--- linux-2.6.32.43/fs/proc/inode.c 2011-03-27 14:31:47.000000000 -0400
45478+++ linux-2.6.32.43/fs/proc/inode.c 2011-04-17 15:56:46.000000000 -0400
45479@@ -457,7 +457,11 @@ struct inode *proc_get_inode(struct supe
45480 if (de->mode) {
45481 inode->i_mode = de->mode;
45482 inode->i_uid = de->uid;
45483+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45484+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45485+#else
45486 inode->i_gid = de->gid;
45487+#endif
45488 }
45489 if (de->size)
45490 inode->i_size = de->size;
45491diff -urNp linux-2.6.32.43/fs/proc/internal.h linux-2.6.32.43/fs/proc/internal.h
45492--- linux-2.6.32.43/fs/proc/internal.h 2011-03-27 14:31:47.000000000 -0400
45493+++ linux-2.6.32.43/fs/proc/internal.h 2011-04-17 15:56:46.000000000 -0400
45494@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
45495 struct pid *pid, struct task_struct *task);
45496 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45497 struct pid *pid, struct task_struct *task);
45498+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45499+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
45500+#endif
45501 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
45502
45503 extern const struct file_operations proc_maps_operations;
45504diff -urNp linux-2.6.32.43/fs/proc/Kconfig linux-2.6.32.43/fs/proc/Kconfig
45505--- linux-2.6.32.43/fs/proc/Kconfig 2011-03-27 14:31:47.000000000 -0400
45506+++ linux-2.6.32.43/fs/proc/Kconfig 2011-04-17 15:56:46.000000000 -0400
45507@@ -30,12 +30,12 @@ config PROC_FS
45508
45509 config PROC_KCORE
45510 bool "/proc/kcore support" if !ARM
45511- depends on PROC_FS && MMU
45512+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
45513
45514 config PROC_VMCORE
45515 bool "/proc/vmcore support (EXPERIMENTAL)"
45516- depends on PROC_FS && CRASH_DUMP
45517- default y
45518+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
45519+ default n
45520 help
45521 Exports the dump image of crashed kernel in ELF format.
45522
45523@@ -59,8 +59,8 @@ config PROC_SYSCTL
45524 limited in memory.
45525
45526 config PROC_PAGE_MONITOR
45527- default y
45528- depends on PROC_FS && MMU
45529+ default n
45530+ depends on PROC_FS && MMU && !GRKERNSEC
45531 bool "Enable /proc page monitoring" if EMBEDDED
45532 help
45533 Various /proc files exist to monitor process memory utilization:
45534diff -urNp linux-2.6.32.43/fs/proc/kcore.c linux-2.6.32.43/fs/proc/kcore.c
45535--- linux-2.6.32.43/fs/proc/kcore.c 2011-03-27 14:31:47.000000000 -0400
45536+++ linux-2.6.32.43/fs/proc/kcore.c 2011-05-16 21:46:57.000000000 -0400
45537@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bu
45538 off_t offset = 0;
45539 struct kcore_list *m;
45540
45541+ pax_track_stack();
45542+
45543 /* setup ELF header */
45544 elf = (struct elfhdr *) bufp;
45545 bufp += sizeof(struct elfhdr);
45546@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __use
45547 * the addresses in the elf_phdr on our list.
45548 */
45549 start = kc_offset_to_vaddr(*fpos - elf_buflen);
45550- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
45551+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
45552+ if (tsz > buflen)
45553 tsz = buflen;
45554-
45555+
45556 while (buflen) {
45557 struct kcore_list *m;
45558
45559@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __use
45560 kfree(elf_buf);
45561 } else {
45562 if (kern_addr_valid(start)) {
45563- unsigned long n;
45564+ char *elf_buf;
45565+ mm_segment_t oldfs;
45566
45567- n = copy_to_user(buffer, (char *)start, tsz);
45568- /*
45569- * We cannot distingush between fault on source
45570- * and fault on destination. When this happens
45571- * we clear too and hope it will trigger the
45572- * EFAULT again.
45573- */
45574- if (n) {
45575- if (clear_user(buffer + tsz - n,
45576- n))
45577+ elf_buf = kmalloc(tsz, GFP_KERNEL);
45578+ if (!elf_buf)
45579+ return -ENOMEM;
45580+ oldfs = get_fs();
45581+ set_fs(KERNEL_DS);
45582+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
45583+ set_fs(oldfs);
45584+ if (copy_to_user(buffer, elf_buf, tsz)) {
45585+ kfree(elf_buf);
45586 return -EFAULT;
45587+ }
45588 }
45589+ set_fs(oldfs);
45590+ kfree(elf_buf);
45591 } else {
45592 if (clear_user(buffer, tsz))
45593 return -EFAULT;
45594@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __use
45595
45596 static int open_kcore(struct inode *inode, struct file *filp)
45597 {
45598+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
45599+ return -EPERM;
45600+#endif
45601 if (!capable(CAP_SYS_RAWIO))
45602 return -EPERM;
45603 if (kcore_need_update)
45604diff -urNp linux-2.6.32.43/fs/proc/meminfo.c linux-2.6.32.43/fs/proc/meminfo.c
45605--- linux-2.6.32.43/fs/proc/meminfo.c 2011-03-27 14:31:47.000000000 -0400
45606+++ linux-2.6.32.43/fs/proc/meminfo.c 2011-05-16 21:46:57.000000000 -0400
45607@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
45608 unsigned long pages[NR_LRU_LISTS];
45609 int lru;
45610
45611+ pax_track_stack();
45612+
45613 /*
45614 * display in kilobytes.
45615 */
45616@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_
45617 vmi.used >> 10,
45618 vmi.largest_chunk >> 10
45619 #ifdef CONFIG_MEMORY_FAILURE
45620- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
45621+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
45622 #endif
45623 );
45624
45625diff -urNp linux-2.6.32.43/fs/proc/nommu.c linux-2.6.32.43/fs/proc/nommu.c
45626--- linux-2.6.32.43/fs/proc/nommu.c 2011-03-27 14:31:47.000000000 -0400
45627+++ linux-2.6.32.43/fs/proc/nommu.c 2011-04-17 15:56:46.000000000 -0400
45628@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_
45629 if (len < 1)
45630 len = 1;
45631 seq_printf(m, "%*c", len, ' ');
45632- seq_path(m, &file->f_path, "");
45633+ seq_path(m, &file->f_path, "\n\\");
45634 }
45635
45636 seq_putc(m, '\n');
45637diff -urNp linux-2.6.32.43/fs/proc/proc_net.c linux-2.6.32.43/fs/proc/proc_net.c
45638--- linux-2.6.32.43/fs/proc/proc_net.c 2011-03-27 14:31:47.000000000 -0400
45639+++ linux-2.6.32.43/fs/proc/proc_net.c 2011-04-17 15:56:46.000000000 -0400
45640@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(str
45641 struct task_struct *task;
45642 struct nsproxy *ns;
45643 struct net *net = NULL;
45644+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45645+ const struct cred *cred = current_cred();
45646+#endif
45647+
45648+#ifdef CONFIG_GRKERNSEC_PROC_USER
45649+ if (cred->fsuid)
45650+ return net;
45651+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45652+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
45653+ return net;
45654+#endif
45655
45656 rcu_read_lock();
45657 task = pid_task(proc_pid(dir), PIDTYPE_PID);
45658diff -urNp linux-2.6.32.43/fs/proc/proc_sysctl.c linux-2.6.32.43/fs/proc/proc_sysctl.c
45659--- linux-2.6.32.43/fs/proc/proc_sysctl.c 2011-03-27 14:31:47.000000000 -0400
45660+++ linux-2.6.32.43/fs/proc/proc_sysctl.c 2011-04-17 15:56:46.000000000 -0400
45661@@ -7,6 +7,8 @@
45662 #include <linux/security.h>
45663 #include "internal.h"
45664
45665+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
45666+
45667 static const struct dentry_operations proc_sys_dentry_operations;
45668 static const struct file_operations proc_sys_file_operations;
45669 static const struct inode_operations proc_sys_inode_operations;
45670@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(st
45671 if (!p)
45672 goto out;
45673
45674+ if (gr_handle_sysctl(p, MAY_EXEC))
45675+ goto out;
45676+
45677 err = ERR_PTR(-ENOMEM);
45678 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
45679 if (h)
45680@@ -228,6 +233,9 @@ static int scan(struct ctl_table_header
45681 if (*pos < file->f_pos)
45682 continue;
45683
45684+ if (gr_handle_sysctl(table, 0))
45685+ continue;
45686+
45687 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
45688 if (res)
45689 return res;
45690@@ -344,6 +352,9 @@ static int proc_sys_getattr(struct vfsmo
45691 if (IS_ERR(head))
45692 return PTR_ERR(head);
45693
45694+ if (table && gr_handle_sysctl(table, MAY_EXEC))
45695+ return -ENOENT;
45696+
45697 generic_fillattr(inode, stat);
45698 if (table)
45699 stat->mode = (stat->mode & S_IFMT) | table->mode;
45700diff -urNp linux-2.6.32.43/fs/proc/root.c linux-2.6.32.43/fs/proc/root.c
45701--- linux-2.6.32.43/fs/proc/root.c 2011-03-27 14:31:47.000000000 -0400
45702+++ linux-2.6.32.43/fs/proc/root.c 2011-04-17 15:56:46.000000000 -0400
45703@@ -134,7 +134,15 @@ void __init proc_root_init(void)
45704 #ifdef CONFIG_PROC_DEVICETREE
45705 proc_device_tree_init();
45706 #endif
45707+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45708+#ifdef CONFIG_GRKERNSEC_PROC_USER
45709+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
45710+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45711+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45712+#endif
45713+#else
45714 proc_mkdir("bus", NULL);
45715+#endif
45716 proc_sys_init();
45717 }
45718
45719diff -urNp linux-2.6.32.43/fs/proc/task_mmu.c linux-2.6.32.43/fs/proc/task_mmu.c
45720--- linux-2.6.32.43/fs/proc/task_mmu.c 2011-03-27 14:31:47.000000000 -0400
45721+++ linux-2.6.32.43/fs/proc/task_mmu.c 2011-04-23 13:38:09.000000000 -0400
45722@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
45723 "VmStk:\t%8lu kB\n"
45724 "VmExe:\t%8lu kB\n"
45725 "VmLib:\t%8lu kB\n"
45726- "VmPTE:\t%8lu kB\n",
45727- hiwater_vm << (PAGE_SHIFT-10),
45728+ "VmPTE:\t%8lu kB\n"
45729+
45730+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45731+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
45732+#endif
45733+
45734+ ,hiwater_vm << (PAGE_SHIFT-10),
45735 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
45736 mm->locked_vm << (PAGE_SHIFT-10),
45737 hiwater_rss << (PAGE_SHIFT-10),
45738 total_rss << (PAGE_SHIFT-10),
45739 data << (PAGE_SHIFT-10),
45740 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
45741- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
45742+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
45743+
45744+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45745+ , mm->context.user_cs_base, mm->context.user_cs_limit
45746+#endif
45747+
45748+ );
45749 }
45750
45751 unsigned long task_vsize(struct mm_struct *mm)
45752@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, v
45753 struct proc_maps_private *priv = m->private;
45754 struct vm_area_struct *vma = v;
45755
45756- vma_stop(priv, vma);
45757+ if (!IS_ERR(vma))
45758+ vma_stop(priv, vma);
45759 if (priv->task)
45760 put_task_struct(priv->task);
45761 }
45762@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *in
45763 return ret;
45764 }
45765
45766+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45767+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45768+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
45769+ _mm->pax_flags & MF_PAX_SEGMEXEC))
45770+#endif
45771+
45772 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
45773 {
45774 struct mm_struct *mm = vma->vm_mm;
45775@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file
45776 int flags = vma->vm_flags;
45777 unsigned long ino = 0;
45778 unsigned long long pgoff = 0;
45779- unsigned long start;
45780 dev_t dev = 0;
45781 int len;
45782
45783@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file
45784 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
45785 }
45786
45787- /* We don't show the stack guard page in /proc/maps */
45788- start = vma->vm_start;
45789- if (vma->vm_flags & VM_GROWSDOWN)
45790- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
45791- start += PAGE_SIZE;
45792-
45793 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
45794- start,
45795+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45796+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
45797+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
45798+#else
45799+ vma->vm_start,
45800 vma->vm_end,
45801+#endif
45802 flags & VM_READ ? 'r' : '-',
45803 flags & VM_WRITE ? 'w' : '-',
45804 flags & VM_EXEC ? 'x' : '-',
45805 flags & VM_MAYSHARE ? 's' : 'p',
45806+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45807+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
45808+#else
45809 pgoff,
45810+#endif
45811 MAJOR(dev), MINOR(dev), ino, &len);
45812
45813 /*
45814@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file
45815 */
45816 if (file) {
45817 pad_len_spaces(m, len);
45818- seq_path(m, &file->f_path, "\n");
45819+ seq_path(m, &file->f_path, "\n\\");
45820 } else {
45821 const char *name = arch_vma_name(vma);
45822 if (!name) {
45823@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file
45824 if (vma->vm_start <= mm->brk &&
45825 vma->vm_end >= mm->start_brk) {
45826 name = "[heap]";
45827- } else if (vma->vm_start <= mm->start_stack &&
45828- vma->vm_end >= mm->start_stack) {
45829+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
45830+ (vma->vm_start <= mm->start_stack &&
45831+ vma->vm_end >= mm->start_stack)) {
45832 name = "[stack]";
45833 }
45834 } else {
45835@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m,
45836 };
45837
45838 memset(&mss, 0, sizeof mss);
45839- mss.vma = vma;
45840- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
45841- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
45842+
45843+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45844+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
45845+#endif
45846+ mss.vma = vma;
45847+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
45848+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
45849+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45850+ }
45851+#endif
45852
45853 show_map_vma(m, vma);
45854
45855@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m,
45856 "Swap: %8lu kB\n"
45857 "KernelPageSize: %8lu kB\n"
45858 "MMUPageSize: %8lu kB\n",
45859+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45860+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
45861+#else
45862 (vma->vm_end - vma->vm_start) >> 10,
45863+#endif
45864 mss.resident >> 10,
45865 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
45866 mss.shared_clean >> 10,
45867diff -urNp linux-2.6.32.43/fs/proc/task_nommu.c linux-2.6.32.43/fs/proc/task_nommu.c
45868--- linux-2.6.32.43/fs/proc/task_nommu.c 2011-03-27 14:31:47.000000000 -0400
45869+++ linux-2.6.32.43/fs/proc/task_nommu.c 2011-04-17 15:56:46.000000000 -0400
45870@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct
45871 else
45872 bytes += kobjsize(mm);
45873
45874- if (current->fs && current->fs->users > 1)
45875+ if (current->fs && atomic_read(&current->fs->users) > 1)
45876 sbytes += kobjsize(current->fs);
45877 else
45878 bytes += kobjsize(current->fs);
45879@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_fil
45880 if (len < 1)
45881 len = 1;
45882 seq_printf(m, "%*c", len, ' ');
45883- seq_path(m, &file->f_path, "");
45884+ seq_path(m, &file->f_path, "\n\\");
45885 }
45886
45887 seq_putc(m, '\n');
45888diff -urNp linux-2.6.32.43/fs/readdir.c linux-2.6.32.43/fs/readdir.c
45889--- linux-2.6.32.43/fs/readdir.c 2011-03-27 14:31:47.000000000 -0400
45890+++ linux-2.6.32.43/fs/readdir.c 2011-04-17 15:56:46.000000000 -0400
45891@@ -16,6 +16,7 @@
45892 #include <linux/security.h>
45893 #include <linux/syscalls.h>
45894 #include <linux/unistd.h>
45895+#include <linux/namei.h>
45896
45897 #include <asm/uaccess.h>
45898
45899@@ -67,6 +68,7 @@ struct old_linux_dirent {
45900
45901 struct readdir_callback {
45902 struct old_linux_dirent __user * dirent;
45903+ struct file * file;
45904 int result;
45905 };
45906
45907@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
45908 buf->result = -EOVERFLOW;
45909 return -EOVERFLOW;
45910 }
45911+
45912+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45913+ return 0;
45914+
45915 buf->result++;
45916 dirent = buf->dirent;
45917 if (!access_ok(VERIFY_WRITE, dirent,
45918@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
45919
45920 buf.result = 0;
45921 buf.dirent = dirent;
45922+ buf.file = file;
45923
45924 error = vfs_readdir(file, fillonedir, &buf);
45925 if (buf.result)
45926@@ -142,6 +149,7 @@ struct linux_dirent {
45927 struct getdents_callback {
45928 struct linux_dirent __user * current_dir;
45929 struct linux_dirent __user * previous;
45930+ struct file * file;
45931 int count;
45932 int error;
45933 };
45934@@ -162,6 +170,10 @@ static int filldir(void * __buf, const c
45935 buf->error = -EOVERFLOW;
45936 return -EOVERFLOW;
45937 }
45938+
45939+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45940+ return 0;
45941+
45942 dirent = buf->previous;
45943 if (dirent) {
45944 if (__put_user(offset, &dirent->d_off))
45945@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
45946 buf.previous = NULL;
45947 buf.count = count;
45948 buf.error = 0;
45949+ buf.file = file;
45950
45951 error = vfs_readdir(file, filldir, &buf);
45952 if (error >= 0)
45953@@ -228,6 +241,7 @@ out:
45954 struct getdents_callback64 {
45955 struct linux_dirent64 __user * current_dir;
45956 struct linux_dirent64 __user * previous;
45957+ struct file *file;
45958 int count;
45959 int error;
45960 };
45961@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const
45962 buf->error = -EINVAL; /* only used if we fail.. */
45963 if (reclen > buf->count)
45964 return -EINVAL;
45965+
45966+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45967+ return 0;
45968+
45969 dirent = buf->previous;
45970 if (dirent) {
45971 if (__put_user(offset, &dirent->d_off))
45972@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
45973
45974 buf.current_dir = dirent;
45975 buf.previous = NULL;
45976+ buf.file = file;
45977 buf.count = count;
45978 buf.error = 0;
45979
45980diff -urNp linux-2.6.32.43/fs/reiserfs/dir.c linux-2.6.32.43/fs/reiserfs/dir.c
45981--- linux-2.6.32.43/fs/reiserfs/dir.c 2011-03-27 14:31:47.000000000 -0400
45982+++ linux-2.6.32.43/fs/reiserfs/dir.c 2011-05-16 21:46:57.000000000 -0400
45983@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
45984 struct reiserfs_dir_entry de;
45985 int ret = 0;
45986
45987+ pax_track_stack();
45988+
45989 reiserfs_write_lock(inode->i_sb);
45990
45991 reiserfs_check_lock_depth(inode->i_sb, "readdir");
45992diff -urNp linux-2.6.32.43/fs/reiserfs/do_balan.c linux-2.6.32.43/fs/reiserfs/do_balan.c
45993--- linux-2.6.32.43/fs/reiserfs/do_balan.c 2011-03-27 14:31:47.000000000 -0400
45994+++ linux-2.6.32.43/fs/reiserfs/do_balan.c 2011-04-17 15:56:46.000000000 -0400
45995@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb,
45996 return;
45997 }
45998
45999- atomic_inc(&(fs_generation(tb->tb_sb)));
46000+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
46001 do_balance_starts(tb);
46002
46003 /* balance leaf returns 0 except if combining L R and S into
46004diff -urNp linux-2.6.32.43/fs/reiserfs/item_ops.c linux-2.6.32.43/fs/reiserfs/item_ops.c
46005--- linux-2.6.32.43/fs/reiserfs/item_ops.c 2011-03-27 14:31:47.000000000 -0400
46006+++ linux-2.6.32.43/fs/reiserfs/item_ops.c 2011-04-17 15:56:46.000000000 -0400
46007@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
46008 vi->vi_index, vi->vi_type, vi->vi_ih);
46009 }
46010
46011-static struct item_operations stat_data_ops = {
46012+static const struct item_operations stat_data_ops = {
46013 .bytes_number = sd_bytes_number,
46014 .decrement_key = sd_decrement_key,
46015 .is_left_mergeable = sd_is_left_mergeable,
46016@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
46017 vi->vi_index, vi->vi_type, vi->vi_ih);
46018 }
46019
46020-static struct item_operations direct_ops = {
46021+static const struct item_operations direct_ops = {
46022 .bytes_number = direct_bytes_number,
46023 .decrement_key = direct_decrement_key,
46024 .is_left_mergeable = direct_is_left_mergeable,
46025@@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
46026 vi->vi_index, vi->vi_type, vi->vi_ih);
46027 }
46028
46029-static struct item_operations indirect_ops = {
46030+static const struct item_operations indirect_ops = {
46031 .bytes_number = indirect_bytes_number,
46032 .decrement_key = indirect_decrement_key,
46033 .is_left_mergeable = indirect_is_left_mergeable,
46034@@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
46035 printk("\n");
46036 }
46037
46038-static struct item_operations direntry_ops = {
46039+static const struct item_operations direntry_ops = {
46040 .bytes_number = direntry_bytes_number,
46041 .decrement_key = direntry_decrement_key,
46042 .is_left_mergeable = direntry_is_left_mergeable,
46043@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
46044 "Invalid item type observed, run fsck ASAP");
46045 }
46046
46047-static struct item_operations errcatch_ops = {
46048+static const struct item_operations errcatch_ops = {
46049 errcatch_bytes_number,
46050 errcatch_decrement_key,
46051 errcatch_is_left_mergeable,
46052@@ -746,7 +746,7 @@ static struct item_operations errcatch_o
46053 #error Item types must use disk-format assigned values.
46054 #endif
46055
46056-struct item_operations *item_ops[TYPE_ANY + 1] = {
46057+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
46058 &stat_data_ops,
46059 &indirect_ops,
46060 &direct_ops,
46061diff -urNp linux-2.6.32.43/fs/reiserfs/journal.c linux-2.6.32.43/fs/reiserfs/journal.c
46062--- linux-2.6.32.43/fs/reiserfs/journal.c 2011-03-27 14:31:47.000000000 -0400
46063+++ linux-2.6.32.43/fs/reiserfs/journal.c 2011-05-16 21:46:57.000000000 -0400
46064@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_brea
46065 struct buffer_head *bh;
46066 int i, j;
46067
46068+ pax_track_stack();
46069+
46070 bh = __getblk(dev, block, bufsize);
46071 if (buffer_uptodate(bh))
46072 return (bh);
46073diff -urNp linux-2.6.32.43/fs/reiserfs/namei.c linux-2.6.32.43/fs/reiserfs/namei.c
46074--- linux-2.6.32.43/fs/reiserfs/namei.c 2011-03-27 14:31:47.000000000 -0400
46075+++ linux-2.6.32.43/fs/reiserfs/namei.c 2011-05-16 21:46:57.000000000 -0400
46076@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode
46077 unsigned long savelink = 1;
46078 struct timespec ctime;
46079
46080+ pax_track_stack();
46081+
46082 /* three balancings: (1) old name removal, (2) new name insertion
46083 and (3) maybe "save" link insertion
46084 stat data updates: (1) old directory,
46085diff -urNp linux-2.6.32.43/fs/reiserfs/procfs.c linux-2.6.32.43/fs/reiserfs/procfs.c
46086--- linux-2.6.32.43/fs/reiserfs/procfs.c 2011-03-27 14:31:47.000000000 -0400
46087+++ linux-2.6.32.43/fs/reiserfs/procfs.c 2011-05-16 21:46:57.000000000 -0400
46088@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m
46089 "SMALL_TAILS " : "NO_TAILS ",
46090 replay_only(sb) ? "REPLAY_ONLY " : "",
46091 convert_reiserfs(sb) ? "CONV " : "",
46092- atomic_read(&r->s_generation_counter),
46093+ atomic_read_unchecked(&r->s_generation_counter),
46094 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
46095 SF(s_do_balance), SF(s_unneeded_left_neighbor),
46096 SF(s_good_search_by_key_reada), SF(s_bmaps),
46097@@ -309,6 +309,8 @@ static int show_journal(struct seq_file
46098 struct journal_params *jp = &rs->s_v1.s_journal;
46099 char b[BDEVNAME_SIZE];
46100
46101+ pax_track_stack();
46102+
46103 seq_printf(m, /* on-disk fields */
46104 "jp_journal_1st_block: \t%i\n"
46105 "jp_journal_dev: \t%s[%x]\n"
46106diff -urNp linux-2.6.32.43/fs/reiserfs/stree.c linux-2.6.32.43/fs/reiserfs/stree.c
46107--- linux-2.6.32.43/fs/reiserfs/stree.c 2011-03-27 14:31:47.000000000 -0400
46108+++ linux-2.6.32.43/fs/reiserfs/stree.c 2011-05-16 21:46:57.000000000 -0400
46109@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs
46110 int iter = 0;
46111 #endif
46112
46113+ pax_track_stack();
46114+
46115 BUG_ON(!th->t_trans_id);
46116
46117 init_tb_struct(th, &s_del_balance, sb, path,
46118@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct r
46119 int retval;
46120 int quota_cut_bytes = 0;
46121
46122+ pax_track_stack();
46123+
46124 BUG_ON(!th->t_trans_id);
46125
46126 le_key2cpu_key(&cpu_key, key);
46127@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiser
46128 int quota_cut_bytes;
46129 loff_t tail_pos = 0;
46130
46131+ pax_track_stack();
46132+
46133 BUG_ON(!th->t_trans_id);
46134
46135 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
46136@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reis
46137 int retval;
46138 int fs_gen;
46139
46140+ pax_track_stack();
46141+
46142 BUG_ON(!th->t_trans_id);
46143
46144 fs_gen = get_generation(inode->i_sb);
46145@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs
46146 int fs_gen = 0;
46147 int quota_bytes = 0;
46148
46149+ pax_track_stack();
46150+
46151 BUG_ON(!th->t_trans_id);
46152
46153 if (inode) { /* Do we count quotas for item? */
46154diff -urNp linux-2.6.32.43/fs/reiserfs/super.c linux-2.6.32.43/fs/reiserfs/super.c
46155--- linux-2.6.32.43/fs/reiserfs/super.c 2011-03-27 14:31:47.000000000 -0400
46156+++ linux-2.6.32.43/fs/reiserfs/super.c 2011-05-16 21:46:57.000000000 -0400
46157@@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct
46158 {.option_name = NULL}
46159 };
46160
46161+ pax_track_stack();
46162+
46163 *blocks = 0;
46164 if (!options || !*options)
46165 /* use default configuration: create tails, journaling on, no
46166diff -urNp linux-2.6.32.43/fs/select.c linux-2.6.32.43/fs/select.c
46167--- linux-2.6.32.43/fs/select.c 2011-03-27 14:31:47.000000000 -0400
46168+++ linux-2.6.32.43/fs/select.c 2011-05-16 21:46:57.000000000 -0400
46169@@ -20,6 +20,7 @@
46170 #include <linux/module.h>
46171 #include <linux/slab.h>
46172 #include <linux/poll.h>
46173+#include <linux/security.h>
46174 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
46175 #include <linux/file.h>
46176 #include <linux/fdtable.h>
46177@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, s
46178 int retval, i, timed_out = 0;
46179 unsigned long slack = 0;
46180
46181+ pax_track_stack();
46182+
46183 rcu_read_lock();
46184 retval = max_select_fd(n, fds);
46185 rcu_read_unlock();
46186@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user
46187 /* Allocate small arguments on the stack to save memory and be faster */
46188 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
46189
46190+ pax_track_stack();
46191+
46192 ret = -EINVAL;
46193 if (n < 0)
46194 goto out_nofds;
46195@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *uf
46196 struct poll_list *walk = head;
46197 unsigned long todo = nfds;
46198
46199+ pax_track_stack();
46200+
46201+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
46202 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
46203 return -EINVAL;
46204
46205diff -urNp linux-2.6.32.43/fs/seq_file.c linux-2.6.32.43/fs/seq_file.c
46206--- linux-2.6.32.43/fs/seq_file.c 2011-03-27 14:31:47.000000000 -0400
46207+++ linux-2.6.32.43/fs/seq_file.c 2011-08-05 20:33:55.000000000 -0400
46208@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
46209 return 0;
46210 }
46211 if (!m->buf) {
46212- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46213+ m->size = PAGE_SIZE;
46214+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46215 if (!m->buf)
46216 return -ENOMEM;
46217 }
46218@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
46219 Eoverflow:
46220 m->op->stop(m, p);
46221 kfree(m->buf);
46222- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46223+ m->size <<= 1;
46224+ m->buf = kmalloc(m->size, GFP_KERNEL);
46225 return !m->buf ? -ENOMEM : -EAGAIN;
46226 }
46227
46228@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
46229 m->version = file->f_version;
46230 /* grab buffer if we didn't have one */
46231 if (!m->buf) {
46232- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46233+ m->size = PAGE_SIZE;
46234+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46235 if (!m->buf)
46236 goto Enomem;
46237 }
46238@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
46239 goto Fill;
46240 m->op->stop(m, p);
46241 kfree(m->buf);
46242- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46243+ m->size <<= 1;
46244+ m->buf = kmalloc(m->size, GFP_KERNEL);
46245 if (!m->buf)
46246 goto Enomem;
46247 m->count = 0;
46248@@ -555,10 +559,10 @@ int single_open(struct file *file, int (
46249 int res = -ENOMEM;
46250
46251 if (op) {
46252- op->start = single_start;
46253- op->next = single_next;
46254- op->stop = single_stop;
46255- op->show = show;
46256+ *(void **)&op->start = single_start;
46257+ *(void **)&op->next = single_next;
46258+ *(void **)&op->stop = single_stop;
46259+ *(void **)&op->show = show;
46260 res = seq_open(file, op);
46261 if (!res)
46262 ((struct seq_file *)file->private_data)->private = data;
46263diff -urNp linux-2.6.32.43/fs/smbfs/proc.c linux-2.6.32.43/fs/smbfs/proc.c
46264--- linux-2.6.32.43/fs/smbfs/proc.c 2011-03-27 14:31:47.000000000 -0400
46265+++ linux-2.6.32.43/fs/smbfs/proc.c 2011-08-05 20:33:55.000000000 -0400
46266@@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *
46267
46268 out:
46269 if (server->local_nls != NULL && server->remote_nls != NULL)
46270- server->ops->convert = convert_cp;
46271+ *(void **)&server->ops->convert = convert_cp;
46272 else
46273- server->ops->convert = convert_memcpy;
46274+ *(void **)&server->ops->convert = convert_memcpy;
46275
46276 smb_unlock_server(server);
46277 return n;
46278@@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server,
46279
46280 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
46281 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
46282- server->ops->getattr = smb_proc_getattr_core;
46283+ *(void **)&server->ops->getattr = smb_proc_getattr_core;
46284 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
46285- server->ops->getattr = smb_proc_getattr_ff;
46286+ *(void **)&server->ops->getattr = smb_proc_getattr_ff;
46287 }
46288
46289 /* Decode server capabilities */
46290@@ -3439,7 +3439,7 @@ out:
46291 static void
46292 install_ops(struct smb_ops *dst, struct smb_ops *src)
46293 {
46294- memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
46295+ memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
46296 }
46297
46298 /* < LANMAN2 */
46299diff -urNp linux-2.6.32.43/fs/smbfs/symlink.c linux-2.6.32.43/fs/smbfs/symlink.c
46300--- linux-2.6.32.43/fs/smbfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
46301+++ linux-2.6.32.43/fs/smbfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
46302@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
46303
46304 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46305 {
46306- char *s = nd_get_link(nd);
46307+ const char *s = nd_get_link(nd);
46308 if (!IS_ERR(s))
46309 __putname(s);
46310 }
46311diff -urNp linux-2.6.32.43/fs/splice.c linux-2.6.32.43/fs/splice.c
46312--- linux-2.6.32.43/fs/splice.c 2011-03-27 14:31:47.000000000 -0400
46313+++ linux-2.6.32.43/fs/splice.c 2011-05-16 21:46:57.000000000 -0400
46314@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode
46315 pipe_lock(pipe);
46316
46317 for (;;) {
46318- if (!pipe->readers) {
46319+ if (!atomic_read(&pipe->readers)) {
46320 send_sig(SIGPIPE, current, 0);
46321 if (!ret)
46322 ret = -EPIPE;
46323@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode
46324 do_wakeup = 0;
46325 }
46326
46327- pipe->waiting_writers++;
46328+ atomic_inc(&pipe->waiting_writers);
46329 pipe_wait(pipe);
46330- pipe->waiting_writers--;
46331+ atomic_dec(&pipe->waiting_writers);
46332 }
46333
46334 pipe_unlock(pipe);
46335@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *
46336 .spd_release = spd_release_page,
46337 };
46338
46339+ pax_track_stack();
46340+
46341 index = *ppos >> PAGE_CACHE_SHIFT;
46342 loff = *ppos & ~PAGE_CACHE_MASK;
46343 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
46344@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file
46345 old_fs = get_fs();
46346 set_fs(get_ds());
46347 /* The cast to a user pointer is valid due to the set_fs() */
46348- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
46349+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
46350 set_fs(old_fs);
46351
46352 return res;
46353@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file
46354 old_fs = get_fs();
46355 set_fs(get_ds());
46356 /* The cast to a user pointer is valid due to the set_fs() */
46357- res = vfs_write(file, (const char __user *)buf, count, &pos);
46358+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
46359 set_fs(old_fs);
46360
46361 return res;
46362@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct
46363 .spd_release = spd_release_page,
46364 };
46365
46366+ pax_track_stack();
46367+
46368 index = *ppos >> PAGE_CACHE_SHIFT;
46369 offset = *ppos & ~PAGE_CACHE_MASK;
46370 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
46371@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct
46372 goto err;
46373
46374 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
46375- vec[i].iov_base = (void __user *) page_address(page);
46376+ vec[i].iov_base = (__force void __user *) page_address(page);
46377 vec[i].iov_len = this_len;
46378 pages[i] = page;
46379 spd.nr_pages++;
46380@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
46381 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
46382 {
46383 while (!pipe->nrbufs) {
46384- if (!pipe->writers)
46385+ if (!atomic_read(&pipe->writers))
46386 return 0;
46387
46388- if (!pipe->waiting_writers && sd->num_spliced)
46389+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
46390 return 0;
46391
46392 if (sd->flags & SPLICE_F_NONBLOCK)
46393@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct fi
46394 * out of the pipe right after the splice_to_pipe(). So set
46395 * PIPE_READERS appropriately.
46396 */
46397- pipe->readers = 1;
46398+ atomic_set(&pipe->readers, 1);
46399
46400 current->splice_pipe = pipe;
46401 }
46402@@ -1592,6 +1596,8 @@ static long vmsplice_to_pipe(struct file
46403 .spd_release = spd_release_page,
46404 };
46405
46406+ pax_track_stack();
46407+
46408 pipe = pipe_info(file->f_path.dentry->d_inode);
46409 if (!pipe)
46410 return -EBADF;
46411@@ -1700,9 +1706,9 @@ static int ipipe_prep(struct pipe_inode_
46412 ret = -ERESTARTSYS;
46413 break;
46414 }
46415- if (!pipe->writers)
46416+ if (!atomic_read(&pipe->writers))
46417 break;
46418- if (!pipe->waiting_writers) {
46419+ if (!atomic_read(&pipe->waiting_writers)) {
46420 if (flags & SPLICE_F_NONBLOCK) {
46421 ret = -EAGAIN;
46422 break;
46423@@ -1734,7 +1740,7 @@ static int opipe_prep(struct pipe_inode_
46424 pipe_lock(pipe);
46425
46426 while (pipe->nrbufs >= PIPE_BUFFERS) {
46427- if (!pipe->readers) {
46428+ if (!atomic_read(&pipe->readers)) {
46429 send_sig(SIGPIPE, current, 0);
46430 ret = -EPIPE;
46431 break;
46432@@ -1747,9 +1753,9 @@ static int opipe_prep(struct pipe_inode_
46433 ret = -ERESTARTSYS;
46434 break;
46435 }
46436- pipe->waiting_writers++;
46437+ atomic_inc(&pipe->waiting_writers);
46438 pipe_wait(pipe);
46439- pipe->waiting_writers--;
46440+ atomic_dec(&pipe->waiting_writers);
46441 }
46442
46443 pipe_unlock(pipe);
46444@@ -1785,14 +1791,14 @@ retry:
46445 pipe_double_lock(ipipe, opipe);
46446
46447 do {
46448- if (!opipe->readers) {
46449+ if (!atomic_read(&opipe->readers)) {
46450 send_sig(SIGPIPE, current, 0);
46451 if (!ret)
46452 ret = -EPIPE;
46453 break;
46454 }
46455
46456- if (!ipipe->nrbufs && !ipipe->writers)
46457+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
46458 break;
46459
46460 /*
46461@@ -1892,7 +1898,7 @@ static int link_pipe(struct pipe_inode_i
46462 pipe_double_lock(ipipe, opipe);
46463
46464 do {
46465- if (!opipe->readers) {
46466+ if (!atomic_read(&opipe->readers)) {
46467 send_sig(SIGPIPE, current, 0);
46468 if (!ret)
46469 ret = -EPIPE;
46470@@ -1937,7 +1943,7 @@ static int link_pipe(struct pipe_inode_i
46471 * return EAGAIN if we have the potential of some data in the
46472 * future, otherwise just return 0
46473 */
46474- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
46475+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
46476 ret = -EAGAIN;
46477
46478 pipe_unlock(ipipe);
46479diff -urNp linux-2.6.32.43/fs/sysfs/file.c linux-2.6.32.43/fs/sysfs/file.c
46480--- linux-2.6.32.43/fs/sysfs/file.c 2011-03-27 14:31:47.000000000 -0400
46481+++ linux-2.6.32.43/fs/sysfs/file.c 2011-05-04 17:56:20.000000000 -0400
46482@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
46483
46484 struct sysfs_open_dirent {
46485 atomic_t refcnt;
46486- atomic_t event;
46487+ atomic_unchecked_t event;
46488 wait_queue_head_t poll;
46489 struct list_head buffers; /* goes through sysfs_buffer.list */
46490 };
46491@@ -53,7 +53,7 @@ struct sysfs_buffer {
46492 size_t count;
46493 loff_t pos;
46494 char * page;
46495- struct sysfs_ops * ops;
46496+ const struct sysfs_ops * ops;
46497 struct mutex mutex;
46498 int needs_read_fill;
46499 int event;
46500@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentr
46501 {
46502 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
46503 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
46504- struct sysfs_ops * ops = buffer->ops;
46505+ const struct sysfs_ops * ops = buffer->ops;
46506 int ret = 0;
46507 ssize_t count;
46508
46509@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
46510 if (!sysfs_get_active_two(attr_sd))
46511 return -ENODEV;
46512
46513- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
46514+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
46515 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
46516
46517 sysfs_put_active_two(attr_sd);
46518@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentr
46519 {
46520 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
46521 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
46522- struct sysfs_ops * ops = buffer->ops;
46523+ const struct sysfs_ops * ops = buffer->ops;
46524 int rc;
46525
46526 /* need attr_sd for attr and ops, its parent for kobj */
46527@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
46528 return -ENOMEM;
46529
46530 atomic_set(&new_od->refcnt, 0);
46531- atomic_set(&new_od->event, 1);
46532+ atomic_set_unchecked(&new_od->event, 1);
46533 init_waitqueue_head(&new_od->poll);
46534 INIT_LIST_HEAD(&new_od->buffers);
46535 goto retry;
46536@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode
46537 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
46538 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
46539 struct sysfs_buffer *buffer;
46540- struct sysfs_ops *ops;
46541+ const struct sysfs_ops *ops;
46542 int error = -EACCES;
46543 char *p;
46544
46545@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
46546
46547 sysfs_put_active_two(attr_sd);
46548
46549- if (buffer->event != atomic_read(&od->event))
46550+ if (buffer->event != atomic_read_unchecked(&od->event))
46551 goto trigger;
46552
46553 return DEFAULT_POLLMASK;
46554@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
46555
46556 od = sd->s_attr.open;
46557 if (od) {
46558- atomic_inc(&od->event);
46559+ atomic_inc_unchecked(&od->event);
46560 wake_up_interruptible(&od->poll);
46561 }
46562
46563diff -urNp linux-2.6.32.43/fs/sysfs/mount.c linux-2.6.32.43/fs/sysfs/mount.c
46564--- linux-2.6.32.43/fs/sysfs/mount.c 2011-03-27 14:31:47.000000000 -0400
46565+++ linux-2.6.32.43/fs/sysfs/mount.c 2011-04-17 15:56:46.000000000 -0400
46566@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
46567 .s_name = "",
46568 .s_count = ATOMIC_INIT(1),
46569 .s_flags = SYSFS_DIR,
46570+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46571+ .s_mode = S_IFDIR | S_IRWXU,
46572+#else
46573 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46574+#endif
46575 .s_ino = 1,
46576 };
46577
46578diff -urNp linux-2.6.32.43/fs/sysfs/symlink.c linux-2.6.32.43/fs/sysfs/symlink.c
46579--- linux-2.6.32.43/fs/sysfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
46580+++ linux-2.6.32.43/fs/sysfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
46581@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct de
46582
46583 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46584 {
46585- char *page = nd_get_link(nd);
46586+ const char *page = nd_get_link(nd);
46587 if (!IS_ERR(page))
46588 free_page((unsigned long)page);
46589 }
46590diff -urNp linux-2.6.32.43/fs/udf/balloc.c linux-2.6.32.43/fs/udf/balloc.c
46591--- linux-2.6.32.43/fs/udf/balloc.c 2011-03-27 14:31:47.000000000 -0400
46592+++ linux-2.6.32.43/fs/udf/balloc.c 2011-04-17 15:56:46.000000000 -0400
46593@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struc
46594
46595 mutex_lock(&sbi->s_alloc_mutex);
46596 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
46597- if (bloc->logicalBlockNum < 0 ||
46598- (bloc->logicalBlockNum + count) >
46599- partmap->s_partition_len) {
46600+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
46601 udf_debug("%d < %d || %d + %d > %d\n",
46602 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
46603 count, partmap->s_partition_len);
46604@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct
46605
46606 mutex_lock(&sbi->s_alloc_mutex);
46607 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
46608- if (bloc->logicalBlockNum < 0 ||
46609- (bloc->logicalBlockNum + count) >
46610- partmap->s_partition_len) {
46611+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
46612 udf_debug("%d < %d || %d + %d > %d\n",
46613 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
46614 partmap->s_partition_len);
46615diff -urNp linux-2.6.32.43/fs/udf/inode.c linux-2.6.32.43/fs/udf/inode.c
46616--- linux-2.6.32.43/fs/udf/inode.c 2011-03-27 14:31:47.000000000 -0400
46617+++ linux-2.6.32.43/fs/udf/inode.c 2011-05-16 21:46:57.000000000 -0400
46618@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(
46619 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
46620 int lastblock = 0;
46621
46622+ pax_track_stack();
46623+
46624 prev_epos.offset = udf_file_entry_alloc_offset(inode);
46625 prev_epos.block = iinfo->i_location;
46626 prev_epos.bh = NULL;
46627diff -urNp linux-2.6.32.43/fs/udf/misc.c linux-2.6.32.43/fs/udf/misc.c
46628--- linux-2.6.32.43/fs/udf/misc.c 2011-03-27 14:31:47.000000000 -0400
46629+++ linux-2.6.32.43/fs/udf/misc.c 2011-04-23 12:56:11.000000000 -0400
46630@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
46631
46632 u8 udf_tag_checksum(const struct tag *t)
46633 {
46634- u8 *data = (u8 *)t;
46635+ const u8 *data = (const u8 *)t;
46636 u8 checksum = 0;
46637 int i;
46638 for (i = 0; i < sizeof(struct tag); ++i)
46639diff -urNp linux-2.6.32.43/fs/utimes.c linux-2.6.32.43/fs/utimes.c
46640--- linux-2.6.32.43/fs/utimes.c 2011-03-27 14:31:47.000000000 -0400
46641+++ linux-2.6.32.43/fs/utimes.c 2011-04-17 15:56:46.000000000 -0400
46642@@ -1,6 +1,7 @@
46643 #include <linux/compiler.h>
46644 #include <linux/file.h>
46645 #include <linux/fs.h>
46646+#include <linux/security.h>
46647 #include <linux/linkage.h>
46648 #include <linux/mount.h>
46649 #include <linux/namei.h>
46650@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
46651 goto mnt_drop_write_and_out;
46652 }
46653 }
46654+
46655+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
46656+ error = -EACCES;
46657+ goto mnt_drop_write_and_out;
46658+ }
46659+
46660 mutex_lock(&inode->i_mutex);
46661 error = notify_change(path->dentry, &newattrs);
46662 mutex_unlock(&inode->i_mutex);
46663diff -urNp linux-2.6.32.43/fs/xattr_acl.c linux-2.6.32.43/fs/xattr_acl.c
46664--- linux-2.6.32.43/fs/xattr_acl.c 2011-03-27 14:31:47.000000000 -0400
46665+++ linux-2.6.32.43/fs/xattr_acl.c 2011-04-17 15:56:46.000000000 -0400
46666@@ -17,8 +17,8 @@
46667 struct posix_acl *
46668 posix_acl_from_xattr(const void *value, size_t size)
46669 {
46670- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
46671- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
46672+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
46673+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
46674 int count;
46675 struct posix_acl *acl;
46676 struct posix_acl_entry *acl_e;
46677diff -urNp linux-2.6.32.43/fs/xattr.c linux-2.6.32.43/fs/xattr.c
46678--- linux-2.6.32.43/fs/xattr.c 2011-03-27 14:31:47.000000000 -0400
46679+++ linux-2.6.32.43/fs/xattr.c 2011-04-17 15:56:46.000000000 -0400
46680@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
46681 * Extended attribute SET operations
46682 */
46683 static long
46684-setxattr(struct dentry *d, const char __user *name, const void __user *value,
46685+setxattr(struct path *path, const char __user *name, const void __user *value,
46686 size_t size, int flags)
46687 {
46688 int error;
46689@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
46690 return PTR_ERR(kvalue);
46691 }
46692
46693- error = vfs_setxattr(d, kname, kvalue, size, flags);
46694+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
46695+ error = -EACCES;
46696+ goto out;
46697+ }
46698+
46699+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
46700+out:
46701 kfree(kvalue);
46702 return error;
46703 }
46704@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
46705 return error;
46706 error = mnt_want_write(path.mnt);
46707 if (!error) {
46708- error = setxattr(path.dentry, name, value, size, flags);
46709+ error = setxattr(&path, name, value, size, flags);
46710 mnt_drop_write(path.mnt);
46711 }
46712 path_put(&path);
46713@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
46714 return error;
46715 error = mnt_want_write(path.mnt);
46716 if (!error) {
46717- error = setxattr(path.dentry, name, value, size, flags);
46718+ error = setxattr(&path, name, value, size, flags);
46719 mnt_drop_write(path.mnt);
46720 }
46721 path_put(&path);
46722@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
46723 const void __user *,value, size_t, size, int, flags)
46724 {
46725 struct file *f;
46726- struct dentry *dentry;
46727 int error = -EBADF;
46728
46729 f = fget(fd);
46730 if (!f)
46731 return error;
46732- dentry = f->f_path.dentry;
46733- audit_inode(NULL, dentry);
46734+ audit_inode(NULL, f->f_path.dentry);
46735 error = mnt_want_write_file(f);
46736 if (!error) {
46737- error = setxattr(dentry, name, value, size, flags);
46738+ error = setxattr(&f->f_path, name, value, size, flags);
46739 mnt_drop_write(f->f_path.mnt);
46740 }
46741 fput(f);
46742diff -urNp linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl32.c
46743--- linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-03-27 14:31:47.000000000 -0400
46744+++ linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-04-17 15:56:46.000000000 -0400
46745@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
46746 xfs_fsop_geom_t fsgeo;
46747 int error;
46748
46749+ memset(&fsgeo, 0, sizeof(fsgeo));
46750 error = xfs_fs_geometry(mp, &fsgeo, 3);
46751 if (error)
46752 return -error;
46753diff -urNp linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl.c
46754--- linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 17:00:52.000000000 -0400
46755+++ linux-2.6.32.43/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 20:07:09.000000000 -0400
46756@@ -134,7 +134,7 @@ xfs_find_handle(
46757 }
46758
46759 error = -EFAULT;
46760- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
46761+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
46762 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
46763 goto out_put;
46764
46765@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
46766 if (IS_ERR(dentry))
46767 return PTR_ERR(dentry);
46768
46769- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
46770+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
46771 if (!kbuf)
46772 goto out_dput;
46773
46774@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
46775 xfs_mount_t *mp,
46776 void __user *arg)
46777 {
46778- xfs_fsop_geom_t fsgeo;
46779+ xfs_fsop_geom_t fsgeo;
46780 int error;
46781
46782 error = xfs_fs_geometry(mp, &fsgeo, 3);
46783diff -urNp linux-2.6.32.43/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.43/fs/xfs/linux-2.6/xfs_iops.c
46784--- linux-2.6.32.43/fs/xfs/linux-2.6/xfs_iops.c 2011-03-27 14:31:47.000000000 -0400
46785+++ linux-2.6.32.43/fs/xfs/linux-2.6/xfs_iops.c 2011-04-17 15:56:46.000000000 -0400
46786@@ -468,7 +468,7 @@ xfs_vn_put_link(
46787 struct nameidata *nd,
46788 void *p)
46789 {
46790- char *s = nd_get_link(nd);
46791+ const char *s = nd_get_link(nd);
46792
46793 if (!IS_ERR(s))
46794 kfree(s);
46795diff -urNp linux-2.6.32.43/fs/xfs/xfs_bmap.c linux-2.6.32.43/fs/xfs/xfs_bmap.c
46796--- linux-2.6.32.43/fs/xfs/xfs_bmap.c 2011-03-27 14:31:47.000000000 -0400
46797+++ linux-2.6.32.43/fs/xfs/xfs_bmap.c 2011-04-17 15:56:46.000000000 -0400
46798@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
46799 int nmap,
46800 int ret_nmap);
46801 #else
46802-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
46803+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
46804 #endif /* DEBUG */
46805
46806 #if defined(XFS_RW_TRACE)
46807diff -urNp linux-2.6.32.43/fs/xfs/xfs_dir2_sf.c linux-2.6.32.43/fs/xfs/xfs_dir2_sf.c
46808--- linux-2.6.32.43/fs/xfs/xfs_dir2_sf.c 2011-03-27 14:31:47.000000000 -0400
46809+++ linux-2.6.32.43/fs/xfs/xfs_dir2_sf.c 2011-04-18 22:07:30.000000000 -0400
46810@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
46811 }
46812
46813 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
46814- if (filldir(dirent, sfep->name, sfep->namelen,
46815+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
46816+ char name[sfep->namelen];
46817+ memcpy(name, sfep->name, sfep->namelen);
46818+ if (filldir(dirent, name, sfep->namelen,
46819+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
46820+ *offset = off & 0x7fffffff;
46821+ return 0;
46822+ }
46823+ } else if (filldir(dirent, sfep->name, sfep->namelen,
46824 off & 0x7fffffff, ino, DT_UNKNOWN)) {
46825 *offset = off & 0x7fffffff;
46826 return 0;
46827diff -urNp linux-2.6.32.43/grsecurity/gracl_alloc.c linux-2.6.32.43/grsecurity/gracl_alloc.c
46828--- linux-2.6.32.43/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
46829+++ linux-2.6.32.43/grsecurity/gracl_alloc.c 2011-04-17 15:56:46.000000000 -0400
46830@@ -0,0 +1,105 @@
46831+#include <linux/kernel.h>
46832+#include <linux/mm.h>
46833+#include <linux/slab.h>
46834+#include <linux/vmalloc.h>
46835+#include <linux/gracl.h>
46836+#include <linux/grsecurity.h>
46837+
46838+static unsigned long alloc_stack_next = 1;
46839+static unsigned long alloc_stack_size = 1;
46840+static void **alloc_stack;
46841+
46842+static __inline__ int
46843+alloc_pop(void)
46844+{
46845+ if (alloc_stack_next == 1)
46846+ return 0;
46847+
46848+ kfree(alloc_stack[alloc_stack_next - 2]);
46849+
46850+ alloc_stack_next--;
46851+
46852+ return 1;
46853+}
46854+
46855+static __inline__ int
46856+alloc_push(void *buf)
46857+{
46858+ if (alloc_stack_next >= alloc_stack_size)
46859+ return 1;
46860+
46861+ alloc_stack[alloc_stack_next - 1] = buf;
46862+
46863+ alloc_stack_next++;
46864+
46865+ return 0;
46866+}
46867+
46868+void *
46869+acl_alloc(unsigned long len)
46870+{
46871+ void *ret = NULL;
46872+
46873+ if (!len || len > PAGE_SIZE)
46874+ goto out;
46875+
46876+ ret = kmalloc(len, GFP_KERNEL);
46877+
46878+ if (ret) {
46879+ if (alloc_push(ret)) {
46880+ kfree(ret);
46881+ ret = NULL;
46882+ }
46883+ }
46884+
46885+out:
46886+ return ret;
46887+}
46888+
46889+void *
46890+acl_alloc_num(unsigned long num, unsigned long len)
46891+{
46892+ if (!len || (num > (PAGE_SIZE / len)))
46893+ return NULL;
46894+
46895+ return acl_alloc(num * len);
46896+}
46897+
46898+void
46899+acl_free_all(void)
46900+{
46901+ if (gr_acl_is_enabled() || !alloc_stack)
46902+ return;
46903+
46904+ while (alloc_pop()) ;
46905+
46906+ if (alloc_stack) {
46907+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
46908+ kfree(alloc_stack);
46909+ else
46910+ vfree(alloc_stack);
46911+ }
46912+
46913+ alloc_stack = NULL;
46914+ alloc_stack_size = 1;
46915+ alloc_stack_next = 1;
46916+
46917+ return;
46918+}
46919+
46920+int
46921+acl_alloc_stack_init(unsigned long size)
46922+{
46923+ if ((size * sizeof (void *)) <= PAGE_SIZE)
46924+ alloc_stack =
46925+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
46926+ else
46927+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
46928+
46929+ alloc_stack_size = size;
46930+
46931+ if (!alloc_stack)
46932+ return 0;
46933+ else
46934+ return 1;
46935+}
46936diff -urNp linux-2.6.32.43/grsecurity/gracl.c linux-2.6.32.43/grsecurity/gracl.c
46937--- linux-2.6.32.43/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
46938+++ linux-2.6.32.43/grsecurity/gracl.c 2011-07-14 20:02:48.000000000 -0400
46939@@ -0,0 +1,4082 @@
46940+#include <linux/kernel.h>
46941+#include <linux/module.h>
46942+#include <linux/sched.h>
46943+#include <linux/mm.h>
46944+#include <linux/file.h>
46945+#include <linux/fs.h>
46946+#include <linux/namei.h>
46947+#include <linux/mount.h>
46948+#include <linux/tty.h>
46949+#include <linux/proc_fs.h>
46950+#include <linux/smp_lock.h>
46951+#include <linux/slab.h>
46952+#include <linux/vmalloc.h>
46953+#include <linux/types.h>
46954+#include <linux/sysctl.h>
46955+#include <linux/netdevice.h>
46956+#include <linux/ptrace.h>
46957+#include <linux/gracl.h>
46958+#include <linux/gralloc.h>
46959+#include <linux/grsecurity.h>
46960+#include <linux/grinternal.h>
46961+#include <linux/pid_namespace.h>
46962+#include <linux/fdtable.h>
46963+#include <linux/percpu.h>
46964+
46965+#include <asm/uaccess.h>
46966+#include <asm/errno.h>
46967+#include <asm/mman.h>
46968+
46969+static struct acl_role_db acl_role_set;
46970+static struct name_db name_set;
46971+static struct inodev_db inodev_set;
46972+
46973+/* for keeping track of userspace pointers used for subjects, so we
46974+ can share references in the kernel as well
46975+*/
46976+
46977+static struct dentry *real_root;
46978+static struct vfsmount *real_root_mnt;
46979+
46980+static struct acl_subj_map_db subj_map_set;
46981+
46982+static struct acl_role_label *default_role;
46983+
46984+static struct acl_role_label *role_list;
46985+
46986+static u16 acl_sp_role_value;
46987+
46988+extern char *gr_shared_page[4];
46989+static DEFINE_MUTEX(gr_dev_mutex);
46990+DEFINE_RWLOCK(gr_inode_lock);
46991+
46992+struct gr_arg *gr_usermode;
46993+
46994+static unsigned int gr_status __read_only = GR_STATUS_INIT;
46995+
46996+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
46997+extern void gr_clear_learn_entries(void);
46998+
46999+#ifdef CONFIG_GRKERNSEC_RESLOG
47000+extern void gr_log_resource(const struct task_struct *task,
47001+ const int res, const unsigned long wanted, const int gt);
47002+#endif
47003+
47004+unsigned char *gr_system_salt;
47005+unsigned char *gr_system_sum;
47006+
47007+static struct sprole_pw **acl_special_roles = NULL;
47008+static __u16 num_sprole_pws = 0;
47009+
47010+static struct acl_role_label *kernel_role = NULL;
47011+
47012+static unsigned int gr_auth_attempts = 0;
47013+static unsigned long gr_auth_expires = 0UL;
47014+
47015+#ifdef CONFIG_NET
47016+extern struct vfsmount *sock_mnt;
47017+#endif
47018+extern struct vfsmount *pipe_mnt;
47019+extern struct vfsmount *shm_mnt;
47020+#ifdef CONFIG_HUGETLBFS
47021+extern struct vfsmount *hugetlbfs_vfsmount;
47022+#endif
47023+
47024+static struct acl_object_label *fakefs_obj_rw;
47025+static struct acl_object_label *fakefs_obj_rwx;
47026+
47027+extern int gr_init_uidset(void);
47028+extern void gr_free_uidset(void);
47029+extern void gr_remove_uid(uid_t uid);
47030+extern int gr_find_uid(uid_t uid);
47031+
47032+__inline__ int
47033+gr_acl_is_enabled(void)
47034+{
47035+ return (gr_status & GR_READY);
47036+}
47037+
47038+#ifdef CONFIG_BTRFS_FS
47039+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
47040+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
47041+#endif
47042+
47043+static inline dev_t __get_dev(const struct dentry *dentry)
47044+{
47045+#ifdef CONFIG_BTRFS_FS
47046+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
47047+ return get_btrfs_dev_from_inode(dentry->d_inode);
47048+ else
47049+#endif
47050+ return dentry->d_inode->i_sb->s_dev;
47051+}
47052+
47053+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
47054+{
47055+ return __get_dev(dentry);
47056+}
47057+
47058+static char gr_task_roletype_to_char(struct task_struct *task)
47059+{
47060+ switch (task->role->roletype &
47061+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
47062+ GR_ROLE_SPECIAL)) {
47063+ case GR_ROLE_DEFAULT:
47064+ return 'D';
47065+ case GR_ROLE_USER:
47066+ return 'U';
47067+ case GR_ROLE_GROUP:
47068+ return 'G';
47069+ case GR_ROLE_SPECIAL:
47070+ return 'S';
47071+ }
47072+
47073+ return 'X';
47074+}
47075+
47076+char gr_roletype_to_char(void)
47077+{
47078+ return gr_task_roletype_to_char(current);
47079+}
47080+
47081+__inline__ int
47082+gr_acl_tpe_check(void)
47083+{
47084+ if (unlikely(!(gr_status & GR_READY)))
47085+ return 0;
47086+ if (current->role->roletype & GR_ROLE_TPE)
47087+ return 1;
47088+ else
47089+ return 0;
47090+}
47091+
47092+int
47093+gr_handle_rawio(const struct inode *inode)
47094+{
47095+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
47096+ if (inode && S_ISBLK(inode->i_mode) &&
47097+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
47098+ !capable(CAP_SYS_RAWIO))
47099+ return 1;
47100+#endif
47101+ return 0;
47102+}
47103+
47104+static int
47105+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
47106+{
47107+ if (likely(lena != lenb))
47108+ return 0;
47109+
47110+ return !memcmp(a, b, lena);
47111+}
47112+
47113+/* this must be called with vfsmount_lock and dcache_lock held */
47114+
47115+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
47116+ struct dentry *root, struct vfsmount *rootmnt,
47117+ char *buffer, int buflen)
47118+{
47119+ char * end = buffer+buflen;
47120+ char * retval;
47121+ int namelen;
47122+
47123+ *--end = '\0';
47124+ buflen--;
47125+
47126+ if (buflen < 1)
47127+ goto Elong;
47128+ /* Get '/' right */
47129+ retval = end-1;
47130+ *retval = '/';
47131+
47132+ for (;;) {
47133+ struct dentry * parent;
47134+
47135+ if (dentry == root && vfsmnt == rootmnt)
47136+ break;
47137+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
47138+ /* Global root? */
47139+ if (vfsmnt->mnt_parent == vfsmnt)
47140+ goto global_root;
47141+ dentry = vfsmnt->mnt_mountpoint;
47142+ vfsmnt = vfsmnt->mnt_parent;
47143+ continue;
47144+ }
47145+ parent = dentry->d_parent;
47146+ prefetch(parent);
47147+ namelen = dentry->d_name.len;
47148+ buflen -= namelen + 1;
47149+ if (buflen < 0)
47150+ goto Elong;
47151+ end -= namelen;
47152+ memcpy(end, dentry->d_name.name, namelen);
47153+ *--end = '/';
47154+ retval = end;
47155+ dentry = parent;
47156+ }
47157+
47158+out:
47159+ return retval;
47160+
47161+global_root:
47162+ namelen = dentry->d_name.len;
47163+ buflen -= namelen;
47164+ if (buflen < 0)
47165+ goto Elong;
47166+ retval -= namelen-1; /* hit the slash */
47167+ memcpy(retval, dentry->d_name.name, namelen);
47168+ goto out;
47169+Elong:
47170+ retval = ERR_PTR(-ENAMETOOLONG);
47171+ goto out;
47172+}
47173+
47174+static char *
47175+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
47176+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
47177+{
47178+ char *retval;
47179+
47180+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
47181+ if (unlikely(IS_ERR(retval)))
47182+ retval = strcpy(buf, "<path too long>");
47183+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
47184+ retval[1] = '\0';
47185+
47186+ return retval;
47187+}
47188+
47189+static char *
47190+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
47191+ char *buf, int buflen)
47192+{
47193+ char *res;
47194+
47195+ /* we can use real_root, real_root_mnt, because this is only called
47196+ by the RBAC system */
47197+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
47198+
47199+ return res;
47200+}
47201+
47202+static char *
47203+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
47204+ char *buf, int buflen)
47205+{
47206+ char *res;
47207+ struct dentry *root;
47208+ struct vfsmount *rootmnt;
47209+ struct task_struct *reaper = &init_task;
47210+
47211+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
47212+ read_lock(&reaper->fs->lock);
47213+ root = dget(reaper->fs->root.dentry);
47214+ rootmnt = mntget(reaper->fs->root.mnt);
47215+ read_unlock(&reaper->fs->lock);
47216+
47217+ spin_lock(&dcache_lock);
47218+ spin_lock(&vfsmount_lock);
47219+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
47220+ spin_unlock(&vfsmount_lock);
47221+ spin_unlock(&dcache_lock);
47222+
47223+ dput(root);
47224+ mntput(rootmnt);
47225+ return res;
47226+}
47227+
47228+static char *
47229+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
47230+{
47231+ char *ret;
47232+ spin_lock(&dcache_lock);
47233+ spin_lock(&vfsmount_lock);
47234+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
47235+ PAGE_SIZE);
47236+ spin_unlock(&vfsmount_lock);
47237+ spin_unlock(&dcache_lock);
47238+ return ret;
47239+}
47240+
47241+char *
47242+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
47243+{
47244+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
47245+ PAGE_SIZE);
47246+}
47247+
47248+char *
47249+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
47250+{
47251+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
47252+ PAGE_SIZE);
47253+}
47254+
47255+char *
47256+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
47257+{
47258+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
47259+ PAGE_SIZE);
47260+}
47261+
47262+char *
47263+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
47264+{
47265+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
47266+ PAGE_SIZE);
47267+}
47268+
47269+char *
47270+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
47271+{
47272+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
47273+ PAGE_SIZE);
47274+}
47275+
47276+__inline__ __u32
47277+to_gr_audit(const __u32 reqmode)
47278+{
47279+ /* masks off auditable permission flags, then shifts them to create
47280+ auditing flags, and adds the special case of append auditing if
47281+ we're requesting write */
47282+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
47283+}
47284+
47285+struct acl_subject_label *
47286+lookup_subject_map(const struct acl_subject_label *userp)
47287+{
47288+ unsigned int index = shash(userp, subj_map_set.s_size);
47289+ struct subject_map *match;
47290+
47291+ match = subj_map_set.s_hash[index];
47292+
47293+ while (match && match->user != userp)
47294+ match = match->next;
47295+
47296+ if (match != NULL)
47297+ return match->kernel;
47298+ else
47299+ return NULL;
47300+}
47301+
47302+static void
47303+insert_subj_map_entry(struct subject_map *subjmap)
47304+{
47305+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
47306+ struct subject_map **curr;
47307+
47308+ subjmap->prev = NULL;
47309+
47310+ curr = &subj_map_set.s_hash[index];
47311+ if (*curr != NULL)
47312+ (*curr)->prev = subjmap;
47313+
47314+ subjmap->next = *curr;
47315+ *curr = subjmap;
47316+
47317+ return;
47318+}
47319+
47320+static struct acl_role_label *
47321+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
47322+ const gid_t gid)
47323+{
47324+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
47325+ struct acl_role_label *match;
47326+ struct role_allowed_ip *ipp;
47327+ unsigned int x;
47328+ u32 curr_ip = task->signal->curr_ip;
47329+
47330+ task->signal->saved_ip = curr_ip;
47331+
47332+ match = acl_role_set.r_hash[index];
47333+
47334+ while (match) {
47335+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
47336+ for (x = 0; x < match->domain_child_num; x++) {
47337+ if (match->domain_children[x] == uid)
47338+ goto found;
47339+ }
47340+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
47341+ break;
47342+ match = match->next;
47343+ }
47344+found:
47345+ if (match == NULL) {
47346+ try_group:
47347+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
47348+ match = acl_role_set.r_hash[index];
47349+
47350+ while (match) {
47351+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
47352+ for (x = 0; x < match->domain_child_num; x++) {
47353+ if (match->domain_children[x] == gid)
47354+ goto found2;
47355+ }
47356+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
47357+ break;
47358+ match = match->next;
47359+ }
47360+found2:
47361+ if (match == NULL)
47362+ match = default_role;
47363+ if (match->allowed_ips == NULL)
47364+ return match;
47365+ else {
47366+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
47367+ if (likely
47368+ ((ntohl(curr_ip) & ipp->netmask) ==
47369+ (ntohl(ipp->addr) & ipp->netmask)))
47370+ return match;
47371+ }
47372+ match = default_role;
47373+ }
47374+ } else if (match->allowed_ips == NULL) {
47375+ return match;
47376+ } else {
47377+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
47378+ if (likely
47379+ ((ntohl(curr_ip) & ipp->netmask) ==
47380+ (ntohl(ipp->addr) & ipp->netmask)))
47381+ return match;
47382+ }
47383+ goto try_group;
47384+ }
47385+
47386+ return match;
47387+}
47388+
47389+struct acl_subject_label *
47390+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
47391+ const struct acl_role_label *role)
47392+{
47393+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
47394+ struct acl_subject_label *match;
47395+
47396+ match = role->subj_hash[index];
47397+
47398+ while (match && (match->inode != ino || match->device != dev ||
47399+ (match->mode & GR_DELETED))) {
47400+ match = match->next;
47401+ }
47402+
47403+ if (match && !(match->mode & GR_DELETED))
47404+ return match;
47405+ else
47406+ return NULL;
47407+}
47408+
47409+struct acl_subject_label *
47410+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
47411+ const struct acl_role_label *role)
47412+{
47413+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
47414+ struct acl_subject_label *match;
47415+
47416+ match = role->subj_hash[index];
47417+
47418+ while (match && (match->inode != ino || match->device != dev ||
47419+ !(match->mode & GR_DELETED))) {
47420+ match = match->next;
47421+ }
47422+
47423+ if (match && (match->mode & GR_DELETED))
47424+ return match;
47425+ else
47426+ return NULL;
47427+}
47428+
47429+static struct acl_object_label *
47430+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
47431+ const struct acl_subject_label *subj)
47432+{
47433+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
47434+ struct acl_object_label *match;
47435+
47436+ match = subj->obj_hash[index];
47437+
47438+ while (match && (match->inode != ino || match->device != dev ||
47439+ (match->mode & GR_DELETED))) {
47440+ match = match->next;
47441+ }
47442+
47443+ if (match && !(match->mode & GR_DELETED))
47444+ return match;
47445+ else
47446+ return NULL;
47447+}
47448+
47449+static struct acl_object_label *
47450+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
47451+ const struct acl_subject_label *subj)
47452+{
47453+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
47454+ struct acl_object_label *match;
47455+
47456+ match = subj->obj_hash[index];
47457+
47458+ while (match && (match->inode != ino || match->device != dev ||
47459+ !(match->mode & GR_DELETED))) {
47460+ match = match->next;
47461+ }
47462+
47463+ if (match && (match->mode & GR_DELETED))
47464+ return match;
47465+
47466+ match = subj->obj_hash[index];
47467+
47468+ while (match && (match->inode != ino || match->device != dev ||
47469+ (match->mode & GR_DELETED))) {
47470+ match = match->next;
47471+ }
47472+
47473+ if (match && !(match->mode & GR_DELETED))
47474+ return match;
47475+ else
47476+ return NULL;
47477+}
47478+
47479+static struct name_entry *
47480+lookup_name_entry(const char *name)
47481+{
47482+ unsigned int len = strlen(name);
47483+ unsigned int key = full_name_hash(name, len);
47484+ unsigned int index = key % name_set.n_size;
47485+ struct name_entry *match;
47486+
47487+ match = name_set.n_hash[index];
47488+
47489+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
47490+ match = match->next;
47491+
47492+ return match;
47493+}
47494+
47495+static struct name_entry *
47496+lookup_name_entry_create(const char *name)
47497+{
47498+ unsigned int len = strlen(name);
47499+ unsigned int key = full_name_hash(name, len);
47500+ unsigned int index = key % name_set.n_size;
47501+ struct name_entry *match;
47502+
47503+ match = name_set.n_hash[index];
47504+
47505+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
47506+ !match->deleted))
47507+ match = match->next;
47508+
47509+ if (match && match->deleted)
47510+ return match;
47511+
47512+ match = name_set.n_hash[index];
47513+
47514+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
47515+ match->deleted))
47516+ match = match->next;
47517+
47518+ if (match && !match->deleted)
47519+ return match;
47520+ else
47521+ return NULL;
47522+}
47523+
47524+static struct inodev_entry *
47525+lookup_inodev_entry(const ino_t ino, const dev_t dev)
47526+{
47527+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
47528+ struct inodev_entry *match;
47529+
47530+ match = inodev_set.i_hash[index];
47531+
47532+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
47533+ match = match->next;
47534+
47535+ return match;
47536+}
47537+
47538+static void
47539+insert_inodev_entry(struct inodev_entry *entry)
47540+{
47541+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
47542+ inodev_set.i_size);
47543+ struct inodev_entry **curr;
47544+
47545+ entry->prev = NULL;
47546+
47547+ curr = &inodev_set.i_hash[index];
47548+ if (*curr != NULL)
47549+ (*curr)->prev = entry;
47550+
47551+ entry->next = *curr;
47552+ *curr = entry;
47553+
47554+ return;
47555+}
47556+
47557+static void
47558+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
47559+{
47560+ unsigned int index =
47561+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
47562+ struct acl_role_label **curr;
47563+ struct acl_role_label *tmp;
47564+
47565+ curr = &acl_role_set.r_hash[index];
47566+
47567+ /* if role was already inserted due to domains and already has
47568+ a role in the same bucket as it attached, then we need to
47569+ combine these two buckets
47570+ */
47571+ if (role->next) {
47572+ tmp = role->next;
47573+ while (tmp->next)
47574+ tmp = tmp->next;
47575+ tmp->next = *curr;
47576+ } else
47577+ role->next = *curr;
47578+ *curr = role;
47579+
47580+ return;
47581+}
47582+
47583+static void
47584+insert_acl_role_label(struct acl_role_label *role)
47585+{
47586+ int i;
47587+
47588+ if (role_list == NULL) {
47589+ role_list = role;
47590+ role->prev = NULL;
47591+ } else {
47592+ role->prev = role_list;
47593+ role_list = role;
47594+ }
47595+
47596+ /* used for hash chains */
47597+ role->next = NULL;
47598+
47599+ if (role->roletype & GR_ROLE_DOMAIN) {
47600+ for (i = 0; i < role->domain_child_num; i++)
47601+ __insert_acl_role_label(role, role->domain_children[i]);
47602+ } else
47603+ __insert_acl_role_label(role, role->uidgid);
47604+}
47605+
47606+static int
47607+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
47608+{
47609+ struct name_entry **curr, *nentry;
47610+ struct inodev_entry *ientry;
47611+ unsigned int len = strlen(name);
47612+ unsigned int key = full_name_hash(name, len);
47613+ unsigned int index = key % name_set.n_size;
47614+
47615+ curr = &name_set.n_hash[index];
47616+
47617+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
47618+ curr = &((*curr)->next);
47619+
47620+ if (*curr != NULL)
47621+ return 1;
47622+
47623+ nentry = acl_alloc(sizeof (struct name_entry));
47624+ if (nentry == NULL)
47625+ return 0;
47626+ ientry = acl_alloc(sizeof (struct inodev_entry));
47627+ if (ientry == NULL)
47628+ return 0;
47629+ ientry->nentry = nentry;
47630+
47631+ nentry->key = key;
47632+ nentry->name = name;
47633+ nentry->inode = inode;
47634+ nentry->device = device;
47635+ nentry->len = len;
47636+ nentry->deleted = deleted;
47637+
47638+ nentry->prev = NULL;
47639+ curr = &name_set.n_hash[index];
47640+ if (*curr != NULL)
47641+ (*curr)->prev = nentry;
47642+ nentry->next = *curr;
47643+ *curr = nentry;
47644+
47645+ /* insert us into the table searchable by inode/dev */
47646+ insert_inodev_entry(ientry);
47647+
47648+ return 1;
47649+}
47650+
47651+static void
47652+insert_acl_obj_label(struct acl_object_label *obj,
47653+ struct acl_subject_label *subj)
47654+{
47655+ unsigned int index =
47656+ fhash(obj->inode, obj->device, subj->obj_hash_size);
47657+ struct acl_object_label **curr;
47658+
47659+
47660+ obj->prev = NULL;
47661+
47662+ curr = &subj->obj_hash[index];
47663+ if (*curr != NULL)
47664+ (*curr)->prev = obj;
47665+
47666+ obj->next = *curr;
47667+ *curr = obj;
47668+
47669+ return;
47670+}
47671+
47672+static void
47673+insert_acl_subj_label(struct acl_subject_label *obj,
47674+ struct acl_role_label *role)
47675+{
47676+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
47677+ struct acl_subject_label **curr;
47678+
47679+ obj->prev = NULL;
47680+
47681+ curr = &role->subj_hash[index];
47682+ if (*curr != NULL)
47683+ (*curr)->prev = obj;
47684+
47685+ obj->next = *curr;
47686+ *curr = obj;
47687+
47688+ return;
47689+}
47690+
47691+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
47692+
47693+static void *
47694+create_table(__u32 * len, int elementsize)
47695+{
47696+ unsigned int table_sizes[] = {
47697+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
47698+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
47699+ 4194301, 8388593, 16777213, 33554393, 67108859
47700+ };
47701+ void *newtable = NULL;
47702+ unsigned int pwr = 0;
47703+
47704+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
47705+ table_sizes[pwr] <= *len)
47706+ pwr++;
47707+
47708+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
47709+ return newtable;
47710+
47711+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
47712+ newtable =
47713+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
47714+ else
47715+ newtable = vmalloc(table_sizes[pwr] * elementsize);
47716+
47717+ *len = table_sizes[pwr];
47718+
47719+ return newtable;
47720+}
47721+
47722+static int
47723+init_variables(const struct gr_arg *arg)
47724+{
47725+ struct task_struct *reaper = &init_task;
47726+ unsigned int stacksize;
47727+
47728+ subj_map_set.s_size = arg->role_db.num_subjects;
47729+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
47730+ name_set.n_size = arg->role_db.num_objects;
47731+ inodev_set.i_size = arg->role_db.num_objects;
47732+
47733+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
47734+ !name_set.n_size || !inodev_set.i_size)
47735+ return 1;
47736+
47737+ if (!gr_init_uidset())
47738+ return 1;
47739+
47740+ /* set up the stack that holds allocation info */
47741+
47742+ stacksize = arg->role_db.num_pointers + 5;
47743+
47744+ if (!acl_alloc_stack_init(stacksize))
47745+ return 1;
47746+
47747+ /* grab reference for the real root dentry and vfsmount */
47748+ read_lock(&reaper->fs->lock);
47749+ real_root = dget(reaper->fs->root.dentry);
47750+ real_root_mnt = mntget(reaper->fs->root.mnt);
47751+ read_unlock(&reaper->fs->lock);
47752+
47753+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
47754+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
47755+#endif
47756+
47757+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
47758+ if (fakefs_obj_rw == NULL)
47759+ return 1;
47760+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
47761+
47762+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
47763+ if (fakefs_obj_rwx == NULL)
47764+ return 1;
47765+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
47766+
47767+ subj_map_set.s_hash =
47768+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
47769+ acl_role_set.r_hash =
47770+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
47771+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
47772+ inodev_set.i_hash =
47773+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
47774+
47775+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
47776+ !name_set.n_hash || !inodev_set.i_hash)
47777+ return 1;
47778+
47779+ memset(subj_map_set.s_hash, 0,
47780+ sizeof(struct subject_map *) * subj_map_set.s_size);
47781+ memset(acl_role_set.r_hash, 0,
47782+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
47783+ memset(name_set.n_hash, 0,
47784+ sizeof (struct name_entry *) * name_set.n_size);
47785+ memset(inodev_set.i_hash, 0,
47786+ sizeof (struct inodev_entry *) * inodev_set.i_size);
47787+
47788+ return 0;
47789+}
47790+
47791+/* free information not needed after startup
47792+ currently contains user->kernel pointer mappings for subjects
47793+*/
47794+
47795+static void
47796+free_init_variables(void)
47797+{
47798+ __u32 i;
47799+
47800+ if (subj_map_set.s_hash) {
47801+ for (i = 0; i < subj_map_set.s_size; i++) {
47802+ if (subj_map_set.s_hash[i]) {
47803+ kfree(subj_map_set.s_hash[i]);
47804+ subj_map_set.s_hash[i] = NULL;
47805+ }
47806+ }
47807+
47808+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
47809+ PAGE_SIZE)
47810+ kfree(subj_map_set.s_hash);
47811+ else
47812+ vfree(subj_map_set.s_hash);
47813+ }
47814+
47815+ return;
47816+}
47817+
47818+static void
47819+free_variables(void)
47820+{
47821+ struct acl_subject_label *s;
47822+ struct acl_role_label *r;
47823+ struct task_struct *task, *task2;
47824+ unsigned int x;
47825+
47826+ gr_clear_learn_entries();
47827+
47828+ read_lock(&tasklist_lock);
47829+ do_each_thread(task2, task) {
47830+ task->acl_sp_role = 0;
47831+ task->acl_role_id = 0;
47832+ task->acl = NULL;
47833+ task->role = NULL;
47834+ } while_each_thread(task2, task);
47835+ read_unlock(&tasklist_lock);
47836+
47837+ /* release the reference to the real root dentry and vfsmount */
47838+ if (real_root)
47839+ dput(real_root);
47840+ real_root = NULL;
47841+ if (real_root_mnt)
47842+ mntput(real_root_mnt);
47843+ real_root_mnt = NULL;
47844+
47845+ /* free all object hash tables */
47846+
47847+ FOR_EACH_ROLE_START(r)
47848+ if (r->subj_hash == NULL)
47849+ goto next_role;
47850+ FOR_EACH_SUBJECT_START(r, s, x)
47851+ if (s->obj_hash == NULL)
47852+ break;
47853+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
47854+ kfree(s->obj_hash);
47855+ else
47856+ vfree(s->obj_hash);
47857+ FOR_EACH_SUBJECT_END(s, x)
47858+ FOR_EACH_NESTED_SUBJECT_START(r, s)
47859+ if (s->obj_hash == NULL)
47860+ break;
47861+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
47862+ kfree(s->obj_hash);
47863+ else
47864+ vfree(s->obj_hash);
47865+ FOR_EACH_NESTED_SUBJECT_END(s)
47866+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
47867+ kfree(r->subj_hash);
47868+ else
47869+ vfree(r->subj_hash);
47870+ r->subj_hash = NULL;
47871+next_role:
47872+ FOR_EACH_ROLE_END(r)
47873+
47874+ acl_free_all();
47875+
47876+ if (acl_role_set.r_hash) {
47877+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
47878+ PAGE_SIZE)
47879+ kfree(acl_role_set.r_hash);
47880+ else
47881+ vfree(acl_role_set.r_hash);
47882+ }
47883+ if (name_set.n_hash) {
47884+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
47885+ PAGE_SIZE)
47886+ kfree(name_set.n_hash);
47887+ else
47888+ vfree(name_set.n_hash);
47889+ }
47890+
47891+ if (inodev_set.i_hash) {
47892+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
47893+ PAGE_SIZE)
47894+ kfree(inodev_set.i_hash);
47895+ else
47896+ vfree(inodev_set.i_hash);
47897+ }
47898+
47899+ gr_free_uidset();
47900+
47901+ memset(&name_set, 0, sizeof (struct name_db));
47902+ memset(&inodev_set, 0, sizeof (struct inodev_db));
47903+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
47904+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
47905+
47906+ default_role = NULL;
47907+ role_list = NULL;
47908+
47909+ return;
47910+}
47911+
47912+static __u32
47913+count_user_objs(struct acl_object_label *userp)
47914+{
47915+ struct acl_object_label o_tmp;
47916+ __u32 num = 0;
47917+
47918+ while (userp) {
47919+ if (copy_from_user(&o_tmp, userp,
47920+ sizeof (struct acl_object_label)))
47921+ break;
47922+
47923+ userp = o_tmp.prev;
47924+ num++;
47925+ }
47926+
47927+ return num;
47928+}
47929+
47930+static struct acl_subject_label *
47931+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
47932+
47933+static int
47934+copy_user_glob(struct acl_object_label *obj)
47935+{
47936+ struct acl_object_label *g_tmp, **guser;
47937+ unsigned int len;
47938+ char *tmp;
47939+
47940+ if (obj->globbed == NULL)
47941+ return 0;
47942+
47943+ guser = &obj->globbed;
47944+ while (*guser) {
47945+ g_tmp = (struct acl_object_label *)
47946+ acl_alloc(sizeof (struct acl_object_label));
47947+ if (g_tmp == NULL)
47948+ return -ENOMEM;
47949+
47950+ if (copy_from_user(g_tmp, *guser,
47951+ sizeof (struct acl_object_label)))
47952+ return -EFAULT;
47953+
47954+ len = strnlen_user(g_tmp->filename, PATH_MAX);
47955+
47956+ if (!len || len >= PATH_MAX)
47957+ return -EINVAL;
47958+
47959+ if ((tmp = (char *) acl_alloc(len)) == NULL)
47960+ return -ENOMEM;
47961+
47962+ if (copy_from_user(tmp, g_tmp->filename, len))
47963+ return -EFAULT;
47964+ tmp[len-1] = '\0';
47965+ g_tmp->filename = tmp;
47966+
47967+ *guser = g_tmp;
47968+ guser = &(g_tmp->next);
47969+ }
47970+
47971+ return 0;
47972+}
47973+
47974+static int
47975+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
47976+ struct acl_role_label *role)
47977+{
47978+ struct acl_object_label *o_tmp;
47979+ unsigned int len;
47980+ int ret;
47981+ char *tmp;
47982+
47983+ while (userp) {
47984+ if ((o_tmp = (struct acl_object_label *)
47985+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
47986+ return -ENOMEM;
47987+
47988+ if (copy_from_user(o_tmp, userp,
47989+ sizeof (struct acl_object_label)))
47990+ return -EFAULT;
47991+
47992+ userp = o_tmp->prev;
47993+
47994+ len = strnlen_user(o_tmp->filename, PATH_MAX);
47995+
47996+ if (!len || len >= PATH_MAX)
47997+ return -EINVAL;
47998+
47999+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48000+ return -ENOMEM;
48001+
48002+ if (copy_from_user(tmp, o_tmp->filename, len))
48003+ return -EFAULT;
48004+ tmp[len-1] = '\0';
48005+ o_tmp->filename = tmp;
48006+
48007+ insert_acl_obj_label(o_tmp, subj);
48008+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
48009+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
48010+ return -ENOMEM;
48011+
48012+ ret = copy_user_glob(o_tmp);
48013+ if (ret)
48014+ return ret;
48015+
48016+ if (o_tmp->nested) {
48017+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
48018+ if (IS_ERR(o_tmp->nested))
48019+ return PTR_ERR(o_tmp->nested);
48020+
48021+ /* insert into nested subject list */
48022+ o_tmp->nested->next = role->hash->first;
48023+ role->hash->first = o_tmp->nested;
48024+ }
48025+ }
48026+
48027+ return 0;
48028+}
48029+
48030+static __u32
48031+count_user_subjs(struct acl_subject_label *userp)
48032+{
48033+ struct acl_subject_label s_tmp;
48034+ __u32 num = 0;
48035+
48036+ while (userp) {
48037+ if (copy_from_user(&s_tmp, userp,
48038+ sizeof (struct acl_subject_label)))
48039+ break;
48040+
48041+ userp = s_tmp.prev;
48042+ /* do not count nested subjects against this count, since
48043+ they are not included in the hash table, but are
48044+ attached to objects. We have already counted
48045+ the subjects in userspace for the allocation
48046+ stack
48047+ */
48048+ if (!(s_tmp.mode & GR_NESTED))
48049+ num++;
48050+ }
48051+
48052+ return num;
48053+}
48054+
48055+static int
48056+copy_user_allowedips(struct acl_role_label *rolep)
48057+{
48058+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
48059+
48060+ ruserip = rolep->allowed_ips;
48061+
48062+ while (ruserip) {
48063+ rlast = rtmp;
48064+
48065+ if ((rtmp = (struct role_allowed_ip *)
48066+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
48067+ return -ENOMEM;
48068+
48069+ if (copy_from_user(rtmp, ruserip,
48070+ sizeof (struct role_allowed_ip)))
48071+ return -EFAULT;
48072+
48073+ ruserip = rtmp->prev;
48074+
48075+ if (!rlast) {
48076+ rtmp->prev = NULL;
48077+ rolep->allowed_ips = rtmp;
48078+ } else {
48079+ rlast->next = rtmp;
48080+ rtmp->prev = rlast;
48081+ }
48082+
48083+ if (!ruserip)
48084+ rtmp->next = NULL;
48085+ }
48086+
48087+ return 0;
48088+}
48089+
48090+static int
48091+copy_user_transitions(struct acl_role_label *rolep)
48092+{
48093+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
48094+
48095+ unsigned int len;
48096+ char *tmp;
48097+
48098+ rusertp = rolep->transitions;
48099+
48100+ while (rusertp) {
48101+ rlast = rtmp;
48102+
48103+ if ((rtmp = (struct role_transition *)
48104+ acl_alloc(sizeof (struct role_transition))) == NULL)
48105+ return -ENOMEM;
48106+
48107+ if (copy_from_user(rtmp, rusertp,
48108+ sizeof (struct role_transition)))
48109+ return -EFAULT;
48110+
48111+ rusertp = rtmp->prev;
48112+
48113+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
48114+
48115+ if (!len || len >= GR_SPROLE_LEN)
48116+ return -EINVAL;
48117+
48118+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48119+ return -ENOMEM;
48120+
48121+ if (copy_from_user(tmp, rtmp->rolename, len))
48122+ return -EFAULT;
48123+ tmp[len-1] = '\0';
48124+ rtmp->rolename = tmp;
48125+
48126+ if (!rlast) {
48127+ rtmp->prev = NULL;
48128+ rolep->transitions = rtmp;
48129+ } else {
48130+ rlast->next = rtmp;
48131+ rtmp->prev = rlast;
48132+ }
48133+
48134+ if (!rusertp)
48135+ rtmp->next = NULL;
48136+ }
48137+
48138+ return 0;
48139+}
48140+
48141+static struct acl_subject_label *
48142+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
48143+{
48144+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
48145+ unsigned int len;
48146+ char *tmp;
48147+ __u32 num_objs;
48148+ struct acl_ip_label **i_tmp, *i_utmp2;
48149+ struct gr_hash_struct ghash;
48150+ struct subject_map *subjmap;
48151+ unsigned int i_num;
48152+ int err;
48153+
48154+ s_tmp = lookup_subject_map(userp);
48155+
48156+ /* we've already copied this subject into the kernel, just return
48157+ the reference to it, and don't copy it over again
48158+ */
48159+ if (s_tmp)
48160+ return(s_tmp);
48161+
48162+ if ((s_tmp = (struct acl_subject_label *)
48163+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
48164+ return ERR_PTR(-ENOMEM);
48165+
48166+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
48167+ if (subjmap == NULL)
48168+ return ERR_PTR(-ENOMEM);
48169+
48170+ subjmap->user = userp;
48171+ subjmap->kernel = s_tmp;
48172+ insert_subj_map_entry(subjmap);
48173+
48174+ if (copy_from_user(s_tmp, userp,
48175+ sizeof (struct acl_subject_label)))
48176+ return ERR_PTR(-EFAULT);
48177+
48178+ len = strnlen_user(s_tmp->filename, PATH_MAX);
48179+
48180+ if (!len || len >= PATH_MAX)
48181+ return ERR_PTR(-EINVAL);
48182+
48183+ if ((tmp = (char *) acl_alloc(len)) == NULL)
48184+ return ERR_PTR(-ENOMEM);
48185+
48186+ if (copy_from_user(tmp, s_tmp->filename, len))
48187+ return ERR_PTR(-EFAULT);
48188+ tmp[len-1] = '\0';
48189+ s_tmp->filename = tmp;
48190+
48191+ if (!strcmp(s_tmp->filename, "/"))
48192+ role->root_label = s_tmp;
48193+
48194+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
48195+ return ERR_PTR(-EFAULT);
48196+
48197+ /* copy user and group transition tables */
48198+
48199+ if (s_tmp->user_trans_num) {
48200+ uid_t *uidlist;
48201+
48202+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
48203+ if (uidlist == NULL)
48204+ return ERR_PTR(-ENOMEM);
48205+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
48206+ return ERR_PTR(-EFAULT);
48207+
48208+ s_tmp->user_transitions = uidlist;
48209+ }
48210+
48211+ if (s_tmp->group_trans_num) {
48212+ gid_t *gidlist;
48213+
48214+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
48215+ if (gidlist == NULL)
48216+ return ERR_PTR(-ENOMEM);
48217+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
48218+ return ERR_PTR(-EFAULT);
48219+
48220+ s_tmp->group_transitions = gidlist;
48221+ }
48222+
48223+ /* set up object hash table */
48224+ num_objs = count_user_objs(ghash.first);
48225+
48226+ s_tmp->obj_hash_size = num_objs;
48227+ s_tmp->obj_hash =
48228+ (struct acl_object_label **)
48229+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
48230+
48231+ if (!s_tmp->obj_hash)
48232+ return ERR_PTR(-ENOMEM);
48233+
48234+ memset(s_tmp->obj_hash, 0,
48235+ s_tmp->obj_hash_size *
48236+ sizeof (struct acl_object_label *));
48237+
48238+ /* add in objects */
48239+ err = copy_user_objs(ghash.first, s_tmp, role);
48240+
48241+ if (err)
48242+ return ERR_PTR(err);
48243+
48244+ /* set pointer for parent subject */
48245+ if (s_tmp->parent_subject) {
48246+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
48247+
48248+ if (IS_ERR(s_tmp2))
48249+ return s_tmp2;
48250+
48251+ s_tmp->parent_subject = s_tmp2;
48252+ }
48253+
48254+ /* add in ip acls */
48255+
48256+ if (!s_tmp->ip_num) {
48257+ s_tmp->ips = NULL;
48258+ goto insert;
48259+ }
48260+
48261+ i_tmp =
48262+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
48263+ sizeof (struct acl_ip_label *));
48264+
48265+ if (!i_tmp)
48266+ return ERR_PTR(-ENOMEM);
48267+
48268+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
48269+ *(i_tmp + i_num) =
48270+ (struct acl_ip_label *)
48271+ acl_alloc(sizeof (struct acl_ip_label));
48272+ if (!*(i_tmp + i_num))
48273+ return ERR_PTR(-ENOMEM);
48274+
48275+ if (copy_from_user
48276+ (&i_utmp2, s_tmp->ips + i_num,
48277+ sizeof (struct acl_ip_label *)))
48278+ return ERR_PTR(-EFAULT);
48279+
48280+ if (copy_from_user
48281+ (*(i_tmp + i_num), i_utmp2,
48282+ sizeof (struct acl_ip_label)))
48283+ return ERR_PTR(-EFAULT);
48284+
48285+ if ((*(i_tmp + i_num))->iface == NULL)
48286+ continue;
48287+
48288+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
48289+ if (!len || len >= IFNAMSIZ)
48290+ return ERR_PTR(-EINVAL);
48291+ tmp = acl_alloc(len);
48292+ if (tmp == NULL)
48293+ return ERR_PTR(-ENOMEM);
48294+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
48295+ return ERR_PTR(-EFAULT);
48296+ (*(i_tmp + i_num))->iface = tmp;
48297+ }
48298+
48299+ s_tmp->ips = i_tmp;
48300+
48301+insert:
48302+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
48303+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
48304+ return ERR_PTR(-ENOMEM);
48305+
48306+ return s_tmp;
48307+}
48308+
48309+static int
48310+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
48311+{
48312+ struct acl_subject_label s_pre;
48313+ struct acl_subject_label * ret;
48314+ int err;
48315+
48316+ while (userp) {
48317+ if (copy_from_user(&s_pre, userp,
48318+ sizeof (struct acl_subject_label)))
48319+ return -EFAULT;
48320+
48321+ /* do not add nested subjects here, add
48322+ while parsing objects
48323+ */
48324+
48325+ if (s_pre.mode & GR_NESTED) {
48326+ userp = s_pre.prev;
48327+ continue;
48328+ }
48329+
48330+ ret = do_copy_user_subj(userp, role);
48331+
48332+ err = PTR_ERR(ret);
48333+ if (IS_ERR(ret))
48334+ return err;
48335+
48336+ insert_acl_subj_label(ret, role);
48337+
48338+ userp = s_pre.prev;
48339+ }
48340+
48341+ return 0;
48342+}
48343+
48344+static int
48345+copy_user_acl(struct gr_arg *arg)
48346+{
48347+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
48348+ struct sprole_pw *sptmp;
48349+ struct gr_hash_struct *ghash;
48350+ uid_t *domainlist;
48351+ unsigned int r_num;
48352+ unsigned int len;
48353+ char *tmp;
48354+ int err = 0;
48355+ __u16 i;
48356+ __u32 num_subjs;
48357+
48358+ /* we need a default and kernel role */
48359+ if (arg->role_db.num_roles < 2)
48360+ return -EINVAL;
48361+
48362+ /* copy special role authentication info from userspace */
48363+
48364+ num_sprole_pws = arg->num_sprole_pws;
48365+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
48366+
48367+ if (!acl_special_roles) {
48368+ err = -ENOMEM;
48369+ goto cleanup;
48370+ }
48371+
48372+ for (i = 0; i < num_sprole_pws; i++) {
48373+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
48374+ if (!sptmp) {
48375+ err = -ENOMEM;
48376+ goto cleanup;
48377+ }
48378+ if (copy_from_user(sptmp, arg->sprole_pws + i,
48379+ sizeof (struct sprole_pw))) {
48380+ err = -EFAULT;
48381+ goto cleanup;
48382+ }
48383+
48384+ len =
48385+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
48386+
48387+ if (!len || len >= GR_SPROLE_LEN) {
48388+ err = -EINVAL;
48389+ goto cleanup;
48390+ }
48391+
48392+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
48393+ err = -ENOMEM;
48394+ goto cleanup;
48395+ }
48396+
48397+ if (copy_from_user(tmp, sptmp->rolename, len)) {
48398+ err = -EFAULT;
48399+ goto cleanup;
48400+ }
48401+ tmp[len-1] = '\0';
48402+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
48403+ printk(KERN_ALERT "Copying special role %s\n", tmp);
48404+#endif
48405+ sptmp->rolename = tmp;
48406+ acl_special_roles[i] = sptmp;
48407+ }
48408+
48409+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
48410+
48411+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
48412+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
48413+
48414+ if (!r_tmp) {
48415+ err = -ENOMEM;
48416+ goto cleanup;
48417+ }
48418+
48419+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
48420+ sizeof (struct acl_role_label *))) {
48421+ err = -EFAULT;
48422+ goto cleanup;
48423+ }
48424+
48425+ if (copy_from_user(r_tmp, r_utmp2,
48426+ sizeof (struct acl_role_label))) {
48427+ err = -EFAULT;
48428+ goto cleanup;
48429+ }
48430+
48431+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
48432+
48433+ if (!len || len >= PATH_MAX) {
48434+ err = -EINVAL;
48435+ goto cleanup;
48436+ }
48437+
48438+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
48439+ err = -ENOMEM;
48440+ goto cleanup;
48441+ }
48442+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
48443+ err = -EFAULT;
48444+ goto cleanup;
48445+ }
48446+ tmp[len-1] = '\0';
48447+ r_tmp->rolename = tmp;
48448+
48449+ if (!strcmp(r_tmp->rolename, "default")
48450+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
48451+ default_role = r_tmp;
48452+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
48453+ kernel_role = r_tmp;
48454+ }
48455+
48456+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
48457+ err = -ENOMEM;
48458+ goto cleanup;
48459+ }
48460+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
48461+ err = -EFAULT;
48462+ goto cleanup;
48463+ }
48464+
48465+ r_tmp->hash = ghash;
48466+
48467+ num_subjs = count_user_subjs(r_tmp->hash->first);
48468+
48469+ r_tmp->subj_hash_size = num_subjs;
48470+ r_tmp->subj_hash =
48471+ (struct acl_subject_label **)
48472+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
48473+
48474+ if (!r_tmp->subj_hash) {
48475+ err = -ENOMEM;
48476+ goto cleanup;
48477+ }
48478+
48479+ err = copy_user_allowedips(r_tmp);
48480+ if (err)
48481+ goto cleanup;
48482+
48483+ /* copy domain info */
48484+ if (r_tmp->domain_children != NULL) {
48485+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
48486+ if (domainlist == NULL) {
48487+ err = -ENOMEM;
48488+ goto cleanup;
48489+ }
48490+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
48491+ err = -EFAULT;
48492+ goto cleanup;
48493+ }
48494+ r_tmp->domain_children = domainlist;
48495+ }
48496+
48497+ err = copy_user_transitions(r_tmp);
48498+ if (err)
48499+ goto cleanup;
48500+
48501+ memset(r_tmp->subj_hash, 0,
48502+ r_tmp->subj_hash_size *
48503+ sizeof (struct acl_subject_label *));
48504+
48505+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
48506+
48507+ if (err)
48508+ goto cleanup;
48509+
48510+ /* set nested subject list to null */
48511+ r_tmp->hash->first = NULL;
48512+
48513+ insert_acl_role_label(r_tmp);
48514+ }
48515+
48516+ goto return_err;
48517+ cleanup:
48518+ free_variables();
48519+ return_err:
48520+ return err;
48521+
48522+}
48523+
48524+static int
48525+gracl_init(struct gr_arg *args)
48526+{
48527+ int error = 0;
48528+
48529+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
48530+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
48531+
48532+ if (init_variables(args)) {
48533+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
48534+ error = -ENOMEM;
48535+ free_variables();
48536+ goto out;
48537+ }
48538+
48539+ error = copy_user_acl(args);
48540+ free_init_variables();
48541+ if (error) {
48542+ free_variables();
48543+ goto out;
48544+ }
48545+
48546+ if ((error = gr_set_acls(0))) {
48547+ free_variables();
48548+ goto out;
48549+ }
48550+
48551+ pax_open_kernel();
48552+ gr_status |= GR_READY;
48553+ pax_close_kernel();
48554+
48555+ out:
48556+ return error;
48557+}
48558+
48559+/* derived from glibc fnmatch() 0: match, 1: no match*/
48560+
48561+static int
48562+glob_match(const char *p, const char *n)
48563+{
48564+ char c;
48565+
48566+ while ((c = *p++) != '\0') {
48567+ switch (c) {
48568+ case '?':
48569+ if (*n == '\0')
48570+ return 1;
48571+ else if (*n == '/')
48572+ return 1;
48573+ break;
48574+ case '\\':
48575+ if (*n != c)
48576+ return 1;
48577+ break;
48578+ case '*':
48579+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
48580+ if (*n == '/')
48581+ return 1;
48582+ else if (c == '?') {
48583+ if (*n == '\0')
48584+ return 1;
48585+ else
48586+ ++n;
48587+ }
48588+ }
48589+ if (c == '\0') {
48590+ return 0;
48591+ } else {
48592+ const char *endp;
48593+
48594+ if ((endp = strchr(n, '/')) == NULL)
48595+ endp = n + strlen(n);
48596+
48597+ if (c == '[') {
48598+ for (--p; n < endp; ++n)
48599+ if (!glob_match(p, n))
48600+ return 0;
48601+ } else if (c == '/') {
48602+ while (*n != '\0' && *n != '/')
48603+ ++n;
48604+ if (*n == '/' && !glob_match(p, n + 1))
48605+ return 0;
48606+ } else {
48607+ for (--p; n < endp; ++n)
48608+ if (*n == c && !glob_match(p, n))
48609+ return 0;
48610+ }
48611+
48612+ return 1;
48613+ }
48614+ case '[':
48615+ {
48616+ int not;
48617+ char cold;
48618+
48619+ if (*n == '\0' || *n == '/')
48620+ return 1;
48621+
48622+ not = (*p == '!' || *p == '^');
48623+ if (not)
48624+ ++p;
48625+
48626+ c = *p++;
48627+ for (;;) {
48628+ unsigned char fn = (unsigned char)*n;
48629+
48630+ if (c == '\0')
48631+ return 1;
48632+ else {
48633+ if (c == fn)
48634+ goto matched;
48635+ cold = c;
48636+ c = *p++;
48637+
48638+ if (c == '-' && *p != ']') {
48639+ unsigned char cend = *p++;
48640+
48641+ if (cend == '\0')
48642+ return 1;
48643+
48644+ if (cold <= fn && fn <= cend)
48645+ goto matched;
48646+
48647+ c = *p++;
48648+ }
48649+ }
48650+
48651+ if (c == ']')
48652+ break;
48653+ }
48654+ if (!not)
48655+ return 1;
48656+ break;
48657+ matched:
48658+ while (c != ']') {
48659+ if (c == '\0')
48660+ return 1;
48661+
48662+ c = *p++;
48663+ }
48664+ if (not)
48665+ return 1;
48666+ }
48667+ break;
48668+ default:
48669+ if (c != *n)
48670+ return 1;
48671+ }
48672+
48673+ ++n;
48674+ }
48675+
48676+ if (*n == '\0')
48677+ return 0;
48678+
48679+ if (*n == '/')
48680+ return 0;
48681+
48682+ return 1;
48683+}
48684+
48685+static struct acl_object_label *
48686+chk_glob_label(struct acl_object_label *globbed,
48687+ struct dentry *dentry, struct vfsmount *mnt, char **path)
48688+{
48689+ struct acl_object_label *tmp;
48690+
48691+ if (*path == NULL)
48692+ *path = gr_to_filename_nolock(dentry, mnt);
48693+
48694+ tmp = globbed;
48695+
48696+ while (tmp) {
48697+ if (!glob_match(tmp->filename, *path))
48698+ return tmp;
48699+ tmp = tmp->next;
48700+ }
48701+
48702+ return NULL;
48703+}
48704+
48705+static struct acl_object_label *
48706+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
48707+ const ino_t curr_ino, const dev_t curr_dev,
48708+ const struct acl_subject_label *subj, char **path, const int checkglob)
48709+{
48710+ struct acl_subject_label *tmpsubj;
48711+ struct acl_object_label *retval;
48712+ struct acl_object_label *retval2;
48713+
48714+ tmpsubj = (struct acl_subject_label *) subj;
48715+ read_lock(&gr_inode_lock);
48716+ do {
48717+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
48718+ if (retval) {
48719+ if (checkglob && retval->globbed) {
48720+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
48721+ (struct vfsmount *)orig_mnt, path);
48722+ if (retval2)
48723+ retval = retval2;
48724+ }
48725+ break;
48726+ }
48727+ } while ((tmpsubj = tmpsubj->parent_subject));
48728+ read_unlock(&gr_inode_lock);
48729+
48730+ return retval;
48731+}
48732+
48733+static __inline__ struct acl_object_label *
48734+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
48735+ const struct dentry *curr_dentry,
48736+ const struct acl_subject_label *subj, char **path, const int checkglob)
48737+{
48738+ int newglob = checkglob;
48739+
48740+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
48741+ as we don't want a / * rule to match instead of the / object
48742+ don't do this for create lookups that call this function though, since they're looking up
48743+ on the parent and thus need globbing checks on all paths
48744+ */
48745+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
48746+ newglob = GR_NO_GLOB;
48747+
48748+ return __full_lookup(orig_dentry, orig_mnt,
48749+ curr_dentry->d_inode->i_ino,
48750+ __get_dev(curr_dentry), subj, path, newglob);
48751+}
48752+
48753+static struct acl_object_label *
48754+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
48755+ const struct acl_subject_label *subj, char *path, const int checkglob)
48756+{
48757+ struct dentry *dentry = (struct dentry *) l_dentry;
48758+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
48759+ struct acl_object_label *retval;
48760+
48761+ spin_lock(&dcache_lock);
48762+ spin_lock(&vfsmount_lock);
48763+
48764+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
48765+#ifdef CONFIG_NET
48766+ mnt == sock_mnt ||
48767+#endif
48768+#ifdef CONFIG_HUGETLBFS
48769+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
48770+#endif
48771+ /* ignore Eric Biederman */
48772+ IS_PRIVATE(l_dentry->d_inode))) {
48773+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
48774+ goto out;
48775+ }
48776+
48777+ for (;;) {
48778+ if (dentry == real_root && mnt == real_root_mnt)
48779+ break;
48780+
48781+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
48782+ if (mnt->mnt_parent == mnt)
48783+ break;
48784+
48785+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
48786+ if (retval != NULL)
48787+ goto out;
48788+
48789+ dentry = mnt->mnt_mountpoint;
48790+ mnt = mnt->mnt_parent;
48791+ continue;
48792+ }
48793+
48794+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
48795+ if (retval != NULL)
48796+ goto out;
48797+
48798+ dentry = dentry->d_parent;
48799+ }
48800+
48801+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
48802+
48803+ if (retval == NULL)
48804+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
48805+out:
48806+ spin_unlock(&vfsmount_lock);
48807+ spin_unlock(&dcache_lock);
48808+
48809+ BUG_ON(retval == NULL);
48810+
48811+ return retval;
48812+}
48813+
48814+static __inline__ struct acl_object_label *
48815+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
48816+ const struct acl_subject_label *subj)
48817+{
48818+ char *path = NULL;
48819+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
48820+}
48821+
48822+static __inline__ struct acl_object_label *
48823+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
48824+ const struct acl_subject_label *subj)
48825+{
48826+ char *path = NULL;
48827+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
48828+}
48829+
48830+static __inline__ struct acl_object_label *
48831+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
48832+ const struct acl_subject_label *subj, char *path)
48833+{
48834+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
48835+}
48836+
48837+static struct acl_subject_label *
48838+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
48839+ const struct acl_role_label *role)
48840+{
48841+ struct dentry *dentry = (struct dentry *) l_dentry;
48842+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
48843+ struct acl_subject_label *retval;
48844+
48845+ spin_lock(&dcache_lock);
48846+ spin_lock(&vfsmount_lock);
48847+
48848+ for (;;) {
48849+ if (dentry == real_root && mnt == real_root_mnt)
48850+ break;
48851+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
48852+ if (mnt->mnt_parent == mnt)
48853+ break;
48854+
48855+ read_lock(&gr_inode_lock);
48856+ retval =
48857+ lookup_acl_subj_label(dentry->d_inode->i_ino,
48858+ __get_dev(dentry), role);
48859+ read_unlock(&gr_inode_lock);
48860+ if (retval != NULL)
48861+ goto out;
48862+
48863+ dentry = mnt->mnt_mountpoint;
48864+ mnt = mnt->mnt_parent;
48865+ continue;
48866+ }
48867+
48868+ read_lock(&gr_inode_lock);
48869+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
48870+ __get_dev(dentry), role);
48871+ read_unlock(&gr_inode_lock);
48872+ if (retval != NULL)
48873+ goto out;
48874+
48875+ dentry = dentry->d_parent;
48876+ }
48877+
48878+ read_lock(&gr_inode_lock);
48879+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
48880+ __get_dev(dentry), role);
48881+ read_unlock(&gr_inode_lock);
48882+
48883+ if (unlikely(retval == NULL)) {
48884+ read_lock(&gr_inode_lock);
48885+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
48886+ __get_dev(real_root), role);
48887+ read_unlock(&gr_inode_lock);
48888+ }
48889+out:
48890+ spin_unlock(&vfsmount_lock);
48891+ spin_unlock(&dcache_lock);
48892+
48893+ BUG_ON(retval == NULL);
48894+
48895+ return retval;
48896+}
48897+
48898+static void
48899+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
48900+{
48901+ struct task_struct *task = current;
48902+ const struct cred *cred = current_cred();
48903+
48904+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
48905+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
48906+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
48907+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
48908+
48909+ return;
48910+}
48911+
48912+static void
48913+gr_log_learn_sysctl(const char *path, const __u32 mode)
48914+{
48915+ struct task_struct *task = current;
48916+ const struct cred *cred = current_cred();
48917+
48918+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
48919+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
48920+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
48921+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
48922+
48923+ return;
48924+}
48925+
48926+static void
48927+gr_log_learn_id_change(const char type, const unsigned int real,
48928+ const unsigned int effective, const unsigned int fs)
48929+{
48930+ struct task_struct *task = current;
48931+ const struct cred *cred = current_cred();
48932+
48933+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
48934+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
48935+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
48936+ type, real, effective, fs, &task->signal->saved_ip);
48937+
48938+ return;
48939+}
48940+
48941+__u32
48942+gr_check_link(const struct dentry * new_dentry,
48943+ const struct dentry * parent_dentry,
48944+ const struct vfsmount * parent_mnt,
48945+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
48946+{
48947+ struct acl_object_label *obj;
48948+ __u32 oldmode, newmode;
48949+ __u32 needmode;
48950+
48951+ if (unlikely(!(gr_status & GR_READY)))
48952+ return (GR_CREATE | GR_LINK);
48953+
48954+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
48955+ oldmode = obj->mode;
48956+
48957+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
48958+ oldmode |= (GR_CREATE | GR_LINK);
48959+
48960+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
48961+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
48962+ needmode |= GR_SETID | GR_AUDIT_SETID;
48963+
48964+ newmode =
48965+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
48966+ oldmode | needmode);
48967+
48968+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
48969+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
48970+ GR_INHERIT | GR_AUDIT_INHERIT);
48971+
48972+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
48973+ goto bad;
48974+
48975+ if ((oldmode & needmode) != needmode)
48976+ goto bad;
48977+
48978+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
48979+ if ((newmode & needmode) != needmode)
48980+ goto bad;
48981+
48982+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
48983+ return newmode;
48984+bad:
48985+ needmode = oldmode;
48986+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
48987+ needmode |= GR_SETID;
48988+
48989+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
48990+ gr_log_learn(old_dentry, old_mnt, needmode);
48991+ return (GR_CREATE | GR_LINK);
48992+ } else if (newmode & GR_SUPPRESS)
48993+ return GR_SUPPRESS;
48994+ else
48995+ return 0;
48996+}
48997+
48998+__u32
48999+gr_search_file(const struct dentry * dentry, const __u32 mode,
49000+ const struct vfsmount * mnt)
49001+{
49002+ __u32 retval = mode;
49003+ struct acl_subject_label *curracl;
49004+ struct acl_object_label *currobj;
49005+
49006+ if (unlikely(!(gr_status & GR_READY)))
49007+ return (mode & ~GR_AUDITS);
49008+
49009+ curracl = current->acl;
49010+
49011+ currobj = chk_obj_label(dentry, mnt, curracl);
49012+ retval = currobj->mode & mode;
49013+
49014+ /* if we're opening a specified transfer file for writing
49015+ (e.g. /dev/initctl), then transfer our role to init
49016+ */
49017+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
49018+ current->role->roletype & GR_ROLE_PERSIST)) {
49019+ struct task_struct *task = init_pid_ns.child_reaper;
49020+
49021+ if (task->role != current->role) {
49022+ task->acl_sp_role = 0;
49023+ task->acl_role_id = current->acl_role_id;
49024+ task->role = current->role;
49025+ rcu_read_lock();
49026+ read_lock(&grsec_exec_file_lock);
49027+ gr_apply_subject_to_task(task);
49028+ read_unlock(&grsec_exec_file_lock);
49029+ rcu_read_unlock();
49030+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
49031+ }
49032+ }
49033+
49034+ if (unlikely
49035+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
49036+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
49037+ __u32 new_mode = mode;
49038+
49039+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
49040+
49041+ retval = new_mode;
49042+
49043+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
49044+ new_mode |= GR_INHERIT;
49045+
49046+ if (!(mode & GR_NOLEARN))
49047+ gr_log_learn(dentry, mnt, new_mode);
49048+ }
49049+
49050+ return retval;
49051+}
49052+
49053+__u32
49054+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
49055+ const struct vfsmount * mnt, const __u32 mode)
49056+{
49057+ struct name_entry *match;
49058+ struct acl_object_label *matchpo;
49059+ struct acl_subject_label *curracl;
49060+ char *path;
49061+ __u32 retval;
49062+
49063+ if (unlikely(!(gr_status & GR_READY)))
49064+ return (mode & ~GR_AUDITS);
49065+
49066+ preempt_disable();
49067+ path = gr_to_filename_rbac(new_dentry, mnt);
49068+ match = lookup_name_entry_create(path);
49069+
49070+ if (!match)
49071+ goto check_parent;
49072+
49073+ curracl = current->acl;
49074+
49075+ read_lock(&gr_inode_lock);
49076+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
49077+ read_unlock(&gr_inode_lock);
49078+
49079+ if (matchpo) {
49080+ if ((matchpo->mode & mode) !=
49081+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
49082+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
49083+ __u32 new_mode = mode;
49084+
49085+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
49086+
49087+ gr_log_learn(new_dentry, mnt, new_mode);
49088+
49089+ preempt_enable();
49090+ return new_mode;
49091+ }
49092+ preempt_enable();
49093+ return (matchpo->mode & mode);
49094+ }
49095+
49096+ check_parent:
49097+ curracl = current->acl;
49098+
49099+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
49100+ retval = matchpo->mode & mode;
49101+
49102+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
49103+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
49104+ __u32 new_mode = mode;
49105+
49106+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
49107+
49108+ gr_log_learn(new_dentry, mnt, new_mode);
49109+ preempt_enable();
49110+ return new_mode;
49111+ }
49112+
49113+ preempt_enable();
49114+ return retval;
49115+}
49116+
49117+int
49118+gr_check_hidden_task(const struct task_struct *task)
49119+{
49120+ if (unlikely(!(gr_status & GR_READY)))
49121+ return 0;
49122+
49123+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
49124+ return 1;
49125+
49126+ return 0;
49127+}
49128+
49129+int
49130+gr_check_protected_task(const struct task_struct *task)
49131+{
49132+ if (unlikely(!(gr_status & GR_READY) || !task))
49133+ return 0;
49134+
49135+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
49136+ task->acl != current->acl)
49137+ return 1;
49138+
49139+ return 0;
49140+}
49141+
49142+int
49143+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
49144+{
49145+ struct task_struct *p;
49146+ int ret = 0;
49147+
49148+ if (unlikely(!(gr_status & GR_READY) || !pid))
49149+ return ret;
49150+
49151+ read_lock(&tasklist_lock);
49152+ do_each_pid_task(pid, type, p) {
49153+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
49154+ p->acl != current->acl) {
49155+ ret = 1;
49156+ goto out;
49157+ }
49158+ } while_each_pid_task(pid, type, p);
49159+out:
49160+ read_unlock(&tasklist_lock);
49161+
49162+ return ret;
49163+}
49164+
49165+void
49166+gr_copy_label(struct task_struct *tsk)
49167+{
49168+ tsk->signal->used_accept = 0;
49169+ tsk->acl_sp_role = 0;
49170+ tsk->acl_role_id = current->acl_role_id;
49171+ tsk->acl = current->acl;
49172+ tsk->role = current->role;
49173+ tsk->signal->curr_ip = current->signal->curr_ip;
49174+ tsk->signal->saved_ip = current->signal->saved_ip;
49175+ if (current->exec_file)
49176+ get_file(current->exec_file);
49177+ tsk->exec_file = current->exec_file;
49178+ tsk->is_writable = current->is_writable;
49179+ if (unlikely(current->signal->used_accept)) {
49180+ current->signal->curr_ip = 0;
49181+ current->signal->saved_ip = 0;
49182+ }
49183+
49184+ return;
49185+}
49186+
49187+static void
49188+gr_set_proc_res(struct task_struct *task)
49189+{
49190+ struct acl_subject_label *proc;
49191+ unsigned short i;
49192+
49193+ proc = task->acl;
49194+
49195+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
49196+ return;
49197+
49198+ for (i = 0; i < RLIM_NLIMITS; i++) {
49199+ if (!(proc->resmask & (1 << i)))
49200+ continue;
49201+
49202+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
49203+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
49204+ }
49205+
49206+ return;
49207+}
49208+
49209+extern int __gr_process_user_ban(struct user_struct *user);
49210+
49211+int
49212+gr_check_user_change(int real, int effective, int fs)
49213+{
49214+ unsigned int i;
49215+ __u16 num;
49216+ uid_t *uidlist;
49217+ int curuid;
49218+ int realok = 0;
49219+ int effectiveok = 0;
49220+ int fsok = 0;
49221+
49222+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
49223+ struct user_struct *user;
49224+
49225+ if (real == -1)
49226+ goto skipit;
49227+
49228+ user = find_user(real);
49229+ if (user == NULL)
49230+ goto skipit;
49231+
49232+ if (__gr_process_user_ban(user)) {
49233+ /* for find_user */
49234+ free_uid(user);
49235+ return 1;
49236+ }
49237+
49238+ /* for find_user */
49239+ free_uid(user);
49240+
49241+skipit:
49242+#endif
49243+
49244+ if (unlikely(!(gr_status & GR_READY)))
49245+ return 0;
49246+
49247+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
49248+ gr_log_learn_id_change('u', real, effective, fs);
49249+
49250+ num = current->acl->user_trans_num;
49251+ uidlist = current->acl->user_transitions;
49252+
49253+ if (uidlist == NULL)
49254+ return 0;
49255+
49256+ if (real == -1)
49257+ realok = 1;
49258+ if (effective == -1)
49259+ effectiveok = 1;
49260+ if (fs == -1)
49261+ fsok = 1;
49262+
49263+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
49264+ for (i = 0; i < num; i++) {
49265+ curuid = (int)uidlist[i];
49266+ if (real == curuid)
49267+ realok = 1;
49268+ if (effective == curuid)
49269+ effectiveok = 1;
49270+ if (fs == curuid)
49271+ fsok = 1;
49272+ }
49273+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
49274+ for (i = 0; i < num; i++) {
49275+ curuid = (int)uidlist[i];
49276+ if (real == curuid)
49277+ break;
49278+ if (effective == curuid)
49279+ break;
49280+ if (fs == curuid)
49281+ break;
49282+ }
49283+ /* not in deny list */
49284+ if (i == num) {
49285+ realok = 1;
49286+ effectiveok = 1;
49287+ fsok = 1;
49288+ }
49289+ }
49290+
49291+ if (realok && effectiveok && fsok)
49292+ return 0;
49293+ else {
49294+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
49295+ return 1;
49296+ }
49297+}
49298+
49299+int
49300+gr_check_group_change(int real, int effective, int fs)
49301+{
49302+ unsigned int i;
49303+ __u16 num;
49304+ gid_t *gidlist;
49305+ int curgid;
49306+ int realok = 0;
49307+ int effectiveok = 0;
49308+ int fsok = 0;
49309+
49310+ if (unlikely(!(gr_status & GR_READY)))
49311+ return 0;
49312+
49313+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
49314+ gr_log_learn_id_change('g', real, effective, fs);
49315+
49316+ num = current->acl->group_trans_num;
49317+ gidlist = current->acl->group_transitions;
49318+
49319+ if (gidlist == NULL)
49320+ return 0;
49321+
49322+ if (real == -1)
49323+ realok = 1;
49324+ if (effective == -1)
49325+ effectiveok = 1;
49326+ if (fs == -1)
49327+ fsok = 1;
49328+
49329+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
49330+ for (i = 0; i < num; i++) {
49331+ curgid = (int)gidlist[i];
49332+ if (real == curgid)
49333+ realok = 1;
49334+ if (effective == curgid)
49335+ effectiveok = 1;
49336+ if (fs == curgid)
49337+ fsok = 1;
49338+ }
49339+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
49340+ for (i = 0; i < num; i++) {
49341+ curgid = (int)gidlist[i];
49342+ if (real == curgid)
49343+ break;
49344+ if (effective == curgid)
49345+ break;
49346+ if (fs == curgid)
49347+ break;
49348+ }
49349+ /* not in deny list */
49350+ if (i == num) {
49351+ realok = 1;
49352+ effectiveok = 1;
49353+ fsok = 1;
49354+ }
49355+ }
49356+
49357+ if (realok && effectiveok && fsok)
49358+ return 0;
49359+ else {
49360+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
49361+ return 1;
49362+ }
49363+}
49364+
49365+void
49366+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
49367+{
49368+ struct acl_role_label *role = task->role;
49369+ struct acl_subject_label *subj = NULL;
49370+ struct acl_object_label *obj;
49371+ struct file *filp;
49372+
49373+ if (unlikely(!(gr_status & GR_READY)))
49374+ return;
49375+
49376+ filp = task->exec_file;
49377+
49378+ /* kernel process, we'll give them the kernel role */
49379+ if (unlikely(!filp)) {
49380+ task->role = kernel_role;
49381+ task->acl = kernel_role->root_label;
49382+ return;
49383+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
49384+ role = lookup_acl_role_label(task, uid, gid);
49385+
49386+ /* perform subject lookup in possibly new role
49387+ we can use this result below in the case where role == task->role
49388+ */
49389+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
49390+
49391+ /* if we changed uid/gid, but result in the same role
49392+ and are using inheritance, don't lose the inherited subject
49393+ if current subject is other than what normal lookup
49394+ would result in, we arrived via inheritance, don't
49395+ lose subject
49396+ */
49397+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
49398+ (subj == task->acl)))
49399+ task->acl = subj;
49400+
49401+ task->role = role;
49402+
49403+ task->is_writable = 0;
49404+
49405+ /* ignore additional mmap checks for processes that are writable
49406+ by the default ACL */
49407+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
49408+ if (unlikely(obj->mode & GR_WRITE))
49409+ task->is_writable = 1;
49410+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
49411+ if (unlikely(obj->mode & GR_WRITE))
49412+ task->is_writable = 1;
49413+
49414+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49415+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
49416+#endif
49417+
49418+ gr_set_proc_res(task);
49419+
49420+ return;
49421+}
49422+
49423+int
49424+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
49425+ const int unsafe_share)
49426+{
49427+ struct task_struct *task = current;
49428+ struct acl_subject_label *newacl;
49429+ struct acl_object_label *obj;
49430+ __u32 retmode;
49431+
49432+ if (unlikely(!(gr_status & GR_READY)))
49433+ return 0;
49434+
49435+ newacl = chk_subj_label(dentry, mnt, task->role);
49436+
49437+ task_lock(task);
49438+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
49439+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
49440+ !(task->role->roletype & GR_ROLE_GOD) &&
49441+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
49442+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
49443+ task_unlock(task);
49444+ if (unsafe_share)
49445+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
49446+ else
49447+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
49448+ return -EACCES;
49449+ }
49450+ task_unlock(task);
49451+
49452+ obj = chk_obj_label(dentry, mnt, task->acl);
49453+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
49454+
49455+ if (!(task->acl->mode & GR_INHERITLEARN) &&
49456+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
49457+ if (obj->nested)
49458+ task->acl = obj->nested;
49459+ else
49460+ task->acl = newacl;
49461+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
49462+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
49463+
49464+ task->is_writable = 0;
49465+
49466+ /* ignore additional mmap checks for processes that are writable
49467+ by the default ACL */
49468+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
49469+ if (unlikely(obj->mode & GR_WRITE))
49470+ task->is_writable = 1;
49471+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
49472+ if (unlikely(obj->mode & GR_WRITE))
49473+ task->is_writable = 1;
49474+
49475+ gr_set_proc_res(task);
49476+
49477+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49478+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
49479+#endif
49480+ return 0;
49481+}
49482+
49483+/* always called with valid inodev ptr */
49484+static void
49485+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
49486+{
49487+ struct acl_object_label *matchpo;
49488+ struct acl_subject_label *matchps;
49489+ struct acl_subject_label *subj;
49490+ struct acl_role_label *role;
49491+ unsigned int x;
49492+
49493+ FOR_EACH_ROLE_START(role)
49494+ FOR_EACH_SUBJECT_START(role, subj, x)
49495+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
49496+ matchpo->mode |= GR_DELETED;
49497+ FOR_EACH_SUBJECT_END(subj,x)
49498+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
49499+ if (subj->inode == ino && subj->device == dev)
49500+ subj->mode |= GR_DELETED;
49501+ FOR_EACH_NESTED_SUBJECT_END(subj)
49502+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
49503+ matchps->mode |= GR_DELETED;
49504+ FOR_EACH_ROLE_END(role)
49505+
49506+ inodev->nentry->deleted = 1;
49507+
49508+ return;
49509+}
49510+
49511+void
49512+gr_handle_delete(const ino_t ino, const dev_t dev)
49513+{
49514+ struct inodev_entry *inodev;
49515+
49516+ if (unlikely(!(gr_status & GR_READY)))
49517+ return;
49518+
49519+ write_lock(&gr_inode_lock);
49520+ inodev = lookup_inodev_entry(ino, dev);
49521+ if (inodev != NULL)
49522+ do_handle_delete(inodev, ino, dev);
49523+ write_unlock(&gr_inode_lock);
49524+
49525+ return;
49526+}
49527+
49528+static void
49529+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
49530+ const ino_t newinode, const dev_t newdevice,
49531+ struct acl_subject_label *subj)
49532+{
49533+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
49534+ struct acl_object_label *match;
49535+
49536+ match = subj->obj_hash[index];
49537+
49538+ while (match && (match->inode != oldinode ||
49539+ match->device != olddevice ||
49540+ !(match->mode & GR_DELETED)))
49541+ match = match->next;
49542+
49543+ if (match && (match->inode == oldinode)
49544+ && (match->device == olddevice)
49545+ && (match->mode & GR_DELETED)) {
49546+ if (match->prev == NULL) {
49547+ subj->obj_hash[index] = match->next;
49548+ if (match->next != NULL)
49549+ match->next->prev = NULL;
49550+ } else {
49551+ match->prev->next = match->next;
49552+ if (match->next != NULL)
49553+ match->next->prev = match->prev;
49554+ }
49555+ match->prev = NULL;
49556+ match->next = NULL;
49557+ match->inode = newinode;
49558+ match->device = newdevice;
49559+ match->mode &= ~GR_DELETED;
49560+
49561+ insert_acl_obj_label(match, subj);
49562+ }
49563+
49564+ return;
49565+}
49566+
49567+static void
49568+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
49569+ const ino_t newinode, const dev_t newdevice,
49570+ struct acl_role_label *role)
49571+{
49572+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
49573+ struct acl_subject_label *match;
49574+
49575+ match = role->subj_hash[index];
49576+
49577+ while (match && (match->inode != oldinode ||
49578+ match->device != olddevice ||
49579+ !(match->mode & GR_DELETED)))
49580+ match = match->next;
49581+
49582+ if (match && (match->inode == oldinode)
49583+ && (match->device == olddevice)
49584+ && (match->mode & GR_DELETED)) {
49585+ if (match->prev == NULL) {
49586+ role->subj_hash[index] = match->next;
49587+ if (match->next != NULL)
49588+ match->next->prev = NULL;
49589+ } else {
49590+ match->prev->next = match->next;
49591+ if (match->next != NULL)
49592+ match->next->prev = match->prev;
49593+ }
49594+ match->prev = NULL;
49595+ match->next = NULL;
49596+ match->inode = newinode;
49597+ match->device = newdevice;
49598+ match->mode &= ~GR_DELETED;
49599+
49600+ insert_acl_subj_label(match, role);
49601+ }
49602+
49603+ return;
49604+}
49605+
49606+static void
49607+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
49608+ const ino_t newinode, const dev_t newdevice)
49609+{
49610+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
49611+ struct inodev_entry *match;
49612+
49613+ match = inodev_set.i_hash[index];
49614+
49615+ while (match && (match->nentry->inode != oldinode ||
49616+ match->nentry->device != olddevice || !match->nentry->deleted))
49617+ match = match->next;
49618+
49619+ if (match && (match->nentry->inode == oldinode)
49620+ && (match->nentry->device == olddevice) &&
49621+ match->nentry->deleted) {
49622+ if (match->prev == NULL) {
49623+ inodev_set.i_hash[index] = match->next;
49624+ if (match->next != NULL)
49625+ match->next->prev = NULL;
49626+ } else {
49627+ match->prev->next = match->next;
49628+ if (match->next != NULL)
49629+ match->next->prev = match->prev;
49630+ }
49631+ match->prev = NULL;
49632+ match->next = NULL;
49633+ match->nentry->inode = newinode;
49634+ match->nentry->device = newdevice;
49635+ match->nentry->deleted = 0;
49636+
49637+ insert_inodev_entry(match);
49638+ }
49639+
49640+ return;
49641+}
49642+
49643+static void
49644+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
49645+ const struct vfsmount *mnt)
49646+{
49647+ struct acl_subject_label *subj;
49648+ struct acl_role_label *role;
49649+ unsigned int x;
49650+ ino_t inode = dentry->d_inode->i_ino;
49651+ dev_t dev = __get_dev(dentry);
49652+
49653+ FOR_EACH_ROLE_START(role)
49654+ update_acl_subj_label(matchn->inode, matchn->device,
49655+ inode, dev, role);
49656+
49657+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
49658+ if ((subj->inode == inode) && (subj->device == dev)) {
49659+ subj->inode = inode;
49660+ subj->device = dev;
49661+ }
49662+ FOR_EACH_NESTED_SUBJECT_END(subj)
49663+ FOR_EACH_SUBJECT_START(role, subj, x)
49664+ update_acl_obj_label(matchn->inode, matchn->device,
49665+ inode, dev, subj);
49666+ FOR_EACH_SUBJECT_END(subj,x)
49667+ FOR_EACH_ROLE_END(role)
49668+
49669+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
49670+
49671+ return;
49672+}
49673+
49674+void
49675+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
49676+{
49677+ struct name_entry *matchn;
49678+
49679+ if (unlikely(!(gr_status & GR_READY)))
49680+ return;
49681+
49682+ preempt_disable();
49683+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
49684+
49685+ if (unlikely((unsigned long)matchn)) {
49686+ write_lock(&gr_inode_lock);
49687+ do_handle_create(matchn, dentry, mnt);
49688+ write_unlock(&gr_inode_lock);
49689+ }
49690+ preempt_enable();
49691+
49692+ return;
49693+}
49694+
49695+void
49696+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
49697+ struct dentry *old_dentry,
49698+ struct dentry *new_dentry,
49699+ struct vfsmount *mnt, const __u8 replace)
49700+{
49701+ struct name_entry *matchn;
49702+ struct inodev_entry *inodev;
49703+ ino_t oldinode = old_dentry->d_inode->i_ino;
49704+ dev_t olddev = __get_dev(old_dentry);
49705+
49706+ /* vfs_rename swaps the name and parent link for old_dentry and
49707+ new_dentry
49708+ at this point, old_dentry has the new name, parent link, and inode
49709+ for the renamed file
49710+ if a file is being replaced by a rename, new_dentry has the inode
49711+ and name for the replaced file
49712+ */
49713+
49714+ if (unlikely(!(gr_status & GR_READY)))
49715+ return;
49716+
49717+ preempt_disable();
49718+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
49719+
49720+ /* we wouldn't have to check d_inode if it weren't for
49721+ NFS silly-renaming
49722+ */
49723+
49724+ write_lock(&gr_inode_lock);
49725+ if (unlikely(replace && new_dentry->d_inode)) {
49726+ ino_t newinode = new_dentry->d_inode->i_ino;
49727+ dev_t newdev = __get_dev(new_dentry);
49728+ inodev = lookup_inodev_entry(newinode, newdev);
49729+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
49730+ do_handle_delete(inodev, newinode, newdev);
49731+ }
49732+
49733+ inodev = lookup_inodev_entry(oldinode, olddev);
49734+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
49735+ do_handle_delete(inodev, oldinode, olddev);
49736+
49737+ if (unlikely((unsigned long)matchn))
49738+ do_handle_create(matchn, old_dentry, mnt);
49739+
49740+ write_unlock(&gr_inode_lock);
49741+ preempt_enable();
49742+
49743+ return;
49744+}
49745+
49746+static int
49747+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
49748+ unsigned char **sum)
49749+{
49750+ struct acl_role_label *r;
49751+ struct role_allowed_ip *ipp;
49752+ struct role_transition *trans;
49753+ unsigned int i;
49754+ int found = 0;
49755+ u32 curr_ip = current->signal->curr_ip;
49756+
49757+ current->signal->saved_ip = curr_ip;
49758+
49759+ /* check transition table */
49760+
49761+ for (trans = current->role->transitions; trans; trans = trans->next) {
49762+ if (!strcmp(rolename, trans->rolename)) {
49763+ found = 1;
49764+ break;
49765+ }
49766+ }
49767+
49768+ if (!found)
49769+ return 0;
49770+
49771+ /* handle special roles that do not require authentication
49772+ and check ip */
49773+
49774+ FOR_EACH_ROLE_START(r)
49775+ if (!strcmp(rolename, r->rolename) &&
49776+ (r->roletype & GR_ROLE_SPECIAL)) {
49777+ found = 0;
49778+ if (r->allowed_ips != NULL) {
49779+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
49780+ if ((ntohl(curr_ip) & ipp->netmask) ==
49781+ (ntohl(ipp->addr) & ipp->netmask))
49782+ found = 1;
49783+ }
49784+ } else
49785+ found = 2;
49786+ if (!found)
49787+ return 0;
49788+
49789+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
49790+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
49791+ *salt = NULL;
49792+ *sum = NULL;
49793+ return 1;
49794+ }
49795+ }
49796+ FOR_EACH_ROLE_END(r)
49797+
49798+ for (i = 0; i < num_sprole_pws; i++) {
49799+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
49800+ *salt = acl_special_roles[i]->salt;
49801+ *sum = acl_special_roles[i]->sum;
49802+ return 1;
49803+ }
49804+ }
49805+
49806+ return 0;
49807+}
49808+
49809+static void
49810+assign_special_role(char *rolename)
49811+{
49812+ struct acl_object_label *obj;
49813+ struct acl_role_label *r;
49814+ struct acl_role_label *assigned = NULL;
49815+ struct task_struct *tsk;
49816+ struct file *filp;
49817+
49818+ FOR_EACH_ROLE_START(r)
49819+ if (!strcmp(rolename, r->rolename) &&
49820+ (r->roletype & GR_ROLE_SPECIAL)) {
49821+ assigned = r;
49822+ break;
49823+ }
49824+ FOR_EACH_ROLE_END(r)
49825+
49826+ if (!assigned)
49827+ return;
49828+
49829+ read_lock(&tasklist_lock);
49830+ read_lock(&grsec_exec_file_lock);
49831+
49832+ tsk = current->real_parent;
49833+ if (tsk == NULL)
49834+ goto out_unlock;
49835+
49836+ filp = tsk->exec_file;
49837+ if (filp == NULL)
49838+ goto out_unlock;
49839+
49840+ tsk->is_writable = 0;
49841+
49842+ tsk->acl_sp_role = 1;
49843+ tsk->acl_role_id = ++acl_sp_role_value;
49844+ tsk->role = assigned;
49845+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
49846+
49847+ /* ignore additional mmap checks for processes that are writable
49848+ by the default ACL */
49849+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
49850+ if (unlikely(obj->mode & GR_WRITE))
49851+ tsk->is_writable = 1;
49852+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
49853+ if (unlikely(obj->mode & GR_WRITE))
49854+ tsk->is_writable = 1;
49855+
49856+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49857+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
49858+#endif
49859+
49860+out_unlock:
49861+ read_unlock(&grsec_exec_file_lock);
49862+ read_unlock(&tasklist_lock);
49863+ return;
49864+}
49865+
49866+int gr_check_secure_terminal(struct task_struct *task)
49867+{
49868+ struct task_struct *p, *p2, *p3;
49869+ struct files_struct *files;
49870+ struct fdtable *fdt;
49871+ struct file *our_file = NULL, *file;
49872+ int i;
49873+
49874+ if (task->signal->tty == NULL)
49875+ return 1;
49876+
49877+ files = get_files_struct(task);
49878+ if (files != NULL) {
49879+ rcu_read_lock();
49880+ fdt = files_fdtable(files);
49881+ for (i=0; i < fdt->max_fds; i++) {
49882+ file = fcheck_files(files, i);
49883+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
49884+ get_file(file);
49885+ our_file = file;
49886+ }
49887+ }
49888+ rcu_read_unlock();
49889+ put_files_struct(files);
49890+ }
49891+
49892+ if (our_file == NULL)
49893+ return 1;
49894+
49895+ read_lock(&tasklist_lock);
49896+ do_each_thread(p2, p) {
49897+ files = get_files_struct(p);
49898+ if (files == NULL ||
49899+ (p->signal && p->signal->tty == task->signal->tty)) {
49900+ if (files != NULL)
49901+ put_files_struct(files);
49902+ continue;
49903+ }
49904+ rcu_read_lock();
49905+ fdt = files_fdtable(files);
49906+ for (i=0; i < fdt->max_fds; i++) {
49907+ file = fcheck_files(files, i);
49908+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
49909+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
49910+ p3 = task;
49911+ while (p3->pid > 0) {
49912+ if (p3 == p)
49913+ break;
49914+ p3 = p3->real_parent;
49915+ }
49916+ if (p3 == p)
49917+ break;
49918+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
49919+ gr_handle_alertkill(p);
49920+ rcu_read_unlock();
49921+ put_files_struct(files);
49922+ read_unlock(&tasklist_lock);
49923+ fput(our_file);
49924+ return 0;
49925+ }
49926+ }
49927+ rcu_read_unlock();
49928+ put_files_struct(files);
49929+ } while_each_thread(p2, p);
49930+ read_unlock(&tasklist_lock);
49931+
49932+ fput(our_file);
49933+ return 1;
49934+}
49935+
49936+ssize_t
49937+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
49938+{
49939+ struct gr_arg_wrapper uwrap;
49940+ unsigned char *sprole_salt = NULL;
49941+ unsigned char *sprole_sum = NULL;
49942+ int error = sizeof (struct gr_arg_wrapper);
49943+ int error2 = 0;
49944+
49945+ mutex_lock(&gr_dev_mutex);
49946+
49947+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
49948+ error = -EPERM;
49949+ goto out;
49950+ }
49951+
49952+ if (count != sizeof (struct gr_arg_wrapper)) {
49953+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
49954+ error = -EINVAL;
49955+ goto out;
49956+ }
49957+
49958+
49959+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
49960+ gr_auth_expires = 0;
49961+ gr_auth_attempts = 0;
49962+ }
49963+
49964+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
49965+ error = -EFAULT;
49966+ goto out;
49967+ }
49968+
49969+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
49970+ error = -EINVAL;
49971+ goto out;
49972+ }
49973+
49974+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
49975+ error = -EFAULT;
49976+ goto out;
49977+ }
49978+
49979+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
49980+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
49981+ time_after(gr_auth_expires, get_seconds())) {
49982+ error = -EBUSY;
49983+ goto out;
49984+ }
49985+
49986+ /* if non-root trying to do anything other than use a special role,
49987+ do not attempt authentication, do not count towards authentication
49988+ locking
49989+ */
49990+
49991+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
49992+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
49993+ current_uid()) {
49994+ error = -EPERM;
49995+ goto out;
49996+ }
49997+
49998+ /* ensure pw and special role name are null terminated */
49999+
50000+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
50001+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
50002+
50003+ /* Okay.
50004+ * We have our enough of the argument structure..(we have yet
50005+ * to copy_from_user the tables themselves) . Copy the tables
50006+ * only if we need them, i.e. for loading operations. */
50007+
50008+ switch (gr_usermode->mode) {
50009+ case GR_STATUS:
50010+ if (gr_status & GR_READY) {
50011+ error = 1;
50012+ if (!gr_check_secure_terminal(current))
50013+ error = 3;
50014+ } else
50015+ error = 2;
50016+ goto out;
50017+ case GR_SHUTDOWN:
50018+ if ((gr_status & GR_READY)
50019+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
50020+ pax_open_kernel();
50021+ gr_status &= ~GR_READY;
50022+ pax_close_kernel();
50023+
50024+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
50025+ free_variables();
50026+ memset(gr_usermode, 0, sizeof (struct gr_arg));
50027+ memset(gr_system_salt, 0, GR_SALT_LEN);
50028+ memset(gr_system_sum, 0, GR_SHA_LEN);
50029+ } else if (gr_status & GR_READY) {
50030+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
50031+ error = -EPERM;
50032+ } else {
50033+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
50034+ error = -EAGAIN;
50035+ }
50036+ break;
50037+ case GR_ENABLE:
50038+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
50039+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
50040+ else {
50041+ if (gr_status & GR_READY)
50042+ error = -EAGAIN;
50043+ else
50044+ error = error2;
50045+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
50046+ }
50047+ break;
50048+ case GR_RELOAD:
50049+ if (!(gr_status & GR_READY)) {
50050+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
50051+ error = -EAGAIN;
50052+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
50053+ lock_kernel();
50054+
50055+ pax_open_kernel();
50056+ gr_status &= ~GR_READY;
50057+ pax_close_kernel();
50058+
50059+ free_variables();
50060+ if (!(error2 = gracl_init(gr_usermode))) {
50061+ unlock_kernel();
50062+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
50063+ } else {
50064+ unlock_kernel();
50065+ error = error2;
50066+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
50067+ }
50068+ } else {
50069+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
50070+ error = -EPERM;
50071+ }
50072+ break;
50073+ case GR_SEGVMOD:
50074+ if (unlikely(!(gr_status & GR_READY))) {
50075+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
50076+ error = -EAGAIN;
50077+ break;
50078+ }
50079+
50080+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
50081+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
50082+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
50083+ struct acl_subject_label *segvacl;
50084+ segvacl =
50085+ lookup_acl_subj_label(gr_usermode->segv_inode,
50086+ gr_usermode->segv_device,
50087+ current->role);
50088+ if (segvacl) {
50089+ segvacl->crashes = 0;
50090+ segvacl->expires = 0;
50091+ }
50092+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
50093+ gr_remove_uid(gr_usermode->segv_uid);
50094+ }
50095+ } else {
50096+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
50097+ error = -EPERM;
50098+ }
50099+ break;
50100+ case GR_SPROLE:
50101+ case GR_SPROLEPAM:
50102+ if (unlikely(!(gr_status & GR_READY))) {
50103+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
50104+ error = -EAGAIN;
50105+ break;
50106+ }
50107+
50108+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
50109+ current->role->expires = 0;
50110+ current->role->auth_attempts = 0;
50111+ }
50112+
50113+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
50114+ time_after(current->role->expires, get_seconds())) {
50115+ error = -EBUSY;
50116+ goto out;
50117+ }
50118+
50119+ if (lookup_special_role_auth
50120+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
50121+ && ((!sprole_salt && !sprole_sum)
50122+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
50123+ char *p = "";
50124+ assign_special_role(gr_usermode->sp_role);
50125+ read_lock(&tasklist_lock);
50126+ if (current->real_parent)
50127+ p = current->real_parent->role->rolename;
50128+ read_unlock(&tasklist_lock);
50129+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
50130+ p, acl_sp_role_value);
50131+ } else {
50132+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
50133+ error = -EPERM;
50134+ if(!(current->role->auth_attempts++))
50135+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
50136+
50137+ goto out;
50138+ }
50139+ break;
50140+ case GR_UNSPROLE:
50141+ if (unlikely(!(gr_status & GR_READY))) {
50142+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
50143+ error = -EAGAIN;
50144+ break;
50145+ }
50146+
50147+ if (current->role->roletype & GR_ROLE_SPECIAL) {
50148+ char *p = "";
50149+ int i = 0;
50150+
50151+ read_lock(&tasklist_lock);
50152+ if (current->real_parent) {
50153+ p = current->real_parent->role->rolename;
50154+ i = current->real_parent->acl_role_id;
50155+ }
50156+ read_unlock(&tasklist_lock);
50157+
50158+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
50159+ gr_set_acls(1);
50160+ } else {
50161+ error = -EPERM;
50162+ goto out;
50163+ }
50164+ break;
50165+ default:
50166+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
50167+ error = -EINVAL;
50168+ break;
50169+ }
50170+
50171+ if (error != -EPERM)
50172+ goto out;
50173+
50174+ if(!(gr_auth_attempts++))
50175+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
50176+
50177+ out:
50178+ mutex_unlock(&gr_dev_mutex);
50179+ return error;
50180+}
50181+
50182+/* must be called with
50183+ rcu_read_lock();
50184+ read_lock(&tasklist_lock);
50185+ read_lock(&grsec_exec_file_lock);
50186+*/
50187+int gr_apply_subject_to_task(struct task_struct *task)
50188+{
50189+ struct acl_object_label *obj;
50190+ char *tmpname;
50191+ struct acl_subject_label *tmpsubj;
50192+ struct file *filp;
50193+ struct name_entry *nmatch;
50194+
50195+ filp = task->exec_file;
50196+ if (filp == NULL)
50197+ return 0;
50198+
50199+ /* the following is to apply the correct subject
50200+ on binaries running when the RBAC system
50201+ is enabled, when the binaries have been
50202+ replaced or deleted since their execution
50203+ -----
50204+ when the RBAC system starts, the inode/dev
50205+ from exec_file will be one the RBAC system
50206+ is unaware of. It only knows the inode/dev
50207+ of the present file on disk, or the absence
50208+ of it.
50209+ */
50210+ preempt_disable();
50211+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
50212+
50213+ nmatch = lookup_name_entry(tmpname);
50214+ preempt_enable();
50215+ tmpsubj = NULL;
50216+ if (nmatch) {
50217+ if (nmatch->deleted)
50218+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
50219+ else
50220+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
50221+ if (tmpsubj != NULL)
50222+ task->acl = tmpsubj;
50223+ }
50224+ if (tmpsubj == NULL)
50225+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
50226+ task->role);
50227+ if (task->acl) {
50228+ task->is_writable = 0;
50229+ /* ignore additional mmap checks for processes that are writable
50230+ by the default ACL */
50231+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50232+ if (unlikely(obj->mode & GR_WRITE))
50233+ task->is_writable = 1;
50234+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
50235+ if (unlikely(obj->mode & GR_WRITE))
50236+ task->is_writable = 1;
50237+
50238+ gr_set_proc_res(task);
50239+
50240+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50241+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50242+#endif
50243+ } else {
50244+ return 1;
50245+ }
50246+
50247+ return 0;
50248+}
50249+
50250+int
50251+gr_set_acls(const int type)
50252+{
50253+ struct task_struct *task, *task2;
50254+ struct acl_role_label *role = current->role;
50255+ __u16 acl_role_id = current->acl_role_id;
50256+ const struct cred *cred;
50257+ int ret;
50258+
50259+ rcu_read_lock();
50260+ read_lock(&tasklist_lock);
50261+ read_lock(&grsec_exec_file_lock);
50262+ do_each_thread(task2, task) {
50263+ /* check to see if we're called from the exit handler,
50264+ if so, only replace ACLs that have inherited the admin
50265+ ACL */
50266+
50267+ if (type && (task->role != role ||
50268+ task->acl_role_id != acl_role_id))
50269+ continue;
50270+
50271+ task->acl_role_id = 0;
50272+ task->acl_sp_role = 0;
50273+
50274+ if (task->exec_file) {
50275+ cred = __task_cred(task);
50276+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
50277+
50278+ ret = gr_apply_subject_to_task(task);
50279+ if (ret) {
50280+ read_unlock(&grsec_exec_file_lock);
50281+ read_unlock(&tasklist_lock);
50282+ rcu_read_unlock();
50283+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
50284+ return ret;
50285+ }
50286+ } else {
50287+ // it's a kernel process
50288+ task->role = kernel_role;
50289+ task->acl = kernel_role->root_label;
50290+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
50291+ task->acl->mode &= ~GR_PROCFIND;
50292+#endif
50293+ }
50294+ } while_each_thread(task2, task);
50295+ read_unlock(&grsec_exec_file_lock);
50296+ read_unlock(&tasklist_lock);
50297+ rcu_read_unlock();
50298+
50299+ return 0;
50300+}
50301+
50302+void
50303+gr_learn_resource(const struct task_struct *task,
50304+ const int res, const unsigned long wanted, const int gt)
50305+{
50306+ struct acl_subject_label *acl;
50307+ const struct cred *cred;
50308+
50309+ if (unlikely((gr_status & GR_READY) &&
50310+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
50311+ goto skip_reslog;
50312+
50313+#ifdef CONFIG_GRKERNSEC_RESLOG
50314+ gr_log_resource(task, res, wanted, gt);
50315+#endif
50316+ skip_reslog:
50317+
50318+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
50319+ return;
50320+
50321+ acl = task->acl;
50322+
50323+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
50324+ !(acl->resmask & (1 << (unsigned short) res))))
50325+ return;
50326+
50327+ if (wanted >= acl->res[res].rlim_cur) {
50328+ unsigned long res_add;
50329+
50330+ res_add = wanted;
50331+ switch (res) {
50332+ case RLIMIT_CPU:
50333+ res_add += GR_RLIM_CPU_BUMP;
50334+ break;
50335+ case RLIMIT_FSIZE:
50336+ res_add += GR_RLIM_FSIZE_BUMP;
50337+ break;
50338+ case RLIMIT_DATA:
50339+ res_add += GR_RLIM_DATA_BUMP;
50340+ break;
50341+ case RLIMIT_STACK:
50342+ res_add += GR_RLIM_STACK_BUMP;
50343+ break;
50344+ case RLIMIT_CORE:
50345+ res_add += GR_RLIM_CORE_BUMP;
50346+ break;
50347+ case RLIMIT_RSS:
50348+ res_add += GR_RLIM_RSS_BUMP;
50349+ break;
50350+ case RLIMIT_NPROC:
50351+ res_add += GR_RLIM_NPROC_BUMP;
50352+ break;
50353+ case RLIMIT_NOFILE:
50354+ res_add += GR_RLIM_NOFILE_BUMP;
50355+ break;
50356+ case RLIMIT_MEMLOCK:
50357+ res_add += GR_RLIM_MEMLOCK_BUMP;
50358+ break;
50359+ case RLIMIT_AS:
50360+ res_add += GR_RLIM_AS_BUMP;
50361+ break;
50362+ case RLIMIT_LOCKS:
50363+ res_add += GR_RLIM_LOCKS_BUMP;
50364+ break;
50365+ case RLIMIT_SIGPENDING:
50366+ res_add += GR_RLIM_SIGPENDING_BUMP;
50367+ break;
50368+ case RLIMIT_MSGQUEUE:
50369+ res_add += GR_RLIM_MSGQUEUE_BUMP;
50370+ break;
50371+ case RLIMIT_NICE:
50372+ res_add += GR_RLIM_NICE_BUMP;
50373+ break;
50374+ case RLIMIT_RTPRIO:
50375+ res_add += GR_RLIM_RTPRIO_BUMP;
50376+ break;
50377+ case RLIMIT_RTTIME:
50378+ res_add += GR_RLIM_RTTIME_BUMP;
50379+ break;
50380+ }
50381+
50382+ acl->res[res].rlim_cur = res_add;
50383+
50384+ if (wanted > acl->res[res].rlim_max)
50385+ acl->res[res].rlim_max = res_add;
50386+
50387+ /* only log the subject filename, since resource logging is supported for
50388+ single-subject learning only */
50389+ rcu_read_lock();
50390+ cred = __task_cred(task);
50391+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
50392+ task->role->roletype, cred->uid, cred->gid, acl->filename,
50393+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
50394+ "", (unsigned long) res, &task->signal->saved_ip);
50395+ rcu_read_unlock();
50396+ }
50397+
50398+ return;
50399+}
50400+
50401+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
50402+void
50403+pax_set_initial_flags(struct linux_binprm *bprm)
50404+{
50405+ struct task_struct *task = current;
50406+ struct acl_subject_label *proc;
50407+ unsigned long flags;
50408+
50409+ if (unlikely(!(gr_status & GR_READY)))
50410+ return;
50411+
50412+ flags = pax_get_flags(task);
50413+
50414+ proc = task->acl;
50415+
50416+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
50417+ flags &= ~MF_PAX_PAGEEXEC;
50418+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
50419+ flags &= ~MF_PAX_SEGMEXEC;
50420+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
50421+ flags &= ~MF_PAX_RANDMMAP;
50422+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
50423+ flags &= ~MF_PAX_EMUTRAMP;
50424+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
50425+ flags &= ~MF_PAX_MPROTECT;
50426+
50427+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
50428+ flags |= MF_PAX_PAGEEXEC;
50429+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
50430+ flags |= MF_PAX_SEGMEXEC;
50431+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
50432+ flags |= MF_PAX_RANDMMAP;
50433+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
50434+ flags |= MF_PAX_EMUTRAMP;
50435+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
50436+ flags |= MF_PAX_MPROTECT;
50437+
50438+ pax_set_flags(task, flags);
50439+
50440+ return;
50441+}
50442+#endif
50443+
50444+#ifdef CONFIG_SYSCTL
50445+/* Eric Biederman likes breaking userland ABI and every inode-based security
50446+ system to save 35kb of memory */
50447+
50448+/* we modify the passed in filename, but adjust it back before returning */
50449+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
50450+{
50451+ struct name_entry *nmatch;
50452+ char *p, *lastp = NULL;
50453+ struct acl_object_label *obj = NULL, *tmp;
50454+ struct acl_subject_label *tmpsubj;
50455+ char c = '\0';
50456+
50457+ read_lock(&gr_inode_lock);
50458+
50459+ p = name + len - 1;
50460+ do {
50461+ nmatch = lookup_name_entry(name);
50462+ if (lastp != NULL)
50463+ *lastp = c;
50464+
50465+ if (nmatch == NULL)
50466+ goto next_component;
50467+ tmpsubj = current->acl;
50468+ do {
50469+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
50470+ if (obj != NULL) {
50471+ tmp = obj->globbed;
50472+ while (tmp) {
50473+ if (!glob_match(tmp->filename, name)) {
50474+ obj = tmp;
50475+ goto found_obj;
50476+ }
50477+ tmp = tmp->next;
50478+ }
50479+ goto found_obj;
50480+ }
50481+ } while ((tmpsubj = tmpsubj->parent_subject));
50482+next_component:
50483+ /* end case */
50484+ if (p == name)
50485+ break;
50486+
50487+ while (*p != '/')
50488+ p--;
50489+ if (p == name)
50490+ lastp = p + 1;
50491+ else {
50492+ lastp = p;
50493+ p--;
50494+ }
50495+ c = *lastp;
50496+ *lastp = '\0';
50497+ } while (1);
50498+found_obj:
50499+ read_unlock(&gr_inode_lock);
50500+ /* obj returned will always be non-null */
50501+ return obj;
50502+}
50503+
50504+/* returns 0 when allowing, non-zero on error
50505+ op of 0 is used for readdir, so we don't log the names of hidden files
50506+*/
50507+__u32
50508+gr_handle_sysctl(const struct ctl_table *table, const int op)
50509+{
50510+ ctl_table *tmp;
50511+ const char *proc_sys = "/proc/sys";
50512+ char *path;
50513+ struct acl_object_label *obj;
50514+ unsigned short len = 0, pos = 0, depth = 0, i;
50515+ __u32 err = 0;
50516+ __u32 mode = 0;
50517+
50518+ if (unlikely(!(gr_status & GR_READY)))
50519+ return 0;
50520+
50521+ /* for now, ignore operations on non-sysctl entries if it's not a
50522+ readdir*/
50523+ if (table->child != NULL && op != 0)
50524+ return 0;
50525+
50526+ mode |= GR_FIND;
50527+ /* it's only a read if it's an entry, read on dirs is for readdir */
50528+ if (op & MAY_READ)
50529+ mode |= GR_READ;
50530+ if (op & MAY_WRITE)
50531+ mode |= GR_WRITE;
50532+
50533+ preempt_disable();
50534+
50535+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50536+
50537+ /* it's only a read/write if it's an actual entry, not a dir
50538+ (which are opened for readdir)
50539+ */
50540+
50541+ /* convert the requested sysctl entry into a pathname */
50542+
50543+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
50544+ len += strlen(tmp->procname);
50545+ len++;
50546+ depth++;
50547+ }
50548+
50549+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
50550+ /* deny */
50551+ goto out;
50552+ }
50553+
50554+ memset(path, 0, PAGE_SIZE);
50555+
50556+ memcpy(path, proc_sys, strlen(proc_sys));
50557+
50558+ pos += strlen(proc_sys);
50559+
50560+ for (; depth > 0; depth--) {
50561+ path[pos] = '/';
50562+ pos++;
50563+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
50564+ if (depth == i) {
50565+ memcpy(path + pos, tmp->procname,
50566+ strlen(tmp->procname));
50567+ pos += strlen(tmp->procname);
50568+ }
50569+ i++;
50570+ }
50571+ }
50572+
50573+ obj = gr_lookup_by_name(path, pos);
50574+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
50575+
50576+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
50577+ ((err & mode) != mode))) {
50578+ __u32 new_mode = mode;
50579+
50580+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50581+
50582+ err = 0;
50583+ gr_log_learn_sysctl(path, new_mode);
50584+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
50585+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
50586+ err = -ENOENT;
50587+ } else if (!(err & GR_FIND)) {
50588+ err = -ENOENT;
50589+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
50590+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
50591+ path, (mode & GR_READ) ? " reading" : "",
50592+ (mode & GR_WRITE) ? " writing" : "");
50593+ err = -EACCES;
50594+ } else if ((err & mode) != mode) {
50595+ err = -EACCES;
50596+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
50597+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
50598+ path, (mode & GR_READ) ? " reading" : "",
50599+ (mode & GR_WRITE) ? " writing" : "");
50600+ err = 0;
50601+ } else
50602+ err = 0;
50603+
50604+ out:
50605+ preempt_enable();
50606+
50607+ return err;
50608+}
50609+#endif
50610+
50611+int
50612+gr_handle_proc_ptrace(struct task_struct *task)
50613+{
50614+ struct file *filp;
50615+ struct task_struct *tmp = task;
50616+ struct task_struct *curtemp = current;
50617+ __u32 retmode;
50618+
50619+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
50620+ if (unlikely(!(gr_status & GR_READY)))
50621+ return 0;
50622+#endif
50623+
50624+ read_lock(&tasklist_lock);
50625+ read_lock(&grsec_exec_file_lock);
50626+ filp = task->exec_file;
50627+
50628+ while (tmp->pid > 0) {
50629+ if (tmp == curtemp)
50630+ break;
50631+ tmp = tmp->real_parent;
50632+ }
50633+
50634+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
50635+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
50636+ read_unlock(&grsec_exec_file_lock);
50637+ read_unlock(&tasklist_lock);
50638+ return 1;
50639+ }
50640+
50641+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
50642+ if (!(gr_status & GR_READY)) {
50643+ read_unlock(&grsec_exec_file_lock);
50644+ read_unlock(&tasklist_lock);
50645+ return 0;
50646+ }
50647+#endif
50648+
50649+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
50650+ read_unlock(&grsec_exec_file_lock);
50651+ read_unlock(&tasklist_lock);
50652+
50653+ if (retmode & GR_NOPTRACE)
50654+ return 1;
50655+
50656+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
50657+ && (current->acl != task->acl || (current->acl != current->role->root_label
50658+ && current->pid != task->pid)))
50659+ return 1;
50660+
50661+ return 0;
50662+}
50663+
50664+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
50665+{
50666+ if (unlikely(!(gr_status & GR_READY)))
50667+ return;
50668+
50669+ if (!(current->role->roletype & GR_ROLE_GOD))
50670+ return;
50671+
50672+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
50673+ p->role->rolename, gr_task_roletype_to_char(p),
50674+ p->acl->filename);
50675+}
50676+
50677+int
50678+gr_handle_ptrace(struct task_struct *task, const long request)
50679+{
50680+ struct task_struct *tmp = task;
50681+ struct task_struct *curtemp = current;
50682+ __u32 retmode;
50683+
50684+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
50685+ if (unlikely(!(gr_status & GR_READY)))
50686+ return 0;
50687+#endif
50688+
50689+ read_lock(&tasklist_lock);
50690+ while (tmp->pid > 0) {
50691+ if (tmp == curtemp)
50692+ break;
50693+ tmp = tmp->real_parent;
50694+ }
50695+
50696+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
50697+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
50698+ read_unlock(&tasklist_lock);
50699+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
50700+ return 1;
50701+ }
50702+ read_unlock(&tasklist_lock);
50703+
50704+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
50705+ if (!(gr_status & GR_READY))
50706+ return 0;
50707+#endif
50708+
50709+ read_lock(&grsec_exec_file_lock);
50710+ if (unlikely(!task->exec_file)) {
50711+ read_unlock(&grsec_exec_file_lock);
50712+ return 0;
50713+ }
50714+
50715+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
50716+ read_unlock(&grsec_exec_file_lock);
50717+
50718+ if (retmode & GR_NOPTRACE) {
50719+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
50720+ return 1;
50721+ }
50722+
50723+ if (retmode & GR_PTRACERD) {
50724+ switch (request) {
50725+ case PTRACE_POKETEXT:
50726+ case PTRACE_POKEDATA:
50727+ case PTRACE_POKEUSR:
50728+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
50729+ case PTRACE_SETREGS:
50730+ case PTRACE_SETFPREGS:
50731+#endif
50732+#ifdef CONFIG_X86
50733+ case PTRACE_SETFPXREGS:
50734+#endif
50735+#ifdef CONFIG_ALTIVEC
50736+ case PTRACE_SETVRREGS:
50737+#endif
50738+ return 1;
50739+ default:
50740+ return 0;
50741+ }
50742+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
50743+ !(current->role->roletype & GR_ROLE_GOD) &&
50744+ (current->acl != task->acl)) {
50745+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
50746+ return 1;
50747+ }
50748+
50749+ return 0;
50750+}
50751+
50752+static int is_writable_mmap(const struct file *filp)
50753+{
50754+ struct task_struct *task = current;
50755+ struct acl_object_label *obj, *obj2;
50756+
50757+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
50758+ !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))) {
50759+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50760+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
50761+ task->role->root_label);
50762+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
50763+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
50764+ return 1;
50765+ }
50766+ }
50767+ return 0;
50768+}
50769+
50770+int
50771+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
50772+{
50773+ __u32 mode;
50774+
50775+ if (unlikely(!file || !(prot & PROT_EXEC)))
50776+ return 1;
50777+
50778+ if (is_writable_mmap(file))
50779+ return 0;
50780+
50781+ mode =
50782+ gr_search_file(file->f_path.dentry,
50783+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
50784+ file->f_path.mnt);
50785+
50786+ if (!gr_tpe_allow(file))
50787+ return 0;
50788+
50789+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
50790+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
50791+ return 0;
50792+ } else if (unlikely(!(mode & GR_EXEC))) {
50793+ return 0;
50794+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
50795+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
50796+ return 1;
50797+ }
50798+
50799+ return 1;
50800+}
50801+
50802+int
50803+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
50804+{
50805+ __u32 mode;
50806+
50807+ if (unlikely(!file || !(prot & PROT_EXEC)))
50808+ return 1;
50809+
50810+ if (is_writable_mmap(file))
50811+ return 0;
50812+
50813+ mode =
50814+ gr_search_file(file->f_path.dentry,
50815+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
50816+ file->f_path.mnt);
50817+
50818+ if (!gr_tpe_allow(file))
50819+ return 0;
50820+
50821+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
50822+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
50823+ return 0;
50824+ } else if (unlikely(!(mode & GR_EXEC))) {
50825+ return 0;
50826+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
50827+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
50828+ return 1;
50829+ }
50830+
50831+ return 1;
50832+}
50833+
50834+void
50835+gr_acl_handle_psacct(struct task_struct *task, const long code)
50836+{
50837+ unsigned long runtime;
50838+ unsigned long cputime;
50839+ unsigned int wday, cday;
50840+ __u8 whr, chr;
50841+ __u8 wmin, cmin;
50842+ __u8 wsec, csec;
50843+ struct timespec timeval;
50844+
50845+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
50846+ !(task->acl->mode & GR_PROCACCT)))
50847+ return;
50848+
50849+ do_posix_clock_monotonic_gettime(&timeval);
50850+ runtime = timeval.tv_sec - task->start_time.tv_sec;
50851+ wday = runtime / (3600 * 24);
50852+ runtime -= wday * (3600 * 24);
50853+ whr = runtime / 3600;
50854+ runtime -= whr * 3600;
50855+ wmin = runtime / 60;
50856+ runtime -= wmin * 60;
50857+ wsec = runtime;
50858+
50859+ cputime = (task->utime + task->stime) / HZ;
50860+ cday = cputime / (3600 * 24);
50861+ cputime -= cday * (3600 * 24);
50862+ chr = cputime / 3600;
50863+ cputime -= chr * 3600;
50864+ cmin = cputime / 60;
50865+ cputime -= cmin * 60;
50866+ csec = cputime;
50867+
50868+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
50869+
50870+ return;
50871+}
50872+
50873+void gr_set_kernel_label(struct task_struct *task)
50874+{
50875+ if (gr_status & GR_READY) {
50876+ task->role = kernel_role;
50877+ task->acl = kernel_role->root_label;
50878+ }
50879+ return;
50880+}
50881+
50882+#ifdef CONFIG_TASKSTATS
50883+int gr_is_taskstats_denied(int pid)
50884+{
50885+ struct task_struct *task;
50886+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50887+ const struct cred *cred;
50888+#endif
50889+ int ret = 0;
50890+
50891+ /* restrict taskstats viewing to un-chrooted root users
50892+ who have the 'view' subject flag if the RBAC system is enabled
50893+ */
50894+
50895+ rcu_read_lock();
50896+ read_lock(&tasklist_lock);
50897+ task = find_task_by_vpid(pid);
50898+ if (task) {
50899+#ifdef CONFIG_GRKERNSEC_CHROOT
50900+ if (proc_is_chrooted(task))
50901+ ret = -EACCES;
50902+#endif
50903+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50904+ cred = __task_cred(task);
50905+#ifdef CONFIG_GRKERNSEC_PROC_USER
50906+ if (cred->uid != 0)
50907+ ret = -EACCES;
50908+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50909+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
50910+ ret = -EACCES;
50911+#endif
50912+#endif
50913+ if (gr_status & GR_READY) {
50914+ if (!(task->acl->mode & GR_VIEW))
50915+ ret = -EACCES;
50916+ }
50917+ } else
50918+ ret = -ENOENT;
50919+
50920+ read_unlock(&tasklist_lock);
50921+ rcu_read_unlock();
50922+
50923+ return ret;
50924+}
50925+#endif
50926+
50927+/* AUXV entries are filled via a descendant of search_binary_handler
50928+ after we've already applied the subject for the target
50929+*/
50930+int gr_acl_enable_at_secure(void)
50931+{
50932+ if (unlikely(!(gr_status & GR_READY)))
50933+ return 0;
50934+
50935+ if (current->acl->mode & GR_ATSECURE)
50936+ return 1;
50937+
50938+ return 0;
50939+}
50940+
50941+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
50942+{
50943+ struct task_struct *task = current;
50944+ struct dentry *dentry = file->f_path.dentry;
50945+ struct vfsmount *mnt = file->f_path.mnt;
50946+ struct acl_object_label *obj, *tmp;
50947+ struct acl_subject_label *subj;
50948+ unsigned int bufsize;
50949+ int is_not_root;
50950+ char *path;
50951+ dev_t dev = __get_dev(dentry);
50952+
50953+ if (unlikely(!(gr_status & GR_READY)))
50954+ return 1;
50955+
50956+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50957+ return 1;
50958+
50959+ /* ignore Eric Biederman */
50960+ if (IS_PRIVATE(dentry->d_inode))
50961+ return 1;
50962+
50963+ subj = task->acl;
50964+ do {
50965+ obj = lookup_acl_obj_label(ino, dev, subj);
50966+ if (obj != NULL)
50967+ return (obj->mode & GR_FIND) ? 1 : 0;
50968+ } while ((subj = subj->parent_subject));
50969+
50970+ /* this is purely an optimization since we're looking for an object
50971+ for the directory we're doing a readdir on
50972+ if it's possible for any globbed object to match the entry we're
50973+ filling into the directory, then the object we find here will be
50974+ an anchor point with attached globbed objects
50975+ */
50976+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
50977+ if (obj->globbed == NULL)
50978+ return (obj->mode & GR_FIND) ? 1 : 0;
50979+
50980+ is_not_root = ((obj->filename[0] == '/') &&
50981+ (obj->filename[1] == '\0')) ? 0 : 1;
50982+ bufsize = PAGE_SIZE - namelen - is_not_root;
50983+
50984+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
50985+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
50986+ return 1;
50987+
50988+ preempt_disable();
50989+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50990+ bufsize);
50991+
50992+ bufsize = strlen(path);
50993+
50994+ /* if base is "/", don't append an additional slash */
50995+ if (is_not_root)
50996+ *(path + bufsize) = '/';
50997+ memcpy(path + bufsize + is_not_root, name, namelen);
50998+ *(path + bufsize + namelen + is_not_root) = '\0';
50999+
51000+ tmp = obj->globbed;
51001+ while (tmp) {
51002+ if (!glob_match(tmp->filename, path)) {
51003+ preempt_enable();
51004+ return (tmp->mode & GR_FIND) ? 1 : 0;
51005+ }
51006+ tmp = tmp->next;
51007+ }
51008+ preempt_enable();
51009+ return (obj->mode & GR_FIND) ? 1 : 0;
51010+}
51011+
51012+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
51013+EXPORT_SYMBOL(gr_acl_is_enabled);
51014+#endif
51015+EXPORT_SYMBOL(gr_learn_resource);
51016+EXPORT_SYMBOL(gr_set_kernel_label);
51017+#ifdef CONFIG_SECURITY
51018+EXPORT_SYMBOL(gr_check_user_change);
51019+EXPORT_SYMBOL(gr_check_group_change);
51020+#endif
51021+
51022diff -urNp linux-2.6.32.43/grsecurity/gracl_cap.c linux-2.6.32.43/grsecurity/gracl_cap.c
51023--- linux-2.6.32.43/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
51024+++ linux-2.6.32.43/grsecurity/gracl_cap.c 2011-04-17 15:56:46.000000000 -0400
51025@@ -0,0 +1,138 @@
51026+#include <linux/kernel.h>
51027+#include <linux/module.h>
51028+#include <linux/sched.h>
51029+#include <linux/gracl.h>
51030+#include <linux/grsecurity.h>
51031+#include <linux/grinternal.h>
51032+
51033+static const char *captab_log[] = {
51034+ "CAP_CHOWN",
51035+ "CAP_DAC_OVERRIDE",
51036+ "CAP_DAC_READ_SEARCH",
51037+ "CAP_FOWNER",
51038+ "CAP_FSETID",
51039+ "CAP_KILL",
51040+ "CAP_SETGID",
51041+ "CAP_SETUID",
51042+ "CAP_SETPCAP",
51043+ "CAP_LINUX_IMMUTABLE",
51044+ "CAP_NET_BIND_SERVICE",
51045+ "CAP_NET_BROADCAST",
51046+ "CAP_NET_ADMIN",
51047+ "CAP_NET_RAW",
51048+ "CAP_IPC_LOCK",
51049+ "CAP_IPC_OWNER",
51050+ "CAP_SYS_MODULE",
51051+ "CAP_SYS_RAWIO",
51052+ "CAP_SYS_CHROOT",
51053+ "CAP_SYS_PTRACE",
51054+ "CAP_SYS_PACCT",
51055+ "CAP_SYS_ADMIN",
51056+ "CAP_SYS_BOOT",
51057+ "CAP_SYS_NICE",
51058+ "CAP_SYS_RESOURCE",
51059+ "CAP_SYS_TIME",
51060+ "CAP_SYS_TTY_CONFIG",
51061+ "CAP_MKNOD",
51062+ "CAP_LEASE",
51063+ "CAP_AUDIT_WRITE",
51064+ "CAP_AUDIT_CONTROL",
51065+ "CAP_SETFCAP",
51066+ "CAP_MAC_OVERRIDE",
51067+ "CAP_MAC_ADMIN"
51068+};
51069+
51070+EXPORT_SYMBOL(gr_is_capable);
51071+EXPORT_SYMBOL(gr_is_capable_nolog);
51072+
51073+int
51074+gr_is_capable(const int cap)
51075+{
51076+ struct task_struct *task = current;
51077+ const struct cred *cred = current_cred();
51078+ struct acl_subject_label *curracl;
51079+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
51080+ kernel_cap_t cap_audit = __cap_empty_set;
51081+
51082+ if (!gr_acl_is_enabled())
51083+ return 1;
51084+
51085+ curracl = task->acl;
51086+
51087+ cap_drop = curracl->cap_lower;
51088+ cap_mask = curracl->cap_mask;
51089+ cap_audit = curracl->cap_invert_audit;
51090+
51091+ while ((curracl = curracl->parent_subject)) {
51092+ /* if the cap isn't specified in the current computed mask but is specified in the
51093+ current level subject, and is lowered in the current level subject, then add
51094+ it to the set of dropped capabilities
51095+ otherwise, add the current level subject's mask to the current computed mask
51096+ */
51097+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
51098+ cap_raise(cap_mask, cap);
51099+ if (cap_raised(curracl->cap_lower, cap))
51100+ cap_raise(cap_drop, cap);
51101+ if (cap_raised(curracl->cap_invert_audit, cap))
51102+ cap_raise(cap_audit, cap);
51103+ }
51104+ }
51105+
51106+ if (!cap_raised(cap_drop, cap)) {
51107+ if (cap_raised(cap_audit, cap))
51108+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
51109+ return 1;
51110+ }
51111+
51112+ curracl = task->acl;
51113+
51114+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
51115+ && cap_raised(cred->cap_effective, cap)) {
51116+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
51117+ task->role->roletype, cred->uid,
51118+ cred->gid, task->exec_file ?
51119+ gr_to_filename(task->exec_file->f_path.dentry,
51120+ task->exec_file->f_path.mnt) : curracl->filename,
51121+ curracl->filename, 0UL,
51122+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
51123+ return 1;
51124+ }
51125+
51126+ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
51127+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
51128+ return 0;
51129+}
51130+
51131+int
51132+gr_is_capable_nolog(const int cap)
51133+{
51134+ struct acl_subject_label *curracl;
51135+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
51136+
51137+ if (!gr_acl_is_enabled())
51138+ return 1;
51139+
51140+ curracl = current->acl;
51141+
51142+ cap_drop = curracl->cap_lower;
51143+ cap_mask = curracl->cap_mask;
51144+
51145+ while ((curracl = curracl->parent_subject)) {
51146+ /* if the cap isn't specified in the current computed mask but is specified in the
51147+ current level subject, and is lowered in the current level subject, then add
51148+ it to the set of dropped capabilities
51149+ otherwise, add the current level subject's mask to the current computed mask
51150+ */
51151+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
51152+ cap_raise(cap_mask, cap);
51153+ if (cap_raised(curracl->cap_lower, cap))
51154+ cap_raise(cap_drop, cap);
51155+ }
51156+ }
51157+
51158+ if (!cap_raised(cap_drop, cap))
51159+ return 1;
51160+
51161+ return 0;
51162+}
51163+
51164diff -urNp linux-2.6.32.43/grsecurity/gracl_fs.c linux-2.6.32.43/grsecurity/gracl_fs.c
51165--- linux-2.6.32.43/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
51166+++ linux-2.6.32.43/grsecurity/gracl_fs.c 2011-04-17 15:56:46.000000000 -0400
51167@@ -0,0 +1,431 @@
51168+#include <linux/kernel.h>
51169+#include <linux/sched.h>
51170+#include <linux/types.h>
51171+#include <linux/fs.h>
51172+#include <linux/file.h>
51173+#include <linux/stat.h>
51174+#include <linux/grsecurity.h>
51175+#include <linux/grinternal.h>
51176+#include <linux/gracl.h>
51177+
51178+__u32
51179+gr_acl_handle_hidden_file(const struct dentry * dentry,
51180+ const struct vfsmount * mnt)
51181+{
51182+ __u32 mode;
51183+
51184+ if (unlikely(!dentry->d_inode))
51185+ return GR_FIND;
51186+
51187+ mode =
51188+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
51189+
51190+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
51191+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
51192+ return mode;
51193+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
51194+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
51195+ return 0;
51196+ } else if (unlikely(!(mode & GR_FIND)))
51197+ return 0;
51198+
51199+ return GR_FIND;
51200+}
51201+
51202+__u32
51203+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
51204+ const int fmode)
51205+{
51206+ __u32 reqmode = GR_FIND;
51207+ __u32 mode;
51208+
51209+ if (unlikely(!dentry->d_inode))
51210+ return reqmode;
51211+
51212+ if (unlikely(fmode & O_APPEND))
51213+ reqmode |= GR_APPEND;
51214+ else if (unlikely(fmode & FMODE_WRITE))
51215+ reqmode |= GR_WRITE;
51216+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
51217+ reqmode |= GR_READ;
51218+ if ((fmode & FMODE_GREXEC) && (fmode & FMODE_EXEC))
51219+ reqmode &= ~GR_READ;
51220+ mode =
51221+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
51222+ mnt);
51223+
51224+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
51225+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
51226+ reqmode & GR_READ ? " reading" : "",
51227+ reqmode & GR_WRITE ? " writing" : reqmode &
51228+ GR_APPEND ? " appending" : "");
51229+ return reqmode;
51230+ } else
51231+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
51232+ {
51233+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
51234+ reqmode & GR_READ ? " reading" : "",
51235+ reqmode & GR_WRITE ? " writing" : reqmode &
51236+ GR_APPEND ? " appending" : "");
51237+ return 0;
51238+ } else if (unlikely((mode & reqmode) != reqmode))
51239+ return 0;
51240+
51241+ return reqmode;
51242+}
51243+
51244+__u32
51245+gr_acl_handle_creat(const struct dentry * dentry,
51246+ const struct dentry * p_dentry,
51247+ const struct vfsmount * p_mnt, const int fmode,
51248+ const int imode)
51249+{
51250+ __u32 reqmode = GR_WRITE | GR_CREATE;
51251+ __u32 mode;
51252+
51253+ if (unlikely(fmode & O_APPEND))
51254+ reqmode |= GR_APPEND;
51255+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
51256+ reqmode |= GR_READ;
51257+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
51258+ reqmode |= GR_SETID;
51259+
51260+ mode =
51261+ gr_check_create(dentry, p_dentry, p_mnt,
51262+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
51263+
51264+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
51265+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
51266+ reqmode & GR_READ ? " reading" : "",
51267+ reqmode & GR_WRITE ? " writing" : reqmode &
51268+ GR_APPEND ? " appending" : "");
51269+ return reqmode;
51270+ } else
51271+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
51272+ {
51273+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
51274+ reqmode & GR_READ ? " reading" : "",
51275+ reqmode & GR_WRITE ? " writing" : reqmode &
51276+ GR_APPEND ? " appending" : "");
51277+ return 0;
51278+ } else if (unlikely((mode & reqmode) != reqmode))
51279+ return 0;
51280+
51281+ return reqmode;
51282+}
51283+
51284+__u32
51285+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
51286+ const int fmode)
51287+{
51288+ __u32 mode, reqmode = GR_FIND;
51289+
51290+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
51291+ reqmode |= GR_EXEC;
51292+ if (fmode & S_IWOTH)
51293+ reqmode |= GR_WRITE;
51294+ if (fmode & S_IROTH)
51295+ reqmode |= GR_READ;
51296+
51297+ mode =
51298+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
51299+ mnt);
51300+
51301+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
51302+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
51303+ reqmode & GR_READ ? " reading" : "",
51304+ reqmode & GR_WRITE ? " writing" : "",
51305+ reqmode & GR_EXEC ? " executing" : "");
51306+ return reqmode;
51307+ } else
51308+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
51309+ {
51310+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
51311+ reqmode & GR_READ ? " reading" : "",
51312+ reqmode & GR_WRITE ? " writing" : "",
51313+ reqmode & GR_EXEC ? " executing" : "");
51314+ return 0;
51315+ } else if (unlikely((mode & reqmode) != reqmode))
51316+ return 0;
51317+
51318+ return reqmode;
51319+}
51320+
51321+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
51322+{
51323+ __u32 mode;
51324+
51325+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
51326+
51327+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
51328+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
51329+ return mode;
51330+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
51331+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
51332+ return 0;
51333+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
51334+ return 0;
51335+
51336+ return (reqmode);
51337+}
51338+
51339+__u32
51340+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
51341+{
51342+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
51343+}
51344+
51345+__u32
51346+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
51347+{
51348+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
51349+}
51350+
51351+__u32
51352+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
51353+{
51354+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
51355+}
51356+
51357+__u32
51358+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
51359+{
51360+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
51361+}
51362+
51363+__u32
51364+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
51365+ mode_t mode)
51366+{
51367+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
51368+ return 1;
51369+
51370+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
51371+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
51372+ GR_FCHMOD_ACL_MSG);
51373+ } else {
51374+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
51375+ }
51376+}
51377+
51378+__u32
51379+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
51380+ mode_t mode)
51381+{
51382+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
51383+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
51384+ GR_CHMOD_ACL_MSG);
51385+ } else {
51386+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
51387+ }
51388+}
51389+
51390+__u32
51391+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
51392+{
51393+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
51394+}
51395+
51396+__u32
51397+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
51398+{
51399+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
51400+}
51401+
51402+__u32
51403+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
51404+{
51405+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
51406+}
51407+
51408+__u32
51409+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
51410+{
51411+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
51412+ GR_UNIXCONNECT_ACL_MSG);
51413+}
51414+
51415+/* hardlinks require at minimum create permission,
51416+ any additional privilege required is based on the
51417+ privilege of the file being linked to
51418+*/
51419+__u32
51420+gr_acl_handle_link(const struct dentry * new_dentry,
51421+ const struct dentry * parent_dentry,
51422+ const struct vfsmount * parent_mnt,
51423+ const struct dentry * old_dentry,
51424+ const struct vfsmount * old_mnt, const char *to)
51425+{
51426+ __u32 mode;
51427+ __u32 needmode = GR_CREATE | GR_LINK;
51428+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
51429+
51430+ mode =
51431+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
51432+ old_mnt);
51433+
51434+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
51435+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
51436+ return mode;
51437+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
51438+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
51439+ return 0;
51440+ } else if (unlikely((mode & needmode) != needmode))
51441+ return 0;
51442+
51443+ return 1;
51444+}
51445+
51446+__u32
51447+gr_acl_handle_symlink(const struct dentry * new_dentry,
51448+ const struct dentry * parent_dentry,
51449+ const struct vfsmount * parent_mnt, const char *from)
51450+{
51451+ __u32 needmode = GR_WRITE | GR_CREATE;
51452+ __u32 mode;
51453+
51454+ mode =
51455+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
51456+ GR_CREATE | GR_AUDIT_CREATE |
51457+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
51458+
51459+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
51460+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
51461+ return mode;
51462+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
51463+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
51464+ return 0;
51465+ } else if (unlikely((mode & needmode) != needmode))
51466+ return 0;
51467+
51468+ return (GR_WRITE | GR_CREATE);
51469+}
51470+
51471+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)
51472+{
51473+ __u32 mode;
51474+
51475+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
51476+
51477+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
51478+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
51479+ return mode;
51480+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
51481+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
51482+ return 0;
51483+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
51484+ return 0;
51485+
51486+ return (reqmode);
51487+}
51488+
51489+__u32
51490+gr_acl_handle_mknod(const struct dentry * new_dentry,
51491+ const struct dentry * parent_dentry,
51492+ const struct vfsmount * parent_mnt,
51493+ const int mode)
51494+{
51495+ __u32 reqmode = GR_WRITE | GR_CREATE;
51496+ if (unlikely(mode & (S_ISUID | S_ISGID)))
51497+ reqmode |= GR_SETID;
51498+
51499+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
51500+ reqmode, GR_MKNOD_ACL_MSG);
51501+}
51502+
51503+__u32
51504+gr_acl_handle_mkdir(const struct dentry *new_dentry,
51505+ const struct dentry *parent_dentry,
51506+ const struct vfsmount *parent_mnt)
51507+{
51508+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
51509+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
51510+}
51511+
51512+#define RENAME_CHECK_SUCCESS(old, new) \
51513+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
51514+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
51515+
51516+int
51517+gr_acl_handle_rename(struct dentry *new_dentry,
51518+ struct dentry *parent_dentry,
51519+ const struct vfsmount *parent_mnt,
51520+ struct dentry *old_dentry,
51521+ struct inode *old_parent_inode,
51522+ struct vfsmount *old_mnt, const char *newname)
51523+{
51524+ __u32 comp1, comp2;
51525+ int error = 0;
51526+
51527+ if (unlikely(!gr_acl_is_enabled()))
51528+ return 0;
51529+
51530+ if (!new_dentry->d_inode) {
51531+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
51532+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
51533+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
51534+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
51535+ GR_DELETE | GR_AUDIT_DELETE |
51536+ GR_AUDIT_READ | GR_AUDIT_WRITE |
51537+ GR_SUPPRESS, old_mnt);
51538+ } else {
51539+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
51540+ GR_CREATE | GR_DELETE |
51541+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
51542+ GR_AUDIT_READ | GR_AUDIT_WRITE |
51543+ GR_SUPPRESS, parent_mnt);
51544+ comp2 =
51545+ gr_search_file(old_dentry,
51546+ GR_READ | GR_WRITE | GR_AUDIT_READ |
51547+ GR_DELETE | GR_AUDIT_DELETE |
51548+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
51549+ }
51550+
51551+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
51552+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
51553+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
51554+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
51555+ && !(comp2 & GR_SUPPRESS)) {
51556+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
51557+ error = -EACCES;
51558+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
51559+ error = -EACCES;
51560+
51561+ return error;
51562+}
51563+
51564+void
51565+gr_acl_handle_exit(void)
51566+{
51567+ u16 id;
51568+ char *rolename;
51569+ struct file *exec_file;
51570+
51571+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
51572+ !(current->role->roletype & GR_ROLE_PERSIST))) {
51573+ id = current->acl_role_id;
51574+ rolename = current->role->rolename;
51575+ gr_set_acls(1);
51576+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
51577+ }
51578+
51579+ write_lock(&grsec_exec_file_lock);
51580+ exec_file = current->exec_file;
51581+ current->exec_file = NULL;
51582+ write_unlock(&grsec_exec_file_lock);
51583+
51584+ if (exec_file)
51585+ fput(exec_file);
51586+}
51587+
51588+int
51589+gr_acl_handle_procpidmem(const struct task_struct *task)
51590+{
51591+ if (unlikely(!gr_acl_is_enabled()))
51592+ return 0;
51593+
51594+ if (task != current && task->acl->mode & GR_PROTPROCFD)
51595+ return -EACCES;
51596+
51597+ return 0;
51598+}
51599diff -urNp linux-2.6.32.43/grsecurity/gracl_ip.c linux-2.6.32.43/grsecurity/gracl_ip.c
51600--- linux-2.6.32.43/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
51601+++ linux-2.6.32.43/grsecurity/gracl_ip.c 2011-04-17 15:56:46.000000000 -0400
51602@@ -0,0 +1,382 @@
51603+#include <linux/kernel.h>
51604+#include <asm/uaccess.h>
51605+#include <asm/errno.h>
51606+#include <net/sock.h>
51607+#include <linux/file.h>
51608+#include <linux/fs.h>
51609+#include <linux/net.h>
51610+#include <linux/in.h>
51611+#include <linux/skbuff.h>
51612+#include <linux/ip.h>
51613+#include <linux/udp.h>
51614+#include <linux/smp_lock.h>
51615+#include <linux/types.h>
51616+#include <linux/sched.h>
51617+#include <linux/netdevice.h>
51618+#include <linux/inetdevice.h>
51619+#include <linux/gracl.h>
51620+#include <linux/grsecurity.h>
51621+#include <linux/grinternal.h>
51622+
51623+#define GR_BIND 0x01
51624+#define GR_CONNECT 0x02
51625+#define GR_INVERT 0x04
51626+#define GR_BINDOVERRIDE 0x08
51627+#define GR_CONNECTOVERRIDE 0x10
51628+#define GR_SOCK_FAMILY 0x20
51629+
51630+static const char * gr_protocols[IPPROTO_MAX] = {
51631+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
51632+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
51633+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
51634+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
51635+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
51636+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
51637+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
51638+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
51639+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
51640+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
51641+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
51642+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
51643+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
51644+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
51645+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
51646+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
51647+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
51648+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
51649+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
51650+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
51651+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
51652+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
51653+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
51654+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
51655+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
51656+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
51657+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
51658+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
51659+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
51660+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
51661+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
51662+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
51663+ };
51664+
51665+static const char * gr_socktypes[SOCK_MAX] = {
51666+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
51667+ "unknown:7", "unknown:8", "unknown:9", "packet"
51668+ };
51669+
51670+static const char * gr_sockfamilies[AF_MAX+1] = {
51671+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
51672+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
51673+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
51674+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
51675+ };
51676+
51677+const char *
51678+gr_proto_to_name(unsigned char proto)
51679+{
51680+ return gr_protocols[proto];
51681+}
51682+
51683+const char *
51684+gr_socktype_to_name(unsigned char type)
51685+{
51686+ return gr_socktypes[type];
51687+}
51688+
51689+const char *
51690+gr_sockfamily_to_name(unsigned char family)
51691+{
51692+ return gr_sockfamilies[family];
51693+}
51694+
51695+int
51696+gr_search_socket(const int domain, const int type, const int protocol)
51697+{
51698+ struct acl_subject_label *curr;
51699+ const struct cred *cred = current_cred();
51700+
51701+ if (unlikely(!gr_acl_is_enabled()))
51702+ goto exit;
51703+
51704+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
51705+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
51706+ goto exit; // let the kernel handle it
51707+
51708+ curr = current->acl;
51709+
51710+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
51711+ /* the family is allowed, if this is PF_INET allow it only if
51712+ the extra sock type/protocol checks pass */
51713+ if (domain == PF_INET)
51714+ goto inet_check;
51715+ goto exit;
51716+ } else {
51717+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
51718+ __u32 fakeip = 0;
51719+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
51720+ current->role->roletype, cred->uid,
51721+ cred->gid, current->exec_file ?
51722+ gr_to_filename(current->exec_file->f_path.dentry,
51723+ current->exec_file->f_path.mnt) :
51724+ curr->filename, curr->filename,
51725+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
51726+ &current->signal->saved_ip);
51727+ goto exit;
51728+ }
51729+ goto exit_fail;
51730+ }
51731+
51732+inet_check:
51733+ /* the rest of this checking is for IPv4 only */
51734+ if (!curr->ips)
51735+ goto exit;
51736+
51737+ if ((curr->ip_type & (1 << type)) &&
51738+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
51739+ goto exit;
51740+
51741+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
51742+ /* we don't place acls on raw sockets , and sometimes
51743+ dgram/ip sockets are opened for ioctl and not
51744+ bind/connect, so we'll fake a bind learn log */
51745+ if (type == SOCK_RAW || type == SOCK_PACKET) {
51746+ __u32 fakeip = 0;
51747+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
51748+ current->role->roletype, cred->uid,
51749+ cred->gid, current->exec_file ?
51750+ gr_to_filename(current->exec_file->f_path.dentry,
51751+ current->exec_file->f_path.mnt) :
51752+ curr->filename, curr->filename,
51753+ &fakeip, 0, type,
51754+ protocol, GR_CONNECT, &current->signal->saved_ip);
51755+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
51756+ __u32 fakeip = 0;
51757+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
51758+ current->role->roletype, cred->uid,
51759+ cred->gid, current->exec_file ?
51760+ gr_to_filename(current->exec_file->f_path.dentry,
51761+ current->exec_file->f_path.mnt) :
51762+ curr->filename, curr->filename,
51763+ &fakeip, 0, type,
51764+ protocol, GR_BIND, &current->signal->saved_ip);
51765+ }
51766+ /* we'll log when they use connect or bind */
51767+ goto exit;
51768+ }
51769+
51770+exit_fail:
51771+ if (domain == PF_INET)
51772+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
51773+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
51774+ else
51775+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
51776+ gr_socktype_to_name(type), protocol);
51777+
51778+ return 0;
51779+exit:
51780+ return 1;
51781+}
51782+
51783+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)
51784+{
51785+ if ((ip->mode & mode) &&
51786+ (ip_port >= ip->low) &&
51787+ (ip_port <= ip->high) &&
51788+ ((ntohl(ip_addr) & our_netmask) ==
51789+ (ntohl(our_addr) & our_netmask))
51790+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
51791+ && (ip->type & (1 << type))) {
51792+ if (ip->mode & GR_INVERT)
51793+ return 2; // specifically denied
51794+ else
51795+ return 1; // allowed
51796+ }
51797+
51798+ return 0; // not specifically allowed, may continue parsing
51799+}
51800+
51801+static int
51802+gr_search_connectbind(const int full_mode, struct sock *sk,
51803+ struct sockaddr_in *addr, const int type)
51804+{
51805+ char iface[IFNAMSIZ] = {0};
51806+ struct acl_subject_label *curr;
51807+ struct acl_ip_label *ip;
51808+ struct inet_sock *isk;
51809+ struct net_device *dev;
51810+ struct in_device *idev;
51811+ unsigned long i;
51812+ int ret;
51813+ int mode = full_mode & (GR_BIND | GR_CONNECT);
51814+ __u32 ip_addr = 0;
51815+ __u32 our_addr;
51816+ __u32 our_netmask;
51817+ char *p;
51818+ __u16 ip_port = 0;
51819+ const struct cred *cred = current_cred();
51820+
51821+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
51822+ return 0;
51823+
51824+ curr = current->acl;
51825+ isk = inet_sk(sk);
51826+
51827+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
51828+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
51829+ addr->sin_addr.s_addr = curr->inaddr_any_override;
51830+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
51831+ struct sockaddr_in saddr;
51832+ int err;
51833+
51834+ saddr.sin_family = AF_INET;
51835+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
51836+ saddr.sin_port = isk->sport;
51837+
51838+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
51839+ if (err)
51840+ return err;
51841+
51842+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
51843+ if (err)
51844+ return err;
51845+ }
51846+
51847+ if (!curr->ips)
51848+ return 0;
51849+
51850+ ip_addr = addr->sin_addr.s_addr;
51851+ ip_port = ntohs(addr->sin_port);
51852+
51853+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
51854+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
51855+ current->role->roletype, cred->uid,
51856+ cred->gid, current->exec_file ?
51857+ gr_to_filename(current->exec_file->f_path.dentry,
51858+ current->exec_file->f_path.mnt) :
51859+ curr->filename, curr->filename,
51860+ &ip_addr, ip_port, type,
51861+ sk->sk_protocol, mode, &current->signal->saved_ip);
51862+ return 0;
51863+ }
51864+
51865+ for (i = 0; i < curr->ip_num; i++) {
51866+ ip = *(curr->ips + i);
51867+ if (ip->iface != NULL) {
51868+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
51869+ p = strchr(iface, ':');
51870+ if (p != NULL)
51871+ *p = '\0';
51872+ dev = dev_get_by_name(sock_net(sk), iface);
51873+ if (dev == NULL)
51874+ continue;
51875+ idev = in_dev_get(dev);
51876+ if (idev == NULL) {
51877+ dev_put(dev);
51878+ continue;
51879+ }
51880+ rcu_read_lock();
51881+ for_ifa(idev) {
51882+ if (!strcmp(ip->iface, ifa->ifa_label)) {
51883+ our_addr = ifa->ifa_address;
51884+ our_netmask = 0xffffffff;
51885+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
51886+ if (ret == 1) {
51887+ rcu_read_unlock();
51888+ in_dev_put(idev);
51889+ dev_put(dev);
51890+ return 0;
51891+ } else if (ret == 2) {
51892+ rcu_read_unlock();
51893+ in_dev_put(idev);
51894+ dev_put(dev);
51895+ goto denied;
51896+ }
51897+ }
51898+ } endfor_ifa(idev);
51899+ rcu_read_unlock();
51900+ in_dev_put(idev);
51901+ dev_put(dev);
51902+ } else {
51903+ our_addr = ip->addr;
51904+ our_netmask = ip->netmask;
51905+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
51906+ if (ret == 1)
51907+ return 0;
51908+ else if (ret == 2)
51909+ goto denied;
51910+ }
51911+ }
51912+
51913+denied:
51914+ if (mode == GR_BIND)
51915+ 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));
51916+ else if (mode == GR_CONNECT)
51917+ 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));
51918+
51919+ return -EACCES;
51920+}
51921+
51922+int
51923+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
51924+{
51925+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
51926+}
51927+
51928+int
51929+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
51930+{
51931+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
51932+}
51933+
51934+int gr_search_listen(struct socket *sock)
51935+{
51936+ struct sock *sk = sock->sk;
51937+ struct sockaddr_in addr;
51938+
51939+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
51940+ addr.sin_port = inet_sk(sk)->sport;
51941+
51942+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
51943+}
51944+
51945+int gr_search_accept(struct socket *sock)
51946+{
51947+ struct sock *sk = sock->sk;
51948+ struct sockaddr_in addr;
51949+
51950+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
51951+ addr.sin_port = inet_sk(sk)->sport;
51952+
51953+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
51954+}
51955+
51956+int
51957+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
51958+{
51959+ if (addr)
51960+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
51961+ else {
51962+ struct sockaddr_in sin;
51963+ const struct inet_sock *inet = inet_sk(sk);
51964+
51965+ sin.sin_addr.s_addr = inet->daddr;
51966+ sin.sin_port = inet->dport;
51967+
51968+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
51969+ }
51970+}
51971+
51972+int
51973+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
51974+{
51975+ struct sockaddr_in sin;
51976+
51977+ if (unlikely(skb->len < sizeof (struct udphdr)))
51978+ return 0; // skip this packet
51979+
51980+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
51981+ sin.sin_port = udp_hdr(skb)->source;
51982+
51983+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
51984+}
51985diff -urNp linux-2.6.32.43/grsecurity/gracl_learn.c linux-2.6.32.43/grsecurity/gracl_learn.c
51986--- linux-2.6.32.43/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
51987+++ linux-2.6.32.43/grsecurity/gracl_learn.c 2011-07-14 21:02:03.000000000 -0400
51988@@ -0,0 +1,208 @@
51989+#include <linux/kernel.h>
51990+#include <linux/mm.h>
51991+#include <linux/sched.h>
51992+#include <linux/poll.h>
51993+#include <linux/smp_lock.h>
51994+#include <linux/string.h>
51995+#include <linux/file.h>
51996+#include <linux/types.h>
51997+#include <linux/vmalloc.h>
51998+#include <linux/grinternal.h>
51999+
52000+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
52001+ size_t count, loff_t *ppos);
52002+extern int gr_acl_is_enabled(void);
52003+
52004+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
52005+static int gr_learn_attached;
52006+
52007+/* use a 512k buffer */
52008+#define LEARN_BUFFER_SIZE (512 * 1024)
52009+
52010+static DEFINE_SPINLOCK(gr_learn_lock);
52011+static DEFINE_MUTEX(gr_learn_user_mutex);
52012+
52013+/* we need to maintain two buffers, so that the kernel context of grlearn
52014+ uses a semaphore around the userspace copying, and the other kernel contexts
52015+ use a spinlock when copying into the buffer, since they cannot sleep
52016+*/
52017+static char *learn_buffer;
52018+static char *learn_buffer_user;
52019+static int learn_buffer_len;
52020+static int learn_buffer_user_len;
52021+
52022+static ssize_t
52023+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
52024+{
52025+ DECLARE_WAITQUEUE(wait, current);
52026+ ssize_t retval = 0;
52027+
52028+ add_wait_queue(&learn_wait, &wait);
52029+ set_current_state(TASK_INTERRUPTIBLE);
52030+ do {
52031+ mutex_lock(&gr_learn_user_mutex);
52032+ spin_lock(&gr_learn_lock);
52033+ if (learn_buffer_len)
52034+ break;
52035+ spin_unlock(&gr_learn_lock);
52036+ mutex_unlock(&gr_learn_user_mutex);
52037+ if (file->f_flags & O_NONBLOCK) {
52038+ retval = -EAGAIN;
52039+ goto out;
52040+ }
52041+ if (signal_pending(current)) {
52042+ retval = -ERESTARTSYS;
52043+ goto out;
52044+ }
52045+
52046+ schedule();
52047+ } while (1);
52048+
52049+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
52050+ learn_buffer_user_len = learn_buffer_len;
52051+ retval = learn_buffer_len;
52052+ learn_buffer_len = 0;
52053+
52054+ spin_unlock(&gr_learn_lock);
52055+
52056+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
52057+ retval = -EFAULT;
52058+
52059+ mutex_unlock(&gr_learn_user_mutex);
52060+out:
52061+ set_current_state(TASK_RUNNING);
52062+ remove_wait_queue(&learn_wait, &wait);
52063+ return retval;
52064+}
52065+
52066+static unsigned int
52067+poll_learn(struct file * file, poll_table * wait)
52068+{
52069+ poll_wait(file, &learn_wait, wait);
52070+
52071+ if (learn_buffer_len)
52072+ return (POLLIN | POLLRDNORM);
52073+
52074+ return 0;
52075+}
52076+
52077+void
52078+gr_clear_learn_entries(void)
52079+{
52080+ char *tmp;
52081+
52082+ mutex_lock(&gr_learn_user_mutex);
52083+ spin_lock(&gr_learn_lock);
52084+ tmp = learn_buffer;
52085+ learn_buffer = NULL;
52086+ spin_unlock(&gr_learn_lock);
52087+ if (tmp)
52088+ vfree(tmp);
52089+ if (learn_buffer_user != NULL) {
52090+ vfree(learn_buffer_user);
52091+ learn_buffer_user = NULL;
52092+ }
52093+ learn_buffer_len = 0;
52094+ mutex_unlock(&gr_learn_user_mutex);
52095+
52096+ return;
52097+}
52098+
52099+void
52100+gr_add_learn_entry(const char *fmt, ...)
52101+{
52102+ va_list args;
52103+ unsigned int len;
52104+
52105+ if (!gr_learn_attached)
52106+ return;
52107+
52108+ spin_lock(&gr_learn_lock);
52109+
52110+ /* leave a gap at the end so we know when it's "full" but don't have to
52111+ compute the exact length of the string we're trying to append
52112+ */
52113+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
52114+ spin_unlock(&gr_learn_lock);
52115+ wake_up_interruptible(&learn_wait);
52116+ return;
52117+ }
52118+ if (learn_buffer == NULL) {
52119+ spin_unlock(&gr_learn_lock);
52120+ return;
52121+ }
52122+
52123+ va_start(args, fmt);
52124+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
52125+ va_end(args);
52126+
52127+ learn_buffer_len += len + 1;
52128+
52129+ spin_unlock(&gr_learn_lock);
52130+ wake_up_interruptible(&learn_wait);
52131+
52132+ return;
52133+}
52134+
52135+static int
52136+open_learn(struct inode *inode, struct file *file)
52137+{
52138+ if (file->f_mode & FMODE_READ && gr_learn_attached)
52139+ return -EBUSY;
52140+ if (file->f_mode & FMODE_READ) {
52141+ int retval = 0;
52142+ mutex_lock(&gr_learn_user_mutex);
52143+ if (learn_buffer == NULL)
52144+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
52145+ if (learn_buffer_user == NULL)
52146+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
52147+ if (learn_buffer == NULL) {
52148+ retval = -ENOMEM;
52149+ goto out_error;
52150+ }
52151+ if (learn_buffer_user == NULL) {
52152+ retval = -ENOMEM;
52153+ goto out_error;
52154+ }
52155+ learn_buffer_len = 0;
52156+ learn_buffer_user_len = 0;
52157+ gr_learn_attached = 1;
52158+out_error:
52159+ mutex_unlock(&gr_learn_user_mutex);
52160+ return retval;
52161+ }
52162+ return 0;
52163+}
52164+
52165+static int
52166+close_learn(struct inode *inode, struct file *file)
52167+{
52168+ if (file->f_mode & FMODE_READ) {
52169+ char *tmp = NULL;
52170+ mutex_lock(&gr_learn_user_mutex);
52171+ spin_lock(&gr_learn_lock);
52172+ tmp = learn_buffer;
52173+ learn_buffer = NULL;
52174+ spin_unlock(&gr_learn_lock);
52175+ if (tmp)
52176+ vfree(tmp);
52177+ if (learn_buffer_user != NULL) {
52178+ vfree(learn_buffer_user);
52179+ learn_buffer_user = NULL;
52180+ }
52181+ learn_buffer_len = 0;
52182+ learn_buffer_user_len = 0;
52183+ gr_learn_attached = 0;
52184+ mutex_unlock(&gr_learn_user_mutex);
52185+ }
52186+
52187+ return 0;
52188+}
52189+
52190+const struct file_operations grsec_fops = {
52191+ .read = read_learn,
52192+ .write = write_grsec_handler,
52193+ .open = open_learn,
52194+ .release = close_learn,
52195+ .poll = poll_learn,
52196+};
52197diff -urNp linux-2.6.32.43/grsecurity/gracl_res.c linux-2.6.32.43/grsecurity/gracl_res.c
52198--- linux-2.6.32.43/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
52199+++ linux-2.6.32.43/grsecurity/gracl_res.c 2011-04-17 15:56:46.000000000 -0400
52200@@ -0,0 +1,67 @@
52201+#include <linux/kernel.h>
52202+#include <linux/sched.h>
52203+#include <linux/gracl.h>
52204+#include <linux/grinternal.h>
52205+
52206+static const char *restab_log[] = {
52207+ [RLIMIT_CPU] = "RLIMIT_CPU",
52208+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
52209+ [RLIMIT_DATA] = "RLIMIT_DATA",
52210+ [RLIMIT_STACK] = "RLIMIT_STACK",
52211+ [RLIMIT_CORE] = "RLIMIT_CORE",
52212+ [RLIMIT_RSS] = "RLIMIT_RSS",
52213+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
52214+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
52215+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
52216+ [RLIMIT_AS] = "RLIMIT_AS",
52217+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
52218+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
52219+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
52220+ [RLIMIT_NICE] = "RLIMIT_NICE",
52221+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
52222+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
52223+ [GR_CRASH_RES] = "RLIMIT_CRASH"
52224+};
52225+
52226+void
52227+gr_log_resource(const struct task_struct *task,
52228+ const int res, const unsigned long wanted, const int gt)
52229+{
52230+ const struct cred *cred;
52231+ unsigned long rlim;
52232+
52233+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
52234+ return;
52235+
52236+ // not yet supported resource
52237+ if (unlikely(!restab_log[res]))
52238+ return;
52239+
52240+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
52241+ rlim = task->signal->rlim[res].rlim_max;
52242+ else
52243+ rlim = task->signal->rlim[res].rlim_cur;
52244+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
52245+ return;
52246+
52247+ rcu_read_lock();
52248+ cred = __task_cred(task);
52249+
52250+ if (res == RLIMIT_NPROC &&
52251+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
52252+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
52253+ goto out_rcu_unlock;
52254+ else if (res == RLIMIT_MEMLOCK &&
52255+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
52256+ goto out_rcu_unlock;
52257+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
52258+ goto out_rcu_unlock;
52259+ rcu_read_unlock();
52260+
52261+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
52262+
52263+ return;
52264+out_rcu_unlock:
52265+ rcu_read_unlock();
52266+ return;
52267+}
52268diff -urNp linux-2.6.32.43/grsecurity/gracl_segv.c linux-2.6.32.43/grsecurity/gracl_segv.c
52269--- linux-2.6.32.43/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
52270+++ linux-2.6.32.43/grsecurity/gracl_segv.c 2011-04-17 15:56:46.000000000 -0400
52271@@ -0,0 +1,284 @@
52272+#include <linux/kernel.h>
52273+#include <linux/mm.h>
52274+#include <asm/uaccess.h>
52275+#include <asm/errno.h>
52276+#include <asm/mman.h>
52277+#include <net/sock.h>
52278+#include <linux/file.h>
52279+#include <linux/fs.h>
52280+#include <linux/net.h>
52281+#include <linux/in.h>
52282+#include <linux/smp_lock.h>
52283+#include <linux/slab.h>
52284+#include <linux/types.h>
52285+#include <linux/sched.h>
52286+#include <linux/timer.h>
52287+#include <linux/gracl.h>
52288+#include <linux/grsecurity.h>
52289+#include <linux/grinternal.h>
52290+
52291+static struct crash_uid *uid_set;
52292+static unsigned short uid_used;
52293+static DEFINE_SPINLOCK(gr_uid_lock);
52294+extern rwlock_t gr_inode_lock;
52295+extern struct acl_subject_label *
52296+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
52297+ struct acl_role_label *role);
52298+extern int gr_fake_force_sig(int sig, struct task_struct *t);
52299+
52300+int
52301+gr_init_uidset(void)
52302+{
52303+ uid_set =
52304+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
52305+ uid_used = 0;
52306+
52307+ return uid_set ? 1 : 0;
52308+}
52309+
52310+void
52311+gr_free_uidset(void)
52312+{
52313+ if (uid_set)
52314+ kfree(uid_set);
52315+
52316+ return;
52317+}
52318+
52319+int
52320+gr_find_uid(const uid_t uid)
52321+{
52322+ struct crash_uid *tmp = uid_set;
52323+ uid_t buid;
52324+ int low = 0, high = uid_used - 1, mid;
52325+
52326+ while (high >= low) {
52327+ mid = (low + high) >> 1;
52328+ buid = tmp[mid].uid;
52329+ if (buid == uid)
52330+ return mid;
52331+ if (buid > uid)
52332+ high = mid - 1;
52333+ if (buid < uid)
52334+ low = mid + 1;
52335+ }
52336+
52337+ return -1;
52338+}
52339+
52340+static __inline__ void
52341+gr_insertsort(void)
52342+{
52343+ unsigned short i, j;
52344+ struct crash_uid index;
52345+
52346+ for (i = 1; i < uid_used; i++) {
52347+ index = uid_set[i];
52348+ j = i;
52349+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
52350+ uid_set[j] = uid_set[j - 1];
52351+ j--;
52352+ }
52353+ uid_set[j] = index;
52354+ }
52355+
52356+ return;
52357+}
52358+
52359+static __inline__ void
52360+gr_insert_uid(const uid_t uid, const unsigned long expires)
52361+{
52362+ int loc;
52363+
52364+ if (uid_used == GR_UIDTABLE_MAX)
52365+ return;
52366+
52367+ loc = gr_find_uid(uid);
52368+
52369+ if (loc >= 0) {
52370+ uid_set[loc].expires = expires;
52371+ return;
52372+ }
52373+
52374+ uid_set[uid_used].uid = uid;
52375+ uid_set[uid_used].expires = expires;
52376+ uid_used++;
52377+
52378+ gr_insertsort();
52379+
52380+ return;
52381+}
52382+
52383+void
52384+gr_remove_uid(const unsigned short loc)
52385+{
52386+ unsigned short i;
52387+
52388+ for (i = loc + 1; i < uid_used; i++)
52389+ uid_set[i - 1] = uid_set[i];
52390+
52391+ uid_used--;
52392+
52393+ return;
52394+}
52395+
52396+int
52397+gr_check_crash_uid(const uid_t uid)
52398+{
52399+ int loc;
52400+ int ret = 0;
52401+
52402+ if (unlikely(!gr_acl_is_enabled()))
52403+ return 0;
52404+
52405+ spin_lock(&gr_uid_lock);
52406+ loc = gr_find_uid(uid);
52407+
52408+ if (loc < 0)
52409+ goto out_unlock;
52410+
52411+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
52412+ gr_remove_uid(loc);
52413+ else
52414+ ret = 1;
52415+
52416+out_unlock:
52417+ spin_unlock(&gr_uid_lock);
52418+ return ret;
52419+}
52420+
52421+static __inline__ int
52422+proc_is_setxid(const struct cred *cred)
52423+{
52424+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
52425+ cred->uid != cred->fsuid)
52426+ return 1;
52427+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
52428+ cred->gid != cred->fsgid)
52429+ return 1;
52430+
52431+ return 0;
52432+}
52433+
52434+void
52435+gr_handle_crash(struct task_struct *task, const int sig)
52436+{
52437+ struct acl_subject_label *curr;
52438+ struct acl_subject_label *curr2;
52439+ struct task_struct *tsk, *tsk2;
52440+ const struct cred *cred;
52441+ const struct cred *cred2;
52442+
52443+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
52444+ return;
52445+
52446+ if (unlikely(!gr_acl_is_enabled()))
52447+ return;
52448+
52449+ curr = task->acl;
52450+
52451+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
52452+ return;
52453+
52454+ if (time_before_eq(curr->expires, get_seconds())) {
52455+ curr->expires = 0;
52456+ curr->crashes = 0;
52457+ }
52458+
52459+ curr->crashes++;
52460+
52461+ if (!curr->expires)
52462+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
52463+
52464+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
52465+ time_after(curr->expires, get_seconds())) {
52466+ rcu_read_lock();
52467+ cred = __task_cred(task);
52468+ if (cred->uid && proc_is_setxid(cred)) {
52469+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
52470+ spin_lock(&gr_uid_lock);
52471+ gr_insert_uid(cred->uid, curr->expires);
52472+ spin_unlock(&gr_uid_lock);
52473+ curr->expires = 0;
52474+ curr->crashes = 0;
52475+ read_lock(&tasklist_lock);
52476+ do_each_thread(tsk2, tsk) {
52477+ cred2 = __task_cred(tsk);
52478+ if (tsk != task && cred2->uid == cred->uid)
52479+ gr_fake_force_sig(SIGKILL, tsk);
52480+ } while_each_thread(tsk2, tsk);
52481+ read_unlock(&tasklist_lock);
52482+ } else {
52483+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
52484+ read_lock(&tasklist_lock);
52485+ do_each_thread(tsk2, tsk) {
52486+ if (likely(tsk != task)) {
52487+ curr2 = tsk->acl;
52488+
52489+ if (curr2->device == curr->device &&
52490+ curr2->inode == curr->inode)
52491+ gr_fake_force_sig(SIGKILL, tsk);
52492+ }
52493+ } while_each_thread(tsk2, tsk);
52494+ read_unlock(&tasklist_lock);
52495+ }
52496+ rcu_read_unlock();
52497+ }
52498+
52499+ return;
52500+}
52501+
52502+int
52503+gr_check_crash_exec(const struct file *filp)
52504+{
52505+ struct acl_subject_label *curr;
52506+
52507+ if (unlikely(!gr_acl_is_enabled()))
52508+ return 0;
52509+
52510+ read_lock(&gr_inode_lock);
52511+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
52512+ filp->f_path.dentry->d_inode->i_sb->s_dev,
52513+ current->role);
52514+ read_unlock(&gr_inode_lock);
52515+
52516+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
52517+ (!curr->crashes && !curr->expires))
52518+ return 0;
52519+
52520+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
52521+ time_after(curr->expires, get_seconds()))
52522+ return 1;
52523+ else if (time_before_eq(curr->expires, get_seconds())) {
52524+ curr->crashes = 0;
52525+ curr->expires = 0;
52526+ }
52527+
52528+ return 0;
52529+}
52530+
52531+void
52532+gr_handle_alertkill(struct task_struct *task)
52533+{
52534+ struct acl_subject_label *curracl;
52535+ __u32 curr_ip;
52536+ struct task_struct *p, *p2;
52537+
52538+ if (unlikely(!gr_acl_is_enabled()))
52539+ return;
52540+
52541+ curracl = task->acl;
52542+ curr_ip = task->signal->curr_ip;
52543+
52544+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
52545+ read_lock(&tasklist_lock);
52546+ do_each_thread(p2, p) {
52547+ if (p->signal->curr_ip == curr_ip)
52548+ gr_fake_force_sig(SIGKILL, p);
52549+ } while_each_thread(p2, p);
52550+ read_unlock(&tasklist_lock);
52551+ } else if (curracl->mode & GR_KILLPROC)
52552+ gr_fake_force_sig(SIGKILL, task);
52553+
52554+ return;
52555+}
52556diff -urNp linux-2.6.32.43/grsecurity/gracl_shm.c linux-2.6.32.43/grsecurity/gracl_shm.c
52557--- linux-2.6.32.43/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
52558+++ linux-2.6.32.43/grsecurity/gracl_shm.c 2011-04-17 15:56:46.000000000 -0400
52559@@ -0,0 +1,40 @@
52560+#include <linux/kernel.h>
52561+#include <linux/mm.h>
52562+#include <linux/sched.h>
52563+#include <linux/file.h>
52564+#include <linux/ipc.h>
52565+#include <linux/gracl.h>
52566+#include <linux/grsecurity.h>
52567+#include <linux/grinternal.h>
52568+
52569+int
52570+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
52571+ const time_t shm_createtime, const uid_t cuid, const int shmid)
52572+{
52573+ struct task_struct *task;
52574+
52575+ if (!gr_acl_is_enabled())
52576+ return 1;
52577+
52578+ rcu_read_lock();
52579+ read_lock(&tasklist_lock);
52580+
52581+ task = find_task_by_vpid(shm_cprid);
52582+
52583+ if (unlikely(!task))
52584+ task = find_task_by_vpid(shm_lapid);
52585+
52586+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
52587+ (task->pid == shm_lapid)) &&
52588+ (task->acl->mode & GR_PROTSHM) &&
52589+ (task->acl != current->acl))) {
52590+ read_unlock(&tasklist_lock);
52591+ rcu_read_unlock();
52592+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
52593+ return 0;
52594+ }
52595+ read_unlock(&tasklist_lock);
52596+ rcu_read_unlock();
52597+
52598+ return 1;
52599+}
52600diff -urNp linux-2.6.32.43/grsecurity/grsec_chdir.c linux-2.6.32.43/grsecurity/grsec_chdir.c
52601--- linux-2.6.32.43/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
52602+++ linux-2.6.32.43/grsecurity/grsec_chdir.c 2011-04-17 15:56:46.000000000 -0400
52603@@ -0,0 +1,19 @@
52604+#include <linux/kernel.h>
52605+#include <linux/sched.h>
52606+#include <linux/fs.h>
52607+#include <linux/file.h>
52608+#include <linux/grsecurity.h>
52609+#include <linux/grinternal.h>
52610+
52611+void
52612+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
52613+{
52614+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
52615+ if ((grsec_enable_chdir && grsec_enable_group &&
52616+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
52617+ !grsec_enable_group)) {
52618+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
52619+ }
52620+#endif
52621+ return;
52622+}
52623diff -urNp linux-2.6.32.43/grsecurity/grsec_chroot.c linux-2.6.32.43/grsecurity/grsec_chroot.c
52624--- linux-2.6.32.43/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
52625+++ linux-2.6.32.43/grsecurity/grsec_chroot.c 2011-07-18 17:14:10.000000000 -0400
52626@@ -0,0 +1,384 @@
52627+#include <linux/kernel.h>
52628+#include <linux/module.h>
52629+#include <linux/sched.h>
52630+#include <linux/file.h>
52631+#include <linux/fs.h>
52632+#include <linux/mount.h>
52633+#include <linux/types.h>
52634+#include <linux/pid_namespace.h>
52635+#include <linux/grsecurity.h>
52636+#include <linux/grinternal.h>
52637+
52638+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
52639+{
52640+#ifdef CONFIG_GRKERNSEC
52641+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
52642+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
52643+ task->gr_is_chrooted = 1;
52644+ else
52645+ task->gr_is_chrooted = 0;
52646+
52647+ task->gr_chroot_dentry = path->dentry;
52648+#endif
52649+ return;
52650+}
52651+
52652+void gr_clear_chroot_entries(struct task_struct *task)
52653+{
52654+#ifdef CONFIG_GRKERNSEC
52655+ task->gr_is_chrooted = 0;
52656+ task->gr_chroot_dentry = NULL;
52657+#endif
52658+ return;
52659+}
52660+
52661+int
52662+gr_handle_chroot_unix(const pid_t pid)
52663+{
52664+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
52665+ struct task_struct *p;
52666+
52667+ if (unlikely(!grsec_enable_chroot_unix))
52668+ return 1;
52669+
52670+ if (likely(!proc_is_chrooted(current)))
52671+ return 1;
52672+
52673+ rcu_read_lock();
52674+ read_lock(&tasklist_lock);
52675+
52676+ p = find_task_by_vpid_unrestricted(pid);
52677+ if (unlikely(p && !have_same_root(current, p))) {
52678+ read_unlock(&tasklist_lock);
52679+ rcu_read_unlock();
52680+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
52681+ return 0;
52682+ }
52683+ read_unlock(&tasklist_lock);
52684+ rcu_read_unlock();
52685+#endif
52686+ return 1;
52687+}
52688+
52689+int
52690+gr_handle_chroot_nice(void)
52691+{
52692+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
52693+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
52694+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
52695+ return -EPERM;
52696+ }
52697+#endif
52698+ return 0;
52699+}
52700+
52701+int
52702+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
52703+{
52704+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
52705+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
52706+ && proc_is_chrooted(current)) {
52707+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
52708+ return -EACCES;
52709+ }
52710+#endif
52711+ return 0;
52712+}
52713+
52714+int
52715+gr_handle_chroot_rawio(const struct inode *inode)
52716+{
52717+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52718+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52719+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
52720+ return 1;
52721+#endif
52722+ return 0;
52723+}
52724+
52725+int
52726+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
52727+{
52728+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
52729+ struct task_struct *p;
52730+ int ret = 0;
52731+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
52732+ return ret;
52733+
52734+ read_lock(&tasklist_lock);
52735+ do_each_pid_task(pid, type, p) {
52736+ if (!have_same_root(current, p)) {
52737+ ret = 1;
52738+ goto out;
52739+ }
52740+ } while_each_pid_task(pid, type, p);
52741+out:
52742+ read_unlock(&tasklist_lock);
52743+ return ret;
52744+#endif
52745+ return 0;
52746+}
52747+
52748+int
52749+gr_pid_is_chrooted(struct task_struct *p)
52750+{
52751+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
52752+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
52753+ return 0;
52754+
52755+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
52756+ !have_same_root(current, p)) {
52757+ return 1;
52758+ }
52759+#endif
52760+ return 0;
52761+}
52762+
52763+EXPORT_SYMBOL(gr_pid_is_chrooted);
52764+
52765+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
52766+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
52767+{
52768+ struct dentry *dentry = (struct dentry *)u_dentry;
52769+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
52770+ struct dentry *realroot;
52771+ struct vfsmount *realrootmnt;
52772+ struct dentry *currentroot;
52773+ struct vfsmount *currentmnt;
52774+ struct task_struct *reaper = &init_task;
52775+ int ret = 1;
52776+
52777+ read_lock(&reaper->fs->lock);
52778+ realrootmnt = mntget(reaper->fs->root.mnt);
52779+ realroot = dget(reaper->fs->root.dentry);
52780+ read_unlock(&reaper->fs->lock);
52781+
52782+ read_lock(&current->fs->lock);
52783+ currentmnt = mntget(current->fs->root.mnt);
52784+ currentroot = dget(current->fs->root.dentry);
52785+ read_unlock(&current->fs->lock);
52786+
52787+ spin_lock(&dcache_lock);
52788+ for (;;) {
52789+ if (unlikely((dentry == realroot && mnt == realrootmnt)
52790+ || (dentry == currentroot && mnt == currentmnt)))
52791+ break;
52792+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
52793+ if (mnt->mnt_parent == mnt)
52794+ break;
52795+ dentry = mnt->mnt_mountpoint;
52796+ mnt = mnt->mnt_parent;
52797+ continue;
52798+ }
52799+ dentry = dentry->d_parent;
52800+ }
52801+ spin_unlock(&dcache_lock);
52802+
52803+ dput(currentroot);
52804+ mntput(currentmnt);
52805+
52806+ /* access is outside of chroot */
52807+ if (dentry == realroot && mnt == realrootmnt)
52808+ ret = 0;
52809+
52810+ dput(realroot);
52811+ mntput(realrootmnt);
52812+ return ret;
52813+}
52814+#endif
52815+
52816+int
52817+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
52818+{
52819+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
52820+ if (!grsec_enable_chroot_fchdir)
52821+ return 1;
52822+
52823+ if (!proc_is_chrooted(current))
52824+ return 1;
52825+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
52826+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
52827+ return 0;
52828+ }
52829+#endif
52830+ return 1;
52831+}
52832+
52833+int
52834+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
52835+ const time_t shm_createtime)
52836+{
52837+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
52838+ struct task_struct *p;
52839+ time_t starttime;
52840+
52841+ if (unlikely(!grsec_enable_chroot_shmat))
52842+ return 1;
52843+
52844+ if (likely(!proc_is_chrooted(current)))
52845+ return 1;
52846+
52847+ rcu_read_lock();
52848+ read_lock(&tasklist_lock);
52849+
52850+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
52851+ starttime = p->start_time.tv_sec;
52852+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
52853+ if (have_same_root(current, p)) {
52854+ goto allow;
52855+ } else {
52856+ read_unlock(&tasklist_lock);
52857+ rcu_read_unlock();
52858+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
52859+ return 0;
52860+ }
52861+ }
52862+ /* creator exited, pid reuse, fall through to next check */
52863+ }
52864+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
52865+ if (unlikely(!have_same_root(current, p))) {
52866+ read_unlock(&tasklist_lock);
52867+ rcu_read_unlock();
52868+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
52869+ return 0;
52870+ }
52871+ }
52872+
52873+allow:
52874+ read_unlock(&tasklist_lock);
52875+ rcu_read_unlock();
52876+#endif
52877+ return 1;
52878+}
52879+
52880+void
52881+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
52882+{
52883+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
52884+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
52885+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
52886+#endif
52887+ return;
52888+}
52889+
52890+int
52891+gr_handle_chroot_mknod(const struct dentry *dentry,
52892+ const struct vfsmount *mnt, const int mode)
52893+{
52894+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
52895+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
52896+ proc_is_chrooted(current)) {
52897+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
52898+ return -EPERM;
52899+ }
52900+#endif
52901+ return 0;
52902+}
52903+
52904+int
52905+gr_handle_chroot_mount(const struct dentry *dentry,
52906+ const struct vfsmount *mnt, const char *dev_name)
52907+{
52908+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
52909+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
52910+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
52911+ return -EPERM;
52912+ }
52913+#endif
52914+ return 0;
52915+}
52916+
52917+int
52918+gr_handle_chroot_pivot(void)
52919+{
52920+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
52921+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
52922+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
52923+ return -EPERM;
52924+ }
52925+#endif
52926+ return 0;
52927+}
52928+
52929+int
52930+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
52931+{
52932+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
52933+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
52934+ !gr_is_outside_chroot(dentry, mnt)) {
52935+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
52936+ return -EPERM;
52937+ }
52938+#endif
52939+ return 0;
52940+}
52941+
52942+int
52943+gr_handle_chroot_caps(struct path *path)
52944+{
52945+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52946+ if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
52947+ (init_task.fs->root.dentry != path->dentry) &&
52948+ (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
52949+
52950+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
52951+ const struct cred *old = current_cred();
52952+ struct cred *new = prepare_creds();
52953+ if (new == NULL)
52954+ return 1;
52955+
52956+ new->cap_permitted = cap_drop(old->cap_permitted,
52957+ chroot_caps);
52958+ new->cap_inheritable = cap_drop(old->cap_inheritable,
52959+ chroot_caps);
52960+ new->cap_effective = cap_drop(old->cap_effective,
52961+ chroot_caps);
52962+
52963+ commit_creds(new);
52964+
52965+ return 0;
52966+ }
52967+#endif
52968+ return 0;
52969+}
52970+
52971+int
52972+gr_handle_chroot_sysctl(const int op)
52973+{
52974+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
52975+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
52976+ && (op & MAY_WRITE))
52977+ return -EACCES;
52978+#endif
52979+ return 0;
52980+}
52981+
52982+void
52983+gr_handle_chroot_chdir(struct path *path)
52984+{
52985+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
52986+ if (grsec_enable_chroot_chdir)
52987+ set_fs_pwd(current->fs, path);
52988+#endif
52989+ return;
52990+}
52991+
52992+int
52993+gr_handle_chroot_chmod(const struct dentry *dentry,
52994+ const struct vfsmount *mnt, const int mode)
52995+{
52996+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
52997+ /* allow chmod +s on directories, but not on files */
52998+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
52999+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
53000+ proc_is_chrooted(current)) {
53001+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
53002+ return -EPERM;
53003+ }
53004+#endif
53005+ return 0;
53006+}
53007+
53008+#ifdef CONFIG_SECURITY
53009+EXPORT_SYMBOL(gr_handle_chroot_caps);
53010+#endif
53011diff -urNp linux-2.6.32.43/grsecurity/grsec_disabled.c linux-2.6.32.43/grsecurity/grsec_disabled.c
53012--- linux-2.6.32.43/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
53013+++ linux-2.6.32.43/grsecurity/grsec_disabled.c 2011-04-17 15:56:46.000000000 -0400
53014@@ -0,0 +1,447 @@
53015+#include <linux/kernel.h>
53016+#include <linux/module.h>
53017+#include <linux/sched.h>
53018+#include <linux/file.h>
53019+#include <linux/fs.h>
53020+#include <linux/kdev_t.h>
53021+#include <linux/net.h>
53022+#include <linux/in.h>
53023+#include <linux/ip.h>
53024+#include <linux/skbuff.h>
53025+#include <linux/sysctl.h>
53026+
53027+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53028+void
53029+pax_set_initial_flags(struct linux_binprm *bprm)
53030+{
53031+ return;
53032+}
53033+#endif
53034+
53035+#ifdef CONFIG_SYSCTL
53036+__u32
53037+gr_handle_sysctl(const struct ctl_table * table, const int op)
53038+{
53039+ return 0;
53040+}
53041+#endif
53042+
53043+#ifdef CONFIG_TASKSTATS
53044+int gr_is_taskstats_denied(int pid)
53045+{
53046+ return 0;
53047+}
53048+#endif
53049+
53050+int
53051+gr_acl_is_enabled(void)
53052+{
53053+ return 0;
53054+}
53055+
53056+int
53057+gr_handle_rawio(const struct inode *inode)
53058+{
53059+ return 0;
53060+}
53061+
53062+void
53063+gr_acl_handle_psacct(struct task_struct *task, const long code)
53064+{
53065+ return;
53066+}
53067+
53068+int
53069+gr_handle_ptrace(struct task_struct *task, const long request)
53070+{
53071+ return 0;
53072+}
53073+
53074+int
53075+gr_handle_proc_ptrace(struct task_struct *task)
53076+{
53077+ return 0;
53078+}
53079+
53080+void
53081+gr_learn_resource(const struct task_struct *task,
53082+ const int res, const unsigned long wanted, const int gt)
53083+{
53084+ return;
53085+}
53086+
53087+int
53088+gr_set_acls(const int type)
53089+{
53090+ return 0;
53091+}
53092+
53093+int
53094+gr_check_hidden_task(const struct task_struct *tsk)
53095+{
53096+ return 0;
53097+}
53098+
53099+int
53100+gr_check_protected_task(const struct task_struct *task)
53101+{
53102+ return 0;
53103+}
53104+
53105+int
53106+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53107+{
53108+ return 0;
53109+}
53110+
53111+void
53112+gr_copy_label(struct task_struct *tsk)
53113+{
53114+ return;
53115+}
53116+
53117+void
53118+gr_set_pax_flags(struct task_struct *task)
53119+{
53120+ return;
53121+}
53122+
53123+int
53124+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53125+ const int unsafe_share)
53126+{
53127+ return 0;
53128+}
53129+
53130+void
53131+gr_handle_delete(const ino_t ino, const dev_t dev)
53132+{
53133+ return;
53134+}
53135+
53136+void
53137+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53138+{
53139+ return;
53140+}
53141+
53142+void
53143+gr_handle_crash(struct task_struct *task, const int sig)
53144+{
53145+ return;
53146+}
53147+
53148+int
53149+gr_check_crash_exec(const struct file *filp)
53150+{
53151+ return 0;
53152+}
53153+
53154+int
53155+gr_check_crash_uid(const uid_t uid)
53156+{
53157+ return 0;
53158+}
53159+
53160+void
53161+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53162+ struct dentry *old_dentry,
53163+ struct dentry *new_dentry,
53164+ struct vfsmount *mnt, const __u8 replace)
53165+{
53166+ return;
53167+}
53168+
53169+int
53170+gr_search_socket(const int family, const int type, const int protocol)
53171+{
53172+ return 1;
53173+}
53174+
53175+int
53176+gr_search_connectbind(const int mode, const struct socket *sock,
53177+ const struct sockaddr_in *addr)
53178+{
53179+ return 0;
53180+}
53181+
53182+int
53183+gr_is_capable(const int cap)
53184+{
53185+ return 1;
53186+}
53187+
53188+int
53189+gr_is_capable_nolog(const int cap)
53190+{
53191+ return 1;
53192+}
53193+
53194+void
53195+gr_handle_alertkill(struct task_struct *task)
53196+{
53197+ return;
53198+}
53199+
53200+__u32
53201+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
53202+{
53203+ return 1;
53204+}
53205+
53206+__u32
53207+gr_acl_handle_hidden_file(const struct dentry * dentry,
53208+ const struct vfsmount * mnt)
53209+{
53210+ return 1;
53211+}
53212+
53213+__u32
53214+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
53215+ const int fmode)
53216+{
53217+ return 1;
53218+}
53219+
53220+__u32
53221+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
53222+{
53223+ return 1;
53224+}
53225+
53226+__u32
53227+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
53228+{
53229+ return 1;
53230+}
53231+
53232+int
53233+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
53234+ unsigned int *vm_flags)
53235+{
53236+ return 1;
53237+}
53238+
53239+__u32
53240+gr_acl_handle_truncate(const struct dentry * dentry,
53241+ const struct vfsmount * mnt)
53242+{
53243+ return 1;
53244+}
53245+
53246+__u32
53247+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
53248+{
53249+ return 1;
53250+}
53251+
53252+__u32
53253+gr_acl_handle_access(const struct dentry * dentry,
53254+ const struct vfsmount * mnt, const int fmode)
53255+{
53256+ return 1;
53257+}
53258+
53259+__u32
53260+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
53261+ mode_t mode)
53262+{
53263+ return 1;
53264+}
53265+
53266+__u32
53267+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
53268+ mode_t mode)
53269+{
53270+ return 1;
53271+}
53272+
53273+__u32
53274+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
53275+{
53276+ return 1;
53277+}
53278+
53279+__u32
53280+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
53281+{
53282+ return 1;
53283+}
53284+
53285+void
53286+grsecurity_init(void)
53287+{
53288+ return;
53289+}
53290+
53291+__u32
53292+gr_acl_handle_mknod(const struct dentry * new_dentry,
53293+ const struct dentry * parent_dentry,
53294+ const struct vfsmount * parent_mnt,
53295+ const int mode)
53296+{
53297+ return 1;
53298+}
53299+
53300+__u32
53301+gr_acl_handle_mkdir(const struct dentry * new_dentry,
53302+ const struct dentry * parent_dentry,
53303+ const struct vfsmount * parent_mnt)
53304+{
53305+ return 1;
53306+}
53307+
53308+__u32
53309+gr_acl_handle_symlink(const struct dentry * new_dentry,
53310+ const struct dentry * parent_dentry,
53311+ const struct vfsmount * parent_mnt, const char *from)
53312+{
53313+ return 1;
53314+}
53315+
53316+__u32
53317+gr_acl_handle_link(const struct dentry * new_dentry,
53318+ const struct dentry * parent_dentry,
53319+ const struct vfsmount * parent_mnt,
53320+ const struct dentry * old_dentry,
53321+ const struct vfsmount * old_mnt, const char *to)
53322+{
53323+ return 1;
53324+}
53325+
53326+int
53327+gr_acl_handle_rename(const struct dentry *new_dentry,
53328+ const struct dentry *parent_dentry,
53329+ const struct vfsmount *parent_mnt,
53330+ const struct dentry *old_dentry,
53331+ const struct inode *old_parent_inode,
53332+ const struct vfsmount *old_mnt, const char *newname)
53333+{
53334+ return 0;
53335+}
53336+
53337+int
53338+gr_acl_handle_filldir(const struct file *file, const char *name,
53339+ const int namelen, const ino_t ino)
53340+{
53341+ return 1;
53342+}
53343+
53344+int
53345+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
53346+ const time_t shm_createtime, const uid_t cuid, const int shmid)
53347+{
53348+ return 1;
53349+}
53350+
53351+int
53352+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
53353+{
53354+ return 0;
53355+}
53356+
53357+int
53358+gr_search_accept(const struct socket *sock)
53359+{
53360+ return 0;
53361+}
53362+
53363+int
53364+gr_search_listen(const struct socket *sock)
53365+{
53366+ return 0;
53367+}
53368+
53369+int
53370+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
53371+{
53372+ return 0;
53373+}
53374+
53375+__u32
53376+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
53377+{
53378+ return 1;
53379+}
53380+
53381+__u32
53382+gr_acl_handle_creat(const struct dentry * dentry,
53383+ const struct dentry * p_dentry,
53384+ const struct vfsmount * p_mnt, const int fmode,
53385+ const int imode)
53386+{
53387+ return 1;
53388+}
53389+
53390+void
53391+gr_acl_handle_exit(void)
53392+{
53393+ return;
53394+}
53395+
53396+int
53397+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53398+{
53399+ return 1;
53400+}
53401+
53402+void
53403+gr_set_role_label(const uid_t uid, const gid_t gid)
53404+{
53405+ return;
53406+}
53407+
53408+int
53409+gr_acl_handle_procpidmem(const struct task_struct *task)
53410+{
53411+ return 0;
53412+}
53413+
53414+int
53415+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
53416+{
53417+ return 0;
53418+}
53419+
53420+int
53421+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
53422+{
53423+ return 0;
53424+}
53425+
53426+void
53427+gr_set_kernel_label(struct task_struct *task)
53428+{
53429+ return;
53430+}
53431+
53432+int
53433+gr_check_user_change(int real, int effective, int fs)
53434+{
53435+ return 0;
53436+}
53437+
53438+int
53439+gr_check_group_change(int real, int effective, int fs)
53440+{
53441+ return 0;
53442+}
53443+
53444+int gr_acl_enable_at_secure(void)
53445+{
53446+ return 0;
53447+}
53448+
53449+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53450+{
53451+ return dentry->d_inode->i_sb->s_dev;
53452+}
53453+
53454+EXPORT_SYMBOL(gr_is_capable);
53455+EXPORT_SYMBOL(gr_is_capable_nolog);
53456+EXPORT_SYMBOL(gr_learn_resource);
53457+EXPORT_SYMBOL(gr_set_kernel_label);
53458+#ifdef CONFIG_SECURITY
53459+EXPORT_SYMBOL(gr_check_user_change);
53460+EXPORT_SYMBOL(gr_check_group_change);
53461+#endif
53462diff -urNp linux-2.6.32.43/grsecurity/grsec_exec.c linux-2.6.32.43/grsecurity/grsec_exec.c
53463--- linux-2.6.32.43/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
53464+++ linux-2.6.32.43/grsecurity/grsec_exec.c 2011-04-17 15:56:46.000000000 -0400
53465@@ -0,0 +1,148 @@
53466+#include <linux/kernel.h>
53467+#include <linux/sched.h>
53468+#include <linux/file.h>
53469+#include <linux/binfmts.h>
53470+#include <linux/smp_lock.h>
53471+#include <linux/fs.h>
53472+#include <linux/types.h>
53473+#include <linux/grdefs.h>
53474+#include <linux/grinternal.h>
53475+#include <linux/capability.h>
53476+#include <linux/compat.h>
53477+
53478+#include <asm/uaccess.h>
53479+
53480+#ifdef CONFIG_GRKERNSEC_EXECLOG
53481+static char gr_exec_arg_buf[132];
53482+static DEFINE_MUTEX(gr_exec_arg_mutex);
53483+#endif
53484+
53485+int
53486+gr_handle_nproc(void)
53487+{
53488+#ifdef CONFIG_GRKERNSEC_EXECVE
53489+ const struct cred *cred = current_cred();
53490+ if (grsec_enable_execve && cred->user &&
53491+ (atomic_read(&cred->user->processes) >
53492+ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
53493+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
53494+ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
53495+ return -EAGAIN;
53496+ }
53497+#endif
53498+ return 0;
53499+}
53500+
53501+void
53502+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
53503+{
53504+#ifdef CONFIG_GRKERNSEC_EXECLOG
53505+ char *grarg = gr_exec_arg_buf;
53506+ unsigned int i, x, execlen = 0;
53507+ char c;
53508+
53509+ if (!((grsec_enable_execlog && grsec_enable_group &&
53510+ in_group_p(grsec_audit_gid))
53511+ || (grsec_enable_execlog && !grsec_enable_group)))
53512+ return;
53513+
53514+ mutex_lock(&gr_exec_arg_mutex);
53515+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
53516+
53517+ if (unlikely(argv == NULL))
53518+ goto log;
53519+
53520+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
53521+ const char __user *p;
53522+ unsigned int len;
53523+
53524+ if (copy_from_user(&p, argv + i, sizeof(p)))
53525+ goto log;
53526+ if (!p)
53527+ goto log;
53528+ len = strnlen_user(p, 128 - execlen);
53529+ if (len > 128 - execlen)
53530+ len = 128 - execlen;
53531+ else if (len > 0)
53532+ len--;
53533+ if (copy_from_user(grarg + execlen, p, len))
53534+ goto log;
53535+
53536+ /* rewrite unprintable characters */
53537+ for (x = 0; x < len; x++) {
53538+ c = *(grarg + execlen + x);
53539+ if (c < 32 || c > 126)
53540+ *(grarg + execlen + x) = ' ';
53541+ }
53542+
53543+ execlen += len;
53544+ *(grarg + execlen) = ' ';
53545+ *(grarg + execlen + 1) = '\0';
53546+ execlen++;
53547+ }
53548+
53549+ log:
53550+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
53551+ bprm->file->f_path.mnt, grarg);
53552+ mutex_unlock(&gr_exec_arg_mutex);
53553+#endif
53554+ return;
53555+}
53556+
53557+#ifdef CONFIG_COMPAT
53558+void
53559+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
53560+{
53561+#ifdef CONFIG_GRKERNSEC_EXECLOG
53562+ char *grarg = gr_exec_arg_buf;
53563+ unsigned int i, x, execlen = 0;
53564+ char c;
53565+
53566+ if (!((grsec_enable_execlog && grsec_enable_group &&
53567+ in_group_p(grsec_audit_gid))
53568+ || (grsec_enable_execlog && !grsec_enable_group)))
53569+ return;
53570+
53571+ mutex_lock(&gr_exec_arg_mutex);
53572+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
53573+
53574+ if (unlikely(argv == NULL))
53575+ goto log;
53576+
53577+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
53578+ compat_uptr_t p;
53579+ unsigned int len;
53580+
53581+ if (get_user(p, argv + i))
53582+ goto log;
53583+ len = strnlen_user(compat_ptr(p), 128 - execlen);
53584+ if (len > 128 - execlen)
53585+ len = 128 - execlen;
53586+ else if (len > 0)
53587+ len--;
53588+ else
53589+ goto log;
53590+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
53591+ goto log;
53592+
53593+ /* rewrite unprintable characters */
53594+ for (x = 0; x < len; x++) {
53595+ c = *(grarg + execlen + x);
53596+ if (c < 32 || c > 126)
53597+ *(grarg + execlen + x) = ' ';
53598+ }
53599+
53600+ execlen += len;
53601+ *(grarg + execlen) = ' ';
53602+ *(grarg + execlen + 1) = '\0';
53603+ execlen++;
53604+ }
53605+
53606+ log:
53607+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
53608+ bprm->file->f_path.mnt, grarg);
53609+ mutex_unlock(&gr_exec_arg_mutex);
53610+#endif
53611+ return;
53612+}
53613+#endif
53614diff -urNp linux-2.6.32.43/grsecurity/grsec_fifo.c linux-2.6.32.43/grsecurity/grsec_fifo.c
53615--- linux-2.6.32.43/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
53616+++ linux-2.6.32.43/grsecurity/grsec_fifo.c 2011-04-17 15:56:46.000000000 -0400
53617@@ -0,0 +1,24 @@
53618+#include <linux/kernel.h>
53619+#include <linux/sched.h>
53620+#include <linux/fs.h>
53621+#include <linux/file.h>
53622+#include <linux/grinternal.h>
53623+
53624+int
53625+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
53626+ const struct dentry *dir, const int flag, const int acc_mode)
53627+{
53628+#ifdef CONFIG_GRKERNSEC_FIFO
53629+ const struct cred *cred = current_cred();
53630+
53631+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
53632+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
53633+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
53634+ (cred->fsuid != dentry->d_inode->i_uid)) {
53635+ if (!inode_permission(dentry->d_inode, acc_mode))
53636+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
53637+ return -EACCES;
53638+ }
53639+#endif
53640+ return 0;
53641+}
53642diff -urNp linux-2.6.32.43/grsecurity/grsec_fork.c linux-2.6.32.43/grsecurity/grsec_fork.c
53643--- linux-2.6.32.43/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
53644+++ linux-2.6.32.43/grsecurity/grsec_fork.c 2011-04-17 15:56:46.000000000 -0400
53645@@ -0,0 +1,23 @@
53646+#include <linux/kernel.h>
53647+#include <linux/sched.h>
53648+#include <linux/grsecurity.h>
53649+#include <linux/grinternal.h>
53650+#include <linux/errno.h>
53651+
53652+void
53653+gr_log_forkfail(const int retval)
53654+{
53655+#ifdef CONFIG_GRKERNSEC_FORKFAIL
53656+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
53657+ switch (retval) {
53658+ case -EAGAIN:
53659+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
53660+ break;
53661+ case -ENOMEM:
53662+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
53663+ break;
53664+ }
53665+ }
53666+#endif
53667+ return;
53668+}
53669diff -urNp linux-2.6.32.43/grsecurity/grsec_init.c linux-2.6.32.43/grsecurity/grsec_init.c
53670--- linux-2.6.32.43/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
53671+++ linux-2.6.32.43/grsecurity/grsec_init.c 2011-06-29 19:35:26.000000000 -0400
53672@@ -0,0 +1,274 @@
53673+#include <linux/kernel.h>
53674+#include <linux/sched.h>
53675+#include <linux/mm.h>
53676+#include <linux/smp_lock.h>
53677+#include <linux/gracl.h>
53678+#include <linux/slab.h>
53679+#include <linux/vmalloc.h>
53680+#include <linux/percpu.h>
53681+#include <linux/module.h>
53682+
53683+int grsec_enable_brute;
53684+int grsec_enable_link;
53685+int grsec_enable_dmesg;
53686+int grsec_enable_harden_ptrace;
53687+int grsec_enable_fifo;
53688+int grsec_enable_execve;
53689+int grsec_enable_execlog;
53690+int grsec_enable_signal;
53691+int grsec_enable_forkfail;
53692+int grsec_enable_audit_ptrace;
53693+int grsec_enable_time;
53694+int grsec_enable_audit_textrel;
53695+int grsec_enable_group;
53696+int grsec_audit_gid;
53697+int grsec_enable_chdir;
53698+int grsec_enable_mount;
53699+int grsec_enable_rofs;
53700+int grsec_enable_chroot_findtask;
53701+int grsec_enable_chroot_mount;
53702+int grsec_enable_chroot_shmat;
53703+int grsec_enable_chroot_fchdir;
53704+int grsec_enable_chroot_double;
53705+int grsec_enable_chroot_pivot;
53706+int grsec_enable_chroot_chdir;
53707+int grsec_enable_chroot_chmod;
53708+int grsec_enable_chroot_mknod;
53709+int grsec_enable_chroot_nice;
53710+int grsec_enable_chroot_execlog;
53711+int grsec_enable_chroot_caps;
53712+int grsec_enable_chroot_sysctl;
53713+int grsec_enable_chroot_unix;
53714+int grsec_enable_tpe;
53715+int grsec_tpe_gid;
53716+int grsec_enable_blackhole;
53717+#ifdef CONFIG_IPV6_MODULE
53718+EXPORT_SYMBOL(grsec_enable_blackhole);
53719+#endif
53720+int grsec_lastack_retries;
53721+int grsec_enable_tpe_all;
53722+int grsec_enable_tpe_invert;
53723+int grsec_enable_socket_all;
53724+int grsec_socket_all_gid;
53725+int grsec_enable_socket_client;
53726+int grsec_socket_client_gid;
53727+int grsec_enable_socket_server;
53728+int grsec_socket_server_gid;
53729+int grsec_resource_logging;
53730+int grsec_disable_privio;
53731+int grsec_enable_log_rwxmaps;
53732+int grsec_lock;
53733+
53734+DEFINE_SPINLOCK(grsec_alert_lock);
53735+unsigned long grsec_alert_wtime = 0;
53736+unsigned long grsec_alert_fyet = 0;
53737+
53738+DEFINE_SPINLOCK(grsec_audit_lock);
53739+
53740+DEFINE_RWLOCK(grsec_exec_file_lock);
53741+
53742+char *gr_shared_page[4];
53743+
53744+char *gr_alert_log_fmt;
53745+char *gr_audit_log_fmt;
53746+char *gr_alert_log_buf;
53747+char *gr_audit_log_buf;
53748+
53749+extern struct gr_arg *gr_usermode;
53750+extern unsigned char *gr_system_salt;
53751+extern unsigned char *gr_system_sum;
53752+
53753+void __init
53754+grsecurity_init(void)
53755+{
53756+ int j;
53757+ /* create the per-cpu shared pages */
53758+
53759+#ifdef CONFIG_X86
53760+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
53761+#endif
53762+
53763+ for (j = 0; j < 4; j++) {
53764+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
53765+ if (gr_shared_page[j] == NULL) {
53766+ panic("Unable to allocate grsecurity shared page");
53767+ return;
53768+ }
53769+ }
53770+
53771+ /* allocate log buffers */
53772+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
53773+ if (!gr_alert_log_fmt) {
53774+ panic("Unable to allocate grsecurity alert log format buffer");
53775+ return;
53776+ }
53777+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
53778+ if (!gr_audit_log_fmt) {
53779+ panic("Unable to allocate grsecurity audit log format buffer");
53780+ return;
53781+ }
53782+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
53783+ if (!gr_alert_log_buf) {
53784+ panic("Unable to allocate grsecurity alert log buffer");
53785+ return;
53786+ }
53787+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
53788+ if (!gr_audit_log_buf) {
53789+ panic("Unable to allocate grsecurity audit log buffer");
53790+ return;
53791+ }
53792+
53793+ /* allocate memory for authentication structure */
53794+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
53795+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
53796+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
53797+
53798+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
53799+ panic("Unable to allocate grsecurity authentication structure");
53800+ return;
53801+ }
53802+
53803+
53804+#ifdef CONFIG_GRKERNSEC_IO
53805+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
53806+ grsec_disable_privio = 1;
53807+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
53808+ grsec_disable_privio = 1;
53809+#else
53810+ grsec_disable_privio = 0;
53811+#endif
53812+#endif
53813+
53814+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
53815+ /* for backward compatibility, tpe_invert always defaults to on if
53816+ enabled in the kernel
53817+ */
53818+ grsec_enable_tpe_invert = 1;
53819+#endif
53820+
53821+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
53822+#ifndef CONFIG_GRKERNSEC_SYSCTL
53823+ grsec_lock = 1;
53824+#endif
53825+
53826+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
53827+ grsec_enable_audit_textrel = 1;
53828+#endif
53829+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53830+ grsec_enable_log_rwxmaps = 1;
53831+#endif
53832+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
53833+ grsec_enable_group = 1;
53834+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
53835+#endif
53836+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
53837+ grsec_enable_chdir = 1;
53838+#endif
53839+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53840+ grsec_enable_harden_ptrace = 1;
53841+#endif
53842+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
53843+ grsec_enable_mount = 1;
53844+#endif
53845+#ifdef CONFIG_GRKERNSEC_LINK
53846+ grsec_enable_link = 1;
53847+#endif
53848+#ifdef CONFIG_GRKERNSEC_BRUTE
53849+ grsec_enable_brute = 1;
53850+#endif
53851+#ifdef CONFIG_GRKERNSEC_DMESG
53852+ grsec_enable_dmesg = 1;
53853+#endif
53854+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
53855+ grsec_enable_blackhole = 1;
53856+ grsec_lastack_retries = 4;
53857+#endif
53858+#ifdef CONFIG_GRKERNSEC_FIFO
53859+ grsec_enable_fifo = 1;
53860+#endif
53861+#ifdef CONFIG_GRKERNSEC_EXECVE
53862+ grsec_enable_execve = 1;
53863+#endif
53864+#ifdef CONFIG_GRKERNSEC_EXECLOG
53865+ grsec_enable_execlog = 1;
53866+#endif
53867+#ifdef CONFIG_GRKERNSEC_SIGNAL
53868+ grsec_enable_signal = 1;
53869+#endif
53870+#ifdef CONFIG_GRKERNSEC_FORKFAIL
53871+ grsec_enable_forkfail = 1;
53872+#endif
53873+#ifdef CONFIG_GRKERNSEC_TIME
53874+ grsec_enable_time = 1;
53875+#endif
53876+#ifdef CONFIG_GRKERNSEC_RESLOG
53877+ grsec_resource_logging = 1;
53878+#endif
53879+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
53880+ grsec_enable_chroot_findtask = 1;
53881+#endif
53882+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
53883+ grsec_enable_chroot_unix = 1;
53884+#endif
53885+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
53886+ grsec_enable_chroot_mount = 1;
53887+#endif
53888+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
53889+ grsec_enable_chroot_fchdir = 1;
53890+#endif
53891+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
53892+ grsec_enable_chroot_shmat = 1;
53893+#endif
53894+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
53895+ grsec_enable_audit_ptrace = 1;
53896+#endif
53897+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
53898+ grsec_enable_chroot_double = 1;
53899+#endif
53900+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
53901+ grsec_enable_chroot_pivot = 1;
53902+#endif
53903+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
53904+ grsec_enable_chroot_chdir = 1;
53905+#endif
53906+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
53907+ grsec_enable_chroot_chmod = 1;
53908+#endif
53909+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
53910+ grsec_enable_chroot_mknod = 1;
53911+#endif
53912+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
53913+ grsec_enable_chroot_nice = 1;
53914+#endif
53915+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
53916+ grsec_enable_chroot_execlog = 1;
53917+#endif
53918+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53919+ grsec_enable_chroot_caps = 1;
53920+#endif
53921+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
53922+ grsec_enable_chroot_sysctl = 1;
53923+#endif
53924+#ifdef CONFIG_GRKERNSEC_TPE
53925+ grsec_enable_tpe = 1;
53926+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
53927+#ifdef CONFIG_GRKERNSEC_TPE_ALL
53928+ grsec_enable_tpe_all = 1;
53929+#endif
53930+#endif
53931+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
53932+ grsec_enable_socket_all = 1;
53933+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
53934+#endif
53935+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
53936+ grsec_enable_socket_client = 1;
53937+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
53938+#endif
53939+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
53940+ grsec_enable_socket_server = 1;
53941+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
53942+#endif
53943+#endif
53944+
53945+ return;
53946+}
53947diff -urNp linux-2.6.32.43/grsecurity/grsec_link.c linux-2.6.32.43/grsecurity/grsec_link.c
53948--- linux-2.6.32.43/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
53949+++ linux-2.6.32.43/grsecurity/grsec_link.c 2011-04-17 15:56:46.000000000 -0400
53950@@ -0,0 +1,43 @@
53951+#include <linux/kernel.h>
53952+#include <linux/sched.h>
53953+#include <linux/fs.h>
53954+#include <linux/file.h>
53955+#include <linux/grinternal.h>
53956+
53957+int
53958+gr_handle_follow_link(const struct inode *parent,
53959+ const struct inode *inode,
53960+ const struct dentry *dentry, const struct vfsmount *mnt)
53961+{
53962+#ifdef CONFIG_GRKERNSEC_LINK
53963+ const struct cred *cred = current_cred();
53964+
53965+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
53966+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
53967+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
53968+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
53969+ return -EACCES;
53970+ }
53971+#endif
53972+ return 0;
53973+}
53974+
53975+int
53976+gr_handle_hardlink(const struct dentry *dentry,
53977+ const struct vfsmount *mnt,
53978+ struct inode *inode, const int mode, const char *to)
53979+{
53980+#ifdef CONFIG_GRKERNSEC_LINK
53981+ const struct cred *cred = current_cred();
53982+
53983+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
53984+ (!S_ISREG(mode) || (mode & S_ISUID) ||
53985+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
53986+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
53987+ !capable(CAP_FOWNER) && cred->uid) {
53988+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
53989+ return -EPERM;
53990+ }
53991+#endif
53992+ return 0;
53993+}
53994diff -urNp linux-2.6.32.43/grsecurity/grsec_log.c linux-2.6.32.43/grsecurity/grsec_log.c
53995--- linux-2.6.32.43/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
53996+++ linux-2.6.32.43/grsecurity/grsec_log.c 2011-05-10 21:58:49.000000000 -0400
53997@@ -0,0 +1,310 @@
53998+#include <linux/kernel.h>
53999+#include <linux/sched.h>
54000+#include <linux/file.h>
54001+#include <linux/tty.h>
54002+#include <linux/fs.h>
54003+#include <linux/grinternal.h>
54004+
54005+#ifdef CONFIG_TREE_PREEMPT_RCU
54006+#define DISABLE_PREEMPT() preempt_disable()
54007+#define ENABLE_PREEMPT() preempt_enable()
54008+#else
54009+#define DISABLE_PREEMPT()
54010+#define ENABLE_PREEMPT()
54011+#endif
54012+
54013+#define BEGIN_LOCKS(x) \
54014+ DISABLE_PREEMPT(); \
54015+ rcu_read_lock(); \
54016+ read_lock(&tasklist_lock); \
54017+ read_lock(&grsec_exec_file_lock); \
54018+ if (x != GR_DO_AUDIT) \
54019+ spin_lock(&grsec_alert_lock); \
54020+ else \
54021+ spin_lock(&grsec_audit_lock)
54022+
54023+#define END_LOCKS(x) \
54024+ if (x != GR_DO_AUDIT) \
54025+ spin_unlock(&grsec_alert_lock); \
54026+ else \
54027+ spin_unlock(&grsec_audit_lock); \
54028+ read_unlock(&grsec_exec_file_lock); \
54029+ read_unlock(&tasklist_lock); \
54030+ rcu_read_unlock(); \
54031+ ENABLE_PREEMPT(); \
54032+ if (x == GR_DONT_AUDIT) \
54033+ gr_handle_alertkill(current)
54034+
54035+enum {
54036+ FLOODING,
54037+ NO_FLOODING
54038+};
54039+
54040+extern char *gr_alert_log_fmt;
54041+extern char *gr_audit_log_fmt;
54042+extern char *gr_alert_log_buf;
54043+extern char *gr_audit_log_buf;
54044+
54045+static int gr_log_start(int audit)
54046+{
54047+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
54048+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
54049+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54050+
54051+ if (audit == GR_DO_AUDIT)
54052+ goto set_fmt;
54053+
54054+ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
54055+ grsec_alert_wtime = jiffies;
54056+ grsec_alert_fyet = 0;
54057+ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
54058+ grsec_alert_fyet++;
54059+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
54060+ grsec_alert_wtime = jiffies;
54061+ grsec_alert_fyet++;
54062+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
54063+ return FLOODING;
54064+ } else return FLOODING;
54065+
54066+set_fmt:
54067+ memset(buf, 0, PAGE_SIZE);
54068+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
54069+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
54070+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
54071+ } else if (current->signal->curr_ip) {
54072+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
54073+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
54074+ } else if (gr_acl_is_enabled()) {
54075+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
54076+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
54077+ } else {
54078+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
54079+ strcpy(buf, fmt);
54080+ }
54081+
54082+ return NO_FLOODING;
54083+}
54084+
54085+static void gr_log_middle(int audit, const char *msg, va_list ap)
54086+ __attribute__ ((format (printf, 2, 0)));
54087+
54088+static void gr_log_middle(int audit, const char *msg, va_list ap)
54089+{
54090+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54091+ unsigned int len = strlen(buf);
54092+
54093+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
54094+
54095+ return;
54096+}
54097+
54098+static void gr_log_middle_varargs(int audit, const char *msg, ...)
54099+ __attribute__ ((format (printf, 2, 3)));
54100+
54101+static void gr_log_middle_varargs(int audit, const char *msg, ...)
54102+{
54103+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54104+ unsigned int len = strlen(buf);
54105+ va_list ap;
54106+
54107+ va_start(ap, msg);
54108+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
54109+ va_end(ap);
54110+
54111+ return;
54112+}
54113+
54114+static void gr_log_end(int audit)
54115+{
54116+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
54117+ unsigned int len = strlen(buf);
54118+
54119+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
54120+ printk("%s\n", buf);
54121+
54122+ return;
54123+}
54124+
54125+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
54126+{
54127+ int logtype;
54128+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
54129+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
54130+ void *voidptr = NULL;
54131+ int num1 = 0, num2 = 0;
54132+ unsigned long ulong1 = 0, ulong2 = 0;
54133+ struct dentry *dentry = NULL;
54134+ struct vfsmount *mnt = NULL;
54135+ struct file *file = NULL;
54136+ struct task_struct *task = NULL;
54137+ const struct cred *cred, *pcred;
54138+ va_list ap;
54139+
54140+ BEGIN_LOCKS(audit);
54141+ logtype = gr_log_start(audit);
54142+ if (logtype == FLOODING) {
54143+ END_LOCKS(audit);
54144+ return;
54145+ }
54146+ va_start(ap, argtypes);
54147+ switch (argtypes) {
54148+ case GR_TTYSNIFF:
54149+ task = va_arg(ap, struct task_struct *);
54150+ 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);
54151+ break;
54152+ case GR_SYSCTL_HIDDEN:
54153+ str1 = va_arg(ap, char *);
54154+ gr_log_middle_varargs(audit, msg, result, str1);
54155+ break;
54156+ case GR_RBAC:
54157+ dentry = va_arg(ap, struct dentry *);
54158+ mnt = va_arg(ap, struct vfsmount *);
54159+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
54160+ break;
54161+ case GR_RBAC_STR:
54162+ dentry = va_arg(ap, struct dentry *);
54163+ mnt = va_arg(ap, struct vfsmount *);
54164+ str1 = va_arg(ap, char *);
54165+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
54166+ break;
54167+ case GR_STR_RBAC:
54168+ str1 = va_arg(ap, char *);
54169+ dentry = va_arg(ap, struct dentry *);
54170+ mnt = va_arg(ap, struct vfsmount *);
54171+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
54172+ break;
54173+ case GR_RBAC_MODE2:
54174+ dentry = va_arg(ap, struct dentry *);
54175+ mnt = va_arg(ap, struct vfsmount *);
54176+ str1 = va_arg(ap, char *);
54177+ str2 = va_arg(ap, char *);
54178+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
54179+ break;
54180+ case GR_RBAC_MODE3:
54181+ dentry = va_arg(ap, struct dentry *);
54182+ mnt = va_arg(ap, struct vfsmount *);
54183+ str1 = va_arg(ap, char *);
54184+ str2 = va_arg(ap, char *);
54185+ str3 = va_arg(ap, char *);
54186+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
54187+ break;
54188+ case GR_FILENAME:
54189+ dentry = va_arg(ap, struct dentry *);
54190+ mnt = va_arg(ap, struct vfsmount *);
54191+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
54192+ break;
54193+ case GR_STR_FILENAME:
54194+ str1 = va_arg(ap, char *);
54195+ dentry = va_arg(ap, struct dentry *);
54196+ mnt = va_arg(ap, struct vfsmount *);
54197+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
54198+ break;
54199+ case GR_FILENAME_STR:
54200+ dentry = va_arg(ap, struct dentry *);
54201+ mnt = va_arg(ap, struct vfsmount *);
54202+ str1 = va_arg(ap, char *);
54203+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
54204+ break;
54205+ case GR_FILENAME_TWO_INT:
54206+ dentry = va_arg(ap, struct dentry *);
54207+ mnt = va_arg(ap, struct vfsmount *);
54208+ num1 = va_arg(ap, int);
54209+ num2 = va_arg(ap, int);
54210+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
54211+ break;
54212+ case GR_FILENAME_TWO_INT_STR:
54213+ dentry = va_arg(ap, struct dentry *);
54214+ mnt = va_arg(ap, struct vfsmount *);
54215+ num1 = va_arg(ap, int);
54216+ num2 = va_arg(ap, int);
54217+ str1 = va_arg(ap, char *);
54218+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
54219+ break;
54220+ case GR_TEXTREL:
54221+ file = va_arg(ap, struct file *);
54222+ ulong1 = va_arg(ap, unsigned long);
54223+ ulong2 = va_arg(ap, unsigned long);
54224+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
54225+ break;
54226+ case GR_PTRACE:
54227+ task = va_arg(ap, struct task_struct *);
54228+ 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);
54229+ break;
54230+ case GR_RESOURCE:
54231+ task = va_arg(ap, struct task_struct *);
54232+ cred = __task_cred(task);
54233+ pcred = __task_cred(task->real_parent);
54234+ ulong1 = va_arg(ap, unsigned long);
54235+ str1 = va_arg(ap, char *);
54236+ ulong2 = va_arg(ap, unsigned long);
54237+ 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);
54238+ break;
54239+ case GR_CAP:
54240+ task = va_arg(ap, struct task_struct *);
54241+ cred = __task_cred(task);
54242+ pcred = __task_cred(task->real_parent);
54243+ str1 = va_arg(ap, char *);
54244+ 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);
54245+ break;
54246+ case GR_SIG:
54247+ str1 = va_arg(ap, char *);
54248+ voidptr = va_arg(ap, void *);
54249+ gr_log_middle_varargs(audit, msg, str1, voidptr);
54250+ break;
54251+ case GR_SIG2:
54252+ task = va_arg(ap, struct task_struct *);
54253+ cred = __task_cred(task);
54254+ pcred = __task_cred(task->real_parent);
54255+ num1 = va_arg(ap, int);
54256+ 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);
54257+ break;
54258+ case GR_CRASH1:
54259+ task = va_arg(ap, struct task_struct *);
54260+ cred = __task_cred(task);
54261+ pcred = __task_cred(task->real_parent);
54262+ ulong1 = va_arg(ap, unsigned long);
54263+ 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);
54264+ break;
54265+ case GR_CRASH2:
54266+ task = va_arg(ap, struct task_struct *);
54267+ cred = __task_cred(task);
54268+ pcred = __task_cred(task->real_parent);
54269+ ulong1 = va_arg(ap, unsigned long);
54270+ 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);
54271+ break;
54272+ case GR_RWXMAP:
54273+ file = va_arg(ap, struct file *);
54274+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
54275+ break;
54276+ case GR_PSACCT:
54277+ {
54278+ unsigned int wday, cday;
54279+ __u8 whr, chr;
54280+ __u8 wmin, cmin;
54281+ __u8 wsec, csec;
54282+ char cur_tty[64] = { 0 };
54283+ char parent_tty[64] = { 0 };
54284+
54285+ task = va_arg(ap, struct task_struct *);
54286+ wday = va_arg(ap, unsigned int);
54287+ cday = va_arg(ap, unsigned int);
54288+ whr = va_arg(ap, int);
54289+ chr = va_arg(ap, int);
54290+ wmin = va_arg(ap, int);
54291+ cmin = va_arg(ap, int);
54292+ wsec = va_arg(ap, int);
54293+ csec = va_arg(ap, int);
54294+ ulong1 = va_arg(ap, unsigned long);
54295+ cred = __task_cred(task);
54296+ pcred = __task_cred(task->real_parent);
54297+
54298+ 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);
54299+ }
54300+ break;
54301+ default:
54302+ gr_log_middle(audit, msg, ap);
54303+ }
54304+ va_end(ap);
54305+ gr_log_end(audit);
54306+ END_LOCKS(audit);
54307+}
54308diff -urNp linux-2.6.32.43/grsecurity/grsec_mem.c linux-2.6.32.43/grsecurity/grsec_mem.c
54309--- linux-2.6.32.43/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
54310+++ linux-2.6.32.43/grsecurity/grsec_mem.c 2011-04-17 15:56:46.000000000 -0400
54311@@ -0,0 +1,33 @@
54312+#include <linux/kernel.h>
54313+#include <linux/sched.h>
54314+#include <linux/mm.h>
54315+#include <linux/mman.h>
54316+#include <linux/grinternal.h>
54317+
54318+void
54319+gr_handle_ioperm(void)
54320+{
54321+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
54322+ return;
54323+}
54324+
54325+void
54326+gr_handle_iopl(void)
54327+{
54328+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
54329+ return;
54330+}
54331+
54332+void
54333+gr_handle_mem_readwrite(u64 from, u64 to)
54334+{
54335+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
54336+ return;
54337+}
54338+
54339+void
54340+gr_handle_vm86(void)
54341+{
54342+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
54343+ return;
54344+}
54345diff -urNp linux-2.6.32.43/grsecurity/grsec_mount.c linux-2.6.32.43/grsecurity/grsec_mount.c
54346--- linux-2.6.32.43/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
54347+++ linux-2.6.32.43/grsecurity/grsec_mount.c 2011-06-20 19:47:03.000000000 -0400
54348@@ -0,0 +1,62 @@
54349+#include <linux/kernel.h>
54350+#include <linux/sched.h>
54351+#include <linux/mount.h>
54352+#include <linux/grsecurity.h>
54353+#include <linux/grinternal.h>
54354+
54355+void
54356+gr_log_remount(const char *devname, const int retval)
54357+{
54358+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54359+ if (grsec_enable_mount && (retval >= 0))
54360+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
54361+#endif
54362+ return;
54363+}
54364+
54365+void
54366+gr_log_unmount(const char *devname, const int retval)
54367+{
54368+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54369+ if (grsec_enable_mount && (retval >= 0))
54370+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
54371+#endif
54372+ return;
54373+}
54374+
54375+void
54376+gr_log_mount(const char *from, const char *to, const int retval)
54377+{
54378+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
54379+ if (grsec_enable_mount && (retval >= 0))
54380+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
54381+#endif
54382+ return;
54383+}
54384+
54385+int
54386+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
54387+{
54388+#ifdef CONFIG_GRKERNSEC_ROFS
54389+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
54390+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
54391+ return -EPERM;
54392+ } else
54393+ return 0;
54394+#endif
54395+ return 0;
54396+}
54397+
54398+int
54399+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
54400+{
54401+#ifdef CONFIG_GRKERNSEC_ROFS
54402+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
54403+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
54404+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
54405+ return -EPERM;
54406+ } else
54407+ return 0;
54408+#endif
54409+ return 0;
54410+}
54411diff -urNp linux-2.6.32.43/grsecurity/grsec_pax.c linux-2.6.32.43/grsecurity/grsec_pax.c
54412--- linux-2.6.32.43/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
54413+++ linux-2.6.32.43/grsecurity/grsec_pax.c 2011-04-17 15:56:46.000000000 -0400
54414@@ -0,0 +1,36 @@
54415+#include <linux/kernel.h>
54416+#include <linux/sched.h>
54417+#include <linux/mm.h>
54418+#include <linux/file.h>
54419+#include <linux/grinternal.h>
54420+#include <linux/grsecurity.h>
54421+
54422+void
54423+gr_log_textrel(struct vm_area_struct * vma)
54424+{
54425+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
54426+ if (grsec_enable_audit_textrel)
54427+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
54428+#endif
54429+ return;
54430+}
54431+
54432+void
54433+gr_log_rwxmmap(struct file *file)
54434+{
54435+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54436+ if (grsec_enable_log_rwxmaps)
54437+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
54438+#endif
54439+ return;
54440+}
54441+
54442+void
54443+gr_log_rwxmprotect(struct file *file)
54444+{
54445+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54446+ if (grsec_enable_log_rwxmaps)
54447+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
54448+#endif
54449+ return;
54450+}
54451diff -urNp linux-2.6.32.43/grsecurity/grsec_ptrace.c linux-2.6.32.43/grsecurity/grsec_ptrace.c
54452--- linux-2.6.32.43/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
54453+++ linux-2.6.32.43/grsecurity/grsec_ptrace.c 2011-04-17 15:56:46.000000000 -0400
54454@@ -0,0 +1,14 @@
54455+#include <linux/kernel.h>
54456+#include <linux/sched.h>
54457+#include <linux/grinternal.h>
54458+#include <linux/grsecurity.h>
54459+
54460+void
54461+gr_audit_ptrace(struct task_struct *task)
54462+{
54463+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
54464+ if (grsec_enable_audit_ptrace)
54465+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
54466+#endif
54467+ return;
54468+}
54469diff -urNp linux-2.6.32.43/grsecurity/grsec_sig.c linux-2.6.32.43/grsecurity/grsec_sig.c
54470--- linux-2.6.32.43/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
54471+++ linux-2.6.32.43/grsecurity/grsec_sig.c 2011-06-29 19:40:31.000000000 -0400
54472@@ -0,0 +1,205 @@
54473+#include <linux/kernel.h>
54474+#include <linux/sched.h>
54475+#include <linux/delay.h>
54476+#include <linux/grsecurity.h>
54477+#include <linux/grinternal.h>
54478+#include <linux/hardirq.h>
54479+
54480+char *signames[] = {
54481+ [SIGSEGV] = "Segmentation fault",
54482+ [SIGILL] = "Illegal instruction",
54483+ [SIGABRT] = "Abort",
54484+ [SIGBUS] = "Invalid alignment/Bus error"
54485+};
54486+
54487+void
54488+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
54489+{
54490+#ifdef CONFIG_GRKERNSEC_SIGNAL
54491+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
54492+ (sig == SIGABRT) || (sig == SIGBUS))) {
54493+ if (t->pid == current->pid) {
54494+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
54495+ } else {
54496+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
54497+ }
54498+ }
54499+#endif
54500+ return;
54501+}
54502+
54503+int
54504+gr_handle_signal(const struct task_struct *p, const int sig)
54505+{
54506+#ifdef CONFIG_GRKERNSEC
54507+ if (current->pid > 1 && gr_check_protected_task(p)) {
54508+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
54509+ return -EPERM;
54510+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
54511+ return -EPERM;
54512+ }
54513+#endif
54514+ return 0;
54515+}
54516+
54517+#ifdef CONFIG_GRKERNSEC
54518+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
54519+
54520+int gr_fake_force_sig(int sig, struct task_struct *t)
54521+{
54522+ unsigned long int flags;
54523+ int ret, blocked, ignored;
54524+ struct k_sigaction *action;
54525+
54526+ spin_lock_irqsave(&t->sighand->siglock, flags);
54527+ action = &t->sighand->action[sig-1];
54528+ ignored = action->sa.sa_handler == SIG_IGN;
54529+ blocked = sigismember(&t->blocked, sig);
54530+ if (blocked || ignored) {
54531+ action->sa.sa_handler = SIG_DFL;
54532+ if (blocked) {
54533+ sigdelset(&t->blocked, sig);
54534+ recalc_sigpending_and_wake(t);
54535+ }
54536+ }
54537+ if (action->sa.sa_handler == SIG_DFL)
54538+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
54539+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
54540+
54541+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
54542+
54543+ return ret;
54544+}
54545+#endif
54546+
54547+#ifdef CONFIG_GRKERNSEC_BRUTE
54548+#define GR_USER_BAN_TIME (15 * 60)
54549+
54550+static int __get_dumpable(unsigned long mm_flags)
54551+{
54552+ int ret;
54553+
54554+ ret = mm_flags & MMF_DUMPABLE_MASK;
54555+ return (ret >= 2) ? 2 : ret;
54556+}
54557+#endif
54558+
54559+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
54560+{
54561+#ifdef CONFIG_GRKERNSEC_BRUTE
54562+ uid_t uid = 0;
54563+
54564+ if (!grsec_enable_brute)
54565+ return;
54566+
54567+ rcu_read_lock();
54568+ read_lock(&tasklist_lock);
54569+ read_lock(&grsec_exec_file_lock);
54570+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
54571+ p->real_parent->brute = 1;
54572+ else {
54573+ const struct cred *cred = __task_cred(p), *cred2;
54574+ struct task_struct *tsk, *tsk2;
54575+
54576+ if (!__get_dumpable(mm_flags) && cred->uid) {
54577+ struct user_struct *user;
54578+
54579+ uid = cred->uid;
54580+
54581+ /* this is put upon execution past expiration */
54582+ user = find_user(uid);
54583+ if (user == NULL)
54584+ goto unlock;
54585+ user->banned = 1;
54586+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
54587+ if (user->ban_expires == ~0UL)
54588+ user->ban_expires--;
54589+
54590+ do_each_thread(tsk2, tsk) {
54591+ cred2 = __task_cred(tsk);
54592+ if (tsk != p && cred2->uid == uid)
54593+ gr_fake_force_sig(SIGKILL, tsk);
54594+ } while_each_thread(tsk2, tsk);
54595+ }
54596+ }
54597+unlock:
54598+ read_unlock(&grsec_exec_file_lock);
54599+ read_unlock(&tasklist_lock);
54600+ rcu_read_unlock();
54601+
54602+ if (uid)
54603+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
54604+#endif
54605+ return;
54606+}
54607+
54608+void gr_handle_brute_check(void)
54609+{
54610+#ifdef CONFIG_GRKERNSEC_BRUTE
54611+ if (current->brute)
54612+ msleep(30 * 1000);
54613+#endif
54614+ return;
54615+}
54616+
54617+void gr_handle_kernel_exploit(void)
54618+{
54619+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
54620+ const struct cred *cred;
54621+ struct task_struct *tsk, *tsk2;
54622+ struct user_struct *user;
54623+ uid_t uid;
54624+
54625+ if (in_irq() || in_serving_softirq() || in_nmi())
54626+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
54627+
54628+ uid = current_uid();
54629+
54630+ if (uid == 0)
54631+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
54632+ else {
54633+ /* kill all the processes of this user, hold a reference
54634+ to their creds struct, and prevent them from creating
54635+ another process until system reset
54636+ */
54637+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
54638+ /* we intentionally leak this ref */
54639+ user = get_uid(current->cred->user);
54640+ if (user) {
54641+ user->banned = 1;
54642+ user->ban_expires = ~0UL;
54643+ }
54644+
54645+ read_lock(&tasklist_lock);
54646+ do_each_thread(tsk2, tsk) {
54647+ cred = __task_cred(tsk);
54648+ if (cred->uid == uid)
54649+ gr_fake_force_sig(SIGKILL, tsk);
54650+ } while_each_thread(tsk2, tsk);
54651+ read_unlock(&tasklist_lock);
54652+ }
54653+#endif
54654+}
54655+
54656+int __gr_process_user_ban(struct user_struct *user)
54657+{
54658+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54659+ if (unlikely(user->banned)) {
54660+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
54661+ user->banned = 0;
54662+ user->ban_expires = 0;
54663+ free_uid(user);
54664+ } else
54665+ return -EPERM;
54666+ }
54667+#endif
54668+ return 0;
54669+}
54670+
54671+int gr_process_user_ban(void)
54672+{
54673+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54674+ return __gr_process_user_ban(current->cred->user);
54675+#endif
54676+ return 0;
54677+}
54678diff -urNp linux-2.6.32.43/grsecurity/grsec_sock.c linux-2.6.32.43/grsecurity/grsec_sock.c
54679--- linux-2.6.32.43/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
54680+++ linux-2.6.32.43/grsecurity/grsec_sock.c 2011-04-17 15:56:46.000000000 -0400
54681@@ -0,0 +1,275 @@
54682+#include <linux/kernel.h>
54683+#include <linux/module.h>
54684+#include <linux/sched.h>
54685+#include <linux/file.h>
54686+#include <linux/net.h>
54687+#include <linux/in.h>
54688+#include <linux/ip.h>
54689+#include <net/sock.h>
54690+#include <net/inet_sock.h>
54691+#include <linux/grsecurity.h>
54692+#include <linux/grinternal.h>
54693+#include <linux/gracl.h>
54694+
54695+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
54696+EXPORT_SYMBOL(gr_cap_rtnetlink);
54697+
54698+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
54699+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
54700+
54701+EXPORT_SYMBOL(gr_search_udp_recvmsg);
54702+EXPORT_SYMBOL(gr_search_udp_sendmsg);
54703+
54704+#ifdef CONFIG_UNIX_MODULE
54705+EXPORT_SYMBOL(gr_acl_handle_unix);
54706+EXPORT_SYMBOL(gr_acl_handle_mknod);
54707+EXPORT_SYMBOL(gr_handle_chroot_unix);
54708+EXPORT_SYMBOL(gr_handle_create);
54709+#endif
54710+
54711+#ifdef CONFIG_GRKERNSEC
54712+#define gr_conn_table_size 32749
54713+struct conn_table_entry {
54714+ struct conn_table_entry *next;
54715+ struct signal_struct *sig;
54716+};
54717+
54718+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
54719+DEFINE_SPINLOCK(gr_conn_table_lock);
54720+
54721+extern const char * gr_socktype_to_name(unsigned char type);
54722+extern const char * gr_proto_to_name(unsigned char proto);
54723+extern const char * gr_sockfamily_to_name(unsigned char family);
54724+
54725+static __inline__ int
54726+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
54727+{
54728+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
54729+}
54730+
54731+static __inline__ int
54732+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
54733+ __u16 sport, __u16 dport)
54734+{
54735+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
54736+ sig->gr_sport == sport && sig->gr_dport == dport))
54737+ return 1;
54738+ else
54739+ return 0;
54740+}
54741+
54742+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
54743+{
54744+ struct conn_table_entry **match;
54745+ unsigned int index;
54746+
54747+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
54748+ sig->gr_sport, sig->gr_dport,
54749+ gr_conn_table_size);
54750+
54751+ newent->sig = sig;
54752+
54753+ match = &gr_conn_table[index];
54754+ newent->next = *match;
54755+ *match = newent;
54756+
54757+ return;
54758+}
54759+
54760+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
54761+{
54762+ struct conn_table_entry *match, *last = NULL;
54763+ unsigned int index;
54764+
54765+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
54766+ sig->gr_sport, sig->gr_dport,
54767+ gr_conn_table_size);
54768+
54769+ match = gr_conn_table[index];
54770+ while (match && !conn_match(match->sig,
54771+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
54772+ sig->gr_dport)) {
54773+ last = match;
54774+ match = match->next;
54775+ }
54776+
54777+ if (match) {
54778+ if (last)
54779+ last->next = match->next;
54780+ else
54781+ gr_conn_table[index] = NULL;
54782+ kfree(match);
54783+ }
54784+
54785+ return;
54786+}
54787+
54788+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
54789+ __u16 sport, __u16 dport)
54790+{
54791+ struct conn_table_entry *match;
54792+ unsigned int index;
54793+
54794+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
54795+
54796+ match = gr_conn_table[index];
54797+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
54798+ match = match->next;
54799+
54800+ if (match)
54801+ return match->sig;
54802+ else
54803+ return NULL;
54804+}
54805+
54806+#endif
54807+
54808+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
54809+{
54810+#ifdef CONFIG_GRKERNSEC
54811+ struct signal_struct *sig = task->signal;
54812+ struct conn_table_entry *newent;
54813+
54814+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
54815+ if (newent == NULL)
54816+ return;
54817+ /* no bh lock needed since we are called with bh disabled */
54818+ spin_lock(&gr_conn_table_lock);
54819+ gr_del_task_from_ip_table_nolock(sig);
54820+ sig->gr_saddr = inet->rcv_saddr;
54821+ sig->gr_daddr = inet->daddr;
54822+ sig->gr_sport = inet->sport;
54823+ sig->gr_dport = inet->dport;
54824+ gr_add_to_task_ip_table_nolock(sig, newent);
54825+ spin_unlock(&gr_conn_table_lock);
54826+#endif
54827+ return;
54828+}
54829+
54830+void gr_del_task_from_ip_table(struct task_struct *task)
54831+{
54832+#ifdef CONFIG_GRKERNSEC
54833+ spin_lock_bh(&gr_conn_table_lock);
54834+ gr_del_task_from_ip_table_nolock(task->signal);
54835+ spin_unlock_bh(&gr_conn_table_lock);
54836+#endif
54837+ return;
54838+}
54839+
54840+void
54841+gr_attach_curr_ip(const struct sock *sk)
54842+{
54843+#ifdef CONFIG_GRKERNSEC
54844+ struct signal_struct *p, *set;
54845+ const struct inet_sock *inet = inet_sk(sk);
54846+
54847+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
54848+ return;
54849+
54850+ set = current->signal;
54851+
54852+ spin_lock_bh(&gr_conn_table_lock);
54853+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
54854+ inet->dport, inet->sport);
54855+ if (unlikely(p != NULL)) {
54856+ set->curr_ip = p->curr_ip;
54857+ set->used_accept = 1;
54858+ gr_del_task_from_ip_table_nolock(p);
54859+ spin_unlock_bh(&gr_conn_table_lock);
54860+ return;
54861+ }
54862+ spin_unlock_bh(&gr_conn_table_lock);
54863+
54864+ set->curr_ip = inet->daddr;
54865+ set->used_accept = 1;
54866+#endif
54867+ return;
54868+}
54869+
54870+int
54871+gr_handle_sock_all(const int family, const int type, const int protocol)
54872+{
54873+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
54874+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
54875+ (family != AF_UNIX)) {
54876+ if (family == AF_INET)
54877+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
54878+ else
54879+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
54880+ return -EACCES;
54881+ }
54882+#endif
54883+ return 0;
54884+}
54885+
54886+int
54887+gr_handle_sock_server(const struct sockaddr *sck)
54888+{
54889+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
54890+ if (grsec_enable_socket_server &&
54891+ in_group_p(grsec_socket_server_gid) &&
54892+ sck && (sck->sa_family != AF_UNIX) &&
54893+ (sck->sa_family != AF_LOCAL)) {
54894+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
54895+ return -EACCES;
54896+ }
54897+#endif
54898+ return 0;
54899+}
54900+
54901+int
54902+gr_handle_sock_server_other(const struct sock *sck)
54903+{
54904+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
54905+ if (grsec_enable_socket_server &&
54906+ in_group_p(grsec_socket_server_gid) &&
54907+ sck && (sck->sk_family != AF_UNIX) &&
54908+ (sck->sk_family != AF_LOCAL)) {
54909+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
54910+ return -EACCES;
54911+ }
54912+#endif
54913+ return 0;
54914+}
54915+
54916+int
54917+gr_handle_sock_client(const struct sockaddr *sck)
54918+{
54919+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
54920+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
54921+ sck && (sck->sa_family != AF_UNIX) &&
54922+ (sck->sa_family != AF_LOCAL)) {
54923+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
54924+ return -EACCES;
54925+ }
54926+#endif
54927+ return 0;
54928+}
54929+
54930+kernel_cap_t
54931+gr_cap_rtnetlink(struct sock *sock)
54932+{
54933+#ifdef CONFIG_GRKERNSEC
54934+ if (!gr_acl_is_enabled())
54935+ return current_cap();
54936+ else if (sock->sk_protocol == NETLINK_ISCSI &&
54937+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
54938+ gr_is_capable(CAP_SYS_ADMIN))
54939+ return current_cap();
54940+ else if (sock->sk_protocol == NETLINK_AUDIT &&
54941+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
54942+ gr_is_capable(CAP_AUDIT_WRITE) &&
54943+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
54944+ gr_is_capable(CAP_AUDIT_CONTROL))
54945+ return current_cap();
54946+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
54947+ ((sock->sk_protocol == NETLINK_ROUTE) ?
54948+ gr_is_capable_nolog(CAP_NET_ADMIN) :
54949+ gr_is_capable(CAP_NET_ADMIN)))
54950+ return current_cap();
54951+ else
54952+ return __cap_empty_set;
54953+#else
54954+ return current_cap();
54955+#endif
54956+}
54957diff -urNp linux-2.6.32.43/grsecurity/grsec_sysctl.c linux-2.6.32.43/grsecurity/grsec_sysctl.c
54958--- linux-2.6.32.43/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
54959+++ linux-2.6.32.43/grsecurity/grsec_sysctl.c 2011-06-29 19:37:19.000000000 -0400
54960@@ -0,0 +1,489 @@
54961+#include <linux/kernel.h>
54962+#include <linux/sched.h>
54963+#include <linux/sysctl.h>
54964+#include <linux/grsecurity.h>
54965+#include <linux/grinternal.h>
54966+
54967+int
54968+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
54969+{
54970+#ifdef CONFIG_GRKERNSEC_SYSCTL
54971+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
54972+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
54973+ return -EACCES;
54974+ }
54975+#endif
54976+ return 0;
54977+}
54978+
54979+#ifdef CONFIG_GRKERNSEC_ROFS
54980+static int __maybe_unused one = 1;
54981+#endif
54982+
54983+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
54984+ctl_table grsecurity_table[] = {
54985+#ifdef CONFIG_GRKERNSEC_SYSCTL
54986+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
54987+#ifdef CONFIG_GRKERNSEC_IO
54988+ {
54989+ .ctl_name = CTL_UNNUMBERED,
54990+ .procname = "disable_priv_io",
54991+ .data = &grsec_disable_privio,
54992+ .maxlen = sizeof(int),
54993+ .mode = 0600,
54994+ .proc_handler = &proc_dointvec,
54995+ },
54996+#endif
54997+#endif
54998+#ifdef CONFIG_GRKERNSEC_LINK
54999+ {
55000+ .ctl_name = CTL_UNNUMBERED,
55001+ .procname = "linking_restrictions",
55002+ .data = &grsec_enable_link,
55003+ .maxlen = sizeof(int),
55004+ .mode = 0600,
55005+ .proc_handler = &proc_dointvec,
55006+ },
55007+#endif
55008+#ifdef CONFIG_GRKERNSEC_BRUTE
55009+ {
55010+ .ctl_name = CTL_UNNUMBERED,
55011+ .procname = "deter_bruteforce",
55012+ .data = &grsec_enable_brute,
55013+ .maxlen = sizeof(int),
55014+ .mode = 0600,
55015+ .proc_handler = &proc_dointvec,
55016+ },
55017+#endif
55018+#ifdef CONFIG_GRKERNSEC_FIFO
55019+ {
55020+ .ctl_name = CTL_UNNUMBERED,
55021+ .procname = "fifo_restrictions",
55022+ .data = &grsec_enable_fifo,
55023+ .maxlen = sizeof(int),
55024+ .mode = 0600,
55025+ .proc_handler = &proc_dointvec,
55026+ },
55027+#endif
55028+#ifdef CONFIG_GRKERNSEC_EXECVE
55029+ {
55030+ .ctl_name = CTL_UNNUMBERED,
55031+ .procname = "execve_limiting",
55032+ .data = &grsec_enable_execve,
55033+ .maxlen = sizeof(int),
55034+ .mode = 0600,
55035+ .proc_handler = &proc_dointvec,
55036+ },
55037+#endif
55038+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55039+ {
55040+ .ctl_name = CTL_UNNUMBERED,
55041+ .procname = "ip_blackhole",
55042+ .data = &grsec_enable_blackhole,
55043+ .maxlen = sizeof(int),
55044+ .mode = 0600,
55045+ .proc_handler = &proc_dointvec,
55046+ },
55047+ {
55048+ .ctl_name = CTL_UNNUMBERED,
55049+ .procname = "lastack_retries",
55050+ .data = &grsec_lastack_retries,
55051+ .maxlen = sizeof(int),
55052+ .mode = 0600,
55053+ .proc_handler = &proc_dointvec,
55054+ },
55055+#endif
55056+#ifdef CONFIG_GRKERNSEC_EXECLOG
55057+ {
55058+ .ctl_name = CTL_UNNUMBERED,
55059+ .procname = "exec_logging",
55060+ .data = &grsec_enable_execlog,
55061+ .maxlen = sizeof(int),
55062+ .mode = 0600,
55063+ .proc_handler = &proc_dointvec,
55064+ },
55065+#endif
55066+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55067+ {
55068+ .ctl_name = CTL_UNNUMBERED,
55069+ .procname = "rwxmap_logging",
55070+ .data = &grsec_enable_log_rwxmaps,
55071+ .maxlen = sizeof(int),
55072+ .mode = 0600,
55073+ .proc_handler = &proc_dointvec,
55074+ },
55075+#endif
55076+#ifdef CONFIG_GRKERNSEC_SIGNAL
55077+ {
55078+ .ctl_name = CTL_UNNUMBERED,
55079+ .procname = "signal_logging",
55080+ .data = &grsec_enable_signal,
55081+ .maxlen = sizeof(int),
55082+ .mode = 0600,
55083+ .proc_handler = &proc_dointvec,
55084+ },
55085+#endif
55086+#ifdef CONFIG_GRKERNSEC_FORKFAIL
55087+ {
55088+ .ctl_name = CTL_UNNUMBERED,
55089+ .procname = "forkfail_logging",
55090+ .data = &grsec_enable_forkfail,
55091+ .maxlen = sizeof(int),
55092+ .mode = 0600,
55093+ .proc_handler = &proc_dointvec,
55094+ },
55095+#endif
55096+#ifdef CONFIG_GRKERNSEC_TIME
55097+ {
55098+ .ctl_name = CTL_UNNUMBERED,
55099+ .procname = "timechange_logging",
55100+ .data = &grsec_enable_time,
55101+ .maxlen = sizeof(int),
55102+ .mode = 0600,
55103+ .proc_handler = &proc_dointvec,
55104+ },
55105+#endif
55106+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55107+ {
55108+ .ctl_name = CTL_UNNUMBERED,
55109+ .procname = "chroot_deny_shmat",
55110+ .data = &grsec_enable_chroot_shmat,
55111+ .maxlen = sizeof(int),
55112+ .mode = 0600,
55113+ .proc_handler = &proc_dointvec,
55114+ },
55115+#endif
55116+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55117+ {
55118+ .ctl_name = CTL_UNNUMBERED,
55119+ .procname = "chroot_deny_unix",
55120+ .data = &grsec_enable_chroot_unix,
55121+ .maxlen = sizeof(int),
55122+ .mode = 0600,
55123+ .proc_handler = &proc_dointvec,
55124+ },
55125+#endif
55126+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55127+ {
55128+ .ctl_name = CTL_UNNUMBERED,
55129+ .procname = "chroot_deny_mount",
55130+ .data = &grsec_enable_chroot_mount,
55131+ .maxlen = sizeof(int),
55132+ .mode = 0600,
55133+ .proc_handler = &proc_dointvec,
55134+ },
55135+#endif
55136+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55137+ {
55138+ .ctl_name = CTL_UNNUMBERED,
55139+ .procname = "chroot_deny_fchdir",
55140+ .data = &grsec_enable_chroot_fchdir,
55141+ .maxlen = sizeof(int),
55142+ .mode = 0600,
55143+ .proc_handler = &proc_dointvec,
55144+ },
55145+#endif
55146+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55147+ {
55148+ .ctl_name = CTL_UNNUMBERED,
55149+ .procname = "chroot_deny_chroot",
55150+ .data = &grsec_enable_chroot_double,
55151+ .maxlen = sizeof(int),
55152+ .mode = 0600,
55153+ .proc_handler = &proc_dointvec,
55154+ },
55155+#endif
55156+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55157+ {
55158+ .ctl_name = CTL_UNNUMBERED,
55159+ .procname = "chroot_deny_pivot",
55160+ .data = &grsec_enable_chroot_pivot,
55161+ .maxlen = sizeof(int),
55162+ .mode = 0600,
55163+ .proc_handler = &proc_dointvec,
55164+ },
55165+#endif
55166+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55167+ {
55168+ .ctl_name = CTL_UNNUMBERED,
55169+ .procname = "chroot_enforce_chdir",
55170+ .data = &grsec_enable_chroot_chdir,
55171+ .maxlen = sizeof(int),
55172+ .mode = 0600,
55173+ .proc_handler = &proc_dointvec,
55174+ },
55175+#endif
55176+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55177+ {
55178+ .ctl_name = CTL_UNNUMBERED,
55179+ .procname = "chroot_deny_chmod",
55180+ .data = &grsec_enable_chroot_chmod,
55181+ .maxlen = sizeof(int),
55182+ .mode = 0600,
55183+ .proc_handler = &proc_dointvec,
55184+ },
55185+#endif
55186+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55187+ {
55188+ .ctl_name = CTL_UNNUMBERED,
55189+ .procname = "chroot_deny_mknod",
55190+ .data = &grsec_enable_chroot_mknod,
55191+ .maxlen = sizeof(int),
55192+ .mode = 0600,
55193+ .proc_handler = &proc_dointvec,
55194+ },
55195+#endif
55196+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55197+ {
55198+ .ctl_name = CTL_UNNUMBERED,
55199+ .procname = "chroot_restrict_nice",
55200+ .data = &grsec_enable_chroot_nice,
55201+ .maxlen = sizeof(int),
55202+ .mode = 0600,
55203+ .proc_handler = &proc_dointvec,
55204+ },
55205+#endif
55206+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55207+ {
55208+ .ctl_name = CTL_UNNUMBERED,
55209+ .procname = "chroot_execlog",
55210+ .data = &grsec_enable_chroot_execlog,
55211+ .maxlen = sizeof(int),
55212+ .mode = 0600,
55213+ .proc_handler = &proc_dointvec,
55214+ },
55215+#endif
55216+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55217+ {
55218+ .ctl_name = CTL_UNNUMBERED,
55219+ .procname = "chroot_caps",
55220+ .data = &grsec_enable_chroot_caps,
55221+ .maxlen = sizeof(int),
55222+ .mode = 0600,
55223+ .proc_handler = &proc_dointvec,
55224+ },
55225+#endif
55226+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55227+ {
55228+ .ctl_name = CTL_UNNUMBERED,
55229+ .procname = "chroot_deny_sysctl",
55230+ .data = &grsec_enable_chroot_sysctl,
55231+ .maxlen = sizeof(int),
55232+ .mode = 0600,
55233+ .proc_handler = &proc_dointvec,
55234+ },
55235+#endif
55236+#ifdef CONFIG_GRKERNSEC_TPE
55237+ {
55238+ .ctl_name = CTL_UNNUMBERED,
55239+ .procname = "tpe",
55240+ .data = &grsec_enable_tpe,
55241+ .maxlen = sizeof(int),
55242+ .mode = 0600,
55243+ .proc_handler = &proc_dointvec,
55244+ },
55245+ {
55246+ .ctl_name = CTL_UNNUMBERED,
55247+ .procname = "tpe_gid",
55248+ .data = &grsec_tpe_gid,
55249+ .maxlen = sizeof(int),
55250+ .mode = 0600,
55251+ .proc_handler = &proc_dointvec,
55252+ },
55253+#endif
55254+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55255+ {
55256+ .ctl_name = CTL_UNNUMBERED,
55257+ .procname = "tpe_invert",
55258+ .data = &grsec_enable_tpe_invert,
55259+ .maxlen = sizeof(int),
55260+ .mode = 0600,
55261+ .proc_handler = &proc_dointvec,
55262+ },
55263+#endif
55264+#ifdef CONFIG_GRKERNSEC_TPE_ALL
55265+ {
55266+ .ctl_name = CTL_UNNUMBERED,
55267+ .procname = "tpe_restrict_all",
55268+ .data = &grsec_enable_tpe_all,
55269+ .maxlen = sizeof(int),
55270+ .mode = 0600,
55271+ .proc_handler = &proc_dointvec,
55272+ },
55273+#endif
55274+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55275+ {
55276+ .ctl_name = CTL_UNNUMBERED,
55277+ .procname = "socket_all",
55278+ .data = &grsec_enable_socket_all,
55279+ .maxlen = sizeof(int),
55280+ .mode = 0600,
55281+ .proc_handler = &proc_dointvec,
55282+ },
55283+ {
55284+ .ctl_name = CTL_UNNUMBERED,
55285+ .procname = "socket_all_gid",
55286+ .data = &grsec_socket_all_gid,
55287+ .maxlen = sizeof(int),
55288+ .mode = 0600,
55289+ .proc_handler = &proc_dointvec,
55290+ },
55291+#endif
55292+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55293+ {
55294+ .ctl_name = CTL_UNNUMBERED,
55295+ .procname = "socket_client",
55296+ .data = &grsec_enable_socket_client,
55297+ .maxlen = sizeof(int),
55298+ .mode = 0600,
55299+ .proc_handler = &proc_dointvec,
55300+ },
55301+ {
55302+ .ctl_name = CTL_UNNUMBERED,
55303+ .procname = "socket_client_gid",
55304+ .data = &grsec_socket_client_gid,
55305+ .maxlen = sizeof(int),
55306+ .mode = 0600,
55307+ .proc_handler = &proc_dointvec,
55308+ },
55309+#endif
55310+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55311+ {
55312+ .ctl_name = CTL_UNNUMBERED,
55313+ .procname = "socket_server",
55314+ .data = &grsec_enable_socket_server,
55315+ .maxlen = sizeof(int),
55316+ .mode = 0600,
55317+ .proc_handler = &proc_dointvec,
55318+ },
55319+ {
55320+ .ctl_name = CTL_UNNUMBERED,
55321+ .procname = "socket_server_gid",
55322+ .data = &grsec_socket_server_gid,
55323+ .maxlen = sizeof(int),
55324+ .mode = 0600,
55325+ .proc_handler = &proc_dointvec,
55326+ },
55327+#endif
55328+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
55329+ {
55330+ .ctl_name = CTL_UNNUMBERED,
55331+ .procname = "audit_group",
55332+ .data = &grsec_enable_group,
55333+ .maxlen = sizeof(int),
55334+ .mode = 0600,
55335+ .proc_handler = &proc_dointvec,
55336+ },
55337+ {
55338+ .ctl_name = CTL_UNNUMBERED,
55339+ .procname = "audit_gid",
55340+ .data = &grsec_audit_gid,
55341+ .maxlen = sizeof(int),
55342+ .mode = 0600,
55343+ .proc_handler = &proc_dointvec,
55344+ },
55345+#endif
55346+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55347+ {
55348+ .ctl_name = CTL_UNNUMBERED,
55349+ .procname = "audit_chdir",
55350+ .data = &grsec_enable_chdir,
55351+ .maxlen = sizeof(int),
55352+ .mode = 0600,
55353+ .proc_handler = &proc_dointvec,
55354+ },
55355+#endif
55356+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55357+ {
55358+ .ctl_name = CTL_UNNUMBERED,
55359+ .procname = "audit_mount",
55360+ .data = &grsec_enable_mount,
55361+ .maxlen = sizeof(int),
55362+ .mode = 0600,
55363+ .proc_handler = &proc_dointvec,
55364+ },
55365+#endif
55366+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55367+ {
55368+ .ctl_name = CTL_UNNUMBERED,
55369+ .procname = "audit_textrel",
55370+ .data = &grsec_enable_audit_textrel,
55371+ .maxlen = sizeof(int),
55372+ .mode = 0600,
55373+ .proc_handler = &proc_dointvec,
55374+ },
55375+#endif
55376+#ifdef CONFIG_GRKERNSEC_DMESG
55377+ {
55378+ .ctl_name = CTL_UNNUMBERED,
55379+ .procname = "dmesg",
55380+ .data = &grsec_enable_dmesg,
55381+ .maxlen = sizeof(int),
55382+ .mode = 0600,
55383+ .proc_handler = &proc_dointvec,
55384+ },
55385+#endif
55386+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55387+ {
55388+ .ctl_name = CTL_UNNUMBERED,
55389+ .procname = "chroot_findtask",
55390+ .data = &grsec_enable_chroot_findtask,
55391+ .maxlen = sizeof(int),
55392+ .mode = 0600,
55393+ .proc_handler = &proc_dointvec,
55394+ },
55395+#endif
55396+#ifdef CONFIG_GRKERNSEC_RESLOG
55397+ {
55398+ .ctl_name = CTL_UNNUMBERED,
55399+ .procname = "resource_logging",
55400+ .data = &grsec_resource_logging,
55401+ .maxlen = sizeof(int),
55402+ .mode = 0600,
55403+ .proc_handler = &proc_dointvec,
55404+ },
55405+#endif
55406+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55407+ {
55408+ .ctl_name = CTL_UNNUMBERED,
55409+ .procname = "audit_ptrace",
55410+ .data = &grsec_enable_audit_ptrace,
55411+ .maxlen = sizeof(int),
55412+ .mode = 0600,
55413+ .proc_handler = &proc_dointvec,
55414+ },
55415+#endif
55416+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55417+ {
55418+ .ctl_name = CTL_UNNUMBERED,
55419+ .procname = "harden_ptrace",
55420+ .data = &grsec_enable_harden_ptrace,
55421+ .maxlen = sizeof(int),
55422+ .mode = 0600,
55423+ .proc_handler = &proc_dointvec,
55424+ },
55425+#endif
55426+ {
55427+ .ctl_name = CTL_UNNUMBERED,
55428+ .procname = "grsec_lock",
55429+ .data = &grsec_lock,
55430+ .maxlen = sizeof(int),
55431+ .mode = 0600,
55432+ .proc_handler = &proc_dointvec,
55433+ },
55434+#endif
55435+#ifdef CONFIG_GRKERNSEC_ROFS
55436+ {
55437+ .ctl_name = CTL_UNNUMBERED,
55438+ .procname = "romount_protect",
55439+ .data = &grsec_enable_rofs,
55440+ .maxlen = sizeof(int),
55441+ .mode = 0600,
55442+ .proc_handler = &proc_dointvec_minmax,
55443+ .extra1 = &one,
55444+ .extra2 = &one,
55445+ },
55446+#endif
55447+ { .ctl_name = 0 }
55448+};
55449+#endif
55450diff -urNp linux-2.6.32.43/grsecurity/grsec_time.c linux-2.6.32.43/grsecurity/grsec_time.c
55451--- linux-2.6.32.43/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
55452+++ linux-2.6.32.43/grsecurity/grsec_time.c 2011-04-17 15:56:46.000000000 -0400
55453@@ -0,0 +1,16 @@
55454+#include <linux/kernel.h>
55455+#include <linux/sched.h>
55456+#include <linux/grinternal.h>
55457+#include <linux/module.h>
55458+
55459+void
55460+gr_log_timechange(void)
55461+{
55462+#ifdef CONFIG_GRKERNSEC_TIME
55463+ if (grsec_enable_time)
55464+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
55465+#endif
55466+ return;
55467+}
55468+
55469+EXPORT_SYMBOL(gr_log_timechange);
55470diff -urNp linux-2.6.32.43/grsecurity/grsec_tpe.c linux-2.6.32.43/grsecurity/grsec_tpe.c
55471--- linux-2.6.32.43/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
55472+++ linux-2.6.32.43/grsecurity/grsec_tpe.c 2011-04-17 15:56:46.000000000 -0400
55473@@ -0,0 +1,39 @@
55474+#include <linux/kernel.h>
55475+#include <linux/sched.h>
55476+#include <linux/file.h>
55477+#include <linux/fs.h>
55478+#include <linux/grinternal.h>
55479+
55480+extern int gr_acl_tpe_check(void);
55481+
55482+int
55483+gr_tpe_allow(const struct file *file)
55484+{
55485+#ifdef CONFIG_GRKERNSEC
55486+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
55487+ const struct cred *cred = current_cred();
55488+
55489+ if (cred->uid && ((grsec_enable_tpe &&
55490+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55491+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
55492+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
55493+#else
55494+ in_group_p(grsec_tpe_gid)
55495+#endif
55496+ ) || gr_acl_tpe_check()) &&
55497+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
55498+ (inode->i_mode & S_IWOTH))))) {
55499+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
55500+ return 0;
55501+ }
55502+#ifdef CONFIG_GRKERNSEC_TPE_ALL
55503+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
55504+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
55505+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
55506+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
55507+ return 0;
55508+ }
55509+#endif
55510+#endif
55511+ return 1;
55512+}
55513diff -urNp linux-2.6.32.43/grsecurity/grsum.c linux-2.6.32.43/grsecurity/grsum.c
55514--- linux-2.6.32.43/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
55515+++ linux-2.6.32.43/grsecurity/grsum.c 2011-04-17 15:56:46.000000000 -0400
55516@@ -0,0 +1,61 @@
55517+#include <linux/err.h>
55518+#include <linux/kernel.h>
55519+#include <linux/sched.h>
55520+#include <linux/mm.h>
55521+#include <linux/scatterlist.h>
55522+#include <linux/crypto.h>
55523+#include <linux/gracl.h>
55524+
55525+
55526+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
55527+#error "crypto and sha256 must be built into the kernel"
55528+#endif
55529+
55530+int
55531+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
55532+{
55533+ char *p;
55534+ struct crypto_hash *tfm;
55535+ struct hash_desc desc;
55536+ struct scatterlist sg;
55537+ unsigned char temp_sum[GR_SHA_LEN];
55538+ volatile int retval = 0;
55539+ volatile int dummy = 0;
55540+ unsigned int i;
55541+
55542+ sg_init_table(&sg, 1);
55543+
55544+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
55545+ if (IS_ERR(tfm)) {
55546+ /* should never happen, since sha256 should be built in */
55547+ return 1;
55548+ }
55549+
55550+ desc.tfm = tfm;
55551+ desc.flags = 0;
55552+
55553+ crypto_hash_init(&desc);
55554+
55555+ p = salt;
55556+ sg_set_buf(&sg, p, GR_SALT_LEN);
55557+ crypto_hash_update(&desc, &sg, sg.length);
55558+
55559+ p = entry->pw;
55560+ sg_set_buf(&sg, p, strlen(p));
55561+
55562+ crypto_hash_update(&desc, &sg, sg.length);
55563+
55564+ crypto_hash_final(&desc, temp_sum);
55565+
55566+ memset(entry->pw, 0, GR_PW_LEN);
55567+
55568+ for (i = 0; i < GR_SHA_LEN; i++)
55569+ if (sum[i] != temp_sum[i])
55570+ retval = 1;
55571+ else
55572+ dummy = 1; // waste a cycle
55573+
55574+ crypto_free_hash(tfm);
55575+
55576+ return retval;
55577+}
55578diff -urNp linux-2.6.32.43/grsecurity/Kconfig linux-2.6.32.43/grsecurity/Kconfig
55579--- linux-2.6.32.43/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
55580+++ linux-2.6.32.43/grsecurity/Kconfig 2011-07-06 19:57:57.000000000 -0400
55581@@ -0,0 +1,1047 @@
55582+#
55583+# grecurity configuration
55584+#
55585+
55586+menu "Grsecurity"
55587+
55588+config GRKERNSEC
55589+ bool "Grsecurity"
55590+ select CRYPTO
55591+ select CRYPTO_SHA256
55592+ help
55593+ If you say Y here, you will be able to configure many features
55594+ that will enhance the security of your system. It is highly
55595+ recommended that you say Y here and read through the help
55596+ for each option so that you fully understand the features and
55597+ can evaluate their usefulness for your machine.
55598+
55599+choice
55600+ prompt "Security Level"
55601+ depends on GRKERNSEC
55602+ default GRKERNSEC_CUSTOM
55603+
55604+config GRKERNSEC_LOW
55605+ bool "Low"
55606+ select GRKERNSEC_LINK
55607+ select GRKERNSEC_FIFO
55608+ select GRKERNSEC_EXECVE
55609+ select GRKERNSEC_RANDNET
55610+ select GRKERNSEC_DMESG
55611+ select GRKERNSEC_CHROOT
55612+ select GRKERNSEC_CHROOT_CHDIR
55613+
55614+ help
55615+ If you choose this option, several of the grsecurity options will
55616+ be enabled that will give you greater protection against a number
55617+ of attacks, while assuring that none of your software will have any
55618+ conflicts with the additional security measures. If you run a lot
55619+ of unusual software, or you are having problems with the higher
55620+ security levels, you should say Y here. With this option, the
55621+ following features are enabled:
55622+
55623+ - Linking restrictions
55624+ - FIFO restrictions
55625+ - Enforcing RLIMIT_NPROC on execve
55626+ - Restricted dmesg
55627+ - Enforced chdir("/") on chroot
55628+ - Runtime module disabling
55629+
55630+config GRKERNSEC_MEDIUM
55631+ bool "Medium"
55632+ select PAX
55633+ select PAX_EI_PAX
55634+ select PAX_PT_PAX_FLAGS
55635+ select PAX_HAVE_ACL_FLAGS
55636+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
55637+ select GRKERNSEC_CHROOT
55638+ select GRKERNSEC_CHROOT_SYSCTL
55639+ select GRKERNSEC_LINK
55640+ select GRKERNSEC_FIFO
55641+ select GRKERNSEC_EXECVE
55642+ select GRKERNSEC_DMESG
55643+ select GRKERNSEC_RANDNET
55644+ select GRKERNSEC_FORKFAIL
55645+ select GRKERNSEC_TIME
55646+ select GRKERNSEC_SIGNAL
55647+ select GRKERNSEC_CHROOT
55648+ select GRKERNSEC_CHROOT_UNIX
55649+ select GRKERNSEC_CHROOT_MOUNT
55650+ select GRKERNSEC_CHROOT_PIVOT
55651+ select GRKERNSEC_CHROOT_DOUBLE
55652+ select GRKERNSEC_CHROOT_CHDIR
55653+ select GRKERNSEC_CHROOT_MKNOD
55654+ select GRKERNSEC_PROC
55655+ select GRKERNSEC_PROC_USERGROUP
55656+ select PAX_RANDUSTACK
55657+ select PAX_ASLR
55658+ select PAX_RANDMMAP
55659+ select PAX_REFCOUNT if (X86 || SPARC64)
55660+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
55661+
55662+ help
55663+ If you say Y here, several features in addition to those included
55664+ in the low additional security level will be enabled. These
55665+ features provide even more security to your system, though in rare
55666+ cases they may be incompatible with very old or poorly written
55667+ software. If you enable this option, make sure that your auth
55668+ service (identd) is running as gid 1001. With this option,
55669+ the following features (in addition to those provided in the
55670+ low additional security level) will be enabled:
55671+
55672+ - Failed fork logging
55673+ - Time change logging
55674+ - Signal logging
55675+ - Deny mounts in chroot
55676+ - Deny double chrooting
55677+ - Deny sysctl writes in chroot
55678+ - Deny mknod in chroot
55679+ - Deny access to abstract AF_UNIX sockets out of chroot
55680+ - Deny pivot_root in chroot
55681+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
55682+ - /proc restrictions with special GID set to 10 (usually wheel)
55683+ - Address Space Layout Randomization (ASLR)
55684+ - Prevent exploitation of most refcount overflows
55685+ - Bounds checking of copying between the kernel and userland
55686+
55687+config GRKERNSEC_HIGH
55688+ bool "High"
55689+ select GRKERNSEC_LINK
55690+ select GRKERNSEC_FIFO
55691+ select GRKERNSEC_EXECVE
55692+ select GRKERNSEC_DMESG
55693+ select GRKERNSEC_FORKFAIL
55694+ select GRKERNSEC_TIME
55695+ select GRKERNSEC_SIGNAL
55696+ select GRKERNSEC_CHROOT
55697+ select GRKERNSEC_CHROOT_SHMAT
55698+ select GRKERNSEC_CHROOT_UNIX
55699+ select GRKERNSEC_CHROOT_MOUNT
55700+ select GRKERNSEC_CHROOT_FCHDIR
55701+ select GRKERNSEC_CHROOT_PIVOT
55702+ select GRKERNSEC_CHROOT_DOUBLE
55703+ select GRKERNSEC_CHROOT_CHDIR
55704+ select GRKERNSEC_CHROOT_MKNOD
55705+ select GRKERNSEC_CHROOT_CAPS
55706+ select GRKERNSEC_CHROOT_SYSCTL
55707+ select GRKERNSEC_CHROOT_FINDTASK
55708+ select GRKERNSEC_SYSFS_RESTRICT
55709+ select GRKERNSEC_PROC
55710+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
55711+ select GRKERNSEC_HIDESYM
55712+ select GRKERNSEC_BRUTE
55713+ select GRKERNSEC_PROC_USERGROUP
55714+ select GRKERNSEC_KMEM
55715+ select GRKERNSEC_RESLOG
55716+ select GRKERNSEC_RANDNET
55717+ select GRKERNSEC_PROC_ADD
55718+ select GRKERNSEC_CHROOT_CHMOD
55719+ select GRKERNSEC_CHROOT_NICE
55720+ select GRKERNSEC_AUDIT_MOUNT
55721+ select GRKERNSEC_MODHARDEN if (MODULES)
55722+ select GRKERNSEC_HARDEN_PTRACE
55723+ select GRKERNSEC_VM86 if (X86_32)
55724+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
55725+ select PAX
55726+ select PAX_RANDUSTACK
55727+ select PAX_ASLR
55728+ select PAX_RANDMMAP
55729+ select PAX_NOEXEC
55730+ select PAX_MPROTECT
55731+ select PAX_EI_PAX
55732+ select PAX_PT_PAX_FLAGS
55733+ select PAX_HAVE_ACL_FLAGS
55734+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
55735+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
55736+ select PAX_RANDKSTACK if (X86_TSC && X86)
55737+ select PAX_SEGMEXEC if (X86_32)
55738+ select PAX_PAGEEXEC
55739+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
55740+ select PAX_EMUTRAMP if (PARISC)
55741+ select PAX_EMUSIGRT if (PARISC)
55742+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
55743+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
55744+ select PAX_REFCOUNT if (X86 || SPARC64)
55745+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
55746+ help
55747+ If you say Y here, many of the features of grsecurity will be
55748+ enabled, which will protect you against many kinds of attacks
55749+ against your system. The heightened security comes at a cost
55750+ of an increased chance of incompatibilities with rare software
55751+ on your machine. Since this security level enables PaX, you should
55752+ view <http://pax.grsecurity.net> and read about the PaX
55753+ project. While you are there, download chpax and run it on
55754+ binaries that cause problems with PaX. Also remember that
55755+ since the /proc restrictions are enabled, you must run your
55756+ identd as gid 1001. This security level enables the following
55757+ features in addition to those listed in the low and medium
55758+ security levels:
55759+
55760+ - Additional /proc restrictions
55761+ - Chmod restrictions in chroot
55762+ - No signals, ptrace, or viewing of processes outside of chroot
55763+ - Capability restrictions in chroot
55764+ - Deny fchdir out of chroot
55765+ - Priority restrictions in chroot
55766+ - Segmentation-based implementation of PaX
55767+ - Mprotect restrictions
55768+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
55769+ - Kernel stack randomization
55770+ - Mount/unmount/remount logging
55771+ - Kernel symbol hiding
55772+ - Prevention of memory exhaustion-based exploits
55773+ - Hardening of module auto-loading
55774+ - Ptrace restrictions
55775+ - Restricted vm86 mode
55776+ - Restricted sysfs/debugfs
55777+ - Active kernel exploit response
55778+
55779+config GRKERNSEC_CUSTOM
55780+ bool "Custom"
55781+ help
55782+ If you say Y here, you will be able to configure every grsecurity
55783+ option, which allows you to enable many more features that aren't
55784+ covered in the basic security levels. These additional features
55785+ include TPE, socket restrictions, and the sysctl system for
55786+ grsecurity. It is advised that you read through the help for
55787+ each option to determine its usefulness in your situation.
55788+
55789+endchoice
55790+
55791+menu "Address Space Protection"
55792+depends on GRKERNSEC
55793+
55794+config GRKERNSEC_KMEM
55795+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
55796+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
55797+ help
55798+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
55799+ be written to via mmap or otherwise to modify the running kernel.
55800+ /dev/port will also not be allowed to be opened. If you have module
55801+ support disabled, enabling this will close up four ways that are
55802+ currently used to insert malicious code into the running kernel.
55803+ Even with all these features enabled, we still highly recommend that
55804+ you use the RBAC system, as it is still possible for an attacker to
55805+ modify the running kernel through privileged I/O granted by ioperm/iopl.
55806+ If you are not using XFree86, you may be able to stop this additional
55807+ case by enabling the 'Disable privileged I/O' option. Though nothing
55808+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
55809+ but only to video memory, which is the only writing we allow in this
55810+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
55811+ not be allowed to mprotect it with PROT_WRITE later.
55812+ It is highly recommended that you say Y here if you meet all the
55813+ conditions above.
55814+
55815+config GRKERNSEC_VM86
55816+ bool "Restrict VM86 mode"
55817+ depends on X86_32
55818+
55819+ help
55820+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
55821+ make use of a special execution mode on 32bit x86 processors called
55822+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
55823+ video cards and will still work with this option enabled. The purpose
55824+ of the option is to prevent exploitation of emulation errors in
55825+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
55826+ Nearly all users should be able to enable this option.
55827+
55828+config GRKERNSEC_IO
55829+ bool "Disable privileged I/O"
55830+ depends on X86
55831+ select RTC_CLASS
55832+ select RTC_INTF_DEV
55833+ select RTC_DRV_CMOS
55834+
55835+ help
55836+ If you say Y here, all ioperm and iopl calls will return an error.
55837+ Ioperm and iopl can be used to modify the running kernel.
55838+ Unfortunately, some programs need this access to operate properly,
55839+ the most notable of which are XFree86 and hwclock. hwclock can be
55840+ remedied by having RTC support in the kernel, so real-time
55841+ clock support is enabled if this option is enabled, to ensure
55842+ that hwclock operates correctly. XFree86 still will not
55843+ operate correctly with this option enabled, so DO NOT CHOOSE Y
55844+ IF YOU USE XFree86. If you use XFree86 and you still want to
55845+ protect your kernel against modification, use the RBAC system.
55846+
55847+config GRKERNSEC_PROC_MEMMAP
55848+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
55849+ default y if (PAX_NOEXEC || PAX_ASLR)
55850+ depends on PAX_NOEXEC || PAX_ASLR
55851+ help
55852+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
55853+ give no information about the addresses of its mappings if
55854+ PaX features that rely on random addresses are enabled on the task.
55855+ If you use PaX it is greatly recommended that you say Y here as it
55856+ closes up a hole that makes the full ASLR useless for suid
55857+ binaries.
55858+
55859+config GRKERNSEC_BRUTE
55860+ bool "Deter exploit bruteforcing"
55861+ help
55862+ If you say Y here, attempts to bruteforce exploits against forking
55863+ daemons such as apache or sshd, as well as against suid/sgid binaries
55864+ will be deterred. When a child of a forking daemon is killed by PaX
55865+ or crashes due to an illegal instruction or other suspicious signal,
55866+ the parent process will be delayed 30 seconds upon every subsequent
55867+ fork until the administrator is able to assess the situation and
55868+ restart the daemon.
55869+ In the suid/sgid case, the attempt is logged, the user has all their
55870+ processes terminated, and they are prevented from executing any further
55871+ processes for 15 minutes.
55872+ It is recommended that you also enable signal logging in the auditing
55873+ section so that logs are generated when a process triggers a suspicious
55874+ signal.
55875+ If the sysctl option is enabled, a sysctl option with name
55876+ "deter_bruteforce" is created.
55877+
55878+config GRKERNSEC_MODHARDEN
55879+ bool "Harden module auto-loading"
55880+ depends on MODULES
55881+ help
55882+ If you say Y here, module auto-loading in response to use of some
55883+ feature implemented by an unloaded module will be restricted to
55884+ root users. Enabling this option helps defend against attacks
55885+ by unprivileged users who abuse the auto-loading behavior to
55886+ cause a vulnerable module to load that is then exploited.
55887+
55888+ If this option prevents a legitimate use of auto-loading for a
55889+ non-root user, the administrator can execute modprobe manually
55890+ with the exact name of the module mentioned in the alert log.
55891+ Alternatively, the administrator can add the module to the list
55892+ of modules loaded at boot by modifying init scripts.
55893+
55894+ Modification of init scripts will most likely be needed on
55895+ Ubuntu servers with encrypted home directory support enabled,
55896+ as the first non-root user logging in will cause the ecb(aes),
55897+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55898+
55899+config GRKERNSEC_HIDESYM
55900+ bool "Hide kernel symbols"
55901+ help
55902+ If you say Y here, getting information on loaded modules, and
55903+ displaying all kernel symbols through a syscall will be restricted
55904+ to users with CAP_SYS_MODULE. For software compatibility reasons,
55905+ /proc/kallsyms will be restricted to the root user. The RBAC
55906+ system can hide that entry even from root.
55907+
55908+ This option also prevents leaking of kernel addresses through
55909+ several /proc entries.
55910+
55911+ Note that this option is only effective provided the following
55912+ conditions are met:
55913+ 1) The kernel using grsecurity is not precompiled by some distribution
55914+ 2) You have also enabled GRKERNSEC_DMESG
55915+ 3) You are using the RBAC system and hiding other files such as your
55916+ kernel image and System.map. Alternatively, enabling this option
55917+ causes the permissions on /boot, /lib/modules, and the kernel
55918+ source directory to change at compile time to prevent
55919+ reading by non-root users.
55920+ If the above conditions are met, this option will aid in providing a
55921+ useful protection against local kernel exploitation of overflows
55922+ and arbitrary read/write vulnerabilities.
55923+
55924+config GRKERNSEC_KERN_LOCKOUT
55925+ bool "Active kernel exploit response"
55926+ depends on X86 || ARM || PPC || SPARC
55927+ help
55928+ If you say Y here, when a PaX alert is triggered due to suspicious
55929+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55930+ or an OOPs occurs due to bad memory accesses, instead of just
55931+ terminating the offending process (and potentially allowing
55932+ a subsequent exploit from the same user), we will take one of two
55933+ actions:
55934+ If the user was root, we will panic the system
55935+ If the user was non-root, we will log the attempt, terminate
55936+ all processes owned by the user, then prevent them from creating
55937+ any new processes until the system is restarted
55938+ This deters repeated kernel exploitation/bruteforcing attempts
55939+ and is useful for later forensics.
55940+
55941+endmenu
55942+menu "Role Based Access Control Options"
55943+depends on GRKERNSEC
55944+
55945+config GRKERNSEC_RBAC_DEBUG
55946+ bool
55947+
55948+config GRKERNSEC_NO_RBAC
55949+ bool "Disable RBAC system"
55950+ help
55951+ If you say Y here, the /dev/grsec device will be removed from the kernel,
55952+ preventing the RBAC system from being enabled. You should only say Y
55953+ here if you have no intention of using the RBAC system, so as to prevent
55954+ an attacker with root access from misusing the RBAC system to hide files
55955+ and processes when loadable module support and /dev/[k]mem have been
55956+ locked down.
55957+
55958+config GRKERNSEC_ACL_HIDEKERN
55959+ bool "Hide kernel processes"
55960+ help
55961+ If you say Y here, all kernel threads will be hidden to all
55962+ processes but those whose subject has the "view hidden processes"
55963+ flag.
55964+
55965+config GRKERNSEC_ACL_MAXTRIES
55966+ int "Maximum tries before password lockout"
55967+ default 3
55968+ help
55969+ This option enforces the maximum number of times a user can attempt
55970+ to authorize themselves with the grsecurity RBAC system before being
55971+ denied the ability to attempt authorization again for a specified time.
55972+ The lower the number, the harder it will be to brute-force a password.
55973+
55974+config GRKERNSEC_ACL_TIMEOUT
55975+ int "Time to wait after max password tries, in seconds"
55976+ default 30
55977+ help
55978+ This option specifies the time the user must wait after attempting to
55979+ authorize to the RBAC system with the maximum number of invalid
55980+ passwords. The higher the number, the harder it will be to brute-force
55981+ a password.
55982+
55983+endmenu
55984+menu "Filesystem Protections"
55985+depends on GRKERNSEC
55986+
55987+config GRKERNSEC_PROC
55988+ bool "Proc restrictions"
55989+ help
55990+ If you say Y here, the permissions of the /proc filesystem
55991+ will be altered to enhance system security and privacy. You MUST
55992+ choose either a user only restriction or a user and group restriction.
55993+ Depending upon the option you choose, you can either restrict users to
55994+ see only the processes they themselves run, or choose a group that can
55995+ view all processes and files normally restricted to root if you choose
55996+ the "restrict to user only" option. NOTE: If you're running identd as
55997+ a non-root user, you will have to run it as the group you specify here.
55998+
55999+config GRKERNSEC_PROC_USER
56000+ bool "Restrict /proc to user only"
56001+ depends on GRKERNSEC_PROC
56002+ help
56003+ If you say Y here, non-root users will only be able to view their own
56004+ processes, and restricts them from viewing network-related information,
56005+ and viewing kernel symbol and module information.
56006+
56007+config GRKERNSEC_PROC_USERGROUP
56008+ bool "Allow special group"
56009+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56010+ help
56011+ If you say Y here, you will be able to select a group that will be
56012+ able to view all processes and network-related information. If you've
56013+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56014+ remain hidden. This option is useful if you want to run identd as
56015+ a non-root user.
56016+
56017+config GRKERNSEC_PROC_GID
56018+ int "GID for special group"
56019+ depends on GRKERNSEC_PROC_USERGROUP
56020+ default 1001
56021+
56022+config GRKERNSEC_PROC_ADD
56023+ bool "Additional restrictions"
56024+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56025+ help
56026+ If you say Y here, additional restrictions will be placed on
56027+ /proc that keep normal users from viewing device information and
56028+ slabinfo information that could be useful for exploits.
56029+
56030+config GRKERNSEC_LINK
56031+ bool "Linking restrictions"
56032+ help
56033+ If you say Y here, /tmp race exploits will be prevented, since users
56034+ will no longer be able to follow symlinks owned by other users in
56035+ world-writable +t directories (e.g. /tmp), unless the owner of the
56036+ symlink is the owner of the directory. users will also not be
56037+ able to hardlink to files they do not own. If the sysctl option is
56038+ enabled, a sysctl option with name "linking_restrictions" is created.
56039+
56040+config GRKERNSEC_FIFO
56041+ bool "FIFO restrictions"
56042+ help
56043+ If you say Y here, users will not be able to write to FIFOs they don't
56044+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56045+ the FIFO is the same owner of the directory it's held in. If the sysctl
56046+ option is enabled, a sysctl option with name "fifo_restrictions" is
56047+ created.
56048+
56049+config GRKERNSEC_SYSFS_RESTRICT
56050+ bool "Sysfs/debugfs restriction"
56051+ depends on SYSFS
56052+ help
56053+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56054+ any filesystem normally mounted under it (e.g. debugfs) will only
56055+ be accessible by root. These filesystems generally provide access
56056+ to hardware and debug information that isn't appropriate for unprivileged
56057+ users of the system. Sysfs and debugfs have also become a large source
56058+ of new vulnerabilities, ranging from infoleaks to local compromise.
56059+ There has been very little oversight with an eye toward security involved
56060+ in adding new exporters of information to these filesystems, so their
56061+ use is discouraged.
56062+ This option is equivalent to a chmod 0700 of the mount paths.
56063+
56064+config GRKERNSEC_ROFS
56065+ bool "Runtime read-only mount protection"
56066+ help
56067+ If you say Y here, a sysctl option with name "romount_protect" will
56068+ be created. By setting this option to 1 at runtime, filesystems
56069+ will be protected in the following ways:
56070+ * No new writable mounts will be allowed
56071+ * Existing read-only mounts won't be able to be remounted read/write
56072+ * Write operations will be denied on all block devices
56073+ This option acts independently of grsec_lock: once it is set to 1,
56074+ it cannot be turned off. Therefore, please be mindful of the resulting
56075+ behavior if this option is enabled in an init script on a read-only
56076+ filesystem. This feature is mainly intended for secure embedded systems.
56077+
56078+config GRKERNSEC_CHROOT
56079+ bool "Chroot jail restrictions"
56080+ help
56081+ If you say Y here, you will be able to choose several options that will
56082+ make breaking out of a chrooted jail much more difficult. If you
56083+ encounter no software incompatibilities with the following options, it
56084+ is recommended that you enable each one.
56085+
56086+config GRKERNSEC_CHROOT_MOUNT
56087+ bool "Deny mounts"
56088+ depends on GRKERNSEC_CHROOT
56089+ help
56090+ If you say Y here, processes inside a chroot will not be able to
56091+ mount or remount filesystems. If the sysctl option is enabled, a
56092+ sysctl option with name "chroot_deny_mount" is created.
56093+
56094+config GRKERNSEC_CHROOT_DOUBLE
56095+ bool "Deny double-chroots"
56096+ depends on GRKERNSEC_CHROOT
56097+ help
56098+ If you say Y here, processes inside a chroot will not be able to chroot
56099+ again outside the chroot. This is a widely used method of breaking
56100+ out of a chroot jail and should not be allowed. If the sysctl
56101+ option is enabled, a sysctl option with name
56102+ "chroot_deny_chroot" is created.
56103+
56104+config GRKERNSEC_CHROOT_PIVOT
56105+ bool "Deny pivot_root in chroot"
56106+ depends on GRKERNSEC_CHROOT
56107+ help
56108+ If you say Y here, processes inside a chroot will not be able to use
56109+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56110+ works similar to chroot in that it changes the root filesystem. This
56111+ function could be misused in a chrooted process to attempt to break out
56112+ of the chroot, and therefore should not be allowed. If the sysctl
56113+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56114+ created.
56115+
56116+config GRKERNSEC_CHROOT_CHDIR
56117+ bool "Enforce chdir(\"/\") on all chroots"
56118+ depends on GRKERNSEC_CHROOT
56119+ help
56120+ If you say Y here, the current working directory of all newly-chrooted
56121+ applications will be set to the the root directory of the chroot.
56122+ The man page on chroot(2) states:
56123+ Note that this call does not change the current working
56124+ directory, so that `.' can be outside the tree rooted at
56125+ `/'. In particular, the super-user can escape from a
56126+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56127+
56128+ It is recommended that you say Y here, since it's not known to break
56129+ any software. If the sysctl option is enabled, a sysctl option with
56130+ name "chroot_enforce_chdir" is created.
56131+
56132+config GRKERNSEC_CHROOT_CHMOD
56133+ bool "Deny (f)chmod +s"
56134+ depends on GRKERNSEC_CHROOT
56135+ help
56136+ If you say Y here, processes inside a chroot will not be able to chmod
56137+ or fchmod files to make them have suid or sgid bits. This protects
56138+ against another published method of breaking a chroot. If the sysctl
56139+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56140+ created.
56141+
56142+config GRKERNSEC_CHROOT_FCHDIR
56143+ bool "Deny fchdir out of chroot"
56144+ depends on GRKERNSEC_CHROOT
56145+ help
56146+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56147+ to a file descriptor of the chrooting process that points to a directory
56148+ outside the filesystem will be stopped. If the sysctl option
56149+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56150+
56151+config GRKERNSEC_CHROOT_MKNOD
56152+ bool "Deny mknod"
56153+ depends on GRKERNSEC_CHROOT
56154+ help
56155+ If you say Y here, processes inside a chroot will not be allowed to
56156+ mknod. The problem with using mknod inside a chroot is that it
56157+ would allow an attacker to create a device entry that is the same
56158+ as one on the physical root of your system, which could range from
56159+ anything from the console device to a device for your harddrive (which
56160+ they could then use to wipe the drive or steal data). It is recommended
56161+ that you say Y here, unless you run into software incompatibilities.
56162+ If the sysctl option is enabled, a sysctl option with name
56163+ "chroot_deny_mknod" is created.
56164+
56165+config GRKERNSEC_CHROOT_SHMAT
56166+ bool "Deny shmat() out of chroot"
56167+ depends on GRKERNSEC_CHROOT
56168+ help
56169+ If you say Y here, processes inside a chroot will not be able to attach
56170+ to shared memory segments that were created outside of the chroot jail.
56171+ It is recommended that you say Y here. If the sysctl option is enabled,
56172+ a sysctl option with name "chroot_deny_shmat" is created.
56173+
56174+config GRKERNSEC_CHROOT_UNIX
56175+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56176+ depends on GRKERNSEC_CHROOT
56177+ help
56178+ If you say Y here, processes inside a chroot will not be able to
56179+ connect to abstract (meaning not belonging to a filesystem) Unix
56180+ domain sockets that were bound outside of a chroot. It is recommended
56181+ that you say Y here. If the sysctl option is enabled, a sysctl option
56182+ with name "chroot_deny_unix" is created.
56183+
56184+config GRKERNSEC_CHROOT_FINDTASK
56185+ bool "Protect outside processes"
56186+ depends on GRKERNSEC_CHROOT
56187+ help
56188+ If you say Y here, processes inside a chroot will not be able to
56189+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56190+ getsid, or view any process outside of the chroot. If the sysctl
56191+ option is enabled, a sysctl option with name "chroot_findtask" is
56192+ created.
56193+
56194+config GRKERNSEC_CHROOT_NICE
56195+ bool "Restrict priority changes"
56196+ depends on GRKERNSEC_CHROOT
56197+ help
56198+ If you say Y here, processes inside a chroot will not be able to raise
56199+ the priority of processes in the chroot, or alter the priority of
56200+ processes outside the chroot. This provides more security than simply
56201+ removing CAP_SYS_NICE from the process' capability set. If the
56202+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56203+ is created.
56204+
56205+config GRKERNSEC_CHROOT_SYSCTL
56206+ bool "Deny sysctl writes"
56207+ depends on GRKERNSEC_CHROOT
56208+ help
56209+ If you say Y here, an attacker in a chroot will not be able to
56210+ write to sysctl entries, either by sysctl(2) or through a /proc
56211+ interface. It is strongly recommended that you say Y here. If the
56212+ sysctl option is enabled, a sysctl option with name
56213+ "chroot_deny_sysctl" is created.
56214+
56215+config GRKERNSEC_CHROOT_CAPS
56216+ bool "Capability restrictions"
56217+ depends on GRKERNSEC_CHROOT
56218+ help
56219+ If you say Y here, the capabilities on all root processes within a
56220+ chroot jail will be lowered to stop module insertion, raw i/o,
56221+ system and net admin tasks, rebooting the system, modifying immutable
56222+ files, modifying IPC owned by another, and changing the system time.
56223+ This is left an option because it can break some apps. Disable this
56224+ if your chrooted apps are having problems performing those kinds of
56225+ tasks. If the sysctl option is enabled, a sysctl option with
56226+ name "chroot_caps" is created.
56227+
56228+endmenu
56229+menu "Kernel Auditing"
56230+depends on GRKERNSEC
56231+
56232+config GRKERNSEC_AUDIT_GROUP
56233+ bool "Single group for auditing"
56234+ help
56235+ If you say Y here, the exec, chdir, and (un)mount logging features
56236+ will only operate on a group you specify. This option is recommended
56237+ if you only want to watch certain users instead of having a large
56238+ amount of logs from the entire system. If the sysctl option is enabled,
56239+ a sysctl option with name "audit_group" is created.
56240+
56241+config GRKERNSEC_AUDIT_GID
56242+ int "GID for auditing"
56243+ depends on GRKERNSEC_AUDIT_GROUP
56244+ default 1007
56245+
56246+config GRKERNSEC_EXECLOG
56247+ bool "Exec logging"
56248+ help
56249+ If you say Y here, all execve() calls will be logged (since the
56250+ other exec*() calls are frontends to execve(), all execution
56251+ will be logged). Useful for shell-servers that like to keep track
56252+ of their users. If the sysctl option is enabled, a sysctl option with
56253+ name "exec_logging" is created.
56254+ WARNING: This option when enabled will produce a LOT of logs, especially
56255+ on an active system.
56256+
56257+config GRKERNSEC_RESLOG
56258+ bool "Resource logging"
56259+ help
56260+ If you say Y here, all attempts to overstep resource limits will
56261+ be logged with the resource name, the requested size, and the current
56262+ limit. It is highly recommended that you say Y here. If the sysctl
56263+ option is enabled, a sysctl option with name "resource_logging" is
56264+ created. If the RBAC system is enabled, the sysctl value is ignored.
56265+
56266+config GRKERNSEC_CHROOT_EXECLOG
56267+ bool "Log execs within chroot"
56268+ help
56269+ If you say Y here, all executions inside a chroot jail will be logged
56270+ to syslog. This can cause a large amount of logs if certain
56271+ applications (eg. djb's daemontools) are installed on the system, and
56272+ is therefore left as an option. If the sysctl option is enabled, a
56273+ sysctl option with name "chroot_execlog" is created.
56274+
56275+config GRKERNSEC_AUDIT_PTRACE
56276+ bool "Ptrace logging"
56277+ help
56278+ If you say Y here, all attempts to attach to a process via ptrace
56279+ will be logged. If the sysctl option is enabled, a sysctl option
56280+ with name "audit_ptrace" is created.
56281+
56282+config GRKERNSEC_AUDIT_CHDIR
56283+ bool "Chdir logging"
56284+ help
56285+ If you say Y here, all chdir() calls will be logged. If the sysctl
56286+ option is enabled, a sysctl option with name "audit_chdir" is created.
56287+
56288+config GRKERNSEC_AUDIT_MOUNT
56289+ bool "(Un)Mount logging"
56290+ help
56291+ If you say Y here, all mounts and unmounts will be logged. If the
56292+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56293+ created.
56294+
56295+config GRKERNSEC_SIGNAL
56296+ bool "Signal logging"
56297+ help
56298+ If you say Y here, certain important signals will be logged, such as
56299+ SIGSEGV, which will as a result inform you of when a error in a program
56300+ occurred, which in some cases could mean a possible exploit attempt.
56301+ If the sysctl option is enabled, a sysctl option with name
56302+ "signal_logging" is created.
56303+
56304+config GRKERNSEC_FORKFAIL
56305+ bool "Fork failure logging"
56306+ help
56307+ If you say Y here, all failed fork() attempts will be logged.
56308+ This could suggest a fork bomb, or someone attempting to overstep
56309+ their process limit. If the sysctl option is enabled, a sysctl option
56310+ with name "forkfail_logging" is created.
56311+
56312+config GRKERNSEC_TIME
56313+ bool "Time change logging"
56314+ help
56315+ If you say Y here, any changes of the system clock will be logged.
56316+ If the sysctl option is enabled, a sysctl option with name
56317+ "timechange_logging" is created.
56318+
56319+config GRKERNSEC_PROC_IPADDR
56320+ bool "/proc/<pid>/ipaddr support"
56321+ help
56322+ If you say Y here, a new entry will be added to each /proc/<pid>
56323+ directory that contains the IP address of the person using the task.
56324+ The IP is carried across local TCP and AF_UNIX stream sockets.
56325+ This information can be useful for IDS/IPSes to perform remote response
56326+ to a local attack. The entry is readable by only the owner of the
56327+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56328+ the RBAC system), and thus does not create privacy concerns.
56329+
56330+config GRKERNSEC_RWXMAP_LOG
56331+ bool 'Denied RWX mmap/mprotect logging'
56332+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56333+ help
56334+ If you say Y here, calls to mmap() and mprotect() with explicit
56335+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56336+ denied by the PAX_MPROTECT feature. If the sysctl option is
56337+ enabled, a sysctl option with name "rwxmap_logging" is created.
56338+
56339+config GRKERNSEC_AUDIT_TEXTREL
56340+ bool 'ELF text relocations logging (READ HELP)'
56341+ depends on PAX_MPROTECT
56342+ help
56343+ If you say Y here, text relocations will be logged with the filename
56344+ of the offending library or binary. The purpose of the feature is
56345+ to help Linux distribution developers get rid of libraries and
56346+ binaries that need text relocations which hinder the future progress
56347+ of PaX. Only Linux distribution developers should say Y here, and
56348+ never on a production machine, as this option creates an information
56349+ leak that could aid an attacker in defeating the randomization of
56350+ a single memory region. If the sysctl option is enabled, a sysctl
56351+ option with name "audit_textrel" is created.
56352+
56353+endmenu
56354+
56355+menu "Executable Protections"
56356+depends on GRKERNSEC
56357+
56358+config GRKERNSEC_EXECVE
56359+ bool "Enforce RLIMIT_NPROC on execs"
56360+ help
56361+ If you say Y here, users with a resource limit on processes will
56362+ have the value checked during execve() calls. The current system
56363+ only checks the system limit during fork() calls. If the sysctl option
56364+ is enabled, a sysctl option with name "execve_limiting" is created.
56365+
56366+config GRKERNSEC_DMESG
56367+ bool "Dmesg(8) restriction"
56368+ help
56369+ If you say Y here, non-root users will not be able to use dmesg(8)
56370+ to view up to the last 4kb of messages in the kernel's log buffer.
56371+ The kernel's log buffer often contains kernel addresses and other
56372+ identifying information useful to an attacker in fingerprinting a
56373+ system for a targeted exploit.
56374+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56375+ created.
56376+
56377+config GRKERNSEC_HARDEN_PTRACE
56378+ bool "Deter ptrace-based process snooping"
56379+ help
56380+ If you say Y here, TTY sniffers and other malicious monitoring
56381+ programs implemented through ptrace will be defeated. If you
56382+ have been using the RBAC system, this option has already been
56383+ enabled for several years for all users, with the ability to make
56384+ fine-grained exceptions.
56385+
56386+ This option only affects the ability of non-root users to ptrace
56387+ processes that are not a descendent of the ptracing process.
56388+ This means that strace ./binary and gdb ./binary will still work,
56389+ but attaching to arbitrary processes will not. If the sysctl
56390+ option is enabled, a sysctl option with name "harden_ptrace" is
56391+ created.
56392+
56393+config GRKERNSEC_TPE
56394+ bool "Trusted Path Execution (TPE)"
56395+ help
56396+ If you say Y here, you will be able to choose a gid to add to the
56397+ supplementary groups of users you want to mark as "untrusted."
56398+ These users will not be able to execute any files that are not in
56399+ root-owned directories writable only by root. If the sysctl option
56400+ is enabled, a sysctl option with name "tpe" is created.
56401+
56402+config GRKERNSEC_TPE_ALL
56403+ bool "Partially restrict all non-root users"
56404+ depends on GRKERNSEC_TPE
56405+ help
56406+ If you say Y here, all non-root users will be covered under
56407+ a weaker TPE restriction. This is separate from, and in addition to,
56408+ the main TPE options that you have selected elsewhere. Thus, if a
56409+ "trusted" GID is chosen, this restriction applies to even that GID.
56410+ Under this restriction, all non-root users will only be allowed to
56411+ execute files in directories they own that are not group or
56412+ world-writable, or in directories owned by root and writable only by
56413+ root. If the sysctl option is enabled, a sysctl option with name
56414+ "tpe_restrict_all" is created.
56415+
56416+config GRKERNSEC_TPE_INVERT
56417+ bool "Invert GID option"
56418+ depends on GRKERNSEC_TPE
56419+ help
56420+ If you say Y here, the group you specify in the TPE configuration will
56421+ decide what group TPE restrictions will be *disabled* for. This
56422+ option is useful if you want TPE restrictions to be applied to most
56423+ users on the system. If the sysctl option is enabled, a sysctl option
56424+ with name "tpe_invert" is created. Unlike other sysctl options, this
56425+ entry will default to on for backward-compatibility.
56426+
56427+config GRKERNSEC_TPE_GID
56428+ int "GID for untrusted users"
56429+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56430+ default 1005
56431+ help
56432+ Setting this GID determines what group TPE restrictions will be
56433+ *enabled* for. If the sysctl option is enabled, a sysctl option
56434+ with name "tpe_gid" is created.
56435+
56436+config GRKERNSEC_TPE_GID
56437+ int "GID for trusted users"
56438+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56439+ default 1005
56440+ help
56441+ Setting this GID determines what group TPE restrictions will be
56442+ *disabled* for. If the sysctl option is enabled, a sysctl option
56443+ with name "tpe_gid" is created.
56444+
56445+endmenu
56446+menu "Network Protections"
56447+depends on GRKERNSEC
56448+
56449+config GRKERNSEC_RANDNET
56450+ bool "Larger entropy pools"
56451+ help
56452+ If you say Y here, the entropy pools used for many features of Linux
56453+ and grsecurity will be doubled in size. Since several grsecurity
56454+ features use additional randomness, it is recommended that you say Y
56455+ here. Saying Y here has a similar effect as modifying
56456+ /proc/sys/kernel/random/poolsize.
56457+
56458+config GRKERNSEC_BLACKHOLE
56459+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56460+ help
56461+ If you say Y here, neither TCP resets nor ICMP
56462+ destination-unreachable packets will be sent in response to packets
56463+ sent to ports for which no associated listening process exists.
56464+ This feature supports both IPV4 and IPV6 and exempts the
56465+ loopback interface from blackholing. Enabling this feature
56466+ makes a host more resilient to DoS attacks and reduces network
56467+ visibility against scanners.
56468+
56469+ The blackhole feature as-implemented is equivalent to the FreeBSD
56470+ blackhole feature, as it prevents RST responses to all packets, not
56471+ just SYNs. Under most application behavior this causes no
56472+ problems, but applications (like haproxy) may not close certain
56473+ connections in a way that cleanly terminates them on the remote
56474+ end, leaving the remote host in LAST_ACK state. Because of this
56475+ side-effect and to prevent intentional LAST_ACK DoSes, this
56476+ feature also adds automatic mitigation against such attacks.
56477+ The mitigation drastically reduces the amount of time a socket
56478+ can spend in LAST_ACK state. If you're using haproxy and not
56479+ all servers it connects to have this option enabled, consider
56480+ disabling this feature on the haproxy host.
56481+
56482+ If the sysctl option is enabled, two sysctl options with names
56483+ "ip_blackhole" and "lastack_retries" will be created.
56484+ While "ip_blackhole" takes the standard zero/non-zero on/off
56485+ toggle, "lastack_retries" uses the same kinds of values as
56486+ "tcp_retries1" and "tcp_retries2". The default value of 4
56487+ prevents a socket from lasting more than 45 seconds in LAST_ACK
56488+ state.
56489+
56490+config GRKERNSEC_SOCKET
56491+ bool "Socket restrictions"
56492+ help
56493+ If you say Y here, you will be able to choose from several options.
56494+ If you assign a GID on your system and add it to the supplementary
56495+ groups of users you want to restrict socket access to, this patch
56496+ will perform up to three things, based on the option(s) you choose.
56497+
56498+config GRKERNSEC_SOCKET_ALL
56499+ bool "Deny any sockets to group"
56500+ depends on GRKERNSEC_SOCKET
56501+ help
56502+ If you say Y here, you will be able to choose a GID of whose users will
56503+ be unable to connect to other hosts from your machine or run server
56504+ applications from your machine. If the sysctl option is enabled, a
56505+ sysctl option with name "socket_all" is created.
56506+
56507+config GRKERNSEC_SOCKET_ALL_GID
56508+ int "GID to deny all sockets for"
56509+ depends on GRKERNSEC_SOCKET_ALL
56510+ default 1004
56511+ help
56512+ Here you can choose the GID to disable socket access for. Remember to
56513+ add the users you want socket access disabled for to the GID
56514+ specified here. If the sysctl option is enabled, a sysctl option
56515+ with name "socket_all_gid" is created.
56516+
56517+config GRKERNSEC_SOCKET_CLIENT
56518+ bool "Deny client sockets to group"
56519+ depends on GRKERNSEC_SOCKET
56520+ help
56521+ If you say Y here, you will be able to choose a GID of whose users will
56522+ be unable to connect to other hosts from your machine, but will be
56523+ able to run servers. If this option is enabled, all users in the group
56524+ you specify will have to use passive mode when initiating ftp transfers
56525+ from the shell on your machine. If the sysctl option is enabled, a
56526+ sysctl option with name "socket_client" is created.
56527+
56528+config GRKERNSEC_SOCKET_CLIENT_GID
56529+ int "GID to deny client sockets for"
56530+ depends on GRKERNSEC_SOCKET_CLIENT
56531+ default 1003
56532+ help
56533+ Here you can choose the GID to disable client socket access for.
56534+ Remember to add the users you want client socket access disabled for to
56535+ the GID specified here. If the sysctl option is enabled, a sysctl
56536+ option with name "socket_client_gid" is created.
56537+
56538+config GRKERNSEC_SOCKET_SERVER
56539+ bool "Deny server sockets to group"
56540+ depends on GRKERNSEC_SOCKET
56541+ help
56542+ If you say Y here, you will be able to choose a GID of whose users will
56543+ be unable to run server applications from your machine. If the sysctl
56544+ option is enabled, a sysctl option with name "socket_server" is created.
56545+
56546+config GRKERNSEC_SOCKET_SERVER_GID
56547+ int "GID to deny server sockets for"
56548+ depends on GRKERNSEC_SOCKET_SERVER
56549+ default 1002
56550+ help
56551+ Here you can choose the GID to disable server socket access for.
56552+ Remember to add the users you want server socket access disabled for to
56553+ the GID specified here. If the sysctl option is enabled, a sysctl
56554+ option with name "socket_server_gid" is created.
56555+
56556+endmenu
56557+menu "Sysctl support"
56558+depends on GRKERNSEC && SYSCTL
56559+
56560+config GRKERNSEC_SYSCTL
56561+ bool "Sysctl support"
56562+ help
56563+ If you say Y here, you will be able to change the options that
56564+ grsecurity runs with at bootup, without having to recompile your
56565+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56566+ to enable (1) or disable (0) various features. All the sysctl entries
56567+ are mutable until the "grsec_lock" entry is set to a non-zero value.
56568+ All features enabled in the kernel configuration are disabled at boot
56569+ if you do not say Y to the "Turn on features by default" option.
56570+ All options should be set at startup, and the grsec_lock entry should
56571+ be set to a non-zero value after all the options are set.
56572+ *THIS IS EXTREMELY IMPORTANT*
56573+
56574+config GRKERNSEC_SYSCTL_DISTRO
56575+ bool "Extra sysctl support for distro makers (READ HELP)"
56576+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56577+ help
56578+ If you say Y here, additional sysctl options will be created
56579+ for features that affect processes running as root. Therefore,
56580+ it is critical when using this option that the grsec_lock entry be
56581+ enabled after boot. Only distros with prebuilt kernel packages
56582+ with this option enabled that can ensure grsec_lock is enabled
56583+ after boot should use this option.
56584+ *Failure to set grsec_lock after boot makes all grsec features
56585+ this option covers useless*
56586+
56587+ Currently this option creates the following sysctl entries:
56588+ "Disable Privileged I/O": "disable_priv_io"
56589+
56590+config GRKERNSEC_SYSCTL_ON
56591+ bool "Turn on features by default"
56592+ depends on GRKERNSEC_SYSCTL
56593+ help
56594+ If you say Y here, instead of having all features enabled in the
56595+ kernel configuration disabled at boot time, the features will be
56596+ enabled at boot time. It is recommended you say Y here unless
56597+ there is some reason you would want all sysctl-tunable features to
56598+ be disabled by default. As mentioned elsewhere, it is important
56599+ to enable the grsec_lock entry once you have finished modifying
56600+ the sysctl entries.
56601+
56602+endmenu
56603+menu "Logging Options"
56604+depends on GRKERNSEC
56605+
56606+config GRKERNSEC_FLOODTIME
56607+ int "Seconds in between log messages (minimum)"
56608+ default 10
56609+ help
56610+ This option allows you to enforce the number of seconds between
56611+ grsecurity log messages. The default should be suitable for most
56612+ people, however, if you choose to change it, choose a value small enough
56613+ to allow informative logs to be produced, but large enough to
56614+ prevent flooding.
56615+
56616+config GRKERNSEC_FLOODBURST
56617+ int "Number of messages in a burst (maximum)"
56618+ default 4
56619+ help
56620+ This option allows you to choose the maximum number of messages allowed
56621+ within the flood time interval you chose in a separate option. The
56622+ default should be suitable for most people, however if you find that
56623+ many of your logs are being interpreted as flooding, you may want to
56624+ raise this value.
56625+
56626+endmenu
56627+
56628+endmenu
56629diff -urNp linux-2.6.32.43/grsecurity/Makefile linux-2.6.32.43/grsecurity/Makefile
56630--- linux-2.6.32.43/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
56631+++ linux-2.6.32.43/grsecurity/Makefile 2011-05-24 20:27:46.000000000 -0400
56632@@ -0,0 +1,33 @@
56633+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
56634+# during 2001-2009 it has been completely redesigned by Brad Spengler
56635+# into an RBAC system
56636+#
56637+# All code in this directory and various hooks inserted throughout the kernel
56638+# are copyright Brad Spengler - Open Source Security, Inc., and released
56639+# under the GPL v2 or higher
56640+
56641+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
56642+ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
56643+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
56644+
56645+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
56646+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
56647+ gracl_learn.o grsec_log.o
56648+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
56649+
56650+ifdef CONFIG_NET
56651+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
56652+endif
56653+
56654+ifndef CONFIG_GRKERNSEC
56655+obj-y += grsec_disabled.o
56656+endif
56657+
56658+ifdef CONFIG_GRKERNSEC_HIDESYM
56659+extra-y := grsec_hidesym.o
56660+$(obj)/grsec_hidesym.o:
56661+ @-chmod -f 500 /boot
56662+ @-chmod -f 500 /lib/modules
56663+ @-chmod -f 700 .
56664+ @echo ' grsec: protected kernel image paths'
56665+endif
56666diff -urNp linux-2.6.32.43/include/acpi/acpi_bus.h linux-2.6.32.43/include/acpi/acpi_bus.h
56667--- linux-2.6.32.43/include/acpi/acpi_bus.h 2011-03-27 14:31:47.000000000 -0400
56668+++ linux-2.6.32.43/include/acpi/acpi_bus.h 2011-08-05 20:33:55.000000000 -0400
56669@@ -107,7 +107,7 @@ struct acpi_device_ops {
56670 acpi_op_bind bind;
56671 acpi_op_unbind unbind;
56672 acpi_op_notify notify;
56673-};
56674+} __no_const;
56675
56676 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
56677
56678diff -urNp linux-2.6.32.43/include/acpi/acpi_drivers.h linux-2.6.32.43/include/acpi/acpi_drivers.h
56679--- linux-2.6.32.43/include/acpi/acpi_drivers.h 2011-03-27 14:31:47.000000000 -0400
56680+++ linux-2.6.32.43/include/acpi/acpi_drivers.h 2011-04-17 15:56:46.000000000 -0400
56681@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acp
56682 Dock Station
56683 -------------------------------------------------------------------------- */
56684 struct acpi_dock_ops {
56685- acpi_notify_handler handler;
56686- acpi_notify_handler uevent;
56687+ const acpi_notify_handler handler;
56688+ const acpi_notify_handler uevent;
56689 };
56690
56691 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
56692@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
56693 extern int register_dock_notifier(struct notifier_block *nb);
56694 extern void unregister_dock_notifier(struct notifier_block *nb);
56695 extern int register_hotplug_dock_device(acpi_handle handle,
56696- struct acpi_dock_ops *ops,
56697+ const struct acpi_dock_ops *ops,
56698 void *context);
56699 extern void unregister_hotplug_dock_device(acpi_handle handle);
56700 #else
56701@@ -144,7 +144,7 @@ static inline void unregister_dock_notif
56702 {
56703 }
56704 static inline int register_hotplug_dock_device(acpi_handle handle,
56705- struct acpi_dock_ops *ops,
56706+ const struct acpi_dock_ops *ops,
56707 void *context)
56708 {
56709 return -ENODEV;
56710diff -urNp linux-2.6.32.43/include/asm-generic/atomic-long.h linux-2.6.32.43/include/asm-generic/atomic-long.h
56711--- linux-2.6.32.43/include/asm-generic/atomic-long.h 2011-03-27 14:31:47.000000000 -0400
56712+++ linux-2.6.32.43/include/asm-generic/atomic-long.h 2011-07-13 22:21:25.000000000 -0400
56713@@ -22,6 +22,12 @@
56714
56715 typedef atomic64_t atomic_long_t;
56716
56717+#ifdef CONFIG_PAX_REFCOUNT
56718+typedef atomic64_unchecked_t atomic_long_unchecked_t;
56719+#else
56720+typedef atomic64_t atomic_long_unchecked_t;
56721+#endif
56722+
56723 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
56724
56725 static inline long atomic_long_read(atomic_long_t *l)
56726@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
56727 return (long)atomic64_read(v);
56728 }
56729
56730+#ifdef CONFIG_PAX_REFCOUNT
56731+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
56732+{
56733+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
56734+
56735+ return (long)atomic64_read_unchecked(v);
56736+}
56737+#endif
56738+
56739 static inline void atomic_long_set(atomic_long_t *l, long i)
56740 {
56741 atomic64_t *v = (atomic64_t *)l;
56742@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
56743 atomic64_set(v, i);
56744 }
56745
56746+#ifdef CONFIG_PAX_REFCOUNT
56747+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
56748+{
56749+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
56750+
56751+ atomic64_set_unchecked(v, i);
56752+}
56753+#endif
56754+
56755 static inline void atomic_long_inc(atomic_long_t *l)
56756 {
56757 atomic64_t *v = (atomic64_t *)l;
56758@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
56759 atomic64_inc(v);
56760 }
56761
56762+#ifdef CONFIG_PAX_REFCOUNT
56763+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
56764+{
56765+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
56766+
56767+ atomic64_inc_unchecked(v);
56768+}
56769+#endif
56770+
56771 static inline void atomic_long_dec(atomic_long_t *l)
56772 {
56773 atomic64_t *v = (atomic64_t *)l;
56774@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
56775 atomic64_dec(v);
56776 }
56777
56778+#ifdef CONFIG_PAX_REFCOUNT
56779+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
56780+{
56781+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
56782+
56783+ atomic64_dec_unchecked(v);
56784+}
56785+#endif
56786+
56787 static inline void atomic_long_add(long i, atomic_long_t *l)
56788 {
56789 atomic64_t *v = (atomic64_t *)l;
56790@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
56791 atomic64_add(i, v);
56792 }
56793
56794+#ifdef CONFIG_PAX_REFCOUNT
56795+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
56796+{
56797+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
56798+
56799+ atomic64_add_unchecked(i, v);
56800+}
56801+#endif
56802+
56803 static inline void atomic_long_sub(long i, atomic_long_t *l)
56804 {
56805 atomic64_t *v = (atomic64_t *)l;
56806@@ -115,6 +166,15 @@ static inline long atomic_long_inc_retur
56807 return (long)atomic64_inc_return(v);
56808 }
56809
56810+#ifdef CONFIG_PAX_REFCOUNT
56811+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
56812+{
56813+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
56814+
56815+ return (long)atomic64_inc_return_unchecked(v);
56816+}
56817+#endif
56818+
56819 static inline long atomic_long_dec_return(atomic_long_t *l)
56820 {
56821 atomic64_t *v = (atomic64_t *)l;
56822@@ -140,6 +200,12 @@ static inline long atomic_long_add_unles
56823
56824 typedef atomic_t atomic_long_t;
56825
56826+#ifdef CONFIG_PAX_REFCOUNT
56827+typedef atomic_unchecked_t atomic_long_unchecked_t;
56828+#else
56829+typedef atomic_t atomic_long_unchecked_t;
56830+#endif
56831+
56832 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
56833 static inline long atomic_long_read(atomic_long_t *l)
56834 {
56835@@ -148,6 +214,15 @@ static inline long atomic_long_read(atom
56836 return (long)atomic_read(v);
56837 }
56838
56839+#ifdef CONFIG_PAX_REFCOUNT
56840+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
56841+{
56842+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
56843+
56844+ return (long)atomic_read_unchecked(v);
56845+}
56846+#endif
56847+
56848 static inline void atomic_long_set(atomic_long_t *l, long i)
56849 {
56850 atomic_t *v = (atomic_t *)l;
56851@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomi
56852 atomic_set(v, i);
56853 }
56854
56855+#ifdef CONFIG_PAX_REFCOUNT
56856+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
56857+{
56858+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
56859+
56860+ atomic_set_unchecked(v, i);
56861+}
56862+#endif
56863+
56864 static inline void atomic_long_inc(atomic_long_t *l)
56865 {
56866 atomic_t *v = (atomic_t *)l;
56867@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomi
56868 atomic_inc(v);
56869 }
56870
56871+#ifdef CONFIG_PAX_REFCOUNT
56872+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
56873+{
56874+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
56875+
56876+ atomic_inc_unchecked(v);
56877+}
56878+#endif
56879+
56880 static inline void atomic_long_dec(atomic_long_t *l)
56881 {
56882 atomic_t *v = (atomic_t *)l;
56883@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomi
56884 atomic_dec(v);
56885 }
56886
56887+#ifdef CONFIG_PAX_REFCOUNT
56888+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
56889+{
56890+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
56891+
56892+ atomic_dec_unchecked(v);
56893+}
56894+#endif
56895+
56896 static inline void atomic_long_add(long i, atomic_long_t *l)
56897 {
56898 atomic_t *v = (atomic_t *)l;
56899@@ -176,6 +278,15 @@ static inline void atomic_long_add(long
56900 atomic_add(i, v);
56901 }
56902
56903+#ifdef CONFIG_PAX_REFCOUNT
56904+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
56905+{
56906+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
56907+
56908+ atomic_add_unchecked(i, v);
56909+}
56910+#endif
56911+
56912 static inline void atomic_long_sub(long i, atomic_long_t *l)
56913 {
56914 atomic_t *v = (atomic_t *)l;
56915@@ -232,6 +343,15 @@ static inline long atomic_long_inc_retur
56916 return (long)atomic_inc_return(v);
56917 }
56918
56919+#ifdef CONFIG_PAX_REFCOUNT
56920+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
56921+{
56922+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
56923+
56924+ return (long)atomic_inc_return_unchecked(v);
56925+}
56926+#endif
56927+
56928 static inline long atomic_long_dec_return(atomic_long_t *l)
56929 {
56930 atomic_t *v = (atomic_t *)l;
56931@@ -255,4 +375,47 @@ static inline long atomic_long_add_unles
56932
56933 #endif /* BITS_PER_LONG == 64 */
56934
56935+#ifdef CONFIG_PAX_REFCOUNT
56936+static inline void pax_refcount_needs_these_functions(void)
56937+{
56938+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
56939+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
56940+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
56941+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
56942+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
56943+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
56944+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
56945+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
56946+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
56947+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
56948+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
56949+
56950+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
56951+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
56952+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
56953+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
56954+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
56955+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
56956+}
56957+#else
56958+#define atomic_read_unchecked(v) atomic_read(v)
56959+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
56960+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
56961+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
56962+#define atomic_inc_unchecked(v) atomic_inc(v)
56963+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
56964+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
56965+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
56966+#define atomic_dec_unchecked(v) atomic_dec(v)
56967+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
56968+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
56969+
56970+#define atomic_long_read_unchecked(v) atomic_long_read(v)
56971+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
56972+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
56973+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
56974+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
56975+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
56976+#endif
56977+
56978 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
56979diff -urNp linux-2.6.32.43/include/asm-generic/cache.h linux-2.6.32.43/include/asm-generic/cache.h
56980--- linux-2.6.32.43/include/asm-generic/cache.h 2011-03-27 14:31:47.000000000 -0400
56981+++ linux-2.6.32.43/include/asm-generic/cache.h 2011-07-06 19:53:33.000000000 -0400
56982@@ -6,7 +6,7 @@
56983 * cache lines need to provide their own cache.h.
56984 */
56985
56986-#define L1_CACHE_SHIFT 5
56987-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
56988+#define L1_CACHE_SHIFT 5UL
56989+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
56990
56991 #endif /* __ASM_GENERIC_CACHE_H */
56992diff -urNp linux-2.6.32.43/include/asm-generic/dma-mapping-common.h linux-2.6.32.43/include/asm-generic/dma-mapping-common.h
56993--- linux-2.6.32.43/include/asm-generic/dma-mapping-common.h 2011-03-27 14:31:47.000000000 -0400
56994+++ linux-2.6.32.43/include/asm-generic/dma-mapping-common.h 2011-04-17 15:56:46.000000000 -0400
56995@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
56996 enum dma_data_direction dir,
56997 struct dma_attrs *attrs)
56998 {
56999- struct dma_map_ops *ops = get_dma_ops(dev);
57000+ const struct dma_map_ops *ops = get_dma_ops(dev);
57001 dma_addr_t addr;
57002
57003 kmemcheck_mark_initialized(ptr, size);
57004@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
57005 enum dma_data_direction dir,
57006 struct dma_attrs *attrs)
57007 {
57008- struct dma_map_ops *ops = get_dma_ops(dev);
57009+ const struct dma_map_ops *ops = get_dma_ops(dev);
57010
57011 BUG_ON(!valid_dma_direction(dir));
57012 if (ops->unmap_page)
57013@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
57014 int nents, enum dma_data_direction dir,
57015 struct dma_attrs *attrs)
57016 {
57017- struct dma_map_ops *ops = get_dma_ops(dev);
57018+ const struct dma_map_ops *ops = get_dma_ops(dev);
57019 int i, ents;
57020 struct scatterlist *s;
57021
57022@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
57023 int nents, enum dma_data_direction dir,
57024 struct dma_attrs *attrs)
57025 {
57026- struct dma_map_ops *ops = get_dma_ops(dev);
57027+ const struct dma_map_ops *ops = get_dma_ops(dev);
57028
57029 BUG_ON(!valid_dma_direction(dir));
57030 debug_dma_unmap_sg(dev, sg, nents, dir);
57031@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
57032 size_t offset, size_t size,
57033 enum dma_data_direction dir)
57034 {
57035- struct dma_map_ops *ops = get_dma_ops(dev);
57036+ const struct dma_map_ops *ops = get_dma_ops(dev);
57037 dma_addr_t addr;
57038
57039 kmemcheck_mark_initialized(page_address(page) + offset, size);
57040@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
57041 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
57042 size_t size, enum dma_data_direction dir)
57043 {
57044- struct dma_map_ops *ops = get_dma_ops(dev);
57045+ const struct dma_map_ops *ops = get_dma_ops(dev);
57046
57047 BUG_ON(!valid_dma_direction(dir));
57048 if (ops->unmap_page)
57049@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
57050 size_t size,
57051 enum dma_data_direction dir)
57052 {
57053- struct dma_map_ops *ops = get_dma_ops(dev);
57054+ const struct dma_map_ops *ops = get_dma_ops(dev);
57055
57056 BUG_ON(!valid_dma_direction(dir));
57057 if (ops->sync_single_for_cpu)
57058@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
57059 dma_addr_t addr, size_t size,
57060 enum dma_data_direction dir)
57061 {
57062- struct dma_map_ops *ops = get_dma_ops(dev);
57063+ const struct dma_map_ops *ops = get_dma_ops(dev);
57064
57065 BUG_ON(!valid_dma_direction(dir));
57066 if (ops->sync_single_for_device)
57067@@ -123,7 +123,7 @@ static inline void dma_sync_single_range
57068 size_t size,
57069 enum dma_data_direction dir)
57070 {
57071- struct dma_map_ops *ops = get_dma_ops(dev);
57072+ const struct dma_map_ops *ops = get_dma_ops(dev);
57073
57074 BUG_ON(!valid_dma_direction(dir));
57075 if (ops->sync_single_range_for_cpu) {
57076@@ -140,7 +140,7 @@ static inline void dma_sync_single_range
57077 size_t size,
57078 enum dma_data_direction dir)
57079 {
57080- struct dma_map_ops *ops = get_dma_ops(dev);
57081+ const struct dma_map_ops *ops = get_dma_ops(dev);
57082
57083 BUG_ON(!valid_dma_direction(dir));
57084 if (ops->sync_single_range_for_device) {
57085@@ -155,7 +155,7 @@ static inline void
57086 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
57087 int nelems, enum dma_data_direction dir)
57088 {
57089- struct dma_map_ops *ops = get_dma_ops(dev);
57090+ const struct dma_map_ops *ops = get_dma_ops(dev);
57091
57092 BUG_ON(!valid_dma_direction(dir));
57093 if (ops->sync_sg_for_cpu)
57094@@ -167,7 +167,7 @@ static inline void
57095 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
57096 int nelems, enum dma_data_direction dir)
57097 {
57098- struct dma_map_ops *ops = get_dma_ops(dev);
57099+ const struct dma_map_ops *ops = get_dma_ops(dev);
57100
57101 BUG_ON(!valid_dma_direction(dir));
57102 if (ops->sync_sg_for_device)
57103diff -urNp linux-2.6.32.43/include/asm-generic/futex.h linux-2.6.32.43/include/asm-generic/futex.h
57104--- linux-2.6.32.43/include/asm-generic/futex.h 2011-03-27 14:31:47.000000000 -0400
57105+++ linux-2.6.32.43/include/asm-generic/futex.h 2011-04-17 15:56:46.000000000 -0400
57106@@ -6,7 +6,7 @@
57107 #include <asm/errno.h>
57108
57109 static inline int
57110-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
57111+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
57112 {
57113 int op = (encoded_op >> 28) & 7;
57114 int cmp = (encoded_op >> 24) & 15;
57115@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
57116 }
57117
57118 static inline int
57119-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
57120+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
57121 {
57122 return -ENOSYS;
57123 }
57124diff -urNp linux-2.6.32.43/include/asm-generic/int-l64.h linux-2.6.32.43/include/asm-generic/int-l64.h
57125--- linux-2.6.32.43/include/asm-generic/int-l64.h 2011-03-27 14:31:47.000000000 -0400
57126+++ linux-2.6.32.43/include/asm-generic/int-l64.h 2011-04-17 15:56:46.000000000 -0400
57127@@ -46,6 +46,8 @@ typedef unsigned int u32;
57128 typedef signed long s64;
57129 typedef unsigned long u64;
57130
57131+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
57132+
57133 #define S8_C(x) x
57134 #define U8_C(x) x ## U
57135 #define S16_C(x) x
57136diff -urNp linux-2.6.32.43/include/asm-generic/int-ll64.h linux-2.6.32.43/include/asm-generic/int-ll64.h
57137--- linux-2.6.32.43/include/asm-generic/int-ll64.h 2011-03-27 14:31:47.000000000 -0400
57138+++ linux-2.6.32.43/include/asm-generic/int-ll64.h 2011-04-17 15:56:46.000000000 -0400
57139@@ -51,6 +51,8 @@ typedef unsigned int u32;
57140 typedef signed long long s64;
57141 typedef unsigned long long u64;
57142
57143+typedef unsigned long long intoverflow_t;
57144+
57145 #define S8_C(x) x
57146 #define U8_C(x) x ## U
57147 #define S16_C(x) x
57148diff -urNp linux-2.6.32.43/include/asm-generic/kmap_types.h linux-2.6.32.43/include/asm-generic/kmap_types.h
57149--- linux-2.6.32.43/include/asm-generic/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
57150+++ linux-2.6.32.43/include/asm-generic/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
57151@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
57152 KMAP_D(16) KM_IRQ_PTE,
57153 KMAP_D(17) KM_NMI,
57154 KMAP_D(18) KM_NMI_PTE,
57155-KMAP_D(19) KM_TYPE_NR
57156+KMAP_D(19) KM_CLEARPAGE,
57157+KMAP_D(20) KM_TYPE_NR
57158 };
57159
57160 #undef KMAP_D
57161diff -urNp linux-2.6.32.43/include/asm-generic/pgtable.h linux-2.6.32.43/include/asm-generic/pgtable.h
57162--- linux-2.6.32.43/include/asm-generic/pgtable.h 2011-03-27 14:31:47.000000000 -0400
57163+++ linux-2.6.32.43/include/asm-generic/pgtable.h 2011-04-17 15:56:46.000000000 -0400
57164@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_ar
57165 unsigned long size);
57166 #endif
57167
57168+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
57169+static inline unsigned long pax_open_kernel(void) { return 0; }
57170+#endif
57171+
57172+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
57173+static inline unsigned long pax_close_kernel(void) { return 0; }
57174+#endif
57175+
57176 #endif /* !__ASSEMBLY__ */
57177
57178 #endif /* _ASM_GENERIC_PGTABLE_H */
57179diff -urNp linux-2.6.32.43/include/asm-generic/pgtable-nopmd.h linux-2.6.32.43/include/asm-generic/pgtable-nopmd.h
57180--- linux-2.6.32.43/include/asm-generic/pgtable-nopmd.h 2011-03-27 14:31:47.000000000 -0400
57181+++ linux-2.6.32.43/include/asm-generic/pgtable-nopmd.h 2011-04-17 15:56:46.000000000 -0400
57182@@ -1,14 +1,19 @@
57183 #ifndef _PGTABLE_NOPMD_H
57184 #define _PGTABLE_NOPMD_H
57185
57186-#ifndef __ASSEMBLY__
57187-
57188 #include <asm-generic/pgtable-nopud.h>
57189
57190-struct mm_struct;
57191-
57192 #define __PAGETABLE_PMD_FOLDED
57193
57194+#define PMD_SHIFT PUD_SHIFT
57195+#define PTRS_PER_PMD 1
57196+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
57197+#define PMD_MASK (~(PMD_SIZE-1))
57198+
57199+#ifndef __ASSEMBLY__
57200+
57201+struct mm_struct;
57202+
57203 /*
57204 * Having the pmd type consist of a pud gets the size right, and allows
57205 * us to conceptually access the pud entry that this pmd is folded into
57206@@ -16,11 +21,6 @@ struct mm_struct;
57207 */
57208 typedef struct { pud_t pud; } pmd_t;
57209
57210-#define PMD_SHIFT PUD_SHIFT
57211-#define PTRS_PER_PMD 1
57212-#define PMD_SIZE (1UL << PMD_SHIFT)
57213-#define PMD_MASK (~(PMD_SIZE-1))
57214-
57215 /*
57216 * The "pud_xxx()" functions here are trivial for a folded two-level
57217 * setup: the pmd is never bad, and a pmd always exists (as it's folded
57218diff -urNp linux-2.6.32.43/include/asm-generic/pgtable-nopud.h linux-2.6.32.43/include/asm-generic/pgtable-nopud.h
57219--- linux-2.6.32.43/include/asm-generic/pgtable-nopud.h 2011-03-27 14:31:47.000000000 -0400
57220+++ linux-2.6.32.43/include/asm-generic/pgtable-nopud.h 2011-04-17 15:56:46.000000000 -0400
57221@@ -1,10 +1,15 @@
57222 #ifndef _PGTABLE_NOPUD_H
57223 #define _PGTABLE_NOPUD_H
57224
57225-#ifndef __ASSEMBLY__
57226-
57227 #define __PAGETABLE_PUD_FOLDED
57228
57229+#define PUD_SHIFT PGDIR_SHIFT
57230+#define PTRS_PER_PUD 1
57231+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
57232+#define PUD_MASK (~(PUD_SIZE-1))
57233+
57234+#ifndef __ASSEMBLY__
57235+
57236 /*
57237 * Having the pud type consist of a pgd gets the size right, and allows
57238 * us to conceptually access the pgd entry that this pud is folded into
57239@@ -12,11 +17,6 @@
57240 */
57241 typedef struct { pgd_t pgd; } pud_t;
57242
57243-#define PUD_SHIFT PGDIR_SHIFT
57244-#define PTRS_PER_PUD 1
57245-#define PUD_SIZE (1UL << PUD_SHIFT)
57246-#define PUD_MASK (~(PUD_SIZE-1))
57247-
57248 /*
57249 * The "pgd_xxx()" functions here are trivial for a folded two-level
57250 * setup: the pud is never bad, and a pud always exists (as it's folded
57251diff -urNp linux-2.6.32.43/include/asm-generic/vmlinux.lds.h linux-2.6.32.43/include/asm-generic/vmlinux.lds.h
57252--- linux-2.6.32.43/include/asm-generic/vmlinux.lds.h 2011-03-27 14:31:47.000000000 -0400
57253+++ linux-2.6.32.43/include/asm-generic/vmlinux.lds.h 2011-04-17 15:56:46.000000000 -0400
57254@@ -199,6 +199,7 @@
57255 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
57256 VMLINUX_SYMBOL(__start_rodata) = .; \
57257 *(.rodata) *(.rodata.*) \
57258+ *(.data.read_only) \
57259 *(__vermagic) /* Kernel version magic */ \
57260 *(__markers_strings) /* Markers: strings */ \
57261 *(__tracepoints_strings)/* Tracepoints: strings */ \
57262@@ -656,22 +657,24 @@
57263 * section in the linker script will go there too. @phdr should have
57264 * a leading colon.
57265 *
57266- * Note that this macros defines __per_cpu_load as an absolute symbol.
57267+ * Note that this macros defines per_cpu_load as an absolute symbol.
57268 * If there is no need to put the percpu section at a predetermined
57269 * address, use PERCPU().
57270 */
57271 #define PERCPU_VADDR(vaddr, phdr) \
57272- VMLINUX_SYMBOL(__per_cpu_load) = .; \
57273- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
57274+ per_cpu_load = .; \
57275+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
57276 - LOAD_OFFSET) { \
57277+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
57278 VMLINUX_SYMBOL(__per_cpu_start) = .; \
57279 *(.data.percpu.first) \
57280- *(.data.percpu.page_aligned) \
57281 *(.data.percpu) \
57282+ . = ALIGN(PAGE_SIZE); \
57283+ *(.data.percpu.page_aligned) \
57284 *(.data.percpu.shared_aligned) \
57285 VMLINUX_SYMBOL(__per_cpu_end) = .; \
57286 } phdr \
57287- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
57288+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
57289
57290 /**
57291 * PERCPU - define output section for percpu area, simple version
57292diff -urNp linux-2.6.32.43/include/drm/drm_crtc_helper.h linux-2.6.32.43/include/drm/drm_crtc_helper.h
57293--- linux-2.6.32.43/include/drm/drm_crtc_helper.h 2011-03-27 14:31:47.000000000 -0400
57294+++ linux-2.6.32.43/include/drm/drm_crtc_helper.h 2011-08-05 20:33:55.000000000 -0400
57295@@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
57296
57297 /* reload the current crtc LUT */
57298 void (*load_lut)(struct drm_crtc *crtc);
57299-};
57300+} __no_const;
57301
57302 struct drm_encoder_helper_funcs {
57303 void (*dpms)(struct drm_encoder *encoder, int mode);
57304@@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
57305 struct drm_connector *connector);
57306 /* disable encoder when not in use - more explicit than dpms off */
57307 void (*disable)(struct drm_encoder *encoder);
57308-};
57309+} __no_const;
57310
57311 struct drm_connector_helper_funcs {
57312 int (*get_modes)(struct drm_connector *connector);
57313diff -urNp linux-2.6.32.43/include/drm/drmP.h linux-2.6.32.43/include/drm/drmP.h
57314--- linux-2.6.32.43/include/drm/drmP.h 2011-03-27 14:31:47.000000000 -0400
57315+++ linux-2.6.32.43/include/drm/drmP.h 2011-04-17 15:56:46.000000000 -0400
57316@@ -71,6 +71,7 @@
57317 #include <linux/workqueue.h>
57318 #include <linux/poll.h>
57319 #include <asm/pgalloc.h>
57320+#include <asm/local.h>
57321 #include "drm.h"
57322
57323 #include <linux/idr.h>
57324@@ -814,7 +815,7 @@ struct drm_driver {
57325 void (*vgaarb_irq)(struct drm_device *dev, bool state);
57326
57327 /* Driver private ops for this object */
57328- struct vm_operations_struct *gem_vm_ops;
57329+ const struct vm_operations_struct *gem_vm_ops;
57330
57331 int major;
57332 int minor;
57333@@ -917,7 +918,7 @@ struct drm_device {
57334
57335 /** \name Usage Counters */
57336 /*@{ */
57337- int open_count; /**< Outstanding files open */
57338+ local_t open_count; /**< Outstanding files open */
57339 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
57340 atomic_t vma_count; /**< Outstanding vma areas open */
57341 int buf_use; /**< Buffers in use -- cannot alloc */
57342@@ -928,7 +929,7 @@ struct drm_device {
57343 /*@{ */
57344 unsigned long counters;
57345 enum drm_stat_type types[15];
57346- atomic_t counts[15];
57347+ atomic_unchecked_t counts[15];
57348 /*@} */
57349
57350 struct list_head filelist;
57351@@ -1016,7 +1017,7 @@ struct drm_device {
57352 struct pci_controller *hose;
57353 #endif
57354 struct drm_sg_mem *sg; /**< Scatter gather memory */
57355- unsigned int num_crtcs; /**< Number of CRTCs on this device */
57356+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
57357 void *dev_private; /**< device private data */
57358 void *mm_private;
57359 struct address_space *dev_mapping;
57360@@ -1042,11 +1043,11 @@ struct drm_device {
57361 spinlock_t object_name_lock;
57362 struct idr object_name_idr;
57363 atomic_t object_count;
57364- atomic_t object_memory;
57365+ atomic_unchecked_t object_memory;
57366 atomic_t pin_count;
57367- atomic_t pin_memory;
57368+ atomic_unchecked_t pin_memory;
57369 atomic_t gtt_count;
57370- atomic_t gtt_memory;
57371+ atomic_unchecked_t gtt_memory;
57372 uint32_t gtt_total;
57373 uint32_t invalidate_domains; /* domains pending invalidation */
57374 uint32_t flush_domains; /* domains pending flush */
57375diff -urNp linux-2.6.32.43/include/drm/ttm/ttm_memory.h linux-2.6.32.43/include/drm/ttm/ttm_memory.h
57376--- linux-2.6.32.43/include/drm/ttm/ttm_memory.h 2011-03-27 14:31:47.000000000 -0400
57377+++ linux-2.6.32.43/include/drm/ttm/ttm_memory.h 2011-08-05 20:33:55.000000000 -0400
57378@@ -47,7 +47,7 @@
57379
57380 struct ttm_mem_shrink {
57381 int (*do_shrink) (struct ttm_mem_shrink *);
57382-};
57383+} __no_const;
57384
57385 /**
57386 * struct ttm_mem_global - Global memory accounting structure.
57387diff -urNp linux-2.6.32.43/include/linux/a.out.h linux-2.6.32.43/include/linux/a.out.h
57388--- linux-2.6.32.43/include/linux/a.out.h 2011-03-27 14:31:47.000000000 -0400
57389+++ linux-2.6.32.43/include/linux/a.out.h 2011-04-17 15:56:46.000000000 -0400
57390@@ -39,6 +39,14 @@ enum machine_type {
57391 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
57392 };
57393
57394+/* Constants for the N_FLAGS field */
57395+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57396+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
57397+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
57398+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
57399+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57400+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57401+
57402 #if !defined (N_MAGIC)
57403 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
57404 #endif
57405diff -urNp linux-2.6.32.43/include/linux/atmdev.h linux-2.6.32.43/include/linux/atmdev.h
57406--- linux-2.6.32.43/include/linux/atmdev.h 2011-03-27 14:31:47.000000000 -0400
57407+++ linux-2.6.32.43/include/linux/atmdev.h 2011-04-17 15:56:46.000000000 -0400
57408@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
57409 #endif
57410
57411 struct k_atm_aal_stats {
57412-#define __HANDLE_ITEM(i) atomic_t i
57413+#define __HANDLE_ITEM(i) atomic_unchecked_t i
57414 __AAL_STAT_ITEMS
57415 #undef __HANDLE_ITEM
57416 };
57417diff -urNp linux-2.6.32.43/include/linux/backlight.h linux-2.6.32.43/include/linux/backlight.h
57418--- linux-2.6.32.43/include/linux/backlight.h 2011-03-27 14:31:47.000000000 -0400
57419+++ linux-2.6.32.43/include/linux/backlight.h 2011-04-17 15:56:46.000000000 -0400
57420@@ -36,18 +36,18 @@ struct backlight_device;
57421 struct fb_info;
57422
57423 struct backlight_ops {
57424- unsigned int options;
57425+ const unsigned int options;
57426
57427 #define BL_CORE_SUSPENDRESUME (1 << 0)
57428
57429 /* Notify the backlight driver some property has changed */
57430- int (*update_status)(struct backlight_device *);
57431+ int (* const update_status)(struct backlight_device *);
57432 /* Return the current backlight brightness (accounting for power,
57433 fb_blank etc.) */
57434- int (*get_brightness)(struct backlight_device *);
57435+ int (* const get_brightness)(struct backlight_device *);
57436 /* Check if given framebuffer device is the one bound to this backlight;
57437 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
57438- int (*check_fb)(struct fb_info *);
57439+ int (* const check_fb)(struct fb_info *);
57440 };
57441
57442 /* This structure defines all the properties of a backlight */
57443@@ -86,7 +86,7 @@ struct backlight_device {
57444 registered this device has been unloaded, and if class_get_devdata()
57445 points to something in the body of that driver, it is also invalid. */
57446 struct mutex ops_lock;
57447- struct backlight_ops *ops;
57448+ const struct backlight_ops *ops;
57449
57450 /* The framebuffer notifier block */
57451 struct notifier_block fb_notif;
57452@@ -103,7 +103,7 @@ static inline void backlight_update_stat
57453 }
57454
57455 extern struct backlight_device *backlight_device_register(const char *name,
57456- struct device *dev, void *devdata, struct backlight_ops *ops);
57457+ struct device *dev, void *devdata, const struct backlight_ops *ops);
57458 extern void backlight_device_unregister(struct backlight_device *bd);
57459 extern void backlight_force_update(struct backlight_device *bd,
57460 enum backlight_update_reason reason);
57461diff -urNp linux-2.6.32.43/include/linux/binfmts.h linux-2.6.32.43/include/linux/binfmts.h
57462--- linux-2.6.32.43/include/linux/binfmts.h 2011-04-17 17:00:52.000000000 -0400
57463+++ linux-2.6.32.43/include/linux/binfmts.h 2011-04-17 15:56:46.000000000 -0400
57464@@ -83,6 +83,7 @@ struct linux_binfmt {
57465 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
57466 int (*load_shlib)(struct file *);
57467 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
57468+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
57469 unsigned long min_coredump; /* minimal dump size */
57470 int hasvdso;
57471 };
57472diff -urNp linux-2.6.32.43/include/linux/blkdev.h linux-2.6.32.43/include/linux/blkdev.h
57473--- linux-2.6.32.43/include/linux/blkdev.h 2011-03-27 14:31:47.000000000 -0400
57474+++ linux-2.6.32.43/include/linux/blkdev.h 2011-04-17 15:56:46.000000000 -0400
57475@@ -1265,19 +1265,19 @@ static inline int blk_integrity_rq(struc
57476 #endif /* CONFIG_BLK_DEV_INTEGRITY */
57477
57478 struct block_device_operations {
57479- int (*open) (struct block_device *, fmode_t);
57480- int (*release) (struct gendisk *, fmode_t);
57481- int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57482- int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57483- int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57484- int (*direct_access) (struct block_device *, sector_t,
57485+ int (* const open) (struct block_device *, fmode_t);
57486+ int (* const release) (struct gendisk *, fmode_t);
57487+ int (* const locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57488+ int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57489+ int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
57490+ int (* const direct_access) (struct block_device *, sector_t,
57491 void **, unsigned long *);
57492- int (*media_changed) (struct gendisk *);
57493- unsigned long long (*set_capacity) (struct gendisk *,
57494+ int (* const media_changed) (struct gendisk *);
57495+ unsigned long long (* const set_capacity) (struct gendisk *,
57496 unsigned long long);
57497- int (*revalidate_disk) (struct gendisk *);
57498- int (*getgeo)(struct block_device *, struct hd_geometry *);
57499- struct module *owner;
57500+ int (* const revalidate_disk) (struct gendisk *);
57501+ int (*const getgeo)(struct block_device *, struct hd_geometry *);
57502+ struct module * const owner;
57503 };
57504
57505 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
57506diff -urNp linux-2.6.32.43/include/linux/blktrace_api.h linux-2.6.32.43/include/linux/blktrace_api.h
57507--- linux-2.6.32.43/include/linux/blktrace_api.h 2011-03-27 14:31:47.000000000 -0400
57508+++ linux-2.6.32.43/include/linux/blktrace_api.h 2011-05-04 17:56:28.000000000 -0400
57509@@ -160,7 +160,7 @@ struct blk_trace {
57510 struct dentry *dir;
57511 struct dentry *dropped_file;
57512 struct dentry *msg_file;
57513- atomic_t dropped;
57514+ atomic_unchecked_t dropped;
57515 };
57516
57517 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
57518diff -urNp linux-2.6.32.43/include/linux/byteorder/little_endian.h linux-2.6.32.43/include/linux/byteorder/little_endian.h
57519--- linux-2.6.32.43/include/linux/byteorder/little_endian.h 2011-03-27 14:31:47.000000000 -0400
57520+++ linux-2.6.32.43/include/linux/byteorder/little_endian.h 2011-04-17 15:56:46.000000000 -0400
57521@@ -42,51 +42,51 @@
57522
57523 static inline __le64 __cpu_to_le64p(const __u64 *p)
57524 {
57525- return (__force __le64)*p;
57526+ return (__force const __le64)*p;
57527 }
57528 static inline __u64 __le64_to_cpup(const __le64 *p)
57529 {
57530- return (__force __u64)*p;
57531+ return (__force const __u64)*p;
57532 }
57533 static inline __le32 __cpu_to_le32p(const __u32 *p)
57534 {
57535- return (__force __le32)*p;
57536+ return (__force const __le32)*p;
57537 }
57538 static inline __u32 __le32_to_cpup(const __le32 *p)
57539 {
57540- return (__force __u32)*p;
57541+ return (__force const __u32)*p;
57542 }
57543 static inline __le16 __cpu_to_le16p(const __u16 *p)
57544 {
57545- return (__force __le16)*p;
57546+ return (__force const __le16)*p;
57547 }
57548 static inline __u16 __le16_to_cpup(const __le16 *p)
57549 {
57550- return (__force __u16)*p;
57551+ return (__force const __u16)*p;
57552 }
57553 static inline __be64 __cpu_to_be64p(const __u64 *p)
57554 {
57555- return (__force __be64)__swab64p(p);
57556+ return (__force const __be64)__swab64p(p);
57557 }
57558 static inline __u64 __be64_to_cpup(const __be64 *p)
57559 {
57560- return __swab64p((__u64 *)p);
57561+ return __swab64p((const __u64 *)p);
57562 }
57563 static inline __be32 __cpu_to_be32p(const __u32 *p)
57564 {
57565- return (__force __be32)__swab32p(p);
57566+ return (__force const __be32)__swab32p(p);
57567 }
57568 static inline __u32 __be32_to_cpup(const __be32 *p)
57569 {
57570- return __swab32p((__u32 *)p);
57571+ return __swab32p((const __u32 *)p);
57572 }
57573 static inline __be16 __cpu_to_be16p(const __u16 *p)
57574 {
57575- return (__force __be16)__swab16p(p);
57576+ return (__force const __be16)__swab16p(p);
57577 }
57578 static inline __u16 __be16_to_cpup(const __be16 *p)
57579 {
57580- return __swab16p((__u16 *)p);
57581+ return __swab16p((const __u16 *)p);
57582 }
57583 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
57584 #define __le64_to_cpus(x) do { (void)(x); } while (0)
57585diff -urNp linux-2.6.32.43/include/linux/cache.h linux-2.6.32.43/include/linux/cache.h
57586--- linux-2.6.32.43/include/linux/cache.h 2011-03-27 14:31:47.000000000 -0400
57587+++ linux-2.6.32.43/include/linux/cache.h 2011-04-17 15:56:46.000000000 -0400
57588@@ -16,6 +16,10 @@
57589 #define __read_mostly
57590 #endif
57591
57592+#ifndef __read_only
57593+#define __read_only __read_mostly
57594+#endif
57595+
57596 #ifndef ____cacheline_aligned
57597 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
57598 #endif
57599diff -urNp linux-2.6.32.43/include/linux/capability.h linux-2.6.32.43/include/linux/capability.h
57600--- linux-2.6.32.43/include/linux/capability.h 2011-03-27 14:31:47.000000000 -0400
57601+++ linux-2.6.32.43/include/linux/capability.h 2011-04-17 15:56:46.000000000 -0400
57602@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff
57603 (security_real_capable_noaudit((t), (cap)) == 0)
57604
57605 extern int capable(int cap);
57606+int capable_nolog(int cap);
57607
57608 /* audit system wants to get cap info from files as well */
57609 struct dentry;
57610diff -urNp linux-2.6.32.43/include/linux/compiler-gcc4.h linux-2.6.32.43/include/linux/compiler-gcc4.h
57611--- linux-2.6.32.43/include/linux/compiler-gcc4.h 2011-03-27 14:31:47.000000000 -0400
57612+++ linux-2.6.32.43/include/linux/compiler-gcc4.h 2011-08-05 20:33:55.000000000 -0400
57613@@ -36,4 +36,13 @@
57614 the kernel context */
57615 #define __cold __attribute__((__cold__))
57616
57617+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
57618+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
57619+#define __bos0(ptr) __bos((ptr), 0)
57620+#define __bos1(ptr) __bos((ptr), 1)
57621+
57622+#if __GNUC_MINOR__ >= 5
57623+#define __no_const __attribute__((no_const))
57624+#endif
57625+
57626 #endif
57627diff -urNp linux-2.6.32.43/include/linux/compiler.h linux-2.6.32.43/include/linux/compiler.h
57628--- linux-2.6.32.43/include/linux/compiler.h 2011-03-27 14:31:47.000000000 -0400
57629+++ linux-2.6.32.43/include/linux/compiler.h 2011-08-05 20:33:55.000000000 -0400
57630@@ -247,6 +247,10 @@ void ftrace_likely_update(struct ftrace_
57631 # define __attribute_const__ /* unimplemented */
57632 #endif
57633
57634+#ifndef __no_const
57635+# define __no_const
57636+#endif
57637+
57638 /*
57639 * Tell gcc if a function is cold. The compiler will assume any path
57640 * directly leading to the call is unlikely.
57641@@ -256,6 +260,22 @@ void ftrace_likely_update(struct ftrace_
57642 #define __cold
57643 #endif
57644
57645+#ifndef __alloc_size
57646+#define __alloc_size(...)
57647+#endif
57648+
57649+#ifndef __bos
57650+#define __bos(ptr, arg)
57651+#endif
57652+
57653+#ifndef __bos0
57654+#define __bos0(ptr)
57655+#endif
57656+
57657+#ifndef __bos1
57658+#define __bos1(ptr)
57659+#endif
57660+
57661 /* Simple shorthand for a section definition */
57662 #ifndef __section
57663 # define __section(S) __attribute__ ((__section__(#S)))
57664@@ -278,6 +298,7 @@ void ftrace_likely_update(struct ftrace_
57665 * use is to mediate communication between process-level code and irq/NMI
57666 * handlers, all running on the same CPU.
57667 */
57668-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
57669+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
57670+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
57671
57672 #endif /* __LINUX_COMPILER_H */
57673diff -urNp linux-2.6.32.43/include/linux/crypto.h linux-2.6.32.43/include/linux/crypto.h
57674--- linux-2.6.32.43/include/linux/crypto.h 2011-03-27 14:31:47.000000000 -0400
57675+++ linux-2.6.32.43/include/linux/crypto.h 2011-08-05 20:33:55.000000000 -0400
57676@@ -394,7 +394,7 @@ struct cipher_tfm {
57677 const u8 *key, unsigned int keylen);
57678 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
57679 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
57680-};
57681+} __no_const;
57682
57683 struct hash_tfm {
57684 int (*init)(struct hash_desc *desc);
57685@@ -415,13 +415,13 @@ struct compress_tfm {
57686 int (*cot_decompress)(struct crypto_tfm *tfm,
57687 const u8 *src, unsigned int slen,
57688 u8 *dst, unsigned int *dlen);
57689-};
57690+} __no_const;
57691
57692 struct rng_tfm {
57693 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
57694 unsigned int dlen);
57695 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
57696-};
57697+} __no_const;
57698
57699 #define crt_ablkcipher crt_u.ablkcipher
57700 #define crt_aead crt_u.aead
57701diff -urNp linux-2.6.32.43/include/linux/dcache.h linux-2.6.32.43/include/linux/dcache.h
57702--- linux-2.6.32.43/include/linux/dcache.h 2011-03-27 14:31:47.000000000 -0400
57703+++ linux-2.6.32.43/include/linux/dcache.h 2011-04-23 13:34:46.000000000 -0400
57704@@ -119,6 +119,8 @@ struct dentry {
57705 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
57706 };
57707
57708+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
57709+
57710 /*
57711 * dentry->d_lock spinlock nesting subclasses:
57712 *
57713diff -urNp linux-2.6.32.43/include/linux/decompress/mm.h linux-2.6.32.43/include/linux/decompress/mm.h
57714--- linux-2.6.32.43/include/linux/decompress/mm.h 2011-03-27 14:31:47.000000000 -0400
57715+++ linux-2.6.32.43/include/linux/decompress/mm.h 2011-04-17 15:56:46.000000000 -0400
57716@@ -78,7 +78,7 @@ static void free(void *where)
57717 * warnings when not needed (indeed large_malloc / large_free are not
57718 * needed by inflate */
57719
57720-#define malloc(a) kmalloc(a, GFP_KERNEL)
57721+#define malloc(a) kmalloc((a), GFP_KERNEL)
57722 #define free(a) kfree(a)
57723
57724 #define large_malloc(a) vmalloc(a)
57725diff -urNp linux-2.6.32.43/include/linux/dma-mapping.h linux-2.6.32.43/include/linux/dma-mapping.h
57726--- linux-2.6.32.43/include/linux/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
57727+++ linux-2.6.32.43/include/linux/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
57728@@ -16,50 +16,50 @@ enum dma_data_direction {
57729 };
57730
57731 struct dma_map_ops {
57732- void* (*alloc_coherent)(struct device *dev, size_t size,
57733+ void* (* const alloc_coherent)(struct device *dev, size_t size,
57734 dma_addr_t *dma_handle, gfp_t gfp);
57735- void (*free_coherent)(struct device *dev, size_t size,
57736+ void (* const free_coherent)(struct device *dev, size_t size,
57737 void *vaddr, dma_addr_t dma_handle);
57738- dma_addr_t (*map_page)(struct device *dev, struct page *page,
57739+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
57740 unsigned long offset, size_t size,
57741 enum dma_data_direction dir,
57742 struct dma_attrs *attrs);
57743- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
57744+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
57745 size_t size, enum dma_data_direction dir,
57746 struct dma_attrs *attrs);
57747- int (*map_sg)(struct device *dev, struct scatterlist *sg,
57748+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
57749 int nents, enum dma_data_direction dir,
57750 struct dma_attrs *attrs);
57751- void (*unmap_sg)(struct device *dev,
57752+ void (* const unmap_sg)(struct device *dev,
57753 struct scatterlist *sg, int nents,
57754 enum dma_data_direction dir,
57755 struct dma_attrs *attrs);
57756- void (*sync_single_for_cpu)(struct device *dev,
57757+ void (* const sync_single_for_cpu)(struct device *dev,
57758 dma_addr_t dma_handle, size_t size,
57759 enum dma_data_direction dir);
57760- void (*sync_single_for_device)(struct device *dev,
57761+ void (* const sync_single_for_device)(struct device *dev,
57762 dma_addr_t dma_handle, size_t size,
57763 enum dma_data_direction dir);
57764- void (*sync_single_range_for_cpu)(struct device *dev,
57765+ void (* const sync_single_range_for_cpu)(struct device *dev,
57766 dma_addr_t dma_handle,
57767 unsigned long offset,
57768 size_t size,
57769 enum dma_data_direction dir);
57770- void (*sync_single_range_for_device)(struct device *dev,
57771+ void (* const sync_single_range_for_device)(struct device *dev,
57772 dma_addr_t dma_handle,
57773 unsigned long offset,
57774 size_t size,
57775 enum dma_data_direction dir);
57776- void (*sync_sg_for_cpu)(struct device *dev,
57777+ void (* const sync_sg_for_cpu)(struct device *dev,
57778 struct scatterlist *sg, int nents,
57779 enum dma_data_direction dir);
57780- void (*sync_sg_for_device)(struct device *dev,
57781+ void (* const sync_sg_for_device)(struct device *dev,
57782 struct scatterlist *sg, int nents,
57783 enum dma_data_direction dir);
57784- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
57785- int (*dma_supported)(struct device *dev, u64 mask);
57786+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
57787+ int (* const dma_supported)(struct device *dev, u64 mask);
57788 int (*set_dma_mask)(struct device *dev, u64 mask);
57789- int is_phys;
57790+ const int is_phys;
57791 };
57792
57793 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
57794diff -urNp linux-2.6.32.43/include/linux/dst.h linux-2.6.32.43/include/linux/dst.h
57795--- linux-2.6.32.43/include/linux/dst.h 2011-03-27 14:31:47.000000000 -0400
57796+++ linux-2.6.32.43/include/linux/dst.h 2011-04-17 15:56:46.000000000 -0400
57797@@ -380,7 +380,7 @@ struct dst_node
57798 struct thread_pool *pool;
57799
57800 /* Transaction IDs live here */
57801- atomic_long_t gen;
57802+ atomic_long_unchecked_t gen;
57803
57804 /*
57805 * How frequently and how many times transaction
57806diff -urNp linux-2.6.32.43/include/linux/elf.h linux-2.6.32.43/include/linux/elf.h
57807--- linux-2.6.32.43/include/linux/elf.h 2011-03-27 14:31:47.000000000 -0400
57808+++ linux-2.6.32.43/include/linux/elf.h 2011-04-17 15:56:46.000000000 -0400
57809@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
57810 #define PT_GNU_EH_FRAME 0x6474e550
57811
57812 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
57813+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
57814+
57815+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
57816+
57817+/* Constants for the e_flags field */
57818+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57819+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
57820+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
57821+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
57822+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57823+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57824
57825 /* These constants define the different elf file types */
57826 #define ET_NONE 0
57827@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
57828 #define DT_DEBUG 21
57829 #define DT_TEXTREL 22
57830 #define DT_JMPREL 23
57831+#define DT_FLAGS 30
57832+ #define DF_TEXTREL 0x00000004
57833 #define DT_ENCODING 32
57834 #define OLD_DT_LOOS 0x60000000
57835 #define DT_LOOS 0x6000000d
57836@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
57837 #define PF_W 0x2
57838 #define PF_X 0x1
57839
57840+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
57841+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
57842+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
57843+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
57844+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
57845+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
57846+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
57847+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
57848+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
57849+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
57850+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
57851+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
57852+
57853 typedef struct elf32_phdr{
57854 Elf32_Word p_type;
57855 Elf32_Off p_offset;
57856@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
57857 #define EI_OSABI 7
57858 #define EI_PAD 8
57859
57860+#define EI_PAX 14
57861+
57862 #define ELFMAG0 0x7f /* EI_MAG */
57863 #define ELFMAG1 'E'
57864 #define ELFMAG2 'L'
57865@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
57866 #define elf_phdr elf32_phdr
57867 #define elf_note elf32_note
57868 #define elf_addr_t Elf32_Off
57869+#define elf_dyn Elf32_Dyn
57870
57871 #else
57872
57873@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
57874 #define elf_phdr elf64_phdr
57875 #define elf_note elf64_note
57876 #define elf_addr_t Elf64_Off
57877+#define elf_dyn Elf64_Dyn
57878
57879 #endif
57880
57881diff -urNp linux-2.6.32.43/include/linux/fscache-cache.h linux-2.6.32.43/include/linux/fscache-cache.h
57882--- linux-2.6.32.43/include/linux/fscache-cache.h 2011-03-27 14:31:47.000000000 -0400
57883+++ linux-2.6.32.43/include/linux/fscache-cache.h 2011-05-04 17:56:28.000000000 -0400
57884@@ -116,7 +116,7 @@ struct fscache_operation {
57885 #endif
57886 };
57887
57888-extern atomic_t fscache_op_debug_id;
57889+extern atomic_unchecked_t fscache_op_debug_id;
57890 extern const struct slow_work_ops fscache_op_slow_work_ops;
57891
57892 extern void fscache_enqueue_operation(struct fscache_operation *);
57893@@ -134,7 +134,7 @@ static inline void fscache_operation_ini
57894 fscache_operation_release_t release)
57895 {
57896 atomic_set(&op->usage, 1);
57897- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
57898+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57899 op->release = release;
57900 INIT_LIST_HEAD(&op->pend_link);
57901 fscache_set_op_state(op, "Init");
57902diff -urNp linux-2.6.32.43/include/linux/fs.h linux-2.6.32.43/include/linux/fs.h
57903--- linux-2.6.32.43/include/linux/fs.h 2011-07-13 17:23:04.000000000 -0400
57904+++ linux-2.6.32.43/include/linux/fs.h 2011-08-05 20:33:55.000000000 -0400
57905@@ -90,6 +90,11 @@ struct inodes_stat_t {
57906 /* Expect random access pattern */
57907 #define FMODE_RANDOM ((__force fmode_t)4096)
57908
57909+/* Hack for grsec so as not to require read permission simply to execute
57910+ * a binary
57911+ */
57912+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
57913+
57914 /*
57915 * The below are the various read and write types that we support. Some of
57916 * them include behavioral modifiers that send information down to the
57917@@ -568,41 +573,41 @@ typedef int (*read_actor_t)(read_descrip
57918 unsigned long, unsigned long);
57919
57920 struct address_space_operations {
57921- int (*writepage)(struct page *page, struct writeback_control *wbc);
57922- int (*readpage)(struct file *, struct page *);
57923- void (*sync_page)(struct page *);
57924+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
57925+ int (* const readpage)(struct file *, struct page *);
57926+ void (* const sync_page)(struct page *);
57927
57928 /* Write back some dirty pages from this mapping. */
57929- int (*writepages)(struct address_space *, struct writeback_control *);
57930+ int (* const writepages)(struct address_space *, struct writeback_control *);
57931
57932 /* Set a page dirty. Return true if this dirtied it */
57933- int (*set_page_dirty)(struct page *page);
57934+ int (* const set_page_dirty)(struct page *page);
57935
57936- int (*readpages)(struct file *filp, struct address_space *mapping,
57937+ int (* const readpages)(struct file *filp, struct address_space *mapping,
57938 struct list_head *pages, unsigned nr_pages);
57939
57940- int (*write_begin)(struct file *, struct address_space *mapping,
57941+ int (* const write_begin)(struct file *, struct address_space *mapping,
57942 loff_t pos, unsigned len, unsigned flags,
57943 struct page **pagep, void **fsdata);
57944- int (*write_end)(struct file *, struct address_space *mapping,
57945+ int (* const write_end)(struct file *, struct address_space *mapping,
57946 loff_t pos, unsigned len, unsigned copied,
57947 struct page *page, void *fsdata);
57948
57949 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
57950- sector_t (*bmap)(struct address_space *, sector_t);
57951- void (*invalidatepage) (struct page *, unsigned long);
57952- int (*releasepage) (struct page *, gfp_t);
57953- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
57954+ sector_t (* const bmap)(struct address_space *, sector_t);
57955+ void (* const invalidatepage) (struct page *, unsigned long);
57956+ int (* const releasepage) (struct page *, gfp_t);
57957+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
57958 loff_t offset, unsigned long nr_segs);
57959- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
57960+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
57961 void **, unsigned long *);
57962 /* migrate the contents of a page to the specified target */
57963- int (*migratepage) (struct address_space *,
57964+ int (* const migratepage) (struct address_space *,
57965 struct page *, struct page *);
57966- int (*launder_page) (struct page *);
57967- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
57968+ int (* const launder_page) (struct page *);
57969+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
57970 unsigned long);
57971- int (*error_remove_page)(struct address_space *, struct page *);
57972+ int (* const error_remove_page)(struct address_space *, struct page *);
57973 };
57974
57975 /*
57976@@ -1031,19 +1036,19 @@ static inline int file_check_writeable(s
57977 typedef struct files_struct *fl_owner_t;
57978
57979 struct file_lock_operations {
57980- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
57981- void (*fl_release_private)(struct file_lock *);
57982+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
57983+ void (* const fl_release_private)(struct file_lock *);
57984 };
57985
57986 struct lock_manager_operations {
57987- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
57988- void (*fl_notify)(struct file_lock *); /* unblock callback */
57989- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
57990- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
57991- void (*fl_release_private)(struct file_lock *);
57992- void (*fl_break)(struct file_lock *);
57993- int (*fl_mylease)(struct file_lock *, struct file_lock *);
57994- int (*fl_change)(struct file_lock **, int);
57995+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
57996+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
57997+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
57998+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
57999+ void (* const fl_release_private)(struct file_lock *);
58000+ void (* const fl_break)(struct file_lock *);
58001+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
58002+ int (* const fl_change)(struct file_lock **, int);
58003 };
58004
58005 struct lock_manager {
58006@@ -1442,7 +1447,7 @@ struct fiemap_extent_info {
58007 unsigned int fi_flags; /* Flags as passed from user */
58008 unsigned int fi_extents_mapped; /* Number of mapped extents */
58009 unsigned int fi_extents_max; /* Size of fiemap_extent array */
58010- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
58011+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
58012 * array */
58013 };
58014 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
58015@@ -1486,7 +1491,7 @@ struct block_device_operations;
58016 * can be called without the big kernel lock held in all filesystems.
58017 */
58018 struct file_operations {
58019- struct module *owner;
58020+ struct module * const owner;
58021 loff_t (*llseek) (struct file *, loff_t, int);
58022 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
58023 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
58024@@ -1559,30 +1564,30 @@ extern ssize_t vfs_writev(struct file *,
58025 unsigned long, loff_t *);
58026
58027 struct super_operations {
58028- struct inode *(*alloc_inode)(struct super_block *sb);
58029- void (*destroy_inode)(struct inode *);
58030+ struct inode *(* const alloc_inode)(struct super_block *sb);
58031+ void (* const destroy_inode)(struct inode *);
58032
58033- void (*dirty_inode) (struct inode *);
58034- int (*write_inode) (struct inode *, int);
58035- void (*drop_inode) (struct inode *);
58036- void (*delete_inode) (struct inode *);
58037- void (*put_super) (struct super_block *);
58038- void (*write_super) (struct super_block *);
58039- int (*sync_fs)(struct super_block *sb, int wait);
58040- int (*freeze_fs) (struct super_block *);
58041- int (*unfreeze_fs) (struct super_block *);
58042- int (*statfs) (struct dentry *, struct kstatfs *);
58043- int (*remount_fs) (struct super_block *, int *, char *);
58044- void (*clear_inode) (struct inode *);
58045- void (*umount_begin) (struct super_block *);
58046+ void (* const dirty_inode) (struct inode *);
58047+ int (* const write_inode) (struct inode *, int);
58048+ void (* const drop_inode) (struct inode *);
58049+ void (* const delete_inode) (struct inode *);
58050+ void (* const put_super) (struct super_block *);
58051+ void (* const write_super) (struct super_block *);
58052+ int (* const sync_fs)(struct super_block *sb, int wait);
58053+ int (* const freeze_fs) (struct super_block *);
58054+ int (* const unfreeze_fs) (struct super_block *);
58055+ int (* const statfs) (struct dentry *, struct kstatfs *);
58056+ int (* const remount_fs) (struct super_block *, int *, char *);
58057+ void (* const clear_inode) (struct inode *);
58058+ void (* const umount_begin) (struct super_block *);
58059
58060- int (*show_options)(struct seq_file *, struct vfsmount *);
58061- int (*show_stats)(struct seq_file *, struct vfsmount *);
58062+ int (* const show_options)(struct seq_file *, struct vfsmount *);
58063+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
58064 #ifdef CONFIG_QUOTA
58065- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
58066- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
58067+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
58068+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
58069 #endif
58070- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
58071+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
58072 };
58073
58074 /*
58075diff -urNp linux-2.6.32.43/include/linux/fs_struct.h linux-2.6.32.43/include/linux/fs_struct.h
58076--- linux-2.6.32.43/include/linux/fs_struct.h 2011-03-27 14:31:47.000000000 -0400
58077+++ linux-2.6.32.43/include/linux/fs_struct.h 2011-04-17 15:56:46.000000000 -0400
58078@@ -4,7 +4,7 @@
58079 #include <linux/path.h>
58080
58081 struct fs_struct {
58082- int users;
58083+ atomic_t users;
58084 rwlock_t lock;
58085 int umask;
58086 int in_exec;
58087diff -urNp linux-2.6.32.43/include/linux/ftrace_event.h linux-2.6.32.43/include/linux/ftrace_event.h
58088--- linux-2.6.32.43/include/linux/ftrace_event.h 2011-03-27 14:31:47.000000000 -0400
58089+++ linux-2.6.32.43/include/linux/ftrace_event.h 2011-05-04 17:56:28.000000000 -0400
58090@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftr
58091 int filter_type);
58092 extern int trace_define_common_fields(struct ftrace_event_call *call);
58093
58094-#define is_signed_type(type) (((type)(-1)) < 0)
58095+#define is_signed_type(type) (((type)(-1)) < (type)1)
58096
58097 int trace_set_clr_event(const char *system, const char *event, int set);
58098
58099diff -urNp linux-2.6.32.43/include/linux/genhd.h linux-2.6.32.43/include/linux/genhd.h
58100--- linux-2.6.32.43/include/linux/genhd.h 2011-03-27 14:31:47.000000000 -0400
58101+++ linux-2.6.32.43/include/linux/genhd.h 2011-04-17 15:56:46.000000000 -0400
58102@@ -161,7 +161,7 @@ struct gendisk {
58103
58104 struct timer_rand_state *random;
58105
58106- atomic_t sync_io; /* RAID */
58107+ atomic_unchecked_t sync_io; /* RAID */
58108 struct work_struct async_notify;
58109 #ifdef CONFIG_BLK_DEV_INTEGRITY
58110 struct blk_integrity *integrity;
58111diff -urNp linux-2.6.32.43/include/linux/gracl.h linux-2.6.32.43/include/linux/gracl.h
58112--- linux-2.6.32.43/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
58113+++ linux-2.6.32.43/include/linux/gracl.h 2011-04-17 15:56:46.000000000 -0400
58114@@ -0,0 +1,317 @@
58115+#ifndef GR_ACL_H
58116+#define GR_ACL_H
58117+
58118+#include <linux/grdefs.h>
58119+#include <linux/resource.h>
58120+#include <linux/capability.h>
58121+#include <linux/dcache.h>
58122+#include <asm/resource.h>
58123+
58124+/* Major status information */
58125+
58126+#define GR_VERSION "grsecurity 2.2.2"
58127+#define GRSECURITY_VERSION 0x2202
58128+
58129+enum {
58130+ GR_SHUTDOWN = 0,
58131+ GR_ENABLE = 1,
58132+ GR_SPROLE = 2,
58133+ GR_RELOAD = 3,
58134+ GR_SEGVMOD = 4,
58135+ GR_STATUS = 5,
58136+ GR_UNSPROLE = 6,
58137+ GR_PASSSET = 7,
58138+ GR_SPROLEPAM = 8,
58139+};
58140+
58141+/* Password setup definitions
58142+ * kernel/grhash.c */
58143+enum {
58144+ GR_PW_LEN = 128,
58145+ GR_SALT_LEN = 16,
58146+ GR_SHA_LEN = 32,
58147+};
58148+
58149+enum {
58150+ GR_SPROLE_LEN = 64,
58151+};
58152+
58153+enum {
58154+ GR_NO_GLOB = 0,
58155+ GR_REG_GLOB,
58156+ GR_CREATE_GLOB
58157+};
58158+
58159+#define GR_NLIMITS 32
58160+
58161+/* Begin Data Structures */
58162+
58163+struct sprole_pw {
58164+ unsigned char *rolename;
58165+ unsigned char salt[GR_SALT_LEN];
58166+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
58167+};
58168+
58169+struct name_entry {
58170+ __u32 key;
58171+ ino_t inode;
58172+ dev_t device;
58173+ char *name;
58174+ __u16 len;
58175+ __u8 deleted;
58176+ struct name_entry *prev;
58177+ struct name_entry *next;
58178+};
58179+
58180+struct inodev_entry {
58181+ struct name_entry *nentry;
58182+ struct inodev_entry *prev;
58183+ struct inodev_entry *next;
58184+};
58185+
58186+struct acl_role_db {
58187+ struct acl_role_label **r_hash;
58188+ __u32 r_size;
58189+};
58190+
58191+struct inodev_db {
58192+ struct inodev_entry **i_hash;
58193+ __u32 i_size;
58194+};
58195+
58196+struct name_db {
58197+ struct name_entry **n_hash;
58198+ __u32 n_size;
58199+};
58200+
58201+struct crash_uid {
58202+ uid_t uid;
58203+ unsigned long expires;
58204+};
58205+
58206+struct gr_hash_struct {
58207+ void **table;
58208+ void **nametable;
58209+ void *first;
58210+ __u32 table_size;
58211+ __u32 used_size;
58212+ int type;
58213+};
58214+
58215+/* Userspace Grsecurity ACL data structures */
58216+
58217+struct acl_subject_label {
58218+ char *filename;
58219+ ino_t inode;
58220+ dev_t device;
58221+ __u32 mode;
58222+ kernel_cap_t cap_mask;
58223+ kernel_cap_t cap_lower;
58224+ kernel_cap_t cap_invert_audit;
58225+
58226+ struct rlimit res[GR_NLIMITS];
58227+ __u32 resmask;
58228+
58229+ __u8 user_trans_type;
58230+ __u8 group_trans_type;
58231+ uid_t *user_transitions;
58232+ gid_t *group_transitions;
58233+ __u16 user_trans_num;
58234+ __u16 group_trans_num;
58235+
58236+ __u32 sock_families[2];
58237+ __u32 ip_proto[8];
58238+ __u32 ip_type;
58239+ struct acl_ip_label **ips;
58240+ __u32 ip_num;
58241+ __u32 inaddr_any_override;
58242+
58243+ __u32 crashes;
58244+ unsigned long expires;
58245+
58246+ struct acl_subject_label *parent_subject;
58247+ struct gr_hash_struct *hash;
58248+ struct acl_subject_label *prev;
58249+ struct acl_subject_label *next;
58250+
58251+ struct acl_object_label **obj_hash;
58252+ __u32 obj_hash_size;
58253+ __u16 pax_flags;
58254+};
58255+
58256+struct role_allowed_ip {
58257+ __u32 addr;
58258+ __u32 netmask;
58259+
58260+ struct role_allowed_ip *prev;
58261+ struct role_allowed_ip *next;
58262+};
58263+
58264+struct role_transition {
58265+ char *rolename;
58266+
58267+ struct role_transition *prev;
58268+ struct role_transition *next;
58269+};
58270+
58271+struct acl_role_label {
58272+ char *rolename;
58273+ uid_t uidgid;
58274+ __u16 roletype;
58275+
58276+ __u16 auth_attempts;
58277+ unsigned long expires;
58278+
58279+ struct acl_subject_label *root_label;
58280+ struct gr_hash_struct *hash;
58281+
58282+ struct acl_role_label *prev;
58283+ struct acl_role_label *next;
58284+
58285+ struct role_transition *transitions;
58286+ struct role_allowed_ip *allowed_ips;
58287+ uid_t *domain_children;
58288+ __u16 domain_child_num;
58289+
58290+ struct acl_subject_label **subj_hash;
58291+ __u32 subj_hash_size;
58292+};
58293+
58294+struct user_acl_role_db {
58295+ struct acl_role_label **r_table;
58296+ __u32 num_pointers; /* Number of allocations to track */
58297+ __u32 num_roles; /* Number of roles */
58298+ __u32 num_domain_children; /* Number of domain children */
58299+ __u32 num_subjects; /* Number of subjects */
58300+ __u32 num_objects; /* Number of objects */
58301+};
58302+
58303+struct acl_object_label {
58304+ char *filename;
58305+ ino_t inode;
58306+ dev_t device;
58307+ __u32 mode;
58308+
58309+ struct acl_subject_label *nested;
58310+ struct acl_object_label *globbed;
58311+
58312+ /* next two structures not used */
58313+
58314+ struct acl_object_label *prev;
58315+ struct acl_object_label *next;
58316+};
58317+
58318+struct acl_ip_label {
58319+ char *iface;
58320+ __u32 addr;
58321+ __u32 netmask;
58322+ __u16 low, high;
58323+ __u8 mode;
58324+ __u32 type;
58325+ __u32 proto[8];
58326+
58327+ /* next two structures not used */
58328+
58329+ struct acl_ip_label *prev;
58330+ struct acl_ip_label *next;
58331+};
58332+
58333+struct gr_arg {
58334+ struct user_acl_role_db role_db;
58335+ unsigned char pw[GR_PW_LEN];
58336+ unsigned char salt[GR_SALT_LEN];
58337+ unsigned char sum[GR_SHA_LEN];
58338+ unsigned char sp_role[GR_SPROLE_LEN];
58339+ struct sprole_pw *sprole_pws;
58340+ dev_t segv_device;
58341+ ino_t segv_inode;
58342+ uid_t segv_uid;
58343+ __u16 num_sprole_pws;
58344+ __u16 mode;
58345+};
58346+
58347+struct gr_arg_wrapper {
58348+ struct gr_arg *arg;
58349+ __u32 version;
58350+ __u32 size;
58351+};
58352+
58353+struct subject_map {
58354+ struct acl_subject_label *user;
58355+ struct acl_subject_label *kernel;
58356+ struct subject_map *prev;
58357+ struct subject_map *next;
58358+};
58359+
58360+struct acl_subj_map_db {
58361+ struct subject_map **s_hash;
58362+ __u32 s_size;
58363+};
58364+
58365+/* End Data Structures Section */
58366+
58367+/* Hash functions generated by empirical testing by Brad Spengler
58368+ Makes good use of the low bits of the inode. Generally 0-1 times
58369+ in loop for successful match. 0-3 for unsuccessful match.
58370+ Shift/add algorithm with modulus of table size and an XOR*/
58371+
58372+static __inline__ unsigned int
58373+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
58374+{
58375+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
58376+}
58377+
58378+ static __inline__ unsigned int
58379+shash(const struct acl_subject_label *userp, const unsigned int sz)
58380+{
58381+ return ((const unsigned long)userp % sz);
58382+}
58383+
58384+static __inline__ unsigned int
58385+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
58386+{
58387+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
58388+}
58389+
58390+static __inline__ unsigned int
58391+nhash(const char *name, const __u16 len, const unsigned int sz)
58392+{
58393+ return full_name_hash((const unsigned char *)name, len) % sz;
58394+}
58395+
58396+#define FOR_EACH_ROLE_START(role) \
58397+ role = role_list; \
58398+ while (role) {
58399+
58400+#define FOR_EACH_ROLE_END(role) \
58401+ role = role->prev; \
58402+ }
58403+
58404+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
58405+ subj = NULL; \
58406+ iter = 0; \
58407+ while (iter < role->subj_hash_size) { \
58408+ if (subj == NULL) \
58409+ subj = role->subj_hash[iter]; \
58410+ if (subj == NULL) { \
58411+ iter++; \
58412+ continue; \
58413+ }
58414+
58415+#define FOR_EACH_SUBJECT_END(subj,iter) \
58416+ subj = subj->next; \
58417+ if (subj == NULL) \
58418+ iter++; \
58419+ }
58420+
58421+
58422+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
58423+ subj = role->hash->first; \
58424+ while (subj != NULL) {
58425+
58426+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
58427+ subj = subj->next; \
58428+ }
58429+
58430+#endif
58431+
58432diff -urNp linux-2.6.32.43/include/linux/gralloc.h linux-2.6.32.43/include/linux/gralloc.h
58433--- linux-2.6.32.43/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
58434+++ linux-2.6.32.43/include/linux/gralloc.h 2011-04-17 15:56:46.000000000 -0400
58435@@ -0,0 +1,9 @@
58436+#ifndef __GRALLOC_H
58437+#define __GRALLOC_H
58438+
58439+void acl_free_all(void);
58440+int acl_alloc_stack_init(unsigned long size);
58441+void *acl_alloc(unsigned long len);
58442+void *acl_alloc_num(unsigned long num, unsigned long len);
58443+
58444+#endif
58445diff -urNp linux-2.6.32.43/include/linux/grdefs.h linux-2.6.32.43/include/linux/grdefs.h
58446--- linux-2.6.32.43/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
58447+++ linux-2.6.32.43/include/linux/grdefs.h 2011-06-11 16:20:26.000000000 -0400
58448@@ -0,0 +1,140 @@
58449+#ifndef GRDEFS_H
58450+#define GRDEFS_H
58451+
58452+/* Begin grsecurity status declarations */
58453+
58454+enum {
58455+ GR_READY = 0x01,
58456+ GR_STATUS_INIT = 0x00 // disabled state
58457+};
58458+
58459+/* Begin ACL declarations */
58460+
58461+/* Role flags */
58462+
58463+enum {
58464+ GR_ROLE_USER = 0x0001,
58465+ GR_ROLE_GROUP = 0x0002,
58466+ GR_ROLE_DEFAULT = 0x0004,
58467+ GR_ROLE_SPECIAL = 0x0008,
58468+ GR_ROLE_AUTH = 0x0010,
58469+ GR_ROLE_NOPW = 0x0020,
58470+ GR_ROLE_GOD = 0x0040,
58471+ GR_ROLE_LEARN = 0x0080,
58472+ GR_ROLE_TPE = 0x0100,
58473+ GR_ROLE_DOMAIN = 0x0200,
58474+ GR_ROLE_PAM = 0x0400,
58475+ GR_ROLE_PERSIST = 0x800
58476+};
58477+
58478+/* ACL Subject and Object mode flags */
58479+enum {
58480+ GR_DELETED = 0x80000000
58481+};
58482+
58483+/* ACL Object-only mode flags */
58484+enum {
58485+ GR_READ = 0x00000001,
58486+ GR_APPEND = 0x00000002,
58487+ GR_WRITE = 0x00000004,
58488+ GR_EXEC = 0x00000008,
58489+ GR_FIND = 0x00000010,
58490+ GR_INHERIT = 0x00000020,
58491+ GR_SETID = 0x00000040,
58492+ GR_CREATE = 0x00000080,
58493+ GR_DELETE = 0x00000100,
58494+ GR_LINK = 0x00000200,
58495+ GR_AUDIT_READ = 0x00000400,
58496+ GR_AUDIT_APPEND = 0x00000800,
58497+ GR_AUDIT_WRITE = 0x00001000,
58498+ GR_AUDIT_EXEC = 0x00002000,
58499+ GR_AUDIT_FIND = 0x00004000,
58500+ GR_AUDIT_INHERIT= 0x00008000,
58501+ GR_AUDIT_SETID = 0x00010000,
58502+ GR_AUDIT_CREATE = 0x00020000,
58503+ GR_AUDIT_DELETE = 0x00040000,
58504+ GR_AUDIT_LINK = 0x00080000,
58505+ GR_PTRACERD = 0x00100000,
58506+ GR_NOPTRACE = 0x00200000,
58507+ GR_SUPPRESS = 0x00400000,
58508+ GR_NOLEARN = 0x00800000,
58509+ GR_INIT_TRANSFER= 0x01000000
58510+};
58511+
58512+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
58513+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
58514+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
58515+
58516+/* ACL subject-only mode flags */
58517+enum {
58518+ GR_KILL = 0x00000001,
58519+ GR_VIEW = 0x00000002,
58520+ GR_PROTECTED = 0x00000004,
58521+ GR_LEARN = 0x00000008,
58522+ GR_OVERRIDE = 0x00000010,
58523+ /* just a placeholder, this mode is only used in userspace */
58524+ GR_DUMMY = 0x00000020,
58525+ GR_PROTSHM = 0x00000040,
58526+ GR_KILLPROC = 0x00000080,
58527+ GR_KILLIPPROC = 0x00000100,
58528+ /* just a placeholder, this mode is only used in userspace */
58529+ GR_NOTROJAN = 0x00000200,
58530+ GR_PROTPROCFD = 0x00000400,
58531+ GR_PROCACCT = 0x00000800,
58532+ GR_RELAXPTRACE = 0x00001000,
58533+ GR_NESTED = 0x00002000,
58534+ GR_INHERITLEARN = 0x00004000,
58535+ GR_PROCFIND = 0x00008000,
58536+ GR_POVERRIDE = 0x00010000,
58537+ GR_KERNELAUTH = 0x00020000,
58538+ GR_ATSECURE = 0x00040000,
58539+ GR_SHMEXEC = 0x00080000
58540+};
58541+
58542+enum {
58543+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
58544+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
58545+ GR_PAX_ENABLE_MPROTECT = 0x0004,
58546+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
58547+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
58548+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
58549+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
58550+ GR_PAX_DISABLE_MPROTECT = 0x0400,
58551+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
58552+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
58553+};
58554+
58555+enum {
58556+ GR_ID_USER = 0x01,
58557+ GR_ID_GROUP = 0x02,
58558+};
58559+
58560+enum {
58561+ GR_ID_ALLOW = 0x01,
58562+ GR_ID_DENY = 0x02,
58563+};
58564+
58565+#define GR_CRASH_RES 31
58566+#define GR_UIDTABLE_MAX 500
58567+
58568+/* begin resource learning section */
58569+enum {
58570+ GR_RLIM_CPU_BUMP = 60,
58571+ GR_RLIM_FSIZE_BUMP = 50000,
58572+ GR_RLIM_DATA_BUMP = 10000,
58573+ GR_RLIM_STACK_BUMP = 1000,
58574+ GR_RLIM_CORE_BUMP = 10000,
58575+ GR_RLIM_RSS_BUMP = 500000,
58576+ GR_RLIM_NPROC_BUMP = 1,
58577+ GR_RLIM_NOFILE_BUMP = 5,
58578+ GR_RLIM_MEMLOCK_BUMP = 50000,
58579+ GR_RLIM_AS_BUMP = 500000,
58580+ GR_RLIM_LOCKS_BUMP = 2,
58581+ GR_RLIM_SIGPENDING_BUMP = 5,
58582+ GR_RLIM_MSGQUEUE_BUMP = 10000,
58583+ GR_RLIM_NICE_BUMP = 1,
58584+ GR_RLIM_RTPRIO_BUMP = 1,
58585+ GR_RLIM_RTTIME_BUMP = 1000000
58586+};
58587+
58588+#endif
58589diff -urNp linux-2.6.32.43/include/linux/grinternal.h linux-2.6.32.43/include/linux/grinternal.h
58590--- linux-2.6.32.43/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
58591+++ linux-2.6.32.43/include/linux/grinternal.h 2011-07-14 20:35:29.000000000 -0400
58592@@ -0,0 +1,218 @@
58593+#ifndef __GRINTERNAL_H
58594+#define __GRINTERNAL_H
58595+
58596+#ifdef CONFIG_GRKERNSEC
58597+
58598+#include <linux/fs.h>
58599+#include <linux/mnt_namespace.h>
58600+#include <linux/nsproxy.h>
58601+#include <linux/gracl.h>
58602+#include <linux/grdefs.h>
58603+#include <linux/grmsg.h>
58604+
58605+void gr_add_learn_entry(const char *fmt, ...)
58606+ __attribute__ ((format (printf, 1, 2)));
58607+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
58608+ const struct vfsmount *mnt);
58609+__u32 gr_check_create(const struct dentry *new_dentry,
58610+ const struct dentry *parent,
58611+ const struct vfsmount *mnt, const __u32 mode);
58612+int gr_check_protected_task(const struct task_struct *task);
58613+__u32 to_gr_audit(const __u32 reqmode);
58614+int gr_set_acls(const int type);
58615+int gr_apply_subject_to_task(struct task_struct *task);
58616+int gr_acl_is_enabled(void);
58617+char gr_roletype_to_char(void);
58618+
58619+void gr_handle_alertkill(struct task_struct *task);
58620+char *gr_to_filename(const struct dentry *dentry,
58621+ const struct vfsmount *mnt);
58622+char *gr_to_filename1(const struct dentry *dentry,
58623+ const struct vfsmount *mnt);
58624+char *gr_to_filename2(const struct dentry *dentry,
58625+ const struct vfsmount *mnt);
58626+char *gr_to_filename3(const struct dentry *dentry,
58627+ const struct vfsmount *mnt);
58628+
58629+extern int grsec_enable_harden_ptrace;
58630+extern int grsec_enable_link;
58631+extern int grsec_enable_fifo;
58632+extern int grsec_enable_execve;
58633+extern int grsec_enable_shm;
58634+extern int grsec_enable_execlog;
58635+extern int grsec_enable_signal;
58636+extern int grsec_enable_audit_ptrace;
58637+extern int grsec_enable_forkfail;
58638+extern int grsec_enable_time;
58639+extern int grsec_enable_rofs;
58640+extern int grsec_enable_chroot_shmat;
58641+extern int grsec_enable_chroot_mount;
58642+extern int grsec_enable_chroot_double;
58643+extern int grsec_enable_chroot_pivot;
58644+extern int grsec_enable_chroot_chdir;
58645+extern int grsec_enable_chroot_chmod;
58646+extern int grsec_enable_chroot_mknod;
58647+extern int grsec_enable_chroot_fchdir;
58648+extern int grsec_enable_chroot_nice;
58649+extern int grsec_enable_chroot_execlog;
58650+extern int grsec_enable_chroot_caps;
58651+extern int grsec_enable_chroot_sysctl;
58652+extern int grsec_enable_chroot_unix;
58653+extern int grsec_enable_tpe;
58654+extern int grsec_tpe_gid;
58655+extern int grsec_enable_tpe_all;
58656+extern int grsec_enable_tpe_invert;
58657+extern int grsec_enable_socket_all;
58658+extern int grsec_socket_all_gid;
58659+extern int grsec_enable_socket_client;
58660+extern int grsec_socket_client_gid;
58661+extern int grsec_enable_socket_server;
58662+extern int grsec_socket_server_gid;
58663+extern int grsec_audit_gid;
58664+extern int grsec_enable_group;
58665+extern int grsec_enable_audit_textrel;
58666+extern int grsec_enable_log_rwxmaps;
58667+extern int grsec_enable_mount;
58668+extern int grsec_enable_chdir;
58669+extern int grsec_resource_logging;
58670+extern int grsec_enable_blackhole;
58671+extern int grsec_lastack_retries;
58672+extern int grsec_enable_brute;
58673+extern int grsec_lock;
58674+
58675+extern spinlock_t grsec_alert_lock;
58676+extern unsigned long grsec_alert_wtime;
58677+extern unsigned long grsec_alert_fyet;
58678+
58679+extern spinlock_t grsec_audit_lock;
58680+
58681+extern rwlock_t grsec_exec_file_lock;
58682+
58683+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
58684+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
58685+ (tsk)->exec_file->f_vfsmnt) : "/")
58686+
58687+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
58688+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
58689+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
58690+
58691+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
58692+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
58693+ (tsk)->exec_file->f_vfsmnt) : "/")
58694+
58695+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
58696+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
58697+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
58698+
58699+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
58700+
58701+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
58702+
58703+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
58704+ (task)->pid, (cred)->uid, \
58705+ (cred)->euid, (cred)->gid, (cred)->egid, \
58706+ gr_parent_task_fullpath(task), \
58707+ (task)->real_parent->comm, (task)->real_parent->pid, \
58708+ (pcred)->uid, (pcred)->euid, \
58709+ (pcred)->gid, (pcred)->egid
58710+
58711+#define GR_CHROOT_CAPS {{ \
58712+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
58713+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
58714+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
58715+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
58716+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
58717+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
58718+
58719+#define security_learn(normal_msg,args...) \
58720+({ \
58721+ read_lock(&grsec_exec_file_lock); \
58722+ gr_add_learn_entry(normal_msg "\n", ## args); \
58723+ read_unlock(&grsec_exec_file_lock); \
58724+})
58725+
58726+enum {
58727+ GR_DO_AUDIT,
58728+ GR_DONT_AUDIT,
58729+ GR_DONT_AUDIT_GOOD
58730+};
58731+
58732+enum {
58733+ GR_TTYSNIFF,
58734+ GR_RBAC,
58735+ GR_RBAC_STR,
58736+ GR_STR_RBAC,
58737+ GR_RBAC_MODE2,
58738+ GR_RBAC_MODE3,
58739+ GR_FILENAME,
58740+ GR_SYSCTL_HIDDEN,
58741+ GR_NOARGS,
58742+ GR_ONE_INT,
58743+ GR_ONE_INT_TWO_STR,
58744+ GR_ONE_STR,
58745+ GR_STR_INT,
58746+ GR_TWO_STR_INT,
58747+ GR_TWO_INT,
58748+ GR_TWO_U64,
58749+ GR_THREE_INT,
58750+ GR_FIVE_INT_TWO_STR,
58751+ GR_TWO_STR,
58752+ GR_THREE_STR,
58753+ GR_FOUR_STR,
58754+ GR_STR_FILENAME,
58755+ GR_FILENAME_STR,
58756+ GR_FILENAME_TWO_INT,
58757+ GR_FILENAME_TWO_INT_STR,
58758+ GR_TEXTREL,
58759+ GR_PTRACE,
58760+ GR_RESOURCE,
58761+ GR_CAP,
58762+ GR_SIG,
58763+ GR_SIG2,
58764+ GR_CRASH1,
58765+ GR_CRASH2,
58766+ GR_PSACCT,
58767+ GR_RWXMAP
58768+};
58769+
58770+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
58771+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
58772+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
58773+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
58774+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
58775+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
58776+#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)
58777+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
58778+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
58779+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
58780+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
58781+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
58782+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
58783+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
58784+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
58785+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
58786+#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)
58787+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
58788+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
58789+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
58790+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
58791+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
58792+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
58793+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
58794+#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)
58795+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
58796+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
58797+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
58798+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
58799+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
58800+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
58801+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
58802+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
58803+#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)
58804+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
58805+
58806+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
58807+
58808+#endif
58809+
58810+#endif
58811diff -urNp linux-2.6.32.43/include/linux/grmsg.h linux-2.6.32.43/include/linux/grmsg.h
58812--- linux-2.6.32.43/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
58813+++ linux-2.6.32.43/include/linux/grmsg.h 2011-04-17 15:56:46.000000000 -0400
58814@@ -0,0 +1,108 @@
58815+#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"
58816+#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"
58817+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
58818+#define GR_STOPMOD_MSG "denied modification of module state by "
58819+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
58820+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
58821+#define GR_IOPERM_MSG "denied use of ioperm() by "
58822+#define GR_IOPL_MSG "denied use of iopl() by "
58823+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
58824+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
58825+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
58826+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
58827+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
58828+#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"
58829+#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"
58830+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
58831+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
58832+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
58833+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
58834+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
58835+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
58836+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
58837+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
58838+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
58839+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
58840+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
58841+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
58842+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
58843+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
58844+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
58845+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
58846+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
58847+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
58848+#define GR_NPROC_MSG "denied overstep of process limit by "
58849+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
58850+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
58851+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
58852+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
58853+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
58854+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
58855+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
58856+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
58857+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
58858+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
58859+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
58860+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
58861+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
58862+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
58863+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
58864+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
58865+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
58866+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
58867+#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"
58868+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
58869+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
58870+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
58871+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
58872+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
58873+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
58874+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
58875+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
58876+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
58877+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
58878+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
58879+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
58880+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
58881+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
58882+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
58883+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
58884+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
58885+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
58886+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
58887+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
58888+#define GR_FAILFORK_MSG "failed fork with errno %s by "
58889+#define GR_NICE_CHROOT_MSG "denied priority change by "
58890+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
58891+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
58892+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
58893+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
58894+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
58895+#define GR_TIME_MSG "time set by "
58896+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
58897+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
58898+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
58899+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
58900+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
58901+#define GR_BIND_MSG "denied bind() by "
58902+#define GR_CONNECT_MSG "denied connect() by "
58903+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
58904+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
58905+#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"
58906+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
58907+#define GR_CAP_ACL_MSG "use of %s denied for "
58908+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
58909+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
58910+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
58911+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
58912+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
58913+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
58914+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
58915+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
58916+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
58917+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
58918+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
58919+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
58920+#define GR_VM86_MSG "denied use of vm86 by "
58921+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
58922+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
58923diff -urNp linux-2.6.32.43/include/linux/grsecurity.h linux-2.6.32.43/include/linux/grsecurity.h
58924--- linux-2.6.32.43/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
58925+++ linux-2.6.32.43/include/linux/grsecurity.h 2011-08-05 19:53:46.000000000 -0400
58926@@ -0,0 +1,218 @@
58927+#ifndef GR_SECURITY_H
58928+#define GR_SECURITY_H
58929+#include <linux/fs.h>
58930+#include <linux/fs_struct.h>
58931+#include <linux/binfmts.h>
58932+#include <linux/gracl.h>
58933+#include <linux/compat.h>
58934+
58935+/* notify of brain-dead configs */
58936+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58937+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
58938+#endif
58939+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
58940+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
58941+#endif
58942+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
58943+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
58944+#endif
58945+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
58946+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
58947+#endif
58948+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
58949+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
58950+#endif
58951+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
58952+#error "CONFIG_PAX enabled, but no PaX options are enabled."
58953+#endif
58954+
58955+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
58956+void gr_handle_brute_check(void);
58957+void gr_handle_kernel_exploit(void);
58958+int gr_process_user_ban(void);
58959+
58960+char gr_roletype_to_char(void);
58961+
58962+int gr_acl_enable_at_secure(void);
58963+
58964+int gr_check_user_change(int real, int effective, int fs);
58965+int gr_check_group_change(int real, int effective, int fs);
58966+
58967+void gr_del_task_from_ip_table(struct task_struct *p);
58968+
58969+int gr_pid_is_chrooted(struct task_struct *p);
58970+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
58971+int gr_handle_chroot_nice(void);
58972+int gr_handle_chroot_sysctl(const int op);
58973+int gr_handle_chroot_setpriority(struct task_struct *p,
58974+ const int niceval);
58975+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
58976+int gr_handle_chroot_chroot(const struct dentry *dentry,
58977+ const struct vfsmount *mnt);
58978+int gr_handle_chroot_caps(struct path *path);
58979+void gr_handle_chroot_chdir(struct path *path);
58980+int gr_handle_chroot_chmod(const struct dentry *dentry,
58981+ const struct vfsmount *mnt, const int mode);
58982+int gr_handle_chroot_mknod(const struct dentry *dentry,
58983+ const struct vfsmount *mnt, const int mode);
58984+int gr_handle_chroot_mount(const struct dentry *dentry,
58985+ const struct vfsmount *mnt,
58986+ const char *dev_name);
58987+int gr_handle_chroot_pivot(void);
58988+int gr_handle_chroot_unix(const pid_t pid);
58989+
58990+int gr_handle_rawio(const struct inode *inode);
58991+int gr_handle_nproc(void);
58992+
58993+void gr_handle_ioperm(void);
58994+void gr_handle_iopl(void);
58995+
58996+int gr_tpe_allow(const struct file *file);
58997+
58998+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
58999+void gr_clear_chroot_entries(struct task_struct *task);
59000+
59001+void gr_log_forkfail(const int retval);
59002+void gr_log_timechange(void);
59003+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
59004+void gr_log_chdir(const struct dentry *dentry,
59005+ const struct vfsmount *mnt);
59006+void gr_log_chroot_exec(const struct dentry *dentry,
59007+ const struct vfsmount *mnt);
59008+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
59009+#ifdef CONFIG_COMPAT
59010+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
59011+#endif
59012+void gr_log_remount(const char *devname, const int retval);
59013+void gr_log_unmount(const char *devname, const int retval);
59014+void gr_log_mount(const char *from, const char *to, const int retval);
59015+void gr_log_textrel(struct vm_area_struct *vma);
59016+void gr_log_rwxmmap(struct file *file);
59017+void gr_log_rwxmprotect(struct file *file);
59018+
59019+int gr_handle_follow_link(const struct inode *parent,
59020+ const struct inode *inode,
59021+ const struct dentry *dentry,
59022+ const struct vfsmount *mnt);
59023+int gr_handle_fifo(const struct dentry *dentry,
59024+ const struct vfsmount *mnt,
59025+ const struct dentry *dir, const int flag,
59026+ const int acc_mode);
59027+int gr_handle_hardlink(const struct dentry *dentry,
59028+ const struct vfsmount *mnt,
59029+ struct inode *inode,
59030+ const int mode, const char *to);
59031+
59032+int gr_is_capable(const int cap);
59033+int gr_is_capable_nolog(const int cap);
59034+void gr_learn_resource(const struct task_struct *task, const int limit,
59035+ const unsigned long wanted, const int gt);
59036+void gr_copy_label(struct task_struct *tsk);
59037+void gr_handle_crash(struct task_struct *task, const int sig);
59038+int gr_handle_signal(const struct task_struct *p, const int sig);
59039+int gr_check_crash_uid(const uid_t uid);
59040+int gr_check_protected_task(const struct task_struct *task);
59041+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
59042+int gr_acl_handle_mmap(const struct file *file,
59043+ const unsigned long prot);
59044+int gr_acl_handle_mprotect(const struct file *file,
59045+ const unsigned long prot);
59046+int gr_check_hidden_task(const struct task_struct *tsk);
59047+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
59048+ const struct vfsmount *mnt);
59049+__u32 gr_acl_handle_utime(const struct dentry *dentry,
59050+ const struct vfsmount *mnt);
59051+__u32 gr_acl_handle_access(const struct dentry *dentry,
59052+ const struct vfsmount *mnt, const int fmode);
59053+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
59054+ const struct vfsmount *mnt, mode_t mode);
59055+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
59056+ const struct vfsmount *mnt, mode_t mode);
59057+__u32 gr_acl_handle_chown(const struct dentry *dentry,
59058+ const struct vfsmount *mnt);
59059+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
59060+ const struct vfsmount *mnt);
59061+int gr_handle_ptrace(struct task_struct *task, const long request);
59062+int gr_handle_proc_ptrace(struct task_struct *task);
59063+__u32 gr_acl_handle_execve(const struct dentry *dentry,
59064+ const struct vfsmount *mnt);
59065+int gr_check_crash_exec(const struct file *filp);
59066+int gr_acl_is_enabled(void);
59067+void gr_set_kernel_label(struct task_struct *task);
59068+void gr_set_role_label(struct task_struct *task, const uid_t uid,
59069+ const gid_t gid);
59070+int gr_set_proc_label(const struct dentry *dentry,
59071+ const struct vfsmount *mnt,
59072+ const int unsafe_share);
59073+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
59074+ const struct vfsmount *mnt);
59075+__u32 gr_acl_handle_open(const struct dentry *dentry,
59076+ const struct vfsmount *mnt, const int fmode);
59077+__u32 gr_acl_handle_creat(const struct dentry *dentry,
59078+ const struct dentry *p_dentry,
59079+ const struct vfsmount *p_mnt, const int fmode,
59080+ const int imode);
59081+void gr_handle_create(const struct dentry *dentry,
59082+ const struct vfsmount *mnt);
59083+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
59084+ const struct dentry *parent_dentry,
59085+ const struct vfsmount *parent_mnt,
59086+ const int mode);
59087+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
59088+ const struct dentry *parent_dentry,
59089+ const struct vfsmount *parent_mnt);
59090+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
59091+ const struct vfsmount *mnt);
59092+void gr_handle_delete(const ino_t ino, const dev_t dev);
59093+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
59094+ const struct vfsmount *mnt);
59095+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
59096+ const struct dentry *parent_dentry,
59097+ const struct vfsmount *parent_mnt,
59098+ const char *from);
59099+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
59100+ const struct dentry *parent_dentry,
59101+ const struct vfsmount *parent_mnt,
59102+ const struct dentry *old_dentry,
59103+ const struct vfsmount *old_mnt, const char *to);
59104+int gr_acl_handle_rename(struct dentry *new_dentry,
59105+ struct dentry *parent_dentry,
59106+ const struct vfsmount *parent_mnt,
59107+ struct dentry *old_dentry,
59108+ struct inode *old_parent_inode,
59109+ struct vfsmount *old_mnt, const char *newname);
59110+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59111+ struct dentry *old_dentry,
59112+ struct dentry *new_dentry,
59113+ struct vfsmount *mnt, const __u8 replace);
59114+__u32 gr_check_link(const struct dentry *new_dentry,
59115+ const struct dentry *parent_dentry,
59116+ const struct vfsmount *parent_mnt,
59117+ const struct dentry *old_dentry,
59118+ const struct vfsmount *old_mnt);
59119+int gr_acl_handle_filldir(const struct file *file, const char *name,
59120+ const unsigned int namelen, const ino_t ino);
59121+
59122+__u32 gr_acl_handle_unix(const struct dentry *dentry,
59123+ const struct vfsmount *mnt);
59124+void gr_acl_handle_exit(void);
59125+void gr_acl_handle_psacct(struct task_struct *task, const long code);
59126+int gr_acl_handle_procpidmem(const struct task_struct *task);
59127+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
59128+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
59129+void gr_audit_ptrace(struct task_struct *task);
59130+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
59131+
59132+#ifdef CONFIG_GRKERNSEC
59133+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
59134+void gr_handle_vm86(void);
59135+void gr_handle_mem_readwrite(u64 from, u64 to);
59136+
59137+extern int grsec_enable_dmesg;
59138+extern int grsec_disable_privio;
59139+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59140+extern int grsec_enable_chroot_findtask;
59141+#endif
59142+#endif
59143+
59144+#endif
59145diff -urNp linux-2.6.32.43/include/linux/hdpu_features.h linux-2.6.32.43/include/linux/hdpu_features.h
59146--- linux-2.6.32.43/include/linux/hdpu_features.h 2011-03-27 14:31:47.000000000 -0400
59147+++ linux-2.6.32.43/include/linux/hdpu_features.h 2011-04-17 15:56:46.000000000 -0400
59148@@ -3,7 +3,7 @@
59149 struct cpustate_t {
59150 spinlock_t lock;
59151 int excl;
59152- int open_count;
59153+ atomic_t open_count;
59154 unsigned char cached_val;
59155 int inited;
59156 unsigned long *set_addr;
59157diff -urNp linux-2.6.32.43/include/linux/highmem.h linux-2.6.32.43/include/linux/highmem.h
59158--- linux-2.6.32.43/include/linux/highmem.h 2011-03-27 14:31:47.000000000 -0400
59159+++ linux-2.6.32.43/include/linux/highmem.h 2011-04-17 15:56:46.000000000 -0400
59160@@ -137,6 +137,18 @@ static inline void clear_highpage(struct
59161 kunmap_atomic(kaddr, KM_USER0);
59162 }
59163
59164+static inline void sanitize_highpage(struct page *page)
59165+{
59166+ void *kaddr;
59167+ unsigned long flags;
59168+
59169+ local_irq_save(flags);
59170+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
59171+ clear_page(kaddr);
59172+ kunmap_atomic(kaddr, KM_CLEARPAGE);
59173+ local_irq_restore(flags);
59174+}
59175+
59176 static inline void zero_user_segments(struct page *page,
59177 unsigned start1, unsigned end1,
59178 unsigned start2, unsigned end2)
59179diff -urNp linux-2.6.32.43/include/linux/i2o.h linux-2.6.32.43/include/linux/i2o.h
59180--- linux-2.6.32.43/include/linux/i2o.h 2011-03-27 14:31:47.000000000 -0400
59181+++ linux-2.6.32.43/include/linux/i2o.h 2011-05-04 17:56:28.000000000 -0400
59182@@ -564,7 +564,7 @@ struct i2o_controller {
59183 struct i2o_device *exec; /* Executive */
59184 #if BITS_PER_LONG == 64
59185 spinlock_t context_list_lock; /* lock for context_list */
59186- atomic_t context_list_counter; /* needed for unique contexts */
59187+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
59188 struct list_head context_list; /* list of context id's
59189 and pointers */
59190 #endif
59191diff -urNp linux-2.6.32.43/include/linux/init_task.h linux-2.6.32.43/include/linux/init_task.h
59192--- linux-2.6.32.43/include/linux/init_task.h 2011-03-27 14:31:47.000000000 -0400
59193+++ linux-2.6.32.43/include/linux/init_task.h 2011-05-18 20:44:59.000000000 -0400
59194@@ -83,6 +83,12 @@ extern struct group_info init_groups;
59195 #define INIT_IDS
59196 #endif
59197
59198+#ifdef CONFIG_X86
59199+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
59200+#else
59201+#define INIT_TASK_THREAD_INFO
59202+#endif
59203+
59204 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
59205 /*
59206 * Because of the reduced scope of CAP_SETPCAP when filesystem
59207@@ -156,6 +162,7 @@ extern struct cred init_cred;
59208 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
59209 .comm = "swapper", \
59210 .thread = INIT_THREAD, \
59211+ INIT_TASK_THREAD_INFO \
59212 .fs = &init_fs, \
59213 .files = &init_files, \
59214 .signal = &init_signals, \
59215diff -urNp linux-2.6.32.43/include/linux/intel-iommu.h linux-2.6.32.43/include/linux/intel-iommu.h
59216--- linux-2.6.32.43/include/linux/intel-iommu.h 2011-03-27 14:31:47.000000000 -0400
59217+++ linux-2.6.32.43/include/linux/intel-iommu.h 2011-08-05 20:33:55.000000000 -0400
59218@@ -296,7 +296,7 @@ struct iommu_flush {
59219 u8 fm, u64 type);
59220 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
59221 unsigned int size_order, u64 type);
59222-};
59223+} __no_const;
59224
59225 enum {
59226 SR_DMAR_FECTL_REG,
59227diff -urNp linux-2.6.32.43/include/linux/interrupt.h linux-2.6.32.43/include/linux/interrupt.h
59228--- linux-2.6.32.43/include/linux/interrupt.h 2011-06-25 12:55:35.000000000 -0400
59229+++ linux-2.6.32.43/include/linux/interrupt.h 2011-06-25 12:56:37.000000000 -0400
59230@@ -363,7 +363,7 @@ enum
59231 /* map softirq index to softirq name. update 'softirq_to_name' in
59232 * kernel/softirq.c when adding a new softirq.
59233 */
59234-extern char *softirq_to_name[NR_SOFTIRQS];
59235+extern const char * const softirq_to_name[NR_SOFTIRQS];
59236
59237 /* softirq mask and active fields moved to irq_cpustat_t in
59238 * asm/hardirq.h to get better cache usage. KAO
59239@@ -371,12 +371,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
59240
59241 struct softirq_action
59242 {
59243- void (*action)(struct softirq_action *);
59244+ void (*action)(void);
59245 };
59246
59247 asmlinkage void do_softirq(void);
59248 asmlinkage void __do_softirq(void);
59249-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
59250+extern void open_softirq(int nr, void (*action)(void));
59251 extern void softirq_init(void);
59252 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
59253 extern void raise_softirq_irqoff(unsigned int nr);
59254diff -urNp linux-2.6.32.43/include/linux/irq.h linux-2.6.32.43/include/linux/irq.h
59255--- linux-2.6.32.43/include/linux/irq.h 2011-03-27 14:31:47.000000000 -0400
59256+++ linux-2.6.32.43/include/linux/irq.h 2011-04-17 15:56:46.000000000 -0400
59257@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq,
59258 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
59259 bool boot)
59260 {
59261+#ifdef CONFIG_CPUMASK_OFFSTACK
59262 gfp_t gfp = GFP_ATOMIC;
59263
59264 if (boot)
59265 gfp = GFP_NOWAIT;
59266
59267-#ifdef CONFIG_CPUMASK_OFFSTACK
59268 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
59269 return false;
59270
59271diff -urNp linux-2.6.32.43/include/linux/kallsyms.h linux-2.6.32.43/include/linux/kallsyms.h
59272--- linux-2.6.32.43/include/linux/kallsyms.h 2011-03-27 14:31:47.000000000 -0400
59273+++ linux-2.6.32.43/include/linux/kallsyms.h 2011-04-17 15:56:46.000000000 -0400
59274@@ -15,7 +15,8 @@
59275
59276 struct module;
59277
59278-#ifdef CONFIG_KALLSYMS
59279+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
59280+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59281 /* Lookup the address for a symbol. Returns 0 if not found. */
59282 unsigned long kallsyms_lookup_name(const char *name);
59283
59284@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(un
59285 /* Stupid that this does nothing, but I didn't create this mess. */
59286 #define __print_symbol(fmt, addr)
59287 #endif /*CONFIG_KALLSYMS*/
59288+#else /* when included by kallsyms.c, vsnprintf.c, or
59289+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
59290+extern void __print_symbol(const char *fmt, unsigned long address);
59291+extern int sprint_symbol(char *buffer, unsigned long address);
59292+const char *kallsyms_lookup(unsigned long addr,
59293+ unsigned long *symbolsize,
59294+ unsigned long *offset,
59295+ char **modname, char *namebuf);
59296+#endif
59297
59298 /* This macro allows us to keep printk typechecking */
59299 static void __check_printsym_format(const char *fmt, ...)
59300diff -urNp linux-2.6.32.43/include/linux/kgdb.h linux-2.6.32.43/include/linux/kgdb.h
59301--- linux-2.6.32.43/include/linux/kgdb.h 2011-03-27 14:31:47.000000000 -0400
59302+++ linux-2.6.32.43/include/linux/kgdb.h 2011-08-05 20:33:55.000000000 -0400
59303@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
59304
59305 extern int kgdb_connected;
59306
59307-extern atomic_t kgdb_setting_breakpoint;
59308-extern atomic_t kgdb_cpu_doing_single_step;
59309+extern atomic_unchecked_t kgdb_setting_breakpoint;
59310+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
59311
59312 extern struct task_struct *kgdb_usethread;
59313 extern struct task_struct *kgdb_contthread;
59314@@ -226,8 +226,8 @@ extern int kgdb_arch_remove_breakpoint(u
59315 * hardware debug registers.
59316 */
59317 struct kgdb_arch {
59318- unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
59319- unsigned long flags;
59320+ const unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
59321+ const unsigned long flags;
59322
59323 int (*set_breakpoint)(unsigned long, char *);
59324 int (*remove_breakpoint)(unsigned long, char *);
59325@@ -251,20 +251,20 @@ struct kgdb_arch {
59326 */
59327 struct kgdb_io {
59328 const char *name;
59329- int (*read_char) (void);
59330- void (*write_char) (u8);
59331- void (*flush) (void);
59332- int (*init) (void);
59333- void (*pre_exception) (void);
59334- void (*post_exception) (void);
59335+ int (* const read_char) (void);
59336+ void (* const write_char) (u8);
59337+ void (* const flush) (void);
59338+ int (* const init) (void);
59339+ void (* const pre_exception) (void);
59340+ void (* const post_exception) (void);
59341 };
59342
59343-extern struct kgdb_arch arch_kgdb_ops;
59344+extern const struct kgdb_arch arch_kgdb_ops;
59345
59346 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
59347
59348-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
59349-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
59350+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
59351+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
59352
59353 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
59354 extern int kgdb_mem2hex(char *mem, char *buf, int count);
59355diff -urNp linux-2.6.32.43/include/linux/kmod.h linux-2.6.32.43/include/linux/kmod.h
59356--- linux-2.6.32.43/include/linux/kmod.h 2011-03-27 14:31:47.000000000 -0400
59357+++ linux-2.6.32.43/include/linux/kmod.h 2011-04-17 15:56:46.000000000 -0400
59358@@ -31,6 +31,8 @@
59359 * usually useless though. */
59360 extern int __request_module(bool wait, const char *name, ...) \
59361 __attribute__((format(printf, 2, 3)));
59362+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
59363+ __attribute__((format(printf, 3, 4)));
59364 #define request_module(mod...) __request_module(true, mod)
59365 #define request_module_nowait(mod...) __request_module(false, mod)
59366 #define try_then_request_module(x, mod...) \
59367diff -urNp linux-2.6.32.43/include/linux/kobject.h linux-2.6.32.43/include/linux/kobject.h
59368--- linux-2.6.32.43/include/linux/kobject.h 2011-03-27 14:31:47.000000000 -0400
59369+++ linux-2.6.32.43/include/linux/kobject.h 2011-04-17 15:56:46.000000000 -0400
59370@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kob
59371
59372 struct kobj_type {
59373 void (*release)(struct kobject *kobj);
59374- struct sysfs_ops *sysfs_ops;
59375+ const struct sysfs_ops *sysfs_ops;
59376 struct attribute **default_attrs;
59377 };
59378
59379@@ -118,9 +118,9 @@ struct kobj_uevent_env {
59380 };
59381
59382 struct kset_uevent_ops {
59383- int (*filter)(struct kset *kset, struct kobject *kobj);
59384- const char *(*name)(struct kset *kset, struct kobject *kobj);
59385- int (*uevent)(struct kset *kset, struct kobject *kobj,
59386+ int (* const filter)(struct kset *kset, struct kobject *kobj);
59387+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
59388+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
59389 struct kobj_uevent_env *env);
59390 };
59391
59392@@ -132,7 +132,7 @@ struct kobj_attribute {
59393 const char *buf, size_t count);
59394 };
59395
59396-extern struct sysfs_ops kobj_sysfs_ops;
59397+extern const struct sysfs_ops kobj_sysfs_ops;
59398
59399 /**
59400 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
59401@@ -155,14 +155,14 @@ struct kset {
59402 struct list_head list;
59403 spinlock_t list_lock;
59404 struct kobject kobj;
59405- struct kset_uevent_ops *uevent_ops;
59406+ const struct kset_uevent_ops *uevent_ops;
59407 };
59408
59409 extern void kset_init(struct kset *kset);
59410 extern int __must_check kset_register(struct kset *kset);
59411 extern void kset_unregister(struct kset *kset);
59412 extern struct kset * __must_check kset_create_and_add(const char *name,
59413- struct kset_uevent_ops *u,
59414+ const struct kset_uevent_ops *u,
59415 struct kobject *parent_kobj);
59416
59417 static inline struct kset *to_kset(struct kobject *kobj)
59418diff -urNp linux-2.6.32.43/include/linux/kvm_host.h linux-2.6.32.43/include/linux/kvm_host.h
59419--- linux-2.6.32.43/include/linux/kvm_host.h 2011-03-27 14:31:47.000000000 -0400
59420+++ linux-2.6.32.43/include/linux/kvm_host.h 2011-04-17 15:56:46.000000000 -0400
59421@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
59422 void vcpu_load(struct kvm_vcpu *vcpu);
59423 void vcpu_put(struct kvm_vcpu *vcpu);
59424
59425-int kvm_init(void *opaque, unsigned int vcpu_size,
59426+int kvm_init(const void *opaque, unsigned int vcpu_size,
59427 struct module *module);
59428 void kvm_exit(void);
59429
59430@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
59431 struct kvm_guest_debug *dbg);
59432 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
59433
59434-int kvm_arch_init(void *opaque);
59435+int kvm_arch_init(const void *opaque);
59436 void kvm_arch_exit(void);
59437
59438 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
59439diff -urNp linux-2.6.32.43/include/linux/libata.h linux-2.6.32.43/include/linux/libata.h
59440--- linux-2.6.32.43/include/linux/libata.h 2011-03-27 14:31:47.000000000 -0400
59441+++ linux-2.6.32.43/include/linux/libata.h 2011-08-05 20:33:55.000000000 -0400
59442@@ -525,11 +525,11 @@ struct ata_ioports {
59443
59444 struct ata_host {
59445 spinlock_t lock;
59446- struct device *dev;
59447+ struct device *dev;
59448 void __iomem * const *iomap;
59449 unsigned int n_ports;
59450 void *private_data;
59451- struct ata_port_operations *ops;
59452+ const struct ata_port_operations *ops;
59453 unsigned long flags;
59454 #ifdef CONFIG_ATA_ACPI
59455 acpi_handle acpi_handle;
59456@@ -710,7 +710,7 @@ struct ata_link {
59457
59458 struct ata_port {
59459 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
59460- struct ata_port_operations *ops;
59461+ const struct ata_port_operations *ops;
59462 spinlock_t *lock;
59463 /* Flags owned by the EH context. Only EH should touch these once the
59464 port is active */
59465@@ -883,7 +883,7 @@ struct ata_port_operations {
59466 * ->inherits must be the last field and all the preceding
59467 * fields must be pointers.
59468 */
59469- const struct ata_port_operations *inherits;
59470+ const struct ata_port_operations * const inherits;
59471 };
59472
59473 struct ata_port_info {
59474@@ -892,7 +892,7 @@ struct ata_port_info {
59475 unsigned long pio_mask;
59476 unsigned long mwdma_mask;
59477 unsigned long udma_mask;
59478- struct ata_port_operations *port_ops;
59479+ const struct ata_port_operations *port_ops;
59480 void *private_data;
59481 };
59482
59483@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timi
59484 extern const unsigned long sata_deb_timing_hotplug[];
59485 extern const unsigned long sata_deb_timing_long[];
59486
59487-extern struct ata_port_operations ata_dummy_port_ops;
59488+extern const struct ata_port_operations ata_dummy_port_ops;
59489 extern const struct ata_port_info ata_dummy_port_info;
59490
59491 static inline const unsigned long *
59492@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_
59493 struct scsi_host_template *sht);
59494 extern void ata_host_detach(struct ata_host *host);
59495 extern void ata_host_init(struct ata_host *, struct device *,
59496- unsigned long, struct ata_port_operations *);
59497+ unsigned long, const struct ata_port_operations *);
59498 extern int ata_scsi_detect(struct scsi_host_template *sht);
59499 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
59500 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
59501diff -urNp linux-2.6.32.43/include/linux/lockd/bind.h linux-2.6.32.43/include/linux/lockd/bind.h
59502--- linux-2.6.32.43/include/linux/lockd/bind.h 2011-03-27 14:31:47.000000000 -0400
59503+++ linux-2.6.32.43/include/linux/lockd/bind.h 2011-04-17 15:56:46.000000000 -0400
59504@@ -23,13 +23,13 @@ struct svc_rqst;
59505 * This is the set of functions for lockd->nfsd communication
59506 */
59507 struct nlmsvc_binding {
59508- __be32 (*fopen)(struct svc_rqst *,
59509+ __be32 (* const fopen)(struct svc_rqst *,
59510 struct nfs_fh *,
59511 struct file **);
59512- void (*fclose)(struct file *);
59513+ void (* const fclose)(struct file *);
59514 };
59515
59516-extern struct nlmsvc_binding * nlmsvc_ops;
59517+extern const struct nlmsvc_binding * nlmsvc_ops;
59518
59519 /*
59520 * Similar to nfs_client_initdata, but without the NFS-specific
59521diff -urNp linux-2.6.32.43/include/linux/mca.h linux-2.6.32.43/include/linux/mca.h
59522--- linux-2.6.32.43/include/linux/mca.h 2011-03-27 14:31:47.000000000 -0400
59523+++ linux-2.6.32.43/include/linux/mca.h 2011-08-05 20:33:55.000000000 -0400
59524@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
59525 int region);
59526 void * (*mca_transform_memory)(struct mca_device *,
59527 void *memory);
59528-};
59529+} __no_const;
59530
59531 struct mca_bus {
59532 u64 default_dma_mask;
59533diff -urNp linux-2.6.32.43/include/linux/memory.h linux-2.6.32.43/include/linux/memory.h
59534--- linux-2.6.32.43/include/linux/memory.h 2011-03-27 14:31:47.000000000 -0400
59535+++ linux-2.6.32.43/include/linux/memory.h 2011-08-05 20:33:55.000000000 -0400
59536@@ -108,7 +108,7 @@ struct memory_accessor {
59537 size_t count);
59538 ssize_t (*write)(struct memory_accessor *, const char *buf,
59539 off_t offset, size_t count);
59540-};
59541+} __no_const;
59542
59543 /*
59544 * Kernel text modification mutex, used for code patching. Users of this lock
59545diff -urNp linux-2.6.32.43/include/linux/mm.h linux-2.6.32.43/include/linux/mm.h
59546--- linux-2.6.32.43/include/linux/mm.h 2011-03-27 14:31:47.000000000 -0400
59547+++ linux-2.6.32.43/include/linux/mm.h 2011-04-17 15:56:46.000000000 -0400
59548@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void
59549
59550 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
59551 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
59552+
59553+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
59554+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
59555+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
59556+#else
59557 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
59558+#endif
59559+
59560 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
59561 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
59562
59563@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
59564 int set_page_dirty_lock(struct page *page);
59565 int clear_page_dirty_for_io(struct page *page);
59566
59567-/* Is the vma a continuation of the stack vma above it? */
59568-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
59569-{
59570- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
59571-}
59572-
59573 extern unsigned long move_page_tables(struct vm_area_struct *vma,
59574 unsigned long old_addr, struct vm_area_struct *new_vma,
59575 unsigned long new_addr, unsigned long len);
59576@@ -890,6 +891,8 @@ struct shrinker {
59577 extern void register_shrinker(struct shrinker *);
59578 extern void unregister_shrinker(struct shrinker *);
59579
59580+pgprot_t vm_get_page_prot(unsigned long vm_flags);
59581+
59582 int vma_wants_writenotify(struct vm_area_struct *vma);
59583
59584 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
59585@@ -1162,6 +1165,7 @@ out:
59586 }
59587
59588 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
59589+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
59590
59591 extern unsigned long do_brk(unsigned long, unsigned long);
59592
59593@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(
59594 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
59595 struct vm_area_struct **pprev);
59596
59597+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
59598+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
59599+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
59600+
59601 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
59602 NULL if none. Assume start_addr < end_addr. */
59603 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
59604@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(st
59605 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
59606 }
59607
59608-pgprot_t vm_get_page_prot(unsigned long vm_flags);
59609 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
59610 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
59611 unsigned long pfn, unsigned long size, pgprot_t);
59612@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long
59613 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
59614 extern int sysctl_memory_failure_early_kill;
59615 extern int sysctl_memory_failure_recovery;
59616-extern atomic_long_t mce_bad_pages;
59617+extern atomic_long_unchecked_t mce_bad_pages;
59618+
59619+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59620+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
59621+#else
59622+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
59623+#endif
59624
59625 #endif /* __KERNEL__ */
59626 #endif /* _LINUX_MM_H */
59627diff -urNp linux-2.6.32.43/include/linux/mm_types.h linux-2.6.32.43/include/linux/mm_types.h
59628--- linux-2.6.32.43/include/linux/mm_types.h 2011-03-27 14:31:47.000000000 -0400
59629+++ linux-2.6.32.43/include/linux/mm_types.h 2011-04-17 15:56:46.000000000 -0400
59630@@ -186,6 +186,8 @@ struct vm_area_struct {
59631 #ifdef CONFIG_NUMA
59632 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
59633 #endif
59634+
59635+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
59636 };
59637
59638 struct core_thread {
59639@@ -287,6 +289,24 @@ struct mm_struct {
59640 #ifdef CONFIG_MMU_NOTIFIER
59641 struct mmu_notifier_mm *mmu_notifier_mm;
59642 #endif
59643+
59644+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59645+ unsigned long pax_flags;
59646+#endif
59647+
59648+#ifdef CONFIG_PAX_DLRESOLVE
59649+ unsigned long call_dl_resolve;
59650+#endif
59651+
59652+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59653+ unsigned long call_syscall;
59654+#endif
59655+
59656+#ifdef CONFIG_PAX_ASLR
59657+ unsigned long delta_mmap; /* randomized offset */
59658+ unsigned long delta_stack; /* randomized offset */
59659+#endif
59660+
59661 };
59662
59663 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
59664diff -urNp linux-2.6.32.43/include/linux/mmu_notifier.h linux-2.6.32.43/include/linux/mmu_notifier.h
59665--- linux-2.6.32.43/include/linux/mmu_notifier.h 2011-03-27 14:31:47.000000000 -0400
59666+++ linux-2.6.32.43/include/linux/mmu_notifier.h 2011-04-17 15:56:46.000000000 -0400
59667@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destr
59668 */
59669 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
59670 ({ \
59671- pte_t __pte; \
59672+ pte_t ___pte; \
59673 struct vm_area_struct *___vma = __vma; \
59674 unsigned long ___address = __address; \
59675- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
59676+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
59677 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
59678- __pte; \
59679+ ___pte; \
59680 })
59681
59682 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
59683diff -urNp linux-2.6.32.43/include/linux/mmzone.h linux-2.6.32.43/include/linux/mmzone.h
59684--- linux-2.6.32.43/include/linux/mmzone.h 2011-03-27 14:31:47.000000000 -0400
59685+++ linux-2.6.32.43/include/linux/mmzone.h 2011-04-17 15:56:46.000000000 -0400
59686@@ -350,7 +350,7 @@ struct zone {
59687 unsigned long flags; /* zone flags, see below */
59688
59689 /* Zone statistics */
59690- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
59691+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
59692
59693 /*
59694 * prev_priority holds the scanning priority for this zone. It is
59695diff -urNp linux-2.6.32.43/include/linux/mod_devicetable.h linux-2.6.32.43/include/linux/mod_devicetable.h
59696--- linux-2.6.32.43/include/linux/mod_devicetable.h 2011-03-27 14:31:47.000000000 -0400
59697+++ linux-2.6.32.43/include/linux/mod_devicetable.h 2011-04-17 15:56:46.000000000 -0400
59698@@ -12,7 +12,7 @@
59699 typedef unsigned long kernel_ulong_t;
59700 #endif
59701
59702-#define PCI_ANY_ID (~0)
59703+#define PCI_ANY_ID ((__u16)~0)
59704
59705 struct pci_device_id {
59706 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
59707@@ -131,7 +131,7 @@ struct usb_device_id {
59708 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
59709 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
59710
59711-#define HID_ANY_ID (~0)
59712+#define HID_ANY_ID (~0U)
59713
59714 struct hid_device_id {
59715 __u16 bus;
59716diff -urNp linux-2.6.32.43/include/linux/module.h linux-2.6.32.43/include/linux/module.h
59717--- linux-2.6.32.43/include/linux/module.h 2011-03-27 14:31:47.000000000 -0400
59718+++ linux-2.6.32.43/include/linux/module.h 2011-08-05 20:33:55.000000000 -0400
59719@@ -16,6 +16,7 @@
59720 #include <linux/kobject.h>
59721 #include <linux/moduleparam.h>
59722 #include <linux/tracepoint.h>
59723+#include <linux/fs.h>
59724
59725 #include <asm/local.h>
59726 #include <asm/module.h>
59727@@ -287,16 +288,16 @@ struct module
59728 int (*init)(void);
59729
59730 /* If this is non-NULL, vfree after init() returns */
59731- void *module_init;
59732+ void *module_init_rx, *module_init_rw;
59733
59734 /* Here is the actual code + data, vfree'd on unload. */
59735- void *module_core;
59736+ void *module_core_rx, *module_core_rw;
59737
59738 /* Here are the sizes of the init and core sections */
59739- unsigned int init_size, core_size;
59740+ unsigned int init_size_rw, core_size_rw;
59741
59742 /* The size of the executable code in each section. */
59743- unsigned int init_text_size, core_text_size;
59744+ unsigned int init_size_rx, core_size_rx;
59745
59746 /* Arch-specific module values */
59747 struct mod_arch_specific arch;
59748@@ -345,6 +346,10 @@ struct module
59749 #ifdef CONFIG_EVENT_TRACING
59750 struct ftrace_event_call *trace_events;
59751 unsigned int num_trace_events;
59752+ struct file_operations trace_id;
59753+ struct file_operations trace_enable;
59754+ struct file_operations trace_format;
59755+ struct file_operations trace_filter;
59756 #endif
59757 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
59758 unsigned long *ftrace_callsites;
59759@@ -393,16 +398,46 @@ struct module *__module_address(unsigned
59760 bool is_module_address(unsigned long addr);
59761 bool is_module_text_address(unsigned long addr);
59762
59763+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
59764+{
59765+
59766+#ifdef CONFIG_PAX_KERNEXEC
59767+ if (ktla_ktva(addr) >= (unsigned long)start &&
59768+ ktla_ktva(addr) < (unsigned long)start + size)
59769+ return 1;
59770+#endif
59771+
59772+ return ((void *)addr >= start && (void *)addr < start + size);
59773+}
59774+
59775+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
59776+{
59777+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
59778+}
59779+
59780+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
59781+{
59782+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
59783+}
59784+
59785+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
59786+{
59787+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
59788+}
59789+
59790+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
59791+{
59792+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
59793+}
59794+
59795 static inline int within_module_core(unsigned long addr, struct module *mod)
59796 {
59797- return (unsigned long)mod->module_core <= addr &&
59798- addr < (unsigned long)mod->module_core + mod->core_size;
59799+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
59800 }
59801
59802 static inline int within_module_init(unsigned long addr, struct module *mod)
59803 {
59804- return (unsigned long)mod->module_init <= addr &&
59805- addr < (unsigned long)mod->module_init + mod->init_size;
59806+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
59807 }
59808
59809 /* Search for module by name: must hold module_mutex. */
59810diff -urNp linux-2.6.32.43/include/linux/moduleloader.h linux-2.6.32.43/include/linux/moduleloader.h
59811--- linux-2.6.32.43/include/linux/moduleloader.h 2011-03-27 14:31:47.000000000 -0400
59812+++ linux-2.6.32.43/include/linux/moduleloader.h 2011-04-17 15:56:46.000000000 -0400
59813@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
59814 sections. Returns NULL on failure. */
59815 void *module_alloc(unsigned long size);
59816
59817+#ifdef CONFIG_PAX_KERNEXEC
59818+void *module_alloc_exec(unsigned long size);
59819+#else
59820+#define module_alloc_exec(x) module_alloc(x)
59821+#endif
59822+
59823 /* Free memory returned from module_alloc. */
59824 void module_free(struct module *mod, void *module_region);
59825
59826+#ifdef CONFIG_PAX_KERNEXEC
59827+void module_free_exec(struct module *mod, void *module_region);
59828+#else
59829+#define module_free_exec(x, y) module_free((x), (y))
59830+#endif
59831+
59832 /* Apply the given relocation to the (simplified) ELF. Return -error
59833 or 0. */
59834 int apply_relocate(Elf_Shdr *sechdrs,
59835diff -urNp linux-2.6.32.43/include/linux/moduleparam.h linux-2.6.32.43/include/linux/moduleparam.h
59836--- linux-2.6.32.43/include/linux/moduleparam.h 2011-03-27 14:31:47.000000000 -0400
59837+++ linux-2.6.32.43/include/linux/moduleparam.h 2011-04-17 15:56:46.000000000 -0400
59838@@ -132,7 +132,7 @@ struct kparam_array
59839
59840 /* Actually copy string: maxlen param is usually sizeof(string). */
59841 #define module_param_string(name, string, len, perm) \
59842- static const struct kparam_string __param_string_##name \
59843+ static const struct kparam_string __param_string_##name __used \
59844 = { len, string }; \
59845 __module_param_call(MODULE_PARAM_PREFIX, name, \
59846 param_set_copystring, param_get_string, \
59847@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffe
59848
59849 /* Comma-separated array: *nump is set to number they actually specified. */
59850 #define module_param_array_named(name, array, type, nump, perm) \
59851- static const struct kparam_array __param_arr_##name \
59852+ static const struct kparam_array __param_arr_##name __used \
59853 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
59854 sizeof(array[0]), array }; \
59855 __module_param_call(MODULE_PARAM_PREFIX, name, \
59856diff -urNp linux-2.6.32.43/include/linux/mutex.h linux-2.6.32.43/include/linux/mutex.h
59857--- linux-2.6.32.43/include/linux/mutex.h 2011-03-27 14:31:47.000000000 -0400
59858+++ linux-2.6.32.43/include/linux/mutex.h 2011-04-17 15:56:46.000000000 -0400
59859@@ -51,7 +51,7 @@ struct mutex {
59860 spinlock_t wait_lock;
59861 struct list_head wait_list;
59862 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
59863- struct thread_info *owner;
59864+ struct task_struct *owner;
59865 #endif
59866 #ifdef CONFIG_DEBUG_MUTEXES
59867 const char *name;
59868diff -urNp linux-2.6.32.43/include/linux/namei.h linux-2.6.32.43/include/linux/namei.h
59869--- linux-2.6.32.43/include/linux/namei.h 2011-03-27 14:31:47.000000000 -0400
59870+++ linux-2.6.32.43/include/linux/namei.h 2011-04-17 15:56:46.000000000 -0400
59871@@ -22,7 +22,7 @@ struct nameidata {
59872 unsigned int flags;
59873 int last_type;
59874 unsigned depth;
59875- char *saved_names[MAX_NESTED_LINKS + 1];
59876+ const char *saved_names[MAX_NESTED_LINKS + 1];
59877
59878 /* Intent data */
59879 union {
59880@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
59881 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
59882 extern void unlock_rename(struct dentry *, struct dentry *);
59883
59884-static inline void nd_set_link(struct nameidata *nd, char *path)
59885+static inline void nd_set_link(struct nameidata *nd, const char *path)
59886 {
59887 nd->saved_names[nd->depth] = path;
59888 }
59889
59890-static inline char *nd_get_link(struct nameidata *nd)
59891+static inline const char *nd_get_link(const struct nameidata *nd)
59892 {
59893 return nd->saved_names[nd->depth];
59894 }
59895diff -urNp linux-2.6.32.43/include/linux/netfilter/xt_gradm.h linux-2.6.32.43/include/linux/netfilter/xt_gradm.h
59896--- linux-2.6.32.43/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
59897+++ linux-2.6.32.43/include/linux/netfilter/xt_gradm.h 2011-04-17 15:56:46.000000000 -0400
59898@@ -0,0 +1,9 @@
59899+#ifndef _LINUX_NETFILTER_XT_GRADM_H
59900+#define _LINUX_NETFILTER_XT_GRADM_H 1
59901+
59902+struct xt_gradm_mtinfo {
59903+ __u16 flags;
59904+ __u16 invflags;
59905+};
59906+
59907+#endif
59908diff -urNp linux-2.6.32.43/include/linux/nodemask.h linux-2.6.32.43/include/linux/nodemask.h
59909--- linux-2.6.32.43/include/linux/nodemask.h 2011-03-27 14:31:47.000000000 -0400
59910+++ linux-2.6.32.43/include/linux/nodemask.h 2011-04-17 15:56:46.000000000 -0400
59911@@ -464,11 +464,11 @@ static inline int num_node_state(enum no
59912
59913 #define any_online_node(mask) \
59914 ({ \
59915- int node; \
59916- for_each_node_mask(node, (mask)) \
59917- if (node_online(node)) \
59918+ int __node; \
59919+ for_each_node_mask(__node, (mask)) \
59920+ if (node_online(__node)) \
59921 break; \
59922- node; \
59923+ __node; \
59924 })
59925
59926 #define num_online_nodes() num_node_state(N_ONLINE)
59927diff -urNp linux-2.6.32.43/include/linux/oprofile.h linux-2.6.32.43/include/linux/oprofile.h
59928--- linux-2.6.32.43/include/linux/oprofile.h 2011-03-27 14:31:47.000000000 -0400
59929+++ linux-2.6.32.43/include/linux/oprofile.h 2011-04-17 15:56:46.000000000 -0400
59930@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super
59931 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
59932 char const * name, ulong * val);
59933
59934-/** Create a file for read-only access to an atomic_t. */
59935+/** Create a file for read-only access to an atomic_unchecked_t. */
59936 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
59937- char const * name, atomic_t * val);
59938+ char const * name, atomic_unchecked_t * val);
59939
59940 /** create a directory */
59941 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
59942diff -urNp linux-2.6.32.43/include/linux/perf_event.h linux-2.6.32.43/include/linux/perf_event.h
59943--- linux-2.6.32.43/include/linux/perf_event.h 2011-03-27 14:31:47.000000000 -0400
59944+++ linux-2.6.32.43/include/linux/perf_event.h 2011-05-04 17:56:28.000000000 -0400
59945@@ -476,7 +476,7 @@ struct hw_perf_event {
59946 struct hrtimer hrtimer;
59947 };
59948 };
59949- atomic64_t prev_count;
59950+ atomic64_unchecked_t prev_count;
59951 u64 sample_period;
59952 u64 last_period;
59953 atomic64_t period_left;
59954@@ -557,7 +557,7 @@ struct perf_event {
59955 const struct pmu *pmu;
59956
59957 enum perf_event_active_state state;
59958- atomic64_t count;
59959+ atomic64_unchecked_t count;
59960
59961 /*
59962 * These are the total time in nanoseconds that the event
59963@@ -595,8 +595,8 @@ struct perf_event {
59964 * These accumulate total time (in nanoseconds) that children
59965 * events have been enabled and running, respectively.
59966 */
59967- atomic64_t child_total_time_enabled;
59968- atomic64_t child_total_time_running;
59969+ atomic64_unchecked_t child_total_time_enabled;
59970+ atomic64_unchecked_t child_total_time_running;
59971
59972 /*
59973 * Protect attach/detach and child_list:
59974diff -urNp linux-2.6.32.43/include/linux/pipe_fs_i.h linux-2.6.32.43/include/linux/pipe_fs_i.h
59975--- linux-2.6.32.43/include/linux/pipe_fs_i.h 2011-03-27 14:31:47.000000000 -0400
59976+++ linux-2.6.32.43/include/linux/pipe_fs_i.h 2011-04-17 15:56:46.000000000 -0400
59977@@ -46,9 +46,9 @@ struct pipe_inode_info {
59978 wait_queue_head_t wait;
59979 unsigned int nrbufs, curbuf;
59980 struct page *tmp_page;
59981- unsigned int readers;
59982- unsigned int writers;
59983- unsigned int waiting_writers;
59984+ atomic_t readers;
59985+ atomic_t writers;
59986+ atomic_t waiting_writers;
59987 unsigned int r_counter;
59988 unsigned int w_counter;
59989 struct fasync_struct *fasync_readers;
59990diff -urNp linux-2.6.32.43/include/linux/poison.h linux-2.6.32.43/include/linux/poison.h
59991--- linux-2.6.32.43/include/linux/poison.h 2011-03-27 14:31:47.000000000 -0400
59992+++ linux-2.6.32.43/include/linux/poison.h 2011-04-17 15:56:46.000000000 -0400
59993@@ -19,8 +19,8 @@
59994 * under normal circumstances, used to verify that nobody uses
59995 * non-initialized list entries.
59996 */
59997-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
59998-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
59999+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
60000+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
60001
60002 /********** include/linux/timer.h **********/
60003 /*
60004diff -urNp linux-2.6.32.43/include/linux/posix-timers.h linux-2.6.32.43/include/linux/posix-timers.h
60005--- linux-2.6.32.43/include/linux/posix-timers.h 2011-03-27 14:31:47.000000000 -0400
60006+++ linux-2.6.32.43/include/linux/posix-timers.h 2011-08-05 20:33:55.000000000 -0400
60007@@ -67,7 +67,7 @@ struct k_itimer {
60008 };
60009
60010 struct k_clock {
60011- int res; /* in nanoseconds */
60012+ const int res; /* in nanoseconds */
60013 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
60014 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
60015 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
60016diff -urNp linux-2.6.32.43/include/linux/preempt.h linux-2.6.32.43/include/linux/preempt.h
60017--- linux-2.6.32.43/include/linux/preempt.h 2011-03-27 14:31:47.000000000 -0400
60018+++ linux-2.6.32.43/include/linux/preempt.h 2011-08-05 20:33:55.000000000 -0400
60019@@ -110,7 +110,7 @@ struct preempt_ops {
60020 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
60021 void (*sched_out)(struct preempt_notifier *notifier,
60022 struct task_struct *next);
60023-};
60024+} __no_const;
60025
60026 /**
60027 * preempt_notifier - key for installing preemption notifiers
60028diff -urNp linux-2.6.32.43/include/linux/proc_fs.h linux-2.6.32.43/include/linux/proc_fs.h
60029--- linux-2.6.32.43/include/linux/proc_fs.h 2011-03-27 14:31:47.000000000 -0400
60030+++ linux-2.6.32.43/include/linux/proc_fs.h 2011-08-05 20:33:55.000000000 -0400
60031@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
60032 return proc_create_data(name, mode, parent, proc_fops, NULL);
60033 }
60034
60035+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
60036+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
60037+{
60038+#ifdef CONFIG_GRKERNSEC_PROC_USER
60039+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
60040+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60041+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
60042+#else
60043+ return proc_create_data(name, mode, parent, proc_fops, NULL);
60044+#endif
60045+}
60046+
60047+
60048 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
60049 mode_t mode, struct proc_dir_entry *base,
60050 read_proc_t *read_proc, void * data)
60051@@ -256,7 +269,7 @@ union proc_op {
60052 int (*proc_show)(struct seq_file *m,
60053 struct pid_namespace *ns, struct pid *pid,
60054 struct task_struct *task);
60055-};
60056+} __no_const;
60057
60058 struct ctl_table_header;
60059 struct ctl_table;
60060diff -urNp linux-2.6.32.43/include/linux/ptrace.h linux-2.6.32.43/include/linux/ptrace.h
60061--- linux-2.6.32.43/include/linux/ptrace.h 2011-03-27 14:31:47.000000000 -0400
60062+++ linux-2.6.32.43/include/linux/ptrace.h 2011-04-17 15:56:46.000000000 -0400
60063@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_
60064 extern void exit_ptrace(struct task_struct *tracer);
60065 #define PTRACE_MODE_READ 1
60066 #define PTRACE_MODE_ATTACH 2
60067-/* Returns 0 on success, -errno on denial. */
60068-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
60069 /* Returns true on success, false on denial. */
60070 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
60071+/* Returns true on success, false on denial. */
60072+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
60073
60074 static inline int ptrace_reparented(struct task_struct *child)
60075 {
60076diff -urNp linux-2.6.32.43/include/linux/random.h linux-2.6.32.43/include/linux/random.h
60077--- linux-2.6.32.43/include/linux/random.h 2011-03-27 14:31:47.000000000 -0400
60078+++ linux-2.6.32.43/include/linux/random.h 2011-04-17 15:56:46.000000000 -0400
60079@@ -74,6 +74,11 @@ unsigned long randomize_range(unsigned l
60080 u32 random32(void);
60081 void srandom32(u32 seed);
60082
60083+static inline unsigned long pax_get_random_long(void)
60084+{
60085+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
60086+}
60087+
60088 #endif /* __KERNEL___ */
60089
60090 #endif /* _LINUX_RANDOM_H */
60091diff -urNp linux-2.6.32.43/include/linux/reboot.h linux-2.6.32.43/include/linux/reboot.h
60092--- linux-2.6.32.43/include/linux/reboot.h 2011-03-27 14:31:47.000000000 -0400
60093+++ linux-2.6.32.43/include/linux/reboot.h 2011-05-22 23:02:06.000000000 -0400
60094@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
60095 * Architecture-specific implementations of sys_reboot commands.
60096 */
60097
60098-extern void machine_restart(char *cmd);
60099-extern void machine_halt(void);
60100-extern void machine_power_off(void);
60101+extern void machine_restart(char *cmd) __noreturn;
60102+extern void machine_halt(void) __noreturn;
60103+extern void machine_power_off(void) __noreturn;
60104
60105 extern void machine_shutdown(void);
60106 struct pt_regs;
60107@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
60108 */
60109
60110 extern void kernel_restart_prepare(char *cmd);
60111-extern void kernel_restart(char *cmd);
60112-extern void kernel_halt(void);
60113-extern void kernel_power_off(void);
60114+extern void kernel_restart(char *cmd) __noreturn;
60115+extern void kernel_halt(void) __noreturn;
60116+extern void kernel_power_off(void) __noreturn;
60117
60118 void ctrl_alt_del(void);
60119
60120@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
60121 * Emergency restart, callable from an interrupt handler.
60122 */
60123
60124-extern void emergency_restart(void);
60125+extern void emergency_restart(void) __noreturn;
60126 #include <asm/emergency-restart.h>
60127
60128 #endif
60129diff -urNp linux-2.6.32.43/include/linux/reiserfs_fs.h linux-2.6.32.43/include/linux/reiserfs_fs.h
60130--- linux-2.6.32.43/include/linux/reiserfs_fs.h 2011-03-27 14:31:47.000000000 -0400
60131+++ linux-2.6.32.43/include/linux/reiserfs_fs.h 2011-04-17 15:56:46.000000000 -0400
60132@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset
60133 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60134
60135 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60136-#define get_generation(s) atomic_read (&fs_generation(s))
60137+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60138 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60139 #define __fs_changed(gen,s) (gen != get_generation (s))
60140 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
60141@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_fro
60142 */
60143
60144 struct item_operations {
60145- int (*bytes_number) (struct item_head * ih, int block_size);
60146- void (*decrement_key) (struct cpu_key *);
60147- int (*is_left_mergeable) (struct reiserfs_key * ih,
60148+ int (* const bytes_number) (struct item_head * ih, int block_size);
60149+ void (* const decrement_key) (struct cpu_key *);
60150+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
60151 unsigned long bsize);
60152- void (*print_item) (struct item_head *, char *item);
60153- void (*check_item) (struct item_head *, char *item);
60154+ void (* const print_item) (struct item_head *, char *item);
60155+ void (* const check_item) (struct item_head *, char *item);
60156
60157- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
60158+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
60159 int is_affected, int insert_size);
60160- int (*check_left) (struct virtual_item * vi, int free,
60161+ int (* const check_left) (struct virtual_item * vi, int free,
60162 int start_skip, int end_skip);
60163- int (*check_right) (struct virtual_item * vi, int free);
60164- int (*part_size) (struct virtual_item * vi, int from, int to);
60165- int (*unit_num) (struct virtual_item * vi);
60166- void (*print_vi) (struct virtual_item * vi);
60167+ int (* const check_right) (struct virtual_item * vi, int free);
60168+ int (* const part_size) (struct virtual_item * vi, int from, int to);
60169+ int (* const unit_num) (struct virtual_item * vi);
60170+ void (* const print_vi) (struct virtual_item * vi);
60171 };
60172
60173-extern struct item_operations *item_ops[TYPE_ANY + 1];
60174+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
60175
60176 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
60177 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
60178diff -urNp linux-2.6.32.43/include/linux/reiserfs_fs_sb.h linux-2.6.32.43/include/linux/reiserfs_fs_sb.h
60179--- linux-2.6.32.43/include/linux/reiserfs_fs_sb.h 2011-03-27 14:31:47.000000000 -0400
60180+++ linux-2.6.32.43/include/linux/reiserfs_fs_sb.h 2011-04-17 15:56:46.000000000 -0400
60181@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
60182 /* Comment? -Hans */
60183 wait_queue_head_t s_wait;
60184 /* To be obsoleted soon by per buffer seals.. -Hans */
60185- atomic_t s_generation_counter; // increased by one every time the
60186+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60187 // tree gets re-balanced
60188 unsigned long s_properties; /* File system properties. Currently holds
60189 on-disk FS format */
60190diff -urNp linux-2.6.32.43/include/linux/relay.h linux-2.6.32.43/include/linux/relay.h
60191--- linux-2.6.32.43/include/linux/relay.h 2011-03-27 14:31:47.000000000 -0400
60192+++ linux-2.6.32.43/include/linux/relay.h 2011-08-05 20:33:55.000000000 -0400
60193@@ -159,7 +159,7 @@ struct rchan_callbacks
60194 * The callback should return 0 if successful, negative if not.
60195 */
60196 int (*remove_buf_file)(struct dentry *dentry);
60197-};
60198+} __no_const;
60199
60200 /*
60201 * CONFIG_RELAY kernel API, kernel/relay.c
60202diff -urNp linux-2.6.32.43/include/linux/sched.h linux-2.6.32.43/include/linux/sched.h
60203--- linux-2.6.32.43/include/linux/sched.h 2011-03-27 14:31:47.000000000 -0400
60204+++ linux-2.6.32.43/include/linux/sched.h 2011-08-05 20:33:55.000000000 -0400
60205@@ -101,6 +101,7 @@ struct bio;
60206 struct fs_struct;
60207 struct bts_context;
60208 struct perf_event_context;
60209+struct linux_binprm;
60210
60211 /*
60212 * List of flags we want to share for kernel threads,
60213@@ -350,7 +351,7 @@ extern signed long schedule_timeout_kill
60214 extern signed long schedule_timeout_uninterruptible(signed long timeout);
60215 asmlinkage void __schedule(void);
60216 asmlinkage void schedule(void);
60217-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
60218+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
60219
60220 struct nsproxy;
60221 struct user_namespace;
60222@@ -371,9 +372,12 @@ struct user_namespace;
60223 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
60224
60225 extern int sysctl_max_map_count;
60226+extern unsigned long sysctl_heap_stack_gap;
60227
60228 #include <linux/aio.h>
60229
60230+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
60231+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
60232 extern unsigned long
60233 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
60234 unsigned long, unsigned long);
60235@@ -666,6 +670,16 @@ struct signal_struct {
60236 struct tty_audit_buf *tty_audit_buf;
60237 #endif
60238
60239+#ifdef CONFIG_GRKERNSEC
60240+ u32 curr_ip;
60241+ u32 saved_ip;
60242+ u32 gr_saddr;
60243+ u32 gr_daddr;
60244+ u16 gr_sport;
60245+ u16 gr_dport;
60246+ u8 used_accept:1;
60247+#endif
60248+
60249 int oom_adj; /* OOM kill score adjustment (bit shift) */
60250 };
60251
60252@@ -723,6 +737,11 @@ struct user_struct {
60253 struct key *session_keyring; /* UID's default session keyring */
60254 #endif
60255
60256+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60257+ unsigned int banned;
60258+ unsigned long ban_expires;
60259+#endif
60260+
60261 /* Hash table maintenance information */
60262 struct hlist_node uidhash_node;
60263 uid_t uid;
60264@@ -1328,8 +1347,8 @@ struct task_struct {
60265 struct list_head thread_group;
60266
60267 struct completion *vfork_done; /* for vfork() */
60268- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
60269- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60270+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
60271+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60272
60273 cputime_t utime, stime, utimescaled, stimescaled;
60274 cputime_t gtime;
60275@@ -1343,16 +1362,6 @@ struct task_struct {
60276 struct task_cputime cputime_expires;
60277 struct list_head cpu_timers[3];
60278
60279-/* process credentials */
60280- const struct cred *real_cred; /* objective and real subjective task
60281- * credentials (COW) */
60282- const struct cred *cred; /* effective (overridable) subjective task
60283- * credentials (COW) */
60284- struct mutex cred_guard_mutex; /* guard against foreign influences on
60285- * credential calculations
60286- * (notably. ptrace) */
60287- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60288-
60289 char comm[TASK_COMM_LEN]; /* executable name excluding path
60290 - access with [gs]et_task_comm (which lock
60291 it with task_lock())
60292@@ -1369,6 +1378,10 @@ struct task_struct {
60293 #endif
60294 /* CPU-specific state of this task */
60295 struct thread_struct thread;
60296+/* thread_info moved to task_struct */
60297+#ifdef CONFIG_X86
60298+ struct thread_info tinfo;
60299+#endif
60300 /* filesystem information */
60301 struct fs_struct *fs;
60302 /* open file information */
60303@@ -1436,6 +1449,15 @@ struct task_struct {
60304 int hardirq_context;
60305 int softirq_context;
60306 #endif
60307+
60308+/* process credentials */
60309+ const struct cred *real_cred; /* objective and real subjective task
60310+ * credentials (COW) */
60311+ struct mutex cred_guard_mutex; /* guard against foreign influences on
60312+ * credential calculations
60313+ * (notably. ptrace) */
60314+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60315+
60316 #ifdef CONFIG_LOCKDEP
60317 # define MAX_LOCK_DEPTH 48UL
60318 u64 curr_chain_key;
60319@@ -1456,6 +1478,9 @@ struct task_struct {
60320
60321 struct backing_dev_info *backing_dev_info;
60322
60323+ const struct cred *cred; /* effective (overridable) subjective task
60324+ * credentials (COW) */
60325+
60326 struct io_context *io_context;
60327
60328 unsigned long ptrace_message;
60329@@ -1519,6 +1544,21 @@ struct task_struct {
60330 unsigned long default_timer_slack_ns;
60331
60332 struct list_head *scm_work_list;
60333+
60334+#ifdef CONFIG_GRKERNSEC
60335+ /* grsecurity */
60336+ struct dentry *gr_chroot_dentry;
60337+ struct acl_subject_label *acl;
60338+ struct acl_role_label *role;
60339+ struct file *exec_file;
60340+ u16 acl_role_id;
60341+ /* is this the task that authenticated to the special role */
60342+ u8 acl_sp_role;
60343+ u8 is_writable;
60344+ u8 brute;
60345+ u8 gr_is_chrooted;
60346+#endif
60347+
60348 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60349 /* Index of current stored adress in ret_stack */
60350 int curr_ret_stack;
60351@@ -1542,6 +1582,57 @@ struct task_struct {
60352 #endif /* CONFIG_TRACING */
60353 };
60354
60355+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
60356+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
60357+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
60358+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
60359+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
60360+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
60361+
60362+#ifdef CONFIG_PAX_SOFTMODE
60363+extern int pax_softmode;
60364+#endif
60365+
60366+extern int pax_check_flags(unsigned long *);
60367+
60368+/* if tsk != current then task_lock must be held on it */
60369+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60370+static inline unsigned long pax_get_flags(struct task_struct *tsk)
60371+{
60372+ if (likely(tsk->mm))
60373+ return tsk->mm->pax_flags;
60374+ else
60375+ return 0UL;
60376+}
60377+
60378+/* if tsk != current then task_lock must be held on it */
60379+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
60380+{
60381+ if (likely(tsk->mm)) {
60382+ tsk->mm->pax_flags = flags;
60383+ return 0;
60384+ }
60385+ return -EINVAL;
60386+}
60387+#endif
60388+
60389+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60390+extern void pax_set_initial_flags(struct linux_binprm *bprm);
60391+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60392+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60393+#endif
60394+
60395+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
60396+extern void pax_report_insns(void *pc, void *sp);
60397+extern void pax_report_refcount_overflow(struct pt_regs *regs);
60398+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
60399+
60400+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
60401+extern void pax_track_stack(void);
60402+#else
60403+static inline void pax_track_stack(void) {}
60404+#endif
60405+
60406 /* Future-safe accessor for struct task_struct's cpus_allowed. */
60407 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
60408
60409@@ -1978,7 +2069,9 @@ void yield(void);
60410 extern struct exec_domain default_exec_domain;
60411
60412 union thread_union {
60413+#ifndef CONFIG_X86
60414 struct thread_info thread_info;
60415+#endif
60416 unsigned long stack[THREAD_SIZE/sizeof(long)];
60417 };
60418
60419@@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
60420 */
60421
60422 extern struct task_struct *find_task_by_vpid(pid_t nr);
60423+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
60424 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
60425 struct pid_namespace *ns);
60426
60427@@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sig
60428 extern void exit_itimers(struct signal_struct *);
60429 extern void flush_itimer_signals(void);
60430
60431-extern NORET_TYPE void do_group_exit(int);
60432+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
60433
60434 extern void daemonize(const char *, ...);
60435 extern int allow_signal(int);
60436@@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stac
60437
60438 #endif
60439
60440-static inline int object_is_on_stack(void *obj)
60441+static inline int object_starts_on_stack(void *obj)
60442 {
60443- void *stack = task_stack_page(current);
60444+ const void *stack = task_stack_page(current);
60445
60446 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
60447 }
60448
60449+#ifdef CONFIG_PAX_USERCOPY
60450+extern int object_is_on_stack(const void *obj, unsigned long len);
60451+#endif
60452+
60453 extern void thread_info_cache_init(void);
60454
60455 #ifdef CONFIG_DEBUG_STACK_USAGE
60456diff -urNp linux-2.6.32.43/include/linux/screen_info.h linux-2.6.32.43/include/linux/screen_info.h
60457--- linux-2.6.32.43/include/linux/screen_info.h 2011-03-27 14:31:47.000000000 -0400
60458+++ linux-2.6.32.43/include/linux/screen_info.h 2011-04-17 15:56:46.000000000 -0400
60459@@ -42,7 +42,8 @@ struct screen_info {
60460 __u16 pages; /* 0x32 */
60461 __u16 vesa_attributes; /* 0x34 */
60462 __u32 capabilities; /* 0x36 */
60463- __u8 _reserved[6]; /* 0x3a */
60464+ __u16 vesapm_size; /* 0x3a */
60465+ __u8 _reserved[4]; /* 0x3c */
60466 } __attribute__((packed));
60467
60468 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
60469diff -urNp linux-2.6.32.43/include/linux/security.h linux-2.6.32.43/include/linux/security.h
60470--- linux-2.6.32.43/include/linux/security.h 2011-03-27 14:31:47.000000000 -0400
60471+++ linux-2.6.32.43/include/linux/security.h 2011-04-17 15:56:46.000000000 -0400
60472@@ -34,6 +34,7 @@
60473 #include <linux/key.h>
60474 #include <linux/xfrm.h>
60475 #include <linux/gfp.h>
60476+#include <linux/grsecurity.h>
60477 #include <net/flow.h>
60478
60479 /* Maximum number of letters for an LSM name string */
60480diff -urNp linux-2.6.32.43/include/linux/shm.h linux-2.6.32.43/include/linux/shm.h
60481--- linux-2.6.32.43/include/linux/shm.h 2011-03-27 14:31:47.000000000 -0400
60482+++ linux-2.6.32.43/include/linux/shm.h 2011-04-17 15:56:46.000000000 -0400
60483@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
60484 pid_t shm_cprid;
60485 pid_t shm_lprid;
60486 struct user_struct *mlock_user;
60487+#ifdef CONFIG_GRKERNSEC
60488+ time_t shm_createtime;
60489+ pid_t shm_lapid;
60490+#endif
60491 };
60492
60493 /* shm_mode upper byte flags */
60494diff -urNp linux-2.6.32.43/include/linux/skbuff.h linux-2.6.32.43/include/linux/skbuff.h
60495--- linux-2.6.32.43/include/linux/skbuff.h 2011-03-27 14:31:47.000000000 -0400
60496+++ linux-2.6.32.43/include/linux/skbuff.h 2011-07-06 19:53:33.000000000 -0400
60497@@ -544,7 +544,7 @@ static inline union skb_shared_tx *skb_t
60498 */
60499 static inline int skb_queue_empty(const struct sk_buff_head *list)
60500 {
60501- return list->next == (struct sk_buff *)list;
60502+ return list->next == (const struct sk_buff *)list;
60503 }
60504
60505 /**
60506@@ -557,7 +557,7 @@ static inline int skb_queue_empty(const
60507 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60508 const struct sk_buff *skb)
60509 {
60510- return (skb->next == (struct sk_buff *) list);
60511+ return (skb->next == (const struct sk_buff *) list);
60512 }
60513
60514 /**
60515@@ -570,7 +570,7 @@ static inline bool skb_queue_is_last(con
60516 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
60517 const struct sk_buff *skb)
60518 {
60519- return (skb->prev == (struct sk_buff *) list);
60520+ return (skb->prev == (const struct sk_buff *) list);
60521 }
60522
60523 /**
60524@@ -1367,7 +1367,7 @@ static inline int skb_network_offset(con
60525 * headroom, you should not reduce this.
60526 */
60527 #ifndef NET_SKB_PAD
60528-#define NET_SKB_PAD 32
60529+#define NET_SKB_PAD (_AC(32,UL))
60530 #endif
60531
60532 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
60533diff -urNp linux-2.6.32.43/include/linux/slab_def.h linux-2.6.32.43/include/linux/slab_def.h
60534--- linux-2.6.32.43/include/linux/slab_def.h 2011-03-27 14:31:47.000000000 -0400
60535+++ linux-2.6.32.43/include/linux/slab_def.h 2011-05-04 17:56:28.000000000 -0400
60536@@ -69,10 +69,10 @@ struct kmem_cache {
60537 unsigned long node_allocs;
60538 unsigned long node_frees;
60539 unsigned long node_overflow;
60540- atomic_t allochit;
60541- atomic_t allocmiss;
60542- atomic_t freehit;
60543- atomic_t freemiss;
60544+ atomic_unchecked_t allochit;
60545+ atomic_unchecked_t allocmiss;
60546+ atomic_unchecked_t freehit;
60547+ atomic_unchecked_t freemiss;
60548
60549 /*
60550 * If debugging is enabled, then the allocator can add additional
60551diff -urNp linux-2.6.32.43/include/linux/slab.h linux-2.6.32.43/include/linux/slab.h
60552--- linux-2.6.32.43/include/linux/slab.h 2011-03-27 14:31:47.000000000 -0400
60553+++ linux-2.6.32.43/include/linux/slab.h 2011-04-17 15:56:46.000000000 -0400
60554@@ -11,12 +11,20 @@
60555
60556 #include <linux/gfp.h>
60557 #include <linux/types.h>
60558+#include <linux/err.h>
60559
60560 /*
60561 * Flags to pass to kmem_cache_create().
60562 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
60563 */
60564 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
60565+
60566+#ifdef CONFIG_PAX_USERCOPY
60567+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
60568+#else
60569+#define SLAB_USERCOPY 0x00000000UL
60570+#endif
60571+
60572 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
60573 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
60574 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
60575@@ -82,10 +90,13 @@
60576 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
60577 * Both make kfree a no-op.
60578 */
60579-#define ZERO_SIZE_PTR ((void *)16)
60580+#define ZERO_SIZE_PTR \
60581+({ \
60582+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
60583+ (void *)(-MAX_ERRNO-1L); \
60584+})
60585
60586-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
60587- (unsigned long)ZERO_SIZE_PTR)
60588+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
60589
60590 /*
60591 * struct kmem_cache related prototypes
60592@@ -138,6 +149,7 @@ void * __must_check krealloc(const void
60593 void kfree(const void *);
60594 void kzfree(const void *);
60595 size_t ksize(const void *);
60596+void check_object_size(const void *ptr, unsigned long n, bool to);
60597
60598 /*
60599 * Allocator specific definitions. These are mainly used to establish optimized
60600@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t
60601
60602 void __init kmem_cache_init_late(void);
60603
60604+#define kmalloc(x, y) \
60605+({ \
60606+ void *___retval; \
60607+ intoverflow_t ___x = (intoverflow_t)x; \
60608+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
60609+ ___retval = NULL; \
60610+ else \
60611+ ___retval = kmalloc((size_t)___x, (y)); \
60612+ ___retval; \
60613+})
60614+
60615+#define kmalloc_node(x, y, z) \
60616+({ \
60617+ void *___retval; \
60618+ intoverflow_t ___x = (intoverflow_t)x; \
60619+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
60620+ ___retval = NULL; \
60621+ else \
60622+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
60623+ ___retval; \
60624+})
60625+
60626+#define kzalloc(x, y) \
60627+({ \
60628+ void *___retval; \
60629+ intoverflow_t ___x = (intoverflow_t)x; \
60630+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
60631+ ___retval = NULL; \
60632+ else \
60633+ ___retval = kzalloc((size_t)___x, (y)); \
60634+ ___retval; \
60635+})
60636+
60637 #endif /* _LINUX_SLAB_H */
60638diff -urNp linux-2.6.32.43/include/linux/slub_def.h linux-2.6.32.43/include/linux/slub_def.h
60639--- linux-2.6.32.43/include/linux/slub_def.h 2011-03-27 14:31:47.000000000 -0400
60640+++ linux-2.6.32.43/include/linux/slub_def.h 2011-08-05 20:33:55.000000000 -0400
60641@@ -86,7 +86,7 @@ struct kmem_cache {
60642 struct kmem_cache_order_objects max;
60643 struct kmem_cache_order_objects min;
60644 gfp_t allocflags; /* gfp flags to use on each alloc */
60645- int refcount; /* Refcount for slab cache destroy */
60646+ atomic_t refcount; /* Refcount for slab cache destroy */
60647 void (*ctor)(void *);
60648 int inuse; /* Offset to metadata */
60649 int align; /* Alignment */
60650@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache
60651 #endif
60652
60653 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
60654-void *__kmalloc(size_t size, gfp_t flags);
60655+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
60656
60657 #ifdef CONFIG_KMEMTRACE
60658 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
60659diff -urNp linux-2.6.32.43/include/linux/sonet.h linux-2.6.32.43/include/linux/sonet.h
60660--- linux-2.6.32.43/include/linux/sonet.h 2011-03-27 14:31:47.000000000 -0400
60661+++ linux-2.6.32.43/include/linux/sonet.h 2011-04-17 15:56:46.000000000 -0400
60662@@ -61,7 +61,7 @@ struct sonet_stats {
60663 #include <asm/atomic.h>
60664
60665 struct k_sonet_stats {
60666-#define __HANDLE_ITEM(i) atomic_t i
60667+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60668 __SONET_ITEMS
60669 #undef __HANDLE_ITEM
60670 };
60671diff -urNp linux-2.6.32.43/include/linux/sunrpc/cache.h linux-2.6.32.43/include/linux/sunrpc/cache.h
60672--- linux-2.6.32.43/include/linux/sunrpc/cache.h 2011-03-27 14:31:47.000000000 -0400
60673+++ linux-2.6.32.43/include/linux/sunrpc/cache.h 2011-08-05 20:33:55.000000000 -0400
60674@@ -125,7 +125,7 @@ struct cache_detail {
60675 */
60676 struct cache_req {
60677 struct cache_deferred_req *(*defer)(struct cache_req *req);
60678-};
60679+} __no_const;
60680 /* this must be embedded in a deferred_request that is being
60681 * delayed awaiting cache-fill
60682 */
60683diff -urNp linux-2.6.32.43/include/linux/sunrpc/clnt.h linux-2.6.32.43/include/linux/sunrpc/clnt.h
60684--- linux-2.6.32.43/include/linux/sunrpc/clnt.h 2011-03-27 14:31:47.000000000 -0400
60685+++ linux-2.6.32.43/include/linux/sunrpc/clnt.h 2011-04-17 15:56:46.000000000 -0400
60686@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_por
60687 {
60688 switch (sap->sa_family) {
60689 case AF_INET:
60690- return ntohs(((struct sockaddr_in *)sap)->sin_port);
60691+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
60692 case AF_INET6:
60693- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
60694+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
60695 }
60696 return 0;
60697 }
60698@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const
60699 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
60700 const struct sockaddr *src)
60701 {
60702- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
60703+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
60704 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
60705
60706 dsin->sin_family = ssin->sin_family;
60707@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const
60708 if (sa->sa_family != AF_INET6)
60709 return 0;
60710
60711- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
60712+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
60713 }
60714
60715 #endif /* __KERNEL__ */
60716diff -urNp linux-2.6.32.43/include/linux/sunrpc/svc_rdma.h linux-2.6.32.43/include/linux/sunrpc/svc_rdma.h
60717--- linux-2.6.32.43/include/linux/sunrpc/svc_rdma.h 2011-03-27 14:31:47.000000000 -0400
60718+++ linux-2.6.32.43/include/linux/sunrpc/svc_rdma.h 2011-05-04 17:56:28.000000000 -0400
60719@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
60720 extern unsigned int svcrdma_max_requests;
60721 extern unsigned int svcrdma_max_req_size;
60722
60723-extern atomic_t rdma_stat_recv;
60724-extern atomic_t rdma_stat_read;
60725-extern atomic_t rdma_stat_write;
60726-extern atomic_t rdma_stat_sq_starve;
60727-extern atomic_t rdma_stat_rq_starve;
60728-extern atomic_t rdma_stat_rq_poll;
60729-extern atomic_t rdma_stat_rq_prod;
60730-extern atomic_t rdma_stat_sq_poll;
60731-extern atomic_t rdma_stat_sq_prod;
60732+extern atomic_unchecked_t rdma_stat_recv;
60733+extern atomic_unchecked_t rdma_stat_read;
60734+extern atomic_unchecked_t rdma_stat_write;
60735+extern atomic_unchecked_t rdma_stat_sq_starve;
60736+extern atomic_unchecked_t rdma_stat_rq_starve;
60737+extern atomic_unchecked_t rdma_stat_rq_poll;
60738+extern atomic_unchecked_t rdma_stat_rq_prod;
60739+extern atomic_unchecked_t rdma_stat_sq_poll;
60740+extern atomic_unchecked_t rdma_stat_sq_prod;
60741
60742 #define RPCRDMA_VERSION 1
60743
60744diff -urNp linux-2.6.32.43/include/linux/suspend.h linux-2.6.32.43/include/linux/suspend.h
60745--- linux-2.6.32.43/include/linux/suspend.h 2011-03-27 14:31:47.000000000 -0400
60746+++ linux-2.6.32.43/include/linux/suspend.h 2011-04-17 15:56:46.000000000 -0400
60747@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
60748 * which require special recovery actions in that situation.
60749 */
60750 struct platform_suspend_ops {
60751- int (*valid)(suspend_state_t state);
60752- int (*begin)(suspend_state_t state);
60753- int (*prepare)(void);
60754- int (*prepare_late)(void);
60755- int (*enter)(suspend_state_t state);
60756- void (*wake)(void);
60757- void (*finish)(void);
60758- void (*end)(void);
60759- void (*recover)(void);
60760+ int (* const valid)(suspend_state_t state);
60761+ int (* const begin)(suspend_state_t state);
60762+ int (* const prepare)(void);
60763+ int (* const prepare_late)(void);
60764+ int (* const enter)(suspend_state_t state);
60765+ void (* const wake)(void);
60766+ void (* const finish)(void);
60767+ void (* const end)(void);
60768+ void (* const recover)(void);
60769 };
60770
60771 #ifdef CONFIG_SUSPEND
60772@@ -120,7 +120,7 @@ struct platform_suspend_ops {
60773 * suspend_set_ops - set platform dependent suspend operations
60774 * @ops: The new suspend operations to set.
60775 */
60776-extern void suspend_set_ops(struct platform_suspend_ops *ops);
60777+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
60778 extern int suspend_valid_only_mem(suspend_state_t state);
60779
60780 /**
60781@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t st
60782 #else /* !CONFIG_SUSPEND */
60783 #define suspend_valid_only_mem NULL
60784
60785-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
60786+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
60787 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
60788 #endif /* !CONFIG_SUSPEND */
60789
60790@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone
60791 * platforms which require special recovery actions in that situation.
60792 */
60793 struct platform_hibernation_ops {
60794- int (*begin)(void);
60795- void (*end)(void);
60796- int (*pre_snapshot)(void);
60797- void (*finish)(void);
60798- int (*prepare)(void);
60799- int (*enter)(void);
60800- void (*leave)(void);
60801- int (*pre_restore)(void);
60802- void (*restore_cleanup)(void);
60803- void (*recover)(void);
60804+ int (* const begin)(void);
60805+ void (* const end)(void);
60806+ int (* const pre_snapshot)(void);
60807+ void (* const finish)(void);
60808+ int (* const prepare)(void);
60809+ int (* const enter)(void);
60810+ void (* const leave)(void);
60811+ int (* const pre_restore)(void);
60812+ void (* const restore_cleanup)(void);
60813+ void (* const recover)(void);
60814 };
60815
60816 #ifdef CONFIG_HIBERNATION
60817@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct
60818 extern void swsusp_unset_page_free(struct page *);
60819 extern unsigned long get_safe_page(gfp_t gfp_mask);
60820
60821-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
60822+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
60823 extern int hibernate(void);
60824 extern bool system_entering_hibernation(void);
60825 #else /* CONFIG_HIBERNATION */
60826@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidd
60827 static inline void swsusp_set_page_free(struct page *p) {}
60828 static inline void swsusp_unset_page_free(struct page *p) {}
60829
60830-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
60831+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
60832 static inline int hibernate(void) { return -ENOSYS; }
60833 static inline bool system_entering_hibernation(void) { return false; }
60834 #endif /* CONFIG_HIBERNATION */
60835diff -urNp linux-2.6.32.43/include/linux/sysctl.h linux-2.6.32.43/include/linux/sysctl.h
60836--- linux-2.6.32.43/include/linux/sysctl.h 2011-03-27 14:31:47.000000000 -0400
60837+++ linux-2.6.32.43/include/linux/sysctl.h 2011-04-17 15:56:46.000000000 -0400
60838@@ -164,7 +164,11 @@ enum
60839 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
60840 };
60841
60842-
60843+#ifdef CONFIG_PAX_SOFTMODE
60844+enum {
60845+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
60846+};
60847+#endif
60848
60849 /* CTL_VM names: */
60850 enum
60851@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_tab
60852
60853 extern int proc_dostring(struct ctl_table *, int,
60854 void __user *, size_t *, loff_t *);
60855+extern int proc_dostring_modpriv(struct ctl_table *, int,
60856+ void __user *, size_t *, loff_t *);
60857 extern int proc_dointvec(struct ctl_table *, int,
60858 void __user *, size_t *, loff_t *);
60859 extern int proc_dointvec_minmax(struct ctl_table *, int,
60860@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name,
60861
60862 extern ctl_handler sysctl_data;
60863 extern ctl_handler sysctl_string;
60864+extern ctl_handler sysctl_string_modpriv;
60865 extern ctl_handler sysctl_intvec;
60866 extern ctl_handler sysctl_jiffies;
60867 extern ctl_handler sysctl_ms_jiffies;
60868diff -urNp linux-2.6.32.43/include/linux/sysfs.h linux-2.6.32.43/include/linux/sysfs.h
60869--- linux-2.6.32.43/include/linux/sysfs.h 2011-03-27 14:31:47.000000000 -0400
60870+++ linux-2.6.32.43/include/linux/sysfs.h 2011-04-17 15:56:46.000000000 -0400
60871@@ -75,8 +75,8 @@ struct bin_attribute {
60872 };
60873
60874 struct sysfs_ops {
60875- ssize_t (*show)(struct kobject *, struct attribute *,char *);
60876- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
60877+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
60878+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
60879 };
60880
60881 struct sysfs_dirent;
60882diff -urNp linux-2.6.32.43/include/linux/thread_info.h linux-2.6.32.43/include/linux/thread_info.h
60883--- linux-2.6.32.43/include/linux/thread_info.h 2011-03-27 14:31:47.000000000 -0400
60884+++ linux-2.6.32.43/include/linux/thread_info.h 2011-04-17 15:56:46.000000000 -0400
60885@@ -23,7 +23,7 @@ struct restart_block {
60886 };
60887 /* For futex_wait and futex_wait_requeue_pi */
60888 struct {
60889- u32 *uaddr;
60890+ u32 __user *uaddr;
60891 u32 val;
60892 u32 flags;
60893 u32 bitset;
60894diff -urNp linux-2.6.32.43/include/linux/tty.h linux-2.6.32.43/include/linux/tty.h
60895--- linux-2.6.32.43/include/linux/tty.h 2011-03-27 14:31:47.000000000 -0400
60896+++ linux-2.6.32.43/include/linux/tty.h 2011-08-05 20:33:55.000000000 -0400
60897@@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
60898 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
60899 extern void tty_ldisc_enable(struct tty_struct *tty);
60900
60901-
60902 /* n_tty.c */
60903 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
60904
60905diff -urNp linux-2.6.32.43/include/linux/tty_ldisc.h linux-2.6.32.43/include/linux/tty_ldisc.h
60906--- linux-2.6.32.43/include/linux/tty_ldisc.h 2011-03-27 14:31:47.000000000 -0400
60907+++ linux-2.6.32.43/include/linux/tty_ldisc.h 2011-04-17 15:56:46.000000000 -0400
60908@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
60909
60910 struct module *owner;
60911
60912- int refcount;
60913+ atomic_t refcount;
60914 };
60915
60916 struct tty_ldisc {
60917diff -urNp linux-2.6.32.43/include/linux/types.h linux-2.6.32.43/include/linux/types.h
60918--- linux-2.6.32.43/include/linux/types.h 2011-03-27 14:31:47.000000000 -0400
60919+++ linux-2.6.32.43/include/linux/types.h 2011-04-17 15:56:46.000000000 -0400
60920@@ -191,10 +191,26 @@ typedef struct {
60921 volatile int counter;
60922 } atomic_t;
60923
60924+#ifdef CONFIG_PAX_REFCOUNT
60925+typedef struct {
60926+ volatile int counter;
60927+} atomic_unchecked_t;
60928+#else
60929+typedef atomic_t atomic_unchecked_t;
60930+#endif
60931+
60932 #ifdef CONFIG_64BIT
60933 typedef struct {
60934 volatile long counter;
60935 } atomic64_t;
60936+
60937+#ifdef CONFIG_PAX_REFCOUNT
60938+typedef struct {
60939+ volatile long counter;
60940+} atomic64_unchecked_t;
60941+#else
60942+typedef atomic64_t atomic64_unchecked_t;
60943+#endif
60944 #endif
60945
60946 struct ustat {
60947diff -urNp linux-2.6.32.43/include/linux/uaccess.h linux-2.6.32.43/include/linux/uaccess.h
60948--- linux-2.6.32.43/include/linux/uaccess.h 2011-03-27 14:31:47.000000000 -0400
60949+++ linux-2.6.32.43/include/linux/uaccess.h 2011-04-17 15:56:46.000000000 -0400
60950@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
60951 long ret; \
60952 mm_segment_t old_fs = get_fs(); \
60953 \
60954- set_fs(KERNEL_DS); \
60955 pagefault_disable(); \
60956+ set_fs(KERNEL_DS); \
60957 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
60958- pagefault_enable(); \
60959 set_fs(old_fs); \
60960+ pagefault_enable(); \
60961 ret; \
60962 })
60963
60964@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_
60965 * Safely read from address @src to the buffer at @dst. If a kernel fault
60966 * happens, handle that and return -EFAULT.
60967 */
60968-extern long probe_kernel_read(void *dst, void *src, size_t size);
60969+extern long probe_kernel_read(void *dst, const void *src, size_t size);
60970
60971 /*
60972 * probe_kernel_write(): safely attempt to write to a location
60973@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst,
60974 * Safely write to address @dst from the buffer at @src. If a kernel fault
60975 * happens, handle that and return -EFAULT.
60976 */
60977-extern long probe_kernel_write(void *dst, void *src, size_t size);
60978+extern long probe_kernel_write(void *dst, const void *src, size_t size);
60979
60980 #endif /* __LINUX_UACCESS_H__ */
60981diff -urNp linux-2.6.32.43/include/linux/unaligned/access_ok.h linux-2.6.32.43/include/linux/unaligned/access_ok.h
60982--- linux-2.6.32.43/include/linux/unaligned/access_ok.h 2011-03-27 14:31:47.000000000 -0400
60983+++ linux-2.6.32.43/include/linux/unaligned/access_ok.h 2011-04-17 15:56:46.000000000 -0400
60984@@ -6,32 +6,32 @@
60985
60986 static inline u16 get_unaligned_le16(const void *p)
60987 {
60988- return le16_to_cpup((__le16 *)p);
60989+ return le16_to_cpup((const __le16 *)p);
60990 }
60991
60992 static inline u32 get_unaligned_le32(const void *p)
60993 {
60994- return le32_to_cpup((__le32 *)p);
60995+ return le32_to_cpup((const __le32 *)p);
60996 }
60997
60998 static inline u64 get_unaligned_le64(const void *p)
60999 {
61000- return le64_to_cpup((__le64 *)p);
61001+ return le64_to_cpup((const __le64 *)p);
61002 }
61003
61004 static inline u16 get_unaligned_be16(const void *p)
61005 {
61006- return be16_to_cpup((__be16 *)p);
61007+ return be16_to_cpup((const __be16 *)p);
61008 }
61009
61010 static inline u32 get_unaligned_be32(const void *p)
61011 {
61012- return be32_to_cpup((__be32 *)p);
61013+ return be32_to_cpup((const __be32 *)p);
61014 }
61015
61016 static inline u64 get_unaligned_be64(const void *p)
61017 {
61018- return be64_to_cpup((__be64 *)p);
61019+ return be64_to_cpup((const __be64 *)p);
61020 }
61021
61022 static inline void put_unaligned_le16(u16 val, void *p)
61023diff -urNp linux-2.6.32.43/include/linux/vmalloc.h linux-2.6.32.43/include/linux/vmalloc.h
61024--- linux-2.6.32.43/include/linux/vmalloc.h 2011-03-27 14:31:47.000000000 -0400
61025+++ linux-2.6.32.43/include/linux/vmalloc.h 2011-04-17 15:56:46.000000000 -0400
61026@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
61027 #define VM_MAP 0x00000004 /* vmap()ed pages */
61028 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
61029 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
61030+
61031+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
61032+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
61033+#endif
61034+
61035 /* bits [20..32] reserved for arch specific ioremap internals */
61036
61037 /*
61038@@ -123,4 +128,81 @@ struct vm_struct **pcpu_get_vm_areas(con
61039
61040 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
61041
61042+#define vmalloc(x) \
61043+({ \
61044+ void *___retval; \
61045+ intoverflow_t ___x = (intoverflow_t)x; \
61046+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
61047+ ___retval = NULL; \
61048+ else \
61049+ ___retval = vmalloc((unsigned long)___x); \
61050+ ___retval; \
61051+})
61052+
61053+#define __vmalloc(x, y, z) \
61054+({ \
61055+ void *___retval; \
61056+ intoverflow_t ___x = (intoverflow_t)x; \
61057+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
61058+ ___retval = NULL; \
61059+ else \
61060+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
61061+ ___retval; \
61062+})
61063+
61064+#define vmalloc_user(x) \
61065+({ \
61066+ void *___retval; \
61067+ intoverflow_t ___x = (intoverflow_t)x; \
61068+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
61069+ ___retval = NULL; \
61070+ else \
61071+ ___retval = vmalloc_user((unsigned long)___x); \
61072+ ___retval; \
61073+})
61074+
61075+#define vmalloc_exec(x) \
61076+({ \
61077+ void *___retval; \
61078+ intoverflow_t ___x = (intoverflow_t)x; \
61079+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
61080+ ___retval = NULL; \
61081+ else \
61082+ ___retval = vmalloc_exec((unsigned long)___x); \
61083+ ___retval; \
61084+})
61085+
61086+#define vmalloc_node(x, y) \
61087+({ \
61088+ void *___retval; \
61089+ intoverflow_t ___x = (intoverflow_t)x; \
61090+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
61091+ ___retval = NULL; \
61092+ else \
61093+ ___retval = vmalloc_node((unsigned long)___x, (y));\
61094+ ___retval; \
61095+})
61096+
61097+#define vmalloc_32(x) \
61098+({ \
61099+ void *___retval; \
61100+ intoverflow_t ___x = (intoverflow_t)x; \
61101+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
61102+ ___retval = NULL; \
61103+ else \
61104+ ___retval = vmalloc_32((unsigned long)___x); \
61105+ ___retval; \
61106+})
61107+
61108+#define vmalloc_32_user(x) \
61109+({ \
61110+ void *___retval; \
61111+ intoverflow_t ___x = (intoverflow_t)x; \
61112+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
61113+ ___retval = NULL; \
61114+ else \
61115+ ___retval = vmalloc_32_user((unsigned long)___x);\
61116+ ___retval; \
61117+})
61118+
61119 #endif /* _LINUX_VMALLOC_H */
61120diff -urNp linux-2.6.32.43/include/linux/vmstat.h linux-2.6.32.43/include/linux/vmstat.h
61121--- linux-2.6.32.43/include/linux/vmstat.h 2011-03-27 14:31:47.000000000 -0400
61122+++ linux-2.6.32.43/include/linux/vmstat.h 2011-04-17 15:56:46.000000000 -0400
61123@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(in
61124 /*
61125 * Zone based page accounting with per cpu differentials.
61126 */
61127-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61128+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61129
61130 static inline void zone_page_state_add(long x, struct zone *zone,
61131 enum zone_stat_item item)
61132 {
61133- atomic_long_add(x, &zone->vm_stat[item]);
61134- atomic_long_add(x, &vm_stat[item]);
61135+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
61136+ atomic_long_add_unchecked(x, &vm_stat[item]);
61137 }
61138
61139 static inline unsigned long global_page_state(enum zone_stat_item item)
61140 {
61141- long x = atomic_long_read(&vm_stat[item]);
61142+ long x = atomic_long_read_unchecked(&vm_stat[item]);
61143 #ifdef CONFIG_SMP
61144 if (x < 0)
61145 x = 0;
61146@@ -158,7 +158,7 @@ static inline unsigned long global_page_
61147 static inline unsigned long zone_page_state(struct zone *zone,
61148 enum zone_stat_item item)
61149 {
61150- long x = atomic_long_read(&zone->vm_stat[item]);
61151+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61152 #ifdef CONFIG_SMP
61153 if (x < 0)
61154 x = 0;
61155@@ -175,7 +175,7 @@ static inline unsigned long zone_page_st
61156 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
61157 enum zone_stat_item item)
61158 {
61159- long x = atomic_long_read(&zone->vm_stat[item]);
61160+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61161
61162 #ifdef CONFIG_SMP
61163 int cpu;
61164@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state
61165
61166 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
61167 {
61168- atomic_long_inc(&zone->vm_stat[item]);
61169- atomic_long_inc(&vm_stat[item]);
61170+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
61171+ atomic_long_inc_unchecked(&vm_stat[item]);
61172 }
61173
61174 static inline void __inc_zone_page_state(struct page *page,
61175@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state
61176
61177 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
61178 {
61179- atomic_long_dec(&zone->vm_stat[item]);
61180- atomic_long_dec(&vm_stat[item]);
61181+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
61182+ atomic_long_dec_unchecked(&vm_stat[item]);
61183 }
61184
61185 static inline void __dec_zone_page_state(struct page *page,
61186diff -urNp linux-2.6.32.43/include/media/v4l2-dev.h linux-2.6.32.43/include/media/v4l2-dev.h
61187--- linux-2.6.32.43/include/media/v4l2-dev.h 2011-03-27 14:31:47.000000000 -0400
61188+++ linux-2.6.32.43/include/media/v4l2-dev.h 2011-08-05 20:33:55.000000000 -0400
61189@@ -34,7 +34,7 @@ struct v4l2_device;
61190 #define V4L2_FL_UNREGISTERED (0)
61191
61192 struct v4l2_file_operations {
61193- struct module *owner;
61194+ struct module * const owner;
61195 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61196 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
61197 unsigned int (*poll) (struct file *, struct poll_table_struct *);
61198diff -urNp linux-2.6.32.43/include/media/v4l2-device.h linux-2.6.32.43/include/media/v4l2-device.h
61199--- linux-2.6.32.43/include/media/v4l2-device.h 2011-03-27 14:31:47.000000000 -0400
61200+++ linux-2.6.32.43/include/media/v4l2-device.h 2011-05-04 17:56:28.000000000 -0400
61201@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(st
61202 this function returns 0. If the name ends with a digit (e.g. cx18),
61203 then the name will be set to cx18-0 since cx180 looks really odd. */
61204 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
61205- atomic_t *instance);
61206+ atomic_unchecked_t *instance);
61207
61208 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
61209 Since the parent disappears this ensures that v4l2_dev doesn't have an
61210diff -urNp linux-2.6.32.43/include/net/flow.h linux-2.6.32.43/include/net/flow.h
61211--- linux-2.6.32.43/include/net/flow.h 2011-03-27 14:31:47.000000000 -0400
61212+++ linux-2.6.32.43/include/net/flow.h 2011-05-04 17:56:28.000000000 -0400
61213@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net
61214 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
61215 u8 dir, flow_resolve_t resolver);
61216 extern void flow_cache_flush(void);
61217-extern atomic_t flow_cache_genid;
61218+extern atomic_unchecked_t flow_cache_genid;
61219
61220 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
61221 {
61222diff -urNp linux-2.6.32.43/include/net/inetpeer.h linux-2.6.32.43/include/net/inetpeer.h
61223--- linux-2.6.32.43/include/net/inetpeer.h 2011-03-27 14:31:47.000000000 -0400
61224+++ linux-2.6.32.43/include/net/inetpeer.h 2011-04-17 15:56:46.000000000 -0400
61225@@ -24,7 +24,7 @@ struct inet_peer
61226 __u32 dtime; /* the time of last use of not
61227 * referenced entries */
61228 atomic_t refcnt;
61229- atomic_t rid; /* Frag reception counter */
61230+ atomic_unchecked_t rid; /* Frag reception counter */
61231 __u32 tcp_ts;
61232 unsigned long tcp_ts_stamp;
61233 };
61234diff -urNp linux-2.6.32.43/include/net/ip_vs.h linux-2.6.32.43/include/net/ip_vs.h
61235--- linux-2.6.32.43/include/net/ip_vs.h 2011-03-27 14:31:47.000000000 -0400
61236+++ linux-2.6.32.43/include/net/ip_vs.h 2011-05-04 17:56:28.000000000 -0400
61237@@ -365,7 +365,7 @@ struct ip_vs_conn {
61238 struct ip_vs_conn *control; /* Master control connection */
61239 atomic_t n_control; /* Number of controlled ones */
61240 struct ip_vs_dest *dest; /* real server */
61241- atomic_t in_pkts; /* incoming packet counter */
61242+ atomic_unchecked_t in_pkts; /* incoming packet counter */
61243
61244 /* packet transmitter for different forwarding methods. If it
61245 mangles the packet, it must return NF_DROP or better NF_STOLEN,
61246@@ -466,7 +466,7 @@ struct ip_vs_dest {
61247 union nf_inet_addr addr; /* IP address of the server */
61248 __be16 port; /* port number of the server */
61249 volatile unsigned flags; /* dest status flags */
61250- atomic_t conn_flags; /* flags to copy to conn */
61251+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
61252 atomic_t weight; /* server weight */
61253
61254 atomic_t refcnt; /* reference counter */
61255diff -urNp linux-2.6.32.43/include/net/irda/ircomm_core.h linux-2.6.32.43/include/net/irda/ircomm_core.h
61256--- linux-2.6.32.43/include/net/irda/ircomm_core.h 2011-03-27 14:31:47.000000000 -0400
61257+++ linux-2.6.32.43/include/net/irda/ircomm_core.h 2011-08-05 20:33:55.000000000 -0400
61258@@ -51,7 +51,7 @@ typedef struct {
61259 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
61260 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
61261 struct ircomm_info *);
61262-} call_t;
61263+} __no_const call_t;
61264
61265 struct ircomm_cb {
61266 irda_queue_t queue;
61267diff -urNp linux-2.6.32.43/include/net/irda/ircomm_tty.h linux-2.6.32.43/include/net/irda/ircomm_tty.h
61268--- linux-2.6.32.43/include/net/irda/ircomm_tty.h 2011-03-27 14:31:47.000000000 -0400
61269+++ linux-2.6.32.43/include/net/irda/ircomm_tty.h 2011-04-17 15:56:46.000000000 -0400
61270@@ -35,6 +35,7 @@
61271 #include <linux/termios.h>
61272 #include <linux/timer.h>
61273 #include <linux/tty.h> /* struct tty_struct */
61274+#include <asm/local.h>
61275
61276 #include <net/irda/irias_object.h>
61277 #include <net/irda/ircomm_core.h>
61278@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
61279 unsigned short close_delay;
61280 unsigned short closing_wait; /* time to wait before closing */
61281
61282- int open_count;
61283- int blocked_open; /* # of blocked opens */
61284+ local_t open_count;
61285+ local_t blocked_open; /* # of blocked opens */
61286
61287 /* Protect concurent access to :
61288 * o self->open_count
61289diff -urNp linux-2.6.32.43/include/net/iucv/af_iucv.h linux-2.6.32.43/include/net/iucv/af_iucv.h
61290--- linux-2.6.32.43/include/net/iucv/af_iucv.h 2011-03-27 14:31:47.000000000 -0400
61291+++ linux-2.6.32.43/include/net/iucv/af_iucv.h 2011-05-04 17:56:28.000000000 -0400
61292@@ -87,7 +87,7 @@ struct iucv_sock {
61293 struct iucv_sock_list {
61294 struct hlist_head head;
61295 rwlock_t lock;
61296- atomic_t autobind_name;
61297+ atomic_unchecked_t autobind_name;
61298 };
61299
61300 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
61301diff -urNp linux-2.6.32.43/include/net/lapb.h linux-2.6.32.43/include/net/lapb.h
61302--- linux-2.6.32.43/include/net/lapb.h 2011-03-27 14:31:47.000000000 -0400
61303+++ linux-2.6.32.43/include/net/lapb.h 2011-08-05 20:33:55.000000000 -0400
61304@@ -95,7 +95,7 @@ struct lapb_cb {
61305 struct sk_buff_head write_queue;
61306 struct sk_buff_head ack_queue;
61307 unsigned char window;
61308- struct lapb_register_struct callbacks;
61309+ struct lapb_register_struct *callbacks;
61310
61311 /* FRMR control information */
61312 struct lapb_frame frmr_data;
61313diff -urNp linux-2.6.32.43/include/net/neighbour.h linux-2.6.32.43/include/net/neighbour.h
61314--- linux-2.6.32.43/include/net/neighbour.h 2011-03-27 14:31:47.000000000 -0400
61315+++ linux-2.6.32.43/include/net/neighbour.h 2011-04-17 15:56:46.000000000 -0400
61316@@ -125,12 +125,12 @@ struct neighbour
61317 struct neigh_ops
61318 {
61319 int family;
61320- void (*solicit)(struct neighbour *, struct sk_buff*);
61321- void (*error_report)(struct neighbour *, struct sk_buff*);
61322- int (*output)(struct sk_buff*);
61323- int (*connected_output)(struct sk_buff*);
61324- int (*hh_output)(struct sk_buff*);
61325- int (*queue_xmit)(struct sk_buff*);
61326+ void (* const solicit)(struct neighbour *, struct sk_buff*);
61327+ void (* const error_report)(struct neighbour *, struct sk_buff*);
61328+ int (* const output)(struct sk_buff*);
61329+ int (* const connected_output)(struct sk_buff*);
61330+ int (* const hh_output)(struct sk_buff*);
61331+ int (* const queue_xmit)(struct sk_buff*);
61332 };
61333
61334 struct pneigh_entry
61335diff -urNp linux-2.6.32.43/include/net/netlink.h linux-2.6.32.43/include/net/netlink.h
61336--- linux-2.6.32.43/include/net/netlink.h 2011-07-13 17:23:04.000000000 -0400
61337+++ linux-2.6.32.43/include/net/netlink.h 2011-07-13 17:23:19.000000000 -0400
61338@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct
61339 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
61340 {
61341 if (mark)
61342- skb_trim(skb, (unsigned char *) mark - skb->data);
61343+ skb_trim(skb, (const unsigned char *) mark - skb->data);
61344 }
61345
61346 /**
61347diff -urNp linux-2.6.32.43/include/net/netns/ipv4.h linux-2.6.32.43/include/net/netns/ipv4.h
61348--- linux-2.6.32.43/include/net/netns/ipv4.h 2011-03-27 14:31:47.000000000 -0400
61349+++ linux-2.6.32.43/include/net/netns/ipv4.h 2011-05-04 17:56:28.000000000 -0400
61350@@ -54,7 +54,7 @@ struct netns_ipv4 {
61351 int current_rt_cache_rebuild_count;
61352
61353 struct timer_list rt_secret_timer;
61354- atomic_t rt_genid;
61355+ atomic_unchecked_t rt_genid;
61356
61357 #ifdef CONFIG_IP_MROUTE
61358 struct sock *mroute_sk;
61359diff -urNp linux-2.6.32.43/include/net/sctp/sctp.h linux-2.6.32.43/include/net/sctp/sctp.h
61360--- linux-2.6.32.43/include/net/sctp/sctp.h 2011-03-27 14:31:47.000000000 -0400
61361+++ linux-2.6.32.43/include/net/sctp/sctp.h 2011-04-17 15:56:46.000000000 -0400
61362@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
61363
61364 #else /* SCTP_DEBUG */
61365
61366-#define SCTP_DEBUG_PRINTK(whatever...)
61367-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
61368+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
61369+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
61370 #define SCTP_ENABLE_DEBUG
61371 #define SCTP_DISABLE_DEBUG
61372 #define SCTP_ASSERT(expr, str, func)
61373diff -urNp linux-2.6.32.43/include/net/sock.h linux-2.6.32.43/include/net/sock.h
61374--- linux-2.6.32.43/include/net/sock.h 2011-03-27 14:31:47.000000000 -0400
61375+++ linux-2.6.32.43/include/net/sock.h 2011-05-04 17:56:28.000000000 -0400
61376@@ -272,7 +272,7 @@ struct sock {
61377 rwlock_t sk_callback_lock;
61378 int sk_err,
61379 sk_err_soft;
61380- atomic_t sk_drops;
61381+ atomic_unchecked_t sk_drops;
61382 unsigned short sk_ack_backlog;
61383 unsigned short sk_max_ack_backlog;
61384 __u32 sk_priority;
61385diff -urNp linux-2.6.32.43/include/net/tcp.h linux-2.6.32.43/include/net/tcp.h
61386--- linux-2.6.32.43/include/net/tcp.h 2011-03-27 14:31:47.000000000 -0400
61387+++ linux-2.6.32.43/include/net/tcp.h 2011-04-17 15:56:46.000000000 -0400
61388@@ -1444,6 +1444,7 @@ enum tcp_seq_states {
61389 struct tcp_seq_afinfo {
61390 char *name;
61391 sa_family_t family;
61392+ /* cannot be const */
61393 struct file_operations seq_fops;
61394 struct seq_operations seq_ops;
61395 };
61396diff -urNp linux-2.6.32.43/include/net/udp.h linux-2.6.32.43/include/net/udp.h
61397--- linux-2.6.32.43/include/net/udp.h 2011-03-27 14:31:47.000000000 -0400
61398+++ linux-2.6.32.43/include/net/udp.h 2011-04-17 15:56:46.000000000 -0400
61399@@ -187,6 +187,7 @@ struct udp_seq_afinfo {
61400 char *name;
61401 sa_family_t family;
61402 struct udp_table *udp_table;
61403+ /* cannot be const */
61404 struct file_operations seq_fops;
61405 struct seq_operations seq_ops;
61406 };
61407diff -urNp linux-2.6.32.43/include/rdma/iw_cm.h linux-2.6.32.43/include/rdma/iw_cm.h
61408--- linux-2.6.32.43/include/rdma/iw_cm.h 2011-03-27 14:31:47.000000000 -0400
61409+++ linux-2.6.32.43/include/rdma/iw_cm.h 2011-08-05 20:33:55.000000000 -0400
61410@@ -129,7 +129,7 @@ struct iw_cm_verbs {
61411 int backlog);
61412
61413 int (*destroy_listen)(struct iw_cm_id *cm_id);
61414-};
61415+} __no_const;
61416
61417 /**
61418 * iw_create_cm_id - Create an IW CM identifier.
61419diff -urNp linux-2.6.32.43/include/scsi/scsi_device.h linux-2.6.32.43/include/scsi/scsi_device.h
61420--- linux-2.6.32.43/include/scsi/scsi_device.h 2011-04-17 17:00:52.000000000 -0400
61421+++ linux-2.6.32.43/include/scsi/scsi_device.h 2011-05-04 17:56:28.000000000 -0400
61422@@ -156,9 +156,9 @@ struct scsi_device {
61423 unsigned int max_device_blocked; /* what device_blocked counts down from */
61424 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
61425
61426- atomic_t iorequest_cnt;
61427- atomic_t iodone_cnt;
61428- atomic_t ioerr_cnt;
61429+ atomic_unchecked_t iorequest_cnt;
61430+ atomic_unchecked_t iodone_cnt;
61431+ atomic_unchecked_t ioerr_cnt;
61432
61433 struct device sdev_gendev,
61434 sdev_dev;
61435diff -urNp linux-2.6.32.43/include/scsi/scsi_transport_fc.h linux-2.6.32.43/include/scsi/scsi_transport_fc.h
61436--- linux-2.6.32.43/include/scsi/scsi_transport_fc.h 2011-03-27 14:31:47.000000000 -0400
61437+++ linux-2.6.32.43/include/scsi/scsi_transport_fc.h 2011-08-05 20:33:55.000000000 -0400
61438@@ -663,9 +663,9 @@ struct fc_function_template {
61439 int (*bsg_timeout)(struct fc_bsg_job *);
61440
61441 /* allocation lengths for host-specific data */
61442- u32 dd_fcrport_size;
61443- u32 dd_fcvport_size;
61444- u32 dd_bsg_size;
61445+ const u32 dd_fcrport_size;
61446+ const u32 dd_fcvport_size;
61447+ const u32 dd_bsg_size;
61448
61449 /*
61450 * The driver sets these to tell the transport class it
61451@@ -675,39 +675,39 @@ struct fc_function_template {
61452 */
61453
61454 /* remote port fixed attributes */
61455- unsigned long show_rport_maxframe_size:1;
61456- unsigned long show_rport_supported_classes:1;
61457- unsigned long show_rport_dev_loss_tmo:1;
61458+ const unsigned long show_rport_maxframe_size:1;
61459+ const unsigned long show_rport_supported_classes:1;
61460+ const unsigned long show_rport_dev_loss_tmo:1;
61461
61462 /*
61463 * target dynamic attributes
61464 * These should all be "1" if the driver uses the remote port
61465 * add/delete functions (so attributes reflect rport values).
61466 */
61467- unsigned long show_starget_node_name:1;
61468- unsigned long show_starget_port_name:1;
61469- unsigned long show_starget_port_id:1;
61470+ const unsigned long show_starget_node_name:1;
61471+ const unsigned long show_starget_port_name:1;
61472+ const unsigned long show_starget_port_id:1;
61473
61474 /* host fixed attributes */
61475- unsigned long show_host_node_name:1;
61476- unsigned long show_host_port_name:1;
61477- unsigned long show_host_permanent_port_name:1;
61478- unsigned long show_host_supported_classes:1;
61479- unsigned long show_host_supported_fc4s:1;
61480- unsigned long show_host_supported_speeds:1;
61481- unsigned long show_host_maxframe_size:1;
61482- unsigned long show_host_serial_number:1;
61483+ const unsigned long show_host_node_name:1;
61484+ const unsigned long show_host_port_name:1;
61485+ const unsigned long show_host_permanent_port_name:1;
61486+ const unsigned long show_host_supported_classes:1;
61487+ const unsigned long show_host_supported_fc4s:1;
61488+ const unsigned long show_host_supported_speeds:1;
61489+ const unsigned long show_host_maxframe_size:1;
61490+ const unsigned long show_host_serial_number:1;
61491 /* host dynamic attributes */
61492- unsigned long show_host_port_id:1;
61493- unsigned long show_host_port_type:1;
61494- unsigned long show_host_port_state:1;
61495- unsigned long show_host_active_fc4s:1;
61496- unsigned long show_host_speed:1;
61497- unsigned long show_host_fabric_name:1;
61498- unsigned long show_host_symbolic_name:1;
61499- unsigned long show_host_system_hostname:1;
61500+ const unsigned long show_host_port_id:1;
61501+ const unsigned long show_host_port_type:1;
61502+ const unsigned long show_host_port_state:1;
61503+ const unsigned long show_host_active_fc4s:1;
61504+ const unsigned long show_host_speed:1;
61505+ const unsigned long show_host_fabric_name:1;
61506+ const unsigned long show_host_symbolic_name:1;
61507+ const unsigned long show_host_system_hostname:1;
61508
61509- unsigned long disable_target_scan:1;
61510+ const unsigned long disable_target_scan:1;
61511 };
61512
61513
61514diff -urNp linux-2.6.32.43/include/sound/ac97_codec.h linux-2.6.32.43/include/sound/ac97_codec.h
61515--- linux-2.6.32.43/include/sound/ac97_codec.h 2011-03-27 14:31:47.000000000 -0400
61516+++ linux-2.6.32.43/include/sound/ac97_codec.h 2011-04-17 15:56:46.000000000 -0400
61517@@ -419,15 +419,15 @@
61518 struct snd_ac97;
61519
61520 struct snd_ac97_build_ops {
61521- int (*build_3d) (struct snd_ac97 *ac97);
61522- int (*build_specific) (struct snd_ac97 *ac97);
61523- int (*build_spdif) (struct snd_ac97 *ac97);
61524- int (*build_post_spdif) (struct snd_ac97 *ac97);
61525+ int (* const build_3d) (struct snd_ac97 *ac97);
61526+ int (* const build_specific) (struct snd_ac97 *ac97);
61527+ int (* const build_spdif) (struct snd_ac97 *ac97);
61528+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
61529 #ifdef CONFIG_PM
61530- void (*suspend) (struct snd_ac97 *ac97);
61531- void (*resume) (struct snd_ac97 *ac97);
61532+ void (* const suspend) (struct snd_ac97 *ac97);
61533+ void (* const resume) (struct snd_ac97 *ac97);
61534 #endif
61535- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
61536+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
61537 };
61538
61539 struct snd_ac97_bus_ops {
61540@@ -477,7 +477,7 @@ struct snd_ac97_template {
61541
61542 struct snd_ac97 {
61543 /* -- lowlevel (hardware) driver specific -- */
61544- struct snd_ac97_build_ops * build_ops;
61545+ const struct snd_ac97_build_ops * build_ops;
61546 void *private_data;
61547 void (*private_free) (struct snd_ac97 *ac97);
61548 /* --- */
61549diff -urNp linux-2.6.32.43/include/sound/ak4xxx-adda.h linux-2.6.32.43/include/sound/ak4xxx-adda.h
61550--- linux-2.6.32.43/include/sound/ak4xxx-adda.h 2011-03-27 14:31:47.000000000 -0400
61551+++ linux-2.6.32.43/include/sound/ak4xxx-adda.h 2011-08-05 20:33:55.000000000 -0400
61552@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
61553 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
61554 unsigned char val);
61555 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
61556-};
61557+} __no_const;
61558
61559 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
61560
61561diff -urNp linux-2.6.32.43/include/sound/hwdep.h linux-2.6.32.43/include/sound/hwdep.h
61562--- linux-2.6.32.43/include/sound/hwdep.h 2011-03-27 14:31:47.000000000 -0400
61563+++ linux-2.6.32.43/include/sound/hwdep.h 2011-08-05 20:33:55.000000000 -0400
61564@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
61565 struct snd_hwdep_dsp_status *status);
61566 int (*dsp_load)(struct snd_hwdep *hw,
61567 struct snd_hwdep_dsp_image *image);
61568-};
61569+} __no_const;
61570
61571 struct snd_hwdep {
61572 struct snd_card *card;
61573diff -urNp linux-2.6.32.43/include/sound/info.h linux-2.6.32.43/include/sound/info.h
61574--- linux-2.6.32.43/include/sound/info.h 2011-03-27 14:31:47.000000000 -0400
61575+++ linux-2.6.32.43/include/sound/info.h 2011-08-05 20:33:55.000000000 -0400
61576@@ -44,7 +44,7 @@ struct snd_info_entry_text {
61577 struct snd_info_buffer *buffer);
61578 void (*write)(struct snd_info_entry *entry,
61579 struct snd_info_buffer *buffer);
61580-};
61581+} __no_const;
61582
61583 struct snd_info_entry_ops {
61584 int (*open)(struct snd_info_entry *entry,
61585diff -urNp linux-2.6.32.43/include/sound/sb16_csp.h linux-2.6.32.43/include/sound/sb16_csp.h
61586--- linux-2.6.32.43/include/sound/sb16_csp.h 2011-03-27 14:31:47.000000000 -0400
61587+++ linux-2.6.32.43/include/sound/sb16_csp.h 2011-08-05 20:33:55.000000000 -0400
61588@@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
61589 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
61590 int (*csp_stop) (struct snd_sb_csp * p);
61591 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
61592-};
61593+} __no_const;
61594
61595 /*
61596 * CSP private data
61597diff -urNp linux-2.6.32.43/include/sound/ymfpci.h linux-2.6.32.43/include/sound/ymfpci.h
61598--- linux-2.6.32.43/include/sound/ymfpci.h 2011-03-27 14:31:47.000000000 -0400
61599+++ linux-2.6.32.43/include/sound/ymfpci.h 2011-05-04 17:56:28.000000000 -0400
61600@@ -358,7 +358,7 @@ struct snd_ymfpci {
61601 spinlock_t reg_lock;
61602 spinlock_t voice_lock;
61603 wait_queue_head_t interrupt_sleep;
61604- atomic_t interrupt_sleep_count;
61605+ atomic_unchecked_t interrupt_sleep_count;
61606 struct snd_info_entry *proc_entry;
61607 const struct firmware *dsp_microcode;
61608 const struct firmware *controller_microcode;
61609diff -urNp linux-2.6.32.43/include/trace/events/irq.h linux-2.6.32.43/include/trace/events/irq.h
61610--- linux-2.6.32.43/include/trace/events/irq.h 2011-03-27 14:31:47.000000000 -0400
61611+++ linux-2.6.32.43/include/trace/events/irq.h 2011-04-17 15:56:46.000000000 -0400
61612@@ -34,7 +34,7 @@
61613 */
61614 TRACE_EVENT(irq_handler_entry,
61615
61616- TP_PROTO(int irq, struct irqaction *action),
61617+ TP_PROTO(int irq, const struct irqaction *action),
61618
61619 TP_ARGS(irq, action),
61620
61621@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
61622 */
61623 TRACE_EVENT(irq_handler_exit,
61624
61625- TP_PROTO(int irq, struct irqaction *action, int ret),
61626+ TP_PROTO(int irq, const struct irqaction *action, int ret),
61627
61628 TP_ARGS(irq, action, ret),
61629
61630@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
61631 */
61632 TRACE_EVENT(softirq_entry,
61633
61634- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
61635+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
61636
61637 TP_ARGS(h, vec),
61638
61639@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
61640 */
61641 TRACE_EVENT(softirq_exit,
61642
61643- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
61644+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
61645
61646 TP_ARGS(h, vec),
61647
61648diff -urNp linux-2.6.32.43/include/video/uvesafb.h linux-2.6.32.43/include/video/uvesafb.h
61649--- linux-2.6.32.43/include/video/uvesafb.h 2011-03-27 14:31:47.000000000 -0400
61650+++ linux-2.6.32.43/include/video/uvesafb.h 2011-04-17 15:56:46.000000000 -0400
61651@@ -177,6 +177,7 @@ struct uvesafb_par {
61652 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
61653 u8 pmi_setpal; /* PMI for palette changes */
61654 u16 *pmi_base; /* protected mode interface location */
61655+ u8 *pmi_code; /* protected mode code location */
61656 void *pmi_start;
61657 void *pmi_pal;
61658 u8 *vbe_state_orig; /*
61659diff -urNp linux-2.6.32.43/init/do_mounts.c linux-2.6.32.43/init/do_mounts.c
61660--- linux-2.6.32.43/init/do_mounts.c 2011-03-27 14:31:47.000000000 -0400
61661+++ linux-2.6.32.43/init/do_mounts.c 2011-04-17 15:56:46.000000000 -0400
61662@@ -216,11 +216,11 @@ static void __init get_fs_names(char *pa
61663
61664 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
61665 {
61666- int err = sys_mount(name, "/root", fs, flags, data);
61667+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
61668 if (err)
61669 return err;
61670
61671- sys_chdir("/root");
61672+ sys_chdir((__force const char __user *)"/root");
61673 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
61674 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
61675 current->fs->pwd.mnt->mnt_sb->s_type->name,
61676@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...
61677 va_start(args, fmt);
61678 vsprintf(buf, fmt, args);
61679 va_end(args);
61680- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
61681+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
61682 if (fd >= 0) {
61683 sys_ioctl(fd, FDEJECT, 0);
61684 sys_close(fd);
61685 }
61686 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
61687- fd = sys_open("/dev/console", O_RDWR, 0);
61688+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
61689 if (fd >= 0) {
61690 sys_ioctl(fd, TCGETS, (long)&termios);
61691 termios.c_lflag &= ~ICANON;
61692 sys_ioctl(fd, TCSETSF, (long)&termios);
61693- sys_read(fd, &c, 1);
61694+ sys_read(fd, (char __user *)&c, 1);
61695 termios.c_lflag |= ICANON;
61696 sys_ioctl(fd, TCSETSF, (long)&termios);
61697 sys_close(fd);
61698@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
61699 mount_root();
61700 out:
61701 devtmpfs_mount("dev");
61702- sys_mount(".", "/", NULL, MS_MOVE, NULL);
61703- sys_chroot(".");
61704+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
61705+ sys_chroot((__force char __user *)".");
61706 }
61707diff -urNp linux-2.6.32.43/init/do_mounts.h linux-2.6.32.43/init/do_mounts.h
61708--- linux-2.6.32.43/init/do_mounts.h 2011-03-27 14:31:47.000000000 -0400
61709+++ linux-2.6.32.43/init/do_mounts.h 2011-04-17 15:56:46.000000000 -0400
61710@@ -15,15 +15,15 @@ extern int root_mountflags;
61711
61712 static inline int create_dev(char *name, dev_t dev)
61713 {
61714- sys_unlink(name);
61715- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
61716+ sys_unlink((__force char __user *)name);
61717+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
61718 }
61719
61720 #if BITS_PER_LONG == 32
61721 static inline u32 bstat(char *name)
61722 {
61723 struct stat64 stat;
61724- if (sys_stat64(name, &stat) != 0)
61725+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
61726 return 0;
61727 if (!S_ISBLK(stat.st_mode))
61728 return 0;
61729diff -urNp linux-2.6.32.43/init/do_mounts_initrd.c linux-2.6.32.43/init/do_mounts_initrd.c
61730--- linux-2.6.32.43/init/do_mounts_initrd.c 2011-03-27 14:31:47.000000000 -0400
61731+++ linux-2.6.32.43/init/do_mounts_initrd.c 2011-04-17 15:56:46.000000000 -0400
61732@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
61733 sys_close(old_fd);sys_close(root_fd);
61734 sys_close(0);sys_close(1);sys_close(2);
61735 sys_setsid();
61736- (void) sys_open("/dev/console",O_RDWR,0);
61737+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
61738 (void) sys_dup(0);
61739 (void) sys_dup(0);
61740 return kernel_execve(shell, argv, envp_init);
61741@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
61742 create_dev("/dev/root.old", Root_RAM0);
61743 /* mount initrd on rootfs' /root */
61744 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
61745- sys_mkdir("/old", 0700);
61746- root_fd = sys_open("/", 0, 0);
61747- old_fd = sys_open("/old", 0, 0);
61748+ sys_mkdir((__force const char __user *)"/old", 0700);
61749+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
61750+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
61751 /* move initrd over / and chdir/chroot in initrd root */
61752- sys_chdir("/root");
61753- sys_mount(".", "/", NULL, MS_MOVE, NULL);
61754- sys_chroot(".");
61755+ sys_chdir((__force const char __user *)"/root");
61756+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
61757+ sys_chroot((__force const char __user *)".");
61758
61759 /*
61760 * In case that a resume from disk is carried out by linuxrc or one of
61761@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
61762
61763 /* move initrd to rootfs' /old */
61764 sys_fchdir(old_fd);
61765- sys_mount("/", ".", NULL, MS_MOVE, NULL);
61766+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
61767 /* switch root and cwd back to / of rootfs */
61768 sys_fchdir(root_fd);
61769- sys_chroot(".");
61770+ sys_chroot((__force const char __user *)".");
61771 sys_close(old_fd);
61772 sys_close(root_fd);
61773
61774 if (new_decode_dev(real_root_dev) == Root_RAM0) {
61775- sys_chdir("/old");
61776+ sys_chdir((__force const char __user *)"/old");
61777 return;
61778 }
61779
61780@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
61781 mount_root();
61782
61783 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
61784- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
61785+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
61786 if (!error)
61787 printk("okay\n");
61788 else {
61789- int fd = sys_open("/dev/root.old", O_RDWR, 0);
61790+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
61791 if (error == -ENOENT)
61792 printk("/initrd does not exist. Ignored.\n");
61793 else
61794 printk("failed\n");
61795 printk(KERN_NOTICE "Unmounting old root\n");
61796- sys_umount("/old", MNT_DETACH);
61797+ sys_umount((__force char __user *)"/old", MNT_DETACH);
61798 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
61799 if (fd < 0) {
61800 error = fd;
61801@@ -119,11 +119,11 @@ int __init initrd_load(void)
61802 * mounted in the normal path.
61803 */
61804 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
61805- sys_unlink("/initrd.image");
61806+ sys_unlink((__force const char __user *)"/initrd.image");
61807 handle_initrd();
61808 return 1;
61809 }
61810 }
61811- sys_unlink("/initrd.image");
61812+ sys_unlink((__force const char __user *)"/initrd.image");
61813 return 0;
61814 }
61815diff -urNp linux-2.6.32.43/init/do_mounts_md.c linux-2.6.32.43/init/do_mounts_md.c
61816--- linux-2.6.32.43/init/do_mounts_md.c 2011-03-27 14:31:47.000000000 -0400
61817+++ linux-2.6.32.43/init/do_mounts_md.c 2011-04-17 15:56:46.000000000 -0400
61818@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
61819 partitioned ? "_d" : "", minor,
61820 md_setup_args[ent].device_names);
61821
61822- fd = sys_open(name, 0, 0);
61823+ fd = sys_open((__force char __user *)name, 0, 0);
61824 if (fd < 0) {
61825 printk(KERN_ERR "md: open failed - cannot start "
61826 "array %s\n", name);
61827@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
61828 * array without it
61829 */
61830 sys_close(fd);
61831- fd = sys_open(name, 0, 0);
61832+ fd = sys_open((__force char __user *)name, 0, 0);
61833 sys_ioctl(fd, BLKRRPART, 0);
61834 }
61835 sys_close(fd);
61836@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
61837
61838 wait_for_device_probe();
61839
61840- fd = sys_open("/dev/md0", 0, 0);
61841+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
61842 if (fd >= 0) {
61843 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
61844 sys_close(fd);
61845diff -urNp linux-2.6.32.43/init/initramfs.c linux-2.6.32.43/init/initramfs.c
61846--- linux-2.6.32.43/init/initramfs.c 2011-03-27 14:31:47.000000000 -0400
61847+++ linux-2.6.32.43/init/initramfs.c 2011-04-17 15:56:46.000000000 -0400
61848@@ -74,7 +74,7 @@ static void __init free_hash(void)
61849 }
61850 }
61851
61852-static long __init do_utime(char __user *filename, time_t mtime)
61853+static long __init do_utime(__force char __user *filename, time_t mtime)
61854 {
61855 struct timespec t[2];
61856
61857@@ -109,7 +109,7 @@ static void __init dir_utime(void)
61858 struct dir_entry *de, *tmp;
61859 list_for_each_entry_safe(de, tmp, &dir_list, list) {
61860 list_del(&de->list);
61861- do_utime(de->name, de->mtime);
61862+ do_utime((__force char __user *)de->name, de->mtime);
61863 kfree(de->name);
61864 kfree(de);
61865 }
61866@@ -271,7 +271,7 @@ static int __init maybe_link(void)
61867 if (nlink >= 2) {
61868 char *old = find_link(major, minor, ino, mode, collected);
61869 if (old)
61870- return (sys_link(old, collected) < 0) ? -1 : 1;
61871+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
61872 }
61873 return 0;
61874 }
61875@@ -280,11 +280,11 @@ static void __init clean_path(char *path
61876 {
61877 struct stat st;
61878
61879- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
61880+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
61881 if (S_ISDIR(st.st_mode))
61882- sys_rmdir(path);
61883+ sys_rmdir((__force char __user *)path);
61884 else
61885- sys_unlink(path);
61886+ sys_unlink((__force char __user *)path);
61887 }
61888 }
61889
61890@@ -305,7 +305,7 @@ static int __init do_name(void)
61891 int openflags = O_WRONLY|O_CREAT;
61892 if (ml != 1)
61893 openflags |= O_TRUNC;
61894- wfd = sys_open(collected, openflags, mode);
61895+ wfd = sys_open((__force char __user *)collected, openflags, mode);
61896
61897 if (wfd >= 0) {
61898 sys_fchown(wfd, uid, gid);
61899@@ -317,17 +317,17 @@ static int __init do_name(void)
61900 }
61901 }
61902 } else if (S_ISDIR(mode)) {
61903- sys_mkdir(collected, mode);
61904- sys_chown(collected, uid, gid);
61905- sys_chmod(collected, mode);
61906+ sys_mkdir((__force char __user *)collected, mode);
61907+ sys_chown((__force char __user *)collected, uid, gid);
61908+ sys_chmod((__force char __user *)collected, mode);
61909 dir_add(collected, mtime);
61910 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
61911 S_ISFIFO(mode) || S_ISSOCK(mode)) {
61912 if (maybe_link() == 0) {
61913- sys_mknod(collected, mode, rdev);
61914- sys_chown(collected, uid, gid);
61915- sys_chmod(collected, mode);
61916- do_utime(collected, mtime);
61917+ sys_mknod((__force char __user *)collected, mode, rdev);
61918+ sys_chown((__force char __user *)collected, uid, gid);
61919+ sys_chmod((__force char __user *)collected, mode);
61920+ do_utime((__force char __user *)collected, mtime);
61921 }
61922 }
61923 return 0;
61924@@ -336,15 +336,15 @@ static int __init do_name(void)
61925 static int __init do_copy(void)
61926 {
61927 if (count >= body_len) {
61928- sys_write(wfd, victim, body_len);
61929+ sys_write(wfd, (__force char __user *)victim, body_len);
61930 sys_close(wfd);
61931- do_utime(vcollected, mtime);
61932+ do_utime((__force char __user *)vcollected, mtime);
61933 kfree(vcollected);
61934 eat(body_len);
61935 state = SkipIt;
61936 return 0;
61937 } else {
61938- sys_write(wfd, victim, count);
61939+ sys_write(wfd, (__force char __user *)victim, count);
61940 body_len -= count;
61941 eat(count);
61942 return 1;
61943@@ -355,9 +355,9 @@ static int __init do_symlink(void)
61944 {
61945 collected[N_ALIGN(name_len) + body_len] = '\0';
61946 clean_path(collected, 0);
61947- sys_symlink(collected + N_ALIGN(name_len), collected);
61948- sys_lchown(collected, uid, gid);
61949- do_utime(collected, mtime);
61950+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
61951+ sys_lchown((__force char __user *)collected, uid, gid);
61952+ do_utime((__force char __user *)collected, mtime);
61953 state = SkipIt;
61954 next_state = Reset;
61955 return 0;
61956diff -urNp linux-2.6.32.43/init/Kconfig linux-2.6.32.43/init/Kconfig
61957--- linux-2.6.32.43/init/Kconfig 2011-05-10 22:12:01.000000000 -0400
61958+++ linux-2.6.32.43/init/Kconfig 2011-05-10 22:12:34.000000000 -0400
61959@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
61960
61961 config COMPAT_BRK
61962 bool "Disable heap randomization"
61963- default y
61964+ default n
61965 help
61966 Randomizing heap placement makes heap exploits harder, but it
61967 also breaks ancient binaries (including anything libc5 based).
61968diff -urNp linux-2.6.32.43/init/main.c linux-2.6.32.43/init/main.c
61969--- linux-2.6.32.43/init/main.c 2011-05-10 22:12:01.000000000 -0400
61970+++ linux-2.6.32.43/init/main.c 2011-08-05 20:33:55.000000000 -0400
61971@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void)
61972 #ifdef CONFIG_TC
61973 extern void tc_init(void);
61974 #endif
61975+extern void grsecurity_init(void);
61976
61977 enum system_states system_state __read_mostly;
61978 EXPORT_SYMBOL(system_state);
61979@@ -183,6 +184,49 @@ static int __init set_reset_devices(char
61980
61981 __setup("reset_devices", set_reset_devices);
61982
61983+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
61984+extern char pax_enter_kernel_user[];
61985+extern char pax_exit_kernel_user[];
61986+extern pgdval_t clone_pgd_mask;
61987+#endif
61988+
61989+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
61990+static int __init setup_pax_nouderef(char *str)
61991+{
61992+#ifdef CONFIG_X86_32
61993+ unsigned int cpu;
61994+ struct desc_struct *gdt;
61995+
61996+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
61997+ gdt = get_cpu_gdt_table(cpu);
61998+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
61999+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
62000+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
62001+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
62002+ }
62003+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
62004+#else
62005+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
62006+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
62007+ clone_pgd_mask = ~(pgdval_t)0UL;
62008+#endif
62009+
62010+ return 0;
62011+}
62012+early_param("pax_nouderef", setup_pax_nouderef);
62013+#endif
62014+
62015+#ifdef CONFIG_PAX_SOFTMODE
62016+int pax_softmode;
62017+
62018+static int __init setup_pax_softmode(char *str)
62019+{
62020+ get_option(&str, &pax_softmode);
62021+ return 1;
62022+}
62023+__setup("pax_softmode=", setup_pax_softmode);
62024+#endif
62025+
62026 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
62027 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
62028 static const char *panic_later, *panic_param;
62029@@ -705,52 +749,53 @@ int initcall_debug;
62030 core_param(initcall_debug, initcall_debug, bool, 0644);
62031
62032 static char msgbuf[64];
62033-static struct boot_trace_call call;
62034-static struct boot_trace_ret ret;
62035+static struct boot_trace_call trace_call;
62036+static struct boot_trace_ret trace_ret;
62037
62038 int do_one_initcall(initcall_t fn)
62039 {
62040 int count = preempt_count();
62041 ktime_t calltime, delta, rettime;
62042+ const char *msg1 = "", *msg2 = "";
62043
62044 if (initcall_debug) {
62045- call.caller = task_pid_nr(current);
62046- printk("calling %pF @ %i\n", fn, call.caller);
62047+ trace_call.caller = task_pid_nr(current);
62048+ printk("calling %pF @ %i\n", fn, trace_call.caller);
62049 calltime = ktime_get();
62050- trace_boot_call(&call, fn);
62051+ trace_boot_call(&trace_call, fn);
62052 enable_boot_trace();
62053 }
62054
62055- ret.result = fn();
62056+ trace_ret.result = fn();
62057
62058 if (initcall_debug) {
62059 disable_boot_trace();
62060 rettime = ktime_get();
62061 delta = ktime_sub(rettime, calltime);
62062- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
62063- trace_boot_ret(&ret, fn);
62064+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
62065+ trace_boot_ret(&trace_ret, fn);
62066 printk("initcall %pF returned %d after %Ld usecs\n", fn,
62067- ret.result, ret.duration);
62068+ trace_ret.result, trace_ret.duration);
62069 }
62070
62071 msgbuf[0] = 0;
62072
62073- if (ret.result && ret.result != -ENODEV && initcall_debug)
62074- sprintf(msgbuf, "error code %d ", ret.result);
62075+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
62076+ sprintf(msgbuf, "error code %d ", trace_ret.result);
62077
62078 if (preempt_count() != count) {
62079- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
62080+ msg1 = " preemption imbalance";
62081 preempt_count() = count;
62082 }
62083 if (irqs_disabled()) {
62084- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
62085+ msg2 = " disabled interrupts";
62086 local_irq_enable();
62087 }
62088- if (msgbuf[0]) {
62089- printk("initcall %pF returned with %s\n", fn, msgbuf);
62090+ if (msgbuf[0] || *msg1 || *msg2) {
62091+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
62092 }
62093
62094- return ret.result;
62095+ return trace_ret.result;
62096 }
62097
62098
62099@@ -893,11 +938,13 @@ static int __init kernel_init(void * unu
62100 if (!ramdisk_execute_command)
62101 ramdisk_execute_command = "/init";
62102
62103- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
62104+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
62105 ramdisk_execute_command = NULL;
62106 prepare_namespace();
62107 }
62108
62109+ grsecurity_init();
62110+
62111 /*
62112 * Ok, we have completed the initial bootup, and
62113 * we're essentially up and running. Get rid of the
62114diff -urNp linux-2.6.32.43/init/noinitramfs.c linux-2.6.32.43/init/noinitramfs.c
62115--- linux-2.6.32.43/init/noinitramfs.c 2011-03-27 14:31:47.000000000 -0400
62116+++ linux-2.6.32.43/init/noinitramfs.c 2011-04-17 15:56:46.000000000 -0400
62117@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
62118 {
62119 int err;
62120
62121- err = sys_mkdir("/dev", 0755);
62122+ err = sys_mkdir((const char __user *)"/dev", 0755);
62123 if (err < 0)
62124 goto out;
62125
62126@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
62127 if (err < 0)
62128 goto out;
62129
62130- err = sys_mkdir("/root", 0700);
62131+ err = sys_mkdir((const char __user *)"/root", 0700);
62132 if (err < 0)
62133 goto out;
62134
62135diff -urNp linux-2.6.32.43/ipc/mqueue.c linux-2.6.32.43/ipc/mqueue.c
62136--- linux-2.6.32.43/ipc/mqueue.c 2011-03-27 14:31:47.000000000 -0400
62137+++ linux-2.6.32.43/ipc/mqueue.c 2011-04-17 15:56:46.000000000 -0400
62138@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(st
62139 mq_bytes = (mq_msg_tblsz +
62140 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
62141
62142+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
62143 spin_lock(&mq_lock);
62144 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
62145 u->mq_bytes + mq_bytes >
62146diff -urNp linux-2.6.32.43/ipc/msg.c linux-2.6.32.43/ipc/msg.c
62147--- linux-2.6.32.43/ipc/msg.c 2011-03-27 14:31:47.000000000 -0400
62148+++ linux-2.6.32.43/ipc/msg.c 2011-08-05 20:33:55.000000000 -0400
62149@@ -310,18 +310,19 @@ static inline int msg_security(struct ke
62150 return security_msg_queue_associate(msq, msgflg);
62151 }
62152
62153+static struct ipc_ops msg_ops = {
62154+ .getnew = newque,
62155+ .associate = msg_security,
62156+ .more_checks = NULL
62157+};
62158+
62159 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
62160 {
62161 struct ipc_namespace *ns;
62162- struct ipc_ops msg_ops;
62163 struct ipc_params msg_params;
62164
62165 ns = current->nsproxy->ipc_ns;
62166
62167- msg_ops.getnew = newque;
62168- msg_ops.associate = msg_security;
62169- msg_ops.more_checks = NULL;
62170-
62171 msg_params.key = key;
62172 msg_params.flg = msgflg;
62173
62174diff -urNp linux-2.6.32.43/ipc/sem.c linux-2.6.32.43/ipc/sem.c
62175--- linux-2.6.32.43/ipc/sem.c 2011-03-27 14:31:47.000000000 -0400
62176+++ linux-2.6.32.43/ipc/sem.c 2011-08-05 20:33:55.000000000 -0400
62177@@ -309,10 +309,15 @@ static inline int sem_more_checks(struct
62178 return 0;
62179 }
62180
62181+static struct ipc_ops sem_ops = {
62182+ .getnew = newary,
62183+ .associate = sem_security,
62184+ .more_checks = sem_more_checks
62185+};
62186+
62187 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62188 {
62189 struct ipc_namespace *ns;
62190- struct ipc_ops sem_ops;
62191 struct ipc_params sem_params;
62192
62193 ns = current->nsproxy->ipc_ns;
62194@@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int,
62195 if (nsems < 0 || nsems > ns->sc_semmsl)
62196 return -EINVAL;
62197
62198- sem_ops.getnew = newary;
62199- sem_ops.associate = sem_security;
62200- sem_ops.more_checks = sem_more_checks;
62201-
62202 sem_params.key = key;
62203 sem_params.flg = semflg;
62204 sem_params.u.nsems = nsems;
62205@@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namesp
62206 ushort* sem_io = fast_sem_io;
62207 int nsems;
62208
62209+ pax_track_stack();
62210+
62211 sma = sem_lock_check(ns, semid);
62212 if (IS_ERR(sma))
62213 return PTR_ERR(sma);
62214@@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
62215 unsigned long jiffies_left = 0;
62216 struct ipc_namespace *ns;
62217
62218+ pax_track_stack();
62219+
62220 ns = current->nsproxy->ipc_ns;
62221
62222 if (nsops < 1 || semid < 0)
62223diff -urNp linux-2.6.32.43/ipc/shm.c linux-2.6.32.43/ipc/shm.c
62224--- linux-2.6.32.43/ipc/shm.c 2011-03-27 14:31:47.000000000 -0400
62225+++ linux-2.6.32.43/ipc/shm.c 2011-08-05 20:33:55.000000000 -0400
62226@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_name
62227 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
62228 #endif
62229
62230+#ifdef CONFIG_GRKERNSEC
62231+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62232+ const time_t shm_createtime, const uid_t cuid,
62233+ const int shmid);
62234+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62235+ const time_t shm_createtime);
62236+#endif
62237+
62238 void shm_init_ns(struct ipc_namespace *ns)
62239 {
62240 ns->shm_ctlmax = SHMMAX;
62241@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *
62242 shp->shm_lprid = 0;
62243 shp->shm_atim = shp->shm_dtim = 0;
62244 shp->shm_ctim = get_seconds();
62245+#ifdef CONFIG_GRKERNSEC
62246+ {
62247+ struct timespec timeval;
62248+ do_posix_clock_monotonic_gettime(&timeval);
62249+
62250+ shp->shm_createtime = timeval.tv_sec;
62251+ }
62252+#endif
62253 shp->shm_segsz = size;
62254 shp->shm_nattch = 0;
62255 shp->shm_file = file;
62256@@ -446,18 +462,19 @@ static inline int shm_more_checks(struct
62257 return 0;
62258 }
62259
62260+static struct ipc_ops shm_ops = {
62261+ .getnew = newseg,
62262+ .associate = shm_security,
62263+ .more_checks = shm_more_checks
62264+};
62265+
62266 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
62267 {
62268 struct ipc_namespace *ns;
62269- struct ipc_ops shm_ops;
62270 struct ipc_params shm_params;
62271
62272 ns = current->nsproxy->ipc_ns;
62273
62274- shm_ops.getnew = newseg;
62275- shm_ops.associate = shm_security;
62276- shm_ops.more_checks = shm_more_checks;
62277-
62278 shm_params.key = key;
62279 shm_params.flg = shmflg;
62280 shm_params.u.size = size;
62281@@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *sh
62282 if (err)
62283 goto out_unlock;
62284
62285+#ifdef CONFIG_GRKERNSEC
62286+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
62287+ shp->shm_perm.cuid, shmid) ||
62288+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
62289+ err = -EACCES;
62290+ goto out_unlock;
62291+ }
62292+#endif
62293+
62294 path.dentry = dget(shp->shm_file->f_path.dentry);
62295 path.mnt = shp->shm_file->f_path.mnt;
62296 shp->shm_nattch++;
62297+#ifdef CONFIG_GRKERNSEC
62298+ shp->shm_lapid = current->pid;
62299+#endif
62300 size = i_size_read(path.dentry->d_inode);
62301 shm_unlock(shp);
62302
62303diff -urNp linux-2.6.32.43/kernel/acct.c linux-2.6.32.43/kernel/acct.c
62304--- linux-2.6.32.43/kernel/acct.c 2011-03-27 14:31:47.000000000 -0400
62305+++ linux-2.6.32.43/kernel/acct.c 2011-04-17 15:56:46.000000000 -0400
62306@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_a
62307 */
62308 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
62309 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
62310- file->f_op->write(file, (char *)&ac,
62311+ file->f_op->write(file, (__force char __user *)&ac,
62312 sizeof(acct_t), &file->f_pos);
62313 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
62314 set_fs(fs);
62315diff -urNp linux-2.6.32.43/kernel/audit.c linux-2.6.32.43/kernel/audit.c
62316--- linux-2.6.32.43/kernel/audit.c 2011-03-27 14:31:47.000000000 -0400
62317+++ linux-2.6.32.43/kernel/audit.c 2011-05-04 17:56:28.000000000 -0400
62318@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
62319 3) suppressed due to audit_rate_limit
62320 4) suppressed due to audit_backlog_limit
62321 */
62322-static atomic_t audit_lost = ATOMIC_INIT(0);
62323+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
62324
62325 /* The netlink socket. */
62326 static struct sock *audit_sock;
62327@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
62328 unsigned long now;
62329 int print;
62330
62331- atomic_inc(&audit_lost);
62332+ atomic_inc_unchecked(&audit_lost);
62333
62334 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
62335
62336@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
62337 printk(KERN_WARNING
62338 "audit: audit_lost=%d audit_rate_limit=%d "
62339 "audit_backlog_limit=%d\n",
62340- atomic_read(&audit_lost),
62341+ atomic_read_unchecked(&audit_lost),
62342 audit_rate_limit,
62343 audit_backlog_limit);
62344 audit_panic(message);
62345@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_b
62346 status_set.pid = audit_pid;
62347 status_set.rate_limit = audit_rate_limit;
62348 status_set.backlog_limit = audit_backlog_limit;
62349- status_set.lost = atomic_read(&audit_lost);
62350+ status_set.lost = atomic_read_unchecked(&audit_lost);
62351 status_set.backlog = skb_queue_len(&audit_skb_queue);
62352 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
62353 &status_set, sizeof(status_set));
62354@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_b
62355 spin_unlock_irq(&tsk->sighand->siglock);
62356 }
62357 read_unlock(&tasklist_lock);
62358- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
62359- &s, sizeof(s));
62360+
62361+ if (!err)
62362+ audit_send_reply(NETLINK_CB(skb).pid, seq,
62363+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
62364 break;
62365 }
62366 case AUDIT_TTY_SET: {
62367diff -urNp linux-2.6.32.43/kernel/auditsc.c linux-2.6.32.43/kernel/auditsc.c
62368--- linux-2.6.32.43/kernel/auditsc.c 2011-03-27 14:31:47.000000000 -0400
62369+++ linux-2.6.32.43/kernel/auditsc.c 2011-05-04 17:56:28.000000000 -0400
62370@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_conte
62371 }
62372
62373 /* global counter which is incremented every time something logs in */
62374-static atomic_t session_id = ATOMIC_INIT(0);
62375+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
62376
62377 /**
62378 * audit_set_loginuid - set a task's audit_context loginuid
62379@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT
62380 */
62381 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
62382 {
62383- unsigned int sessionid = atomic_inc_return(&session_id);
62384+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
62385 struct audit_context *context = task->audit_context;
62386
62387 if (context && context->in_syscall) {
62388diff -urNp linux-2.6.32.43/kernel/capability.c linux-2.6.32.43/kernel/capability.c
62389--- linux-2.6.32.43/kernel/capability.c 2011-03-27 14:31:47.000000000 -0400
62390+++ linux-2.6.32.43/kernel/capability.c 2011-04-17 15:56:46.000000000 -0400
62391@@ -305,10 +305,26 @@ int capable(int cap)
62392 BUG();
62393 }
62394
62395- if (security_capable(cap) == 0) {
62396+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
62397 current->flags |= PF_SUPERPRIV;
62398 return 1;
62399 }
62400 return 0;
62401 }
62402+
62403+int capable_nolog(int cap)
62404+{
62405+ if (unlikely(!cap_valid(cap))) {
62406+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
62407+ BUG();
62408+ }
62409+
62410+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
62411+ current->flags |= PF_SUPERPRIV;
62412+ return 1;
62413+ }
62414+ return 0;
62415+}
62416+
62417 EXPORT_SYMBOL(capable);
62418+EXPORT_SYMBOL(capable_nolog);
62419diff -urNp linux-2.6.32.43/kernel/cgroup.c linux-2.6.32.43/kernel/cgroup.c
62420--- linux-2.6.32.43/kernel/cgroup.c 2011-03-27 14:31:47.000000000 -0400
62421+++ linux-2.6.32.43/kernel/cgroup.c 2011-05-16 21:46:57.000000000 -0400
62422@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
62423 struct hlist_head *hhead;
62424 struct cg_cgroup_link *link;
62425
62426+ pax_track_stack();
62427+
62428 /* First see if we already have a cgroup group that matches
62429 * the desired set */
62430 read_lock(&css_set_lock);
62431diff -urNp linux-2.6.32.43/kernel/configs.c linux-2.6.32.43/kernel/configs.c
62432--- linux-2.6.32.43/kernel/configs.c 2011-03-27 14:31:47.000000000 -0400
62433+++ linux-2.6.32.43/kernel/configs.c 2011-04-17 15:56:46.000000000 -0400
62434@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
62435 struct proc_dir_entry *entry;
62436
62437 /* create the current config file */
62438+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62439+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
62440+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
62441+ &ikconfig_file_ops);
62442+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62443+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
62444+ &ikconfig_file_ops);
62445+#endif
62446+#else
62447 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
62448 &ikconfig_file_ops);
62449+#endif
62450+
62451 if (!entry)
62452 return -ENOMEM;
62453
62454diff -urNp linux-2.6.32.43/kernel/cpu.c linux-2.6.32.43/kernel/cpu.c
62455--- linux-2.6.32.43/kernel/cpu.c 2011-03-27 14:31:47.000000000 -0400
62456+++ linux-2.6.32.43/kernel/cpu.c 2011-04-17 15:56:46.000000000 -0400
62457@@ -19,7 +19,7 @@
62458 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
62459 static DEFINE_MUTEX(cpu_add_remove_lock);
62460
62461-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
62462+static RAW_NOTIFIER_HEAD(cpu_chain);
62463
62464 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
62465 * Should always be manipulated under cpu_add_remove_lock
62466diff -urNp linux-2.6.32.43/kernel/cred.c linux-2.6.32.43/kernel/cred.c
62467--- linux-2.6.32.43/kernel/cred.c 2011-03-27 14:31:47.000000000 -0400
62468+++ linux-2.6.32.43/kernel/cred.c 2011-05-17 19:26:34.000000000 -0400
62469@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head
62470 */
62471 void __put_cred(struct cred *cred)
62472 {
62473+ pax_track_stack();
62474+
62475 kdebug("__put_cred(%p{%d,%d})", cred,
62476 atomic_read(&cred->usage),
62477 read_cred_subscribers(cred));
62478@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
62479 {
62480 struct cred *cred;
62481
62482+ pax_track_stack();
62483+
62484 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
62485 atomic_read(&tsk->cred->usage),
62486 read_cred_subscribers(tsk->cred));
62487@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct
62488 {
62489 const struct cred *cred;
62490
62491+ pax_track_stack();
62492+
62493 rcu_read_lock();
62494
62495 do {
62496@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
62497 {
62498 struct cred *new;
62499
62500+ pax_track_stack();
62501+
62502 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
62503 if (!new)
62504 return NULL;
62505@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
62506 const struct cred *old;
62507 struct cred *new;
62508
62509+ pax_track_stack();
62510+
62511 validate_process_creds();
62512
62513 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
62514@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
62515 struct thread_group_cred *tgcred = NULL;
62516 struct cred *new;
62517
62518+ pax_track_stack();
62519+
62520 #ifdef CONFIG_KEYS
62521 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
62522 if (!tgcred)
62523@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, un
62524 struct cred *new;
62525 int ret;
62526
62527+ pax_track_stack();
62528+
62529 mutex_init(&p->cred_guard_mutex);
62530
62531 if (
62532@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
62533 struct task_struct *task = current;
62534 const struct cred *old = task->real_cred;
62535
62536+ pax_track_stack();
62537+
62538 kdebug("commit_creds(%p{%d,%d})", new,
62539 atomic_read(&new->usage),
62540 read_cred_subscribers(new));
62541@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
62542
62543 get_cred(new); /* we will require a ref for the subj creds too */
62544
62545+ gr_set_role_label(task, new->uid, new->gid);
62546+
62547 /* dumpability changes */
62548 if (old->euid != new->euid ||
62549 old->egid != new->egid ||
62550@@ -606,6 +624,8 @@ EXPORT_SYMBOL(commit_creds);
62551 */
62552 void abort_creds(struct cred *new)
62553 {
62554+ pax_track_stack();
62555+
62556 kdebug("abort_creds(%p{%d,%d})", new,
62557 atomic_read(&new->usage),
62558 read_cred_subscribers(new));
62559@@ -629,6 +649,8 @@ const struct cred *override_creds(const
62560 {
62561 const struct cred *old = current->cred;
62562
62563+ pax_track_stack();
62564+
62565 kdebug("override_creds(%p{%d,%d})", new,
62566 atomic_read(&new->usage),
62567 read_cred_subscribers(new));
62568@@ -658,6 +680,8 @@ void revert_creds(const struct cred *old
62569 {
62570 const struct cred *override = current->cred;
62571
62572+ pax_track_stack();
62573+
62574 kdebug("revert_creds(%p{%d,%d})", old,
62575 atomic_read(&old->usage),
62576 read_cred_subscribers(old));
62577@@ -704,6 +728,8 @@ struct cred *prepare_kernel_cred(struct
62578 const struct cred *old;
62579 struct cred *new;
62580
62581+ pax_track_stack();
62582+
62583 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
62584 if (!new)
62585 return NULL;
62586@@ -758,6 +784,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
62587 */
62588 int set_security_override(struct cred *new, u32 secid)
62589 {
62590+ pax_track_stack();
62591+
62592 return security_kernel_act_as(new, secid);
62593 }
62594 EXPORT_SYMBOL(set_security_override);
62595@@ -777,6 +805,8 @@ int set_security_override_from_ctx(struc
62596 u32 secid;
62597 int ret;
62598
62599+ pax_track_stack();
62600+
62601 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
62602 if (ret < 0)
62603 return ret;
62604diff -urNp linux-2.6.32.43/kernel/exit.c linux-2.6.32.43/kernel/exit.c
62605--- linux-2.6.32.43/kernel/exit.c 2011-03-27 14:31:47.000000000 -0400
62606+++ linux-2.6.32.43/kernel/exit.c 2011-04-17 15:56:46.000000000 -0400
62607@@ -55,6 +55,10 @@
62608 #include <asm/pgtable.h>
62609 #include <asm/mmu_context.h>
62610
62611+#ifdef CONFIG_GRKERNSEC
62612+extern rwlock_t grsec_exec_file_lock;
62613+#endif
62614+
62615 static void exit_mm(struct task_struct * tsk);
62616
62617 static void __unhash_process(struct task_struct *p)
62618@@ -174,6 +178,8 @@ void release_task(struct task_struct * p
62619 struct task_struct *leader;
62620 int zap_leader;
62621 repeat:
62622+ gr_del_task_from_ip_table(p);
62623+
62624 tracehook_prepare_release_task(p);
62625 /* don't need to get the RCU readlock here - the process is dead and
62626 * can't be modifying its own credentials */
62627@@ -341,11 +347,22 @@ static void reparent_to_kthreadd(void)
62628 {
62629 write_lock_irq(&tasklist_lock);
62630
62631+#ifdef CONFIG_GRKERNSEC
62632+ write_lock(&grsec_exec_file_lock);
62633+ if (current->exec_file) {
62634+ fput(current->exec_file);
62635+ current->exec_file = NULL;
62636+ }
62637+ write_unlock(&grsec_exec_file_lock);
62638+#endif
62639+
62640 ptrace_unlink(current);
62641 /* Reparent to init */
62642 current->real_parent = current->parent = kthreadd_task;
62643 list_move_tail(&current->sibling, &current->real_parent->children);
62644
62645+ gr_set_kernel_label(current);
62646+
62647 /* Set the exit signal to SIGCHLD so we signal init on exit */
62648 current->exit_signal = SIGCHLD;
62649
62650@@ -397,7 +414,7 @@ int allow_signal(int sig)
62651 * know it'll be handled, so that they don't get converted to
62652 * SIGKILL or just silently dropped.
62653 */
62654- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
62655+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
62656 recalc_sigpending();
62657 spin_unlock_irq(&current->sighand->siglock);
62658 return 0;
62659@@ -433,6 +450,17 @@ void daemonize(const char *name, ...)
62660 vsnprintf(current->comm, sizeof(current->comm), name, args);
62661 va_end(args);
62662
62663+#ifdef CONFIG_GRKERNSEC
62664+ write_lock(&grsec_exec_file_lock);
62665+ if (current->exec_file) {
62666+ fput(current->exec_file);
62667+ current->exec_file = NULL;
62668+ }
62669+ write_unlock(&grsec_exec_file_lock);
62670+#endif
62671+
62672+ gr_set_kernel_label(current);
62673+
62674 /*
62675 * If we were started as result of loading a module, close all of the
62676 * user space pages. We don't need them, and if we didn't close them
62677@@ -897,17 +925,17 @@ NORET_TYPE void do_exit(long code)
62678 struct task_struct *tsk = current;
62679 int group_dead;
62680
62681- profile_task_exit(tsk);
62682-
62683- WARN_ON(atomic_read(&tsk->fs_excl));
62684-
62685+ /*
62686+ * Check this first since set_fs() below depends on
62687+ * current_thread_info(), which we better not access when we're in
62688+ * interrupt context. Other than that, we want to do the set_fs()
62689+ * as early as possible.
62690+ */
62691 if (unlikely(in_interrupt()))
62692 panic("Aiee, killing interrupt handler!");
62693- if (unlikely(!tsk->pid))
62694- panic("Attempted to kill the idle task!");
62695
62696 /*
62697- * If do_exit is called because this processes oopsed, it's possible
62698+ * If do_exit is called because this processes Oops'ed, it's possible
62699 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
62700 * continuing. Amongst other possible reasons, this is to prevent
62701 * mm_release()->clear_child_tid() from writing to a user-controlled
62702@@ -915,6 +943,13 @@ NORET_TYPE void do_exit(long code)
62703 */
62704 set_fs(USER_DS);
62705
62706+ profile_task_exit(tsk);
62707+
62708+ WARN_ON(atomic_read(&tsk->fs_excl));
62709+
62710+ if (unlikely(!tsk->pid))
62711+ panic("Attempted to kill the idle task!");
62712+
62713 tracehook_report_exit(&code);
62714
62715 validate_creds_for_do_exit(tsk);
62716@@ -973,6 +1008,9 @@ NORET_TYPE void do_exit(long code)
62717 tsk->exit_code = code;
62718 taskstats_exit(tsk, group_dead);
62719
62720+ gr_acl_handle_psacct(tsk, code);
62721+ gr_acl_handle_exit();
62722+
62723 exit_mm(tsk);
62724
62725 if (group_dead)
62726@@ -1188,7 +1226,7 @@ static int wait_task_zombie(struct wait_
62727
62728 if (unlikely(wo->wo_flags & WNOWAIT)) {
62729 int exit_code = p->exit_code;
62730- int why, status;
62731+ int why;
62732
62733 get_task_struct(p);
62734 read_unlock(&tasklist_lock);
62735diff -urNp linux-2.6.32.43/kernel/fork.c linux-2.6.32.43/kernel/fork.c
62736--- linux-2.6.32.43/kernel/fork.c 2011-03-27 14:31:47.000000000 -0400
62737+++ linux-2.6.32.43/kernel/fork.c 2011-04-17 15:56:46.000000000 -0400
62738@@ -253,7 +253,7 @@ static struct task_struct *dup_task_stru
62739 *stackend = STACK_END_MAGIC; /* for overflow detection */
62740
62741 #ifdef CONFIG_CC_STACKPROTECTOR
62742- tsk->stack_canary = get_random_int();
62743+ tsk->stack_canary = pax_get_random_long();
62744 #endif
62745
62746 /* One for us, one for whoever does the "release_task()" (usually parent) */
62747@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm
62748 mm->locked_vm = 0;
62749 mm->mmap = NULL;
62750 mm->mmap_cache = NULL;
62751- mm->free_area_cache = oldmm->mmap_base;
62752- mm->cached_hole_size = ~0UL;
62753+ mm->free_area_cache = oldmm->free_area_cache;
62754+ mm->cached_hole_size = oldmm->cached_hole_size;
62755 mm->map_count = 0;
62756 cpumask_clear(mm_cpumask(mm));
62757 mm->mm_rb = RB_ROOT;
62758@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm
62759 tmp->vm_flags &= ~VM_LOCKED;
62760 tmp->vm_mm = mm;
62761 tmp->vm_next = tmp->vm_prev = NULL;
62762+ tmp->vm_mirror = NULL;
62763 anon_vma_link(tmp);
62764 file = tmp->vm_file;
62765 if (file) {
62766@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm
62767 if (retval)
62768 goto out;
62769 }
62770+
62771+#ifdef CONFIG_PAX_SEGMEXEC
62772+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
62773+ struct vm_area_struct *mpnt_m;
62774+
62775+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
62776+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
62777+
62778+ if (!mpnt->vm_mirror)
62779+ continue;
62780+
62781+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
62782+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
62783+ mpnt->vm_mirror = mpnt_m;
62784+ } else {
62785+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
62786+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
62787+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
62788+ mpnt->vm_mirror->vm_mirror = mpnt;
62789+ }
62790+ }
62791+ BUG_ON(mpnt_m);
62792+ }
62793+#endif
62794+
62795 /* a new mm has just been created */
62796 arch_dup_mmap(oldmm, mm);
62797 retval = 0;
62798@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_f
62799 write_unlock(&fs->lock);
62800 return -EAGAIN;
62801 }
62802- fs->users++;
62803+ atomic_inc(&fs->users);
62804 write_unlock(&fs->lock);
62805 return 0;
62806 }
62807 tsk->fs = copy_fs_struct(fs);
62808 if (!tsk->fs)
62809 return -ENOMEM;
62810+ gr_set_chroot_entries(tsk, &tsk->fs->root);
62811 return 0;
62812 }
62813
62814@@ -1033,10 +1060,13 @@ static struct task_struct *copy_process(
62815 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
62816 #endif
62817 retval = -EAGAIN;
62818+
62819+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
62820+
62821 if (atomic_read(&p->real_cred->user->processes) >=
62822 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
62823- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
62824- p->real_cred->user != INIT_USER)
62825+ if (p->real_cred->user != INIT_USER &&
62826+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
62827 goto bad_fork_free;
62828 }
62829
62830@@ -1183,6 +1213,8 @@ static struct task_struct *copy_process(
62831 goto bad_fork_free_pid;
62832 }
62833
62834+ gr_copy_label(p);
62835+
62836 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
62837 /*
62838 * Clear TID on mm_release()?
62839@@ -1333,6 +1365,8 @@ bad_fork_cleanup_count:
62840 bad_fork_free:
62841 free_task(p);
62842 fork_out:
62843+ gr_log_forkfail(retval);
62844+
62845 return ERR_PTR(retval);
62846 }
62847
62848@@ -1426,6 +1460,8 @@ long do_fork(unsigned long clone_flags,
62849 if (clone_flags & CLONE_PARENT_SETTID)
62850 put_user(nr, parent_tidptr);
62851
62852+ gr_handle_brute_check();
62853+
62854 if (clone_flags & CLONE_VFORK) {
62855 p->vfork_done = &vfork;
62856 init_completion(&vfork);
62857@@ -1558,7 +1594,7 @@ static int unshare_fs(unsigned long unsh
62858 return 0;
62859
62860 /* don't need lock here; in the worst case we'll do useless copy */
62861- if (fs->users == 1)
62862+ if (atomic_read(&fs->users) == 1)
62863 return 0;
62864
62865 *new_fsp = copy_fs_struct(fs);
62866@@ -1681,7 +1717,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
62867 fs = current->fs;
62868 write_lock(&fs->lock);
62869 current->fs = new_fs;
62870- if (--fs->users)
62871+ gr_set_chroot_entries(current, &current->fs->root);
62872+ if (atomic_dec_return(&fs->users))
62873 new_fs = NULL;
62874 else
62875 new_fs = fs;
62876diff -urNp linux-2.6.32.43/kernel/futex.c linux-2.6.32.43/kernel/futex.c
62877--- linux-2.6.32.43/kernel/futex.c 2011-03-27 14:31:47.000000000 -0400
62878+++ linux-2.6.32.43/kernel/futex.c 2011-05-16 21:46:57.000000000 -0400
62879@@ -54,6 +54,7 @@
62880 #include <linux/mount.h>
62881 #include <linux/pagemap.h>
62882 #include <linux/syscalls.h>
62883+#include <linux/ptrace.h>
62884 #include <linux/signal.h>
62885 #include <linux/module.h>
62886 #include <linux/magic.h>
62887@@ -221,6 +222,11 @@ get_futex_key(u32 __user *uaddr, int fsh
62888 struct page *page;
62889 int err;
62890
62891+#ifdef CONFIG_PAX_SEGMEXEC
62892+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
62893+ return -EFAULT;
62894+#endif
62895+
62896 /*
62897 * The futex address must be "naturally" aligned.
62898 */
62899@@ -1789,6 +1795,8 @@ static int futex_wait(u32 __user *uaddr,
62900 struct futex_q q;
62901 int ret;
62902
62903+ pax_track_stack();
62904+
62905 if (!bitset)
62906 return -EINVAL;
62907
62908@@ -1841,7 +1849,7 @@ retry:
62909
62910 restart = &current_thread_info()->restart_block;
62911 restart->fn = futex_wait_restart;
62912- restart->futex.uaddr = (u32 *)uaddr;
62913+ restart->futex.uaddr = uaddr;
62914 restart->futex.val = val;
62915 restart->futex.time = abs_time->tv64;
62916 restart->futex.bitset = bitset;
62917@@ -2203,6 +2211,8 @@ static int futex_wait_requeue_pi(u32 __u
62918 struct futex_q q;
62919 int res, ret;
62920
62921+ pax_track_stack();
62922+
62923 if (!bitset)
62924 return -EINVAL;
62925
62926@@ -2377,7 +2387,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
62927 {
62928 struct robust_list_head __user *head;
62929 unsigned long ret;
62930+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
62931 const struct cred *cred = current_cred(), *pcred;
62932+#endif
62933
62934 if (!futex_cmpxchg_enabled)
62935 return -ENOSYS;
62936@@ -2393,11 +2405,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
62937 if (!p)
62938 goto err_unlock;
62939 ret = -EPERM;
62940+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62941+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
62942+ goto err_unlock;
62943+#else
62944 pcred = __task_cred(p);
62945 if (cred->euid != pcred->euid &&
62946 cred->euid != pcred->uid &&
62947 !capable(CAP_SYS_PTRACE))
62948 goto err_unlock;
62949+#endif
62950 head = p->robust_list;
62951 rcu_read_unlock();
62952 }
62953@@ -2459,7 +2476,7 @@ retry:
62954 */
62955 static inline int fetch_robust_entry(struct robust_list __user **entry,
62956 struct robust_list __user * __user *head,
62957- int *pi)
62958+ unsigned int *pi)
62959 {
62960 unsigned long uentry;
62961
62962@@ -2640,6 +2657,7 @@ static int __init futex_init(void)
62963 {
62964 u32 curval;
62965 int i;
62966+ mm_segment_t oldfs;
62967
62968 /*
62969 * This will fail and we want it. Some arch implementations do
62970@@ -2651,7 +2669,10 @@ static int __init futex_init(void)
62971 * implementation, the non functional ones will return
62972 * -ENOSYS.
62973 */
62974+ oldfs = get_fs();
62975+ set_fs(USER_DS);
62976 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
62977+ set_fs(oldfs);
62978 if (curval == -EFAULT)
62979 futex_cmpxchg_enabled = 1;
62980
62981diff -urNp linux-2.6.32.43/kernel/futex_compat.c linux-2.6.32.43/kernel/futex_compat.c
62982--- linux-2.6.32.43/kernel/futex_compat.c 2011-03-27 14:31:47.000000000 -0400
62983+++ linux-2.6.32.43/kernel/futex_compat.c 2011-04-17 15:56:46.000000000 -0400
62984@@ -10,6 +10,7 @@
62985 #include <linux/compat.h>
62986 #include <linux/nsproxy.h>
62987 #include <linux/futex.h>
62988+#include <linux/ptrace.h>
62989
62990 #include <asm/uaccess.h>
62991
62992@@ -135,7 +136,10 @@ compat_sys_get_robust_list(int pid, comp
62993 {
62994 struct compat_robust_list_head __user *head;
62995 unsigned long ret;
62996- const struct cred *cred = current_cred(), *pcred;
62997+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
62998+ const struct cred *cred = current_cred();
62999+ const struct cred *pcred;
63000+#endif
63001
63002 if (!futex_cmpxchg_enabled)
63003 return -ENOSYS;
63004@@ -151,11 +155,16 @@ compat_sys_get_robust_list(int pid, comp
63005 if (!p)
63006 goto err_unlock;
63007 ret = -EPERM;
63008+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63009+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
63010+ goto err_unlock;
63011+#else
63012 pcred = __task_cred(p);
63013 if (cred->euid != pcred->euid &&
63014 cred->euid != pcred->uid &&
63015 !capable(CAP_SYS_PTRACE))
63016 goto err_unlock;
63017+#endif
63018 head = p->compat_robust_list;
63019 read_unlock(&tasklist_lock);
63020 }
63021diff -urNp linux-2.6.32.43/kernel/gcov/base.c linux-2.6.32.43/kernel/gcov/base.c
63022--- linux-2.6.32.43/kernel/gcov/base.c 2011-03-27 14:31:47.000000000 -0400
63023+++ linux-2.6.32.43/kernel/gcov/base.c 2011-04-17 15:56:46.000000000 -0400
63024@@ -102,11 +102,6 @@ void gcov_enable_events(void)
63025 }
63026
63027 #ifdef CONFIG_MODULES
63028-static inline int within(void *addr, void *start, unsigned long size)
63029-{
63030- return ((addr >= start) && (addr < start + size));
63031-}
63032-
63033 /* Update list and generate events when modules are unloaded. */
63034 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63035 void *data)
63036@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
63037 prev = NULL;
63038 /* Remove entries located in module from linked list. */
63039 for (info = gcov_info_head; info; info = info->next) {
63040- if (within(info, mod->module_core, mod->core_size)) {
63041+ if (within_module_core_rw((unsigned long)info, mod)) {
63042 if (prev)
63043 prev->next = info->next;
63044 else
63045diff -urNp linux-2.6.32.43/kernel/hrtimer.c linux-2.6.32.43/kernel/hrtimer.c
63046--- linux-2.6.32.43/kernel/hrtimer.c 2011-03-27 14:31:47.000000000 -0400
63047+++ linux-2.6.32.43/kernel/hrtimer.c 2011-04-17 15:56:46.000000000 -0400
63048@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
63049 local_irq_restore(flags);
63050 }
63051
63052-static void run_hrtimer_softirq(struct softirq_action *h)
63053+static void run_hrtimer_softirq(void)
63054 {
63055 hrtimer_peek_ahead_timers();
63056 }
63057diff -urNp linux-2.6.32.43/kernel/kallsyms.c linux-2.6.32.43/kernel/kallsyms.c
63058--- linux-2.6.32.43/kernel/kallsyms.c 2011-03-27 14:31:47.000000000 -0400
63059+++ linux-2.6.32.43/kernel/kallsyms.c 2011-04-17 15:56:46.000000000 -0400
63060@@ -11,6 +11,9 @@
63061 * Changed the compression method from stem compression to "table lookup"
63062 * compression (see scripts/kallsyms.c for a more complete description)
63063 */
63064+#ifdef CONFIG_GRKERNSEC_HIDESYM
63065+#define __INCLUDED_BY_HIDESYM 1
63066+#endif
63067 #include <linux/kallsyms.h>
63068 #include <linux/module.h>
63069 #include <linux/init.h>
63070@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_mark
63071
63072 static inline int is_kernel_inittext(unsigned long addr)
63073 {
63074+ if (system_state != SYSTEM_BOOTING)
63075+ return 0;
63076+
63077 if (addr >= (unsigned long)_sinittext
63078 && addr <= (unsigned long)_einittext)
63079 return 1;
63080 return 0;
63081 }
63082
63083+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63084+#ifdef CONFIG_MODULES
63085+static inline int is_module_text(unsigned long addr)
63086+{
63087+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
63088+ return 1;
63089+
63090+ addr = ktla_ktva(addr);
63091+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
63092+}
63093+#else
63094+static inline int is_module_text(unsigned long addr)
63095+{
63096+ return 0;
63097+}
63098+#endif
63099+#endif
63100+
63101 static inline int is_kernel_text(unsigned long addr)
63102 {
63103 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
63104@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigne
63105
63106 static inline int is_kernel(unsigned long addr)
63107 {
63108+
63109+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63110+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
63111+ return 1;
63112+
63113+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
63114+#else
63115 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
63116+#endif
63117+
63118 return 1;
63119 return in_gate_area_no_task(addr);
63120 }
63121
63122 static int is_ksym_addr(unsigned long addr)
63123 {
63124+
63125+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63126+ if (is_module_text(addr))
63127+ return 0;
63128+#endif
63129+
63130 if (all_var)
63131 return is_kernel(addr);
63132
63133@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(st
63134
63135 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
63136 {
63137- iter->name[0] = '\0';
63138 iter->nameoff = get_symbol_offset(new_pos);
63139 iter->pos = new_pos;
63140 }
63141@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, vo
63142 {
63143 struct kallsym_iter *iter = m->private;
63144
63145+#ifdef CONFIG_GRKERNSEC_HIDESYM
63146+ if (current_uid())
63147+ return 0;
63148+#endif
63149+
63150 /* Some debugging symbols have no name. Ignore them. */
63151 if (!iter->name[0])
63152 return 0;
63153@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *i
63154 struct kallsym_iter *iter;
63155 int ret;
63156
63157- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
63158+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
63159 if (!iter)
63160 return -ENOMEM;
63161 reset_iter(iter, 0);
63162diff -urNp linux-2.6.32.43/kernel/kgdb.c linux-2.6.32.43/kernel/kgdb.c
63163--- linux-2.6.32.43/kernel/kgdb.c 2011-04-17 17:00:52.000000000 -0400
63164+++ linux-2.6.32.43/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
63165@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
63166 /* Guard for recursive entry */
63167 static int exception_level;
63168
63169-static struct kgdb_io *kgdb_io_ops;
63170+static const struct kgdb_io *kgdb_io_ops;
63171 static DEFINE_SPINLOCK(kgdb_registration_lock);
63172
63173 /* kgdb console driver is loaded */
63174@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1)
63175 */
63176 static atomic_t passive_cpu_wait[NR_CPUS];
63177 static atomic_t cpu_in_kgdb[NR_CPUS];
63178-atomic_t kgdb_setting_breakpoint;
63179+atomic_unchecked_t kgdb_setting_breakpoint;
63180
63181 struct task_struct *kgdb_usethread;
63182 struct task_struct *kgdb_contthread;
63183@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBY
63184 sizeof(unsigned long)];
63185
63186 /* to keep track of the CPU which is doing the single stepping*/
63187-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63188+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63189
63190 /*
63191 * If you are debugging a problem where roundup (the collection of
63192@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
63193 return 0;
63194 if (kgdb_connected)
63195 return 1;
63196- if (atomic_read(&kgdb_setting_breakpoint))
63197+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
63198 return 1;
63199 if (print_wait)
63200 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
63201@@ -1426,8 +1426,8 @@ acquirelock:
63202 * instance of the exception handler wanted to come into the
63203 * debugger on a different CPU via a single step
63204 */
63205- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
63206- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
63207+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
63208+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
63209
63210 atomic_set(&kgdb_active, -1);
63211 touch_softlockup_watchdog();
63212@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void
63213 *
63214 * Register it with the KGDB core.
63215 */
63216-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
63217+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
63218 {
63219 int err;
63220
63221@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
63222 *
63223 * Unregister it with the KGDB core.
63224 */
63225-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
63226+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
63227 {
63228 BUG_ON(kgdb_connected);
63229
63230@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod
63231 */
63232 void kgdb_breakpoint(void)
63233 {
63234- atomic_set(&kgdb_setting_breakpoint, 1);
63235+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
63236 wmb(); /* Sync point before breakpoint */
63237 arch_kgdb_breakpoint();
63238 wmb(); /* Sync point after breakpoint */
63239- atomic_set(&kgdb_setting_breakpoint, 0);
63240+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
63241 }
63242 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
63243
63244diff -urNp linux-2.6.32.43/kernel/kmod.c linux-2.6.32.43/kernel/kmod.c
63245--- linux-2.6.32.43/kernel/kmod.c 2011-03-27 14:31:47.000000000 -0400
63246+++ linux-2.6.32.43/kernel/kmod.c 2011-04-17 15:56:46.000000000 -0400
63247@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
63248 * If module auto-loading support is disabled then this function
63249 * becomes a no-operation.
63250 */
63251-int __request_module(bool wait, const char *fmt, ...)
63252+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
63253 {
63254- va_list args;
63255 char module_name[MODULE_NAME_LEN];
63256 unsigned int max_modprobes;
63257 int ret;
63258- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
63259+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
63260 static char *envp[] = { "HOME=/",
63261 "TERM=linux",
63262 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
63263@@ -84,12 +83,24 @@ int __request_module(bool wait, const ch
63264 if (ret)
63265 return ret;
63266
63267- va_start(args, fmt);
63268- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
63269- va_end(args);
63270+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
63271 if (ret >= MODULE_NAME_LEN)
63272 return -ENAMETOOLONG;
63273
63274+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63275+ if (!current_uid()) {
63276+ /* hack to workaround consolekit/udisks stupidity */
63277+ read_lock(&tasklist_lock);
63278+ if (!strcmp(current->comm, "mount") &&
63279+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
63280+ read_unlock(&tasklist_lock);
63281+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
63282+ return -EPERM;
63283+ }
63284+ read_unlock(&tasklist_lock);
63285+ }
63286+#endif
63287+
63288 /* If modprobe needs a service that is in a module, we get a recursive
63289 * loop. Limit the number of running kmod threads to max_threads/2 or
63290 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
63291@@ -121,6 +132,48 @@ int __request_module(bool wait, const ch
63292 atomic_dec(&kmod_concurrent);
63293 return ret;
63294 }
63295+
63296+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
63297+{
63298+ va_list args;
63299+ int ret;
63300+
63301+ va_start(args, fmt);
63302+ ret = ____request_module(wait, module_param, fmt, args);
63303+ va_end(args);
63304+
63305+ return ret;
63306+}
63307+
63308+int __request_module(bool wait, const char *fmt, ...)
63309+{
63310+ va_list args;
63311+ int ret;
63312+
63313+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63314+ if (current_uid()) {
63315+ char module_param[MODULE_NAME_LEN];
63316+
63317+ memset(module_param, 0, sizeof(module_param));
63318+
63319+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
63320+
63321+ va_start(args, fmt);
63322+ ret = ____request_module(wait, module_param, fmt, args);
63323+ va_end(args);
63324+
63325+ return ret;
63326+ }
63327+#endif
63328+
63329+ va_start(args, fmt);
63330+ ret = ____request_module(wait, NULL, fmt, args);
63331+ va_end(args);
63332+
63333+ return ret;
63334+}
63335+
63336+
63337 EXPORT_SYMBOL(__request_module);
63338 #endif /* CONFIG_MODULES */
63339
63340diff -urNp linux-2.6.32.43/kernel/kprobes.c linux-2.6.32.43/kernel/kprobes.c
63341--- linux-2.6.32.43/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
63342+++ linux-2.6.32.43/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
63343@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_
63344 * kernel image and loaded module images reside. This is required
63345 * so x86_64 can correctly handle the %rip-relative fixups.
63346 */
63347- kip->insns = module_alloc(PAGE_SIZE);
63348+ kip->insns = module_alloc_exec(PAGE_SIZE);
63349 if (!kip->insns) {
63350 kfree(kip);
63351 return NULL;
63352@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(st
63353 */
63354 if (!list_is_singular(&kprobe_insn_pages)) {
63355 list_del(&kip->list);
63356- module_free(NULL, kip->insns);
63357+ module_free_exec(NULL, kip->insns);
63358 kfree(kip);
63359 }
63360 return 1;
63361@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
63362 {
63363 int i, err = 0;
63364 unsigned long offset = 0, size = 0;
63365- char *modname, namebuf[128];
63366+ char *modname, namebuf[KSYM_NAME_LEN];
63367 const char *symbol_name;
63368 void *addr;
63369 struct kprobe_blackpoint *kb;
63370@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(st
63371 const char *sym = NULL;
63372 unsigned int i = *(loff_t *) v;
63373 unsigned long offset = 0;
63374- char *modname, namebuf[128];
63375+ char *modname, namebuf[KSYM_NAME_LEN];
63376
63377 head = &kprobe_table[i];
63378 preempt_disable();
63379diff -urNp linux-2.6.32.43/kernel/lockdep.c linux-2.6.32.43/kernel/lockdep.c
63380--- linux-2.6.32.43/kernel/lockdep.c 2011-06-25 12:55:35.000000000 -0400
63381+++ linux-2.6.32.43/kernel/lockdep.c 2011-06-25 12:56:37.000000000 -0400
63382@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_t
63383 /*
63384 * Various lockdep statistics:
63385 */
63386-atomic_t chain_lookup_hits;
63387-atomic_t chain_lookup_misses;
63388-atomic_t hardirqs_on_events;
63389-atomic_t hardirqs_off_events;
63390-atomic_t redundant_hardirqs_on;
63391-atomic_t redundant_hardirqs_off;
63392-atomic_t softirqs_on_events;
63393-atomic_t softirqs_off_events;
63394-atomic_t redundant_softirqs_on;
63395-atomic_t redundant_softirqs_off;
63396-atomic_t nr_unused_locks;
63397-atomic_t nr_cyclic_checks;
63398-atomic_t nr_find_usage_forwards_checks;
63399-atomic_t nr_find_usage_backwards_checks;
63400+atomic_unchecked_t chain_lookup_hits;
63401+atomic_unchecked_t chain_lookup_misses;
63402+atomic_unchecked_t hardirqs_on_events;
63403+atomic_unchecked_t hardirqs_off_events;
63404+atomic_unchecked_t redundant_hardirqs_on;
63405+atomic_unchecked_t redundant_hardirqs_off;
63406+atomic_unchecked_t softirqs_on_events;
63407+atomic_unchecked_t softirqs_off_events;
63408+atomic_unchecked_t redundant_softirqs_on;
63409+atomic_unchecked_t redundant_softirqs_off;
63410+atomic_unchecked_t nr_unused_locks;
63411+atomic_unchecked_t nr_cyclic_checks;
63412+atomic_unchecked_t nr_find_usage_forwards_checks;
63413+atomic_unchecked_t nr_find_usage_backwards_checks;
63414 #endif
63415
63416 /*
63417@@ -577,6 +577,10 @@ static int static_obj(void *obj)
63418 int i;
63419 #endif
63420
63421+#ifdef CONFIG_PAX_KERNEXEC
63422+ start = ktla_ktva(start);
63423+#endif
63424+
63425 /*
63426 * static variable?
63427 */
63428@@ -592,8 +596,7 @@ static int static_obj(void *obj)
63429 */
63430 for_each_possible_cpu(i) {
63431 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
63432- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
63433- + per_cpu_offset(i);
63434+ end = start + PERCPU_ENOUGH_ROOM;
63435
63436 if ((addr >= start) && (addr < end))
63437 return 1;
63438@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *
63439 if (!static_obj(lock->key)) {
63440 debug_locks_off();
63441 printk("INFO: trying to register non-static key.\n");
63442+ printk("lock:%pS key:%pS.\n", lock, lock->key);
63443 printk("the code is fine but needs lockdep annotation.\n");
63444 printk("turning off the locking correctness validator.\n");
63445 dump_stack();
63446@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep
63447 if (!class)
63448 return 0;
63449 }
63450- debug_atomic_inc((atomic_t *)&class->ops);
63451+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
63452 if (very_verbose(class)) {
63453 printk("\nacquire class [%p] %s", class->key, class->name);
63454 if (class->name_version > 1)
63455diff -urNp linux-2.6.32.43/kernel/lockdep_internals.h linux-2.6.32.43/kernel/lockdep_internals.h
63456--- linux-2.6.32.43/kernel/lockdep_internals.h 2011-03-27 14:31:47.000000000 -0400
63457+++ linux-2.6.32.43/kernel/lockdep_internals.h 2011-04-17 15:56:46.000000000 -0400
63458@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_
63459 /*
63460 * Various lockdep statistics:
63461 */
63462-extern atomic_t chain_lookup_hits;
63463-extern atomic_t chain_lookup_misses;
63464-extern atomic_t hardirqs_on_events;
63465-extern atomic_t hardirqs_off_events;
63466-extern atomic_t redundant_hardirqs_on;
63467-extern atomic_t redundant_hardirqs_off;
63468-extern atomic_t softirqs_on_events;
63469-extern atomic_t softirqs_off_events;
63470-extern atomic_t redundant_softirqs_on;
63471-extern atomic_t redundant_softirqs_off;
63472-extern atomic_t nr_unused_locks;
63473-extern atomic_t nr_cyclic_checks;
63474-extern atomic_t nr_cyclic_check_recursions;
63475-extern atomic_t nr_find_usage_forwards_checks;
63476-extern atomic_t nr_find_usage_forwards_recursions;
63477-extern atomic_t nr_find_usage_backwards_checks;
63478-extern atomic_t nr_find_usage_backwards_recursions;
63479-# define debug_atomic_inc(ptr) atomic_inc(ptr)
63480-# define debug_atomic_dec(ptr) atomic_dec(ptr)
63481-# define debug_atomic_read(ptr) atomic_read(ptr)
63482+extern atomic_unchecked_t chain_lookup_hits;
63483+extern atomic_unchecked_t chain_lookup_misses;
63484+extern atomic_unchecked_t hardirqs_on_events;
63485+extern atomic_unchecked_t hardirqs_off_events;
63486+extern atomic_unchecked_t redundant_hardirqs_on;
63487+extern atomic_unchecked_t redundant_hardirqs_off;
63488+extern atomic_unchecked_t softirqs_on_events;
63489+extern atomic_unchecked_t softirqs_off_events;
63490+extern atomic_unchecked_t redundant_softirqs_on;
63491+extern atomic_unchecked_t redundant_softirqs_off;
63492+extern atomic_unchecked_t nr_unused_locks;
63493+extern atomic_unchecked_t nr_cyclic_checks;
63494+extern atomic_unchecked_t nr_cyclic_check_recursions;
63495+extern atomic_unchecked_t nr_find_usage_forwards_checks;
63496+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
63497+extern atomic_unchecked_t nr_find_usage_backwards_checks;
63498+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
63499+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
63500+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
63501+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
63502 #else
63503 # define debug_atomic_inc(ptr) do { } while (0)
63504 # define debug_atomic_dec(ptr) do { } while (0)
63505diff -urNp linux-2.6.32.43/kernel/lockdep_proc.c linux-2.6.32.43/kernel/lockdep_proc.c
63506--- linux-2.6.32.43/kernel/lockdep_proc.c 2011-03-27 14:31:47.000000000 -0400
63507+++ linux-2.6.32.43/kernel/lockdep_proc.c 2011-04-17 15:56:46.000000000 -0400
63508@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
63509
63510 static void print_name(struct seq_file *m, struct lock_class *class)
63511 {
63512- char str[128];
63513+ char str[KSYM_NAME_LEN];
63514 const char *name = class->name;
63515
63516 if (!name) {
63517diff -urNp linux-2.6.32.43/kernel/module.c linux-2.6.32.43/kernel/module.c
63518--- linux-2.6.32.43/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
63519+++ linux-2.6.32.43/kernel/module.c 2011-04-29 18:52:40.000000000 -0400
63520@@ -55,6 +55,7 @@
63521 #include <linux/async.h>
63522 #include <linux/percpu.h>
63523 #include <linux/kmemleak.h>
63524+#include <linux/grsecurity.h>
63525
63526 #define CREATE_TRACE_POINTS
63527 #include <trace/events/module.h>
63528@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
63529 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
63530
63531 /* Bounds of module allocation, for speeding __module_address */
63532-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
63533+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
63534+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
63535
63536 int register_module_notifier(struct notifier_block * nb)
63537 {
63538@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct
63539 return true;
63540
63541 list_for_each_entry_rcu(mod, &modules, list) {
63542- struct symsearch arr[] = {
63543+ struct symsearch modarr[] = {
63544 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
63545 NOT_GPL_ONLY, false },
63546 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
63547@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct
63548 #endif
63549 };
63550
63551- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
63552+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
63553 return true;
63554 }
63555 return false;
63556@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned lo
63557 void *ptr;
63558 int cpu;
63559
63560- if (align > PAGE_SIZE) {
63561+ if (align-1 >= PAGE_SIZE) {
63562 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
63563 name, align, PAGE_SIZE);
63564 align = PAGE_SIZE;
63565@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resol
63566 * /sys/module/foo/sections stuff
63567 * J. Corbet <corbet@lwn.net>
63568 */
63569-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
63570+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63571
63572 static inline bool sect_empty(const Elf_Shdr *sect)
63573 {
63574@@ -1545,7 +1547,8 @@ static void free_module(struct module *m
63575 destroy_params(mod->kp, mod->num_kp);
63576
63577 /* This may be NULL, but that's OK */
63578- module_free(mod, mod->module_init);
63579+ module_free(mod, mod->module_init_rw);
63580+ module_free_exec(mod, mod->module_init_rx);
63581 kfree(mod->args);
63582 if (mod->percpu)
63583 percpu_modfree(mod->percpu);
63584@@ -1554,10 +1557,12 @@ static void free_module(struct module *m
63585 percpu_modfree(mod->refptr);
63586 #endif
63587 /* Free lock-classes: */
63588- lockdep_free_key_range(mod->module_core, mod->core_size);
63589+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
63590+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
63591
63592 /* Finally, free the core (containing the module structure) */
63593- module_free(mod, mod->module_core);
63594+ module_free_exec(mod, mod->module_core_rx);
63595+ module_free(mod, mod->module_core_rw);
63596
63597 #ifdef CONFIG_MPU
63598 update_protections(current->mm);
63599@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *se
63600 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
63601 int ret = 0;
63602 const struct kernel_symbol *ksym;
63603+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63604+ int is_fs_load = 0;
63605+ int register_filesystem_found = 0;
63606+ char *p;
63607+
63608+ p = strstr(mod->args, "grsec_modharden_fs");
63609+
63610+ if (p) {
63611+ char *endptr = p + strlen("grsec_modharden_fs");
63612+ /* copy \0 as well */
63613+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
63614+ is_fs_load = 1;
63615+ }
63616+#endif
63617+
63618
63619 for (i = 1; i < n; i++) {
63620+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63621+ const char *name = strtab + sym[i].st_name;
63622+
63623+ /* it's a real shame this will never get ripped and copied
63624+ upstream! ;(
63625+ */
63626+ if (is_fs_load && !strcmp(name, "register_filesystem"))
63627+ register_filesystem_found = 1;
63628+#endif
63629 switch (sym[i].st_shndx) {
63630 case SHN_COMMON:
63631 /* We compiled with -fno-common. These are not
63632@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *se
63633 strtab + sym[i].st_name, mod);
63634 /* Ok if resolved. */
63635 if (ksym) {
63636+ pax_open_kernel();
63637 sym[i].st_value = ksym->value;
63638+ pax_close_kernel();
63639 break;
63640 }
63641
63642@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *se
63643 secbase = (unsigned long)mod->percpu;
63644 else
63645 secbase = sechdrs[sym[i].st_shndx].sh_addr;
63646+ pax_open_kernel();
63647 sym[i].st_value += secbase;
63648+ pax_close_kernel();
63649 break;
63650 }
63651 }
63652
63653+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63654+ if (is_fs_load && !register_filesystem_found) {
63655+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
63656+ ret = -EPERM;
63657+ }
63658+#endif
63659+
63660 return ret;
63661 }
63662
63663@@ -1731,11 +1771,12 @@ static void layout_sections(struct modul
63664 || s->sh_entsize != ~0UL
63665 || strstarts(secstrings + s->sh_name, ".init"))
63666 continue;
63667- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
63668+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
63669+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
63670+ else
63671+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
63672 DEBUGP("\t%s\n", secstrings + s->sh_name);
63673 }
63674- if (m == 0)
63675- mod->core_text_size = mod->core_size;
63676 }
63677
63678 DEBUGP("Init section allocation order:\n");
63679@@ -1748,12 +1789,13 @@ static void layout_sections(struct modul
63680 || s->sh_entsize != ~0UL
63681 || !strstarts(secstrings + s->sh_name, ".init"))
63682 continue;
63683- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
63684- | INIT_OFFSET_MASK);
63685+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
63686+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
63687+ else
63688+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
63689+ s->sh_entsize |= INIT_OFFSET_MASK;
63690 DEBUGP("\t%s\n", secstrings + s->sh_name);
63691 }
63692- if (m == 0)
63693- mod->init_text_size = mod->init_size;
63694 }
63695 }
63696
63697@@ -1857,9 +1899,8 @@ static int is_exported(const char *name,
63698
63699 /* As per nm */
63700 static char elf_type(const Elf_Sym *sym,
63701- Elf_Shdr *sechdrs,
63702- const char *secstrings,
63703- struct module *mod)
63704+ const Elf_Shdr *sechdrs,
63705+ const char *secstrings)
63706 {
63707 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
63708 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
63709@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struc
63710
63711 /* Put symbol section at end of init part of module. */
63712 symsect->sh_flags |= SHF_ALLOC;
63713- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
63714+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
63715 symindex) | INIT_OFFSET_MASK;
63716 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
63717
63718@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struc
63719 }
63720
63721 /* Append room for core symbols at end of core part. */
63722- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
63723- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
63724+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
63725+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
63726
63727 /* Put string table section at end of init part of module. */
63728 strsect->sh_flags |= SHF_ALLOC;
63729- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
63730+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
63731 strindex) | INIT_OFFSET_MASK;
63732 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
63733
63734 /* Append room for core symbols' strings at end of core part. */
63735- *pstroffs = mod->core_size;
63736+ *pstroffs = mod->core_size_rx;
63737 __set_bit(0, strmap);
63738- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
63739+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
63740
63741 return symoffs;
63742 }
63743@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *
63744 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
63745 mod->strtab = (void *)sechdrs[strindex].sh_addr;
63746
63747+ pax_open_kernel();
63748+
63749 /* Set types up while we still have access to sections. */
63750 for (i = 0; i < mod->num_symtab; i++)
63751 mod->symtab[i].st_info
63752- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
63753+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
63754
63755- mod->core_symtab = dst = mod->module_core + symoffs;
63756+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
63757 src = mod->symtab;
63758 *dst = *src;
63759 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
63760@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *
63761 }
63762 mod->core_num_syms = ndst;
63763
63764- mod->core_strtab = s = mod->module_core + stroffs;
63765+ mod->core_strtab = s = mod->module_core_rx + stroffs;
63766 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
63767 if (test_bit(i, strmap))
63768 *++s = mod->strtab[i];
63769+
63770+ pax_close_kernel();
63771 }
63772 #else
63773 static inline unsigned long layout_symtab(struct module *mod,
63774@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _
63775 #endif
63776 }
63777
63778-static void *module_alloc_update_bounds(unsigned long size)
63779+static void *module_alloc_update_bounds_rw(unsigned long size)
63780 {
63781 void *ret = module_alloc(size);
63782
63783 if (ret) {
63784 /* Update module bounds. */
63785- if ((unsigned long)ret < module_addr_min)
63786- module_addr_min = (unsigned long)ret;
63787- if ((unsigned long)ret + size > module_addr_max)
63788- module_addr_max = (unsigned long)ret + size;
63789+ if ((unsigned long)ret < module_addr_min_rw)
63790+ module_addr_min_rw = (unsigned long)ret;
63791+ if ((unsigned long)ret + size > module_addr_max_rw)
63792+ module_addr_max_rw = (unsigned long)ret + size;
63793+ }
63794+ return ret;
63795+}
63796+
63797+static void *module_alloc_update_bounds_rx(unsigned long size)
63798+{
63799+ void *ret = module_alloc_exec(size);
63800+
63801+ if (ret) {
63802+ /* Update module bounds. */
63803+ if ((unsigned long)ret < module_addr_min_rx)
63804+ module_addr_min_rx = (unsigned long)ret;
63805+ if ((unsigned long)ret + size > module_addr_max_rx)
63806+ module_addr_max_rx = (unsigned long)ret + size;
63807 }
63808 return ret;
63809 }
63810@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct
63811 unsigned int i;
63812
63813 /* only scan the sections containing data */
63814- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
63815- (unsigned long)mod->module_core,
63816+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
63817+ (unsigned long)mod->module_core_rw,
63818 sizeof(struct module), GFP_KERNEL);
63819
63820 for (i = 1; i < hdr->e_shnum; i++) {
63821@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct
63822 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
63823 continue;
63824
63825- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
63826- (unsigned long)mod->module_core,
63827+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
63828+ (unsigned long)mod->module_core_rw,
63829 sechdrs[i].sh_size, GFP_KERNEL);
63830 }
63831 }
63832@@ -2263,7 +2322,7 @@ static noinline struct module *load_modu
63833 secstrings, &stroffs, strmap);
63834
63835 /* Do the allocs. */
63836- ptr = module_alloc_update_bounds(mod->core_size);
63837+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
63838 /*
63839 * The pointer to this block is stored in the module structure
63840 * which is inside the block. Just mark it as not being a
63841@@ -2274,23 +2333,47 @@ static noinline struct module *load_modu
63842 err = -ENOMEM;
63843 goto free_percpu;
63844 }
63845- memset(ptr, 0, mod->core_size);
63846- mod->module_core = ptr;
63847+ memset(ptr, 0, mod->core_size_rw);
63848+ mod->module_core_rw = ptr;
63849
63850- ptr = module_alloc_update_bounds(mod->init_size);
63851+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
63852 /*
63853 * The pointer to this block is stored in the module structure
63854 * which is inside the block. This block doesn't need to be
63855 * scanned as it contains data and code that will be freed
63856 * after the module is initialized.
63857 */
63858- kmemleak_ignore(ptr);
63859- if (!ptr && mod->init_size) {
63860+ kmemleak_not_leak(ptr);
63861+ if (!ptr && mod->init_size_rw) {
63862+ err = -ENOMEM;
63863+ goto free_core_rw;
63864+ }
63865+ memset(ptr, 0, mod->init_size_rw);
63866+ mod->module_init_rw = ptr;
63867+
63868+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
63869+ kmemleak_not_leak(ptr);
63870+ if (!ptr) {
63871 err = -ENOMEM;
63872- goto free_core;
63873+ goto free_init_rw;
63874 }
63875- memset(ptr, 0, mod->init_size);
63876- mod->module_init = ptr;
63877+
63878+ pax_open_kernel();
63879+ memset(ptr, 0, mod->core_size_rx);
63880+ pax_close_kernel();
63881+ mod->module_core_rx = ptr;
63882+
63883+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
63884+ kmemleak_not_leak(ptr);
63885+ if (!ptr && mod->init_size_rx) {
63886+ err = -ENOMEM;
63887+ goto free_core_rx;
63888+ }
63889+
63890+ pax_open_kernel();
63891+ memset(ptr, 0, mod->init_size_rx);
63892+ pax_close_kernel();
63893+ mod->module_init_rx = ptr;
63894
63895 /* Transfer each section which specifies SHF_ALLOC */
63896 DEBUGP("final section addresses:\n");
63897@@ -2300,17 +2383,45 @@ static noinline struct module *load_modu
63898 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
63899 continue;
63900
63901- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
63902- dest = mod->module_init
63903- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
63904- else
63905- dest = mod->module_core + sechdrs[i].sh_entsize;
63906+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
63907+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
63908+ dest = mod->module_init_rw
63909+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
63910+ else
63911+ dest = mod->module_init_rx
63912+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
63913+ } else {
63914+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
63915+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
63916+ else
63917+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
63918+ }
63919+
63920+ if (sechdrs[i].sh_type != SHT_NOBITS) {
63921
63922- if (sechdrs[i].sh_type != SHT_NOBITS)
63923- memcpy(dest, (void *)sechdrs[i].sh_addr,
63924- sechdrs[i].sh_size);
63925+#ifdef CONFIG_PAX_KERNEXEC
63926+#ifdef CONFIG_X86_64
63927+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
63928+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
63929+#endif
63930+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
63931+ pax_open_kernel();
63932+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
63933+ pax_close_kernel();
63934+ } else
63935+#endif
63936+
63937+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
63938+ }
63939 /* Update sh_addr to point to copy in image. */
63940- sechdrs[i].sh_addr = (unsigned long)dest;
63941+
63942+#ifdef CONFIG_PAX_KERNEXEC
63943+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
63944+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
63945+ else
63946+#endif
63947+
63948+ sechdrs[i].sh_addr = (unsigned long)dest;
63949 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
63950 }
63951 /* Module has been moved. */
63952@@ -2322,7 +2433,7 @@ static noinline struct module *load_modu
63953 mod->name);
63954 if (!mod->refptr) {
63955 err = -ENOMEM;
63956- goto free_init;
63957+ goto free_init_rx;
63958 }
63959 #endif
63960 /* Now we've moved module, initialize linked lists, etc. */
63961@@ -2351,6 +2462,31 @@ static noinline struct module *load_modu
63962 /* Set up MODINFO_ATTR fields */
63963 setup_modinfo(mod, sechdrs, infoindex);
63964
63965+ mod->args = args;
63966+
63967+#ifdef CONFIG_GRKERNSEC_MODHARDEN
63968+ {
63969+ char *p, *p2;
63970+
63971+ if (strstr(mod->args, "grsec_modharden_netdev")) {
63972+ 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);
63973+ err = -EPERM;
63974+ goto cleanup;
63975+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
63976+ p += strlen("grsec_modharden_normal");
63977+ p2 = strstr(p, "_");
63978+ if (p2) {
63979+ *p2 = '\0';
63980+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
63981+ *p2 = '_';
63982+ }
63983+ err = -EPERM;
63984+ goto cleanup;
63985+ }
63986+ }
63987+#endif
63988+
63989+
63990 /* Fix up syms, so that st_value is a pointer to location. */
63991 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
63992 mod);
63993@@ -2431,8 +2567,8 @@ static noinline struct module *load_modu
63994
63995 /* Now do relocations. */
63996 for (i = 1; i < hdr->e_shnum; i++) {
63997- const char *strtab = (char *)sechdrs[strindex].sh_addr;
63998 unsigned int info = sechdrs[i].sh_info;
63999+ strtab = (char *)sechdrs[strindex].sh_addr;
64000
64001 /* Not a valid relocation section? */
64002 if (info >= hdr->e_shnum)
64003@@ -2493,16 +2629,15 @@ static noinline struct module *load_modu
64004 * Do it before processing of module parameters, so the module
64005 * can provide parameter accessor functions of its own.
64006 */
64007- if (mod->module_init)
64008- flush_icache_range((unsigned long)mod->module_init,
64009- (unsigned long)mod->module_init
64010- + mod->init_size);
64011- flush_icache_range((unsigned long)mod->module_core,
64012- (unsigned long)mod->module_core + mod->core_size);
64013+ if (mod->module_init_rx)
64014+ flush_icache_range((unsigned long)mod->module_init_rx,
64015+ (unsigned long)mod->module_init_rx
64016+ + mod->init_size_rx);
64017+ flush_icache_range((unsigned long)mod->module_core_rx,
64018+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
64019
64020 set_fs(old_fs);
64021
64022- mod->args = args;
64023 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
64024 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
64025 mod->name);
64026@@ -2546,12 +2681,16 @@ static noinline struct module *load_modu
64027 free_unload:
64028 module_unload_free(mod);
64029 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
64030+ free_init_rx:
64031 percpu_modfree(mod->refptr);
64032- free_init:
64033 #endif
64034- module_free(mod, mod->module_init);
64035- free_core:
64036- module_free(mod, mod->module_core);
64037+ module_free_exec(mod, mod->module_init_rx);
64038+ free_core_rx:
64039+ module_free_exec(mod, mod->module_core_rx);
64040+ free_init_rw:
64041+ module_free(mod, mod->module_init_rw);
64042+ free_core_rw:
64043+ module_free(mod, mod->module_core_rw);
64044 /* mod will be freed with core. Don't access it beyond this line! */
64045 free_percpu:
64046 if (percpu)
64047@@ -2653,10 +2792,12 @@ SYSCALL_DEFINE3(init_module, void __user
64048 mod->symtab = mod->core_symtab;
64049 mod->strtab = mod->core_strtab;
64050 #endif
64051- module_free(mod, mod->module_init);
64052- mod->module_init = NULL;
64053- mod->init_size = 0;
64054- mod->init_text_size = 0;
64055+ module_free(mod, mod->module_init_rw);
64056+ module_free_exec(mod, mod->module_init_rx);
64057+ mod->module_init_rw = NULL;
64058+ mod->module_init_rx = NULL;
64059+ mod->init_size_rw = 0;
64060+ mod->init_size_rx = 0;
64061 mutex_unlock(&module_mutex);
64062
64063 return 0;
64064@@ -2687,10 +2828,16 @@ static const char *get_ksymbol(struct mo
64065 unsigned long nextval;
64066
64067 /* At worse, next value is at end of module */
64068- if (within_module_init(addr, mod))
64069- nextval = (unsigned long)mod->module_init+mod->init_text_size;
64070+ if (within_module_init_rx(addr, mod))
64071+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
64072+ else if (within_module_init_rw(addr, mod))
64073+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
64074+ else if (within_module_core_rx(addr, mod))
64075+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
64076+ else if (within_module_core_rw(addr, mod))
64077+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
64078 else
64079- nextval = (unsigned long)mod->module_core+mod->core_text_size;
64080+ return NULL;
64081
64082 /* Scan for closest preceeding symbol, and next symbol. (ELF
64083 starts real symbols at 1). */
64084@@ -2936,7 +3083,7 @@ static int m_show(struct seq_file *m, vo
64085 char buf[8];
64086
64087 seq_printf(m, "%s %u",
64088- mod->name, mod->init_size + mod->core_size);
64089+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
64090 print_unload_info(m, mod);
64091
64092 /* Informative for users. */
64093@@ -2945,7 +3092,7 @@ static int m_show(struct seq_file *m, vo
64094 mod->state == MODULE_STATE_COMING ? "Loading":
64095 "Live");
64096 /* Used by oprofile and other similar tools. */
64097- seq_printf(m, " 0x%p", mod->module_core);
64098+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
64099
64100 /* Taints info */
64101 if (mod->taints)
64102@@ -2981,7 +3128,17 @@ static const struct file_operations proc
64103
64104 static int __init proc_modules_init(void)
64105 {
64106+#ifndef CONFIG_GRKERNSEC_HIDESYM
64107+#ifdef CONFIG_GRKERNSEC_PROC_USER
64108+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64109+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64110+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
64111+#else
64112 proc_create("modules", 0, NULL, &proc_modules_operations);
64113+#endif
64114+#else
64115+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
64116+#endif
64117 return 0;
64118 }
64119 module_init(proc_modules_init);
64120@@ -3040,12 +3197,12 @@ struct module *__module_address(unsigned
64121 {
64122 struct module *mod;
64123
64124- if (addr < module_addr_min || addr > module_addr_max)
64125+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
64126+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
64127 return NULL;
64128
64129 list_for_each_entry_rcu(mod, &modules, list)
64130- if (within_module_core(addr, mod)
64131- || within_module_init(addr, mod))
64132+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
64133 return mod;
64134 return NULL;
64135 }
64136@@ -3079,11 +3236,20 @@ bool is_module_text_address(unsigned lon
64137 */
64138 struct module *__module_text_address(unsigned long addr)
64139 {
64140- struct module *mod = __module_address(addr);
64141+ struct module *mod;
64142+
64143+#ifdef CONFIG_X86_32
64144+ addr = ktla_ktva(addr);
64145+#endif
64146+
64147+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
64148+ return NULL;
64149+
64150+ mod = __module_address(addr);
64151+
64152 if (mod) {
64153 /* Make sure it's within the text section. */
64154- if (!within(addr, mod->module_init, mod->init_text_size)
64155- && !within(addr, mod->module_core, mod->core_text_size))
64156+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
64157 mod = NULL;
64158 }
64159 return mod;
64160diff -urNp linux-2.6.32.43/kernel/mutex.c linux-2.6.32.43/kernel/mutex.c
64161--- linux-2.6.32.43/kernel/mutex.c 2011-03-27 14:31:47.000000000 -0400
64162+++ linux-2.6.32.43/kernel/mutex.c 2011-04-17 15:56:46.000000000 -0400
64163@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock,
64164 */
64165
64166 for (;;) {
64167- struct thread_info *owner;
64168+ struct task_struct *owner;
64169
64170 /*
64171 * If we own the BKL, then don't spin. The owner of
64172@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock,
64173 spin_lock_mutex(&lock->wait_lock, flags);
64174
64175 debug_mutex_lock_common(lock, &waiter);
64176- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
64177+ debug_mutex_add_waiter(lock, &waiter, task);
64178
64179 /* add waiting tasks to the end of the waitqueue (FIFO): */
64180 list_add_tail(&waiter.list, &lock->wait_list);
64181@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock,
64182 * TASK_UNINTERRUPTIBLE case.)
64183 */
64184 if (unlikely(signal_pending_state(state, task))) {
64185- mutex_remove_waiter(lock, &waiter,
64186- task_thread_info(task));
64187+ mutex_remove_waiter(lock, &waiter, task);
64188 mutex_release(&lock->dep_map, 1, ip);
64189 spin_unlock_mutex(&lock->wait_lock, flags);
64190
64191@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock,
64192 done:
64193 lock_acquired(&lock->dep_map, ip);
64194 /* got the lock - rejoice! */
64195- mutex_remove_waiter(lock, &waiter, current_thread_info());
64196+ mutex_remove_waiter(lock, &waiter, task);
64197 mutex_set_owner(lock);
64198
64199 /* set it to 0 if there are no waiters left: */
64200diff -urNp linux-2.6.32.43/kernel/mutex-debug.c linux-2.6.32.43/kernel/mutex-debug.c
64201--- linux-2.6.32.43/kernel/mutex-debug.c 2011-03-27 14:31:47.000000000 -0400
64202+++ linux-2.6.32.43/kernel/mutex-debug.c 2011-04-17 15:56:46.000000000 -0400
64203@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
64204 }
64205
64206 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64207- struct thread_info *ti)
64208+ struct task_struct *task)
64209 {
64210 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
64211
64212 /* Mark the current thread as blocked on the lock: */
64213- ti->task->blocked_on = waiter;
64214+ task->blocked_on = waiter;
64215 }
64216
64217 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64218- struct thread_info *ti)
64219+ struct task_struct *task)
64220 {
64221 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
64222- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
64223- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
64224- ti->task->blocked_on = NULL;
64225+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
64226+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
64227+ task->blocked_on = NULL;
64228
64229 list_del_init(&waiter->list);
64230 waiter->task = NULL;
64231@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
64232 return;
64233
64234 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
64235- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
64236+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
64237 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
64238 mutex_clear_owner(lock);
64239 }
64240diff -urNp linux-2.6.32.43/kernel/mutex-debug.h linux-2.6.32.43/kernel/mutex-debug.h
64241--- linux-2.6.32.43/kernel/mutex-debug.h 2011-03-27 14:31:47.000000000 -0400
64242+++ linux-2.6.32.43/kernel/mutex-debug.h 2011-04-17 15:56:46.000000000 -0400
64243@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
64244 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
64245 extern void debug_mutex_add_waiter(struct mutex *lock,
64246 struct mutex_waiter *waiter,
64247- struct thread_info *ti);
64248+ struct task_struct *task);
64249 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
64250- struct thread_info *ti);
64251+ struct task_struct *task);
64252 extern void debug_mutex_unlock(struct mutex *lock);
64253 extern void debug_mutex_init(struct mutex *lock, const char *name,
64254 struct lock_class_key *key);
64255
64256 static inline void mutex_set_owner(struct mutex *lock)
64257 {
64258- lock->owner = current_thread_info();
64259+ lock->owner = current;
64260 }
64261
64262 static inline void mutex_clear_owner(struct mutex *lock)
64263diff -urNp linux-2.6.32.43/kernel/mutex.h linux-2.6.32.43/kernel/mutex.h
64264--- linux-2.6.32.43/kernel/mutex.h 2011-03-27 14:31:47.000000000 -0400
64265+++ linux-2.6.32.43/kernel/mutex.h 2011-04-17 15:56:46.000000000 -0400
64266@@ -19,7 +19,7 @@
64267 #ifdef CONFIG_SMP
64268 static inline void mutex_set_owner(struct mutex *lock)
64269 {
64270- lock->owner = current_thread_info();
64271+ lock->owner = current;
64272 }
64273
64274 static inline void mutex_clear_owner(struct mutex *lock)
64275diff -urNp linux-2.6.32.43/kernel/panic.c linux-2.6.32.43/kernel/panic.c
64276--- linux-2.6.32.43/kernel/panic.c 2011-03-27 14:31:47.000000000 -0400
64277+++ linux-2.6.32.43/kernel/panic.c 2011-04-17 15:56:46.000000000 -0400
64278@@ -352,7 +352,7 @@ static void warn_slowpath_common(const c
64279 const char *board;
64280
64281 printk(KERN_WARNING "------------[ cut here ]------------\n");
64282- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
64283+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
64284 board = dmi_get_system_info(DMI_PRODUCT_NAME);
64285 if (board)
64286 printk(KERN_WARNING "Hardware name: %s\n", board);
64287@@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
64288 */
64289 void __stack_chk_fail(void)
64290 {
64291- panic("stack-protector: Kernel stack is corrupted in: %p\n",
64292+ dump_stack();
64293+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
64294 __builtin_return_address(0));
64295 }
64296 EXPORT_SYMBOL(__stack_chk_fail);
64297diff -urNp linux-2.6.32.43/kernel/params.c linux-2.6.32.43/kernel/params.c
64298--- linux-2.6.32.43/kernel/params.c 2011-03-27 14:31:47.000000000 -0400
64299+++ linux-2.6.32.43/kernel/params.c 2011-04-17 15:56:46.000000000 -0400
64300@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct
64301 return ret;
64302 }
64303
64304-static struct sysfs_ops module_sysfs_ops = {
64305+static const struct sysfs_ops module_sysfs_ops = {
64306 .show = module_attr_show,
64307 .store = module_attr_store,
64308 };
64309@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *ks
64310 return 0;
64311 }
64312
64313-static struct kset_uevent_ops module_uevent_ops = {
64314+static const struct kset_uevent_ops module_uevent_ops = {
64315 .filter = uevent_filter,
64316 };
64317
64318diff -urNp linux-2.6.32.43/kernel/perf_event.c linux-2.6.32.43/kernel/perf_event.c
64319--- linux-2.6.32.43/kernel/perf_event.c 2011-04-17 17:00:52.000000000 -0400
64320+++ linux-2.6.32.43/kernel/perf_event.c 2011-05-04 17:56:28.000000000 -0400
64321@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostl
64322 */
64323 int sysctl_perf_event_sample_rate __read_mostly = 100000;
64324
64325-static atomic64_t perf_event_id;
64326+static atomic64_unchecked_t perf_event_id;
64327
64328 /*
64329 * Lock for (sysadmin-configurable) event reservations:
64330@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struc
64331 * In order to keep per-task stats reliable we need to flip the event
64332 * values when we flip the contexts.
64333 */
64334- value = atomic64_read(&next_event->count);
64335- value = atomic64_xchg(&event->count, value);
64336- atomic64_set(&next_event->count, value);
64337+ value = atomic64_read_unchecked(&next_event->count);
64338+ value = atomic64_xchg_unchecked(&event->count, value);
64339+ atomic64_set_unchecked(&next_event->count, value);
64340
64341 swap(event->total_time_enabled, next_event->total_time_enabled);
64342 swap(event->total_time_running, next_event->total_time_running);
64343@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_e
64344 update_event_times(event);
64345 }
64346
64347- return atomic64_read(&event->count);
64348+ return atomic64_read_unchecked(&event->count);
64349 }
64350
64351 /*
64352@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct
64353 values[n++] = 1 + leader->nr_siblings;
64354 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64355 values[n++] = leader->total_time_enabled +
64356- atomic64_read(&leader->child_total_time_enabled);
64357+ atomic64_read_unchecked(&leader->child_total_time_enabled);
64358 }
64359 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64360 values[n++] = leader->total_time_running +
64361- atomic64_read(&leader->child_total_time_running);
64362+ atomic64_read_unchecked(&leader->child_total_time_running);
64363 }
64364
64365 size = n * sizeof(u64);
64366@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct pe
64367 values[n++] = perf_event_read_value(event);
64368 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64369 values[n++] = event->total_time_enabled +
64370- atomic64_read(&event->child_total_time_enabled);
64371+ atomic64_read_unchecked(&event->child_total_time_enabled);
64372 }
64373 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64374 values[n++] = event->total_time_running +
64375- atomic64_read(&event->child_total_time_running);
64376+ atomic64_read_unchecked(&event->child_total_time_running);
64377 }
64378 if (read_format & PERF_FORMAT_ID)
64379 values[n++] = primary_event_id(event);
64380@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct fil
64381 static void perf_event_reset(struct perf_event *event)
64382 {
64383 (void)perf_event_read(event);
64384- atomic64_set(&event->count, 0);
64385+ atomic64_set_unchecked(&event->count, 0);
64386 perf_event_update_userpage(event);
64387 }
64388
64389@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct p
64390 ++userpg->lock;
64391 barrier();
64392 userpg->index = perf_event_index(event);
64393- userpg->offset = atomic64_read(&event->count);
64394+ userpg->offset = atomic64_read_unchecked(&event->count);
64395 if (event->state == PERF_EVENT_STATE_ACTIVE)
64396- userpg->offset -= atomic64_read(&event->hw.prev_count);
64397+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
64398
64399 userpg->time_enabled = event->total_time_enabled +
64400- atomic64_read(&event->child_total_time_enabled);
64401+ atomic64_read_unchecked(&event->child_total_time_enabled);
64402
64403 userpg->time_running = event->total_time_running +
64404- atomic64_read(&event->child_total_time_running);
64405+ atomic64_read_unchecked(&event->child_total_time_running);
64406
64407 barrier();
64408 ++userpg->lock;
64409@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct
64410 u64 values[4];
64411 int n = 0;
64412
64413- values[n++] = atomic64_read(&event->count);
64414+ values[n++] = atomic64_read_unchecked(&event->count);
64415 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64416 values[n++] = event->total_time_enabled +
64417- atomic64_read(&event->child_total_time_enabled);
64418+ atomic64_read_unchecked(&event->child_total_time_enabled);
64419 }
64420 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64421 values[n++] = event->total_time_running +
64422- atomic64_read(&event->child_total_time_running);
64423+ atomic64_read_unchecked(&event->child_total_time_running);
64424 }
64425 if (read_format & PERF_FORMAT_ID)
64426 values[n++] = primary_event_id(event);
64427@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struc
64428 if (leader != event)
64429 leader->pmu->read(leader);
64430
64431- values[n++] = atomic64_read(&leader->count);
64432+ values[n++] = atomic64_read_unchecked(&leader->count);
64433 if (read_format & PERF_FORMAT_ID)
64434 values[n++] = primary_event_id(leader);
64435
64436@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struc
64437 if (sub != event)
64438 sub->pmu->read(sub);
64439
64440- values[n++] = atomic64_read(&sub->count);
64441+ values[n++] = atomic64_read_unchecked(&sub->count);
64442 if (read_format & PERF_FORMAT_ID)
64443 values[n++] = primary_event_id(sub);
64444
64445@@ -3787,7 +3787,7 @@ static void perf_swevent_add(struct perf
64446 {
64447 struct hw_perf_event *hwc = &event->hw;
64448
64449- atomic64_add(nr, &event->count);
64450+ atomic64_add_unchecked(nr, &event->count);
64451
64452 if (!hwc->sample_period)
64453 return;
64454@@ -4044,9 +4044,9 @@ static void cpu_clock_perf_event_update(
64455 u64 now;
64456
64457 now = cpu_clock(cpu);
64458- prev = atomic64_read(&event->hw.prev_count);
64459- atomic64_set(&event->hw.prev_count, now);
64460- atomic64_add(now - prev, &event->count);
64461+ prev = atomic64_read_unchecked(&event->hw.prev_count);
64462+ atomic64_set_unchecked(&event->hw.prev_count, now);
64463+ atomic64_add_unchecked(now - prev, &event->count);
64464 }
64465
64466 static int cpu_clock_perf_event_enable(struct perf_event *event)
64467@@ -4054,7 +4054,7 @@ static int cpu_clock_perf_event_enable(s
64468 struct hw_perf_event *hwc = &event->hw;
64469 int cpu = raw_smp_processor_id();
64470
64471- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
64472+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
64473 perf_swevent_start_hrtimer(event);
64474
64475 return 0;
64476@@ -4086,9 +4086,9 @@ static void task_clock_perf_event_update
64477 u64 prev;
64478 s64 delta;
64479
64480- prev = atomic64_xchg(&event->hw.prev_count, now);
64481+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
64482 delta = now - prev;
64483- atomic64_add(delta, &event->count);
64484+ atomic64_add_unchecked(delta, &event->count);
64485 }
64486
64487 static int task_clock_perf_event_enable(struct perf_event *event)
64488@@ -4098,7 +4098,7 @@ static int task_clock_perf_event_enable(
64489
64490 now = event->ctx->time;
64491
64492- atomic64_set(&hwc->prev_count, now);
64493+ atomic64_set_unchecked(&hwc->prev_count, now);
64494
64495 perf_swevent_start_hrtimer(event);
64496
64497@@ -4293,7 +4293,7 @@ perf_event_alloc(struct perf_event_attr
64498 event->parent = parent_event;
64499
64500 event->ns = get_pid_ns(current->nsproxy->pid_ns);
64501- event->id = atomic64_inc_return(&perf_event_id);
64502+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
64503
64504 event->state = PERF_EVENT_STATE_INACTIVE;
64505
64506@@ -4724,15 +4724,15 @@ static void sync_child_event(struct perf
64507 if (child_event->attr.inherit_stat)
64508 perf_event_read_event(child_event, child);
64509
64510- child_val = atomic64_read(&child_event->count);
64511+ child_val = atomic64_read_unchecked(&child_event->count);
64512
64513 /*
64514 * Add back the child's count to the parent's count:
64515 */
64516- atomic64_add(child_val, &parent_event->count);
64517- atomic64_add(child_event->total_time_enabled,
64518+ atomic64_add_unchecked(child_val, &parent_event->count);
64519+ atomic64_add_unchecked(child_event->total_time_enabled,
64520 &parent_event->child_total_time_enabled);
64521- atomic64_add(child_event->total_time_running,
64522+ atomic64_add_unchecked(child_event->total_time_running,
64523 &parent_event->child_total_time_running);
64524
64525 /*
64526diff -urNp linux-2.6.32.43/kernel/pid.c linux-2.6.32.43/kernel/pid.c
64527--- linux-2.6.32.43/kernel/pid.c 2011-04-22 19:16:29.000000000 -0400
64528+++ linux-2.6.32.43/kernel/pid.c 2011-07-14 19:15:33.000000000 -0400
64529@@ -33,6 +33,7 @@
64530 #include <linux/rculist.h>
64531 #include <linux/bootmem.h>
64532 #include <linux/hash.h>
64533+#include <linux/security.h>
64534 #include <linux/pid_namespace.h>
64535 #include <linux/init_task.h>
64536 #include <linux/syscalls.h>
64537@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
64538
64539 int pid_max = PID_MAX_DEFAULT;
64540
64541-#define RESERVED_PIDS 300
64542+#define RESERVED_PIDS 500
64543
64544 int pid_max_min = RESERVED_PIDS + 1;
64545 int pid_max_max = PID_MAX_LIMIT;
64546@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
64547 */
64548 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
64549 {
64550- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
64551+ struct task_struct *task;
64552+
64553+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
64554+
64555+ if (gr_pid_is_chrooted(task))
64556+ return NULL;
64557+
64558+ return task;
64559 }
64560
64561 struct task_struct *find_task_by_vpid(pid_t vnr)
64562@@ -391,6 +399,13 @@ struct task_struct *find_task_by_vpid(pi
64563 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
64564 }
64565
64566+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
64567+{
64568+ struct task_struct *task;
64569+
64570+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
64571+}
64572+
64573 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
64574 {
64575 struct pid *pid;
64576diff -urNp linux-2.6.32.43/kernel/posix-cpu-timers.c linux-2.6.32.43/kernel/posix-cpu-timers.c
64577--- linux-2.6.32.43/kernel/posix-cpu-timers.c 2011-03-27 14:31:47.000000000 -0400
64578+++ linux-2.6.32.43/kernel/posix-cpu-timers.c 2011-08-06 09:33:44.000000000 -0400
64579@@ -6,6 +6,7 @@
64580 #include <linux/posix-timers.h>
64581 #include <linux/errno.h>
64582 #include <linux/math64.h>
64583+#include <linux/security.h>
64584 #include <asm/uaccess.h>
64585 #include <linux/kernel_stat.h>
64586 #include <trace/events/timer.h>
64587@@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(st
64588
64589 static __init int init_posix_cpu_timers(void)
64590 {
64591- struct k_clock process = {
64592+ static struct k_clock process = {
64593 .clock_getres = process_cpu_clock_getres,
64594 .clock_get = process_cpu_clock_get,
64595 .clock_set = do_posix_clock_nosettime,
64596@@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(
64597 .nsleep = process_cpu_nsleep,
64598 .nsleep_restart = process_cpu_nsleep_restart,
64599 };
64600- struct k_clock thread = {
64601+ static struct k_clock thread = {
64602 .clock_getres = thread_cpu_clock_getres,
64603 .clock_get = thread_cpu_clock_get,
64604 .clock_set = do_posix_clock_nosettime,
64605diff -urNp linux-2.6.32.43/kernel/posix-timers.c linux-2.6.32.43/kernel/posix-timers.c
64606--- linux-2.6.32.43/kernel/posix-timers.c 2011-03-27 14:31:47.000000000 -0400
64607+++ linux-2.6.32.43/kernel/posix-timers.c 2011-08-06 09:34:14.000000000 -0400
64608@@ -42,6 +42,7 @@
64609 #include <linux/compiler.h>
64610 #include <linux/idr.h>
64611 #include <linux/posix-timers.h>
64612+#include <linux/grsecurity.h>
64613 #include <linux/syscalls.h>
64614 #include <linux/wait.h>
64615 #include <linux/workqueue.h>
64616@@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
64617 * which we beg off on and pass to do_sys_settimeofday().
64618 */
64619
64620-static struct k_clock posix_clocks[MAX_CLOCKS];
64621+static struct k_clock *posix_clocks[MAX_CLOCKS];
64622
64623 /*
64624 * These ones are defined below.
64625@@ -157,8 +158,8 @@ static inline void unlock_timer(struct k
64626 */
64627 #define CLOCK_DISPATCH(clock, call, arglist) \
64628 ((clock) < 0 ? posix_cpu_##call arglist : \
64629- (posix_clocks[clock].call != NULL \
64630- ? (*posix_clocks[clock].call) arglist : common_##call arglist))
64631+ (posix_clocks[clock]->call != NULL \
64632+ ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
64633
64634 /*
64635 * Default clock hook functions when the struct k_clock passed
64636@@ -172,7 +173,7 @@ static inline int common_clock_getres(co
64637 struct timespec *tp)
64638 {
64639 tp->tv_sec = 0;
64640- tp->tv_nsec = posix_clocks[which_clock].res;
64641+ tp->tv_nsec = posix_clocks[which_clock]->res;
64642 return 0;
64643 }
64644
64645@@ -217,9 +218,11 @@ static inline int invalid_clockid(const
64646 return 0;
64647 if ((unsigned) which_clock >= MAX_CLOCKS)
64648 return 1;
64649- if (posix_clocks[which_clock].clock_getres != NULL)
64650+ if (!posix_clocks[which_clock])
64651 return 0;
64652- if (posix_clocks[which_clock].res != 0)
64653+ if (posix_clocks[which_clock]->clock_getres != NULL)
64654+ return 0;
64655+ if (posix_clocks[which_clock]->res != 0)
64656 return 0;
64657 return 1;
64658 }
64659@@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t
64660 */
64661 static __init int init_posix_timers(void)
64662 {
64663- struct k_clock clock_realtime = {
64664+ static struct k_clock clock_realtime = {
64665 .clock_getres = hrtimer_get_res,
64666 };
64667- struct k_clock clock_monotonic = {
64668+ static struct k_clock clock_monotonic = {
64669 .clock_getres = hrtimer_get_res,
64670 .clock_get = posix_ktime_get_ts,
64671 .clock_set = do_posix_clock_nosettime,
64672 };
64673- struct k_clock clock_monotonic_raw = {
64674+ static struct k_clock clock_monotonic_raw = {
64675 .clock_getres = hrtimer_get_res,
64676 .clock_get = posix_get_monotonic_raw,
64677 .clock_set = do_posix_clock_nosettime,
64678 .timer_create = no_timer_create,
64679 .nsleep = no_nsleep,
64680 };
64681- struct k_clock clock_realtime_coarse = {
64682+ static struct k_clock clock_realtime_coarse = {
64683 .clock_getres = posix_get_coarse_res,
64684 .clock_get = posix_get_realtime_coarse,
64685 .clock_set = do_posix_clock_nosettime,
64686 .timer_create = no_timer_create,
64687 .nsleep = no_nsleep,
64688 };
64689- struct k_clock clock_monotonic_coarse = {
64690+ static struct k_clock clock_monotonic_coarse = {
64691 .clock_getres = posix_get_coarse_res,
64692 .clock_get = posix_get_monotonic_coarse,
64693 .clock_set = do_posix_clock_nosettime,
64694@@ -296,6 +299,8 @@ static __init int init_posix_timers(void
64695 .nsleep = no_nsleep,
64696 };
64697
64698+ pax_track_stack();
64699+
64700 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
64701 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
64702 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
64703@@ -484,7 +489,7 @@ void register_posix_clock(const clockid_
64704 return;
64705 }
64706
64707- posix_clocks[clock_id] = *new_clock;
64708+ posix_clocks[clock_id] = new_clock;
64709 }
64710 EXPORT_SYMBOL_GPL(register_posix_clock);
64711
64712@@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
64713 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
64714 return -EFAULT;
64715
64716+ /* only the CLOCK_REALTIME clock can be set, all other clocks
64717+ have their clock_set fptr set to a nosettime dummy function
64718+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
64719+ call common_clock_set, which calls do_sys_settimeofday, which
64720+ we hook
64721+ */
64722+
64723 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
64724 }
64725
64726diff -urNp linux-2.6.32.43/kernel/power/hibernate.c linux-2.6.32.43/kernel/power/hibernate.c
64727--- linux-2.6.32.43/kernel/power/hibernate.c 2011-03-27 14:31:47.000000000 -0400
64728+++ linux-2.6.32.43/kernel/power/hibernate.c 2011-04-17 15:56:46.000000000 -0400
64729@@ -48,14 +48,14 @@ enum {
64730
64731 static int hibernation_mode = HIBERNATION_SHUTDOWN;
64732
64733-static struct platform_hibernation_ops *hibernation_ops;
64734+static const struct platform_hibernation_ops *hibernation_ops;
64735
64736 /**
64737 * hibernation_set_ops - set the global hibernate operations
64738 * @ops: the hibernation operations to use in subsequent hibernation transitions
64739 */
64740
64741-void hibernation_set_ops(struct platform_hibernation_ops *ops)
64742+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
64743 {
64744 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
64745 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
64746diff -urNp linux-2.6.32.43/kernel/power/poweroff.c linux-2.6.32.43/kernel/power/poweroff.c
64747--- linux-2.6.32.43/kernel/power/poweroff.c 2011-03-27 14:31:47.000000000 -0400
64748+++ linux-2.6.32.43/kernel/power/poweroff.c 2011-04-17 15:56:46.000000000 -0400
64749@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
64750 .enable_mask = SYSRQ_ENABLE_BOOT,
64751 };
64752
64753-static int pm_sysrq_init(void)
64754+static int __init pm_sysrq_init(void)
64755 {
64756 register_sysrq_key('o', &sysrq_poweroff_op);
64757 return 0;
64758diff -urNp linux-2.6.32.43/kernel/power/process.c linux-2.6.32.43/kernel/power/process.c
64759--- linux-2.6.32.43/kernel/power/process.c 2011-03-27 14:31:47.000000000 -0400
64760+++ linux-2.6.32.43/kernel/power/process.c 2011-04-17 15:56:46.000000000 -0400
64761@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_
64762 struct timeval start, end;
64763 u64 elapsed_csecs64;
64764 unsigned int elapsed_csecs;
64765+ bool timedout = false;
64766
64767 do_gettimeofday(&start);
64768
64769 end_time = jiffies + TIMEOUT;
64770 do {
64771 todo = 0;
64772+ if (time_after(jiffies, end_time))
64773+ timedout = true;
64774 read_lock(&tasklist_lock);
64775 do_each_thread(g, p) {
64776 if (frozen(p) || !freezeable(p))
64777@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_
64778 * It is "frozen enough". If the task does wake
64779 * up, it will immediately call try_to_freeze.
64780 */
64781- if (!task_is_stopped_or_traced(p) &&
64782- !freezer_should_skip(p))
64783+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
64784 todo++;
64785+ if (timedout) {
64786+ printk(KERN_ERR "Task refusing to freeze:\n");
64787+ sched_show_task(p);
64788+ }
64789+ }
64790 } while_each_thread(g, p);
64791 read_unlock(&tasklist_lock);
64792 yield(); /* Yield is okay here */
64793- if (time_after(jiffies, end_time))
64794- break;
64795- } while (todo);
64796+ } while (todo && !timedout);
64797
64798 do_gettimeofday(&end);
64799 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
64800diff -urNp linux-2.6.32.43/kernel/power/suspend.c linux-2.6.32.43/kernel/power/suspend.c
64801--- linux-2.6.32.43/kernel/power/suspend.c 2011-03-27 14:31:47.000000000 -0400
64802+++ linux-2.6.32.43/kernel/power/suspend.c 2011-04-17 15:56:46.000000000 -0400
64803@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_M
64804 [PM_SUSPEND_MEM] = "mem",
64805 };
64806
64807-static struct platform_suspend_ops *suspend_ops;
64808+static const struct platform_suspend_ops *suspend_ops;
64809
64810 /**
64811 * suspend_set_ops - Set the global suspend method table.
64812 * @ops: Pointer to ops structure.
64813 */
64814-void suspend_set_ops(struct platform_suspend_ops *ops)
64815+void suspend_set_ops(const struct platform_suspend_ops *ops)
64816 {
64817 mutex_lock(&pm_mutex);
64818 suspend_ops = ops;
64819diff -urNp linux-2.6.32.43/kernel/printk.c linux-2.6.32.43/kernel/printk.c
64820--- linux-2.6.32.43/kernel/printk.c 2011-03-27 14:31:47.000000000 -0400
64821+++ linux-2.6.32.43/kernel/printk.c 2011-04-17 15:56:46.000000000 -0400
64822@@ -278,6 +278,11 @@ int do_syslog(int type, char __user *buf
64823 char c;
64824 int error = 0;
64825
64826+#ifdef CONFIG_GRKERNSEC_DMESG
64827+ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
64828+ return -EPERM;
64829+#endif
64830+
64831 error = security_syslog(type);
64832 if (error)
64833 return error;
64834diff -urNp linux-2.6.32.43/kernel/profile.c linux-2.6.32.43/kernel/profile.c
64835--- linux-2.6.32.43/kernel/profile.c 2011-03-27 14:31:47.000000000 -0400
64836+++ linux-2.6.32.43/kernel/profile.c 2011-05-04 17:56:28.000000000 -0400
64837@@ -39,7 +39,7 @@ struct profile_hit {
64838 /* Oprofile timer tick hook */
64839 static int (*timer_hook)(struct pt_regs *) __read_mostly;
64840
64841-static atomic_t *prof_buffer;
64842+static atomic_unchecked_t *prof_buffer;
64843 static unsigned long prof_len, prof_shift;
64844
64845 int prof_on __read_mostly;
64846@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
64847 hits[i].pc = 0;
64848 continue;
64849 }
64850- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
64851+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
64852 hits[i].hits = hits[i].pc = 0;
64853 }
64854 }
64855@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
64856 * Add the current hit(s) and flush the write-queue out
64857 * to the global buffer:
64858 */
64859- atomic_add(nr_hits, &prof_buffer[pc]);
64860+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
64861 for (i = 0; i < NR_PROFILE_HIT; ++i) {
64862- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
64863+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
64864 hits[i].pc = hits[i].hits = 0;
64865 }
64866 out:
64867@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
64868 if (prof_on != type || !prof_buffer)
64869 return;
64870 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
64871- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
64872+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
64873 }
64874 #endif /* !CONFIG_SMP */
64875 EXPORT_SYMBOL_GPL(profile_hits);
64876@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
64877 return -EFAULT;
64878 buf++; p++; count--; read++;
64879 }
64880- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
64881+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
64882 if (copy_to_user(buf, (void *)pnt, count))
64883 return -EFAULT;
64884 read += count;
64885@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
64886 }
64887 #endif
64888 profile_discard_flip_buffers();
64889- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
64890+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
64891 return count;
64892 }
64893
64894diff -urNp linux-2.6.32.43/kernel/ptrace.c linux-2.6.32.43/kernel/ptrace.c
64895--- linux-2.6.32.43/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
64896+++ linux-2.6.32.43/kernel/ptrace.c 2011-05-22 23:02:06.000000000 -0400
64897@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
64898 return ret;
64899 }
64900
64901-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
64902+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
64903+ unsigned int log)
64904 {
64905 const struct cred *cred = current_cred(), *tcred;
64906
64907@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_stru
64908 cred->gid != tcred->egid ||
64909 cred->gid != tcred->sgid ||
64910 cred->gid != tcred->gid) &&
64911- !capable(CAP_SYS_PTRACE)) {
64912+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
64913+ (log && !capable(CAP_SYS_PTRACE)))
64914+ ) {
64915 rcu_read_unlock();
64916 return -EPERM;
64917 }
64918@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_stru
64919 smp_rmb();
64920 if (task->mm)
64921 dumpable = get_dumpable(task->mm);
64922- if (!dumpable && !capable(CAP_SYS_PTRACE))
64923+ if (!dumpable &&
64924+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
64925+ (log && !capable(CAP_SYS_PTRACE))))
64926 return -EPERM;
64927
64928 return security_ptrace_access_check(task, mode);
64929@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struc
64930 {
64931 int err;
64932 task_lock(task);
64933- err = __ptrace_may_access(task, mode);
64934+ err = __ptrace_may_access(task, mode, 0);
64935+ task_unlock(task);
64936+ return !err;
64937+}
64938+
64939+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
64940+{
64941+ int err;
64942+ task_lock(task);
64943+ err = __ptrace_may_access(task, mode, 1);
64944 task_unlock(task);
64945 return !err;
64946 }
64947@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *ta
64948 goto out;
64949
64950 task_lock(task);
64951- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
64952+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
64953 task_unlock(task);
64954 if (retval)
64955 goto unlock_creds;
64956@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *ta
64957 goto unlock_tasklist;
64958
64959 task->ptrace = PT_PTRACED;
64960- if (capable(CAP_SYS_PTRACE))
64961+ if (capable_nolog(CAP_SYS_PTRACE))
64962 task->ptrace |= PT_PTRACE_CAP;
64963
64964 __ptrace_link(task, current);
64965@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *
64966 {
64967 int copied = 0;
64968
64969+ pax_track_stack();
64970+
64971 while (len > 0) {
64972 char buf[128];
64973 int this_len, retval;
64974@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct
64975 {
64976 int copied = 0;
64977
64978+ pax_track_stack();
64979+
64980 while (len > 0) {
64981 char buf[128];
64982 int this_len, retval;
64983@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *c
64984 int ret = -EIO;
64985 siginfo_t siginfo;
64986
64987+ pax_track_stack();
64988+
64989 switch (request) {
64990 case PTRACE_PEEKTEXT:
64991 case PTRACE_PEEKDATA:
64992@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *c
64993 ret = ptrace_setoptions(child, data);
64994 break;
64995 case PTRACE_GETEVENTMSG:
64996- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
64997+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
64998 break;
64999
65000 case PTRACE_GETSIGINFO:
65001 ret = ptrace_getsiginfo(child, &siginfo);
65002 if (!ret)
65003- ret = copy_siginfo_to_user((siginfo_t __user *) data,
65004+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
65005 &siginfo);
65006 break;
65007
65008 case PTRACE_SETSIGINFO:
65009- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
65010+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
65011 sizeof siginfo))
65012 ret = -EFAULT;
65013 else
65014@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
65015 goto out;
65016 }
65017
65018+ if (gr_handle_ptrace(child, request)) {
65019+ ret = -EPERM;
65020+ goto out_put_task_struct;
65021+ }
65022+
65023 if (request == PTRACE_ATTACH) {
65024 ret = ptrace_attach(child);
65025 /*
65026 * Some architectures need to do book-keeping after
65027 * a ptrace attach.
65028 */
65029- if (!ret)
65030+ if (!ret) {
65031 arch_ptrace_attach(child);
65032+ gr_audit_ptrace(child);
65033+ }
65034 goto out_put_task_struct;
65035 }
65036
65037@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_
65038 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
65039 if (copied != sizeof(tmp))
65040 return -EIO;
65041- return put_user(tmp, (unsigned long __user *)data);
65042+ return put_user(tmp, (__force unsigned long __user *)data);
65043 }
65044
65045 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
65046@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_st
65047 siginfo_t siginfo;
65048 int ret;
65049
65050+ pax_track_stack();
65051+
65052 switch (request) {
65053 case PTRACE_PEEKTEXT:
65054 case PTRACE_PEEKDATA:
65055@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat
65056 goto out;
65057 }
65058
65059+ if (gr_handle_ptrace(child, request)) {
65060+ ret = -EPERM;
65061+ goto out_put_task_struct;
65062+ }
65063+
65064 if (request == PTRACE_ATTACH) {
65065 ret = ptrace_attach(child);
65066 /*
65067 * Some architectures need to do book-keeping after
65068 * a ptrace attach.
65069 */
65070- if (!ret)
65071+ if (!ret) {
65072 arch_ptrace_attach(child);
65073+ gr_audit_ptrace(child);
65074+ }
65075 goto out_put_task_struct;
65076 }
65077
65078diff -urNp linux-2.6.32.43/kernel/rcutorture.c linux-2.6.32.43/kernel/rcutorture.c
65079--- linux-2.6.32.43/kernel/rcutorture.c 2011-03-27 14:31:47.000000000 -0400
65080+++ linux-2.6.32.43/kernel/rcutorture.c 2011-05-04 17:56:28.000000000 -0400
65081@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
65082 { 0 };
65083 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
65084 { 0 };
65085-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65086-static atomic_t n_rcu_torture_alloc;
65087-static atomic_t n_rcu_torture_alloc_fail;
65088-static atomic_t n_rcu_torture_free;
65089-static atomic_t n_rcu_torture_mberror;
65090-static atomic_t n_rcu_torture_error;
65091+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65092+static atomic_unchecked_t n_rcu_torture_alloc;
65093+static atomic_unchecked_t n_rcu_torture_alloc_fail;
65094+static atomic_unchecked_t n_rcu_torture_free;
65095+static atomic_unchecked_t n_rcu_torture_mberror;
65096+static atomic_unchecked_t n_rcu_torture_error;
65097 static long n_rcu_torture_timers;
65098 static struct list_head rcu_torture_removed;
65099 static cpumask_var_t shuffle_tmp_mask;
65100@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
65101
65102 spin_lock_bh(&rcu_torture_lock);
65103 if (list_empty(&rcu_torture_freelist)) {
65104- atomic_inc(&n_rcu_torture_alloc_fail);
65105+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
65106 spin_unlock_bh(&rcu_torture_lock);
65107 return NULL;
65108 }
65109- atomic_inc(&n_rcu_torture_alloc);
65110+ atomic_inc_unchecked(&n_rcu_torture_alloc);
65111 p = rcu_torture_freelist.next;
65112 list_del_init(p);
65113 spin_unlock_bh(&rcu_torture_lock);
65114@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
65115 static void
65116 rcu_torture_free(struct rcu_torture *p)
65117 {
65118- atomic_inc(&n_rcu_torture_free);
65119+ atomic_inc_unchecked(&n_rcu_torture_free);
65120 spin_lock_bh(&rcu_torture_lock);
65121 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
65122 spin_unlock_bh(&rcu_torture_lock);
65123@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
65124 i = rp->rtort_pipe_count;
65125 if (i > RCU_TORTURE_PIPE_LEN)
65126 i = RCU_TORTURE_PIPE_LEN;
65127- atomic_inc(&rcu_torture_wcount[i]);
65128+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
65129 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65130 rp->rtort_mbtest = 0;
65131 rcu_torture_free(rp);
65132@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_fr
65133 i = rp->rtort_pipe_count;
65134 if (i > RCU_TORTURE_PIPE_LEN)
65135 i = RCU_TORTURE_PIPE_LEN;
65136- atomic_inc(&rcu_torture_wcount[i]);
65137+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
65138 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65139 rp->rtort_mbtest = 0;
65140 list_del(&rp->rtort_free);
65141@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
65142 i = old_rp->rtort_pipe_count;
65143 if (i > RCU_TORTURE_PIPE_LEN)
65144 i = RCU_TORTURE_PIPE_LEN;
65145- atomic_inc(&rcu_torture_wcount[i]);
65146+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
65147 old_rp->rtort_pipe_count++;
65148 cur_ops->deferred_free(old_rp);
65149 }
65150@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned l
65151 return;
65152 }
65153 if (p->rtort_mbtest == 0)
65154- atomic_inc(&n_rcu_torture_mberror);
65155+ atomic_inc_unchecked(&n_rcu_torture_mberror);
65156 spin_lock(&rand_lock);
65157 cur_ops->read_delay(&rand);
65158 n_rcu_torture_timers++;
65159@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
65160 continue;
65161 }
65162 if (p->rtort_mbtest == 0)
65163- atomic_inc(&n_rcu_torture_mberror);
65164+ atomic_inc_unchecked(&n_rcu_torture_mberror);
65165 cur_ops->read_delay(&rand);
65166 preempt_disable();
65167 pipe_count = p->rtort_pipe_count;
65168@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
65169 rcu_torture_current,
65170 rcu_torture_current_version,
65171 list_empty(&rcu_torture_freelist),
65172- atomic_read(&n_rcu_torture_alloc),
65173- atomic_read(&n_rcu_torture_alloc_fail),
65174- atomic_read(&n_rcu_torture_free),
65175- atomic_read(&n_rcu_torture_mberror),
65176+ atomic_read_unchecked(&n_rcu_torture_alloc),
65177+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
65178+ atomic_read_unchecked(&n_rcu_torture_free),
65179+ atomic_read_unchecked(&n_rcu_torture_mberror),
65180 n_rcu_torture_timers);
65181- if (atomic_read(&n_rcu_torture_mberror) != 0)
65182+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
65183 cnt += sprintf(&page[cnt], " !!!");
65184 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
65185 if (i > 1) {
65186 cnt += sprintf(&page[cnt], "!!! ");
65187- atomic_inc(&n_rcu_torture_error);
65188+ atomic_inc_unchecked(&n_rcu_torture_error);
65189 WARN_ON_ONCE(1);
65190 }
65191 cnt += sprintf(&page[cnt], "Reader Pipe: ");
65192@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
65193 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
65194 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65195 cnt += sprintf(&page[cnt], " %d",
65196- atomic_read(&rcu_torture_wcount[i]));
65197+ atomic_read_unchecked(&rcu_torture_wcount[i]));
65198 }
65199 cnt += sprintf(&page[cnt], "\n");
65200 if (cur_ops->stats)
65201@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
65202
65203 if (cur_ops->cleanup)
65204 cur_ops->cleanup();
65205- if (atomic_read(&n_rcu_torture_error))
65206+ if (atomic_read_unchecked(&n_rcu_torture_error))
65207 rcu_torture_print_module_parms("End of test: FAILURE");
65208 else
65209 rcu_torture_print_module_parms("End of test: SUCCESS");
65210@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
65211
65212 rcu_torture_current = NULL;
65213 rcu_torture_current_version = 0;
65214- atomic_set(&n_rcu_torture_alloc, 0);
65215- atomic_set(&n_rcu_torture_alloc_fail, 0);
65216- atomic_set(&n_rcu_torture_free, 0);
65217- atomic_set(&n_rcu_torture_mberror, 0);
65218- atomic_set(&n_rcu_torture_error, 0);
65219+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
65220+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
65221+ atomic_set_unchecked(&n_rcu_torture_free, 0);
65222+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
65223+ atomic_set_unchecked(&n_rcu_torture_error, 0);
65224 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
65225- atomic_set(&rcu_torture_wcount[i], 0);
65226+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
65227 for_each_possible_cpu(cpu) {
65228 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65229 per_cpu(rcu_torture_count, cpu)[i] = 0;
65230diff -urNp linux-2.6.32.43/kernel/rcutree.c linux-2.6.32.43/kernel/rcutree.c
65231--- linux-2.6.32.43/kernel/rcutree.c 2011-03-27 14:31:47.000000000 -0400
65232+++ linux-2.6.32.43/kernel/rcutree.c 2011-04-17 15:56:46.000000000 -0400
65233@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state
65234 /*
65235 * Do softirq processing for the current CPU.
65236 */
65237-static void rcu_process_callbacks(struct softirq_action *unused)
65238+static void rcu_process_callbacks(void)
65239 {
65240 /*
65241 * Memory references from any prior RCU read-side critical sections
65242diff -urNp linux-2.6.32.43/kernel/rcutree_plugin.h linux-2.6.32.43/kernel/rcutree_plugin.h
65243--- linux-2.6.32.43/kernel/rcutree_plugin.h 2011-03-27 14:31:47.000000000 -0400
65244+++ linux-2.6.32.43/kernel/rcutree_plugin.h 2011-04-17 15:56:46.000000000 -0400
65245@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_swi
65246 */
65247 void __rcu_read_lock(void)
65248 {
65249- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
65250+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
65251 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
65252 }
65253 EXPORT_SYMBOL_GPL(__rcu_read_lock);
65254@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
65255 struct task_struct *t = current;
65256
65257 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
65258- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
65259+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
65260 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
65261 rcu_read_unlock_special(t);
65262 }
65263diff -urNp linux-2.6.32.43/kernel/relay.c linux-2.6.32.43/kernel/relay.c
65264--- linux-2.6.32.43/kernel/relay.c 2011-03-27 14:31:47.000000000 -0400
65265+++ linux-2.6.32.43/kernel/relay.c 2011-05-16 21:46:57.000000000 -0400
65266@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct fi
65267 unsigned int flags,
65268 int *nonpad_ret)
65269 {
65270- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
65271+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
65272 struct rchan_buf *rbuf = in->private_data;
65273 unsigned int subbuf_size = rbuf->chan->subbuf_size;
65274 uint64_t pos = (uint64_t) *ppos;
65275@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct fi
65276 .ops = &relay_pipe_buf_ops,
65277 .spd_release = relay_page_release,
65278 };
65279+ ssize_t ret;
65280+
65281+ pax_track_stack();
65282
65283 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
65284 return 0;
65285diff -urNp linux-2.6.32.43/kernel/resource.c linux-2.6.32.43/kernel/resource.c
65286--- linux-2.6.32.43/kernel/resource.c 2011-03-27 14:31:47.000000000 -0400
65287+++ linux-2.6.32.43/kernel/resource.c 2011-04-17 15:56:46.000000000 -0400
65288@@ -132,8 +132,18 @@ static const struct file_operations proc
65289
65290 static int __init ioresources_init(void)
65291 {
65292+#ifdef CONFIG_GRKERNSEC_PROC_ADD
65293+#ifdef CONFIG_GRKERNSEC_PROC_USER
65294+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
65295+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
65296+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65297+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
65298+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
65299+#endif
65300+#else
65301 proc_create("ioports", 0, NULL, &proc_ioports_operations);
65302 proc_create("iomem", 0, NULL, &proc_iomem_operations);
65303+#endif
65304 return 0;
65305 }
65306 __initcall(ioresources_init);
65307diff -urNp linux-2.6.32.43/kernel/rtmutex.c linux-2.6.32.43/kernel/rtmutex.c
65308--- linux-2.6.32.43/kernel/rtmutex.c 2011-03-27 14:31:47.000000000 -0400
65309+++ linux-2.6.32.43/kernel/rtmutex.c 2011-04-17 15:56:46.000000000 -0400
65310@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt
65311 */
65312 spin_lock_irqsave(&pendowner->pi_lock, flags);
65313
65314- WARN_ON(!pendowner->pi_blocked_on);
65315+ BUG_ON(!pendowner->pi_blocked_on);
65316 WARN_ON(pendowner->pi_blocked_on != waiter);
65317 WARN_ON(pendowner->pi_blocked_on->lock != lock);
65318
65319diff -urNp linux-2.6.32.43/kernel/rtmutex-tester.c linux-2.6.32.43/kernel/rtmutex-tester.c
65320--- linux-2.6.32.43/kernel/rtmutex-tester.c 2011-03-27 14:31:47.000000000 -0400
65321+++ linux-2.6.32.43/kernel/rtmutex-tester.c 2011-05-04 17:56:28.000000000 -0400
65322@@ -21,7 +21,7 @@
65323 #define MAX_RT_TEST_MUTEXES 8
65324
65325 static spinlock_t rttest_lock;
65326-static atomic_t rttest_event;
65327+static atomic_unchecked_t rttest_event;
65328
65329 struct test_thread_data {
65330 int opcode;
65331@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_
65332
65333 case RTTEST_LOCKCONT:
65334 td->mutexes[td->opdata] = 1;
65335- td->event = atomic_add_return(1, &rttest_event);
65336+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65337 return 0;
65338
65339 case RTTEST_RESET:
65340@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_
65341 return 0;
65342
65343 case RTTEST_RESETEVENT:
65344- atomic_set(&rttest_event, 0);
65345+ atomic_set_unchecked(&rttest_event, 0);
65346 return 0;
65347
65348 default:
65349@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_
65350 return ret;
65351
65352 td->mutexes[id] = 1;
65353- td->event = atomic_add_return(1, &rttest_event);
65354+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65355 rt_mutex_lock(&mutexes[id]);
65356- td->event = atomic_add_return(1, &rttest_event);
65357+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65358 td->mutexes[id] = 4;
65359 return 0;
65360
65361@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_
65362 return ret;
65363
65364 td->mutexes[id] = 1;
65365- td->event = atomic_add_return(1, &rttest_event);
65366+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65367 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
65368- td->event = atomic_add_return(1, &rttest_event);
65369+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65370 td->mutexes[id] = ret ? 0 : 4;
65371 return ret ? -EINTR : 0;
65372
65373@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_
65374 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
65375 return ret;
65376
65377- td->event = atomic_add_return(1, &rttest_event);
65378+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65379 rt_mutex_unlock(&mutexes[id]);
65380- td->event = atomic_add_return(1, &rttest_event);
65381+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65382 td->mutexes[id] = 0;
65383 return 0;
65384
65385@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mu
65386 break;
65387
65388 td->mutexes[dat] = 2;
65389- td->event = atomic_add_return(1, &rttest_event);
65390+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65391 break;
65392
65393 case RTTEST_LOCKBKL:
65394@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mu
65395 return;
65396
65397 td->mutexes[dat] = 3;
65398- td->event = atomic_add_return(1, &rttest_event);
65399+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65400 break;
65401
65402 case RTTEST_LOCKNOWAIT:
65403@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mu
65404 return;
65405
65406 td->mutexes[dat] = 1;
65407- td->event = atomic_add_return(1, &rttest_event);
65408+ td->event = atomic_add_return_unchecked(1, &rttest_event);
65409 return;
65410
65411 case RTTEST_LOCKBKL:
65412diff -urNp linux-2.6.32.43/kernel/sched.c linux-2.6.32.43/kernel/sched.c
65413--- linux-2.6.32.43/kernel/sched.c 2011-03-27 14:31:47.000000000 -0400
65414+++ linux-2.6.32.43/kernel/sched.c 2011-05-22 23:02:06.000000000 -0400
65415@@ -5043,7 +5043,7 @@ out:
65416 * In CONFIG_NO_HZ case, the idle load balance owner will do the
65417 * rebalancing for all the cpus for whom scheduler ticks are stopped.
65418 */
65419-static void run_rebalance_domains(struct softirq_action *h)
65420+static void run_rebalance_domains(void)
65421 {
65422 int this_cpu = smp_processor_id();
65423 struct rq *this_rq = cpu_rq(this_cpu);
65424@@ -5700,6 +5700,8 @@ asmlinkage void __sched schedule(void)
65425 struct rq *rq;
65426 int cpu;
65427
65428+ pax_track_stack();
65429+
65430 need_resched:
65431 preempt_disable();
65432 cpu = smp_processor_id();
65433@@ -5770,7 +5772,7 @@ EXPORT_SYMBOL(schedule);
65434 * Look out! "owner" is an entirely speculative pointer
65435 * access and not reliable.
65436 */
65437-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
65438+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
65439 {
65440 unsigned int cpu;
65441 struct rq *rq;
65442@@ -5784,10 +5786,10 @@ int mutex_spin_on_owner(struct mutex *lo
65443 * DEBUG_PAGEALLOC could have unmapped it if
65444 * the mutex owner just released it and exited.
65445 */
65446- if (probe_kernel_address(&owner->cpu, cpu))
65447+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
65448 return 0;
65449 #else
65450- cpu = owner->cpu;
65451+ cpu = task_thread_info(owner)->cpu;
65452 #endif
65453
65454 /*
65455@@ -5816,7 +5818,7 @@ int mutex_spin_on_owner(struct mutex *lo
65456 /*
65457 * Is that owner really running on that cpu?
65458 */
65459- if (task_thread_info(rq->curr) != owner || need_resched())
65460+ if (rq->curr != owner || need_resched())
65461 return 0;
65462
65463 cpu_relax();
65464@@ -6359,6 +6361,8 @@ int can_nice(const struct task_struct *p
65465 /* convert nice value [19,-20] to rlimit style value [1,40] */
65466 int nice_rlim = 20 - nice;
65467
65468+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
65469+
65470 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
65471 capable(CAP_SYS_NICE));
65472 }
65473@@ -6392,7 +6396,8 @@ SYSCALL_DEFINE1(nice, int, increment)
65474 if (nice > 19)
65475 nice = 19;
65476
65477- if (increment < 0 && !can_nice(current, nice))
65478+ if (increment < 0 && (!can_nice(current, nice) ||
65479+ gr_handle_chroot_nice()))
65480 return -EPERM;
65481
65482 retval = security_task_setnice(current, nice);
65483@@ -8774,7 +8779,7 @@ static void init_sched_groups_power(int
65484 long power;
65485 int weight;
65486
65487- WARN_ON(!sd || !sd->groups);
65488+ BUG_ON(!sd || !sd->groups);
65489
65490 if (cpu != group_first_cpu(sd->groups))
65491 return;
65492diff -urNp linux-2.6.32.43/kernel/signal.c linux-2.6.32.43/kernel/signal.c
65493--- linux-2.6.32.43/kernel/signal.c 2011-04-17 17:00:52.000000000 -0400
65494+++ linux-2.6.32.43/kernel/signal.c 2011-07-14 20:33:33.000000000 -0400
65495@@ -41,12 +41,12 @@
65496
65497 static struct kmem_cache *sigqueue_cachep;
65498
65499-static void __user *sig_handler(struct task_struct *t, int sig)
65500+static __sighandler_t sig_handler(struct task_struct *t, int sig)
65501 {
65502 return t->sighand->action[sig - 1].sa.sa_handler;
65503 }
65504
65505-static int sig_handler_ignored(void __user *handler, int sig)
65506+static int sig_handler_ignored(__sighandler_t handler, int sig)
65507 {
65508 /* Is it explicitly or implicitly ignored? */
65509 return handler == SIG_IGN ||
65510@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __us
65511 static int sig_task_ignored(struct task_struct *t, int sig,
65512 int from_ancestor_ns)
65513 {
65514- void __user *handler;
65515+ __sighandler_t handler;
65516
65517 handler = sig_handler(t, sig);
65518
65519@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc
65520 */
65521 user = get_uid(__task_cred(t)->user);
65522 atomic_inc(&user->sigpending);
65523+
65524+ if (!override_rlimit)
65525+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
65526 if (override_rlimit ||
65527 atomic_read(&user->sigpending) <=
65528 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
65529@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct
65530
65531 int unhandled_signal(struct task_struct *tsk, int sig)
65532 {
65533- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
65534+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
65535 if (is_global_init(tsk))
65536 return 1;
65537 if (handler != SIG_IGN && handler != SIG_DFL)
65538@@ -627,6 +630,12 @@ static int check_kill_permission(int sig
65539 }
65540 }
65541
65542+ /* allow glibc communication via tgkill to other threads in our
65543+ thread group */
65544+ if ((info->si_code != SI_TKILL || sig != (SIGRTMIN+1) ||
65545+ task_tgid_vnr(t) != info->si_pid) && gr_handle_signal(t, sig))
65546+ return -EPERM;
65547+
65548 return security_task_kill(t, info, sig, 0);
65549 }
65550
65551@@ -968,7 +977,7 @@ __group_send_sig_info(int sig, struct si
65552 return send_signal(sig, info, p, 1);
65553 }
65554
65555-static int
65556+int
65557 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
65558 {
65559 return send_signal(sig, info, t, 0);
65560@@ -1005,6 +1014,7 @@ force_sig_info(int sig, struct siginfo *
65561 unsigned long int flags;
65562 int ret, blocked, ignored;
65563 struct k_sigaction *action;
65564+ int is_unhandled = 0;
65565
65566 spin_lock_irqsave(&t->sighand->siglock, flags);
65567 action = &t->sighand->action[sig-1];
65568@@ -1019,9 +1029,18 @@ force_sig_info(int sig, struct siginfo *
65569 }
65570 if (action->sa.sa_handler == SIG_DFL)
65571 t->signal->flags &= ~SIGNAL_UNKILLABLE;
65572+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
65573+ is_unhandled = 1;
65574 ret = specific_send_sig_info(sig, info, t);
65575 spin_unlock_irqrestore(&t->sighand->siglock, flags);
65576
65577+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
65578+ normal operation */
65579+ if (is_unhandled) {
65580+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
65581+ gr_handle_crash(t, sig);
65582+ }
65583+
65584 return ret;
65585 }
65586
65587@@ -1081,8 +1100,11 @@ int group_send_sig_info(int sig, struct
65588 {
65589 int ret = check_kill_permission(sig, info, p);
65590
65591- if (!ret && sig)
65592+ if (!ret && sig) {
65593 ret = do_send_sig_info(sig, info, p, true);
65594+ if (!ret)
65595+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
65596+ }
65597
65598 return ret;
65599 }
65600@@ -1644,6 +1666,8 @@ void ptrace_notify(int exit_code)
65601 {
65602 siginfo_t info;
65603
65604+ pax_track_stack();
65605+
65606 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
65607
65608 memset(&info, 0, sizeof info);
65609@@ -2275,7 +2299,15 @@ do_send_specific(pid_t tgid, pid_t pid,
65610 int error = -ESRCH;
65611
65612 rcu_read_lock();
65613- p = find_task_by_vpid(pid);
65614+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65615+ /* allow glibc communication via tgkill to other threads in our
65616+ thread group */
65617+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
65618+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
65619+ p = find_task_by_vpid_unrestricted(pid);
65620+ else
65621+#endif
65622+ p = find_task_by_vpid(pid);
65623 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
65624 error = check_kill_permission(sig, info, p);
65625 /*
65626diff -urNp linux-2.6.32.43/kernel/smp.c linux-2.6.32.43/kernel/smp.c
65627--- linux-2.6.32.43/kernel/smp.c 2011-03-27 14:31:47.000000000 -0400
65628+++ linux-2.6.32.43/kernel/smp.c 2011-04-17 15:56:46.000000000 -0400
65629@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void
65630 }
65631 EXPORT_SYMBOL(smp_call_function);
65632
65633-void ipi_call_lock(void)
65634+void ipi_call_lock(void) __acquires(call_function.lock)
65635 {
65636 spin_lock(&call_function.lock);
65637 }
65638
65639-void ipi_call_unlock(void)
65640+void ipi_call_unlock(void) __releases(call_function.lock)
65641 {
65642 spin_unlock(&call_function.lock);
65643 }
65644
65645-void ipi_call_lock_irq(void)
65646+void ipi_call_lock_irq(void) __acquires(call_function.lock)
65647 {
65648 spin_lock_irq(&call_function.lock);
65649 }
65650
65651-void ipi_call_unlock_irq(void)
65652+void ipi_call_unlock_irq(void) __releases(call_function.lock)
65653 {
65654 spin_unlock_irq(&call_function.lock);
65655 }
65656diff -urNp linux-2.6.32.43/kernel/softirq.c linux-2.6.32.43/kernel/softirq.c
65657--- linux-2.6.32.43/kernel/softirq.c 2011-03-27 14:31:47.000000000 -0400
65658+++ linux-2.6.32.43/kernel/softirq.c 2011-08-05 20:33:55.000000000 -0400
65659@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
65660
65661 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
65662
65663-char *softirq_to_name[NR_SOFTIRQS] = {
65664+const char * const softirq_to_name[NR_SOFTIRQS] = {
65665 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
65666 "TASKLET", "SCHED", "HRTIMER", "RCU"
65667 };
65668@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
65669
65670 asmlinkage void __do_softirq(void)
65671 {
65672- struct softirq_action *h;
65673+ const struct softirq_action *h;
65674 __u32 pending;
65675 int max_restart = MAX_SOFTIRQ_RESTART;
65676 int cpu;
65677@@ -233,7 +233,7 @@ restart:
65678 kstat_incr_softirqs_this_cpu(h - softirq_vec);
65679
65680 trace_softirq_entry(h, softirq_vec);
65681- h->action(h);
65682+ h->action();
65683 trace_softirq_exit(h, softirq_vec);
65684 if (unlikely(prev_count != preempt_count())) {
65685 printk(KERN_ERR "huh, entered softirq %td %s %p"
65686@@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
65687 local_irq_restore(flags);
65688 }
65689
65690-void open_softirq(int nr, void (*action)(struct softirq_action *))
65691+void open_softirq(int nr, void (*action)(void))
65692 {
65693- softirq_vec[nr].action = action;
65694+ pax_open_kernel();
65695+ *(void **)&softirq_vec[nr].action = action;
65696+ pax_close_kernel();
65697 }
65698
65699 /*
65700@@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct
65701
65702 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
65703
65704-static void tasklet_action(struct softirq_action *a)
65705+static void tasklet_action(void)
65706 {
65707 struct tasklet_struct *list;
65708
65709@@ -454,7 +456,7 @@ static void tasklet_action(struct softir
65710 }
65711 }
65712
65713-static void tasklet_hi_action(struct softirq_action *a)
65714+static void tasklet_hi_action(void)
65715 {
65716 struct tasklet_struct *list;
65717
65718diff -urNp linux-2.6.32.43/kernel/sys.c linux-2.6.32.43/kernel/sys.c
65719--- linux-2.6.32.43/kernel/sys.c 2011-03-27 14:31:47.000000000 -0400
65720+++ linux-2.6.32.43/kernel/sys.c 2011-04-17 15:56:46.000000000 -0400
65721@@ -133,6 +133,12 @@ static int set_one_prio(struct task_stru
65722 error = -EACCES;
65723 goto out;
65724 }
65725+
65726+ if (gr_handle_chroot_setpriority(p, niceval)) {
65727+ error = -EACCES;
65728+ goto out;
65729+ }
65730+
65731 no_nice = security_task_setnice(p, niceval);
65732 if (no_nice) {
65733 error = no_nice;
65734@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
65735 !(user = find_user(who)))
65736 goto out_unlock; /* No processes for this user */
65737
65738- do_each_thread(g, p)
65739+ do_each_thread(g, p) {
65740 if (__task_cred(p)->uid == who)
65741 error = set_one_prio(p, niceval, error);
65742- while_each_thread(g, p);
65743+ } while_each_thread(g, p);
65744 if (who != cred->uid)
65745 free_uid(user); /* For find_user() */
65746 break;
65747@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which,
65748 !(user = find_user(who)))
65749 goto out_unlock; /* No processes for this user */
65750
65751- do_each_thread(g, p)
65752+ do_each_thread(g, p) {
65753 if (__task_cred(p)->uid == who) {
65754 niceval = 20 - task_nice(p);
65755 if (niceval > retval)
65756 retval = niceval;
65757 }
65758- while_each_thread(g, p);
65759+ } while_each_thread(g, p);
65760 if (who != cred->uid)
65761 free_uid(user); /* for find_user() */
65762 break;
65763@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
65764 goto error;
65765 }
65766
65767+ if (gr_check_group_change(new->gid, new->egid, -1))
65768+ goto error;
65769+
65770 if (rgid != (gid_t) -1 ||
65771 (egid != (gid_t) -1 && egid != old->gid))
65772 new->sgid = new->egid;
65773@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
65774 goto error;
65775
65776 retval = -EPERM;
65777+
65778+ if (gr_check_group_change(gid, gid, gid))
65779+ goto error;
65780+
65781 if (capable(CAP_SETGID))
65782 new->gid = new->egid = new->sgid = new->fsgid = gid;
65783 else if (gid == old->gid || gid == old->sgid)
65784@@ -627,6 +640,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
65785 goto error;
65786 }
65787
65788+ if (gr_check_user_change(new->uid, new->euid, -1))
65789+ goto error;
65790+
65791 if (new->uid != old->uid) {
65792 retval = set_user(new);
65793 if (retval < 0)
65794@@ -675,6 +691,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
65795 goto error;
65796
65797 retval = -EPERM;
65798+
65799+ if (gr_check_crash_uid(uid))
65800+ goto error;
65801+ if (gr_check_user_change(uid, uid, uid))
65802+ goto error;
65803+
65804 if (capable(CAP_SETUID)) {
65805 new->suid = new->uid = uid;
65806 if (uid != old->uid) {
65807@@ -732,6 +754,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
65808 goto error;
65809 }
65810
65811+ if (gr_check_user_change(ruid, euid, -1))
65812+ goto error;
65813+
65814 if (ruid != (uid_t) -1) {
65815 new->uid = ruid;
65816 if (ruid != old->uid) {
65817@@ -800,6 +825,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
65818 goto error;
65819 }
65820
65821+ if (gr_check_group_change(rgid, egid, -1))
65822+ goto error;
65823+
65824 if (rgid != (gid_t) -1)
65825 new->gid = rgid;
65826 if (egid != (gid_t) -1)
65827@@ -849,6 +877,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
65828 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
65829 goto error;
65830
65831+ if (gr_check_user_change(-1, -1, uid))
65832+ goto error;
65833+
65834 if (uid == old->uid || uid == old->euid ||
65835 uid == old->suid || uid == old->fsuid ||
65836 capable(CAP_SETUID)) {
65837@@ -889,6 +920,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
65838 if (gid == old->gid || gid == old->egid ||
65839 gid == old->sgid || gid == old->fsgid ||
65840 capable(CAP_SETGID)) {
65841+ if (gr_check_group_change(-1, -1, gid))
65842+ goto error;
65843+
65844 if (gid != old_fsgid) {
65845 new->fsgid = gid;
65846 goto change_okay;
65847@@ -1454,7 +1488,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
65848 error = get_dumpable(me->mm);
65849 break;
65850 case PR_SET_DUMPABLE:
65851- if (arg2 < 0 || arg2 > 1) {
65852+ if (arg2 > 1) {
65853 error = -EINVAL;
65854 break;
65855 }
65856diff -urNp linux-2.6.32.43/kernel/sysctl.c linux-2.6.32.43/kernel/sysctl.c
65857--- linux-2.6.32.43/kernel/sysctl.c 2011-03-27 14:31:47.000000000 -0400
65858+++ linux-2.6.32.43/kernel/sysctl.c 2011-04-17 15:56:46.000000000 -0400
65859@@ -63,6 +63,13 @@
65860 static int deprecated_sysctl_warning(struct __sysctl_args *args);
65861
65862 #if defined(CONFIG_SYSCTL)
65863+#include <linux/grsecurity.h>
65864+#include <linux/grinternal.h>
65865+
65866+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
65867+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
65868+ const int op);
65869+extern int gr_handle_chroot_sysctl(const int op);
65870
65871 /* External variables not in a header file. */
65872 extern int C_A_D;
65873@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_ta
65874 static int proc_taint(struct ctl_table *table, int write,
65875 void __user *buffer, size_t *lenp, loff_t *ppos);
65876 #endif
65877+extern ctl_table grsecurity_table[];
65878
65879 static struct ctl_table root_table[];
65880 static struct ctl_table_root sysctl_table_root;
65881@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
65882 int sysctl_legacy_va_layout;
65883 #endif
65884
65885+#ifdef CONFIG_PAX_SOFTMODE
65886+static ctl_table pax_table[] = {
65887+ {
65888+ .ctl_name = CTL_UNNUMBERED,
65889+ .procname = "softmode",
65890+ .data = &pax_softmode,
65891+ .maxlen = sizeof(unsigned int),
65892+ .mode = 0600,
65893+ .proc_handler = &proc_dointvec,
65894+ },
65895+
65896+ { .ctl_name = 0 }
65897+};
65898+#endif
65899+
65900 extern int prove_locking;
65901 extern int lock_stat;
65902
65903@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = N
65904 #endif
65905
65906 static struct ctl_table kern_table[] = {
65907+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65908+ {
65909+ .ctl_name = CTL_UNNUMBERED,
65910+ .procname = "grsecurity",
65911+ .mode = 0500,
65912+ .child = grsecurity_table,
65913+ },
65914+#endif
65915+
65916+#ifdef CONFIG_PAX_SOFTMODE
65917+ {
65918+ .ctl_name = CTL_UNNUMBERED,
65919+ .procname = "pax",
65920+ .mode = 0500,
65921+ .child = pax_table,
65922+ },
65923+#endif
65924+
65925 {
65926 .ctl_name = CTL_UNNUMBERED,
65927 .procname = "sched_child_runs_first",
65928@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
65929 .data = &modprobe_path,
65930 .maxlen = KMOD_PATH_LEN,
65931 .mode = 0644,
65932- .proc_handler = &proc_dostring,
65933- .strategy = &sysctl_string,
65934+ .proc_handler = &proc_dostring_modpriv,
65935+ .strategy = &sysctl_string_modpriv,
65936 },
65937 {
65938 .ctl_name = CTL_UNNUMBERED,
65939@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
65940 .mode = 0644,
65941 .proc_handler = &proc_dointvec
65942 },
65943+ {
65944+ .procname = "heap_stack_gap",
65945+ .data = &sysctl_heap_stack_gap,
65946+ .maxlen = sizeof(sysctl_heap_stack_gap),
65947+ .mode = 0644,
65948+ .proc_handler = proc_doulongvec_minmax,
65949+ },
65950 #else
65951 {
65952 .ctl_name = CTL_UNNUMBERED,
65953@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl
65954 return 0;
65955 }
65956
65957+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
65958+
65959 static int parse_table(int __user *name, int nlen,
65960 void __user *oldval, size_t __user *oldlenp,
65961 void __user *newval, size_t newlen,
65962@@ -1821,7 +1871,7 @@ repeat:
65963 if (n == table->ctl_name) {
65964 int error;
65965 if (table->child) {
65966- if (sysctl_perm(root, table, MAY_EXEC))
65967+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
65968 return -EPERM;
65969 name++;
65970 nlen--;
65971@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *r
65972 int error;
65973 int mode;
65974
65975+ if (table->parent != NULL && table->parent->procname != NULL &&
65976+ table->procname != NULL &&
65977+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
65978+ return -EACCES;
65979+ if (gr_handle_chroot_sysctl(op))
65980+ return -EACCES;
65981+ error = gr_handle_sysctl(table, op);
65982+ if (error)
65983+ return error;
65984+
65985+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
65986+ if (error)
65987+ return error;
65988+
65989+ if (root->permissions)
65990+ mode = root->permissions(root, current->nsproxy, table);
65991+ else
65992+ mode = table->mode;
65993+
65994+ return test_perm(mode, op);
65995+}
65996+
65997+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
65998+{
65999+ int error;
66000+ int mode;
66001+
66002 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
66003 if (error)
66004 return error;
66005@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *tabl
66006 buffer, lenp, ppos);
66007 }
66008
66009+int proc_dostring_modpriv(struct ctl_table *table, int write,
66010+ void __user *buffer, size_t *lenp, loff_t *ppos)
66011+{
66012+ if (write && !capable(CAP_SYS_MODULE))
66013+ return -EPERM;
66014+
66015+ return _proc_do_string(table->data, table->maxlen, write,
66016+ buffer, lenp, ppos);
66017+}
66018+
66019
66020 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
66021 int *valp,
66022@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(v
66023 vleft = table->maxlen / sizeof(unsigned long);
66024 left = *lenp;
66025
66026- for (; left && vleft--; i++, min++, max++, first=0) {
66027+ for (; left && vleft--; i++, first=0) {
66028 if (write) {
66029 while (left) {
66030 char c;
66031@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *tabl
66032 return -ENOSYS;
66033 }
66034
66035+int proc_dostring_modpriv(struct ctl_table *table, int write,
66036+ void __user *buffer, size_t *lenp, loff_t *ppos)
66037+{
66038+ return -ENOSYS;
66039+}
66040+
66041 int proc_dointvec(struct ctl_table *table, int write,
66042 void __user *buffer, size_t *lenp, loff_t *ppos)
66043 {
66044@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *tabl
66045 return 1;
66046 }
66047
66048+int sysctl_string_modpriv(struct ctl_table *table,
66049+ void __user *oldval, size_t __user *oldlenp,
66050+ void __user *newval, size_t newlen)
66051+{
66052+ if (newval && newlen && !capable(CAP_SYS_MODULE))
66053+ return -EPERM;
66054+
66055+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
66056+}
66057+
66058 /*
66059 * This function makes sure that all of the integers in the vector
66060 * are between the minimum and maximum values given in the arrays
66061@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *tabl
66062 return -ENOSYS;
66063 }
66064
66065+int sysctl_string_modpriv(struct ctl_table *table,
66066+ void __user *oldval, size_t __user *oldlenp,
66067+ void __user *newval, size_t newlen)
66068+{
66069+ return -ENOSYS;
66070+}
66071+
66072 int sysctl_intvec(struct ctl_table *table,
66073 void __user *oldval, size_t __user *oldlenp,
66074 void __user *newval, size_t newlen)
66075@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
66076 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
66077 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
66078 EXPORT_SYMBOL(proc_dostring);
66079+EXPORT_SYMBOL(proc_dostring_modpriv);
66080 EXPORT_SYMBOL(proc_doulongvec_minmax);
66081 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
66082 EXPORT_SYMBOL(register_sysctl_table);
66083@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
66084 EXPORT_SYMBOL(sysctl_jiffies);
66085 EXPORT_SYMBOL(sysctl_ms_jiffies);
66086 EXPORT_SYMBOL(sysctl_string);
66087+EXPORT_SYMBOL(sysctl_string_modpriv);
66088 EXPORT_SYMBOL(sysctl_data);
66089 EXPORT_SYMBOL(unregister_sysctl_table);
66090diff -urNp linux-2.6.32.43/kernel/sysctl_check.c linux-2.6.32.43/kernel/sysctl_check.c
66091--- linux-2.6.32.43/kernel/sysctl_check.c 2011-03-27 14:31:47.000000000 -0400
66092+++ linux-2.6.32.43/kernel/sysctl_check.c 2011-04-17 15:56:46.000000000 -0400
66093@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *n
66094 } else {
66095 if ((table->strategy == sysctl_data) ||
66096 (table->strategy == sysctl_string) ||
66097+ (table->strategy == sysctl_string_modpriv) ||
66098 (table->strategy == sysctl_intvec) ||
66099 (table->strategy == sysctl_jiffies) ||
66100 (table->strategy == sysctl_ms_jiffies) ||
66101 (table->proc_handler == proc_dostring) ||
66102+ (table->proc_handler == proc_dostring_modpriv) ||
66103 (table->proc_handler == proc_dointvec) ||
66104 (table->proc_handler == proc_dointvec_minmax) ||
66105 (table->proc_handler == proc_dointvec_jiffies) ||
66106diff -urNp linux-2.6.32.43/kernel/taskstats.c linux-2.6.32.43/kernel/taskstats.c
66107--- linux-2.6.32.43/kernel/taskstats.c 2011-07-13 17:23:04.000000000 -0400
66108+++ linux-2.6.32.43/kernel/taskstats.c 2011-07-13 17:23:19.000000000 -0400
66109@@ -26,9 +26,12 @@
66110 #include <linux/cgroup.h>
66111 #include <linux/fs.h>
66112 #include <linux/file.h>
66113+#include <linux/grsecurity.h>
66114 #include <net/genetlink.h>
66115 #include <asm/atomic.h>
66116
66117+extern int gr_is_taskstats_denied(int pid);
66118+
66119 /*
66120 * Maximum length of a cpumask that can be specified in
66121 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
66122@@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_
66123 size_t size;
66124 cpumask_var_t mask;
66125
66126+ if (gr_is_taskstats_denied(current->pid))
66127+ return -EACCES;
66128+
66129 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
66130 return -ENOMEM;
66131
66132diff -urNp linux-2.6.32.43/kernel/time/tick-broadcast.c linux-2.6.32.43/kernel/time/tick-broadcast.c
66133--- linux-2.6.32.43/kernel/time/tick-broadcast.c 2011-05-23 16:56:59.000000000 -0400
66134+++ linux-2.6.32.43/kernel/time/tick-broadcast.c 2011-05-23 16:57:13.000000000 -0400
66135@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl
66136 * then clear the broadcast bit.
66137 */
66138 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
66139- int cpu = smp_processor_id();
66140+ cpu = smp_processor_id();
66141
66142 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
66143 tick_broadcast_clear_oneshot(cpu);
66144diff -urNp linux-2.6.32.43/kernel/time/timekeeping.c linux-2.6.32.43/kernel/time/timekeeping.c
66145--- linux-2.6.32.43/kernel/time/timekeeping.c 2011-06-25 12:55:35.000000000 -0400
66146+++ linux-2.6.32.43/kernel/time/timekeeping.c 2011-06-25 12:56:37.000000000 -0400
66147@@ -14,6 +14,7 @@
66148 #include <linux/init.h>
66149 #include <linux/mm.h>
66150 #include <linux/sched.h>
66151+#include <linux/grsecurity.h>
66152 #include <linux/sysdev.h>
66153 #include <linux/clocksource.h>
66154 #include <linux/jiffies.h>
66155@@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
66156 */
66157 struct timespec ts = xtime;
66158 timespec_add_ns(&ts, nsec);
66159- ACCESS_ONCE(xtime_cache) = ts;
66160+ ACCESS_ONCE_RW(xtime_cache) = ts;
66161 }
66162
66163 /* must hold xtime_lock */
66164@@ -333,6 +334,8 @@ int do_settimeofday(struct timespec *tv)
66165 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
66166 return -EINVAL;
66167
66168+ gr_log_timechange();
66169+
66170 write_seqlock_irqsave(&xtime_lock, flags);
66171
66172 timekeeping_forward_now();
66173diff -urNp linux-2.6.32.43/kernel/time/timer_list.c linux-2.6.32.43/kernel/time/timer_list.c
66174--- linux-2.6.32.43/kernel/time/timer_list.c 2011-03-27 14:31:47.000000000 -0400
66175+++ linux-2.6.32.43/kernel/time/timer_list.c 2011-04-17 15:56:46.000000000 -0400
66176@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
66177
66178 static void print_name_offset(struct seq_file *m, void *sym)
66179 {
66180+#ifdef CONFIG_GRKERNSEC_HIDESYM
66181+ SEQ_printf(m, "<%p>", NULL);
66182+#else
66183 char symname[KSYM_NAME_LEN];
66184
66185 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
66186 SEQ_printf(m, "<%p>", sym);
66187 else
66188 SEQ_printf(m, "%s", symname);
66189+#endif
66190 }
66191
66192 static void
66193@@ -112,7 +116,11 @@ next_one:
66194 static void
66195 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
66196 {
66197+#ifdef CONFIG_GRKERNSEC_HIDESYM
66198+ SEQ_printf(m, " .base: %p\n", NULL);
66199+#else
66200 SEQ_printf(m, " .base: %p\n", base);
66201+#endif
66202 SEQ_printf(m, " .index: %d\n",
66203 base->index);
66204 SEQ_printf(m, " .resolution: %Lu nsecs\n",
66205@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs
66206 {
66207 struct proc_dir_entry *pe;
66208
66209+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66210+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
66211+#else
66212 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
66213+#endif
66214 if (!pe)
66215 return -ENOMEM;
66216 return 0;
66217diff -urNp linux-2.6.32.43/kernel/time/timer_stats.c linux-2.6.32.43/kernel/time/timer_stats.c
66218--- linux-2.6.32.43/kernel/time/timer_stats.c 2011-03-27 14:31:47.000000000 -0400
66219+++ linux-2.6.32.43/kernel/time/timer_stats.c 2011-05-04 17:56:28.000000000 -0400
66220@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
66221 static unsigned long nr_entries;
66222 static struct entry entries[MAX_ENTRIES];
66223
66224-static atomic_t overflow_count;
66225+static atomic_unchecked_t overflow_count;
66226
66227 /*
66228 * The entries are in a hash-table, for fast lookup:
66229@@ -140,7 +140,7 @@ static void reset_entries(void)
66230 nr_entries = 0;
66231 memset(entries, 0, sizeof(entries));
66232 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
66233- atomic_set(&overflow_count, 0);
66234+ atomic_set_unchecked(&overflow_count, 0);
66235 }
66236
66237 static struct entry *alloc_entry(void)
66238@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
66239 if (likely(entry))
66240 entry->count++;
66241 else
66242- atomic_inc(&overflow_count);
66243+ atomic_inc_unchecked(&overflow_count);
66244
66245 out_unlock:
66246 spin_unlock_irqrestore(lock, flags);
66247@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
66248
66249 static void print_name_offset(struct seq_file *m, unsigned long addr)
66250 {
66251+#ifdef CONFIG_GRKERNSEC_HIDESYM
66252+ seq_printf(m, "<%p>", NULL);
66253+#else
66254 char symname[KSYM_NAME_LEN];
66255
66256 if (lookup_symbol_name(addr, symname) < 0)
66257 seq_printf(m, "<%p>", (void *)addr);
66258 else
66259 seq_printf(m, "%s", symname);
66260+#endif
66261 }
66262
66263 static int tstats_show(struct seq_file *m, void *v)
66264@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
66265
66266 seq_puts(m, "Timer Stats Version: v0.2\n");
66267 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
66268- if (atomic_read(&overflow_count))
66269+ if (atomic_read_unchecked(&overflow_count))
66270 seq_printf(m, "Overflow: %d entries\n",
66271- atomic_read(&overflow_count));
66272+ atomic_read_unchecked(&overflow_count));
66273
66274 for (i = 0; i < nr_entries; i++) {
66275 entry = entries + i;
66276@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(voi
66277 {
66278 struct proc_dir_entry *pe;
66279
66280+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66281+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
66282+#else
66283 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
66284+#endif
66285 if (!pe)
66286 return -ENOMEM;
66287 return 0;
66288diff -urNp linux-2.6.32.43/kernel/time.c linux-2.6.32.43/kernel/time.c
66289--- linux-2.6.32.43/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
66290+++ linux-2.6.32.43/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
66291@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec
66292 return error;
66293
66294 if (tz) {
66295+ /* we log in do_settimeofday called below, so don't log twice
66296+ */
66297+ if (!tv)
66298+ gr_log_timechange();
66299+
66300 /* SMP safe, global irq locking makes it work. */
66301 sys_tz = *tz;
66302 update_vsyscall_tz();
66303@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
66304 * Avoid unnecessary multiplications/divisions in the
66305 * two most common HZ cases:
66306 */
66307-unsigned int inline jiffies_to_msecs(const unsigned long j)
66308+inline unsigned int jiffies_to_msecs(const unsigned long j)
66309 {
66310 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
66311 return (MSEC_PER_SEC / HZ) * j;
66312@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(con
66313 }
66314 EXPORT_SYMBOL(jiffies_to_msecs);
66315
66316-unsigned int inline jiffies_to_usecs(const unsigned long j)
66317+inline unsigned int jiffies_to_usecs(const unsigned long j)
66318 {
66319 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
66320 return (USEC_PER_SEC / HZ) * j;
66321diff -urNp linux-2.6.32.43/kernel/timer.c linux-2.6.32.43/kernel/timer.c
66322--- linux-2.6.32.43/kernel/timer.c 2011-03-27 14:31:47.000000000 -0400
66323+++ linux-2.6.32.43/kernel/timer.c 2011-04-17 15:56:46.000000000 -0400
66324@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
66325 /*
66326 * This function runs timers and the timer-tq in bottom half context.
66327 */
66328-static void run_timer_softirq(struct softirq_action *h)
66329+static void run_timer_softirq(void)
66330 {
66331 struct tvec_base *base = __get_cpu_var(tvec_bases);
66332
66333diff -urNp linux-2.6.32.43/kernel/trace/blktrace.c linux-2.6.32.43/kernel/trace/blktrace.c
66334--- linux-2.6.32.43/kernel/trace/blktrace.c 2011-03-27 14:31:47.000000000 -0400
66335+++ linux-2.6.32.43/kernel/trace/blktrace.c 2011-05-04 17:56:28.000000000 -0400
66336@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct f
66337 struct blk_trace *bt = filp->private_data;
66338 char buf[16];
66339
66340- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
66341+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
66342
66343 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
66344 }
66345@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(str
66346 return 1;
66347
66348 bt = buf->chan->private_data;
66349- atomic_inc(&bt->dropped);
66350+ atomic_inc_unchecked(&bt->dropped);
66351 return 0;
66352 }
66353
66354@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_qu
66355
66356 bt->dir = dir;
66357 bt->dev = dev;
66358- atomic_set(&bt->dropped, 0);
66359+ atomic_set_unchecked(&bt->dropped, 0);
66360
66361 ret = -EIO;
66362 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
66363diff -urNp linux-2.6.32.43/kernel/trace/ftrace.c linux-2.6.32.43/kernel/trace/ftrace.c
66364--- linux-2.6.32.43/kernel/trace/ftrace.c 2011-06-25 12:55:35.000000000 -0400
66365+++ linux-2.6.32.43/kernel/trace/ftrace.c 2011-06-25 12:56:37.000000000 -0400
66366@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod,
66367
66368 ip = rec->ip;
66369
66370+ ret = ftrace_arch_code_modify_prepare();
66371+ FTRACE_WARN_ON(ret);
66372+ if (ret)
66373+ return 0;
66374+
66375 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
66376+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
66377 if (ret) {
66378 ftrace_bug(ret, ip);
66379 rec->flags |= FTRACE_FL_FAILED;
66380- return 0;
66381 }
66382- return 1;
66383+ return ret ? 0 : 1;
66384 }
66385
66386 /*
66387diff -urNp linux-2.6.32.43/kernel/trace/ring_buffer.c linux-2.6.32.43/kernel/trace/ring_buffer.c
66388--- linux-2.6.32.43/kernel/trace/ring_buffer.c 2011-03-27 14:31:47.000000000 -0400
66389+++ linux-2.6.32.43/kernel/trace/ring_buffer.c 2011-04-17 15:56:46.000000000 -0400
66390@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(st
66391 * the reader page). But if the next page is a header page,
66392 * its flags will be non zero.
66393 */
66394-static int inline
66395+static inline int
66396 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
66397 struct buffer_page *page, struct list_head *list)
66398 {
66399diff -urNp linux-2.6.32.43/kernel/trace/trace.c linux-2.6.32.43/kernel/trace/trace.c
66400--- linux-2.6.32.43/kernel/trace/trace.c 2011-03-27 14:31:47.000000000 -0400
66401+++ linux-2.6.32.43/kernel/trace/trace.c 2011-05-16 21:46:57.000000000 -0400
66402@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(
66403 size_t rem;
66404 unsigned int i;
66405
66406+ pax_track_stack();
66407+
66408 /* copy the tracer to avoid using a global lock all around */
66409 mutex_lock(&trace_types_lock);
66410 if (unlikely(old_tracer != current_trace && current_trace)) {
66411@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file
66412 int entries, size, i;
66413 size_t ret;
66414
66415+ pax_track_stack();
66416+
66417 if (*ppos & (PAGE_SIZE - 1)) {
66418 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
66419 return -EINVAL;
66420@@ -3816,10 +3820,9 @@ static const struct file_operations trac
66421 };
66422 #endif
66423
66424-static struct dentry *d_tracer;
66425-
66426 struct dentry *tracing_init_dentry(void)
66427 {
66428+ static struct dentry *d_tracer;
66429 static int once;
66430
66431 if (d_tracer)
66432@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
66433 return d_tracer;
66434 }
66435
66436-static struct dentry *d_percpu;
66437-
66438 struct dentry *tracing_dentry_percpu(void)
66439 {
66440+ static struct dentry *d_percpu;
66441 static int once;
66442 struct dentry *d_tracer;
66443
66444diff -urNp linux-2.6.32.43/kernel/trace/trace_events.c linux-2.6.32.43/kernel/trace/trace_events.c
66445--- linux-2.6.32.43/kernel/trace/trace_events.c 2011-03-27 14:31:47.000000000 -0400
66446+++ linux-2.6.32.43/kernel/trace/trace_events.c 2011-08-05 20:33:55.000000000 -0400
66447@@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list
66448 * Modules must own their file_operations to keep up with
66449 * reference counting.
66450 */
66451+
66452 struct ftrace_module_file_ops {
66453 struct list_head list;
66454 struct module *mod;
66455- struct file_operations id;
66456- struct file_operations enable;
66457- struct file_operations format;
66458- struct file_operations filter;
66459 };
66460
66461 static void remove_subsystem_dir(const char *name)
66462@@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod
66463
66464 file_ops->mod = mod;
66465
66466- file_ops->id = ftrace_event_id_fops;
66467- file_ops->id.owner = mod;
66468-
66469- file_ops->enable = ftrace_enable_fops;
66470- file_ops->enable.owner = mod;
66471-
66472- file_ops->filter = ftrace_event_filter_fops;
66473- file_ops->filter.owner = mod;
66474-
66475- file_ops->format = ftrace_event_format_fops;
66476- file_ops->format.owner = mod;
66477+ pax_open_kernel();
66478+ *(void **)&mod->trace_id.owner = mod;
66479+ *(void **)&mod->trace_enable.owner = mod;
66480+ *(void **)&mod->trace_filter.owner = mod;
66481+ *(void **)&mod->trace_format.owner = mod;
66482+ pax_close_kernel();
66483
66484 list_add(&file_ops->list, &ftrace_module_file_list);
66485
66486@@ -1063,8 +1055,8 @@ static void trace_module_add_events(stru
66487 call->mod = mod;
66488 list_add(&call->list, &ftrace_events);
66489 event_create_dir(call, d_events,
66490- &file_ops->id, &file_ops->enable,
66491- &file_ops->filter, &file_ops->format);
66492+ &mod->trace_id, &mod->trace_enable,
66493+ &mod->trace_filter, &mod->trace_format);
66494 }
66495 }
66496
66497diff -urNp linux-2.6.32.43/kernel/trace/trace_mmiotrace.c linux-2.6.32.43/kernel/trace/trace_mmiotrace.c
66498--- linux-2.6.32.43/kernel/trace/trace_mmiotrace.c 2011-03-27 14:31:47.000000000 -0400
66499+++ linux-2.6.32.43/kernel/trace/trace_mmiotrace.c 2011-05-04 17:56:28.000000000 -0400
66500@@ -23,7 +23,7 @@ struct header_iter {
66501 static struct trace_array *mmio_trace_array;
66502 static bool overrun_detected;
66503 static unsigned long prev_overruns;
66504-static atomic_t dropped_count;
66505+static atomic_unchecked_t dropped_count;
66506
66507 static void mmio_reset_data(struct trace_array *tr)
66508 {
66509@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iter
66510
66511 static unsigned long count_overruns(struct trace_iterator *iter)
66512 {
66513- unsigned long cnt = atomic_xchg(&dropped_count, 0);
66514+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
66515 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
66516
66517 if (over > prev_overruns)
66518@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct
66519 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
66520 sizeof(*entry), 0, pc);
66521 if (!event) {
66522- atomic_inc(&dropped_count);
66523+ atomic_inc_unchecked(&dropped_count);
66524 return;
66525 }
66526 entry = ring_buffer_event_data(event);
66527@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct
66528 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
66529 sizeof(*entry), 0, pc);
66530 if (!event) {
66531- atomic_inc(&dropped_count);
66532+ atomic_inc_unchecked(&dropped_count);
66533 return;
66534 }
66535 entry = ring_buffer_event_data(event);
66536diff -urNp linux-2.6.32.43/kernel/trace/trace_output.c linux-2.6.32.43/kernel/trace/trace_output.c
66537--- linux-2.6.32.43/kernel/trace/trace_output.c 2011-03-27 14:31:47.000000000 -0400
66538+++ linux-2.6.32.43/kernel/trace/trace_output.c 2011-04-17 15:56:46.000000000 -0400
66539@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s,
66540 return 0;
66541 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
66542 if (!IS_ERR(p)) {
66543- p = mangle_path(s->buffer + s->len, p, "\n");
66544+ p = mangle_path(s->buffer + s->len, p, "\n\\");
66545 if (p) {
66546 s->len = p - s->buffer;
66547 return 1;
66548diff -urNp linux-2.6.32.43/kernel/trace/trace_stack.c linux-2.6.32.43/kernel/trace/trace_stack.c
66549--- linux-2.6.32.43/kernel/trace/trace_stack.c 2011-03-27 14:31:47.000000000 -0400
66550+++ linux-2.6.32.43/kernel/trace/trace_stack.c 2011-04-17 15:56:46.000000000 -0400
66551@@ -50,7 +50,7 @@ static inline void check_stack(void)
66552 return;
66553
66554 /* we do not handle interrupt stacks yet */
66555- if (!object_is_on_stack(&this_size))
66556+ if (!object_starts_on_stack(&this_size))
66557 return;
66558
66559 local_irq_save(flags);
66560diff -urNp linux-2.6.32.43/kernel/trace/trace_workqueue.c linux-2.6.32.43/kernel/trace/trace_workqueue.c
66561--- linux-2.6.32.43/kernel/trace/trace_workqueue.c 2011-03-27 14:31:47.000000000 -0400
66562+++ linux-2.6.32.43/kernel/trace/trace_workqueue.c 2011-04-17 15:56:46.000000000 -0400
66563@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
66564 int cpu;
66565 pid_t pid;
66566 /* Can be inserted from interrupt or user context, need to be atomic */
66567- atomic_t inserted;
66568+ atomic_unchecked_t inserted;
66569 /*
66570 * Don't need to be atomic, works are serialized in a single workqueue thread
66571 * on a single CPU.
66572@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_st
66573 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
66574 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
66575 if (node->pid == wq_thread->pid) {
66576- atomic_inc(&node->inserted);
66577+ atomic_inc_unchecked(&node->inserted);
66578 goto found;
66579 }
66580 }
66581@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct se
66582 tsk = get_pid_task(pid, PIDTYPE_PID);
66583 if (tsk) {
66584 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
66585- atomic_read(&cws->inserted), cws->executed,
66586+ atomic_read_unchecked(&cws->inserted), cws->executed,
66587 tsk->comm);
66588 put_task_struct(tsk);
66589 }
66590diff -urNp linux-2.6.32.43/kernel/user.c linux-2.6.32.43/kernel/user.c
66591--- linux-2.6.32.43/kernel/user.c 2011-03-27 14:31:47.000000000 -0400
66592+++ linux-2.6.32.43/kernel/user.c 2011-04-17 15:56:46.000000000 -0400
66593@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct use
66594 spin_lock_irq(&uidhash_lock);
66595 up = uid_hash_find(uid, hashent);
66596 if (up) {
66597+ put_user_ns(ns);
66598 key_put(new->uid_keyring);
66599 key_put(new->session_keyring);
66600 kmem_cache_free(uid_cachep, new);
66601diff -urNp linux-2.6.32.43/lib/bug.c linux-2.6.32.43/lib/bug.c
66602--- linux-2.6.32.43/lib/bug.c 2011-03-27 14:31:47.000000000 -0400
66603+++ linux-2.6.32.43/lib/bug.c 2011-04-17 15:56:46.000000000 -0400
66604@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned l
66605 return BUG_TRAP_TYPE_NONE;
66606
66607 bug = find_bug(bugaddr);
66608+ if (!bug)
66609+ return BUG_TRAP_TYPE_NONE;
66610
66611 printk(KERN_EMERG "------------[ cut here ]------------\n");
66612
66613diff -urNp linux-2.6.32.43/lib/debugobjects.c linux-2.6.32.43/lib/debugobjects.c
66614--- linux-2.6.32.43/lib/debugobjects.c 2011-07-13 17:23:04.000000000 -0400
66615+++ linux-2.6.32.43/lib/debugobjects.c 2011-07-13 17:23:19.000000000 -0400
66616@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(voi
66617 if (limit > 4)
66618 return;
66619
66620- is_on_stack = object_is_on_stack(addr);
66621+ is_on_stack = object_starts_on_stack(addr);
66622 if (is_on_stack == onstack)
66623 return;
66624
66625diff -urNp linux-2.6.32.43/lib/dma-debug.c linux-2.6.32.43/lib/dma-debug.c
66626--- linux-2.6.32.43/lib/dma-debug.c 2011-03-27 14:31:47.000000000 -0400
66627+++ linux-2.6.32.43/lib/dma-debug.c 2011-04-17 15:56:46.000000000 -0400
66628@@ -861,7 +861,7 @@ out:
66629
66630 static void check_for_stack(struct device *dev, void *addr)
66631 {
66632- if (object_is_on_stack(addr))
66633+ if (object_starts_on_stack(addr))
66634 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
66635 "stack [addr=%p]\n", addr);
66636 }
66637diff -urNp linux-2.6.32.43/lib/idr.c linux-2.6.32.43/lib/idr.c
66638--- linux-2.6.32.43/lib/idr.c 2011-03-27 14:31:47.000000000 -0400
66639+++ linux-2.6.32.43/lib/idr.c 2011-04-17 15:56:46.000000000 -0400
66640@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, in
66641 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
66642
66643 /* if already at the top layer, we need to grow */
66644- if (id >= 1 << (idp->layers * IDR_BITS)) {
66645+ if (id >= (1 << (idp->layers * IDR_BITS))) {
66646 *starting_id = id;
66647 return IDR_NEED_TO_GROW;
66648 }
66649diff -urNp linux-2.6.32.43/lib/inflate.c linux-2.6.32.43/lib/inflate.c
66650--- linux-2.6.32.43/lib/inflate.c 2011-03-27 14:31:47.000000000 -0400
66651+++ linux-2.6.32.43/lib/inflate.c 2011-04-17 15:56:46.000000000 -0400
66652@@ -266,7 +266,7 @@ static void free(void *where)
66653 malloc_ptr = free_mem_ptr;
66654 }
66655 #else
66656-#define malloc(a) kmalloc(a, GFP_KERNEL)
66657+#define malloc(a) kmalloc((a), GFP_KERNEL)
66658 #define free(a) kfree(a)
66659 #endif
66660
66661diff -urNp linux-2.6.32.43/lib/Kconfig.debug linux-2.6.32.43/lib/Kconfig.debug
66662--- linux-2.6.32.43/lib/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
66663+++ linux-2.6.32.43/lib/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
66664@@ -905,7 +905,7 @@ config LATENCYTOP
66665 select STACKTRACE
66666 select SCHEDSTATS
66667 select SCHED_DEBUG
66668- depends on HAVE_LATENCYTOP_SUPPORT
66669+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
66670 help
66671 Enable this option if you want to use the LatencyTOP tool
66672 to find out which userspace is blocking on what kernel operations.
66673diff -urNp linux-2.6.32.43/lib/kobject.c linux-2.6.32.43/lib/kobject.c
66674--- linux-2.6.32.43/lib/kobject.c 2011-03-27 14:31:47.000000000 -0400
66675+++ linux-2.6.32.43/lib/kobject.c 2011-04-17 15:56:46.000000000 -0400
66676@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct ko
66677 return ret;
66678 }
66679
66680-struct sysfs_ops kobj_sysfs_ops = {
66681+const struct sysfs_ops kobj_sysfs_ops = {
66682 .show = kobj_attr_show,
66683 .store = kobj_attr_store,
66684 };
66685@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
66686 * If the kset was not able to be created, NULL will be returned.
66687 */
66688 static struct kset *kset_create(const char *name,
66689- struct kset_uevent_ops *uevent_ops,
66690+ const struct kset_uevent_ops *uevent_ops,
66691 struct kobject *parent_kobj)
66692 {
66693 struct kset *kset;
66694@@ -832,7 +832,7 @@ static struct kset *kset_create(const ch
66695 * If the kset was not able to be created, NULL will be returned.
66696 */
66697 struct kset *kset_create_and_add(const char *name,
66698- struct kset_uevent_ops *uevent_ops,
66699+ const struct kset_uevent_ops *uevent_ops,
66700 struct kobject *parent_kobj)
66701 {
66702 struct kset *kset;
66703diff -urNp linux-2.6.32.43/lib/kobject_uevent.c linux-2.6.32.43/lib/kobject_uevent.c
66704--- linux-2.6.32.43/lib/kobject_uevent.c 2011-03-27 14:31:47.000000000 -0400
66705+++ linux-2.6.32.43/lib/kobject_uevent.c 2011-04-17 15:56:46.000000000 -0400
66706@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *k
66707 const char *subsystem;
66708 struct kobject *top_kobj;
66709 struct kset *kset;
66710- struct kset_uevent_ops *uevent_ops;
66711+ const struct kset_uevent_ops *uevent_ops;
66712 u64 seq;
66713 int i = 0;
66714 int retval = 0;
66715diff -urNp linux-2.6.32.43/lib/kref.c linux-2.6.32.43/lib/kref.c
66716--- linux-2.6.32.43/lib/kref.c 2011-03-27 14:31:47.000000000 -0400
66717+++ linux-2.6.32.43/lib/kref.c 2011-04-17 15:56:46.000000000 -0400
66718@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
66719 */
66720 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
66721 {
66722- WARN_ON(release == NULL);
66723+ BUG_ON(release == NULL);
66724 WARN_ON(release == (void (*)(struct kref *))kfree);
66725
66726 if (atomic_dec_and_test(&kref->refcount)) {
66727diff -urNp linux-2.6.32.43/lib/parser.c linux-2.6.32.43/lib/parser.c
66728--- linux-2.6.32.43/lib/parser.c 2011-03-27 14:31:47.000000000 -0400
66729+++ linux-2.6.32.43/lib/parser.c 2011-04-17 15:56:46.000000000 -0400
66730@@ -126,7 +126,7 @@ static int match_number(substring_t *s,
66731 char *buf;
66732 int ret;
66733
66734- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
66735+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
66736 if (!buf)
66737 return -ENOMEM;
66738 memcpy(buf, s->from, s->to - s->from);
66739diff -urNp linux-2.6.32.43/lib/radix-tree.c linux-2.6.32.43/lib/radix-tree.c
66740--- linux-2.6.32.43/lib/radix-tree.c 2011-03-27 14:31:47.000000000 -0400
66741+++ linux-2.6.32.43/lib/radix-tree.c 2011-04-17 15:56:46.000000000 -0400
66742@@ -81,7 +81,7 @@ struct radix_tree_preload {
66743 int nr;
66744 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
66745 };
66746-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
66747+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
66748
66749 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
66750 {
66751diff -urNp linux-2.6.32.43/lib/random32.c linux-2.6.32.43/lib/random32.c
66752--- linux-2.6.32.43/lib/random32.c 2011-03-27 14:31:47.000000000 -0400
66753+++ linux-2.6.32.43/lib/random32.c 2011-04-17 15:56:46.000000000 -0400
66754@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *
66755 */
66756 static inline u32 __seed(u32 x, u32 m)
66757 {
66758- return (x < m) ? x + m : x;
66759+ return (x <= m) ? x + m + 1 : x;
66760 }
66761
66762 /**
66763diff -urNp linux-2.6.32.43/lib/vsprintf.c linux-2.6.32.43/lib/vsprintf.c
66764--- linux-2.6.32.43/lib/vsprintf.c 2011-03-27 14:31:47.000000000 -0400
66765+++ linux-2.6.32.43/lib/vsprintf.c 2011-04-17 15:56:46.000000000 -0400
66766@@ -16,6 +16,9 @@
66767 * - scnprintf and vscnprintf
66768 */
66769
66770+#ifdef CONFIG_GRKERNSEC_HIDESYM
66771+#define __INCLUDED_BY_HIDESYM 1
66772+#endif
66773 #include <stdarg.h>
66774 #include <linux/module.h>
66775 #include <linux/types.h>
66776@@ -546,12 +549,12 @@ static char *number(char *buf, char *end
66777 return buf;
66778 }
66779
66780-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
66781+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
66782 {
66783 int len, i;
66784
66785 if ((unsigned long)s < PAGE_SIZE)
66786- s = "<NULL>";
66787+ s = "(null)";
66788
66789 len = strnlen(s, spec.precision);
66790
66791@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, ch
66792 unsigned long value = (unsigned long) ptr;
66793 #ifdef CONFIG_KALLSYMS
66794 char sym[KSYM_SYMBOL_LEN];
66795- if (ext != 'f' && ext != 's')
66796+ if (ext != 'f' && ext != 's' && ext != 'a')
66797 sprint_symbol(sym, value);
66798 else
66799 kallsyms_lookup(value, NULL, NULL, NULL, sym);
66800@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf,
66801 * - 'f' For simple symbolic function names without offset
66802 * - 'S' For symbolic direct pointers with offset
66803 * - 's' For symbolic direct pointers without offset
66804+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
66805+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
66806 * - 'R' For a struct resource pointer, it prints the range of
66807 * addresses (not the name nor the flags)
66808 * - 'M' For a 6-byte MAC address, it prints the address in the
66809@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, ch
66810 struct printf_spec spec)
66811 {
66812 if (!ptr)
66813- return string(buf, end, "(null)", spec);
66814+ return string(buf, end, "(nil)", spec);
66815
66816 switch (*fmt) {
66817 case 'F':
66818@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, ch
66819 case 's':
66820 /* Fallthrough */
66821 case 'S':
66822+#ifdef CONFIG_GRKERNSEC_HIDESYM
66823+ break;
66824+#else
66825+ return symbol_string(buf, end, ptr, spec, *fmt);
66826+#endif
66827+ case 'a':
66828+ /* Fallthrough */
66829+ case 'A':
66830 return symbol_string(buf, end, ptr, spec, *fmt);
66831 case 'R':
66832 return resource_string(buf, end, ptr, spec);
66833@@ -1445,7 +1458,7 @@ do { \
66834 size_t len;
66835 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
66836 || (unsigned long)save_str < PAGE_SIZE)
66837- save_str = "<NULL>";
66838+ save_str = "(null)";
66839 len = strlen(save_str);
66840 if (str + len + 1 < end)
66841 memcpy(str, save_str, len + 1);
66842@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size,
66843 typeof(type) value; \
66844 if (sizeof(type) == 8) { \
66845 args = PTR_ALIGN(args, sizeof(u32)); \
66846- *(u32 *)&value = *(u32 *)args; \
66847- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
66848+ *(u32 *)&value = *(const u32 *)args; \
66849+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
66850 } else { \
66851 args = PTR_ALIGN(args, sizeof(type)); \
66852- value = *(typeof(type) *)args; \
66853+ value = *(const typeof(type) *)args; \
66854 } \
66855 args += sizeof(type); \
66856 value; \
66857@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size,
66858 const char *str_arg = args;
66859 size_t len = strlen(str_arg);
66860 args += len + 1;
66861- str = string(str, end, (char *)str_arg, spec);
66862+ str = string(str, end, str_arg, spec);
66863 break;
66864 }
66865
66866diff -urNp linux-2.6.32.43/localversion-grsec linux-2.6.32.43/localversion-grsec
66867--- linux-2.6.32.43/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
66868+++ linux-2.6.32.43/localversion-grsec 2011-04-17 15:56:46.000000000 -0400
66869@@ -0,0 +1 @@
66870+-grsec
66871diff -urNp linux-2.6.32.43/Makefile linux-2.6.32.43/Makefile
66872--- linux-2.6.32.43/Makefile 2011-07-13 17:23:04.000000000 -0400
66873+++ linux-2.6.32.43/Makefile 2011-08-07 14:32:43.000000000 -0400
66874@@ -221,8 +221,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
66875
66876 HOSTCC = gcc
66877 HOSTCXX = g++
66878-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
66879-HOSTCXXFLAGS = -O2
66880+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
66881+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
66882+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
66883
66884 # Decide whether to build built-in, modular, or both.
66885 # Normally, just do built-in.
66886@@ -342,10 +343,12 @@ LINUXINCLUDE := -Iinclude \
66887 KBUILD_CPPFLAGS := -D__KERNEL__
66888
66889 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
66890+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
66891 -fno-strict-aliasing -fno-common \
66892 -Werror-implicit-function-declaration \
66893 -Wno-format-security \
66894 -fno-delete-null-pointer-checks
66895+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
66896 KBUILD_AFLAGS := -D__ASSEMBLY__
66897
66898 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
66899@@ -376,8 +379,8 @@ export RCS_TAR_IGNORE := --exclude SCCS
66900 # Rules shared between *config targets and build targets
66901
66902 # Basic helpers built in scripts/
66903-PHONY += scripts_basic
66904-scripts_basic:
66905+PHONY += scripts_basic gcc-plugins
66906+scripts_basic: gcc-plugins
66907 $(Q)$(MAKE) $(build)=scripts/basic
66908
66909 # To avoid any implicit rule to kick in, define an empty command.
66910@@ -403,7 +406,7 @@ endif
66911 # of make so .config is not included in this case either (for *config).
66912
66913 no-dot-config-targets := clean mrproper distclean \
66914- cscope TAGS tags help %docs check% \
66915+ cscope gtags TAGS tags help %docs check% \
66916 include/linux/version.h headers_% \
66917 kernelrelease kernelversion
66918
66919@@ -526,6 +529,25 @@ else
66920 KBUILD_CFLAGS += -O2
66921 endif
66922
66923+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh $(HOSTCC)), y)
66924+CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so
66925+ifdef CONFIG_PAX_MEMORY_STACKLEAK
66926+STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -fplugin-arg-stackleak_plugin-track-lowest-sp=100
66927+endif
66928+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN)
66929+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN
66930+gcc-plugins:
66931+ $(Q)$(MAKE) $(build)=tools/gcc
66932+else
66933+gcc-plugins:
66934+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
66935+ $(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.))
66936+else
66937+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
66938+endif
66939+ $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
66940+endif
66941+
66942 include $(srctree)/arch/$(SRCARCH)/Makefile
66943
66944 ifneq ($(CONFIG_FRAME_WARN),0)
66945@@ -644,7 +666,7 @@ export mod_strip_cmd
66946
66947
66948 ifeq ($(KBUILD_EXTMOD),)
66949-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
66950+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
66951
66952 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
66953 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
66954@@ -970,7 +992,7 @@ ifneq ($(KBUILD_SRC),)
66955 endif
66956
66957 # prepare2 creates a makefile if using a separate output directory
66958-prepare2: prepare3 outputmakefile
66959+prepare2: prepare3 outputmakefile gcc-plugins
66960
66961 prepare1: prepare2 include/linux/version.h include/linux/utsrelease.h \
66962 include/asm include/config/auto.conf
66963@@ -1198,7 +1220,7 @@ MRPROPER_FILES += .config .config.old in
66964 include/linux/autoconf.h include/linux/version.h \
66965 include/linux/utsrelease.h \
66966 include/linux/bounds.h include/asm*/asm-offsets.h \
66967- Module.symvers Module.markers tags TAGS cscope*
66968+ Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
66969
66970 # clean - Delete most, but leave enough to build external modules
66971 #
66972@@ -1289,6 +1311,7 @@ help:
66973 @echo ' modules_prepare - Set up for building external modules'
66974 @echo ' tags/TAGS - Generate tags file for editors'
66975 @echo ' cscope - Generate cscope index'
66976+ @echo ' gtags - Generate GNU GLOBAL index'
66977 @echo ' kernelrelease - Output the release version string'
66978 @echo ' kernelversion - Output the version stored in Makefile'
66979 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
66980@@ -1421,7 +1444,7 @@ clean: $(clean-dirs)
66981 $(call cmd,rmdirs)
66982 $(call cmd,rmfiles)
66983 @find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
66984- \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
66985+ \( -name '*.[oas]' -o -name '*.[ks]o' -o -name '.*.cmd' \
66986 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
66987 -o -name '*.gcno' \) -type f -print | xargs rm -f
66988
66989@@ -1445,7 +1468,7 @@ endif # KBUILD_EXTMOD
66990 quiet_cmd_tags = GEN $@
66991 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
66992
66993-tags TAGS cscope: FORCE
66994+tags TAGS cscope gtags: FORCE
66995 $(call cmd,tags)
66996
66997 # Scripts to check various things for consistency
66998diff -urNp linux-2.6.32.43/mm/backing-dev.c linux-2.6.32.43/mm/backing-dev.c
66999--- linux-2.6.32.43/mm/backing-dev.c 2011-03-27 14:31:47.000000000 -0400
67000+++ linux-2.6.32.43/mm/backing-dev.c 2011-05-04 17:56:28.000000000 -0400
67001@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rc
67002 * Add the default flusher task that gets created for any bdi
67003 * that has dirty data pending writeout
67004 */
67005-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
67006+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
67007 {
67008 if (!bdi_cap_writeback_dirty(bdi))
67009 return;
67010diff -urNp linux-2.6.32.43/mm/filemap.c linux-2.6.32.43/mm/filemap.c
67011--- linux-2.6.32.43/mm/filemap.c 2011-03-27 14:31:47.000000000 -0400
67012+++ linux-2.6.32.43/mm/filemap.c 2011-04-17 15:56:46.000000000 -0400
67013@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file
67014 struct address_space *mapping = file->f_mapping;
67015
67016 if (!mapping->a_ops->readpage)
67017- return -ENOEXEC;
67018+ return -ENODEV;
67019 file_accessed(file);
67020 vma->vm_ops = &generic_file_vm_ops;
67021 vma->vm_flags |= VM_CAN_NONLINEAR;
67022@@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct f
67023 *pos = i_size_read(inode);
67024
67025 if (limit != RLIM_INFINITY) {
67026+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
67027 if (*pos >= limit) {
67028 send_sig(SIGXFSZ, current, 0);
67029 return -EFBIG;
67030diff -urNp linux-2.6.32.43/mm/fremap.c linux-2.6.32.43/mm/fremap.c
67031--- linux-2.6.32.43/mm/fremap.c 2011-03-27 14:31:47.000000000 -0400
67032+++ linux-2.6.32.43/mm/fremap.c 2011-04-17 15:56:46.000000000 -0400
67033@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
67034 retry:
67035 vma = find_vma(mm, start);
67036
67037+#ifdef CONFIG_PAX_SEGMEXEC
67038+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
67039+ goto out;
67040+#endif
67041+
67042 /*
67043 * Make sure the vma is shared, that it supports prefaulting,
67044 * and that the remapped range is valid and fully within
67045@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
67046 /*
67047 * drop PG_Mlocked flag for over-mapped range
67048 */
67049- unsigned int saved_flags = vma->vm_flags;
67050+ unsigned long saved_flags = vma->vm_flags;
67051 munlock_vma_pages_range(vma, start, start + size);
67052 vma->vm_flags = saved_flags;
67053 }
67054diff -urNp linux-2.6.32.43/mm/highmem.c linux-2.6.32.43/mm/highmem.c
67055--- linux-2.6.32.43/mm/highmem.c 2011-03-27 14:31:47.000000000 -0400
67056+++ linux-2.6.32.43/mm/highmem.c 2011-04-17 15:56:46.000000000 -0400
67057@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
67058 * So no dangers, even with speculative execution.
67059 */
67060 page = pte_page(pkmap_page_table[i]);
67061+ pax_open_kernel();
67062 pte_clear(&init_mm, (unsigned long)page_address(page),
67063 &pkmap_page_table[i]);
67064-
67065+ pax_close_kernel();
67066 set_page_address(page, NULL);
67067 need_flush = 1;
67068 }
67069@@ -177,9 +178,11 @@ start:
67070 }
67071 }
67072 vaddr = PKMAP_ADDR(last_pkmap_nr);
67073+
67074+ pax_open_kernel();
67075 set_pte_at(&init_mm, vaddr,
67076 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
67077-
67078+ pax_close_kernel();
67079 pkmap_count[last_pkmap_nr] = 1;
67080 set_page_address(page, (void *)vaddr);
67081
67082diff -urNp linux-2.6.32.43/mm/hugetlb.c linux-2.6.32.43/mm/hugetlb.c
67083--- linux-2.6.32.43/mm/hugetlb.c 2011-07-13 17:23:04.000000000 -0400
67084+++ linux-2.6.32.43/mm/hugetlb.c 2011-07-13 17:23:19.000000000 -0400
67085@@ -1933,6 +1933,26 @@ static int unmap_ref_private(struct mm_s
67086 return 1;
67087 }
67088
67089+#ifdef CONFIG_PAX_SEGMEXEC
67090+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
67091+{
67092+ struct mm_struct *mm = vma->vm_mm;
67093+ struct vm_area_struct *vma_m;
67094+ unsigned long address_m;
67095+ pte_t *ptep_m;
67096+
67097+ vma_m = pax_find_mirror_vma(vma);
67098+ if (!vma_m)
67099+ return;
67100+
67101+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67102+ address_m = address + SEGMEXEC_TASK_SIZE;
67103+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
67104+ get_page(page_m);
67105+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
67106+}
67107+#endif
67108+
67109 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
67110 unsigned long address, pte_t *ptep, pte_t pte,
67111 struct page *pagecache_page)
67112@@ -2004,6 +2024,11 @@ retry_avoidcopy:
67113 huge_ptep_clear_flush(vma, address, ptep);
67114 set_huge_pte_at(mm, address, ptep,
67115 make_huge_pte(vma, new_page, 1));
67116+
67117+#ifdef CONFIG_PAX_SEGMEXEC
67118+ pax_mirror_huge_pte(vma, address, new_page);
67119+#endif
67120+
67121 /* Make the old page be freed below */
67122 new_page = old_page;
67123 }
67124@@ -2135,6 +2160,10 @@ retry:
67125 && (vma->vm_flags & VM_SHARED)));
67126 set_huge_pte_at(mm, address, ptep, new_pte);
67127
67128+#ifdef CONFIG_PAX_SEGMEXEC
67129+ pax_mirror_huge_pte(vma, address, page);
67130+#endif
67131+
67132 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
67133 /* Optimization, do the COW without a second fault */
67134 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
67135@@ -2163,6 +2192,28 @@ int hugetlb_fault(struct mm_struct *mm,
67136 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
67137 struct hstate *h = hstate_vma(vma);
67138
67139+#ifdef CONFIG_PAX_SEGMEXEC
67140+ struct vm_area_struct *vma_m;
67141+
67142+ vma_m = pax_find_mirror_vma(vma);
67143+ if (vma_m) {
67144+ unsigned long address_m;
67145+
67146+ if (vma->vm_start > vma_m->vm_start) {
67147+ address_m = address;
67148+ address -= SEGMEXEC_TASK_SIZE;
67149+ vma = vma_m;
67150+ h = hstate_vma(vma);
67151+ } else
67152+ address_m = address + SEGMEXEC_TASK_SIZE;
67153+
67154+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
67155+ return VM_FAULT_OOM;
67156+ address_m &= HPAGE_MASK;
67157+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
67158+ }
67159+#endif
67160+
67161 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
67162 if (!ptep)
67163 return VM_FAULT_OOM;
67164diff -urNp linux-2.6.32.43/mm/internal.h linux-2.6.32.43/mm/internal.h
67165--- linux-2.6.32.43/mm/internal.h 2011-03-27 14:31:47.000000000 -0400
67166+++ linux-2.6.32.43/mm/internal.h 2011-07-09 09:13:08.000000000 -0400
67167@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page
67168 * in mm/page_alloc.c
67169 */
67170 extern void __free_pages_bootmem(struct page *page, unsigned int order);
67171+extern void free_compound_page(struct page *page);
67172 extern void prep_compound_page(struct page *page, unsigned long order);
67173
67174
67175diff -urNp linux-2.6.32.43/mm/Kconfig linux-2.6.32.43/mm/Kconfig
67176--- linux-2.6.32.43/mm/Kconfig 2011-03-27 14:31:47.000000000 -0400
67177+++ linux-2.6.32.43/mm/Kconfig 2011-04-17 15:56:46.000000000 -0400
67178@@ -228,7 +228,7 @@ config KSM
67179 config DEFAULT_MMAP_MIN_ADDR
67180 int "Low address space to protect from user allocation"
67181 depends on MMU
67182- default 4096
67183+ default 65536
67184 help
67185 This is the portion of low virtual memory which should be protected
67186 from userspace allocation. Keeping a user from writing to low pages
67187diff -urNp linux-2.6.32.43/mm/kmemleak.c linux-2.6.32.43/mm/kmemleak.c
67188--- linux-2.6.32.43/mm/kmemleak.c 2011-06-25 12:55:35.000000000 -0400
67189+++ linux-2.6.32.43/mm/kmemleak.c 2011-06-25 12:56:37.000000000 -0400
67190@@ -358,7 +358,7 @@ static void print_unreferenced(struct se
67191
67192 for (i = 0; i < object->trace_len; i++) {
67193 void *ptr = (void *)object->trace[i];
67194- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
67195+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
67196 }
67197 }
67198
67199diff -urNp linux-2.6.32.43/mm/maccess.c linux-2.6.32.43/mm/maccess.c
67200--- linux-2.6.32.43/mm/maccess.c 2011-03-27 14:31:47.000000000 -0400
67201+++ linux-2.6.32.43/mm/maccess.c 2011-04-17 15:56:46.000000000 -0400
67202@@ -14,7 +14,7 @@
67203 * Safely read from address @src to the buffer at @dst. If a kernel fault
67204 * happens, handle that and return -EFAULT.
67205 */
67206-long probe_kernel_read(void *dst, void *src, size_t size)
67207+long probe_kernel_read(void *dst, const void *src, size_t size)
67208 {
67209 long ret;
67210 mm_segment_t old_fs = get_fs();
67211@@ -39,7 +39,7 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
67212 * Safely write to address @dst from the buffer at @src. If a kernel fault
67213 * happens, handle that and return -EFAULT.
67214 */
67215-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
67216+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
67217 {
67218 long ret;
67219 mm_segment_t old_fs = get_fs();
67220diff -urNp linux-2.6.32.43/mm/madvise.c linux-2.6.32.43/mm/madvise.c
67221--- linux-2.6.32.43/mm/madvise.c 2011-03-27 14:31:47.000000000 -0400
67222+++ linux-2.6.32.43/mm/madvise.c 2011-04-17 15:56:46.000000000 -0400
67223@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_a
67224 pgoff_t pgoff;
67225 unsigned long new_flags = vma->vm_flags;
67226
67227+#ifdef CONFIG_PAX_SEGMEXEC
67228+ struct vm_area_struct *vma_m;
67229+#endif
67230+
67231 switch (behavior) {
67232 case MADV_NORMAL:
67233 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
67234@@ -103,6 +107,13 @@ success:
67235 /*
67236 * vm_flags is protected by the mmap_sem held in write mode.
67237 */
67238+
67239+#ifdef CONFIG_PAX_SEGMEXEC
67240+ vma_m = pax_find_mirror_vma(vma);
67241+ if (vma_m)
67242+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
67243+#endif
67244+
67245 vma->vm_flags = new_flags;
67246
67247 out:
67248@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_a
67249 struct vm_area_struct ** prev,
67250 unsigned long start, unsigned long end)
67251 {
67252+
67253+#ifdef CONFIG_PAX_SEGMEXEC
67254+ struct vm_area_struct *vma_m;
67255+#endif
67256+
67257 *prev = vma;
67258 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
67259 return -EINVAL;
67260@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_a
67261 zap_page_range(vma, start, end - start, &details);
67262 } else
67263 zap_page_range(vma, start, end - start, NULL);
67264+
67265+#ifdef CONFIG_PAX_SEGMEXEC
67266+ vma_m = pax_find_mirror_vma(vma);
67267+ if (vma_m) {
67268+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
67269+ struct zap_details details = {
67270+ .nonlinear_vma = vma_m,
67271+ .last_index = ULONG_MAX,
67272+ };
67273+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
67274+ } else
67275+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
67276+ }
67277+#endif
67278+
67279 return 0;
67280 }
67281
67282@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
67283 if (end < start)
67284 goto out;
67285
67286+#ifdef CONFIG_PAX_SEGMEXEC
67287+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
67288+ if (end > SEGMEXEC_TASK_SIZE)
67289+ goto out;
67290+ } else
67291+#endif
67292+
67293+ if (end > TASK_SIZE)
67294+ goto out;
67295+
67296 error = 0;
67297 if (end == start)
67298 goto out;
67299diff -urNp linux-2.6.32.43/mm/memory.c linux-2.6.32.43/mm/memory.c
67300--- linux-2.6.32.43/mm/memory.c 2011-07-13 17:23:04.000000000 -0400
67301+++ linux-2.6.32.43/mm/memory.c 2011-07-13 17:23:23.000000000 -0400
67302@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct
67303 return;
67304
67305 pmd = pmd_offset(pud, start);
67306+
67307+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
67308 pud_clear(pud);
67309 pmd_free_tlb(tlb, pmd, start);
67310+#endif
67311+
67312 }
67313
67314 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
67315@@ -219,9 +223,12 @@ static inline void free_pud_range(struct
67316 if (end - 1 > ceiling - 1)
67317 return;
67318
67319+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
67320 pud = pud_offset(pgd, start);
67321 pgd_clear(pgd);
67322 pud_free_tlb(tlb, pud, start);
67323+#endif
67324+
67325 }
67326
67327 /*
67328@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct
67329 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
67330 i = 0;
67331
67332- do {
67333+ while (nr_pages) {
67334 struct vm_area_struct *vma;
67335
67336- vma = find_extend_vma(mm, start);
67337+ vma = find_vma(mm, start);
67338 if (!vma && in_gate_area(tsk, start)) {
67339 unsigned long pg = start & PAGE_MASK;
67340 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
67341@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct
67342 continue;
67343 }
67344
67345- if (!vma ||
67346+ if (!vma || start < vma->vm_start ||
67347 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
67348 !(vm_flags & vma->vm_flags))
67349 return i ? : -EFAULT;
67350@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct
67351 start += PAGE_SIZE;
67352 nr_pages--;
67353 } while (nr_pages && start < vma->vm_end);
67354- } while (nr_pages);
67355+ }
67356 return i;
67357 }
67358
67359@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_st
67360 page_add_file_rmap(page);
67361 set_pte_at(mm, addr, pte, mk_pte(page, prot));
67362
67363+#ifdef CONFIG_PAX_SEGMEXEC
67364+ pax_mirror_file_pte(vma, addr, page, ptl);
67365+#endif
67366+
67367 retval = 0;
67368 pte_unmap_unlock(pte, ptl);
67369 return retval;
67370@@ -1560,10 +1571,22 @@ out:
67371 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
67372 struct page *page)
67373 {
67374+
67375+#ifdef CONFIG_PAX_SEGMEXEC
67376+ struct vm_area_struct *vma_m;
67377+#endif
67378+
67379 if (addr < vma->vm_start || addr >= vma->vm_end)
67380 return -EFAULT;
67381 if (!page_count(page))
67382 return -EINVAL;
67383+
67384+#ifdef CONFIG_PAX_SEGMEXEC
67385+ vma_m = pax_find_mirror_vma(vma);
67386+ if (vma_m)
67387+ vma_m->vm_flags |= VM_INSERTPAGE;
67388+#endif
67389+
67390 vma->vm_flags |= VM_INSERTPAGE;
67391 return insert_page(vma, addr, page, vma->vm_page_prot);
67392 }
67393@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struc
67394 unsigned long pfn)
67395 {
67396 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
67397+ BUG_ON(vma->vm_mirror);
67398
67399 if (addr < vma->vm_start || addr >= vma->vm_end)
67400 return -EFAULT;
67401@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct
67402 copy_user_highpage(dst, src, va, vma);
67403 }
67404
67405+#ifdef CONFIG_PAX_SEGMEXEC
67406+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
67407+{
67408+ struct mm_struct *mm = vma->vm_mm;
67409+ spinlock_t *ptl;
67410+ pte_t *pte, entry;
67411+
67412+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
67413+ entry = *pte;
67414+ if (!pte_present(entry)) {
67415+ if (!pte_none(entry)) {
67416+ BUG_ON(pte_file(entry));
67417+ free_swap_and_cache(pte_to_swp_entry(entry));
67418+ pte_clear_not_present_full(mm, address, pte, 0);
67419+ }
67420+ } else {
67421+ struct page *page;
67422+
67423+ flush_cache_page(vma, address, pte_pfn(entry));
67424+ entry = ptep_clear_flush(vma, address, pte);
67425+ BUG_ON(pte_dirty(entry));
67426+ page = vm_normal_page(vma, address, entry);
67427+ if (page) {
67428+ update_hiwater_rss(mm);
67429+ if (PageAnon(page))
67430+ dec_mm_counter(mm, anon_rss);
67431+ else
67432+ dec_mm_counter(mm, file_rss);
67433+ page_remove_rmap(page);
67434+ page_cache_release(page);
67435+ }
67436+ }
67437+ pte_unmap_unlock(pte, ptl);
67438+}
67439+
67440+/* PaX: if vma is mirrored, synchronize the mirror's PTE
67441+ *
67442+ * the ptl of the lower mapped page is held on entry and is not released on exit
67443+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
67444+ */
67445+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
67446+{
67447+ struct mm_struct *mm = vma->vm_mm;
67448+ unsigned long address_m;
67449+ spinlock_t *ptl_m;
67450+ struct vm_area_struct *vma_m;
67451+ pmd_t *pmd_m;
67452+ pte_t *pte_m, entry_m;
67453+
67454+ BUG_ON(!page_m || !PageAnon(page_m));
67455+
67456+ vma_m = pax_find_mirror_vma(vma);
67457+ if (!vma_m)
67458+ return;
67459+
67460+ BUG_ON(!PageLocked(page_m));
67461+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67462+ address_m = address + SEGMEXEC_TASK_SIZE;
67463+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
67464+ pte_m = pte_offset_map_nested(pmd_m, address_m);
67465+ ptl_m = pte_lockptr(mm, pmd_m);
67466+ if (ptl != ptl_m) {
67467+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
67468+ if (!pte_none(*pte_m))
67469+ goto out;
67470+ }
67471+
67472+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
67473+ page_cache_get(page_m);
67474+ page_add_anon_rmap(page_m, vma_m, address_m);
67475+ inc_mm_counter(mm, anon_rss);
67476+ set_pte_at(mm, address_m, pte_m, entry_m);
67477+ update_mmu_cache(vma_m, address_m, entry_m);
67478+out:
67479+ if (ptl != ptl_m)
67480+ spin_unlock(ptl_m);
67481+ pte_unmap_nested(pte_m);
67482+ unlock_page(page_m);
67483+}
67484+
67485+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
67486+{
67487+ struct mm_struct *mm = vma->vm_mm;
67488+ unsigned long address_m;
67489+ spinlock_t *ptl_m;
67490+ struct vm_area_struct *vma_m;
67491+ pmd_t *pmd_m;
67492+ pte_t *pte_m, entry_m;
67493+
67494+ BUG_ON(!page_m || PageAnon(page_m));
67495+
67496+ vma_m = pax_find_mirror_vma(vma);
67497+ if (!vma_m)
67498+ return;
67499+
67500+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67501+ address_m = address + SEGMEXEC_TASK_SIZE;
67502+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
67503+ pte_m = pte_offset_map_nested(pmd_m, address_m);
67504+ ptl_m = pte_lockptr(mm, pmd_m);
67505+ if (ptl != ptl_m) {
67506+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
67507+ if (!pte_none(*pte_m))
67508+ goto out;
67509+ }
67510+
67511+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
67512+ page_cache_get(page_m);
67513+ page_add_file_rmap(page_m);
67514+ inc_mm_counter(mm, file_rss);
67515+ set_pte_at(mm, address_m, pte_m, entry_m);
67516+ update_mmu_cache(vma_m, address_m, entry_m);
67517+out:
67518+ if (ptl != ptl_m)
67519+ spin_unlock(ptl_m);
67520+ pte_unmap_nested(pte_m);
67521+}
67522+
67523+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
67524+{
67525+ struct mm_struct *mm = vma->vm_mm;
67526+ unsigned long address_m;
67527+ spinlock_t *ptl_m;
67528+ struct vm_area_struct *vma_m;
67529+ pmd_t *pmd_m;
67530+ pte_t *pte_m, entry_m;
67531+
67532+ vma_m = pax_find_mirror_vma(vma);
67533+ if (!vma_m)
67534+ return;
67535+
67536+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67537+ address_m = address + SEGMEXEC_TASK_SIZE;
67538+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
67539+ pte_m = pte_offset_map_nested(pmd_m, address_m);
67540+ ptl_m = pte_lockptr(mm, pmd_m);
67541+ if (ptl != ptl_m) {
67542+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
67543+ if (!pte_none(*pte_m))
67544+ goto out;
67545+ }
67546+
67547+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
67548+ set_pte_at(mm, address_m, pte_m, entry_m);
67549+out:
67550+ if (ptl != ptl_m)
67551+ spin_unlock(ptl_m);
67552+ pte_unmap_nested(pte_m);
67553+}
67554+
67555+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
67556+{
67557+ struct page *page_m;
67558+ pte_t entry;
67559+
67560+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
67561+ goto out;
67562+
67563+ entry = *pte;
67564+ page_m = vm_normal_page(vma, address, entry);
67565+ if (!page_m)
67566+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
67567+ else if (PageAnon(page_m)) {
67568+ if (pax_find_mirror_vma(vma)) {
67569+ pte_unmap_unlock(pte, ptl);
67570+ lock_page(page_m);
67571+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
67572+ if (pte_same(entry, *pte))
67573+ pax_mirror_anon_pte(vma, address, page_m, ptl);
67574+ else
67575+ unlock_page(page_m);
67576+ }
67577+ } else
67578+ pax_mirror_file_pte(vma, address, page_m, ptl);
67579+
67580+out:
67581+ pte_unmap_unlock(pte, ptl);
67582+}
67583+#endif
67584+
67585 /*
67586 * This routine handles present pages, when users try to write
67587 * to a shared page. It is done by copying the page to a new address
67588@@ -2156,6 +2360,12 @@ gotten:
67589 */
67590 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
67591 if (likely(pte_same(*page_table, orig_pte))) {
67592+
67593+#ifdef CONFIG_PAX_SEGMEXEC
67594+ if (pax_find_mirror_vma(vma))
67595+ BUG_ON(!trylock_page(new_page));
67596+#endif
67597+
67598 if (old_page) {
67599 if (!PageAnon(old_page)) {
67600 dec_mm_counter(mm, file_rss);
67601@@ -2207,6 +2417,10 @@ gotten:
67602 page_remove_rmap(old_page);
67603 }
67604
67605+#ifdef CONFIG_PAX_SEGMEXEC
67606+ pax_mirror_anon_pte(vma, address, new_page, ptl);
67607+#endif
67608+
67609 /* Free the old page.. */
67610 new_page = old_page;
67611 ret |= VM_FAULT_WRITE;
67612@@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct
67613 swap_free(entry);
67614 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
67615 try_to_free_swap(page);
67616+
67617+#ifdef CONFIG_PAX_SEGMEXEC
67618+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
67619+#endif
67620+
67621 unlock_page(page);
67622
67623 if (flags & FAULT_FLAG_WRITE) {
67624@@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct
67625
67626 /* No need to invalidate - it was non-present before */
67627 update_mmu_cache(vma, address, pte);
67628+
67629+#ifdef CONFIG_PAX_SEGMEXEC
67630+ pax_mirror_anon_pte(vma, address, page, ptl);
67631+#endif
67632+
67633 unlock:
67634 pte_unmap_unlock(page_table, ptl);
67635 out:
67636@@ -2632,40 +2856,6 @@ out_release:
67637 }
67638
67639 /*
67640- * This is like a special single-page "expand_{down|up}wards()",
67641- * except we must first make sure that 'address{-|+}PAGE_SIZE'
67642- * doesn't hit another vma.
67643- */
67644-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
67645-{
67646- address &= PAGE_MASK;
67647- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
67648- struct vm_area_struct *prev = vma->vm_prev;
67649-
67650- /*
67651- * Is there a mapping abutting this one below?
67652- *
67653- * That's only ok if it's the same stack mapping
67654- * that has gotten split..
67655- */
67656- if (prev && prev->vm_end == address)
67657- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
67658-
67659- expand_stack(vma, address - PAGE_SIZE);
67660- }
67661- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
67662- struct vm_area_struct *next = vma->vm_next;
67663-
67664- /* As VM_GROWSDOWN but s/below/above/ */
67665- if (next && next->vm_start == address + PAGE_SIZE)
67666- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
67667-
67668- expand_upwards(vma, address + PAGE_SIZE);
67669- }
67670- return 0;
67671-}
67672-
67673-/*
67674 * We enter with non-exclusive mmap_sem (to exclude vma changes,
67675 * but allow concurrent faults), and pte mapped but not yet locked.
67676 * We return with mmap_sem still held, but pte unmapped and unlocked.
67677@@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_s
67678 unsigned long address, pte_t *page_table, pmd_t *pmd,
67679 unsigned int flags)
67680 {
67681- struct page *page;
67682+ struct page *page = NULL;
67683 spinlock_t *ptl;
67684 pte_t entry;
67685
67686- pte_unmap(page_table);
67687-
67688- /* Check if we need to add a guard page to the stack */
67689- if (check_stack_guard_page(vma, address) < 0)
67690- return VM_FAULT_SIGBUS;
67691-
67692- /* Use the zero-page for reads */
67693 if (!(flags & FAULT_FLAG_WRITE)) {
67694 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
67695 vma->vm_page_prot));
67696- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
67697+ ptl = pte_lockptr(mm, pmd);
67698+ spin_lock(ptl);
67699 if (!pte_none(*page_table))
67700 goto unlock;
67701 goto setpte;
67702 }
67703
67704 /* Allocate our own private page. */
67705+ pte_unmap(page_table);
67706+
67707 if (unlikely(anon_vma_prepare(vma)))
67708 goto oom;
67709 page = alloc_zeroed_user_highpage_movable(vma, address);
67710@@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_s
67711 if (!pte_none(*page_table))
67712 goto release;
67713
67714+#ifdef CONFIG_PAX_SEGMEXEC
67715+ if (pax_find_mirror_vma(vma))
67716+ BUG_ON(!trylock_page(page));
67717+#endif
67718+
67719 inc_mm_counter(mm, anon_rss);
67720 page_add_new_anon_rmap(page, vma, address);
67721 setpte:
67722@@ -2720,6 +2911,12 @@ setpte:
67723
67724 /* No need to invalidate - it was non-present before */
67725 update_mmu_cache(vma, address, entry);
67726+
67727+#ifdef CONFIG_PAX_SEGMEXEC
67728+ if (page)
67729+ pax_mirror_anon_pte(vma, address, page, ptl);
67730+#endif
67731+
67732 unlock:
67733 pte_unmap_unlock(page_table, ptl);
67734 return 0;
67735@@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *
67736 */
67737 /* Only go through if we didn't race with anybody else... */
67738 if (likely(pte_same(*page_table, orig_pte))) {
67739+
67740+#ifdef CONFIG_PAX_SEGMEXEC
67741+ if (anon && pax_find_mirror_vma(vma))
67742+ BUG_ON(!trylock_page(page));
67743+#endif
67744+
67745 flush_icache_page(vma, page);
67746 entry = mk_pte(page, vma->vm_page_prot);
67747 if (flags & FAULT_FLAG_WRITE)
67748@@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *
67749
67750 /* no need to invalidate: a not-present page won't be cached */
67751 update_mmu_cache(vma, address, entry);
67752+
67753+#ifdef CONFIG_PAX_SEGMEXEC
67754+ if (anon)
67755+ pax_mirror_anon_pte(vma, address, page, ptl);
67756+ else
67757+ pax_mirror_file_pte(vma, address, page, ptl);
67758+#endif
67759+
67760 } else {
67761 if (charged)
67762 mem_cgroup_uncharge_page(page);
67763@@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struc
67764 if (flags & FAULT_FLAG_WRITE)
67765 flush_tlb_page(vma, address);
67766 }
67767+
67768+#ifdef CONFIG_PAX_SEGMEXEC
67769+ pax_mirror_pte(vma, address, pte, pmd, ptl);
67770+ return 0;
67771+#endif
67772+
67773 unlock:
67774 pte_unmap_unlock(pte, ptl);
67775 return 0;
67776@@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm
67777 pmd_t *pmd;
67778 pte_t *pte;
67779
67780+#ifdef CONFIG_PAX_SEGMEXEC
67781+ struct vm_area_struct *vma_m;
67782+#endif
67783+
67784 __set_current_state(TASK_RUNNING);
67785
67786 count_vm_event(PGFAULT);
67787@@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm
67788 if (unlikely(is_vm_hugetlb_page(vma)))
67789 return hugetlb_fault(mm, vma, address, flags);
67790
67791+#ifdef CONFIG_PAX_SEGMEXEC
67792+ vma_m = pax_find_mirror_vma(vma);
67793+ if (vma_m) {
67794+ unsigned long address_m;
67795+ pgd_t *pgd_m;
67796+ pud_t *pud_m;
67797+ pmd_t *pmd_m;
67798+
67799+ if (vma->vm_start > vma_m->vm_start) {
67800+ address_m = address;
67801+ address -= SEGMEXEC_TASK_SIZE;
67802+ vma = vma_m;
67803+ } else
67804+ address_m = address + SEGMEXEC_TASK_SIZE;
67805+
67806+ pgd_m = pgd_offset(mm, address_m);
67807+ pud_m = pud_alloc(mm, pgd_m, address_m);
67808+ if (!pud_m)
67809+ return VM_FAULT_OOM;
67810+ pmd_m = pmd_alloc(mm, pud_m, address_m);
67811+ if (!pmd_m)
67812+ return VM_FAULT_OOM;
67813+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
67814+ return VM_FAULT_OOM;
67815+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
67816+ }
67817+#endif
67818+
67819 pgd = pgd_offset(mm, address);
67820 pud = pud_alloc(mm, pgd, address);
67821 if (!pud)
67822@@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
67823 gate_vma.vm_start = FIXADDR_USER_START;
67824 gate_vma.vm_end = FIXADDR_USER_END;
67825 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
67826- gate_vma.vm_page_prot = __P101;
67827+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
67828 /*
67829 * Make sure the vDSO gets into every core dump.
67830 * Dumping its contents makes post-mortem fully interpretable later
67831diff -urNp linux-2.6.32.43/mm/memory-failure.c linux-2.6.32.43/mm/memory-failure.c
67832--- linux-2.6.32.43/mm/memory-failure.c 2011-03-27 14:31:47.000000000 -0400
67833+++ linux-2.6.32.43/mm/memory-failure.c 2011-04-17 15:56:46.000000000 -0400
67834@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __r
67835
67836 int sysctl_memory_failure_recovery __read_mostly = 1;
67837
67838-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
67839+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
67840
67841 /*
67842 * Send all the processes who have the page mapped an ``action optional''
67843@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn,
67844 return 0;
67845 }
67846
67847- atomic_long_add(1, &mce_bad_pages);
67848+ atomic_long_add_unchecked(1, &mce_bad_pages);
67849
67850 /*
67851 * We need/can do nothing about count=0 pages.
67852diff -urNp linux-2.6.32.43/mm/mempolicy.c linux-2.6.32.43/mm/mempolicy.c
67853--- linux-2.6.32.43/mm/mempolicy.c 2011-03-27 14:31:47.000000000 -0400
67854+++ linux-2.6.32.43/mm/mempolicy.c 2011-04-17 15:56:46.000000000 -0400
67855@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_st
67856 struct vm_area_struct *next;
67857 int err;
67858
67859+#ifdef CONFIG_PAX_SEGMEXEC
67860+ struct vm_area_struct *vma_m;
67861+#endif
67862+
67863 err = 0;
67864 for (; vma && vma->vm_start < end; vma = next) {
67865 next = vma->vm_next;
67866@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_st
67867 err = policy_vma(vma, new);
67868 if (err)
67869 break;
67870+
67871+#ifdef CONFIG_PAX_SEGMEXEC
67872+ vma_m = pax_find_mirror_vma(vma);
67873+ if (vma_m) {
67874+ err = policy_vma(vma_m, new);
67875+ if (err)
67876+ break;
67877+ }
67878+#endif
67879+
67880 }
67881 return err;
67882 }
67883@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start
67884
67885 if (end < start)
67886 return -EINVAL;
67887+
67888+#ifdef CONFIG_PAX_SEGMEXEC
67889+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
67890+ if (end > SEGMEXEC_TASK_SIZE)
67891+ return -EINVAL;
67892+ } else
67893+#endif
67894+
67895+ if (end > TASK_SIZE)
67896+ return -EINVAL;
67897+
67898 if (end == start)
67899 return 0;
67900
67901@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
67902 if (!mm)
67903 return -EINVAL;
67904
67905+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67906+ if (mm != current->mm &&
67907+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
67908+ err = -EPERM;
67909+ goto out;
67910+ }
67911+#endif
67912+
67913 /*
67914 * Check if this process has the right to modify the specified
67915 * process. The right exists if the process has administrative
67916@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
67917 rcu_read_lock();
67918 tcred = __task_cred(task);
67919 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
67920- cred->uid != tcred->suid && cred->uid != tcred->uid &&
67921- !capable(CAP_SYS_NICE)) {
67922+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
67923 rcu_read_unlock();
67924 err = -EPERM;
67925 goto out;
67926@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, vo
67927
67928 if (file) {
67929 seq_printf(m, " file=");
67930- seq_path(m, &file->f_path, "\n\t= ");
67931+ seq_path(m, &file->f_path, "\n\t\\= ");
67932 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67933 seq_printf(m, " heap");
67934 } else if (vma->vm_start <= mm->start_stack &&
67935diff -urNp linux-2.6.32.43/mm/migrate.c linux-2.6.32.43/mm/migrate.c
67936--- linux-2.6.32.43/mm/migrate.c 2011-07-13 17:23:04.000000000 -0400
67937+++ linux-2.6.32.43/mm/migrate.c 2011-07-13 17:23:23.000000000 -0400
67938@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struc
67939 unsigned long chunk_start;
67940 int err;
67941
67942+ pax_track_stack();
67943+
67944 task_nodes = cpuset_mems_allowed(task);
67945
67946 err = -ENOMEM;
67947@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
67948 if (!mm)
67949 return -EINVAL;
67950
67951+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67952+ if (mm != current->mm &&
67953+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
67954+ err = -EPERM;
67955+ goto out;
67956+ }
67957+#endif
67958+
67959 /*
67960 * Check if this process has the right to modify the specified
67961 * process. The right exists if the process has administrative
67962@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
67963 rcu_read_lock();
67964 tcred = __task_cred(task);
67965 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
67966- cred->uid != tcred->suid && cred->uid != tcred->uid &&
67967- !capable(CAP_SYS_NICE)) {
67968+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
67969 rcu_read_unlock();
67970 err = -EPERM;
67971 goto out;
67972diff -urNp linux-2.6.32.43/mm/mlock.c linux-2.6.32.43/mm/mlock.c
67973--- linux-2.6.32.43/mm/mlock.c 2011-03-27 14:31:47.000000000 -0400
67974+++ linux-2.6.32.43/mm/mlock.c 2011-04-17 15:56:46.000000000 -0400
67975@@ -13,6 +13,7 @@
67976 #include <linux/pagemap.h>
67977 #include <linux/mempolicy.h>
67978 #include <linux/syscalls.h>
67979+#include <linux/security.h>
67980 #include <linux/sched.h>
67981 #include <linux/module.h>
67982 #include <linux/rmap.h>
67983@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
67984 }
67985 }
67986
67987-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
67988-{
67989- return (vma->vm_flags & VM_GROWSDOWN) &&
67990- (vma->vm_start == addr) &&
67991- !vma_stack_continue(vma->vm_prev, addr);
67992-}
67993-
67994 /**
67995 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
67996 * @vma: target vma
67997@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(stru
67998 if (vma->vm_flags & VM_WRITE)
67999 gup_flags |= FOLL_WRITE;
68000
68001- /* We don't try to access the guard page of a stack vma */
68002- if (stack_guard_page(vma, start)) {
68003- addr += PAGE_SIZE;
68004- nr_pages--;
68005- }
68006-
68007 while (nr_pages > 0) {
68008 int i;
68009
68010@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start,
68011 {
68012 unsigned long nstart, end, tmp;
68013 struct vm_area_struct * vma, * prev;
68014- int error;
68015+ int error = -EINVAL;
68016
68017 len = PAGE_ALIGN(len);
68018 end = start + len;
68019@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start,
68020 return -EINVAL;
68021 if (end == start)
68022 return 0;
68023+ if (end > TASK_SIZE)
68024+ return -EINVAL;
68025+
68026 vma = find_vma_prev(current->mm, start, &prev);
68027 if (!vma || vma->vm_start > start)
68028 return -ENOMEM;
68029@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start,
68030 for (nstart = start ; ; ) {
68031 unsigned int newflags;
68032
68033+#ifdef CONFIG_PAX_SEGMEXEC
68034+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68035+ break;
68036+#endif
68037+
68038 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
68039
68040 newflags = vma->vm_flags | VM_LOCKED;
68041@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
68042 lock_limit >>= PAGE_SHIFT;
68043
68044 /* check against resource limits */
68045+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
68046 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
68047 error = do_mlock(start, len, 1);
68048 up_write(&current->mm->mmap_sem);
68049@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
68050 static int do_mlockall(int flags)
68051 {
68052 struct vm_area_struct * vma, * prev = NULL;
68053- unsigned int def_flags = 0;
68054
68055 if (flags & MCL_FUTURE)
68056- def_flags = VM_LOCKED;
68057- current->mm->def_flags = def_flags;
68058+ current->mm->def_flags |= VM_LOCKED;
68059+ else
68060+ current->mm->def_flags &= ~VM_LOCKED;
68061 if (flags == MCL_FUTURE)
68062 goto out;
68063
68064 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
68065- unsigned int newflags;
68066+ unsigned long newflags;
68067+
68068+#ifdef CONFIG_PAX_SEGMEXEC
68069+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68070+ break;
68071+#endif
68072
68073+ BUG_ON(vma->vm_end > TASK_SIZE);
68074 newflags = vma->vm_flags | VM_LOCKED;
68075 if (!(flags & MCL_CURRENT))
68076 newflags &= ~VM_LOCKED;
68077@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
68078 lock_limit >>= PAGE_SHIFT;
68079
68080 ret = -ENOMEM;
68081+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
68082 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
68083 capable(CAP_IPC_LOCK))
68084 ret = do_mlockall(flags);
68085diff -urNp linux-2.6.32.43/mm/mmap.c linux-2.6.32.43/mm/mmap.c
68086--- linux-2.6.32.43/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
68087+++ linux-2.6.32.43/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
68088@@ -45,6 +45,16 @@
68089 #define arch_rebalance_pgtables(addr, len) (addr)
68090 #endif
68091
68092+static inline void verify_mm_writelocked(struct mm_struct *mm)
68093+{
68094+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
68095+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
68096+ up_read(&mm->mmap_sem);
68097+ BUG();
68098+ }
68099+#endif
68100+}
68101+
68102 static void unmap_region(struct mm_struct *mm,
68103 struct vm_area_struct *vma, struct vm_area_struct *prev,
68104 unsigned long start, unsigned long end);
68105@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struc
68106 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
68107 *
68108 */
68109-pgprot_t protection_map[16] = {
68110+pgprot_t protection_map[16] __read_only = {
68111 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
68112 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
68113 };
68114
68115 pgprot_t vm_get_page_prot(unsigned long vm_flags)
68116 {
68117- return __pgprot(pgprot_val(protection_map[vm_flags &
68118+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
68119 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
68120 pgprot_val(arch_vm_get_page_prot(vm_flags)));
68121+
68122+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68123+ if (!nx_enabled &&
68124+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
68125+ (vm_flags & (VM_READ | VM_WRITE)))
68126+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
68127+#endif
68128+
68129+ return prot;
68130 }
68131 EXPORT_SYMBOL(vm_get_page_prot);
68132
68133 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
68134 int sysctl_overcommit_ratio = 50; /* default is 50% */
68135 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
68136+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
68137 struct percpu_counter vm_committed_as;
68138
68139 /*
68140@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma
68141 struct vm_area_struct *next = vma->vm_next;
68142
68143 might_sleep();
68144+ BUG_ON(vma->vm_mirror);
68145 if (vma->vm_ops && vma->vm_ops->close)
68146 vma->vm_ops->close(vma);
68147 if (vma->vm_file) {
68148@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
68149 * not page aligned -Ram Gupta
68150 */
68151 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
68152+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
68153 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
68154 (mm->end_data - mm->start_data) > rlim)
68155 goto out;
68156@@ -704,6 +726,12 @@ static int
68157 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
68158 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68159 {
68160+
68161+#ifdef CONFIG_PAX_SEGMEXEC
68162+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
68163+ return 0;
68164+#endif
68165+
68166 if (is_mergeable_vma(vma, file, vm_flags) &&
68167 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
68168 if (vma->vm_pgoff == vm_pgoff)
68169@@ -723,6 +751,12 @@ static int
68170 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68171 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68172 {
68173+
68174+#ifdef CONFIG_PAX_SEGMEXEC
68175+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
68176+ return 0;
68177+#endif
68178+
68179 if (is_mergeable_vma(vma, file, vm_flags) &&
68180 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
68181 pgoff_t vm_pglen;
68182@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struc
68183 struct vm_area_struct *vma_merge(struct mm_struct *mm,
68184 struct vm_area_struct *prev, unsigned long addr,
68185 unsigned long end, unsigned long vm_flags,
68186- struct anon_vma *anon_vma, struct file *file,
68187+ struct anon_vma *anon_vma, struct file *file,
68188 pgoff_t pgoff, struct mempolicy *policy)
68189 {
68190 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
68191 struct vm_area_struct *area, *next;
68192
68193+#ifdef CONFIG_PAX_SEGMEXEC
68194+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
68195+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
68196+
68197+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
68198+#endif
68199+
68200 /*
68201 * We later require that vma->vm_flags == vm_flags,
68202 * so this tests vma->vm_flags & VM_SPECIAL, too.
68203@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct
68204 if (next && next->vm_end == end) /* cases 6, 7, 8 */
68205 next = next->vm_next;
68206
68207+#ifdef CONFIG_PAX_SEGMEXEC
68208+ if (prev)
68209+ prev_m = pax_find_mirror_vma(prev);
68210+ if (area)
68211+ area_m = pax_find_mirror_vma(area);
68212+ if (next)
68213+ next_m = pax_find_mirror_vma(next);
68214+#endif
68215+
68216 /*
68217 * Can it merge with the predecessor?
68218 */
68219@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct
68220 /* cases 1, 6 */
68221 vma_adjust(prev, prev->vm_start,
68222 next->vm_end, prev->vm_pgoff, NULL);
68223- } else /* cases 2, 5, 7 */
68224+
68225+#ifdef CONFIG_PAX_SEGMEXEC
68226+ if (prev_m)
68227+ vma_adjust(prev_m, prev_m->vm_start,
68228+ next_m->vm_end, prev_m->vm_pgoff, NULL);
68229+#endif
68230+
68231+ } else { /* cases 2, 5, 7 */
68232 vma_adjust(prev, prev->vm_start,
68233 end, prev->vm_pgoff, NULL);
68234+
68235+#ifdef CONFIG_PAX_SEGMEXEC
68236+ if (prev_m)
68237+ vma_adjust(prev_m, prev_m->vm_start,
68238+ end_m, prev_m->vm_pgoff, NULL);
68239+#endif
68240+
68241+ }
68242 return prev;
68243 }
68244
68245@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct
68246 mpol_equal(policy, vma_policy(next)) &&
68247 can_vma_merge_before(next, vm_flags,
68248 anon_vma, file, pgoff+pglen)) {
68249- if (prev && addr < prev->vm_end) /* case 4 */
68250+ if (prev && addr < prev->vm_end) { /* case 4 */
68251 vma_adjust(prev, prev->vm_start,
68252 addr, prev->vm_pgoff, NULL);
68253- else /* cases 3, 8 */
68254+
68255+#ifdef CONFIG_PAX_SEGMEXEC
68256+ if (prev_m)
68257+ vma_adjust(prev_m, prev_m->vm_start,
68258+ addr_m, prev_m->vm_pgoff, NULL);
68259+#endif
68260+
68261+ } else { /* cases 3, 8 */
68262 vma_adjust(area, addr, next->vm_end,
68263 next->vm_pgoff - pglen, NULL);
68264+
68265+#ifdef CONFIG_PAX_SEGMEXEC
68266+ if (area_m)
68267+ vma_adjust(area_m, addr_m, next_m->vm_end,
68268+ next_m->vm_pgoff - pglen, NULL);
68269+#endif
68270+
68271+ }
68272 return area;
68273 }
68274
68275@@ -898,14 +978,11 @@ none:
68276 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
68277 struct file *file, long pages)
68278 {
68279- const unsigned long stack_flags
68280- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
68281-
68282 if (file) {
68283 mm->shared_vm += pages;
68284 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
68285 mm->exec_vm += pages;
68286- } else if (flags & stack_flags)
68287+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
68288 mm->stack_vm += pages;
68289 if (flags & (VM_RESERVED|VM_IO))
68290 mm->reserved_vm += pages;
68291@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file
68292 * (the exception is when the underlying filesystem is noexec
68293 * mounted, in which case we dont add PROT_EXEC.)
68294 */
68295- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
68296+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
68297 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
68298 prot |= PROT_EXEC;
68299
68300@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file
68301 /* Obtain the address to map to. we verify (or select) it and ensure
68302 * that it represents a valid section of the address space.
68303 */
68304- addr = get_unmapped_area(file, addr, len, pgoff, flags);
68305+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
68306 if (addr & ~PAGE_MASK)
68307 return addr;
68308
68309@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file
68310 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
68311 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
68312
68313+#ifdef CONFIG_PAX_MPROTECT
68314+ if (mm->pax_flags & MF_PAX_MPROTECT) {
68315+#ifndef CONFIG_PAX_MPROTECT_COMPAT
68316+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
68317+ gr_log_rwxmmap(file);
68318+
68319+#ifdef CONFIG_PAX_EMUPLT
68320+ vm_flags &= ~VM_EXEC;
68321+#else
68322+ return -EPERM;
68323+#endif
68324+
68325+ }
68326+
68327+ if (!(vm_flags & VM_EXEC))
68328+ vm_flags &= ~VM_MAYEXEC;
68329+#else
68330+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
68331+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
68332+#endif
68333+ else
68334+ vm_flags &= ~VM_MAYWRITE;
68335+ }
68336+#endif
68337+
68338+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68339+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
68340+ vm_flags &= ~VM_PAGEEXEC;
68341+#endif
68342+
68343 if (flags & MAP_LOCKED)
68344 if (!can_do_mlock())
68345 return -EPERM;
68346@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file
68347 locked += mm->locked_vm;
68348 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
68349 lock_limit >>= PAGE_SHIFT;
68350+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
68351 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
68352 return -EAGAIN;
68353 }
68354@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file
68355 if (error)
68356 return error;
68357
68358+ if (!gr_acl_handle_mmap(file, prot))
68359+ return -EACCES;
68360+
68361 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
68362 }
68363 EXPORT_SYMBOL(do_mmap_pgoff);
68364@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
68365 */
68366 int vma_wants_writenotify(struct vm_area_struct *vma)
68367 {
68368- unsigned int vm_flags = vma->vm_flags;
68369+ unsigned long vm_flags = vma->vm_flags;
68370
68371 /* If it was private or non-writable, the write bit is already clear */
68372- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
68373+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
68374 return 0;
68375
68376 /* The backer wishes to know when pages are first written to? */
68377@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *f
68378 unsigned long charged = 0;
68379 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
68380
68381+#ifdef CONFIG_PAX_SEGMEXEC
68382+ struct vm_area_struct *vma_m = NULL;
68383+#endif
68384+
68385+ /*
68386+ * mm->mmap_sem is required to protect against another thread
68387+ * changing the mappings in case we sleep.
68388+ */
68389+ verify_mm_writelocked(mm);
68390+
68391 /* Clear old maps */
68392 error = -ENOMEM;
68393-munmap_back:
68394 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
68395 if (vma && vma->vm_start < addr + len) {
68396 if (do_munmap(mm, addr, len))
68397 return -ENOMEM;
68398- goto munmap_back;
68399+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
68400+ BUG_ON(vma && vma->vm_start < addr + len);
68401 }
68402
68403 /* Check against address space limit. */
68404@@ -1173,6 +1294,16 @@ munmap_back:
68405 goto unacct_error;
68406 }
68407
68408+#ifdef CONFIG_PAX_SEGMEXEC
68409+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
68410+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
68411+ if (!vma_m) {
68412+ error = -ENOMEM;
68413+ goto free_vma;
68414+ }
68415+ }
68416+#endif
68417+
68418 vma->vm_mm = mm;
68419 vma->vm_start = addr;
68420 vma->vm_end = addr + len;
68421@@ -1195,6 +1326,19 @@ munmap_back:
68422 error = file->f_op->mmap(file, vma);
68423 if (error)
68424 goto unmap_and_free_vma;
68425+
68426+#ifdef CONFIG_PAX_SEGMEXEC
68427+ if (vma_m && (vm_flags & VM_EXECUTABLE))
68428+ added_exe_file_vma(mm);
68429+#endif
68430+
68431+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68432+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
68433+ vma->vm_flags |= VM_PAGEEXEC;
68434+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
68435+ }
68436+#endif
68437+
68438 if (vm_flags & VM_EXECUTABLE)
68439 added_exe_file_vma(mm);
68440
68441@@ -1218,6 +1362,11 @@ munmap_back:
68442 vma_link(mm, vma, prev, rb_link, rb_parent);
68443 file = vma->vm_file;
68444
68445+#ifdef CONFIG_PAX_SEGMEXEC
68446+ if (vma_m)
68447+ pax_mirror_vma(vma_m, vma);
68448+#endif
68449+
68450 /* Once vma denies write, undo our temporary denial count */
68451 if (correct_wcount)
68452 atomic_inc(&inode->i_writecount);
68453@@ -1226,6 +1375,7 @@ out:
68454
68455 mm->total_vm += len >> PAGE_SHIFT;
68456 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
68457+ track_exec_limit(mm, addr, addr + len, vm_flags);
68458 if (vm_flags & VM_LOCKED) {
68459 /*
68460 * makes pages present; downgrades, drops, reacquires mmap_sem
68461@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
68462 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
68463 charged = 0;
68464 free_vma:
68465+
68466+#ifdef CONFIG_PAX_SEGMEXEC
68467+ if (vma_m)
68468+ kmem_cache_free(vm_area_cachep, vma_m);
68469+#endif
68470+
68471 kmem_cache_free(vm_area_cachep, vma);
68472 unacct_error:
68473 if (charged)
68474@@ -1255,6 +1411,44 @@ unacct_error:
68475 return error;
68476 }
68477
68478+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
68479+{
68480+ if (!vma) {
68481+#ifdef CONFIG_STACK_GROWSUP
68482+ if (addr > sysctl_heap_stack_gap)
68483+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
68484+ else
68485+ vma = find_vma(current->mm, 0);
68486+ if (vma && (vma->vm_flags & VM_GROWSUP))
68487+ return false;
68488+#endif
68489+ return true;
68490+ }
68491+
68492+ if (addr + len > vma->vm_start)
68493+ return false;
68494+
68495+ if (vma->vm_flags & VM_GROWSDOWN)
68496+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
68497+#ifdef CONFIG_STACK_GROWSUP
68498+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
68499+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
68500+#endif
68501+
68502+ return true;
68503+}
68504+
68505+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
68506+{
68507+ if (vma->vm_start < len)
68508+ return -ENOMEM;
68509+ if (!(vma->vm_flags & VM_GROWSDOWN))
68510+ return vma->vm_start - len;
68511+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
68512+ return vma->vm_start - len - sysctl_heap_stack_gap;
68513+ return -ENOMEM;
68514+}
68515+
68516 /* Get an address range which is currently unmapped.
68517 * For shmat() with addr=0.
68518 *
68519@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp
68520 if (flags & MAP_FIXED)
68521 return addr;
68522
68523+#ifdef CONFIG_PAX_RANDMMAP
68524+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
68525+#endif
68526+
68527 if (addr) {
68528 addr = PAGE_ALIGN(addr);
68529- vma = find_vma(mm, addr);
68530- if (TASK_SIZE - len >= addr &&
68531- (!vma || addr + len <= vma->vm_start))
68532- return addr;
68533+ if (TASK_SIZE - len >= addr) {
68534+ vma = find_vma(mm, addr);
68535+ if (check_heap_stack_gap(vma, addr, len))
68536+ return addr;
68537+ }
68538 }
68539 if (len > mm->cached_hole_size) {
68540- start_addr = addr = mm->free_area_cache;
68541+ start_addr = addr = mm->free_area_cache;
68542 } else {
68543- start_addr = addr = TASK_UNMAPPED_BASE;
68544- mm->cached_hole_size = 0;
68545+ start_addr = addr = mm->mmap_base;
68546+ mm->cached_hole_size = 0;
68547 }
68548
68549 full_search:
68550@@ -1303,34 +1502,40 @@ full_search:
68551 * Start a new search - just in case we missed
68552 * some holes.
68553 */
68554- if (start_addr != TASK_UNMAPPED_BASE) {
68555- addr = TASK_UNMAPPED_BASE;
68556- start_addr = addr;
68557+ if (start_addr != mm->mmap_base) {
68558+ start_addr = addr = mm->mmap_base;
68559 mm->cached_hole_size = 0;
68560 goto full_search;
68561 }
68562 return -ENOMEM;
68563 }
68564- if (!vma || addr + len <= vma->vm_start) {
68565- /*
68566- * Remember the place where we stopped the search:
68567- */
68568- mm->free_area_cache = addr + len;
68569- return addr;
68570- }
68571+ if (check_heap_stack_gap(vma, addr, len))
68572+ break;
68573 if (addr + mm->cached_hole_size < vma->vm_start)
68574 mm->cached_hole_size = vma->vm_start - addr;
68575 addr = vma->vm_end;
68576 }
68577+
68578+ /*
68579+ * Remember the place where we stopped the search:
68580+ */
68581+ mm->free_area_cache = addr + len;
68582+ return addr;
68583 }
68584 #endif
68585
68586 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
68587 {
68588+
68589+#ifdef CONFIG_PAX_SEGMEXEC
68590+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
68591+ return;
68592+#endif
68593+
68594 /*
68595 * Is this a new hole at the lowest possible address?
68596 */
68597- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
68598+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
68599 mm->free_area_cache = addr;
68600 mm->cached_hole_size = ~0UL;
68601 }
68602@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct fi
68603 {
68604 struct vm_area_struct *vma;
68605 struct mm_struct *mm = current->mm;
68606- unsigned long addr = addr0;
68607+ unsigned long base = mm->mmap_base, addr = addr0;
68608
68609 /* requested length too big for entire address space */
68610 if (len > TASK_SIZE)
68611@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct fi
68612 if (flags & MAP_FIXED)
68613 return addr;
68614
68615+#ifdef CONFIG_PAX_RANDMMAP
68616+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
68617+#endif
68618+
68619 /* requesting a specific address */
68620 if (addr) {
68621 addr = PAGE_ALIGN(addr);
68622- vma = find_vma(mm, addr);
68623- if (TASK_SIZE - len >= addr &&
68624- (!vma || addr + len <= vma->vm_start))
68625- return addr;
68626+ if (TASK_SIZE - len >= addr) {
68627+ vma = find_vma(mm, addr);
68628+ if (check_heap_stack_gap(vma, addr, len))
68629+ return addr;
68630+ }
68631 }
68632
68633 /* check if free_area_cache is useful for us */
68634@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct fi
68635 /* make sure it can fit in the remaining address space */
68636 if (addr > len) {
68637 vma = find_vma(mm, addr-len);
68638- if (!vma || addr <= vma->vm_start)
68639+ if (check_heap_stack_gap(vma, addr - len, len))
68640 /* remember the address as a hint for next time */
68641 return (mm->free_area_cache = addr-len);
68642 }
68643@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct fi
68644 * return with success:
68645 */
68646 vma = find_vma(mm, addr);
68647- if (!vma || addr+len <= vma->vm_start)
68648+ if (check_heap_stack_gap(vma, addr, len))
68649 /* remember the address as a hint for next time */
68650 return (mm->free_area_cache = addr);
68651
68652@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct fi
68653 mm->cached_hole_size = vma->vm_start - addr;
68654
68655 /* try just below the current vma->vm_start */
68656- addr = vma->vm_start-len;
68657- } while (len < vma->vm_start);
68658+ addr = skip_heap_stack_gap(vma, len);
68659+ } while (!IS_ERR_VALUE(addr));
68660
68661 bottomup:
68662 /*
68663@@ -1414,13 +1624,21 @@ bottomup:
68664 * can happen with large stack limits and large mmap()
68665 * allocations.
68666 */
68667+ mm->mmap_base = TASK_UNMAPPED_BASE;
68668+
68669+#ifdef CONFIG_PAX_RANDMMAP
68670+ if (mm->pax_flags & MF_PAX_RANDMMAP)
68671+ mm->mmap_base += mm->delta_mmap;
68672+#endif
68673+
68674+ mm->free_area_cache = mm->mmap_base;
68675 mm->cached_hole_size = ~0UL;
68676- mm->free_area_cache = TASK_UNMAPPED_BASE;
68677 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
68678 /*
68679 * Restore the topdown base:
68680 */
68681- mm->free_area_cache = mm->mmap_base;
68682+ mm->mmap_base = base;
68683+ mm->free_area_cache = base;
68684 mm->cached_hole_size = ~0UL;
68685
68686 return addr;
68687@@ -1429,6 +1647,12 @@ bottomup:
68688
68689 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
68690 {
68691+
68692+#ifdef CONFIG_PAX_SEGMEXEC
68693+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
68694+ return;
68695+#endif
68696+
68697 /*
68698 * Is this a new hole at the highest possible address?
68699 */
68700@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_s
68701 mm->free_area_cache = addr;
68702
68703 /* dont allow allocations above current base */
68704- if (mm->free_area_cache > mm->mmap_base)
68705+ if (mm->free_area_cache > mm->mmap_base) {
68706 mm->free_area_cache = mm->mmap_base;
68707+ mm->cached_hole_size = ~0UL;
68708+ }
68709 }
68710
68711 unsigned long
68712@@ -1545,6 +1771,27 @@ out:
68713 return prev ? prev->vm_next : vma;
68714 }
68715
68716+#ifdef CONFIG_PAX_SEGMEXEC
68717+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
68718+{
68719+ struct vm_area_struct *vma_m;
68720+
68721+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
68722+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
68723+ BUG_ON(vma->vm_mirror);
68724+ return NULL;
68725+ }
68726+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
68727+ vma_m = vma->vm_mirror;
68728+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
68729+ BUG_ON(vma->vm_file != vma_m->vm_file);
68730+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
68731+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
68732+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
68733+ return vma_m;
68734+}
68735+#endif
68736+
68737 /*
68738 * Verify that the stack growth is acceptable and
68739 * update accounting. This is shared with both the
68740@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_a
68741 return -ENOMEM;
68742
68743 /* Stack limit test */
68744+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
68745 if (size > rlim[RLIMIT_STACK].rlim_cur)
68746 return -ENOMEM;
68747
68748@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_a
68749 unsigned long limit;
68750 locked = mm->locked_vm + grow;
68751 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
68752+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
68753 if (locked > limit && !capable(CAP_IPC_LOCK))
68754 return -ENOMEM;
68755 }
68756@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_a
68757 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
68758 * vma is the last one with address > vma->vm_end. Have to extend vma.
68759 */
68760+#ifndef CONFIG_IA64
68761+static
68762+#endif
68763 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
68764 {
68765 int error;
68766+ bool locknext;
68767
68768 if (!(vma->vm_flags & VM_GROWSUP))
68769 return -EFAULT;
68770
68771+ /* Also guard against wrapping around to address 0. */
68772+ if (address < PAGE_ALIGN(address+1))
68773+ address = PAGE_ALIGN(address+1);
68774+ else
68775+ return -ENOMEM;
68776+
68777 /*
68778 * We must make sure the anon_vma is allocated
68779 * so that the anon_vma locking is not a noop.
68780 */
68781 if (unlikely(anon_vma_prepare(vma)))
68782 return -ENOMEM;
68783+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
68784+ if (locknext && anon_vma_prepare(vma->vm_next))
68785+ return -ENOMEM;
68786 anon_vma_lock(vma);
68787+ if (locknext)
68788+ anon_vma_lock(vma->vm_next);
68789
68790 /*
68791 * vma->vm_start/vm_end cannot change under us because the caller
68792 * is required to hold the mmap_sem in read mode. We need the
68793- * anon_vma lock to serialize against concurrent expand_stacks.
68794- * Also guard against wrapping around to address 0.
68795+ * anon_vma locks to serialize against concurrent expand_stacks
68796+ * and expand_upwards.
68797 */
68798- if (address < PAGE_ALIGN(address+4))
68799- address = PAGE_ALIGN(address+4);
68800- else {
68801- anon_vma_unlock(vma);
68802- return -ENOMEM;
68803- }
68804 error = 0;
68805
68806 /* Somebody else might have raced and expanded it already */
68807- if (address > vma->vm_end) {
68808+ 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)
68809+ error = -ENOMEM;
68810+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
68811 unsigned long size, grow;
68812
68813 size = address - vma->vm_start;
68814@@ -1640,6 +1900,8 @@ int expand_upwards(struct vm_area_struct
68815 if (!error)
68816 vma->vm_end = address;
68817 }
68818+ if (locknext)
68819+ anon_vma_unlock(vma->vm_next);
68820 anon_vma_unlock(vma);
68821 return error;
68822 }
68823@@ -1652,6 +1914,8 @@ static int expand_downwards(struct vm_ar
68824 unsigned long address)
68825 {
68826 int error;
68827+ bool lockprev = false;
68828+ struct vm_area_struct *prev;
68829
68830 /*
68831 * We must make sure the anon_vma is allocated
68832@@ -1665,6 +1929,15 @@ static int expand_downwards(struct vm_ar
68833 if (error)
68834 return error;
68835
68836+ prev = vma->vm_prev;
68837+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
68838+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
68839+#endif
68840+ if (lockprev && anon_vma_prepare(prev))
68841+ return -ENOMEM;
68842+ if (lockprev)
68843+ anon_vma_lock(prev);
68844+
68845 anon_vma_lock(vma);
68846
68847 /*
68848@@ -1674,9 +1947,17 @@ static int expand_downwards(struct vm_ar
68849 */
68850
68851 /* Somebody else might have raced and expanded it already */
68852- if (address < vma->vm_start) {
68853+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
68854+ error = -ENOMEM;
68855+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
68856 unsigned long size, grow;
68857
68858+#ifdef CONFIG_PAX_SEGMEXEC
68859+ struct vm_area_struct *vma_m;
68860+
68861+ vma_m = pax_find_mirror_vma(vma);
68862+#endif
68863+
68864 size = vma->vm_end - address;
68865 grow = (vma->vm_start - address) >> PAGE_SHIFT;
68866
68867@@ -1684,9 +1965,20 @@ static int expand_downwards(struct vm_ar
68868 if (!error) {
68869 vma->vm_start = address;
68870 vma->vm_pgoff -= grow;
68871+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
68872+
68873+#ifdef CONFIG_PAX_SEGMEXEC
68874+ if (vma_m) {
68875+ vma_m->vm_start -= grow << PAGE_SHIFT;
68876+ vma_m->vm_pgoff -= grow;
68877+ }
68878+#endif
68879+
68880 }
68881 }
68882 anon_vma_unlock(vma);
68883+ if (lockprev)
68884+ anon_vma_unlock(prev);
68885 return error;
68886 }
68887
68888@@ -1762,6 +2054,13 @@ static void remove_vma_list(struct mm_st
68889 do {
68890 long nrpages = vma_pages(vma);
68891
68892+#ifdef CONFIG_PAX_SEGMEXEC
68893+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
68894+ vma = remove_vma(vma);
68895+ continue;
68896+ }
68897+#endif
68898+
68899 mm->total_vm -= nrpages;
68900 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
68901 vma = remove_vma(vma);
68902@@ -1807,6 +2106,16 @@ detach_vmas_to_be_unmapped(struct mm_str
68903 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
68904 vma->vm_prev = NULL;
68905 do {
68906+
68907+#ifdef CONFIG_PAX_SEGMEXEC
68908+ if (vma->vm_mirror) {
68909+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
68910+ vma->vm_mirror->vm_mirror = NULL;
68911+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
68912+ vma->vm_mirror = NULL;
68913+ }
68914+#endif
68915+
68916 rb_erase(&vma->vm_rb, &mm->mm_rb);
68917 mm->map_count--;
68918 tail_vma = vma;
68919@@ -1834,10 +2143,25 @@ int split_vma(struct mm_struct * mm, str
68920 struct mempolicy *pol;
68921 struct vm_area_struct *new;
68922
68923+#ifdef CONFIG_PAX_SEGMEXEC
68924+ struct vm_area_struct *vma_m, *new_m = NULL;
68925+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
68926+#endif
68927+
68928 if (is_vm_hugetlb_page(vma) && (addr &
68929 ~(huge_page_mask(hstate_vma(vma)))))
68930 return -EINVAL;
68931
68932+#ifdef CONFIG_PAX_SEGMEXEC
68933+ vma_m = pax_find_mirror_vma(vma);
68934+
68935+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
68936+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
68937+ if (mm->map_count >= sysctl_max_map_count-1)
68938+ return -ENOMEM;
68939+ } else
68940+#endif
68941+
68942 if (mm->map_count >= sysctl_max_map_count)
68943 return -ENOMEM;
68944
68945@@ -1845,6 +2169,16 @@ int split_vma(struct mm_struct * mm, str
68946 if (!new)
68947 return -ENOMEM;
68948
68949+#ifdef CONFIG_PAX_SEGMEXEC
68950+ if (vma_m) {
68951+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
68952+ if (!new_m) {
68953+ kmem_cache_free(vm_area_cachep, new);
68954+ return -ENOMEM;
68955+ }
68956+ }
68957+#endif
68958+
68959 /* most fields are the same, copy all, and then fixup */
68960 *new = *vma;
68961
68962@@ -1855,8 +2189,29 @@ int split_vma(struct mm_struct * mm, str
68963 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
68964 }
68965
68966+#ifdef CONFIG_PAX_SEGMEXEC
68967+ if (vma_m) {
68968+ *new_m = *vma_m;
68969+ new_m->vm_mirror = new;
68970+ new->vm_mirror = new_m;
68971+
68972+ if (new_below)
68973+ new_m->vm_end = addr_m;
68974+ else {
68975+ new_m->vm_start = addr_m;
68976+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
68977+ }
68978+ }
68979+#endif
68980+
68981 pol = mpol_dup(vma_policy(vma));
68982 if (IS_ERR(pol)) {
68983+
68984+#ifdef CONFIG_PAX_SEGMEXEC
68985+ if (new_m)
68986+ kmem_cache_free(vm_area_cachep, new_m);
68987+#endif
68988+
68989 kmem_cache_free(vm_area_cachep, new);
68990 return PTR_ERR(pol);
68991 }
68992@@ -1877,6 +2232,28 @@ int split_vma(struct mm_struct * mm, str
68993 else
68994 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
68995
68996+#ifdef CONFIG_PAX_SEGMEXEC
68997+ if (vma_m) {
68998+ mpol_get(pol);
68999+ vma_set_policy(new_m, pol);
69000+
69001+ if (new_m->vm_file) {
69002+ get_file(new_m->vm_file);
69003+ if (vma_m->vm_flags & VM_EXECUTABLE)
69004+ added_exe_file_vma(mm);
69005+ }
69006+
69007+ if (new_m->vm_ops && new_m->vm_ops->open)
69008+ new_m->vm_ops->open(new_m);
69009+
69010+ if (new_below)
69011+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
69012+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
69013+ else
69014+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
69015+ }
69016+#endif
69017+
69018 return 0;
69019 }
69020
69021@@ -1885,11 +2262,30 @@ int split_vma(struct mm_struct * mm, str
69022 * work. This now handles partial unmappings.
69023 * Jeremy Fitzhardinge <jeremy@goop.org>
69024 */
69025+#ifdef CONFIG_PAX_SEGMEXEC
69026+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69027+{
69028+ int ret = __do_munmap(mm, start, len);
69029+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
69030+ return ret;
69031+
69032+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
69033+}
69034+
69035+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69036+#else
69037 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69038+#endif
69039 {
69040 unsigned long end;
69041 struct vm_area_struct *vma, *prev, *last;
69042
69043+ /*
69044+ * mm->mmap_sem is required to protect against another thread
69045+ * changing the mappings in case we sleep.
69046+ */
69047+ verify_mm_writelocked(mm);
69048+
69049 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
69050 return -EINVAL;
69051
69052@@ -1953,6 +2349,8 @@ int do_munmap(struct mm_struct *mm, unsi
69053 /* Fix up all other VM information */
69054 remove_vma_list(mm, vma);
69055
69056+ track_exec_limit(mm, start, end, 0UL);
69057+
69058 return 0;
69059 }
69060
69061@@ -1965,22 +2363,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
69062
69063 profile_munmap(addr);
69064
69065+#ifdef CONFIG_PAX_SEGMEXEC
69066+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
69067+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
69068+ return -EINVAL;
69069+#endif
69070+
69071 down_write(&mm->mmap_sem);
69072 ret = do_munmap(mm, addr, len);
69073 up_write(&mm->mmap_sem);
69074 return ret;
69075 }
69076
69077-static inline void verify_mm_writelocked(struct mm_struct *mm)
69078-{
69079-#ifdef CONFIG_DEBUG_VM
69080- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
69081- WARN_ON(1);
69082- up_read(&mm->mmap_sem);
69083- }
69084-#endif
69085-}
69086-
69087 /*
69088 * this is really a simplified "do_mmap". it only handles
69089 * anonymous maps. eventually we may be able to do some
69090@@ -1994,6 +2388,7 @@ unsigned long do_brk(unsigned long addr,
69091 struct rb_node ** rb_link, * rb_parent;
69092 pgoff_t pgoff = addr >> PAGE_SHIFT;
69093 int error;
69094+ unsigned long charged;
69095
69096 len = PAGE_ALIGN(len);
69097 if (!len)
69098@@ -2005,16 +2400,30 @@ unsigned long do_brk(unsigned long addr,
69099
69100 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
69101
69102+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
69103+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
69104+ flags &= ~VM_EXEC;
69105+
69106+#ifdef CONFIG_PAX_MPROTECT
69107+ if (mm->pax_flags & MF_PAX_MPROTECT)
69108+ flags &= ~VM_MAYEXEC;
69109+#endif
69110+
69111+ }
69112+#endif
69113+
69114 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
69115 if (error & ~PAGE_MASK)
69116 return error;
69117
69118+ charged = len >> PAGE_SHIFT;
69119+
69120 /*
69121 * mlock MCL_FUTURE?
69122 */
69123 if (mm->def_flags & VM_LOCKED) {
69124 unsigned long locked, lock_limit;
69125- locked = len >> PAGE_SHIFT;
69126+ locked = charged;
69127 locked += mm->locked_vm;
69128 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
69129 lock_limit >>= PAGE_SHIFT;
69130@@ -2031,22 +2440,22 @@ unsigned long do_brk(unsigned long addr,
69131 /*
69132 * Clear old maps. this also does some error checking for us
69133 */
69134- munmap_back:
69135 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69136 if (vma && vma->vm_start < addr + len) {
69137 if (do_munmap(mm, addr, len))
69138 return -ENOMEM;
69139- goto munmap_back;
69140+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69141+ BUG_ON(vma && vma->vm_start < addr + len);
69142 }
69143
69144 /* Check against address space limits *after* clearing old maps... */
69145- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
69146+ if (!may_expand_vm(mm, charged))
69147 return -ENOMEM;
69148
69149 if (mm->map_count > sysctl_max_map_count)
69150 return -ENOMEM;
69151
69152- if (security_vm_enough_memory(len >> PAGE_SHIFT))
69153+ if (security_vm_enough_memory(charged))
69154 return -ENOMEM;
69155
69156 /* Can we just expand an old private anonymous mapping? */
69157@@ -2060,7 +2469,7 @@ unsigned long do_brk(unsigned long addr,
69158 */
69159 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69160 if (!vma) {
69161- vm_unacct_memory(len >> PAGE_SHIFT);
69162+ vm_unacct_memory(charged);
69163 return -ENOMEM;
69164 }
69165
69166@@ -2072,11 +2481,12 @@ unsigned long do_brk(unsigned long addr,
69167 vma->vm_page_prot = vm_get_page_prot(flags);
69168 vma_link(mm, vma, prev, rb_link, rb_parent);
69169 out:
69170- mm->total_vm += len >> PAGE_SHIFT;
69171+ mm->total_vm += charged;
69172 if (flags & VM_LOCKED) {
69173 if (!mlock_vma_pages_range(vma, addr, addr + len))
69174- mm->locked_vm += (len >> PAGE_SHIFT);
69175+ mm->locked_vm += charged;
69176 }
69177+ track_exec_limit(mm, addr, addr + len, flags);
69178 return addr;
69179 }
69180
69181@@ -2123,8 +2533,10 @@ void exit_mmap(struct mm_struct *mm)
69182 * Walk the list again, actually closing and freeing it,
69183 * with preemption enabled, without holding any MM locks.
69184 */
69185- while (vma)
69186+ while (vma) {
69187+ vma->vm_mirror = NULL;
69188 vma = remove_vma(vma);
69189+ }
69190
69191 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
69192 }
69193@@ -2138,6 +2550,10 @@ int insert_vm_struct(struct mm_struct *
69194 struct vm_area_struct * __vma, * prev;
69195 struct rb_node ** rb_link, * rb_parent;
69196
69197+#ifdef CONFIG_PAX_SEGMEXEC
69198+ struct vm_area_struct *vma_m = NULL;
69199+#endif
69200+
69201 /*
69202 * The vm_pgoff of a purely anonymous vma should be irrelevant
69203 * until its first write fault, when page's anon_vma and index
69204@@ -2160,7 +2576,22 @@ int insert_vm_struct(struct mm_struct *
69205 if ((vma->vm_flags & VM_ACCOUNT) &&
69206 security_vm_enough_memory_mm(mm, vma_pages(vma)))
69207 return -ENOMEM;
69208+
69209+#ifdef CONFIG_PAX_SEGMEXEC
69210+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
69211+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69212+ if (!vma_m)
69213+ return -ENOMEM;
69214+ }
69215+#endif
69216+
69217 vma_link(mm, vma, prev, rb_link, rb_parent);
69218+
69219+#ifdef CONFIG_PAX_SEGMEXEC
69220+ if (vma_m)
69221+ pax_mirror_vma(vma_m, vma);
69222+#endif
69223+
69224 return 0;
69225 }
69226
69227@@ -2178,6 +2609,8 @@ struct vm_area_struct *copy_vma(struct v
69228 struct rb_node **rb_link, *rb_parent;
69229 struct mempolicy *pol;
69230
69231+ BUG_ON(vma->vm_mirror);
69232+
69233 /*
69234 * If anonymous vma has not yet been faulted, update new pgoff
69235 * to match new location, to increase its chance of merging.
69236@@ -2221,6 +2654,35 @@ struct vm_area_struct *copy_vma(struct v
69237 return new_vma;
69238 }
69239
69240+#ifdef CONFIG_PAX_SEGMEXEC
69241+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
69242+{
69243+ struct vm_area_struct *prev_m;
69244+ struct rb_node **rb_link_m, *rb_parent_m;
69245+ struct mempolicy *pol_m;
69246+
69247+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
69248+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
69249+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
69250+ *vma_m = *vma;
69251+ pol_m = vma_policy(vma_m);
69252+ mpol_get(pol_m);
69253+ vma_set_policy(vma_m, pol_m);
69254+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
69255+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
69256+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
69257+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
69258+ if (vma_m->vm_file)
69259+ get_file(vma_m->vm_file);
69260+ if (vma_m->vm_ops && vma_m->vm_ops->open)
69261+ vma_m->vm_ops->open(vma_m);
69262+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
69263+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
69264+ vma_m->vm_mirror = vma;
69265+ vma->vm_mirror = vma_m;
69266+}
69267+#endif
69268+
69269 /*
69270 * Return true if the calling process may expand its vm space by the passed
69271 * number of pages
69272@@ -2231,7 +2693,7 @@ int may_expand_vm(struct mm_struct *mm,
69273 unsigned long lim;
69274
69275 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
69276-
69277+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
69278 if (cur + npages > lim)
69279 return 0;
69280 return 1;
69281@@ -2301,6 +2763,22 @@ int install_special_mapping(struct mm_st
69282 vma->vm_start = addr;
69283 vma->vm_end = addr + len;
69284
69285+#ifdef CONFIG_PAX_MPROTECT
69286+ if (mm->pax_flags & MF_PAX_MPROTECT) {
69287+#ifndef CONFIG_PAX_MPROTECT_COMPAT
69288+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
69289+ return -EPERM;
69290+ if (!(vm_flags & VM_EXEC))
69291+ vm_flags &= ~VM_MAYEXEC;
69292+#else
69293+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
69294+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
69295+#endif
69296+ else
69297+ vm_flags &= ~VM_MAYWRITE;
69298+ }
69299+#endif
69300+
69301 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
69302 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69303
69304diff -urNp linux-2.6.32.43/mm/mprotect.c linux-2.6.32.43/mm/mprotect.c
69305--- linux-2.6.32.43/mm/mprotect.c 2011-03-27 14:31:47.000000000 -0400
69306+++ linux-2.6.32.43/mm/mprotect.c 2011-04-17 15:56:46.000000000 -0400
69307@@ -24,10 +24,16 @@
69308 #include <linux/mmu_notifier.h>
69309 #include <linux/migrate.h>
69310 #include <linux/perf_event.h>
69311+
69312+#ifdef CONFIG_PAX_MPROTECT
69313+#include <linux/elf.h>
69314+#endif
69315+
69316 #include <asm/uaccess.h>
69317 #include <asm/pgtable.h>
69318 #include <asm/cacheflush.h>
69319 #include <asm/tlbflush.h>
69320+#include <asm/mmu_context.h>
69321
69322 #ifndef pgprot_modify
69323 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
69324@@ -132,6 +138,48 @@ static void change_protection(struct vm_
69325 flush_tlb_range(vma, start, end);
69326 }
69327
69328+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69329+/* called while holding the mmap semaphor for writing except stack expansion */
69330+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
69331+{
69332+ unsigned long oldlimit, newlimit = 0UL;
69333+
69334+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
69335+ return;
69336+
69337+ spin_lock(&mm->page_table_lock);
69338+ oldlimit = mm->context.user_cs_limit;
69339+ if ((prot & VM_EXEC) && oldlimit < end)
69340+ /* USER_CS limit moved up */
69341+ newlimit = end;
69342+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
69343+ /* USER_CS limit moved down */
69344+ newlimit = start;
69345+
69346+ if (newlimit) {
69347+ mm->context.user_cs_limit = newlimit;
69348+
69349+#ifdef CONFIG_SMP
69350+ wmb();
69351+ cpus_clear(mm->context.cpu_user_cs_mask);
69352+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
69353+#endif
69354+
69355+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
69356+ }
69357+ spin_unlock(&mm->page_table_lock);
69358+ if (newlimit == end) {
69359+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
69360+
69361+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
69362+ if (is_vm_hugetlb_page(vma))
69363+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
69364+ else
69365+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
69366+ }
69367+}
69368+#endif
69369+
69370 int
69371 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
69372 unsigned long start, unsigned long end, unsigned long newflags)
69373@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vm
69374 int error;
69375 int dirty_accountable = 0;
69376
69377+#ifdef CONFIG_PAX_SEGMEXEC
69378+ struct vm_area_struct *vma_m = NULL;
69379+ unsigned long start_m, end_m;
69380+
69381+ start_m = start + SEGMEXEC_TASK_SIZE;
69382+ end_m = end + SEGMEXEC_TASK_SIZE;
69383+#endif
69384+
69385 if (newflags == oldflags) {
69386 *pprev = vma;
69387 return 0;
69388 }
69389
69390+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
69391+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
69392+
69393+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
69394+ return -ENOMEM;
69395+
69396+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
69397+ return -ENOMEM;
69398+ }
69399+
69400 /*
69401 * If we make a private mapping writable we increase our commit;
69402 * but (without finer accounting) cannot reduce our commit if we
69403@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vm
69404 }
69405 }
69406
69407+#ifdef CONFIG_PAX_SEGMEXEC
69408+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
69409+ if (start != vma->vm_start) {
69410+ error = split_vma(mm, vma, start, 1);
69411+ if (error)
69412+ goto fail;
69413+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
69414+ *pprev = (*pprev)->vm_next;
69415+ }
69416+
69417+ if (end != vma->vm_end) {
69418+ error = split_vma(mm, vma, end, 0);
69419+ if (error)
69420+ goto fail;
69421+ }
69422+
69423+ if (pax_find_mirror_vma(vma)) {
69424+ error = __do_munmap(mm, start_m, end_m - start_m);
69425+ if (error)
69426+ goto fail;
69427+ } else {
69428+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69429+ if (!vma_m) {
69430+ error = -ENOMEM;
69431+ goto fail;
69432+ }
69433+ vma->vm_flags = newflags;
69434+ pax_mirror_vma(vma_m, vma);
69435+ }
69436+ }
69437+#endif
69438+
69439 /*
69440 * First try to merge with previous and/or next vma.
69441 */
69442@@ -195,9 +293,21 @@ success:
69443 * vm_flags and vm_page_prot are protected by the mmap_sem
69444 * held in write mode.
69445 */
69446+
69447+#ifdef CONFIG_PAX_SEGMEXEC
69448+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
69449+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
69450+#endif
69451+
69452 vma->vm_flags = newflags;
69453+
69454+#ifdef CONFIG_PAX_MPROTECT
69455+ if (mm->binfmt && mm->binfmt->handle_mprotect)
69456+ mm->binfmt->handle_mprotect(vma, newflags);
69457+#endif
69458+
69459 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
69460- vm_get_page_prot(newflags));
69461+ vm_get_page_prot(vma->vm_flags));
69462
69463 if (vma_wants_writenotify(vma)) {
69464 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
69465@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
69466 end = start + len;
69467 if (end <= start)
69468 return -ENOMEM;
69469+
69470+#ifdef CONFIG_PAX_SEGMEXEC
69471+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69472+ if (end > SEGMEXEC_TASK_SIZE)
69473+ return -EINVAL;
69474+ } else
69475+#endif
69476+
69477+ if (end > TASK_SIZE)
69478+ return -EINVAL;
69479+
69480 if (!arch_validate_prot(prot))
69481 return -EINVAL;
69482
69483@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
69484 /*
69485 * Does the application expect PROT_READ to imply PROT_EXEC:
69486 */
69487- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
69488+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
69489 prot |= PROT_EXEC;
69490
69491 vm_flags = calc_vm_prot_bits(prot);
69492@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
69493 if (start > vma->vm_start)
69494 prev = vma;
69495
69496+#ifdef CONFIG_PAX_MPROTECT
69497+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
69498+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
69499+#endif
69500+
69501 for (nstart = start ; ; ) {
69502 unsigned long newflags;
69503
69504@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
69505
69506 /* newflags >> 4 shift VM_MAY% in place of VM_% */
69507 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
69508+ if (prot & (PROT_WRITE | PROT_EXEC))
69509+ gr_log_rwxmprotect(vma->vm_file);
69510+
69511+ error = -EACCES;
69512+ goto out;
69513+ }
69514+
69515+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
69516 error = -EACCES;
69517 goto out;
69518 }
69519@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
69520 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
69521 if (error)
69522 goto out;
69523+
69524+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
69525+
69526 nstart = tmp;
69527
69528 if (nstart < prev->vm_end)
69529diff -urNp linux-2.6.32.43/mm/mremap.c linux-2.6.32.43/mm/mremap.c
69530--- linux-2.6.32.43/mm/mremap.c 2011-04-17 17:00:52.000000000 -0400
69531+++ linux-2.6.32.43/mm/mremap.c 2011-04-17 17:03:58.000000000 -0400
69532@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_str
69533 continue;
69534 pte = ptep_clear_flush(vma, old_addr, old_pte);
69535 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
69536+
69537+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69538+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
69539+ pte = pte_exprotect(pte);
69540+#endif
69541+
69542 set_pte_at(mm, new_addr, new_pte, pte);
69543 }
69544
69545@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_res
69546 if (is_vm_hugetlb_page(vma))
69547 goto Einval;
69548
69549+#ifdef CONFIG_PAX_SEGMEXEC
69550+ if (pax_find_mirror_vma(vma))
69551+ goto Einval;
69552+#endif
69553+
69554 /* We can't remap across vm area boundaries */
69555 if (old_len > vma->vm_end - addr)
69556 goto Efault;
69557@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned
69558 unsigned long ret = -EINVAL;
69559 unsigned long charged = 0;
69560 unsigned long map_flags;
69561+ unsigned long pax_task_size = TASK_SIZE;
69562
69563 if (new_addr & ~PAGE_MASK)
69564 goto out;
69565
69566- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
69567+#ifdef CONFIG_PAX_SEGMEXEC
69568+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
69569+ pax_task_size = SEGMEXEC_TASK_SIZE;
69570+#endif
69571+
69572+ pax_task_size -= PAGE_SIZE;
69573+
69574+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
69575 goto out;
69576
69577 /* Check if the location we're moving into overlaps the
69578 * old location at all, and fail if it does.
69579 */
69580- if ((new_addr <= addr) && (new_addr+new_len) > addr)
69581- goto out;
69582-
69583- if ((addr <= new_addr) && (addr+old_len) > new_addr)
69584+ if (addr + old_len > new_addr && new_addr + new_len > addr)
69585 goto out;
69586
69587 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
69588@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long ad
69589 struct vm_area_struct *vma;
69590 unsigned long ret = -EINVAL;
69591 unsigned long charged = 0;
69592+ unsigned long pax_task_size = TASK_SIZE;
69593
69594 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
69595 goto out;
69596@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long ad
69597 if (!new_len)
69598 goto out;
69599
69600+#ifdef CONFIG_PAX_SEGMEXEC
69601+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
69602+ pax_task_size = SEGMEXEC_TASK_SIZE;
69603+#endif
69604+
69605+ pax_task_size -= PAGE_SIZE;
69606+
69607+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
69608+ old_len > pax_task_size || addr > pax_task_size-old_len)
69609+ goto out;
69610+
69611 if (flags & MREMAP_FIXED) {
69612 if (flags & MREMAP_MAYMOVE)
69613 ret = mremap_to(addr, old_len, new_addr, new_len);
69614@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long ad
69615 addr + new_len);
69616 }
69617 ret = addr;
69618+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
69619 goto out;
69620 }
69621 }
69622@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long ad
69623 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
69624 if (ret)
69625 goto out;
69626+
69627+ map_flags = vma->vm_flags;
69628 ret = move_vma(vma, addr, old_len, new_len, new_addr);
69629+ if (!(ret & ~PAGE_MASK)) {
69630+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
69631+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
69632+ }
69633 }
69634 out:
69635 if (ret & ~PAGE_MASK)
69636diff -urNp linux-2.6.32.43/mm/nommu.c linux-2.6.32.43/mm/nommu.c
69637--- linux-2.6.32.43/mm/nommu.c 2011-03-27 14:31:47.000000000 -0400
69638+++ linux-2.6.32.43/mm/nommu.c 2011-04-17 15:56:46.000000000 -0400
69639@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMI
69640 int sysctl_overcommit_ratio = 50; /* default is 50% */
69641 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
69642 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
69643-int heap_stack_gap = 0;
69644
69645 atomic_long_t mmap_pages_allocated;
69646
69647@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct m
69648 EXPORT_SYMBOL(find_vma);
69649
69650 /*
69651- * find a VMA
69652- * - we don't extend stack VMAs under NOMMU conditions
69653- */
69654-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
69655-{
69656- return find_vma(mm, addr);
69657-}
69658-
69659-/*
69660 * expand a stack to a given address
69661 * - not supported under NOMMU conditions
69662 */
69663diff -urNp linux-2.6.32.43/mm/page_alloc.c linux-2.6.32.43/mm/page_alloc.c
69664--- linux-2.6.32.43/mm/page_alloc.c 2011-06-25 12:55:35.000000000 -0400
69665+++ linux-2.6.32.43/mm/page_alloc.c 2011-07-09 09:13:08.000000000 -0400
69666@@ -289,7 +289,7 @@ out:
69667 * This usage means that zero-order pages may not be compound.
69668 */
69669
69670-static void free_compound_page(struct page *page)
69671+void free_compound_page(struct page *page)
69672 {
69673 __free_pages_ok(page, compound_order(page));
69674 }
69675@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page
69676 int bad = 0;
69677 int wasMlocked = __TestClearPageMlocked(page);
69678
69679+#ifdef CONFIG_PAX_MEMORY_SANITIZE
69680+ unsigned long index = 1UL << order;
69681+#endif
69682+
69683 kmemcheck_free_shadow(page, order);
69684
69685 for (i = 0 ; i < (1 << order) ; ++i)
69686@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page
69687 debug_check_no_obj_freed(page_address(page),
69688 PAGE_SIZE << order);
69689 }
69690+
69691+#ifdef CONFIG_PAX_MEMORY_SANITIZE
69692+ for (; index; --index)
69693+ sanitize_highpage(page + index - 1);
69694+#endif
69695+
69696 arch_free_page(page, order);
69697 kernel_map_pages(page, 1 << order, 0);
69698
69699@@ -702,8 +712,10 @@ static int prep_new_page(struct page *pa
69700 arch_alloc_page(page, order);
69701 kernel_map_pages(page, 1 << order, 1);
69702
69703+#ifndef CONFIG_PAX_MEMORY_SANITIZE
69704 if (gfp_flags & __GFP_ZERO)
69705 prep_zero_page(page, order, gfp_flags);
69706+#endif
69707
69708 if (order && (gfp_flags & __GFP_COMP))
69709 prep_compound_page(page, order);
69710@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct pa
69711 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
69712 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
69713 }
69714+
69715+#ifdef CONFIG_PAX_MEMORY_SANITIZE
69716+ sanitize_highpage(page);
69717+#endif
69718+
69719 arch_free_page(page, 0);
69720 kernel_map_pages(page, 1, 0);
69721
69722@@ -2179,6 +2196,8 @@ void show_free_areas(void)
69723 int cpu;
69724 struct zone *zone;
69725
69726+ pax_track_stack();
69727+
69728 for_each_populated_zone(zone) {
69729 show_node(zone);
69730 printk("%s per-cpu:\n", zone->name);
69731@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct p
69732 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
69733 }
69734 #else
69735-static void inline setup_usemap(struct pglist_data *pgdat,
69736+static inline void setup_usemap(struct pglist_data *pgdat,
69737 struct zone *zone, unsigned long zonesize) {}
69738 #endif /* CONFIG_SPARSEMEM */
69739
69740diff -urNp linux-2.6.32.43/mm/percpu.c linux-2.6.32.43/mm/percpu.c
69741--- linux-2.6.32.43/mm/percpu.c 2011-03-27 14:31:47.000000000 -0400
69742+++ linux-2.6.32.43/mm/percpu.c 2011-04-17 15:56:46.000000000 -0400
69743@@ -115,7 +115,7 @@ static unsigned int pcpu_first_unit_cpu
69744 static unsigned int pcpu_last_unit_cpu __read_mostly;
69745
69746 /* the address of the first chunk which starts with the kernel static area */
69747-void *pcpu_base_addr __read_mostly;
69748+void *pcpu_base_addr __read_only;
69749 EXPORT_SYMBOL_GPL(pcpu_base_addr);
69750
69751 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
69752diff -urNp linux-2.6.32.43/mm/rmap.c linux-2.6.32.43/mm/rmap.c
69753--- linux-2.6.32.43/mm/rmap.c 2011-03-27 14:31:47.000000000 -0400
69754+++ linux-2.6.32.43/mm/rmap.c 2011-04-17 15:56:46.000000000 -0400
69755@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_stru
69756 /* page_table_lock to protect against threads */
69757 spin_lock(&mm->page_table_lock);
69758 if (likely(!vma->anon_vma)) {
69759+
69760+#ifdef CONFIG_PAX_SEGMEXEC
69761+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
69762+
69763+ if (vma_m) {
69764+ BUG_ON(vma_m->anon_vma);
69765+ vma_m->anon_vma = anon_vma;
69766+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
69767+ }
69768+#endif
69769+
69770 vma->anon_vma = anon_vma;
69771 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
69772 allocated = NULL;
69773diff -urNp linux-2.6.32.43/mm/shmem.c linux-2.6.32.43/mm/shmem.c
69774--- linux-2.6.32.43/mm/shmem.c 2011-03-27 14:31:47.000000000 -0400
69775+++ linux-2.6.32.43/mm/shmem.c 2011-05-18 20:09:37.000000000 -0400
69776@@ -31,7 +31,7 @@
69777 #include <linux/swap.h>
69778 #include <linux/ima.h>
69779
69780-static struct vfsmount *shm_mnt;
69781+struct vfsmount *shm_mnt;
69782
69783 #ifdef CONFIG_SHMEM
69784 /*
69785@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *
69786 goto unlock;
69787 }
69788 entry = shmem_swp_entry(info, index, NULL);
69789+ if (!entry)
69790+ goto unlock;
69791 if (entry->val) {
69792 /*
69793 * The more uptodate page coming down from a stacked
69794@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_ent
69795 struct vm_area_struct pvma;
69796 struct page *page;
69797
69798+ pax_track_stack();
69799+
69800 spol = mpol_cond_copy(&mpol,
69801 mpol_shared_policy_lookup(&info->policy, idx));
69802
69803@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *d
69804
69805 info = SHMEM_I(inode);
69806 inode->i_size = len-1;
69807- if (len <= (char *)inode - (char *)info) {
69808+ if (len <= (char *)inode - (char *)info && len <= 64) {
69809 /* do it inline */
69810 memcpy(info, symname, len);
69811 inode->i_op = &shmem_symlink_inline_operations;
69812@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block
69813 int err = -ENOMEM;
69814
69815 /* Round up to L1_CACHE_BYTES to resist false sharing */
69816- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
69817- L1_CACHE_BYTES), GFP_KERNEL);
69818+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
69819 if (!sbinfo)
69820 return -ENOMEM;
69821
69822diff -urNp linux-2.6.32.43/mm/slab.c linux-2.6.32.43/mm/slab.c
69823--- linux-2.6.32.43/mm/slab.c 2011-03-27 14:31:47.000000000 -0400
69824+++ linux-2.6.32.43/mm/slab.c 2011-05-04 17:56:20.000000000 -0400
69825@@ -174,7 +174,7 @@
69826
69827 /* Legal flag mask for kmem_cache_create(). */
69828 #if DEBUG
69829-# define CREATE_MASK (SLAB_RED_ZONE | \
69830+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
69831 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
69832 SLAB_CACHE_DMA | \
69833 SLAB_STORE_USER | \
69834@@ -182,7 +182,7 @@
69835 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
69836 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
69837 #else
69838-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
69839+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
69840 SLAB_CACHE_DMA | \
69841 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
69842 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
69843@@ -308,7 +308,7 @@ struct kmem_list3 {
69844 * Need this for bootstrapping a per node allocator.
69845 */
69846 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
69847-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
69848+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
69849 #define CACHE_CACHE 0
69850 #define SIZE_AC MAX_NUMNODES
69851 #define SIZE_L3 (2 * MAX_NUMNODES)
69852@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_
69853 if ((x)->max_freeable < i) \
69854 (x)->max_freeable = i; \
69855 } while (0)
69856-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
69857-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
69858-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
69859-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
69860+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
69861+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
69862+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
69863+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
69864 #else
69865 #define STATS_INC_ACTIVE(x) do { } while (0)
69866 #define STATS_DEC_ACTIVE(x) do { } while (0)
69867@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct
69868 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
69869 */
69870 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
69871- const struct slab *slab, void *obj)
69872+ const struct slab *slab, const void *obj)
69873 {
69874 u32 offset = (obj - slab->s_mem);
69875 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
69876@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
69877 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
69878 sizes[INDEX_AC].cs_size,
69879 ARCH_KMALLOC_MINALIGN,
69880- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
69881+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
69882 NULL);
69883
69884 if (INDEX_AC != INDEX_L3) {
69885@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
69886 kmem_cache_create(names[INDEX_L3].name,
69887 sizes[INDEX_L3].cs_size,
69888 ARCH_KMALLOC_MINALIGN,
69889- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
69890+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
69891 NULL);
69892 }
69893
69894@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
69895 sizes->cs_cachep = kmem_cache_create(names->name,
69896 sizes->cs_size,
69897 ARCH_KMALLOC_MINALIGN,
69898- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
69899+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
69900 NULL);
69901 }
69902 #ifdef CONFIG_ZONE_DMA
69903@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, vo
69904 }
69905 /* cpu stats */
69906 {
69907- unsigned long allochit = atomic_read(&cachep->allochit);
69908- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
69909- unsigned long freehit = atomic_read(&cachep->freehit);
69910- unsigned long freemiss = atomic_read(&cachep->freemiss);
69911+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
69912+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
69913+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
69914+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
69915
69916 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
69917 allochit, allocmiss, freehit, freemiss);
69918@@ -4471,15 +4471,66 @@ static const struct file_operations proc
69919
69920 static int __init slab_proc_init(void)
69921 {
69922- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
69923+ mode_t gr_mode = S_IRUGO;
69924+
69925+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69926+ gr_mode = S_IRUSR;
69927+#endif
69928+
69929+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
69930 #ifdef CONFIG_DEBUG_SLAB_LEAK
69931- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
69932+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
69933 #endif
69934 return 0;
69935 }
69936 module_init(slab_proc_init);
69937 #endif
69938
69939+void check_object_size(const void *ptr, unsigned long n, bool to)
69940+{
69941+
69942+#ifdef CONFIG_PAX_USERCOPY
69943+ struct page *page;
69944+ struct kmem_cache *cachep = NULL;
69945+ struct slab *slabp;
69946+ unsigned int objnr;
69947+ unsigned long offset;
69948+
69949+ if (!n)
69950+ return;
69951+
69952+ if (ZERO_OR_NULL_PTR(ptr))
69953+ goto report;
69954+
69955+ if (!virt_addr_valid(ptr))
69956+ return;
69957+
69958+ page = virt_to_head_page(ptr);
69959+
69960+ if (!PageSlab(page)) {
69961+ if (object_is_on_stack(ptr, n) == -1)
69962+ goto report;
69963+ return;
69964+ }
69965+
69966+ cachep = page_get_cache(page);
69967+ if (!(cachep->flags & SLAB_USERCOPY))
69968+ goto report;
69969+
69970+ slabp = page_get_slab(page);
69971+ objnr = obj_to_index(cachep, slabp, ptr);
69972+ BUG_ON(objnr >= cachep->num);
69973+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
69974+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
69975+ return;
69976+
69977+report:
69978+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
69979+#endif
69980+
69981+}
69982+EXPORT_SYMBOL(check_object_size);
69983+
69984 /**
69985 * ksize - get the actual amount of memory allocated for a given object
69986 * @objp: Pointer to the object
69987diff -urNp linux-2.6.32.43/mm/slob.c linux-2.6.32.43/mm/slob.c
69988--- linux-2.6.32.43/mm/slob.c 2011-03-27 14:31:47.000000000 -0400
69989+++ linux-2.6.32.43/mm/slob.c 2011-07-06 19:53:33.000000000 -0400
69990@@ -29,7 +29,7 @@
69991 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
69992 * alloc_pages() directly, allocating compound pages so the page order
69993 * does not have to be separately tracked, and also stores the exact
69994- * allocation size in page->private so that it can be used to accurately
69995+ * allocation size in slob_page->size so that it can be used to accurately
69996 * provide ksize(). These objects are detected in kfree() because slob_page()
69997 * is false for them.
69998 *
69999@@ -58,6 +58,7 @@
70000 */
70001
70002 #include <linux/kernel.h>
70003+#include <linux/sched.h>
70004 #include <linux/slab.h>
70005 #include <linux/mm.h>
70006 #include <linux/swap.h> /* struct reclaim_state */
70007@@ -100,7 +101,8 @@ struct slob_page {
70008 unsigned long flags; /* mandatory */
70009 atomic_t _count; /* mandatory */
70010 slobidx_t units; /* free units left in page */
70011- unsigned long pad[2];
70012+ unsigned long pad[1];
70013+ unsigned long size; /* size when >=PAGE_SIZE */
70014 slob_t *free; /* first free slob_t in page */
70015 struct list_head list; /* linked list of free pages */
70016 };
70017@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
70018 */
70019 static inline int is_slob_page(struct slob_page *sp)
70020 {
70021- return PageSlab((struct page *)sp);
70022+ return PageSlab((struct page *)sp) && !sp->size;
70023 }
70024
70025 static inline void set_slob_page(struct slob_page *sp)
70026@@ -148,7 +150,7 @@ static inline void clear_slob_page(struc
70027
70028 static inline struct slob_page *slob_page(const void *addr)
70029 {
70030- return (struct slob_page *)virt_to_page(addr);
70031+ return (struct slob_page *)virt_to_head_page(addr);
70032 }
70033
70034 /*
70035@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_
70036 /*
70037 * Return the size of a slob block.
70038 */
70039-static slobidx_t slob_units(slob_t *s)
70040+static slobidx_t slob_units(const slob_t *s)
70041 {
70042 if (s->units > 0)
70043 return s->units;
70044@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
70045 /*
70046 * Return the next free slob block pointer after this one.
70047 */
70048-static slob_t *slob_next(slob_t *s)
70049+static slob_t *slob_next(const slob_t *s)
70050 {
70051 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
70052 slobidx_t next;
70053@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
70054 /*
70055 * Returns true if s is the last free block in its page.
70056 */
70057-static int slob_last(slob_t *s)
70058+static int slob_last(const slob_t *s)
70059 {
70060 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
70061 }
70062@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, i
70063 if (!page)
70064 return NULL;
70065
70066+ set_slob_page(page);
70067 return page_address(page);
70068 }
70069
70070@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp
70071 if (!b)
70072 return NULL;
70073 sp = slob_page(b);
70074- set_slob_page(sp);
70075
70076 spin_lock_irqsave(&slob_lock, flags);
70077 sp->units = SLOB_UNITS(PAGE_SIZE);
70078 sp->free = b;
70079+ sp->size = 0;
70080 INIT_LIST_HEAD(&sp->list);
70081 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
70082 set_slob_page_free(sp, slob_list);
70083@@ -475,10 +478,9 @@ out:
70084 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
70085 #endif
70086
70087-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70088+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
70089 {
70090- unsigned int *m;
70091- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70092+ slob_t *m;
70093 void *ret;
70094
70095 lockdep_trace_alloc(gfp);
70096@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t
70097
70098 if (!m)
70099 return NULL;
70100- *m = size;
70101+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
70102+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
70103+ m[0].units = size;
70104+ m[1].units = align;
70105 ret = (void *)m + align;
70106
70107 trace_kmalloc_node(_RET_IP_, ret,
70108@@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t
70109
70110 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
70111 if (ret) {
70112- struct page *page;
70113- page = virt_to_page(ret);
70114- page->private = size;
70115+ struct slob_page *sp;
70116+ sp = slob_page(ret);
70117+ sp->size = size;
70118 }
70119
70120 trace_kmalloc_node(_RET_IP_, ret,
70121 size, PAGE_SIZE << order, gfp, node);
70122 }
70123
70124- kmemleak_alloc(ret, size, 1, gfp);
70125+ return ret;
70126+}
70127+
70128+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
70129+{
70130+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70131+ void *ret = __kmalloc_node_align(size, gfp, node, align);
70132+
70133+ if (!ZERO_OR_NULL_PTR(ret))
70134+ kmemleak_alloc(ret, size, 1, gfp);
70135 return ret;
70136 }
70137 EXPORT_SYMBOL(__kmalloc_node);
70138@@ -528,13 +542,88 @@ void kfree(const void *block)
70139 sp = slob_page(block);
70140 if (is_slob_page(sp)) {
70141 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70142- unsigned int *m = (unsigned int *)(block - align);
70143- slob_free(m, *m + align);
70144- } else
70145+ slob_t *m = (slob_t *)(block - align);
70146+ slob_free(m, m[0].units + align);
70147+ } else {
70148+ clear_slob_page(sp);
70149+ free_slob_page(sp);
70150+ sp->size = 0;
70151 put_page(&sp->page);
70152+ }
70153 }
70154 EXPORT_SYMBOL(kfree);
70155
70156+void check_object_size(const void *ptr, unsigned long n, bool to)
70157+{
70158+
70159+#ifdef CONFIG_PAX_USERCOPY
70160+ struct slob_page *sp;
70161+ const slob_t *free;
70162+ const void *base;
70163+ unsigned long flags;
70164+
70165+ if (!n)
70166+ return;
70167+
70168+ if (ZERO_OR_NULL_PTR(ptr))
70169+ goto report;
70170+
70171+ if (!virt_addr_valid(ptr))
70172+ return;
70173+
70174+ sp = slob_page(ptr);
70175+ if (!PageSlab((struct page*)sp)) {
70176+ if (object_is_on_stack(ptr, n) == -1)
70177+ goto report;
70178+ return;
70179+ }
70180+
70181+ if (sp->size) {
70182+ base = page_address(&sp->page);
70183+ if (base <= ptr && n <= sp->size - (ptr - base))
70184+ return;
70185+ goto report;
70186+ }
70187+
70188+ /* some tricky double walking to find the chunk */
70189+ spin_lock_irqsave(&slob_lock, flags);
70190+ base = (void *)((unsigned long)ptr & PAGE_MASK);
70191+ free = sp->free;
70192+
70193+ while (!slob_last(free) && (void *)free <= ptr) {
70194+ base = free + slob_units(free);
70195+ free = slob_next(free);
70196+ }
70197+
70198+ while (base < (void *)free) {
70199+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
70200+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
70201+ int offset;
70202+
70203+ if (ptr < base + align)
70204+ break;
70205+
70206+ offset = ptr - base - align;
70207+ if (offset >= m) {
70208+ base += size;
70209+ continue;
70210+ }
70211+
70212+ if (n > m - offset)
70213+ break;
70214+
70215+ spin_unlock_irqrestore(&slob_lock, flags);
70216+ return;
70217+ }
70218+
70219+ spin_unlock_irqrestore(&slob_lock, flags);
70220+report:
70221+ pax_report_usercopy(ptr, n, to, NULL);
70222+#endif
70223+
70224+}
70225+EXPORT_SYMBOL(check_object_size);
70226+
70227 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
70228 size_t ksize(const void *block)
70229 {
70230@@ -547,10 +636,10 @@ size_t ksize(const void *block)
70231 sp = slob_page(block);
70232 if (is_slob_page(sp)) {
70233 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
70234- unsigned int *m = (unsigned int *)(block - align);
70235- return SLOB_UNITS(*m) * SLOB_UNIT;
70236+ slob_t *m = (slob_t *)(block - align);
70237+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
70238 } else
70239- return sp->page.private;
70240+ return sp->size;
70241 }
70242 EXPORT_SYMBOL(ksize);
70243
70244@@ -566,8 +655,13 @@ struct kmem_cache *kmem_cache_create(con
70245 {
70246 struct kmem_cache *c;
70247
70248+#ifdef CONFIG_PAX_USERCOPY
70249+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
70250+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
70251+#else
70252 c = slob_alloc(sizeof(struct kmem_cache),
70253 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
70254+#endif
70255
70256 if (c) {
70257 c->name = name;
70258@@ -605,17 +699,25 @@ void *kmem_cache_alloc_node(struct kmem_
70259 {
70260 void *b;
70261
70262+#ifdef CONFIG_PAX_USERCOPY
70263+ b = __kmalloc_node_align(c->size, flags, node, c->align);
70264+#else
70265 if (c->size < PAGE_SIZE) {
70266 b = slob_alloc(c->size, flags, c->align, node);
70267 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
70268 SLOB_UNITS(c->size) * SLOB_UNIT,
70269 flags, node);
70270 } else {
70271+ struct slob_page *sp;
70272+
70273 b = slob_new_pages(flags, get_order(c->size), node);
70274+ sp = slob_page(b);
70275+ sp->size = c->size;
70276 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
70277 PAGE_SIZE << get_order(c->size),
70278 flags, node);
70279 }
70280+#endif
70281
70282 if (c->ctor)
70283 c->ctor(b);
70284@@ -627,10 +729,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
70285
70286 static void __kmem_cache_free(void *b, int size)
70287 {
70288- if (size < PAGE_SIZE)
70289+ struct slob_page *sp = slob_page(b);
70290+
70291+ if (is_slob_page(sp))
70292 slob_free(b, size);
70293- else
70294+ else {
70295+ clear_slob_page(sp);
70296+ free_slob_page(sp);
70297+ sp->size = 0;
70298 slob_free_pages(b, get_order(size));
70299+ }
70300 }
70301
70302 static void kmem_rcu_free(struct rcu_head *head)
70303@@ -643,18 +751,32 @@ static void kmem_rcu_free(struct rcu_hea
70304
70305 void kmem_cache_free(struct kmem_cache *c, void *b)
70306 {
70307+ int size = c->size;
70308+
70309+#ifdef CONFIG_PAX_USERCOPY
70310+ if (size + c->align < PAGE_SIZE) {
70311+ size += c->align;
70312+ b -= c->align;
70313+ }
70314+#endif
70315+
70316 kmemleak_free_recursive(b, c->flags);
70317 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
70318 struct slob_rcu *slob_rcu;
70319- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
70320+ slob_rcu = b + (size - sizeof(struct slob_rcu));
70321 INIT_RCU_HEAD(&slob_rcu->head);
70322- slob_rcu->size = c->size;
70323+ slob_rcu->size = size;
70324 call_rcu(&slob_rcu->head, kmem_rcu_free);
70325 } else {
70326- __kmem_cache_free(b, c->size);
70327+ __kmem_cache_free(b, size);
70328 }
70329
70330+#ifdef CONFIG_PAX_USERCOPY
70331+ trace_kfree(_RET_IP_, b);
70332+#else
70333 trace_kmem_cache_free(_RET_IP_, b);
70334+#endif
70335+
70336 }
70337 EXPORT_SYMBOL(kmem_cache_free);
70338
70339diff -urNp linux-2.6.32.43/mm/slub.c linux-2.6.32.43/mm/slub.c
70340--- linux-2.6.32.43/mm/slub.c 2011-03-27 14:31:47.000000000 -0400
70341+++ linux-2.6.32.43/mm/slub.c 2011-04-17 15:56:46.000000000 -0400
70342@@ -410,7 +410,7 @@ static void print_track(const char *s, s
70343 if (!t->addr)
70344 return;
70345
70346- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
70347+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
70348 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
70349 }
70350
70351@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *
70352
70353 page = virt_to_head_page(x);
70354
70355+ BUG_ON(!PageSlab(page));
70356+
70357 slab_free(s, page, x, _RET_IP_);
70358
70359 trace_kmem_cache_free(_RET_IP_, x);
70360@@ -1937,7 +1939,7 @@ static int slub_min_objects;
70361 * Merge control. If this is set then no merging of slab caches will occur.
70362 * (Could be removed. This was introduced to pacify the merge skeptics.)
70363 */
70364-static int slub_nomerge;
70365+static int slub_nomerge = 1;
70366
70367 /*
70368 * Calculate the order of allocation given an slab object size.
70369@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_c
70370 * list to avoid pounding the page allocator excessively.
70371 */
70372 set_min_partial(s, ilog2(s->size));
70373- s->refcount = 1;
70374+ atomic_set(&s->refcount, 1);
70375 #ifdef CONFIG_NUMA
70376 s->remote_node_defrag_ratio = 1000;
70377 #endif
70378@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struc
70379 void kmem_cache_destroy(struct kmem_cache *s)
70380 {
70381 down_write(&slub_lock);
70382- s->refcount--;
70383- if (!s->refcount) {
70384+ if (atomic_dec_and_test(&s->refcount)) {
70385 list_del(&s->list);
70386 up_write(&slub_lock);
70387 if (kmem_cache_close(s)) {
70388@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(cha
70389 __setup("slub_nomerge", setup_slub_nomerge);
70390
70391 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
70392- const char *name, int size, gfp_t gfp_flags)
70393+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
70394 {
70395- unsigned int flags = 0;
70396-
70397 if (gfp_flags & SLUB_DMA)
70398- flags = SLAB_CACHE_DMA;
70399+ flags |= SLAB_CACHE_DMA;
70400
70401 /*
70402 * This function is called with IRQs disabled during early-boot on
70403@@ -2915,6 +2914,46 @@ void *__kmalloc_node(size_t size, gfp_t
70404 EXPORT_SYMBOL(__kmalloc_node);
70405 #endif
70406
70407+void check_object_size(const void *ptr, unsigned long n, bool to)
70408+{
70409+
70410+#ifdef CONFIG_PAX_USERCOPY
70411+ struct page *page;
70412+ struct kmem_cache *s = NULL;
70413+ unsigned long offset;
70414+
70415+ if (!n)
70416+ return;
70417+
70418+ if (ZERO_OR_NULL_PTR(ptr))
70419+ goto report;
70420+
70421+ if (!virt_addr_valid(ptr))
70422+ return;
70423+
70424+ page = get_object_page(ptr);
70425+
70426+ if (!page) {
70427+ if (object_is_on_stack(ptr, n) == -1)
70428+ goto report;
70429+ return;
70430+ }
70431+
70432+ s = page->slab;
70433+ if (!(s->flags & SLAB_USERCOPY))
70434+ goto report;
70435+
70436+ offset = (ptr - page_address(page)) % s->size;
70437+ if (offset <= s->objsize && n <= s->objsize - offset)
70438+ return;
70439+
70440+report:
70441+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
70442+#endif
70443+
70444+}
70445+EXPORT_SYMBOL(check_object_size);
70446+
70447 size_t ksize(const void *object)
70448 {
70449 struct page *page;
70450@@ -3185,8 +3224,8 @@ void __init kmem_cache_init(void)
70451 * kmem_cache_open for slab_state == DOWN.
70452 */
70453 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
70454- sizeof(struct kmem_cache_node), GFP_NOWAIT);
70455- kmalloc_caches[0].refcount = -1;
70456+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
70457+ atomic_set(&kmalloc_caches[0].refcount, -1);
70458 caches++;
70459
70460 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
70461@@ -3198,18 +3237,18 @@ void __init kmem_cache_init(void)
70462 /* Caches that are not of the two-to-the-power-of size */
70463 if (KMALLOC_MIN_SIZE <= 32) {
70464 create_kmalloc_cache(&kmalloc_caches[1],
70465- "kmalloc-96", 96, GFP_NOWAIT);
70466+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
70467 caches++;
70468 }
70469 if (KMALLOC_MIN_SIZE <= 64) {
70470 create_kmalloc_cache(&kmalloc_caches[2],
70471- "kmalloc-192", 192, GFP_NOWAIT);
70472+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
70473 caches++;
70474 }
70475
70476 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
70477 create_kmalloc_cache(&kmalloc_caches[i],
70478- "kmalloc", 1 << i, GFP_NOWAIT);
70479+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
70480 caches++;
70481 }
70482
70483@@ -3293,7 +3332,7 @@ static int slab_unmergeable(struct kmem_
70484 /*
70485 * We may have set a slab to be unmergeable during bootstrap.
70486 */
70487- if (s->refcount < 0)
70488+ if (atomic_read(&s->refcount) < 0)
70489 return 1;
70490
70491 return 0;
70492@@ -3353,7 +3392,7 @@ struct kmem_cache *kmem_cache_create(con
70493 if (s) {
70494 int cpu;
70495
70496- s->refcount++;
70497+ atomic_inc(&s->refcount);
70498 /*
70499 * Adjust the object sizes so that we clear
70500 * the complete object on kzalloc.
70501@@ -3372,7 +3411,7 @@ struct kmem_cache *kmem_cache_create(con
70502
70503 if (sysfs_slab_alias(s, name)) {
70504 down_write(&slub_lock);
70505- s->refcount--;
70506+ atomic_dec(&s->refcount);
70507 up_write(&slub_lock);
70508 goto err;
70509 }
70510@@ -4101,7 +4140,7 @@ SLAB_ATTR_RO(ctor);
70511
70512 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
70513 {
70514- return sprintf(buf, "%d\n", s->refcount - 1);
70515+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
70516 }
70517 SLAB_ATTR_RO(aliases);
70518
70519@@ -4503,7 +4542,7 @@ static void kmem_cache_release(struct ko
70520 kfree(s);
70521 }
70522
70523-static struct sysfs_ops slab_sysfs_ops = {
70524+static const struct sysfs_ops slab_sysfs_ops = {
70525 .show = slab_attr_show,
70526 .store = slab_attr_store,
70527 };
70528@@ -4522,7 +4561,7 @@ static int uevent_filter(struct kset *ks
70529 return 0;
70530 }
70531
70532-static struct kset_uevent_ops slab_uevent_ops = {
70533+static const struct kset_uevent_ops slab_uevent_ops = {
70534 .filter = uevent_filter,
70535 };
70536
70537@@ -4785,7 +4824,13 @@ static const struct file_operations proc
70538
70539 static int __init slab_proc_init(void)
70540 {
70541- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
70542+ mode_t gr_mode = S_IRUGO;
70543+
70544+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70545+ gr_mode = S_IRUSR;
70546+#endif
70547+
70548+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
70549 return 0;
70550 }
70551 module_init(slab_proc_init);
70552diff -urNp linux-2.6.32.43/mm/swap.c linux-2.6.32.43/mm/swap.c
70553--- linux-2.6.32.43/mm/swap.c 2011-03-27 14:31:47.000000000 -0400
70554+++ linux-2.6.32.43/mm/swap.c 2011-07-09 09:15:19.000000000 -0400
70555@@ -30,6 +30,7 @@
70556 #include <linux/notifier.h>
70557 #include <linux/backing-dev.h>
70558 #include <linux/memcontrol.h>
70559+#include <linux/hugetlb.h>
70560
70561 #include "internal.h"
70562
70563@@ -65,6 +66,8 @@ static void put_compound_page(struct pag
70564 compound_page_dtor *dtor;
70565
70566 dtor = get_compound_page_dtor(page);
70567+ if (!PageHuge(page))
70568+ BUG_ON(dtor != free_compound_page);
70569 (*dtor)(page);
70570 }
70571 }
70572diff -urNp linux-2.6.32.43/mm/util.c linux-2.6.32.43/mm/util.c
70573--- linux-2.6.32.43/mm/util.c 2011-03-27 14:31:47.000000000 -0400
70574+++ linux-2.6.32.43/mm/util.c 2011-04-17 15:56:46.000000000 -0400
70575@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
70576 void arch_pick_mmap_layout(struct mm_struct *mm)
70577 {
70578 mm->mmap_base = TASK_UNMAPPED_BASE;
70579+
70580+#ifdef CONFIG_PAX_RANDMMAP
70581+ if (mm->pax_flags & MF_PAX_RANDMMAP)
70582+ mm->mmap_base += mm->delta_mmap;
70583+#endif
70584+
70585 mm->get_unmapped_area = arch_get_unmapped_area;
70586 mm->unmap_area = arch_unmap_area;
70587 }
70588diff -urNp linux-2.6.32.43/mm/vmalloc.c linux-2.6.32.43/mm/vmalloc.c
70589--- linux-2.6.32.43/mm/vmalloc.c 2011-03-27 14:31:47.000000000 -0400
70590+++ linux-2.6.32.43/mm/vmalloc.c 2011-04-17 15:56:46.000000000 -0400
70591@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd,
70592
70593 pte = pte_offset_kernel(pmd, addr);
70594 do {
70595- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
70596- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
70597+
70598+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70599+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
70600+ BUG_ON(!pte_exec(*pte));
70601+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
70602+ continue;
70603+ }
70604+#endif
70605+
70606+ {
70607+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
70608+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
70609+ }
70610 } while (pte++, addr += PAGE_SIZE, addr != end);
70611 }
70612
70613@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, un
70614 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
70615 {
70616 pte_t *pte;
70617+ int ret = -ENOMEM;
70618
70619 /*
70620 * nr is a running index into the array which helps higher level
70621@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, un
70622 pte = pte_alloc_kernel(pmd, addr);
70623 if (!pte)
70624 return -ENOMEM;
70625+
70626+ pax_open_kernel();
70627 do {
70628 struct page *page = pages[*nr];
70629
70630- if (WARN_ON(!pte_none(*pte)))
70631- return -EBUSY;
70632- if (WARN_ON(!page))
70633- return -ENOMEM;
70634+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70635+ if (!(pgprot_val(prot) & _PAGE_NX))
70636+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
70637+ else
70638+#endif
70639+
70640+ if (WARN_ON(!pte_none(*pte))) {
70641+ ret = -EBUSY;
70642+ goto out;
70643+ }
70644+ if (WARN_ON(!page)) {
70645+ ret = -ENOMEM;
70646+ goto out;
70647+ }
70648 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
70649 (*nr)++;
70650 } while (pte++, addr += PAGE_SIZE, addr != end);
70651- return 0;
70652+ ret = 0;
70653+out:
70654+ pax_close_kernel();
70655+ return ret;
70656 }
70657
70658 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
70659@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void
70660 * and fall back on vmalloc() if that fails. Others
70661 * just put it in the vmalloc space.
70662 */
70663-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
70664+#ifdef CONFIG_MODULES
70665+#ifdef MODULES_VADDR
70666 unsigned long addr = (unsigned long)x;
70667 if (addr >= MODULES_VADDR && addr < MODULES_END)
70668 return 1;
70669 #endif
70670+
70671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70672+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
70673+ return 1;
70674+#endif
70675+
70676+#endif
70677+
70678 return is_vmalloc_addr(x);
70679 }
70680
70681@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void
70682
70683 if (!pgd_none(*pgd)) {
70684 pud_t *pud = pud_offset(pgd, addr);
70685+#ifdef CONFIG_X86
70686+ if (!pud_large(*pud))
70687+#endif
70688 if (!pud_none(*pud)) {
70689 pmd_t *pmd = pmd_offset(pud, addr);
70690+#ifdef CONFIG_X86
70691+ if (!pmd_large(*pmd))
70692+#endif
70693 if (!pmd_none(*pmd)) {
70694 pte_t *ptep, pte;
70695
70696@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vm
70697 struct rb_node *tmp;
70698
70699 while (*p) {
70700- struct vmap_area *tmp;
70701+ struct vmap_area *varea;
70702
70703 parent = *p;
70704- tmp = rb_entry(parent, struct vmap_area, rb_node);
70705- if (va->va_start < tmp->va_end)
70706+ varea = rb_entry(parent, struct vmap_area, rb_node);
70707+ if (va->va_start < varea->va_end)
70708 p = &(*p)->rb_left;
70709- else if (va->va_end > tmp->va_start)
70710+ else if (va->va_end > varea->va_start)
70711 p = &(*p)->rb_right;
70712 else
70713 BUG();
70714@@ -1232,6 +1274,16 @@ static struct vm_struct *__get_vm_area_n
70715 struct vm_struct *area;
70716
70717 BUG_ON(in_interrupt());
70718+
70719+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70720+ if (flags & VM_KERNEXEC) {
70721+ if (start != VMALLOC_START || end != VMALLOC_END)
70722+ return NULL;
70723+ start = (unsigned long)MODULES_EXEC_VADDR;
70724+ end = (unsigned long)MODULES_EXEC_END;
70725+ }
70726+#endif
70727+
70728 if (flags & VM_IOREMAP) {
70729 int bit = fls(size);
70730
70731@@ -1457,6 +1509,11 @@ void *vmap(struct page **pages, unsigned
70732 if (count > totalram_pages)
70733 return NULL;
70734
70735+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70736+ if (!(pgprot_val(prot) & _PAGE_NX))
70737+ flags |= VM_KERNEXEC;
70738+#endif
70739+
70740 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
70741 __builtin_return_address(0));
70742 if (!area)
70743@@ -1567,6 +1624,13 @@ static void *__vmalloc_node(unsigned lon
70744 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
70745 return NULL;
70746
70747+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70748+ if (!(pgprot_val(prot) & _PAGE_NX))
70749+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
70750+ node, gfp_mask, caller);
70751+ else
70752+#endif
70753+
70754 area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
70755 VMALLOC_END, node, gfp_mask, caller);
70756
70757@@ -1585,6 +1649,7 @@ static void *__vmalloc_node(unsigned lon
70758 return addr;
70759 }
70760
70761+#undef __vmalloc
70762 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
70763 {
70764 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
70765@@ -1601,6 +1666,7 @@ EXPORT_SYMBOL(__vmalloc);
70766 * For tight control over page level allocator and protection flags
70767 * use __vmalloc() instead.
70768 */
70769+#undef vmalloc
70770 void *vmalloc(unsigned long size)
70771 {
70772 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
70773@@ -1615,6 +1681,7 @@ EXPORT_SYMBOL(vmalloc);
70774 * The resulting memory area is zeroed so it can be mapped to userspace
70775 * without leaking data.
70776 */
70777+#undef vmalloc_user
70778 void *vmalloc_user(unsigned long size)
70779 {
70780 struct vm_struct *area;
70781@@ -1642,6 +1709,7 @@ EXPORT_SYMBOL(vmalloc_user);
70782 * For tight control over page level allocator and protection flags
70783 * use __vmalloc() instead.
70784 */
70785+#undef vmalloc_node
70786 void *vmalloc_node(unsigned long size, int node)
70787 {
70788 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
70789@@ -1664,10 +1732,10 @@ EXPORT_SYMBOL(vmalloc_node);
70790 * For tight control over page level allocator and protection flags
70791 * use __vmalloc() instead.
70792 */
70793-
70794+#undef vmalloc_exec
70795 void *vmalloc_exec(unsigned long size)
70796 {
70797- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
70798+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
70799 -1, __builtin_return_address(0));
70800 }
70801
70802@@ -1686,6 +1754,7 @@ void *vmalloc_exec(unsigned long size)
70803 * Allocate enough 32bit PA addressable pages to cover @size from the
70804 * page level allocator and map them into contiguous kernel virtual space.
70805 */
70806+#undef vmalloc_32
70807 void *vmalloc_32(unsigned long size)
70808 {
70809 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
70810@@ -1700,6 +1769,7 @@ EXPORT_SYMBOL(vmalloc_32);
70811 * The resulting memory area is 32bit addressable and zeroed so it can be
70812 * mapped to userspace without leaking data.
70813 */
70814+#undef vmalloc_32_user
70815 void *vmalloc_32_user(unsigned long size)
70816 {
70817 struct vm_struct *area;
70818@@ -1964,6 +2034,8 @@ int remap_vmalloc_range(struct vm_area_s
70819 unsigned long uaddr = vma->vm_start;
70820 unsigned long usize = vma->vm_end - vma->vm_start;
70821
70822+ BUG_ON(vma->vm_mirror);
70823+
70824 if ((PAGE_SIZE-1) & (unsigned long)addr)
70825 return -EINVAL;
70826
70827diff -urNp linux-2.6.32.43/mm/vmstat.c linux-2.6.32.43/mm/vmstat.c
70828--- linux-2.6.32.43/mm/vmstat.c 2011-03-27 14:31:47.000000000 -0400
70829+++ linux-2.6.32.43/mm/vmstat.c 2011-04-17 15:56:46.000000000 -0400
70830@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
70831 *
70832 * vm_stat contains the global counters
70833 */
70834-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70835+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70836 EXPORT_SYMBOL(vm_stat);
70837
70838 #ifdef CONFIG_SMP
70839@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
70840 v = p->vm_stat_diff[i];
70841 p->vm_stat_diff[i] = 0;
70842 local_irq_restore(flags);
70843- atomic_long_add(v, &zone->vm_stat[i]);
70844+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
70845 global_diff[i] += v;
70846 #ifdef CONFIG_NUMA
70847 /* 3 seconds idle till flush */
70848@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
70849
70850 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
70851 if (global_diff[i])
70852- atomic_long_add(global_diff[i], &vm_stat[i]);
70853+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
70854 }
70855
70856 #endif
70857@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
70858 start_cpu_timer(cpu);
70859 #endif
70860 #ifdef CONFIG_PROC_FS
70861- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
70862- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
70863- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
70864- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
70865+ {
70866+ mode_t gr_mode = S_IRUGO;
70867+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70868+ gr_mode = S_IRUSR;
70869+#endif
70870+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
70871+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
70872+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
70873+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
70874+#else
70875+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
70876+#endif
70877+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
70878+ }
70879 #endif
70880 return 0;
70881 }
70882diff -urNp linux-2.6.32.43/net/8021q/vlan.c linux-2.6.32.43/net/8021q/vlan.c
70883--- linux-2.6.32.43/net/8021q/vlan.c 2011-03-27 14:31:47.000000000 -0400
70884+++ linux-2.6.32.43/net/8021q/vlan.c 2011-04-17 15:56:46.000000000 -0400
70885@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net
70886 err = -EPERM;
70887 if (!capable(CAP_NET_ADMIN))
70888 break;
70889- if ((args.u.name_type >= 0) &&
70890- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
70891+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
70892 struct vlan_net *vn;
70893
70894 vn = net_generic(net, vlan_net_id);
70895diff -urNp linux-2.6.32.43/net/atm/atm_misc.c linux-2.6.32.43/net/atm/atm_misc.c
70896--- linux-2.6.32.43/net/atm/atm_misc.c 2011-03-27 14:31:47.000000000 -0400
70897+++ linux-2.6.32.43/net/atm/atm_misc.c 2011-04-17 15:56:46.000000000 -0400
70898@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int t
70899 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
70900 return 1;
70901 atm_return(vcc,truesize);
70902- atomic_inc(&vcc->stats->rx_drop);
70903+ atomic_inc_unchecked(&vcc->stats->rx_drop);
70904 return 0;
70905 }
70906
70907@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct
70908 }
70909 }
70910 atm_return(vcc,guess);
70911- atomic_inc(&vcc->stats->rx_drop);
70912+ atomic_inc_unchecked(&vcc->stats->rx_drop);
70913 return NULL;
70914 }
70915
70916@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafpr
70917
70918 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
70919 {
70920-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
70921+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
70922 __SONET_ITEMS
70923 #undef __HANDLE_ITEM
70924 }
70925@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_sta
70926
70927 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
70928 {
70929-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
70930+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
70931 __SONET_ITEMS
70932 #undef __HANDLE_ITEM
70933 }
70934diff -urNp linux-2.6.32.43/net/atm/lec.h linux-2.6.32.43/net/atm/lec.h
70935--- linux-2.6.32.43/net/atm/lec.h 2011-03-27 14:31:47.000000000 -0400
70936+++ linux-2.6.32.43/net/atm/lec.h 2011-08-05 20:33:55.000000000 -0400
70937@@ -48,7 +48,7 @@ struct lane2_ops {
70938 const u8 *tlvs, u32 sizeoftlvs);
70939 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
70940 const u8 *tlvs, u32 sizeoftlvs);
70941-};
70942+} __no_const;
70943
70944 /*
70945 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
70946diff -urNp linux-2.6.32.43/net/atm/mpc.c linux-2.6.32.43/net/atm/mpc.c
70947--- linux-2.6.32.43/net/atm/mpc.c 2011-03-27 14:31:47.000000000 -0400
70948+++ linux-2.6.32.43/net/atm/mpc.c 2011-08-05 20:33:55.000000000 -0400
70949@@ -291,8 +291,8 @@ static void start_mpc(struct mpoa_client
70950 printk("mpoa: (%s) start_mpc not starting\n", dev->name);
70951 else {
70952 mpc->old_ops = dev->netdev_ops;
70953- mpc->new_ops = *mpc->old_ops;
70954- mpc->new_ops.ndo_start_xmit = mpc_send_packet;
70955+ memcpy((void *)&mpc->new_ops, mpc->old_ops, sizeof(mpc->new_ops));
70956+ *(void **)&mpc->new_ops.ndo_start_xmit = mpc_send_packet;
70957 dev->netdev_ops = &mpc->new_ops;
70958 }
70959 }
70960diff -urNp linux-2.6.32.43/net/atm/mpoa_caches.c linux-2.6.32.43/net/atm/mpoa_caches.c
70961--- linux-2.6.32.43/net/atm/mpoa_caches.c 2011-03-27 14:31:47.000000000 -0400
70962+++ linux-2.6.32.43/net/atm/mpoa_caches.c 2011-05-16 21:46:57.000000000 -0400
70963@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_cl
70964 struct timeval now;
70965 struct k_message msg;
70966
70967+ pax_track_stack();
70968+
70969 do_gettimeofday(&now);
70970
70971 write_lock_irq(&client->egress_lock);
70972diff -urNp linux-2.6.32.43/net/atm/proc.c linux-2.6.32.43/net/atm/proc.c
70973--- linux-2.6.32.43/net/atm/proc.c 2011-03-27 14:31:47.000000000 -0400
70974+++ linux-2.6.32.43/net/atm/proc.c 2011-04-17 15:56:46.000000000 -0400
70975@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *s
70976 const struct k_atm_aal_stats *stats)
70977 {
70978 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
70979- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
70980- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
70981- atomic_read(&stats->rx_drop));
70982+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
70983+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
70984+ atomic_read_unchecked(&stats->rx_drop));
70985 }
70986
70987 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
70988@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *se
70989 {
70990 struct sock *sk = sk_atm(vcc);
70991
70992+#ifdef CONFIG_GRKERNSEC_HIDESYM
70993+ seq_printf(seq, "%p ", NULL);
70994+#else
70995 seq_printf(seq, "%p ", vcc);
70996+#endif
70997+
70998 if (!vcc->dev)
70999 seq_printf(seq, "Unassigned ");
71000 else
71001@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *se
71002 {
71003 if (!vcc->dev)
71004 seq_printf(seq, sizeof(void *) == 4 ?
71005+#ifdef CONFIG_GRKERNSEC_HIDESYM
71006+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
71007+#else
71008 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
71009+#endif
71010 else
71011 seq_printf(seq, "%3d %3d %5d ",
71012 vcc->dev->number, vcc->vpi, vcc->vci);
71013diff -urNp linux-2.6.32.43/net/atm/resources.c linux-2.6.32.43/net/atm/resources.c
71014--- linux-2.6.32.43/net/atm/resources.c 2011-03-27 14:31:47.000000000 -0400
71015+++ linux-2.6.32.43/net/atm/resources.c 2011-04-17 15:56:46.000000000 -0400
71016@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *
71017 static void copy_aal_stats(struct k_atm_aal_stats *from,
71018 struct atm_aal_stats *to)
71019 {
71020-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
71021+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
71022 __AAL_STAT_ITEMS
71023 #undef __HANDLE_ITEM
71024 }
71025@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_
71026 static void subtract_aal_stats(struct k_atm_aal_stats *from,
71027 struct atm_aal_stats *to)
71028 {
71029-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
71030+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
71031 __AAL_STAT_ITEMS
71032 #undef __HANDLE_ITEM
71033 }
71034diff -urNp linux-2.6.32.43/net/bluetooth/l2cap.c linux-2.6.32.43/net/bluetooth/l2cap.c
71035--- linux-2.6.32.43/net/bluetooth/l2cap.c 2011-03-27 14:31:47.000000000 -0400
71036+++ linux-2.6.32.43/net/bluetooth/l2cap.c 2011-06-25 14:36:21.000000000 -0400
71037@@ -1885,7 +1885,7 @@ static int l2cap_sock_getsockopt_old(str
71038 err = -ENOTCONN;
71039 break;
71040 }
71041-
71042+ memset(&cinfo, 0, sizeof(cinfo));
71043 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle;
71044 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3);
71045
71046@@ -2719,7 +2719,7 @@ static inline int l2cap_config_req(struc
71047
71048 /* Reject if config buffer is too small. */
71049 len = cmd_len - sizeof(*req);
71050- if (l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
71051+ if (len < 0 || l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
71052 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
71053 l2cap_build_conf_rsp(sk, rsp,
71054 L2CAP_CONF_REJECT, flags), rsp);
71055diff -urNp linux-2.6.32.43/net/bluetooth/rfcomm/sock.c linux-2.6.32.43/net/bluetooth/rfcomm/sock.c
71056--- linux-2.6.32.43/net/bluetooth/rfcomm/sock.c 2011-03-27 14:31:47.000000000 -0400
71057+++ linux-2.6.32.43/net/bluetooth/rfcomm/sock.c 2011-06-12 06:35:00.000000000 -0400
71058@@ -878,6 +878,7 @@ static int rfcomm_sock_getsockopt_old(st
71059
71060 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
71061
71062+ memset(&cinfo, 0, sizeof(cinfo));
71063 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
71064 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
71065
71066diff -urNp linux-2.6.32.43/net/bridge/br_private.h linux-2.6.32.43/net/bridge/br_private.h
71067--- linux-2.6.32.43/net/bridge/br_private.h 2011-03-27 14:31:47.000000000 -0400
71068+++ linux-2.6.32.43/net/bridge/br_private.h 2011-04-17 15:56:46.000000000 -0400
71069@@ -254,7 +254,7 @@ extern void br_ifinfo_notify(int event,
71070
71071 #ifdef CONFIG_SYSFS
71072 /* br_sysfs_if.c */
71073-extern struct sysfs_ops brport_sysfs_ops;
71074+extern const struct sysfs_ops brport_sysfs_ops;
71075 extern int br_sysfs_addif(struct net_bridge_port *p);
71076
71077 /* br_sysfs_br.c */
71078diff -urNp linux-2.6.32.43/net/bridge/br_stp_if.c linux-2.6.32.43/net/bridge/br_stp_if.c
71079--- linux-2.6.32.43/net/bridge/br_stp_if.c 2011-03-27 14:31:47.000000000 -0400
71080+++ linux-2.6.32.43/net/bridge/br_stp_if.c 2011-04-17 15:56:46.000000000 -0400
71081@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
71082 char *envp[] = { NULL };
71083
71084 if (br->stp_enabled == BR_USER_STP) {
71085- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
71086+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
71087 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
71088 br->dev->name, r);
71089
71090diff -urNp linux-2.6.32.43/net/bridge/br_sysfs_if.c linux-2.6.32.43/net/bridge/br_sysfs_if.c
71091--- linux-2.6.32.43/net/bridge/br_sysfs_if.c 2011-03-27 14:31:47.000000000 -0400
71092+++ linux-2.6.32.43/net/bridge/br_sysfs_if.c 2011-04-17 15:56:46.000000000 -0400
71093@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobje
71094 return ret;
71095 }
71096
71097-struct sysfs_ops brport_sysfs_ops = {
71098+const struct sysfs_ops brport_sysfs_ops = {
71099 .show = brport_show,
71100 .store = brport_store,
71101 };
71102diff -urNp linux-2.6.32.43/net/bridge/netfilter/ebtables.c linux-2.6.32.43/net/bridge/netfilter/ebtables.c
71103--- linux-2.6.32.43/net/bridge/netfilter/ebtables.c 2011-04-17 17:00:52.000000000 -0400
71104+++ linux-2.6.32.43/net/bridge/netfilter/ebtables.c 2011-05-16 21:46:57.000000000 -0400
71105@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struc
71106 unsigned int entries_size, nentries;
71107 char *entries;
71108
71109+ pax_track_stack();
71110+
71111 if (cmd == EBT_SO_GET_ENTRIES) {
71112 entries_size = t->private->entries_size;
71113 nentries = t->private->nentries;
71114diff -urNp linux-2.6.32.43/net/can/bcm.c linux-2.6.32.43/net/can/bcm.c
71115--- linux-2.6.32.43/net/can/bcm.c 2011-05-10 22:12:01.000000000 -0400
71116+++ linux-2.6.32.43/net/can/bcm.c 2011-05-10 22:12:34.000000000 -0400
71117@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file
71118 struct bcm_sock *bo = bcm_sk(sk);
71119 struct bcm_op *op;
71120
71121+#ifdef CONFIG_GRKERNSEC_HIDESYM
71122+ seq_printf(m, ">>> socket %p", NULL);
71123+ seq_printf(m, " / sk %p", NULL);
71124+ seq_printf(m, " / bo %p", NULL);
71125+#else
71126 seq_printf(m, ">>> socket %p", sk->sk_socket);
71127 seq_printf(m, " / sk %p", sk);
71128 seq_printf(m, " / bo %p", bo);
71129+#endif
71130 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
71131 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
71132 seq_printf(m, " <<<\n");
71133diff -urNp linux-2.6.32.43/net/core/dev.c linux-2.6.32.43/net/core/dev.c
71134--- linux-2.6.32.43/net/core/dev.c 2011-04-17 17:00:52.000000000 -0400
71135+++ linux-2.6.32.43/net/core/dev.c 2011-08-05 20:33:55.000000000 -0400
71136@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const cha
71137 if (no_module && capable(CAP_NET_ADMIN))
71138 no_module = request_module("netdev-%s", name);
71139 if (no_module && capable(CAP_SYS_MODULE)) {
71140+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71141+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
71142+#else
71143 if (!request_module("%s", name))
71144 pr_err("Loading kernel module for a network device "
71145 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
71146 "instead\n", name);
71147+#endif
71148 }
71149 }
71150 EXPORT_SYMBOL(dev_load);
71151@@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct
71152
71153 struct dev_gso_cb {
71154 void (*destructor)(struct sk_buff *skb);
71155-};
71156+} __no_const;
71157
71158 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
71159
71160@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
71161 }
71162 EXPORT_SYMBOL(netif_rx_ni);
71163
71164-static void net_tx_action(struct softirq_action *h)
71165+static void net_tx_action(void)
71166 {
71167 struct softnet_data *sd = &__get_cpu_var(softnet_data);
71168
71169@@ -2826,7 +2830,7 @@ void netif_napi_del(struct napi_struct *
71170 EXPORT_SYMBOL(netif_napi_del);
71171
71172
71173-static void net_rx_action(struct softirq_action *h)
71174+static void net_rx_action(void)
71175 {
71176 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
71177 unsigned long time_limit = jiffies + 2;
71178diff -urNp linux-2.6.32.43/net/core/flow.c linux-2.6.32.43/net/core/flow.c
71179--- linux-2.6.32.43/net/core/flow.c 2011-03-27 14:31:47.000000000 -0400
71180+++ linux-2.6.32.43/net/core/flow.c 2011-05-04 17:56:20.000000000 -0400
71181@@ -35,11 +35,11 @@ struct flow_cache_entry {
71182 atomic_t *object_ref;
71183 };
71184
71185-atomic_t flow_cache_genid = ATOMIC_INIT(0);
71186+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
71187
71188 static u32 flow_hash_shift;
71189 #define flow_hash_size (1 << flow_hash_shift)
71190-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
71191+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
71192
71193 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
71194
71195@@ -52,7 +52,7 @@ struct flow_percpu_info {
71196 u32 hash_rnd;
71197 int count;
71198 };
71199-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
71200+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
71201
71202 #define flow_hash_rnd_recalc(cpu) \
71203 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
71204@@ -69,7 +69,7 @@ struct flow_flush_info {
71205 atomic_t cpuleft;
71206 struct completion completion;
71207 };
71208-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
71209+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
71210
71211 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
71212
71213@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net,
71214 if (fle->family == family &&
71215 fle->dir == dir &&
71216 flow_key_compare(key, &fle->key) == 0) {
71217- if (fle->genid == atomic_read(&flow_cache_genid)) {
71218+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
71219 void *ret = fle->object;
71220
71221 if (ret)
71222@@ -228,7 +228,7 @@ nocache:
71223 err = resolver(net, key, family, dir, &obj, &obj_ref);
71224
71225 if (fle && !err) {
71226- fle->genid = atomic_read(&flow_cache_genid);
71227+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
71228
71229 if (fle->object)
71230 atomic_dec(fle->object_ref);
71231@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(uns
71232
71233 fle = flow_table(cpu)[i];
71234 for (; fle; fle = fle->next) {
71235- unsigned genid = atomic_read(&flow_cache_genid);
71236+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
71237
71238 if (!fle->object || fle->genid == genid)
71239 continue;
71240diff -urNp linux-2.6.32.43/net/core/rtnetlink.c linux-2.6.32.43/net/core/rtnetlink.c
71241--- linux-2.6.32.43/net/core/rtnetlink.c 2011-03-27 14:31:47.000000000 -0400
71242+++ linux-2.6.32.43/net/core/rtnetlink.c 2011-08-05 20:33:55.000000000 -0400
71243@@ -57,7 +57,7 @@ struct rtnl_link
71244 {
71245 rtnl_doit_func doit;
71246 rtnl_dumpit_func dumpit;
71247-};
71248+} __no_const;
71249
71250 static DEFINE_MUTEX(rtnl_mutex);
71251
71252diff -urNp linux-2.6.32.43/net/core/skbuff.c linux-2.6.32.43/net/core/skbuff.c
71253--- linux-2.6.32.43/net/core/skbuff.c 2011-03-27 14:31:47.000000000 -0400
71254+++ linux-2.6.32.43/net/core/skbuff.c 2011-05-16 21:46:57.000000000 -0400
71255@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb,
71256 struct sk_buff *frag_iter;
71257 struct sock *sk = skb->sk;
71258
71259+ pax_track_stack();
71260+
71261 /*
71262 * __skb_splice_bits() only fails if the output has no room left,
71263 * so no point in going over the frag_list for the error case.
71264diff -urNp linux-2.6.32.43/net/core/sock.c linux-2.6.32.43/net/core/sock.c
71265--- linux-2.6.32.43/net/core/sock.c 2011-03-27 14:31:47.000000000 -0400
71266+++ linux-2.6.32.43/net/core/sock.c 2011-05-04 17:56:20.000000000 -0400
71267@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock,
71268 break;
71269
71270 case SO_PEERCRED:
71271+ {
71272+ struct ucred peercred;
71273 if (len > sizeof(sk->sk_peercred))
71274 len = sizeof(sk->sk_peercred);
71275- if (copy_to_user(optval, &sk->sk_peercred, len))
71276+ peercred = sk->sk_peercred;
71277+ if (copy_to_user(optval, &peercred, len))
71278 return -EFAULT;
71279 goto lenout;
71280+ }
71281
71282 case SO_PEERNAME:
71283 {
71284@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock,
71285 */
71286 smp_wmb();
71287 atomic_set(&sk->sk_refcnt, 1);
71288- atomic_set(&sk->sk_drops, 0);
71289+ atomic_set_unchecked(&sk->sk_drops, 0);
71290 }
71291 EXPORT_SYMBOL(sock_init_data);
71292
71293diff -urNp linux-2.6.32.43/net/decnet/sysctl_net_decnet.c linux-2.6.32.43/net/decnet/sysctl_net_decnet.c
71294--- linux-2.6.32.43/net/decnet/sysctl_net_decnet.c 2011-03-27 14:31:47.000000000 -0400
71295+++ linux-2.6.32.43/net/decnet/sysctl_net_decnet.c 2011-04-17 15:56:46.000000000 -0400
71296@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_t
71297
71298 if (len > *lenp) len = *lenp;
71299
71300- if (copy_to_user(buffer, addr, len))
71301+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
71302 return -EFAULT;
71303
71304 *lenp = len;
71305@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table
71306
71307 if (len > *lenp) len = *lenp;
71308
71309- if (copy_to_user(buffer, devname, len))
71310+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
71311 return -EFAULT;
71312
71313 *lenp = len;
71314diff -urNp linux-2.6.32.43/net/econet/Kconfig linux-2.6.32.43/net/econet/Kconfig
71315--- linux-2.6.32.43/net/econet/Kconfig 2011-03-27 14:31:47.000000000 -0400
71316+++ linux-2.6.32.43/net/econet/Kconfig 2011-04-17 15:56:46.000000000 -0400
71317@@ -4,7 +4,7 @@
71318
71319 config ECONET
71320 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
71321- depends on EXPERIMENTAL && INET
71322+ depends on EXPERIMENTAL && INET && BROKEN
71323 ---help---
71324 Econet is a fairly old and slow networking protocol mainly used by
71325 Acorn computers to access file and print servers. It uses native
71326diff -urNp linux-2.6.32.43/net/ieee802154/dgram.c linux-2.6.32.43/net/ieee802154/dgram.c
71327--- linux-2.6.32.43/net/ieee802154/dgram.c 2011-03-27 14:31:47.000000000 -0400
71328+++ linux-2.6.32.43/net/ieee802154/dgram.c 2011-05-04 17:56:28.000000000 -0400
71329@@ -318,7 +318,7 @@ out:
71330 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
71331 {
71332 if (sock_queue_rcv_skb(sk, skb) < 0) {
71333- atomic_inc(&sk->sk_drops);
71334+ atomic_inc_unchecked(&sk->sk_drops);
71335 kfree_skb(skb);
71336 return NET_RX_DROP;
71337 }
71338diff -urNp linux-2.6.32.43/net/ieee802154/raw.c linux-2.6.32.43/net/ieee802154/raw.c
71339--- linux-2.6.32.43/net/ieee802154/raw.c 2011-03-27 14:31:47.000000000 -0400
71340+++ linux-2.6.32.43/net/ieee802154/raw.c 2011-05-04 17:56:28.000000000 -0400
71341@@ -206,7 +206,7 @@ out:
71342 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
71343 {
71344 if (sock_queue_rcv_skb(sk, skb) < 0) {
71345- atomic_inc(&sk->sk_drops);
71346+ atomic_inc_unchecked(&sk->sk_drops);
71347 kfree_skb(skb);
71348 return NET_RX_DROP;
71349 }
71350diff -urNp linux-2.6.32.43/net/ipv4/inet_diag.c linux-2.6.32.43/net/ipv4/inet_diag.c
71351--- linux-2.6.32.43/net/ipv4/inet_diag.c 2011-07-13 17:23:04.000000000 -0400
71352+++ linux-2.6.32.43/net/ipv4/inet_diag.c 2011-06-20 19:31:13.000000000 -0400
71353@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct soc
71354 r->idiag_retrans = 0;
71355
71356 r->id.idiag_if = sk->sk_bound_dev_if;
71357+#ifdef CONFIG_GRKERNSEC_HIDESYM
71358+ r->id.idiag_cookie[0] = 0;
71359+ r->id.idiag_cookie[1] = 0;
71360+#else
71361 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
71362 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
71363+#endif
71364
71365 r->id.idiag_sport = inet->sport;
71366 r->id.idiag_dport = inet->dport;
71367@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct in
71368 r->idiag_family = tw->tw_family;
71369 r->idiag_retrans = 0;
71370 r->id.idiag_if = tw->tw_bound_dev_if;
71371+
71372+#ifdef CONFIG_GRKERNSEC_HIDESYM
71373+ r->id.idiag_cookie[0] = 0;
71374+ r->id.idiag_cookie[1] = 0;
71375+#else
71376 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
71377 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
71378+#endif
71379+
71380 r->id.idiag_sport = tw->tw_sport;
71381 r->id.idiag_dport = tw->tw_dport;
71382 r->id.idiag_src[0] = tw->tw_rcv_saddr;
71383@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk
71384 if (sk == NULL)
71385 goto unlock;
71386
71387+#ifndef CONFIG_GRKERNSEC_HIDESYM
71388 err = -ESTALE;
71389 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
71390 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
71391 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
71392 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
71393 goto out;
71394+#endif
71395
71396 err = -ENOMEM;
71397 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
71398@@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_
71399 r->idiag_retrans = req->retrans;
71400
71401 r->id.idiag_if = sk->sk_bound_dev_if;
71402+
71403+#ifdef CONFIG_GRKERNSEC_HIDESYM
71404+ r->id.idiag_cookie[0] = 0;
71405+ r->id.idiag_cookie[1] = 0;
71406+#else
71407 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
71408 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
71409+#endif
71410
71411 tmo = req->expires - jiffies;
71412 if (tmo < 0)
71413diff -urNp linux-2.6.32.43/net/ipv4/inet_hashtables.c linux-2.6.32.43/net/ipv4/inet_hashtables.c
71414--- linux-2.6.32.43/net/ipv4/inet_hashtables.c 2011-03-27 14:31:47.000000000 -0400
71415+++ linux-2.6.32.43/net/ipv4/inet_hashtables.c 2011-04-17 15:56:46.000000000 -0400
71416@@ -18,11 +18,14 @@
71417 #include <linux/sched.h>
71418 #include <linux/slab.h>
71419 #include <linux/wait.h>
71420+#include <linux/security.h>
71421
71422 #include <net/inet_connection_sock.h>
71423 #include <net/inet_hashtables.h>
71424 #include <net/ip.h>
71425
71426+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
71427+
71428 /*
71429 * Allocate and initialize a new local port bind bucket.
71430 * The bindhash mutex for snum's hash chain must be held here.
71431@@ -490,6 +493,8 @@ ok:
71432 }
71433 spin_unlock(&head->lock);
71434
71435+ gr_update_task_in_ip_table(current, inet_sk(sk));
71436+
71437 if (tw) {
71438 inet_twsk_deschedule(tw, death_row);
71439 inet_twsk_put(tw);
71440diff -urNp linux-2.6.32.43/net/ipv4/inetpeer.c linux-2.6.32.43/net/ipv4/inetpeer.c
71441--- linux-2.6.32.43/net/ipv4/inetpeer.c 2011-03-27 14:31:47.000000000 -0400
71442+++ linux-2.6.32.43/net/ipv4/inetpeer.c 2011-05-16 21:46:57.000000000 -0400
71443@@ -366,6 +366,8 @@ struct inet_peer *inet_getpeer(__be32 da
71444 struct inet_peer *p, *n;
71445 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
71446
71447+ pax_track_stack();
71448+
71449 /* Look up for the address quickly. */
71450 read_lock_bh(&peer_pool_lock);
71451 p = lookup(daddr, NULL);
71452@@ -389,7 +391,7 @@ struct inet_peer *inet_getpeer(__be32 da
71453 return NULL;
71454 n->v4daddr = daddr;
71455 atomic_set(&n->refcnt, 1);
71456- atomic_set(&n->rid, 0);
71457+ atomic_set_unchecked(&n->rid, 0);
71458 n->ip_id_count = secure_ip_id(daddr);
71459 n->tcp_ts_stamp = 0;
71460
71461diff -urNp linux-2.6.32.43/net/ipv4/ip_fragment.c linux-2.6.32.43/net/ipv4/ip_fragment.c
71462--- linux-2.6.32.43/net/ipv4/ip_fragment.c 2011-03-27 14:31:47.000000000 -0400
71463+++ linux-2.6.32.43/net/ipv4/ip_fragment.c 2011-04-17 15:56:46.000000000 -0400
71464@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct
71465 return 0;
71466
71467 start = qp->rid;
71468- end = atomic_inc_return(&peer->rid);
71469+ end = atomic_inc_return_unchecked(&peer->rid);
71470 qp->rid = end;
71471
71472 rc = qp->q.fragments && (end - start) > max;
71473diff -urNp linux-2.6.32.43/net/ipv4/ip_sockglue.c linux-2.6.32.43/net/ipv4/ip_sockglue.c
71474--- linux-2.6.32.43/net/ipv4/ip_sockglue.c 2011-03-27 14:31:47.000000000 -0400
71475+++ linux-2.6.32.43/net/ipv4/ip_sockglue.c 2011-05-16 21:46:57.000000000 -0400
71476@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock
71477 int val;
71478 int len;
71479
71480+ pax_track_stack();
71481+
71482 if (level != SOL_IP)
71483 return -EOPNOTSUPP;
71484
71485diff -urNp linux-2.6.32.43/net/ipv4/netfilter/arp_tables.c linux-2.6.32.43/net/ipv4/netfilter/arp_tables.c
71486--- linux-2.6.32.43/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:00:52.000000000 -0400
71487+++ linux-2.6.32.43/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:04:18.000000000 -0400
71488@@ -934,6 +934,7 @@ static int get_info(struct net *net, voi
71489 private = &tmp;
71490 }
71491 #endif
71492+ memset(&info, 0, sizeof(info));
71493 info.valid_hooks = t->valid_hooks;
71494 memcpy(info.hook_entry, private->hook_entry,
71495 sizeof(info.hook_entry));
71496diff -urNp linux-2.6.32.43/net/ipv4/netfilter/ip_tables.c linux-2.6.32.43/net/ipv4/netfilter/ip_tables.c
71497--- linux-2.6.32.43/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:00:52.000000000 -0400
71498+++ linux-2.6.32.43/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:04:18.000000000 -0400
71499@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, voi
71500 private = &tmp;
71501 }
71502 #endif
71503+ memset(&info, 0, sizeof(info));
71504 info.valid_hooks = t->valid_hooks;
71505 memcpy(info.hook_entry, private->hook_entry,
71506 sizeof(info.hook_entry));
71507diff -urNp linux-2.6.32.43/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.32.43/net/ipv4/netfilter/nf_nat_snmp_basic.c
71508--- linux-2.6.32.43/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-03-27 14:31:47.000000000 -0400
71509+++ linux-2.6.32.43/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-04-17 15:56:46.000000000 -0400
71510@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(
71511
71512 *len = 0;
71513
71514- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
71515+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
71516 if (*octets == NULL) {
71517 if (net_ratelimit())
71518 printk("OOM in bsalg (%d)\n", __LINE__);
71519diff -urNp linux-2.6.32.43/net/ipv4/raw.c linux-2.6.32.43/net/ipv4/raw.c
71520--- linux-2.6.32.43/net/ipv4/raw.c 2011-03-27 14:31:47.000000000 -0400
71521+++ linux-2.6.32.43/net/ipv4/raw.c 2011-05-04 17:59:08.000000000 -0400
71522@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk,
71523 /* Charge it to the socket. */
71524
71525 if (sock_queue_rcv_skb(sk, skb) < 0) {
71526- atomic_inc(&sk->sk_drops);
71527+ atomic_inc_unchecked(&sk->sk_drops);
71528 kfree_skb(skb);
71529 return NET_RX_DROP;
71530 }
71531@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk,
71532 int raw_rcv(struct sock *sk, struct sk_buff *skb)
71533 {
71534 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
71535- atomic_inc(&sk->sk_drops);
71536+ atomic_inc_unchecked(&sk->sk_drops);
71537 kfree_skb(skb);
71538 return NET_RX_DROP;
71539 }
71540@@ -724,15 +724,22 @@ static int raw_init(struct sock *sk)
71541
71542 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
71543 {
71544+ struct icmp_filter filter;
71545+
71546+ if (optlen < 0)
71547+ return -EINVAL;
71548 if (optlen > sizeof(struct icmp_filter))
71549 optlen = sizeof(struct icmp_filter);
71550- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
71551+ if (copy_from_user(&filter, optval, optlen))
71552 return -EFAULT;
71553+ memcpy(&raw_sk(sk)->filter, &filter, optlen);
71554+
71555 return 0;
71556 }
71557
71558 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
71559 {
71560+ struct icmp_filter filter;
71561 int len, ret = -EFAULT;
71562
71563 if (get_user(len, optlen))
71564@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock
71565 if (len > sizeof(struct icmp_filter))
71566 len = sizeof(struct icmp_filter);
71567 ret = -EFAULT;
71568+ memcpy(&filter, &raw_sk(sk)->filter, len);
71569 if (put_user(len, optlen) ||
71570- copy_to_user(optval, &raw_sk(sk)->filter, len))
71571+ copy_to_user(optval, &filter, len))
71572 goto out;
71573 ret = 0;
71574 out: return ret;
71575@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq
71576 sk_wmem_alloc_get(sp),
71577 sk_rmem_alloc_get(sp),
71578 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
71579- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
71580+ atomic_read(&sp->sk_refcnt),
71581+#ifdef CONFIG_GRKERNSEC_HIDESYM
71582+ NULL,
71583+#else
71584+ sp,
71585+#endif
71586+ atomic_read_unchecked(&sp->sk_drops));
71587 }
71588
71589 static int raw_seq_show(struct seq_file *seq, void *v)
71590diff -urNp linux-2.6.32.43/net/ipv4/route.c linux-2.6.32.43/net/ipv4/route.c
71591--- linux-2.6.32.43/net/ipv4/route.c 2011-03-27 14:31:47.000000000 -0400
71592+++ linux-2.6.32.43/net/ipv4/route.c 2011-05-04 17:56:28.000000000 -0400
71593@@ -268,7 +268,7 @@ static inline unsigned int rt_hash(__be3
71594
71595 static inline int rt_genid(struct net *net)
71596 {
71597- return atomic_read(&net->ipv4.rt_genid);
71598+ return atomic_read_unchecked(&net->ipv4.rt_genid);
71599 }
71600
71601 #ifdef CONFIG_PROC_FS
71602@@ -888,7 +888,7 @@ static void rt_cache_invalidate(struct n
71603 unsigned char shuffle;
71604
71605 get_random_bytes(&shuffle, sizeof(shuffle));
71606- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
71607+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
71608 }
71609
71610 /*
71611@@ -3356,7 +3356,7 @@ static __net_initdata struct pernet_oper
71612
71613 static __net_init int rt_secret_timer_init(struct net *net)
71614 {
71615- atomic_set(&net->ipv4.rt_genid,
71616+ atomic_set_unchecked(&net->ipv4.rt_genid,
71617 (int) ((num_physpages ^ (num_physpages>>8)) ^
71618 (jiffies ^ (jiffies >> 7))));
71619
71620diff -urNp linux-2.6.32.43/net/ipv4/tcp.c linux-2.6.32.43/net/ipv4/tcp.c
71621--- linux-2.6.32.43/net/ipv4/tcp.c 2011-03-27 14:31:47.000000000 -0400
71622+++ linux-2.6.32.43/net/ipv4/tcp.c 2011-05-16 21:46:57.000000000 -0400
71623@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock
71624 int val;
71625 int err = 0;
71626
71627+ pax_track_stack();
71628+
71629 /* This is a string value all the others are int's */
71630 if (optname == TCP_CONGESTION) {
71631 char name[TCP_CA_NAME_MAX];
71632@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock
71633 struct tcp_sock *tp = tcp_sk(sk);
71634 int val, len;
71635
71636+ pax_track_stack();
71637+
71638 if (get_user(len, optlen))
71639 return -EFAULT;
71640
71641diff -urNp linux-2.6.32.43/net/ipv4/tcp_ipv4.c linux-2.6.32.43/net/ipv4/tcp_ipv4.c
71642--- linux-2.6.32.43/net/ipv4/tcp_ipv4.c 2011-03-27 14:31:47.000000000 -0400
71643+++ linux-2.6.32.43/net/ipv4/tcp_ipv4.c 2011-08-05 20:33:55.000000000 -0400
71644@@ -84,6 +84,9 @@
71645 int sysctl_tcp_tw_reuse __read_mostly;
71646 int sysctl_tcp_low_latency __read_mostly;
71647
71648+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71649+extern int grsec_enable_blackhole;
71650+#endif
71651
71652 #ifdef CONFIG_TCP_MD5SIG
71653 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
71654@@ -1542,6 +1545,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
71655 return 0;
71656
71657 reset:
71658+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71659+ if (!grsec_enable_blackhole)
71660+#endif
71661 tcp_v4_send_reset(rsk, skb);
71662 discard:
71663 kfree_skb(skb);
71664@@ -1603,12 +1609,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
71665 TCP_SKB_CB(skb)->sacked = 0;
71666
71667 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
71668- if (!sk)
71669+ if (!sk) {
71670+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71671+ ret = 1;
71672+#endif
71673 goto no_tcp_socket;
71674+ }
71675
71676 process:
71677- if (sk->sk_state == TCP_TIME_WAIT)
71678+ if (sk->sk_state == TCP_TIME_WAIT) {
71679+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71680+ ret = 2;
71681+#endif
71682 goto do_time_wait;
71683+ }
71684
71685 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
71686 goto discard_and_relse;
71687@@ -1650,6 +1664,10 @@ no_tcp_socket:
71688 bad_packet:
71689 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
71690 } else {
71691+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71692+ if (!grsec_enable_blackhole || (ret == 1 &&
71693+ (skb->dev->flags & IFF_LOOPBACK)))
71694+#endif
71695 tcp_v4_send_reset(NULL, skb);
71696 }
71697
71698@@ -2194,14 +2212,14 @@ int tcp_proc_register(struct net *net, s
71699 int rc = 0;
71700 struct proc_dir_entry *p;
71701
71702- afinfo->seq_fops.open = tcp_seq_open;
71703- afinfo->seq_fops.read = seq_read;
71704- afinfo->seq_fops.llseek = seq_lseek;
71705- afinfo->seq_fops.release = seq_release_net;
71706-
71707- afinfo->seq_ops.start = tcp_seq_start;
71708- afinfo->seq_ops.next = tcp_seq_next;
71709- afinfo->seq_ops.stop = tcp_seq_stop;
71710+ *(void **)&afinfo->seq_fops.open = tcp_seq_open;
71711+ *(void **)&afinfo->seq_fops.read = seq_read;
71712+ *(void **)&afinfo->seq_fops.llseek = seq_lseek;
71713+ *(void **)&afinfo->seq_fops.release = seq_release_net;
71714+
71715+ *(void **)&afinfo->seq_ops.start = tcp_seq_start;
71716+ *(void **)&afinfo->seq_ops.next = tcp_seq_next;
71717+ *(void **)&afinfo->seq_ops.stop = tcp_seq_stop;
71718
71719 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
71720 &afinfo->seq_fops, afinfo);
71721@@ -2237,7 +2255,11 @@ static void get_openreq4(struct sock *sk
71722 0, /* non standard timer */
71723 0, /* open_requests have no inode */
71724 atomic_read(&sk->sk_refcnt),
71725+#ifdef CONFIG_GRKERNSEC_HIDESYM
71726+ NULL,
71727+#else
71728 req,
71729+#endif
71730 len);
71731 }
71732
71733@@ -2279,7 +2301,12 @@ static void get_tcp4_sock(struct sock *s
71734 sock_i_uid(sk),
71735 icsk->icsk_probes_out,
71736 sock_i_ino(sk),
71737- atomic_read(&sk->sk_refcnt), sk,
71738+ atomic_read(&sk->sk_refcnt),
71739+#ifdef CONFIG_GRKERNSEC_HIDESYM
71740+ NULL,
71741+#else
71742+ sk,
71743+#endif
71744 jiffies_to_clock_t(icsk->icsk_rto),
71745 jiffies_to_clock_t(icsk->icsk_ack.ato),
71746 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
71747@@ -2307,7 +2334,13 @@ static void get_timewait4_sock(struct in
71748 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
71749 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
71750 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
71751- atomic_read(&tw->tw_refcnt), tw, len);
71752+ atomic_read(&tw->tw_refcnt),
71753+#ifdef CONFIG_GRKERNSEC_HIDESYM
71754+ NULL,
71755+#else
71756+ tw,
71757+#endif
71758+ len);
71759 }
71760
71761 #define TMPSZ 150
71762diff -urNp linux-2.6.32.43/net/ipv4/tcp_minisocks.c linux-2.6.32.43/net/ipv4/tcp_minisocks.c
71763--- linux-2.6.32.43/net/ipv4/tcp_minisocks.c 2011-03-27 14:31:47.000000000 -0400
71764+++ linux-2.6.32.43/net/ipv4/tcp_minisocks.c 2011-04-17 15:56:46.000000000 -0400
71765@@ -26,6 +26,10 @@
71766 #include <net/inet_common.h>
71767 #include <net/xfrm.h>
71768
71769+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71770+extern int grsec_enable_blackhole;
71771+#endif
71772+
71773 #ifdef CONFIG_SYSCTL
71774 #define SYNC_INIT 0 /* let the user enable it */
71775 #else
71776@@ -672,6 +676,10 @@ listen_overflow:
71777
71778 embryonic_reset:
71779 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
71780+
71781+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71782+ if (!grsec_enable_blackhole)
71783+#endif
71784 if (!(flg & TCP_FLAG_RST))
71785 req->rsk_ops->send_reset(sk, skb);
71786
71787diff -urNp linux-2.6.32.43/net/ipv4/tcp_output.c linux-2.6.32.43/net/ipv4/tcp_output.c
71788--- linux-2.6.32.43/net/ipv4/tcp_output.c 2011-03-27 14:31:47.000000000 -0400
71789+++ linux-2.6.32.43/net/ipv4/tcp_output.c 2011-05-16 21:46:57.000000000 -0400
71790@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct s
71791 __u8 *md5_hash_location;
71792 int mss;
71793
71794+ pax_track_stack();
71795+
71796 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
71797 if (skb == NULL)
71798 return NULL;
71799diff -urNp linux-2.6.32.43/net/ipv4/tcp_probe.c linux-2.6.32.43/net/ipv4/tcp_probe.c
71800--- linux-2.6.32.43/net/ipv4/tcp_probe.c 2011-03-27 14:31:47.000000000 -0400
71801+++ linux-2.6.32.43/net/ipv4/tcp_probe.c 2011-04-17 15:56:46.000000000 -0400
71802@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file
71803 if (cnt + width >= len)
71804 break;
71805
71806- if (copy_to_user(buf + cnt, tbuf, width))
71807+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
71808 return -EFAULT;
71809 cnt += width;
71810 }
71811diff -urNp linux-2.6.32.43/net/ipv4/tcp_timer.c linux-2.6.32.43/net/ipv4/tcp_timer.c
71812--- linux-2.6.32.43/net/ipv4/tcp_timer.c 2011-03-27 14:31:47.000000000 -0400
71813+++ linux-2.6.32.43/net/ipv4/tcp_timer.c 2011-04-17 15:56:46.000000000 -0400
71814@@ -21,6 +21,10 @@
71815 #include <linux/module.h>
71816 #include <net/tcp.h>
71817
71818+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71819+extern int grsec_lastack_retries;
71820+#endif
71821+
71822 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
71823 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
71824 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
71825@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock
71826 }
71827 }
71828
71829+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71830+ if ((sk->sk_state == TCP_LAST_ACK) &&
71831+ (grsec_lastack_retries > 0) &&
71832+ (grsec_lastack_retries < retry_until))
71833+ retry_until = grsec_lastack_retries;
71834+#endif
71835+
71836 if (retransmits_timed_out(sk, retry_until)) {
71837 /* Has it gone just too far? */
71838 tcp_write_err(sk);
71839diff -urNp linux-2.6.32.43/net/ipv4/udp.c linux-2.6.32.43/net/ipv4/udp.c
71840--- linux-2.6.32.43/net/ipv4/udp.c 2011-07-13 17:23:04.000000000 -0400
71841+++ linux-2.6.32.43/net/ipv4/udp.c 2011-08-05 20:33:55.000000000 -0400
71842@@ -86,6 +86,7 @@
71843 #include <linux/types.h>
71844 #include <linux/fcntl.h>
71845 #include <linux/module.h>
71846+#include <linux/security.h>
71847 #include <linux/socket.h>
71848 #include <linux/sockios.h>
71849 #include <linux/igmp.h>
71850@@ -106,6 +107,10 @@
71851 #include <net/xfrm.h>
71852 #include "udp_impl.h"
71853
71854+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71855+extern int grsec_enable_blackhole;
71856+#endif
71857+
71858 struct udp_table udp_table;
71859 EXPORT_SYMBOL(udp_table);
71860
71861@@ -371,6 +376,9 @@ found:
71862 return s;
71863 }
71864
71865+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
71866+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
71867+
71868 /*
71869 * This routine is called by the ICMP module when it gets some
71870 * sort of error condition. If err < 0 then the socket should
71871@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
71872 dport = usin->sin_port;
71873 if (dport == 0)
71874 return -EINVAL;
71875+
71876+ err = gr_search_udp_sendmsg(sk, usin);
71877+ if (err)
71878+ return err;
71879 } else {
71880 if (sk->sk_state != TCP_ESTABLISHED)
71881 return -EDESTADDRREQ;
71882+
71883+ err = gr_search_udp_sendmsg(sk, NULL);
71884+ if (err)
71885+ return err;
71886+
71887 daddr = inet->daddr;
71888 dport = inet->dport;
71889 /* Open fast path for connected socket.
71890@@ -945,6 +962,10 @@ try_again:
71891 if (!skb)
71892 goto out;
71893
71894+ err = gr_search_udp_recvmsg(sk, skb);
71895+ if (err)
71896+ goto out_free;
71897+
71898 ulen = skb->len - sizeof(struct udphdr);
71899 copied = len;
71900 if (copied > ulen)
71901@@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct so
71902 if (rc == -ENOMEM) {
71903 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
71904 is_udplite);
71905- atomic_inc(&sk->sk_drops);
71906+ atomic_inc_unchecked(&sk->sk_drops);
71907 }
71908 goto drop;
71909 }
71910@@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
71911 goto csum_error;
71912
71913 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
71914+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71915+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
71916+#endif
71917 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
71918
71919 /*
71920@@ -1719,14 +1743,14 @@ int udp_proc_register(struct net *net, s
71921 struct proc_dir_entry *p;
71922 int rc = 0;
71923
71924- afinfo->seq_fops.open = udp_seq_open;
71925- afinfo->seq_fops.read = seq_read;
71926- afinfo->seq_fops.llseek = seq_lseek;
71927- afinfo->seq_fops.release = seq_release_net;
71928-
71929- afinfo->seq_ops.start = udp_seq_start;
71930- afinfo->seq_ops.next = udp_seq_next;
71931- afinfo->seq_ops.stop = udp_seq_stop;
71932+ *(void **)&afinfo->seq_fops.open = udp_seq_open;
71933+ *(void **)&afinfo->seq_fops.read = seq_read;
71934+ *(void **)&afinfo->seq_fops.llseek = seq_lseek;
71935+ *(void **)&afinfo->seq_fops.release = seq_release_net;
71936+
71937+ *(void **)&afinfo->seq_ops.start = udp_seq_start;
71938+ *(void **)&afinfo->seq_ops.next = udp_seq_next;
71939+ *(void **)&afinfo->seq_ops.stop = udp_seq_stop;
71940
71941 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
71942 &afinfo->seq_fops, afinfo);
71943@@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock
71944 sk_wmem_alloc_get(sp),
71945 sk_rmem_alloc_get(sp),
71946 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
71947- atomic_read(&sp->sk_refcnt), sp,
71948- atomic_read(&sp->sk_drops), len);
71949+ atomic_read(&sp->sk_refcnt),
71950+#ifdef CONFIG_GRKERNSEC_HIDESYM
71951+ NULL,
71952+#else
71953+ sp,
71954+#endif
71955+ atomic_read_unchecked(&sp->sk_drops), len);
71956 }
71957
71958 int udp4_seq_show(struct seq_file *seq, void *v)
71959diff -urNp linux-2.6.32.43/net/ipv6/inet6_connection_sock.c linux-2.6.32.43/net/ipv6/inet6_connection_sock.c
71960--- linux-2.6.32.43/net/ipv6/inet6_connection_sock.c 2011-03-27 14:31:47.000000000 -0400
71961+++ linux-2.6.32.43/net/ipv6/inet6_connection_sock.c 2011-05-04 17:56:28.000000000 -0400
71962@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *
71963 #ifdef CONFIG_XFRM
71964 {
71965 struct rt6_info *rt = (struct rt6_info *)dst;
71966- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
71967+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
71968 }
71969 #endif
71970 }
71971@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(
71972 #ifdef CONFIG_XFRM
71973 if (dst) {
71974 struct rt6_info *rt = (struct rt6_info *)dst;
71975- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
71976+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
71977 sk->sk_dst_cache = NULL;
71978 dst_release(dst);
71979 dst = NULL;
71980diff -urNp linux-2.6.32.43/net/ipv6/inet6_hashtables.c linux-2.6.32.43/net/ipv6/inet6_hashtables.c
71981--- linux-2.6.32.43/net/ipv6/inet6_hashtables.c 2011-03-27 14:31:47.000000000 -0400
71982+++ linux-2.6.32.43/net/ipv6/inet6_hashtables.c 2011-05-04 17:56:28.000000000 -0400
71983@@ -118,7 +118,7 @@ out:
71984 }
71985 EXPORT_SYMBOL(__inet6_lookup_established);
71986
71987-static int inline compute_score(struct sock *sk, struct net *net,
71988+static inline int compute_score(struct sock *sk, struct net *net,
71989 const unsigned short hnum,
71990 const struct in6_addr *daddr,
71991 const int dif)
71992diff -urNp linux-2.6.32.43/net/ipv6/ipv6_sockglue.c linux-2.6.32.43/net/ipv6/ipv6_sockglue.c
71993--- linux-2.6.32.43/net/ipv6/ipv6_sockglue.c 2011-03-27 14:31:47.000000000 -0400
71994+++ linux-2.6.32.43/net/ipv6/ipv6_sockglue.c 2011-05-16 21:46:57.000000000 -0400
71995@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct soc
71996 int val, valbool;
71997 int retv = -ENOPROTOOPT;
71998
71999+ pax_track_stack();
72000+
72001 if (optval == NULL)
72002 val=0;
72003 else {
72004@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct soc
72005 int len;
72006 int val;
72007
72008+ pax_track_stack();
72009+
72010 if (ip6_mroute_opt(optname))
72011 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
72012
72013diff -urNp linux-2.6.32.43/net/ipv6/netfilter/ip6_tables.c linux-2.6.32.43/net/ipv6/netfilter/ip6_tables.c
72014--- linux-2.6.32.43/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:00:52.000000000 -0400
72015+++ linux-2.6.32.43/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:04:18.000000000 -0400
72016@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, voi
72017 private = &tmp;
72018 }
72019 #endif
72020+ memset(&info, 0, sizeof(info));
72021 info.valid_hooks = t->valid_hooks;
72022 memcpy(info.hook_entry, private->hook_entry,
72023 sizeof(info.hook_entry));
72024diff -urNp linux-2.6.32.43/net/ipv6/raw.c linux-2.6.32.43/net/ipv6/raw.c
72025--- linux-2.6.32.43/net/ipv6/raw.c 2011-03-27 14:31:47.000000000 -0400
72026+++ linux-2.6.32.43/net/ipv6/raw.c 2011-05-16 21:46:57.000000000 -0400
72027@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct s
72028 {
72029 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
72030 skb_checksum_complete(skb)) {
72031- atomic_inc(&sk->sk_drops);
72032+ atomic_inc_unchecked(&sk->sk_drops);
72033 kfree_skb(skb);
72034 return NET_RX_DROP;
72035 }
72036
72037 /* Charge it to the socket. */
72038 if (sock_queue_rcv_skb(sk,skb)<0) {
72039- atomic_inc(&sk->sk_drops);
72040+ atomic_inc_unchecked(&sk->sk_drops);
72041 kfree_skb(skb);
72042 return NET_RX_DROP;
72043 }
72044@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
72045 struct raw6_sock *rp = raw6_sk(sk);
72046
72047 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
72048- atomic_inc(&sk->sk_drops);
72049+ atomic_inc_unchecked(&sk->sk_drops);
72050 kfree_skb(skb);
72051 return NET_RX_DROP;
72052 }
72053@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
72054
72055 if (inet->hdrincl) {
72056 if (skb_checksum_complete(skb)) {
72057- atomic_inc(&sk->sk_drops);
72058+ atomic_inc_unchecked(&sk->sk_drops);
72059 kfree_skb(skb);
72060 return NET_RX_DROP;
72061 }
72062@@ -518,7 +518,7 @@ csum_copy_err:
72063 as some normal condition.
72064 */
72065 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
72066- atomic_inc(&sk->sk_drops);
72067+ atomic_inc_unchecked(&sk->sk_drops);
72068 goto out;
72069 }
72070
72071@@ -600,7 +600,7 @@ out:
72072 return err;
72073 }
72074
72075-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
72076+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
72077 struct flowi *fl, struct rt6_info *rt,
72078 unsigned int flags)
72079 {
72080@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *i
72081 u16 proto;
72082 int err;
72083
72084+ pax_track_stack();
72085+
72086 /* Rough check on arithmetic overflow,
72087 better check is made in ip6_append_data().
72088 */
72089@@ -916,12 +918,17 @@ do_confirm:
72090 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
72091 char __user *optval, int optlen)
72092 {
72093+ struct icmp6_filter filter;
72094+
72095 switch (optname) {
72096 case ICMPV6_FILTER:
72097+ if (optlen < 0)
72098+ return -EINVAL;
72099 if (optlen > sizeof(struct icmp6_filter))
72100 optlen = sizeof(struct icmp6_filter);
72101- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
72102+ if (copy_from_user(&filter, optval, optlen))
72103 return -EFAULT;
72104+ memcpy(&raw6_sk(sk)->filter, &filter, optlen);
72105 return 0;
72106 default:
72107 return -ENOPROTOOPT;
72108@@ -933,6 +940,7 @@ static int rawv6_seticmpfilter(struct so
72109 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
72110 char __user *optval, int __user *optlen)
72111 {
72112+ struct icmp6_filter filter;
72113 int len;
72114
72115 switch (optname) {
72116@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct so
72117 len = sizeof(struct icmp6_filter);
72118 if (put_user(len, optlen))
72119 return -EFAULT;
72120- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
72121+ memcpy(&filter, &raw6_sk(sk)->filter, len);
72122+ if (copy_to_user(optval, &filter, len))
72123 return -EFAULT;
72124 return 0;
72125 default:
72126@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct se
72127 0, 0L, 0,
72128 sock_i_uid(sp), 0,
72129 sock_i_ino(sp),
72130- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
72131+ atomic_read(&sp->sk_refcnt),
72132+#ifdef CONFIG_GRKERNSEC_HIDESYM
72133+ NULL,
72134+#else
72135+ sp,
72136+#endif
72137+ atomic_read_unchecked(&sp->sk_drops));
72138 }
72139
72140 static int raw6_seq_show(struct seq_file *seq, void *v)
72141diff -urNp linux-2.6.32.43/net/ipv6/tcp_ipv6.c linux-2.6.32.43/net/ipv6/tcp_ipv6.c
72142--- linux-2.6.32.43/net/ipv6/tcp_ipv6.c 2011-03-27 14:31:47.000000000 -0400
72143+++ linux-2.6.32.43/net/ipv6/tcp_ipv6.c 2011-04-17 15:56:46.000000000 -0400
72144@@ -88,6 +88,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
72145 }
72146 #endif
72147
72148+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72149+extern int grsec_enable_blackhole;
72150+#endif
72151+
72152 static void tcp_v6_hash(struct sock *sk)
72153 {
72154 if (sk->sk_state != TCP_CLOSE) {
72155@@ -1578,6 +1582,9 @@ static int tcp_v6_do_rcv(struct sock *sk
72156 return 0;
72157
72158 reset:
72159+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72160+ if (!grsec_enable_blackhole)
72161+#endif
72162 tcp_v6_send_reset(sk, skb);
72163 discard:
72164 if (opt_skb)
72165@@ -1655,12 +1662,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
72166 TCP_SKB_CB(skb)->sacked = 0;
72167
72168 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
72169- if (!sk)
72170+ if (!sk) {
72171+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72172+ ret = 1;
72173+#endif
72174 goto no_tcp_socket;
72175+ }
72176
72177 process:
72178- if (sk->sk_state == TCP_TIME_WAIT)
72179+ if (sk->sk_state == TCP_TIME_WAIT) {
72180+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72181+ ret = 2;
72182+#endif
72183 goto do_time_wait;
72184+ }
72185
72186 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
72187 goto discard_and_relse;
72188@@ -1700,6 +1715,10 @@ no_tcp_socket:
72189 bad_packet:
72190 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
72191 } else {
72192+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72193+ if (!grsec_enable_blackhole || (ret == 1 &&
72194+ (skb->dev->flags & IFF_LOOPBACK)))
72195+#endif
72196 tcp_v6_send_reset(NULL, skb);
72197 }
72198
72199@@ -1915,7 +1934,13 @@ static void get_openreq6(struct seq_file
72200 uid,
72201 0, /* non standard timer */
72202 0, /* open_requests have no inode */
72203- 0, req);
72204+ 0,
72205+#ifdef CONFIG_GRKERNSEC_HIDESYM
72206+ NULL
72207+#else
72208+ req
72209+#endif
72210+ );
72211 }
72212
72213 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
72214@@ -1965,7 +1990,12 @@ static void get_tcp6_sock(struct seq_fil
72215 sock_i_uid(sp),
72216 icsk->icsk_probes_out,
72217 sock_i_ino(sp),
72218- atomic_read(&sp->sk_refcnt), sp,
72219+ atomic_read(&sp->sk_refcnt),
72220+#ifdef CONFIG_GRKERNSEC_HIDESYM
72221+ NULL,
72222+#else
72223+ sp,
72224+#endif
72225 jiffies_to_clock_t(icsk->icsk_rto),
72226 jiffies_to_clock_t(icsk->icsk_ack.ato),
72227 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
72228@@ -2000,7 +2030,13 @@ static void get_timewait6_sock(struct se
72229 dest->s6_addr32[2], dest->s6_addr32[3], destp,
72230 tw->tw_substate, 0, 0,
72231 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
72232- atomic_read(&tw->tw_refcnt), tw);
72233+ atomic_read(&tw->tw_refcnt),
72234+#ifdef CONFIG_GRKERNSEC_HIDESYM
72235+ NULL
72236+#else
72237+ tw
72238+#endif
72239+ );
72240 }
72241
72242 static int tcp6_seq_show(struct seq_file *seq, void *v)
72243diff -urNp linux-2.6.32.43/net/ipv6/udp.c linux-2.6.32.43/net/ipv6/udp.c
72244--- linux-2.6.32.43/net/ipv6/udp.c 2011-07-13 17:23:04.000000000 -0400
72245+++ linux-2.6.32.43/net/ipv6/udp.c 2011-07-13 17:23:27.000000000 -0400
72246@@ -49,6 +49,10 @@
72247 #include <linux/seq_file.h>
72248 #include "udp_impl.h"
72249
72250+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72251+extern int grsec_enable_blackhole;
72252+#endif
72253+
72254 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
72255 {
72256 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
72257@@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
72258 if (rc == -ENOMEM) {
72259 UDP6_INC_STATS_BH(sock_net(sk),
72260 UDP_MIB_RCVBUFERRORS, is_udplite);
72261- atomic_inc(&sk->sk_drops);
72262+ atomic_inc_unchecked(&sk->sk_drops);
72263 }
72264 goto drop;
72265 }
72266@@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
72267 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
72268 proto == IPPROTO_UDPLITE);
72269
72270+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72271+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
72272+#endif
72273 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
72274
72275 kfree_skb(skb);
72276@@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct se
72277 0, 0L, 0,
72278 sock_i_uid(sp), 0,
72279 sock_i_ino(sp),
72280- atomic_read(&sp->sk_refcnt), sp,
72281- atomic_read(&sp->sk_drops));
72282+ atomic_read(&sp->sk_refcnt),
72283+#ifdef CONFIG_GRKERNSEC_HIDESYM
72284+ NULL,
72285+#else
72286+ sp,
72287+#endif
72288+ atomic_read_unchecked(&sp->sk_drops));
72289 }
72290
72291 int udp6_seq_show(struct seq_file *seq, void *v)
72292diff -urNp linux-2.6.32.43/net/irda/ircomm/ircomm_tty.c linux-2.6.32.43/net/irda/ircomm/ircomm_tty.c
72293--- linux-2.6.32.43/net/irda/ircomm/ircomm_tty.c 2011-03-27 14:31:47.000000000 -0400
72294+++ linux-2.6.32.43/net/irda/ircomm/ircomm_tty.c 2011-04-17 15:56:46.000000000 -0400
72295@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(st
72296 add_wait_queue(&self->open_wait, &wait);
72297
72298 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
72299- __FILE__,__LINE__, tty->driver->name, self->open_count );
72300+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
72301
72302 /* As far as I can see, we protect open_count - Jean II */
72303 spin_lock_irqsave(&self->spinlock, flags);
72304 if (!tty_hung_up_p(filp)) {
72305 extra_count = 1;
72306- self->open_count--;
72307+ local_dec(&self->open_count);
72308 }
72309 spin_unlock_irqrestore(&self->spinlock, flags);
72310- self->blocked_open++;
72311+ local_inc(&self->blocked_open);
72312
72313 while (1) {
72314 if (tty->termios->c_cflag & CBAUD) {
72315@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(st
72316 }
72317
72318 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
72319- __FILE__,__LINE__, tty->driver->name, self->open_count );
72320+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
72321
72322 schedule();
72323 }
72324@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(st
72325 if (extra_count) {
72326 /* ++ is not atomic, so this should be protected - Jean II */
72327 spin_lock_irqsave(&self->spinlock, flags);
72328- self->open_count++;
72329+ local_inc(&self->open_count);
72330 spin_unlock_irqrestore(&self->spinlock, flags);
72331 }
72332- self->blocked_open--;
72333+ local_dec(&self->blocked_open);
72334
72335 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
72336- __FILE__,__LINE__, tty->driver->name, self->open_count);
72337+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
72338
72339 if (!retval)
72340 self->flags |= ASYNC_NORMAL_ACTIVE;
72341@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_st
72342 }
72343 /* ++ is not atomic, so this should be protected - Jean II */
72344 spin_lock_irqsave(&self->spinlock, flags);
72345- self->open_count++;
72346+ local_inc(&self->open_count);
72347
72348 tty->driver_data = self;
72349 self->tty = tty;
72350 spin_unlock_irqrestore(&self->spinlock, flags);
72351
72352 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
72353- self->line, self->open_count);
72354+ self->line, local_read(&self->open_count));
72355
72356 /* Not really used by us, but lets do it anyway */
72357 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
72358@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_
72359 return;
72360 }
72361
72362- if ((tty->count == 1) && (self->open_count != 1)) {
72363+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
72364 /*
72365 * Uh, oh. tty->count is 1, which means that the tty
72366 * structure will be freed. state->count should always
72367@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_
72368 */
72369 IRDA_DEBUG(0, "%s(), bad serial port count; "
72370 "tty->count is 1, state->count is %d\n", __func__ ,
72371- self->open_count);
72372- self->open_count = 1;
72373+ local_read(&self->open_count));
72374+ local_set(&self->open_count, 1);
72375 }
72376
72377- if (--self->open_count < 0) {
72378+ if (local_dec_return(&self->open_count) < 0) {
72379 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
72380- __func__, self->line, self->open_count);
72381- self->open_count = 0;
72382+ __func__, self->line, local_read(&self->open_count));
72383+ local_set(&self->open_count, 0);
72384 }
72385- if (self->open_count) {
72386+ if (local_read(&self->open_count)) {
72387 spin_unlock_irqrestore(&self->spinlock, flags);
72388
72389 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
72390@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_
72391 tty->closing = 0;
72392 self->tty = NULL;
72393
72394- if (self->blocked_open) {
72395+ if (local_read(&self->blocked_open)) {
72396 if (self->close_delay)
72397 schedule_timeout_interruptible(self->close_delay);
72398 wake_up_interruptible(&self->open_wait);
72399@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty
72400 spin_lock_irqsave(&self->spinlock, flags);
72401 self->flags &= ~ASYNC_NORMAL_ACTIVE;
72402 self->tty = NULL;
72403- self->open_count = 0;
72404+ local_set(&self->open_count, 0);
72405 spin_unlock_irqrestore(&self->spinlock, flags);
72406
72407 wake_up_interruptible(&self->open_wait);
72408@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct
72409 seq_putc(m, '\n');
72410
72411 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
72412- seq_printf(m, "Open count: %d\n", self->open_count);
72413+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
72414 seq_printf(m, "Max data size: %d\n", self->max_data_size);
72415 seq_printf(m, "Max header size: %d\n", self->max_header_size);
72416
72417diff -urNp linux-2.6.32.43/net/iucv/af_iucv.c linux-2.6.32.43/net/iucv/af_iucv.c
72418--- linux-2.6.32.43/net/iucv/af_iucv.c 2011-03-27 14:31:47.000000000 -0400
72419+++ linux-2.6.32.43/net/iucv/af_iucv.c 2011-05-04 17:56:28.000000000 -0400
72420@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct soc
72421
72422 write_lock_bh(&iucv_sk_list.lock);
72423
72424- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
72425+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
72426 while (__iucv_get_sock_by_name(name)) {
72427 sprintf(name, "%08x",
72428- atomic_inc_return(&iucv_sk_list.autobind_name));
72429+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
72430 }
72431
72432 write_unlock_bh(&iucv_sk_list.lock);
72433diff -urNp linux-2.6.32.43/net/key/af_key.c linux-2.6.32.43/net/key/af_key.c
72434--- linux-2.6.32.43/net/key/af_key.c 2011-03-27 14:31:47.000000000 -0400
72435+++ linux-2.6.32.43/net/key/af_key.c 2011-05-16 21:46:57.000000000 -0400
72436@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk
72437 struct xfrm_migrate m[XFRM_MAX_DEPTH];
72438 struct xfrm_kmaddress k;
72439
72440+ pax_track_stack();
72441+
72442 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
72443 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
72444 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
72445@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_fil
72446 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
72447 else
72448 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
72449+#ifdef CONFIG_GRKERNSEC_HIDESYM
72450+ NULL,
72451+#else
72452 s,
72453+#endif
72454 atomic_read(&s->sk_refcnt),
72455 sk_rmem_alloc_get(s),
72456 sk_wmem_alloc_get(s),
72457diff -urNp linux-2.6.32.43/net/lapb/lapb_iface.c linux-2.6.32.43/net/lapb/lapb_iface.c
72458--- linux-2.6.32.43/net/lapb/lapb_iface.c 2011-03-27 14:31:47.000000000 -0400
72459+++ linux-2.6.32.43/net/lapb/lapb_iface.c 2011-08-05 20:33:55.000000000 -0400
72460@@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev
72461 goto out;
72462
72463 lapb->dev = dev;
72464- lapb->callbacks = *callbacks;
72465+ lapb->callbacks = callbacks;
72466
72467 __lapb_insert_cb(lapb);
72468
72469@@ -379,32 +379,32 @@ int lapb_data_received(struct net_device
72470
72471 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
72472 {
72473- if (lapb->callbacks.connect_confirmation)
72474- lapb->callbacks.connect_confirmation(lapb->dev, reason);
72475+ if (lapb->callbacks->connect_confirmation)
72476+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
72477 }
72478
72479 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
72480 {
72481- if (lapb->callbacks.connect_indication)
72482- lapb->callbacks.connect_indication(lapb->dev, reason);
72483+ if (lapb->callbacks->connect_indication)
72484+ lapb->callbacks->connect_indication(lapb->dev, reason);
72485 }
72486
72487 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
72488 {
72489- if (lapb->callbacks.disconnect_confirmation)
72490- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
72491+ if (lapb->callbacks->disconnect_confirmation)
72492+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
72493 }
72494
72495 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
72496 {
72497- if (lapb->callbacks.disconnect_indication)
72498- lapb->callbacks.disconnect_indication(lapb->dev, reason);
72499+ if (lapb->callbacks->disconnect_indication)
72500+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
72501 }
72502
72503 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
72504 {
72505- if (lapb->callbacks.data_indication)
72506- return lapb->callbacks.data_indication(lapb->dev, skb);
72507+ if (lapb->callbacks->data_indication)
72508+ return lapb->callbacks->data_indication(lapb->dev, skb);
72509
72510 kfree_skb(skb);
72511 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
72512@@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *l
72513 {
72514 int used = 0;
72515
72516- if (lapb->callbacks.data_transmit) {
72517- lapb->callbacks.data_transmit(lapb->dev, skb);
72518+ if (lapb->callbacks->data_transmit) {
72519+ lapb->callbacks->data_transmit(lapb->dev, skb);
72520 used = 1;
72521 }
72522
72523diff -urNp linux-2.6.32.43/net/mac80211/cfg.c linux-2.6.32.43/net/mac80211/cfg.c
72524--- linux-2.6.32.43/net/mac80211/cfg.c 2011-03-27 14:31:47.000000000 -0400
72525+++ linux-2.6.32.43/net/mac80211/cfg.c 2011-04-17 15:56:46.000000000 -0400
72526@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(st
72527 return err;
72528 }
72529
72530-struct cfg80211_ops mac80211_config_ops = {
72531+const struct cfg80211_ops mac80211_config_ops = {
72532 .add_virtual_intf = ieee80211_add_iface,
72533 .del_virtual_intf = ieee80211_del_iface,
72534 .change_virtual_intf = ieee80211_change_iface,
72535diff -urNp linux-2.6.32.43/net/mac80211/cfg.h linux-2.6.32.43/net/mac80211/cfg.h
72536--- linux-2.6.32.43/net/mac80211/cfg.h 2011-03-27 14:31:47.000000000 -0400
72537+++ linux-2.6.32.43/net/mac80211/cfg.h 2011-04-17 15:56:46.000000000 -0400
72538@@ -4,6 +4,6 @@
72539 #ifndef __CFG_H
72540 #define __CFG_H
72541
72542-extern struct cfg80211_ops mac80211_config_ops;
72543+extern const struct cfg80211_ops mac80211_config_ops;
72544
72545 #endif /* __CFG_H */
72546diff -urNp linux-2.6.32.43/net/mac80211/debugfs_key.c linux-2.6.32.43/net/mac80211/debugfs_key.c
72547--- linux-2.6.32.43/net/mac80211/debugfs_key.c 2011-03-27 14:31:47.000000000 -0400
72548+++ linux-2.6.32.43/net/mac80211/debugfs_key.c 2011-04-17 15:56:46.000000000 -0400
72549@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file
72550 size_t count, loff_t *ppos)
72551 {
72552 struct ieee80211_key *key = file->private_data;
72553- int i, res, bufsize = 2 * key->conf.keylen + 2;
72554+ int i, bufsize = 2 * key->conf.keylen + 2;
72555 char *buf = kmalloc(bufsize, GFP_KERNEL);
72556 char *p = buf;
72557+ ssize_t res;
72558+
72559+ if (buf == NULL)
72560+ return -ENOMEM;
72561
72562 for (i = 0; i < key->conf.keylen; i++)
72563 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
72564diff -urNp linux-2.6.32.43/net/mac80211/debugfs_sta.c linux-2.6.32.43/net/mac80211/debugfs_sta.c
72565--- linux-2.6.32.43/net/mac80211/debugfs_sta.c 2011-03-27 14:31:47.000000000 -0400
72566+++ linux-2.6.32.43/net/mac80211/debugfs_sta.c 2011-05-16 21:46:57.000000000 -0400
72567@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struc
72568 int i;
72569 struct sta_info *sta = file->private_data;
72570
72571+ pax_track_stack();
72572+
72573 spin_lock_bh(&sta->lock);
72574 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
72575 sta->ampdu_mlme.dialog_token_allocator + 1);
72576diff -urNp linux-2.6.32.43/net/mac80211/ieee80211_i.h linux-2.6.32.43/net/mac80211/ieee80211_i.h
72577--- linux-2.6.32.43/net/mac80211/ieee80211_i.h 2011-03-27 14:31:47.000000000 -0400
72578+++ linux-2.6.32.43/net/mac80211/ieee80211_i.h 2011-04-17 15:56:46.000000000 -0400
72579@@ -25,6 +25,7 @@
72580 #include <linux/etherdevice.h>
72581 #include <net/cfg80211.h>
72582 #include <net/mac80211.h>
72583+#include <asm/local.h>
72584 #include "key.h"
72585 #include "sta_info.h"
72586
72587@@ -635,7 +636,7 @@ struct ieee80211_local {
72588 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
72589 spinlock_t queue_stop_reason_lock;
72590
72591- int open_count;
72592+ local_t open_count;
72593 int monitors, cooked_mntrs;
72594 /* number of interfaces with corresponding FIF_ flags */
72595 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
72596diff -urNp linux-2.6.32.43/net/mac80211/iface.c linux-2.6.32.43/net/mac80211/iface.c
72597--- linux-2.6.32.43/net/mac80211/iface.c 2011-03-27 14:31:47.000000000 -0400
72598+++ linux-2.6.32.43/net/mac80211/iface.c 2011-04-17 15:56:46.000000000 -0400
72599@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_dev
72600 break;
72601 }
72602
72603- if (local->open_count == 0) {
72604+ if (local_read(&local->open_count) == 0) {
72605 res = drv_start(local);
72606 if (res)
72607 goto err_del_bss;
72608@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_dev
72609 * Validate the MAC address for this device.
72610 */
72611 if (!is_valid_ether_addr(dev->dev_addr)) {
72612- if (!local->open_count)
72613+ if (!local_read(&local->open_count))
72614 drv_stop(local);
72615 return -EADDRNOTAVAIL;
72616 }
72617@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_dev
72618
72619 hw_reconf_flags |= __ieee80211_recalc_idle(local);
72620
72621- local->open_count++;
72622+ local_inc(&local->open_count);
72623 if (hw_reconf_flags) {
72624 ieee80211_hw_config(local, hw_reconf_flags);
72625 /*
72626@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_dev
72627 err_del_interface:
72628 drv_remove_interface(local, &conf);
72629 err_stop:
72630- if (!local->open_count)
72631+ if (!local_read(&local->open_count))
72632 drv_stop(local);
72633 err_del_bss:
72634 sdata->bss = NULL;
72635@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_dev
72636 WARN_ON(!list_empty(&sdata->u.ap.vlans));
72637 }
72638
72639- local->open_count--;
72640+ local_dec(&local->open_count);
72641
72642 switch (sdata->vif.type) {
72643 case NL80211_IFTYPE_AP_VLAN:
72644@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_dev
72645
72646 ieee80211_recalc_ps(local, -1);
72647
72648- if (local->open_count == 0) {
72649+ if (local_read(&local->open_count) == 0) {
72650 ieee80211_clear_tx_pending(local);
72651 ieee80211_stop_device(local);
72652
72653diff -urNp linux-2.6.32.43/net/mac80211/main.c linux-2.6.32.43/net/mac80211/main.c
72654--- linux-2.6.32.43/net/mac80211/main.c 2011-05-10 22:12:02.000000000 -0400
72655+++ linux-2.6.32.43/net/mac80211/main.c 2011-05-10 22:12:34.000000000 -0400
72656@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211
72657 local->hw.conf.power_level = power;
72658 }
72659
72660- if (changed && local->open_count) {
72661+ if (changed && local_read(&local->open_count)) {
72662 ret = drv_config(local, changed);
72663 /*
72664 * Goal:
72665diff -urNp linux-2.6.32.43/net/mac80211/mlme.c linux-2.6.32.43/net/mac80211/mlme.c
72666--- linux-2.6.32.43/net/mac80211/mlme.c 2011-03-27 14:31:47.000000000 -0400
72667+++ linux-2.6.32.43/net/mac80211/mlme.c 2011-05-16 21:46:57.000000000 -0400
72668@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
72669 bool have_higher_than_11mbit = false, newsta = false;
72670 u16 ap_ht_cap_flags;
72671
72672+ pax_track_stack();
72673+
72674 /*
72675 * AssocResp and ReassocResp have identical structure, so process both
72676 * of them in this function.
72677diff -urNp linux-2.6.32.43/net/mac80211/pm.c linux-2.6.32.43/net/mac80211/pm.c
72678--- linux-2.6.32.43/net/mac80211/pm.c 2011-03-27 14:31:47.000000000 -0400
72679+++ linux-2.6.32.43/net/mac80211/pm.c 2011-04-17 15:56:46.000000000 -0400
72680@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211
72681 }
72682
72683 /* stop hardware - this must stop RX */
72684- if (local->open_count)
72685+ if (local_read(&local->open_count))
72686 ieee80211_stop_device(local);
72687
72688 local->suspended = true;
72689diff -urNp linux-2.6.32.43/net/mac80211/rate.c linux-2.6.32.43/net/mac80211/rate.c
72690--- linux-2.6.32.43/net/mac80211/rate.c 2011-03-27 14:31:47.000000000 -0400
72691+++ linux-2.6.32.43/net/mac80211/rate.c 2011-04-17 15:56:46.000000000 -0400
72692@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct
72693 struct rate_control_ref *ref, *old;
72694
72695 ASSERT_RTNL();
72696- if (local->open_count)
72697+ if (local_read(&local->open_count))
72698 return -EBUSY;
72699
72700 ref = rate_control_alloc(name, local);
72701diff -urNp linux-2.6.32.43/net/mac80211/tx.c linux-2.6.32.43/net/mac80211/tx.c
72702--- linux-2.6.32.43/net/mac80211/tx.c 2011-03-27 14:31:47.000000000 -0400
72703+++ linux-2.6.32.43/net/mac80211/tx.c 2011-04-17 15:56:46.000000000 -0400
72704@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct
72705 return cpu_to_le16(dur);
72706 }
72707
72708-static int inline is_ieee80211_device(struct ieee80211_local *local,
72709+static inline int is_ieee80211_device(struct ieee80211_local *local,
72710 struct net_device *dev)
72711 {
72712 return local == wdev_priv(dev->ieee80211_ptr);
72713diff -urNp linux-2.6.32.43/net/mac80211/util.c linux-2.6.32.43/net/mac80211/util.c
72714--- linux-2.6.32.43/net/mac80211/util.c 2011-03-27 14:31:47.000000000 -0400
72715+++ linux-2.6.32.43/net/mac80211/util.c 2011-04-17 15:56:46.000000000 -0400
72716@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_
72717 local->resuming = true;
72718
72719 /* restart hardware */
72720- if (local->open_count) {
72721+ if (local_read(&local->open_count)) {
72722 /*
72723 * Upon resume hardware can sometimes be goofy due to
72724 * various platform / driver / bus issues, so restarting
72725diff -urNp linux-2.6.32.43/net/netfilter/ipvs/ip_vs_app.c linux-2.6.32.43/net/netfilter/ipvs/ip_vs_app.c
72726--- linux-2.6.32.43/net/netfilter/ipvs/ip_vs_app.c 2011-03-27 14:31:47.000000000 -0400
72727+++ linux-2.6.32.43/net/netfilter/ipvs/ip_vs_app.c 2011-05-17 19:26:34.000000000 -0400
72728@@ -564,7 +564,7 @@ static const struct file_operations ip_v
72729 .open = ip_vs_app_open,
72730 .read = seq_read,
72731 .llseek = seq_lseek,
72732- .release = seq_release,
72733+ .release = seq_release_net,
72734 };
72735 #endif
72736
72737diff -urNp linux-2.6.32.43/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.32.43/net/netfilter/ipvs/ip_vs_conn.c
72738--- linux-2.6.32.43/net/netfilter/ipvs/ip_vs_conn.c 2011-03-27 14:31:47.000000000 -0400
72739+++ linux-2.6.32.43/net/netfilter/ipvs/ip_vs_conn.c 2011-05-17 19:26:34.000000000 -0400
72740@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
72741 /* if the connection is not template and is created
72742 * by sync, preserve the activity flag.
72743 */
72744- cp->flags |= atomic_read(&dest->conn_flags) &
72745+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
72746 (~IP_VS_CONN_F_INACTIVE);
72747 else
72748- cp->flags |= atomic_read(&dest->conn_flags);
72749+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
72750 cp->dest = dest;
72751
72752 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
72753@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const
72754 atomic_set(&cp->refcnt, 1);
72755
72756 atomic_set(&cp->n_control, 0);
72757- atomic_set(&cp->in_pkts, 0);
72758+ atomic_set_unchecked(&cp->in_pkts, 0);
72759
72760 atomic_inc(&ip_vs_conn_count);
72761 if (flags & IP_VS_CONN_F_NO_CPORT)
72762@@ -871,7 +871,7 @@ static const struct file_operations ip_v
72763 .open = ip_vs_conn_open,
72764 .read = seq_read,
72765 .llseek = seq_lseek,
72766- .release = seq_release,
72767+ .release = seq_release_net,
72768 };
72769
72770 static const char *ip_vs_origin_name(unsigned flags)
72771@@ -934,7 +934,7 @@ static const struct file_operations ip_v
72772 .open = ip_vs_conn_sync_open,
72773 .read = seq_read,
72774 .llseek = seq_lseek,
72775- .release = seq_release,
72776+ .release = seq_release_net,
72777 };
72778
72779 #endif
72780@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip
72781
72782 /* Don't drop the entry if its number of incoming packets is not
72783 located in [0, 8] */
72784- i = atomic_read(&cp->in_pkts);
72785+ i = atomic_read_unchecked(&cp->in_pkts);
72786 if (i > 8 || i < 0) return 0;
72787
72788 if (!todrop_rate[i]) return 0;
72789diff -urNp linux-2.6.32.43/net/netfilter/ipvs/ip_vs_core.c linux-2.6.32.43/net/netfilter/ipvs/ip_vs_core.c
72790--- linux-2.6.32.43/net/netfilter/ipvs/ip_vs_core.c 2011-03-27 14:31:47.000000000 -0400
72791+++ linux-2.6.32.43/net/netfilter/ipvs/ip_vs_core.c 2011-05-04 17:56:28.000000000 -0400
72792@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *sv
72793 ret = cp->packet_xmit(skb, cp, pp);
72794 /* do not touch skb anymore */
72795
72796- atomic_inc(&cp->in_pkts);
72797+ atomic_inc_unchecked(&cp->in_pkts);
72798 ip_vs_conn_put(cp);
72799 return ret;
72800 }
72801@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk
72802 * Sync connection if it is about to close to
72803 * encorage the standby servers to update the connections timeout
72804 */
72805- pkts = atomic_add_return(1, &cp->in_pkts);
72806+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
72807 if (af == AF_INET &&
72808 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
72809 (((cp->protocol != IPPROTO_TCP ||
72810diff -urNp linux-2.6.32.43/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.32.43/net/netfilter/ipvs/ip_vs_ctl.c
72811--- linux-2.6.32.43/net/netfilter/ipvs/ip_vs_ctl.c 2011-03-27 14:31:47.000000000 -0400
72812+++ linux-2.6.32.43/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-17 19:26:34.000000000 -0400
72813@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service
72814 ip_vs_rs_hash(dest);
72815 write_unlock_bh(&__ip_vs_rs_lock);
72816 }
72817- atomic_set(&dest->conn_flags, conn_flags);
72818+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
72819
72820 /* bind the service */
72821 if (!dest->svc) {
72822@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct se
72823 " %-7s %-6d %-10d %-10d\n",
72824 &dest->addr.in6,
72825 ntohs(dest->port),
72826- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
72827+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
72828 atomic_read(&dest->weight),
72829 atomic_read(&dest->activeconns),
72830 atomic_read(&dest->inactconns));
72831@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct se
72832 "%-7s %-6d %-10d %-10d\n",
72833 ntohl(dest->addr.ip),
72834 ntohs(dest->port),
72835- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
72836+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
72837 atomic_read(&dest->weight),
72838 atomic_read(&dest->activeconns),
72839 atomic_read(&dest->inactconns));
72840@@ -1927,7 +1927,7 @@ static const struct file_operations ip_v
72841 .open = ip_vs_info_open,
72842 .read = seq_read,
72843 .llseek = seq_lseek,
72844- .release = seq_release_private,
72845+ .release = seq_release_net,
72846 };
72847
72848 #endif
72849@@ -1976,7 +1976,7 @@ static const struct file_operations ip_v
72850 .open = ip_vs_stats_seq_open,
72851 .read = seq_read,
72852 .llseek = seq_lseek,
72853- .release = single_release,
72854+ .release = single_release_net,
72855 };
72856
72857 #endif
72858@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip
72859
72860 entry.addr = dest->addr.ip;
72861 entry.port = dest->port;
72862- entry.conn_flags = atomic_read(&dest->conn_flags);
72863+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
72864 entry.weight = atomic_read(&dest->weight);
72865 entry.u_threshold = dest->u_threshold;
72866 entry.l_threshold = dest->l_threshold;
72867@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cm
72868 unsigned char arg[128];
72869 int ret = 0;
72870
72871+ pax_track_stack();
72872+
72873 if (!capable(CAP_NET_ADMIN))
72874 return -EPERM;
72875
72876@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct s
72877 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
72878
72879 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
72880- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
72881+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
72882 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
72883 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
72884 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
72885diff -urNp linux-2.6.32.43/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.32.43/net/netfilter/ipvs/ip_vs_sync.c
72886--- linux-2.6.32.43/net/netfilter/ipvs/ip_vs_sync.c 2011-03-27 14:31:47.000000000 -0400
72887+++ linux-2.6.32.43/net/netfilter/ipvs/ip_vs_sync.c 2011-05-04 17:56:28.000000000 -0400
72888@@ -438,7 +438,7 @@ static void ip_vs_process_message(const
72889
72890 if (opt)
72891 memcpy(&cp->in_seq, opt, sizeof(*opt));
72892- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
72893+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
72894 cp->state = state;
72895 cp->old_state = cp->state;
72896 /*
72897diff -urNp linux-2.6.32.43/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.32.43/net/netfilter/ipvs/ip_vs_xmit.c
72898--- linux-2.6.32.43/net/netfilter/ipvs/ip_vs_xmit.c 2011-03-27 14:31:47.000000000 -0400
72899+++ linux-2.6.32.43/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-04 17:56:28.000000000 -0400
72900@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
72901 else
72902 rc = NF_ACCEPT;
72903 /* do not touch skb anymore */
72904- atomic_inc(&cp->in_pkts);
72905+ atomic_inc_unchecked(&cp->in_pkts);
72906 goto out;
72907 }
72908
72909@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
72910 else
72911 rc = NF_ACCEPT;
72912 /* do not touch skb anymore */
72913- atomic_inc(&cp->in_pkts);
72914+ atomic_inc_unchecked(&cp->in_pkts);
72915 goto out;
72916 }
72917
72918diff -urNp linux-2.6.32.43/net/netfilter/Kconfig linux-2.6.32.43/net/netfilter/Kconfig
72919--- linux-2.6.32.43/net/netfilter/Kconfig 2011-03-27 14:31:47.000000000 -0400
72920+++ linux-2.6.32.43/net/netfilter/Kconfig 2011-04-17 15:56:46.000000000 -0400
72921@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
72922
72923 To compile it as a module, choose M here. If unsure, say N.
72924
72925+config NETFILTER_XT_MATCH_GRADM
72926+ tristate '"gradm" match support'
72927+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
72928+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
72929+ ---help---
72930+ The gradm match allows to match on grsecurity RBAC being enabled.
72931+ It is useful when iptables rules are applied early on bootup to
72932+ prevent connections to the machine (except from a trusted host)
72933+ while the RBAC system is disabled.
72934+
72935 config NETFILTER_XT_MATCH_HASHLIMIT
72936 tristate '"hashlimit" match support'
72937 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
72938diff -urNp linux-2.6.32.43/net/netfilter/Makefile linux-2.6.32.43/net/netfilter/Makefile
72939--- linux-2.6.32.43/net/netfilter/Makefile 2011-03-27 14:31:47.000000000 -0400
72940+++ linux-2.6.32.43/net/netfilter/Makefile 2011-04-17 15:56:46.000000000 -0400
72941@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRAC
72942 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
72943 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
72944 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
72945+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
72946 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
72947 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
72948 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
72949diff -urNp linux-2.6.32.43/net/netfilter/nf_conntrack_netlink.c linux-2.6.32.43/net/netfilter/nf_conntrack_netlink.c
72950--- linux-2.6.32.43/net/netfilter/nf_conntrack_netlink.c 2011-03-27 14:31:47.000000000 -0400
72951+++ linux-2.6.32.43/net/netfilter/nf_conntrack_netlink.c 2011-04-17 15:56:46.000000000 -0400
72952@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlatt
72953 static int
72954 ctnetlink_parse_tuple(const struct nlattr * const cda[],
72955 struct nf_conntrack_tuple *tuple,
72956- enum ctattr_tuple type, u_int8_t l3num)
72957+ enum ctattr_type type, u_int8_t l3num)
72958 {
72959 struct nlattr *tb[CTA_TUPLE_MAX+1];
72960 int err;
72961diff -urNp linux-2.6.32.43/net/netfilter/nfnetlink_log.c linux-2.6.32.43/net/netfilter/nfnetlink_log.c
72962--- linux-2.6.32.43/net/netfilter/nfnetlink_log.c 2011-03-27 14:31:47.000000000 -0400
72963+++ linux-2.6.32.43/net/netfilter/nfnetlink_log.c 2011-05-04 17:56:28.000000000 -0400
72964@@ -68,7 +68,7 @@ struct nfulnl_instance {
72965 };
72966
72967 static DEFINE_RWLOCK(instances_lock);
72968-static atomic_t global_seq;
72969+static atomic_unchecked_t global_seq;
72970
72971 #define INSTANCE_BUCKETS 16
72972 static struct hlist_head instance_table[INSTANCE_BUCKETS];
72973@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_ins
72974 /* global sequence number */
72975 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
72976 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
72977- htonl(atomic_inc_return(&global_seq)));
72978+ htonl(atomic_inc_return_unchecked(&global_seq)));
72979
72980 if (data_len) {
72981 struct nlattr *nla;
72982diff -urNp linux-2.6.32.43/net/netfilter/xt_gradm.c linux-2.6.32.43/net/netfilter/xt_gradm.c
72983--- linux-2.6.32.43/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
72984+++ linux-2.6.32.43/net/netfilter/xt_gradm.c 2011-04-17 15:56:46.000000000 -0400
72985@@ -0,0 +1,51 @@
72986+/*
72987+ * gradm match for netfilter
72988